efi/x86: Drop the special GDT for the EFI thunk
[linux-2.6-microblaze.git] / drivers / firmware / efi / libstub / efistub.h
1 /* SPDX-License-Identifier: GPL-2.0 */
2
3 #ifndef _DRIVERS_FIRMWARE_EFI_EFISTUB_H
4 #define _DRIVERS_FIRMWARE_EFI_EFISTUB_H
5
6 #include <linux/compiler.h>
7 #include <linux/efi.h>
8 #include <linux/kernel.h>
9 #include <linux/kern_levels.h>
10 #include <linux/types.h>
11 #include <asm/efi.h>
12
13 /* error code which can't be mistaken for valid address */
14 #define EFI_ERROR       (~0UL)
15
16 /*
17  * __init annotations should not be used in the EFI stub, since the code is
18  * either included in the decompressor (x86, ARM) where they have no effect,
19  * or the whole stub is __init annotated at the section level (arm64), by
20  * renaming the sections, in which case the __init annotation will be
21  * redundant, and will result in section names like .init.init.text, and our
22  * linker script does not expect that.
23  */
24 #undef __init
25
26 /*
27  * Allow the platform to override the allocation granularity: this allows
28  * systems that have the capability to run with a larger page size to deal
29  * with the allocations for initrd and fdt more efficiently.
30  */
31 #ifndef EFI_ALLOC_ALIGN
32 #define EFI_ALLOC_ALIGN         EFI_PAGE_SIZE
33 #endif
34
35 extern bool efi_nochunk;
36 extern bool efi_nokaslr;
37 extern bool efi_noinitrd;
38 extern int efi_loglevel;
39 extern bool efi_novamap;
40
41 extern const efi_system_table_t *efi_system_table;
42
43 efi_status_t __efiapi efi_pe_entry(efi_handle_t handle,
44                                    efi_system_table_t *sys_table_arg);
45
46 #ifndef ARCH_HAS_EFISTUB_WRAPPERS
47
48 #define efi_is_native()         (true)
49 #define efi_bs_call(func, ...)  efi_system_table->boottime->func(__VA_ARGS__)
50 #define efi_rt_call(func, ...)  efi_system_table->runtime->func(__VA_ARGS__)
51 #define efi_table_attr(inst, attr)      (inst->attr)
52 #define efi_call_proto(inst, func, ...) inst->func(inst, ##__VA_ARGS__)
53
54 #endif
55
56 #define efi_info(fmt, ...) \
57         efi_printk(KERN_INFO fmt, ##__VA_ARGS__)
58 #define efi_err(fmt, ...) \
59         efi_printk(KERN_ERR "ERROR: " fmt, ##__VA_ARGS__)
60 #define efi_debug(fmt, ...) \
61         efi_printk(KERN_DEBUG "DEBUG: " fmt, ##__VA_ARGS__)
62
63 /* Helper macros for the usual case of using simple C variables: */
64 #ifndef fdt_setprop_inplace_var
65 #define fdt_setprop_inplace_var(fdt, node_offset, name, var) \
66         fdt_setprop_inplace((fdt), (node_offset), (name), &(var), sizeof(var))
67 #endif
68
69 #ifndef fdt_setprop_var
70 #define fdt_setprop_var(fdt, node_offset, name, var) \
71         fdt_setprop((fdt), (node_offset), (name), &(var), sizeof(var))
72 #endif
73
74 #define get_efi_var(name, vendor, ...)                          \
75         efi_rt_call(get_variable, (efi_char16_t *)(name),       \
76                     (efi_guid_t *)(vendor), __VA_ARGS__)
77
78 #define set_efi_var(name, vendor, ...)                          \
79         efi_rt_call(set_variable, (efi_char16_t *)(name),       \
80                     (efi_guid_t *)(vendor), __VA_ARGS__)
81
82 #define efi_get_handle_at(array, idx)                                   \
83         (efi_is_native() ? (array)[idx]                                 \
84                 : (efi_handle_t)(unsigned long)((u32 *)(array))[idx])
85
86 #define efi_get_handle_num(size)                                        \
87         ((size) / (efi_is_native() ? sizeof(efi_handle_t) : sizeof(u32)))
88
89 #define for_each_efi_handle(handle, array, size, i)                     \
90         for (i = 0;                                                     \
91              i < efi_get_handle_num(size) &&                            \
92                 ((handle = efi_get_handle_at((array), i)) || true);     \
93              i++)
94
95 static inline
96 void efi_set_u64_split(u64 data, u32 *lo, u32 *hi)
97 {
98         *lo = lower_32_bits(data);
99         *hi = upper_32_bits(data);
100 }
101
102 /*
103  * Allocation types for calls to boottime->allocate_pages.
104  */
105 #define EFI_ALLOCATE_ANY_PAGES          0
106 #define EFI_ALLOCATE_MAX_ADDRESS        1
107 #define EFI_ALLOCATE_ADDRESS            2
108 #define EFI_MAX_ALLOCATE_TYPE           3
109
110 /*
111  * The type of search to perform when calling boottime->locate_handle
112  */
113 #define EFI_LOCATE_ALL_HANDLES                  0
114 #define EFI_LOCATE_BY_REGISTER_NOTIFY           1
115 #define EFI_LOCATE_BY_PROTOCOL                  2
116
117 /*
118  * boottime->stall takes the time period in microseconds
119  */
120 #define EFI_USEC_PER_SEC                1000000
121
122 /*
123  * boottime->set_timer takes the time in 100ns units
124  */
125 #define EFI_100NSEC_PER_USEC    ((u64)10)
126
127 struct efi_boot_memmap {
128         efi_memory_desc_t       **map;
129         unsigned long           *map_size;
130         unsigned long           *desc_size;
131         u32                     *desc_ver;
132         unsigned long           *key_ptr;
133         unsigned long           *buff_size;
134 };
135
136 typedef struct efi_generic_dev_path efi_device_path_protocol_t;
137
138 typedef void *efi_event_t;
139 /* Note that notifications won't work in mixed mode */
140 typedef void (__efiapi *efi_event_notify_t)(efi_event_t, void *);
141
142 #define EFI_EVT_TIMER           0x80000000U
143 #define EFI_EVT_RUNTIME         0x40000000U
144 #define EFI_EVT_NOTIFY_WAIT     0x00000100U
145 #define EFI_EVT_NOTIFY_SIGNAL   0x00000200U
146
147 /*
148  * boottime->wait_for_event takes an array of events as input.
149  * Provide a helper to set it up correctly for mixed mode.
150  */
151 static inline
152 void efi_set_event_at(efi_event_t *events, size_t idx, efi_event_t event)
153 {
154         if (efi_is_native())
155                 events[idx] = event;
156         else
157                 ((u32 *)events)[idx] = (u32)(unsigned long)event;
158 }
159
160 #define EFI_TPL_APPLICATION     4
161 #define EFI_TPL_CALLBACK        8
162 #define EFI_TPL_NOTIFY          16
163 #define EFI_TPL_HIGH_LEVEL      31
164
165 typedef enum {
166         EfiTimerCancel,
167         EfiTimerPeriodic,
168         EfiTimerRelative
169 } EFI_TIMER_DELAY;
170
171 /*
172  * EFI Boot Services table
173  */
174 union efi_boot_services {
175         struct {
176                 efi_table_hdr_t hdr;
177                 void *raise_tpl;
178                 void *restore_tpl;
179                 efi_status_t (__efiapi *allocate_pages)(int, int, unsigned long,
180                                                         efi_physical_addr_t *);
181                 efi_status_t (__efiapi *free_pages)(efi_physical_addr_t,
182                                                     unsigned long);
183                 efi_status_t (__efiapi *get_memory_map)(unsigned long *, void *,
184                                                         unsigned long *,
185                                                         unsigned long *, u32 *);
186                 efi_status_t (__efiapi *allocate_pool)(int, unsigned long,
187                                                        void **);
188                 efi_status_t (__efiapi *free_pool)(void *);
189                 efi_status_t (__efiapi *create_event)(u32, unsigned long,
190                                                       efi_event_notify_t, void *,
191                                                       efi_event_t *);
192                 efi_status_t (__efiapi *set_timer)(efi_event_t,
193                                                   EFI_TIMER_DELAY, u64);
194                 efi_status_t (__efiapi *wait_for_event)(unsigned long,
195                                                         efi_event_t *,
196                                                         unsigned long *);
197                 void *signal_event;
198                 efi_status_t (__efiapi *close_event)(efi_event_t);
199                 void *check_event;
200                 void *install_protocol_interface;
201                 void *reinstall_protocol_interface;
202                 void *uninstall_protocol_interface;
203                 efi_status_t (__efiapi *handle_protocol)(efi_handle_t,
204                                                          efi_guid_t *, void **);
205                 void *__reserved;
206                 void *register_protocol_notify;
207                 efi_status_t (__efiapi *locate_handle)(int, efi_guid_t *,
208                                                        void *, unsigned long *,
209                                                        efi_handle_t *);
210                 efi_status_t (__efiapi *locate_device_path)(efi_guid_t *,
211                                                             efi_device_path_protocol_t **,
212                                                             efi_handle_t *);
213                 efi_status_t (__efiapi *install_configuration_table)(efi_guid_t *,
214                                                                      void *);
215                 void *load_image;
216                 void *start_image;
217                 efi_status_t __noreturn (__efiapi *exit)(efi_handle_t,
218                                                          efi_status_t,
219                                                          unsigned long,
220                                                          efi_char16_t *);
221                 void *unload_image;
222                 efi_status_t (__efiapi *exit_boot_services)(efi_handle_t,
223                                                             unsigned long);
224                 void *get_next_monotonic_count;
225                 efi_status_t (__efiapi *stall)(unsigned long);
226                 void *set_watchdog_timer;
227                 void *connect_controller;
228                 efi_status_t (__efiapi *disconnect_controller)(efi_handle_t,
229                                                                efi_handle_t,
230                                                                efi_handle_t);
231                 void *open_protocol;
232                 void *close_protocol;
233                 void *open_protocol_information;
234                 void *protocols_per_handle;
235                 void *locate_handle_buffer;
236                 efi_status_t (__efiapi *locate_protocol)(efi_guid_t *, void *,
237                                                          void **);
238                 void *install_multiple_protocol_interfaces;
239                 void *uninstall_multiple_protocol_interfaces;
240                 void *calculate_crc32;
241                 void *copy_mem;
242                 void *set_mem;
243                 void *create_event_ex;
244         };
245         struct {
246                 efi_table_hdr_t hdr;
247                 u32 raise_tpl;
248                 u32 restore_tpl;
249                 u32 allocate_pages;
250                 u32 free_pages;
251                 u32 get_memory_map;
252                 u32 allocate_pool;
253                 u32 free_pool;
254                 u32 create_event;
255                 u32 set_timer;
256                 u32 wait_for_event;
257                 u32 signal_event;
258                 u32 close_event;
259                 u32 check_event;
260                 u32 install_protocol_interface;
261                 u32 reinstall_protocol_interface;
262                 u32 uninstall_protocol_interface;
263                 u32 handle_protocol;
264                 u32 __reserved;
265                 u32 register_protocol_notify;
266                 u32 locate_handle;
267                 u32 locate_device_path;
268                 u32 install_configuration_table;
269                 u32 load_image;
270                 u32 start_image;
271                 u32 exit;
272                 u32 unload_image;
273                 u32 exit_boot_services;
274                 u32 get_next_monotonic_count;
275                 u32 stall;
276                 u32 set_watchdog_timer;
277                 u32 connect_controller;
278                 u32 disconnect_controller;
279                 u32 open_protocol;
280                 u32 close_protocol;
281                 u32 open_protocol_information;
282                 u32 protocols_per_handle;
283                 u32 locate_handle_buffer;
284                 u32 locate_protocol;
285                 u32 install_multiple_protocol_interfaces;
286                 u32 uninstall_multiple_protocol_interfaces;
287                 u32 calculate_crc32;
288                 u32 copy_mem;
289                 u32 set_mem;
290                 u32 create_event_ex;
291         } mixed_mode;
292 };
293
294 typedef union efi_uga_draw_protocol efi_uga_draw_protocol_t;
295
296 union efi_uga_draw_protocol {
297         struct {
298                 efi_status_t (__efiapi *get_mode)(efi_uga_draw_protocol_t *,
299                                                   u32*, u32*, u32*, u32*);
300                 void *set_mode;
301                 void *blt;
302         };
303         struct {
304                 u32 get_mode;
305                 u32 set_mode;
306                 u32 blt;
307         } mixed_mode;
308 };
309
310 typedef struct {
311         u16 scan_code;
312         efi_char16_t unicode_char;
313 } efi_input_key_t;
314
315 union efi_simple_text_input_protocol {
316         struct {
317                 void *reset;
318                 efi_status_t (__efiapi *read_keystroke)(efi_simple_text_input_protocol_t *,
319                                                         efi_input_key_t *);
320                 efi_event_t wait_for_key;
321         };
322         struct {
323                 u32 reset;
324                 u32 read_keystroke;
325                 u32 wait_for_key;
326         } mixed_mode;
327 };
328
329 efi_status_t efi_wait_for_key(unsigned long usec, efi_input_key_t *key);
330
331 union efi_simple_text_output_protocol {
332         struct {
333                 void *reset;
334                 efi_status_t (__efiapi *output_string)(efi_simple_text_output_protocol_t *,
335                                                        efi_char16_t *);
336                 void *test_string;
337         };
338         struct {
339                 u32 reset;
340                 u32 output_string;
341                 u32 test_string;
342         } mixed_mode;
343 };
344
345 #define PIXEL_RGB_RESERVED_8BIT_PER_COLOR               0
346 #define PIXEL_BGR_RESERVED_8BIT_PER_COLOR               1
347 #define PIXEL_BIT_MASK                                  2
348 #define PIXEL_BLT_ONLY                                  3
349 #define PIXEL_FORMAT_MAX                                4
350
351 typedef struct {
352         u32 red_mask;
353         u32 green_mask;
354         u32 blue_mask;
355         u32 reserved_mask;
356 } efi_pixel_bitmask_t;
357
358 typedef struct {
359         u32 version;
360         u32 horizontal_resolution;
361         u32 vertical_resolution;
362         int pixel_format;
363         efi_pixel_bitmask_t pixel_information;
364         u32 pixels_per_scan_line;
365 } efi_graphics_output_mode_info_t;
366
367 typedef union efi_graphics_output_protocol_mode efi_graphics_output_protocol_mode_t;
368
369 union efi_graphics_output_protocol_mode {
370         struct {
371                 u32 max_mode;
372                 u32 mode;
373                 efi_graphics_output_mode_info_t *info;
374                 unsigned long size_of_info;
375                 efi_physical_addr_t frame_buffer_base;
376                 unsigned long frame_buffer_size;
377         };
378         struct {
379                 u32 max_mode;
380                 u32 mode;
381                 u32 info;
382                 u32 size_of_info;
383                 u64 frame_buffer_base;
384                 u32 frame_buffer_size;
385         } mixed_mode;
386 };
387
388 typedef union efi_graphics_output_protocol efi_graphics_output_protocol_t;
389
390 union efi_graphics_output_protocol {
391         struct {
392                 efi_status_t (__efiapi *query_mode)(efi_graphics_output_protocol_t *,
393                                                     u32, unsigned long *,
394                                                     efi_graphics_output_mode_info_t **);
395                 efi_status_t (__efiapi *set_mode)  (efi_graphics_output_protocol_t *, u32);
396                 void *blt;
397                 efi_graphics_output_protocol_mode_t *mode;
398         };
399         struct {
400                 u32 query_mode;
401                 u32 set_mode;
402                 u32 blt;
403                 u32 mode;
404         } mixed_mode;
405 };
406
407 typedef union {
408         struct {
409                 u32                     revision;
410                 efi_handle_t            parent_handle;
411                 efi_system_table_t      *system_table;
412                 efi_handle_t            device_handle;
413                 void                    *file_path;
414                 void                    *reserved;
415                 u32                     load_options_size;
416                 void                    *load_options;
417                 void                    *image_base;
418                 __aligned_u64           image_size;
419                 unsigned int            image_code_type;
420                 unsigned int            image_data_type;
421                 efi_status_t            (__efiapi *unload)(efi_handle_t image_handle);
422         };
423         struct {
424                 u32             revision;
425                 u32             parent_handle;
426                 u32             system_table;
427                 u32             device_handle;
428                 u32             file_path;
429                 u32             reserved;
430                 u32             load_options_size;
431                 u32             load_options;
432                 u32             image_base;
433                 __aligned_u64   image_size;
434                 u32             image_code_type;
435                 u32             image_data_type;
436                 u32             unload;
437         } mixed_mode;
438 } efi_loaded_image_t;
439
440 typedef struct {
441         u64                     size;
442         u64                     file_size;
443         u64                     phys_size;
444         efi_time_t              create_time;
445         efi_time_t              last_access_time;
446         efi_time_t              modification_time;
447         __aligned_u64           attribute;
448         efi_char16_t            filename[];
449 } efi_file_info_t;
450
451 typedef struct efi_file_protocol efi_file_protocol_t;
452
453 struct efi_file_protocol {
454         u64             revision;
455         efi_status_t    (__efiapi *open)        (efi_file_protocol_t *,
456                                                  efi_file_protocol_t **,
457                                                  efi_char16_t *, u64, u64);
458         efi_status_t    (__efiapi *close)       (efi_file_protocol_t *);
459         efi_status_t    (__efiapi *delete)      (efi_file_protocol_t *);
460         efi_status_t    (__efiapi *read)        (efi_file_protocol_t *,
461                                                  unsigned long *, void *);
462         efi_status_t    (__efiapi *write)       (efi_file_protocol_t *,
463                                                  unsigned long, void *);
464         efi_status_t    (__efiapi *get_position)(efi_file_protocol_t *, u64 *);
465         efi_status_t    (__efiapi *set_position)(efi_file_protocol_t *, u64);
466         efi_status_t    (__efiapi *get_info)    (efi_file_protocol_t *,
467                                                  efi_guid_t *, unsigned long *,
468                                                  void *);
469         efi_status_t    (__efiapi *set_info)    (efi_file_protocol_t *,
470                                                  efi_guid_t *, unsigned long,
471                                                  void *);
472         efi_status_t    (__efiapi *flush)       (efi_file_protocol_t *);
473 };
474
475 typedef struct efi_simple_file_system_protocol efi_simple_file_system_protocol_t;
476
477 struct efi_simple_file_system_protocol {
478         u64     revision;
479         int     (__efiapi *open_volume)(efi_simple_file_system_protocol_t *,
480                                         efi_file_protocol_t **);
481 };
482
483 #define EFI_FILE_MODE_READ      0x0000000000000001
484 #define EFI_FILE_MODE_WRITE     0x0000000000000002
485 #define EFI_FILE_MODE_CREATE    0x8000000000000000
486
487 typedef enum {
488         EfiPciIoWidthUint8,
489         EfiPciIoWidthUint16,
490         EfiPciIoWidthUint32,
491         EfiPciIoWidthUint64,
492         EfiPciIoWidthFifoUint8,
493         EfiPciIoWidthFifoUint16,
494         EfiPciIoWidthFifoUint32,
495         EfiPciIoWidthFifoUint64,
496         EfiPciIoWidthFillUint8,
497         EfiPciIoWidthFillUint16,
498         EfiPciIoWidthFillUint32,
499         EfiPciIoWidthFillUint64,
500         EfiPciIoWidthMaximum
501 } EFI_PCI_IO_PROTOCOL_WIDTH;
502
503 typedef enum {
504         EfiPciIoAttributeOperationGet,
505         EfiPciIoAttributeOperationSet,
506         EfiPciIoAttributeOperationEnable,
507         EfiPciIoAttributeOperationDisable,
508         EfiPciIoAttributeOperationSupported,
509     EfiPciIoAttributeOperationMaximum
510 } EFI_PCI_IO_PROTOCOL_ATTRIBUTE_OPERATION;
511
512 typedef struct {
513         u32 read;
514         u32 write;
515 } efi_pci_io_protocol_access_32_t;
516
517 typedef union efi_pci_io_protocol efi_pci_io_protocol_t;
518
519 typedef
520 efi_status_t (__efiapi *efi_pci_io_protocol_cfg_t)(efi_pci_io_protocol_t *,
521                                                    EFI_PCI_IO_PROTOCOL_WIDTH,
522                                                    u32 offset,
523                                                    unsigned long count,
524                                                    void *buffer);
525
526 typedef struct {
527         void *read;
528         void *write;
529 } efi_pci_io_protocol_access_t;
530
531 typedef struct {
532         efi_pci_io_protocol_cfg_t read;
533         efi_pci_io_protocol_cfg_t write;
534 } efi_pci_io_protocol_config_access_t;
535
536 union efi_pci_io_protocol {
537         struct {
538                 void *poll_mem;
539                 void *poll_io;
540                 efi_pci_io_protocol_access_t mem;
541                 efi_pci_io_protocol_access_t io;
542                 efi_pci_io_protocol_config_access_t pci;
543                 void *copy_mem;
544                 void *map;
545                 void *unmap;
546                 void *allocate_buffer;
547                 void *free_buffer;
548                 void *flush;
549                 efi_status_t (__efiapi *get_location)(efi_pci_io_protocol_t *,
550                                                       unsigned long *segment_nr,
551                                                       unsigned long *bus_nr,
552                                                       unsigned long *device_nr,
553                                                       unsigned long *func_nr);
554                 void *attributes;
555                 void *get_bar_attributes;
556                 void *set_bar_attributes;
557                 uint64_t romsize;
558                 void *romimage;
559         };
560         struct {
561                 u32 poll_mem;
562                 u32 poll_io;
563                 efi_pci_io_protocol_access_32_t mem;
564                 efi_pci_io_protocol_access_32_t io;
565                 efi_pci_io_protocol_access_32_t pci;
566                 u32 copy_mem;
567                 u32 map;
568                 u32 unmap;
569                 u32 allocate_buffer;
570                 u32 free_buffer;
571                 u32 flush;
572                 u32 get_location;
573                 u32 attributes;
574                 u32 get_bar_attributes;
575                 u32 set_bar_attributes;
576                 u64 romsize;
577                 u32 romimage;
578         } mixed_mode;
579 };
580
581 #define EFI_PCI_IO_ATTRIBUTE_ISA_MOTHERBOARD_IO 0x0001
582 #define EFI_PCI_IO_ATTRIBUTE_ISA_IO 0x0002
583 #define EFI_PCI_IO_ATTRIBUTE_VGA_PALETTE_IO 0x0004
584 #define EFI_PCI_IO_ATTRIBUTE_VGA_MEMORY 0x0008
585 #define EFI_PCI_IO_ATTRIBUTE_VGA_IO 0x0010
586 #define EFI_PCI_IO_ATTRIBUTE_IDE_PRIMARY_IO 0x0020
587 #define EFI_PCI_IO_ATTRIBUTE_IDE_SECONDARY_IO 0x0040
588 #define EFI_PCI_IO_ATTRIBUTE_MEMORY_WRITE_COMBINE 0x0080
589 #define EFI_PCI_IO_ATTRIBUTE_IO 0x0100
590 #define EFI_PCI_IO_ATTRIBUTE_MEMORY 0x0200
591 #define EFI_PCI_IO_ATTRIBUTE_BUS_MASTER 0x0400
592 #define EFI_PCI_IO_ATTRIBUTE_MEMORY_CACHED 0x0800
593 #define EFI_PCI_IO_ATTRIBUTE_MEMORY_DISABLE 0x1000
594 #define EFI_PCI_IO_ATTRIBUTE_EMBEDDED_DEVICE 0x2000
595 #define EFI_PCI_IO_ATTRIBUTE_EMBEDDED_ROM 0x4000
596 #define EFI_PCI_IO_ATTRIBUTE_DUAL_ADDRESS_CYCLE 0x8000
597 #define EFI_PCI_IO_ATTRIBUTE_ISA_IO_16 0x10000
598 #define EFI_PCI_IO_ATTRIBUTE_VGA_PALETTE_IO_16 0x20000
599 #define EFI_PCI_IO_ATTRIBUTE_VGA_IO_16 0x40000
600
601 struct efi_dev_path;
602
603 typedef union apple_properties_protocol apple_properties_protocol_t;
604
605 union apple_properties_protocol {
606         struct {
607                 unsigned long version;
608                 efi_status_t (__efiapi *get)(apple_properties_protocol_t *,
609                                              struct efi_dev_path *,
610                                              efi_char16_t *, void *, u32 *);
611                 efi_status_t (__efiapi *set)(apple_properties_protocol_t *,
612                                              struct efi_dev_path *,
613                                              efi_char16_t *, void *, u32);
614                 efi_status_t (__efiapi *del)(apple_properties_protocol_t *,
615                                              struct efi_dev_path *,
616                                              efi_char16_t *);
617                 efi_status_t (__efiapi *get_all)(apple_properties_protocol_t *,
618                                                  void *buffer, u32 *);
619         };
620         struct {
621                 u32 version;
622                 u32 get;
623                 u32 set;
624                 u32 del;
625                 u32 get_all;
626         } mixed_mode;
627 };
628
629 typedef u32 efi_tcg2_event_log_format;
630
631 typedef union efi_tcg2_protocol efi_tcg2_protocol_t;
632
633 union efi_tcg2_protocol {
634         struct {
635                 void *get_capability;
636                 efi_status_t (__efiapi *get_event_log)(efi_handle_t,
637                                                        efi_tcg2_event_log_format,
638                                                        efi_physical_addr_t *,
639                                                        efi_physical_addr_t *,
640                                                        efi_bool_t *);
641                 void *hash_log_extend_event;
642                 void *submit_command;
643                 void *get_active_pcr_banks;
644                 void *set_active_pcr_banks;
645                 void *get_result_of_set_active_pcr_banks;
646         };
647         struct {
648                 u32 get_capability;
649                 u32 get_event_log;
650                 u32 hash_log_extend_event;
651                 u32 submit_command;
652                 u32 get_active_pcr_banks;
653                 u32 set_active_pcr_banks;
654                 u32 get_result_of_set_active_pcr_banks;
655         } mixed_mode;
656 };
657
658 typedef union efi_load_file_protocol efi_load_file_protocol_t;
659 typedef union efi_load_file_protocol efi_load_file2_protocol_t;
660
661 union efi_load_file_protocol {
662         struct {
663                 efi_status_t (__efiapi *load_file)(efi_load_file_protocol_t *,
664                                                    efi_device_path_protocol_t *,
665                                                    bool, unsigned long *, void *);
666         };
667         struct {
668                 u32 load_file;
669         } mixed_mode;
670 };
671
672 void efi_pci_disable_bridge_busmaster(void);
673
674 typedef efi_status_t (*efi_exit_boot_map_processing)(
675         struct efi_boot_memmap *map,
676         void *priv);
677
678 efi_status_t efi_exit_boot_services(void *handle,
679                                     struct efi_boot_memmap *map,
680                                     void *priv,
681                                     efi_exit_boot_map_processing priv_func);
682
683 efi_status_t allocate_new_fdt_and_exit_boot(void *handle,
684                                             unsigned long *new_fdt_addr,
685                                             unsigned long max_addr,
686                                             u64 initrd_addr, u64 initrd_size,
687                                             char *cmdline_ptr,
688                                             unsigned long fdt_addr,
689                                             unsigned long fdt_size);
690
691 void *get_fdt(unsigned long *fdt_size);
692
693 void efi_get_virtmap(efi_memory_desc_t *memory_map, unsigned long map_size,
694                      unsigned long desc_size, efi_memory_desc_t *runtime_map,
695                      int *count);
696
697 efi_status_t efi_get_random_bytes(unsigned long size, u8 *out);
698
699 efi_status_t efi_random_alloc(unsigned long size, unsigned long align,
700                               unsigned long *addr, unsigned long random_seed);
701
702 efi_status_t check_platform_features(void);
703
704 void *get_efi_config_table(efi_guid_t guid);
705
706 /* NOTE: These functions do not print a trailing newline after the string */
707 void efi_char16_puts(efi_char16_t *);
708 void efi_puts(const char *str);
709
710 __printf(1, 2) int efi_printk(char const *fmt, ...);
711
712 void efi_free(unsigned long size, unsigned long addr);
713
714 char *efi_convert_cmdline(efi_loaded_image_t *image, int *cmd_line_len);
715
716 efi_status_t efi_get_memory_map(struct efi_boot_memmap *map);
717
718 efi_status_t efi_allocate_pages(unsigned long size, unsigned long *addr,
719                                 unsigned long max);
720
721 efi_status_t efi_allocate_pages_aligned(unsigned long size, unsigned long *addr,
722                                         unsigned long max, unsigned long align);
723
724 efi_status_t efi_relocate_kernel(unsigned long *image_addr,
725                                  unsigned long image_size,
726                                  unsigned long alloc_size,
727                                  unsigned long preferred_addr,
728                                  unsigned long alignment,
729                                  unsigned long min_addr);
730
731 efi_status_t efi_parse_options(char const *cmdline);
732
733 void efi_parse_option_graphics(char *option);
734
735 efi_status_t efi_setup_gop(struct screen_info *si, efi_guid_t *proto,
736                            unsigned long size);
737
738 efi_status_t handle_cmdline_files(efi_loaded_image_t *image,
739                                   const efi_char16_t *optstr,
740                                   int optstr_size,
741                                   unsigned long soft_limit,
742                                   unsigned long hard_limit,
743                                   unsigned long *load_addr,
744                                   unsigned long *load_size);
745
746
747 static inline efi_status_t efi_load_dtb(efi_loaded_image_t *image,
748                                         unsigned long *load_addr,
749                                         unsigned long *load_size)
750 {
751         return handle_cmdline_files(image, L"dtb=", sizeof(L"dtb=") - 2,
752                                     ULONG_MAX, ULONG_MAX, load_addr, load_size);
753 }
754
755 efi_status_t efi_load_initrd(efi_loaded_image_t *image,
756                              unsigned long *load_addr,
757                              unsigned long *load_size,
758                              unsigned long soft_limit,
759                              unsigned long hard_limit);
760
761 #endif