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