]> Git Repo - J-u-boot.git/blob - include/efi_api.h
Merge patch series "UART support for higher baudrate"
[J-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 <[email protected]>
9  * Copyright (C) 1999, 2002-2003 Hewlett-Packard Co.
10  *      David Mosberger-Tang <[email protected]>
11  *      Stephane Eranian <[email protected]>
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 #include <pe.h>
22
23 /* UEFI spec version 2.9 */
24 #define EFI_SPECIFICATION_VERSION (2 << 16 | 100)
25
26 /* Types and defines for EFI CreateEvent */
27 enum efi_timer_delay {
28         EFI_TIMER_STOP = 0,
29         EFI_TIMER_PERIODIC = 1,
30         EFI_TIMER_RELATIVE = 2
31 };
32
33 typedef void *efi_hii_handle_t;
34 typedef u16 *efi_string_t;
35 typedef u16 efi_string_id_t;
36 typedef u32 efi_hii_font_style_t;
37 typedef u16 efi_question_id_t;
38 typedef u16 efi_image_id_t;
39 typedef u16 efi_form_id_t;
40
41 #define EVT_TIMER                               0x80000000
42 #define EVT_RUNTIME                             0x40000000
43 #define EVT_NOTIFY_WAIT                         0x00000100
44 #define EVT_NOTIFY_SIGNAL                       0x00000200
45 #define EVT_SIGNAL_EXIT_BOOT_SERVICES           0x00000201
46 #define EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE       0x60000202
47
48 #define TPL_APPLICATION         0x04
49 #define TPL_CALLBACK            0x08
50 #define TPL_NOTIFY              0x10
51 #define TPL_HIGH_LEVEL          0x1F
52
53 struct efi_event;
54
55 /* OsIndicationsSupported flags */
56 #define EFI_OS_INDICATIONS_BOOT_TO_FW_UI                    0x0000000000000001
57 #define EFI_OS_INDICATIONS_TIMESTAMP_REVOCATION             0x0000000000000002
58 #define EFI_OS_INDICATIONS_FILE_CAPSULE_DELIVERY_SUPPORTED  0x0000000000000004
59 #define EFI_OS_INDICATIONS_FMP_CAPSULE_SUPPORTED            0x0000000000000008
60 #define EFI_OS_INDICATIONS_CAPSULE_RESULT_VAR_SUPPORTED     0x0000000000000010
61 #define EFI_OS_INDICATIONS_START_OS_RECOVERY                0x0000000000000020
62 #define EFI_OS_INDICATIONS_START_PLATFORM_RECOVERY          0x0000000000000040
63 #define EFI_OS_INDICATIONS_JSON_CONFIG_DATA_REFRESH         0x0000000000000080
64
65 /* EFI Boot Services table */
66 #define EFI_BOOT_SERVICES_SIGNATURE 0x56524553544f4f42
67 struct efi_boot_services {
68         struct efi_table_hdr hdr;
69         efi_status_t (EFIAPI *raise_tpl)(efi_uintn_t new_tpl);
70         void (EFIAPI *restore_tpl)(efi_uintn_t old_tpl);
71
72         efi_status_t (EFIAPI *allocate_pages)(int, int, efi_uintn_t,
73                                               efi_physical_addr_t *);
74         efi_status_t (EFIAPI *free_pages)(efi_physical_addr_t, efi_uintn_t);
75         efi_status_t (EFIAPI *get_memory_map)(efi_uintn_t *memory_map_size,
76                                               struct efi_mem_desc *desc,
77                                               efi_uintn_t *key,
78                                               efi_uintn_t *desc_size,
79                                               u32 *desc_version);
80         efi_status_t (EFIAPI *allocate_pool)(int, efi_uintn_t, void **);
81         efi_status_t (EFIAPI *free_pool)(void *);
82
83         efi_status_t (EFIAPI *create_event)(uint32_t type,
84                         efi_uintn_t notify_tpl,
85                         void (EFIAPI *notify_function) (
86                                         struct efi_event *event,
87                                         void *context),
88                         void *notify_context, struct efi_event **event);
89         efi_status_t (EFIAPI *set_timer)(struct efi_event *event,
90                                          enum efi_timer_delay type,
91                                          uint64_t trigger_time);
92         efi_status_t (EFIAPI *wait_for_event)(efi_uintn_t number_of_events,
93                                               struct efi_event **event,
94                                               efi_uintn_t *index);
95         efi_status_t (EFIAPI *signal_event)(struct efi_event *event);
96         efi_status_t (EFIAPI *close_event)(struct efi_event *event);
97         efi_status_t (EFIAPI *check_event)(struct efi_event *event);
98 #define EFI_NATIVE_INTERFACE    0x00000000
99         efi_status_t (EFIAPI *install_protocol_interface)(
100                         efi_handle_t *handle, const efi_guid_t *protocol,
101                         int protocol_interface_type, void *protocol_interface);
102         efi_status_t (EFIAPI *reinstall_protocol_interface)(
103                         efi_handle_t handle, const efi_guid_t *protocol,
104                         void *old_interface, void *new_interface);
105         efi_status_t (EFIAPI *uninstall_protocol_interface)(
106                         efi_handle_t handle, const efi_guid_t *protocol,
107                         void *protocol_interface);
108         efi_status_t (EFIAPI *handle_protocol)(
109                         efi_handle_t handle, const efi_guid_t *protocol,
110                         void **protocol_interface);
111         void *reserved;
112         efi_status_t (EFIAPI *register_protocol_notify)(
113                         const efi_guid_t *protocol, struct efi_event *event,
114                         void **registration);
115         efi_status_t (EFIAPI *locate_handle)(
116                         enum efi_locate_search_type search_type,
117                         const efi_guid_t *protocol, void *search_key,
118                         efi_uintn_t *buffer_size, efi_handle_t *buffer);
119         efi_status_t (EFIAPI *locate_device_path)(const efi_guid_t *protocol,
120                         struct efi_device_path **device_path,
121                         efi_handle_t *device);
122         efi_status_t (EFIAPI *install_configuration_table)(
123                         const efi_guid_t *guid, void *table);
124
125         efi_status_t (EFIAPI *load_image)(bool boot_policiy,
126                         efi_handle_t parent_image,
127                         struct efi_device_path *file_path, void *source_buffer,
128                         efi_uintn_t source_size, efi_handle_t *image);
129         efi_status_t (EFIAPI *start_image)(efi_handle_t handle,
130                                            efi_uintn_t *exitdata_size,
131                                            u16 **exitdata);
132         efi_status_t (EFIAPI *exit)(efi_handle_t handle,
133                                     efi_status_t exit_status,
134                                     efi_uintn_t exitdata_size, u16 *exitdata);
135         efi_status_t (EFIAPI *unload_image)(efi_handle_t image_handle);
136         efi_status_t (EFIAPI *exit_boot_services)(efi_handle_t image_handle,
137                                                   efi_uintn_t map_key);
138
139         efi_status_t (EFIAPI *get_next_monotonic_count)(u64 *count);
140         efi_status_t (EFIAPI *stall)(unsigned long usecs);
141         efi_status_t (EFIAPI *set_watchdog_timer)(unsigned long timeout,
142                         uint64_t watchdog_code, unsigned long data_size,
143                         uint16_t *watchdog_data);
144         efi_status_t(EFIAPI *connect_controller)(efi_handle_t controller_handle,
145                         efi_handle_t *driver_image_handle,
146                         struct efi_device_path *remaining_device_path,
147                         bool recursive);
148         efi_status_t (EFIAPI *disconnect_controller)(
149                         efi_handle_t controller_handle,
150                         efi_handle_t driver_image_handle,
151                         efi_handle_t child_handle);
152 #define EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL  0x00000001
153 #define EFI_OPEN_PROTOCOL_GET_PROTOCOL        0x00000002
154 #define EFI_OPEN_PROTOCOL_TEST_PROTOCOL       0x00000004
155 #define EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER 0x00000008
156 #define EFI_OPEN_PROTOCOL_BY_DRIVER           0x00000010
157 #define EFI_OPEN_PROTOCOL_EXCLUSIVE           0x00000020
158         efi_status_t (EFIAPI *open_protocol)(efi_handle_t handle,
159                         const efi_guid_t *protocol, void **interface,
160                         efi_handle_t agent_handle,
161                         efi_handle_t controller_handle, u32 attributes);
162         efi_status_t (EFIAPI *close_protocol)(
163                         efi_handle_t handle, const efi_guid_t *protocol,
164                         efi_handle_t agent_handle,
165                         efi_handle_t controller_handle);
166         efi_status_t(EFIAPI *open_protocol_information)(efi_handle_t handle,
167                         const efi_guid_t *protocol,
168                         struct efi_open_protocol_info_entry **entry_buffer,
169                         efi_uintn_t *entry_count);
170         efi_status_t (EFIAPI *protocols_per_handle)(efi_handle_t handle,
171                         efi_guid_t ***protocol_buffer,
172                         efi_uintn_t *protocols_buffer_count);
173         efi_status_t (EFIAPI *locate_handle_buffer) (
174                         enum efi_locate_search_type search_type,
175                         const efi_guid_t *protocol, void *search_key,
176                         efi_uintn_t *no_handles, efi_handle_t **buffer);
177         efi_status_t (EFIAPI *locate_protocol)(const efi_guid_t *protocol,
178                         void *registration, void **protocol_interface);
179         efi_status_t (EFIAPI *install_multiple_protocol_interfaces)(
180                         efi_handle_t *handle, ...);
181         efi_status_t (EFIAPI *uninstall_multiple_protocol_interfaces)(
182                         efi_handle_t handle, ...);
183         efi_status_t (EFIAPI *calculate_crc32)(const void *data,
184                                                efi_uintn_t data_size,
185                                                u32 *crc32);
186         void (EFIAPI *copy_mem)(void *destination, const void *source,
187                         size_t length);
188         void (EFIAPI *set_mem)(void *buffer, size_t size, uint8_t value);
189         efi_status_t (EFIAPI *create_event_ex)(
190                                 uint32_t type, efi_uintn_t notify_tpl,
191                                 void (EFIAPI *notify_function) (
192                                         struct efi_event *event,
193                                         void *context),
194                                 void *notify_context,
195                                 const efi_guid_t *event_group,
196                                 struct efi_event **event);
197 };
198
199 /* Types and defines for EFI ResetSystem */
200 enum efi_reset_type {
201         EFI_RESET_COLD = 0,
202         EFI_RESET_WARM = 1,
203         EFI_RESET_SHUTDOWN = 2,
204         EFI_RESET_PLATFORM_SPECIFIC = 3,
205 };
206
207 /* EFI Runtime Services table */
208 #define EFI_RUNTIME_SERVICES_SIGNATURE  0x56524553544e5552ULL
209
210 #define CAPSULE_FLAGS_PERSIST_ACROSS_RESET      0x00010000
211 #define CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE     0x00020000
212 #define CAPSULE_FLAGS_INITIATE_RESET            0x00040000
213
214 #define CAPSULE_SUPPORT_AUTHENTICATION          0x0000000000000001
215 #define CAPSULE_SUPPORT_DEPENDENCY              0x0000000000000002
216
217 #define EFI_CAPSULE_REPORT_GUID \
218         EFI_GUID(0x39b68c46, 0xf7fb, 0x441b, 0xb6, 0xec, \
219                  0x16, 0xb0, 0xf6, 0x98, 0x21, 0xf3)
220
221 #define EFI_MEMORY_RANGE_CAPSULE_GUID \
222         EFI_GUID(0xde9f0ec, 0x88b6, 0x428f, 0x97, 0x7a, \
223                  0x25, 0x8f, 0x1d, 0xe, 0x5e, 0x72)
224
225 #define EFI_FIRMWARE_MANAGEMENT_CAPSULE_ID_GUID \
226         EFI_GUID(0x6dcbd5ed, 0xe82d, 0x4c44, 0xbd, 0xa1, \
227                  0x71, 0x94, 0x19, 0x9a, 0xd9, 0x2a)
228
229 #define EFI_CONFORMANCE_PROFILES_TABLE_GUID \
230         EFI_GUID(0x36122546, 0xf7ef, 0x4c8f, 0xbd, 0x9b, \
231                  0xeb, 0x85, 0x25, 0xb5, 0x0c, 0x0b)
232
233 #define EFI_CONFORMANCE_PROFILES_TABLE_VERSION 1
234
235 #define EFI_CONFORMANCE_PROFILE_EBBR_2_1_GUID \
236         EFI_GUID(0xcce33c35, 0x74ac, 0x4087, 0xbc, 0xe7, \
237                  0x8b, 0x29, 0xb0, 0x2e, 0xeb, 0x27)
238
239 struct efi_conformance_profiles_table {
240         u16 version;
241         u16 number_of_profiles;
242         efi_guid_t      conformance_profiles[];
243 } __packed;
244
245 struct efi_capsule_header {
246         efi_guid_t capsule_guid;
247         u32 header_size;
248         u32 flags;
249         u32 capsule_image_size;
250 } __packed;
251
252 struct efi_capsule_result_variable_header {
253         u32 variable_total_size;
254         u32 reserved;
255         efi_guid_t capsule_guid;
256         struct efi_time capsule_processed;
257         efi_status_t capsule_status;
258 } __packed;
259
260 struct efi_memory_range {
261         efi_physical_addr_t     address;
262         u64                     length;
263 };
264
265 struct efi_memory_range_capsule {
266         struct efi_capsule_header *header;
267         /* EFI_MEMORY_TYPE: 0x80000000-0xFFFFFFFF */
268         enum efi_memory_type os_requested_memory_type;
269         u64 number_of_memory_ranges;
270         struct efi_memory_range memory_ranges[];
271 } __packed;
272
273 struct efi_firmware_management_capsule_header {
274         u32 version;
275         u16 embedded_driver_count;
276         u16 payload_item_count;
277         u64 item_offset_list[];
278 } __packed;
279
280 struct efi_firmware_management_capsule_image_header {
281         u32 version;
282         efi_guid_t update_image_type_id;
283         u8 update_image_index;
284         u8 reserved[3];
285         u32 update_image_size;
286         u32 update_vendor_code_size;
287         u64 update_hardware_instance;
288         u64 image_capsule_support;
289 } __packed;
290
291 struct efi_capsule_result_variable_fmp {
292         u16 version;
293         u8 payload_index;
294         u8 update_image_index;
295         efi_guid_t update_image_type_id;
296         // u16 capsule_file_name[];
297         // u16 capsule_target[];
298 } __packed;
299
300 #define EFI_RT_SUPPORTED_GET_TIME                       0x0001
301 #define EFI_RT_SUPPORTED_SET_TIME                       0x0002
302 #define EFI_RT_SUPPORTED_GET_WAKEUP_TIME                0x0004
303 #define EFI_RT_SUPPORTED_SET_WAKEUP_TIME                0x0008
304 #define EFI_RT_SUPPORTED_GET_VARIABLE                   0x0010
305 #define EFI_RT_SUPPORTED_GET_NEXT_VARIABLE_NAME         0x0020
306 #define EFI_RT_SUPPORTED_SET_VARIABLE                   0x0040
307 #define EFI_RT_SUPPORTED_SET_VIRTUAL_ADDRESS_MAP        0x0080
308 #define EFI_RT_SUPPORTED_CONVERT_POINTER                0x0100
309 #define EFI_RT_SUPPORTED_GET_NEXT_HIGH_MONOTONIC_COUNT  0x0200
310 #define EFI_RT_SUPPORTED_RESET_SYSTEM                   0x0400
311 #define EFI_RT_SUPPORTED_UPDATE_CAPSULE                 0x0800
312 #define EFI_RT_SUPPORTED_QUERY_CAPSULE_CAPABILITIES     0x1000
313 #define EFI_RT_SUPPORTED_QUERY_VARIABLE_INFO            0x2000
314
315 #define EFI_RT_PROPERTIES_TABLE_GUID \
316         EFI_GUID(0xeb66918a, 0x7eef, 0x402a, 0x84, 0x2e, \
317                  0x93, 0x1d, 0x21, 0xc3, 0x8a, 0xe9)
318
319 #define EFI_RT_PROPERTIES_TABLE_VERSION 0x1
320
321 struct efi_rt_properties_table {
322         u16 version;
323         u16 length;
324         u32 runtime_services_supported;
325 };
326
327 #define EFI_OPTIONAL_PTR        0x00000001
328
329 struct efi_runtime_services {
330         struct efi_table_hdr hdr;
331         efi_status_t (EFIAPI *get_time)(struct efi_time *time,
332                         struct efi_time_cap *capabilities);
333         efi_status_t (EFIAPI *set_time)(struct efi_time *time);
334         efi_status_t (EFIAPI *get_wakeup_time)(char *enabled, char *pending,
335                         struct efi_time *time);
336         efi_status_t (EFIAPI *set_wakeup_time)(char enabled,
337                         struct efi_time *time);
338         efi_status_t (EFIAPI *set_virtual_address_map)(
339                         efi_uintn_t memory_map_size,
340                         efi_uintn_t descriptor_size,
341                         uint32_t descriptor_version,
342                         struct efi_mem_desc *virtmap);
343         efi_status_t (EFIAPI *convert_pointer)(
344                         efi_uintn_t debug_disposition, void **address);
345         efi_status_t (EFIAPI *get_variable)(u16 *variable_name,
346                                             const efi_guid_t *vendor,
347                                             u32 *attributes,
348                                             efi_uintn_t *data_size, void *data);
349         efi_status_t (EFIAPI *get_next_variable_name)(
350                         efi_uintn_t *variable_name_size,
351                         u16 *variable_name, efi_guid_t *vendor);
352         efi_status_t (EFIAPI *set_variable)(u16 *variable_name,
353                                             const efi_guid_t *vendor,
354                                             u32 attributes,
355                                             efi_uintn_t data_size,
356                                             const void *data);
357         efi_status_t (EFIAPI *get_next_high_mono_count)(
358                         uint32_t *high_count);
359         void (EFIAPI *reset_system)(enum efi_reset_type reset_type,
360                                     efi_status_t reset_status,
361                                     unsigned long data_size, void *reset_data);
362         efi_status_t (EFIAPI *update_capsule)(
363                         struct efi_capsule_header **capsule_header_array,
364                         efi_uintn_t capsule_count,
365                         u64 scatter_gather_list);
366         efi_status_t (EFIAPI *query_capsule_caps)(
367                         struct efi_capsule_header **capsule_header_array,
368                         efi_uintn_t capsule_count,
369                         u64 *maximum_capsule_size,
370                         u32 *reset_type);
371         efi_status_t (EFIAPI *query_variable_info)(
372                         u32 attributes,
373                         u64 *maximum_variable_storage_size,
374                         u64 *remaining_variable_storage_size,
375                         u64 *maximum_variable_size);
376 };
377
378 /* EFI event group GUID definitions */
379
380 #define EFI_EVENT_GROUP_EXIT_BOOT_SERVICES \
381         EFI_GUID(0x27abf055, 0xb1b8, 0x4c26, 0x80, 0x48, \
382                  0x74, 0x8f, 0x37, 0xba, 0xa2, 0xdf)
383
384 #define EFI_EVENT_GROUP_BEFORE_EXIT_BOOT_SERVICES \
385         EFI_GUID(0x8be0e274, 0x3970, 0x4b44, 0x80, 0xc5, \
386                  0x1a, 0xb9, 0x50, 0x2f, 0x3b, 0xfc)
387
388 #define EFI_EVENT_GROUP_VIRTUAL_ADDRESS_CHANGE \
389         EFI_GUID(0x13fa7698, 0xc831, 0x49c7, 0x87, 0xea, \
390                  0x8f, 0x43, 0xfc, 0xc2, 0x51, 0x96)
391
392 #define EFI_EVENT_GROUP_MEMORY_MAP_CHANGE \
393         EFI_GUID(0x78bee926, 0x692f, 0x48fd, 0x9e, 0xdb, \
394                  0x01, 0x42, 0x2e, 0xf0, 0xd7, 0xab)
395
396 #define EFI_EVENT_GROUP_READY_TO_BOOT \
397         EFI_GUID(0x7ce88fb3, 0x4bd7, 0x4679, 0x87, 0xa8, \
398                  0xa8, 0xd8, 0xde, 0xe5, 0x0d, 0x2b)
399
400 #define EFI_EVENT_GROUP_AFTER_READY_TO_BOOT \
401         EFI_GUID(0x3a2a00ad, 0x98b9, 0x4cdf, 0xa4, 0x78, \
402                  0x70, 0x27, 0x77, 0xf1, 0xc1, 0xb)
403
404 #define EFI_EVENT_GROUP_RESET_SYSTEM \
405         EFI_GUID(0x62da6a56, 0x13fb, 0x485a, 0xa8, 0xda, \
406                  0xa3, 0xdd, 0x79, 0x12, 0xcb, 0x6b)
407 #define EFI_EVENT_GROUP_RETURN_TO_EFIBOOTMGR \
408         EFI_GUID(0xb4a40fe6, 0x9149, 0x4f29, 0x94, 0x47, \
409                  0x49, 0x38, 0x7a, 0x7f, 0xab, 0x87)
410
411 /* EFI Configuration Table and GUID definitions */
412 #define NULL_GUID \
413         EFI_GUID(0x00000000, 0x0000, 0x0000, 0x00, 0x00, \
414                  0x00, 0x00, 0x00, 0x00, 0x00, 0x00)
415
416 #define EFI_GLOBAL_VARIABLE_GUID \
417         EFI_GUID(0x8be4df61, 0x93ca, 0x11d2, 0xaa, 0x0d, \
418                  0x00, 0xe0, 0x98, 0x03, 0x2b, 0x8c)
419
420 #define EFI_IMAGE_SECURITY_DATABASE_GUID \
421         EFI_GUID(0xd719b2cb, 0x3d3a, 0x4596, 0xa3, 0xbc, \
422                  0xda, 0xd0, 0x0e, 0x67, 0x65, 0x6f)
423
424 #define EFI_FDT_GUID \
425         EFI_GUID(0xb1b621d5, 0xf19c, 0x41a5, \
426                  0x83, 0x0b, 0xd9, 0x15, 0x2c, 0x69, 0xaa, 0xe0)
427
428 #define EFI_ACPI_TABLE_GUID \
429         EFI_GUID(0x8868e871, 0xe4f1, 0x11d3, \
430                  0xbc, 0x22, 0x00, 0x80, 0xc7, 0x3c, 0x88, 0x81)
431
432 #define SMBIOS_TABLE_GUID \
433         EFI_GUID(0xeb9d2d31, 0x2d88, 0x11d3,  \
434                  0x9a, 0x16, 0x00, 0x90, 0x27, 0x3f, 0xc1, 0x4d)
435
436 #define SMBIOS3_TABLE_GUID \
437         EFI_GUID(0xf2fd1544, 0x9794, 0x4a2c, \
438                  0x99, 0x2e, 0xe5, 0xbb, 0xcf, 0x20, 0xe3, 0x94)
439
440 #define EFI_LOAD_FILE_PROTOCOL_GUID \
441         EFI_GUID(0x56ec3091, 0x954c, 0x11d2, \
442                  0x8e, 0x3f, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b)
443
444 #define EFI_LOAD_FILE2_PROTOCOL_GUID \
445         EFI_GUID(0x4006c0c1, 0xfcb3, 0x403e, \
446                  0x99, 0x6d, 0x4a, 0x6c, 0x87, 0x24, 0xe0, 0x6d)
447
448 #define EFI_TCG2_FINAL_EVENTS_TABLE_GUID \
449         EFI_GUID(0x1e2ed096, 0x30e2, 0x4254, 0xbd, \
450                  0x89, 0x86, 0x3b, 0xbe, 0xf8, 0x23, 0x25)
451
452 #define EFI_RNG_PROTOCOL_GUID \
453         EFI_GUID(0x3152bca5, 0xeade, 0x433d, 0x86, 0x2e, \
454                  0xc0, 0x1c, 0xdc, 0x29, 0x1f, 0x44)
455
456 #define EFI_DT_FIXUP_PROTOCOL_GUID \
457         EFI_GUID(0xe617d64c, 0xfe08, 0x46da, 0xf4, 0xdc, \
458                  0xbb, 0xd5, 0x87, 0x0c, 0x73, 0x00)
459
460 #define EFI_TCG2_PROTOCOL_GUID \
461         EFI_GUID(0x607f766c, 0x7455, 0x42be, 0x93, \
462                  0x0b, 0xe4, 0xd7, 0x6d, 0xb2, 0x72, 0x0f)
463
464 #define RISCV_EFI_BOOT_PROTOCOL_GUID \
465         EFI_GUID(0xccd15fec, 0x6f73, 0x4eec, 0x83, \
466                  0x95, 0x3e, 0x69, 0xe4, 0xb9, 0x40, 0xbf)
467
468 /**
469  * struct efi_configuration_table - EFI Configuration Table
470  *
471  * This table contains a set of GUID/pointer pairs.
472  * The EFI Configuration Table may contain at most one instance of each table type.
473  *
474  * @guid:               GUID that uniquely identifies the system configuration table
475  * @table:              A pointer to the table associated with guid
476  */
477 struct efi_configuration_table {
478         efi_guid_t guid;
479         void *table;
480 } __packed;
481
482 #define EFI_SYSTEM_TABLE_SIGNATURE ((u64)0x5453595320494249ULL)
483
484 /**
485  * struct efi_system_table - EFI System Table
486  *
487  * EFI System Table contains pointers to the runtime and boot services tables.
488  *
489  * @hdr:                The table header for the EFI System Table
490  * @fw_vendor:          A pointer to a null terminated string that identifies the vendor
491  *                      that produces the system firmware
492  * @fw_revision:        The revision of the system firmware
493  * @con_in_handle:      The handle for the active console input device
494  * @con_in:             A pointer to the EFI_SIMPLE_TEXT_INPUT_PROTOCOL interface
495  *                      that is associated with con_in_handle
496  * @con_out_handle:     The handle for the active console output device
497  * @con_out:            A pointer to the EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL interface
498  *                      that is associated with con_out_handle
499  * @stderr_handle:      The handle for the active standard error console device
500  * @std_err:            A pointer to the EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL interface
501  *                      that is associated with stderr_handle
502  * @runtime:            A pointer to the EFI Runtime Services Table
503  * @boottime:           A pointer to the EFI Boot Services Table
504  * @nr_tables:          The number of system configuration tables
505  * @tables:             A pointer to the system configuration tables
506  */
507 struct efi_system_table {
508         struct efi_table_hdr hdr;
509         u16 *fw_vendor;   /* physical addr of wchar_t vendor string */
510         u32 fw_revision;
511         efi_handle_t con_in_handle;
512         struct efi_simple_text_input_protocol *con_in;
513         efi_handle_t con_out_handle;
514         struct efi_simple_text_output_protocol *con_out;
515         efi_handle_t stderr_handle;
516         struct efi_simple_text_output_protocol *std_err;
517         struct efi_runtime_services *runtime;
518         struct efi_boot_services *boottime;
519         efi_uintn_t nr_tables;
520         struct efi_configuration_table *tables;
521 };
522
523 /**
524  * efi_main() - entry point of EFI applications
525  *
526  * @image_handle:       handle with the Loaded Image Protocol
527  * @systab:             pointer to the system table
528  * Return:              status code
529  */
530 efi_status_t EFIAPI efi_main(efi_handle_t image_handle,
531                              struct efi_system_table *systab);
532
533 #define EFI_LOADED_IMAGE_PROTOCOL_GUID \
534         EFI_GUID(0x5b1b31a1, 0x9562, 0x11d2, \
535                  0x8e, 0x3f, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b)
536
537 #define EFI_LOADED_IMAGE_DEVICE_PATH_PROTOCOL_GUID \
538         EFI_GUID(0xbc62157e, 0x3e33, 0x4fec, \
539                  0x99, 0x20, 0x2d, 0x3b, 0x36, 0xd7, 0x50, 0xdf)
540
541 #define EFI_LOADED_IMAGE_PROTOCOL_REVISION 0x1000
542
543 struct efi_loaded_image {
544         u32 revision;
545         void *parent_handle;
546         struct efi_system_table *system_table;
547         efi_handle_t device_handle;
548         struct efi_device_path *file_path;
549         void *reserved;
550         u32 load_options_size;
551         void *load_options;
552         void *image_base;
553         aligned_u64 image_size;
554         unsigned int image_code_type;
555         unsigned int image_data_type;
556         efi_status_t (EFIAPI *unload)(efi_handle_t image_handle);
557 };
558
559 #define EFI_DEVICE_PATH_PROTOCOL_GUID \
560         EFI_GUID(0x09576e91, 0x6d3f, 0x11d2, \
561                  0x8e, 0x39, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b)
562
563 #define DEVICE_PATH_TYPE_END                    0x7f
564 #  define DEVICE_PATH_SUB_TYPE_INSTANCE_END     0x01
565 #  define DEVICE_PATH_SUB_TYPE_END              0xff
566
567 struct efi_mac_addr {
568         u8 addr[32];
569 } __packed;
570
571 #define DEVICE_PATH_TYPE_HARDWARE_DEVICE        0x01
572 #  define DEVICE_PATH_SUB_TYPE_MEMORY           0x03
573 #  define DEVICE_PATH_SUB_TYPE_VENDOR           0x04
574 #  define DEVICE_PATH_SUB_TYPE_CONTROLLER       0x05
575
576 struct efi_device_path_memory {
577         struct efi_device_path dp;
578         u32 memory_type;
579         u64 start_address;
580         u64 end_address;
581 } __packed;
582
583 struct efi_device_path_vendor {
584         struct efi_device_path dp;
585         efi_guid_t guid;
586         u8 vendor_data[];
587 } __packed;
588
589 struct efi_device_path_udevice {
590         struct efi_device_path dp;
591         efi_guid_t guid;
592         int uclass_id;
593         int dev_number;
594 } __packed;
595
596 struct efi_device_path_controller {
597         struct efi_device_path dp;
598         u32 controller_number;
599 } __packed;
600
601 #define DEVICE_PATH_TYPE_ACPI_DEVICE            0x02
602 #  define DEVICE_PATH_SUB_TYPE_ACPI_DEVICE      0x01
603
604 #define EFI_PNP_ID(ID)                          (u32)(((ID) << 16) | 0x41D0)
605 #define EISA_PNP_ID(ID)                         EFI_PNP_ID(ID)
606 #define EISA_PNP_NUM(ID)                        ((ID) >> 16)
607
608 struct efi_device_path_acpi_path {
609         struct efi_device_path dp;
610         u32 hid;
611         u32 uid;
612 } __packed;
613
614 #define DEVICE_PATH_TYPE_MESSAGING_DEVICE       0x03
615 #  define DEVICE_PATH_SUB_TYPE_MSG_ATAPI        0x01
616 #  define DEVICE_PATH_SUB_TYPE_MSG_SCSI         0x02
617 #  define DEVICE_PATH_SUB_TYPE_MSG_USB          0x05
618 #  define DEVICE_PATH_SUB_TYPE_MSG_MAC_ADDR     0x0b
619 #  define DEVICE_PATH_SUB_TYPE_MSG_IPV4         0x0c
620 #  define DEVICE_PATH_SUB_TYPE_MSG_UART         0x0e
621 #  define DEVICE_PATH_SUB_TYPE_MSG_USB_CLASS    0x0f
622 #  define DEVICE_PATH_SUB_TYPE_MSG_USB_WWI      0x10
623 #  define DEVICE_PATH_SUB_TYPE_MSG_SATA         0x12
624 #  define DEVICE_PATH_SUB_TYPE_MSG_NVME         0x17
625 #  define DEVICE_PATH_SUB_TYPE_MSG_URI          0x18
626 #  define DEVICE_PATH_SUB_TYPE_MSG_SD           0x1a
627 #  define DEVICE_PATH_SUB_TYPE_MSG_MMC          0x1d
628
629 struct efi_device_path_atapi {
630         struct efi_device_path dp;
631         u8 primary_secondary;
632         u8 slave_master;
633         u16 logical_unit_number;
634 } __packed;
635
636 struct efi_device_path_scsi {
637         struct efi_device_path dp;
638         u16 target_id;
639         u16 logical_unit_number;
640 } __packed;
641
642 struct efi_device_path_uart {
643         struct efi_device_path dp;
644         u32 reserved;
645         u64 baud_rate;
646         u8 data_bits;
647         u8 parity;
648         u8 stop_bits;
649 } __packed;
650
651 struct efi_device_path_usb {
652         struct efi_device_path dp;
653         u8 parent_port_number;
654         u8 usb_interface;
655 } __packed;
656
657 struct efi_device_path_sata {
658         struct efi_device_path dp;
659         u16 hba_port;
660         u16 port_multiplier_port;
661         u16 logical_unit_number;
662 } __packed;
663
664 struct efi_device_path_mac_addr {
665         struct efi_device_path dp;
666         struct efi_mac_addr mac;
667         u8 if_type;
668 } __packed;
669
670 struct efi_device_path_usb_class {
671         struct efi_device_path dp;
672         u16 vendor_id;
673         u16 product_id;
674         u8 device_class;
675         u8 device_subclass;
676         u8 device_protocol;
677 } __packed;
678
679 struct efi_device_path_sd_mmc_path {
680         struct efi_device_path dp;
681         u8 slot_number;
682 } __packed;
683
684 struct efi_device_path_nvme {
685         struct efi_device_path dp;
686         u32 ns_id;
687         u8 eui64[8];
688 } __packed;
689
690 struct efi_device_path_uri {
691         struct efi_device_path dp;
692         u8 uri[];
693 } __packed;
694
695 struct efi_ipv4_address {
696         u8 ip_addr[4];
697 };
698
699 struct efi_device_path_ipv4 {
700         struct efi_device_path dp;
701         struct efi_ipv4_address local_ip_address;
702         struct efi_ipv4_address remote_ip_address;
703         u16 local_port;
704         u16 remote_port;
705         u16 protocol;
706         u8 static_ip_address;
707         struct efi_ipv4_address gateway_ip_address;
708         struct efi_ipv4_address subnet_mask;
709 } __packed;
710
711 #define DEVICE_PATH_TYPE_MEDIA_DEVICE           0x04
712 #  define DEVICE_PATH_SUB_TYPE_HARD_DRIVE_PATH  0x01
713 #  define DEVICE_PATH_SUB_TYPE_CDROM_PATH       0x02
714 #  define DEVICE_PATH_SUB_TYPE_VENDOR_PATH      0x03
715 #  define DEVICE_PATH_SUB_TYPE_FILE_PATH        0x04
716
717 struct efi_device_path_hard_drive_path {
718         struct efi_device_path dp;
719         u32 partition_number;
720         u64 partition_start;
721         u64 partition_end;
722         u8 partition_signature[16];
723         u8 partmap_type;
724         u8 signature_type;
725 } __packed;
726
727 struct efi_device_path_cdrom_path {
728         struct efi_device_path dp;
729         u32 boot_entry;
730         u64 partition_start;
731         u64 partition_size;
732 } __packed;
733
734 struct efi_device_path_file_path {
735         struct efi_device_path dp;
736         u16 str[];
737 } __packed;
738
739 #define EFI_BLOCK_IO_PROTOCOL_GUID \
740         EFI_GUID(0x964e5b21, 0x6459, 0x11d2, \
741                  0x8e, 0x39, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b)
742
743 struct efi_block_io_media {
744         u32 media_id;
745         char removable_media;
746         char media_present;
747         char logical_partition;
748         char read_only;
749         char write_caching;
750         u8 pad[3];
751         u32 block_size;
752         u32 io_align;
753         u8 pad2[4];
754         u64 last_block;
755         /* Added in revision 2 of the protocol */
756         u64 lowest_aligned_lba;
757         u32 logical_blocks_per_physical_block;
758         /* Added in revision 3 of the protocol */
759         u32 optimal_transfer_length_granualarity;
760 };
761
762 #define EFI_BLOCK_IO_PROTOCOL_REVISION2 0x00020001
763 #define EFI_BLOCK_IO_PROTOCOL_REVISION3 0x0002001f
764
765 struct efi_block_io {
766         u64 revision;
767         struct efi_block_io_media *media;
768         efi_status_t (EFIAPI *reset)(struct efi_block_io *this,
769                         char extended_verification);
770         efi_status_t (EFIAPI *read_blocks)(struct efi_block_io *this,
771                         u32 media_id, u64 lba, efi_uintn_t buffer_size,
772                         void *buffer);
773         efi_status_t (EFIAPI *write_blocks)(struct efi_block_io *this,
774                         u32 media_id, u64 lba, efi_uintn_t buffer_size,
775                         void *buffer);
776         efi_status_t (EFIAPI *flush_blocks)(struct efi_block_io *this);
777 };
778
779 struct simple_text_output_mode {
780         s32 max_mode;
781         s32 mode;
782         s32 attribute;
783         s32 cursor_column;
784         s32 cursor_row;
785         bool cursor_visible;
786 };
787
788 #define EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL_GUID \
789         EFI_GUID(0x387477c2, 0x69c7, 0x11d2, \
790                  0x8e, 0x39, 0x0, 0xa0, 0xc9, 0x69, 0x72, 0x3b)
791
792 #define EFI_BLACK                0x00
793 #define EFI_BLUE                 0x01
794 #define EFI_GREEN                0x02
795 #define EFI_CYAN                 0x03
796 #define EFI_RED                  0x04
797 #define EFI_MAGENTA              0x05
798 #define EFI_BROWN                0x06
799 #define EFI_LIGHTGRAY            0x07
800 #define EFI_BRIGHT               0x08
801 #define EFI_DARKGRAY             0x08
802 #define EFI_LIGHTBLUE            0x09
803 #define EFI_LIGHTGREEN           0x0a
804 #define EFI_LIGHTCYAN            0x0b
805 #define EFI_LIGHTRED             0x0c
806 #define EFI_LIGHTMAGENTA         0x0d
807 #define EFI_YELLOW               0x0e
808 #define EFI_WHITE                0x0f
809 #define EFI_BACKGROUND_BLACK     0x00
810 #define EFI_BACKGROUND_BLUE      0x10
811 #define EFI_BACKGROUND_GREEN     0x20
812 #define EFI_BACKGROUND_CYAN      0x30
813 #define EFI_BACKGROUND_RED       0x40
814 #define EFI_BACKGROUND_MAGENTA   0x50
815 #define EFI_BACKGROUND_BROWN     0x60
816 #define EFI_BACKGROUND_LIGHTGRAY 0x70
817
818 /* extract foreground color from EFI attribute */
819 #define EFI_ATTR_FG(attr)        ((attr) & 0x07)
820 /* treat high bit of FG as bright/bold (similar to edk2) */
821 #define EFI_ATTR_BOLD(attr)      (((attr) >> 3) & 0x01)
822 /* extract background color from EFI attribute */
823 #define EFI_ATTR_BG(attr)        (((attr) >> 4) & 0x7)
824
825 struct efi_simple_text_output_protocol {
826         efi_status_t (EFIAPI *reset)(
827                         struct efi_simple_text_output_protocol *this,
828                         char extended_verification);
829         efi_status_t (EFIAPI *output_string)(
830                         struct efi_simple_text_output_protocol *this,
831                         const u16 *str);
832         efi_status_t (EFIAPI *test_string)(
833                         struct efi_simple_text_output_protocol *this,
834                         const u16 *str);
835         efi_status_t(EFIAPI *query_mode)(
836                         struct efi_simple_text_output_protocol *this,
837                         unsigned long mode_number, unsigned long *columns,
838                         unsigned long *rows);
839         efi_status_t(EFIAPI *set_mode)(
840                         struct efi_simple_text_output_protocol *this,
841                         unsigned long mode_number);
842         efi_status_t(EFIAPI *set_attribute)(
843                         struct efi_simple_text_output_protocol *this,
844                         unsigned long attribute);
845         efi_status_t(EFIAPI *clear_screen) (
846                         struct efi_simple_text_output_protocol *this);
847         efi_status_t(EFIAPI *set_cursor_position) (
848                         struct efi_simple_text_output_protocol *this,
849                         unsigned long column, unsigned long row);
850         efi_status_t(EFIAPI *enable_cursor)(
851                         struct efi_simple_text_output_protocol *this,
852                         bool enable);
853         struct simple_text_output_mode *mode;
854 };
855
856 #define EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL_GUID \
857         EFI_GUID(0xdd9e7534, 0x7762, 0x4698, \
858                  0x8c, 0x14, 0xf5, 0x85, 0x17, 0xa6, 0x25, 0xaa)
859
860 struct efi_input_key {
861         u16 scan_code;
862         u16 unicode_char;
863 };
864
865 #define EFI_SHIFT_STATE_INVALID         0x00000000
866 #define EFI_RIGHT_SHIFT_PRESSED         0x00000001
867 #define EFI_LEFT_SHIFT_PRESSED          0x00000002
868 #define EFI_RIGHT_CONTROL_PRESSED       0x00000004
869 #define EFI_LEFT_CONTROL_PRESSED        0x00000008
870 #define EFI_RIGHT_ALT_PRESSED           0x00000010
871 #define EFI_LEFT_ALT_PRESSED            0x00000020
872 #define EFI_RIGHT_LOGO_PRESSED          0x00000040
873 #define EFI_LEFT_LOGO_PRESSED           0x00000080
874 #define EFI_MENU_KEY_PRESSED            0x00000100
875 #define EFI_SYS_REQ_PRESSED             0x00000200
876 #define EFI_SHIFT_STATE_VALID           0x80000000
877
878 #define EFI_TOGGLE_STATE_INVALID        0x00
879 #define EFI_SCROLL_LOCK_ACTIVE          0x01
880 #define EFI_NUM_LOCK_ACTIVE             0x02
881 #define EFI_CAPS_LOCK_ACTIVE            0x04
882 #define EFI_KEY_STATE_EXPOSED           0x40
883 #define EFI_TOGGLE_STATE_VALID          0x80
884
885 struct efi_key_state {
886         u32 key_shift_state;
887         u8 key_toggle_state;
888 };
889
890 struct efi_key_data {
891         struct efi_input_key key;
892         struct efi_key_state key_state;
893 };
894
895 struct efi_simple_text_input_ex_protocol {
896         efi_status_t (EFIAPI *reset) (
897                 struct efi_simple_text_input_ex_protocol *this,
898                 bool extended_verification);
899         efi_status_t (EFIAPI *read_key_stroke_ex) (
900                 struct efi_simple_text_input_ex_protocol *this,
901                 struct efi_key_data *key_data);
902         struct efi_event *wait_for_key_ex;
903         efi_status_t (EFIAPI *set_state) (
904                 struct efi_simple_text_input_ex_protocol *this,
905                 u8 *key_toggle_state);
906         efi_status_t (EFIAPI *register_key_notify) (
907                 struct efi_simple_text_input_ex_protocol *this,
908                 struct efi_key_data *key_data,
909                 efi_status_t (EFIAPI *key_notify_function)(
910                         struct efi_key_data *key_data),
911                 void **notify_handle);
912         efi_status_t (EFIAPI *unregister_key_notify) (
913                 struct efi_simple_text_input_ex_protocol *this,
914                 void *notification_handle);
915 };
916
917 #define EFI_SIMPLE_TEXT_INPUT_PROTOCOL_GUID \
918         EFI_GUID(0x387477c1, 0x69c7, 0x11d2, \
919                  0x8e, 0x39, 0x0, 0xa0, 0xc9, 0x69, 0x72, 0x3b)
920
921 struct efi_simple_text_input_protocol {
922         efi_status_t(EFIAPI *reset)(struct efi_simple_text_input_protocol *this,
923                                     bool extended_verification);
924         efi_status_t(EFIAPI *read_key_stroke)(
925                         struct efi_simple_text_input_protocol *this,
926                         struct efi_input_key *key);
927         struct efi_event *wait_for_key;
928 };
929
930 #define EFI_DEVICE_PATH_TO_TEXT_PROTOCOL_GUID \
931         EFI_GUID(0x8b843e20, 0x8132, 0x4852, \
932                  0x90, 0xcc, 0x55, 0x1a, 0x4e, 0x4a, 0x7f, 0x1c)
933
934 struct efi_device_path_to_text_protocol {
935         uint16_t *(EFIAPI *convert_device_node_to_text)(
936                         struct efi_device_path *device_node,
937                         bool display_only,
938                         bool allow_shortcuts);
939         uint16_t *(EFIAPI *convert_device_path_to_text)(
940                         struct efi_device_path *device_path,
941                         bool display_only,
942                         bool allow_shortcuts);
943 };
944
945 #define EFI_DEVICE_PATH_UTILITIES_PROTOCOL_GUID \
946         EFI_GUID(0x0379be4e, 0xd706, 0x437d, \
947                  0xb0, 0x37, 0xed, 0xb8, 0x2f, 0xb7, 0x72, 0xa4)
948
949 struct efi_device_path_utilities_protocol {
950         efi_uintn_t (EFIAPI *get_device_path_size)(
951                 const struct efi_device_path *device_path);
952         struct efi_device_path *(EFIAPI *duplicate_device_path)(
953                 const struct efi_device_path *device_path);
954         struct efi_device_path *(EFIAPI *append_device_path)(
955                 const struct efi_device_path *src1,
956                 const struct efi_device_path *src2);
957         struct efi_device_path *(EFIAPI *append_device_node)(
958                 const struct efi_device_path *device_path,
959                 const struct efi_device_path *device_node);
960         struct efi_device_path *(EFIAPI *append_device_path_instance)(
961                 const struct efi_device_path *device_path,
962                 const struct efi_device_path *device_path_instance);
963         struct efi_device_path *(EFIAPI *get_next_device_path_instance)(
964                 struct efi_device_path **device_path_instance,
965                 efi_uintn_t *device_path_instance_size);
966         bool (EFIAPI *is_device_path_multi_instance)(
967                 const struct efi_device_path *device_path);
968         struct efi_device_path *(EFIAPI *create_device_node)(
969                 uint8_t node_type,
970                 uint8_t node_sub_type,
971                 uint16_t node_length);
972 };
973
974 /*
975  * Human Interface Infrastructure (HII)
976  */
977 struct efi_hii_package_list_header {
978         efi_guid_t package_list_guid;
979         u32 package_length;
980 } __packed;
981
982 /**
983  * struct efi_hii_package_header - EFI HII package header
984  *
985  * @fields:     'fields' replaces the bit-fields defined in the EFI
986  *              specification to to avoid possible compiler incompatibilities::
987  *
988  *                  u32 length:24;
989  *                  u32 type:8;
990  */
991 struct efi_hii_package_header {
992         u32 fields;
993 } __packed;
994
995 #define __EFI_HII_PACKAGE_LEN_SHIFT     0
996 #define __EFI_HII_PACKAGE_TYPE_SHIFT    24
997 #define __EFI_HII_PACKAGE_LEN_MASK      0xffffff
998 #define __EFI_HII_PACKAGE_TYPE_MASK     0xff
999
1000 #define EFI_HII_PACKAGE_TYPE_ALL          0x00
1001 #define EFI_HII_PACKAGE_TYPE_GUID         0x01
1002 #define EFI_HII_PACKAGE_FORMS             0x02
1003 #define EFI_HII_PACKAGE_STRINGS           0x04
1004 #define EFI_HII_PACKAGE_FONTS             0x05
1005 #define EFI_HII_PACKAGE_IMAGES            0x06
1006 #define EFI_HII_PACKAGE_SIMPLE_FONTS      0x07
1007 #define EFI_HII_PACKAGE_DEVICE_PATH       0x08
1008 #define EFI_HII_PACKAGE_KEYBOARD_LAYOUT   0x09
1009 #define EFI_HII_PACKAGE_ANIMATIONS        0x0A
1010 #define EFI_HII_PACKAGE_END               0xDF
1011 #define EFI_HII_PACKAGE_TYPE_SYSTEM_BEGIN 0xE0
1012 #define EFI_HII_PACKAGE_TYPE_SYSTEM_END   0xFF
1013
1014 /*
1015  * HII GUID package
1016  */
1017 struct efi_hii_guid_package {
1018         struct efi_hii_package_header header;
1019         efi_guid_t guid;
1020         char data[];
1021 } __packed;
1022
1023 /*
1024  * HII string package
1025  */
1026 struct efi_hii_strings_package {
1027         struct efi_hii_package_header header;
1028         u32 header_size;
1029         u32 string_info_offset;
1030         u16 language_window[16];
1031         efi_string_id_t language_name;
1032         u8  language[];
1033 } __packed;
1034
1035 struct efi_hii_string_block {
1036         u8 block_type;
1037         /* u8 block_body[]; */
1038 } __packed;
1039
1040 #define EFI_HII_SIBT_END               0x00
1041 #define EFI_HII_SIBT_STRING_SCSU       0x10
1042 #define EFI_HII_SIBT_STRING_SCSU_FONT  0x11
1043 #define EFI_HII_SIBT_STRINGS_SCSU      0x12
1044 #define EFI_HII_SIBT_STRINGS_SCSU_FONT 0x13
1045 #define EFI_HII_SIBT_STRING_UCS2       0x14
1046 #define EFI_HII_SIBT_STRING_UCS2_FONT  0x15
1047 #define EFI_HII_SIBT_STRINGS_UCS2      0x16
1048 #define EFI_HII_SIBT_STRINGS_UCS2_FONT 0x17
1049 #define EFI_HII_SIBT_DUPLICATE         0x20
1050 #define EFI_HII_SIBT_SKIP2             0x21
1051 #define EFI_HII_SIBT_SKIP1             0x22
1052 #define EFI_HII_SIBT_EXT1              0x30
1053 #define EFI_HII_SIBT_EXT2              0x31
1054 #define EFI_HII_SIBT_EXT4              0x32
1055 #define EFI_HII_SIBT_FONT              0x40
1056
1057 struct efi_hii_sibt_string_ucs2_block {
1058         struct efi_hii_string_block header;
1059         u16 string_text[];
1060 } __packed;
1061
1062 static inline struct efi_hii_string_block *
1063 efi_hii_sibt_string_ucs2_block_next(struct efi_hii_sibt_string_ucs2_block *blk)
1064 {
1065         return ((void *)blk) + sizeof(*blk) +
1066                 (u16_strlen(blk->string_text) + 1) * 2;
1067 }
1068
1069 /*
1070  * HII forms package
1071  * TODO: full scope of definitions
1072  */
1073 struct efi_hii_time {
1074         u8 hour;
1075         u8 minute;
1076         u8 second;
1077 };
1078
1079 struct efi_hii_date {
1080         u16 year;
1081         u8 month;
1082         u8 day;
1083 };
1084
1085 struct efi_hii_ref {
1086         efi_question_id_t question_id;
1087         efi_form_id_t form_id;
1088         efi_guid_t form_set_guid;
1089         efi_string_id_t device_path;
1090 };
1091
1092 union efi_ifr_type_value {
1093         u8 u8;                          // EFI_IFR_TYPE_NUM_SIZE_8
1094         u16 u16;                        // EFI_IFR_TYPE_NUM_SIZE_16
1095         u32 u32;                        // EFI_IFR_TYPE_NUM_SIZE_32
1096         u64 u64;                        // EFI_IFR_TYPE_NUM_SIZE_64
1097         bool b;                         // EFI_IFR_TYPE_BOOLEAN
1098         struct efi_hii_time time;       // EFI_IFR_TYPE_TIME
1099         struct efi_hii_date date;       // EFI_IFR_TYPE_DATE
1100         efi_string_id_t string; // EFI_IFR_TYPE_STRING, EFI_IFR_TYPE_ACTION
1101         struct efi_hii_ref ref;         // EFI_IFR_TYPE_REF
1102         // u8 buffer[];                 // EFI_IFR_TYPE_BUFFER
1103 };
1104
1105 #define EFI_IFR_TYPE_NUM_SIZE_8         0x00
1106 #define EFI_IFR_TYPE_NUM_SIZE_16        0x01
1107 #define EFI_IFR_TYPE_NUM_SIZE_32        0x02
1108 #define EFI_IFR_TYPE_NUM_SIZE_64        0x03
1109 #define EFI_IFR_TYPE_BOOLEAN            0x04
1110 #define EFI_IFR_TYPE_TIME               0x05
1111 #define EFI_IFR_TYPE_DATE               0x06
1112 #define EFI_IFR_TYPE_STRING             0x07
1113 #define EFI_IFR_TYPE_OTHER              0x08
1114 #define EFI_IFR_TYPE_UNDEFINED          0x09
1115 #define EFI_IFR_TYPE_ACTION             0x0A
1116 #define EFI_IFR_TYPE_BUFFER             0x0B
1117 #define EFI_IFR_TYPE_REF                0x0C
1118 #define EFI_IFR_OPTION_DEFAULT          0x10
1119 #define EFI_IFR_OPTION_DEFAULT_MFG      0x20
1120
1121 #define EFI_IFR_ONE_OF_OPTION_OP        0x09
1122
1123 struct efi_ifr_op_header {
1124         u8 opCode;
1125         u8 length:7;
1126         u8 scope:1;
1127 };
1128
1129 struct efi_ifr_one_of_option {
1130         struct efi_ifr_op_header header;
1131         efi_string_id_t option;
1132         u8 flags;
1133         u8 type;
1134         union efi_ifr_type_value value;
1135 };
1136
1137 typedef efi_uintn_t efi_browser_action_t;
1138
1139 #define EFI_BROWSER_ACTION_REQUEST_NONE                 0
1140 #define EFI_BROWSER_ACTION_REQUEST_RESET                1
1141 #define EFI_BROWSER_ACTION_REQUEST_SUBMIT               2
1142 #define EFI_BROWSER_ACTION_REQUEST_EXIT                 3
1143 #define EFI_BROWSER_ACTION_REQUEST_FORM_SUBMIT_EXIT     4
1144 #define EFI_BROWSER_ACTION_REQUEST_FORM_DISCARD_EXIT    5
1145 #define EFI_BROWSER_ACTION_REQUEST_FORM_APPLY           6
1146 #define EFI_BROWSER_ACTION_REQUEST_FORM_DISCARD         7
1147 #define EFI_BROWSER_ACTION_REQUEST_RECONNECT            8
1148
1149 typedef efi_uintn_t efi_browser_action_request_t;
1150
1151 #define EFI_BROWSER_ACTION_CHANGING                     0
1152 #define EFI_BROWSER_ACTION_CHANGED                      1
1153 #define EFI_BROWSER_ACTION_RETRIEVE                     2
1154 #define EFI_BROWSER_ACTION_FORM_OPEN                    3
1155 #define EFI_BROWSER_ACTION_FORM_CLOSE                   4
1156 #define EFI_BROWSER_ACTION_SUBMITTED                    5
1157 #define EFI_BROWSER_ACTION_DEFAULT_STANDARD             0x1000
1158 #define EFI_BROWSER_ACTION_DEFAULT_MANUFACTURING        0x1001
1159 #define EFI_BROWSER_ACTION_DEFAULT_SAFE                 0x1002
1160 #define EFI_BROWSER_ACTION_DEFAULT_PLATFORM             0x2000
1161 #define EFI_BROWSER_ACTION_DEFAULT_HARDWARE             0x3000
1162 #define EFI_BROWSER_ACTION_DEFAULT_FIRMWARE             0x4000
1163
1164 /*
1165  * HII keyboard package
1166  */
1167 typedef enum {
1168         EFI_KEY_LCTRL, EFI_KEY_A0, EFI_KEY_LALT, EFI_KEY_SPACE_BAR,
1169         EFI_KEY_A2, EFI_KEY_A3, EFI_KEY_A4, EFI_KEY_RCTRL, EFI_KEY_LEFT_ARROW,
1170         EFI_KEY_DOWN_ARROW, EFI_KEY_RIGHT_ARROW, EFI_KEY_ZERO,
1171         EFI_KEY_PERIOD, EFI_KEY_ENTER, EFI_KEY_LSHIFT, EFI_KEY_B0,
1172         EFI_KEY_B1, EFI_KEY_B2, EFI_KEY_B3, EFI_KEY_B4, EFI_KEY_B5, EFI_KEY_B6,
1173         EFI_KEY_B7, EFI_KEY_B8, EFI_KEY_B9, EFI_KEY_B10, EFI_KEY_RSHIFT,
1174         EFI_KEY_UP_ARROW, EFI_KEY_ONE, EFI_KEY_TWO, EFI_KEY_THREE,
1175         EFI_KEY_CAPS_LOCK, EFI_KEY_C1, EFI_KEY_C2, EFI_KEY_C3, EFI_KEY_C4,
1176         EFI_KEY_C5, EFI_KEY_C6, EFI_KEY_C7, EFI_KEY_C8, EFI_KEY_C9,
1177         EFI_KEY_C10, EFI_KEY_C11, EFI_KEY_C12, EFI_KEY_FOUR, EFI_KEY_FIVE,
1178         EFI_KEY_SIX, EFI_KEY_PLUS, EFI_KEY_TAB, EFI_KEY_D1, EFI_KEY_D2,
1179         EFI_KEY_D3, EFI_KEY_D4, EFI_KEY_D5, EFI_KEY_D6, EFI_KEY_D7, EFI_KEY_D8,
1180         EFI_KEY_D9, EFI_KEY_D10, EFI_KEY_D11, EFI_KEY_D12, EFI_KEY_D13,
1181         EFI_KEY_DEL, EFI_KEY_END, EFI_KEY_PG_DN, EFI_KEY_SEVEN, EFI_KEY_EIGHT,
1182         EFI_KEY_NINE, EFI_KEY_E0, EFI_KEY_E1, EFI_KEY_E2, EFI_KEY_E3,
1183         EFI_KEY_E4, EFI_KEY_E5, EFI_KEY_E6, EFI_KEY_E7, EFI_KEY_E8, EFI_KEY_E9,
1184         EFI_KEY_E10, EFI_KEY_E11, EFI_KEY_E12, EFI_KEY_BACK_SPACE,
1185         EFI_KEY_INS, EFI_KEY_HOME, EFI_KEY_PG_UP, EFI_KEY_NLCK, EFI_KEY_SLASH,
1186         EFI_KEY_ASTERISK, EFI_KEY_MINUS, EFI_KEY_ESC, EFI_KEY_F1, EFI_KEY_F2,
1187         EFI_KEY_F3, EFI_KEY_F4, EFI_KEY_F5, EFI_KEY_F6, EFI_KEY_F7, EFI_KEY_F8,
1188         EFI_KEY_F9, EFI_KEY_F10, EFI_KEY_F11, EFI_KEY_F12, EFI_KEY_PRINT,
1189         EFI_KEY_SLCK, EFI_KEY_PAUSE,
1190 } efi_key;
1191
1192 struct efi_key_descriptor {
1193         u32 key;
1194         u16 unicode;
1195         u16 shifted_unicode;
1196         u16 alt_gr_unicode;
1197         u16 shifted_alt_gr_unicode;
1198         u16 modifier;
1199         u16 affected_attribute;
1200 } __packed;
1201
1202 struct efi_hii_keyboard_layout {
1203         u16 layout_length;
1204         /*
1205          * The EFI spec defines this as efi_guid_t.
1206          * clang and gcc both report alignment problems here.
1207          * clang with -Wunaligned-access
1208          * warning: field guid within 'struct efi_hii_keyboard_layout' is less
1209          * aligned than 'efi_guid_t' and is usually due to
1210          * 'struct efi_hii_keyboard_layout' being packed, which can lead to
1211          * unaligned accesses
1212          *
1213          * GCC with -Wpacked-not-aligned -Waddress-of-packed-member
1214          * 'efi_guid_t' offset 2 in 'struct efi_hii_keyboard_layout'
1215          * isn't aligned to 4
1216          *
1217          * Removing the alignment from efi_guid_t is not an option, since
1218          * it is also used in non-packed structs and that would break
1219          * calculations with offsetof
1220          *
1221          * This is the only place we get a report for. That happens because
1222          * all other declarations of efi_guid_t within a packed struct happens
1223          * to be 4-byte aligned.  i.e a u32, a u64 a 2 * u16 or any combination
1224          * that ends up landing efi_guid_t on a 4byte boundary precedes.
1225          *
1226          * Replace this with a 1-byte aligned counterpart of b[16].  This is a
1227          * packed struct so the memory  placement of efi_guid_t should not change
1228          *
1229          */
1230         u8 guid[16];
1231         u32 layout_descriptor_string_offset;
1232         u8 descriptor_count;
1233         /* struct efi_key_descriptor descriptors[]; follows here */
1234 } __packed;
1235
1236 struct efi_hii_keyboard_package {
1237         struct efi_hii_package_header header;
1238         u16 layout_count;
1239         struct efi_hii_keyboard_layout layout[];
1240 } __packed;
1241
1242 /*
1243  * HII protocols
1244  */
1245 #define EFI_HII_STRING_PROTOCOL_GUID \
1246         EFI_GUID(0x0fd96974, 0x23aa, 0x4cdc, \
1247                  0xb9, 0xcb, 0x98, 0xd1, 0x77, 0x50, 0x32, 0x2a)
1248
1249 struct efi_font_info {
1250         efi_hii_font_style_t font_style;
1251         u16 font_size;
1252         u16 font_name[1];
1253 };
1254
1255 struct efi_hii_string_protocol {
1256         efi_status_t(EFIAPI *new_string)(
1257                 const struct efi_hii_string_protocol *this,
1258                 efi_hii_handle_t package_list,
1259                 efi_string_id_t *string_id,
1260                 const u8 *language,
1261                 const u16 *language_name,
1262                 const efi_string_t string,
1263                 const struct efi_font_info *string_font_info);
1264         efi_status_t(EFIAPI *get_string)(
1265                 const struct efi_hii_string_protocol *this,
1266                 const u8 *language,
1267                 efi_hii_handle_t package_list,
1268                 efi_string_id_t string_id,
1269                 efi_string_t string,
1270                 efi_uintn_t *string_size,
1271                 struct efi_font_info **string_font_info);
1272         efi_status_t(EFIAPI *set_string)(
1273                 const struct efi_hii_string_protocol *this,
1274                 efi_hii_handle_t package_list,
1275                 efi_string_id_t string_id,
1276                 const u8 *language,
1277                 const efi_string_t string,
1278                 const struct efi_font_info *string_font_info);
1279         efi_status_t(EFIAPI *get_languages)(
1280                 const struct efi_hii_string_protocol *this,
1281                 efi_hii_handle_t package_list,
1282                 u8 *languages,
1283                 efi_uintn_t *languages_size);
1284         efi_status_t(EFIAPI *get_secondary_languages)(
1285                 const struct efi_hii_string_protocol *this,
1286                 efi_hii_handle_t package_list,
1287                 const u8 *primary_language,
1288                 u8 *secondary_languages,
1289                 efi_uintn_t *secondary_languages_size);
1290 };
1291
1292 #define EFI_HII_DATABASE_PROTOCOL_GUID       \
1293         EFI_GUID(0xef9fc172, 0xa1b2, 0x4693, \
1294                  0xb3, 0x27, 0x6d, 0x32, 0xfc, 0x41, 0x60, 0x42)
1295
1296 struct efi_hii_database_protocol {
1297         efi_status_t(EFIAPI *new_package_list)(
1298                 const struct efi_hii_database_protocol *this,
1299                 const struct efi_hii_package_list_header *package_list,
1300                 const efi_handle_t driver_handle,
1301                 efi_hii_handle_t *handle);
1302         efi_status_t(EFIAPI *remove_package_list)(
1303                 const struct efi_hii_database_protocol *this,
1304                 efi_hii_handle_t handle);
1305         efi_status_t(EFIAPI *update_package_list)(
1306                 const struct efi_hii_database_protocol *this,
1307                 efi_hii_handle_t handle,
1308                 const struct efi_hii_package_list_header *package_list);
1309         efi_status_t(EFIAPI *list_package_lists)(
1310                 const struct efi_hii_database_protocol *this,
1311                 u8 package_type,
1312                 const efi_guid_t *package_guid,
1313                 efi_uintn_t *handle_buffer_length,
1314                 efi_hii_handle_t *handle);
1315         efi_status_t(EFIAPI *export_package_lists)(
1316                 const struct efi_hii_database_protocol *this,
1317                 efi_hii_handle_t handle,
1318                 efi_uintn_t *buffer_size,
1319                 struct efi_hii_package_list_header *buffer);
1320         efi_status_t(EFIAPI *register_package_notify)(
1321                 const struct efi_hii_database_protocol *this,
1322                 u8 package_type,
1323                 const efi_guid_t *package_guid,
1324                 const void *package_notify_fn,
1325                 efi_uintn_t notify_type,
1326                 efi_handle_t *notify_handle);
1327         efi_status_t(EFIAPI *unregister_package_notify)(
1328                 const struct efi_hii_database_protocol *this,
1329                 efi_handle_t notification_handle
1330                 );
1331         efi_status_t(EFIAPI *find_keyboard_layouts)(
1332                 const struct efi_hii_database_protocol *this,
1333                 u16 *key_guid_buffer_length,
1334                 efi_guid_t *key_guid_buffer);
1335         efi_status_t(EFIAPI *get_keyboard_layout)(
1336                 const struct efi_hii_database_protocol *this,
1337                 efi_guid_t *key_guid,
1338                 u16 *keyboard_layout_length,
1339                 struct efi_hii_keyboard_layout *keyboard_layout);
1340         efi_status_t(EFIAPI *set_keyboard_layout)(
1341                 const struct efi_hii_database_protocol *this,
1342                 efi_guid_t *key_guid);
1343         efi_status_t(EFIAPI *get_package_list_handle)(
1344                 const struct efi_hii_database_protocol *this,
1345                 efi_hii_handle_t package_list_handle,
1346                 efi_handle_t *driver_handle);
1347 };
1348
1349 #define EFI_HII_CONFIG_ROUTING_PROTOCOL_GUID \
1350         EFI_GUID(0x587e72d7, 0xcc50, 0x4f79, \
1351                  0x82, 0x09, 0xca, 0x29, 0x1f, 0xc1, 0xa1, 0x0f)
1352
1353 struct efi_hii_config_routing_protocol {
1354         efi_status_t(EFIAPI *extract_config)(
1355                 const struct efi_hii_config_routing_protocol *this,
1356                 const efi_string_t request,
1357                 efi_string_t *progress,
1358                 efi_string_t *results);
1359         efi_status_t(EFIAPI *export_config)(
1360                 const struct efi_hii_config_routing_protocol *this,
1361                 efi_string_t *results);
1362         efi_status_t(EFIAPI *route_config)(
1363                 const struct efi_hii_config_routing_protocol *this,
1364                 const efi_string_t configuration,
1365                 efi_string_t *progress);
1366         efi_status_t(EFIAPI *block_to_config)(
1367                 const struct efi_hii_config_routing_protocol *this,
1368                 const efi_string_t config_request,
1369                 const uint8_t *block,
1370                 const efi_uintn_t block_size,
1371                 efi_string_t *config,
1372                 efi_string_t *progress);
1373         efi_status_t(EFIAPI *config_to_block)(
1374                 const struct efi_hii_config_routing_protocol *this,
1375                 const efi_string_t config_resp,
1376                 const uint8_t *block,
1377                 const efi_uintn_t *block_size,
1378                 efi_string_t *progress);
1379         efi_status_t(EFIAPI *get_alt_config)(
1380                 const struct efi_hii_config_routing_protocol *this,
1381                 const efi_string_t config_resp,
1382                 const efi_guid_t *guid,
1383                 const efi_string_t name,
1384                 const struct efi_device_path *device_path,
1385                 const efi_string_t alt_cfg_id,
1386                 efi_string_t *alt_cfg_resp);
1387 };
1388
1389 #define EFI_HII_CONFIG_ACCESS_PROTOCOL_GUID \
1390         EFI_GUID(0x330d4706, 0xf2a0, 0x4e4f, \
1391                  0xa3, 0x69, 0xb6, 0x6f, 0xa8, 0xd5, 0x43, 0x85)
1392
1393 struct efi_hii_config_access_protocol {
1394         efi_status_t(EFIAPI *extract_config_access)(
1395                 const struct efi_hii_config_access_protocol *this,
1396                 const efi_string_t request,
1397                 efi_string_t *progress,
1398                 efi_string_t *results);
1399         efi_status_t(EFIAPI *route_config_access)(
1400                 const struct efi_hii_config_access_protocol *this,
1401                 const efi_string_t configuration,
1402                 efi_string_t *progress);
1403         efi_status_t(EFIAPI *form_callback)(
1404                 const struct efi_hii_config_access_protocol *this,
1405                 efi_browser_action_t action,
1406                 efi_question_id_t question_id,
1407                 u8 type,
1408                 union efi_ifr_type_value *value,
1409                 efi_browser_action_request_t *action_request);
1410 };
1411
1412 #define EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID \
1413         EFI_GUID(0x9042a9de, 0x23dc, 0x4a38, \
1414                  0x96, 0xfb, 0x7a, 0xde, 0xd0, 0x80, 0x51, 0x6a)
1415
1416 #define EFI_GOT_RGBA8           0
1417 #define EFI_GOT_BGRA8           1
1418 #define EFI_GOT_BITMASK         2
1419
1420 struct efi_gop_mode_info {
1421         u32 version;
1422         u32 width;
1423         u32 height;
1424         u32 pixel_format;
1425         u32 pixel_bitmask[4];
1426         u32 pixels_per_scanline;
1427 };
1428
1429 struct efi_gop_mode {
1430         u32 max_mode;
1431         u32 mode;
1432         struct efi_gop_mode_info *info;
1433         unsigned long info_size;
1434         efi_physical_addr_t fb_base;
1435         unsigned long fb_size;
1436 };
1437
1438 struct efi_gop_pixel {
1439         u8 blue;
1440         u8 green;
1441         u8 red;
1442         u8 reserved;
1443 };
1444
1445 #define EFI_BLT_VIDEO_FILL              0
1446 #define EFI_BLT_VIDEO_TO_BLT_BUFFER     1
1447 #define EFI_BLT_BUFFER_TO_VIDEO         2
1448 #define EFI_BLT_VIDEO_TO_VIDEO          3
1449
1450 struct efi_gop {
1451         efi_status_t (EFIAPI *query_mode)(struct efi_gop *this, u32 mode_number,
1452                                           efi_uintn_t *size_of_info,
1453                                           struct efi_gop_mode_info **info);
1454         efi_status_t (EFIAPI *set_mode)(struct efi_gop *this, u32 mode_number);
1455         efi_status_t (EFIAPI *blt)(struct efi_gop *this,
1456                                    struct efi_gop_pixel *buffer,
1457                                    u32 operation, efi_uintn_t sx,
1458                                    efi_uintn_t sy, efi_uintn_t dx,
1459                                    efi_uintn_t dy, efi_uintn_t width,
1460                                    efi_uintn_t height, efi_uintn_t delta);
1461         struct efi_gop_mode *mode;
1462 };
1463
1464 #define EFI_SIMPLE_NETWORK_PROTOCOL_GUID \
1465         EFI_GUID(0xa19832b9, 0xac25, 0x11d3, \
1466                  0x9a, 0x2d, 0x00, 0x90, 0x27, 0x3f, 0xc1, 0x4d)
1467
1468 struct efi_mac_address {
1469         char mac_addr[32];
1470 };
1471
1472 struct efi_ip_address {
1473         u8 ip_addr[16];
1474 } __attribute__((aligned(4)));
1475
1476 enum efi_simple_network_state {
1477         EFI_NETWORK_STOPPED,
1478         EFI_NETWORK_STARTED,
1479         EFI_NETWORK_INITIALIZED,
1480 };
1481
1482 struct efi_simple_network_mode {
1483         enum efi_simple_network_state state;
1484         u32 hwaddr_size;
1485         u32 media_header_size;
1486         u32 max_packet_size;
1487         u32 nvram_size;
1488         u32 nvram_access_size;
1489         u32 receive_filter_mask;
1490         u32 receive_filter_setting;
1491         u32 max_mcast_filter_count;
1492         u32 mcast_filter_count;
1493         struct efi_mac_address mcast_filter[16];
1494         struct efi_mac_address current_address;
1495         struct efi_mac_address broadcast_address;
1496         struct efi_mac_address permanent_address;
1497         u8 if_type;
1498         u8 mac_changeable;
1499         u8 multitx_supported;
1500         u8 media_present_supported;
1501         u8 media_present;
1502 };
1503
1504 /* receive_filters bit mask */
1505 #define EFI_SIMPLE_NETWORK_RECEIVE_UNICAST               0x01
1506 #define EFI_SIMPLE_NETWORK_RECEIVE_MULTICAST             0x02
1507 #define EFI_SIMPLE_NETWORK_RECEIVE_BROADCAST             0x04
1508 #define EFI_SIMPLE_NETWORK_RECEIVE_PROMISCUOUS           0x08
1509 #define EFI_SIMPLE_NETWORK_RECEIVE_PROMISCUOUS_MULTICAST 0x10
1510
1511 /* interrupt status bit mask */
1512 #define EFI_SIMPLE_NETWORK_RECEIVE_INTERRUPT    0x01
1513 #define EFI_SIMPLE_NETWORK_TRANSMIT_INTERRUPT   0x02
1514 #define EFI_SIMPLE_NETWORK_COMMAND_INTERRUPT    0x04
1515 #define EFI_SIMPLE_NETWORK_SOFTWARE_INTERRUPT   0x08
1516
1517 /* revision of the simple network protocol */
1518 #define EFI_SIMPLE_NETWORK_PROTOCOL_REVISION    0x00010000
1519
1520 struct efi_simple_network {
1521         u64 revision;
1522         efi_status_t (EFIAPI *start)(struct efi_simple_network *this);
1523         efi_status_t (EFIAPI *stop)(struct efi_simple_network *this);
1524         efi_status_t (EFIAPI *initialize)(struct efi_simple_network *this,
1525                         ulong extra_rx, ulong extra_tx);
1526         efi_status_t (EFIAPI *reset)(struct efi_simple_network *this,
1527                         int extended_verification);
1528         efi_status_t (EFIAPI *shutdown)(struct efi_simple_network *this);
1529         efi_status_t (EFIAPI *receive_filters)(struct efi_simple_network *this,
1530                         u32 enable, u32 disable, int reset_mcast_filter,
1531                         ulong mcast_filter_count,
1532                         struct efi_mac_address *mcast_filter);
1533         efi_status_t (EFIAPI *station_address)(struct efi_simple_network *this,
1534                         int reset, struct efi_mac_address *new_mac);
1535         efi_status_t (EFIAPI *statistics)(struct efi_simple_network *this,
1536                         int reset, ulong *stat_size, void *stat_table);
1537         efi_status_t (EFIAPI *mcastiptomac)(struct efi_simple_network *this,
1538                         int ipv6, struct efi_ip_address *ip,
1539                         struct efi_mac_address *mac);
1540         efi_status_t (EFIAPI *nvdata)(struct efi_simple_network *this,
1541                         int read_write, ulong offset, ulong buffer_size,
1542                         char *buffer);
1543         efi_status_t (EFIAPI *get_status)(struct efi_simple_network *this,
1544                         u32 *int_status, void **txbuf);
1545         efi_status_t (EFIAPI *transmit)(struct efi_simple_network *this,
1546                         size_t header_size, size_t buffer_size, void *buffer,
1547                         struct efi_mac_address *src_addr,
1548                         struct efi_mac_address *dest_addr, u16 *protocol);
1549         efi_status_t (EFIAPI *receive)(struct efi_simple_network *this,
1550                         size_t *header_size, size_t *buffer_size, void *buffer,
1551                         struct efi_mac_address *src_addr,
1552                         struct efi_mac_address *dest_addr, u16 *protocol);
1553         struct efi_event *wait_for_packet;
1554         struct efi_simple_network_mode *mode;
1555         /* private fields */
1556         u32 int_status;
1557 };
1558
1559 #define EFI_PXE_BASE_CODE_PROTOCOL_GUID \
1560         EFI_GUID(0x03c4e603, 0xac28, 0x11d3, \
1561                  0x9a, 0x2d, 0x00, 0x90, 0x27, 0x3f, 0xc1, 0x4d)
1562
1563 #define EFI_PXE_BASE_CODE_PROTOCOL_REVISION 0x00010000
1564 #define EFI_PXE_BASE_CODE_MAX_IPCNT 8
1565
1566 struct efi_pxe_packet {
1567         u8 packet[1472];
1568 };
1569
1570 struct efi_pxe_mode {
1571         u8 started;
1572         u8 ipv6_available;
1573         u8 ipv6_supported;
1574         u8 using_ipv6;
1575         u8 bis_supported;
1576         u8 bis_detected;
1577         u8 auto_arp;
1578         u8 send_guid;
1579         u8 dhcp_discover_valid;
1580         u8 dhcp_ack_received;
1581         u8 proxy_offer_received;
1582         u8 pxe_discover_valid;
1583         u8 pxe_reply_received;
1584         u8 pxe_bis_reply_received;
1585         u8 icmp_error_received;
1586         u8 tftp_error_received;
1587         u8 make_callbacks;
1588         u8 ttl;
1589         u8 tos;
1590         u8 pad;
1591         struct efi_ip_address station_ip;
1592         struct efi_ip_address subnet_mask;
1593         struct efi_pxe_packet dhcp_discover;
1594         struct efi_pxe_packet dhcp_ack;
1595         struct efi_pxe_packet proxy_offer;
1596         struct efi_pxe_packet pxe_discover;
1597         struct efi_pxe_packet pxe_reply;
1598 };
1599
1600 struct efi_pxe_base_code_srvlist {
1601         u16 type;
1602         u8 accept_any_response;
1603         u8 reserved;
1604         struct efi_ip_address ip_addr;
1605 };
1606
1607 struct efi_pxe_base_code_discover_info {
1608         u8 use_m_cast;
1609         u8 use_b_cast;
1610         u8 use_u_cast;
1611         u8 must_use_list;
1612         struct efi_ip_address server_m_cast_ip;
1613         u16 ip_cnt;
1614         struct efi_pxe_base_code_srvlist srv_list[];
1615 };
1616
1617 struct efi_pxe_base_code_mtftp_info {
1618         struct efi_ip_address m_cast_ip;
1619         u16 cport;
1620         u16 sport;
1621         u16 listen_timeout;
1622         u16 transit_timeout;
1623 };
1624
1625 struct efi_pxe_base_code_filter {
1626         u8 filters;
1627         u8 ip_cnt;
1628         u16 reserved;
1629         struct efi_ip_address ip_list[EFI_PXE_BASE_CODE_MAX_IPCNT];
1630 };
1631
1632 struct efi_pxe_base_code_dhcpv4_packet {
1633         u8 bootp_op_code;
1634         u8 bootp_hw_type;
1635         u8 bootp_addr_len;
1636         u8 bootp_gate_hops;
1637         u32 bootp_ident;
1638         u16 bootp_seconds;
1639         u16 bootp_flags;
1640         u8 bootp_ci_addr[4];
1641         u8 bootp_yi_addr[4];
1642         u8 bootp_si_addr[4];
1643         u8 bootp_gi_addr[4];
1644         u8 bootp_hw_addr[16];
1645         u8 bootp_srv_name[64];
1646         u8 bootp_boot_file[128];
1647         u32 dhcp_magick;
1648         u8 dhcp_options[56];
1649 };
1650
1651 struct efi_pxe_base_code_dhcpv6_packet {
1652         u8 message_type;
1653         u8 transaction_id[3];
1654         u8 dhcp_options[1024];
1655 };
1656
1657 typedef union {
1658         u8 raw[1472];
1659         struct efi_pxe_base_code_dhcpv4_packet dhcpv4;
1660         struct efi_pxe_base_code_dhcpv6_packet dhcpv6;
1661 } EFI_PXE_BASE_CODE_PACKET;
1662
1663 struct efi_pxe_base_code_protocol {
1664         u64 revision;
1665         efi_status_t (EFIAPI *start)(struct efi_pxe_base_code_protocol *this,
1666                                      u8 use_ipv6);
1667         efi_status_t (EFIAPI *stop)(struct efi_pxe_base_code_protocol *this);
1668         efi_status_t (EFIAPI *dhcp)(struct efi_pxe_base_code_protocol *this,
1669                                     u8 sort_offers);
1670         efi_status_t (EFIAPI *discover)(
1671                                 struct efi_pxe_base_code_protocol *this,
1672                                 u16 type, u16 *layer, u8 bis,
1673                                 struct efi_pxe_base_code_discover_info *info);
1674         efi_status_t (EFIAPI *mtftp)(
1675                                 struct efi_pxe_base_code_protocol *this,
1676                                 u32 operation, void *buffer_ptr,
1677                                 u8 overwrite, efi_uintn_t *buffer_size,
1678                                 struct efi_ip_address server_ip, char *filename,
1679                                 struct efi_pxe_base_code_mtftp_info *info,
1680                                 u8 dont_use_buffer);
1681         efi_status_t (EFIAPI *udp_write)(
1682                                 struct efi_pxe_base_code_protocol *this,
1683                                 u16 op_flags, struct efi_ip_address *dest_ip,
1684                                 u16 *dest_port,
1685                                 struct efi_ip_address *gateway_ip,
1686                                 struct efi_ip_address *src_ip, u16 *src_port,
1687                                 efi_uintn_t *header_size, void *header_ptr,
1688                                 efi_uintn_t *buffer_size, void *buffer_ptr);
1689         efi_status_t (EFIAPI *udp_read)(
1690                                 struct efi_pxe_base_code_protocol *this,
1691                                 u16 op_flags, struct efi_ip_address *dest_ip,
1692                                 u16 *dest_port, struct efi_ip_address *src_ip,
1693                                 u16 *src_port, efi_uintn_t *header_size,
1694                                 void *header_ptr, efi_uintn_t *buffer_size,
1695                                 void *buffer_ptr);
1696         efi_status_t (EFIAPI *set_ip_filter)(
1697                                 struct efi_pxe_base_code_protocol *this,
1698                                 struct efi_pxe_base_code_filter *new_filter);
1699         efi_status_t (EFIAPI *arp)(struct efi_pxe_base_code_protocol *this,
1700                                    struct efi_ip_address *ip_addr,
1701                                    struct efi_mac_address *mac_addr);
1702         efi_status_t (EFIAPI *set_parameters)(
1703                                 struct efi_pxe_base_code_protocol *this,
1704                                 u8 *new_auto_arp, u8 *new_send_guid,
1705                                 u8 *new_ttl, u8 *new_tos,
1706                                 u8 *new_make_callback);
1707         efi_status_t (EFIAPI *set_station_ip)(
1708                                 struct efi_pxe_base_code_protocol *this,
1709                                 struct efi_ip_address *new_station_ip,
1710                                 struct efi_ip_address *new_subnet_mask);
1711         efi_status_t (EFIAPI *set_packets)(
1712                                 struct efi_pxe_base_code_protocol *this,
1713                                 u8 *new_dhcp_discover_valid,
1714                                 u8 *new_dhcp_ack_received,
1715                                 u8 *new_proxy_offer_received,
1716                                 u8 *new_pxe_discover_valid,
1717                                 u8 *new_pxe_reply_received,
1718                                 u8 *new_pxe_bis_reply_received,
1719                                 EFI_PXE_BASE_CODE_PACKET *new_dchp_discover,
1720                                 EFI_PXE_BASE_CODE_PACKET *new_dhcp_acc,
1721                                 EFI_PXE_BASE_CODE_PACKET *new_proxy_offer,
1722                                 EFI_PXE_BASE_CODE_PACKET *new_pxe_discover,
1723                                 EFI_PXE_BASE_CODE_PACKET *new_pxe_reply,
1724                                 EFI_PXE_BASE_CODE_PACKET *new_pxe_bis_reply);
1725         struct efi_pxe_mode *mode;
1726 };
1727
1728 #define EFI_IP4_CONFIG2_PROTOCOL_GUID \
1729         EFI_GUID(0x5b446ed1, 0xe30b, 0x4faa, \
1730                  0x87, 0x1a, 0x36, 0x54, 0xec, 0xa3, 0x60, 0x80)
1731
1732 enum efi_ip4_config2_data_type {
1733         EFI_IP4_CONFIG2_DATA_TYPE_INTERFACEINFO,
1734         EFI_IP4_CONFIG2_DATA_TYPE_POLICY,
1735         EFI_IP4_CONFIG2_DATA_TYPE_MANUAL_ADDRESS,
1736         EFI_IP4_CONFIG2_DATA_TYPE_GATEWAY,
1737         EFI_IP4_CONFIG2_DATA_TYPE_DNSSERVER,
1738         EFI_IP4_CONFIG2_DATA_TYPE_MAXIMUM,
1739 };
1740
1741 struct efi_ip4_config2_protocol {
1742         efi_status_t (EFIAPI * set_data)(struct efi_ip4_config2_protocol *this,
1743                                          enum efi_ip4_config2_data_type data_type,
1744                                          efi_uintn_t data_size,
1745                                          void *data);
1746         efi_status_t (EFIAPI * get_data)(struct efi_ip4_config2_protocol *this,
1747                                          enum efi_ip4_config2_data_type data_type,
1748                                          efi_uintn_t *data_size,
1749                                          void *data);
1750         efi_status_t (EFIAPI * register_data_notify)(struct efi_ip4_config2_protocol *this,
1751                                                      enum efi_ip4_config2_data_type data_type,
1752                                                      struct efi_event *event);
1753         efi_status_t (EFIAPI * unregister_data_notify)(struct efi_ip4_config2_protocol *this,
1754                                                        enum efi_ip4_config2_data_type data_type,
1755                                                        struct efi_event *event);
1756 };
1757
1758 struct efi_ip4_route_table {
1759         struct efi_ipv4_address subnet_address;
1760         struct efi_ipv4_address subnet_mask;
1761         struct efi_ipv4_address gateway_address;
1762 };
1763
1764 #define EFI_IP4_CONFIG2_INTERFACE_INFO_NAME_SIZE 32
1765
1766 struct efi_ip4_config2_interface_info {
1767         u16 name[EFI_IP4_CONFIG2_INTERFACE_INFO_NAME_SIZE];
1768         u8 if_type;
1769         u32 hw_address_size;
1770         struct efi_mac_address hw_address;
1771         struct efi_ipv4_address station_address;
1772         struct efi_ipv4_address subnet_mask;
1773         u32 route_table_size;
1774         struct efi_ip4_route_table *route_table;
1775 };
1776
1777 enum efi_ip4_config2_policy {
1778         EFI_IP4_CONFIG2_POLICY_STATIC,
1779         EFI_IP4_CONFIG2_POLICY_DHCP,
1780         EFI_IP4_CONFIG2_POLICY_MAX
1781 };
1782
1783 struct efi_ip4_config2_manual_address {
1784         struct efi_ipv4_address address;
1785         struct efi_ipv4_address subnet_mask;
1786 };
1787
1788 #define EFI_HTTP_SERVICE_BINDING_PROTOCOL_GUID \
1789         EFI_GUID(0xbdc8e6af, 0xd9bc, 0x4379, \
1790                  0xa7, 0x2a, 0xe0, 0xc4, 0xe7, 0x5d, 0xae, 0x1c)
1791
1792 struct efi_service_binding_protocol {
1793         efi_status_t (EFIAPI * create_child)(struct efi_service_binding_protocol *this,
1794                                              efi_handle_t *child_handle);
1795         efi_status_t (EFIAPI * destroy_child)(struct efi_service_binding_protocol *this,
1796                                               efi_handle_t child_handle);
1797 };
1798
1799 #define EFI_HTTP_PROTOCOL_GUID \
1800         EFI_GUID(0x7A59B29B, 0x910B, 0x4171, \
1801                  0x82, 0x42, 0xA8, 0x5A, 0x0D, 0xF2, 0x5B, 0x5B)
1802
1803 enum efi_http_version {
1804         HTTPVERSION10,
1805         HTTPVERSION11,
1806         HTTPVERSIONUNSUPPORTED
1807 };
1808
1809 struct efi_httpv4_access_point {
1810         bool use_default_address;
1811         struct efi_ipv4_address local_address;
1812         struct efi_ipv4_address local_subnet;
1813         u16 local_port;
1814 };
1815
1816 union efi_http_access_point {
1817         struct efi_httpv4_access_point *ipv4_node;
1818         struct efi_httpv6_access_point *ipv6_node;
1819 };
1820
1821 struct efi_http_config_data {
1822         enum efi_http_version http_version;
1823         u32 timeout;
1824         bool is_ipv6;
1825         union efi_http_access_point access_point;
1826 };
1827
1828 enum efi_http_method {
1829         HTTP_METHOD_GET,
1830         HTTP_METHOD_POST,
1831         HTTP_METHOD_PATCH,
1832         HTTP_METHOD_OPTIONS,
1833         HTTP_METHOD_CONNECT,
1834         HTTP_METHOD_HEAD,
1835         HTTP_METHOD_PUT,
1836         HTTP_METHOD_DELETE,
1837         HTTP_METHOD_TRACE,
1838         HTTP_METHOD_MAX
1839 };
1840
1841 enum efi_http_status_code {
1842         HTTP_STATUS_UNSUPPORTED_STATUS = 0,
1843         HTTP_STATUS_100_CONTINUE,
1844         HTTP_STATUS_101_SWITCHING_PROTOCOLS,
1845         HTTP_STATUS_200_OK,
1846         HTTP_STATUS_201_CREATED,
1847         HTTP_STATUS_202_ACCEPTED,
1848         HTTP_STATUS_203_NON_AUTHORITATIVE_INFORMATION,
1849         HTTP_STATUS_204_NO_CONTENT,
1850         HTTP_STATUS_205_RESET_CONTENT,
1851         HTTP_STATUS_206_PARTIAL_CONTENT,
1852         HTTP_STATUS_300_MULTIPLE_CHOICES,
1853         HTTP_STATUS_301_MOVED_PERMANENTLY,
1854         HTTP_STATUS_302_FOUND,
1855         HTTP_STATUS_303_SEE_OTHER,
1856         HTTP_STATUS_304_NOT_MODIFIED,
1857         HTTP_STATUS_305_USE_PROXY,
1858         HTTP_STATUS_307_TEMPORARY_REDIRECT,
1859         HTTP_STATUS_400_BAD_REQUEST,
1860         HTTP_STATUS_401_UNAUTHORIZED,
1861         HTTP_STATUS_402_PAYMENT_REQUIRED,
1862         HTTP_STATUS_403_FORBIDDEN,
1863         HTTP_STATUS_404_NOT_FOUND,
1864         HTTP_STATUS_405_METHOD_NOT_ALLOWED,
1865         HTTP_STATUS_406_NOT_ACCEPTABLE,
1866         HTTP_STATUS_407_PROXY_AUTHENTICATION_REQUIRED,
1867         HTTP_STATUS_408_REQUEST_TIME_OUT,
1868         HTTP_STATUS_409_CONFLICT,
1869         HTTP_STATUS_410_GONE,
1870         HTTP_STATUS_411_LENGTH_REQUIRED,
1871         HTTP_STATUS_412_PRECONDITION_FAILED,
1872         HTTP_STATUS_413_REQUEST_ENTITY_TOO_LARGE,
1873         HTTP_STATUS_414_REQUEST_URI_TOO_LARGE,
1874         HTTP_STATUS_415_UNSUPPORTED_MEDIA_TYPE,
1875         HTTP_STATUS_416_REQUESTED_RANGE_NOT_SATISFIED,
1876         HTTP_STATUS_417_EXPECTATION_FAILED,
1877         HTTP_STATUS_500_INTERNAL_SERVER_ERROR,
1878         HTTP_STATUS_501_NOT_IMPLEMENTED,
1879         HTTP_STATUS_502_BAD_GATEWAY,
1880         HTTP_STATUS_503_SERVICE_UNAVAILABLE,
1881         HTTP_STATUS_504_GATEWAY_TIME_OUT,
1882         HTTP_STATUS_505_HTTP_VERSION_NOT_SUPPORTED,
1883         HTTP_STATUS_308_PERMANENT_REDIRECT
1884 };
1885
1886 struct efi_http_request_data {
1887         enum efi_http_method method;
1888         u16 *url;
1889 };
1890
1891 struct efi_http_response_data {
1892         enum efi_http_status_code status_code;
1893 };
1894
1895 struct efi_http_header {
1896         char *field_name;
1897         char *field_value;
1898 };
1899
1900 struct efi_http_message {
1901         union {
1902                 struct efi_http_request_data *request;
1903                 struct efi_http_response_data *response;
1904         } data;
1905         efi_uintn_t header_count;
1906         struct efi_http_header *headers;
1907         efi_uintn_t body_length;
1908         void *body;
1909 };
1910
1911 struct efi_http_token {
1912         struct efi_event *event;
1913         efi_status_t status;
1914         struct efi_http_message *message;
1915 };
1916
1917 struct efi_http_protocol {
1918         efi_status_t (EFIAPI * get_mode_data)(struct efi_http_protocol *this,
1919                                               struct efi_http_config_data *data);
1920         efi_status_t (EFIAPI * configure)(struct efi_http_protocol *this,
1921                                           struct efi_http_config_data *data);
1922         efi_status_t (EFIAPI * request)(struct efi_http_protocol *this,
1923                                         struct efi_http_token *token);
1924         efi_status_t (EFIAPI * cancel)(struct efi_http_protocol *this,
1925                                        struct efi_http_token *token);
1926         efi_status_t (EFIAPI * response)(struct efi_http_protocol *this,
1927                                          struct efi_http_token *token);
1928         efi_status_t (EFIAPI * poll)(struct efi_http_protocol *this);
1929 };
1930
1931 #define EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID \
1932         EFI_GUID(0x964e5b22, 0x6459, 0x11d2, \
1933                  0x8e, 0x39, 0x0, 0xa0, 0xc9, 0x69, 0x72, 0x3b)
1934 #define EFI_FILE_PROTOCOL_REVISION      0x00010000
1935 #define EFI_FILE_PROTOCOL_REVISION2     0x00020000
1936 #define EFI_FILE_PROTOCOL_LATEST_REVISION EFI_FILE_PROTOCOL_REVISION2
1937
1938 struct efi_file_io_token {
1939         struct efi_event *event;
1940         efi_status_t status;
1941         efi_uintn_t buffer_size;
1942         void *buffer;};
1943
1944 struct efi_file_handle {
1945         u64 rev;
1946         efi_status_t (EFIAPI *open)(struct efi_file_handle *this,
1947                         struct efi_file_handle **new_handle,
1948                         u16 *file_name, u64 open_mode, u64 attributes);
1949         efi_status_t (EFIAPI *close)(struct efi_file_handle *this);
1950         efi_status_t (EFIAPI *delete)(struct efi_file_handle *this);
1951         efi_status_t (EFIAPI *read)(struct efi_file_handle *this,
1952                         efi_uintn_t *buffer_size, void *buffer);
1953         efi_status_t (EFIAPI *write)(struct efi_file_handle *this,
1954                         efi_uintn_t *buffer_size, void *buffer);
1955         efi_status_t (EFIAPI *getpos)(struct efi_file_handle *this,
1956                                       u64 *pos);
1957         efi_status_t (EFIAPI *setpos)(struct efi_file_handle *this,
1958                                       u64 pos);
1959         efi_status_t (EFIAPI *getinfo)(struct efi_file_handle *this,
1960                         const efi_guid_t *info_type, efi_uintn_t *buffer_size,
1961                         void *buffer);
1962         efi_status_t (EFIAPI *setinfo)(struct efi_file_handle *this,
1963                         const efi_guid_t *info_type, efi_uintn_t buffer_size,
1964                         void *buffer);
1965         efi_status_t (EFIAPI *flush)(struct efi_file_handle *this);
1966         efi_status_t (EFIAPI *open_ex)(struct efi_file_handle *this,
1967                         struct efi_file_handle **new_handle,
1968                         u16 *file_name, u64 open_mode, u64 attributes,
1969                         struct efi_file_io_token *token);
1970         efi_status_t (EFIAPI *read_ex)(struct efi_file_handle *this,
1971                         struct efi_file_io_token *token);
1972         efi_status_t (EFIAPI *write_ex)(struct efi_file_handle *this,
1973                         struct efi_file_io_token *token);
1974         efi_status_t (EFIAPI *flush_ex)(struct efi_file_handle *this,
1975                         struct efi_file_io_token *token);
1976 };
1977
1978 #define EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_REVISION 0x00010000
1979
1980 struct efi_simple_file_system_protocol {
1981         u64 rev;
1982         efi_status_t (EFIAPI *open_volume)(struct efi_simple_file_system_protocol *this,
1983                         struct efi_file_handle **root);
1984 };
1985
1986 #define EFI_FILE_INFO_GUID \
1987         EFI_GUID(0x9576e92, 0x6d3f, 0x11d2, \
1988                  0x8e, 0x39, 0x0, 0xa0, 0xc9, 0x69, 0x72, 0x3b)
1989
1990 #define EFI_FILE_SYSTEM_INFO_GUID \
1991         EFI_GUID(0x09576e93, 0x6d3f, 0x11d2, \
1992                  0x8e, 0x39, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b)
1993
1994 #define EFI_FILE_SYSTEM_VOLUME_LABEL_ID \
1995         EFI_GUID(0xdb47d7d3, 0xfe81, 0x11d3, \
1996                  0x9a, 0x35, 0x00, 0x90, 0x27, 0x3f, 0xC1, 0x4d)
1997
1998 #define EFI_FILE_MODE_READ      0x0000000000000001
1999 #define EFI_FILE_MODE_WRITE     0x0000000000000002
2000 #define EFI_FILE_MODE_CREATE    0x8000000000000000
2001
2002 #define EFI_FILE_READ_ONLY      0x0000000000000001
2003 #define EFI_FILE_HIDDEN         0x0000000000000002
2004 #define EFI_FILE_SYSTEM         0x0000000000000004
2005 #define EFI_FILE_RESERVED       0x0000000000000008
2006 #define EFI_FILE_DIRECTORY      0x0000000000000010
2007 #define EFI_FILE_ARCHIVE        0x0000000000000020
2008 #define EFI_FILE_VALID_ATTR     0x0000000000000037
2009
2010 struct efi_file_info {
2011         u64 size;
2012         u64 file_size;
2013         u64 physical_size;
2014         struct efi_time create_time;
2015         struct efi_time last_access_time;
2016         struct efi_time modification_time;
2017         u64 attribute;
2018         u16 file_name[0];
2019 };
2020
2021 struct efi_file_system_info {
2022         u64 size;
2023         u8 read_only;
2024         u64 volume_size;
2025         u64 free_space;
2026         u32 block_size;
2027         u16 volume_label[0];
2028 };
2029
2030 #define EFI_DRIVER_BINDING_PROTOCOL_GUID \
2031         EFI_GUID(0x18a031ab, 0xb443, 0x4d1a,\
2032                  0xa5, 0xc0, 0x0c, 0x09, 0x26, 0x1e, 0x9f, 0x71)
2033 struct efi_driver_binding_protocol {
2034         efi_status_t (EFIAPI * supported)(
2035                         struct efi_driver_binding_protocol *this,
2036                         efi_handle_t controller_handle,
2037                         struct efi_device_path *remaining_device_path);
2038         efi_status_t (EFIAPI * start)(
2039                         struct efi_driver_binding_protocol *this,
2040                         efi_handle_t controller_handle,
2041                         struct efi_device_path *remaining_device_path);
2042         efi_status_t (EFIAPI * stop)(
2043                         struct efi_driver_binding_protocol *this,
2044                         efi_handle_t controller_handle,
2045                         efi_uintn_t number_of_children,
2046                         efi_handle_t *child_handle_buffer);
2047         u32 version;
2048         efi_handle_t image_handle;
2049         efi_handle_t driver_binding_handle;
2050 };
2051
2052 /* Current version of the Unicode collation protocol */
2053 #define EFI_UNICODE_COLLATION_PROTOCOL2_GUID \
2054         EFI_GUID(0xa4c751fc, 0x23ae, 0x4c3e, \
2055                  0x92, 0xe9, 0x49, 0x64, 0xcf, 0x63, 0xf3, 0x49)
2056 struct efi_unicode_collation_protocol {
2057         efi_intn_t (EFIAPI *stri_coll)(
2058                 struct efi_unicode_collation_protocol *this, u16 *s1, u16 *s2);
2059         bool (EFIAPI *metai_match)(struct efi_unicode_collation_protocol *this,
2060                                    const u16 *string, const u16 *patter);
2061         void (EFIAPI *str_lwr)(struct efi_unicode_collation_protocol
2062                                *this, u16 *string);
2063         void (EFIAPI *str_upr)(struct efi_unicode_collation_protocol *this,
2064                                u16 *string);
2065         void (EFIAPI *fat_to_str)(struct efi_unicode_collation_protocol *this,
2066                                   efi_uintn_t fat_size, char *fat, u16 *string);
2067         bool (EFIAPI *str_to_fat)(struct efi_unicode_collation_protocol *this,
2068                                   const u16 *string, efi_uintn_t fat_size,
2069                                   char *fat);
2070         char *supported_languages;
2071 };
2072
2073 struct efi_load_file_protocol {
2074         efi_status_t (EFIAPI *load_file)(struct efi_load_file_protocol *this,
2075                                          struct efi_device_path *file_path,
2076                                          bool boot_policy,
2077                                          efi_uintn_t *buffer_size,
2078                                          void *buffer);
2079 };
2080
2081 struct efi_system_resource_entry {
2082         efi_guid_t fw_class;
2083         u32 fw_type;
2084         u32 fw_version;
2085         u32 lowest_supported_fw_version;
2086         u32 capsule_flags;
2087         u32 last_attempt_version;
2088         u32 last_attempt_status;
2089 } __packed;
2090
2091 struct efi_system_resource_table {
2092         u32 fw_resource_count;
2093         u32 fw_resource_count_max;
2094         u64 fw_resource_version;
2095         struct efi_system_resource_entry entries[];
2096 } __packed;
2097
2098 /* Boot manager load options */
2099 #define LOAD_OPTION_ACTIVE              0x00000001
2100 #define LOAD_OPTION_FORCE_RECONNECT     0x00000002
2101 #define LOAD_OPTION_HIDDEN              0x00000008
2102 /* All values 0x00000200-0x00001F00 are reserved */
2103 #define LOAD_OPTION_CATEGORY            0x00001F00
2104 #define LOAD_OPTION_CATEGORY_BOOT       0x00000000
2105 #define LOAD_OPTION_CATEGORY_APP        0x00000100
2106
2107 /*
2108  * System Resource Table
2109  */
2110 /* Firmware Type Definitions */
2111 #define ESRT_FW_TYPE_UNKNOWN            0x00000000
2112 #define ESRT_FW_TYPE_SYSTEMFIRMWARE     0x00000001
2113 #define ESRT_FW_TYPE_DEVICEFIRMWARE     0x00000002
2114 #define ESRT_FW_TYPE_UEFIDRIVER         0x00000003
2115
2116 #define EFI_SYSTEM_RESOURCE_TABLE_GUID\
2117         EFI_GUID(0xb122a263, 0x3661, 0x4f68,\
2118                 0x99, 0x29, 0x78, 0xf8, 0xb0, 0xd6, 0x21, 0x80)
2119
2120 /* Last Attempt Status Values */
2121 #define LAST_ATTEMPT_STATUS_SUCCESS                     0x00000000
2122 #define LAST_ATTEMPT_STATUS_ERROR_UNSUCCESSFUL          0x00000001
2123 #define LAST_ATTEMPT_STATUS_ERROR_INSUFFICIENT_RESOURCES 0x00000002
2124 #define LAST_ATTEMPT_STATUS_ERROR_INCORRECT_VERSION     0x00000003
2125 #define LAST_ATTEMPT_STATUS_ERROR_INVALID_FORMAT        0x00000004
2126 #define LAST_ATTEMPT_STATUS_ERROR_AUTH_ERROR            0x00000005
2127 #define LAST_ATTEMPT_STATUS_ERROR_PWR_EVT_AC            0x00000006
2128 #define LAST_ATTEMPT_STATUS_ERROR_PWR_EVT_BATT          0x00000007
2129 #define LAST_ATTEMPT_STATUS_ERROR_UNSATISFIED_DEPENDENCIES 0x00000008
2130
2131 /*
2132  * The LastAttemptStatus values of 0x1000 - 0x4000 are reserved for vendor
2133  * usage.
2134  */
2135 #define LAST_ATTEMPT_STATUS_ERROR_UNSUCCESSFUL_VENDOR_RANGE_MIN 0x00001000
2136 #define LAST_ATTEMPT_STATUS_ERROR_UNSUCCESSFUL_VENDOR_RANGE_MAX 0x00004000
2137
2138 /* Certificate types in signature database */
2139 #define EFI_CERT_SHA1_GUID \
2140         EFI_GUID(0x826ca512, 0xcf10, 0x4ac9, 0xb1, 0x87, \
2141                  0xbe, 0x01, 0x49, 0x66, 0x31, 0xbd)
2142 #define EFI_CERT_SHA224_GUID \
2143         EFI_GUID(0xb6e5233, 0xa65c, 0x44c9, 0x94, 0x07, \
2144                  0xd9, 0xab, 0x83, 0xbf, 0xc8, 0xbd)
2145 #define EFI_CERT_SHA256_GUID \
2146         EFI_GUID(0xc1c41626, 0x504c, 0x4092, 0xac, 0xa9, \
2147                  0x41, 0xf9, 0x36, 0x93, 0x43, 0x28)
2148 #define EFI_CERT_SHA384_GUID \
2149         EFI_GUID(0xff3e5307, 0x9fd0, 0x48c9, 0x85, 0xf1, \
2150                  0x8a, 0xd5, 0x6c, 0x70, 0x1e, 0x01)
2151 #define EFI_CERT_SHA512_GUID \
2152         EFI_GUID(0x93e0fae, 0xa6c4, 0x4f50, 0x9f, 0x1b, \
2153                  0xd4, 0x1e, 0x2b, 0x89, 0xc1, 0x9a)
2154 #define EFI_CERT_RSA2048_GUID \
2155         EFI_GUID(0x3c5766e8, 0x269c, 0x4e34, 0xaa, 0x14, \
2156                  0xed, 0x77, 0x6e, 0x85, 0xb3, 0xb6)
2157 #define EFI_CERT_X509_GUID \
2158         EFI_GUID(0xa5c059a1, 0x94e4, 0x4aa7, 0x87, 0xb5, \
2159                  0xab, 0x15, 0x5c, 0x2b, 0xf0, 0x72)
2160 #define EFI_CERT_X509_SHA256_GUID \
2161         EFI_GUID(0x3bd2a492, 0x96c0, 0x4079, 0xb4, 0x20, \
2162                  0xfc, 0xf9, 0x8e, 0xf1, 0x03, 0xed)
2163 #define EFI_CERT_X509_SHA384_GUID \
2164         EFI_GUID(0x7076876e, 0x80c2, 0x4ee6,            \
2165                  0xaa, 0xd2, 0x28, 0xb3, 0x49, 0xa6, 0x86, 0x5b)
2166 #define EFI_CERT_X509_SHA512_GUID \
2167         EFI_GUID(0x446dbf63, 0x2502, 0x4cda,            \
2168                  0xbc, 0xfa, 0x24, 0x65, 0xd2, 0xb0, 0xfe, 0x9d)
2169 #define EFI_CERT_TYPE_PKCS7_GUID \
2170         EFI_GUID(0x4aafd29d, 0x68df, 0x49ee, 0x8a, 0xa9, \
2171                  0x34, 0x7d, 0x37, 0x56, 0x65, 0xa7)
2172
2173 #define EFI_LZMA_COMPRESSED \
2174         EFI_GUID(0xee4e5898, 0x3914, 0x4259, 0x9d, 0x6e, \
2175                  0xdc, 0x7b, 0xd7, 0x94, 0x03, 0xcf)
2176 #define EFI_DXE_SERVICES \
2177         EFI_GUID(0x05ad34ba, 0x6f02, 0x4214, 0x95, 0x2e, \
2178                  0x4d, 0xa0, 0x39, 0x8e, 0x2b, 0xb9)
2179 #define EFI_HOB_LIST \
2180         EFI_GUID(0x7739f24c, 0x93d7, 0x11d4, 0x9a, 0x3a,  \
2181                  0x00, 0x90, 0x27, 0x3f, 0xc1, 0x4d)
2182 #define EFI_MEMORY_TYPE \
2183         EFI_GUID(0x4c19049f, 0x4137, 0x4dd3, 0x9c, 0x10, \
2184                  0x8b, 0x97, 0xa8, 0x3f, 0xfd, 0xfa)
2185 #define EFI_MEM_STATUS_CODE_REC \
2186         EFI_GUID(0x060cc026, 0x4c0d, 0x4dda, 0x8f, 0x41, \
2187                  0x59, 0x5f, 0xef, 0x00, 0xa5, 0x02)
2188 #define EFI_GUID_EFI_ACPI1 \
2189         EFI_GUID(0xeb9d2d30, 0x2d88, 0x11d3,  0x9a, 0x16, \
2190                  0x00, 0x90, 0x27, 0x3f, 0xc1, 0x4d)
2191
2192 /**
2193  * struct win_certificate_uefi_guid - A certificate that encapsulates
2194  * a GUID-specific signature
2195  *
2196  * @hdr:        Windows certificate header
2197  * @cert_type:  Certificate type
2198  * @cert_data:  Certificate data
2199  */
2200 struct win_certificate_uefi_guid {
2201         WIN_CERTIFICATE hdr;
2202         efi_guid_t      cert_type;
2203         u8              cert_data[];
2204 } __attribute__((__packed__));
2205
2206 /**
2207  * struct efi_variable_authentication_2 - A time-based authentication method
2208  * descriptor
2209  *
2210  * This structure describes an authentication information for
2211  * a variable with EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS
2212  * and should be included as part of a variable's value.
2213  * Only EFI_CERT_TYPE_PKCS7_GUID is accepted.
2214  *
2215  * @time_stamp: Descriptor's time stamp
2216  * @auth_info:  Authentication info
2217  */
2218 struct efi_variable_authentication_2 {
2219         struct efi_time                  time_stamp;
2220         struct win_certificate_uefi_guid auth_info;
2221 } __attribute__((__packed__));
2222
2223 /**
2224  * struct efi_firmware_image_authentication - Capsule authentication method
2225  * descriptor
2226  *
2227  * This structure describes an authentication information for
2228  * a capsule with IMAGE_ATTRIBUTE_AUTHENTICATION_REQUIRED set
2229  * and should be included as part of the capsule.
2230  * Only EFI_CERT_TYPE_PKCS7_GUID is accepted.
2231  *
2232  * @monotonic_count: Count to prevent replay
2233  * @auth_info: Authentication info
2234  */
2235 struct efi_firmware_image_authentication {
2236         uint64_t monotonic_count;
2237         struct win_certificate_uefi_guid auth_info;
2238 } __attribute__((__packed__));
2239
2240 /**
2241  * struct efi_signature_data - A format of signature
2242  *
2243  * This structure describes a single signature in signature database.
2244  *
2245  * @signature_owner:    Signature owner
2246  * @signature_data:     Signature data
2247  */
2248 struct efi_signature_data {
2249         efi_guid_t      signature_owner;
2250         u8              signature_data[];
2251 } __attribute__((__packed__));
2252
2253 /**
2254  * struct efi_signature_list - A format of signature database
2255  *
2256  * This structure describes a list of signatures with the same type.
2257  * An authenticated variable's value is a concatenation of one or more
2258  * efi_signature_list's.
2259  *
2260  * @signature_type:             Signature type
2261  * @signature_list_size:        Size of signature list
2262  * @signature_header_size:      Size of signature header
2263  * @signature_size:             Size of signature
2264  */
2265 struct efi_signature_list {
2266         efi_guid_t      signature_type;
2267         u32             signature_list_size;
2268         u32             signature_header_size;
2269         u32             signature_size;
2270 /*      u8              signature_header[signature_header_size]; */
2271 /*      struct efi_signature_data signatures[...][signature_size]; */
2272 } __attribute__((__packed__));
2273
2274 /*
2275  * Firmware management protocol
2276  */
2277 #define EFI_FIRMWARE_MANAGEMENT_PROTOCOL_GUID \
2278         EFI_GUID(0x86c77a67, 0x0b97, 0x4633, 0xa1, 0x87, \
2279                  0x49, 0x10, 0x4d, 0x06, 0x85, 0xc7)
2280
2281 #define IMAGE_ATTRIBUTE_IMAGE_UPDATABLE         0x0000000000000001
2282 #define IMAGE_ATTRIBUTE_RESET_REQUIRED          0x0000000000000002
2283 #define IMAGE_ATTRIBUTE_AUTHENTICATION_REQUIRED 0x0000000000000004
2284 #define IMAGE_ATTRIBUTE_IN_USE                  0x0000000000000008
2285 #define IMAGE_ATTRIBUTE_UEFI_IMAGE              0x0000000000000010
2286 #define IMAGE_ATTRIBUTE_DEPENDENCY              0x0000000000000020
2287
2288 #define IMAGE_COMPATIBILITY_CHECK_SUPPORTED     0x0000000000000001
2289
2290 #define IMAGE_UPDATABLE_VALID                   0x0000000000000001
2291 #define IMAGE_UPDATABLE_INVALID                 0x0000000000000002
2292 #define IMAGE_UPDATABLE_INVALID_TYPE            0x0000000000000004
2293 #define IMAGE_UPDATABLE_INVALID_OLLD            0x0000000000000008
2294 #define IMAGE_UPDATABLE_VALID_WITH_VENDOR_CODE  0x0000000000000010
2295
2296 #define PACKAGE_ATTRIBUTE_VERSION_UPDATABLE             0x0000000000000001
2297 #define PACKAGE_ATTRIBUTE_RESET_REQUIRED                0x0000000000000002
2298 #define PACKAGE_ATTRIBUTE_AUTHENTICATION_REQUIRED       0x0000000000000004
2299
2300 #define EFI_FIRMWARE_IMAGE_DESCRIPTOR_VERSION   4
2301
2302 typedef struct efi_firmware_image_dependencies {
2303         u8 dependencies[0];
2304 } efi_firmware_image_dep_t;
2305
2306 struct efi_firmware_image_descriptor {
2307         u8 image_index;
2308         efi_guid_t image_type_id;
2309         u64 image_id;
2310         u16 *image_id_name;
2311         u32 version;
2312         u16 *version_name;
2313         efi_uintn_t size;
2314         u64 attributes_supported;
2315         u64 attributes_setting;
2316         u64 compatibilities;
2317         u32 lowest_supported_image_version;
2318         u32 last_attempt_version;
2319         u32 last_attempt_status;
2320         u64 hardware_instance;
2321         efi_firmware_image_dep_t *dependencies;
2322 };
2323
2324 struct efi_firmware_management_protocol {
2325         efi_status_t (EFIAPI *get_image_info)(
2326                         struct efi_firmware_management_protocol *this,
2327                         efi_uintn_t *image_info_size,
2328                         struct efi_firmware_image_descriptor *image_info,
2329                         u32 *descriptor_version,
2330                         u8 *descriptor_count,
2331                         efi_uintn_t *descriptor_size,
2332                         u32 *package_version,
2333                         u16 **package_version_name);
2334         efi_status_t (EFIAPI *get_image)(
2335                         struct efi_firmware_management_protocol *this,
2336                         u8 image_index,
2337                         void *image,
2338                         efi_uintn_t *image_size);
2339         efi_status_t (EFIAPI *set_image)(
2340                         struct efi_firmware_management_protocol *this,
2341                         u8 image_index,
2342                         const void *image,
2343                         efi_uintn_t image_size,
2344                         const void *vendor_code,
2345                         efi_status_t (*progress)(efi_uintn_t completion),
2346                         u16 **abort_reason);
2347         efi_status_t (EFIAPI *check_image)(
2348                         struct efi_firmware_management_protocol *this,
2349                         u8 image_index,
2350                         const void *image,
2351                         efi_uintn_t *image_size,
2352                         u32 *image_updatable);
2353         efi_status_t (EFIAPI *get_package_info)(
2354                         struct efi_firmware_management_protocol *this,
2355                         u32 *package_version,
2356                         u16 **package_version_name,
2357                         u32 *package_version_name_maxlen,
2358                         u64 *attributes_supported,
2359                         u64 *attributes_setting);
2360         efi_status_t (EFIAPI *set_package_info)(
2361                         struct efi_firmware_management_protocol *this,
2362                         const void *image,
2363                         efi_uintn_t *image_size,
2364                         const void *vendor_code,
2365                         u32 package_version,
2366                         const u16 *package_version_name);
2367 };
2368
2369 #define EFI_DISK_IO_PROTOCOL_GUID       \
2370         EFI_GUID(0xce345171, 0xba0b, 0x11d2, 0x8e, 0x4f, \
2371                  0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b)
2372
2373 struct efi_disk {
2374         u64 revision;
2375         efi_status_t (EFIAPI *read_disk)(struct efi_disk *this, u32 media_id,
2376                                          u64 offset, efi_uintn_t buffer_size,
2377                                          void *buffer);
2378
2379         efi_status_t (EFIAPI *write_disk)(struct efi_disk *this, u32 media_id,
2380                                           u64 offset, efi_uintn_t buffer_size,
2381                                           void *buffer);
2382 };
2383
2384 #endif
This page took 0.158285 seconds and 4 git commands to generate.