]> git.sur5r.net Git - u-boot/blob - include/efi_api.h
efi_loader: correcty determine total device path length
[u-boot] / include / efi_api.h
1 /*
2  * Extensible Firmware Interface
3  * Based on 'Extensible Firmware Interface Specification' version 0.9,
4  * April 30, 1999
5  *
6  * Copyright (C) 1999 VA Linux Systems
7  * Copyright (C) 1999 Walt Drummond <drummond@valinux.com>
8  * Copyright (C) 1999, 2002-2003 Hewlett-Packard Co.
9  *      David Mosberger-Tang <davidm@hpl.hp.com>
10  *      Stephane Eranian <eranian@hpl.hp.com>
11  *
12  * From include/linux/efi.h in kernel 4.1 with some additions/subtractions
13  */
14
15 #ifndef _EFI_API_H
16 #define _EFI_API_H
17
18 #include <efi.h>
19
20 #ifdef CONFIG_EFI_LOADER
21 #include <asm/setjmp.h>
22 #endif
23
24 /* Types and defines for EFI CreateEvent */
25 enum efi_timer_delay {
26         EFI_TIMER_STOP = 0,
27         EFI_TIMER_PERIODIC = 1,
28         EFI_TIMER_RELATIVE = 2
29 };
30
31 #define efi_uintn_t size_t
32 typedef uint16_t *efi_string_t;
33
34 #define EVT_TIMER                               0x80000000
35 #define EVT_RUNTIME                             0x40000000
36 #define EVT_NOTIFY_WAIT                         0x00000100
37 #define EVT_NOTIFY_SIGNAL                       0x00000200
38 #define EVT_SIGNAL_EXIT_BOOT_SERVICES           0x00000201
39 #define EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE       0x60000202
40
41 #define TPL_APPLICATION         0x04
42 #define TPL_CALLBACK            0x08
43 #define TPL_NOTIFY              0x10
44 #define TPL_HIGH_LEVEL          0x1F
45
46 struct efi_event;
47
48 /* EFI Boot Services table */
49 struct efi_boot_services {
50         struct efi_table_hdr hdr;
51         efi_status_t (EFIAPI *raise_tpl)(efi_uintn_t new_tpl);
52         void (EFIAPI *restore_tpl)(efi_uintn_t old_tpl);
53
54         efi_status_t (EFIAPI *allocate_pages)(int, int, efi_uintn_t,
55                                               efi_physical_addr_t *);
56         efi_status_t (EFIAPI *free_pages)(efi_physical_addr_t, efi_uintn_t);
57         efi_status_t (EFIAPI *get_memory_map)(efi_uintn_t *memory_map_size,
58                                               struct efi_mem_desc *desc,
59                                               efi_uintn_t *key,
60                                               efi_uintn_t *desc_size,
61                                               u32 *desc_version);
62         efi_status_t (EFIAPI *allocate_pool)(int, efi_uintn_t, void **);
63         efi_status_t (EFIAPI *free_pool)(void *);
64
65         efi_status_t (EFIAPI *create_event)(uint32_t type,
66                         efi_uintn_t notify_tpl,
67                         void (EFIAPI *notify_function) (
68                                         struct efi_event *event,
69                                         void *context),
70                         void *notify_context, struct efi_event **event);
71         efi_status_t (EFIAPI *set_timer)(struct efi_event *event,
72                                          enum efi_timer_delay type,
73                                          uint64_t trigger_time);
74         efi_status_t (EFIAPI *wait_for_event)(efi_uintn_t number_of_events,
75                                               struct efi_event **event,
76                                               efi_uintn_t *index);
77         efi_status_t (EFIAPI *signal_event)(struct efi_event *event);
78         efi_status_t (EFIAPI *close_event)(struct efi_event *event);
79         efi_status_t (EFIAPI *check_event)(struct efi_event *event);
80 #define EFI_NATIVE_INTERFACE    0x00000000
81         efi_status_t (EFIAPI *install_protocol_interface)(
82                         void **handle, const efi_guid_t *protocol,
83                         int protocol_interface_type, void *protocol_interface);
84         efi_status_t (EFIAPI *reinstall_protocol_interface)(
85                         void *handle, const efi_guid_t *protocol,
86                         void *old_interface, void *new_interface);
87         efi_status_t (EFIAPI *uninstall_protocol_interface)(
88                         efi_handle_t handle, const efi_guid_t *protocol,
89                         void *protocol_interface);
90         efi_status_t (EFIAPI *handle_protocol)(
91                         efi_handle_t handle, const efi_guid_t *protocol,
92                         void **protocol_interface);
93         void *reserved;
94         efi_status_t (EFIAPI *register_protocol_notify)(
95                         const efi_guid_t *protocol, struct efi_event *event,
96                         void **registration);
97         efi_status_t (EFIAPI *locate_handle)(
98                         enum efi_locate_search_type search_type,
99                         const efi_guid_t *protocol, void *search_key,
100                         efi_uintn_t *buffer_size, efi_handle_t *buffer);
101         efi_status_t (EFIAPI *locate_device_path)(const efi_guid_t *protocol,
102                         struct efi_device_path **device_path,
103                         efi_handle_t *device);
104         efi_status_t (EFIAPI *install_configuration_table)(
105                         efi_guid_t *guid, void *table);
106
107         efi_status_t (EFIAPI *load_image)(bool boot_policiy,
108                         efi_handle_t parent_image,
109                         struct efi_device_path *file_path, void *source_buffer,
110                         efi_uintn_t source_size, efi_handle_t *image);
111         efi_status_t (EFIAPI *start_image)(efi_handle_t handle,
112                                            unsigned long *exitdata_size,
113                                            s16 **exitdata);
114         efi_status_t (EFIAPI *exit)(efi_handle_t handle,
115                                     efi_status_t exit_status,
116                                     unsigned long exitdata_size, s16 *exitdata);
117         efi_status_t (EFIAPI *unload_image)(efi_handle_t image_handle);
118         efi_status_t (EFIAPI *exit_boot_services)(efi_handle_t, unsigned long);
119
120         efi_status_t (EFIAPI *get_next_monotonic_count)(u64 *count);
121         efi_status_t (EFIAPI *stall)(unsigned long usecs);
122         efi_status_t (EFIAPI *set_watchdog_timer)(unsigned long timeout,
123                         uint64_t watchdog_code, unsigned long data_size,
124                         uint16_t *watchdog_data);
125         efi_status_t(EFIAPI *connect_controller)(efi_handle_t controller_handle,
126                         efi_handle_t *driver_image_handle,
127                         struct efi_device_path *remaining_device_path,
128                         bool recursive);
129         efi_status_t (EFIAPI *disconnect_controller)(
130                         efi_handle_t controller_handle,
131                         efi_handle_t driver_image_handle,
132                         efi_handle_t child_handle);
133 #define EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL  0x00000001
134 #define EFI_OPEN_PROTOCOL_GET_PROTOCOL        0x00000002
135 #define EFI_OPEN_PROTOCOL_TEST_PROTOCOL       0x00000004
136 #define EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER 0x00000008
137 #define EFI_OPEN_PROTOCOL_BY_DRIVER           0x00000010
138 #define EFI_OPEN_PROTOCOL_EXCLUSIVE           0x00000020
139         efi_status_t (EFIAPI *open_protocol)(efi_handle_t handle,
140                         const efi_guid_t *protocol, void **interface,
141                         efi_handle_t agent_handle,
142                         efi_handle_t controller_handle, u32 attributes);
143         efi_status_t (EFIAPI *close_protocol)(
144                         efi_handle_t handle, const efi_guid_t *protocol,
145                         efi_handle_t agent_handle,
146                         efi_handle_t controller_handle);
147         efi_status_t(EFIAPI *open_protocol_information)(efi_handle_t handle,
148                         const efi_guid_t *protocol,
149                         struct efi_open_protocol_info_entry **entry_buffer,
150                         efi_uintn_t *entry_count);
151         efi_status_t (EFIAPI *protocols_per_handle)(efi_handle_t handle,
152                         efi_guid_t ***protocol_buffer,
153                         efi_uintn_t *protocols_buffer_count);
154         efi_status_t (EFIAPI *locate_handle_buffer) (
155                         enum efi_locate_search_type search_type,
156                         const efi_guid_t *protocol, void *search_key,
157                         efi_uintn_t *no_handles, efi_handle_t **buffer);
158         efi_status_t (EFIAPI *locate_protocol)(const efi_guid_t *protocol,
159                         void *registration, void **protocol_interface);
160         efi_status_t (EFIAPI *install_multiple_protocol_interfaces)(
161                         void **handle, ...);
162         efi_status_t (EFIAPI *uninstall_multiple_protocol_interfaces)(
163                         void *handle, ...);
164         efi_status_t (EFIAPI *calculate_crc32)(void *data,
165                         unsigned long data_size, uint32_t *crc32);
166         void (EFIAPI *copy_mem)(void *destination, const void *source,
167                         size_t length);
168         void (EFIAPI *set_mem)(void *buffer, size_t size, uint8_t value);
169         efi_status_t (EFIAPI *create_event_ex)(
170                                 uint32_t type, efi_uintn_t notify_tpl,
171                                 void (EFIAPI *notify_function) (
172                                         struct efi_event *event,
173                                         void *context),
174                                 void *notify_context,
175                                 efi_guid_t *event_group,
176                                 struct efi_event **event);
177 };
178
179 /* Types and defines for EFI ResetSystem */
180 enum efi_reset_type {
181         EFI_RESET_COLD = 0,
182         EFI_RESET_WARM = 1,
183         EFI_RESET_SHUTDOWN = 2,
184         EFI_RESET_PLATFORM_SPECIFIC = 3,
185 };
186
187 /* EFI Runtime Services table */
188 #define EFI_RUNTIME_SERVICES_SIGNATURE  0x5652453544e5552ULL
189 #define EFI_RUNTIME_SERVICES_REVISION   0x00010000
190
191 #define CAPSULE_FLAGS_PERSIST_ACROSS_RESET      0x00010000
192 #define CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE     0x00020000
193 #define CAPSULE_FLAGS_INITIATE_RESET            0x00040000
194
195 struct efi_capsule_header {
196         efi_guid_t *capsule_guid;
197         u32 header_size;
198         u32 flags;
199         u32 capsule_image_size;
200 };
201
202 struct efi_runtime_services {
203         struct efi_table_hdr hdr;
204         efi_status_t (EFIAPI *get_time)(struct efi_time *time,
205                         struct efi_time_cap *capabilities);
206         efi_status_t (EFIAPI *set_time)(struct efi_time *time);
207         efi_status_t (EFIAPI *get_wakeup_time)(char *enabled, char *pending,
208                         struct efi_time *time);
209         efi_status_t (EFIAPI *set_wakeup_time)(char enabled,
210                         struct efi_time *time);
211         efi_status_t (EFIAPI *set_virtual_address_map)(
212                         unsigned long memory_map_size,
213                         unsigned long descriptor_size,
214                         uint32_t descriptor_version,
215                         struct efi_mem_desc *virtmap);
216         efi_status_t (*convert_pointer)(unsigned long dbg, void **address);
217         efi_status_t (EFIAPI *get_variable)(s16 *variable_name,
218                         efi_guid_t *vendor, u32 *attributes,
219                         unsigned long *data_size, void *data);
220         efi_status_t (EFIAPI *get_next_variable)(
221                         unsigned long *variable_name_size,
222                         s16 *variable_name, efi_guid_t *vendor);
223         efi_status_t (EFIAPI *set_variable)(s16 *variable_name,
224                         efi_guid_t *vendor, u32 attributes,
225                         unsigned long data_size, void *data);
226         efi_status_t (EFIAPI *get_next_high_mono_count)(
227                         uint32_t *high_count);
228         void (EFIAPI *reset_system)(enum efi_reset_type reset_type,
229                                     efi_status_t reset_status,
230                                     unsigned long data_size, void *reset_data);
231         efi_status_t (EFIAPI *update_capsule)(
232                         struct efi_capsule_header **capsule_header_array,
233                         efi_uintn_t capsule_count,
234                         u64 scatter_gather_list);
235         efi_status_t (EFIAPI *query_capsule_caps)(
236                         struct efi_capsule_header **capsule_header_array,
237                         efi_uintn_t capsule_count,
238                         u64 maximum_capsule_size,
239                         u32 reset_type);
240         efi_status_t (EFIAPI *query_variable_info)(
241                         u32 attributes,
242                         u64 maximum_variable_storage_size,
243                         u64 remaining_variable_storage_size,
244                         u64 maximum_variable_size);
245 };
246
247 /* EFI event group GUID definitions */
248 #define EFI_EVENT_GROUP_EXIT_BOOT_SERVICES \
249         EFI_GUID(0x27abf055, 0xb1b8, 0x4c26, 0x80, 0x48, \
250                  0x74, 0x8f, 0x37, 0xba, 0xa2, 0xdf)
251
252 #define EFI_EVENT_GROUP_VIRTUAL_ADDRESS_CHANGE \
253         EFI_GUID(0x13fa7698, 0xc831, 0x49c7, 0x87, 0xea, \
254                  0x8f, 0x43, 0xfc, 0xc2, 0x51, 0x96)
255
256 #define EFI_EVENT_GROUP_MEMORY_MAP_CHANGE \
257         EFI_GUID(0x78bee926, 0x692f, 0x48fd, 0x9e, 0xdb, \
258                  0x01, 0x42, 0x2e, 0xf0, 0xd7, 0xab)
259
260 #define EFI_EVENT_GROUP_READY_TO_BOOT \
261         EFI_GUID(0x7ce88fb3, 0x4bd7, 0x4679, 0x87, 0xa8, \
262                  0xa8, 0xd8, 0xde, 0xe5, 0x0d, 0x2b)
263
264 #define EFI_EVENT_GROUP_RESET_SYSTEM \
265         EFI_GUID(0x62da6a56, 0x13fb, 0x485a, 0xa8, 0xda, \
266                  0xa3, 0xdd, 0x79, 0x12, 0xcb, 0x6b)
267
268 /* EFI Configuration Table and GUID definitions */
269 #define NULL_GUID \
270         EFI_GUID(0x00000000, 0x0000, 0x0000, 0x00, 0x00, \
271                  0x00, 0x00, 0x00, 0x00, 0x00, 0x00)
272
273 #define EFI_GLOBAL_VARIABLE_GUID \
274         EFI_GUID(0x8be4df61, 0x93ca, 0x11d2, 0xaa, 0x0d, \
275                  0x00, 0xe0, 0x98, 0x03, 0x2b, 0x8c)
276
277 #define LOADED_IMAGE_PROTOCOL_GUID \
278         EFI_GUID(0x5b1b31a1, 0x9562, 0x11d2, 0x8e, 0x3f, \
279                  0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b)
280
281 #define EFI_FDT_GUID \
282         EFI_GUID(0xb1b621d5, 0xf19c, 0x41a5, \
283                  0x83, 0x0b, 0xd9, 0x15, 0x2c, 0x69, 0xaa, 0xe0)
284
285 #define SMBIOS_TABLE_GUID \
286         EFI_GUID(0xeb9d2d31, 0x2d88, 0x11d3,  \
287                  0x9a, 0x16, 0x00, 0x90, 0x27, 0x3f, 0xc1, 0x4d)
288
289 struct efi_configuration_table
290 {
291         efi_guid_t guid;
292         void *table;
293 };
294
295 #define EFI_SYSTEM_TABLE_SIGNATURE ((u64)0x5453595320494249ULL)
296
297 struct efi_system_table {
298         struct efi_table_hdr hdr;
299         unsigned long fw_vendor;   /* physical addr of wchar_t vendor string */
300         u32 fw_revision;
301         efi_handle_t con_in_handle;
302         struct efi_simple_input_interface *con_in;
303         efi_handle_t con_out_handle;
304         struct efi_simple_text_output_protocol *con_out;
305         efi_handle_t stderr_handle;
306         struct efi_simple_text_output_protocol *std_err;
307         struct efi_runtime_services *runtime;
308         struct efi_boot_services *boottime;
309         efi_uintn_t nr_tables;
310         struct efi_configuration_table *tables;
311 };
312
313 #define LOADED_IMAGE_GUID \
314         EFI_GUID(0x5b1b31a1, 0x9562, 0x11d2, \
315                  0x8e, 0x3f, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b)
316
317 struct efi_loaded_image {
318         u32 revision;
319         void *parent_handle;
320         struct efi_system_table *system_table;
321         efi_handle_t device_handle;
322         struct efi_device_path *file_path;
323         void *reserved;
324         u32 load_options_size;
325         void *load_options;
326         void *image_base;
327         aligned_u64 image_size;
328         unsigned int image_code_type;
329         unsigned int image_data_type;
330         unsigned long unload;
331
332         /* Below are efi loader private fields */
333 #ifdef CONFIG_EFI_LOADER
334         void *reloc_base;
335         aligned_u64 reloc_size;
336         efi_status_t exit_status;
337         struct jmp_buf_data exit_jmp;
338 #endif
339 };
340
341 #define DEVICE_PATH_GUID \
342         EFI_GUID(0x09576e91, 0x6d3f, 0x11d2, \
343                  0x8e, 0x39, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b )
344
345 #define DEVICE_PATH_TYPE_END                    0x7f
346 #  define DEVICE_PATH_SUB_TYPE_END              0xff
347
348 struct efi_device_path {
349         u8 type;
350         u8 sub_type;
351         u16 length;
352 } __packed;
353
354 struct efi_mac_addr {
355         u8 addr[32];
356 } __packed;
357
358 #define DEVICE_PATH_TYPE_HARDWARE_DEVICE        0x01
359 #  define DEVICE_PATH_SUB_TYPE_MEMORY           0x03
360 #  define DEVICE_PATH_SUB_TYPE_VENDOR           0x04
361
362 struct efi_device_path_memory {
363         struct efi_device_path dp;
364         u32 memory_type;
365         u64 start_address;
366         u64 end_address;
367 } __packed;
368
369 struct efi_device_path_vendor {
370         struct efi_device_path dp;
371         efi_guid_t guid;
372         u8 vendor_data[];
373 } __packed;
374
375 #define DEVICE_PATH_TYPE_ACPI_DEVICE            0x02
376 #  define DEVICE_PATH_SUB_TYPE_ACPI_DEVICE      0x01
377
378 #define EFI_PNP_ID(ID)                          (u32)(((ID) << 16) | 0x41D0)
379 #define EISA_PNP_ID(ID)                         EFI_PNP_ID(ID)
380 #define EISA_PNP_NUM(ID)                        ((ID) >> 16)
381
382 struct efi_device_path_acpi_path {
383         struct efi_device_path dp;
384         u32 hid;
385         u32 uid;
386 } __packed;
387
388 #define DEVICE_PATH_TYPE_MESSAGING_DEVICE       0x03
389 #  define DEVICE_PATH_SUB_TYPE_MSG_ATAPI        0x01
390 #  define DEVICE_PATH_SUB_TYPE_MSG_SCSI         0x02
391 #  define DEVICE_PATH_SUB_TYPE_MSG_USB          0x05
392 #  define DEVICE_PATH_SUB_TYPE_MSG_MAC_ADDR     0x0b
393 #  define DEVICE_PATH_SUB_TYPE_MSG_USB_CLASS    0x0f
394 #  define DEVICE_PATH_SUB_TYPE_MSG_SD           0x1a
395 #  define DEVICE_PATH_SUB_TYPE_MSG_MMC          0x1d
396
397 struct efi_device_path_atapi {
398         struct efi_device_path dp;
399         u8 primary_secondary;
400         u8 slave_master;
401         u16 logical_unit_number;
402 } __packed;
403
404 struct efi_device_path_scsi {
405         struct efi_device_path dp;
406         u16 target_id;
407         u16 logical_unit_number;
408 } __packed;
409
410 struct efi_device_path_usb {
411         struct efi_device_path dp;
412         u8 parent_port_number;
413         u8 usb_interface;
414 } __packed;
415
416 struct efi_device_path_mac_addr {
417         struct efi_device_path dp;
418         struct efi_mac_addr mac;
419         u8 if_type;
420 } __packed;
421
422 struct efi_device_path_usb_class {
423         struct efi_device_path dp;
424         u16 vendor_id;
425         u16 product_id;
426         u8 device_class;
427         u8 device_subclass;
428         u8 device_protocol;
429 } __packed;
430
431 struct efi_device_path_sd_mmc_path {
432         struct efi_device_path dp;
433         u8 slot_number;
434 } __packed;
435
436 #define DEVICE_PATH_TYPE_MEDIA_DEVICE           0x04
437 #  define DEVICE_PATH_SUB_TYPE_HARD_DRIVE_PATH  0x01
438 #  define DEVICE_PATH_SUB_TYPE_CDROM_PATH       0x02
439 #  define DEVICE_PATH_SUB_TYPE_FILE_PATH        0x04
440
441 struct efi_device_path_hard_drive_path {
442         struct efi_device_path dp;
443         u32 partition_number;
444         u64 partition_start;
445         u64 partition_end;
446         u8 partition_signature[16];
447         u8 partmap_type;
448         u8 signature_type;
449 } __packed;
450
451 struct efi_device_path_cdrom_path {
452         struct efi_device_path dp;
453         u32 boot_entry;
454         u64 partition_start;
455         u64 partition_end;
456 } __packed;
457
458 struct efi_device_path_file_path {
459         struct efi_device_path dp;
460         u16 str[];
461 } __packed;
462
463 #define BLOCK_IO_GUID \
464         EFI_GUID(0x964e5b21, 0x6459, 0x11d2, \
465                  0x8e, 0x39, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b)
466
467 struct efi_block_io_media
468 {
469         u32 media_id;
470         char removable_media;
471         char media_present;
472         char logical_partition;
473         char read_only;
474         char write_caching;
475         u8 pad[3];
476         u32 block_size;
477         u32 io_align;
478         u8 pad2[4];
479         u64 last_block;
480         /* Added in revision 2 of the protocol */
481         u64 lowest_aligned_lba;
482         u32 logical_blocks_per_physical_block;
483         /* Added in revision 3 of the protocol */
484         u32 optimal_transfer_length_granualarity;
485 };
486
487 #define EFI_BLOCK_IO_PROTOCOL_REVISION2 0x00020001
488 #define EFI_BLOCK_IO_PROTOCOL_REVISION3 0x0002001f
489
490 struct efi_block_io {
491         u64 revision;
492         struct efi_block_io_media *media;
493         efi_status_t (EFIAPI *reset)(struct efi_block_io *this,
494                         char extended_verification);
495         efi_status_t (EFIAPI *read_blocks)(struct efi_block_io *this,
496                         u32 media_id, u64 lba, efi_uintn_t buffer_size,
497                         void *buffer);
498         efi_status_t (EFIAPI *write_blocks)(struct efi_block_io *this,
499                         u32 media_id, u64 lba, efi_uintn_t buffer_size,
500                         void *buffer);
501         efi_status_t (EFIAPI *flush_blocks)(struct efi_block_io *this);
502 };
503
504 struct simple_text_output_mode {
505         s32 max_mode;
506         s32 mode;
507         s32 attribute;
508         s32 cursor_column;
509         s32 cursor_row;
510         bool cursor_visible;
511 };
512
513
514 #define EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL_GUID \
515         EFI_GUID(0x387477c2, 0x69c7, 0x11d2, \
516                  0x8e, 0x39, 0x0, 0xa0, 0xc9, 0x69, 0x72, 0x3b)
517
518 #define EFI_BLACK                0x00
519 #define EFI_BLUE                 0x01
520 #define EFI_GREEN                0x02
521 #define EFI_CYAN                 0x03
522 #define EFI_RED                  0x04
523 #define EFI_MAGENTA              0x05
524 #define EFI_BROWN                0x06
525 #define EFI_LIGHTGRAY            0x07
526 #define EFI_BRIGHT               0x08
527 #define EFI_DARKGRAY             0x08
528 #define EFI_LIGHTBLUE            0x09
529 #define EFI_LIGHTGREEN           0x0a
530 #define EFI_LIGHTCYAN            0x0b
531 #define EFI_LIGHTRED             0x0c
532 #define EFI_LIGHTMAGENTA         0x0d
533 #define EFI_YELLOW               0x0e
534 #define EFI_WHITE                0x0f
535 #define EFI_BACKGROUND_BLACK     0x00
536 #define EFI_BACKGROUND_BLUE      0x10
537 #define EFI_BACKGROUND_GREEN     0x20
538 #define EFI_BACKGROUND_CYAN      0x30
539 #define EFI_BACKGROUND_RED       0x40
540 #define EFI_BACKGROUND_MAGENTA   0x50
541 #define EFI_BACKGROUND_BROWN     0x60
542 #define EFI_BACKGROUND_LIGHTGRAY 0x70
543
544 /* extract foreground color from EFI attribute */
545 #define EFI_ATTR_FG(attr)        ((attr) & 0x07)
546 /* treat high bit of FG as bright/bold (similar to edk2) */
547 #define EFI_ATTR_BOLD(attr)      (((attr) >> 3) & 0x01)
548 /* extract background color from EFI attribute */
549 #define EFI_ATTR_BG(attr)        (((attr) >> 4) & 0x7)
550
551 struct efi_simple_text_output_protocol {
552         void *reset;
553         efi_status_t (EFIAPI *output_string)(
554                         struct efi_simple_text_output_protocol *this,
555                         const efi_string_t str);
556         efi_status_t (EFIAPI *test_string)(
557                         struct efi_simple_text_output_protocol *this,
558                         const efi_string_t str);
559         efi_status_t(EFIAPI *query_mode)(
560                         struct efi_simple_text_output_protocol *this,
561                         unsigned long mode_number, unsigned long *columns,
562                         unsigned long *rows);
563         efi_status_t(EFIAPI *set_mode)(
564                         struct efi_simple_text_output_protocol *this,
565                         unsigned long mode_number);
566         efi_status_t(EFIAPI *set_attribute)(
567                         struct efi_simple_text_output_protocol *this,
568                         unsigned long attribute);
569         efi_status_t(EFIAPI *clear_screen) (
570                         struct efi_simple_text_output_protocol *this);
571         efi_status_t(EFIAPI *set_cursor_position) (
572                         struct efi_simple_text_output_protocol *this,
573                         unsigned long column, unsigned long row);
574         efi_status_t(EFIAPI *enable_cursor)(
575                         struct efi_simple_text_output_protocol *this,
576                         bool enable);
577         struct simple_text_output_mode *mode;
578 };
579
580 struct efi_input_key {
581         u16 scan_code;
582         s16 unicode_char;
583 };
584
585 #define EFI_SIMPLE_TEXT_INPUT_PROTOCOL_GUID \
586         EFI_GUID(0x387477c1, 0x69c7, 0x11d2, \
587                  0x8e, 0x39, 0x0, 0xa0, 0xc9, 0x69, 0x72, 0x3b)
588
589 struct efi_simple_input_interface {
590         efi_status_t(EFIAPI *reset)(struct efi_simple_input_interface *this,
591                         bool ExtendedVerification);
592         efi_status_t(EFIAPI *read_key_stroke)(
593                         struct efi_simple_input_interface *this,
594                         struct efi_input_key *key);
595         struct efi_event *wait_for_key;
596 };
597
598 #define EFI_DEVICE_PATH_TO_TEXT_PROTOCOL_GUID \
599         EFI_GUID(0x8b843e20, 0x8132, 0x4852, \
600                  0x90, 0xcc, 0x55, 0x1a, 0x4e, 0x4a, 0x7f, 0x1c)
601
602 struct efi_device_path_to_text_protocol
603 {
604         uint16_t *(EFIAPI *convert_device_node_to_text)(
605                         struct efi_device_path *device_node,
606                         bool display_only,
607                         bool allow_shortcuts);
608         uint16_t *(EFIAPI *convert_device_path_to_text)(
609                         struct efi_device_path *device_path,
610                         bool display_only,
611                         bool allow_shortcuts);
612 };
613
614 #define EFI_DEVICE_PATH_UTILITIES_PROTOCOL_GUID \
615         EFI_GUID(0x0379be4e, 0xd706, 0x437d, \
616                  0xb0, 0x37, 0xed, 0xb8, 0x2f, 0xb7, 0x72, 0xa4)
617
618 struct efi_device_path_utilities_protocol {
619         efi_uintn_t (EFIAPI *get_device_path_size)(
620                 const struct efi_device_path *device_path);
621         struct efi_device_path *(EFIAPI *duplicate_device_path)(
622                 const struct efi_device_path *device_path);
623         struct efi_device_path *(EFIAPI *append_device_path)(
624                 const struct efi_device_path *src1,
625                 const struct efi_device_path *src2);
626         struct efi_device_path *(EFIAPI *append_device_node)(
627                 const struct efi_device_path *device_path,
628                 const struct efi_device_path *device_node);
629         struct efi_device_path *(EFIAPI *append_device_path_instance)(
630                 const struct efi_device_path *device_path,
631                 const struct efi_device_path *device_path_instance);
632         struct efi_device_path *(EFIAPI *get_next_device_path_instance)(
633                 struct efi_device_path **device_path_instance,
634                 efi_uintn_t *device_path_instance_size);
635         bool (EFIAPI *is_device_path_multi_instance)(
636                 const struct efi_device_path *device_path);
637         struct efi_device_path *(EFIAPI *create_device_node)(
638                 uint8_t node_type,
639                 uint8_t node_sub_type,
640                 uint16_t node_length);
641 };
642
643 #define EFI_GOP_GUID \
644         EFI_GUID(0x9042a9de, 0x23dc, 0x4a38, \
645                  0x96, 0xfb, 0x7a, 0xde, 0xd0, 0x80, 0x51, 0x6a)
646
647 #define EFI_GOT_RGBA8           0
648 #define EFI_GOT_BGRA8           1
649 #define EFI_GOT_BITMASK         2
650
651 struct efi_gop_mode_info
652 {
653         u32 version;
654         u32 width;
655         u32 height;
656         u32 pixel_format;
657         u32 pixel_bitmask[4];
658         u32 pixels_per_scanline;
659 };
660
661 struct efi_gop_mode
662 {
663         u32 max_mode;
664         u32 mode;
665         struct efi_gop_mode_info *info;
666         unsigned long info_size;
667         efi_physical_addr_t fb_base;
668         unsigned long fb_size;
669 };
670
671 struct efi_gop_pixel {
672         u8 blue;
673         u8 green;
674         u8 red;
675         u8 reserved;
676 };
677
678 #define EFI_BLT_VIDEO_FILL              0
679 #define EFI_BLT_VIDEO_TO_BLT_BUFFER     1
680 #define EFI_BLT_BUFFER_TO_VIDEO         2
681 #define EFI_BLT_VIDEO_TO_VIDEO          3
682
683 struct efi_gop
684 {
685         efi_status_t (EFIAPI *query_mode)(struct efi_gop *this, u32 mode_number,
686                                           efi_uintn_t *size_of_info,
687                                           struct efi_gop_mode_info **info);
688         efi_status_t (EFIAPI *set_mode)(struct efi_gop *this, u32 mode_number);
689         efi_status_t (EFIAPI *blt)(struct efi_gop *this,
690                                    struct efi_gop_pixel *buffer,
691                                    u32 operation, efi_uintn_t sx,
692                                    efi_uintn_t sy, efi_uintn_t dx,
693                                    efi_uintn_t dy, efi_uintn_t width,
694                                    efi_uintn_t height, efi_uintn_t delta);
695         struct efi_gop_mode *mode;
696 };
697
698 #define EFI_SIMPLE_NETWORK_GUID \
699         EFI_GUID(0xa19832b9, 0xac25, 0x11d3, \
700                  0x9a, 0x2d, 0x00, 0x90, 0x27, 0x3f, 0xc1, 0x4d)
701
702 struct efi_mac_address {
703         char mac_addr[32];
704 };
705
706 struct efi_ip_address {
707         u8 ip_addr[16];
708 } __attribute__((aligned(4)));
709
710 enum efi_simple_network_state {
711         EFI_NETWORK_STOPPED,
712         EFI_NETWORK_STARTED,
713         EFI_NETWORK_INITIALIZED,
714 };
715
716 struct efi_simple_network_mode {
717         enum efi_simple_network_state state;
718         u32 hwaddr_size;
719         u32 media_header_size;
720         u32 max_packet_size;
721         u32 nvram_size;
722         u32 nvram_access_size;
723         u32 receive_filter_mask;
724         u32 receive_filter_setting;
725         u32 max_mcast_filter_count;
726         u32 mcast_filter_count;
727         struct efi_mac_address mcast_filter[16];
728         struct efi_mac_address current_address;
729         struct efi_mac_address broadcast_address;
730         struct efi_mac_address permanent_address;
731         u8 if_type;
732         u8 mac_changeable;
733         u8 multitx_supported;
734         u8 media_present_supported;
735         u8 media_present;
736 };
737
738 /* receive_filters bit mask */
739 #define EFI_SIMPLE_NETWORK_RECEIVE_UNICAST               0x01
740 #define EFI_SIMPLE_NETWORK_RECEIVE_MULTICAST             0x02
741 #define EFI_SIMPLE_NETWORK_RECEIVE_BROADCAST             0x04
742 #define EFI_SIMPLE_NETWORK_RECEIVE_PROMISCUOUS           0x08
743 #define EFI_SIMPLE_NETWORK_RECEIVE_PROMISCUOUS_MULTICAST 0x10
744
745 /* interrupt status bit mask */
746 #define EFI_SIMPLE_NETWORK_RECEIVE_INTERRUPT    0x01
747 #define EFI_SIMPLE_NETWORK_TRANSMIT_INTERRUPT   0x02
748 #define EFI_SIMPLE_NETWORK_COMMAND_INTERRUPT    0x04
749 #define EFI_SIMPLE_NETWORK_SOFTWARE_INTERRUPT   0x08
750
751 /* revision of the simple network protocol */
752 #define EFI_SIMPLE_NETWORK_PROTOCOL_REVISION    0x00010000
753
754 struct efi_simple_network
755 {
756         u64 revision;
757         efi_status_t (EFIAPI *start)(struct efi_simple_network *this);
758         efi_status_t (EFIAPI *stop)(struct efi_simple_network *this);
759         efi_status_t (EFIAPI *initialize)(struct efi_simple_network *this,
760                         ulong extra_rx, ulong extra_tx);
761         efi_status_t (EFIAPI *reset)(struct efi_simple_network *this,
762                         int extended_verification);
763         efi_status_t (EFIAPI *shutdown)(struct efi_simple_network *this);
764         efi_status_t (EFIAPI *receive_filters)(struct efi_simple_network *this,
765                         u32 enable, u32 disable, int reset_mcast_filter,
766                         ulong mcast_filter_count,
767                         struct efi_mac_address *mcast_filter);
768         efi_status_t (EFIAPI *station_address)(struct efi_simple_network *this,
769                         int reset, struct efi_mac_address *new_mac);
770         efi_status_t (EFIAPI *statistics)(struct efi_simple_network *this,
771                         int reset, ulong *stat_size, void *stat_table);
772         efi_status_t (EFIAPI *mcastiptomac)(struct efi_simple_network *this,
773                         int ipv6, struct efi_ip_address *ip,
774                         struct efi_mac_address *mac);
775         efi_status_t (EFIAPI *nvdata)(struct efi_simple_network *this,
776                         int read_write, ulong offset, ulong buffer_size,
777                         char *buffer);
778         efi_status_t (EFIAPI *get_status)(struct efi_simple_network *this,
779                         u32 *int_status, void **txbuf);
780         efi_status_t (EFIAPI *transmit)(struct efi_simple_network *this,
781                         size_t header_size, size_t buffer_size, void *buffer,
782                         struct efi_mac_address *src_addr,
783                         struct efi_mac_address *dest_addr, u16 *protocol);
784         efi_status_t (EFIAPI *receive)(struct efi_simple_network *this,
785                         size_t *header_size, size_t *buffer_size, void *buffer,
786                         struct efi_mac_address *src_addr,
787                         struct efi_mac_address *dest_addr, u16 *protocol);
788         struct efi_event *wait_for_packet;
789         struct efi_simple_network_mode *mode;
790 };
791
792 #define EFI_PXE_GUID \
793         EFI_GUID(0x03c4e603, 0xac28, 0x11d3, \
794                  0x9a, 0x2d, 0x00, 0x90, 0x27, 0x3f, 0xc1, 0x4d)
795
796 struct efi_pxe_packet {
797         u8 packet[1472];
798 };
799
800 struct efi_pxe_mode
801 {
802         u8 started;
803         u8 ipv6_available;
804         u8 ipv6_supported;
805         u8 using_ipv6;
806         u8 bis_supported;
807         u8 bis_detected;
808         u8 auto_arp;
809         u8 send_guid;
810         u8 dhcp_discover_valid;
811         u8 dhcp_ack_received;
812         u8 proxy_offer_received;
813         u8 pxe_discover_valid;
814         u8 pxe_reply_received;
815         u8 pxe_bis_reply_received;
816         u8 icmp_error_received;
817         u8 tftp_error_received;
818         u8 make_callbacks;
819         u8 ttl;
820         u8 tos;
821         u8 pad;
822         struct efi_ip_address station_ip;
823         struct efi_ip_address subnet_mask;
824         struct efi_pxe_packet dhcp_discover;
825         struct efi_pxe_packet dhcp_ack;
826         struct efi_pxe_packet proxy_offer;
827         struct efi_pxe_packet pxe_discover;
828         struct efi_pxe_packet pxe_reply;
829 };
830
831 struct efi_pxe {
832         u64 rev;
833         void (EFIAPI *start)(void);
834         void (EFIAPI *stop)(void);
835         void (EFIAPI *dhcp)(void);
836         void (EFIAPI *discover)(void);
837         void (EFIAPI *mftp)(void);
838         void (EFIAPI *udpwrite)(void);
839         void (EFIAPI *udpread)(void);
840         void (EFIAPI *setipfilter)(void);
841         void (EFIAPI *arp)(void);
842         void (EFIAPI *setparams)(void);
843         void (EFIAPI *setstationip)(void);
844         void (EFIAPI *setpackets)(void);
845         struct efi_pxe_mode *mode;
846 };
847
848 #define EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID \
849         EFI_GUID(0x964e5b22, 0x6459, 0x11d2, \
850                  0x8e, 0x39, 0x0, 0xa0, 0xc9, 0x69, 0x72, 0x3b)
851 #define EFI_FILE_PROTOCOL_REVISION 0x00010000
852
853 struct efi_file_handle {
854         u64 rev;
855         efi_status_t (EFIAPI *open)(struct efi_file_handle *file,
856                         struct efi_file_handle **new_handle,
857                         s16 *file_name, u64 open_mode, u64 attributes);
858         efi_status_t (EFIAPI *close)(struct efi_file_handle *file);
859         efi_status_t (EFIAPI *delete)(struct efi_file_handle *file);
860         efi_status_t (EFIAPI *read)(struct efi_file_handle *file,
861                         efi_uintn_t *buffer_size, void *buffer);
862         efi_status_t (EFIAPI *write)(struct efi_file_handle *file,
863                         efi_uintn_t *buffer_size, void *buffer);
864         efi_status_t (EFIAPI *getpos)(struct efi_file_handle *file,
865                         efi_uintn_t *pos);
866         efi_status_t (EFIAPI *setpos)(struct efi_file_handle *file,
867                         efi_uintn_t pos);
868         efi_status_t (EFIAPI *getinfo)(struct efi_file_handle *file,
869                         const efi_guid_t *info_type, efi_uintn_t *buffer_size,
870                         void *buffer);
871         efi_status_t (EFIAPI *setinfo)(struct efi_file_handle *file,
872                         const efi_guid_t *info_type, efi_uintn_t buffer_size,
873                         void *buffer);
874         efi_status_t (EFIAPI *flush)(struct efi_file_handle *file);
875 };
876
877 #define EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID \
878         EFI_GUID(0x964e5b22, 0x6459, 0x11d2, \
879                  0x8e, 0x39, 0x0, 0xa0, 0xc9, 0x69, 0x72, 0x3b)
880 #define EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_REVISION 0x00010000
881
882 struct efi_simple_file_system_protocol {
883         u64 rev;
884         efi_status_t (EFIAPI *open_volume)(struct efi_simple_file_system_protocol *this,
885                         struct efi_file_handle **root);
886 };
887
888 #define EFI_FILE_INFO_GUID \
889         EFI_GUID(0x9576e92, 0x6d3f, 0x11d2, \
890                  0x8e, 0x39, 0x0, 0xa0, 0xc9, 0x69, 0x72, 0x3b)
891
892 #define EFI_FILE_SYSTEM_INFO_GUID \
893         EFI_GUID(0x09576e93, 0x6d3f, 0x11d2, \
894                  0x8e, 0x39, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b)
895
896 #define EFI_FILE_MODE_READ      0x0000000000000001
897 #define EFI_FILE_MODE_WRITE     0x0000000000000002
898 #define EFI_FILE_MODE_CREATE    0x8000000000000000
899
900 #define EFI_FILE_READ_ONLY      0x0000000000000001
901 #define EFI_FILE_HIDDEN         0x0000000000000002
902 #define EFI_FILE_SYSTEM         0x0000000000000004
903 #define EFI_FILE_RESERVED       0x0000000000000008
904 #define EFI_FILE_DIRECTORY      0x0000000000000010
905 #define EFI_FILE_ARCHIVE        0x0000000000000020
906 #define EFI_FILE_VALID_ATTR     0x0000000000000037
907
908 struct efi_file_info {
909         u64 size;
910         u64 file_size;
911         u64 physical_size;
912         struct efi_time create_time;
913         struct efi_time last_access_time;
914         struct efi_time modification_time;
915         u64 attribute;
916         s16 file_name[0];
917 };
918
919 struct efi_file_system_info {
920         u64 size;
921         u8 read_only;
922         u64 volume_size;
923         u64 free_space;
924         u32 block_size;
925         u16 volume_label[0];
926 };
927
928 #define EFI_DRIVER_BINDING_PROTOCOL_GUID \
929         EFI_GUID(0x18a031ab, 0xb443, 0x4d1a,\
930                  0xa5, 0xc0, 0x0c, 0x09, 0x26, 0x1e, 0x9f, 0x71)
931 struct efi_driver_binding_protocol {
932         efi_status_t (EFIAPI * supported)(
933                         struct efi_driver_binding_protocol *this,
934                         efi_handle_t controller_handle,
935                         struct efi_device_path *remaining_device_path);
936         efi_status_t (EFIAPI * start)(
937                         struct efi_driver_binding_protocol *this,
938                         efi_handle_t controller_handle,
939                         struct efi_device_path *remaining_device_path);
940         efi_status_t (EFIAPI * stop)(
941                         struct efi_driver_binding_protocol *this,
942                         efi_handle_t controller_handle,
943                         efi_uintn_t number_of_children,
944                         efi_handle_t *child_handle_buffer);
945         u32 version;
946         efi_handle_t image_handle;
947         efi_handle_t driver_binding_handle;
948 };
949
950 #endif