|
| 1 | +/* |
| 2 | + * Copyright (c) 2020, Intel Corporation |
| 3 | + * All rights reserved. |
| 4 | + * |
| 5 | + * Author: Jérémy Compostella <[email protected]> |
| 6 | + * |
| 7 | + * Redistribution and use in source and binary forms, with or without |
| 8 | + * modification, are permitted provided that the following conditions |
| 9 | + * are met: |
| 10 | + * |
| 11 | + * * Redistributions of source code must retain the above copyright |
| 12 | + * notice, this list of conditions and the following disclaimer. |
| 13 | + * * Redistributions in binary form must reproduce the above copyright |
| 14 | + * notice, this list of conditions and the following disclaimer |
| 15 | + * in the documentation and/or other materials provided with the |
| 16 | + * distribution. |
| 17 | + * |
| 18 | + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 19 | + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 20 | + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
| 21 | + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
| 22 | + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 23 | + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 24 | + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
| 25 | + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 26 | + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
| 27 | + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 28 | + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED |
| 29 | + * OF THE POSSIBILITY OF SUCH DAMAGE. |
| 30 | + */ |
| 31 | + |
| 32 | + |
| 33 | +#include <kconfig.h> |
| 34 | +#include <libpayload-config.h> |
| 35 | +#include <libpayload.h> |
| 36 | +#include <ewlog.h> |
| 37 | + |
| 38 | +#include "lpkey/lpkey.h" |
| 39 | + |
| 40 | +static EFI_CHECK_EVENT saved_check_event; |
| 41 | +static EFI_EVENT wait_for_key; |
| 42 | + |
| 43 | +static EFIAPI EFI_STATUS |
| 44 | +lpkey_check_event(EFI_EVENT Event) |
| 45 | +{ |
| 46 | + if (Event != wait_for_key) |
| 47 | + return saved_check_event(Event); |
| 48 | + |
| 49 | + return havekey() ? EFI_SUCCESS : EFI_NOT_READY; |
| 50 | +} |
| 51 | + |
| 52 | +static EFI_GUID guid = SIMPLE_TEXT_OUTPUT_PROTOCOL; |
| 53 | + |
| 54 | +static EFI_STATUS lpkey_init(EFI_SYSTEM_TABLE *st) |
| 55 | +{ |
| 56 | + EFI_STATUS ret; |
| 57 | + SIMPLE_INPUT_INTERFACE *input; |
| 58 | + |
| 59 | + if (!st) |
| 60 | + return EFI_INVALID_PARAMETER; |
| 61 | + |
| 62 | + ret = st->BootServices->LocateProtocol(&guid, NULL, (VOID **)&input); |
| 63 | + if (EFI_ERROR(ret)) { |
| 64 | + ewerr("Could not locate simple text input protocol"); |
| 65 | + return ret; |
| 66 | + } |
| 67 | + |
| 68 | + wait_for_key = input->WaitForKey; |
| 69 | + saved_check_event = st->BootServices->CheckEvent; |
| 70 | + st->BootServices->CheckEvent = lpkey_check_event; |
| 71 | + |
| 72 | + return EFI_SUCCESS; |
| 73 | +} |
| 74 | + |
| 75 | + |
| 76 | +static EFI_STATUS lpkey_exit(EFI_SYSTEM_TABLE *st) |
| 77 | +{ |
| 78 | + if (!st) |
| 79 | + return EFI_INVALID_PARAMETER; |
| 80 | + |
| 81 | + st->BootServices->CheckEvent = saved_check_event; |
| 82 | + |
| 83 | + return EFI_SUCCESS; |
| 84 | +} |
| 85 | + |
| 86 | +ewdrv_t lpkey_drv = { |
| 87 | + .name = "lpkey", |
| 88 | + .description = "Provide key event support based on libpayload havekey()", |
| 89 | + .init = lpkey_init, |
| 90 | + .exit = lpkey_exit |
| 91 | +}; |
| 92 | + |
0 commit comments