efi/libstub: Extend native protocol definitions with mixed_mode aliases
[linux-block.git] / include / linux / efi.h
CommitLineData
b2441318 1/* SPDX-License-Identifier: GPL-2.0 */
1da177e4
LT
2#ifndef _LINUX_EFI_H
3#define _LINUX_EFI_H
4
5/*
6 * Extensible Firmware Interface
7 * Based on 'Extensible Firmware Interface Specification' version 0.9, April 30, 1999
8 *
9 * Copyright (C) 1999 VA Linux Systems
10 * Copyright (C) 1999 Walt Drummond <drummond@valinux.com>
11 * Copyright (C) 1999, 2002-2003 Hewlett-Packard Co.
12 * David Mosberger-Tang <davidm@hpl.hp.com>
13 * Stephane Eranian <eranian@hpl.hp.com>
14 */
15#include <linux/init.h>
16#include <linux/string.h>
17#include <linux/time.h>
18#include <linux/types.h>
19#include <linux/proc_fs.h>
20#include <linux/rtc.h>
21#include <linux/ioport.h>
4a3575fd 22#include <linux/pfn.h>
5ee9c198 23#include <linux/pstore.h>
60863c0d 24#include <linux/range.h>
8562c99c 25#include <linux/reboot.h>
ba7e34b1 26#include <linux/uuid.h>
2c23b73c 27#include <linux/screen_info.h>
1da177e4
LT
28
29#include <asm/page.h>
1da177e4
LT
30
31#define EFI_SUCCESS 0
32#define EFI_LOAD_ERROR ( 1 | (1UL << (BITS_PER_LONG-1)))
33#define EFI_INVALID_PARAMETER ( 2 | (1UL << (BITS_PER_LONG-1)))
34#define EFI_UNSUPPORTED ( 3 | (1UL << (BITS_PER_LONG-1)))
35#define EFI_BAD_BUFFER_SIZE ( 4 | (1UL << (BITS_PER_LONG-1)))
36#define EFI_BUFFER_TOO_SMALL ( 5 | (1UL << (BITS_PER_LONG-1)))
5d9db883
MG
37#define EFI_NOT_READY ( 6 | (1UL << (BITS_PER_LONG-1)))
38#define EFI_DEVICE_ERROR ( 7 | (1UL << (BITS_PER_LONG-1)))
39#define EFI_WRITE_PROTECTED ( 8 | (1UL << (BITS_PER_LONG-1)))
40#define EFI_OUT_OF_RESOURCES ( 9 | (1UL << (BITS_PER_LONG-1)))
1da177e4 41#define EFI_NOT_FOUND (14 | (1UL << (BITS_PER_LONG-1)))
dce48e35 42#define EFI_ABORTED (21 | (1UL << (BITS_PER_LONG-1)))
5d9db883 43#define EFI_SECURITY_VIOLATION (26 | (1UL << (BITS_PER_LONG-1)))
1da177e4
LT
44
45typedef unsigned long efi_status_t;
46typedef u8 efi_bool_t;
47typedef u16 efi_char16_t; /* UNICODE character */
ed37ddff
RF
48typedef u64 efi_physical_addr_t;
49typedef void *efi_handle_t;
1da177e4 50
2732ea0d
AB
51#define efi_get_handle_at(array, idx) \
52 (efi_is_64bit() ? (efi_handle_t)(unsigned long)((u64 *)(array))[idx] \
53 : (efi_handle_t)(unsigned long)((u32 *)(array))[idx])
54
55#define efi_get_handle_num(size) \
56 ((size) / (efi_is_64bit() ? sizeof(u64) : sizeof(u32)))
57
58#define for_each_efi_handle(handle, array, size, i) \
59 for (i = 0; \
60 i < efi_get_handle_num(size) && \
61 ((handle = efi_get_handle_at((array), i)) || true); \
62 i++)
63
494c704f
AB
64/*
65 * The UEFI spec and EDK2 reference implementation both define EFI_GUID as
66 * struct { u32 a; u16; b; u16 c; u8 d[8]; }; and so the implied alignment
67 * is 32 bits not 8 bits like our guid_t. In some cases (i.e., on 32-bit ARM),
68 * this means that firmware services invoked by the kernel may assume that
69 * efi_guid_t* arguments are 32-bit aligned, and use memory accessors that
70 * do not tolerate misalignment. So let's set the minimum alignment to 32 bits.
71 *
72 * Note that the UEFI spec as well as some comments in the EDK2 code base
73 * suggest that EFI_GUID should be 64-bit aligned, but this appears to be
74 * a mistake, given that no code seems to exist that actually enforces that
75 * or relies on it.
76 */
77typedef guid_t efi_guid_t __aligned(__alignof__(u32));
1da177e4
LT
78
79#define EFI_GUID(a,b,c,d0,d1,d2,d3,d4,d5,d6,d7) \
c0020756 80 GUID_INIT(a, b, c, d0, d1, d2, d3, d4, d5, d6, d7)
1da177e4
LT
81
82/*
83 * Generic EFI table header
84 */
85typedef struct {
86 u64 signature;
87 u32 revision;
88 u32 headersize;
89 u32 crc32;
90 u32 reserved;
91} efi_table_hdr_t;
92
93/*
94 * Memory map descriptor:
95 */
96
97/* Memory types: */
98#define EFI_RESERVED_TYPE 0
99#define EFI_LOADER_CODE 1
100#define EFI_LOADER_DATA 2
101#define EFI_BOOT_SERVICES_CODE 3
102#define EFI_BOOT_SERVICES_DATA 4
103#define EFI_RUNTIME_SERVICES_CODE 5
104#define EFI_RUNTIME_SERVICES_DATA 6
105#define EFI_CONVENTIONAL_MEMORY 7
106#define EFI_UNUSABLE_MEMORY 8
107#define EFI_ACPI_RECLAIM_MEMORY 9
108#define EFI_ACPI_MEMORY_NVS 10
109#define EFI_MEMORY_MAPPED_IO 11
110#define EFI_MEMORY_MAPPED_IO_PORT_SPACE 12
111#define EFI_PAL_CODE 13
ad5fb870
DW
112#define EFI_PERSISTENT_MEMORY 14
113#define EFI_MAX_MEMORY_TYPE 15
1da177e4
LT
114
115/* Attribute values: */
116#define EFI_MEMORY_UC ((u64)0x0000000000000001ULL) /* uncached */
117#define EFI_MEMORY_WC ((u64)0x0000000000000002ULL) /* write-coalescing */
118#define EFI_MEMORY_WT ((u64)0x0000000000000004ULL) /* write-through */
119#define EFI_MEMORY_WB ((u64)0x0000000000000008ULL) /* write-back */
9c97e0bd 120#define EFI_MEMORY_UCE ((u64)0x0000000000000010ULL) /* uncached, exported */
1da177e4
LT
121#define EFI_MEMORY_WP ((u64)0x0000000000001000ULL) /* write-protect */
122#define EFI_MEMORY_RP ((u64)0x0000000000002000ULL) /* read-protect */
123#define EFI_MEMORY_XP ((u64)0x0000000000004000ULL) /* execute-protect */
c016ca08 124#define EFI_MEMORY_NV ((u64)0x0000000000008000ULL) /* non-volatile */
b05b9f5f
TL
125#define EFI_MEMORY_MORE_RELIABLE \
126 ((u64)0x0000000000010000ULL) /* higher reliability */
87db73ae 127#define EFI_MEMORY_RO ((u64)0x0000000000020000ULL) /* read-only */
fe3e5e65 128#define EFI_MEMORY_SP ((u64)0x0000000000040000ULL) /* soft reserved */
1da177e4
LT
129#define EFI_MEMORY_RUNTIME ((u64)0x8000000000000000ULL) /* range requires runtime mapping */
130#define EFI_MEMORY_DESCRIPTOR_VERSION 1
131
132#define EFI_PAGE_SHIFT 12
ed37ddff 133#define EFI_PAGE_SIZE (1UL << EFI_PAGE_SHIFT)
0100a3e6 134#define EFI_PAGES_MAX (U64_MAX >> EFI_PAGE_SHIFT)
1da177e4 135
1da177e4
LT
136typedef struct {
137 u32 type;
138 u32 pad;
139 u64 phys_addr;
140 u64 virt_addr;
141 u64 num_pages;
142 u64 attribute;
1da177e4
LT
143} efi_memory_desc_t;
144
3b370237
MG
145typedef struct {
146 efi_guid_t guid;
147 u32 headersize;
148 u32 flags;
149 u32 imagesize;
150} efi_capsule_header_t;
151
dadb57ab
JH
152struct efi_boot_memmap {
153 efi_memory_desc_t **map;
154 unsigned long *map_size;
155 unsigned long *desc_size;
156 u32 *desc_ver;
157 unsigned long *key_ptr;
158 unsigned long *buff_size;
159};
160
f0133f3c
MF
161/*
162 * EFI capsule flags
163 */
164#define EFI_CAPSULE_PERSIST_ACROSS_RESET 0x00010000
165#define EFI_CAPSULE_POPULATE_SYSTEM_TABLE 0x00020000
166#define EFI_CAPSULE_INITIATE_RESET 0x00040000
167
3fabd628
AB
168struct capsule_info {
169 efi_capsule_header_t header;
f24c4d47 170 efi_capsule_header_t *capsule;
3fabd628
AB
171 int reset_type;
172 long index;
173 size_t count;
174 size_t total_size;
f24c4d47
AB
175 struct page **pages;
176 phys_addr_t *phys;
3fabd628
AB
177 size_t page_bytes_remain;
178};
179
180int __efi_capsule_setup_info(struct capsule_info *cap_info);
181
bb05e4ba
MF
182/*
183 * Allocation types for calls to boottime->allocate_pages.
184 */
185#define EFI_ALLOCATE_ANY_PAGES 0
186#define EFI_ALLOCATE_MAX_ADDRESS 1
187#define EFI_ALLOCATE_ADDRESS 2
188#define EFI_MAX_ALLOCATE_TYPE 3
189
e088a4ad 190typedef int (*efi_freemem_callback_t) (u64 start, u64 end, void *arg);
1da177e4
LT
191
192/*
193 * Types and defines for Time Services
194 */
195#define EFI_TIME_ADJUST_DAYLIGHT 0x1
196#define EFI_TIME_IN_DAYLIGHT 0x2
197#define EFI_UNSPECIFIED_TIMEZONE 0x07ff
198
199typedef struct {
200 u16 year;
201 u8 month;
202 u8 day;
203 u8 hour;
204 u8 minute;
205 u8 second;
206 u8 pad1;
207 u32 nanosecond;
208 s16 timezone;
209 u8 daylight;
210 u8 pad2;
211} efi_time_t;
212
213typedef struct {
214 u32 resolution;
215 u32 accuracy;
216 u8 sets_to_zero;
217} efi_time_cap_t;
218
677703ce
MF
219typedef struct {
220 efi_table_hdr_t hdr;
221 u32 raise_tpl;
222 u32 restore_tpl;
223 u32 allocate_pages;
224 u32 free_pages;
225 u32 get_memory_map;
226 u32 allocate_pool;
227 u32 free_pool;
228 u32 create_event;
229 u32 set_timer;
230 u32 wait_for_event;
231 u32 signal_event;
232 u32 close_event;
233 u32 check_event;
234 u32 install_protocol_interface;
235 u32 reinstall_protocol_interface;
236 u32 uninstall_protocol_interface;
237 u32 handle_protocol;
238 u32 __reserved;
239 u32 register_protocol_notify;
240 u32 locate_handle;
241 u32 locate_device_path;
242 u32 install_configuration_table;
243 u32 load_image;
244 u32 start_image;
245 u32 exit;
246 u32 unload_image;
247 u32 exit_boot_services;
248 u32 get_next_monotonic_count;
249 u32 stall;
250 u32 set_watchdog_timer;
251 u32 connect_controller;
252 u32 disconnect_controller;
253 u32 open_protocol;
254 u32 close_protocol;
255 u32 open_protocol_information;
256 u32 protocols_per_handle;
257 u32 locate_handle_buffer;
258 u32 locate_protocol;
259 u32 install_multiple_protocol_interfaces;
260 u32 uninstall_multiple_protocol_interfaces;
261 u32 calculate_crc32;
262 u32 copy_mem;
263 u32 set_mem;
264 u32 create_event_ex;
265} __packed efi_boot_services_32_t;
266
267typedef struct {
268 efi_table_hdr_t hdr;
269 u64 raise_tpl;
270 u64 restore_tpl;
271 u64 allocate_pages;
272 u64 free_pages;
273 u64 get_memory_map;
274 u64 allocate_pool;
275 u64 free_pool;
276 u64 create_event;
277 u64 set_timer;
278 u64 wait_for_event;
279 u64 signal_event;
280 u64 close_event;
281 u64 check_event;
282 u64 install_protocol_interface;
283 u64 reinstall_protocol_interface;
284 u64 uninstall_protocol_interface;
285 u64 handle_protocol;
286 u64 __reserved;
287 u64 register_protocol_notify;
288 u64 locate_handle;
289 u64 locate_device_path;
290 u64 install_configuration_table;
291 u64 load_image;
292 u64 start_image;
293 u64 exit;
294 u64 unload_image;
295 u64 exit_boot_services;
296 u64 get_next_monotonic_count;
297 u64 stall;
298 u64 set_watchdog_timer;
299 u64 connect_controller;
300 u64 disconnect_controller;
301 u64 open_protocol;
302 u64 close_protocol;
303 u64 open_protocol_information;
304 u64 protocols_per_handle;
305 u64 locate_handle_buffer;
306 u64 locate_protocol;
307 u64 install_multiple_protocol_interfaces;
308 u64 uninstall_multiple_protocol_interfaces;
309 u64 calculate_crc32;
310 u64 copy_mem;
311 u64 set_mem;
312 u64 create_event_ex;
313} __packed efi_boot_services_64_t;
314
f30ca6ba
MF
315/*
316 * EFI Boot Services table
317 */
1786e830
AB
318typedef union {
319 struct {
320 efi_table_hdr_t hdr;
321 void *raise_tpl;
322 void *restore_tpl;
323 efi_status_t (*allocate_pages)(int, int, unsigned long,
324 efi_physical_addr_t *);
325 efi_status_t (*free_pages)(efi_physical_addr_t, unsigned long);
326 efi_status_t (*get_memory_map)(unsigned long *, void *, unsigned long *,
327 unsigned long *, u32 *);
328 efi_status_t (*allocate_pool)(int, unsigned long, void **);
329 efi_status_t (*free_pool)(void *);
330 void *create_event;
331 void *set_timer;
332 void *wait_for_event;
333 void *signal_event;
334 void *close_event;
335 void *check_event;
336 void *install_protocol_interface;
337 void *reinstall_protocol_interface;
338 void *uninstall_protocol_interface;
339 efi_status_t (*handle_protocol)(efi_handle_t, efi_guid_t *, void **);
340 void *__reserved;
341 void *register_protocol_notify;
342 efi_status_t (*locate_handle)(int, efi_guid_t *, void *,
343 unsigned long *, efi_handle_t *);
344 void *locate_device_path;
345 efi_status_t (*install_configuration_table)(efi_guid_t *, void *);
346 void *load_image;
347 void *start_image;
348 void *exit;
349 void *unload_image;
350 efi_status_t (*exit_boot_services)(efi_handle_t, unsigned long);
351 void *get_next_monotonic_count;
352 void *stall;
353 void *set_watchdog_timer;
354 void *connect_controller;
355 void *disconnect_controller;
356 void *open_protocol;
357 void *close_protocol;
358 void *open_protocol_information;
359 void *protocols_per_handle;
360 void *locate_handle_buffer;
361 efi_status_t (*locate_protocol)(efi_guid_t *, void *, void **);
362 void *install_multiple_protocol_interfaces;
363 void *uninstall_multiple_protocol_interfaces;
364 void *calculate_crc32;
365 void *copy_mem;
366 void *set_mem;
367 void *create_event_ex;
368 };
369 efi_boot_services_32_t mixed_mode;
f30ca6ba
MF
370} efi_boot_services_t;
371
dd5fc854
MG
372typedef enum {
373 EfiPciIoWidthUint8,
374 EfiPciIoWidthUint16,
375 EfiPciIoWidthUint32,
376 EfiPciIoWidthUint64,
377 EfiPciIoWidthFifoUint8,
378 EfiPciIoWidthFifoUint16,
379 EfiPciIoWidthFifoUint32,
380 EfiPciIoWidthFifoUint64,
381 EfiPciIoWidthFillUint8,
382 EfiPciIoWidthFillUint16,
383 EfiPciIoWidthFillUint32,
384 EfiPciIoWidthFillUint64,
385 EfiPciIoWidthMaximum
386} EFI_PCI_IO_PROTOCOL_WIDTH;
387
388typedef enum {
389 EfiPciIoAttributeOperationGet,
390 EfiPciIoAttributeOperationSet,
391 EfiPciIoAttributeOperationEnable,
392 EfiPciIoAttributeOperationDisable,
393 EfiPciIoAttributeOperationSupported,
394 EfiPciIoAttributeOperationMaximum
395} EFI_PCI_IO_PROTOCOL_ATTRIBUTE_OPERATION;
396
677703ce
MF
397typedef struct {
398 u32 read;
399 u32 write;
400} efi_pci_io_protocol_access_32_t;
401
402typedef struct {
403 u64 read;
404 u64 write;
405} efi_pci_io_protocol_access_64_t;
dd5fc854 406
1786e830
AB
407typedef union efi_pci_io_protocol efi_pci_io_protocol_t;
408
409typedef
410efi_status_t (*efi_pci_io_protocol_cfg_t)(efi_pci_io_protocol_t *,
411 EFI_PCI_IO_PROTOCOL_WIDTH,
412 u32 offset, unsigned long count,
413 void *buffer);
414
dd5fc854
MG
415typedef struct {
416 void *read;
417 void *write;
418} efi_pci_io_protocol_access_t;
419
1786e830
AB
420typedef struct {
421 efi_pci_io_protocol_cfg_t read;
422 efi_pci_io_protocol_cfg_t write;
423} efi_pci_io_protocol_config_access_t;
424
677703ce
MF
425typedef struct {
426 u32 poll_mem;
427 u32 poll_io;
428 efi_pci_io_protocol_access_32_t mem;
429 efi_pci_io_protocol_access_32_t io;
430 efi_pci_io_protocol_access_32_t pci;
431 u32 copy_mem;
432 u32 map;
433 u32 unmap;
434 u32 allocate_buffer;
435 u32 free_buffer;
436 u32 flush;
437 u32 get_location;
438 u32 attributes;
439 u32 get_bar_attributes;
440 u32 set_bar_attributes;
0b3225ab
AB
441 u64 romsize;
442 u32 romimage;
cb0ba793 443} efi_pci_io_protocol_32_t;
677703ce
MF
444
445typedef struct {
446 u64 poll_mem;
447 u64 poll_io;
448 efi_pci_io_protocol_access_64_t mem;
449 efi_pci_io_protocol_access_64_t io;
450 efi_pci_io_protocol_access_64_t pci;
451 u64 copy_mem;
452 u64 map;
453 u64 unmap;
454 u64 allocate_buffer;
455 u64 free_buffer;
456 u64 flush;
457 u64 get_location;
458 u64 attributes;
459 u64 get_bar_attributes;
460 u64 set_bar_attributes;
0b3225ab
AB
461 u64 romsize;
462 u64 romimage;
cb0ba793 463} efi_pci_io_protocol_64_t;
677703ce 464
1786e830
AB
465union efi_pci_io_protocol {
466 struct {
467 void *poll_mem;
468 void *poll_io;
469 efi_pci_io_protocol_access_t mem;
470 efi_pci_io_protocol_access_t io;
471 efi_pci_io_protocol_config_access_t pci;
472 void *copy_mem;
473 void *map;
474 void *unmap;
475 void *allocate_buffer;
476 void *free_buffer;
477 void *flush;
478 void *get_location;
479 void *attributes;
480 void *get_bar_attributes;
481 void *set_bar_attributes;
482 uint64_t romsize;
483 void *romimage;
484 };
485 struct {
486 u32 poll_mem;
487 u32 poll_io;
488 efi_pci_io_protocol_access_32_t mem;
489 efi_pci_io_protocol_access_32_t io;
490 efi_pci_io_protocol_access_32_t pci;
491 u32 copy_mem;
492 u32 map;
493 u32 unmap;
494 u32 allocate_buffer;
495 u32 free_buffer;
496 u32 flush;
497 u32 get_location;
498 u32 attributes;
499 u32 get_bar_attributes;
500 u32 set_bar_attributes;
501 u64 romsize;
502 u32 romimage;
503 } mixed_mode;
504};
dd5fc854
MG
505
506#define EFI_PCI_IO_ATTRIBUTE_ISA_MOTHERBOARD_IO 0x0001
507#define EFI_PCI_IO_ATTRIBUTE_ISA_IO 0x0002
508#define EFI_PCI_IO_ATTRIBUTE_VGA_PALETTE_IO 0x0004
509#define EFI_PCI_IO_ATTRIBUTE_VGA_MEMORY 0x0008
510#define EFI_PCI_IO_ATTRIBUTE_VGA_IO 0x0010
511#define EFI_PCI_IO_ATTRIBUTE_IDE_PRIMARY_IO 0x0020
512#define EFI_PCI_IO_ATTRIBUTE_IDE_SECONDARY_IO 0x0040
513#define EFI_PCI_IO_ATTRIBUTE_MEMORY_WRITE_COMBINE 0x0080
514#define EFI_PCI_IO_ATTRIBUTE_IO 0x0100
515#define EFI_PCI_IO_ATTRIBUTE_MEMORY 0x0200
516#define EFI_PCI_IO_ATTRIBUTE_BUS_MASTER 0x0400
517#define EFI_PCI_IO_ATTRIBUTE_MEMORY_CACHED 0x0800
518#define EFI_PCI_IO_ATTRIBUTE_MEMORY_DISABLE 0x1000
519#define EFI_PCI_IO_ATTRIBUTE_EMBEDDED_DEVICE 0x2000
520#define EFI_PCI_IO_ATTRIBUTE_EMBEDDED_ROM 0x4000
521#define EFI_PCI_IO_ATTRIBUTE_DUAL_ADDRESS_CYCLE 0x8000
522#define EFI_PCI_IO_ATTRIBUTE_ISA_IO_16 0x10000
523#define EFI_PCI_IO_ATTRIBUTE_VGA_PALETTE_IO_16 0x20000
524#define EFI_PCI_IO_ATTRIBUTE_VGA_IO_16 0x40000
525
58c5475a
LW
526typedef struct {
527 u32 version;
528 u32 get;
529 u32 set;
530 u32 del;
531 u32 get_all;
532} apple_properties_protocol_32_t;
533
534typedef struct {
535 u64 version;
536 u64 get;
537 u64 set;
538 u64 del;
539 u64 get_all;
540} apple_properties_protocol_64_t;
541
1786e830
AB
542struct efi_dev_path;
543
544typedef union apple_properties_protocol apple_properties_protocol_t;
545
546union apple_properties_protocol {
547 struct {
548 unsigned long version;
549 efi_status_t (*get)(apple_properties_protocol_t *,
550 struct efi_dev_path *, efi_char16_t *,
551 void *, u32 *);
552 efi_status_t (*set)(apple_properties_protocol_t *,
553 struct efi_dev_path *, efi_char16_t *,
554 void *, u32);
555 efi_status_t (*del)(apple_properties_protocol_t *,
556 struct efi_dev_path *, efi_char16_t *);
557 efi_status_t (*get_all)(apple_properties_protocol_t *,
558 void *buffer, u32 *);
559 };
560 struct {
561 u32 version;
562 u32 get;
563 u32 set;
564 u32 del;
565 u32 get_all;
566 } mixed_mode;
567};
568
33b6d034
TW
569typedef struct {
570 u32 get_capability;
571 u32 get_event_log;
572 u32 hash_log_extend_event;
573 u32 submit_command;
574 u32 get_active_pcr_banks;
575 u32 set_active_pcr_banks;
576 u32 get_result_of_set_active_pcr_banks;
577} efi_tcg2_protocol_32_t;
578
579typedef struct {
580 u64 get_capability;
581 u64 get_event_log;
582 u64 hash_log_extend_event;
583 u64 submit_command;
584 u64 get_active_pcr_banks;
585 u64 set_active_pcr_banks;
586 u64 get_result_of_set_active_pcr_banks;
587} efi_tcg2_protocol_64_t;
588
589typedef u32 efi_tcg2_event_log_format;
590
1786e830
AB
591typedef union efi_tcg2_protocol efi_tcg2_protocol_t;
592
593union efi_tcg2_protocol {
594 struct {
595 void *get_capability;
596 efi_status_t (*get_event_log)(efi_handle_t,
597 efi_tcg2_event_log_format,
598 efi_physical_addr_t *,
599 efi_physical_addr_t *,
600 efi_bool_t *);
601 void *hash_log_extend_event;
602 void *submit_command;
603 void *get_active_pcr_banks;
604 void *set_active_pcr_banks;
605 void *get_result_of_set_active_pcr_banks;
606 };
607 struct {
608 u32 get_capability;
609 u32 get_event_log;
610 u32 hash_log_extend_event;
611 u32 submit_command;
612 u32 get_active_pcr_banks;
613 u32 set_active_pcr_banks;
614 u32 get_result_of_set_active_pcr_banks;
615 } mixed_mode;
616};
33b6d034 617
1da177e4
LT
618/*
619 * Types and defines for EFI ResetSystem
620 */
621#define EFI_RESET_COLD 0
622#define EFI_RESET_WARM 1
623#define EFI_RESET_SHUTDOWN 2
624
625/*
626 * EFI Runtime Services table
627 */
628#define EFI_RUNTIME_SERVICES_SIGNATURE ((u64)0x5652453544e5552ULL)
629#define EFI_RUNTIME_SERVICES_REVISION 0x00010000
630
677703ce
MF
631typedef struct {
632 efi_table_hdr_t hdr;
633 u32 get_time;
634 u32 set_time;
635 u32 get_wakeup_time;
636 u32 set_wakeup_time;
637 u32 set_virtual_address_map;
638 u32 convert_pointer;
639 u32 get_variable;
640 u32 get_next_variable;
641 u32 set_variable;
642 u32 get_next_high_mono_count;
643 u32 reset_system;
644 u32 update_capsule;
645 u32 query_capsule_caps;
646 u32 query_variable_info;
647} efi_runtime_services_32_t;
648
649typedef struct {
650 efi_table_hdr_t hdr;
651 u64 get_time;
652 u64 set_time;
653 u64 get_wakeup_time;
654 u64 set_wakeup_time;
655 u64 set_virtual_address_map;
656 u64 convert_pointer;
657 u64 get_variable;
658 u64 get_next_variable;
659 u64 set_variable;
660 u64 get_next_high_mono_count;
661 u64 reset_system;
662 u64 update_capsule;
663 u64 query_capsule_caps;
664 u64 query_variable_info;
665} efi_runtime_services_64_t;
666
1da177e4
LT
667typedef efi_status_t efi_get_time_t (efi_time_t *tm, efi_time_cap_t *tc);
668typedef efi_status_t efi_set_time_t (efi_time_t *tm);
669typedef efi_status_t efi_get_wakeup_time_t (efi_bool_t *enabled, efi_bool_t *pending,
670 efi_time_t *tm);
671typedef efi_status_t efi_set_wakeup_time_t (efi_bool_t enabled, efi_time_t *tm);
672typedef efi_status_t efi_get_variable_t (efi_char16_t *name, efi_guid_t *vendor, u32 *attr,
673 unsigned long *data_size, void *data);
674typedef efi_status_t efi_get_next_variable_t (unsigned long *name_size, efi_char16_t *name,
675 efi_guid_t *vendor);
676typedef efi_status_t efi_set_variable_t (efi_char16_t *name, efi_guid_t *vendor,
f7a2d73f 677 u32 attr, unsigned long data_size,
1da177e4
LT
678 void *data);
679typedef efi_status_t efi_get_next_high_mono_count_t (u32 *count);
680typedef void efi_reset_system_t (int reset_type, efi_status_t status,
681 unsigned long data_size, efi_char16_t *data);
682typedef efi_status_t efi_set_virtual_address_map_t (unsigned long memory_map_size,
683 unsigned long descriptor_size,
684 u32 descriptor_version,
685 efi_memory_desc_t *virtual_map);
3b370237
MG
686typedef efi_status_t efi_query_variable_info_t(u32 attr,
687 u64 *storage_space,
688 u64 *remaining_space,
689 u64 *max_variable_size);
690typedef efi_status_t efi_update_capsule_t(efi_capsule_header_t **capsules,
691 unsigned long count,
692 unsigned long sg_list);
693typedef efi_status_t efi_query_capsule_caps_t(efi_capsule_header_t **capsules,
694 unsigned long count,
695 u64 *max_size,
696 int *reset_type);
ca0e30dc
AB
697typedef efi_status_t efi_query_variable_store_t(u32 attributes,
698 unsigned long size,
699 bool nonblocking);
1da177e4 700
1786e830
AB
701typedef union {
702 struct {
703 efi_table_hdr_t hdr;
704 efi_get_time_t *get_time;
705 efi_set_time_t *set_time;
706 efi_get_wakeup_time_t *get_wakeup_time;
707 efi_set_wakeup_time_t *set_wakeup_time;
708 efi_set_virtual_address_map_t *set_virtual_address_map;
709 void *convert_pointer;
710 efi_get_variable_t *get_variable;
711 efi_get_next_variable_t *get_next_variable;
712 efi_set_variable_t *set_variable;
713 efi_get_next_high_mono_count_t *get_next_high_mono_count;
714 efi_reset_system_t *reset_system;
715 efi_update_capsule_t *update_capsule;
716 efi_query_capsule_caps_t *query_capsule_caps;
717 efi_query_variable_info_t *query_variable_info;
718 };
719 efi_runtime_services_32_t mixed_mode;
c4c39c70
AB
720} efi_runtime_services_t;
721
022ee6c5
AB
722void efi_native_runtime_setup(void);
723
1da177e4 724/*
54fd11fe
PJ
725 * EFI Configuration Table and GUID definitions
726 *
7fb2b43c
IM
727 * These are all defined in a single line to make them easier to
728 * grep for and to see them at a glance - while still having a
729 * similar structure to the definitions in the spec.
730 *
731 * Here's how they are structured:
54fd11fe
PJ
732 *
733 * GUID: 12345678-1234-1234-1234-123456789012
734 * Spec:
735 * #define EFI_SOME_PROTOCOL_GUID \
736 * {0x12345678,0x1234,0x1234,\
737 * {0x12,0x34,0x12,0x34,0x56,0x78,0x90,0x12}}
738 * Here:
7fb2b43c
IM
739 * #define SOME_PROTOCOL_GUID EFI_GUID(0x12345678, 0x1234, 0x1234, 0x12, 0x34, 0x12, 0x34, 0x56, 0x78, 0x90, 0x12)
740 * ^ tabs ^extra space
741 *
742 * Note that the 'extra space' separates the values at the same place
743 * where the UEFI SPEC breaks the line.
1da177e4 744 */
7fb2b43c
IM
745#define NULL_GUID EFI_GUID(0x00000000, 0x0000, 0x0000, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00)
746#define MPS_TABLE_GUID EFI_GUID(0xeb9d2d2f, 0x2d88, 0x11d3, 0x9a, 0x16, 0x00, 0x90, 0x27, 0x3f, 0xc1, 0x4d)
747#define ACPI_TABLE_GUID EFI_GUID(0xeb9d2d30, 0x2d88, 0x11d3, 0x9a, 0x16, 0x00, 0x90, 0x27, 0x3f, 0xc1, 0x4d)
748#define ACPI_20_TABLE_GUID EFI_GUID(0x8868e871, 0xe4f1, 0x11d3, 0xbc, 0x22, 0x00, 0x80, 0xc7, 0x3c, 0x88, 0x81)
749#define SMBIOS_TABLE_GUID EFI_GUID(0xeb9d2d31, 0x2d88, 0x11d3, 0x9a, 0x16, 0x00, 0x90, 0x27, 0x3f, 0xc1, 0x4d)
750#define SMBIOS3_TABLE_GUID EFI_GUID(0xf2fd1544, 0x9794, 0x4a2c, 0x99, 0x2e, 0xe5, 0xbb, 0xcf, 0x20, 0xe3, 0x94)
751#define SAL_SYSTEM_TABLE_GUID EFI_GUID(0xeb9d2d32, 0x2d88, 0x11d3, 0x9a, 0x16, 0x00, 0x90, 0x27, 0x3f, 0xc1, 0x4d)
752#define HCDP_TABLE_GUID EFI_GUID(0xf951938d, 0x620b, 0x42ef, 0x82, 0x79, 0xa8, 0x4b, 0x79, 0x61, 0x78, 0x98)
753#define UGA_IO_PROTOCOL_GUID EFI_GUID(0x61a4d49e, 0x6f68, 0x4f1b, 0xb9, 0x22, 0xa8, 0x6e, 0xed, 0x0b, 0x07, 0xa2)
754#define EFI_GLOBAL_VARIABLE_GUID EFI_GUID(0x8be4df61, 0x93ca, 0x11d2, 0xaa, 0x0d, 0x00, 0xe0, 0x98, 0x03, 0x2b, 0x8c)
755#define UV_SYSTEM_TABLE_GUID EFI_GUID(0x3b13a7d4, 0x633e, 0x11dd, 0x93, 0xec, 0xda, 0x25, 0x56, 0xd8, 0x95, 0x93)
756#define LINUX_EFI_CRASH_GUID EFI_GUID(0xcfc8fc79, 0xbe2e, 0x4ddc, 0x97, 0xf0, 0x9f, 0x98, 0xbf, 0xe2, 0x98, 0xa0)
757#define LOADED_IMAGE_PROTOCOL_GUID EFI_GUID(0x5b1b31a1, 0x9562, 0x11d2, 0x8e, 0x3f, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b)
758#define EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID EFI_GUID(0x9042a9de, 0x23dc, 0x4a38, 0x96, 0xfb, 0x7a, 0xde, 0xd0, 0x80, 0x51, 0x6a)
759#define EFI_UGA_PROTOCOL_GUID EFI_GUID(0x982c298b, 0xf4fa, 0x41cb, 0xb8, 0x38, 0x77, 0xaa, 0x68, 0x8f, 0xb8, 0x39)
760#define EFI_PCI_IO_PROTOCOL_GUID EFI_GUID(0x4cf5b200, 0x68b8, 0x4ca5, 0x9e, 0xec, 0xb2, 0x3e, 0x3f, 0x50, 0x02, 0x9a)
761#define EFI_FILE_INFO_ID EFI_GUID(0x09576e92, 0x6d3f, 0x11d2, 0x8e, 0x39, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b)
762#define EFI_SYSTEM_RESOURCE_TABLE_GUID EFI_GUID(0xb122a263, 0x3661, 0x4f68, 0x99, 0x29, 0x78, 0xf8, 0xb0, 0xd6, 0x21, 0x80)
763#define EFI_FILE_SYSTEM_GUID EFI_GUID(0x964e5b22, 0x6459, 0x11d2, 0x8e, 0x39, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b)
764#define DEVICE_TREE_GUID EFI_GUID(0xb1b621d5, 0xf19c, 0x41a5, 0x83, 0x0b, 0xd9, 0x15, 0x2c, 0x69, 0xaa, 0xe0)
765#define EFI_PROPERTIES_TABLE_GUID EFI_GUID(0x880aaca3, 0x4adc, 0x4a04, 0x90, 0x79, 0xb7, 0x47, 0x34, 0x08, 0x25, 0xe5)
766#define EFI_RNG_PROTOCOL_GUID EFI_GUID(0x3152bca5, 0xeade, 0x433d, 0x86, 0x2e, 0xc0, 0x1c, 0xdc, 0x29, 0x1f, 0x44)
568bc4e8 767#define EFI_RNG_ALGORITHM_RAW EFI_GUID(0xe43176d7, 0xb6e8, 0x4827, 0xb7, 0x84, 0x7f, 0xfd, 0xc4, 0xb6, 0x85, 0x61)
7fb2b43c
IM
768#define EFI_MEMORY_ATTRIBUTES_TABLE_GUID EFI_GUID(0xdcfa911d, 0x26eb, 0x469f, 0xa2, 0x20, 0x38, 0xb7, 0xdc, 0x46, 0x12, 0x20)
769#define EFI_CONSOLE_OUT_DEVICE_GUID EFI_GUID(0xd3b36f2c, 0xd551, 0x11d4, 0x9a, 0x46, 0x00, 0x90, 0x27, 0x3f, 0xc1, 0x4d)
58c5475a 770#define APPLE_PROPERTIES_PROTOCOL_GUID EFI_GUID(0x91bd12fe, 0xf6c3, 0x44fb, 0xa5, 0xb7, 0x51, 0x22, 0xab, 0x30, 0x3a, 0xe0)
33b6d034 771#define EFI_TCG2_PROTOCOL_GUID EFI_GUID(0x607f766c, 0x7455, 0x42be, 0x93, 0x0b, 0xe4, 0xd7, 0x6d, 0xb2, 0x72, 0x0f)
fc372064 772
e58910cd
JB
773#define EFI_IMAGE_SECURITY_DATABASE_GUID EFI_GUID(0xd719b2cb, 0x3d3a, 0x4596, 0xa3, 0xbc, 0xda, 0xd0, 0x0e, 0x67, 0x65, 0x6f)
774#define EFI_SHIM_LOCK_GUID EFI_GUID(0x605dab50, 0xe046, 0x4300, 0xab, 0xb6, 0x3d, 0xd8, 0x10, 0xdd, 0x8b, 0x23)
775
5c126ba2
DH
776#define EFI_CERT_SHA256_GUID EFI_GUID(0xc1c41626, 0x504c, 0x4092, 0xac, 0xa9, 0x41, 0xf9, 0x36, 0x93, 0x43, 0x28)
777#define EFI_CERT_X509_GUID EFI_GUID(0xa5c059a1, 0x94e4, 0x4aa7, 0x87, 0xb5, 0xab, 0x15, 0x5c, 0x2b, 0xf0, 0x72)
778#define EFI_CERT_X509_SHA256_GUID EFI_GUID(0x3bd2a492, 0x96c0, 0x4079, 0xb4, 0x20, 0xfc, 0xf9, 0x8e, 0xf1, 0x03, 0xed)
779
801820be
AB
780/*
781 * This GUID is used to pass to the kernel proper the struct screen_info
782 * structure that was populated by the stub based on the GOP protocol instance
783 * associated with ConOut
784 */
7fb2b43c
IM
785#define LINUX_EFI_ARM_SCREEN_INFO_TABLE_GUID EFI_GUID(0xe03fc20a, 0x85dc, 0x406e, 0xb9, 0x0e, 0x4a, 0xb5, 0x02, 0x37, 0x1d, 0x95)
786#define LINUX_EFI_LOADER_ENTRY_GUID EFI_GUID(0x4a67b082, 0x0a4c, 0x41cf, 0xb6, 0xc7, 0x44, 0x0b, 0x29, 0xbb, 0x8c, 0x4f)
63625988 787#define LINUX_EFI_RANDOM_SEED_TABLE_GUID EFI_GUID(0x1ce1e5bc, 0x7ceb, 0x42f2, 0x81, 0xe5, 0x8a, 0xad, 0xf1, 0x80, 0xf5, 0x7b)
33b6d034 788#define LINUX_EFI_TPM_EVENT_LOG_GUID EFI_GUID(0xb7799cb0, 0xeca2, 0x4943, 0x96, 0x67, 0x1f, 0xae, 0x07, 0xb7, 0x47, 0xfa)
c46f3405 789#define LINUX_EFI_TPM_FINAL_LOG_GUID EFI_GUID(0x1e2ed096, 0x30e2, 0x4254, 0xbd, 0x89, 0x86, 0x3b, 0xbe, 0xf8, 0x23, 0x25)
71e0940d 790#define LINUX_EFI_MEMRESERVE_TABLE_GUID EFI_GUID(0x888eb0c6, 0x8ede, 0x4ff5, 0xa8, 0xf0, 0x9a, 0xee, 0x5c, 0xb9, 0x77, 0xc2)
06f7d4a1 791
1c5fecb6
N
792/* OEM GUIDs */
793#define DELLEMC_EFI_RCI2_TABLE_GUID EFI_GUID(0x2d9f28a2, 0xa886, 0x456a, 0x97, 0xa8, 0xf1, 0x1e, 0xf2, 0x4f, 0xf4, 0x55)
794
1adbfa35
OJ
795typedef struct {
796 efi_guid_t guid;
797 u64 table;
798} efi_config_table_64_t;
799
800typedef struct {
801 efi_guid_t guid;
802 u32 table;
803} efi_config_table_32_t;
804
1786e830
AB
805typedef union {
806 struct {
807 efi_guid_t guid;
808 unsigned long table;
809 };
810 efi_config_table_32_t mixed_mode;
1da177e4
LT
811} efi_config_table_t;
812
272686bf
LL
813typedef struct {
814 efi_guid_t guid;
815 const char *name;
816 unsigned long *ptr;
817} efi_config_table_type_t;
818
1da177e4 819#define EFI_SYSTEM_TABLE_SIGNATURE ((u64)0x5453595320494249ULL)
1da177e4 820
3b370237
MG
821#define EFI_2_30_SYSTEM_TABLE_REVISION ((2 << 16) | (30))
822#define EFI_2_20_SYSTEM_TABLE_REVISION ((2 << 16) | (20))
823#define EFI_2_10_SYSTEM_TABLE_REVISION ((2 << 16) | (10))
824#define EFI_2_00_SYSTEM_TABLE_REVISION ((2 << 16) | (00))
825#define EFI_1_10_SYSTEM_TABLE_REVISION ((1 << 16) | (10))
826#define EFI_1_02_SYSTEM_TABLE_REVISION ((1 << 16) | (02))
827
1adbfa35
OJ
828typedef struct {
829 efi_table_hdr_t hdr;
830 u64 fw_vendor; /* physical addr of CHAR16 vendor string */
831 u32 fw_revision;
832 u32 __pad1;
833 u64 con_in_handle;
834 u64 con_in;
835 u64 con_out_handle;
836 u64 con_out;
837 u64 stderr_handle;
838 u64 stderr;
839 u64 runtime;
840 u64 boottime;
841 u32 nr_tables;
842 u32 __pad2;
843 u64 tables;
844} efi_system_table_64_t;
845
846typedef struct {
847 efi_table_hdr_t hdr;
848 u32 fw_vendor; /* physical addr of CHAR16 vendor string */
849 u32 fw_revision;
850 u32 con_in_handle;
851 u32 con_in;
852 u32 con_out_handle;
853 u32 con_out;
854 u32 stderr_handle;
855 u32 stderr;
856 u32 runtime;
857 u32 boottime;
858 u32 nr_tables;
859 u32 tables;
860} efi_system_table_32_t;
861
1786e830
AB
862typedef union {
863 struct {
864 efi_table_hdr_t hdr;
865 unsigned long fw_vendor; /* physical addr of CHAR16 vendor string */
866 u32 fw_revision;
867 unsigned long con_in_handle;
868 unsigned long con_in;
869 unsigned long con_out_handle;
870 unsigned long con_out;
871 unsigned long stderr_handle;
872 unsigned long stderr;
873 efi_runtime_services_t *runtime;
874 efi_boot_services_t *boottime;
875 unsigned long nr_tables;
876 unsigned long tables;
877 };
878 efi_system_table_32_t mixed_mode;
1da177e4
LT
879} efi_system_table_t;
880
9479c7ce
MF
881/*
882 * Architecture independent structure for describing a memory map for the
883 * benefit of efi_memmap_init_early(), saving us the need to pass four
884 * parameters.
885 */
886struct efi_memory_map_data {
887 phys_addr_t phys_map;
888 unsigned long size;
889 unsigned long desc_version;
890 unsigned long desc_size;
891};
892
1da177e4 893struct efi_memory_map {
44511fb9 894 phys_addr_t phys_map;
7ae65fd3
MT
895 void *map;
896 void *map_end;
1da177e4
LT
897 int nr_map;
898 unsigned long desc_version;
7ae65fd3 899 unsigned long desc_size;
dca0f971 900 bool late;
1da177e4
LT
901};
902
60863c0d
MF
903struct efi_mem_range {
904 struct range range;
905 u64 attribute;
1da177e4
LT
906};
907
0302f71c
MS
908struct efi_fdt_params {
909 u64 system_table;
910 u64 mmap;
911 u32 mmap_size;
912 u32 desc_size;
913 u32 desc_ver;
914};
915
677703ce
MF
916typedef struct {
917 u32 revision;
918 u32 parent_handle;
919 u32 system_table;
920 u32 device_handle;
921 u32 file_path;
922 u32 reserved;
923 u32 load_options_size;
924 u32 load_options;
925 u32 image_base;
926 __aligned_u64 image_size;
927 unsigned int image_code_type;
928 unsigned int image_data_type;
9fa76ca7 929 u32 unload;
677703ce
MF
930} efi_loaded_image_32_t;
931
932typedef struct {
933 u32 revision;
934 u64 parent_handle;
935 u64 system_table;
936 u64 device_handle;
937 u64 file_path;
938 u64 reserved;
939 u32 load_options_size;
940 u64 load_options;
941 u64 image_base;
942 __aligned_u64 image_size;
943 unsigned int image_code_type;
944 unsigned int image_data_type;
9fa76ca7 945 u64 unload;
677703ce
MF
946} efi_loaded_image_64_t;
947
1786e830
AB
948typedef union efi_loaded_image efi_loaded_image_t;
949
950union efi_loaded_image {
951 struct {
952 u32 revision;
953 efi_handle_t parent_handle;
954 efi_system_table_t *system_table;
955 efi_handle_t device_handle;
956 void *file_path;
957 void *reserved;
958 u32 load_options_size;
959 void *load_options;
960 void *image_base;
961 __aligned_u64 image_size;
962 unsigned int image_code_type;
963 unsigned int image_data_type;
964 efi_status_t (*unload)(efi_handle_t image_handle);
965 };
966 struct {
967 u32 revision;
968 u32 parent_handle;
969 u32 system_table;
970 u32 device_handle;
971 u32 file_path;
972 u32 reserved;
973 u32 load_options_size;
974 u32 load_options;
975 u32 image_base;
976 __aligned_u64 image_size;
977 unsigned int image_code_type;
978 unsigned int image_data_type;
979 u32 unload;
980 } mixed_mode;
981};
55839d51
MF
982
983typedef struct {
984 u64 size;
985 u64 file_size;
986 u64 phys_size;
987 efi_time_t create_time;
988 efi_time_t last_access_time;
989 efi_time_t modification_time;
990 __aligned_u64 attribute;
991 efi_char16_t filename[1];
992} efi_file_info_t;
993
677703ce
MF
994typedef struct {
995 u64 revision;
996 u32 open;
997 u32 close;
998 u32 delete;
999 u32 read;
1000 u32 write;
1001 u32 get_position;
1002 u32 set_position;
1003 u32 get_info;
1004 u32 set_info;
1005 u32 flush;
1006} efi_file_handle_32_t;
1007
1008typedef struct {
1009 u64 revision;
1010 u64 open;
1011 u64 close;
1012 u64 delete;
1013 u64 read;
1014 u64 write;
1015 u64 get_position;
1016 u64 set_position;
1017 u64 get_info;
1018 u64 set_info;
1019 u64 flush;
1020} efi_file_handle_64_t;
1021
1786e830
AB
1022typedef union efi_file_handle efi_file_handle_t;
1023
1024union efi_file_handle {
1025 struct {
1026 u64 revision;
1027 efi_status_t (*open)(efi_file_handle_t *,
1028 efi_file_handle_t **,
1029 efi_char16_t *, u64, u64);
1030 efi_status_t (*close)(efi_file_handle_t *);
1031 void *delete;
1032 efi_status_t (*read)(efi_file_handle_t *, unsigned long *,
1033 void *);
1034 void *write;
1035 void *get_position;
1036 void *set_position;
1037 efi_status_t (*get_info)(efi_file_handle_t *, efi_guid_t *,
1038 unsigned long *, void *);
1039 void *set_info;
1040 void *flush;
1041 };
1042 struct {
1043 u64 revision;
1044 u32 open;
1045 u32 close;
1046 u32 delete;
1047 u32 read;
1048 u32 write;
1049 u32 get_position;
1050 u32 set_position;
1051 u32 get_info;
1052 u32 set_info;
1053 u32 flush;
1054 } mixed_mode;
1055};
55839d51 1056
c4db9c1e
LW
1057typedef struct {
1058 u64 revision;
1059 u32 open_volume;
1060} efi_file_io_interface_32_t;
1061
1062typedef struct {
1063 u64 revision;
1064 u64 open_volume;
1065} efi_file_io_interface_64_t;
1066
1786e830
AB
1067typedef union efi_file_io_interface efi_file_io_interface_t;
1068
1069union efi_file_io_interface {
1070 struct {
1071 u64 revision;
1072 int (*open_volume)(efi_file_io_interface_t *,
1073 efi_file_handle_t **);
1074 };
1075 struct {
1076 u64 revision;
1077 u32 open_volume;
1078 } mixed_mode;
1079} ;
ed37ddff 1080
55839d51
MF
1081#define EFI_FILE_MODE_READ 0x0000000000000001
1082#define EFI_FILE_MODE_WRITE 0x0000000000000002
1083#define EFI_FILE_MODE_CREATE 0x8000000000000000
1084
bf924863
AB
1085typedef struct {
1086 u32 version;
1087 u32 length;
1088 u64 memory_protection_attribute;
1089} efi_properties_table_t;
1090
1091#define EFI_PROPERTIES_TABLE_VERSION 0x00010000
1092#define EFI_PROPERTIES_RUNTIME_MEMORY_PROTECTION_NON_EXECUTABLE_PE_DATA 0x1
1093
b2c99e3c
BH
1094#define EFI_INVALID_TABLE_ADDR (~0UL)
1095
a604af07
AB
1096typedef struct {
1097 u32 version;
1098 u32 num_entries;
1099 u32 desc_size;
1100 u32 reserved;
1101 efi_memory_desc_t entry[0];
1102} efi_memory_attributes_table_t;
1103
5c126ba2
DH
1104typedef struct {
1105 efi_guid_t signature_owner;
1106 u8 signature_data[];
1107} efi_signature_data_t;
1108
1109typedef struct {
1110 efi_guid_t signature_type;
1111 u32 signature_list_size;
1112 u32 signature_header_size;
1113 u32 signature_size;
1114 u8 signature_header[];
1115 /* efi_signature_data_t signatures[][] */
1116} efi_signature_list_t;
1117
1118typedef u8 efi_sha256_hash_t[32];
1119
1120typedef struct {
1121 efi_sha256_hash_t to_be_signed_hash;
1122 efi_time_t time_of_revocation;
1123} efi_cert_x509_sha256_t;
1124
1da177e4
LT
1125/*
1126 * All runtime access to EFI goes through this structure:
1127 */
1128extern struct efi {
1129 efi_system_table_t *systab; /* EFI system table */
3b370237 1130 unsigned int runtime_version; /* Runtime services version */
b2c99e3c
BH
1131 unsigned long mps; /* MPS table */
1132 unsigned long acpi; /* ACPI table (IA64 ext 0.71) */
1133 unsigned long acpi20; /* ACPI table (ACPI 2.0) */
e1ccbbc9
AB
1134 unsigned long smbios; /* SMBIOS table (32 bit entry point) */
1135 unsigned long smbios3; /* SMBIOS table (64 bit entry point) */
b2c99e3c
BH
1136 unsigned long boot_info; /* boot info table */
1137 unsigned long hcdp; /* HCDP table */
1138 unsigned long uga; /* UGA table */
a0998eb1
DY
1139 unsigned long fw_vendor; /* fw_vendor */
1140 unsigned long runtime; /* runtime table */
1141 unsigned long config_table; /* config tables */
0bb54905 1142 unsigned long esrt; /* ESRT table */
bf924863 1143 unsigned long properties_table; /* properties table */
a604af07 1144 unsigned long mem_attr_table; /* memory attributes table */
63625988 1145 unsigned long rng_seed; /* UEFI firmware random seed */
33b6d034 1146 unsigned long tpm_log; /* TPM2 Event Log table */
c46f3405 1147 unsigned long tpm_final_log; /* TPM2 Final Events Log table */
71e0940d 1148 unsigned long mem_reserve; /* Linux EFI memreserve table */
1da177e4
LT
1149 efi_get_time_t *get_time;
1150 efi_set_time_t *set_time;
1151 efi_get_wakeup_time_t *get_wakeup_time;
1152 efi_set_wakeup_time_t *set_wakeup_time;
1153 efi_get_variable_t *get_variable;
1154 efi_get_next_variable_t *get_next_variable;
1155 efi_set_variable_t *set_variable;
70d2a3cf 1156 efi_set_variable_t *set_variable_nonblocking;
3b370237 1157 efi_query_variable_info_t *query_variable_info;
d3cac1f8 1158 efi_query_variable_info_t *query_variable_info_nonblocking;
3b370237
MG
1159 efi_update_capsule_t *update_capsule;
1160 efi_query_capsule_caps_t *query_capsule_caps;
1da177e4
LT
1161 efi_get_next_high_mono_count_t *get_next_high_mono_count;
1162 efi_reset_system_t *reset_system;
1163 efi_set_virtual_address_map_t *set_virtual_address_map;
884f4f66 1164 struct efi_memory_map memmap;
3e909599 1165 unsigned long flags;
1da177e4
LT
1166} efi;
1167
7e904a91
SP
1168extern struct mm_struct efi_mm;
1169
1da177e4
LT
1170static inline int
1171efi_guidcmp (efi_guid_t left, efi_guid_t right)
1172{
1173 return memcmp(&left, &right, sizeof (efi_guid_t));
1174}
1175
1176static inline char *
26e02272 1177efi_guid_to_str(efi_guid_t *guid, char *out)
1da177e4 1178{
925ede0b 1179 sprintf(out, "%pUl", guid->b);
1da177e4
LT
1180 return out;
1181}
1182
1183extern void efi_init (void);
1184extern void *efi_get_pal_addr (void);
1185extern void efi_map_pal_code (void);
1da177e4 1186extern void efi_memmap_walk (efi_freemem_callback_t callback, void *arg);
70f4f935 1187extern void efi_gettimeofday (struct timespec64 *ts);
1da177e4 1188extern void efi_enter_virtual_mode (void); /* switch EFI to virtual mode, if possible */
78510792 1189#ifdef CONFIG_X86
ca0e30dc
AB
1190extern efi_status_t efi_query_variable_store(u32 attributes,
1191 unsigned long size,
1192 bool nonblocking);
78510792 1193#else
a6e4d5a0 1194
ca0e30dc
AB
1195static inline efi_status_t efi_query_variable_store(u32 attributes,
1196 unsigned long size,
1197 bool nonblocking)
a6e4d5a0
MF
1198{
1199 return EFI_SUCCESS;
1200}
78510792 1201#endif
7bc90e01 1202extern void __iomem *efi_lookup_mapped_addr(u64 phys_addr);
9479c7ce 1203
20b1e22d 1204extern phys_addr_t __init efi_memmap_alloc(unsigned int num_entries);
9479c7ce 1205extern int __init efi_memmap_init_early(struct efi_memory_map_data *data);
dca0f971 1206extern int __init efi_memmap_init_late(phys_addr_t addr, unsigned long size);
9479c7ce 1207extern void __init efi_memmap_unmap(void);
c45f4da3 1208extern int __init efi_memmap_install(phys_addr_t addr, unsigned int nr_map);
60863c0d
MF
1209extern int __init efi_memmap_split_count(efi_memory_desc_t *md,
1210 struct range *range);
1211extern void __init efi_memmap_insert(struct efi_memory_map *old_memmap,
1212 void *buf, struct efi_mem_range *mem);
9479c7ce 1213
272686bf 1214extern int efi_config_init(efi_config_table_type_t *arch_tables);
3846c158 1215#ifdef CONFIG_EFI_ESRT
0bb54905 1216extern void __init efi_esrt_init(void);
3846c158
PJ
1217#else
1218static inline void efi_esrt_init(void) { }
1219#endif
7bb68410
AB
1220extern int efi_config_parse_tables(void *config_tables, int count, int sz,
1221 efi_config_table_type_t *arch_tables);
1da177e4 1222extern u64 efi_get_iobase (void);
f99afd08 1223extern int efi_mem_type(unsigned long phys_addr);
1da177e4 1224extern u64 efi_mem_attributes (unsigned long phys_addr);
32e62c63 1225extern u64 efi_mem_attribute (unsigned long phys_addr, unsigned long size);
1da177e4 1226extern int __init efi_uart_console_only (void);
0bb54905
PJ
1227extern u64 efi_mem_desc_end(efi_memory_desc_t *md);
1228extern int efi_mem_desc_lookup(u64 phys_addr, efi_memory_desc_t *out_md);
816e7612 1229extern void efi_mem_reserve(phys_addr_t addr, u64 size);
a23d3bb0 1230extern int efi_mem_reserve_persistent(phys_addr_t addr, u64 size);
1da177e4 1231extern void efi_initialize_iomem_resources(struct resource *code_resource,
00bf4098 1232 struct resource *data_resource, struct resource *bss_resource);
7968c0e3 1233extern int efi_get_fdt_params(struct efi_fdt_params *params);
0bb54905 1234extern struct kobject *efi_kobj;
1da177e4 1235
44be28e9 1236extern int efi_reboot_quirk_mode;
0c5ed61a
MF
1237extern bool efi_poweroff_required(void);
1238
0f96a99d
TI
1239#ifdef CONFIG_EFI_FAKE_MEMMAP
1240extern void __init efi_fake_memmap(void);
1241#else
1242static inline void efi_fake_memmap(void) { }
1243#endif
1244
10f0d2f5
AB
1245/*
1246 * efi_memattr_perm_setter - arch specific callback function passed into
1247 * efi_memattr_apply_permissions() that updates the
1248 * mapping permissions described by the second
1249 * argument in the page tables referred to by the
1250 * first argument.
1251 */
1252typedef int (*efi_memattr_perm_setter)(struct mm_struct *, efi_memory_desc_t *);
1253
1254extern int efi_memattr_init(void);
1255extern int efi_memattr_apply_permissions(struct mm_struct *mm,
1256 efi_memattr_perm_setter fn);
1257
02e43c2d
BH
1258/*
1259 * efi_early_memdesc_ptr - get the n-th EFI memmap descriptor
1260 * @map: the start of efi memmap
1261 * @desc_size: the size of space for each EFI memmap descriptor
1262 * @n: the index of efi memmap descriptor
1263 *
1264 * EFI boot service provides the GetMemoryMap() function to get a copy of the
1265 * current memory map which is an array of memory descriptors, each of
1266 * which describes a contiguous block of memory. It also gets the size of the
1267 * map, and the size of each descriptor, etc.
1268 *
1269 * Note that per section 6.2 of UEFI Spec 2.6 Errata A, the returned size of
1270 * each descriptor might not be equal to sizeof(efi_memory_memdesc_t),
1271 * since efi_memory_memdesc_t may be extended in the future. Thus the OS
1272 * MUST use the returned size of the descriptor to find the start of each
1273 * efi_memory_memdesc_t in the memory map array. This should only be used
1274 * during bootup since for_each_efi_memory_desc_xxx() is available after the
1275 * kernel initializes the EFI subsystem to set up struct efi_memory_map.
1276 */
1277#define efi_early_memdesc_ptr(map, desc_size, n) \
1278 (efi_memory_desc_t *)((void *)(map) + ((n) * (desc_size)))
1279
e885cd80 1280/* Iterate through an efi_memory_map */
78ce248f 1281#define for_each_efi_memory_desc_in_map(m, md) \
e885cd80 1282 for ((md) = (m)->map; \
d4c4fed0 1283 (md) && ((void *)(md) + (m)->desc_size) <= (m)->map_end; \
e885cd80
MS
1284 (md) = (void *)(md) + (m)->desc_size)
1285
78ce248f
MF
1286/**
1287 * for_each_efi_memory_desc - iterate over descriptors in efi.memmap
1288 * @md: the efi_memory_desc_t * iterator
1289 *
1290 * Once the loop finishes @md must not be accessed.
1291 */
1292#define for_each_efi_memory_desc(md) \
884f4f66 1293 for_each_efi_memory_desc_in_map(&efi.memmap, md)
78ce248f 1294
98d2a6ca
LE
1295/*
1296 * Format an EFI memory descriptor's type and attributes to a user-provided
1297 * character buffer, as per snprintf(), and return the buffer.
1298 */
1299char * __init efi_md_typeattr_format(char *buf, size_t size,
1300 const efi_memory_desc_t *md);
1301
0bc9ae39
DH
1302
1303typedef void (*efi_element_handler_t)(const char *source,
1304 const void *element_data,
1305 size_t element_size);
1306extern int __init parse_efi_signature_list(
1307 const char *source,
1308 const void *data, size_t size,
1309 efi_element_handler_t (*get_handler_for_guid)(const efi_guid_t *));
1310
1da177e4
LT
1311/**
1312 * efi_range_is_wc - check the WC bit on an address range
1313 * @start: starting kvirt address
1314 * @len: length of range
1315 *
1316 * Consult the EFI memory map and make sure it's ok to set this range WC.
1317 * Returns true or false.
1318 */
1319static inline int efi_range_is_wc(unsigned long start, unsigned long len)
1320{
986a80d5 1321 unsigned long i;
1da177e4
LT
1322
1323 for (i = 0; i < len; i += (1UL << EFI_PAGE_SHIFT)) {
1324 unsigned long paddr = __pa(start + i);
1325 if (!(efi_mem_attributes(paddr) & EFI_MEMORY_WC))
1326 return 0;
1327 }
1328 /* The range checked out */
1329 return 1;
1330}
1331
1332#ifdef CONFIG_EFI_PCDP
1333extern int __init efi_setup_pcdp_console(char *);
1334#endif
1335
1336/*
83e68189
MF
1337 * We play games with efi_enabled so that the compiler will, if
1338 * possible, remove EFI-related code altogether.
1da177e4 1339 */
83e68189 1340#define EFI_BOOT 0 /* Were we booted from EFI? */
83e68189
MF
1341#define EFI_CONFIG_TABLES 2 /* Can we use EFI config tables? */
1342#define EFI_RUNTIME_SERVICES 3 /* Can we use runtime services? */
1343#define EFI_MEMMAP 4 /* Can we use EFI memory map? */
1344#define EFI_64BIT 5 /* Is the firmware 64-bit? */
9f27bc54
DK
1345#define EFI_PARAVIRT 6 /* Access is via a paravirt interface */
1346#define EFI_ARCH_1 7 /* First arch-specific bit */
fed6cefe 1347#define EFI_DBG 8 /* Print additional debug info at runtime */
a1041713 1348#define EFI_NX_PE_DATA 9 /* Can runtime data regions be mapped non-executable? */
a19ebf59 1349#define EFI_MEM_ATTR 10 /* Did firmware publish an EFI_MEMORY_ATTRIBUTES table? */
b617c526 1350#define EFI_MEM_NO_SOFT_RESERVE 11 /* Is the kernel configured to ignore soft reservations? */
83e68189 1351
1da177e4 1352#ifdef CONFIG_EFI
3e909599
MF
1353/*
1354 * Test whether the above EFI_* bits are enabled.
1355 */
1356static inline bool efi_enabled(int feature)
1357{
1358 return test_bit(feature, &efi.flags) != 0;
1359}
8562c99c 1360extern void efi_reboot(enum reboot_mode reboot_mode, const char *__unused);
b617c526
DW
1361
1362bool __pure __efi_soft_reserve_enabled(void);
1363
1364static inline bool __pure efi_soft_reserve_enabled(void)
1365{
1366 return IS_ENABLED(CONFIG_EFI_SOFT_RESERVE)
1367 && __efi_soft_reserve_enabled();
1368}
1da177e4 1369#else
3e909599 1370static inline bool efi_enabled(int feature)
83e68189 1371{
3e909599 1372 return false;
83e68189 1373}
8562c99c
MF
1374static inline void
1375efi_reboot(enum reboot_mode reboot_mode, const char *__unused) {}
87615a34
MF
1376
1377static inline bool
1378efi_capsule_pending(int *reset_type)
1379{
1380 return false;
1381}
b617c526
DW
1382
1383static inline bool efi_soft_reserve_enabled(void)
1384{
1385 return false;
1386}
1da177e4
LT
1387#endif
1388
806b0351
MF
1389extern int efi_status_to_err(efi_status_t status);
1390
1da177e4
LT
1391/*
1392 * Variable Attributes
1393 */
1394#define EFI_VARIABLE_NON_VOLATILE 0x0000000000000001
1395#define EFI_VARIABLE_BOOTSERVICE_ACCESS 0x0000000000000002
1396#define EFI_VARIABLE_RUNTIME_ACCESS 0x0000000000000004
41b3254c
MG
1397#define EFI_VARIABLE_HARDWARE_ERROR_RECORD 0x0000000000000008
1398#define EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS 0x0000000000000010
1399#define EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS 0x0000000000000020
1400#define EFI_VARIABLE_APPEND_WRITE 0x0000000000000040
1401
1402#define EFI_VARIABLE_MASK (EFI_VARIABLE_NON_VOLATILE | \
1403 EFI_VARIABLE_BOOTSERVICE_ACCESS | \
1404 EFI_VARIABLE_RUNTIME_ACCESS | \
1405 EFI_VARIABLE_HARDWARE_ERROR_RECORD | \
1406 EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS | \
1407 EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS | \
1408 EFI_VARIABLE_APPEND_WRITE)
e14ab23d
MF
1409/*
1410 * Length of a GUID string (strlen("aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee"))
1411 * not including trailing NUL
1412 */
ba7e34b1 1413#define EFI_VARIABLE_GUID_LEN UUID_STRING_LEN
e14ab23d 1414
e2527a7c
MF
1415/*
1416 * The type of search to perform when calling boottime->locate_handle
1417 */
1418#define EFI_LOCATE_ALL_HANDLES 0
1419#define EFI_LOCATE_BY_REGISTER_NOTIFY 1
1420#define EFI_LOCATE_BY_PROTOCOL 2
1421
1da177e4
LT
1422/*
1423 * EFI Device Path information
1424 */
1425#define EFI_DEV_HW 0x01
1426#define EFI_DEV_PCI 1
1427#define EFI_DEV_PCCARD 2
1428#define EFI_DEV_MEM_MAPPED 3
1429#define EFI_DEV_VENDOR 4
1430#define EFI_DEV_CONTROLLER 5
1431#define EFI_DEV_ACPI 0x02
1432#define EFI_DEV_BASIC_ACPI 1
1433#define EFI_DEV_EXPANDED_ACPI 2
1434#define EFI_DEV_MSG 0x03
1435#define EFI_DEV_MSG_ATAPI 1
1436#define EFI_DEV_MSG_SCSI 2
1437#define EFI_DEV_MSG_FC 3
1438#define EFI_DEV_MSG_1394 4
1439#define EFI_DEV_MSG_USB 5
1440#define EFI_DEV_MSG_USB_CLASS 15
1441#define EFI_DEV_MSG_I20 6
1442#define EFI_DEV_MSG_MAC 11
1443#define EFI_DEV_MSG_IPV4 12
1444#define EFI_DEV_MSG_IPV6 13
1445#define EFI_DEV_MSG_INFINIBAND 9
1446#define EFI_DEV_MSG_UART 14
1447#define EFI_DEV_MSG_VENDOR 10
1448#define EFI_DEV_MEDIA 0x04
1449#define EFI_DEV_MEDIA_HARD_DRIVE 1
1450#define EFI_DEV_MEDIA_CDROM 2
1451#define EFI_DEV_MEDIA_VENDOR 3
1452#define EFI_DEV_MEDIA_FILE 4
1453#define EFI_DEV_MEDIA_PROTOCOL 5
1454#define EFI_DEV_BIOS_BOOT 0x05
1455#define EFI_DEV_END_PATH 0x7F
1456#define EFI_DEV_END_PATH2 0xFF
1457#define EFI_DEV_END_INSTANCE 0x01
1458#define EFI_DEV_END_ENTIRE 0xFF
1459
1460struct efi_generic_dev_path {
1461 u8 type;
1462 u8 sub_type;
1463 u16 length;
1464} __attribute ((packed));
1465
46cd4b75
LW
1466struct efi_dev_path {
1467 u8 type; /* can be replaced with unnamed */
1468 u8 sub_type; /* struct efi_generic_dev_path; */
1469 u16 length; /* once we've moved to -std=c11 */
1470 union {
1471 struct {
1472 u32 hid;
1473 u32 uid;
1474 } acpi;
1475 struct {
1476 u8 fn;
1477 u8 dev;
1478 } pci;
1479 };
1480} __attribute ((packed));
1481
1482#if IS_ENABLED(CONFIG_EFI_DEV_PATH_PARSER)
1483struct device *efi_get_device_by_path(struct efi_dev_path **node, size_t *len);
1484#endif
1485
4a3575fd
HY
1486static inline void memrange_efi_to_native(u64 *addr, u64 *npages)
1487{
1488 *npages = PFN_UP(*addr + (*npages<<EFI_PAGE_SHIFT)) - PFN_DOWN(*addr);
1489 *addr &= PAGE_MASK;
1490}
1491
4fc756bd
MW
1492/*
1493 * EFI Variable support.
1494 *
1495 * Different firmware drivers can expose their EFI-like variables using
1496 * the following.
1497 */
1498
1499struct efivar_operations {
1500 efi_get_variable_t *get_variable;
1501 efi_get_next_variable_t *get_next_variable;
1502 efi_set_variable_t *set_variable;
70d2a3cf 1503 efi_set_variable_t *set_variable_nonblocking;
a6e4d5a0 1504 efi_query_variable_store_t *query_variable_store;
4fc756bd
MW
1505};
1506
1507struct efivars {
4fc756bd 1508 struct kset *kset;
605e70c7 1509 struct kobject *kobject;
4fc756bd
MW
1510 const struct efivar_operations *ops;
1511};
1512
e14ab23d
MF
1513/*
1514 * The maximum size of VariableName + Data = 1024
1515 * Therefore, it's reasonable to save that much
1516 * space in each part of the structure,
1517 * and we use a page for reading/writing.
1518 */
1519
a5d92ad3
MF
1520#define EFI_VAR_NAME_LEN 1024
1521
e14ab23d 1522struct efi_variable {
a5d92ad3 1523 efi_char16_t VariableName[EFI_VAR_NAME_LEN/sizeof(efi_char16_t)];
e14ab23d
MF
1524 efi_guid_t VendorGuid;
1525 unsigned long DataSize;
1526 __u8 Data[1024];
1527 efi_status_t Status;
1528 __u32 Attributes;
1529} __attribute__((packed));
1530
1531struct efivar_entry {
1532 struct efi_variable var;
1533 struct list_head list;
1534 struct kobject kobj;
e0d59733
SA
1535 bool scanning;
1536 bool deleting;
e14ab23d
MF
1537};
1538
db4545d9 1539typedef struct {
677703ce
MF
1540 u32 reset;
1541 u32 output_string;
1542 u32 test_string;
db4545d9 1543} efi_simple_text_output_protocol_32_t;
677703ce 1544
db4545d9 1545typedef struct {
677703ce
MF
1546 u64 reset;
1547 u64 output_string;
1548 u64 test_string;
db4545d9 1549} efi_simple_text_output_protocol_64_t;
ed37ddff 1550
1786e830
AB
1551typedef union efi_simple_text_output_protocol efi_simple_text_output_protocol_t;
1552
1553union efi_simple_text_output_protocol {
1554 struct {
1555 void *reset;
1556 efi_status_t (*output_string)(efi_simple_text_output_protocol_t *,
1557 efi_char16_t *);
1558 void *test_string;
1559 };
1560 struct {
1561 u32 reset;
1562 u32 output_string;
1563 u32 test_string;
1564 } mixed_mode;
ed37ddff
RF
1565};
1566
fc372064
AB
1567#define PIXEL_RGB_RESERVED_8BIT_PER_COLOR 0
1568#define PIXEL_BGR_RESERVED_8BIT_PER_COLOR 1
1569#define PIXEL_BIT_MASK 2
1570#define PIXEL_BLT_ONLY 3
1571#define PIXEL_FORMAT_MAX 4
1572
44c84b4a 1573typedef struct {
fc372064
AB
1574 u32 red_mask;
1575 u32 green_mask;
1576 u32 blue_mask;
1577 u32 reserved_mask;
44c84b4a 1578} efi_pixel_bitmask_t;
fc372064 1579
44c84b4a 1580typedef struct {
fc372064
AB
1581 u32 version;
1582 u32 horizontal_resolution;
1583 u32 vertical_resolution;
1584 int pixel_format;
44c84b4a 1585 efi_pixel_bitmask_t pixel_information;
fc372064 1586 u32 pixels_per_scan_line;
44c84b4a 1587} efi_graphics_output_mode_info_t;
fc372064 1588
44c84b4a 1589typedef struct {
fc372064
AB
1590 u32 max_mode;
1591 u32 mode;
1592 u32 info;
1593 u32 size_of_info;
1594 u64 frame_buffer_base;
1595 u32 frame_buffer_size;
44c84b4a 1596} efi_graphics_output_protocol_mode_32_t;
fc372064 1597
44c84b4a 1598typedef struct {
fc372064
AB
1599 u32 max_mode;
1600 u32 mode;
1601 u64 info;
1602 u64 size_of_info;
1603 u64 frame_buffer_base;
1604 u64 frame_buffer_size;
44c84b4a 1605} efi_graphics_output_protocol_mode_64_t;
fc372064 1606
1786e830
AB
1607typedef union efi_graphics_output_protocol_mode efi_graphics_output_protocol_mode_t;
1608
1609union efi_graphics_output_protocol_mode {
1610 struct {
1611 u32 max_mode;
1612 u32 mode;
1613 efi_graphics_output_mode_info_t *info;
1614 unsigned long size_of_info;
1615 efi_physical_addr_t frame_buffer_base;
1616 unsigned long frame_buffer_size;
1617 };
1618 struct {
1619 u32 max_mode;
1620 u32 mode;
1621 u32 info;
1622 u32 size_of_info;
1623 u64 frame_buffer_base;
1624 u32 frame_buffer_size;
1625 } mixed_mode;
1626};
fc372064 1627
44c84b4a 1628typedef struct {
fc372064
AB
1629 u32 query_mode;
1630 u32 set_mode;
1631 u32 blt;
1632 u32 mode;
44c84b4a 1633} efi_graphics_output_protocol_32_t;
fc372064 1634
44c84b4a 1635typedef struct {
fc372064
AB
1636 u64 query_mode;
1637 u64 set_mode;
1638 u64 blt;
1639 u64 mode;
44c84b4a 1640} efi_graphics_output_protocol_64_t;
fc372064 1641
1786e830
AB
1642typedef union efi_graphics_output_protocol efi_graphics_output_protocol_t;
1643
1644union efi_graphics_output_protocol {
1645 struct {
1646 void *query_mode;
1647 void *set_mode;
1648 void *blt;
1649 efi_graphics_output_protocol_mode_t *mode;
1650 };
1651 struct {
1652 u32 query_mode;
1653 u32 set_mode;
1654 u32 blt;
1655 u32 mode;
1656 } mixed_mode;
1657};
fc372064 1658
04851772
MF
1659extern struct list_head efivar_sysfs_list;
1660
1661static inline void
1662efivar_unregister(struct efivar_entry *var)
1663{
1664 kobject_put(&var->kobj);
1665}
1666
e14ab23d 1667int efivars_register(struct efivars *efivars,
4fc756bd 1668 const struct efivar_operations *ops,
e14ab23d
MF
1669 struct kobject *kobject);
1670int efivars_unregister(struct efivars *efivars);
1671struct kobject *efivars_kobject(void);
1672
1673int efivar_init(int (*func)(efi_char16_t *, efi_guid_t, unsigned long, void *),
1cfd6316 1674 void *data, bool duplicates, struct list_head *head);
e14ab23d 1675
21b3ddd3
SC
1676int efivar_entry_add(struct efivar_entry *entry, struct list_head *head);
1677int efivar_entry_remove(struct efivar_entry *entry);
e14ab23d
MF
1678
1679int __efivar_entry_delete(struct efivar_entry *entry);
1680int efivar_entry_delete(struct efivar_entry *entry);
1681
e14ab23d 1682int efivar_entry_size(struct efivar_entry *entry, unsigned long *size);
8a415b8c
MF
1683int __efivar_entry_get(struct efivar_entry *entry, u32 *attributes,
1684 unsigned long *size, void *data);
e14ab23d
MF
1685int efivar_entry_get(struct efivar_entry *entry, u32 *attributes,
1686 unsigned long *size, void *data);
1687int efivar_entry_set(struct efivar_entry *entry, u32 attributes,
1688 unsigned long size, void *data, struct list_head *head);
1689int efivar_entry_set_get_size(struct efivar_entry *entry, u32 attributes,
1690 unsigned long *size, void *data, bool *set);
1691int efivar_entry_set_safe(efi_char16_t *name, efi_guid_t vendor, u32 attributes,
1692 bool block, unsigned long size, void *data);
1693
21b3ddd3 1694int efivar_entry_iter_begin(void);
e14ab23d
MF
1695void efivar_entry_iter_end(void);
1696
1697int __efivar_entry_iter(int (*func)(struct efivar_entry *, void *),
1698 struct list_head *head, void *data,
1699 struct efivar_entry **prev);
1700int efivar_entry_iter(int (*func)(struct efivar_entry *, void *),
1701 struct list_head *head, void *data);
1702
1703struct efivar_entry *efivar_entry_find(efi_char16_t *name, efi_guid_t guid,
1704 struct list_head *head, bool remove);
1705
8282f5d9
PJ
1706bool efivar_validate(efi_guid_t vendor, efi_char16_t *var_name, u8 *data,
1707 unsigned long data_size);
ed8b0de5
PJ
1708bool efivar_variable_is_removable(efi_guid_t vendor, const char *name,
1709 size_t len);
e14ab23d 1710
a9499fa7 1711extern struct work_struct efivar_work;
04851772
MF
1712void efivar_run_worker(void);
1713
a9499fa7 1714#if defined(CONFIG_EFI_VARS) || defined(CONFIG_EFI_VARS_MODULE)
e14ab23d 1715int efivars_sysfs_init(void);
4fc756bd 1716
e0d59733
SA
1717#define EFIVARS_DATA_SIZE_MAX 1024
1718
4fc756bd 1719#endif /* CONFIG_EFI_VARS */
f0133f3c
MF
1720extern bool efi_capsule_pending(int *reset_type);
1721
1722extern int efi_capsule_supported(efi_guid_t guid, u32 flags,
1723 size_t size, int *reset);
1724
1725extern int efi_capsule_update(efi_capsule_header_t *capsule,
2a457fb3 1726 phys_addr_t *pages);
4fc756bd 1727
926172d4
DY
1728#ifdef CONFIG_EFI_RUNTIME_MAP
1729int efi_runtime_map_init(struct kobject *);
6a2c20e7
VG
1730int efi_get_runtime_map_size(void);
1731int efi_get_runtime_map_desc_size(void);
1732int efi_runtime_map_copy(void *buf, size_t bufsz);
926172d4
DY
1733#else
1734static inline int efi_runtime_map_init(struct kobject *kobj)
1735{
1736 return 0;
1737}
1738
6a2c20e7
VG
1739static inline int efi_get_runtime_map_size(void)
1740{
1741 return 0;
1742}
1743
1744static inline int efi_get_runtime_map_desc_size(void)
1745{
1746 return 0;
1747}
1748
1749static inline int efi_runtime_map_copy(void *buf, size_t bufsz)
1750{
1751 return 0;
1752}
1753
926172d4
DY
1754#endif
1755
bd669475
AB
1756/* prototypes shared between arch specific and generic stub code */
1757
bd669475
AB
1758void efi_printk(efi_system_table_t *sys_table_arg, char *str);
1759
1760void efi_free(efi_system_table_t *sys_table_arg, unsigned long size,
1761 unsigned long addr);
1762
1763char *efi_convert_cmdline(efi_system_table_t *sys_table_arg,
1764 efi_loaded_image_t *image, int *cmd_line_len);
1765
1766efi_status_t efi_get_memory_map(efi_system_table_t *sys_table_arg,
dadb57ab 1767 struct efi_boot_memmap *map);
bd669475 1768
220dd769
KS
1769efi_status_t efi_low_alloc_above(efi_system_table_t *sys_table_arg,
1770 unsigned long size, unsigned long align,
1771 unsigned long *addr, unsigned long min);
1772
1773static inline
bd669475
AB
1774efi_status_t efi_low_alloc(efi_system_table_t *sys_table_arg,
1775 unsigned long size, unsigned long align,
220dd769
KS
1776 unsigned long *addr)
1777{
1778 /*
1779 * Don't allocate at 0x0. It will confuse code that
1780 * checks pointers against NULL. Skip the first 8
1781 * bytes so we start at a nice even number.
1782 */
1783 return efi_low_alloc_above(sys_table_arg, size, align, addr, 0x8);
1784}
bd669475
AB
1785
1786efi_status_t efi_high_alloc(efi_system_table_t *sys_table_arg,
1787 unsigned long size, unsigned long align,
1788 unsigned long *addr, unsigned long max);
1789
1790efi_status_t efi_relocate_kernel(efi_system_table_t *sys_table_arg,
1791 unsigned long *image_addr,
1792 unsigned long image_size,
1793 unsigned long alloc_size,
1794 unsigned long preferred_addr,
220dd769
KS
1795 unsigned long alignment,
1796 unsigned long min_addr);
bd669475
AB
1797
1798efi_status_t handle_cmdline_files(efi_system_table_t *sys_table_arg,
1799 efi_loaded_image_t *image,
1800 char *cmd_line, char *option_string,
1801 unsigned long max_addr,
1802 unsigned long *load_addr,
1803 unsigned long *load_size);
1804
60f38de7 1805efi_status_t efi_parse_options(char const *cmdline);
5a17dae4 1806
2c23b73c
AB
1807efi_status_t efi_setup_gop(efi_system_table_t *sys_table_arg,
1808 struct screen_info *si, efi_guid_t *proto,
1809 unsigned long size);
1810
0082517f
JHP
1811#ifdef CONFIG_EFI
1812extern bool efi_runtime_disabled(void);
1813#else
1814static inline bool efi_runtime_disabled(void) { return true; }
1815#endif
1816
80e75596 1817extern void efi_call_virt_check_flags(unsigned long flags, const char *call);
13b210dd 1818extern unsigned long efi_call_virt_save_flags(void);
80e75596 1819
de8cb458
DH
1820enum efi_secureboot_mode {
1821 efi_secureboot_mode_unset,
1822 efi_secureboot_mode_unknown,
1823 efi_secureboot_mode_disabled,
1824 efi_secureboot_mode_enabled,
1825};
1826enum efi_secureboot_mode efi_get_secureboot(efi_system_table_t *sys_table);
1827
ccc829ba
MG
1828#ifdef CONFIG_RESET_ATTACK_MITIGATION
1829void efi_enable_reset_attack_mitigation(efi_system_table_t *sys_table_arg);
1830#else
1831static inline void
1832efi_enable_reset_attack_mitigation(efi_system_table_t *sys_table_arg) { }
1833#endif
1834
0d959814
DB
1835efi_status_t efi_random_get_seed(efi_system_table_t *sys_table_arg);
1836
33b6d034
TW
1837void efi_retrieve_tpm2_eventlog(efi_system_table_t *sys_table);
1838
80e75596
AT
1839/*
1840 * Arch code can implement the following three template macros, avoiding
1841 * reptition for the void/non-void return cases of {__,}efi_call_virt():
1842 *
1843 * * arch_efi_call_virt_setup()
1844 *
1845 * Sets up the environment for the call (e.g. switching page tables,
1846 * allowing kernel-mode use of floating point, if required).
1847 *
1848 * * arch_efi_call_virt()
1849 *
1850 * Performs the call. The last expression in the macro must be the call
1851 * itself, allowing the logic to be shared by the void and non-void
1852 * cases.
1853 *
1854 * * arch_efi_call_virt_teardown()
1855 *
1856 * Restores the usual kernel environment once the call has returned.
1857 */
1858
1859#define efi_call_virt_pointer(p, f, args...) \
1860({ \
1861 efi_status_t __s; \
1862 unsigned long __flags; \
1863 \
1864 arch_efi_call_virt_setup(); \
1865 \
13b210dd 1866 __flags = efi_call_virt_save_flags(); \
80e75596
AT
1867 __s = arch_efi_call_virt(p, f, args); \
1868 efi_call_virt_check_flags(__flags, __stringify(f)); \
1869 \
1870 arch_efi_call_virt_teardown(); \
1871 \
1872 __s; \
1873})
1874
1875#define __efi_call_virt_pointer(p, f, args...) \
1876({ \
1877 unsigned long __flags; \
1878 \
1879 arch_efi_call_virt_setup(); \
1880 \
13b210dd 1881 __flags = efi_call_virt_save_flags(); \
80e75596
AT
1882 arch_efi_call_virt(p, f, args); \
1883 efi_call_virt_check_flags(__flags, __stringify(f)); \
1884 \
1885 arch_efi_call_virt_teardown(); \
1886})
1887
fc07716b
JH
1888typedef efi_status_t (*efi_exit_boot_map_processing)(
1889 efi_system_table_t *sys_table_arg,
1890 struct efi_boot_memmap *map,
1891 void *priv);
1892
1893efi_status_t efi_exit_boot_services(efi_system_table_t *sys_table,
1894 void *handle,
1895 struct efi_boot_memmap *map,
1896 void *priv,
1897 efi_exit_boot_map_processing priv_func);
63625988 1898
c2ceb5fd
AB
1899#define EFI_RANDOM_SEED_SIZE 64U
1900
63625988
AB
1901struct linux_efi_random_seed {
1902 u32 size;
1903 u8 bits[];
1904};
1905
33b6d034
TW
1906struct linux_efi_tpm_eventlog {
1907 u32 size;
166a2809 1908 u32 final_events_preboot_size;
33b6d034
TW
1909 u8 version;
1910 u8 log[];
1911};
1912
1913extern int efi_tpm_eventlog_init(void);
1914
c46f3405
MG
1915struct efi_tcg2_final_events_table {
1916 u64 version;
1917 u64 nr_events;
1918 u8 events[];
1919};
1920extern int efi_tpm_final_log_size;
1921
1c5fecb6
N
1922extern unsigned long rci2_table_phys;
1923
3425d934
SP
1924/*
1925 * efi_runtime_service() function identifiers.
1926 * "NONE" is used by efi_recover_from_page_fault() to check if the page
1927 * fault happened while executing an efi runtime service.
1928 */
9dbbedaa 1929enum efi_rts_ids {
5c418dc7
AR
1930 EFI_NONE,
1931 EFI_GET_TIME,
1932 EFI_SET_TIME,
1933 EFI_GET_WAKEUP_TIME,
1934 EFI_SET_WAKEUP_TIME,
1935 EFI_GET_VARIABLE,
1936 EFI_GET_NEXT_VARIABLE,
1937 EFI_SET_VARIABLE,
1938 EFI_QUERY_VARIABLE_INFO,
1939 EFI_GET_NEXT_HIGH_MONO_COUNT,
1940 EFI_RESET_SYSTEM,
1941 EFI_UPDATE_CAPSULE,
1942 EFI_QUERY_CAPSULE_CAPS,
9dbbedaa
SP
1943};
1944
1945/*
1946 * efi_runtime_work: Details of EFI Runtime Service work
1947 * @arg<1-5>: EFI Runtime Service function arguments
1948 * @status: Status of executing EFI Runtime Service
1949 * @efi_rts_id: EFI Runtime Service function identifier
1950 * @efi_rts_comp: Struct used for handling completions
1951 */
1952struct efi_runtime_work {
1953 void *arg1;
1954 void *arg2;
1955 void *arg3;
1956 void *arg4;
1957 void *arg5;
1958 efi_status_t status;
1959 struct work_struct work;
1960 enum efi_rts_ids efi_rts_id;
1961 struct completion efi_rts_comp;
1962};
1963
1964extern struct efi_runtime_work efi_rts_work;
1965
3eb420e7
SP
1966/* Workqueue to queue EFI Runtime Services */
1967extern struct workqueue_struct *efi_rts_wq;
1968
71e0940d 1969struct linux_efi_memreserve {
5f0b0ecf
AB
1970 int size; // allocated size of the array
1971 atomic_t count; // number of entries used
1972 phys_addr_t next; // pa of next struct instance
1973 struct {
1974 phys_addr_t base;
1975 phys_addr_t size;
1976 } entry[0];
71e0940d
AB
1977};
1978
5f0b0ecf
AB
1979#define EFI_MEMRESERVE_SIZE(count) (sizeof(struct linux_efi_memreserve) + \
1980 (count) * sizeof(((struct linux_efi_memreserve *)0)->entry[0]))
1981
80424b02
AB
1982#define EFI_MEMRESERVE_COUNT(size) (((size) - sizeof(struct linux_efi_memreserve)) \
1983 / sizeof(((struct linux_efi_memreserve *)0)->entry[0]))
1984
1da177e4 1985#endif /* _LINUX_EFI_H */