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