xref: /openbmc/linux/include/linux/efi.h (revision 806b0351c9ff9890c1ef0ba2c46237baef49ac79)
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>
242c23b73cSArd Biesheuvel #include <linux/screen_info.h>
251da177e4SLinus Torvalds 
261da177e4SLinus Torvalds #include <asm/page.h>
271da177e4SLinus Torvalds 
281da177e4SLinus Torvalds #define EFI_SUCCESS		0
291da177e4SLinus Torvalds #define EFI_LOAD_ERROR          ( 1 | (1UL << (BITS_PER_LONG-1)))
301da177e4SLinus Torvalds #define EFI_INVALID_PARAMETER	( 2 | (1UL << (BITS_PER_LONG-1)))
311da177e4SLinus Torvalds #define EFI_UNSUPPORTED		( 3 | (1UL << (BITS_PER_LONG-1)))
321da177e4SLinus Torvalds #define EFI_BAD_BUFFER_SIZE     ( 4 | (1UL << (BITS_PER_LONG-1)))
331da177e4SLinus Torvalds #define EFI_BUFFER_TOO_SMALL	( 5 | (1UL << (BITS_PER_LONG-1)))
345d9db883SMatthew Garrett #define EFI_NOT_READY		( 6 | (1UL << (BITS_PER_LONG-1)))
355d9db883SMatthew Garrett #define EFI_DEVICE_ERROR	( 7 | (1UL << (BITS_PER_LONG-1)))
365d9db883SMatthew Garrett #define EFI_WRITE_PROTECTED	( 8 | (1UL << (BITS_PER_LONG-1)))
375d9db883SMatthew Garrett #define EFI_OUT_OF_RESOURCES	( 9 | (1UL << (BITS_PER_LONG-1)))
381da177e4SLinus Torvalds #define EFI_NOT_FOUND		(14 | (1UL << (BITS_PER_LONG-1)))
395d9db883SMatthew Garrett #define EFI_SECURITY_VIOLATION	(26 | (1UL << (BITS_PER_LONG-1)))
401da177e4SLinus Torvalds 
411da177e4SLinus Torvalds typedef unsigned long efi_status_t;
421da177e4SLinus Torvalds typedef u8 efi_bool_t;
431da177e4SLinus Torvalds typedef u16 efi_char16_t;		/* UNICODE character */
44ed37ddffSRoy Franz typedef u64 efi_physical_addr_t;
45ed37ddffSRoy Franz typedef void *efi_handle_t;
461da177e4SLinus Torvalds 
471da177e4SLinus Torvalds 
481da177e4SLinus Torvalds typedef struct {
491da177e4SLinus Torvalds 	u8 b[16];
501da177e4SLinus Torvalds } efi_guid_t;
511da177e4SLinus Torvalds 
521da177e4SLinus Torvalds #define EFI_GUID(a,b,c,d0,d1,d2,d3,d4,d5,d6,d7) \
531da177e4SLinus Torvalds ((efi_guid_t) \
541da177e4SLinus Torvalds {{ (a) & 0xff, ((a) >> 8) & 0xff, ((a) >> 16) & 0xff, ((a) >> 24) & 0xff, \
551da177e4SLinus Torvalds   (b) & 0xff, ((b) >> 8) & 0xff, \
561da177e4SLinus Torvalds   (c) & 0xff, ((c) >> 8) & 0xff, \
571da177e4SLinus Torvalds   (d0), (d1), (d2), (d3), (d4), (d5), (d6), (d7) }})
581da177e4SLinus Torvalds 
591da177e4SLinus Torvalds /*
601da177e4SLinus Torvalds  * Generic EFI table header
611da177e4SLinus Torvalds  */
621da177e4SLinus Torvalds typedef	struct {
631da177e4SLinus Torvalds 	u64 signature;
641da177e4SLinus Torvalds 	u32 revision;
651da177e4SLinus Torvalds 	u32 headersize;
661da177e4SLinus Torvalds 	u32 crc32;
671da177e4SLinus Torvalds 	u32 reserved;
681da177e4SLinus Torvalds } efi_table_hdr_t;
691da177e4SLinus Torvalds 
701da177e4SLinus Torvalds /*
711da177e4SLinus Torvalds  * Memory map descriptor:
721da177e4SLinus Torvalds  */
731da177e4SLinus Torvalds 
741da177e4SLinus Torvalds /* Memory types: */
751da177e4SLinus Torvalds #define EFI_RESERVED_TYPE		 0
761da177e4SLinus Torvalds #define EFI_LOADER_CODE			 1
771da177e4SLinus Torvalds #define EFI_LOADER_DATA			 2
781da177e4SLinus Torvalds #define EFI_BOOT_SERVICES_CODE		 3
791da177e4SLinus Torvalds #define EFI_BOOT_SERVICES_DATA		 4
801da177e4SLinus Torvalds #define EFI_RUNTIME_SERVICES_CODE	 5
811da177e4SLinus Torvalds #define EFI_RUNTIME_SERVICES_DATA	 6
821da177e4SLinus Torvalds #define EFI_CONVENTIONAL_MEMORY		 7
831da177e4SLinus Torvalds #define EFI_UNUSABLE_MEMORY		 8
841da177e4SLinus Torvalds #define EFI_ACPI_RECLAIM_MEMORY		 9
851da177e4SLinus Torvalds #define EFI_ACPI_MEMORY_NVS		10
861da177e4SLinus Torvalds #define EFI_MEMORY_MAPPED_IO		11
871da177e4SLinus Torvalds #define EFI_MEMORY_MAPPED_IO_PORT_SPACE	12
881da177e4SLinus Torvalds #define EFI_PAL_CODE			13
89ad5fb870SDan Williams #define EFI_PERSISTENT_MEMORY		14
90ad5fb870SDan Williams #define EFI_MAX_MEMORY_TYPE		15
911da177e4SLinus Torvalds 
921da177e4SLinus Torvalds /* Attribute values: */
931da177e4SLinus Torvalds #define EFI_MEMORY_UC		((u64)0x0000000000000001ULL)	/* uncached */
941da177e4SLinus Torvalds #define EFI_MEMORY_WC		((u64)0x0000000000000002ULL)	/* write-coalescing */
951da177e4SLinus Torvalds #define EFI_MEMORY_WT		((u64)0x0000000000000004ULL)	/* write-through */
961da177e4SLinus Torvalds #define EFI_MEMORY_WB		((u64)0x0000000000000008ULL)	/* write-back */
979c97e0bdSLaszlo Ersek #define EFI_MEMORY_UCE		((u64)0x0000000000000010ULL)	/* uncached, exported */
981da177e4SLinus Torvalds #define EFI_MEMORY_WP		((u64)0x0000000000001000ULL)	/* write-protect */
991da177e4SLinus Torvalds #define EFI_MEMORY_RP		((u64)0x0000000000002000ULL)	/* read-protect */
1001da177e4SLinus Torvalds #define EFI_MEMORY_XP		((u64)0x0000000000004000ULL)	/* execute-protect */
101c016ca08SRobert Elliott #define EFI_MEMORY_NV		((u64)0x0000000000008000ULL)	/* non-volatile */
102b05b9f5fSTony Luck #define EFI_MEMORY_MORE_RELIABLE \
103b05b9f5fSTony Luck 				((u64)0x0000000000010000ULL)	/* higher reliability */
10487db73aeSArd Biesheuvel #define EFI_MEMORY_RO		((u64)0x0000000000020000ULL)	/* read-only */
1051da177e4SLinus Torvalds #define EFI_MEMORY_RUNTIME	((u64)0x8000000000000000ULL)	/* range requires runtime mapping */
1061da177e4SLinus Torvalds #define EFI_MEMORY_DESCRIPTOR_VERSION	1
1071da177e4SLinus Torvalds 
1081da177e4SLinus Torvalds #define EFI_PAGE_SHIFT		12
109ed37ddffSRoy Franz #define EFI_PAGE_SIZE		(1UL << EFI_PAGE_SHIFT)
1101da177e4SLinus Torvalds 
1111da177e4SLinus Torvalds typedef struct {
1121da177e4SLinus Torvalds 	u32 type;
1131da177e4SLinus Torvalds 	u32 pad;
1141da177e4SLinus Torvalds 	u64 phys_addr;
1151da177e4SLinus Torvalds 	u64 virt_addr;
1161da177e4SLinus Torvalds 	u64 num_pages;
1171da177e4SLinus Torvalds 	u64 attribute;
1181da177e4SLinus Torvalds } efi_memory_desc_t;
1191da177e4SLinus Torvalds 
1203b370237SMatthew Garrett typedef struct {
1213b370237SMatthew Garrett 	efi_guid_t guid;
1223b370237SMatthew Garrett 	u32 headersize;
1233b370237SMatthew Garrett 	u32 flags;
1243b370237SMatthew Garrett 	u32 imagesize;
1253b370237SMatthew Garrett } efi_capsule_header_t;
1263b370237SMatthew Garrett 
127bb05e4baSMatt Fleming /*
128bb05e4baSMatt Fleming  * Allocation types for calls to boottime->allocate_pages.
129bb05e4baSMatt Fleming  */
130bb05e4baSMatt Fleming #define EFI_ALLOCATE_ANY_PAGES		0
131bb05e4baSMatt Fleming #define EFI_ALLOCATE_MAX_ADDRESS	1
132bb05e4baSMatt Fleming #define EFI_ALLOCATE_ADDRESS		2
133bb05e4baSMatt Fleming #define EFI_MAX_ALLOCATE_TYPE		3
134bb05e4baSMatt Fleming 
135e088a4adSMatthew Wilcox typedef int (*efi_freemem_callback_t) (u64 start, u64 end, void *arg);
1361da177e4SLinus Torvalds 
1371da177e4SLinus Torvalds /*
1381da177e4SLinus Torvalds  * Types and defines for Time Services
1391da177e4SLinus Torvalds  */
1401da177e4SLinus Torvalds #define EFI_TIME_ADJUST_DAYLIGHT 0x1
1411da177e4SLinus Torvalds #define EFI_TIME_IN_DAYLIGHT     0x2
1421da177e4SLinus Torvalds #define EFI_UNSPECIFIED_TIMEZONE 0x07ff
1431da177e4SLinus Torvalds 
1441da177e4SLinus Torvalds typedef struct {
1451da177e4SLinus Torvalds 	u16 year;
1461da177e4SLinus Torvalds 	u8 month;
1471da177e4SLinus Torvalds 	u8 day;
1481da177e4SLinus Torvalds 	u8 hour;
1491da177e4SLinus Torvalds 	u8 minute;
1501da177e4SLinus Torvalds 	u8 second;
1511da177e4SLinus Torvalds 	u8 pad1;
1521da177e4SLinus Torvalds 	u32 nanosecond;
1531da177e4SLinus Torvalds 	s16 timezone;
1541da177e4SLinus Torvalds 	u8 daylight;
1551da177e4SLinus Torvalds 	u8 pad2;
1561da177e4SLinus Torvalds } efi_time_t;
1571da177e4SLinus Torvalds 
1581da177e4SLinus Torvalds typedef struct {
1591da177e4SLinus Torvalds 	u32 resolution;
1601da177e4SLinus Torvalds 	u32 accuracy;
1611da177e4SLinus Torvalds 	u8 sets_to_zero;
1621da177e4SLinus Torvalds } efi_time_cap_t;
1631da177e4SLinus Torvalds 
164677703ceSMatt Fleming typedef struct {
165677703ceSMatt Fleming 	efi_table_hdr_t hdr;
166677703ceSMatt Fleming 	u32 raise_tpl;
167677703ceSMatt Fleming 	u32 restore_tpl;
168677703ceSMatt Fleming 	u32 allocate_pages;
169677703ceSMatt Fleming 	u32 free_pages;
170677703ceSMatt Fleming 	u32 get_memory_map;
171677703ceSMatt Fleming 	u32 allocate_pool;
172677703ceSMatt Fleming 	u32 free_pool;
173677703ceSMatt Fleming 	u32 create_event;
174677703ceSMatt Fleming 	u32 set_timer;
175677703ceSMatt Fleming 	u32 wait_for_event;
176677703ceSMatt Fleming 	u32 signal_event;
177677703ceSMatt Fleming 	u32 close_event;
178677703ceSMatt Fleming 	u32 check_event;
179677703ceSMatt Fleming 	u32 install_protocol_interface;
180677703ceSMatt Fleming 	u32 reinstall_protocol_interface;
181677703ceSMatt Fleming 	u32 uninstall_protocol_interface;
182677703ceSMatt Fleming 	u32 handle_protocol;
183677703ceSMatt Fleming 	u32 __reserved;
184677703ceSMatt Fleming 	u32 register_protocol_notify;
185677703ceSMatt Fleming 	u32 locate_handle;
186677703ceSMatt Fleming 	u32 locate_device_path;
187677703ceSMatt Fleming 	u32 install_configuration_table;
188677703ceSMatt Fleming 	u32 load_image;
189677703ceSMatt Fleming 	u32 start_image;
190677703ceSMatt Fleming 	u32 exit;
191677703ceSMatt Fleming 	u32 unload_image;
192677703ceSMatt Fleming 	u32 exit_boot_services;
193677703ceSMatt Fleming 	u32 get_next_monotonic_count;
194677703ceSMatt Fleming 	u32 stall;
195677703ceSMatt Fleming 	u32 set_watchdog_timer;
196677703ceSMatt Fleming 	u32 connect_controller;
197677703ceSMatt Fleming 	u32 disconnect_controller;
198677703ceSMatt Fleming 	u32 open_protocol;
199677703ceSMatt Fleming 	u32 close_protocol;
200677703ceSMatt Fleming 	u32 open_protocol_information;
201677703ceSMatt Fleming 	u32 protocols_per_handle;
202677703ceSMatt Fleming 	u32 locate_handle_buffer;
203677703ceSMatt Fleming 	u32 locate_protocol;
204677703ceSMatt Fleming 	u32 install_multiple_protocol_interfaces;
205677703ceSMatt Fleming 	u32 uninstall_multiple_protocol_interfaces;
206677703ceSMatt Fleming 	u32 calculate_crc32;
207677703ceSMatt Fleming 	u32 copy_mem;
208677703ceSMatt Fleming 	u32 set_mem;
209677703ceSMatt Fleming 	u32 create_event_ex;
210677703ceSMatt Fleming } __packed efi_boot_services_32_t;
211677703ceSMatt Fleming 
212677703ceSMatt Fleming typedef struct {
213677703ceSMatt Fleming 	efi_table_hdr_t hdr;
214677703ceSMatt Fleming 	u64 raise_tpl;
215677703ceSMatt Fleming 	u64 restore_tpl;
216677703ceSMatt Fleming 	u64 allocate_pages;
217677703ceSMatt Fleming 	u64 free_pages;
218677703ceSMatt Fleming 	u64 get_memory_map;
219677703ceSMatt Fleming 	u64 allocate_pool;
220677703ceSMatt Fleming 	u64 free_pool;
221677703ceSMatt Fleming 	u64 create_event;
222677703ceSMatt Fleming 	u64 set_timer;
223677703ceSMatt Fleming 	u64 wait_for_event;
224677703ceSMatt Fleming 	u64 signal_event;
225677703ceSMatt Fleming 	u64 close_event;
226677703ceSMatt Fleming 	u64 check_event;
227677703ceSMatt Fleming 	u64 install_protocol_interface;
228677703ceSMatt Fleming 	u64 reinstall_protocol_interface;
229677703ceSMatt Fleming 	u64 uninstall_protocol_interface;
230677703ceSMatt Fleming 	u64 handle_protocol;
231677703ceSMatt Fleming 	u64 __reserved;
232677703ceSMatt Fleming 	u64 register_protocol_notify;
233677703ceSMatt Fleming 	u64 locate_handle;
234677703ceSMatt Fleming 	u64 locate_device_path;
235677703ceSMatt Fleming 	u64 install_configuration_table;
236677703ceSMatt Fleming 	u64 load_image;
237677703ceSMatt Fleming 	u64 start_image;
238677703ceSMatt Fleming 	u64 exit;
239677703ceSMatt Fleming 	u64 unload_image;
240677703ceSMatt Fleming 	u64 exit_boot_services;
241677703ceSMatt Fleming 	u64 get_next_monotonic_count;
242677703ceSMatt Fleming 	u64 stall;
243677703ceSMatt Fleming 	u64 set_watchdog_timer;
244677703ceSMatt Fleming 	u64 connect_controller;
245677703ceSMatt Fleming 	u64 disconnect_controller;
246677703ceSMatt Fleming 	u64 open_protocol;
247677703ceSMatt Fleming 	u64 close_protocol;
248677703ceSMatt Fleming 	u64 open_protocol_information;
249677703ceSMatt Fleming 	u64 protocols_per_handle;
250677703ceSMatt Fleming 	u64 locate_handle_buffer;
251677703ceSMatt Fleming 	u64 locate_protocol;
252677703ceSMatt Fleming 	u64 install_multiple_protocol_interfaces;
253677703ceSMatt Fleming 	u64 uninstall_multiple_protocol_interfaces;
254677703ceSMatt Fleming 	u64 calculate_crc32;
255677703ceSMatt Fleming 	u64 copy_mem;
256677703ceSMatt Fleming 	u64 set_mem;
257677703ceSMatt Fleming 	u64 create_event_ex;
258677703ceSMatt Fleming } __packed efi_boot_services_64_t;
259677703ceSMatt Fleming 
2601da177e4SLinus Torvalds /*
261f30ca6baSMatt Fleming  * EFI Boot Services table
262f30ca6baSMatt Fleming  */
263f30ca6baSMatt Fleming typedef struct {
264f30ca6baSMatt Fleming 	efi_table_hdr_t hdr;
265f30ca6baSMatt Fleming 	void *raise_tpl;
266f30ca6baSMatt Fleming 	void *restore_tpl;
267ed37ddffSRoy Franz 	efi_status_t (*allocate_pages)(int, int, unsigned long,
268ed37ddffSRoy Franz 				       efi_physical_addr_t *);
269ed37ddffSRoy Franz 	efi_status_t (*free_pages)(efi_physical_addr_t, unsigned long);
270ed37ddffSRoy Franz 	efi_status_t (*get_memory_map)(unsigned long *, void *, unsigned long *,
271ed37ddffSRoy Franz 				       unsigned long *, u32 *);
272ed37ddffSRoy Franz 	efi_status_t (*allocate_pool)(int, unsigned long, void **);
273ed37ddffSRoy Franz 	efi_status_t (*free_pool)(void *);
274f30ca6baSMatt Fleming 	void *create_event;
275f30ca6baSMatt Fleming 	void *set_timer;
276f30ca6baSMatt Fleming 	void *wait_for_event;
277f30ca6baSMatt Fleming 	void *signal_event;
278f30ca6baSMatt Fleming 	void *close_event;
279f30ca6baSMatt Fleming 	void *check_event;
280f30ca6baSMatt Fleming 	void *install_protocol_interface;
281f30ca6baSMatt Fleming 	void *reinstall_protocol_interface;
282f30ca6baSMatt Fleming 	void *uninstall_protocol_interface;
283ed37ddffSRoy Franz 	efi_status_t (*handle_protocol)(efi_handle_t, efi_guid_t *, void **);
284f30ca6baSMatt Fleming 	void *__reserved;
285f30ca6baSMatt Fleming 	void *register_protocol_notify;
286fc372064SArd Biesheuvel 	efi_status_t (*locate_handle)(int, efi_guid_t *, void *,
287fc372064SArd Biesheuvel 				      unsigned long *, efi_handle_t *);
288f30ca6baSMatt Fleming 	void *locate_device_path;
289801820beSArd Biesheuvel 	efi_status_t (*install_configuration_table)(efi_guid_t *, void *);
290f30ca6baSMatt Fleming 	void *load_image;
291f30ca6baSMatt Fleming 	void *start_image;
292f30ca6baSMatt Fleming 	void *exit;
293f30ca6baSMatt Fleming 	void *unload_image;
294ed37ddffSRoy Franz 	efi_status_t (*exit_boot_services)(efi_handle_t, unsigned long);
295f30ca6baSMatt Fleming 	void *get_next_monotonic_count;
296f30ca6baSMatt Fleming 	void *stall;
297f30ca6baSMatt Fleming 	void *set_watchdog_timer;
298f30ca6baSMatt Fleming 	void *connect_controller;
299f30ca6baSMatt Fleming 	void *disconnect_controller;
300f30ca6baSMatt Fleming 	void *open_protocol;
301f30ca6baSMatt Fleming 	void *close_protocol;
302f30ca6baSMatt Fleming 	void *open_protocol_information;
303f30ca6baSMatt Fleming 	void *protocols_per_handle;
304f30ca6baSMatt Fleming 	void *locate_handle_buffer;
305e4fbf476SArd Biesheuvel 	efi_status_t (*locate_protocol)(efi_guid_t *, void *, void **);
306f30ca6baSMatt Fleming 	void *install_multiple_protocol_interfaces;
307f30ca6baSMatt Fleming 	void *uninstall_multiple_protocol_interfaces;
308f30ca6baSMatt Fleming 	void *calculate_crc32;
309f30ca6baSMatt Fleming 	void *copy_mem;
310f30ca6baSMatt Fleming 	void *set_mem;
311f30ca6baSMatt Fleming 	void *create_event_ex;
312f30ca6baSMatt Fleming } efi_boot_services_t;
313f30ca6baSMatt Fleming 
314dd5fc854SMatthew Garrett typedef enum {
315dd5fc854SMatthew Garrett 	EfiPciIoWidthUint8,
316dd5fc854SMatthew Garrett 	EfiPciIoWidthUint16,
317dd5fc854SMatthew Garrett 	EfiPciIoWidthUint32,
318dd5fc854SMatthew Garrett 	EfiPciIoWidthUint64,
319dd5fc854SMatthew Garrett 	EfiPciIoWidthFifoUint8,
320dd5fc854SMatthew Garrett 	EfiPciIoWidthFifoUint16,
321dd5fc854SMatthew Garrett 	EfiPciIoWidthFifoUint32,
322dd5fc854SMatthew Garrett 	EfiPciIoWidthFifoUint64,
323dd5fc854SMatthew Garrett 	EfiPciIoWidthFillUint8,
324dd5fc854SMatthew Garrett 	EfiPciIoWidthFillUint16,
325dd5fc854SMatthew Garrett 	EfiPciIoWidthFillUint32,
326dd5fc854SMatthew Garrett 	EfiPciIoWidthFillUint64,
327dd5fc854SMatthew Garrett 	EfiPciIoWidthMaximum
328dd5fc854SMatthew Garrett } EFI_PCI_IO_PROTOCOL_WIDTH;
329dd5fc854SMatthew Garrett 
330dd5fc854SMatthew Garrett typedef enum {
331dd5fc854SMatthew Garrett 	EfiPciIoAttributeOperationGet,
332dd5fc854SMatthew Garrett 	EfiPciIoAttributeOperationSet,
333dd5fc854SMatthew Garrett 	EfiPciIoAttributeOperationEnable,
334dd5fc854SMatthew Garrett 	EfiPciIoAttributeOperationDisable,
335dd5fc854SMatthew Garrett 	EfiPciIoAttributeOperationSupported,
336dd5fc854SMatthew Garrett     EfiPciIoAttributeOperationMaximum
337dd5fc854SMatthew Garrett } EFI_PCI_IO_PROTOCOL_ATTRIBUTE_OPERATION;
338dd5fc854SMatthew Garrett 
339677703ceSMatt Fleming typedef struct {
340677703ceSMatt Fleming 	u32 read;
341677703ceSMatt Fleming 	u32 write;
342677703ceSMatt Fleming } efi_pci_io_protocol_access_32_t;
343677703ceSMatt Fleming 
344677703ceSMatt Fleming typedef struct {
345677703ceSMatt Fleming 	u64 read;
346677703ceSMatt Fleming 	u64 write;
347677703ceSMatt Fleming } efi_pci_io_protocol_access_64_t;
348dd5fc854SMatthew Garrett 
349dd5fc854SMatthew Garrett typedef struct {
350dd5fc854SMatthew Garrett 	void *read;
351dd5fc854SMatthew Garrett 	void *write;
352dd5fc854SMatthew Garrett } efi_pci_io_protocol_access_t;
353dd5fc854SMatthew Garrett 
354dd5fc854SMatthew Garrett typedef struct {
355677703ceSMatt Fleming 	u32 poll_mem;
356677703ceSMatt Fleming 	u32 poll_io;
357677703ceSMatt Fleming 	efi_pci_io_protocol_access_32_t mem;
358677703ceSMatt Fleming 	efi_pci_io_protocol_access_32_t io;
359677703ceSMatt Fleming 	efi_pci_io_protocol_access_32_t pci;
360677703ceSMatt Fleming 	u32 copy_mem;
361677703ceSMatt Fleming 	u32 map;
362677703ceSMatt Fleming 	u32 unmap;
363677703ceSMatt Fleming 	u32 allocate_buffer;
364677703ceSMatt Fleming 	u32 free_buffer;
365677703ceSMatt Fleming 	u32 flush;
366677703ceSMatt Fleming 	u32 get_location;
367677703ceSMatt Fleming 	u32 attributes;
368677703ceSMatt Fleming 	u32 get_bar_attributes;
369677703ceSMatt Fleming 	u32 set_bar_attributes;
370677703ceSMatt Fleming 	uint64_t romsize;
371677703ceSMatt Fleming 	void *romimage;
372677703ceSMatt Fleming } efi_pci_io_protocol_32;
373677703ceSMatt Fleming 
374677703ceSMatt Fleming typedef struct {
375677703ceSMatt Fleming 	u64 poll_mem;
376677703ceSMatt Fleming 	u64 poll_io;
377677703ceSMatt Fleming 	efi_pci_io_protocol_access_64_t mem;
378677703ceSMatt Fleming 	efi_pci_io_protocol_access_64_t io;
379677703ceSMatt Fleming 	efi_pci_io_protocol_access_64_t pci;
380677703ceSMatt Fleming 	u64 copy_mem;
381677703ceSMatt Fleming 	u64 map;
382677703ceSMatt Fleming 	u64 unmap;
383677703ceSMatt Fleming 	u64 allocate_buffer;
384677703ceSMatt Fleming 	u64 free_buffer;
385677703ceSMatt Fleming 	u64 flush;
386677703ceSMatt Fleming 	u64 get_location;
387677703ceSMatt Fleming 	u64 attributes;
388677703ceSMatt Fleming 	u64 get_bar_attributes;
389677703ceSMatt Fleming 	u64 set_bar_attributes;
390677703ceSMatt Fleming 	uint64_t romsize;
391677703ceSMatt Fleming 	void *romimage;
392677703ceSMatt Fleming } efi_pci_io_protocol_64;
393677703ceSMatt Fleming 
394677703ceSMatt Fleming typedef struct {
395dd5fc854SMatthew Garrett 	void *poll_mem;
396dd5fc854SMatthew Garrett 	void *poll_io;
397dd5fc854SMatthew Garrett 	efi_pci_io_protocol_access_t mem;
398dd5fc854SMatthew Garrett 	efi_pci_io_protocol_access_t io;
399dd5fc854SMatthew Garrett 	efi_pci_io_protocol_access_t pci;
400dd5fc854SMatthew Garrett 	void *copy_mem;
401dd5fc854SMatthew Garrett 	void *map;
402dd5fc854SMatthew Garrett 	void *unmap;
403dd5fc854SMatthew Garrett 	void *allocate_buffer;
404dd5fc854SMatthew Garrett 	void *free_buffer;
405dd5fc854SMatthew Garrett 	void *flush;
406dd5fc854SMatthew Garrett 	void *get_location;
407dd5fc854SMatthew Garrett 	void *attributes;
408dd5fc854SMatthew Garrett 	void *get_bar_attributes;
409dd5fc854SMatthew Garrett 	void *set_bar_attributes;
410dd5fc854SMatthew Garrett 	uint64_t romsize;
411dd5fc854SMatthew Garrett 	void *romimage;
412dd5fc854SMatthew Garrett } efi_pci_io_protocol;
413dd5fc854SMatthew Garrett 
414dd5fc854SMatthew Garrett #define EFI_PCI_IO_ATTRIBUTE_ISA_MOTHERBOARD_IO 0x0001
415dd5fc854SMatthew Garrett #define EFI_PCI_IO_ATTRIBUTE_ISA_IO 0x0002
416dd5fc854SMatthew Garrett #define EFI_PCI_IO_ATTRIBUTE_VGA_PALETTE_IO 0x0004
417dd5fc854SMatthew Garrett #define EFI_PCI_IO_ATTRIBUTE_VGA_MEMORY 0x0008
418dd5fc854SMatthew Garrett #define EFI_PCI_IO_ATTRIBUTE_VGA_IO 0x0010
419dd5fc854SMatthew Garrett #define EFI_PCI_IO_ATTRIBUTE_IDE_PRIMARY_IO 0x0020
420dd5fc854SMatthew Garrett #define EFI_PCI_IO_ATTRIBUTE_IDE_SECONDARY_IO 0x0040
421dd5fc854SMatthew Garrett #define EFI_PCI_IO_ATTRIBUTE_MEMORY_WRITE_COMBINE 0x0080
422dd5fc854SMatthew Garrett #define EFI_PCI_IO_ATTRIBUTE_IO 0x0100
423dd5fc854SMatthew Garrett #define EFI_PCI_IO_ATTRIBUTE_MEMORY 0x0200
424dd5fc854SMatthew Garrett #define EFI_PCI_IO_ATTRIBUTE_BUS_MASTER 0x0400
425dd5fc854SMatthew Garrett #define EFI_PCI_IO_ATTRIBUTE_MEMORY_CACHED 0x0800
426dd5fc854SMatthew Garrett #define EFI_PCI_IO_ATTRIBUTE_MEMORY_DISABLE 0x1000
427dd5fc854SMatthew Garrett #define EFI_PCI_IO_ATTRIBUTE_EMBEDDED_DEVICE 0x2000
428dd5fc854SMatthew Garrett #define EFI_PCI_IO_ATTRIBUTE_EMBEDDED_ROM 0x4000
429dd5fc854SMatthew Garrett #define EFI_PCI_IO_ATTRIBUTE_DUAL_ADDRESS_CYCLE 0x8000
430dd5fc854SMatthew Garrett #define EFI_PCI_IO_ATTRIBUTE_ISA_IO_16 0x10000
431dd5fc854SMatthew Garrett #define EFI_PCI_IO_ATTRIBUTE_VGA_PALETTE_IO_16 0x20000
432dd5fc854SMatthew Garrett #define EFI_PCI_IO_ATTRIBUTE_VGA_IO_16 0x40000
433dd5fc854SMatthew Garrett 
434f30ca6baSMatt Fleming /*
4351da177e4SLinus Torvalds  * Types and defines for EFI ResetSystem
4361da177e4SLinus Torvalds  */
4371da177e4SLinus Torvalds #define EFI_RESET_COLD 0
4381da177e4SLinus Torvalds #define EFI_RESET_WARM 1
4391da177e4SLinus Torvalds #define EFI_RESET_SHUTDOWN 2
4401da177e4SLinus Torvalds 
4411da177e4SLinus Torvalds /*
4421da177e4SLinus Torvalds  * EFI Runtime Services table
4431da177e4SLinus Torvalds  */
4441da177e4SLinus Torvalds #define EFI_RUNTIME_SERVICES_SIGNATURE ((u64)0x5652453544e5552ULL)
4451da177e4SLinus Torvalds #define EFI_RUNTIME_SERVICES_REVISION  0x00010000
4461da177e4SLinus Torvalds 
4471da177e4SLinus Torvalds typedef struct {
4481da177e4SLinus Torvalds 	efi_table_hdr_t hdr;
449677703ceSMatt Fleming 	u32 get_time;
450677703ceSMatt Fleming 	u32 set_time;
451677703ceSMatt Fleming 	u32 get_wakeup_time;
452677703ceSMatt Fleming 	u32 set_wakeup_time;
453677703ceSMatt Fleming 	u32 set_virtual_address_map;
454677703ceSMatt Fleming 	u32 convert_pointer;
455677703ceSMatt Fleming 	u32 get_variable;
456677703ceSMatt Fleming 	u32 get_next_variable;
457677703ceSMatt Fleming 	u32 set_variable;
458677703ceSMatt Fleming 	u32 get_next_high_mono_count;
459677703ceSMatt Fleming 	u32 reset_system;
460677703ceSMatt Fleming 	u32 update_capsule;
461677703ceSMatt Fleming 	u32 query_capsule_caps;
462677703ceSMatt Fleming 	u32 query_variable_info;
463677703ceSMatt Fleming } efi_runtime_services_32_t;
464677703ceSMatt Fleming 
465677703ceSMatt Fleming typedef struct {
466677703ceSMatt Fleming 	efi_table_hdr_t hdr;
467677703ceSMatt Fleming 	u64 get_time;
468677703ceSMatt Fleming 	u64 set_time;
469677703ceSMatt Fleming 	u64 get_wakeup_time;
470677703ceSMatt Fleming 	u64 set_wakeup_time;
471677703ceSMatt Fleming 	u64 set_virtual_address_map;
472677703ceSMatt Fleming 	u64 convert_pointer;
473677703ceSMatt Fleming 	u64 get_variable;
474677703ceSMatt Fleming 	u64 get_next_variable;
475677703ceSMatt Fleming 	u64 set_variable;
476677703ceSMatt Fleming 	u64 get_next_high_mono_count;
477677703ceSMatt Fleming 	u64 reset_system;
478677703ceSMatt Fleming 	u64 update_capsule;
479677703ceSMatt Fleming 	u64 query_capsule_caps;
480677703ceSMatt Fleming 	u64 query_variable_info;
481677703ceSMatt Fleming } efi_runtime_services_64_t;
482677703ceSMatt Fleming 
483677703ceSMatt Fleming typedef struct {
484677703ceSMatt Fleming 	efi_table_hdr_t hdr;
48543ab0476SBorislav Petkov 	void *get_time;
48643ab0476SBorislav Petkov 	void *set_time;
48743ab0476SBorislav Petkov 	void *get_wakeup_time;
48843ab0476SBorislav Petkov 	void *set_wakeup_time;
48943ab0476SBorislav Petkov 	void *set_virtual_address_map;
49043ab0476SBorislav Petkov 	void *convert_pointer;
49143ab0476SBorislav Petkov 	void *get_variable;
49243ab0476SBorislav Petkov 	void *get_next_variable;
49343ab0476SBorislav Petkov 	void *set_variable;
49443ab0476SBorislav Petkov 	void *get_next_high_mono_count;
49543ab0476SBorislav Petkov 	void *reset_system;
49643ab0476SBorislav Petkov 	void *update_capsule;
49743ab0476SBorislav Petkov 	void *query_capsule_caps;
49843ab0476SBorislav Petkov 	void *query_variable_info;
4991da177e4SLinus Torvalds } efi_runtime_services_t;
5001da177e4SLinus Torvalds 
5011da177e4SLinus Torvalds typedef efi_status_t efi_get_time_t (efi_time_t *tm, efi_time_cap_t *tc);
5021da177e4SLinus Torvalds typedef efi_status_t efi_set_time_t (efi_time_t *tm);
5031da177e4SLinus Torvalds typedef efi_status_t efi_get_wakeup_time_t (efi_bool_t *enabled, efi_bool_t *pending,
5041da177e4SLinus Torvalds 					    efi_time_t *tm);
5051da177e4SLinus Torvalds typedef efi_status_t efi_set_wakeup_time_t (efi_bool_t enabled, efi_time_t *tm);
5061da177e4SLinus Torvalds typedef efi_status_t efi_get_variable_t (efi_char16_t *name, efi_guid_t *vendor, u32 *attr,
5071da177e4SLinus Torvalds 					 unsigned long *data_size, void *data);
5081da177e4SLinus Torvalds typedef efi_status_t efi_get_next_variable_t (unsigned long *name_size, efi_char16_t *name,
5091da177e4SLinus Torvalds 					      efi_guid_t *vendor);
5101da177e4SLinus Torvalds typedef efi_status_t efi_set_variable_t (efi_char16_t *name, efi_guid_t *vendor,
511f7a2d73fSMatthew Garrett 					 u32 attr, unsigned long data_size,
5121da177e4SLinus Torvalds 					 void *data);
5131da177e4SLinus Torvalds typedef efi_status_t efi_get_next_high_mono_count_t (u32 *count);
5141da177e4SLinus Torvalds typedef void efi_reset_system_t (int reset_type, efi_status_t status,
5151da177e4SLinus Torvalds 				 unsigned long data_size, efi_char16_t *data);
5161da177e4SLinus Torvalds typedef efi_status_t efi_set_virtual_address_map_t (unsigned long memory_map_size,
5171da177e4SLinus Torvalds 						unsigned long descriptor_size,
5181da177e4SLinus Torvalds 						u32 descriptor_version,
5191da177e4SLinus Torvalds 						efi_memory_desc_t *virtual_map);
5203b370237SMatthew Garrett typedef efi_status_t efi_query_variable_info_t(u32 attr,
5213b370237SMatthew Garrett 					       u64 *storage_space,
5223b370237SMatthew Garrett 					       u64 *remaining_space,
5233b370237SMatthew Garrett 					       u64 *max_variable_size);
5243b370237SMatthew Garrett typedef efi_status_t efi_update_capsule_t(efi_capsule_header_t **capsules,
5253b370237SMatthew Garrett 					  unsigned long count,
5263b370237SMatthew Garrett 					  unsigned long sg_list);
5273b370237SMatthew Garrett typedef efi_status_t efi_query_capsule_caps_t(efi_capsule_header_t **capsules,
5283b370237SMatthew Garrett 					      unsigned long count,
5293b370237SMatthew Garrett 					      u64 *max_size,
5303b370237SMatthew Garrett 					      int *reset_type);
531ca0e30dcSArd Biesheuvel typedef efi_status_t efi_query_variable_store_t(u32 attributes,
532ca0e30dcSArd Biesheuvel 						unsigned long size,
533ca0e30dcSArd Biesheuvel 						bool nonblocking);
5341da177e4SLinus Torvalds 
535022ee6c5SArd Biesheuvel void efi_native_runtime_setup(void);
536022ee6c5SArd Biesheuvel 
5371da177e4SLinus Torvalds /*
5381da177e4SLinus Torvalds  *  EFI Configuration Table and GUID definitions
5391da177e4SLinus Torvalds  */
5401da177e4SLinus Torvalds #define NULL_GUID \
541662b1d89SPeter Jones 	EFI_GUID(0x00000000, 0x0000, 0x0000, \
542662b1d89SPeter Jones 		 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00)
5431da177e4SLinus Torvalds 
5441da177e4SLinus Torvalds #define MPS_TABLE_GUID    \
545662b1d89SPeter Jones 	EFI_GUID(0xeb9d2d2f, 0x2d88, 0x11d3, \
546662b1d89SPeter Jones 		 0x9a, 0x16, 0x00, 0x90, 0x27, 0x3f, 0xc1, 0x4d)
5471da177e4SLinus Torvalds 
5481da177e4SLinus Torvalds #define ACPI_TABLE_GUID    \
549662b1d89SPeter Jones 	EFI_GUID(0xeb9d2d30, 0x2d88, 0x11d3, \
550662b1d89SPeter Jones 		 0x9a, 0x16, 0x00, 0x90, 0x27, 0x3f, 0xc1, 0x4d)
5511da177e4SLinus Torvalds 
5521da177e4SLinus Torvalds #define ACPI_20_TABLE_GUID    \
553662b1d89SPeter Jones 	EFI_GUID(0x8868e871, 0xe4f1, 0x11d3, \
554662b1d89SPeter Jones 		 0xbc, 0x22, 0x00, 0x80, 0xc7, 0x3c, 0x88, 0x81)
5551da177e4SLinus Torvalds 
5561da177e4SLinus Torvalds #define SMBIOS_TABLE_GUID    \
557662b1d89SPeter Jones 	EFI_GUID(0xeb9d2d31, 0x2d88, 0x11d3, \
558662b1d89SPeter Jones 		 0x9a, 0x16, 0x00, 0x90, 0x27, 0x3f, 0xc1, 0x4d)
5591da177e4SLinus Torvalds 
560e1ccbbc9SArd Biesheuvel #define SMBIOS3_TABLE_GUID    \
561662b1d89SPeter Jones 	EFI_GUID(0xf2fd1544, 0x9794, 0x4a2c, \
562662b1d89SPeter Jones 		 0x99, 0x2e, 0xe5, 0xbb, 0xcf, 0x20, 0xe3, 0x94)
563e1ccbbc9SArd Biesheuvel 
5641da177e4SLinus Torvalds #define SAL_SYSTEM_TABLE_GUID    \
565662b1d89SPeter Jones 	EFI_GUID(0xeb9d2d32, 0x2d88, 0x11d3, \
566662b1d89SPeter Jones 		 0x9a, 0x16, 0x00, 0x90, 0x27, 0x3f, 0xc1, 0x4d)
5671da177e4SLinus Torvalds 
5681da177e4SLinus Torvalds #define HCDP_TABLE_GUID	\
569662b1d89SPeter Jones 	EFI_GUID(0xf951938d, 0x620b, 0x42ef, \
570662b1d89SPeter Jones 		 0x82, 0x79, 0xa8, 0x4b, 0x79, 0x61, 0x78, 0x98)
5711da177e4SLinus Torvalds 
5721da177e4SLinus Torvalds #define UGA_IO_PROTOCOL_GUID \
573662b1d89SPeter Jones 	EFI_GUID(0x61a4d49e, 0x6f68, 0x4f1b, \
574662b1d89SPeter Jones 		 0xb9, 0x22, 0xa8, 0x6e, 0xed, 0x0b, 0x07, 0xa2)
5751da177e4SLinus Torvalds 
5761da177e4SLinus Torvalds #define EFI_GLOBAL_VARIABLE_GUID \
577662b1d89SPeter Jones 	EFI_GUID(0x8be4df61, 0x93ca, 0x11d2, \
578662b1d89SPeter Jones 		 0xaa, 0x0d, 0x00, 0xe0, 0x98, 0x03, 0x2b, 0x8c)
5791da177e4SLinus Torvalds 
580a50f70b1SRuss Anderson #define UV_SYSTEM_TABLE_GUID \
581662b1d89SPeter Jones 	EFI_GUID(0x3b13a7d4, 0x633e, 0x11dd, \
582662b1d89SPeter Jones 		 0x93, 0xec, 0xda, 0x25, 0x56, 0xd8, 0x95, 0x93)
583a50f70b1SRuss Anderson 
5845ee9c198SMatthew Garrett #define LINUX_EFI_CRASH_GUID \
585662b1d89SPeter Jones 	EFI_GUID(0xcfc8fc79, 0xbe2e, 0x4ddc, \
586662b1d89SPeter Jones 		 0x97, 0xf0, 0x9f, 0x98, 0xbf, 0xe2, 0x98, 0xa0)
5875ee9c198SMatthew Garrett 
5888e84f345SMatt Fleming #define LOADED_IMAGE_PROTOCOL_GUID \
589662b1d89SPeter Jones 	EFI_GUID(0x5b1b31a1, 0x9562, 0x11d2, \
590662b1d89SPeter Jones 		 0x8e, 0x3f, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b)
5918e84f345SMatt Fleming 
5920f7c5d47SMatt Fleming #define EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID \
593662b1d89SPeter Jones 	EFI_GUID(0x9042a9de, 0x23dc, 0x4a38, \
594662b1d89SPeter Jones 		 0x96, 0xfb, 0x7a, 0xde, 0xd0, 0x80, 0x51, 0x6a)
5950f7c5d47SMatt Fleming 
5960f7c5d47SMatt Fleming #define EFI_UGA_PROTOCOL_GUID \
597662b1d89SPeter Jones 	EFI_GUID(0x982c298b, 0xf4fa, 0x41cb, \
598662b1d89SPeter Jones 		 0xb8, 0x38, 0x77, 0xaa, 0x68, 0x8f, 0xb8, 0x39)
5990f7c5d47SMatt Fleming 
6000f7c5d47SMatt Fleming #define EFI_PCI_IO_PROTOCOL_GUID \
601662b1d89SPeter Jones 	EFI_GUID(0x4cf5b200, 0x68b8, 0x4ca5, \
602662b1d89SPeter Jones 		 0x9e, 0xec, 0xb2, 0x3e, 0x3f, 0x50, 0x02, 0x9a)
6030f7c5d47SMatt Fleming 
60455839d51SMatt Fleming #define EFI_FILE_INFO_ID \
605662b1d89SPeter Jones 	EFI_GUID(0x9576e92, 0x6d3f, 0x11d2, \
606662b1d89SPeter Jones 		 0x8e, 0x39, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b)
60755839d51SMatt Fleming 
6080bb54905SPeter Jones #define EFI_SYSTEM_RESOURCE_TABLE_GUID \
609662b1d89SPeter Jones 	EFI_GUID(0xb122a263, 0x3661, 0x4f68, \
610662b1d89SPeter Jones 		 0x99, 0x29, 0x78, 0xf8, 0xb0, 0xd6, 0x21, 0x80)
6110bb54905SPeter Jones 
61255839d51SMatt Fleming #define EFI_FILE_SYSTEM_GUID \
613662b1d89SPeter Jones 	EFI_GUID(0x964e5b22, 0x6459, 0x11d2, \
614662b1d89SPeter Jones 		 0x8e, 0x39, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b)
61555839d51SMatt Fleming 
616263b4a30SRoy Franz #define DEVICE_TREE_GUID \
617662b1d89SPeter Jones 	EFI_GUID(0xb1b621d5, 0xf19c, 0x41a5, \
618662b1d89SPeter Jones 		 0x83, 0x0b, 0xd9, 0x15, 0x2c, 0x69, 0xaa, 0xe0)
619263b4a30SRoy Franz 
620bf924863SArd Biesheuvel #define EFI_PROPERTIES_TABLE_GUID \
621662b1d89SPeter Jones 	EFI_GUID(0x880aaca3, 0x4adc, 0x4a04, \
622662b1d89SPeter Jones 		 0x90, 0x79, 0xb7, 0x47, 0x34, 0x08, 0x25, 0xe5)
623bf924863SArd Biesheuvel 
624e4fbf476SArd Biesheuvel #define EFI_RNG_PROTOCOL_GUID \
625e4fbf476SArd Biesheuvel 	EFI_GUID(0x3152bca5, 0xeade, 0x433d, \
626e4fbf476SArd Biesheuvel 		 0x86, 0x2e, 0xc0, 0x1c, 0xdc, 0x29, 0x1f, 0x44)
627e4fbf476SArd Biesheuvel 
628a604af07SArd Biesheuvel #define EFI_MEMORY_ATTRIBUTES_TABLE_GUID \
629a604af07SArd Biesheuvel 	EFI_GUID(0xdcfa911d, 0x26eb, 0x469f, \
630a604af07SArd Biesheuvel 		 0xa2, 0x20, 0x38, 0xb7, 0xdc, 0x46, 0x12, 0x20)
631a604af07SArd Biesheuvel 
632fc372064SArd Biesheuvel #define EFI_CONSOLE_OUT_DEVICE_GUID \
633fc372064SArd Biesheuvel 	EFI_GUID(0xd3b36f2c, 0xd551, 0x11d4, \
634fc372064SArd Biesheuvel 		 0x9a, 0x46, 0x00, 0x90, 0x27, 0x3f, 0xc1, 0x4d)
635fc372064SArd Biesheuvel 
636801820beSArd Biesheuvel /*
637801820beSArd Biesheuvel  * This GUID is used to pass to the kernel proper the struct screen_info
638801820beSArd Biesheuvel  * structure that was populated by the stub based on the GOP protocol instance
639801820beSArd Biesheuvel  * associated with ConOut
640801820beSArd Biesheuvel  */
641801820beSArd Biesheuvel #define LINUX_EFI_ARM_SCREEN_INFO_TABLE_GUID \
642801820beSArd Biesheuvel 	EFI_GUID(0xe03fc20a, 0x85dc, 0x406e, \
643801820beSArd Biesheuvel 		 0xb9, 0xe, 0x4a, 0xb5, 0x02, 0x37, 0x1d, 0x95)
644801820beSArd Biesheuvel 
64506f7d4a1SCompostella, Jeremy #define LINUX_EFI_LOADER_ENTRY_GUID \
64606f7d4a1SCompostella, Jeremy 	EFI_GUID(0x4a67b082, 0x0a4c, 0x41cf, \
64706f7d4a1SCompostella, Jeremy 		 0xb6, 0xc7, 0x44, 0x0b, 0x29, 0xbb, 0x8c, 0x4f)
64806f7d4a1SCompostella, Jeremy 
6491da177e4SLinus Torvalds typedef struct {
6501da177e4SLinus Torvalds 	efi_guid_t guid;
6511adbfa35SOlof Johansson 	u64 table;
6521adbfa35SOlof Johansson } efi_config_table_64_t;
6531adbfa35SOlof Johansson 
6541adbfa35SOlof Johansson typedef struct {
6551adbfa35SOlof Johansson 	efi_guid_t guid;
6561adbfa35SOlof Johansson 	u32 table;
6571adbfa35SOlof Johansson } efi_config_table_32_t;
6581adbfa35SOlof Johansson 
6591adbfa35SOlof Johansson typedef struct {
6601adbfa35SOlof Johansson 	efi_guid_t guid;
6611da177e4SLinus Torvalds 	unsigned long table;
6621da177e4SLinus Torvalds } efi_config_table_t;
6631da177e4SLinus Torvalds 
664272686bfSLeif Lindholm typedef struct {
665272686bfSLeif Lindholm 	efi_guid_t guid;
666272686bfSLeif Lindholm 	const char *name;
667272686bfSLeif Lindholm 	unsigned long *ptr;
668272686bfSLeif Lindholm } efi_config_table_type_t;
669272686bfSLeif Lindholm 
6701da177e4SLinus Torvalds #define EFI_SYSTEM_TABLE_SIGNATURE ((u64)0x5453595320494249ULL)
6711da177e4SLinus Torvalds 
6723b370237SMatthew Garrett #define EFI_2_30_SYSTEM_TABLE_REVISION  ((2 << 16) | (30))
6733b370237SMatthew Garrett #define EFI_2_20_SYSTEM_TABLE_REVISION  ((2 << 16) | (20))
6743b370237SMatthew Garrett #define EFI_2_10_SYSTEM_TABLE_REVISION  ((2 << 16) | (10))
6753b370237SMatthew Garrett #define EFI_2_00_SYSTEM_TABLE_REVISION  ((2 << 16) | (00))
6763b370237SMatthew Garrett #define EFI_1_10_SYSTEM_TABLE_REVISION  ((1 << 16) | (10))
6773b370237SMatthew Garrett #define EFI_1_02_SYSTEM_TABLE_REVISION  ((1 << 16) | (02))
6783b370237SMatthew Garrett 
6791da177e4SLinus Torvalds typedef struct {
6801da177e4SLinus Torvalds 	efi_table_hdr_t hdr;
6811adbfa35SOlof Johansson 	u64 fw_vendor;	/* physical addr of CHAR16 vendor string */
6821adbfa35SOlof Johansson 	u32 fw_revision;
6831adbfa35SOlof Johansson 	u32 __pad1;
6841adbfa35SOlof Johansson 	u64 con_in_handle;
6851adbfa35SOlof Johansson 	u64 con_in;
6861adbfa35SOlof Johansson 	u64 con_out_handle;
6871adbfa35SOlof Johansson 	u64 con_out;
6881adbfa35SOlof Johansson 	u64 stderr_handle;
6891adbfa35SOlof Johansson 	u64 stderr;
6901adbfa35SOlof Johansson 	u64 runtime;
6911adbfa35SOlof Johansson 	u64 boottime;
6921adbfa35SOlof Johansson 	u32 nr_tables;
6931adbfa35SOlof Johansson 	u32 __pad2;
6941adbfa35SOlof Johansson 	u64 tables;
6951adbfa35SOlof Johansson } efi_system_table_64_t;
6961adbfa35SOlof Johansson 
6971adbfa35SOlof Johansson typedef struct {
6981adbfa35SOlof Johansson 	efi_table_hdr_t hdr;
6991adbfa35SOlof Johansson 	u32 fw_vendor;	/* physical addr of CHAR16 vendor string */
7001adbfa35SOlof Johansson 	u32 fw_revision;
7011adbfa35SOlof Johansson 	u32 con_in_handle;
7021adbfa35SOlof Johansson 	u32 con_in;
7031adbfa35SOlof Johansson 	u32 con_out_handle;
7041adbfa35SOlof Johansson 	u32 con_out;
7051adbfa35SOlof Johansson 	u32 stderr_handle;
7061adbfa35SOlof Johansson 	u32 stderr;
7071adbfa35SOlof Johansson 	u32 runtime;
7081adbfa35SOlof Johansson 	u32 boottime;
7091adbfa35SOlof Johansson 	u32 nr_tables;
7101adbfa35SOlof Johansson 	u32 tables;
7111adbfa35SOlof Johansson } efi_system_table_32_t;
7121adbfa35SOlof Johansson 
7131adbfa35SOlof Johansson typedef struct {
7141adbfa35SOlof Johansson 	efi_table_hdr_t hdr;
7151da177e4SLinus Torvalds 	unsigned long fw_vendor;	/* physical addr of CHAR16 vendor string */
7161da177e4SLinus Torvalds 	u32 fw_revision;
7171da177e4SLinus Torvalds 	unsigned long con_in_handle;
7181da177e4SLinus Torvalds 	unsigned long con_in;
7191da177e4SLinus Torvalds 	unsigned long con_out_handle;
7201da177e4SLinus Torvalds 	unsigned long con_out;
7211da177e4SLinus Torvalds 	unsigned long stderr_handle;
7221da177e4SLinus Torvalds 	unsigned long stderr;
7231da177e4SLinus Torvalds 	efi_runtime_services_t *runtime;
724f30ca6baSMatt Fleming 	efi_boot_services_t *boottime;
7251da177e4SLinus Torvalds 	unsigned long nr_tables;
7261da177e4SLinus Torvalds 	unsigned long tables;
7271da177e4SLinus Torvalds } efi_system_table_t;
7281da177e4SLinus Torvalds 
7291da177e4SLinus Torvalds struct efi_memory_map {
73044511fb9SArd Biesheuvel 	phys_addr_t phys_map;
7317ae65fd3SMatt Tolentino 	void *map;
7327ae65fd3SMatt Tolentino 	void *map_end;
7331da177e4SLinus Torvalds 	int nr_map;
7341da177e4SLinus Torvalds 	unsigned long desc_version;
7357ae65fd3SMatt Tolentino 	unsigned long desc_size;
7361da177e4SLinus Torvalds };
7371da177e4SLinus Torvalds 
7380302f71cSMark Salter struct efi_fdt_params {
7390302f71cSMark Salter 	u64 system_table;
7400302f71cSMark Salter 	u64 mmap;
7410302f71cSMark Salter 	u32 mmap_size;
7420302f71cSMark Salter 	u32 desc_size;
7430302f71cSMark Salter 	u32 desc_ver;
7440302f71cSMark Salter };
7450302f71cSMark Salter 
7468e84f345SMatt Fleming typedef struct {
7478e84f345SMatt Fleming 	u32 revision;
748677703ceSMatt Fleming 	u32 parent_handle;
749677703ceSMatt Fleming 	u32 system_table;
750677703ceSMatt Fleming 	u32 device_handle;
751677703ceSMatt Fleming 	u32 file_path;
752677703ceSMatt Fleming 	u32 reserved;
753677703ceSMatt Fleming 	u32 load_options_size;
754677703ceSMatt Fleming 	u32 load_options;
755677703ceSMatt Fleming 	u32 image_base;
756677703ceSMatt Fleming 	__aligned_u64 image_size;
757677703ceSMatt Fleming 	unsigned int image_code_type;
758677703ceSMatt Fleming 	unsigned int image_data_type;
759677703ceSMatt Fleming 	unsigned long unload;
760677703ceSMatt Fleming } efi_loaded_image_32_t;
761677703ceSMatt Fleming 
762677703ceSMatt Fleming typedef struct {
763677703ceSMatt Fleming 	u32 revision;
764677703ceSMatt Fleming 	u64 parent_handle;
765677703ceSMatt Fleming 	u64 system_table;
766677703ceSMatt Fleming 	u64 device_handle;
767677703ceSMatt Fleming 	u64 file_path;
768677703ceSMatt Fleming 	u64 reserved;
769677703ceSMatt Fleming 	u32 load_options_size;
770677703ceSMatt Fleming 	u64 load_options;
771677703ceSMatt Fleming 	u64 image_base;
772677703ceSMatt Fleming 	__aligned_u64 image_size;
773677703ceSMatt Fleming 	unsigned int image_code_type;
774677703ceSMatt Fleming 	unsigned int image_data_type;
775677703ceSMatt Fleming 	unsigned long unload;
776677703ceSMatt Fleming } efi_loaded_image_64_t;
777677703ceSMatt Fleming 
778677703ceSMatt Fleming typedef struct {
779677703ceSMatt Fleming 	u32 revision;
7808e84f345SMatt Fleming 	void *parent_handle;
7818e84f345SMatt Fleming 	efi_system_table_t *system_table;
7828e84f345SMatt Fleming 	void *device_handle;
7838e84f345SMatt Fleming 	void *file_path;
7848e84f345SMatt Fleming 	void *reserved;
7858e84f345SMatt Fleming 	u32 load_options_size;
7868e84f345SMatt Fleming 	void *load_options;
7878e84f345SMatt Fleming 	void *image_base;
7888e84f345SMatt Fleming 	__aligned_u64 image_size;
7898e84f345SMatt Fleming 	unsigned int image_code_type;
7908e84f345SMatt Fleming 	unsigned int image_data_type;
7918e84f345SMatt Fleming 	unsigned long unload;
7928e84f345SMatt Fleming } efi_loaded_image_t;
7938e84f345SMatt Fleming 
79455839d51SMatt Fleming 
79555839d51SMatt Fleming typedef struct {
79655839d51SMatt Fleming 	u64 size;
79755839d51SMatt Fleming 	u64 file_size;
79855839d51SMatt Fleming 	u64 phys_size;
79955839d51SMatt Fleming 	efi_time_t create_time;
80055839d51SMatt Fleming 	efi_time_t last_access_time;
80155839d51SMatt Fleming 	efi_time_t modification_time;
80255839d51SMatt Fleming 	__aligned_u64 attribute;
80355839d51SMatt Fleming 	efi_char16_t filename[1];
80455839d51SMatt Fleming } efi_file_info_t;
80555839d51SMatt Fleming 
806677703ceSMatt Fleming typedef struct {
807677703ceSMatt Fleming 	u64 revision;
808677703ceSMatt Fleming 	u32 open;
809677703ceSMatt Fleming 	u32 close;
810677703ceSMatt Fleming 	u32 delete;
811677703ceSMatt Fleming 	u32 read;
812677703ceSMatt Fleming 	u32 write;
813677703ceSMatt Fleming 	u32 get_position;
814677703ceSMatt Fleming 	u32 set_position;
815677703ceSMatt Fleming 	u32 get_info;
816677703ceSMatt Fleming 	u32 set_info;
817677703ceSMatt Fleming 	u32 flush;
818677703ceSMatt Fleming } efi_file_handle_32_t;
819677703ceSMatt Fleming 
820677703ceSMatt Fleming typedef struct {
821677703ceSMatt Fleming 	u64 revision;
822677703ceSMatt Fleming 	u64 open;
823677703ceSMatt Fleming 	u64 close;
824677703ceSMatt Fleming 	u64 delete;
825677703ceSMatt Fleming 	u64 read;
826677703ceSMatt Fleming 	u64 write;
827677703ceSMatt Fleming 	u64 get_position;
828677703ceSMatt Fleming 	u64 set_position;
829677703ceSMatt Fleming 	u64 get_info;
830677703ceSMatt Fleming 	u64 set_info;
831677703ceSMatt Fleming 	u64 flush;
832677703ceSMatt Fleming } efi_file_handle_64_t;
833677703ceSMatt Fleming 
834ed37ddffSRoy Franz typedef struct _efi_file_handle {
83555839d51SMatt Fleming 	u64 revision;
836ed37ddffSRoy Franz 	efi_status_t (*open)(struct _efi_file_handle *,
837ed37ddffSRoy Franz 			     struct _efi_file_handle **,
838ed37ddffSRoy Franz 			     efi_char16_t *, u64, u64);
839ed37ddffSRoy Franz 	efi_status_t (*close)(struct _efi_file_handle *);
84055839d51SMatt Fleming 	void *delete;
841ed37ddffSRoy Franz 	efi_status_t (*read)(struct _efi_file_handle *, unsigned long *,
842ed37ddffSRoy Franz 			     void *);
84355839d51SMatt Fleming 	void *write;
84455839d51SMatt Fleming 	void *get_position;
84555839d51SMatt Fleming 	void *set_position;
846ed37ddffSRoy Franz 	efi_status_t (*get_info)(struct _efi_file_handle *, efi_guid_t *,
847ed37ddffSRoy Franz 			unsigned long *, void *);
84855839d51SMatt Fleming 	void *set_info;
84955839d51SMatt Fleming 	void *flush;
85055839d51SMatt Fleming } efi_file_handle_t;
85155839d51SMatt Fleming 
852ed37ddffSRoy Franz typedef struct _efi_file_io_interface {
853ed37ddffSRoy Franz 	u64 revision;
854ed37ddffSRoy Franz 	int (*open_volume)(struct _efi_file_io_interface *,
855ed37ddffSRoy Franz 			   efi_file_handle_t **);
856ed37ddffSRoy Franz } efi_file_io_interface_t;
857ed37ddffSRoy Franz 
85855839d51SMatt Fleming #define EFI_FILE_MODE_READ	0x0000000000000001
85955839d51SMatt Fleming #define EFI_FILE_MODE_WRITE	0x0000000000000002
86055839d51SMatt Fleming #define EFI_FILE_MODE_CREATE	0x8000000000000000
86155839d51SMatt Fleming 
862bf924863SArd Biesheuvel typedef struct {
863bf924863SArd Biesheuvel 	u32 version;
864bf924863SArd Biesheuvel 	u32 length;
865bf924863SArd Biesheuvel 	u64 memory_protection_attribute;
866bf924863SArd Biesheuvel } efi_properties_table_t;
867bf924863SArd Biesheuvel 
868bf924863SArd Biesheuvel #define EFI_PROPERTIES_TABLE_VERSION	0x00010000
869bf924863SArd Biesheuvel #define EFI_PROPERTIES_RUNTIME_MEMORY_PROTECTION_NON_EXECUTABLE_PE_DATA	0x1
870bf924863SArd Biesheuvel 
871b2c99e3cSBjorn Helgaas #define EFI_INVALID_TABLE_ADDR		(~0UL)
872b2c99e3cSBjorn Helgaas 
873a604af07SArd Biesheuvel typedef struct {
874a604af07SArd Biesheuvel 	u32 version;
875a604af07SArd Biesheuvel 	u32 num_entries;
876a604af07SArd Biesheuvel 	u32 desc_size;
877a604af07SArd Biesheuvel 	u32 reserved;
878a604af07SArd Biesheuvel 	efi_memory_desc_t entry[0];
879a604af07SArd Biesheuvel } efi_memory_attributes_table_t;
880a604af07SArd Biesheuvel 
8811da177e4SLinus Torvalds /*
8821da177e4SLinus Torvalds  * All runtime access to EFI goes through this structure:
8831da177e4SLinus Torvalds  */
8841da177e4SLinus Torvalds extern struct efi {
8851da177e4SLinus Torvalds 	efi_system_table_t *systab;	/* EFI system table */
8863b370237SMatthew Garrett 	unsigned int runtime_version;	/* Runtime services version */
887b2c99e3cSBjorn Helgaas 	unsigned long mps;		/* MPS table */
888b2c99e3cSBjorn Helgaas 	unsigned long acpi;		/* ACPI table  (IA64 ext 0.71) */
889b2c99e3cSBjorn Helgaas 	unsigned long acpi20;		/* ACPI table  (ACPI 2.0) */
890e1ccbbc9SArd Biesheuvel 	unsigned long smbios;		/* SMBIOS table (32 bit entry point) */
891e1ccbbc9SArd Biesheuvel 	unsigned long smbios3;		/* SMBIOS table (64 bit entry point) */
892b2c99e3cSBjorn Helgaas 	unsigned long sal_systab;	/* SAL system table */
893b2c99e3cSBjorn Helgaas 	unsigned long boot_info;	/* boot info table */
894b2c99e3cSBjorn Helgaas 	unsigned long hcdp;		/* HCDP table */
895b2c99e3cSBjorn Helgaas 	unsigned long uga;		/* UGA table */
896a50f70b1SRuss Anderson 	unsigned long uv_systab;	/* UV system table */
897a0998eb1SDave Young 	unsigned long fw_vendor;	/* fw_vendor */
898a0998eb1SDave Young 	unsigned long runtime;		/* runtime table */
899a0998eb1SDave Young 	unsigned long config_table;	/* config tables */
9000bb54905SPeter Jones 	unsigned long esrt;		/* ESRT table */
901bf924863SArd Biesheuvel 	unsigned long properties_table;	/* properties table */
902a604af07SArd Biesheuvel 	unsigned long mem_attr_table;	/* memory attributes table */
9031da177e4SLinus Torvalds 	efi_get_time_t *get_time;
9041da177e4SLinus Torvalds 	efi_set_time_t *set_time;
9051da177e4SLinus Torvalds 	efi_get_wakeup_time_t *get_wakeup_time;
9061da177e4SLinus Torvalds 	efi_set_wakeup_time_t *set_wakeup_time;
9071da177e4SLinus Torvalds 	efi_get_variable_t *get_variable;
9081da177e4SLinus Torvalds 	efi_get_next_variable_t *get_next_variable;
9091da177e4SLinus Torvalds 	efi_set_variable_t *set_variable;
91070d2a3cfSArd Biesheuvel 	efi_set_variable_t *set_variable_nonblocking;
9113b370237SMatthew Garrett 	efi_query_variable_info_t *query_variable_info;
912d3cac1f8SArd Biesheuvel 	efi_query_variable_info_t *query_variable_info_nonblocking;
9133b370237SMatthew Garrett 	efi_update_capsule_t *update_capsule;
9143b370237SMatthew Garrett 	efi_query_capsule_caps_t *query_capsule_caps;
9151da177e4SLinus Torvalds 	efi_get_next_high_mono_count_t *get_next_high_mono_count;
9161da177e4SLinus Torvalds 	efi_reset_system_t *reset_system;
9171da177e4SLinus Torvalds 	efi_set_virtual_address_map_t *set_virtual_address_map;
918884f4f66SMatt Fleming 	struct efi_memory_map memmap;
9193e909599SMatt Fleming 	unsigned long flags;
9201da177e4SLinus Torvalds } efi;
9211da177e4SLinus Torvalds 
9221da177e4SLinus Torvalds static inline int
9231da177e4SLinus Torvalds efi_guidcmp (efi_guid_t left, efi_guid_t right)
9241da177e4SLinus Torvalds {
9251da177e4SLinus Torvalds 	return memcmp(&left, &right, sizeof (efi_guid_t));
9261da177e4SLinus Torvalds }
9271da177e4SLinus Torvalds 
9281da177e4SLinus Torvalds static inline char *
92926e02272SBorislav Petkov efi_guid_to_str(efi_guid_t *guid, char *out)
9301da177e4SLinus Torvalds {
931925ede0bSJoe Perches 	sprintf(out, "%pUl", guid->b);
9321da177e4SLinus Torvalds         return out;
9331da177e4SLinus Torvalds }
9341da177e4SLinus Torvalds 
9351da177e4SLinus Torvalds extern void efi_init (void);
9361da177e4SLinus Torvalds extern void *efi_get_pal_addr (void);
9371da177e4SLinus Torvalds extern void efi_map_pal_code (void);
9381da177e4SLinus Torvalds extern void efi_memmap_walk (efi_freemem_callback_t callback, void *arg);
9391da177e4SLinus Torvalds extern void efi_gettimeofday (struct timespec *ts);
9401da177e4SLinus Torvalds extern void efi_enter_virtual_mode (void);	/* switch EFI to virtual mode, if possible */
94178510792SJosh Triplett #ifdef CONFIG_X86
9422223af38SJosh Triplett extern void efi_late_init(void);
94378510792SJosh Triplett extern void efi_free_boot_services(void);
944ca0e30dcSArd Biesheuvel extern efi_status_t efi_query_variable_store(u32 attributes,
945ca0e30dcSArd Biesheuvel 					     unsigned long size,
946ca0e30dcSArd Biesheuvel 					     bool nonblocking);
947b05b9f5fSTony Luck extern void efi_find_mirror(void);
94878510792SJosh Triplett #else
9492223af38SJosh Triplett static inline void efi_late_init(void) {}
95078510792SJosh Triplett static inline void efi_free_boot_services(void) {}
951a6e4d5a0SMatt Fleming 
952ca0e30dcSArd Biesheuvel static inline efi_status_t efi_query_variable_store(u32 attributes,
953ca0e30dcSArd Biesheuvel 						    unsigned long size,
954ca0e30dcSArd Biesheuvel 						    bool nonblocking)
955a6e4d5a0SMatt Fleming {
956a6e4d5a0SMatt Fleming 	return EFI_SUCCESS;
957a6e4d5a0SMatt Fleming }
95878510792SJosh Triplett #endif
9597bc90e01SJosh Triplett extern void __iomem *efi_lookup_mapped_addr(u64 phys_addr);
960272686bfSLeif Lindholm extern int efi_config_init(efi_config_table_type_t *arch_tables);
9613846c158SPeter Jones #ifdef CONFIG_EFI_ESRT
9620bb54905SPeter Jones extern void __init efi_esrt_init(void);
9633846c158SPeter Jones #else
9643846c158SPeter Jones static inline void efi_esrt_init(void) { }
9653846c158SPeter Jones #endif
9667bb68410SArd Biesheuvel extern int efi_config_parse_tables(void *config_tables, int count, int sz,
9677bb68410SArd Biesheuvel 				   efi_config_table_type_t *arch_tables);
9681da177e4SLinus Torvalds extern u64 efi_get_iobase (void);
9691da177e4SLinus Torvalds extern u32 efi_mem_type (unsigned long phys_addr);
9701da177e4SLinus Torvalds extern u64 efi_mem_attributes (unsigned long phys_addr);
97132e62c63SBjorn Helgaas extern u64 efi_mem_attribute (unsigned long phys_addr, unsigned long size);
9721da177e4SLinus Torvalds extern int __init efi_uart_console_only (void);
9730bb54905SPeter Jones extern u64 efi_mem_desc_end(efi_memory_desc_t *md);
9740bb54905SPeter Jones extern int efi_mem_desc_lookup(u64 phys_addr, efi_memory_desc_t *out_md);
9751da177e4SLinus Torvalds extern void efi_initialize_iomem_resources(struct resource *code_resource,
97600bf4098SBernhard Walle 		struct resource *data_resource, struct resource *bss_resource);
9773565184eSDavid Vrabel extern void efi_get_time(struct timespec *now);
978916f676fSMatthew Garrett extern void efi_reserve_boot_services(void);
9797968c0e3SLeif Lindholm extern int efi_get_fdt_params(struct efi_fdt_params *params);
9800bb54905SPeter Jones extern struct kobject *efi_kobj;
9811da177e4SLinus Torvalds 
98244be28e9SMatt Fleming extern int efi_reboot_quirk_mode;
9830c5ed61aSMatt Fleming extern bool efi_poweroff_required(void);
9840c5ed61aSMatt Fleming 
9850f96a99dSTaku Izumi #ifdef CONFIG_EFI_FAKE_MEMMAP
9860f96a99dSTaku Izumi extern void __init efi_fake_memmap(void);
9870f96a99dSTaku Izumi #else
9880f96a99dSTaku Izumi static inline void efi_fake_memmap(void) { }
9890f96a99dSTaku Izumi #endif
9900f96a99dSTaku Izumi 
99110f0d2f5SArd Biesheuvel /*
99210f0d2f5SArd Biesheuvel  * efi_memattr_perm_setter - arch specific callback function passed into
99310f0d2f5SArd Biesheuvel  *                           efi_memattr_apply_permissions() that updates the
99410f0d2f5SArd Biesheuvel  *                           mapping permissions described by the second
99510f0d2f5SArd Biesheuvel  *                           argument in the page tables referred to by the
99610f0d2f5SArd Biesheuvel  *                           first argument.
99710f0d2f5SArd Biesheuvel  */
99810f0d2f5SArd Biesheuvel typedef int (*efi_memattr_perm_setter)(struct mm_struct *, efi_memory_desc_t *);
99910f0d2f5SArd Biesheuvel 
100010f0d2f5SArd Biesheuvel extern int efi_memattr_init(void);
100110f0d2f5SArd Biesheuvel extern int efi_memattr_apply_permissions(struct mm_struct *mm,
100210f0d2f5SArd Biesheuvel 					 efi_memattr_perm_setter fn);
100310f0d2f5SArd Biesheuvel 
1004e885cd80SMark Salter /* Iterate through an efi_memory_map */
100578ce248fSMatt Fleming #define for_each_efi_memory_desc_in_map(m, md)				   \
1006e885cd80SMark Salter 	for ((md) = (m)->map;						   \
1007e885cd80SMark Salter 	     (md) <= (efi_memory_desc_t *)((m)->map_end - (m)->desc_size); \
1008e885cd80SMark Salter 	     (md) = (void *)(md) + (m)->desc_size)
1009e885cd80SMark Salter 
101078ce248fSMatt Fleming /**
101178ce248fSMatt Fleming  * for_each_efi_memory_desc - iterate over descriptors in efi.memmap
101278ce248fSMatt Fleming  * @md: the efi_memory_desc_t * iterator
101378ce248fSMatt Fleming  *
101478ce248fSMatt Fleming  * Once the loop finishes @md must not be accessed.
101578ce248fSMatt Fleming  */
101678ce248fSMatt Fleming #define for_each_efi_memory_desc(md) \
1017884f4f66SMatt Fleming 	for_each_efi_memory_desc_in_map(&efi.memmap, md)
101878ce248fSMatt Fleming 
101998d2a6caSLaszlo Ersek /*
102098d2a6caSLaszlo Ersek  * Format an EFI memory descriptor's type and attributes to a user-provided
102198d2a6caSLaszlo Ersek  * character buffer, as per snprintf(), and return the buffer.
102298d2a6caSLaszlo Ersek  */
102398d2a6caSLaszlo Ersek char * __init efi_md_typeattr_format(char *buf, size_t size,
102498d2a6caSLaszlo Ersek 				     const efi_memory_desc_t *md);
102598d2a6caSLaszlo Ersek 
10261da177e4SLinus Torvalds /**
10271da177e4SLinus Torvalds  * efi_range_is_wc - check the WC bit on an address range
10281da177e4SLinus Torvalds  * @start: starting kvirt address
10291da177e4SLinus Torvalds  * @len: length of range
10301da177e4SLinus Torvalds  *
10311da177e4SLinus Torvalds  * Consult the EFI memory map and make sure it's ok to set this range WC.
10321da177e4SLinus Torvalds  * Returns true or false.
10331da177e4SLinus Torvalds  */
10341da177e4SLinus Torvalds static inline int efi_range_is_wc(unsigned long start, unsigned long len)
10351da177e4SLinus Torvalds {
1036986a80d5SJesper Juhl 	unsigned long i;
10371da177e4SLinus Torvalds 
10381da177e4SLinus Torvalds 	for (i = 0; i < len; i += (1UL << EFI_PAGE_SHIFT)) {
10391da177e4SLinus Torvalds 		unsigned long paddr = __pa(start + i);
10401da177e4SLinus Torvalds 		if (!(efi_mem_attributes(paddr) & EFI_MEMORY_WC))
10411da177e4SLinus Torvalds 			return 0;
10421da177e4SLinus Torvalds 	}
10431da177e4SLinus Torvalds 	/* The range checked out */
10441da177e4SLinus Torvalds 	return 1;
10451da177e4SLinus Torvalds }
10461da177e4SLinus Torvalds 
10471da177e4SLinus Torvalds #ifdef CONFIG_EFI_PCDP
10481da177e4SLinus Torvalds extern int __init efi_setup_pcdp_console(char *);
10491da177e4SLinus Torvalds #endif
10501da177e4SLinus Torvalds 
10511da177e4SLinus Torvalds /*
105283e68189SMatt Fleming  * We play games with efi_enabled so that the compiler will, if
105383e68189SMatt Fleming  * possible, remove EFI-related code altogether.
10541da177e4SLinus Torvalds  */
105583e68189SMatt Fleming #define EFI_BOOT		0	/* Were we booted from EFI? */
105683e68189SMatt Fleming #define EFI_CONFIG_TABLES	2	/* Can we use EFI config tables? */
105783e68189SMatt Fleming #define EFI_RUNTIME_SERVICES	3	/* Can we use runtime services? */
105883e68189SMatt Fleming #define EFI_MEMMAP		4	/* Can we use EFI memory map? */
105983e68189SMatt Fleming #define EFI_64BIT		5	/* Is the firmware 64-bit? */
10609f27bc54SDaniel Kiper #define EFI_PARAVIRT		6	/* Access is via a paravirt interface */
10619f27bc54SDaniel Kiper #define EFI_ARCH_1		7	/* First arch-specific bit */
1062fed6cefeSBorislav Petkov #define EFI_DBG			8	/* Print additional debug info at runtime */
1063a1041713SArd Biesheuvel #define EFI_NX_PE_DATA		9	/* Can runtime data regions be mapped non-executable? */
106483e68189SMatt Fleming 
10651da177e4SLinus Torvalds #ifdef CONFIG_EFI
10663e909599SMatt Fleming /*
10673e909599SMatt Fleming  * Test whether the above EFI_* bits are enabled.
10683e909599SMatt Fleming  */
10693e909599SMatt Fleming static inline bool efi_enabled(int feature)
107083e68189SMatt Fleming {
10713e909599SMatt Fleming 	return test_bit(feature, &efi.flags) != 0;
10723e909599SMatt Fleming }
10738562c99cSMatt Fleming extern void efi_reboot(enum reboot_mode reboot_mode, const char *__unused);
10743e909599SMatt Fleming #else
10753e909599SMatt Fleming static inline bool efi_enabled(int feature)
10763e909599SMatt Fleming {
10773e909599SMatt Fleming 	return false;
107883e68189SMatt Fleming }
10798562c99cSMatt Fleming static inline void
10808562c99cSMatt Fleming efi_reboot(enum reboot_mode reboot_mode, const char *__unused) {}
10811da177e4SLinus Torvalds #endif
10821da177e4SLinus Torvalds 
1083*806b0351SMatt Fleming extern int efi_status_to_err(efi_status_t status);
1084*806b0351SMatt Fleming 
10851da177e4SLinus Torvalds /*
10861da177e4SLinus Torvalds  * Variable Attributes
10871da177e4SLinus Torvalds  */
10881da177e4SLinus Torvalds #define EFI_VARIABLE_NON_VOLATILE       0x0000000000000001
10891da177e4SLinus Torvalds #define EFI_VARIABLE_BOOTSERVICE_ACCESS 0x0000000000000002
10901da177e4SLinus Torvalds #define EFI_VARIABLE_RUNTIME_ACCESS     0x0000000000000004
109141b3254cSMatthew Garrett #define EFI_VARIABLE_HARDWARE_ERROR_RECORD 0x0000000000000008
109241b3254cSMatthew Garrett #define EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS 0x0000000000000010
109341b3254cSMatthew Garrett #define EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS 0x0000000000000020
109441b3254cSMatthew Garrett #define EFI_VARIABLE_APPEND_WRITE	0x0000000000000040
10951da177e4SLinus Torvalds 
109641b3254cSMatthew Garrett #define EFI_VARIABLE_MASK 	(EFI_VARIABLE_NON_VOLATILE | \
109741b3254cSMatthew Garrett 				EFI_VARIABLE_BOOTSERVICE_ACCESS | \
109841b3254cSMatthew Garrett 				EFI_VARIABLE_RUNTIME_ACCESS | \
109941b3254cSMatthew Garrett 				EFI_VARIABLE_HARDWARE_ERROR_RECORD | \
110041b3254cSMatthew Garrett 				EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS | \
110141b3254cSMatthew Garrett 				EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS | \
110241b3254cSMatthew Garrett 				EFI_VARIABLE_APPEND_WRITE)
11031da177e4SLinus Torvalds /*
1104e14ab23dSMatt Fleming  * Length of a GUID string (strlen("aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee"))
1105e14ab23dSMatt Fleming  * not including trailing NUL
1106e14ab23dSMatt Fleming  */
1107e14ab23dSMatt Fleming #define EFI_VARIABLE_GUID_LEN 36
1108e14ab23dSMatt Fleming 
1109e14ab23dSMatt Fleming /*
1110e2527a7cSMatt Fleming  * The type of search to perform when calling boottime->locate_handle
1111e2527a7cSMatt Fleming  */
1112e2527a7cSMatt Fleming #define EFI_LOCATE_ALL_HANDLES			0
1113e2527a7cSMatt Fleming #define EFI_LOCATE_BY_REGISTER_NOTIFY		1
1114e2527a7cSMatt Fleming #define EFI_LOCATE_BY_PROTOCOL			2
1115e2527a7cSMatt Fleming 
1116e2527a7cSMatt Fleming /*
11171da177e4SLinus Torvalds  * EFI Device Path information
11181da177e4SLinus Torvalds  */
11191da177e4SLinus Torvalds #define EFI_DEV_HW			0x01
11201da177e4SLinus Torvalds #define  EFI_DEV_PCI				 1
11211da177e4SLinus Torvalds #define  EFI_DEV_PCCARD				 2
11221da177e4SLinus Torvalds #define  EFI_DEV_MEM_MAPPED			 3
11231da177e4SLinus Torvalds #define  EFI_DEV_VENDOR				 4
11241da177e4SLinus Torvalds #define  EFI_DEV_CONTROLLER			 5
11251da177e4SLinus Torvalds #define EFI_DEV_ACPI			0x02
11261da177e4SLinus Torvalds #define   EFI_DEV_BASIC_ACPI			 1
11271da177e4SLinus Torvalds #define   EFI_DEV_EXPANDED_ACPI			 2
11281da177e4SLinus Torvalds #define EFI_DEV_MSG			0x03
11291da177e4SLinus Torvalds #define   EFI_DEV_MSG_ATAPI			 1
11301da177e4SLinus Torvalds #define   EFI_DEV_MSG_SCSI			 2
11311da177e4SLinus Torvalds #define   EFI_DEV_MSG_FC			 3
11321da177e4SLinus Torvalds #define   EFI_DEV_MSG_1394			 4
11331da177e4SLinus Torvalds #define   EFI_DEV_MSG_USB			 5
11341da177e4SLinus Torvalds #define   EFI_DEV_MSG_USB_CLASS			15
11351da177e4SLinus Torvalds #define   EFI_DEV_MSG_I20			 6
11361da177e4SLinus Torvalds #define   EFI_DEV_MSG_MAC			11
11371da177e4SLinus Torvalds #define   EFI_DEV_MSG_IPV4			12
11381da177e4SLinus Torvalds #define   EFI_DEV_MSG_IPV6			13
11391da177e4SLinus Torvalds #define   EFI_DEV_MSG_INFINIBAND		 9
11401da177e4SLinus Torvalds #define   EFI_DEV_MSG_UART			14
11411da177e4SLinus Torvalds #define   EFI_DEV_MSG_VENDOR			10
11421da177e4SLinus Torvalds #define EFI_DEV_MEDIA			0x04
11431da177e4SLinus Torvalds #define   EFI_DEV_MEDIA_HARD_DRIVE		 1
11441da177e4SLinus Torvalds #define   EFI_DEV_MEDIA_CDROM			 2
11451da177e4SLinus Torvalds #define   EFI_DEV_MEDIA_VENDOR			 3
11461da177e4SLinus Torvalds #define   EFI_DEV_MEDIA_FILE			 4
11471da177e4SLinus Torvalds #define   EFI_DEV_MEDIA_PROTOCOL		 5
11481da177e4SLinus Torvalds #define EFI_DEV_BIOS_BOOT		0x05
11491da177e4SLinus Torvalds #define EFI_DEV_END_PATH		0x7F
11501da177e4SLinus Torvalds #define EFI_DEV_END_PATH2		0xFF
11511da177e4SLinus Torvalds #define   EFI_DEV_END_INSTANCE			0x01
11521da177e4SLinus Torvalds #define   EFI_DEV_END_ENTIRE			0xFF
11531da177e4SLinus Torvalds 
11541da177e4SLinus Torvalds struct efi_generic_dev_path {
11551da177e4SLinus Torvalds 	u8 type;
11561da177e4SLinus Torvalds 	u8 sub_type;
11571da177e4SLinus Torvalds 	u16 length;
11581da177e4SLinus Torvalds } __attribute ((packed));
11591da177e4SLinus Torvalds 
11604a3575fdSHuang, Ying static inline void memrange_efi_to_native(u64 *addr, u64 *npages)
11614a3575fdSHuang, Ying {
11624a3575fdSHuang, Ying 	*npages = PFN_UP(*addr + (*npages<<EFI_PAGE_SHIFT)) - PFN_DOWN(*addr);
11634a3575fdSHuang, Ying 	*addr &= PAGE_MASK;
11644a3575fdSHuang, Ying }
11654a3575fdSHuang, Ying 
116604851772SMatt Fleming /*
11674fc756bdSMike Waychison  * EFI Variable support.
11684fc756bdSMike Waychison  *
11694fc756bdSMike Waychison  * Different firmware drivers can expose their EFI-like variables using
11704fc756bdSMike Waychison  * the following.
11714fc756bdSMike Waychison  */
11724fc756bdSMike Waychison 
11734fc756bdSMike Waychison struct efivar_operations {
11744fc756bdSMike Waychison 	efi_get_variable_t *get_variable;
11754fc756bdSMike Waychison 	efi_get_next_variable_t *get_next_variable;
11764fc756bdSMike Waychison 	efi_set_variable_t *set_variable;
117770d2a3cfSArd Biesheuvel 	efi_set_variable_t *set_variable_nonblocking;
1178a6e4d5a0SMatt Fleming 	efi_query_variable_store_t *query_variable_store;
11794fc756bdSMike Waychison };
11804fc756bdSMike Waychison 
11814fc756bdSMike Waychison struct efivars {
11824fc756bdSMike Waychison 	/*
11834fc756bdSMike Waychison 	 * ->lock protects two things:
118482f990a8SMatt Fleming 	 * 1) efivarfs_list and efivars_sysfs_list
118582f990a8SMatt Fleming 	 * 2) ->ops calls
11864fc756bdSMike Waychison 	 */
11874fc756bdSMike Waychison 	spinlock_t lock;
11884fc756bdSMike Waychison 	struct kset *kset;
1189605e70c7SLee, Chun-Yi 	struct kobject *kobject;
11904fc756bdSMike Waychison 	const struct efivar_operations *ops;
11914fc756bdSMike Waychison };
11924fc756bdSMike Waychison 
1193e14ab23dSMatt Fleming /*
1194e14ab23dSMatt Fleming  * The maximum size of VariableName + Data = 1024
1195e14ab23dSMatt Fleming  * Therefore, it's reasonable to save that much
1196e14ab23dSMatt Fleming  * space in each part of the structure,
1197e14ab23dSMatt Fleming  * and we use a page for reading/writing.
1198e14ab23dSMatt Fleming  */
1199e14ab23dSMatt Fleming 
1200a5d92ad3SMatt Fleming #define EFI_VAR_NAME_LEN	1024
1201a5d92ad3SMatt Fleming 
1202e14ab23dSMatt Fleming struct efi_variable {
1203a5d92ad3SMatt Fleming 	efi_char16_t  VariableName[EFI_VAR_NAME_LEN/sizeof(efi_char16_t)];
1204e14ab23dSMatt Fleming 	efi_guid_t    VendorGuid;
1205e14ab23dSMatt Fleming 	unsigned long DataSize;
1206e14ab23dSMatt Fleming 	__u8          Data[1024];
1207e14ab23dSMatt Fleming 	efi_status_t  Status;
1208e14ab23dSMatt Fleming 	__u32         Attributes;
1209e14ab23dSMatt Fleming } __attribute__((packed));
1210e14ab23dSMatt Fleming 
1211e14ab23dSMatt Fleming struct efivar_entry {
1212e14ab23dSMatt Fleming 	struct efi_variable var;
1213e14ab23dSMatt Fleming 	struct list_head list;
1214e14ab23dSMatt Fleming 	struct kobject kobj;
1215e0d59733SSeiji Aguchi 	bool scanning;
1216e0d59733SSeiji Aguchi 	bool deleting;
1217e14ab23dSMatt Fleming };
1218e14ab23dSMatt Fleming 
1219677703ceSMatt Fleming struct efi_simple_text_output_protocol_32 {
1220677703ceSMatt Fleming 	u32 reset;
1221677703ceSMatt Fleming 	u32 output_string;
1222677703ceSMatt Fleming 	u32 test_string;
1223677703ceSMatt Fleming };
1224677703ceSMatt Fleming 
1225677703ceSMatt Fleming struct efi_simple_text_output_protocol_64 {
1226677703ceSMatt Fleming 	u64 reset;
1227677703ceSMatt Fleming 	u64 output_string;
1228677703ceSMatt Fleming 	u64 test_string;
1229677703ceSMatt Fleming };
1230ed37ddffSRoy Franz 
1231ed37ddffSRoy Franz struct efi_simple_text_output_protocol {
1232ed37ddffSRoy Franz 	void *reset;
1233ed37ddffSRoy Franz 	efi_status_t (*output_string)(void *, void *);
1234ed37ddffSRoy Franz 	void *test_string;
1235ed37ddffSRoy Franz };
1236ed37ddffSRoy Franz 
1237fc372064SArd Biesheuvel #define PIXEL_RGB_RESERVED_8BIT_PER_COLOR		0
1238fc372064SArd Biesheuvel #define PIXEL_BGR_RESERVED_8BIT_PER_COLOR		1
1239fc372064SArd Biesheuvel #define PIXEL_BIT_MASK					2
1240fc372064SArd Biesheuvel #define PIXEL_BLT_ONLY					3
1241fc372064SArd Biesheuvel #define PIXEL_FORMAT_MAX				4
1242fc372064SArd Biesheuvel 
1243fc372064SArd Biesheuvel struct efi_pixel_bitmask {
1244fc372064SArd Biesheuvel 	u32 red_mask;
1245fc372064SArd Biesheuvel 	u32 green_mask;
1246fc372064SArd Biesheuvel 	u32 blue_mask;
1247fc372064SArd Biesheuvel 	u32 reserved_mask;
1248fc372064SArd Biesheuvel };
1249fc372064SArd Biesheuvel 
1250fc372064SArd Biesheuvel struct efi_graphics_output_mode_info {
1251fc372064SArd Biesheuvel 	u32 version;
1252fc372064SArd Biesheuvel 	u32 horizontal_resolution;
1253fc372064SArd Biesheuvel 	u32 vertical_resolution;
1254fc372064SArd Biesheuvel 	int pixel_format;
1255fc372064SArd Biesheuvel 	struct efi_pixel_bitmask pixel_information;
1256fc372064SArd Biesheuvel 	u32 pixels_per_scan_line;
1257fc372064SArd Biesheuvel } __packed;
1258fc372064SArd Biesheuvel 
1259fc372064SArd Biesheuvel struct efi_graphics_output_protocol_mode_32 {
1260fc372064SArd Biesheuvel 	u32 max_mode;
1261fc372064SArd Biesheuvel 	u32 mode;
1262fc372064SArd Biesheuvel 	u32 info;
1263fc372064SArd Biesheuvel 	u32 size_of_info;
1264fc372064SArd Biesheuvel 	u64 frame_buffer_base;
1265fc372064SArd Biesheuvel 	u32 frame_buffer_size;
1266fc372064SArd Biesheuvel } __packed;
1267fc372064SArd Biesheuvel 
1268fc372064SArd Biesheuvel struct efi_graphics_output_protocol_mode_64 {
1269fc372064SArd Biesheuvel 	u32 max_mode;
1270fc372064SArd Biesheuvel 	u32 mode;
1271fc372064SArd Biesheuvel 	u64 info;
1272fc372064SArd Biesheuvel 	u64 size_of_info;
1273fc372064SArd Biesheuvel 	u64 frame_buffer_base;
1274fc372064SArd Biesheuvel 	u64 frame_buffer_size;
1275fc372064SArd Biesheuvel } __packed;
1276fc372064SArd Biesheuvel 
1277fc372064SArd Biesheuvel struct efi_graphics_output_protocol_mode {
1278fc372064SArd Biesheuvel 	u32 max_mode;
1279fc372064SArd Biesheuvel 	u32 mode;
1280fc372064SArd Biesheuvel 	unsigned long info;
1281fc372064SArd Biesheuvel 	unsigned long size_of_info;
1282fc372064SArd Biesheuvel 	u64 frame_buffer_base;
1283fc372064SArd Biesheuvel 	unsigned long frame_buffer_size;
1284fc372064SArd Biesheuvel } __packed;
1285fc372064SArd Biesheuvel 
1286fc372064SArd Biesheuvel struct efi_graphics_output_protocol_32 {
1287fc372064SArd Biesheuvel 	u32 query_mode;
1288fc372064SArd Biesheuvel 	u32 set_mode;
1289fc372064SArd Biesheuvel 	u32 blt;
1290fc372064SArd Biesheuvel 	u32 mode;
1291fc372064SArd Biesheuvel };
1292fc372064SArd Biesheuvel 
1293fc372064SArd Biesheuvel struct efi_graphics_output_protocol_64 {
1294fc372064SArd Biesheuvel 	u64 query_mode;
1295fc372064SArd Biesheuvel 	u64 set_mode;
1296fc372064SArd Biesheuvel 	u64 blt;
1297fc372064SArd Biesheuvel 	u64 mode;
1298fc372064SArd Biesheuvel };
1299fc372064SArd Biesheuvel 
1300fc372064SArd Biesheuvel struct efi_graphics_output_protocol {
1301fc372064SArd Biesheuvel 	unsigned long query_mode;
1302fc372064SArd Biesheuvel 	unsigned long set_mode;
1303fc372064SArd Biesheuvel 	unsigned long blt;
1304fc372064SArd Biesheuvel 	struct efi_graphics_output_protocol_mode *mode;
1305fc372064SArd Biesheuvel };
1306fc372064SArd Biesheuvel 
1307fc372064SArd Biesheuvel typedef efi_status_t (*efi_graphics_output_protocol_query_mode)(
1308fc372064SArd Biesheuvel 	struct efi_graphics_output_protocol *, u32, unsigned long *,
1309fc372064SArd Biesheuvel 	struct efi_graphics_output_mode_info **);
1310fc372064SArd Biesheuvel 
131104851772SMatt Fleming extern struct list_head efivar_sysfs_list;
131204851772SMatt Fleming 
131304851772SMatt Fleming static inline void
131404851772SMatt Fleming efivar_unregister(struct efivar_entry *var)
131504851772SMatt Fleming {
131604851772SMatt Fleming 	kobject_put(&var->kobj);
131704851772SMatt Fleming }
131804851772SMatt Fleming 
1319e14ab23dSMatt Fleming int efivars_register(struct efivars *efivars,
13204fc756bdSMike Waychison 		     const struct efivar_operations *ops,
1321e14ab23dSMatt Fleming 		     struct kobject *kobject);
1322e14ab23dSMatt Fleming int efivars_unregister(struct efivars *efivars);
1323e14ab23dSMatt Fleming struct kobject *efivars_kobject(void);
1324e14ab23dSMatt Fleming 
1325e14ab23dSMatt Fleming int efivar_init(int (*func)(efi_char16_t *, efi_guid_t, unsigned long, void *),
1326e14ab23dSMatt Fleming 		void *data, bool atomic, bool duplicates,
1327e14ab23dSMatt Fleming 		struct list_head *head);
1328e14ab23dSMatt Fleming 
1329e14ab23dSMatt Fleming void efivar_entry_add(struct efivar_entry *entry, struct list_head *head);
1330e14ab23dSMatt Fleming void efivar_entry_remove(struct efivar_entry *entry);
1331e14ab23dSMatt Fleming 
1332e14ab23dSMatt Fleming int __efivar_entry_delete(struct efivar_entry *entry);
1333e14ab23dSMatt Fleming int efivar_entry_delete(struct efivar_entry *entry);
1334e14ab23dSMatt Fleming 
1335e14ab23dSMatt Fleming int efivar_entry_size(struct efivar_entry *entry, unsigned long *size);
13368a415b8cSMatt Fleming int __efivar_entry_get(struct efivar_entry *entry, u32 *attributes,
13378a415b8cSMatt Fleming 		       unsigned long *size, void *data);
1338e14ab23dSMatt Fleming int efivar_entry_get(struct efivar_entry *entry, u32 *attributes,
1339e14ab23dSMatt Fleming 		     unsigned long *size, void *data);
1340e14ab23dSMatt Fleming int efivar_entry_set(struct efivar_entry *entry, u32 attributes,
1341e14ab23dSMatt Fleming 		     unsigned long size, void *data, struct list_head *head);
1342e14ab23dSMatt Fleming int efivar_entry_set_get_size(struct efivar_entry *entry, u32 attributes,
1343e14ab23dSMatt Fleming 			      unsigned long *size, void *data, bool *set);
1344e14ab23dSMatt Fleming int efivar_entry_set_safe(efi_char16_t *name, efi_guid_t vendor, u32 attributes,
1345e14ab23dSMatt Fleming 			  bool block, unsigned long size, void *data);
1346e14ab23dSMatt Fleming 
1347e14ab23dSMatt Fleming void efivar_entry_iter_begin(void);
1348e14ab23dSMatt Fleming void efivar_entry_iter_end(void);
1349e14ab23dSMatt Fleming 
1350e14ab23dSMatt Fleming int __efivar_entry_iter(int (*func)(struct efivar_entry *, void *),
1351e14ab23dSMatt Fleming 			struct list_head *head, void *data,
1352e14ab23dSMatt Fleming 			struct efivar_entry **prev);
1353e14ab23dSMatt Fleming int efivar_entry_iter(int (*func)(struct efivar_entry *, void *),
1354e14ab23dSMatt Fleming 		      struct list_head *head, void *data);
1355e14ab23dSMatt Fleming 
1356e14ab23dSMatt Fleming struct efivar_entry *efivar_entry_find(efi_char16_t *name, efi_guid_t guid,
1357e14ab23dSMatt Fleming 				       struct list_head *head, bool remove);
1358e14ab23dSMatt Fleming 
13598282f5d9SPeter Jones bool efivar_validate(efi_guid_t vendor, efi_char16_t *var_name, u8 *data,
13608282f5d9SPeter Jones 		     unsigned long data_size);
1361ed8b0de5SPeter Jones bool efivar_variable_is_removable(efi_guid_t vendor, const char *name,
1362ed8b0de5SPeter Jones 				  size_t len);
1363e14ab23dSMatt Fleming 
1364a9499fa7STom Gundersen extern struct work_struct efivar_work;
136504851772SMatt Fleming void efivar_run_worker(void);
136604851772SMatt Fleming 
1367a9499fa7STom Gundersen #if defined(CONFIG_EFI_VARS) || defined(CONFIG_EFI_VARS_MODULE)
1368e14ab23dSMatt Fleming int efivars_sysfs_init(void);
13694fc756bdSMike Waychison 
1370e0d59733SSeiji Aguchi #define EFIVARS_DATA_SIZE_MAX 1024
1371e0d59733SSeiji Aguchi 
13724fc756bdSMike Waychison #endif /* CONFIG_EFI_VARS */
13734fc756bdSMike Waychison 
1374926172d4SDave Young #ifdef CONFIG_EFI_RUNTIME_MAP
1375926172d4SDave Young int efi_runtime_map_init(struct kobject *);
1376926172d4SDave Young void efi_runtime_map_setup(void *, int, u32);
13776a2c20e7SVivek Goyal int efi_get_runtime_map_size(void);
13786a2c20e7SVivek Goyal int efi_get_runtime_map_desc_size(void);
13796a2c20e7SVivek Goyal int efi_runtime_map_copy(void *buf, size_t bufsz);
1380926172d4SDave Young #else
1381926172d4SDave Young static inline int efi_runtime_map_init(struct kobject *kobj)
1382926172d4SDave Young {
1383926172d4SDave Young 	return 0;
1384926172d4SDave Young }
1385926172d4SDave Young 
1386926172d4SDave Young static inline void
1387926172d4SDave Young efi_runtime_map_setup(void *map, int nr_entries, u32 desc_size) {}
13886a2c20e7SVivek Goyal 
13896a2c20e7SVivek Goyal static inline int efi_get_runtime_map_size(void)
13906a2c20e7SVivek Goyal {
13916a2c20e7SVivek Goyal 	return 0;
13926a2c20e7SVivek Goyal }
13936a2c20e7SVivek Goyal 
13946a2c20e7SVivek Goyal static inline int efi_get_runtime_map_desc_size(void)
13956a2c20e7SVivek Goyal {
13966a2c20e7SVivek Goyal 	return 0;
13976a2c20e7SVivek Goyal }
13986a2c20e7SVivek Goyal 
13996a2c20e7SVivek Goyal static inline int efi_runtime_map_copy(void *buf, size_t bufsz)
14006a2c20e7SVivek Goyal {
14016a2c20e7SVivek Goyal 	return 0;
14026a2c20e7SVivek Goyal }
14036a2c20e7SVivek Goyal 
1404926172d4SDave Young #endif
1405926172d4SDave Young 
1406bd669475SArd Biesheuvel /* prototypes shared between arch specific and generic stub code */
1407bd669475SArd Biesheuvel 
1408bd669475SArd Biesheuvel #define pr_efi(sys_table, msg)     efi_printk(sys_table, "EFI stub: "msg)
1409bd669475SArd Biesheuvel #define pr_efi_err(sys_table, msg) efi_printk(sys_table, "EFI stub: ERROR: "msg)
1410bd669475SArd Biesheuvel 
1411bd669475SArd Biesheuvel void efi_printk(efi_system_table_t *sys_table_arg, char *str);
1412bd669475SArd Biesheuvel 
1413bd669475SArd Biesheuvel void efi_free(efi_system_table_t *sys_table_arg, unsigned long size,
1414bd669475SArd Biesheuvel 	      unsigned long addr);
1415bd669475SArd Biesheuvel 
1416bd669475SArd Biesheuvel char *efi_convert_cmdline(efi_system_table_t *sys_table_arg,
1417bd669475SArd Biesheuvel 			  efi_loaded_image_t *image, int *cmd_line_len);
1418bd669475SArd Biesheuvel 
1419bd669475SArd Biesheuvel efi_status_t efi_get_memory_map(efi_system_table_t *sys_table_arg,
1420bd669475SArd Biesheuvel 				efi_memory_desc_t **map,
1421bd669475SArd Biesheuvel 				unsigned long *map_size,
1422bd669475SArd Biesheuvel 				unsigned long *desc_size,
1423bd669475SArd Biesheuvel 				u32 *desc_ver,
1424bd669475SArd Biesheuvel 				unsigned long *key_ptr);
1425bd669475SArd Biesheuvel 
1426bd669475SArd Biesheuvel efi_status_t efi_low_alloc(efi_system_table_t *sys_table_arg,
1427bd669475SArd Biesheuvel 			   unsigned long size, unsigned long align,
1428bd669475SArd Biesheuvel 			   unsigned long *addr);
1429bd669475SArd Biesheuvel 
1430bd669475SArd Biesheuvel efi_status_t efi_high_alloc(efi_system_table_t *sys_table_arg,
1431bd669475SArd Biesheuvel 			    unsigned long size, unsigned long align,
1432bd669475SArd Biesheuvel 			    unsigned long *addr, unsigned long max);
1433bd669475SArd Biesheuvel 
1434bd669475SArd Biesheuvel efi_status_t efi_relocate_kernel(efi_system_table_t *sys_table_arg,
1435bd669475SArd Biesheuvel 				 unsigned long *image_addr,
1436bd669475SArd Biesheuvel 				 unsigned long image_size,
1437bd669475SArd Biesheuvel 				 unsigned long alloc_size,
1438bd669475SArd Biesheuvel 				 unsigned long preferred_addr,
1439bd669475SArd Biesheuvel 				 unsigned long alignment);
1440bd669475SArd Biesheuvel 
1441bd669475SArd Biesheuvel efi_status_t handle_cmdline_files(efi_system_table_t *sys_table_arg,
1442bd669475SArd Biesheuvel 				  efi_loaded_image_t *image,
1443bd669475SArd Biesheuvel 				  char *cmd_line, char *option_string,
1444bd669475SArd Biesheuvel 				  unsigned long max_addr,
1445bd669475SArd Biesheuvel 				  unsigned long *load_addr,
1446bd669475SArd Biesheuvel 				  unsigned long *load_size);
1447bd669475SArd Biesheuvel 
14485a17dae4SMatt Fleming efi_status_t efi_parse_options(char *cmdline);
14495a17dae4SMatt Fleming 
14502c23b73cSArd Biesheuvel efi_status_t efi_setup_gop(efi_system_table_t *sys_table_arg,
14512c23b73cSArd Biesheuvel 			   struct screen_info *si, efi_guid_t *proto,
14522c23b73cSArd Biesheuvel 			   unsigned long size);
14532c23b73cSArd Biesheuvel 
1454b2e0a54aSDave Young bool efi_runtime_disabled(void);
14551da177e4SLinus Torvalds #endif /* _LINUX_EFI_H */
1456