Merge tag 'efi-2019-07-rc5-2' of git://git.denx.de/u-boot-efi
[platform/kernel/u-boot.git] / include / efi_api.h
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * Extensible Firmware Interface
4  * Based on 'Extensible Firmware Interface Specification' version 0.9,
5  * April 30, 1999
6  *
7  * Copyright (C) 1999 VA Linux Systems
8  * Copyright (C) 1999 Walt Drummond <drummond@valinux.com>
9  * Copyright (C) 1999, 2002-2003 Hewlett-Packard Co.
10  *      David Mosberger-Tang <davidm@hpl.hp.com>
11  *      Stephane Eranian <eranian@hpl.hp.com>
12  *
13  * From include/linux/efi.h in kernel 4.1 with some additions/subtractions
14  */
15
16 #ifndef _EFI_API_H
17 #define _EFI_API_H
18
19 #include <efi.h>
20 #include <charset.h>
21
22 #ifdef CONFIG_EFI_LOADER
23 #include <asm/setjmp.h>
24 #endif
25
26 /* UEFI spec version 2.7 */
27 #define EFI_SPECIFICATION_VERSION (2 << 16 | 70)
28
29 /* Types and defines for EFI CreateEvent */
30 enum efi_timer_delay {
31         EFI_TIMER_STOP = 0,
32         EFI_TIMER_PERIODIC = 1,
33         EFI_TIMER_RELATIVE = 2
34 };
35
36 #define efi_intn_t ssize_t
37 #define efi_uintn_t size_t
38 typedef void *efi_hii_handle_t;
39 typedef u16 *efi_string_t;
40 typedef u16 efi_string_id_t;
41 typedef u32 efi_hii_font_style_t;
42 typedef u16 efi_question_id_t;
43 typedef u16 efi_image_id_t;
44 typedef u16 efi_form_id_t;
45
46 #define EVT_TIMER                               0x80000000
47 #define EVT_RUNTIME                             0x40000000
48 #define EVT_NOTIFY_WAIT                         0x00000100
49 #define EVT_NOTIFY_SIGNAL                       0x00000200
50 #define EVT_SIGNAL_EXIT_BOOT_SERVICES           0x00000201
51 #define EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE       0x60000202
52
53 #define TPL_APPLICATION         0x04
54 #define TPL_CALLBACK            0x08
55 #define TPL_NOTIFY              0x10
56 #define TPL_HIGH_LEVEL          0x1F
57
58 struct efi_event;
59
60 /* EFI Boot Services table */
61 #define EFI_BOOT_SERVICES_SIGNATURE 0x56524553544f4f42
62 struct efi_boot_services {
63         struct efi_table_hdr hdr;
64         efi_status_t (EFIAPI *raise_tpl)(efi_uintn_t new_tpl);
65         void (EFIAPI *restore_tpl)(efi_uintn_t old_tpl);
66
67         efi_status_t (EFIAPI *allocate_pages)(int, int, efi_uintn_t,
68                                               efi_physical_addr_t *);
69         efi_status_t (EFIAPI *free_pages)(efi_physical_addr_t, efi_uintn_t);
70         efi_status_t (EFIAPI *get_memory_map)(efi_uintn_t *memory_map_size,
71                                               struct efi_mem_desc *desc,
72                                               efi_uintn_t *key,
73                                               efi_uintn_t *desc_size,
74                                               u32 *desc_version);
75         efi_status_t (EFIAPI *allocate_pool)(int, efi_uintn_t, void **);
76         efi_status_t (EFIAPI *free_pool)(void *);
77
78         efi_status_t (EFIAPI *create_event)(uint32_t type,
79                         efi_uintn_t notify_tpl,
80                         void (EFIAPI *notify_function) (
81                                         struct efi_event *event,
82                                         void *context),
83                         void *notify_context, struct efi_event **event);
84         efi_status_t (EFIAPI *set_timer)(struct efi_event *event,
85                                          enum efi_timer_delay type,
86                                          uint64_t trigger_time);
87         efi_status_t (EFIAPI *wait_for_event)(efi_uintn_t number_of_events,
88                                               struct efi_event **event,
89                                               efi_uintn_t *index);
90         efi_status_t (EFIAPI *signal_event)(struct efi_event *event);
91         efi_status_t (EFIAPI *close_event)(struct efi_event *event);
92         efi_status_t (EFIAPI *check_event)(struct efi_event *event);
93 #define EFI_NATIVE_INTERFACE    0x00000000
94         efi_status_t (EFIAPI *install_protocol_interface)(
95                         efi_handle_t *handle, const efi_guid_t *protocol,
96                         int protocol_interface_type, void *protocol_interface);
97         efi_status_t (EFIAPI *reinstall_protocol_interface)(
98                         efi_handle_t handle, const efi_guid_t *protocol,
99                         void *old_interface, void *new_interface);
100         efi_status_t (EFIAPI *uninstall_protocol_interface)(
101                         efi_handle_t handle, const efi_guid_t *protocol,
102                         void *protocol_interface);
103         efi_status_t (EFIAPI *handle_protocol)(
104                         efi_handle_t handle, const efi_guid_t *protocol,
105                         void **protocol_interface);
106         void *reserved;
107         efi_status_t (EFIAPI *register_protocol_notify)(
108                         const efi_guid_t *protocol, struct efi_event *event,
109                         void **registration);
110         efi_status_t (EFIAPI *locate_handle)(
111                         enum efi_locate_search_type search_type,
112                         const efi_guid_t *protocol, void *search_key,
113                         efi_uintn_t *buffer_size, efi_handle_t *buffer);
114         efi_status_t (EFIAPI *locate_device_path)(const efi_guid_t *protocol,
115                         struct efi_device_path **device_path,
116                         efi_handle_t *device);
117         efi_status_t (EFIAPI *install_configuration_table)(
118                         efi_guid_t *guid, void *table);
119
120         efi_status_t (EFIAPI *load_image)(bool boot_policiy,
121                         efi_handle_t parent_image,
122                         struct efi_device_path *file_path, void *source_buffer,
123                         efi_uintn_t source_size, efi_handle_t *image);
124         efi_status_t (EFIAPI *start_image)(efi_handle_t handle,
125                                            efi_uintn_t *exitdata_size,
126                                            u16 **exitdata);
127         efi_status_t (EFIAPI *exit)(efi_handle_t handle,
128                                     efi_status_t exit_status,
129                                     efi_uintn_t exitdata_size, u16 *exitdata);
130         efi_status_t (EFIAPI *unload_image)(efi_handle_t image_handle);
131         efi_status_t (EFIAPI *exit_boot_services)(efi_handle_t image_handle,
132                                                   efi_uintn_t map_key);
133
134         efi_status_t (EFIAPI *get_next_monotonic_count)(u64 *count);
135         efi_status_t (EFIAPI *stall)(unsigned long usecs);
136         efi_status_t (EFIAPI *set_watchdog_timer)(unsigned long timeout,
137                         uint64_t watchdog_code, unsigned long data_size,
138                         uint16_t *watchdog_data);
139         efi_status_t(EFIAPI *connect_controller)(efi_handle_t controller_handle,
140                         efi_handle_t *driver_image_handle,
141                         struct efi_device_path *remaining_device_path,
142                         bool recursive);
143         efi_status_t (EFIAPI *disconnect_controller)(
144                         efi_handle_t controller_handle,
145                         efi_handle_t driver_image_handle,
146                         efi_handle_t child_handle);
147 #define EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL  0x00000001
148 #define EFI_OPEN_PROTOCOL_GET_PROTOCOL        0x00000002
149 #define EFI_OPEN_PROTOCOL_TEST_PROTOCOL       0x00000004
150 #define EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER 0x00000008
151 #define EFI_OPEN_PROTOCOL_BY_DRIVER           0x00000010
152 #define EFI_OPEN_PROTOCOL_EXCLUSIVE           0x00000020
153         efi_status_t (EFIAPI *open_protocol)(efi_handle_t handle,
154                         const efi_guid_t *protocol, void **interface,
155                         efi_handle_t agent_handle,
156                         efi_handle_t controller_handle, u32 attributes);
157         efi_status_t (EFIAPI *close_protocol)(
158                         efi_handle_t handle, const efi_guid_t *protocol,
159                         efi_handle_t agent_handle,
160                         efi_handle_t controller_handle);
161         efi_status_t(EFIAPI *open_protocol_information)(efi_handle_t handle,
162                         const efi_guid_t *protocol,
163                         struct efi_open_protocol_info_entry **entry_buffer,
164                         efi_uintn_t *entry_count);
165         efi_status_t (EFIAPI *protocols_per_handle)(efi_handle_t handle,
166                         efi_guid_t ***protocol_buffer,
167                         efi_uintn_t *protocols_buffer_count);
168         efi_status_t (EFIAPI *locate_handle_buffer) (
169                         enum efi_locate_search_type search_type,
170                         const efi_guid_t *protocol, void *search_key,
171                         efi_uintn_t *no_handles, efi_handle_t **buffer);
172         efi_status_t (EFIAPI *locate_protocol)(const efi_guid_t *protocol,
173                         void *registration, void **protocol_interface);
174         efi_status_t (EFIAPI *install_multiple_protocol_interfaces)(
175                         efi_handle_t *handle, ...);
176         efi_status_t (EFIAPI *uninstall_multiple_protocol_interfaces)(
177                         efi_handle_t handle, ...);
178         efi_status_t (EFIAPI *calculate_crc32)(const void *data,
179                                                efi_uintn_t data_size,
180                                                u32 *crc32);
181         void (EFIAPI *copy_mem)(void *destination, const void *source,
182                         size_t length);
183         void (EFIAPI *set_mem)(void *buffer, size_t size, uint8_t value);
184         efi_status_t (EFIAPI *create_event_ex)(
185                                 uint32_t type, efi_uintn_t notify_tpl,
186                                 void (EFIAPI *notify_function) (
187                                         struct efi_event *event,
188                                         void *context),
189                                 void *notify_context,
190                                 efi_guid_t *event_group,
191                                 struct efi_event **event);
192 };
193
194 /* Types and defines for EFI ResetSystem */
195 enum efi_reset_type {
196         EFI_RESET_COLD = 0,
197         EFI_RESET_WARM = 1,
198         EFI_RESET_SHUTDOWN = 2,
199         EFI_RESET_PLATFORM_SPECIFIC = 3,
200 };
201
202 /* EFI Runtime Services table */
203 #define EFI_RUNTIME_SERVICES_SIGNATURE  0x56524553544e5552ULL
204
205 #define CAPSULE_FLAGS_PERSIST_ACROSS_RESET      0x00010000
206 #define CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE     0x00020000
207 #define CAPSULE_FLAGS_INITIATE_RESET            0x00040000
208
209 struct efi_capsule_header {
210         efi_guid_t *capsule_guid;
211         u32 header_size;
212         u32 flags;
213         u32 capsule_image_size;
214 };
215
216 #define EFI_RT_SUPPORTED_GET_TIME                       0x0001
217 #define EFI_RT_SUPPORTED_SET_TIME                       0x0002
218 #define EFI_RT_SUPPORTED_GET_WAKEUP_TIME                0x0004
219 #define EFI_RT_SUPPORTED_SET_WAKEUP_TIME                0x0008
220 #define EFI_RT_SUPPORTED_GET_VARIABLE                   0x0010
221 #define EFI_RT_SUPPORTED_GET_NEXT_VARIABLE_NAME         0x0020
222 #define EFI_RT_SUPPORTED_SET_VARIABLE                   0x0040
223 #define EFI_RT_SUPPORTED_SET_VIRTUAL_ADDRESS_MAP        0x0080
224 #define EFI_RT_SUPPORTED_CONVERT_POINTER                0x0100
225 #define EFI_RT_SUPPORTED_GET_NEXT_HIGH_MONOTONIC_COUNT  0x0200
226 #define EFI_RT_SUPPORTED_RESET_SYSTEM                   0x0400
227 #define EFI_RT_SUPPORTED_UPDATE_CAPSULE                 0x0800
228 #define EFI_RT_SUPPORTED_QUERY_CAPSULE_CAPABILITIES     0x1000
229 #define EFI_RT_SUPPORTED_QUERY_VARIABLE_INFO            0x2000
230
231 struct efi_runtime_services {
232         struct efi_table_hdr hdr;
233         efi_status_t (EFIAPI *get_time)(struct efi_time *time,
234                         struct efi_time_cap *capabilities);
235         efi_status_t (EFIAPI *set_time)(struct efi_time *time);
236         efi_status_t (EFIAPI *get_wakeup_time)(char *enabled, char *pending,
237                         struct efi_time *time);
238         efi_status_t (EFIAPI *set_wakeup_time)(char enabled,
239                         struct efi_time *time);
240         efi_status_t (EFIAPI *set_virtual_address_map)(
241                         unsigned long memory_map_size,
242                         unsigned long descriptor_size,
243                         uint32_t descriptor_version,
244                         struct efi_mem_desc *virtmap);
245         efi_status_t (*convert_pointer)(unsigned long dbg, void **address);
246         efi_status_t (EFIAPI *get_variable)(u16 *variable_name,
247                                             const efi_guid_t *vendor,
248                                             u32 *attributes,
249                                             efi_uintn_t *data_size, void *data);
250         efi_status_t (EFIAPI *get_next_variable_name)(
251                         efi_uintn_t *variable_name_size,
252                         u16 *variable_name, const efi_guid_t *vendor);
253         efi_status_t (EFIAPI *set_variable)(u16 *variable_name,
254                                             const efi_guid_t *vendor,
255                                             u32 attributes,
256                                             efi_uintn_t data_size,
257                                             const void *data);
258         efi_status_t (EFIAPI *get_next_high_mono_count)(
259                         uint32_t *high_count);
260         void (EFIAPI *reset_system)(enum efi_reset_type reset_type,
261                                     efi_status_t reset_status,
262                                     unsigned long data_size, void *reset_data);
263         efi_status_t (EFIAPI *update_capsule)(
264                         struct efi_capsule_header **capsule_header_array,
265                         efi_uintn_t capsule_count,
266                         u64 scatter_gather_list);
267         efi_status_t (EFIAPI *query_capsule_caps)(
268                         struct efi_capsule_header **capsule_header_array,
269                         efi_uintn_t capsule_count,
270                         u64 *maximum_capsule_size,
271                         u32 *reset_type);
272         efi_status_t (EFIAPI *query_variable_info)(
273                         u32 attributes,
274                         u64 *maximum_variable_storage_size,
275                         u64 *remaining_variable_storage_size,
276                         u64 *maximum_variable_size);
277 };
278
279 /* EFI event group GUID definitions */
280 #define EFI_EVENT_GROUP_EXIT_BOOT_SERVICES \
281         EFI_GUID(0x27abf055, 0xb1b8, 0x4c26, 0x80, 0x48, \
282                  0x74, 0x8f, 0x37, 0xba, 0xa2, 0xdf)
283
284 #define EFI_EVENT_GROUP_VIRTUAL_ADDRESS_CHANGE \
285         EFI_GUID(0x13fa7698, 0xc831, 0x49c7, 0x87, 0xea, \
286                  0x8f, 0x43, 0xfc, 0xc2, 0x51, 0x96)
287
288 #define EFI_EVENT_GROUP_MEMORY_MAP_CHANGE \
289         EFI_GUID(0x78bee926, 0x692f, 0x48fd, 0x9e, 0xdb, \
290                  0x01, 0x42, 0x2e, 0xf0, 0xd7, 0xab)
291
292 #define EFI_EVENT_GROUP_READY_TO_BOOT \
293         EFI_GUID(0x7ce88fb3, 0x4bd7, 0x4679, 0x87, 0xa8, \
294                  0xa8, 0xd8, 0xde, 0xe5, 0x0d, 0x2b)
295
296 #define EFI_EVENT_GROUP_RESET_SYSTEM \
297         EFI_GUID(0x62da6a56, 0x13fb, 0x485a, 0xa8, 0xda, \
298                  0xa3, 0xdd, 0x79, 0x12, 0xcb, 0x6b)
299
300 /* EFI Configuration Table and GUID definitions */
301 #define NULL_GUID \
302         EFI_GUID(0x00000000, 0x0000, 0x0000, 0x00, 0x00, \
303                  0x00, 0x00, 0x00, 0x00, 0x00, 0x00)
304
305 #define EFI_GLOBAL_VARIABLE_GUID \
306         EFI_GUID(0x8be4df61, 0x93ca, 0x11d2, 0xaa, 0x0d, \
307                  0x00, 0xe0, 0x98, 0x03, 0x2b, 0x8c)
308
309 #define EFI_FDT_GUID \
310         EFI_GUID(0xb1b621d5, 0xf19c, 0x41a5, \
311                  0x83, 0x0b, 0xd9, 0x15, 0x2c, 0x69, 0xaa, 0xe0)
312
313 #define EFI_ACPI_TABLE_GUID \
314         EFI_GUID(0x8868e871, 0xe4f1, 0x11d3, \
315                  0xbc, 0x22, 0x00, 0x80, 0xc7, 0x3c, 0x88, 0x81)
316
317 #define SMBIOS_TABLE_GUID \
318         EFI_GUID(0xeb9d2d31, 0x2d88, 0x11d3,  \
319                  0x9a, 0x16, 0x00, 0x90, 0x27, 0x3f, 0xc1, 0x4d)
320
321 struct efi_configuration_table {
322         efi_guid_t guid;
323         void *table;
324 } __packed;
325
326 #define EFI_SYSTEM_TABLE_SIGNATURE ((u64)0x5453595320494249ULL)
327
328 struct efi_system_table {
329         struct efi_table_hdr hdr;
330         u16 *fw_vendor;   /* physical addr of wchar_t vendor string */
331         u32 fw_revision;
332         efi_handle_t con_in_handle;
333         struct efi_simple_text_input_protocol *con_in;
334         efi_handle_t con_out_handle;
335         struct efi_simple_text_output_protocol *con_out;
336         efi_handle_t stderr_handle;
337         struct efi_simple_text_output_protocol *std_err;
338         struct efi_runtime_services *runtime;
339         struct efi_boot_services *boottime;
340         efi_uintn_t nr_tables;
341         struct efi_configuration_table *tables;
342 };
343
344 #define EFI_LOADED_IMAGE_PROTOCOL_GUID \
345         EFI_GUID(0x5b1b31a1, 0x9562, 0x11d2, \
346                  0x8e, 0x3f, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b)
347
348 #define EFI_LOADED_IMAGE_DEVICE_PATH_PROTOCOL_GUID \
349         EFI_GUID(0xbc62157e, 0x3e33, 0x4fec, \
350                  0x99, 0x20, 0x2d, 0x3b, 0x36, 0xd7, 0x50, 0xdf)
351
352 #define EFI_LOADED_IMAGE_PROTOCOL_REVISION 0x1000
353
354 struct efi_loaded_image {
355         u32 revision;
356         void *parent_handle;
357         struct efi_system_table *system_table;
358         efi_handle_t device_handle;
359         struct efi_device_path *file_path;
360         void *reserved;
361         u32 load_options_size;
362         void *load_options;
363         void *image_base;
364         aligned_u64 image_size;
365         unsigned int image_code_type;
366         unsigned int image_data_type;
367         efi_status_t (EFIAPI *unload)(efi_handle_t image_handle);
368 };
369
370 #define EFI_DEVICE_PATH_PROTOCOL_GUID \
371         EFI_GUID(0x09576e91, 0x6d3f, 0x11d2, \
372                  0x8e, 0x39, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b)
373
374 #define DEVICE_PATH_TYPE_END                    0x7f
375 #  define DEVICE_PATH_SUB_TYPE_INSTANCE_END     0x01
376 #  define DEVICE_PATH_SUB_TYPE_END              0xff
377
378 struct efi_device_path {
379         u8 type;
380         u8 sub_type;
381         u16 length;
382 } __packed;
383
384 struct efi_mac_addr {
385         u8 addr[32];
386 } __packed;
387
388 #define DEVICE_PATH_TYPE_HARDWARE_DEVICE        0x01
389 #  define DEVICE_PATH_SUB_TYPE_MEMORY           0x03
390 #  define DEVICE_PATH_SUB_TYPE_VENDOR           0x04
391
392 struct efi_device_path_memory {
393         struct efi_device_path dp;
394         u32 memory_type;
395         u64 start_address;
396         u64 end_address;
397 } __packed;
398
399 struct efi_device_path_vendor {
400         struct efi_device_path dp;
401         efi_guid_t guid;
402         u8 vendor_data[];
403 } __packed;
404
405 #define DEVICE_PATH_TYPE_ACPI_DEVICE            0x02
406 #  define DEVICE_PATH_SUB_TYPE_ACPI_DEVICE      0x01
407
408 #define EFI_PNP_ID(ID)                          (u32)(((ID) << 16) | 0x41D0)
409 #define EISA_PNP_ID(ID)                         EFI_PNP_ID(ID)
410 #define EISA_PNP_NUM(ID)                        ((ID) >> 16)
411
412 struct efi_device_path_acpi_path {
413         struct efi_device_path dp;
414         u32 hid;
415         u32 uid;
416 } __packed;
417
418 #define DEVICE_PATH_TYPE_MESSAGING_DEVICE       0x03
419 #  define DEVICE_PATH_SUB_TYPE_MSG_ATAPI        0x01
420 #  define DEVICE_PATH_SUB_TYPE_MSG_SCSI         0x02
421 #  define DEVICE_PATH_SUB_TYPE_MSG_USB          0x05
422 #  define DEVICE_PATH_SUB_TYPE_MSG_MAC_ADDR     0x0b
423 #  define DEVICE_PATH_SUB_TYPE_MSG_USB_CLASS    0x0f
424 #  define DEVICE_PATH_SUB_TYPE_MSG_SD           0x1a
425 #  define DEVICE_PATH_SUB_TYPE_MSG_MMC          0x1d
426
427 struct efi_device_path_atapi {
428         struct efi_device_path dp;
429         u8 primary_secondary;
430         u8 slave_master;
431         u16 logical_unit_number;
432 } __packed;
433
434 struct efi_device_path_scsi {
435         struct efi_device_path dp;
436         u16 target_id;
437         u16 logical_unit_number;
438 } __packed;
439
440 struct efi_device_path_usb {
441         struct efi_device_path dp;
442         u8 parent_port_number;
443         u8 usb_interface;
444 } __packed;
445
446 struct efi_device_path_mac_addr {
447         struct efi_device_path dp;
448         struct efi_mac_addr mac;
449         u8 if_type;
450 } __packed;
451
452 struct efi_device_path_usb_class {
453         struct efi_device_path dp;
454         u16 vendor_id;
455         u16 product_id;
456         u8 device_class;
457         u8 device_subclass;
458         u8 device_protocol;
459 } __packed;
460
461 struct efi_device_path_sd_mmc_path {
462         struct efi_device_path dp;
463         u8 slot_number;
464 } __packed;
465
466 #define DEVICE_PATH_TYPE_MEDIA_DEVICE           0x04
467 #  define DEVICE_PATH_SUB_TYPE_HARD_DRIVE_PATH  0x01
468 #  define DEVICE_PATH_SUB_TYPE_CDROM_PATH       0x02
469 #  define DEVICE_PATH_SUB_TYPE_FILE_PATH        0x04
470
471 struct efi_device_path_hard_drive_path {
472         struct efi_device_path dp;
473         u32 partition_number;
474         u64 partition_start;
475         u64 partition_end;
476         u8 partition_signature[16];
477         u8 partmap_type;
478         u8 signature_type;
479 } __packed;
480
481 struct efi_device_path_cdrom_path {
482         struct efi_device_path dp;
483         u32 boot_entry;
484         u64 partition_start;
485         u64 partition_end;
486 } __packed;
487
488 struct efi_device_path_file_path {
489         struct efi_device_path dp;
490         u16 str[];
491 } __packed;
492
493 #define EFI_BLOCK_IO_PROTOCOL_GUID \
494         EFI_GUID(0x964e5b21, 0x6459, 0x11d2, \
495                  0x8e, 0x39, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b)
496
497 struct efi_block_io_media {
498         u32 media_id;
499         char removable_media;
500         char media_present;
501         char logical_partition;
502         char read_only;
503         char write_caching;
504         u8 pad[3];
505         u32 block_size;
506         u32 io_align;
507         u8 pad2[4];
508         u64 last_block;
509         /* Added in revision 2 of the protocol */
510         u64 lowest_aligned_lba;
511         u32 logical_blocks_per_physical_block;
512         /* Added in revision 3 of the protocol */
513         u32 optimal_transfer_length_granualarity;
514 };
515
516 #define EFI_BLOCK_IO_PROTOCOL_REVISION2 0x00020001
517 #define EFI_BLOCK_IO_PROTOCOL_REVISION3 0x0002001f
518
519 struct efi_block_io {
520         u64 revision;
521         struct efi_block_io_media *media;
522         efi_status_t (EFIAPI *reset)(struct efi_block_io *this,
523                         char extended_verification);
524         efi_status_t (EFIAPI *read_blocks)(struct efi_block_io *this,
525                         u32 media_id, u64 lba, efi_uintn_t buffer_size,
526                         void *buffer);
527         efi_status_t (EFIAPI *write_blocks)(struct efi_block_io *this,
528                         u32 media_id, u64 lba, efi_uintn_t buffer_size,
529                         void *buffer);
530         efi_status_t (EFIAPI *flush_blocks)(struct efi_block_io *this);
531 };
532
533 struct simple_text_output_mode {
534         s32 max_mode;
535         s32 mode;
536         s32 attribute;
537         s32 cursor_column;
538         s32 cursor_row;
539         bool cursor_visible;
540 };
541
542 #define EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL_GUID \
543         EFI_GUID(0x387477c2, 0x69c7, 0x11d2, \
544                  0x8e, 0x39, 0x0, 0xa0, 0xc9, 0x69, 0x72, 0x3b)
545
546 #define EFI_BLACK                0x00
547 #define EFI_BLUE                 0x01
548 #define EFI_GREEN                0x02
549 #define EFI_CYAN                 0x03
550 #define EFI_RED                  0x04
551 #define EFI_MAGENTA              0x05
552 #define EFI_BROWN                0x06
553 #define EFI_LIGHTGRAY            0x07
554 #define EFI_BRIGHT               0x08
555 #define EFI_DARKGRAY             0x08
556 #define EFI_LIGHTBLUE            0x09
557 #define EFI_LIGHTGREEN           0x0a
558 #define EFI_LIGHTCYAN            0x0b
559 #define EFI_LIGHTRED             0x0c
560 #define EFI_LIGHTMAGENTA         0x0d
561 #define EFI_YELLOW               0x0e
562 #define EFI_WHITE                0x0f
563 #define EFI_BACKGROUND_BLACK     0x00
564 #define EFI_BACKGROUND_BLUE      0x10
565 #define EFI_BACKGROUND_GREEN     0x20
566 #define EFI_BACKGROUND_CYAN      0x30
567 #define EFI_BACKGROUND_RED       0x40
568 #define EFI_BACKGROUND_MAGENTA   0x50
569 #define EFI_BACKGROUND_BROWN     0x60
570 #define EFI_BACKGROUND_LIGHTGRAY 0x70
571
572 /* extract foreground color from EFI attribute */
573 #define EFI_ATTR_FG(attr)        ((attr) & 0x07)
574 /* treat high bit of FG as bright/bold (similar to edk2) */
575 #define EFI_ATTR_BOLD(attr)      (((attr) >> 3) & 0x01)
576 /* extract background color from EFI attribute */
577 #define EFI_ATTR_BG(attr)        (((attr) >> 4) & 0x7)
578
579 struct efi_simple_text_output_protocol {
580         void *reset;
581         efi_status_t (EFIAPI *output_string)(
582                         struct efi_simple_text_output_protocol *this,
583                         const efi_string_t str);
584         efi_status_t (EFIAPI *test_string)(
585                         struct efi_simple_text_output_protocol *this,
586                         const efi_string_t str);
587         efi_status_t(EFIAPI *query_mode)(
588                         struct efi_simple_text_output_protocol *this,
589                         unsigned long mode_number, unsigned long *columns,
590                         unsigned long *rows);
591         efi_status_t(EFIAPI *set_mode)(
592                         struct efi_simple_text_output_protocol *this,
593                         unsigned long mode_number);
594         efi_status_t(EFIAPI *set_attribute)(
595                         struct efi_simple_text_output_protocol *this,
596                         unsigned long attribute);
597         efi_status_t(EFIAPI *clear_screen) (
598                         struct efi_simple_text_output_protocol *this);
599         efi_status_t(EFIAPI *set_cursor_position) (
600                         struct efi_simple_text_output_protocol *this,
601                         unsigned long column, unsigned long row);
602         efi_status_t(EFIAPI *enable_cursor)(
603                         struct efi_simple_text_output_protocol *this,
604                         bool enable);
605         struct simple_text_output_mode *mode;
606 };
607
608 #define EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL_GUID \
609         EFI_GUID(0xdd9e7534, 0x7762, 0x4698, \
610                  0x8c, 0x14, 0xf5, 0x85, 0x17, 0xa6, 0x25, 0xaa)
611
612 struct efi_input_key {
613         u16 scan_code;
614         s16 unicode_char;
615 };
616
617 #define EFI_SHIFT_STATE_INVALID         0x00000000
618 #define EFI_RIGHT_SHIFT_PRESSED         0x00000001
619 #define EFI_LEFT_SHIFT_PRESSED          0x00000002
620 #define EFI_RIGHT_CONTROL_PRESSED       0x00000004
621 #define EFI_LEFT_CONTROL_PRESSED        0x00000008
622 #define EFI_RIGHT_ALT_PRESSED           0x00000010
623 #define EFI_LEFT_ALT_PRESSED            0x00000020
624 #define EFI_RIGHT_LOGO_PRESSED          0x00000040
625 #define EFI_LEFT_LOGO_PRESSED           0x00000080
626 #define EFI_MENU_KEY_PRESSED            0x00000100
627 #define EFI_SYS_REQ_PRESSED             0x00000200
628 #define EFI_SHIFT_STATE_VALID           0x80000000
629
630 #define EFI_TOGGLE_STATE_INVALID        0x00
631 #define EFI_SCROLL_LOCK_ACTIVE          0x01
632 #define EFI_NUM_LOCK_ACTIVE             0x02
633 #define EFI_CAPS_LOCK_ACTIVE            0x04
634 #define EFI_KEY_STATE_EXPOSED           0x40
635 #define EFI_TOGGLE_STATE_VALID          0x80
636
637 struct efi_key_state {
638         u32 key_shift_state;
639         u8 key_toggle_state;
640 };
641
642 struct efi_key_data {
643         struct efi_input_key key;
644         struct efi_key_state key_state;
645 };
646
647 struct efi_simple_text_input_ex_protocol {
648         efi_status_t (EFIAPI *reset) (
649                 struct efi_simple_text_input_ex_protocol *this,
650                 bool extended_verification);
651         efi_status_t (EFIAPI *read_key_stroke_ex) (
652                 struct efi_simple_text_input_ex_protocol *this,
653                 struct efi_key_data *key_data);
654         struct efi_event *wait_for_key_ex;
655         efi_status_t (EFIAPI *set_state) (
656                 struct efi_simple_text_input_ex_protocol *this,
657                 u8 *key_toggle_state);
658         efi_status_t (EFIAPI *register_key_notify) (
659                 struct efi_simple_text_input_ex_protocol *this,
660                 struct efi_key_data *key_data,
661                 efi_status_t (EFIAPI *key_notify_function)(
662                         struct efi_key_data *key_data),
663                 void **notify_handle);
664         efi_status_t (EFIAPI *unregister_key_notify) (
665                 struct efi_simple_text_input_ex_protocol *this,
666                 void *notification_handle);
667 };
668
669 #define EFI_SIMPLE_TEXT_INPUT_PROTOCOL_GUID \
670         EFI_GUID(0x387477c1, 0x69c7, 0x11d2, \
671                  0x8e, 0x39, 0x0, 0xa0, 0xc9, 0x69, 0x72, 0x3b)
672
673 struct efi_simple_text_input_protocol {
674         efi_status_t(EFIAPI *reset)(struct efi_simple_text_input_protocol *this,
675                                     bool extended_verification);
676         efi_status_t(EFIAPI *read_key_stroke)(
677                         struct efi_simple_text_input_protocol *this,
678                         struct efi_input_key *key);
679         struct efi_event *wait_for_key;
680 };
681
682 #define EFI_DEVICE_PATH_TO_TEXT_PROTOCOL_GUID \
683         EFI_GUID(0x8b843e20, 0x8132, 0x4852, \
684                  0x90, 0xcc, 0x55, 0x1a, 0x4e, 0x4a, 0x7f, 0x1c)
685
686 struct efi_device_path_to_text_protocol {
687         uint16_t *(EFIAPI *convert_device_node_to_text)(
688                         struct efi_device_path *device_node,
689                         bool display_only,
690                         bool allow_shortcuts);
691         uint16_t *(EFIAPI *convert_device_path_to_text)(
692                         struct efi_device_path *device_path,
693                         bool display_only,
694                         bool allow_shortcuts);
695 };
696
697 #define EFI_DEVICE_PATH_UTILITIES_PROTOCOL_GUID \
698         EFI_GUID(0x0379be4e, 0xd706, 0x437d, \
699                  0xb0, 0x37, 0xed, 0xb8, 0x2f, 0xb7, 0x72, 0xa4)
700
701 struct efi_device_path_utilities_protocol {
702         efi_uintn_t (EFIAPI *get_device_path_size)(
703                 const struct efi_device_path *device_path);
704         struct efi_device_path *(EFIAPI *duplicate_device_path)(
705                 const struct efi_device_path *device_path);
706         struct efi_device_path *(EFIAPI *append_device_path)(
707                 const struct efi_device_path *src1,
708                 const struct efi_device_path *src2);
709         struct efi_device_path *(EFIAPI *append_device_node)(
710                 const struct efi_device_path *device_path,
711                 const struct efi_device_path *device_node);
712         struct efi_device_path *(EFIAPI *append_device_path_instance)(
713                 const struct efi_device_path *device_path,
714                 const struct efi_device_path *device_path_instance);
715         struct efi_device_path *(EFIAPI *get_next_device_path_instance)(
716                 struct efi_device_path **device_path_instance,
717                 efi_uintn_t *device_path_instance_size);
718         bool (EFIAPI *is_device_path_multi_instance)(
719                 const struct efi_device_path *device_path);
720         struct efi_device_path *(EFIAPI *create_device_node)(
721                 uint8_t node_type,
722                 uint8_t node_sub_type,
723                 uint16_t node_length);
724 };
725
726 /*
727  * Human Interface Infrastructure (HII)
728  */
729 struct efi_hii_package_list_header {
730         efi_guid_t package_list_guid;
731         u32 package_length;
732 } __packed;
733
734 /**
735  * struct efi_hii_package_header - EFI HII package header
736  *
737  * @fields:     'fields' replaces the bit-fields defined in the EFI
738  *              specification to to avoid possible compiler incompatibilities::
739  *
740  *              u32 length:24;
741  *              u32 type:8;
742  */
743 struct efi_hii_package_header {
744         u32 fields;
745 } __packed;
746
747 #define __EFI_HII_PACKAGE_LEN_SHIFT     0
748 #define __EFI_HII_PACKAGE_TYPE_SHIFT    24
749 #define __EFI_HII_PACKAGE_LEN_MASK      0xffffff
750 #define __EFI_HII_PACKAGE_TYPE_MASK     0xff
751
752 #define EFI_HII_PACKAGE_TYPE_ALL          0x00
753 #define EFI_HII_PACKAGE_TYPE_GUID         0x01
754 #define EFI_HII_PACKAGE_FORMS             0x02
755 #define EFI_HII_PACKAGE_STRINGS           0x04
756 #define EFI_HII_PACKAGE_FONTS             0x05
757 #define EFI_HII_PACKAGE_IMAGES            0x06
758 #define EFI_HII_PACKAGE_SIMPLE_FONTS      0x07
759 #define EFI_HII_PACKAGE_DEVICE_PATH       0x08
760 #define EFI_HII_PACKAGE_KEYBOARD_LAYOUT   0x09
761 #define EFI_HII_PACKAGE_ANIMATIONS        0x0A
762 #define EFI_HII_PACKAGE_END               0xDF
763 #define EFI_HII_PACKAGE_TYPE_SYSTEM_BEGIN 0xE0
764 #define EFI_HII_PACKAGE_TYPE_SYSTEM_END   0xFF
765
766 /*
767  * HII GUID package
768  */
769 struct efi_hii_guid_package {
770         struct efi_hii_package_header header;
771         efi_guid_t guid;
772         char data[];
773 } __packed;
774
775 /*
776  * HII string package
777  */
778 struct efi_hii_strings_package {
779         struct efi_hii_package_header header;
780         u32 header_size;
781         u32 string_info_offset;
782         u16 language_window[16];
783         efi_string_id_t language_name;
784         u8  language[];
785 } __packed;
786
787 struct efi_hii_string_block {
788         u8 block_type;
789         /* u8 block_body[]; */
790 } __packed;
791
792 #define EFI_HII_SIBT_END               0x00
793 #define EFI_HII_SIBT_STRING_SCSU       0x10
794 #define EFI_HII_SIBT_STRING_SCSU_FONT  0x11
795 #define EFI_HII_SIBT_STRINGS_SCSU      0x12
796 #define EFI_HII_SIBT_STRINGS_SCSU_FONT 0x13
797 #define EFI_HII_SIBT_STRING_UCS2       0x14
798 #define EFI_HII_SIBT_STRING_UCS2_FONT  0x15
799 #define EFI_HII_SIBT_STRINGS_UCS2      0x16
800 #define EFI_HII_SIBT_STRINGS_UCS2_FONT 0x17
801 #define EFI_HII_SIBT_DUPLICATE         0x20
802 #define EFI_HII_SIBT_SKIP2             0x21
803 #define EFI_HII_SIBT_SKIP1             0x22
804 #define EFI_HII_SIBT_EXT1              0x30
805 #define EFI_HII_SIBT_EXT2              0x31
806 #define EFI_HII_SIBT_EXT4              0x32
807 #define EFI_HII_SIBT_FONT              0x40
808
809 struct efi_hii_sibt_string_ucs2_block {
810         struct efi_hii_string_block header;
811         u16 string_text[];
812 } __packed;
813
814 static inline struct efi_hii_string_block *
815 efi_hii_sibt_string_ucs2_block_next(struct efi_hii_sibt_string_ucs2_block *blk)
816 {
817         return ((void *)blk) + sizeof(*blk) +
818                 (u16_strlen(blk->string_text) + 1) * 2;
819 }
820
821 /*
822  * HII forms package
823  * TODO: full scope of definitions
824  */
825 struct efi_hii_time {
826         u8 hour;
827         u8 minute;
828         u8 second;
829 };
830
831 struct efi_hii_date {
832         u16 year;
833         u8 month;
834         u8 day;
835 };
836
837 struct efi_hii_ref {
838         efi_question_id_t question_id;
839         efi_form_id_t form_id;
840         efi_guid_t form_set_guid;
841         efi_string_id_t device_path;
842 };
843
844 union efi_ifr_type_value {
845         u8 u8;                          // EFI_IFR_TYPE_NUM_SIZE_8
846         u16 u16;                        // EFI_IFR_TYPE_NUM_SIZE_16
847         u32 u32;                        // EFI_IFR_TYPE_NUM_SIZE_32
848         u64 u64;                        // EFI_IFR_TYPE_NUM_SIZE_64
849         bool b;                         // EFI_IFR_TYPE_BOOLEAN
850         struct efi_hii_time time;       // EFI_IFR_TYPE_TIME
851         struct efi_hii_date date;       // EFI_IFR_TYPE_DATE
852         efi_string_id_t string; // EFI_IFR_TYPE_STRING, EFI_IFR_TYPE_ACTION
853         struct efi_hii_ref ref;         // EFI_IFR_TYPE_REF
854         // u8 buffer[];                 // EFI_IFR_TYPE_BUFFER
855 };
856
857 #define EFI_IFR_TYPE_NUM_SIZE_8         0x00
858 #define EFI_IFR_TYPE_NUM_SIZE_16        0x01
859 #define EFI_IFR_TYPE_NUM_SIZE_32        0x02
860 #define EFI_IFR_TYPE_NUM_SIZE_64        0x03
861 #define EFI_IFR_TYPE_BOOLEAN            0x04
862 #define EFI_IFR_TYPE_TIME               0x05
863 #define EFI_IFR_TYPE_DATE               0x06
864 #define EFI_IFR_TYPE_STRING             0x07
865 #define EFI_IFR_TYPE_OTHER              0x08
866 #define EFI_IFR_TYPE_UNDEFINED          0x09
867 #define EFI_IFR_TYPE_ACTION             0x0A
868 #define EFI_IFR_TYPE_BUFFER             0x0B
869 #define EFI_IFR_TYPE_REF                0x0C
870 #define EFI_IFR_OPTION_DEFAULT          0x10
871 #define EFI_IFR_OPTION_DEFAULT_MFG      0x20
872
873 #define EFI_IFR_ONE_OF_OPTION_OP        0x09
874
875 struct efi_ifr_op_header {
876         u8 opCode;
877         u8 length:7;
878         u8 scope:1;
879 };
880
881 struct efi_ifr_one_of_option {
882         struct efi_ifr_op_header header;
883         efi_string_id_t option;
884         u8 flags;
885         u8 type;
886         union efi_ifr_type_value value;
887 };
888
889 typedef efi_uintn_t efi_browser_action_t;
890
891 #define EFI_BROWSER_ACTION_REQUEST_NONE                 0
892 #define EFI_BROWSER_ACTION_REQUEST_RESET                1
893 #define EFI_BROWSER_ACTION_REQUEST_SUBMIT               2
894 #define EFI_BROWSER_ACTION_REQUEST_EXIT                 3
895 #define EFI_BROWSER_ACTION_REQUEST_FORM_SUBMIT_EXIT     4
896 #define EFI_BROWSER_ACTION_REQUEST_FORM_DISCARD_EXIT    5
897 #define EFI_BROWSER_ACTION_REQUEST_FORM_APPLY           6
898 #define EFI_BROWSER_ACTION_REQUEST_FORM_DISCARD         7
899 #define EFI_BROWSER_ACTION_REQUEST_RECONNECT            8
900
901 typedef efi_uintn_t efi_browser_action_request_t;
902
903 #define EFI_BROWSER_ACTION_CHANGING                     0
904 #define EFI_BROWSER_ACTION_CHANGED                      1
905 #define EFI_BROWSER_ACTION_RETRIEVE                     2
906 #define EFI_BROWSER_ACTION_FORM_OPEN                    3
907 #define EFI_BROWSER_ACTION_FORM_CLOSE                   4
908 #define EFI_BROWSER_ACTION_SUBMITTED                    5
909 #define EFI_BROWSER_ACTION_DEFAULT_STANDARD             0x1000
910 #define EFI_BROWSER_ACTION_DEFAULT_MANUFACTURING        0x1001
911 #define EFI_BROWSER_ACTION_DEFAULT_SAFE                 0x1002
912 #define EFI_BROWSER_ACTION_DEFAULT_PLATFORM             0x2000
913 #define EFI_BROWSER_ACTION_DEFAULT_HARDWARE             0x3000
914 #define EFI_BROWSER_ACTION_DEFAULT_FIRMWARE             0x4000
915
916 /*
917  * HII keyboard package
918  */
919 typedef enum {
920         EFI_KEY_LCTRL, EFI_KEY_A0, EFI_KEY_LALT, EFI_KEY_SPACE_BAR,
921         EFI_KEY_A2, EFI_KEY_A3, EFI_KEY_A4, EFI_KEY_RCTRL, EFI_KEY_LEFT_ARROW,
922         EFI_KEY_DOWN_ARROW, EFI_KEY_RIGHT_ARROW, EFI_KEY_ZERO,
923         EFI_KEY_PERIOD, EFI_KEY_ENTER, EFI_KEY_LSHIFT, EFI_KEY_B0,
924         EFI_KEY_B1, EFI_KEY_B2, EFI_KEY_B3, EFI_KEY_B4, EFI_KEY_B5, EFI_KEY_B6,
925         EFI_KEY_B7, EFI_KEY_B8, EFI_KEY_B9, EFI_KEY_B10, EFI_KEY_RSHIFT,
926         EFI_KEY_UP_ARROW, EFI_KEY_ONE, EFI_KEY_TWO, EFI_KEY_THREE,
927         EFI_KEY_CAPS_LOCK, EFI_KEY_C1, EFI_KEY_C2, EFI_KEY_C3, EFI_KEY_C4,
928         EFI_KEY_C5, EFI_KEY_C6, EFI_KEY_C7, EFI_KEY_C8, EFI_KEY_C9,
929         EFI_KEY_C10, EFI_KEY_C11, EFI_KEY_C12, EFI_KEY_FOUR, EFI_KEY_FIVE,
930         EFI_KEY_SIX, EFI_KEY_PLUS, EFI_KEY_TAB, EFI_KEY_D1, EFI_KEY_D2,
931         EFI_KEY_D3, EFI_KEY_D4, EFI_KEY_D5, EFI_KEY_D6, EFI_KEY_D7, EFI_KEY_D8,
932         EFI_KEY_D9, EFI_KEY_D10, EFI_KEY_D11, EFI_KEY_D12, EFI_KEY_D13,
933         EFI_KEY_DEL, EFI_KEY_END, EFI_KEY_PG_DN, EFI_KEY_SEVEN, EFI_KEY_EIGHT,
934         EFI_KEY_NINE, EFI_KEY_E0, EFI_KEY_E1, EFI_KEY_E2, EFI_KEY_E3,
935         EFI_KEY_E4, EFI_KEY_E5, EFI_KEY_E6, EFI_KEY_E7, EFI_KEY_E8, EFI_KEY_E9,
936         EFI_KEY_E10, EFI_KEY_E11, EFI_KEY_E12, EFI_KEY_BACK_SPACE,
937         EFI_KEY_INS, EFI_KEY_HOME, EFI_KEY_PG_UP, EFI_KEY_NLCK, EFI_KEY_SLASH,
938         EFI_KEY_ASTERISK, EFI_KEY_MINUS, EFI_KEY_ESC, EFI_KEY_F1, EFI_KEY_F2,
939         EFI_KEY_F3, EFI_KEY_F4, EFI_KEY_F5, EFI_KEY_F6, EFI_KEY_F7, EFI_KEY_F8,
940         EFI_KEY_F9, EFI_KEY_F10, EFI_KEY_F11, EFI_KEY_F12, EFI_KEY_PRINT,
941         EFI_KEY_SLCK, EFI_KEY_PAUSE,
942 } efi_key;
943
944 struct efi_key_descriptor {
945         u32 key;
946         u16 unicode;
947         u16 shifted_unicode;
948         u16 alt_gr_unicode;
949         u16 shifted_alt_gr_unicode;
950         u16 modifier;
951         u16 affected_attribute;
952 } __packed;
953
954 struct efi_hii_keyboard_layout {
955         u16 layout_length;
956         efi_guid_t guid;
957         u32 layout_descriptor_string_offset;
958         u8 descriptor_count;
959         struct efi_key_descriptor descriptors[];
960 } __packed;
961
962 struct efi_hii_keyboard_package {
963         struct efi_hii_package_header header;
964         u16 layout_count;
965         struct efi_hii_keyboard_layout layout[];
966 } __packed;
967
968 /*
969  * HII protocols
970  */
971 #define EFI_HII_STRING_PROTOCOL_GUID \
972         EFI_GUID(0x0fd96974, 0x23aa, 0x4cdc, \
973                  0xb9, 0xcb, 0x98, 0xd1, 0x77, 0x50, 0x32, 0x2a)
974
975 struct efi_font_info {
976         efi_hii_font_style_t font_style;
977         u16 font_size;
978         u16 font_name[1];
979 };
980
981 struct efi_hii_string_protocol {
982         efi_status_t(EFIAPI *new_string)(
983                 const struct efi_hii_string_protocol *this,
984                 efi_hii_handle_t package_list,
985                 efi_string_id_t *string_id,
986                 const u8 *language,
987                 const u16 *language_name,
988                 const efi_string_t string,
989                 const struct efi_font_info *string_font_info);
990         efi_status_t(EFIAPI *get_string)(
991                 const struct efi_hii_string_protocol *this,
992                 const u8 *language,
993                 efi_hii_handle_t package_list,
994                 efi_string_id_t string_id,
995                 efi_string_t string,
996                 efi_uintn_t *string_size,
997                 struct efi_font_info **string_font_info);
998         efi_status_t(EFIAPI *set_string)(
999                 const struct efi_hii_string_protocol *this,
1000                 efi_hii_handle_t package_list,
1001                 efi_string_id_t string_id,
1002                 const u8 *language,
1003                 const efi_string_t string,
1004                 const struct efi_font_info *string_font_info);
1005         efi_status_t(EFIAPI *get_languages)(
1006                 const struct efi_hii_string_protocol *this,
1007                 efi_hii_handle_t package_list,
1008                 u8 *languages,
1009                 efi_uintn_t *languages_size);
1010         efi_status_t(EFIAPI *get_secondary_languages)(
1011                 const struct efi_hii_string_protocol *this,
1012                 efi_hii_handle_t package_list,
1013                 const u8 *primary_language,
1014                 u8 *secondary_languages,
1015                 efi_uintn_t *secondary_languages_size);
1016 };
1017
1018 #define EFI_HII_DATABASE_PROTOCOL_GUID       \
1019         EFI_GUID(0xef9fc172, 0xa1b2, 0x4693, \
1020                  0xb3, 0x27, 0x6d, 0x32, 0xfc, 0x41, 0x60, 0x42)
1021
1022 struct efi_hii_database_protocol {
1023         efi_status_t(EFIAPI *new_package_list)(
1024                 const struct efi_hii_database_protocol *this,
1025                 const struct efi_hii_package_list_header *package_list,
1026                 const efi_handle_t driver_handle,
1027                 efi_hii_handle_t *handle);
1028         efi_status_t(EFIAPI *remove_package_list)(
1029                 const struct efi_hii_database_protocol *this,
1030                 efi_hii_handle_t handle);
1031         efi_status_t(EFIAPI *update_package_list)(
1032                 const struct efi_hii_database_protocol *this,
1033                 efi_hii_handle_t handle,
1034                 const struct efi_hii_package_list_header *package_list);
1035         efi_status_t(EFIAPI *list_package_lists)(
1036                 const struct efi_hii_database_protocol *this,
1037                 u8 package_type,
1038                 const efi_guid_t *package_guid,
1039                 efi_uintn_t *handle_buffer_length,
1040                 efi_hii_handle_t *handle);
1041         efi_status_t(EFIAPI *export_package_lists)(
1042                 const struct efi_hii_database_protocol *this,
1043                 efi_hii_handle_t handle,
1044                 efi_uintn_t *buffer_size,
1045                 struct efi_hii_package_list_header *buffer);
1046         efi_status_t(EFIAPI *register_package_notify)(
1047                 const struct efi_hii_database_protocol *this,
1048                 u8 package_type,
1049                 const efi_guid_t *package_guid,
1050                 const void *package_notify_fn,
1051                 efi_uintn_t notify_type,
1052                 efi_handle_t *notify_handle);
1053         efi_status_t(EFIAPI *unregister_package_notify)(
1054                 const struct efi_hii_database_protocol *this,
1055                 efi_handle_t notification_handle
1056                 );
1057         efi_status_t(EFIAPI *find_keyboard_layouts)(
1058                 const struct efi_hii_database_protocol *this,
1059                 u16 *key_guid_buffer_length,
1060                 efi_guid_t *key_guid_buffer);
1061         efi_status_t(EFIAPI *get_keyboard_layout)(
1062                 const struct efi_hii_database_protocol *this,
1063                 efi_guid_t *key_guid,
1064                 u16 *keyboard_layout_length,
1065                 struct efi_hii_keyboard_layout *keyboard_layout);
1066         efi_status_t(EFIAPI *set_keyboard_layout)(
1067                 const struct efi_hii_database_protocol *this,
1068                 efi_guid_t *key_guid);
1069         efi_status_t(EFIAPI *get_package_list_handle)(
1070                 const struct efi_hii_database_protocol *this,
1071                 efi_hii_handle_t package_list_handle,
1072                 efi_handle_t *driver_handle);
1073 };
1074
1075 #define EFI_HII_CONFIG_ROUTING_PROTOCOL_GUID \
1076         EFI_GUID(0x587e72d7, 0xcc50, 0x4f79, \
1077                  0x82, 0x09, 0xca, 0x29, 0x1f, 0xc1, 0xa1, 0x0f)
1078
1079 struct efi_hii_config_routing_protocol {
1080         efi_status_t(EFIAPI *extract_config)(
1081                 const struct efi_hii_config_routing_protocol *this,
1082                 const efi_string_t request,
1083                 efi_string_t *progress,
1084                 efi_string_t *results);
1085         efi_status_t(EFIAPI *export_config)(
1086                 const struct efi_hii_config_routing_protocol *this,
1087                 efi_string_t *results);
1088         efi_status_t(EFIAPI *route_config)(
1089                 const struct efi_hii_config_routing_protocol *this,
1090                 const efi_string_t configuration,
1091                 efi_string_t *progress);
1092         efi_status_t(EFIAPI *block_to_config)(
1093                 const struct efi_hii_config_routing_protocol *this,
1094                 const efi_string_t config_request,
1095                 const uint8_t *block,
1096                 const efi_uintn_t block_size,
1097                 efi_string_t *config,
1098                 efi_string_t *progress);
1099         efi_status_t(EFIAPI *config_to_block)(
1100                 const struct efi_hii_config_routing_protocol *this,
1101                 const efi_string_t config_resp,
1102                 const uint8_t *block,
1103                 const efi_uintn_t *block_size,
1104                 efi_string_t *progress);
1105         efi_status_t(EFIAPI *get_alt_config)(
1106                 const struct efi_hii_config_routing_protocol *this,
1107                 const efi_string_t config_resp,
1108                 const efi_guid_t *guid,
1109                 const efi_string_t name,
1110                 const struct efi_device_path *device_path,
1111                 const efi_string_t alt_cfg_id,
1112                 efi_string_t *alt_cfg_resp);
1113 };
1114
1115 #define EFI_HII_CONFIG_ACCESS_PROTOCOL_GUID \
1116         EFI_GUID(0x330d4706, 0xf2a0, 0x4e4f, \
1117                  0xa3, 0x69, 0xb6, 0x6f, 0xa8, 0xd5, 0x43, 0x85)
1118
1119 struct efi_hii_config_access_protocol {
1120         efi_status_t(EFIAPI *extract_config_access)(
1121                 const struct efi_hii_config_access_protocol *this,
1122                 const efi_string_t request,
1123                 efi_string_t *progress,
1124                 efi_string_t *results);
1125         efi_status_t(EFIAPI *route_config_access)(
1126                 const struct efi_hii_config_access_protocol *this,
1127                 const efi_string_t configuration,
1128                 efi_string_t *progress);
1129         efi_status_t(EFIAPI *form_callback)(
1130                 const struct efi_hii_config_access_protocol *this,
1131                 efi_browser_action_t action,
1132                 efi_question_id_t question_id,
1133                 u8 type,
1134                 union efi_ifr_type_value *value,
1135                 efi_browser_action_request_t *action_request);
1136 };
1137
1138 #define EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID \
1139         EFI_GUID(0x9042a9de, 0x23dc, 0x4a38, \
1140                  0x96, 0xfb, 0x7a, 0xde, 0xd0, 0x80, 0x51, 0x6a)
1141
1142 #define EFI_GOT_RGBA8           0
1143 #define EFI_GOT_BGRA8           1
1144 #define EFI_GOT_BITMASK         2
1145
1146 struct efi_gop_mode_info {
1147         u32 version;
1148         u32 width;
1149         u32 height;
1150         u32 pixel_format;
1151         u32 pixel_bitmask[4];
1152         u32 pixels_per_scanline;
1153 };
1154
1155 struct efi_gop_mode {
1156         u32 max_mode;
1157         u32 mode;
1158         struct efi_gop_mode_info *info;
1159         unsigned long info_size;
1160         efi_physical_addr_t fb_base;
1161         unsigned long fb_size;
1162 };
1163
1164 struct efi_gop_pixel {
1165         u8 blue;
1166         u8 green;
1167         u8 red;
1168         u8 reserved;
1169 };
1170
1171 #define EFI_BLT_VIDEO_FILL              0
1172 #define EFI_BLT_VIDEO_TO_BLT_BUFFER     1
1173 #define EFI_BLT_BUFFER_TO_VIDEO         2
1174 #define EFI_BLT_VIDEO_TO_VIDEO          3
1175
1176 struct efi_gop {
1177         efi_status_t (EFIAPI *query_mode)(struct efi_gop *this, u32 mode_number,
1178                                           efi_uintn_t *size_of_info,
1179                                           struct efi_gop_mode_info **info);
1180         efi_status_t (EFIAPI *set_mode)(struct efi_gop *this, u32 mode_number);
1181         efi_status_t (EFIAPI *blt)(struct efi_gop *this,
1182                                    struct efi_gop_pixel *buffer,
1183                                    u32 operation, efi_uintn_t sx,
1184                                    efi_uintn_t sy, efi_uintn_t dx,
1185                                    efi_uintn_t dy, efi_uintn_t width,
1186                                    efi_uintn_t height, efi_uintn_t delta);
1187         struct efi_gop_mode *mode;
1188 };
1189
1190 #define EFI_SIMPLE_NETWORK_PROTOCOL_GUID \
1191         EFI_GUID(0xa19832b9, 0xac25, 0x11d3, \
1192                  0x9a, 0x2d, 0x00, 0x90, 0x27, 0x3f, 0xc1, 0x4d)
1193
1194 struct efi_mac_address {
1195         char mac_addr[32];
1196 };
1197
1198 struct efi_ip_address {
1199         u8 ip_addr[16];
1200 } __attribute__((aligned(4)));
1201
1202 enum efi_simple_network_state {
1203         EFI_NETWORK_STOPPED,
1204         EFI_NETWORK_STARTED,
1205         EFI_NETWORK_INITIALIZED,
1206 };
1207
1208 struct efi_simple_network_mode {
1209         enum efi_simple_network_state state;
1210         u32 hwaddr_size;
1211         u32 media_header_size;
1212         u32 max_packet_size;
1213         u32 nvram_size;
1214         u32 nvram_access_size;
1215         u32 receive_filter_mask;
1216         u32 receive_filter_setting;
1217         u32 max_mcast_filter_count;
1218         u32 mcast_filter_count;
1219         struct efi_mac_address mcast_filter[16];
1220         struct efi_mac_address current_address;
1221         struct efi_mac_address broadcast_address;
1222         struct efi_mac_address permanent_address;
1223         u8 if_type;
1224         u8 mac_changeable;
1225         u8 multitx_supported;
1226         u8 media_present_supported;
1227         u8 media_present;
1228 };
1229
1230 /* receive_filters bit mask */
1231 #define EFI_SIMPLE_NETWORK_RECEIVE_UNICAST               0x01
1232 #define EFI_SIMPLE_NETWORK_RECEIVE_MULTICAST             0x02
1233 #define EFI_SIMPLE_NETWORK_RECEIVE_BROADCAST             0x04
1234 #define EFI_SIMPLE_NETWORK_RECEIVE_PROMISCUOUS           0x08
1235 #define EFI_SIMPLE_NETWORK_RECEIVE_PROMISCUOUS_MULTICAST 0x10
1236
1237 /* interrupt status bit mask */
1238 #define EFI_SIMPLE_NETWORK_RECEIVE_INTERRUPT    0x01
1239 #define EFI_SIMPLE_NETWORK_TRANSMIT_INTERRUPT   0x02
1240 #define EFI_SIMPLE_NETWORK_COMMAND_INTERRUPT    0x04
1241 #define EFI_SIMPLE_NETWORK_SOFTWARE_INTERRUPT   0x08
1242
1243 /* revision of the simple network protocol */
1244 #define EFI_SIMPLE_NETWORK_PROTOCOL_REVISION    0x00010000
1245
1246 struct efi_simple_network {
1247         u64 revision;
1248         efi_status_t (EFIAPI *start)(struct efi_simple_network *this);
1249         efi_status_t (EFIAPI *stop)(struct efi_simple_network *this);
1250         efi_status_t (EFIAPI *initialize)(struct efi_simple_network *this,
1251                         ulong extra_rx, ulong extra_tx);
1252         efi_status_t (EFIAPI *reset)(struct efi_simple_network *this,
1253                         int extended_verification);
1254         efi_status_t (EFIAPI *shutdown)(struct efi_simple_network *this);
1255         efi_status_t (EFIAPI *receive_filters)(struct efi_simple_network *this,
1256                         u32 enable, u32 disable, int reset_mcast_filter,
1257                         ulong mcast_filter_count,
1258                         struct efi_mac_address *mcast_filter);
1259         efi_status_t (EFIAPI *station_address)(struct efi_simple_network *this,
1260                         int reset, struct efi_mac_address *new_mac);
1261         efi_status_t (EFIAPI *statistics)(struct efi_simple_network *this,
1262                         int reset, ulong *stat_size, void *stat_table);
1263         efi_status_t (EFIAPI *mcastiptomac)(struct efi_simple_network *this,
1264                         int ipv6, struct efi_ip_address *ip,
1265                         struct efi_mac_address *mac);
1266         efi_status_t (EFIAPI *nvdata)(struct efi_simple_network *this,
1267                         int read_write, ulong offset, ulong buffer_size,
1268                         char *buffer);
1269         efi_status_t (EFIAPI *get_status)(struct efi_simple_network *this,
1270                         u32 *int_status, void **txbuf);
1271         efi_status_t (EFIAPI *transmit)(struct efi_simple_network *this,
1272                         size_t header_size, size_t buffer_size, void *buffer,
1273                         struct efi_mac_address *src_addr,
1274                         struct efi_mac_address *dest_addr, u16 *protocol);
1275         efi_status_t (EFIAPI *receive)(struct efi_simple_network *this,
1276                         size_t *header_size, size_t *buffer_size, void *buffer,
1277                         struct efi_mac_address *src_addr,
1278                         struct efi_mac_address *dest_addr, u16 *protocol);
1279         struct efi_event *wait_for_packet;
1280         struct efi_simple_network_mode *mode;
1281 };
1282
1283 #define EFI_PXE_BASE_CODE_PROTOCOL_GUID \
1284         EFI_GUID(0x03c4e603, 0xac28, 0x11d3, \
1285                  0x9a, 0x2d, 0x00, 0x90, 0x27, 0x3f, 0xc1, 0x4d)
1286
1287 struct efi_pxe_packet {
1288         u8 packet[1472];
1289 };
1290
1291 struct efi_pxe_mode {
1292         u8 started;
1293         u8 ipv6_available;
1294         u8 ipv6_supported;
1295         u8 using_ipv6;
1296         u8 bis_supported;
1297         u8 bis_detected;
1298         u8 auto_arp;
1299         u8 send_guid;
1300         u8 dhcp_discover_valid;
1301         u8 dhcp_ack_received;
1302         u8 proxy_offer_received;
1303         u8 pxe_discover_valid;
1304         u8 pxe_reply_received;
1305         u8 pxe_bis_reply_received;
1306         u8 icmp_error_received;
1307         u8 tftp_error_received;
1308         u8 make_callbacks;
1309         u8 ttl;
1310         u8 tos;
1311         u8 pad;
1312         struct efi_ip_address station_ip;
1313         struct efi_ip_address subnet_mask;
1314         struct efi_pxe_packet dhcp_discover;
1315         struct efi_pxe_packet dhcp_ack;
1316         struct efi_pxe_packet proxy_offer;
1317         struct efi_pxe_packet pxe_discover;
1318         struct efi_pxe_packet pxe_reply;
1319 };
1320
1321 struct efi_pxe {
1322         u64 rev;
1323         void (EFIAPI *start)(void);
1324         void (EFIAPI *stop)(void);
1325         void (EFIAPI *dhcp)(void);
1326         void (EFIAPI *discover)(void);
1327         void (EFIAPI *mftp)(void);
1328         void (EFIAPI *udpwrite)(void);
1329         void (EFIAPI *udpread)(void);
1330         void (EFIAPI *setipfilter)(void);
1331         void (EFIAPI *arp)(void);
1332         void (EFIAPI *setparams)(void);
1333         void (EFIAPI *setstationip)(void);
1334         void (EFIAPI *setpackets)(void);
1335         struct efi_pxe_mode *mode;
1336 };
1337
1338 #define EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID \
1339         EFI_GUID(0x964e5b22, 0x6459, 0x11d2, \
1340                  0x8e, 0x39, 0x0, 0xa0, 0xc9, 0x69, 0x72, 0x3b)
1341 #define EFI_FILE_PROTOCOL_REVISION      0x00010000
1342 #define EFI_FILE_PROTOCOL_REVISION2     0x00020000
1343 #define EFI_FILE_PROTOCOL_LATEST_REVISION EFI_FILE_PROTOCOL_REVISION2
1344
1345 struct efi_file_handle {
1346         u64 rev;
1347         efi_status_t (EFIAPI *open)(struct efi_file_handle *file,
1348                         struct efi_file_handle **new_handle,
1349                         u16 *file_name, u64 open_mode, u64 attributes);
1350         efi_status_t (EFIAPI *close)(struct efi_file_handle *file);
1351         efi_status_t (EFIAPI *delete)(struct efi_file_handle *file);
1352         efi_status_t (EFIAPI *read)(struct efi_file_handle *file,
1353                         efi_uintn_t *buffer_size, void *buffer);
1354         efi_status_t (EFIAPI *write)(struct efi_file_handle *file,
1355                         efi_uintn_t *buffer_size, void *buffer);
1356         efi_status_t (EFIAPI *getpos)(struct efi_file_handle *file,
1357                                       u64 *pos);
1358         efi_status_t (EFIAPI *setpos)(struct efi_file_handle *file,
1359                                       u64 pos);
1360         efi_status_t (EFIAPI *getinfo)(struct efi_file_handle *file,
1361                         const efi_guid_t *info_type, efi_uintn_t *buffer_size,
1362                         void *buffer);
1363         efi_status_t (EFIAPI *setinfo)(struct efi_file_handle *file,
1364                         const efi_guid_t *info_type, efi_uintn_t buffer_size,
1365                         void *buffer);
1366         efi_status_t (EFIAPI *flush)(struct efi_file_handle *file);
1367         /*
1368          * TODO: We currently only support EFI file protocol revision 0x00010000
1369          *       while UEFI specs 2.4 - 2.7 prescribe revision 0x00020000.
1370          */
1371 };
1372
1373 #define EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_REVISION 0x00010000
1374
1375 struct efi_simple_file_system_protocol {
1376         u64 rev;
1377         efi_status_t (EFIAPI *open_volume)(struct efi_simple_file_system_protocol *this,
1378                         struct efi_file_handle **root);
1379 };
1380
1381 #define EFI_FILE_INFO_GUID \
1382         EFI_GUID(0x9576e92, 0x6d3f, 0x11d2, \
1383                  0x8e, 0x39, 0x0, 0xa0, 0xc9, 0x69, 0x72, 0x3b)
1384
1385 #define EFI_FILE_SYSTEM_INFO_GUID \
1386         EFI_GUID(0x09576e93, 0x6d3f, 0x11d2, \
1387                  0x8e, 0x39, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b)
1388
1389 #define EFI_FILE_MODE_READ      0x0000000000000001
1390 #define EFI_FILE_MODE_WRITE     0x0000000000000002
1391 #define EFI_FILE_MODE_CREATE    0x8000000000000000
1392
1393 #define EFI_FILE_READ_ONLY      0x0000000000000001
1394 #define EFI_FILE_HIDDEN         0x0000000000000002
1395 #define EFI_FILE_SYSTEM         0x0000000000000004
1396 #define EFI_FILE_RESERVED       0x0000000000000008
1397 #define EFI_FILE_DIRECTORY      0x0000000000000010
1398 #define EFI_FILE_ARCHIVE        0x0000000000000020
1399 #define EFI_FILE_VALID_ATTR     0x0000000000000037
1400
1401 struct efi_file_info {
1402         u64 size;
1403         u64 file_size;
1404         u64 physical_size;
1405         struct efi_time create_time;
1406         struct efi_time last_access_time;
1407         struct efi_time modification_time;
1408         u64 attribute;
1409         u16 file_name[0];
1410 };
1411
1412 struct efi_file_system_info {
1413         u64 size;
1414         u8 read_only;
1415         u64 volume_size;
1416         u64 free_space;
1417         u32 block_size;
1418         u16 volume_label[0];
1419 };
1420
1421 #define EFI_DRIVER_BINDING_PROTOCOL_GUID \
1422         EFI_GUID(0x18a031ab, 0xb443, 0x4d1a,\
1423                  0xa5, 0xc0, 0x0c, 0x09, 0x26, 0x1e, 0x9f, 0x71)
1424 struct efi_driver_binding_protocol {
1425         efi_status_t (EFIAPI * supported)(
1426                         struct efi_driver_binding_protocol *this,
1427                         efi_handle_t controller_handle,
1428                         struct efi_device_path *remaining_device_path);
1429         efi_status_t (EFIAPI * start)(
1430                         struct efi_driver_binding_protocol *this,
1431                         efi_handle_t controller_handle,
1432                         struct efi_device_path *remaining_device_path);
1433         efi_status_t (EFIAPI * stop)(
1434                         struct efi_driver_binding_protocol *this,
1435                         efi_handle_t controller_handle,
1436                         efi_uintn_t number_of_children,
1437                         efi_handle_t *child_handle_buffer);
1438         u32 version;
1439         efi_handle_t image_handle;
1440         efi_handle_t driver_binding_handle;
1441 };
1442
1443 /* Deprecated version of the Unicode collation protocol */
1444 #define EFI_UNICODE_COLLATION_PROTOCOL_GUID \
1445         EFI_GUID(0x1d85cd7f, 0xf43d, 0x11d2, \
1446                  0x9a, 0x0c, 0x00, 0x90, 0x27, 0x3f, 0xc1, 0x4d)
1447 /* Current version of the Unicode collation protocol */
1448 #define EFI_UNICODE_COLLATION_PROTOCOL2_GUID \
1449         EFI_GUID(0xa4c751fc, 0x23ae, 0x4c3e, \
1450                  0x92, 0xe9, 0x49, 0x64, 0xcf, 0x63, 0xf3, 0x49)
1451 struct efi_unicode_collation_protocol {
1452         efi_intn_t (EFIAPI *stri_coll)(
1453                 struct efi_unicode_collation_protocol *this, u16 *s1, u16 *s2);
1454         bool (EFIAPI *metai_match)(struct efi_unicode_collation_protocol *this,
1455                                    const u16 *string, const u16 *patter);
1456         void (EFIAPI *str_lwr)(struct efi_unicode_collation_protocol
1457                                *this, u16 *string);
1458         void (EFIAPI *str_upr)(struct efi_unicode_collation_protocol *this,
1459                                u16 *string);
1460         void (EFIAPI *fat_to_str)(struct efi_unicode_collation_protocol *this,
1461                                   efi_uintn_t fat_size, char *fat, u16 *string);
1462         bool (EFIAPI *str_to_fat)(struct efi_unicode_collation_protocol *this,
1463                                   const u16 *string, efi_uintn_t fat_size,
1464                                   char *fat);
1465         char *supported_languages;
1466 };
1467
1468 /* Boot manager load options */
1469 #define LOAD_OPTION_ACTIVE              0x00000001
1470 #define LOAD_OPTION_FORCE_RECONNECT     0x00000002
1471 #define LOAD_OPTION_HIDDEN              0x00000008
1472 /* All values 0x00000200-0x00001F00 are reserved */
1473 #define LOAD_OPTION_CATEGORY            0x00001F00
1474 #define LOAD_OPTION_CATEGORY_BOOT       0x00000000
1475 #define LOAD_OPTION_CATEGORY_APP        0x00000100
1476
1477 #endif