xref: /openbmc/linux/include/linux/efi.h (revision d4c4fed08f31f3746000c46cb1b20bed2959547a)
11da177e4SLinus Torvalds #ifndef _LINUX_EFI_H
21da177e4SLinus Torvalds #define _LINUX_EFI_H
31da177e4SLinus Torvalds 
41da177e4SLinus Torvalds /*
51da177e4SLinus Torvalds  * Extensible Firmware Interface
61da177e4SLinus Torvalds  * Based on 'Extensible Firmware Interface Specification' version 0.9, April 30, 1999
71da177e4SLinus Torvalds  *
81da177e4SLinus Torvalds  * Copyright (C) 1999 VA Linux Systems
91da177e4SLinus Torvalds  * Copyright (C) 1999 Walt Drummond <drummond@valinux.com>
101da177e4SLinus Torvalds  * Copyright (C) 1999, 2002-2003 Hewlett-Packard Co.
111da177e4SLinus Torvalds  *	David Mosberger-Tang <davidm@hpl.hp.com>
121da177e4SLinus Torvalds  *	Stephane Eranian <eranian@hpl.hp.com>
131da177e4SLinus Torvalds  */
141da177e4SLinus Torvalds #include <linux/init.h>
151da177e4SLinus Torvalds #include <linux/string.h>
161da177e4SLinus Torvalds #include <linux/time.h>
171da177e4SLinus Torvalds #include <linux/types.h>
181da177e4SLinus Torvalds #include <linux/proc_fs.h>
191da177e4SLinus Torvalds #include <linux/rtc.h>
201da177e4SLinus Torvalds #include <linux/ioport.h>
214a3575fdSHuang, Ying #include <linux/pfn.h>
225ee9c198SMatthew Garrett #include <linux/pstore.h>
238562c99cSMatt Fleming #include <linux/reboot.h>
24ba7e34b1SAndy Shevchenko #include <linux/uuid.h>
252c23b73cSArd Biesheuvel #include <linux/screen_info.h>
261da177e4SLinus Torvalds 
271da177e4SLinus Torvalds #include <asm/page.h>
281da177e4SLinus Torvalds 
291da177e4SLinus Torvalds #define EFI_SUCCESS		0
301da177e4SLinus Torvalds #define EFI_LOAD_ERROR          ( 1 | (1UL << (BITS_PER_LONG-1)))
311da177e4SLinus Torvalds #define EFI_INVALID_PARAMETER	( 2 | (1UL << (BITS_PER_LONG-1)))
321da177e4SLinus Torvalds #define EFI_UNSUPPORTED		( 3 | (1UL << (BITS_PER_LONG-1)))
331da177e4SLinus Torvalds #define EFI_BAD_BUFFER_SIZE     ( 4 | (1UL << (BITS_PER_LONG-1)))
341da177e4SLinus Torvalds #define EFI_BUFFER_TOO_SMALL	( 5 | (1UL << (BITS_PER_LONG-1)))
355d9db883SMatthew Garrett #define EFI_NOT_READY		( 6 | (1UL << (BITS_PER_LONG-1)))
365d9db883SMatthew Garrett #define EFI_DEVICE_ERROR	( 7 | (1UL << (BITS_PER_LONG-1)))
375d9db883SMatthew Garrett #define EFI_WRITE_PROTECTED	( 8 | (1UL << (BITS_PER_LONG-1)))
385d9db883SMatthew Garrett #define EFI_OUT_OF_RESOURCES	( 9 | (1UL << (BITS_PER_LONG-1)))
391da177e4SLinus Torvalds #define EFI_NOT_FOUND		(14 | (1UL << (BITS_PER_LONG-1)))
405d9db883SMatthew Garrett #define EFI_SECURITY_VIOLATION	(26 | (1UL << (BITS_PER_LONG-1)))
411da177e4SLinus Torvalds 
421da177e4SLinus Torvalds typedef unsigned long efi_status_t;
431da177e4SLinus Torvalds typedef u8 efi_bool_t;
441da177e4SLinus Torvalds typedef u16 efi_char16_t;		/* UNICODE character */
45ed37ddffSRoy Franz typedef u64 efi_physical_addr_t;
46ed37ddffSRoy Franz typedef void *efi_handle_t;
471da177e4SLinus Torvalds 
48ba7e34b1SAndy Shevchenko typedef uuid_le efi_guid_t;
491da177e4SLinus Torvalds 
501da177e4SLinus Torvalds #define EFI_GUID(a,b,c,d0,d1,d2,d3,d4,d5,d6,d7) \
51ba7e34b1SAndy Shevchenko 	UUID_LE(a, b, c, d0, d1, d2, d3, d4, d5, d6, d7)
521da177e4SLinus Torvalds 
531da177e4SLinus Torvalds /*
541da177e4SLinus Torvalds  * Generic EFI table header
551da177e4SLinus Torvalds  */
561da177e4SLinus Torvalds typedef	struct {
571da177e4SLinus Torvalds 	u64 signature;
581da177e4SLinus Torvalds 	u32 revision;
591da177e4SLinus Torvalds 	u32 headersize;
601da177e4SLinus Torvalds 	u32 crc32;
611da177e4SLinus Torvalds 	u32 reserved;
621da177e4SLinus Torvalds } efi_table_hdr_t;
631da177e4SLinus Torvalds 
641da177e4SLinus Torvalds /*
651da177e4SLinus Torvalds  * Memory map descriptor:
661da177e4SLinus Torvalds  */
671da177e4SLinus Torvalds 
681da177e4SLinus Torvalds /* Memory types: */
691da177e4SLinus Torvalds #define EFI_RESERVED_TYPE		 0
701da177e4SLinus Torvalds #define EFI_LOADER_CODE			 1
711da177e4SLinus Torvalds #define EFI_LOADER_DATA			 2
721da177e4SLinus Torvalds #define EFI_BOOT_SERVICES_CODE		 3
731da177e4SLinus Torvalds #define EFI_BOOT_SERVICES_DATA		 4
741da177e4SLinus Torvalds #define EFI_RUNTIME_SERVICES_CODE	 5
751da177e4SLinus Torvalds #define EFI_RUNTIME_SERVICES_DATA	 6
761da177e4SLinus Torvalds #define EFI_CONVENTIONAL_MEMORY		 7
771da177e4SLinus Torvalds #define EFI_UNUSABLE_MEMORY		 8
781da177e4SLinus Torvalds #define EFI_ACPI_RECLAIM_MEMORY		 9
791da177e4SLinus Torvalds #define EFI_ACPI_MEMORY_NVS		10
801da177e4SLinus Torvalds #define EFI_MEMORY_MAPPED_IO		11
811da177e4SLinus Torvalds #define EFI_MEMORY_MAPPED_IO_PORT_SPACE	12
821da177e4SLinus Torvalds #define EFI_PAL_CODE			13
83ad5fb870SDan Williams #define EFI_PERSISTENT_MEMORY		14
84ad5fb870SDan Williams #define EFI_MAX_MEMORY_TYPE		15
851da177e4SLinus Torvalds 
861da177e4SLinus Torvalds /* Attribute values: */
871da177e4SLinus Torvalds #define EFI_MEMORY_UC		((u64)0x0000000000000001ULL)	/* uncached */
881da177e4SLinus Torvalds #define EFI_MEMORY_WC		((u64)0x0000000000000002ULL)	/* write-coalescing */
891da177e4SLinus Torvalds #define EFI_MEMORY_WT		((u64)0x0000000000000004ULL)	/* write-through */
901da177e4SLinus Torvalds #define EFI_MEMORY_WB		((u64)0x0000000000000008ULL)	/* write-back */
919c97e0bdSLaszlo Ersek #define EFI_MEMORY_UCE		((u64)0x0000000000000010ULL)	/* uncached, exported */
921da177e4SLinus Torvalds #define EFI_MEMORY_WP		((u64)0x0000000000001000ULL)	/* write-protect */
931da177e4SLinus Torvalds #define EFI_MEMORY_RP		((u64)0x0000000000002000ULL)	/* read-protect */
941da177e4SLinus Torvalds #define EFI_MEMORY_XP		((u64)0x0000000000004000ULL)	/* execute-protect */
95c016ca08SRobert Elliott #define EFI_MEMORY_NV		((u64)0x0000000000008000ULL)	/* non-volatile */
96b05b9f5fSTony Luck #define EFI_MEMORY_MORE_RELIABLE \
97b05b9f5fSTony Luck 				((u64)0x0000000000010000ULL)	/* higher reliability */
9887db73aeSArd Biesheuvel #define EFI_MEMORY_RO		((u64)0x0000000000020000ULL)	/* read-only */
991da177e4SLinus Torvalds #define EFI_MEMORY_RUNTIME	((u64)0x8000000000000000ULL)	/* range requires runtime mapping */
1001da177e4SLinus Torvalds #define EFI_MEMORY_DESCRIPTOR_VERSION	1
1011da177e4SLinus Torvalds 
1021da177e4SLinus Torvalds #define EFI_PAGE_SHIFT		12
103ed37ddffSRoy Franz #define EFI_PAGE_SIZE		(1UL << EFI_PAGE_SHIFT)
1041da177e4SLinus Torvalds 
1051da177e4SLinus Torvalds typedef struct {
1061da177e4SLinus Torvalds 	u32 type;
1071da177e4SLinus Torvalds 	u32 pad;
1081da177e4SLinus Torvalds 	u64 phys_addr;
1091da177e4SLinus Torvalds 	u64 virt_addr;
1101da177e4SLinus Torvalds 	u64 num_pages;
1111da177e4SLinus Torvalds 	u64 attribute;
1121da177e4SLinus Torvalds } efi_memory_desc_t;
1131da177e4SLinus Torvalds 
1143b370237SMatthew Garrett typedef struct {
1153b370237SMatthew Garrett 	efi_guid_t guid;
1163b370237SMatthew Garrett 	u32 headersize;
1173b370237SMatthew Garrett 	u32 flags;
1183b370237SMatthew Garrett 	u32 imagesize;
1193b370237SMatthew Garrett } efi_capsule_header_t;
1203b370237SMatthew Garrett 
121bb05e4baSMatt Fleming /*
122f0133f3cSMatt Fleming  * EFI capsule flags
123f0133f3cSMatt Fleming  */
124f0133f3cSMatt Fleming #define EFI_CAPSULE_PERSIST_ACROSS_RESET	0x00010000
125f0133f3cSMatt Fleming #define EFI_CAPSULE_POPULATE_SYSTEM_TABLE	0x00020000
126f0133f3cSMatt Fleming #define EFI_CAPSULE_INITIATE_RESET		0x00040000
127f0133f3cSMatt Fleming 
128f0133f3cSMatt Fleming /*
129bb05e4baSMatt Fleming  * Allocation types for calls to boottime->allocate_pages.
130bb05e4baSMatt Fleming  */
131bb05e4baSMatt Fleming #define EFI_ALLOCATE_ANY_PAGES		0
132bb05e4baSMatt Fleming #define EFI_ALLOCATE_MAX_ADDRESS	1
133bb05e4baSMatt Fleming #define EFI_ALLOCATE_ADDRESS		2
134bb05e4baSMatt Fleming #define EFI_MAX_ALLOCATE_TYPE		3
135bb05e4baSMatt Fleming 
136e088a4adSMatthew Wilcox typedef int (*efi_freemem_callback_t) (u64 start, u64 end, void *arg);
1371da177e4SLinus Torvalds 
1381da177e4SLinus Torvalds /*
1391da177e4SLinus Torvalds  * Types and defines for Time Services
1401da177e4SLinus Torvalds  */
1411da177e4SLinus Torvalds #define EFI_TIME_ADJUST_DAYLIGHT 0x1
1421da177e4SLinus Torvalds #define EFI_TIME_IN_DAYLIGHT     0x2
1431da177e4SLinus Torvalds #define EFI_UNSPECIFIED_TIMEZONE 0x07ff
1441da177e4SLinus Torvalds 
1451da177e4SLinus Torvalds typedef struct {
1461da177e4SLinus Torvalds 	u16 year;
1471da177e4SLinus Torvalds 	u8 month;
1481da177e4SLinus Torvalds 	u8 day;
1491da177e4SLinus Torvalds 	u8 hour;
1501da177e4SLinus Torvalds 	u8 minute;
1511da177e4SLinus Torvalds 	u8 second;
1521da177e4SLinus Torvalds 	u8 pad1;
1531da177e4SLinus Torvalds 	u32 nanosecond;
1541da177e4SLinus Torvalds 	s16 timezone;
1551da177e4SLinus Torvalds 	u8 daylight;
1561da177e4SLinus Torvalds 	u8 pad2;
1571da177e4SLinus Torvalds } efi_time_t;
1581da177e4SLinus Torvalds 
1591da177e4SLinus Torvalds typedef struct {
1601da177e4SLinus Torvalds 	u32 resolution;
1611da177e4SLinus Torvalds 	u32 accuracy;
1621da177e4SLinus Torvalds 	u8 sets_to_zero;
1631da177e4SLinus Torvalds } efi_time_cap_t;
1641da177e4SLinus Torvalds 
165677703ceSMatt Fleming typedef struct {
166677703ceSMatt Fleming 	efi_table_hdr_t hdr;
167677703ceSMatt Fleming 	u32 raise_tpl;
168677703ceSMatt Fleming 	u32 restore_tpl;
169677703ceSMatt Fleming 	u32 allocate_pages;
170677703ceSMatt Fleming 	u32 free_pages;
171677703ceSMatt Fleming 	u32 get_memory_map;
172677703ceSMatt Fleming 	u32 allocate_pool;
173677703ceSMatt Fleming 	u32 free_pool;
174677703ceSMatt Fleming 	u32 create_event;
175677703ceSMatt Fleming 	u32 set_timer;
176677703ceSMatt Fleming 	u32 wait_for_event;
177677703ceSMatt Fleming 	u32 signal_event;
178677703ceSMatt Fleming 	u32 close_event;
179677703ceSMatt Fleming 	u32 check_event;
180677703ceSMatt Fleming 	u32 install_protocol_interface;
181677703ceSMatt Fleming 	u32 reinstall_protocol_interface;
182677703ceSMatt Fleming 	u32 uninstall_protocol_interface;
183677703ceSMatt Fleming 	u32 handle_protocol;
184677703ceSMatt Fleming 	u32 __reserved;
185677703ceSMatt Fleming 	u32 register_protocol_notify;
186677703ceSMatt Fleming 	u32 locate_handle;
187677703ceSMatt Fleming 	u32 locate_device_path;
188677703ceSMatt Fleming 	u32 install_configuration_table;
189677703ceSMatt Fleming 	u32 load_image;
190677703ceSMatt Fleming 	u32 start_image;
191677703ceSMatt Fleming 	u32 exit;
192677703ceSMatt Fleming 	u32 unload_image;
193677703ceSMatt Fleming 	u32 exit_boot_services;
194677703ceSMatt Fleming 	u32 get_next_monotonic_count;
195677703ceSMatt Fleming 	u32 stall;
196677703ceSMatt Fleming 	u32 set_watchdog_timer;
197677703ceSMatt Fleming 	u32 connect_controller;
198677703ceSMatt Fleming 	u32 disconnect_controller;
199677703ceSMatt Fleming 	u32 open_protocol;
200677703ceSMatt Fleming 	u32 close_protocol;
201677703ceSMatt Fleming 	u32 open_protocol_information;
202677703ceSMatt Fleming 	u32 protocols_per_handle;
203677703ceSMatt Fleming 	u32 locate_handle_buffer;
204677703ceSMatt Fleming 	u32 locate_protocol;
205677703ceSMatt Fleming 	u32 install_multiple_protocol_interfaces;
206677703ceSMatt Fleming 	u32 uninstall_multiple_protocol_interfaces;
207677703ceSMatt Fleming 	u32 calculate_crc32;
208677703ceSMatt Fleming 	u32 copy_mem;
209677703ceSMatt Fleming 	u32 set_mem;
210677703ceSMatt Fleming 	u32 create_event_ex;
211677703ceSMatt Fleming } __packed efi_boot_services_32_t;
212677703ceSMatt Fleming 
213677703ceSMatt Fleming typedef struct {
214677703ceSMatt Fleming 	efi_table_hdr_t hdr;
215677703ceSMatt Fleming 	u64 raise_tpl;
216677703ceSMatt Fleming 	u64 restore_tpl;
217677703ceSMatt Fleming 	u64 allocate_pages;
218677703ceSMatt Fleming 	u64 free_pages;
219677703ceSMatt Fleming 	u64 get_memory_map;
220677703ceSMatt Fleming 	u64 allocate_pool;
221677703ceSMatt Fleming 	u64 free_pool;
222677703ceSMatt Fleming 	u64 create_event;
223677703ceSMatt Fleming 	u64 set_timer;
224677703ceSMatt Fleming 	u64 wait_for_event;
225677703ceSMatt Fleming 	u64 signal_event;
226677703ceSMatt Fleming 	u64 close_event;
227677703ceSMatt Fleming 	u64 check_event;
228677703ceSMatt Fleming 	u64 install_protocol_interface;
229677703ceSMatt Fleming 	u64 reinstall_protocol_interface;
230677703ceSMatt Fleming 	u64 uninstall_protocol_interface;
231677703ceSMatt Fleming 	u64 handle_protocol;
232677703ceSMatt Fleming 	u64 __reserved;
233677703ceSMatt Fleming 	u64 register_protocol_notify;
234677703ceSMatt Fleming 	u64 locate_handle;
235677703ceSMatt Fleming 	u64 locate_device_path;
236677703ceSMatt Fleming 	u64 install_configuration_table;
237677703ceSMatt Fleming 	u64 load_image;
238677703ceSMatt Fleming 	u64 start_image;
239677703ceSMatt Fleming 	u64 exit;
240677703ceSMatt Fleming 	u64 unload_image;
241677703ceSMatt Fleming 	u64 exit_boot_services;
242677703ceSMatt Fleming 	u64 get_next_monotonic_count;
243677703ceSMatt Fleming 	u64 stall;
244677703ceSMatt Fleming 	u64 set_watchdog_timer;
245677703ceSMatt Fleming 	u64 connect_controller;
246677703ceSMatt Fleming 	u64 disconnect_controller;
247677703ceSMatt Fleming 	u64 open_protocol;
248677703ceSMatt Fleming 	u64 close_protocol;
249677703ceSMatt Fleming 	u64 open_protocol_information;
250677703ceSMatt Fleming 	u64 protocols_per_handle;
251677703ceSMatt Fleming 	u64 locate_handle_buffer;
252677703ceSMatt Fleming 	u64 locate_protocol;
253677703ceSMatt Fleming 	u64 install_multiple_protocol_interfaces;
254677703ceSMatt Fleming 	u64 uninstall_multiple_protocol_interfaces;
255677703ceSMatt Fleming 	u64 calculate_crc32;
256677703ceSMatt Fleming 	u64 copy_mem;
257677703ceSMatt Fleming 	u64 set_mem;
258677703ceSMatt Fleming 	u64 create_event_ex;
259677703ceSMatt Fleming } __packed efi_boot_services_64_t;
260677703ceSMatt Fleming 
2611da177e4SLinus Torvalds /*
262f30ca6baSMatt Fleming  * EFI Boot Services table
263f30ca6baSMatt Fleming  */
264f30ca6baSMatt Fleming typedef struct {
265f30ca6baSMatt Fleming 	efi_table_hdr_t hdr;
266f30ca6baSMatt Fleming 	void *raise_tpl;
267f30ca6baSMatt Fleming 	void *restore_tpl;
268ed37ddffSRoy Franz 	efi_status_t (*allocate_pages)(int, int, unsigned long,
269ed37ddffSRoy Franz 				       efi_physical_addr_t *);
270ed37ddffSRoy Franz 	efi_status_t (*free_pages)(efi_physical_addr_t, unsigned long);
271ed37ddffSRoy Franz 	efi_status_t (*get_memory_map)(unsigned long *, void *, unsigned long *,
272ed37ddffSRoy Franz 				       unsigned long *, u32 *);
273ed37ddffSRoy Franz 	efi_status_t (*allocate_pool)(int, unsigned long, void **);
274ed37ddffSRoy Franz 	efi_status_t (*free_pool)(void *);
275f30ca6baSMatt Fleming 	void *create_event;
276f30ca6baSMatt Fleming 	void *set_timer;
277f30ca6baSMatt Fleming 	void *wait_for_event;
278f30ca6baSMatt Fleming 	void *signal_event;
279f30ca6baSMatt Fleming 	void *close_event;
280f30ca6baSMatt Fleming 	void *check_event;
281f30ca6baSMatt Fleming 	void *install_protocol_interface;
282f30ca6baSMatt Fleming 	void *reinstall_protocol_interface;
283f30ca6baSMatt Fleming 	void *uninstall_protocol_interface;
284ed37ddffSRoy Franz 	efi_status_t (*handle_protocol)(efi_handle_t, efi_guid_t *, void **);
285f30ca6baSMatt Fleming 	void *__reserved;
286f30ca6baSMatt Fleming 	void *register_protocol_notify;
287fc372064SArd Biesheuvel 	efi_status_t (*locate_handle)(int, efi_guid_t *, void *,
288fc372064SArd Biesheuvel 				      unsigned long *, efi_handle_t *);
289f30ca6baSMatt Fleming 	void *locate_device_path;
290801820beSArd Biesheuvel 	efi_status_t (*install_configuration_table)(efi_guid_t *, void *);
291f30ca6baSMatt Fleming 	void *load_image;
292f30ca6baSMatt Fleming 	void *start_image;
293f30ca6baSMatt Fleming 	void *exit;
294f30ca6baSMatt Fleming 	void *unload_image;
295ed37ddffSRoy Franz 	efi_status_t (*exit_boot_services)(efi_handle_t, unsigned long);
296f30ca6baSMatt Fleming 	void *get_next_monotonic_count;
297f30ca6baSMatt Fleming 	void *stall;
298f30ca6baSMatt Fleming 	void *set_watchdog_timer;
299f30ca6baSMatt Fleming 	void *connect_controller;
300f30ca6baSMatt Fleming 	void *disconnect_controller;
301f30ca6baSMatt Fleming 	void *open_protocol;
302f30ca6baSMatt Fleming 	void *close_protocol;
303f30ca6baSMatt Fleming 	void *open_protocol_information;
304f30ca6baSMatt Fleming 	void *protocols_per_handle;
305f30ca6baSMatt Fleming 	void *locate_handle_buffer;
306e4fbf476SArd Biesheuvel 	efi_status_t (*locate_protocol)(efi_guid_t *, void *, void **);
307f30ca6baSMatt Fleming 	void *install_multiple_protocol_interfaces;
308f30ca6baSMatt Fleming 	void *uninstall_multiple_protocol_interfaces;
309f30ca6baSMatt Fleming 	void *calculate_crc32;
310f30ca6baSMatt Fleming 	void *copy_mem;
311f30ca6baSMatt Fleming 	void *set_mem;
312f30ca6baSMatt Fleming 	void *create_event_ex;
313f30ca6baSMatt Fleming } efi_boot_services_t;
314f30ca6baSMatt Fleming 
315dd5fc854SMatthew Garrett typedef enum {
316dd5fc854SMatthew Garrett 	EfiPciIoWidthUint8,
317dd5fc854SMatthew Garrett 	EfiPciIoWidthUint16,
318dd5fc854SMatthew Garrett 	EfiPciIoWidthUint32,
319dd5fc854SMatthew Garrett 	EfiPciIoWidthUint64,
320dd5fc854SMatthew Garrett 	EfiPciIoWidthFifoUint8,
321dd5fc854SMatthew Garrett 	EfiPciIoWidthFifoUint16,
322dd5fc854SMatthew Garrett 	EfiPciIoWidthFifoUint32,
323dd5fc854SMatthew Garrett 	EfiPciIoWidthFifoUint64,
324dd5fc854SMatthew Garrett 	EfiPciIoWidthFillUint8,
325dd5fc854SMatthew Garrett 	EfiPciIoWidthFillUint16,
326dd5fc854SMatthew Garrett 	EfiPciIoWidthFillUint32,
327dd5fc854SMatthew Garrett 	EfiPciIoWidthFillUint64,
328dd5fc854SMatthew Garrett 	EfiPciIoWidthMaximum
329dd5fc854SMatthew Garrett } EFI_PCI_IO_PROTOCOL_WIDTH;
330dd5fc854SMatthew Garrett 
331dd5fc854SMatthew Garrett typedef enum {
332dd5fc854SMatthew Garrett 	EfiPciIoAttributeOperationGet,
333dd5fc854SMatthew Garrett 	EfiPciIoAttributeOperationSet,
334dd5fc854SMatthew Garrett 	EfiPciIoAttributeOperationEnable,
335dd5fc854SMatthew Garrett 	EfiPciIoAttributeOperationDisable,
336dd5fc854SMatthew Garrett 	EfiPciIoAttributeOperationSupported,
337dd5fc854SMatthew Garrett     EfiPciIoAttributeOperationMaximum
338dd5fc854SMatthew Garrett } EFI_PCI_IO_PROTOCOL_ATTRIBUTE_OPERATION;
339dd5fc854SMatthew Garrett 
340677703ceSMatt Fleming typedef struct {
341677703ceSMatt Fleming 	u32 read;
342677703ceSMatt Fleming 	u32 write;
343677703ceSMatt Fleming } efi_pci_io_protocol_access_32_t;
344677703ceSMatt Fleming 
345677703ceSMatt Fleming typedef struct {
346677703ceSMatt Fleming 	u64 read;
347677703ceSMatt Fleming 	u64 write;
348677703ceSMatt Fleming } efi_pci_io_protocol_access_64_t;
349dd5fc854SMatthew Garrett 
350dd5fc854SMatthew Garrett typedef struct {
351dd5fc854SMatthew Garrett 	void *read;
352dd5fc854SMatthew Garrett 	void *write;
353dd5fc854SMatthew Garrett } efi_pci_io_protocol_access_t;
354dd5fc854SMatthew Garrett 
355dd5fc854SMatthew Garrett typedef struct {
356677703ceSMatt Fleming 	u32 poll_mem;
357677703ceSMatt Fleming 	u32 poll_io;
358677703ceSMatt Fleming 	efi_pci_io_protocol_access_32_t mem;
359677703ceSMatt Fleming 	efi_pci_io_protocol_access_32_t io;
360677703ceSMatt Fleming 	efi_pci_io_protocol_access_32_t pci;
361677703ceSMatt Fleming 	u32 copy_mem;
362677703ceSMatt Fleming 	u32 map;
363677703ceSMatt Fleming 	u32 unmap;
364677703ceSMatt Fleming 	u32 allocate_buffer;
365677703ceSMatt Fleming 	u32 free_buffer;
366677703ceSMatt Fleming 	u32 flush;
367677703ceSMatt Fleming 	u32 get_location;
368677703ceSMatt Fleming 	u32 attributes;
369677703ceSMatt Fleming 	u32 get_bar_attributes;
370677703ceSMatt Fleming 	u32 set_bar_attributes;
371677703ceSMatt Fleming 	uint64_t romsize;
372677703ceSMatt Fleming 	void *romimage;
373677703ceSMatt Fleming } efi_pci_io_protocol_32;
374677703ceSMatt Fleming 
375677703ceSMatt Fleming typedef struct {
376677703ceSMatt Fleming 	u64 poll_mem;
377677703ceSMatt Fleming 	u64 poll_io;
378677703ceSMatt Fleming 	efi_pci_io_protocol_access_64_t mem;
379677703ceSMatt Fleming 	efi_pci_io_protocol_access_64_t io;
380677703ceSMatt Fleming 	efi_pci_io_protocol_access_64_t pci;
381677703ceSMatt Fleming 	u64 copy_mem;
382677703ceSMatt Fleming 	u64 map;
383677703ceSMatt Fleming 	u64 unmap;
384677703ceSMatt Fleming 	u64 allocate_buffer;
385677703ceSMatt Fleming 	u64 free_buffer;
386677703ceSMatt Fleming 	u64 flush;
387677703ceSMatt Fleming 	u64 get_location;
388677703ceSMatt Fleming 	u64 attributes;
389677703ceSMatt Fleming 	u64 get_bar_attributes;
390677703ceSMatt Fleming 	u64 set_bar_attributes;
391677703ceSMatt Fleming 	uint64_t romsize;
392677703ceSMatt Fleming 	void *romimage;
393677703ceSMatt Fleming } efi_pci_io_protocol_64;
394677703ceSMatt Fleming 
395677703ceSMatt Fleming typedef struct {
396dd5fc854SMatthew Garrett 	void *poll_mem;
397dd5fc854SMatthew Garrett 	void *poll_io;
398dd5fc854SMatthew Garrett 	efi_pci_io_protocol_access_t mem;
399dd5fc854SMatthew Garrett 	efi_pci_io_protocol_access_t io;
400dd5fc854SMatthew Garrett 	efi_pci_io_protocol_access_t pci;
401dd5fc854SMatthew Garrett 	void *copy_mem;
402dd5fc854SMatthew Garrett 	void *map;
403dd5fc854SMatthew Garrett 	void *unmap;
404dd5fc854SMatthew Garrett 	void *allocate_buffer;
405dd5fc854SMatthew Garrett 	void *free_buffer;
406dd5fc854SMatthew Garrett 	void *flush;
407dd5fc854SMatthew Garrett 	void *get_location;
408dd5fc854SMatthew Garrett 	void *attributes;
409dd5fc854SMatthew Garrett 	void *get_bar_attributes;
410dd5fc854SMatthew Garrett 	void *set_bar_attributes;
411dd5fc854SMatthew Garrett 	uint64_t romsize;
412dd5fc854SMatthew Garrett 	void *romimage;
413dd5fc854SMatthew Garrett } efi_pci_io_protocol;
414dd5fc854SMatthew Garrett 
415dd5fc854SMatthew Garrett #define EFI_PCI_IO_ATTRIBUTE_ISA_MOTHERBOARD_IO 0x0001
416dd5fc854SMatthew Garrett #define EFI_PCI_IO_ATTRIBUTE_ISA_IO 0x0002
417dd5fc854SMatthew Garrett #define EFI_PCI_IO_ATTRIBUTE_VGA_PALETTE_IO 0x0004
418dd5fc854SMatthew Garrett #define EFI_PCI_IO_ATTRIBUTE_VGA_MEMORY 0x0008
419dd5fc854SMatthew Garrett #define EFI_PCI_IO_ATTRIBUTE_VGA_IO 0x0010
420dd5fc854SMatthew Garrett #define EFI_PCI_IO_ATTRIBUTE_IDE_PRIMARY_IO 0x0020
421dd5fc854SMatthew Garrett #define EFI_PCI_IO_ATTRIBUTE_IDE_SECONDARY_IO 0x0040
422dd5fc854SMatthew Garrett #define EFI_PCI_IO_ATTRIBUTE_MEMORY_WRITE_COMBINE 0x0080
423dd5fc854SMatthew Garrett #define EFI_PCI_IO_ATTRIBUTE_IO 0x0100
424dd5fc854SMatthew Garrett #define EFI_PCI_IO_ATTRIBUTE_MEMORY 0x0200
425dd5fc854SMatthew Garrett #define EFI_PCI_IO_ATTRIBUTE_BUS_MASTER 0x0400
426dd5fc854SMatthew Garrett #define EFI_PCI_IO_ATTRIBUTE_MEMORY_CACHED 0x0800
427dd5fc854SMatthew Garrett #define EFI_PCI_IO_ATTRIBUTE_MEMORY_DISABLE 0x1000
428dd5fc854SMatthew Garrett #define EFI_PCI_IO_ATTRIBUTE_EMBEDDED_DEVICE 0x2000
429dd5fc854SMatthew Garrett #define EFI_PCI_IO_ATTRIBUTE_EMBEDDED_ROM 0x4000
430dd5fc854SMatthew Garrett #define EFI_PCI_IO_ATTRIBUTE_DUAL_ADDRESS_CYCLE 0x8000
431dd5fc854SMatthew Garrett #define EFI_PCI_IO_ATTRIBUTE_ISA_IO_16 0x10000
432dd5fc854SMatthew Garrett #define EFI_PCI_IO_ATTRIBUTE_VGA_PALETTE_IO_16 0x20000
433dd5fc854SMatthew Garrett #define EFI_PCI_IO_ATTRIBUTE_VGA_IO_16 0x40000
434dd5fc854SMatthew Garrett 
435f30ca6baSMatt Fleming /*
4361da177e4SLinus Torvalds  * Types and defines for EFI ResetSystem
4371da177e4SLinus Torvalds  */
4381da177e4SLinus Torvalds #define EFI_RESET_COLD 0
4391da177e4SLinus Torvalds #define EFI_RESET_WARM 1
4401da177e4SLinus Torvalds #define EFI_RESET_SHUTDOWN 2
4411da177e4SLinus Torvalds 
4421da177e4SLinus Torvalds /*
4431da177e4SLinus Torvalds  * EFI Runtime Services table
4441da177e4SLinus Torvalds  */
4451da177e4SLinus Torvalds #define EFI_RUNTIME_SERVICES_SIGNATURE ((u64)0x5652453544e5552ULL)
4461da177e4SLinus Torvalds #define EFI_RUNTIME_SERVICES_REVISION  0x00010000
4471da177e4SLinus Torvalds 
4481da177e4SLinus Torvalds typedef struct {
4491da177e4SLinus Torvalds 	efi_table_hdr_t hdr;
450677703ceSMatt Fleming 	u32 get_time;
451677703ceSMatt Fleming 	u32 set_time;
452677703ceSMatt Fleming 	u32 get_wakeup_time;
453677703ceSMatt Fleming 	u32 set_wakeup_time;
454677703ceSMatt Fleming 	u32 set_virtual_address_map;
455677703ceSMatt Fleming 	u32 convert_pointer;
456677703ceSMatt Fleming 	u32 get_variable;
457677703ceSMatt Fleming 	u32 get_next_variable;
458677703ceSMatt Fleming 	u32 set_variable;
459677703ceSMatt Fleming 	u32 get_next_high_mono_count;
460677703ceSMatt Fleming 	u32 reset_system;
461677703ceSMatt Fleming 	u32 update_capsule;
462677703ceSMatt Fleming 	u32 query_capsule_caps;
463677703ceSMatt Fleming 	u32 query_variable_info;
464677703ceSMatt Fleming } efi_runtime_services_32_t;
465677703ceSMatt Fleming 
466677703ceSMatt Fleming typedef struct {
467677703ceSMatt Fleming 	efi_table_hdr_t hdr;
468677703ceSMatt Fleming 	u64 get_time;
469677703ceSMatt Fleming 	u64 set_time;
470677703ceSMatt Fleming 	u64 get_wakeup_time;
471677703ceSMatt Fleming 	u64 set_wakeup_time;
472677703ceSMatt Fleming 	u64 set_virtual_address_map;
473677703ceSMatt Fleming 	u64 convert_pointer;
474677703ceSMatt Fleming 	u64 get_variable;
475677703ceSMatt Fleming 	u64 get_next_variable;
476677703ceSMatt Fleming 	u64 set_variable;
477677703ceSMatt Fleming 	u64 get_next_high_mono_count;
478677703ceSMatt Fleming 	u64 reset_system;
479677703ceSMatt Fleming 	u64 update_capsule;
480677703ceSMatt Fleming 	u64 query_capsule_caps;
481677703ceSMatt Fleming 	u64 query_variable_info;
482677703ceSMatt Fleming } efi_runtime_services_64_t;
483677703ceSMatt Fleming 
484677703ceSMatt Fleming typedef struct {
485677703ceSMatt Fleming 	efi_table_hdr_t hdr;
48643ab0476SBorislav Petkov 	void *get_time;
48743ab0476SBorislav Petkov 	void *set_time;
48843ab0476SBorislav Petkov 	void *get_wakeup_time;
48943ab0476SBorislav Petkov 	void *set_wakeup_time;
49043ab0476SBorislav Petkov 	void *set_virtual_address_map;
49143ab0476SBorislav Petkov 	void *convert_pointer;
49243ab0476SBorislav Petkov 	void *get_variable;
49343ab0476SBorislav Petkov 	void *get_next_variable;
49443ab0476SBorislav Petkov 	void *set_variable;
49543ab0476SBorislav Petkov 	void *get_next_high_mono_count;
49643ab0476SBorislav Petkov 	void *reset_system;
49743ab0476SBorislav Petkov 	void *update_capsule;
49843ab0476SBorislav Petkov 	void *query_capsule_caps;
49943ab0476SBorislav Petkov 	void *query_variable_info;
5001da177e4SLinus Torvalds } efi_runtime_services_t;
5011da177e4SLinus Torvalds 
5021da177e4SLinus Torvalds typedef efi_status_t efi_get_time_t (efi_time_t *tm, efi_time_cap_t *tc);
5031da177e4SLinus Torvalds typedef efi_status_t efi_set_time_t (efi_time_t *tm);
5041da177e4SLinus Torvalds typedef efi_status_t efi_get_wakeup_time_t (efi_bool_t *enabled, efi_bool_t *pending,
5051da177e4SLinus Torvalds 					    efi_time_t *tm);
5061da177e4SLinus Torvalds typedef efi_status_t efi_set_wakeup_time_t (efi_bool_t enabled, efi_time_t *tm);
5071da177e4SLinus Torvalds typedef efi_status_t efi_get_variable_t (efi_char16_t *name, efi_guid_t *vendor, u32 *attr,
5081da177e4SLinus Torvalds 					 unsigned long *data_size, void *data);
5091da177e4SLinus Torvalds typedef efi_status_t efi_get_next_variable_t (unsigned long *name_size, efi_char16_t *name,
5101da177e4SLinus Torvalds 					      efi_guid_t *vendor);
5111da177e4SLinus Torvalds typedef efi_status_t efi_set_variable_t (efi_char16_t *name, efi_guid_t *vendor,
512f7a2d73fSMatthew Garrett 					 u32 attr, unsigned long data_size,
5131da177e4SLinus Torvalds 					 void *data);
5141da177e4SLinus Torvalds typedef efi_status_t efi_get_next_high_mono_count_t (u32 *count);
5151da177e4SLinus Torvalds typedef void efi_reset_system_t (int reset_type, efi_status_t status,
5161da177e4SLinus Torvalds 				 unsigned long data_size, efi_char16_t *data);
5171da177e4SLinus Torvalds typedef efi_status_t efi_set_virtual_address_map_t (unsigned long memory_map_size,
5181da177e4SLinus Torvalds 						unsigned long descriptor_size,
5191da177e4SLinus Torvalds 						u32 descriptor_version,
5201da177e4SLinus Torvalds 						efi_memory_desc_t *virtual_map);
5213b370237SMatthew Garrett typedef efi_status_t efi_query_variable_info_t(u32 attr,
5223b370237SMatthew Garrett 					       u64 *storage_space,
5233b370237SMatthew Garrett 					       u64 *remaining_space,
5243b370237SMatthew Garrett 					       u64 *max_variable_size);
5253b370237SMatthew Garrett typedef efi_status_t efi_update_capsule_t(efi_capsule_header_t **capsules,
5263b370237SMatthew Garrett 					  unsigned long count,
5273b370237SMatthew Garrett 					  unsigned long sg_list);
5283b370237SMatthew Garrett typedef efi_status_t efi_query_capsule_caps_t(efi_capsule_header_t **capsules,
5293b370237SMatthew Garrett 					      unsigned long count,
5303b370237SMatthew Garrett 					      u64 *max_size,
5313b370237SMatthew Garrett 					      int *reset_type);
532ca0e30dcSArd Biesheuvel typedef efi_status_t efi_query_variable_store_t(u32 attributes,
533ca0e30dcSArd Biesheuvel 						unsigned long size,
534ca0e30dcSArd Biesheuvel 						bool nonblocking);
5351da177e4SLinus Torvalds 
536022ee6c5SArd Biesheuvel void efi_native_runtime_setup(void);
537022ee6c5SArd Biesheuvel 
5381da177e4SLinus Torvalds /*
5391da177e4SLinus Torvalds  * EFI Configuration Table and GUID definitions
54054fd11feSPeter Jones  *
5417fb2b43cSIngo Molnar  * These are all defined in a single line to make them easier to
5427fb2b43cSIngo Molnar  * grep for and to see them at a glance - while still having a
5437fb2b43cSIngo Molnar  * similar structure to the definitions in the spec.
5447fb2b43cSIngo Molnar  *
5457fb2b43cSIngo Molnar  * Here's how they are structured:
54654fd11feSPeter Jones  *
54754fd11feSPeter Jones  * GUID: 12345678-1234-1234-1234-123456789012
54854fd11feSPeter Jones  * Spec:
54954fd11feSPeter Jones  *      #define EFI_SOME_PROTOCOL_GUID \
55054fd11feSPeter Jones  *        {0x12345678,0x1234,0x1234,\
55154fd11feSPeter Jones  *          {0x12,0x34,0x12,0x34,0x56,0x78,0x90,0x12}}
55254fd11feSPeter Jones  * Here:
5537fb2b43cSIngo Molnar  *	#define SOME_PROTOCOL_GUID		EFI_GUID(0x12345678, 0x1234, 0x1234,  0x12, 0x34, 0x12, 0x34, 0x56, 0x78, 0x90, 0x12)
5547fb2b43cSIngo Molnar  *					^ tabs					    ^extra space
5557fb2b43cSIngo Molnar  *
5567fb2b43cSIngo Molnar  * Note that the 'extra space' separates the values at the same place
5577fb2b43cSIngo Molnar  * where the UEFI SPEC breaks the line.
5581da177e4SLinus Torvalds  */
5597fb2b43cSIngo Molnar #define NULL_GUID				EFI_GUID(0x00000000, 0x0000, 0x0000,  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00)
5607fb2b43cSIngo Molnar #define MPS_TABLE_GUID				EFI_GUID(0xeb9d2d2f, 0x2d88, 0x11d3,  0x9a, 0x16, 0x00, 0x90, 0x27, 0x3f, 0xc1, 0x4d)
5617fb2b43cSIngo Molnar #define ACPI_TABLE_GUID				EFI_GUID(0xeb9d2d30, 0x2d88, 0x11d3,  0x9a, 0x16, 0x00, 0x90, 0x27, 0x3f, 0xc1, 0x4d)
5627fb2b43cSIngo Molnar #define ACPI_20_TABLE_GUID			EFI_GUID(0x8868e871, 0xe4f1, 0x11d3,  0xbc, 0x22, 0x00, 0x80, 0xc7, 0x3c, 0x88, 0x81)
5637fb2b43cSIngo Molnar #define SMBIOS_TABLE_GUID			EFI_GUID(0xeb9d2d31, 0x2d88, 0x11d3,  0x9a, 0x16, 0x00, 0x90, 0x27, 0x3f, 0xc1, 0x4d)
5647fb2b43cSIngo Molnar #define SMBIOS3_TABLE_GUID			EFI_GUID(0xf2fd1544, 0x9794, 0x4a2c,  0x99, 0x2e, 0xe5, 0xbb, 0xcf, 0x20, 0xe3, 0x94)
5657fb2b43cSIngo Molnar #define SAL_SYSTEM_TABLE_GUID			EFI_GUID(0xeb9d2d32, 0x2d88, 0x11d3,  0x9a, 0x16, 0x00, 0x90, 0x27, 0x3f, 0xc1, 0x4d)
5667fb2b43cSIngo Molnar #define HCDP_TABLE_GUID				EFI_GUID(0xf951938d, 0x620b, 0x42ef,  0x82, 0x79, 0xa8, 0x4b, 0x79, 0x61, 0x78, 0x98)
5677fb2b43cSIngo Molnar #define UGA_IO_PROTOCOL_GUID			EFI_GUID(0x61a4d49e, 0x6f68, 0x4f1b,  0xb9, 0x22, 0xa8, 0x6e, 0xed, 0x0b, 0x07, 0xa2)
5687fb2b43cSIngo Molnar #define EFI_GLOBAL_VARIABLE_GUID		EFI_GUID(0x8be4df61, 0x93ca, 0x11d2,  0xaa, 0x0d, 0x00, 0xe0, 0x98, 0x03, 0x2b, 0x8c)
5697fb2b43cSIngo Molnar #define UV_SYSTEM_TABLE_GUID			EFI_GUID(0x3b13a7d4, 0x633e, 0x11dd,  0x93, 0xec, 0xda, 0x25, 0x56, 0xd8, 0x95, 0x93)
5707fb2b43cSIngo Molnar #define LINUX_EFI_CRASH_GUID			EFI_GUID(0xcfc8fc79, 0xbe2e, 0x4ddc,  0x97, 0xf0, 0x9f, 0x98, 0xbf, 0xe2, 0x98, 0xa0)
5717fb2b43cSIngo Molnar #define LOADED_IMAGE_PROTOCOL_GUID		EFI_GUID(0x5b1b31a1, 0x9562, 0x11d2,  0x8e, 0x3f, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b)
5727fb2b43cSIngo Molnar #define EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID	EFI_GUID(0x9042a9de, 0x23dc, 0x4a38,  0x96, 0xfb, 0x7a, 0xde, 0xd0, 0x80, 0x51, 0x6a)
5737fb2b43cSIngo Molnar #define EFI_UGA_PROTOCOL_GUID			EFI_GUID(0x982c298b, 0xf4fa, 0x41cb,  0xb8, 0x38, 0x77, 0xaa, 0x68, 0x8f, 0xb8, 0x39)
5747fb2b43cSIngo Molnar #define EFI_PCI_IO_PROTOCOL_GUID		EFI_GUID(0x4cf5b200, 0x68b8, 0x4ca5,  0x9e, 0xec, 0xb2, 0x3e, 0x3f, 0x50, 0x02, 0x9a)
5757fb2b43cSIngo Molnar #define EFI_FILE_INFO_ID			EFI_GUID(0x09576e92, 0x6d3f, 0x11d2,  0x8e, 0x39, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b)
5767fb2b43cSIngo Molnar #define EFI_SYSTEM_RESOURCE_TABLE_GUID		EFI_GUID(0xb122a263, 0x3661, 0x4f68,  0x99, 0x29, 0x78, 0xf8, 0xb0, 0xd6, 0x21, 0x80)
5777fb2b43cSIngo Molnar #define EFI_FILE_SYSTEM_GUID			EFI_GUID(0x964e5b22, 0x6459, 0x11d2,  0x8e, 0x39, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b)
5787fb2b43cSIngo Molnar #define DEVICE_TREE_GUID			EFI_GUID(0xb1b621d5, 0xf19c, 0x41a5,  0x83, 0x0b, 0xd9, 0x15, 0x2c, 0x69, 0xaa, 0xe0)
5797fb2b43cSIngo Molnar #define EFI_PROPERTIES_TABLE_GUID		EFI_GUID(0x880aaca3, 0x4adc, 0x4a04,  0x90, 0x79, 0xb7, 0x47, 0x34, 0x08, 0x25, 0xe5)
5807fb2b43cSIngo Molnar #define EFI_RNG_PROTOCOL_GUID			EFI_GUID(0x3152bca5, 0xeade, 0x433d,  0x86, 0x2e, 0xc0, 0x1c, 0xdc, 0x29, 0x1f, 0x44)
5817fb2b43cSIngo Molnar #define EFI_MEMORY_ATTRIBUTES_TABLE_GUID	EFI_GUID(0xdcfa911d, 0x26eb, 0x469f,  0xa2, 0x20, 0x38, 0xb7, 0xdc, 0x46, 0x12, 0x20)
5827fb2b43cSIngo Molnar #define EFI_CONSOLE_OUT_DEVICE_GUID		EFI_GUID(0xd3b36f2c, 0xd551, 0x11d4,  0x9a, 0x46, 0x00, 0x90, 0x27, 0x3f, 0xc1, 0x4d)
583fc372064SArd Biesheuvel 
584801820beSArd Biesheuvel /*
585801820beSArd Biesheuvel  * This GUID is used to pass to the kernel proper the struct screen_info
586801820beSArd Biesheuvel  * structure that was populated by the stub based on the GOP protocol instance
587801820beSArd Biesheuvel  * associated with ConOut
588801820beSArd Biesheuvel  */
5897fb2b43cSIngo Molnar #define LINUX_EFI_ARM_SCREEN_INFO_TABLE_GUID	EFI_GUID(0xe03fc20a, 0x85dc, 0x406e,  0xb9, 0x0e, 0x4a, 0xb5, 0x02, 0x37, 0x1d, 0x95)
5907fb2b43cSIngo Molnar #define LINUX_EFI_LOADER_ENTRY_GUID		EFI_GUID(0x4a67b082, 0x0a4c, 0x41cf,  0xb6, 0xc7, 0x44, 0x0b, 0x29, 0xbb, 0x8c, 0x4f)
59106f7d4a1SCompostella, Jeremy 
5921da177e4SLinus Torvalds typedef struct {
5931da177e4SLinus Torvalds 	efi_guid_t guid;
5941adbfa35SOlof Johansson 	u64 table;
5951adbfa35SOlof Johansson } efi_config_table_64_t;
5961adbfa35SOlof Johansson 
5971adbfa35SOlof Johansson typedef struct {
5981adbfa35SOlof Johansson 	efi_guid_t guid;
5991adbfa35SOlof Johansson 	u32 table;
6001adbfa35SOlof Johansson } efi_config_table_32_t;
6011adbfa35SOlof Johansson 
6021adbfa35SOlof Johansson typedef struct {
6031adbfa35SOlof Johansson 	efi_guid_t guid;
6041da177e4SLinus Torvalds 	unsigned long table;
6051da177e4SLinus Torvalds } efi_config_table_t;
6061da177e4SLinus Torvalds 
607272686bfSLeif Lindholm typedef struct {
608272686bfSLeif Lindholm 	efi_guid_t guid;
609272686bfSLeif Lindholm 	const char *name;
610272686bfSLeif Lindholm 	unsigned long *ptr;
611272686bfSLeif Lindholm } efi_config_table_type_t;
612272686bfSLeif Lindholm 
6131da177e4SLinus Torvalds #define EFI_SYSTEM_TABLE_SIGNATURE ((u64)0x5453595320494249ULL)
6141da177e4SLinus Torvalds 
6153b370237SMatthew Garrett #define EFI_2_30_SYSTEM_TABLE_REVISION  ((2 << 16) | (30))
6163b370237SMatthew Garrett #define EFI_2_20_SYSTEM_TABLE_REVISION  ((2 << 16) | (20))
6173b370237SMatthew Garrett #define EFI_2_10_SYSTEM_TABLE_REVISION  ((2 << 16) | (10))
6183b370237SMatthew Garrett #define EFI_2_00_SYSTEM_TABLE_REVISION  ((2 << 16) | (00))
6193b370237SMatthew Garrett #define EFI_1_10_SYSTEM_TABLE_REVISION  ((1 << 16) | (10))
6203b370237SMatthew Garrett #define EFI_1_02_SYSTEM_TABLE_REVISION  ((1 << 16) | (02))
6213b370237SMatthew Garrett 
6221da177e4SLinus Torvalds typedef struct {
6231da177e4SLinus Torvalds 	efi_table_hdr_t hdr;
6241adbfa35SOlof Johansson 	u64 fw_vendor;	/* physical addr of CHAR16 vendor string */
6251adbfa35SOlof Johansson 	u32 fw_revision;
6261adbfa35SOlof Johansson 	u32 __pad1;
6271adbfa35SOlof Johansson 	u64 con_in_handle;
6281adbfa35SOlof Johansson 	u64 con_in;
6291adbfa35SOlof Johansson 	u64 con_out_handle;
6301adbfa35SOlof Johansson 	u64 con_out;
6311adbfa35SOlof Johansson 	u64 stderr_handle;
6321adbfa35SOlof Johansson 	u64 stderr;
6331adbfa35SOlof Johansson 	u64 runtime;
6341adbfa35SOlof Johansson 	u64 boottime;
6351adbfa35SOlof Johansson 	u32 nr_tables;
6361adbfa35SOlof Johansson 	u32 __pad2;
6371adbfa35SOlof Johansson 	u64 tables;
6381adbfa35SOlof Johansson } efi_system_table_64_t;
6391adbfa35SOlof Johansson 
6401adbfa35SOlof Johansson typedef struct {
6411adbfa35SOlof Johansson 	efi_table_hdr_t hdr;
6421adbfa35SOlof Johansson 	u32 fw_vendor;	/* physical addr of CHAR16 vendor string */
6431adbfa35SOlof Johansson 	u32 fw_revision;
6441adbfa35SOlof Johansson 	u32 con_in_handle;
6451adbfa35SOlof Johansson 	u32 con_in;
6461adbfa35SOlof Johansson 	u32 con_out_handle;
6471adbfa35SOlof Johansson 	u32 con_out;
6481adbfa35SOlof Johansson 	u32 stderr_handle;
6491adbfa35SOlof Johansson 	u32 stderr;
6501adbfa35SOlof Johansson 	u32 runtime;
6511adbfa35SOlof Johansson 	u32 boottime;
6521adbfa35SOlof Johansson 	u32 nr_tables;
6531adbfa35SOlof Johansson 	u32 tables;
6541adbfa35SOlof Johansson } efi_system_table_32_t;
6551adbfa35SOlof Johansson 
6561adbfa35SOlof Johansson typedef struct {
6571adbfa35SOlof Johansson 	efi_table_hdr_t hdr;
6581da177e4SLinus Torvalds 	unsigned long fw_vendor;	/* physical addr of CHAR16 vendor string */
6591da177e4SLinus Torvalds 	u32 fw_revision;
6601da177e4SLinus Torvalds 	unsigned long con_in_handle;
6611da177e4SLinus Torvalds 	unsigned long con_in;
6621da177e4SLinus Torvalds 	unsigned long con_out_handle;
6631da177e4SLinus Torvalds 	unsigned long con_out;
6641da177e4SLinus Torvalds 	unsigned long stderr_handle;
6651da177e4SLinus Torvalds 	unsigned long stderr;
6661da177e4SLinus Torvalds 	efi_runtime_services_t *runtime;
667f30ca6baSMatt Fleming 	efi_boot_services_t *boottime;
6681da177e4SLinus Torvalds 	unsigned long nr_tables;
6691da177e4SLinus Torvalds 	unsigned long tables;
6701da177e4SLinus Torvalds } efi_system_table_t;
6711da177e4SLinus Torvalds 
6721da177e4SLinus Torvalds struct efi_memory_map {
67344511fb9SArd Biesheuvel 	phys_addr_t phys_map;
6747ae65fd3SMatt Tolentino 	void *map;
6757ae65fd3SMatt Tolentino 	void *map_end;
6761da177e4SLinus Torvalds 	int nr_map;
6771da177e4SLinus Torvalds 	unsigned long desc_version;
6787ae65fd3SMatt Tolentino 	unsigned long desc_size;
6791da177e4SLinus Torvalds };
6801da177e4SLinus Torvalds 
6810302f71cSMark Salter struct efi_fdt_params {
6820302f71cSMark Salter 	u64 system_table;
6830302f71cSMark Salter 	u64 mmap;
6840302f71cSMark Salter 	u32 mmap_size;
6850302f71cSMark Salter 	u32 desc_size;
6860302f71cSMark Salter 	u32 desc_ver;
6870302f71cSMark Salter };
6880302f71cSMark Salter 
6898e84f345SMatt Fleming typedef struct {
6908e84f345SMatt Fleming 	u32 revision;
691677703ceSMatt Fleming 	u32 parent_handle;
692677703ceSMatt Fleming 	u32 system_table;
693677703ceSMatt Fleming 	u32 device_handle;
694677703ceSMatt Fleming 	u32 file_path;
695677703ceSMatt Fleming 	u32 reserved;
696677703ceSMatt Fleming 	u32 load_options_size;
697677703ceSMatt Fleming 	u32 load_options;
698677703ceSMatt Fleming 	u32 image_base;
699677703ceSMatt Fleming 	__aligned_u64 image_size;
700677703ceSMatt Fleming 	unsigned int image_code_type;
701677703ceSMatt Fleming 	unsigned int image_data_type;
702677703ceSMatt Fleming 	unsigned long unload;
703677703ceSMatt Fleming } efi_loaded_image_32_t;
704677703ceSMatt Fleming 
705677703ceSMatt Fleming typedef struct {
706677703ceSMatt Fleming 	u32 revision;
707677703ceSMatt Fleming 	u64 parent_handle;
708677703ceSMatt Fleming 	u64 system_table;
709677703ceSMatt Fleming 	u64 device_handle;
710677703ceSMatt Fleming 	u64 file_path;
711677703ceSMatt Fleming 	u64 reserved;
712677703ceSMatt Fleming 	u32 load_options_size;
713677703ceSMatt Fleming 	u64 load_options;
714677703ceSMatt Fleming 	u64 image_base;
715677703ceSMatt Fleming 	__aligned_u64 image_size;
716677703ceSMatt Fleming 	unsigned int image_code_type;
717677703ceSMatt Fleming 	unsigned int image_data_type;
718677703ceSMatt Fleming 	unsigned long unload;
719677703ceSMatt Fleming } efi_loaded_image_64_t;
720677703ceSMatt Fleming 
721677703ceSMatt Fleming typedef struct {
722677703ceSMatt Fleming 	u32 revision;
7238e84f345SMatt Fleming 	void *parent_handle;
7248e84f345SMatt Fleming 	efi_system_table_t *system_table;
7258e84f345SMatt Fleming 	void *device_handle;
7268e84f345SMatt Fleming 	void *file_path;
7278e84f345SMatt Fleming 	void *reserved;
7288e84f345SMatt Fleming 	u32 load_options_size;
7298e84f345SMatt Fleming 	void *load_options;
7308e84f345SMatt Fleming 	void *image_base;
7318e84f345SMatt Fleming 	__aligned_u64 image_size;
7328e84f345SMatt Fleming 	unsigned int image_code_type;
7338e84f345SMatt Fleming 	unsigned int image_data_type;
7348e84f345SMatt Fleming 	unsigned long unload;
7358e84f345SMatt Fleming } efi_loaded_image_t;
7368e84f345SMatt Fleming 
73755839d51SMatt Fleming 
73855839d51SMatt Fleming typedef struct {
73955839d51SMatt Fleming 	u64 size;
74055839d51SMatt Fleming 	u64 file_size;
74155839d51SMatt Fleming 	u64 phys_size;
74255839d51SMatt Fleming 	efi_time_t create_time;
74355839d51SMatt Fleming 	efi_time_t last_access_time;
74455839d51SMatt Fleming 	efi_time_t modification_time;
74555839d51SMatt Fleming 	__aligned_u64 attribute;
74655839d51SMatt Fleming 	efi_char16_t filename[1];
74755839d51SMatt Fleming } efi_file_info_t;
74855839d51SMatt Fleming 
749677703ceSMatt Fleming typedef struct {
750677703ceSMatt Fleming 	u64 revision;
751677703ceSMatt Fleming 	u32 open;
752677703ceSMatt Fleming 	u32 close;
753677703ceSMatt Fleming 	u32 delete;
754677703ceSMatt Fleming 	u32 read;
755677703ceSMatt Fleming 	u32 write;
756677703ceSMatt Fleming 	u32 get_position;
757677703ceSMatt Fleming 	u32 set_position;
758677703ceSMatt Fleming 	u32 get_info;
759677703ceSMatt Fleming 	u32 set_info;
760677703ceSMatt Fleming 	u32 flush;
761677703ceSMatt Fleming } efi_file_handle_32_t;
762677703ceSMatt Fleming 
763677703ceSMatt Fleming typedef struct {
764677703ceSMatt Fleming 	u64 revision;
765677703ceSMatt Fleming 	u64 open;
766677703ceSMatt Fleming 	u64 close;
767677703ceSMatt Fleming 	u64 delete;
768677703ceSMatt Fleming 	u64 read;
769677703ceSMatt Fleming 	u64 write;
770677703ceSMatt Fleming 	u64 get_position;
771677703ceSMatt Fleming 	u64 set_position;
772677703ceSMatt Fleming 	u64 get_info;
773677703ceSMatt Fleming 	u64 set_info;
774677703ceSMatt Fleming 	u64 flush;
775677703ceSMatt Fleming } efi_file_handle_64_t;
776677703ceSMatt Fleming 
777ed37ddffSRoy Franz typedef struct _efi_file_handle {
77855839d51SMatt Fleming 	u64 revision;
779ed37ddffSRoy Franz 	efi_status_t (*open)(struct _efi_file_handle *,
780ed37ddffSRoy Franz 			     struct _efi_file_handle **,
781ed37ddffSRoy Franz 			     efi_char16_t *, u64, u64);
782ed37ddffSRoy Franz 	efi_status_t (*close)(struct _efi_file_handle *);
78355839d51SMatt Fleming 	void *delete;
784ed37ddffSRoy Franz 	efi_status_t (*read)(struct _efi_file_handle *, unsigned long *,
785ed37ddffSRoy Franz 			     void *);
78655839d51SMatt Fleming 	void *write;
78755839d51SMatt Fleming 	void *get_position;
78855839d51SMatt Fleming 	void *set_position;
789ed37ddffSRoy Franz 	efi_status_t (*get_info)(struct _efi_file_handle *, efi_guid_t *,
790ed37ddffSRoy Franz 			unsigned long *, void *);
79155839d51SMatt Fleming 	void *set_info;
79255839d51SMatt Fleming 	void *flush;
79355839d51SMatt Fleming } efi_file_handle_t;
79455839d51SMatt Fleming 
795ed37ddffSRoy Franz typedef struct _efi_file_io_interface {
796ed37ddffSRoy Franz 	u64 revision;
797ed37ddffSRoy Franz 	int (*open_volume)(struct _efi_file_io_interface *,
798ed37ddffSRoy Franz 			   efi_file_handle_t **);
799ed37ddffSRoy Franz } efi_file_io_interface_t;
800ed37ddffSRoy Franz 
80155839d51SMatt Fleming #define EFI_FILE_MODE_READ	0x0000000000000001
80255839d51SMatt Fleming #define EFI_FILE_MODE_WRITE	0x0000000000000002
80355839d51SMatt Fleming #define EFI_FILE_MODE_CREATE	0x8000000000000000
80455839d51SMatt Fleming 
805bf924863SArd Biesheuvel typedef struct {
806bf924863SArd Biesheuvel 	u32 version;
807bf924863SArd Biesheuvel 	u32 length;
808bf924863SArd Biesheuvel 	u64 memory_protection_attribute;
809bf924863SArd Biesheuvel } efi_properties_table_t;
810bf924863SArd Biesheuvel 
811bf924863SArd Biesheuvel #define EFI_PROPERTIES_TABLE_VERSION	0x00010000
812bf924863SArd Biesheuvel #define EFI_PROPERTIES_RUNTIME_MEMORY_PROTECTION_NON_EXECUTABLE_PE_DATA	0x1
813bf924863SArd Biesheuvel 
814b2c99e3cSBjorn Helgaas #define EFI_INVALID_TABLE_ADDR		(~0UL)
815b2c99e3cSBjorn Helgaas 
816a604af07SArd Biesheuvel typedef struct {
817a604af07SArd Biesheuvel 	u32 version;
818a604af07SArd Biesheuvel 	u32 num_entries;
819a604af07SArd Biesheuvel 	u32 desc_size;
820a604af07SArd Biesheuvel 	u32 reserved;
821a604af07SArd Biesheuvel 	efi_memory_desc_t entry[0];
822a604af07SArd Biesheuvel } efi_memory_attributes_table_t;
823a604af07SArd Biesheuvel 
8241da177e4SLinus Torvalds /*
8251da177e4SLinus Torvalds  * All runtime access to EFI goes through this structure:
8261da177e4SLinus Torvalds  */
8271da177e4SLinus Torvalds extern struct efi {
8281da177e4SLinus Torvalds 	efi_system_table_t *systab;	/* EFI system table */
8293b370237SMatthew Garrett 	unsigned int runtime_version;	/* Runtime services version */
830b2c99e3cSBjorn Helgaas 	unsigned long mps;		/* MPS table */
831b2c99e3cSBjorn Helgaas 	unsigned long acpi;		/* ACPI table  (IA64 ext 0.71) */
832b2c99e3cSBjorn Helgaas 	unsigned long acpi20;		/* ACPI table  (ACPI 2.0) */
833e1ccbbc9SArd Biesheuvel 	unsigned long smbios;		/* SMBIOS table (32 bit entry point) */
834e1ccbbc9SArd Biesheuvel 	unsigned long smbios3;		/* SMBIOS table (64 bit entry point) */
835b2c99e3cSBjorn Helgaas 	unsigned long sal_systab;	/* SAL system table */
836b2c99e3cSBjorn Helgaas 	unsigned long boot_info;	/* boot info table */
837b2c99e3cSBjorn Helgaas 	unsigned long hcdp;		/* HCDP table */
838b2c99e3cSBjorn Helgaas 	unsigned long uga;		/* UGA table */
839a50f70b1SRuss Anderson 	unsigned long uv_systab;	/* UV system table */
840a0998eb1SDave Young 	unsigned long fw_vendor;	/* fw_vendor */
841a0998eb1SDave Young 	unsigned long runtime;		/* runtime table */
842a0998eb1SDave Young 	unsigned long config_table;	/* config tables */
8430bb54905SPeter Jones 	unsigned long esrt;		/* ESRT table */
844bf924863SArd Biesheuvel 	unsigned long properties_table;	/* properties table */
845a604af07SArd Biesheuvel 	unsigned long mem_attr_table;	/* memory attributes table */
8461da177e4SLinus Torvalds 	efi_get_time_t *get_time;
8471da177e4SLinus Torvalds 	efi_set_time_t *set_time;
8481da177e4SLinus Torvalds 	efi_get_wakeup_time_t *get_wakeup_time;
8491da177e4SLinus Torvalds 	efi_set_wakeup_time_t *set_wakeup_time;
8501da177e4SLinus Torvalds 	efi_get_variable_t *get_variable;
8511da177e4SLinus Torvalds 	efi_get_next_variable_t *get_next_variable;
8521da177e4SLinus Torvalds 	efi_set_variable_t *set_variable;
85370d2a3cfSArd Biesheuvel 	efi_set_variable_t *set_variable_nonblocking;
8543b370237SMatthew Garrett 	efi_query_variable_info_t *query_variable_info;
855d3cac1f8SArd Biesheuvel 	efi_query_variable_info_t *query_variable_info_nonblocking;
8563b370237SMatthew Garrett 	efi_update_capsule_t *update_capsule;
8573b370237SMatthew Garrett 	efi_query_capsule_caps_t *query_capsule_caps;
8581da177e4SLinus Torvalds 	efi_get_next_high_mono_count_t *get_next_high_mono_count;
8591da177e4SLinus Torvalds 	efi_reset_system_t *reset_system;
8601da177e4SLinus Torvalds 	efi_set_virtual_address_map_t *set_virtual_address_map;
861884f4f66SMatt Fleming 	struct efi_memory_map memmap;
8623e909599SMatt Fleming 	unsigned long flags;
8631da177e4SLinus Torvalds } efi;
8641da177e4SLinus Torvalds 
8651da177e4SLinus Torvalds static inline int
8661da177e4SLinus Torvalds efi_guidcmp (efi_guid_t left, efi_guid_t right)
8671da177e4SLinus Torvalds {
8681da177e4SLinus Torvalds 	return memcmp(&left, &right, sizeof (efi_guid_t));
8691da177e4SLinus Torvalds }
8701da177e4SLinus Torvalds 
8711da177e4SLinus Torvalds static inline char *
87226e02272SBorislav Petkov efi_guid_to_str(efi_guid_t *guid, char *out)
8731da177e4SLinus Torvalds {
874925ede0bSJoe Perches 	sprintf(out, "%pUl", guid->b);
8751da177e4SLinus Torvalds         return out;
8761da177e4SLinus Torvalds }
8771da177e4SLinus Torvalds 
8781da177e4SLinus Torvalds extern void efi_init (void);
8791da177e4SLinus Torvalds extern void *efi_get_pal_addr (void);
8801da177e4SLinus Torvalds extern void efi_map_pal_code (void);
8811da177e4SLinus Torvalds extern void efi_memmap_walk (efi_freemem_callback_t callback, void *arg);
88270f4f935SArnd Bergmann extern void efi_gettimeofday (struct timespec64 *ts);
8831da177e4SLinus Torvalds extern void efi_enter_virtual_mode (void);	/* switch EFI to virtual mode, if possible */
88478510792SJosh Triplett #ifdef CONFIG_X86
8852223af38SJosh Triplett extern void efi_late_init(void);
88678510792SJosh Triplett extern void efi_free_boot_services(void);
887ca0e30dcSArd Biesheuvel extern efi_status_t efi_query_variable_store(u32 attributes,
888ca0e30dcSArd Biesheuvel 					     unsigned long size,
889ca0e30dcSArd Biesheuvel 					     bool nonblocking);
890b05b9f5fSTony Luck extern void efi_find_mirror(void);
89178510792SJosh Triplett #else
8922223af38SJosh Triplett static inline void efi_late_init(void) {}
89378510792SJosh Triplett static inline void efi_free_boot_services(void) {}
894a6e4d5a0SMatt Fleming 
895ca0e30dcSArd Biesheuvel static inline efi_status_t efi_query_variable_store(u32 attributes,
896ca0e30dcSArd Biesheuvel 						    unsigned long size,
897ca0e30dcSArd Biesheuvel 						    bool nonblocking)
898a6e4d5a0SMatt Fleming {
899a6e4d5a0SMatt Fleming 	return EFI_SUCCESS;
900a6e4d5a0SMatt Fleming }
90178510792SJosh Triplett #endif
9027bc90e01SJosh Triplett extern void __iomem *efi_lookup_mapped_addr(u64 phys_addr);
903272686bfSLeif Lindholm extern int efi_config_init(efi_config_table_type_t *arch_tables);
9043846c158SPeter Jones #ifdef CONFIG_EFI_ESRT
9050bb54905SPeter Jones extern void __init efi_esrt_init(void);
9063846c158SPeter Jones #else
9073846c158SPeter Jones static inline void efi_esrt_init(void) { }
9083846c158SPeter Jones #endif
9097bb68410SArd Biesheuvel extern int efi_config_parse_tables(void *config_tables, int count, int sz,
9107bb68410SArd Biesheuvel 				   efi_config_table_type_t *arch_tables);
9111da177e4SLinus Torvalds extern u64 efi_get_iobase (void);
9121da177e4SLinus Torvalds extern u32 efi_mem_type (unsigned long phys_addr);
9131da177e4SLinus Torvalds extern u64 efi_mem_attributes (unsigned long phys_addr);
91432e62c63SBjorn Helgaas extern u64 efi_mem_attribute (unsigned long phys_addr, unsigned long size);
9151da177e4SLinus Torvalds extern int __init efi_uart_console_only (void);
9160bb54905SPeter Jones extern u64 efi_mem_desc_end(efi_memory_desc_t *md);
9170bb54905SPeter Jones extern int efi_mem_desc_lookup(u64 phys_addr, efi_memory_desc_t *out_md);
9181da177e4SLinus Torvalds extern void efi_initialize_iomem_resources(struct resource *code_resource,
91900bf4098SBernhard Walle 		struct resource *data_resource, struct resource *bss_resource);
920916f676fSMatthew Garrett extern void efi_reserve_boot_services(void);
9217968c0e3SLeif Lindholm extern int efi_get_fdt_params(struct efi_fdt_params *params);
9220bb54905SPeter Jones extern struct kobject *efi_kobj;
9231da177e4SLinus Torvalds 
92444be28e9SMatt Fleming extern int efi_reboot_quirk_mode;
9250c5ed61aSMatt Fleming extern bool efi_poweroff_required(void);
9260c5ed61aSMatt Fleming 
9270f96a99dSTaku Izumi #ifdef CONFIG_EFI_FAKE_MEMMAP
9280f96a99dSTaku Izumi extern void __init efi_fake_memmap(void);
9290f96a99dSTaku Izumi #else
9300f96a99dSTaku Izumi static inline void efi_fake_memmap(void) { }
9310f96a99dSTaku Izumi #endif
9320f96a99dSTaku Izumi 
93310f0d2f5SArd Biesheuvel /*
93410f0d2f5SArd Biesheuvel  * efi_memattr_perm_setter - arch specific callback function passed into
93510f0d2f5SArd Biesheuvel  *                           efi_memattr_apply_permissions() that updates the
93610f0d2f5SArd Biesheuvel  *                           mapping permissions described by the second
93710f0d2f5SArd Biesheuvel  *                           argument in the page tables referred to by the
93810f0d2f5SArd Biesheuvel  *                           first argument.
93910f0d2f5SArd Biesheuvel  */
94010f0d2f5SArd Biesheuvel typedef int (*efi_memattr_perm_setter)(struct mm_struct *, efi_memory_desc_t *);
94110f0d2f5SArd Biesheuvel 
94210f0d2f5SArd Biesheuvel extern int efi_memattr_init(void);
94310f0d2f5SArd Biesheuvel extern int efi_memattr_apply_permissions(struct mm_struct *mm,
94410f0d2f5SArd Biesheuvel 					 efi_memattr_perm_setter fn);
94510f0d2f5SArd Biesheuvel 
946e885cd80SMark Salter /* Iterate through an efi_memory_map */
94778ce248fSMatt Fleming #define for_each_efi_memory_desc_in_map(m, md)				   \
948e885cd80SMark Salter 	for ((md) = (m)->map;						   \
949*d4c4fed0SJan Beulich 	     (md) && ((void *)(md) + (m)->desc_size) <= (m)->map_end;	   \
950e885cd80SMark Salter 	     (md) = (void *)(md) + (m)->desc_size)
951e885cd80SMark Salter 
95278ce248fSMatt Fleming /**
95378ce248fSMatt Fleming  * for_each_efi_memory_desc - iterate over descriptors in efi.memmap
95478ce248fSMatt Fleming  * @md: the efi_memory_desc_t * iterator
95578ce248fSMatt Fleming  *
95678ce248fSMatt Fleming  * Once the loop finishes @md must not be accessed.
95778ce248fSMatt Fleming  */
95878ce248fSMatt Fleming #define for_each_efi_memory_desc(md) \
959884f4f66SMatt Fleming 	for_each_efi_memory_desc_in_map(&efi.memmap, md)
96078ce248fSMatt Fleming 
96198d2a6caSLaszlo Ersek /*
96298d2a6caSLaszlo Ersek  * Format an EFI memory descriptor's type and attributes to a user-provided
96398d2a6caSLaszlo Ersek  * character buffer, as per snprintf(), and return the buffer.
96498d2a6caSLaszlo Ersek  */
96598d2a6caSLaszlo Ersek char * __init efi_md_typeattr_format(char *buf, size_t size,
96698d2a6caSLaszlo Ersek 				     const efi_memory_desc_t *md);
96798d2a6caSLaszlo Ersek 
9681da177e4SLinus Torvalds /**
9691da177e4SLinus Torvalds  * efi_range_is_wc - check the WC bit on an address range
9701da177e4SLinus Torvalds  * @start: starting kvirt address
9711da177e4SLinus Torvalds  * @len: length of range
9721da177e4SLinus Torvalds  *
9731da177e4SLinus Torvalds  * Consult the EFI memory map and make sure it's ok to set this range WC.
9741da177e4SLinus Torvalds  * Returns true or false.
9751da177e4SLinus Torvalds  */
9761da177e4SLinus Torvalds static inline int efi_range_is_wc(unsigned long start, unsigned long len)
9771da177e4SLinus Torvalds {
978986a80d5SJesper Juhl 	unsigned long i;
9791da177e4SLinus Torvalds 
9801da177e4SLinus Torvalds 	for (i = 0; i < len; i += (1UL << EFI_PAGE_SHIFT)) {
9811da177e4SLinus Torvalds 		unsigned long paddr = __pa(start + i);
9821da177e4SLinus Torvalds 		if (!(efi_mem_attributes(paddr) & EFI_MEMORY_WC))
9831da177e4SLinus Torvalds 			return 0;
9841da177e4SLinus Torvalds 	}
9851da177e4SLinus Torvalds 	/* The range checked out */
9861da177e4SLinus Torvalds 	return 1;
9871da177e4SLinus Torvalds }
9881da177e4SLinus Torvalds 
9891da177e4SLinus Torvalds #ifdef CONFIG_EFI_PCDP
9901da177e4SLinus Torvalds extern int __init efi_setup_pcdp_console(char *);
9911da177e4SLinus Torvalds #endif
9921da177e4SLinus Torvalds 
9931da177e4SLinus Torvalds /*
99483e68189SMatt Fleming  * We play games with efi_enabled so that the compiler will, if
99583e68189SMatt Fleming  * possible, remove EFI-related code altogether.
9961da177e4SLinus Torvalds  */
99783e68189SMatt Fleming #define EFI_BOOT		0	/* Were we booted from EFI? */
99883e68189SMatt Fleming #define EFI_CONFIG_TABLES	2	/* Can we use EFI config tables? */
99983e68189SMatt Fleming #define EFI_RUNTIME_SERVICES	3	/* Can we use runtime services? */
100083e68189SMatt Fleming #define EFI_MEMMAP		4	/* Can we use EFI memory map? */
100183e68189SMatt Fleming #define EFI_64BIT		5	/* Is the firmware 64-bit? */
10029f27bc54SDaniel Kiper #define EFI_PARAVIRT		6	/* Access is via a paravirt interface */
10039f27bc54SDaniel Kiper #define EFI_ARCH_1		7	/* First arch-specific bit */
1004fed6cefeSBorislav Petkov #define EFI_DBG			8	/* Print additional debug info at runtime */
1005a1041713SArd Biesheuvel #define EFI_NX_PE_DATA		9	/* Can runtime data regions be mapped non-executable? */
100683e68189SMatt Fleming 
10071da177e4SLinus Torvalds #ifdef CONFIG_EFI
10083e909599SMatt Fleming /*
10093e909599SMatt Fleming  * Test whether the above EFI_* bits are enabled.
10103e909599SMatt Fleming  */
10113e909599SMatt Fleming static inline bool efi_enabled(int feature)
101283e68189SMatt Fleming {
10133e909599SMatt Fleming 	return test_bit(feature, &efi.flags) != 0;
10143e909599SMatt Fleming }
10158562c99cSMatt Fleming extern void efi_reboot(enum reboot_mode reboot_mode, const char *__unused);
10163e909599SMatt Fleming #else
10173e909599SMatt Fleming static inline bool efi_enabled(int feature)
10183e909599SMatt Fleming {
10193e909599SMatt Fleming 	return false;
102083e68189SMatt Fleming }
10218562c99cSMatt Fleming static inline void
10228562c99cSMatt Fleming efi_reboot(enum reboot_mode reboot_mode, const char *__unused) {}
102387615a34SMatt Fleming 
102487615a34SMatt Fleming static inline bool
102587615a34SMatt Fleming efi_capsule_pending(int *reset_type)
102687615a34SMatt Fleming {
102787615a34SMatt Fleming 	return false;
102887615a34SMatt Fleming }
10291da177e4SLinus Torvalds #endif
10301da177e4SLinus Torvalds 
1031806b0351SMatt Fleming extern int efi_status_to_err(efi_status_t status);
1032806b0351SMatt Fleming 
10331da177e4SLinus Torvalds /*
10341da177e4SLinus Torvalds  * Variable Attributes
10351da177e4SLinus Torvalds  */
10361da177e4SLinus Torvalds #define EFI_VARIABLE_NON_VOLATILE       0x0000000000000001
10371da177e4SLinus Torvalds #define EFI_VARIABLE_BOOTSERVICE_ACCESS 0x0000000000000002
10381da177e4SLinus Torvalds #define EFI_VARIABLE_RUNTIME_ACCESS     0x0000000000000004
103941b3254cSMatthew Garrett #define EFI_VARIABLE_HARDWARE_ERROR_RECORD 0x0000000000000008
104041b3254cSMatthew Garrett #define EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS 0x0000000000000010
104141b3254cSMatthew Garrett #define EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS 0x0000000000000020
104241b3254cSMatthew Garrett #define EFI_VARIABLE_APPEND_WRITE	0x0000000000000040
10431da177e4SLinus Torvalds 
104441b3254cSMatthew Garrett #define EFI_VARIABLE_MASK 	(EFI_VARIABLE_NON_VOLATILE | \
104541b3254cSMatthew Garrett 				EFI_VARIABLE_BOOTSERVICE_ACCESS | \
104641b3254cSMatthew Garrett 				EFI_VARIABLE_RUNTIME_ACCESS | \
104741b3254cSMatthew Garrett 				EFI_VARIABLE_HARDWARE_ERROR_RECORD | \
104841b3254cSMatthew Garrett 				EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS | \
104941b3254cSMatthew Garrett 				EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS | \
105041b3254cSMatthew Garrett 				EFI_VARIABLE_APPEND_WRITE)
10511da177e4SLinus Torvalds /*
1052e14ab23dSMatt Fleming  * Length of a GUID string (strlen("aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee"))
1053e14ab23dSMatt Fleming  * not including trailing NUL
1054e14ab23dSMatt Fleming  */
1055ba7e34b1SAndy Shevchenko #define EFI_VARIABLE_GUID_LEN	UUID_STRING_LEN
1056e14ab23dSMatt Fleming 
1057e14ab23dSMatt Fleming /*
1058e2527a7cSMatt Fleming  * The type of search to perform when calling boottime->locate_handle
1059e2527a7cSMatt Fleming  */
1060e2527a7cSMatt Fleming #define EFI_LOCATE_ALL_HANDLES			0
1061e2527a7cSMatt Fleming #define EFI_LOCATE_BY_REGISTER_NOTIFY		1
1062e2527a7cSMatt Fleming #define EFI_LOCATE_BY_PROTOCOL			2
1063e2527a7cSMatt Fleming 
1064e2527a7cSMatt Fleming /*
10651da177e4SLinus Torvalds  * EFI Device Path information
10661da177e4SLinus Torvalds  */
10671da177e4SLinus Torvalds #define EFI_DEV_HW			0x01
10681da177e4SLinus Torvalds #define  EFI_DEV_PCI				 1
10691da177e4SLinus Torvalds #define  EFI_DEV_PCCARD				 2
10701da177e4SLinus Torvalds #define  EFI_DEV_MEM_MAPPED			 3
10711da177e4SLinus Torvalds #define  EFI_DEV_VENDOR				 4
10721da177e4SLinus Torvalds #define  EFI_DEV_CONTROLLER			 5
10731da177e4SLinus Torvalds #define EFI_DEV_ACPI			0x02
10741da177e4SLinus Torvalds #define   EFI_DEV_BASIC_ACPI			 1
10751da177e4SLinus Torvalds #define   EFI_DEV_EXPANDED_ACPI			 2
10761da177e4SLinus Torvalds #define EFI_DEV_MSG			0x03
10771da177e4SLinus Torvalds #define   EFI_DEV_MSG_ATAPI			 1
10781da177e4SLinus Torvalds #define   EFI_DEV_MSG_SCSI			 2
10791da177e4SLinus Torvalds #define   EFI_DEV_MSG_FC			 3
10801da177e4SLinus Torvalds #define   EFI_DEV_MSG_1394			 4
10811da177e4SLinus Torvalds #define   EFI_DEV_MSG_USB			 5
10821da177e4SLinus Torvalds #define   EFI_DEV_MSG_USB_CLASS			15
10831da177e4SLinus Torvalds #define   EFI_DEV_MSG_I20			 6
10841da177e4SLinus Torvalds #define   EFI_DEV_MSG_MAC			11
10851da177e4SLinus Torvalds #define   EFI_DEV_MSG_IPV4			12
10861da177e4SLinus Torvalds #define   EFI_DEV_MSG_IPV6			13
10871da177e4SLinus Torvalds #define   EFI_DEV_MSG_INFINIBAND		 9
10881da177e4SLinus Torvalds #define   EFI_DEV_MSG_UART			14
10891da177e4SLinus Torvalds #define   EFI_DEV_MSG_VENDOR			10
10901da177e4SLinus Torvalds #define EFI_DEV_MEDIA			0x04
10911da177e4SLinus Torvalds #define   EFI_DEV_MEDIA_HARD_DRIVE		 1
10921da177e4SLinus Torvalds #define   EFI_DEV_MEDIA_CDROM			 2
10931da177e4SLinus Torvalds #define   EFI_DEV_MEDIA_VENDOR			 3
10941da177e4SLinus Torvalds #define   EFI_DEV_MEDIA_FILE			 4
10951da177e4SLinus Torvalds #define   EFI_DEV_MEDIA_PROTOCOL		 5
10961da177e4SLinus Torvalds #define EFI_DEV_BIOS_BOOT		0x05
10971da177e4SLinus Torvalds #define EFI_DEV_END_PATH		0x7F
10981da177e4SLinus Torvalds #define EFI_DEV_END_PATH2		0xFF
10991da177e4SLinus Torvalds #define   EFI_DEV_END_INSTANCE			0x01
11001da177e4SLinus Torvalds #define   EFI_DEV_END_ENTIRE			0xFF
11011da177e4SLinus Torvalds 
11021da177e4SLinus Torvalds struct efi_generic_dev_path {
11031da177e4SLinus Torvalds 	u8 type;
11041da177e4SLinus Torvalds 	u8 sub_type;
11051da177e4SLinus Torvalds 	u16 length;
11061da177e4SLinus Torvalds } __attribute ((packed));
11071da177e4SLinus Torvalds 
11084a3575fdSHuang, Ying static inline void memrange_efi_to_native(u64 *addr, u64 *npages)
11094a3575fdSHuang, Ying {
11104a3575fdSHuang, Ying 	*npages = PFN_UP(*addr + (*npages<<EFI_PAGE_SHIFT)) - PFN_DOWN(*addr);
11114a3575fdSHuang, Ying 	*addr &= PAGE_MASK;
11124a3575fdSHuang, Ying }
11134a3575fdSHuang, Ying 
111404851772SMatt Fleming /*
11154fc756bdSMike Waychison  * EFI Variable support.
11164fc756bdSMike Waychison  *
11174fc756bdSMike Waychison  * Different firmware drivers can expose their EFI-like variables using
11184fc756bdSMike Waychison  * the following.
11194fc756bdSMike Waychison  */
11204fc756bdSMike Waychison 
11214fc756bdSMike Waychison struct efivar_operations {
11224fc756bdSMike Waychison 	efi_get_variable_t *get_variable;
11234fc756bdSMike Waychison 	efi_get_next_variable_t *get_next_variable;
11244fc756bdSMike Waychison 	efi_set_variable_t *set_variable;
112570d2a3cfSArd Biesheuvel 	efi_set_variable_t *set_variable_nonblocking;
1126a6e4d5a0SMatt Fleming 	efi_query_variable_store_t *query_variable_store;
11274fc756bdSMike Waychison };
11284fc756bdSMike Waychison 
11294fc756bdSMike Waychison struct efivars {
11304fc756bdSMike Waychison 	/*
11314fc756bdSMike Waychison 	 * ->lock protects two things:
113282f990a8SMatt Fleming 	 * 1) efivarfs_list and efivars_sysfs_list
113382f990a8SMatt Fleming 	 * 2) ->ops calls
11344fc756bdSMike Waychison 	 */
11354fc756bdSMike Waychison 	spinlock_t lock;
11364fc756bdSMike Waychison 	struct kset *kset;
1137605e70c7SLee, Chun-Yi 	struct kobject *kobject;
11384fc756bdSMike Waychison 	const struct efivar_operations *ops;
11394fc756bdSMike Waychison };
11404fc756bdSMike Waychison 
1141e14ab23dSMatt Fleming /*
1142e14ab23dSMatt Fleming  * The maximum size of VariableName + Data = 1024
1143e14ab23dSMatt Fleming  * Therefore, it's reasonable to save that much
1144e14ab23dSMatt Fleming  * space in each part of the structure,
1145e14ab23dSMatt Fleming  * and we use a page for reading/writing.
1146e14ab23dSMatt Fleming  */
1147e14ab23dSMatt Fleming 
1148a5d92ad3SMatt Fleming #define EFI_VAR_NAME_LEN	1024
1149a5d92ad3SMatt Fleming 
1150e14ab23dSMatt Fleming struct efi_variable {
1151a5d92ad3SMatt Fleming 	efi_char16_t  VariableName[EFI_VAR_NAME_LEN/sizeof(efi_char16_t)];
1152e14ab23dSMatt Fleming 	efi_guid_t    VendorGuid;
1153e14ab23dSMatt Fleming 	unsigned long DataSize;
1154e14ab23dSMatt Fleming 	__u8          Data[1024];
1155e14ab23dSMatt Fleming 	efi_status_t  Status;
1156e14ab23dSMatt Fleming 	__u32         Attributes;
1157e14ab23dSMatt Fleming } __attribute__((packed));
1158e14ab23dSMatt Fleming 
1159e14ab23dSMatt Fleming struct efivar_entry {
1160e14ab23dSMatt Fleming 	struct efi_variable var;
1161e14ab23dSMatt Fleming 	struct list_head list;
1162e14ab23dSMatt Fleming 	struct kobject kobj;
1163e0d59733SSeiji Aguchi 	bool scanning;
1164e0d59733SSeiji Aguchi 	bool deleting;
1165e14ab23dSMatt Fleming };
1166e14ab23dSMatt Fleming 
1167677703ceSMatt Fleming struct efi_simple_text_output_protocol_32 {
1168677703ceSMatt Fleming 	u32 reset;
1169677703ceSMatt Fleming 	u32 output_string;
1170677703ceSMatt Fleming 	u32 test_string;
1171677703ceSMatt Fleming };
1172677703ceSMatt Fleming 
1173677703ceSMatt Fleming struct efi_simple_text_output_protocol_64 {
1174677703ceSMatt Fleming 	u64 reset;
1175677703ceSMatt Fleming 	u64 output_string;
1176677703ceSMatt Fleming 	u64 test_string;
1177677703ceSMatt Fleming };
1178ed37ddffSRoy Franz 
1179ed37ddffSRoy Franz struct efi_simple_text_output_protocol {
1180ed37ddffSRoy Franz 	void *reset;
1181ed37ddffSRoy Franz 	efi_status_t (*output_string)(void *, void *);
1182ed37ddffSRoy Franz 	void *test_string;
1183ed37ddffSRoy Franz };
1184ed37ddffSRoy Franz 
1185fc372064SArd Biesheuvel #define PIXEL_RGB_RESERVED_8BIT_PER_COLOR		0
1186fc372064SArd Biesheuvel #define PIXEL_BGR_RESERVED_8BIT_PER_COLOR		1
1187fc372064SArd Biesheuvel #define PIXEL_BIT_MASK					2
1188fc372064SArd Biesheuvel #define PIXEL_BLT_ONLY					3
1189fc372064SArd Biesheuvel #define PIXEL_FORMAT_MAX				4
1190fc372064SArd Biesheuvel 
1191fc372064SArd Biesheuvel struct efi_pixel_bitmask {
1192fc372064SArd Biesheuvel 	u32 red_mask;
1193fc372064SArd Biesheuvel 	u32 green_mask;
1194fc372064SArd Biesheuvel 	u32 blue_mask;
1195fc372064SArd Biesheuvel 	u32 reserved_mask;
1196fc372064SArd Biesheuvel };
1197fc372064SArd Biesheuvel 
1198fc372064SArd Biesheuvel struct efi_graphics_output_mode_info {
1199fc372064SArd Biesheuvel 	u32 version;
1200fc372064SArd Biesheuvel 	u32 horizontal_resolution;
1201fc372064SArd Biesheuvel 	u32 vertical_resolution;
1202fc372064SArd Biesheuvel 	int pixel_format;
1203fc372064SArd Biesheuvel 	struct efi_pixel_bitmask pixel_information;
1204fc372064SArd Biesheuvel 	u32 pixels_per_scan_line;
1205fc372064SArd Biesheuvel } __packed;
1206fc372064SArd Biesheuvel 
1207fc372064SArd Biesheuvel struct efi_graphics_output_protocol_mode_32 {
1208fc372064SArd Biesheuvel 	u32 max_mode;
1209fc372064SArd Biesheuvel 	u32 mode;
1210fc372064SArd Biesheuvel 	u32 info;
1211fc372064SArd Biesheuvel 	u32 size_of_info;
1212fc372064SArd Biesheuvel 	u64 frame_buffer_base;
1213fc372064SArd Biesheuvel 	u32 frame_buffer_size;
1214fc372064SArd Biesheuvel } __packed;
1215fc372064SArd Biesheuvel 
1216fc372064SArd Biesheuvel struct efi_graphics_output_protocol_mode_64 {
1217fc372064SArd Biesheuvel 	u32 max_mode;
1218fc372064SArd Biesheuvel 	u32 mode;
1219fc372064SArd Biesheuvel 	u64 info;
1220fc372064SArd Biesheuvel 	u64 size_of_info;
1221fc372064SArd Biesheuvel 	u64 frame_buffer_base;
1222fc372064SArd Biesheuvel 	u64 frame_buffer_size;
1223fc372064SArd Biesheuvel } __packed;
1224fc372064SArd Biesheuvel 
1225fc372064SArd Biesheuvel struct efi_graphics_output_protocol_mode {
1226fc372064SArd Biesheuvel 	u32 max_mode;
1227fc372064SArd Biesheuvel 	u32 mode;
1228fc372064SArd Biesheuvel 	unsigned long info;
1229fc372064SArd Biesheuvel 	unsigned long size_of_info;
1230fc372064SArd Biesheuvel 	u64 frame_buffer_base;
1231fc372064SArd Biesheuvel 	unsigned long frame_buffer_size;
1232fc372064SArd Biesheuvel } __packed;
1233fc372064SArd Biesheuvel 
1234fc372064SArd Biesheuvel struct efi_graphics_output_protocol_32 {
1235fc372064SArd Biesheuvel 	u32 query_mode;
1236fc372064SArd Biesheuvel 	u32 set_mode;
1237fc372064SArd Biesheuvel 	u32 blt;
1238fc372064SArd Biesheuvel 	u32 mode;
1239fc372064SArd Biesheuvel };
1240fc372064SArd Biesheuvel 
1241fc372064SArd Biesheuvel struct efi_graphics_output_protocol_64 {
1242fc372064SArd Biesheuvel 	u64 query_mode;
1243fc372064SArd Biesheuvel 	u64 set_mode;
1244fc372064SArd Biesheuvel 	u64 blt;
1245fc372064SArd Biesheuvel 	u64 mode;
1246fc372064SArd Biesheuvel };
1247fc372064SArd Biesheuvel 
1248fc372064SArd Biesheuvel struct efi_graphics_output_protocol {
1249fc372064SArd Biesheuvel 	unsigned long query_mode;
1250fc372064SArd Biesheuvel 	unsigned long set_mode;
1251fc372064SArd Biesheuvel 	unsigned long blt;
1252fc372064SArd Biesheuvel 	struct efi_graphics_output_protocol_mode *mode;
1253fc372064SArd Biesheuvel };
1254fc372064SArd Biesheuvel 
1255fc372064SArd Biesheuvel typedef efi_status_t (*efi_graphics_output_protocol_query_mode)(
1256fc372064SArd Biesheuvel 	struct efi_graphics_output_protocol *, u32, unsigned long *,
1257fc372064SArd Biesheuvel 	struct efi_graphics_output_mode_info **);
1258fc372064SArd Biesheuvel 
125904851772SMatt Fleming extern struct list_head efivar_sysfs_list;
126004851772SMatt Fleming 
126104851772SMatt Fleming static inline void
126204851772SMatt Fleming efivar_unregister(struct efivar_entry *var)
126304851772SMatt Fleming {
126404851772SMatt Fleming 	kobject_put(&var->kobj);
126504851772SMatt Fleming }
126604851772SMatt Fleming 
1267e14ab23dSMatt Fleming int efivars_register(struct efivars *efivars,
12684fc756bdSMike Waychison 		     const struct efivar_operations *ops,
1269e14ab23dSMatt Fleming 		     struct kobject *kobject);
1270e14ab23dSMatt Fleming int efivars_unregister(struct efivars *efivars);
1271e14ab23dSMatt Fleming struct kobject *efivars_kobject(void);
1272e14ab23dSMatt Fleming 
1273e14ab23dSMatt Fleming int efivar_init(int (*func)(efi_char16_t *, efi_guid_t, unsigned long, void *),
12741cfd6316SJulia Lawall 		void *data, bool duplicates, struct list_head *head);
1275e14ab23dSMatt Fleming 
1276e14ab23dSMatt Fleming void efivar_entry_add(struct efivar_entry *entry, struct list_head *head);
1277e14ab23dSMatt Fleming void efivar_entry_remove(struct efivar_entry *entry);
1278e14ab23dSMatt Fleming 
1279e14ab23dSMatt Fleming int __efivar_entry_delete(struct efivar_entry *entry);
1280e14ab23dSMatt Fleming int efivar_entry_delete(struct efivar_entry *entry);
1281e14ab23dSMatt Fleming 
1282e14ab23dSMatt Fleming int efivar_entry_size(struct efivar_entry *entry, unsigned long *size);
12838a415b8cSMatt Fleming int __efivar_entry_get(struct efivar_entry *entry, u32 *attributes,
12848a415b8cSMatt Fleming 		       unsigned long *size, void *data);
1285e14ab23dSMatt Fleming int efivar_entry_get(struct efivar_entry *entry, u32 *attributes,
1286e14ab23dSMatt Fleming 		     unsigned long *size, void *data);
1287e14ab23dSMatt Fleming int efivar_entry_set(struct efivar_entry *entry, u32 attributes,
1288e14ab23dSMatt Fleming 		     unsigned long size, void *data, struct list_head *head);
1289e14ab23dSMatt Fleming int efivar_entry_set_get_size(struct efivar_entry *entry, u32 attributes,
1290e14ab23dSMatt Fleming 			      unsigned long *size, void *data, bool *set);
1291e14ab23dSMatt Fleming int efivar_entry_set_safe(efi_char16_t *name, efi_guid_t vendor, u32 attributes,
1292e14ab23dSMatt Fleming 			  bool block, unsigned long size, void *data);
1293e14ab23dSMatt Fleming 
1294e14ab23dSMatt Fleming void efivar_entry_iter_begin(void);
1295e14ab23dSMatt Fleming void efivar_entry_iter_end(void);
1296e14ab23dSMatt Fleming 
1297e14ab23dSMatt Fleming int __efivar_entry_iter(int (*func)(struct efivar_entry *, void *),
1298e14ab23dSMatt Fleming 			struct list_head *head, void *data,
1299e14ab23dSMatt Fleming 			struct efivar_entry **prev);
1300e14ab23dSMatt Fleming int efivar_entry_iter(int (*func)(struct efivar_entry *, void *),
1301e14ab23dSMatt Fleming 		      struct list_head *head, void *data);
1302e14ab23dSMatt Fleming 
1303e14ab23dSMatt Fleming struct efivar_entry *efivar_entry_find(efi_char16_t *name, efi_guid_t guid,
1304e14ab23dSMatt Fleming 				       struct list_head *head, bool remove);
1305e14ab23dSMatt Fleming 
13068282f5d9SPeter Jones bool efivar_validate(efi_guid_t vendor, efi_char16_t *var_name, u8 *data,
13078282f5d9SPeter Jones 		     unsigned long data_size);
1308ed8b0de5SPeter Jones bool efivar_variable_is_removable(efi_guid_t vendor, const char *name,
1309ed8b0de5SPeter Jones 				  size_t len);
1310e14ab23dSMatt Fleming 
1311a9499fa7STom Gundersen extern struct work_struct efivar_work;
131204851772SMatt Fleming void efivar_run_worker(void);
131304851772SMatt Fleming 
1314a9499fa7STom Gundersen #if defined(CONFIG_EFI_VARS) || defined(CONFIG_EFI_VARS_MODULE)
1315e14ab23dSMatt Fleming int efivars_sysfs_init(void);
13164fc756bdSMike Waychison 
1317e0d59733SSeiji Aguchi #define EFIVARS_DATA_SIZE_MAX 1024
1318e0d59733SSeiji Aguchi 
13194fc756bdSMike Waychison #endif /* CONFIG_EFI_VARS */
1320f0133f3cSMatt Fleming extern bool efi_capsule_pending(int *reset_type);
1321f0133f3cSMatt Fleming 
1322f0133f3cSMatt Fleming extern int efi_capsule_supported(efi_guid_t guid, u32 flags,
1323f0133f3cSMatt Fleming 				 size_t size, int *reset);
1324f0133f3cSMatt Fleming 
1325f0133f3cSMatt Fleming extern int efi_capsule_update(efi_capsule_header_t *capsule,
1326f0133f3cSMatt Fleming 			      struct page **pages);
13274fc756bdSMike Waychison 
1328926172d4SDave Young #ifdef CONFIG_EFI_RUNTIME_MAP
1329926172d4SDave Young int efi_runtime_map_init(struct kobject *);
1330926172d4SDave Young void efi_runtime_map_setup(void *, int, u32);
13316a2c20e7SVivek Goyal int efi_get_runtime_map_size(void);
13326a2c20e7SVivek Goyal int efi_get_runtime_map_desc_size(void);
13336a2c20e7SVivek Goyal int efi_runtime_map_copy(void *buf, size_t bufsz);
1334926172d4SDave Young #else
1335926172d4SDave Young static inline int efi_runtime_map_init(struct kobject *kobj)
1336926172d4SDave Young {
1337926172d4SDave Young 	return 0;
1338926172d4SDave Young }
1339926172d4SDave Young 
1340926172d4SDave Young static inline void
1341926172d4SDave Young efi_runtime_map_setup(void *map, int nr_entries, u32 desc_size) {}
13426a2c20e7SVivek Goyal 
13436a2c20e7SVivek Goyal static inline int efi_get_runtime_map_size(void)
13446a2c20e7SVivek Goyal {
13456a2c20e7SVivek Goyal 	return 0;
13466a2c20e7SVivek Goyal }
13476a2c20e7SVivek Goyal 
13486a2c20e7SVivek Goyal static inline int efi_get_runtime_map_desc_size(void)
13496a2c20e7SVivek Goyal {
13506a2c20e7SVivek Goyal 	return 0;
13516a2c20e7SVivek Goyal }
13526a2c20e7SVivek Goyal 
13536a2c20e7SVivek Goyal static inline int efi_runtime_map_copy(void *buf, size_t bufsz)
13546a2c20e7SVivek Goyal {
13556a2c20e7SVivek Goyal 	return 0;
13566a2c20e7SVivek Goyal }
13576a2c20e7SVivek Goyal 
1358926172d4SDave Young #endif
1359926172d4SDave Young 
1360bd669475SArd Biesheuvel /* prototypes shared between arch specific and generic stub code */
1361bd669475SArd Biesheuvel 
1362bd669475SArd Biesheuvel #define pr_efi(sys_table, msg)     efi_printk(sys_table, "EFI stub: "msg)
1363bd669475SArd Biesheuvel #define pr_efi_err(sys_table, msg) efi_printk(sys_table, "EFI stub: ERROR: "msg)
1364bd669475SArd Biesheuvel 
1365bd669475SArd Biesheuvel void efi_printk(efi_system_table_t *sys_table_arg, char *str);
1366bd669475SArd Biesheuvel 
1367bd669475SArd Biesheuvel void efi_free(efi_system_table_t *sys_table_arg, unsigned long size,
1368bd669475SArd Biesheuvel 	      unsigned long addr);
1369bd669475SArd Biesheuvel 
1370bd669475SArd Biesheuvel char *efi_convert_cmdline(efi_system_table_t *sys_table_arg,
1371bd669475SArd Biesheuvel 			  efi_loaded_image_t *image, int *cmd_line_len);
1372bd669475SArd Biesheuvel 
1373bd669475SArd Biesheuvel efi_status_t efi_get_memory_map(efi_system_table_t *sys_table_arg,
1374bd669475SArd Biesheuvel 				efi_memory_desc_t **map,
1375bd669475SArd Biesheuvel 				unsigned long *map_size,
1376bd669475SArd Biesheuvel 				unsigned long *desc_size,
1377bd669475SArd Biesheuvel 				u32 *desc_ver,
1378bd669475SArd Biesheuvel 				unsigned long *key_ptr);
1379bd669475SArd Biesheuvel 
1380bd669475SArd Biesheuvel efi_status_t efi_low_alloc(efi_system_table_t *sys_table_arg,
1381bd669475SArd Biesheuvel 			   unsigned long size, unsigned long align,
1382bd669475SArd Biesheuvel 			   unsigned long *addr);
1383bd669475SArd Biesheuvel 
1384bd669475SArd Biesheuvel efi_status_t efi_high_alloc(efi_system_table_t *sys_table_arg,
1385bd669475SArd Biesheuvel 			    unsigned long size, unsigned long align,
1386bd669475SArd Biesheuvel 			    unsigned long *addr, unsigned long max);
1387bd669475SArd Biesheuvel 
1388bd669475SArd Biesheuvel efi_status_t efi_relocate_kernel(efi_system_table_t *sys_table_arg,
1389bd669475SArd Biesheuvel 				 unsigned long *image_addr,
1390bd669475SArd Biesheuvel 				 unsigned long image_size,
1391bd669475SArd Biesheuvel 				 unsigned long alloc_size,
1392bd669475SArd Biesheuvel 				 unsigned long preferred_addr,
1393bd669475SArd Biesheuvel 				 unsigned long alignment);
1394bd669475SArd Biesheuvel 
1395bd669475SArd Biesheuvel efi_status_t handle_cmdline_files(efi_system_table_t *sys_table_arg,
1396bd669475SArd Biesheuvel 				  efi_loaded_image_t *image,
1397bd669475SArd Biesheuvel 				  char *cmd_line, char *option_string,
1398bd669475SArd Biesheuvel 				  unsigned long max_addr,
1399bd669475SArd Biesheuvel 				  unsigned long *load_addr,
1400bd669475SArd Biesheuvel 				  unsigned long *load_size);
1401bd669475SArd Biesheuvel 
14025a17dae4SMatt Fleming efi_status_t efi_parse_options(char *cmdline);
14035a17dae4SMatt Fleming 
14042c23b73cSArd Biesheuvel efi_status_t efi_setup_gop(efi_system_table_t *sys_table_arg,
14052c23b73cSArd Biesheuvel 			   struct screen_info *si, efi_guid_t *proto,
14062c23b73cSArd Biesheuvel 			   unsigned long size);
14072c23b73cSArd Biesheuvel 
1408b2e0a54aSDave Young bool efi_runtime_disabled(void);
140980e75596SAlex Thorlton extern void efi_call_virt_check_flags(unsigned long flags, const char *call);
141080e75596SAlex Thorlton 
141180e75596SAlex Thorlton /*
141280e75596SAlex Thorlton  * Arch code can implement the following three template macros, avoiding
141380e75596SAlex Thorlton  * reptition for the void/non-void return cases of {__,}efi_call_virt():
141480e75596SAlex Thorlton  *
141580e75596SAlex Thorlton  *  * arch_efi_call_virt_setup()
141680e75596SAlex Thorlton  *
141780e75596SAlex Thorlton  *    Sets up the environment for the call (e.g. switching page tables,
141880e75596SAlex Thorlton  *    allowing kernel-mode use of floating point, if required).
141980e75596SAlex Thorlton  *
142080e75596SAlex Thorlton  *  * arch_efi_call_virt()
142180e75596SAlex Thorlton  *
142280e75596SAlex Thorlton  *    Performs the call. The last expression in the macro must be the call
142380e75596SAlex Thorlton  *    itself, allowing the logic to be shared by the void and non-void
142480e75596SAlex Thorlton  *    cases.
142580e75596SAlex Thorlton  *
142680e75596SAlex Thorlton  *  * arch_efi_call_virt_teardown()
142780e75596SAlex Thorlton  *
142880e75596SAlex Thorlton  *    Restores the usual kernel environment once the call has returned.
142980e75596SAlex Thorlton  */
143080e75596SAlex Thorlton 
143180e75596SAlex Thorlton #define efi_call_virt_pointer(p, f, args...)				\
143280e75596SAlex Thorlton ({									\
143380e75596SAlex Thorlton 	efi_status_t __s;						\
143480e75596SAlex Thorlton 	unsigned long __flags;						\
143580e75596SAlex Thorlton 									\
143680e75596SAlex Thorlton 	arch_efi_call_virt_setup();					\
143780e75596SAlex Thorlton 									\
143880e75596SAlex Thorlton 	local_save_flags(__flags);					\
143980e75596SAlex Thorlton 	__s = arch_efi_call_virt(p, f, args);				\
144080e75596SAlex Thorlton 	efi_call_virt_check_flags(__flags, __stringify(f));		\
144180e75596SAlex Thorlton 									\
144280e75596SAlex Thorlton 	arch_efi_call_virt_teardown();					\
144380e75596SAlex Thorlton 									\
144480e75596SAlex Thorlton 	__s;								\
144580e75596SAlex Thorlton })
144680e75596SAlex Thorlton 
144780e75596SAlex Thorlton #define __efi_call_virt_pointer(p, f, args...)				\
144880e75596SAlex Thorlton ({									\
144980e75596SAlex Thorlton 	unsigned long __flags;						\
145080e75596SAlex Thorlton 									\
145180e75596SAlex Thorlton 	arch_efi_call_virt_setup();					\
145280e75596SAlex Thorlton 									\
145380e75596SAlex Thorlton 	local_save_flags(__flags);					\
145480e75596SAlex Thorlton 	arch_efi_call_virt(p, f, args);					\
145580e75596SAlex Thorlton 	efi_call_virt_check_flags(__flags, __stringify(f));		\
145680e75596SAlex Thorlton 									\
145780e75596SAlex Thorlton 	arch_efi_call_virt_teardown();					\
145880e75596SAlex Thorlton })
145980e75596SAlex Thorlton 
14601da177e4SLinus Torvalds #endif /* _LINUX_EFI_H */
1461