xref: /openbmc/linux/include/linux/efi.h (revision 87db73aebf55554fefaa3eade0a28f282a1511b8)
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>
241da177e4SLinus Torvalds 
251da177e4SLinus Torvalds #include <asm/page.h>
261da177e4SLinus Torvalds 
271da177e4SLinus Torvalds #define EFI_SUCCESS		0
281da177e4SLinus Torvalds #define EFI_LOAD_ERROR          ( 1 | (1UL << (BITS_PER_LONG-1)))
291da177e4SLinus Torvalds #define EFI_INVALID_PARAMETER	( 2 | (1UL << (BITS_PER_LONG-1)))
301da177e4SLinus Torvalds #define EFI_UNSUPPORTED		( 3 | (1UL << (BITS_PER_LONG-1)))
311da177e4SLinus Torvalds #define EFI_BAD_BUFFER_SIZE     ( 4 | (1UL << (BITS_PER_LONG-1)))
321da177e4SLinus Torvalds #define EFI_BUFFER_TOO_SMALL	( 5 | (1UL << (BITS_PER_LONG-1)))
335d9db883SMatthew Garrett #define EFI_NOT_READY		( 6 | (1UL << (BITS_PER_LONG-1)))
345d9db883SMatthew Garrett #define EFI_DEVICE_ERROR	( 7 | (1UL << (BITS_PER_LONG-1)))
355d9db883SMatthew Garrett #define EFI_WRITE_PROTECTED	( 8 | (1UL << (BITS_PER_LONG-1)))
365d9db883SMatthew Garrett #define EFI_OUT_OF_RESOURCES	( 9 | (1UL << (BITS_PER_LONG-1)))
371da177e4SLinus Torvalds #define EFI_NOT_FOUND		(14 | (1UL << (BITS_PER_LONG-1)))
385d9db883SMatthew Garrett #define EFI_SECURITY_VIOLATION	(26 | (1UL << (BITS_PER_LONG-1)))
391da177e4SLinus Torvalds 
401da177e4SLinus Torvalds typedef unsigned long efi_status_t;
411da177e4SLinus Torvalds typedef u8 efi_bool_t;
421da177e4SLinus Torvalds typedef u16 efi_char16_t;		/* UNICODE character */
43ed37ddffSRoy Franz typedef u64 efi_physical_addr_t;
44ed37ddffSRoy Franz typedef void *efi_handle_t;
451da177e4SLinus Torvalds 
461da177e4SLinus Torvalds 
471da177e4SLinus Torvalds typedef struct {
481da177e4SLinus Torvalds 	u8 b[16];
491da177e4SLinus Torvalds } efi_guid_t;
501da177e4SLinus Torvalds 
511da177e4SLinus Torvalds #define EFI_GUID(a,b,c,d0,d1,d2,d3,d4,d5,d6,d7) \
521da177e4SLinus Torvalds ((efi_guid_t) \
531da177e4SLinus Torvalds {{ (a) & 0xff, ((a) >> 8) & 0xff, ((a) >> 16) & 0xff, ((a) >> 24) & 0xff, \
541da177e4SLinus Torvalds   (b) & 0xff, ((b) >> 8) & 0xff, \
551da177e4SLinus Torvalds   (c) & 0xff, ((c) >> 8) & 0xff, \
561da177e4SLinus Torvalds   (d0), (d1), (d2), (d3), (d4), (d5), (d6), (d7) }})
571da177e4SLinus Torvalds 
581da177e4SLinus Torvalds /*
591da177e4SLinus Torvalds  * Generic EFI table header
601da177e4SLinus Torvalds  */
611da177e4SLinus Torvalds typedef	struct {
621da177e4SLinus Torvalds 	u64 signature;
631da177e4SLinus Torvalds 	u32 revision;
641da177e4SLinus Torvalds 	u32 headersize;
651da177e4SLinus Torvalds 	u32 crc32;
661da177e4SLinus Torvalds 	u32 reserved;
671da177e4SLinus Torvalds } efi_table_hdr_t;
681da177e4SLinus Torvalds 
691da177e4SLinus Torvalds /*
701da177e4SLinus Torvalds  * Memory map descriptor:
711da177e4SLinus Torvalds  */
721da177e4SLinus Torvalds 
731da177e4SLinus Torvalds /* Memory types: */
741da177e4SLinus Torvalds #define EFI_RESERVED_TYPE		 0
751da177e4SLinus Torvalds #define EFI_LOADER_CODE			 1
761da177e4SLinus Torvalds #define EFI_LOADER_DATA			 2
771da177e4SLinus Torvalds #define EFI_BOOT_SERVICES_CODE		 3
781da177e4SLinus Torvalds #define EFI_BOOT_SERVICES_DATA		 4
791da177e4SLinus Torvalds #define EFI_RUNTIME_SERVICES_CODE	 5
801da177e4SLinus Torvalds #define EFI_RUNTIME_SERVICES_DATA	 6
811da177e4SLinus Torvalds #define EFI_CONVENTIONAL_MEMORY		 7
821da177e4SLinus Torvalds #define EFI_UNUSABLE_MEMORY		 8
831da177e4SLinus Torvalds #define EFI_ACPI_RECLAIM_MEMORY		 9
841da177e4SLinus Torvalds #define EFI_ACPI_MEMORY_NVS		10
851da177e4SLinus Torvalds #define EFI_MEMORY_MAPPED_IO		11
861da177e4SLinus Torvalds #define EFI_MEMORY_MAPPED_IO_PORT_SPACE	12
871da177e4SLinus Torvalds #define EFI_PAL_CODE			13
88ad5fb870SDan Williams #define EFI_PERSISTENT_MEMORY		14
89ad5fb870SDan Williams #define EFI_MAX_MEMORY_TYPE		15
901da177e4SLinus Torvalds 
911da177e4SLinus Torvalds /* Attribute values: */
921da177e4SLinus Torvalds #define EFI_MEMORY_UC		((u64)0x0000000000000001ULL)	/* uncached */
931da177e4SLinus Torvalds #define EFI_MEMORY_WC		((u64)0x0000000000000002ULL)	/* write-coalescing */
941da177e4SLinus Torvalds #define EFI_MEMORY_WT		((u64)0x0000000000000004ULL)	/* write-through */
951da177e4SLinus Torvalds #define EFI_MEMORY_WB		((u64)0x0000000000000008ULL)	/* write-back */
969c97e0bdSLaszlo Ersek #define EFI_MEMORY_UCE		((u64)0x0000000000000010ULL)	/* uncached, exported */
971da177e4SLinus Torvalds #define EFI_MEMORY_WP		((u64)0x0000000000001000ULL)	/* write-protect */
981da177e4SLinus Torvalds #define EFI_MEMORY_RP		((u64)0x0000000000002000ULL)	/* read-protect */
991da177e4SLinus Torvalds #define EFI_MEMORY_XP		((u64)0x0000000000004000ULL)	/* execute-protect */
100b05b9f5fSTony Luck #define EFI_MEMORY_MORE_RELIABLE \
101b05b9f5fSTony Luck 				((u64)0x0000000000010000ULL)	/* higher reliability */
102*87db73aeSArd Biesheuvel #define EFI_MEMORY_RO		((u64)0x0000000000020000ULL)	/* read-only */
1031da177e4SLinus Torvalds #define EFI_MEMORY_RUNTIME	((u64)0x8000000000000000ULL)	/* range requires runtime mapping */
1041da177e4SLinus Torvalds #define EFI_MEMORY_DESCRIPTOR_VERSION	1
1051da177e4SLinus Torvalds 
1061da177e4SLinus Torvalds #define EFI_PAGE_SHIFT		12
107ed37ddffSRoy Franz #define EFI_PAGE_SIZE		(1UL << EFI_PAGE_SHIFT)
1081da177e4SLinus Torvalds 
1091da177e4SLinus Torvalds typedef struct {
1101da177e4SLinus Torvalds 	u32 type;
1111da177e4SLinus Torvalds 	u32 pad;
1121da177e4SLinus Torvalds 	u64 phys_addr;
1131da177e4SLinus Torvalds 	u64 virt_addr;
1141da177e4SLinus Torvalds 	u64 num_pages;
1151da177e4SLinus Torvalds 	u64 attribute;
1161da177e4SLinus Torvalds } efi_memory_desc_t;
1171da177e4SLinus Torvalds 
1183b370237SMatthew Garrett typedef struct {
1193b370237SMatthew Garrett 	efi_guid_t guid;
1203b370237SMatthew Garrett 	u32 headersize;
1213b370237SMatthew Garrett 	u32 flags;
1223b370237SMatthew Garrett 	u32 imagesize;
1233b370237SMatthew Garrett } efi_capsule_header_t;
1243b370237SMatthew Garrett 
125bb05e4baSMatt Fleming /*
126bb05e4baSMatt Fleming  * Allocation types for calls to boottime->allocate_pages.
127bb05e4baSMatt Fleming  */
128bb05e4baSMatt Fleming #define EFI_ALLOCATE_ANY_PAGES		0
129bb05e4baSMatt Fleming #define EFI_ALLOCATE_MAX_ADDRESS	1
130bb05e4baSMatt Fleming #define EFI_ALLOCATE_ADDRESS		2
131bb05e4baSMatt Fleming #define EFI_MAX_ALLOCATE_TYPE		3
132bb05e4baSMatt Fleming 
133e088a4adSMatthew Wilcox typedef int (*efi_freemem_callback_t) (u64 start, u64 end, void *arg);
1341da177e4SLinus Torvalds 
1351da177e4SLinus Torvalds /*
1361da177e4SLinus Torvalds  * Types and defines for Time Services
1371da177e4SLinus Torvalds  */
1381da177e4SLinus Torvalds #define EFI_TIME_ADJUST_DAYLIGHT 0x1
1391da177e4SLinus Torvalds #define EFI_TIME_IN_DAYLIGHT     0x2
1401da177e4SLinus Torvalds #define EFI_UNSPECIFIED_TIMEZONE 0x07ff
1411da177e4SLinus Torvalds 
1421da177e4SLinus Torvalds typedef struct {
1431da177e4SLinus Torvalds 	u16 year;
1441da177e4SLinus Torvalds 	u8 month;
1451da177e4SLinus Torvalds 	u8 day;
1461da177e4SLinus Torvalds 	u8 hour;
1471da177e4SLinus Torvalds 	u8 minute;
1481da177e4SLinus Torvalds 	u8 second;
1491da177e4SLinus Torvalds 	u8 pad1;
1501da177e4SLinus Torvalds 	u32 nanosecond;
1511da177e4SLinus Torvalds 	s16 timezone;
1521da177e4SLinus Torvalds 	u8 daylight;
1531da177e4SLinus Torvalds 	u8 pad2;
1541da177e4SLinus Torvalds } efi_time_t;
1551da177e4SLinus Torvalds 
1561da177e4SLinus Torvalds typedef struct {
1571da177e4SLinus Torvalds 	u32 resolution;
1581da177e4SLinus Torvalds 	u32 accuracy;
1591da177e4SLinus Torvalds 	u8 sets_to_zero;
1601da177e4SLinus Torvalds } efi_time_cap_t;
1611da177e4SLinus Torvalds 
162677703ceSMatt Fleming typedef struct {
163677703ceSMatt Fleming 	efi_table_hdr_t hdr;
164677703ceSMatt Fleming 	u32 raise_tpl;
165677703ceSMatt Fleming 	u32 restore_tpl;
166677703ceSMatt Fleming 	u32 allocate_pages;
167677703ceSMatt Fleming 	u32 free_pages;
168677703ceSMatt Fleming 	u32 get_memory_map;
169677703ceSMatt Fleming 	u32 allocate_pool;
170677703ceSMatt Fleming 	u32 free_pool;
171677703ceSMatt Fleming 	u32 create_event;
172677703ceSMatt Fleming 	u32 set_timer;
173677703ceSMatt Fleming 	u32 wait_for_event;
174677703ceSMatt Fleming 	u32 signal_event;
175677703ceSMatt Fleming 	u32 close_event;
176677703ceSMatt Fleming 	u32 check_event;
177677703ceSMatt Fleming 	u32 install_protocol_interface;
178677703ceSMatt Fleming 	u32 reinstall_protocol_interface;
179677703ceSMatt Fleming 	u32 uninstall_protocol_interface;
180677703ceSMatt Fleming 	u32 handle_protocol;
181677703ceSMatt Fleming 	u32 __reserved;
182677703ceSMatt Fleming 	u32 register_protocol_notify;
183677703ceSMatt Fleming 	u32 locate_handle;
184677703ceSMatt Fleming 	u32 locate_device_path;
185677703ceSMatt Fleming 	u32 install_configuration_table;
186677703ceSMatt Fleming 	u32 load_image;
187677703ceSMatt Fleming 	u32 start_image;
188677703ceSMatt Fleming 	u32 exit;
189677703ceSMatt Fleming 	u32 unload_image;
190677703ceSMatt Fleming 	u32 exit_boot_services;
191677703ceSMatt Fleming 	u32 get_next_monotonic_count;
192677703ceSMatt Fleming 	u32 stall;
193677703ceSMatt Fleming 	u32 set_watchdog_timer;
194677703ceSMatt Fleming 	u32 connect_controller;
195677703ceSMatt Fleming 	u32 disconnect_controller;
196677703ceSMatt Fleming 	u32 open_protocol;
197677703ceSMatt Fleming 	u32 close_protocol;
198677703ceSMatt Fleming 	u32 open_protocol_information;
199677703ceSMatt Fleming 	u32 protocols_per_handle;
200677703ceSMatt Fleming 	u32 locate_handle_buffer;
201677703ceSMatt Fleming 	u32 locate_protocol;
202677703ceSMatt Fleming 	u32 install_multiple_protocol_interfaces;
203677703ceSMatt Fleming 	u32 uninstall_multiple_protocol_interfaces;
204677703ceSMatt Fleming 	u32 calculate_crc32;
205677703ceSMatt Fleming 	u32 copy_mem;
206677703ceSMatt Fleming 	u32 set_mem;
207677703ceSMatt Fleming 	u32 create_event_ex;
208677703ceSMatt Fleming } __packed efi_boot_services_32_t;
209677703ceSMatt Fleming 
210677703ceSMatt Fleming typedef struct {
211677703ceSMatt Fleming 	efi_table_hdr_t hdr;
212677703ceSMatt Fleming 	u64 raise_tpl;
213677703ceSMatt Fleming 	u64 restore_tpl;
214677703ceSMatt Fleming 	u64 allocate_pages;
215677703ceSMatt Fleming 	u64 free_pages;
216677703ceSMatt Fleming 	u64 get_memory_map;
217677703ceSMatt Fleming 	u64 allocate_pool;
218677703ceSMatt Fleming 	u64 free_pool;
219677703ceSMatt Fleming 	u64 create_event;
220677703ceSMatt Fleming 	u64 set_timer;
221677703ceSMatt Fleming 	u64 wait_for_event;
222677703ceSMatt Fleming 	u64 signal_event;
223677703ceSMatt Fleming 	u64 close_event;
224677703ceSMatt Fleming 	u64 check_event;
225677703ceSMatt Fleming 	u64 install_protocol_interface;
226677703ceSMatt Fleming 	u64 reinstall_protocol_interface;
227677703ceSMatt Fleming 	u64 uninstall_protocol_interface;
228677703ceSMatt Fleming 	u64 handle_protocol;
229677703ceSMatt Fleming 	u64 __reserved;
230677703ceSMatt Fleming 	u64 register_protocol_notify;
231677703ceSMatt Fleming 	u64 locate_handle;
232677703ceSMatt Fleming 	u64 locate_device_path;
233677703ceSMatt Fleming 	u64 install_configuration_table;
234677703ceSMatt Fleming 	u64 load_image;
235677703ceSMatt Fleming 	u64 start_image;
236677703ceSMatt Fleming 	u64 exit;
237677703ceSMatt Fleming 	u64 unload_image;
238677703ceSMatt Fleming 	u64 exit_boot_services;
239677703ceSMatt Fleming 	u64 get_next_monotonic_count;
240677703ceSMatt Fleming 	u64 stall;
241677703ceSMatt Fleming 	u64 set_watchdog_timer;
242677703ceSMatt Fleming 	u64 connect_controller;
243677703ceSMatt Fleming 	u64 disconnect_controller;
244677703ceSMatt Fleming 	u64 open_protocol;
245677703ceSMatt Fleming 	u64 close_protocol;
246677703ceSMatt Fleming 	u64 open_protocol_information;
247677703ceSMatt Fleming 	u64 protocols_per_handle;
248677703ceSMatt Fleming 	u64 locate_handle_buffer;
249677703ceSMatt Fleming 	u64 locate_protocol;
250677703ceSMatt Fleming 	u64 install_multiple_protocol_interfaces;
251677703ceSMatt Fleming 	u64 uninstall_multiple_protocol_interfaces;
252677703ceSMatt Fleming 	u64 calculate_crc32;
253677703ceSMatt Fleming 	u64 copy_mem;
254677703ceSMatt Fleming 	u64 set_mem;
255677703ceSMatt Fleming 	u64 create_event_ex;
256677703ceSMatt Fleming } __packed efi_boot_services_64_t;
257677703ceSMatt Fleming 
2581da177e4SLinus Torvalds /*
259f30ca6baSMatt Fleming  * EFI Boot Services table
260f30ca6baSMatt Fleming  */
261f30ca6baSMatt Fleming typedef struct {
262f30ca6baSMatt Fleming 	efi_table_hdr_t hdr;
263f30ca6baSMatt Fleming 	void *raise_tpl;
264f30ca6baSMatt Fleming 	void *restore_tpl;
265ed37ddffSRoy Franz 	efi_status_t (*allocate_pages)(int, int, unsigned long,
266ed37ddffSRoy Franz 				       efi_physical_addr_t *);
267ed37ddffSRoy Franz 	efi_status_t (*free_pages)(efi_physical_addr_t, unsigned long);
268ed37ddffSRoy Franz 	efi_status_t (*get_memory_map)(unsigned long *, void *, unsigned long *,
269ed37ddffSRoy Franz 				       unsigned long *, u32 *);
270ed37ddffSRoy Franz 	efi_status_t (*allocate_pool)(int, unsigned long, void **);
271ed37ddffSRoy Franz 	efi_status_t (*free_pool)(void *);
272f30ca6baSMatt Fleming 	void *create_event;
273f30ca6baSMatt Fleming 	void *set_timer;
274f30ca6baSMatt Fleming 	void *wait_for_event;
275f30ca6baSMatt Fleming 	void *signal_event;
276f30ca6baSMatt Fleming 	void *close_event;
277f30ca6baSMatt Fleming 	void *check_event;
278f30ca6baSMatt Fleming 	void *install_protocol_interface;
279f30ca6baSMatt Fleming 	void *reinstall_protocol_interface;
280f30ca6baSMatt Fleming 	void *uninstall_protocol_interface;
281ed37ddffSRoy Franz 	efi_status_t (*handle_protocol)(efi_handle_t, efi_guid_t *, void **);
282f30ca6baSMatt Fleming 	void *__reserved;
283f30ca6baSMatt Fleming 	void *register_protocol_notify;
284f30ca6baSMatt Fleming 	void *locate_handle;
285f30ca6baSMatt Fleming 	void *locate_device_path;
286f30ca6baSMatt Fleming 	void *install_configuration_table;
287f30ca6baSMatt Fleming 	void *load_image;
288f30ca6baSMatt Fleming 	void *start_image;
289f30ca6baSMatt Fleming 	void *exit;
290f30ca6baSMatt Fleming 	void *unload_image;
291ed37ddffSRoy Franz 	efi_status_t (*exit_boot_services)(efi_handle_t, unsigned long);
292f30ca6baSMatt Fleming 	void *get_next_monotonic_count;
293f30ca6baSMatt Fleming 	void *stall;
294f30ca6baSMatt Fleming 	void *set_watchdog_timer;
295f30ca6baSMatt Fleming 	void *connect_controller;
296f30ca6baSMatt Fleming 	void *disconnect_controller;
297f30ca6baSMatt Fleming 	void *open_protocol;
298f30ca6baSMatt Fleming 	void *close_protocol;
299f30ca6baSMatt Fleming 	void *open_protocol_information;
300f30ca6baSMatt Fleming 	void *protocols_per_handle;
301f30ca6baSMatt Fleming 	void *locate_handle_buffer;
302f30ca6baSMatt Fleming 	void *locate_protocol;
303f30ca6baSMatt Fleming 	void *install_multiple_protocol_interfaces;
304f30ca6baSMatt Fleming 	void *uninstall_multiple_protocol_interfaces;
305f30ca6baSMatt Fleming 	void *calculate_crc32;
306f30ca6baSMatt Fleming 	void *copy_mem;
307f30ca6baSMatt Fleming 	void *set_mem;
308f30ca6baSMatt Fleming 	void *create_event_ex;
309f30ca6baSMatt Fleming } efi_boot_services_t;
310f30ca6baSMatt Fleming 
311dd5fc854SMatthew Garrett typedef enum {
312dd5fc854SMatthew Garrett 	EfiPciIoWidthUint8,
313dd5fc854SMatthew Garrett 	EfiPciIoWidthUint16,
314dd5fc854SMatthew Garrett 	EfiPciIoWidthUint32,
315dd5fc854SMatthew Garrett 	EfiPciIoWidthUint64,
316dd5fc854SMatthew Garrett 	EfiPciIoWidthFifoUint8,
317dd5fc854SMatthew Garrett 	EfiPciIoWidthFifoUint16,
318dd5fc854SMatthew Garrett 	EfiPciIoWidthFifoUint32,
319dd5fc854SMatthew Garrett 	EfiPciIoWidthFifoUint64,
320dd5fc854SMatthew Garrett 	EfiPciIoWidthFillUint8,
321dd5fc854SMatthew Garrett 	EfiPciIoWidthFillUint16,
322dd5fc854SMatthew Garrett 	EfiPciIoWidthFillUint32,
323dd5fc854SMatthew Garrett 	EfiPciIoWidthFillUint64,
324dd5fc854SMatthew Garrett 	EfiPciIoWidthMaximum
325dd5fc854SMatthew Garrett } EFI_PCI_IO_PROTOCOL_WIDTH;
326dd5fc854SMatthew Garrett 
327dd5fc854SMatthew Garrett typedef enum {
328dd5fc854SMatthew Garrett 	EfiPciIoAttributeOperationGet,
329dd5fc854SMatthew Garrett 	EfiPciIoAttributeOperationSet,
330dd5fc854SMatthew Garrett 	EfiPciIoAttributeOperationEnable,
331dd5fc854SMatthew Garrett 	EfiPciIoAttributeOperationDisable,
332dd5fc854SMatthew Garrett 	EfiPciIoAttributeOperationSupported,
333dd5fc854SMatthew Garrett     EfiPciIoAttributeOperationMaximum
334dd5fc854SMatthew Garrett } EFI_PCI_IO_PROTOCOL_ATTRIBUTE_OPERATION;
335dd5fc854SMatthew Garrett 
336677703ceSMatt Fleming typedef struct {
337677703ceSMatt Fleming 	u32 read;
338677703ceSMatt Fleming 	u32 write;
339677703ceSMatt Fleming } efi_pci_io_protocol_access_32_t;
340677703ceSMatt Fleming 
341677703ceSMatt Fleming typedef struct {
342677703ceSMatt Fleming 	u64 read;
343677703ceSMatt Fleming 	u64 write;
344677703ceSMatt Fleming } efi_pci_io_protocol_access_64_t;
345dd5fc854SMatthew Garrett 
346dd5fc854SMatthew Garrett typedef struct {
347dd5fc854SMatthew Garrett 	void *read;
348dd5fc854SMatthew Garrett 	void *write;
349dd5fc854SMatthew Garrett } efi_pci_io_protocol_access_t;
350dd5fc854SMatthew Garrett 
351dd5fc854SMatthew Garrett typedef struct {
352677703ceSMatt Fleming 	u32 poll_mem;
353677703ceSMatt Fleming 	u32 poll_io;
354677703ceSMatt Fleming 	efi_pci_io_protocol_access_32_t mem;
355677703ceSMatt Fleming 	efi_pci_io_protocol_access_32_t io;
356677703ceSMatt Fleming 	efi_pci_io_protocol_access_32_t pci;
357677703ceSMatt Fleming 	u32 copy_mem;
358677703ceSMatt Fleming 	u32 map;
359677703ceSMatt Fleming 	u32 unmap;
360677703ceSMatt Fleming 	u32 allocate_buffer;
361677703ceSMatt Fleming 	u32 free_buffer;
362677703ceSMatt Fleming 	u32 flush;
363677703ceSMatt Fleming 	u32 get_location;
364677703ceSMatt Fleming 	u32 attributes;
365677703ceSMatt Fleming 	u32 get_bar_attributes;
366677703ceSMatt Fleming 	u32 set_bar_attributes;
367677703ceSMatt Fleming 	uint64_t romsize;
368677703ceSMatt Fleming 	void *romimage;
369677703ceSMatt Fleming } efi_pci_io_protocol_32;
370677703ceSMatt Fleming 
371677703ceSMatt Fleming typedef struct {
372677703ceSMatt Fleming 	u64 poll_mem;
373677703ceSMatt Fleming 	u64 poll_io;
374677703ceSMatt Fleming 	efi_pci_io_protocol_access_64_t mem;
375677703ceSMatt Fleming 	efi_pci_io_protocol_access_64_t io;
376677703ceSMatt Fleming 	efi_pci_io_protocol_access_64_t pci;
377677703ceSMatt Fleming 	u64 copy_mem;
378677703ceSMatt Fleming 	u64 map;
379677703ceSMatt Fleming 	u64 unmap;
380677703ceSMatt Fleming 	u64 allocate_buffer;
381677703ceSMatt Fleming 	u64 free_buffer;
382677703ceSMatt Fleming 	u64 flush;
383677703ceSMatt Fleming 	u64 get_location;
384677703ceSMatt Fleming 	u64 attributes;
385677703ceSMatt Fleming 	u64 get_bar_attributes;
386677703ceSMatt Fleming 	u64 set_bar_attributes;
387677703ceSMatt Fleming 	uint64_t romsize;
388677703ceSMatt Fleming 	void *romimage;
389677703ceSMatt Fleming } efi_pci_io_protocol_64;
390677703ceSMatt Fleming 
391677703ceSMatt Fleming typedef struct {
392dd5fc854SMatthew Garrett 	void *poll_mem;
393dd5fc854SMatthew Garrett 	void *poll_io;
394dd5fc854SMatthew Garrett 	efi_pci_io_protocol_access_t mem;
395dd5fc854SMatthew Garrett 	efi_pci_io_protocol_access_t io;
396dd5fc854SMatthew Garrett 	efi_pci_io_protocol_access_t pci;
397dd5fc854SMatthew Garrett 	void *copy_mem;
398dd5fc854SMatthew Garrett 	void *map;
399dd5fc854SMatthew Garrett 	void *unmap;
400dd5fc854SMatthew Garrett 	void *allocate_buffer;
401dd5fc854SMatthew Garrett 	void *free_buffer;
402dd5fc854SMatthew Garrett 	void *flush;
403dd5fc854SMatthew Garrett 	void *get_location;
404dd5fc854SMatthew Garrett 	void *attributes;
405dd5fc854SMatthew Garrett 	void *get_bar_attributes;
406dd5fc854SMatthew Garrett 	void *set_bar_attributes;
407dd5fc854SMatthew Garrett 	uint64_t romsize;
408dd5fc854SMatthew Garrett 	void *romimage;
409dd5fc854SMatthew Garrett } efi_pci_io_protocol;
410dd5fc854SMatthew Garrett 
411dd5fc854SMatthew Garrett #define EFI_PCI_IO_ATTRIBUTE_ISA_MOTHERBOARD_IO 0x0001
412dd5fc854SMatthew Garrett #define EFI_PCI_IO_ATTRIBUTE_ISA_IO 0x0002
413dd5fc854SMatthew Garrett #define EFI_PCI_IO_ATTRIBUTE_VGA_PALETTE_IO 0x0004
414dd5fc854SMatthew Garrett #define EFI_PCI_IO_ATTRIBUTE_VGA_MEMORY 0x0008
415dd5fc854SMatthew Garrett #define EFI_PCI_IO_ATTRIBUTE_VGA_IO 0x0010
416dd5fc854SMatthew Garrett #define EFI_PCI_IO_ATTRIBUTE_IDE_PRIMARY_IO 0x0020
417dd5fc854SMatthew Garrett #define EFI_PCI_IO_ATTRIBUTE_IDE_SECONDARY_IO 0x0040
418dd5fc854SMatthew Garrett #define EFI_PCI_IO_ATTRIBUTE_MEMORY_WRITE_COMBINE 0x0080
419dd5fc854SMatthew Garrett #define EFI_PCI_IO_ATTRIBUTE_IO 0x0100
420dd5fc854SMatthew Garrett #define EFI_PCI_IO_ATTRIBUTE_MEMORY 0x0200
421dd5fc854SMatthew Garrett #define EFI_PCI_IO_ATTRIBUTE_BUS_MASTER 0x0400
422dd5fc854SMatthew Garrett #define EFI_PCI_IO_ATTRIBUTE_MEMORY_CACHED 0x0800
423dd5fc854SMatthew Garrett #define EFI_PCI_IO_ATTRIBUTE_MEMORY_DISABLE 0x1000
424dd5fc854SMatthew Garrett #define EFI_PCI_IO_ATTRIBUTE_EMBEDDED_DEVICE 0x2000
425dd5fc854SMatthew Garrett #define EFI_PCI_IO_ATTRIBUTE_EMBEDDED_ROM 0x4000
426dd5fc854SMatthew Garrett #define EFI_PCI_IO_ATTRIBUTE_DUAL_ADDRESS_CYCLE 0x8000
427dd5fc854SMatthew Garrett #define EFI_PCI_IO_ATTRIBUTE_ISA_IO_16 0x10000
428dd5fc854SMatthew Garrett #define EFI_PCI_IO_ATTRIBUTE_VGA_PALETTE_IO_16 0x20000
429dd5fc854SMatthew Garrett #define EFI_PCI_IO_ATTRIBUTE_VGA_IO_16 0x40000
430dd5fc854SMatthew Garrett 
431f30ca6baSMatt Fleming /*
4321da177e4SLinus Torvalds  * Types and defines for EFI ResetSystem
4331da177e4SLinus Torvalds  */
4341da177e4SLinus Torvalds #define EFI_RESET_COLD 0
4351da177e4SLinus Torvalds #define EFI_RESET_WARM 1
4361da177e4SLinus Torvalds #define EFI_RESET_SHUTDOWN 2
4371da177e4SLinus Torvalds 
4381da177e4SLinus Torvalds /*
4391da177e4SLinus Torvalds  * EFI Runtime Services table
4401da177e4SLinus Torvalds  */
4411da177e4SLinus Torvalds #define EFI_RUNTIME_SERVICES_SIGNATURE ((u64)0x5652453544e5552ULL)
4421da177e4SLinus Torvalds #define EFI_RUNTIME_SERVICES_REVISION  0x00010000
4431da177e4SLinus Torvalds 
4441da177e4SLinus Torvalds typedef struct {
4451da177e4SLinus Torvalds 	efi_table_hdr_t hdr;
446677703ceSMatt Fleming 	u32 get_time;
447677703ceSMatt Fleming 	u32 set_time;
448677703ceSMatt Fleming 	u32 get_wakeup_time;
449677703ceSMatt Fleming 	u32 set_wakeup_time;
450677703ceSMatt Fleming 	u32 set_virtual_address_map;
451677703ceSMatt Fleming 	u32 convert_pointer;
452677703ceSMatt Fleming 	u32 get_variable;
453677703ceSMatt Fleming 	u32 get_next_variable;
454677703ceSMatt Fleming 	u32 set_variable;
455677703ceSMatt Fleming 	u32 get_next_high_mono_count;
456677703ceSMatt Fleming 	u32 reset_system;
457677703ceSMatt Fleming 	u32 update_capsule;
458677703ceSMatt Fleming 	u32 query_capsule_caps;
459677703ceSMatt Fleming 	u32 query_variable_info;
460677703ceSMatt Fleming } efi_runtime_services_32_t;
461677703ceSMatt Fleming 
462677703ceSMatt Fleming typedef struct {
463677703ceSMatt Fleming 	efi_table_hdr_t hdr;
464677703ceSMatt Fleming 	u64 get_time;
465677703ceSMatt Fleming 	u64 set_time;
466677703ceSMatt Fleming 	u64 get_wakeup_time;
467677703ceSMatt Fleming 	u64 set_wakeup_time;
468677703ceSMatt Fleming 	u64 set_virtual_address_map;
469677703ceSMatt Fleming 	u64 convert_pointer;
470677703ceSMatt Fleming 	u64 get_variable;
471677703ceSMatt Fleming 	u64 get_next_variable;
472677703ceSMatt Fleming 	u64 set_variable;
473677703ceSMatt Fleming 	u64 get_next_high_mono_count;
474677703ceSMatt Fleming 	u64 reset_system;
475677703ceSMatt Fleming 	u64 update_capsule;
476677703ceSMatt Fleming 	u64 query_capsule_caps;
477677703ceSMatt Fleming 	u64 query_variable_info;
478677703ceSMatt Fleming } efi_runtime_services_64_t;
479677703ceSMatt Fleming 
480677703ceSMatt Fleming typedef struct {
481677703ceSMatt Fleming 	efi_table_hdr_t hdr;
48243ab0476SBorislav Petkov 	void *get_time;
48343ab0476SBorislav Petkov 	void *set_time;
48443ab0476SBorislav Petkov 	void *get_wakeup_time;
48543ab0476SBorislav Petkov 	void *set_wakeup_time;
48643ab0476SBorislav Petkov 	void *set_virtual_address_map;
48743ab0476SBorislav Petkov 	void *convert_pointer;
48843ab0476SBorislav Petkov 	void *get_variable;
48943ab0476SBorislav Petkov 	void *get_next_variable;
49043ab0476SBorislav Petkov 	void *set_variable;
49143ab0476SBorislav Petkov 	void *get_next_high_mono_count;
49243ab0476SBorislav Petkov 	void *reset_system;
49343ab0476SBorislav Petkov 	void *update_capsule;
49443ab0476SBorislav Petkov 	void *query_capsule_caps;
49543ab0476SBorislav Petkov 	void *query_variable_info;
4961da177e4SLinus Torvalds } efi_runtime_services_t;
4971da177e4SLinus Torvalds 
4981da177e4SLinus Torvalds typedef efi_status_t efi_get_time_t (efi_time_t *tm, efi_time_cap_t *tc);
4991da177e4SLinus Torvalds typedef efi_status_t efi_set_time_t (efi_time_t *tm);
5001da177e4SLinus Torvalds typedef efi_status_t efi_get_wakeup_time_t (efi_bool_t *enabled, efi_bool_t *pending,
5011da177e4SLinus Torvalds 					    efi_time_t *tm);
5021da177e4SLinus Torvalds typedef efi_status_t efi_set_wakeup_time_t (efi_bool_t enabled, efi_time_t *tm);
5031da177e4SLinus Torvalds typedef efi_status_t efi_get_variable_t (efi_char16_t *name, efi_guid_t *vendor, u32 *attr,
5041da177e4SLinus Torvalds 					 unsigned long *data_size, void *data);
5051da177e4SLinus Torvalds typedef efi_status_t efi_get_next_variable_t (unsigned long *name_size, efi_char16_t *name,
5061da177e4SLinus Torvalds 					      efi_guid_t *vendor);
5071da177e4SLinus Torvalds typedef efi_status_t efi_set_variable_t (efi_char16_t *name, efi_guid_t *vendor,
508f7a2d73fSMatthew Garrett 					 u32 attr, unsigned long data_size,
5091da177e4SLinus Torvalds 					 void *data);
5106d80dba1SMatt Fleming typedef efi_status_t
5116d80dba1SMatt Fleming efi_set_variable_nonblocking_t(efi_char16_t *name, efi_guid_t *vendor,
5126d80dba1SMatt Fleming 			       u32 attr, unsigned long data_size, void *data);
5136d80dba1SMatt Fleming 
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);
532a6e4d5a0SMatt Fleming typedef efi_status_t efi_query_variable_store_t(u32 attributes, unsigned long size);
5331da177e4SLinus Torvalds 
534022ee6c5SArd Biesheuvel void efi_native_runtime_setup(void);
535022ee6c5SArd Biesheuvel 
5361da177e4SLinus Torvalds /*
5371da177e4SLinus Torvalds  *  EFI Configuration Table and GUID definitions
5381da177e4SLinus Torvalds  */
5391da177e4SLinus Torvalds #define NULL_GUID \
5401da177e4SLinus Torvalds     EFI_GUID(  0x00000000, 0x0000, 0x0000, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 )
5411da177e4SLinus Torvalds 
5421da177e4SLinus Torvalds #define MPS_TABLE_GUID    \
5431da177e4SLinus Torvalds     EFI_GUID(  0xeb9d2d2f, 0x2d88, 0x11d3, 0x9a, 0x16, 0x0, 0x90, 0x27, 0x3f, 0xc1, 0x4d )
5441da177e4SLinus Torvalds 
5451da177e4SLinus Torvalds #define ACPI_TABLE_GUID    \
5461da177e4SLinus Torvalds     EFI_GUID(  0xeb9d2d30, 0x2d88, 0x11d3, 0x9a, 0x16, 0x0, 0x90, 0x27, 0x3f, 0xc1, 0x4d )
5471da177e4SLinus Torvalds 
5481da177e4SLinus Torvalds #define ACPI_20_TABLE_GUID    \
5491da177e4SLinus Torvalds     EFI_GUID(  0x8868e871, 0xe4f1, 0x11d3, 0xbc, 0x22, 0x0, 0x80, 0xc7, 0x3c, 0x88, 0x81 )
5501da177e4SLinus Torvalds 
5511da177e4SLinus Torvalds #define SMBIOS_TABLE_GUID    \
5521da177e4SLinus Torvalds     EFI_GUID(  0xeb9d2d31, 0x2d88, 0x11d3, 0x9a, 0x16, 0x0, 0x90, 0x27, 0x3f, 0xc1, 0x4d )
5531da177e4SLinus Torvalds 
554e1ccbbc9SArd Biesheuvel #define SMBIOS3_TABLE_GUID    \
555e1ccbbc9SArd Biesheuvel     EFI_GUID(  0xf2fd1544, 0x9794, 0x4a2c, 0x99, 0x2e, 0xe5, 0xbb, 0xcf, 0x20, 0xe3, 0x94 )
556e1ccbbc9SArd Biesheuvel 
5571da177e4SLinus Torvalds #define SAL_SYSTEM_TABLE_GUID    \
5581da177e4SLinus Torvalds     EFI_GUID(  0xeb9d2d32, 0x2d88, 0x11d3, 0x9a, 0x16, 0x0, 0x90, 0x27, 0x3f, 0xc1, 0x4d )
5591da177e4SLinus Torvalds 
5601da177e4SLinus Torvalds #define HCDP_TABLE_GUID	\
5611da177e4SLinus Torvalds     EFI_GUID(  0xf951938d, 0x620b, 0x42ef, 0x82, 0x79, 0xa8, 0x4b, 0x79, 0x61, 0x78, 0x98 )
5621da177e4SLinus Torvalds 
5631da177e4SLinus Torvalds #define UGA_IO_PROTOCOL_GUID \
5641da177e4SLinus Torvalds     EFI_GUID(  0x61a4d49e, 0x6f68, 0x4f1b, 0xb9, 0x22, 0xa8, 0x6e, 0xed, 0xb, 0x7, 0xa2 )
5651da177e4SLinus Torvalds 
5661da177e4SLinus Torvalds #define EFI_GLOBAL_VARIABLE_GUID \
5671da177e4SLinus Torvalds     EFI_GUID(  0x8be4df61, 0x93ca, 0x11d2, 0xaa, 0x0d, 0x00, 0xe0, 0x98, 0x03, 0x2b, 0x8c )
5681da177e4SLinus Torvalds 
569a50f70b1SRuss Anderson #define UV_SYSTEM_TABLE_GUID \
570a50f70b1SRuss Anderson     EFI_GUID(  0x3b13a7d4, 0x633e, 0x11dd, 0x93, 0xec, 0xda, 0x25, 0x56, 0xd8, 0x95, 0x93 )
571a50f70b1SRuss Anderson 
5725ee9c198SMatthew Garrett #define LINUX_EFI_CRASH_GUID \
5735ee9c198SMatthew Garrett     EFI_GUID(  0xcfc8fc79, 0xbe2e, 0x4ddc, 0x97, 0xf0, 0x9f, 0x98, 0xbf, 0xe2, 0x98, 0xa0 )
5745ee9c198SMatthew Garrett 
5758e84f345SMatt Fleming #define LOADED_IMAGE_PROTOCOL_GUID \
5768e84f345SMatt Fleming     EFI_GUID(  0x5b1b31a1, 0x9562, 0x11d2, 0x8e, 0x3f, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b )
5778e84f345SMatt Fleming 
5780f7c5d47SMatt Fleming #define EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID \
5790f7c5d47SMatt Fleming     EFI_GUID(  0x9042a9de, 0x23dc, 0x4a38, 0x96, 0xfb, 0x7a, 0xde, 0xd0, 0x80, 0x51, 0x6a )
5800f7c5d47SMatt Fleming 
5810f7c5d47SMatt Fleming #define EFI_UGA_PROTOCOL_GUID \
5820f7c5d47SMatt Fleming     EFI_GUID(  0x982c298b, 0xf4fa, 0x41cb, 0xb8, 0x38, 0x77, 0xaa, 0x68, 0x8f, 0xb8, 0x39 )
5830f7c5d47SMatt Fleming 
5840f7c5d47SMatt Fleming #define EFI_PCI_IO_PROTOCOL_GUID \
5850f7c5d47SMatt Fleming     EFI_GUID(  0x4cf5b200, 0x68b8, 0x4ca5, 0x9e, 0xec, 0xb2, 0x3e, 0x3f, 0x50, 0x2, 0x9a )
5860f7c5d47SMatt Fleming 
58755839d51SMatt Fleming #define EFI_FILE_INFO_ID \
58855839d51SMatt Fleming     EFI_GUID(  0x9576e92, 0x6d3f, 0x11d2, 0x8e, 0x39, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b )
58955839d51SMatt Fleming 
5900bb54905SPeter Jones #define EFI_SYSTEM_RESOURCE_TABLE_GUID \
5910bb54905SPeter Jones     EFI_GUID(  0xb122a263, 0x3661, 0x4f68, 0x99, 0x29, 0x78, 0xf8, 0xb0, 0xd6, 0x21, 0x80 )
5920bb54905SPeter Jones 
59355839d51SMatt Fleming #define EFI_FILE_SYSTEM_GUID \
59455839d51SMatt Fleming     EFI_GUID(  0x964e5b22, 0x6459, 0x11d2, 0x8e, 0x39, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b )
59555839d51SMatt Fleming 
596263b4a30SRoy Franz #define DEVICE_TREE_GUID \
597263b4a30SRoy Franz     EFI_GUID(  0xb1b621d5, 0xf19c, 0x41a5, 0x83, 0x0b, 0xd9, 0x15, 0x2c, 0x69, 0xaa, 0xe0 )
598263b4a30SRoy Franz 
5991da177e4SLinus Torvalds typedef struct {
6001da177e4SLinus Torvalds 	efi_guid_t guid;
6011adbfa35SOlof Johansson 	u64 table;
6021adbfa35SOlof Johansson } efi_config_table_64_t;
6031adbfa35SOlof Johansson 
6041adbfa35SOlof Johansson typedef struct {
6051adbfa35SOlof Johansson 	efi_guid_t guid;
6061adbfa35SOlof Johansson 	u32 table;
6071adbfa35SOlof Johansson } efi_config_table_32_t;
6081adbfa35SOlof Johansson 
6091adbfa35SOlof Johansson typedef struct {
6101adbfa35SOlof Johansson 	efi_guid_t guid;
6111da177e4SLinus Torvalds 	unsigned long table;
6121da177e4SLinus Torvalds } efi_config_table_t;
6131da177e4SLinus Torvalds 
614272686bfSLeif Lindholm typedef struct {
615272686bfSLeif Lindholm 	efi_guid_t guid;
616272686bfSLeif Lindholm 	const char *name;
617272686bfSLeif Lindholm 	unsigned long *ptr;
618272686bfSLeif Lindholm } efi_config_table_type_t;
619272686bfSLeif Lindholm 
6201da177e4SLinus Torvalds #define EFI_SYSTEM_TABLE_SIGNATURE ((u64)0x5453595320494249ULL)
6211da177e4SLinus Torvalds 
6223b370237SMatthew Garrett #define EFI_2_30_SYSTEM_TABLE_REVISION  ((2 << 16) | (30))
6233b370237SMatthew Garrett #define EFI_2_20_SYSTEM_TABLE_REVISION  ((2 << 16) | (20))
6243b370237SMatthew Garrett #define EFI_2_10_SYSTEM_TABLE_REVISION  ((2 << 16) | (10))
6253b370237SMatthew Garrett #define EFI_2_00_SYSTEM_TABLE_REVISION  ((2 << 16) | (00))
6263b370237SMatthew Garrett #define EFI_1_10_SYSTEM_TABLE_REVISION  ((1 << 16) | (10))
6273b370237SMatthew Garrett #define EFI_1_02_SYSTEM_TABLE_REVISION  ((1 << 16) | (02))
6283b370237SMatthew Garrett 
6291da177e4SLinus Torvalds typedef struct {
6301da177e4SLinus Torvalds 	efi_table_hdr_t hdr;
6311adbfa35SOlof Johansson 	u64 fw_vendor;	/* physical addr of CHAR16 vendor string */
6321adbfa35SOlof Johansson 	u32 fw_revision;
6331adbfa35SOlof Johansson 	u32 __pad1;
6341adbfa35SOlof Johansson 	u64 con_in_handle;
6351adbfa35SOlof Johansson 	u64 con_in;
6361adbfa35SOlof Johansson 	u64 con_out_handle;
6371adbfa35SOlof Johansson 	u64 con_out;
6381adbfa35SOlof Johansson 	u64 stderr_handle;
6391adbfa35SOlof Johansson 	u64 stderr;
6401adbfa35SOlof Johansson 	u64 runtime;
6411adbfa35SOlof Johansson 	u64 boottime;
6421adbfa35SOlof Johansson 	u32 nr_tables;
6431adbfa35SOlof Johansson 	u32 __pad2;
6441adbfa35SOlof Johansson 	u64 tables;
6451adbfa35SOlof Johansson } efi_system_table_64_t;
6461adbfa35SOlof Johansson 
6471adbfa35SOlof Johansson typedef struct {
6481adbfa35SOlof Johansson 	efi_table_hdr_t hdr;
6491adbfa35SOlof Johansson 	u32 fw_vendor;	/* physical addr of CHAR16 vendor string */
6501adbfa35SOlof Johansson 	u32 fw_revision;
6511adbfa35SOlof Johansson 	u32 con_in_handle;
6521adbfa35SOlof Johansson 	u32 con_in;
6531adbfa35SOlof Johansson 	u32 con_out_handle;
6541adbfa35SOlof Johansson 	u32 con_out;
6551adbfa35SOlof Johansson 	u32 stderr_handle;
6561adbfa35SOlof Johansson 	u32 stderr;
6571adbfa35SOlof Johansson 	u32 runtime;
6581adbfa35SOlof Johansson 	u32 boottime;
6591adbfa35SOlof Johansson 	u32 nr_tables;
6601adbfa35SOlof Johansson 	u32 tables;
6611adbfa35SOlof Johansson } efi_system_table_32_t;
6621adbfa35SOlof Johansson 
6631adbfa35SOlof Johansson typedef struct {
6641adbfa35SOlof Johansson 	efi_table_hdr_t hdr;
6651da177e4SLinus Torvalds 	unsigned long fw_vendor;	/* physical addr of CHAR16 vendor string */
6661da177e4SLinus Torvalds 	u32 fw_revision;
6671da177e4SLinus Torvalds 	unsigned long con_in_handle;
6681da177e4SLinus Torvalds 	unsigned long con_in;
6691da177e4SLinus Torvalds 	unsigned long con_out_handle;
6701da177e4SLinus Torvalds 	unsigned long con_out;
6711da177e4SLinus Torvalds 	unsigned long stderr_handle;
6721da177e4SLinus Torvalds 	unsigned long stderr;
6731da177e4SLinus Torvalds 	efi_runtime_services_t *runtime;
674f30ca6baSMatt Fleming 	efi_boot_services_t *boottime;
6751da177e4SLinus Torvalds 	unsigned long nr_tables;
6761da177e4SLinus Torvalds 	unsigned long tables;
6771da177e4SLinus Torvalds } efi_system_table_t;
6781da177e4SLinus Torvalds 
6791da177e4SLinus Torvalds struct efi_memory_map {
6807ae65fd3SMatt Tolentino 	void *phys_map;
6817ae65fd3SMatt Tolentino 	void *map;
6827ae65fd3SMatt Tolentino 	void *map_end;
6831da177e4SLinus Torvalds 	int nr_map;
6841da177e4SLinus Torvalds 	unsigned long desc_version;
6857ae65fd3SMatt Tolentino 	unsigned long desc_size;
6861da177e4SLinus Torvalds };
6871da177e4SLinus Torvalds 
6880302f71cSMark Salter struct efi_fdt_params {
6890302f71cSMark Salter 	u64 system_table;
6900302f71cSMark Salter 	u64 mmap;
6910302f71cSMark Salter 	u32 mmap_size;
6920302f71cSMark Salter 	u32 desc_size;
6930302f71cSMark Salter 	u32 desc_ver;
6940302f71cSMark Salter };
6950302f71cSMark Salter 
6968e84f345SMatt Fleming typedef struct {
6978e84f345SMatt Fleming 	u32 revision;
698677703ceSMatt Fleming 	u32 parent_handle;
699677703ceSMatt Fleming 	u32 system_table;
700677703ceSMatt Fleming 	u32 device_handle;
701677703ceSMatt Fleming 	u32 file_path;
702677703ceSMatt Fleming 	u32 reserved;
703677703ceSMatt Fleming 	u32 load_options_size;
704677703ceSMatt Fleming 	u32 load_options;
705677703ceSMatt Fleming 	u32 image_base;
706677703ceSMatt Fleming 	__aligned_u64 image_size;
707677703ceSMatt Fleming 	unsigned int image_code_type;
708677703ceSMatt Fleming 	unsigned int image_data_type;
709677703ceSMatt Fleming 	unsigned long unload;
710677703ceSMatt Fleming } efi_loaded_image_32_t;
711677703ceSMatt Fleming 
712677703ceSMatt Fleming typedef struct {
713677703ceSMatt Fleming 	u32 revision;
714677703ceSMatt Fleming 	u64 parent_handle;
715677703ceSMatt Fleming 	u64 system_table;
716677703ceSMatt Fleming 	u64 device_handle;
717677703ceSMatt Fleming 	u64 file_path;
718677703ceSMatt Fleming 	u64 reserved;
719677703ceSMatt Fleming 	u32 load_options_size;
720677703ceSMatt Fleming 	u64 load_options;
721677703ceSMatt Fleming 	u64 image_base;
722677703ceSMatt Fleming 	__aligned_u64 image_size;
723677703ceSMatt Fleming 	unsigned int image_code_type;
724677703ceSMatt Fleming 	unsigned int image_data_type;
725677703ceSMatt Fleming 	unsigned long unload;
726677703ceSMatt Fleming } efi_loaded_image_64_t;
727677703ceSMatt Fleming 
728677703ceSMatt Fleming typedef struct {
729677703ceSMatt Fleming 	u32 revision;
7308e84f345SMatt Fleming 	void *parent_handle;
7318e84f345SMatt Fleming 	efi_system_table_t *system_table;
7328e84f345SMatt Fleming 	void *device_handle;
7338e84f345SMatt Fleming 	void *file_path;
7348e84f345SMatt Fleming 	void *reserved;
7358e84f345SMatt Fleming 	u32 load_options_size;
7368e84f345SMatt Fleming 	void *load_options;
7378e84f345SMatt Fleming 	void *image_base;
7388e84f345SMatt Fleming 	__aligned_u64 image_size;
7398e84f345SMatt Fleming 	unsigned int image_code_type;
7408e84f345SMatt Fleming 	unsigned int image_data_type;
7418e84f345SMatt Fleming 	unsigned long unload;
7428e84f345SMatt Fleming } efi_loaded_image_t;
7438e84f345SMatt Fleming 
74455839d51SMatt Fleming 
74555839d51SMatt Fleming typedef struct {
74655839d51SMatt Fleming 	u64 size;
74755839d51SMatt Fleming 	u64 file_size;
74855839d51SMatt Fleming 	u64 phys_size;
74955839d51SMatt Fleming 	efi_time_t create_time;
75055839d51SMatt Fleming 	efi_time_t last_access_time;
75155839d51SMatt Fleming 	efi_time_t modification_time;
75255839d51SMatt Fleming 	__aligned_u64 attribute;
75355839d51SMatt Fleming 	efi_char16_t filename[1];
75455839d51SMatt Fleming } efi_file_info_t;
75555839d51SMatt Fleming 
756677703ceSMatt Fleming typedef struct {
757677703ceSMatt Fleming 	u64 revision;
758677703ceSMatt Fleming 	u32 open;
759677703ceSMatt Fleming 	u32 close;
760677703ceSMatt Fleming 	u32 delete;
761677703ceSMatt Fleming 	u32 read;
762677703ceSMatt Fleming 	u32 write;
763677703ceSMatt Fleming 	u32 get_position;
764677703ceSMatt Fleming 	u32 set_position;
765677703ceSMatt Fleming 	u32 get_info;
766677703ceSMatt Fleming 	u32 set_info;
767677703ceSMatt Fleming 	u32 flush;
768677703ceSMatt Fleming } efi_file_handle_32_t;
769677703ceSMatt Fleming 
770677703ceSMatt Fleming typedef struct {
771677703ceSMatt Fleming 	u64 revision;
772677703ceSMatt Fleming 	u64 open;
773677703ceSMatt Fleming 	u64 close;
774677703ceSMatt Fleming 	u64 delete;
775677703ceSMatt Fleming 	u64 read;
776677703ceSMatt Fleming 	u64 write;
777677703ceSMatt Fleming 	u64 get_position;
778677703ceSMatt Fleming 	u64 set_position;
779677703ceSMatt Fleming 	u64 get_info;
780677703ceSMatt Fleming 	u64 set_info;
781677703ceSMatt Fleming 	u64 flush;
782677703ceSMatt Fleming } efi_file_handle_64_t;
783677703ceSMatt Fleming 
784ed37ddffSRoy Franz typedef struct _efi_file_handle {
78555839d51SMatt Fleming 	u64 revision;
786ed37ddffSRoy Franz 	efi_status_t (*open)(struct _efi_file_handle *,
787ed37ddffSRoy Franz 			     struct _efi_file_handle **,
788ed37ddffSRoy Franz 			     efi_char16_t *, u64, u64);
789ed37ddffSRoy Franz 	efi_status_t (*close)(struct _efi_file_handle *);
79055839d51SMatt Fleming 	void *delete;
791ed37ddffSRoy Franz 	efi_status_t (*read)(struct _efi_file_handle *, unsigned long *,
792ed37ddffSRoy Franz 			     void *);
79355839d51SMatt Fleming 	void *write;
79455839d51SMatt Fleming 	void *get_position;
79555839d51SMatt Fleming 	void *set_position;
796ed37ddffSRoy Franz 	efi_status_t (*get_info)(struct _efi_file_handle *, efi_guid_t *,
797ed37ddffSRoy Franz 			unsigned long *, void *);
79855839d51SMatt Fleming 	void *set_info;
79955839d51SMatt Fleming 	void *flush;
80055839d51SMatt Fleming } efi_file_handle_t;
80155839d51SMatt Fleming 
802ed37ddffSRoy Franz typedef struct _efi_file_io_interface {
803ed37ddffSRoy Franz 	u64 revision;
804ed37ddffSRoy Franz 	int (*open_volume)(struct _efi_file_io_interface *,
805ed37ddffSRoy Franz 			   efi_file_handle_t **);
806ed37ddffSRoy Franz } efi_file_io_interface_t;
807ed37ddffSRoy Franz 
80855839d51SMatt Fleming #define EFI_FILE_MODE_READ	0x0000000000000001
80955839d51SMatt Fleming #define EFI_FILE_MODE_WRITE	0x0000000000000002
81055839d51SMatt Fleming #define EFI_FILE_MODE_CREATE	0x8000000000000000
81155839d51SMatt Fleming 
812b2c99e3cSBjorn Helgaas #define EFI_INVALID_TABLE_ADDR		(~0UL)
813b2c99e3cSBjorn Helgaas 
8141da177e4SLinus Torvalds /*
8151da177e4SLinus Torvalds  * All runtime access to EFI goes through this structure:
8161da177e4SLinus Torvalds  */
8171da177e4SLinus Torvalds extern struct efi {
8181da177e4SLinus Torvalds 	efi_system_table_t *systab;	/* EFI system table */
8193b370237SMatthew Garrett 	unsigned int runtime_version;	/* Runtime services version */
820b2c99e3cSBjorn Helgaas 	unsigned long mps;		/* MPS table */
821b2c99e3cSBjorn Helgaas 	unsigned long acpi;		/* ACPI table  (IA64 ext 0.71) */
822b2c99e3cSBjorn Helgaas 	unsigned long acpi20;		/* ACPI table  (ACPI 2.0) */
823e1ccbbc9SArd Biesheuvel 	unsigned long smbios;		/* SMBIOS table (32 bit entry point) */
824e1ccbbc9SArd Biesheuvel 	unsigned long smbios3;		/* SMBIOS table (64 bit entry point) */
825b2c99e3cSBjorn Helgaas 	unsigned long sal_systab;	/* SAL system table */
826b2c99e3cSBjorn Helgaas 	unsigned long boot_info;	/* boot info table */
827b2c99e3cSBjorn Helgaas 	unsigned long hcdp;		/* HCDP table */
828b2c99e3cSBjorn Helgaas 	unsigned long uga;		/* UGA table */
829a50f70b1SRuss Anderson 	unsigned long uv_systab;	/* UV system table */
830a0998eb1SDave Young 	unsigned long fw_vendor;	/* fw_vendor */
831a0998eb1SDave Young 	unsigned long runtime;		/* runtime table */
832a0998eb1SDave Young 	unsigned long config_table;	/* config tables */
8330bb54905SPeter Jones 	unsigned long esrt;		/* ESRT table */
8341da177e4SLinus Torvalds 	efi_get_time_t *get_time;
8351da177e4SLinus Torvalds 	efi_set_time_t *set_time;
8361da177e4SLinus Torvalds 	efi_get_wakeup_time_t *get_wakeup_time;
8371da177e4SLinus Torvalds 	efi_set_wakeup_time_t *set_wakeup_time;
8381da177e4SLinus Torvalds 	efi_get_variable_t *get_variable;
8391da177e4SLinus Torvalds 	efi_get_next_variable_t *get_next_variable;
8401da177e4SLinus Torvalds 	efi_set_variable_t *set_variable;
8416d80dba1SMatt Fleming 	efi_set_variable_nonblocking_t *set_variable_nonblocking;
8423b370237SMatthew Garrett 	efi_query_variable_info_t *query_variable_info;
8433b370237SMatthew Garrett 	efi_update_capsule_t *update_capsule;
8443b370237SMatthew Garrett 	efi_query_capsule_caps_t *query_capsule_caps;
8451da177e4SLinus Torvalds 	efi_get_next_high_mono_count_t *get_next_high_mono_count;
8461da177e4SLinus Torvalds 	efi_reset_system_t *reset_system;
8471da177e4SLinus Torvalds 	efi_set_virtual_address_map_t *set_virtual_address_map;
848258f6fd7SLeif Lindholm 	struct efi_memory_map *memmap;
8493e909599SMatt Fleming 	unsigned long flags;
8501da177e4SLinus Torvalds } efi;
8511da177e4SLinus Torvalds 
8521da177e4SLinus Torvalds static inline int
8531da177e4SLinus Torvalds efi_guidcmp (efi_guid_t left, efi_guid_t right)
8541da177e4SLinus Torvalds {
8551da177e4SLinus Torvalds 	return memcmp(&left, &right, sizeof (efi_guid_t));
8561da177e4SLinus Torvalds }
8571da177e4SLinus Torvalds 
8581da177e4SLinus Torvalds static inline char *
85926e02272SBorislav Petkov efi_guid_to_str(efi_guid_t *guid, char *out)
8601da177e4SLinus Torvalds {
861925ede0bSJoe Perches 	sprintf(out, "%pUl", guid->b);
8621da177e4SLinus Torvalds         return out;
8631da177e4SLinus Torvalds }
8641da177e4SLinus Torvalds 
8651da177e4SLinus Torvalds extern void efi_init (void);
8661da177e4SLinus Torvalds extern void *efi_get_pal_addr (void);
8671da177e4SLinus Torvalds extern void efi_map_pal_code (void);
8681da177e4SLinus Torvalds extern void efi_memmap_walk (efi_freemem_callback_t callback, void *arg);
8691da177e4SLinus Torvalds extern void efi_gettimeofday (struct timespec *ts);
8701da177e4SLinus Torvalds extern void efi_enter_virtual_mode (void);	/* switch EFI to virtual mode, if possible */
87178510792SJosh Triplett #ifdef CONFIG_X86
8722223af38SJosh Triplett extern void efi_late_init(void);
87378510792SJosh Triplett extern void efi_free_boot_services(void);
874a6e4d5a0SMatt Fleming extern efi_status_t efi_query_variable_store(u32 attributes, unsigned long size);
875b05b9f5fSTony Luck extern void efi_find_mirror(void);
87678510792SJosh Triplett #else
8772223af38SJosh Triplett static inline void efi_late_init(void) {}
87878510792SJosh Triplett static inline void efi_free_boot_services(void) {}
879a6e4d5a0SMatt Fleming 
880a6e4d5a0SMatt Fleming static inline efi_status_t efi_query_variable_store(u32 attributes, unsigned long size)
881a6e4d5a0SMatt Fleming {
882a6e4d5a0SMatt Fleming 	return EFI_SUCCESS;
883a6e4d5a0SMatt Fleming }
88478510792SJosh Triplett #endif
8857bc90e01SJosh Triplett extern void __iomem *efi_lookup_mapped_addr(u64 phys_addr);
886272686bfSLeif Lindholm extern int efi_config_init(efi_config_table_type_t *arch_tables);
8873846c158SPeter Jones #ifdef CONFIG_EFI_ESRT
8880bb54905SPeter Jones extern void __init efi_esrt_init(void);
8893846c158SPeter Jones #else
8903846c158SPeter Jones static inline void efi_esrt_init(void) { }
8913846c158SPeter Jones #endif
8927bb68410SArd Biesheuvel extern int efi_config_parse_tables(void *config_tables, int count, int sz,
8937bb68410SArd Biesheuvel 				   efi_config_table_type_t *arch_tables);
8941da177e4SLinus Torvalds extern u64 efi_get_iobase (void);
8951da177e4SLinus Torvalds extern u32 efi_mem_type (unsigned long phys_addr);
8961da177e4SLinus Torvalds extern u64 efi_mem_attributes (unsigned long phys_addr);
89732e62c63SBjorn Helgaas extern u64 efi_mem_attribute (unsigned long phys_addr, unsigned long size);
8981da177e4SLinus Torvalds extern int __init efi_uart_console_only (void);
8990bb54905SPeter Jones extern u64 efi_mem_desc_end(efi_memory_desc_t *md);
9000bb54905SPeter Jones extern int efi_mem_desc_lookup(u64 phys_addr, efi_memory_desc_t *out_md);
9011da177e4SLinus Torvalds extern void efi_initialize_iomem_resources(struct resource *code_resource,
90200bf4098SBernhard Walle 		struct resource *data_resource, struct resource *bss_resource);
9033565184eSDavid Vrabel extern void efi_get_time(struct timespec *now);
904916f676fSMatthew Garrett extern void efi_reserve_boot_services(void);
9050302f71cSMark Salter extern int efi_get_fdt_params(struct efi_fdt_params *params, int verbose);
9061da177e4SLinus Torvalds extern struct efi_memory_map memmap;
9070bb54905SPeter Jones extern struct kobject *efi_kobj;
9081da177e4SLinus Torvalds 
90944be28e9SMatt Fleming extern int efi_reboot_quirk_mode;
9100c5ed61aSMatt Fleming extern bool efi_poweroff_required(void);
9110c5ed61aSMatt Fleming 
912e885cd80SMark Salter /* Iterate through an efi_memory_map */
913e885cd80SMark Salter #define for_each_efi_memory_desc(m, md)					   \
914e885cd80SMark Salter 	for ((md) = (m)->map;						   \
915e885cd80SMark Salter 	     (md) <= (efi_memory_desc_t *)((m)->map_end - (m)->desc_size); \
916e885cd80SMark Salter 	     (md) = (void *)(md) + (m)->desc_size)
917e885cd80SMark Salter 
91898d2a6caSLaszlo Ersek /*
91998d2a6caSLaszlo Ersek  * Format an EFI memory descriptor's type and attributes to a user-provided
92098d2a6caSLaszlo Ersek  * character buffer, as per snprintf(), and return the buffer.
92198d2a6caSLaszlo Ersek  */
92298d2a6caSLaszlo Ersek char * __init efi_md_typeattr_format(char *buf, size_t size,
92398d2a6caSLaszlo Ersek 				     const efi_memory_desc_t *md);
92498d2a6caSLaszlo Ersek 
9251da177e4SLinus Torvalds /**
9261da177e4SLinus Torvalds  * efi_range_is_wc - check the WC bit on an address range
9271da177e4SLinus Torvalds  * @start: starting kvirt address
9281da177e4SLinus Torvalds  * @len: length of range
9291da177e4SLinus Torvalds  *
9301da177e4SLinus Torvalds  * Consult the EFI memory map and make sure it's ok to set this range WC.
9311da177e4SLinus Torvalds  * Returns true or false.
9321da177e4SLinus Torvalds  */
9331da177e4SLinus Torvalds static inline int efi_range_is_wc(unsigned long start, unsigned long len)
9341da177e4SLinus Torvalds {
935986a80d5SJesper Juhl 	unsigned long i;
9361da177e4SLinus Torvalds 
9371da177e4SLinus Torvalds 	for (i = 0; i < len; i += (1UL << EFI_PAGE_SHIFT)) {
9381da177e4SLinus Torvalds 		unsigned long paddr = __pa(start + i);
9391da177e4SLinus Torvalds 		if (!(efi_mem_attributes(paddr) & EFI_MEMORY_WC))
9401da177e4SLinus Torvalds 			return 0;
9411da177e4SLinus Torvalds 	}
9421da177e4SLinus Torvalds 	/* The range checked out */
9431da177e4SLinus Torvalds 	return 1;
9441da177e4SLinus Torvalds }
9451da177e4SLinus Torvalds 
9461da177e4SLinus Torvalds #ifdef CONFIG_EFI_PCDP
9471da177e4SLinus Torvalds extern int __init efi_setup_pcdp_console(char *);
9481da177e4SLinus Torvalds #endif
9491da177e4SLinus Torvalds 
9501da177e4SLinus Torvalds /*
95183e68189SMatt Fleming  * We play games with efi_enabled so that the compiler will, if
95283e68189SMatt Fleming  * possible, remove EFI-related code altogether.
9531da177e4SLinus Torvalds  */
95483e68189SMatt Fleming #define EFI_BOOT		0	/* Were we booted from EFI? */
95583e68189SMatt Fleming #define EFI_SYSTEM_TABLES	1	/* Can we use EFI system tables? */
95683e68189SMatt Fleming #define EFI_CONFIG_TABLES	2	/* Can we use EFI config tables? */
95783e68189SMatt Fleming #define EFI_RUNTIME_SERVICES	3	/* Can we use runtime services? */
95883e68189SMatt Fleming #define EFI_MEMMAP		4	/* Can we use EFI memory map? */
95983e68189SMatt Fleming #define EFI_64BIT		5	/* Is the firmware 64-bit? */
9609f27bc54SDaniel Kiper #define EFI_PARAVIRT		6	/* Access is via a paravirt interface */
9619f27bc54SDaniel Kiper #define EFI_ARCH_1		7	/* First arch-specific bit */
962fed6cefeSBorislav Petkov #define EFI_DBG			8	/* Print additional debug info at runtime */
96383e68189SMatt Fleming 
9641da177e4SLinus Torvalds #ifdef CONFIG_EFI
9653e909599SMatt Fleming /*
9663e909599SMatt Fleming  * Test whether the above EFI_* bits are enabled.
9673e909599SMatt Fleming  */
9683e909599SMatt Fleming static inline bool efi_enabled(int feature)
96983e68189SMatt Fleming {
9703e909599SMatt Fleming 	return test_bit(feature, &efi.flags) != 0;
9713e909599SMatt Fleming }
9728562c99cSMatt Fleming extern void efi_reboot(enum reboot_mode reboot_mode, const char *__unused);
9733e909599SMatt Fleming #else
9743e909599SMatt Fleming static inline bool efi_enabled(int feature)
9753e909599SMatt Fleming {
9763e909599SMatt Fleming 	return false;
97783e68189SMatt Fleming }
9788562c99cSMatt Fleming static inline void
9798562c99cSMatt Fleming efi_reboot(enum reboot_mode reboot_mode, const char *__unused) {}
9801da177e4SLinus Torvalds #endif
9811da177e4SLinus Torvalds 
9821da177e4SLinus Torvalds /*
9831da177e4SLinus Torvalds  * Variable Attributes
9841da177e4SLinus Torvalds  */
9851da177e4SLinus Torvalds #define EFI_VARIABLE_NON_VOLATILE       0x0000000000000001
9861da177e4SLinus Torvalds #define EFI_VARIABLE_BOOTSERVICE_ACCESS 0x0000000000000002
9871da177e4SLinus Torvalds #define EFI_VARIABLE_RUNTIME_ACCESS     0x0000000000000004
98841b3254cSMatthew Garrett #define EFI_VARIABLE_HARDWARE_ERROR_RECORD 0x0000000000000008
98941b3254cSMatthew Garrett #define EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS 0x0000000000000010
99041b3254cSMatthew Garrett #define EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS 0x0000000000000020
99141b3254cSMatthew Garrett #define EFI_VARIABLE_APPEND_WRITE	0x0000000000000040
9921da177e4SLinus Torvalds 
99341b3254cSMatthew Garrett #define EFI_VARIABLE_MASK 	(EFI_VARIABLE_NON_VOLATILE | \
99441b3254cSMatthew Garrett 				EFI_VARIABLE_BOOTSERVICE_ACCESS | \
99541b3254cSMatthew Garrett 				EFI_VARIABLE_RUNTIME_ACCESS | \
99641b3254cSMatthew Garrett 				EFI_VARIABLE_HARDWARE_ERROR_RECORD | \
99741b3254cSMatthew Garrett 				EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS | \
99841b3254cSMatthew Garrett 				EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS | \
99941b3254cSMatthew Garrett 				EFI_VARIABLE_APPEND_WRITE)
10001da177e4SLinus Torvalds /*
1001e14ab23dSMatt Fleming  * Length of a GUID string (strlen("aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee"))
1002e14ab23dSMatt Fleming  * not including trailing NUL
1003e14ab23dSMatt Fleming  */
1004e14ab23dSMatt Fleming #define EFI_VARIABLE_GUID_LEN 36
1005e14ab23dSMatt Fleming 
1006e14ab23dSMatt Fleming /*
1007e2527a7cSMatt Fleming  * The type of search to perform when calling boottime->locate_handle
1008e2527a7cSMatt Fleming  */
1009e2527a7cSMatt Fleming #define EFI_LOCATE_ALL_HANDLES			0
1010e2527a7cSMatt Fleming #define EFI_LOCATE_BY_REGISTER_NOTIFY		1
1011e2527a7cSMatt Fleming #define EFI_LOCATE_BY_PROTOCOL			2
1012e2527a7cSMatt Fleming 
1013e2527a7cSMatt Fleming /*
10141da177e4SLinus Torvalds  * EFI Device Path information
10151da177e4SLinus Torvalds  */
10161da177e4SLinus Torvalds #define EFI_DEV_HW			0x01
10171da177e4SLinus Torvalds #define  EFI_DEV_PCI				 1
10181da177e4SLinus Torvalds #define  EFI_DEV_PCCARD				 2
10191da177e4SLinus Torvalds #define  EFI_DEV_MEM_MAPPED			 3
10201da177e4SLinus Torvalds #define  EFI_DEV_VENDOR				 4
10211da177e4SLinus Torvalds #define  EFI_DEV_CONTROLLER			 5
10221da177e4SLinus Torvalds #define EFI_DEV_ACPI			0x02
10231da177e4SLinus Torvalds #define   EFI_DEV_BASIC_ACPI			 1
10241da177e4SLinus Torvalds #define   EFI_DEV_EXPANDED_ACPI			 2
10251da177e4SLinus Torvalds #define EFI_DEV_MSG			0x03
10261da177e4SLinus Torvalds #define   EFI_DEV_MSG_ATAPI			 1
10271da177e4SLinus Torvalds #define   EFI_DEV_MSG_SCSI			 2
10281da177e4SLinus Torvalds #define   EFI_DEV_MSG_FC			 3
10291da177e4SLinus Torvalds #define   EFI_DEV_MSG_1394			 4
10301da177e4SLinus Torvalds #define   EFI_DEV_MSG_USB			 5
10311da177e4SLinus Torvalds #define   EFI_DEV_MSG_USB_CLASS			15
10321da177e4SLinus Torvalds #define   EFI_DEV_MSG_I20			 6
10331da177e4SLinus Torvalds #define   EFI_DEV_MSG_MAC			11
10341da177e4SLinus Torvalds #define   EFI_DEV_MSG_IPV4			12
10351da177e4SLinus Torvalds #define   EFI_DEV_MSG_IPV6			13
10361da177e4SLinus Torvalds #define   EFI_DEV_MSG_INFINIBAND		 9
10371da177e4SLinus Torvalds #define   EFI_DEV_MSG_UART			14
10381da177e4SLinus Torvalds #define   EFI_DEV_MSG_VENDOR			10
10391da177e4SLinus Torvalds #define EFI_DEV_MEDIA			0x04
10401da177e4SLinus Torvalds #define   EFI_DEV_MEDIA_HARD_DRIVE		 1
10411da177e4SLinus Torvalds #define   EFI_DEV_MEDIA_CDROM			 2
10421da177e4SLinus Torvalds #define   EFI_DEV_MEDIA_VENDOR			 3
10431da177e4SLinus Torvalds #define   EFI_DEV_MEDIA_FILE			 4
10441da177e4SLinus Torvalds #define   EFI_DEV_MEDIA_PROTOCOL		 5
10451da177e4SLinus Torvalds #define EFI_DEV_BIOS_BOOT		0x05
10461da177e4SLinus Torvalds #define EFI_DEV_END_PATH		0x7F
10471da177e4SLinus Torvalds #define EFI_DEV_END_PATH2		0xFF
10481da177e4SLinus Torvalds #define   EFI_DEV_END_INSTANCE			0x01
10491da177e4SLinus Torvalds #define   EFI_DEV_END_ENTIRE			0xFF
10501da177e4SLinus Torvalds 
10511da177e4SLinus Torvalds struct efi_generic_dev_path {
10521da177e4SLinus Torvalds 	u8 type;
10531da177e4SLinus Torvalds 	u8 sub_type;
10541da177e4SLinus Torvalds 	u16 length;
10551da177e4SLinus Torvalds } __attribute ((packed));
10561da177e4SLinus Torvalds 
10574a3575fdSHuang, Ying static inline void memrange_efi_to_native(u64 *addr, u64 *npages)
10584a3575fdSHuang, Ying {
10594a3575fdSHuang, Ying 	*npages = PFN_UP(*addr + (*npages<<EFI_PAGE_SHIFT)) - PFN_DOWN(*addr);
10604a3575fdSHuang, Ying 	*addr &= PAGE_MASK;
10614a3575fdSHuang, Ying }
10624a3575fdSHuang, Ying 
106304851772SMatt Fleming /*
10644fc756bdSMike Waychison  * EFI Variable support.
10654fc756bdSMike Waychison  *
10664fc756bdSMike Waychison  * Different firmware drivers can expose their EFI-like variables using
10674fc756bdSMike Waychison  * the following.
10684fc756bdSMike Waychison  */
10694fc756bdSMike Waychison 
10704fc756bdSMike Waychison struct efivar_operations {
10714fc756bdSMike Waychison 	efi_get_variable_t *get_variable;
10724fc756bdSMike Waychison 	efi_get_next_variable_t *get_next_variable;
10734fc756bdSMike Waychison 	efi_set_variable_t *set_variable;
10746d80dba1SMatt Fleming 	efi_set_variable_nonblocking_t *set_variable_nonblocking;
1075a6e4d5a0SMatt Fleming 	efi_query_variable_store_t *query_variable_store;
10764fc756bdSMike Waychison };
10774fc756bdSMike Waychison 
10784fc756bdSMike Waychison struct efivars {
10794fc756bdSMike Waychison 	/*
10804fc756bdSMike Waychison 	 * ->lock protects two things:
108182f990a8SMatt Fleming 	 * 1) efivarfs_list and efivars_sysfs_list
108282f990a8SMatt Fleming 	 * 2) ->ops calls
10834fc756bdSMike Waychison 	 */
10844fc756bdSMike Waychison 	spinlock_t lock;
10854fc756bdSMike Waychison 	struct kset *kset;
1086605e70c7SLee, Chun-Yi 	struct kobject *kobject;
10874fc756bdSMike Waychison 	const struct efivar_operations *ops;
10884fc756bdSMike Waychison };
10894fc756bdSMike Waychison 
1090e14ab23dSMatt Fleming /*
1091e14ab23dSMatt Fleming  * The maximum size of VariableName + Data = 1024
1092e14ab23dSMatt Fleming  * Therefore, it's reasonable to save that much
1093e14ab23dSMatt Fleming  * space in each part of the structure,
1094e14ab23dSMatt Fleming  * and we use a page for reading/writing.
1095e14ab23dSMatt Fleming  */
1096e14ab23dSMatt Fleming 
1097a5d92ad3SMatt Fleming #define EFI_VAR_NAME_LEN	1024
1098a5d92ad3SMatt Fleming 
1099e14ab23dSMatt Fleming struct efi_variable {
1100a5d92ad3SMatt Fleming 	efi_char16_t  VariableName[EFI_VAR_NAME_LEN/sizeof(efi_char16_t)];
1101e14ab23dSMatt Fleming 	efi_guid_t    VendorGuid;
1102e14ab23dSMatt Fleming 	unsigned long DataSize;
1103e14ab23dSMatt Fleming 	__u8          Data[1024];
1104e14ab23dSMatt Fleming 	efi_status_t  Status;
1105e14ab23dSMatt Fleming 	__u32         Attributes;
1106e14ab23dSMatt Fleming } __attribute__((packed));
1107e14ab23dSMatt Fleming 
1108e14ab23dSMatt Fleming struct efivar_entry {
1109e14ab23dSMatt Fleming 	struct efi_variable var;
1110e14ab23dSMatt Fleming 	struct list_head list;
1111e14ab23dSMatt Fleming 	struct kobject kobj;
1112e0d59733SSeiji Aguchi 	bool scanning;
1113e0d59733SSeiji Aguchi 	bool deleting;
1114e14ab23dSMatt Fleming };
1115e14ab23dSMatt Fleming 
1116677703ceSMatt Fleming struct efi_simple_text_output_protocol_32 {
1117677703ceSMatt Fleming 	u32 reset;
1118677703ceSMatt Fleming 	u32 output_string;
1119677703ceSMatt Fleming 	u32 test_string;
1120677703ceSMatt Fleming };
1121677703ceSMatt Fleming 
1122677703ceSMatt Fleming struct efi_simple_text_output_protocol_64 {
1123677703ceSMatt Fleming 	u64 reset;
1124677703ceSMatt Fleming 	u64 output_string;
1125677703ceSMatt Fleming 	u64 test_string;
1126677703ceSMatt Fleming };
1127ed37ddffSRoy Franz 
1128ed37ddffSRoy Franz struct efi_simple_text_output_protocol {
1129ed37ddffSRoy Franz 	void *reset;
1130ed37ddffSRoy Franz 	efi_status_t (*output_string)(void *, void *);
1131ed37ddffSRoy Franz 	void *test_string;
1132ed37ddffSRoy Franz };
1133ed37ddffSRoy Franz 
113404851772SMatt Fleming extern struct list_head efivar_sysfs_list;
113504851772SMatt Fleming 
113604851772SMatt Fleming static inline void
113704851772SMatt Fleming efivar_unregister(struct efivar_entry *var)
113804851772SMatt Fleming {
113904851772SMatt Fleming 	kobject_put(&var->kobj);
114004851772SMatt Fleming }
114104851772SMatt Fleming 
1142e14ab23dSMatt Fleming int efivars_register(struct efivars *efivars,
11434fc756bdSMike Waychison 		     const struct efivar_operations *ops,
1144e14ab23dSMatt Fleming 		     struct kobject *kobject);
1145e14ab23dSMatt Fleming int efivars_unregister(struct efivars *efivars);
1146e14ab23dSMatt Fleming struct kobject *efivars_kobject(void);
1147e14ab23dSMatt Fleming 
1148e14ab23dSMatt Fleming int efivar_init(int (*func)(efi_char16_t *, efi_guid_t, unsigned long, void *),
1149e14ab23dSMatt Fleming 		void *data, bool atomic, bool duplicates,
1150e14ab23dSMatt Fleming 		struct list_head *head);
1151e14ab23dSMatt Fleming 
1152e14ab23dSMatt Fleming void efivar_entry_add(struct efivar_entry *entry, struct list_head *head);
1153e14ab23dSMatt Fleming void efivar_entry_remove(struct efivar_entry *entry);
1154e14ab23dSMatt Fleming 
1155e14ab23dSMatt Fleming int __efivar_entry_delete(struct efivar_entry *entry);
1156e14ab23dSMatt Fleming int efivar_entry_delete(struct efivar_entry *entry);
1157e14ab23dSMatt Fleming 
1158e14ab23dSMatt Fleming int efivar_entry_size(struct efivar_entry *entry, unsigned long *size);
11598a415b8cSMatt Fleming int __efivar_entry_get(struct efivar_entry *entry, u32 *attributes,
11608a415b8cSMatt Fleming 		       unsigned long *size, void *data);
1161e14ab23dSMatt Fleming int efivar_entry_get(struct efivar_entry *entry, u32 *attributes,
1162e14ab23dSMatt Fleming 		     unsigned long *size, void *data);
1163e14ab23dSMatt Fleming int efivar_entry_set(struct efivar_entry *entry, u32 attributes,
1164e14ab23dSMatt Fleming 		     unsigned long size, void *data, struct list_head *head);
1165e14ab23dSMatt Fleming int efivar_entry_set_get_size(struct efivar_entry *entry, u32 attributes,
1166e14ab23dSMatt Fleming 			      unsigned long *size, void *data, bool *set);
1167e14ab23dSMatt Fleming int efivar_entry_set_safe(efi_char16_t *name, efi_guid_t vendor, u32 attributes,
1168e14ab23dSMatt Fleming 			  bool block, unsigned long size, void *data);
1169e14ab23dSMatt Fleming 
1170e14ab23dSMatt Fleming void efivar_entry_iter_begin(void);
1171e14ab23dSMatt Fleming void efivar_entry_iter_end(void);
1172e14ab23dSMatt Fleming 
1173e14ab23dSMatt Fleming int __efivar_entry_iter(int (*func)(struct efivar_entry *, void *),
1174e14ab23dSMatt Fleming 			struct list_head *head, void *data,
1175e14ab23dSMatt Fleming 			struct efivar_entry **prev);
1176e14ab23dSMatt Fleming int efivar_entry_iter(int (*func)(struct efivar_entry *, void *),
1177e14ab23dSMatt Fleming 		      struct list_head *head, void *data);
1178e14ab23dSMatt Fleming 
1179e14ab23dSMatt Fleming struct efivar_entry *efivar_entry_find(efi_char16_t *name, efi_guid_t guid,
1180e14ab23dSMatt Fleming 				       struct list_head *head, bool remove);
1181e14ab23dSMatt Fleming 
1182a5d92ad3SMatt Fleming bool efivar_validate(efi_char16_t *var_name, u8 *data, unsigned long len);
1183e14ab23dSMatt Fleming 
1184a9499fa7STom Gundersen extern struct work_struct efivar_work;
118504851772SMatt Fleming void efivar_run_worker(void);
118604851772SMatt Fleming 
1187a9499fa7STom Gundersen #if defined(CONFIG_EFI_VARS) || defined(CONFIG_EFI_VARS_MODULE)
1188e14ab23dSMatt Fleming int efivars_sysfs_init(void);
11894fc756bdSMike Waychison 
1190e0d59733SSeiji Aguchi #define EFIVARS_DATA_SIZE_MAX 1024
1191e0d59733SSeiji Aguchi 
11924fc756bdSMike Waychison #endif /* CONFIG_EFI_VARS */
11934fc756bdSMike Waychison 
1194926172d4SDave Young #ifdef CONFIG_EFI_RUNTIME_MAP
1195926172d4SDave Young int efi_runtime_map_init(struct kobject *);
1196926172d4SDave Young void efi_runtime_map_setup(void *, int, u32);
11976a2c20e7SVivek Goyal int efi_get_runtime_map_size(void);
11986a2c20e7SVivek Goyal int efi_get_runtime_map_desc_size(void);
11996a2c20e7SVivek Goyal int efi_runtime_map_copy(void *buf, size_t bufsz);
1200926172d4SDave Young #else
1201926172d4SDave Young static inline int efi_runtime_map_init(struct kobject *kobj)
1202926172d4SDave Young {
1203926172d4SDave Young 	return 0;
1204926172d4SDave Young }
1205926172d4SDave Young 
1206926172d4SDave Young static inline void
1207926172d4SDave Young efi_runtime_map_setup(void *map, int nr_entries, u32 desc_size) {}
12086a2c20e7SVivek Goyal 
12096a2c20e7SVivek Goyal static inline int efi_get_runtime_map_size(void)
12106a2c20e7SVivek Goyal {
12116a2c20e7SVivek Goyal 	return 0;
12126a2c20e7SVivek Goyal }
12136a2c20e7SVivek Goyal 
12146a2c20e7SVivek Goyal static inline int efi_get_runtime_map_desc_size(void)
12156a2c20e7SVivek Goyal {
12166a2c20e7SVivek Goyal 	return 0;
12176a2c20e7SVivek Goyal }
12186a2c20e7SVivek Goyal 
12196a2c20e7SVivek Goyal static inline int efi_runtime_map_copy(void *buf, size_t bufsz)
12206a2c20e7SVivek Goyal {
12216a2c20e7SVivek Goyal 	return 0;
12226a2c20e7SVivek Goyal }
12236a2c20e7SVivek Goyal 
1224926172d4SDave Young #endif
1225926172d4SDave Young 
1226bd669475SArd Biesheuvel /* prototypes shared between arch specific and generic stub code */
1227bd669475SArd Biesheuvel 
1228bd669475SArd Biesheuvel #define pr_efi(sys_table, msg)     efi_printk(sys_table, "EFI stub: "msg)
1229bd669475SArd Biesheuvel #define pr_efi_err(sys_table, msg) efi_printk(sys_table, "EFI stub: ERROR: "msg)
1230bd669475SArd Biesheuvel 
1231bd669475SArd Biesheuvel void efi_printk(efi_system_table_t *sys_table_arg, char *str);
1232bd669475SArd Biesheuvel 
1233bd669475SArd Biesheuvel void efi_free(efi_system_table_t *sys_table_arg, unsigned long size,
1234bd669475SArd Biesheuvel 	      unsigned long addr);
1235bd669475SArd Biesheuvel 
1236bd669475SArd Biesheuvel char *efi_convert_cmdline(efi_system_table_t *sys_table_arg,
1237bd669475SArd Biesheuvel 			  efi_loaded_image_t *image, int *cmd_line_len);
1238bd669475SArd Biesheuvel 
1239bd669475SArd Biesheuvel efi_status_t efi_get_memory_map(efi_system_table_t *sys_table_arg,
1240bd669475SArd Biesheuvel 				efi_memory_desc_t **map,
1241bd669475SArd Biesheuvel 				unsigned long *map_size,
1242bd669475SArd Biesheuvel 				unsigned long *desc_size,
1243bd669475SArd Biesheuvel 				u32 *desc_ver,
1244bd669475SArd Biesheuvel 				unsigned long *key_ptr);
1245bd669475SArd Biesheuvel 
1246bd669475SArd Biesheuvel efi_status_t efi_low_alloc(efi_system_table_t *sys_table_arg,
1247bd669475SArd Biesheuvel 			   unsigned long size, unsigned long align,
1248bd669475SArd Biesheuvel 			   unsigned long *addr);
1249bd669475SArd Biesheuvel 
1250bd669475SArd Biesheuvel efi_status_t efi_high_alloc(efi_system_table_t *sys_table_arg,
1251bd669475SArd Biesheuvel 			    unsigned long size, unsigned long align,
1252bd669475SArd Biesheuvel 			    unsigned long *addr, unsigned long max);
1253bd669475SArd Biesheuvel 
1254bd669475SArd Biesheuvel efi_status_t efi_relocate_kernel(efi_system_table_t *sys_table_arg,
1255bd669475SArd Biesheuvel 				 unsigned long *image_addr,
1256bd669475SArd Biesheuvel 				 unsigned long image_size,
1257bd669475SArd Biesheuvel 				 unsigned long alloc_size,
1258bd669475SArd Biesheuvel 				 unsigned long preferred_addr,
1259bd669475SArd Biesheuvel 				 unsigned long alignment);
1260bd669475SArd Biesheuvel 
1261bd669475SArd Biesheuvel efi_status_t handle_cmdline_files(efi_system_table_t *sys_table_arg,
1262bd669475SArd Biesheuvel 				  efi_loaded_image_t *image,
1263bd669475SArd Biesheuvel 				  char *cmd_line, char *option_string,
1264bd669475SArd Biesheuvel 				  unsigned long max_addr,
1265bd669475SArd Biesheuvel 				  unsigned long *load_addr,
1266bd669475SArd Biesheuvel 				  unsigned long *load_size);
1267bd669475SArd Biesheuvel 
12685a17dae4SMatt Fleming efi_status_t efi_parse_options(char *cmdline);
12695a17dae4SMatt Fleming 
1270b2e0a54aSDave Young bool efi_runtime_disabled(void);
12711da177e4SLinus Torvalds #endif /* _LINUX_EFI_H */
1272