Skip to content

Commit 9b47c52

Browse files
nivedita76ardbiesheuvel
authored andcommitted
efi/libstub: Add definitions for console input and events
Add the required typedefs etc for using con_in's simple text input protocol, and for using the boottime event services. Also add the prototype for the "stall" boot service. Signed-off-by: Arvind Sankar <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Ard Biesheuvel <[email protected]>
1 parent 23d5b73 commit 9b47c52

File tree

4 files changed

+85
-7
lines changed

4 files changed

+85
-7
lines changed

arch/x86/include/asm/efi.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <asm/nospec-branch.h>
1010
#include <asm/mmu_context.h>
1111
#include <linux/build_bug.h>
12+
#include <linux/kernel.h>
1213

1314
extern unsigned long efi_fw_vendor, efi_config_table;
1415

@@ -293,6 +294,15 @@ static inline u32 efi64_convert_status(efi_status_t status)
293294
#define __efi64_argmap_allocate_pool(type, size, buffer) \
294295
((type), (size), efi64_zero_upper(buffer))
295296

297+
#define __efi64_argmap_create_event(type, tpl, f, c, event) \
298+
((type), (tpl), (f), (c), efi64_zero_upper(event))
299+
300+
#define __efi64_argmap_set_timer(event, type, time) \
301+
((event), (type), lower_32_bits(time), upper_32_bits(time))
302+
303+
#define __efi64_argmap_wait_for_event(num, event, index) \
304+
((num), (event), efi64_zero_upper(index))
305+
296306
#define __efi64_argmap_handle_protocol(handle, protocol, interface) \
297307
((handle), (protocol), efi64_zero_upper(interface))
298308

arch/x86/xen/efi.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ static efi_system_table_t efi_systab_xen __initdata = {
2929
.fw_vendor = EFI_INVALID_TABLE_ADDR, /* Initialized later. */
3030
.fw_revision = 0, /* Initialized later. */
3131
.con_in_handle = EFI_INVALID_TABLE_ADDR, /* Not used under Xen. */
32-
.con_in = EFI_INVALID_TABLE_ADDR, /* Not used under Xen. */
32+
.con_in = NULL, /* Not used under Xen. */
3333
.con_out_handle = EFI_INVALID_TABLE_ADDR, /* Not used under Xen. */
3434
.con_out = NULL, /* Not used under Xen. */
3535
.stderr_handle = EFI_INVALID_TABLE_ADDR, /* Not used under Xen. */

drivers/firmware/efi/libstub/efistub.h

Lines changed: 72 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,16 @@ void efi_set_u64_split(u64 data, u32 *lo, u32 *hi)
111111
#define EFI_LOCATE_BY_REGISTER_NOTIFY 1
112112
#define EFI_LOCATE_BY_PROTOCOL 2
113113

114+
/*
115+
* boottime->stall takes the time period in microseconds
116+
*/
117+
#define EFI_USEC_PER_SEC 1000000
118+
119+
/*
120+
* boottime->set_timer takes the time in 100ns units
121+
*/
122+
#define EFI_100NSEC_PER_USEC ((u64)10)
123+
114124
struct efi_boot_memmap {
115125
efi_memory_desc_t **map;
116126
unsigned long *map_size;
@@ -122,6 +132,39 @@ struct efi_boot_memmap {
122132

123133
typedef struct efi_generic_dev_path efi_device_path_protocol_t;
124134

135+
typedef void *efi_event_t;
136+
/* Note that notifications won't work in mixed mode */
137+
typedef void (__efiapi *efi_event_notify_t)(efi_event_t, void *);
138+
139+
#define EFI_EVT_TIMER 0x80000000U
140+
#define EFI_EVT_RUNTIME 0x40000000U
141+
#define EFI_EVT_NOTIFY_WAIT 0x00000100U
142+
#define EFI_EVT_NOTIFY_SIGNAL 0x00000200U
143+
144+
/*
145+
* boottime->wait_for_event takes an array of events as input.
146+
* Provide a helper to set it up correctly for mixed mode.
147+
*/
148+
static inline
149+
void efi_set_event_at(efi_event_t *events, size_t idx, efi_event_t event)
150+
{
151+
if (efi_is_native())
152+
events[idx] = event;
153+
else
154+
((u32 *)events)[idx] = (u32)(unsigned long)event;
155+
}
156+
157+
#define EFI_TPL_APPLICATION 4
158+
#define EFI_TPL_CALLBACK 8
159+
#define EFI_TPL_NOTIFY 16
160+
#define EFI_TPL_HIGH_LEVEL 31
161+
162+
typedef enum {
163+
EfiTimerCancel,
164+
EfiTimerPeriodic,
165+
EfiTimerRelative
166+
} EFI_TIMER_DELAY;
167+
125168
/*
126169
* EFI Boot Services table
127170
*/
@@ -140,11 +183,16 @@ union efi_boot_services {
140183
efi_status_t (__efiapi *allocate_pool)(int, unsigned long,
141184
void **);
142185
efi_status_t (__efiapi *free_pool)(void *);
143-
void *create_event;
144-
void *set_timer;
145-
void *wait_for_event;
186+
efi_status_t (__efiapi *create_event)(u32, unsigned long,
187+
efi_event_notify_t, void *,
188+
efi_event_t *);
189+
efi_status_t (__efiapi *set_timer)(efi_event_t,
190+
EFI_TIMER_DELAY, u64);
191+
efi_status_t (__efiapi *wait_for_event)(unsigned long,
192+
efi_event_t *,
193+
unsigned long *);
146194
void *signal_event;
147-
void *close_event;
195+
efi_status_t (__efiapi *close_event)(efi_event_t);
148196
void *check_event;
149197
void *install_protocol_interface;
150198
void *reinstall_protocol_interface;
@@ -171,7 +219,7 @@ union efi_boot_services {
171219
efi_status_t (__efiapi *exit_boot_services)(efi_handle_t,
172220
unsigned long);
173221
void *get_next_monotonic_count;
174-
void *stall;
222+
efi_status_t (__efiapi *stall)(unsigned long);
175223
void *set_watchdog_timer;
176224
void *connect_controller;
177225
efi_status_t (__efiapi *disconnect_controller)(efi_handle_t,
@@ -256,6 +304,25 @@ union efi_uga_draw_protocol {
256304
} mixed_mode;
257305
};
258306

307+
typedef struct {
308+
u16 scan_code;
309+
efi_char16_t unicode_char;
310+
} efi_input_key_t;
311+
312+
union efi_simple_text_input_protocol {
313+
struct {
314+
void *reset;
315+
efi_status_t (__efiapi *read_keystroke)(efi_simple_text_input_protocol_t *,
316+
efi_input_key_t *);
317+
efi_event_t wait_for_key;
318+
};
319+
struct {
320+
u32 reset;
321+
u32 read_keystroke;
322+
u32 wait_for_key;
323+
} mixed_mode;
324+
};
325+
259326
union efi_simple_text_output_protocol {
260327
struct {
261328
void *reset;

include/linux/efi.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,7 @@ typedef struct {
426426
u32 tables;
427427
} efi_system_table_32_t;
428428

429+
typedef union efi_simple_text_input_protocol efi_simple_text_input_protocol_t;
429430
typedef union efi_simple_text_output_protocol efi_simple_text_output_protocol_t;
430431

431432
typedef union {
@@ -434,7 +435,7 @@ typedef union {
434435
unsigned long fw_vendor; /* physical addr of CHAR16 vendor string */
435436
u32 fw_revision;
436437
unsigned long con_in_handle;
437-
unsigned long con_in;
438+
efi_simple_text_input_protocol_t *con_in;
438439
unsigned long con_out_handle;
439440
efi_simple_text_output_protocol_t *con_out;
440441
unsigned long stderr_handle;

0 commit comments

Comments
 (0)