xref: /openbmc/linux/include/linux/efi.h (revision 6d80dba1c9fe4316ef626980102b92fa30c7845a)
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
881da177e4SLinus Torvalds #define EFI_MAX_MEMORY_TYPE		14
891da177e4SLinus Torvalds 
901da177e4SLinus Torvalds /* Attribute values: */
911da177e4SLinus Torvalds #define EFI_MEMORY_UC		((u64)0x0000000000000001ULL)	/* uncached */
921da177e4SLinus Torvalds #define EFI_MEMORY_WC		((u64)0x0000000000000002ULL)	/* write-coalescing */
931da177e4SLinus Torvalds #define EFI_MEMORY_WT		((u64)0x0000000000000004ULL)	/* write-through */
941da177e4SLinus Torvalds #define EFI_MEMORY_WB		((u64)0x0000000000000008ULL)	/* write-back */
959c97e0bdSLaszlo Ersek #define EFI_MEMORY_UCE		((u64)0x0000000000000010ULL)	/* uncached, exported */
961da177e4SLinus Torvalds #define EFI_MEMORY_WP		((u64)0x0000000000001000ULL)	/* write-protect */
971da177e4SLinus Torvalds #define EFI_MEMORY_RP		((u64)0x0000000000002000ULL)	/* read-protect */
981da177e4SLinus Torvalds #define EFI_MEMORY_XP		((u64)0x0000000000004000ULL)	/* execute-protect */
991da177e4SLinus Torvalds #define EFI_MEMORY_RUNTIME	((u64)0x8000000000000000ULL)	/* range requires runtime mapping */
1001da177e4SLinus Torvalds #define EFI_MEMORY_DESCRIPTOR_VERSION	1
1011da177e4SLinus Torvalds 
1021da177e4SLinus Torvalds #define EFI_PAGE_SHIFT		12
103ed37ddffSRoy Franz #define EFI_PAGE_SIZE		(1UL << EFI_PAGE_SHIFT)
1041da177e4SLinus Torvalds 
1051da177e4SLinus Torvalds typedef struct {
1061da177e4SLinus Torvalds 	u32 type;
1071da177e4SLinus Torvalds 	u32 pad;
1081da177e4SLinus Torvalds 	u64 phys_addr;
1091da177e4SLinus Torvalds 	u64 virt_addr;
1101da177e4SLinus Torvalds 	u64 num_pages;
1111da177e4SLinus Torvalds 	u64 attribute;
1121da177e4SLinus Torvalds } efi_memory_desc_t;
1131da177e4SLinus Torvalds 
1143b370237SMatthew Garrett typedef struct {
1153b370237SMatthew Garrett 	efi_guid_t guid;
1163b370237SMatthew Garrett 	u32 headersize;
1173b370237SMatthew Garrett 	u32 flags;
1183b370237SMatthew Garrett 	u32 imagesize;
1193b370237SMatthew Garrett } efi_capsule_header_t;
1203b370237SMatthew Garrett 
121bb05e4baSMatt Fleming /*
122bb05e4baSMatt Fleming  * Allocation types for calls to boottime->allocate_pages.
123bb05e4baSMatt Fleming  */
124bb05e4baSMatt Fleming #define EFI_ALLOCATE_ANY_PAGES		0
125bb05e4baSMatt Fleming #define EFI_ALLOCATE_MAX_ADDRESS	1
126bb05e4baSMatt Fleming #define EFI_ALLOCATE_ADDRESS		2
127bb05e4baSMatt Fleming #define EFI_MAX_ALLOCATE_TYPE		3
128bb05e4baSMatt Fleming 
129e088a4adSMatthew Wilcox typedef int (*efi_freemem_callback_t) (u64 start, u64 end, void *arg);
1301da177e4SLinus Torvalds 
1311da177e4SLinus Torvalds /*
1321da177e4SLinus Torvalds  * Types and defines for Time Services
1331da177e4SLinus Torvalds  */
1341da177e4SLinus Torvalds #define EFI_TIME_ADJUST_DAYLIGHT 0x1
1351da177e4SLinus Torvalds #define EFI_TIME_IN_DAYLIGHT     0x2
1361da177e4SLinus Torvalds #define EFI_UNSPECIFIED_TIMEZONE 0x07ff
1371da177e4SLinus Torvalds 
1381da177e4SLinus Torvalds typedef struct {
1391da177e4SLinus Torvalds 	u16 year;
1401da177e4SLinus Torvalds 	u8 month;
1411da177e4SLinus Torvalds 	u8 day;
1421da177e4SLinus Torvalds 	u8 hour;
1431da177e4SLinus Torvalds 	u8 minute;
1441da177e4SLinus Torvalds 	u8 second;
1451da177e4SLinus Torvalds 	u8 pad1;
1461da177e4SLinus Torvalds 	u32 nanosecond;
1471da177e4SLinus Torvalds 	s16 timezone;
1481da177e4SLinus Torvalds 	u8 daylight;
1491da177e4SLinus Torvalds 	u8 pad2;
1501da177e4SLinus Torvalds } efi_time_t;
1511da177e4SLinus Torvalds 
1521da177e4SLinus Torvalds typedef struct {
1531da177e4SLinus Torvalds 	u32 resolution;
1541da177e4SLinus Torvalds 	u32 accuracy;
1551da177e4SLinus Torvalds 	u8 sets_to_zero;
1561da177e4SLinus Torvalds } efi_time_cap_t;
1571da177e4SLinus Torvalds 
158677703ceSMatt Fleming typedef struct {
159677703ceSMatt Fleming 	efi_table_hdr_t hdr;
160677703ceSMatt Fleming 	u32 raise_tpl;
161677703ceSMatt Fleming 	u32 restore_tpl;
162677703ceSMatt Fleming 	u32 allocate_pages;
163677703ceSMatt Fleming 	u32 free_pages;
164677703ceSMatt Fleming 	u32 get_memory_map;
165677703ceSMatt Fleming 	u32 allocate_pool;
166677703ceSMatt Fleming 	u32 free_pool;
167677703ceSMatt Fleming 	u32 create_event;
168677703ceSMatt Fleming 	u32 set_timer;
169677703ceSMatt Fleming 	u32 wait_for_event;
170677703ceSMatt Fleming 	u32 signal_event;
171677703ceSMatt Fleming 	u32 close_event;
172677703ceSMatt Fleming 	u32 check_event;
173677703ceSMatt Fleming 	u32 install_protocol_interface;
174677703ceSMatt Fleming 	u32 reinstall_protocol_interface;
175677703ceSMatt Fleming 	u32 uninstall_protocol_interface;
176677703ceSMatt Fleming 	u32 handle_protocol;
177677703ceSMatt Fleming 	u32 __reserved;
178677703ceSMatt Fleming 	u32 register_protocol_notify;
179677703ceSMatt Fleming 	u32 locate_handle;
180677703ceSMatt Fleming 	u32 locate_device_path;
181677703ceSMatt Fleming 	u32 install_configuration_table;
182677703ceSMatt Fleming 	u32 load_image;
183677703ceSMatt Fleming 	u32 start_image;
184677703ceSMatt Fleming 	u32 exit;
185677703ceSMatt Fleming 	u32 unload_image;
186677703ceSMatt Fleming 	u32 exit_boot_services;
187677703ceSMatt Fleming 	u32 get_next_monotonic_count;
188677703ceSMatt Fleming 	u32 stall;
189677703ceSMatt Fleming 	u32 set_watchdog_timer;
190677703ceSMatt Fleming 	u32 connect_controller;
191677703ceSMatt Fleming 	u32 disconnect_controller;
192677703ceSMatt Fleming 	u32 open_protocol;
193677703ceSMatt Fleming 	u32 close_protocol;
194677703ceSMatt Fleming 	u32 open_protocol_information;
195677703ceSMatt Fleming 	u32 protocols_per_handle;
196677703ceSMatt Fleming 	u32 locate_handle_buffer;
197677703ceSMatt Fleming 	u32 locate_protocol;
198677703ceSMatt Fleming 	u32 install_multiple_protocol_interfaces;
199677703ceSMatt Fleming 	u32 uninstall_multiple_protocol_interfaces;
200677703ceSMatt Fleming 	u32 calculate_crc32;
201677703ceSMatt Fleming 	u32 copy_mem;
202677703ceSMatt Fleming 	u32 set_mem;
203677703ceSMatt Fleming 	u32 create_event_ex;
204677703ceSMatt Fleming } __packed efi_boot_services_32_t;
205677703ceSMatt Fleming 
206677703ceSMatt Fleming typedef struct {
207677703ceSMatt Fleming 	efi_table_hdr_t hdr;
208677703ceSMatt Fleming 	u64 raise_tpl;
209677703ceSMatt Fleming 	u64 restore_tpl;
210677703ceSMatt Fleming 	u64 allocate_pages;
211677703ceSMatt Fleming 	u64 free_pages;
212677703ceSMatt Fleming 	u64 get_memory_map;
213677703ceSMatt Fleming 	u64 allocate_pool;
214677703ceSMatt Fleming 	u64 free_pool;
215677703ceSMatt Fleming 	u64 create_event;
216677703ceSMatt Fleming 	u64 set_timer;
217677703ceSMatt Fleming 	u64 wait_for_event;
218677703ceSMatt Fleming 	u64 signal_event;
219677703ceSMatt Fleming 	u64 close_event;
220677703ceSMatt Fleming 	u64 check_event;
221677703ceSMatt Fleming 	u64 install_protocol_interface;
222677703ceSMatt Fleming 	u64 reinstall_protocol_interface;
223677703ceSMatt Fleming 	u64 uninstall_protocol_interface;
224677703ceSMatt Fleming 	u64 handle_protocol;
225677703ceSMatt Fleming 	u64 __reserved;
226677703ceSMatt Fleming 	u64 register_protocol_notify;
227677703ceSMatt Fleming 	u64 locate_handle;
228677703ceSMatt Fleming 	u64 locate_device_path;
229677703ceSMatt Fleming 	u64 install_configuration_table;
230677703ceSMatt Fleming 	u64 load_image;
231677703ceSMatt Fleming 	u64 start_image;
232677703ceSMatt Fleming 	u64 exit;
233677703ceSMatt Fleming 	u64 unload_image;
234677703ceSMatt Fleming 	u64 exit_boot_services;
235677703ceSMatt Fleming 	u64 get_next_monotonic_count;
236677703ceSMatt Fleming 	u64 stall;
237677703ceSMatt Fleming 	u64 set_watchdog_timer;
238677703ceSMatt Fleming 	u64 connect_controller;
239677703ceSMatt Fleming 	u64 disconnect_controller;
240677703ceSMatt Fleming 	u64 open_protocol;
241677703ceSMatt Fleming 	u64 close_protocol;
242677703ceSMatt Fleming 	u64 open_protocol_information;
243677703ceSMatt Fleming 	u64 protocols_per_handle;
244677703ceSMatt Fleming 	u64 locate_handle_buffer;
245677703ceSMatt Fleming 	u64 locate_protocol;
246677703ceSMatt Fleming 	u64 install_multiple_protocol_interfaces;
247677703ceSMatt Fleming 	u64 uninstall_multiple_protocol_interfaces;
248677703ceSMatt Fleming 	u64 calculate_crc32;
249677703ceSMatt Fleming 	u64 copy_mem;
250677703ceSMatt Fleming 	u64 set_mem;
251677703ceSMatt Fleming 	u64 create_event_ex;
252677703ceSMatt Fleming } __packed efi_boot_services_64_t;
253677703ceSMatt Fleming 
2541da177e4SLinus Torvalds /*
255f30ca6baSMatt Fleming  * EFI Boot Services table
256f30ca6baSMatt Fleming  */
257f30ca6baSMatt Fleming typedef struct {
258f30ca6baSMatt Fleming 	efi_table_hdr_t hdr;
259f30ca6baSMatt Fleming 	void *raise_tpl;
260f30ca6baSMatt Fleming 	void *restore_tpl;
261ed37ddffSRoy Franz 	efi_status_t (*allocate_pages)(int, int, unsigned long,
262ed37ddffSRoy Franz 				       efi_physical_addr_t *);
263ed37ddffSRoy Franz 	efi_status_t (*free_pages)(efi_physical_addr_t, unsigned long);
264ed37ddffSRoy Franz 	efi_status_t (*get_memory_map)(unsigned long *, void *, unsigned long *,
265ed37ddffSRoy Franz 				       unsigned long *, u32 *);
266ed37ddffSRoy Franz 	efi_status_t (*allocate_pool)(int, unsigned long, void **);
267ed37ddffSRoy Franz 	efi_status_t (*free_pool)(void *);
268f30ca6baSMatt Fleming 	void *create_event;
269f30ca6baSMatt Fleming 	void *set_timer;
270f30ca6baSMatt Fleming 	void *wait_for_event;
271f30ca6baSMatt Fleming 	void *signal_event;
272f30ca6baSMatt Fleming 	void *close_event;
273f30ca6baSMatt Fleming 	void *check_event;
274f30ca6baSMatt Fleming 	void *install_protocol_interface;
275f30ca6baSMatt Fleming 	void *reinstall_protocol_interface;
276f30ca6baSMatt Fleming 	void *uninstall_protocol_interface;
277ed37ddffSRoy Franz 	efi_status_t (*handle_protocol)(efi_handle_t, efi_guid_t *, void **);
278f30ca6baSMatt Fleming 	void *__reserved;
279f30ca6baSMatt Fleming 	void *register_protocol_notify;
280f30ca6baSMatt Fleming 	void *locate_handle;
281f30ca6baSMatt Fleming 	void *locate_device_path;
282f30ca6baSMatt Fleming 	void *install_configuration_table;
283f30ca6baSMatt Fleming 	void *load_image;
284f30ca6baSMatt Fleming 	void *start_image;
285f30ca6baSMatt Fleming 	void *exit;
286f30ca6baSMatt Fleming 	void *unload_image;
287ed37ddffSRoy Franz 	efi_status_t (*exit_boot_services)(efi_handle_t, unsigned long);
288f30ca6baSMatt Fleming 	void *get_next_monotonic_count;
289f30ca6baSMatt Fleming 	void *stall;
290f30ca6baSMatt Fleming 	void *set_watchdog_timer;
291f30ca6baSMatt Fleming 	void *connect_controller;
292f30ca6baSMatt Fleming 	void *disconnect_controller;
293f30ca6baSMatt Fleming 	void *open_protocol;
294f30ca6baSMatt Fleming 	void *close_protocol;
295f30ca6baSMatt Fleming 	void *open_protocol_information;
296f30ca6baSMatt Fleming 	void *protocols_per_handle;
297f30ca6baSMatt Fleming 	void *locate_handle_buffer;
298f30ca6baSMatt Fleming 	void *locate_protocol;
299f30ca6baSMatt Fleming 	void *install_multiple_protocol_interfaces;
300f30ca6baSMatt Fleming 	void *uninstall_multiple_protocol_interfaces;
301f30ca6baSMatt Fleming 	void *calculate_crc32;
302f30ca6baSMatt Fleming 	void *copy_mem;
303f30ca6baSMatt Fleming 	void *set_mem;
304f30ca6baSMatt Fleming 	void *create_event_ex;
305f30ca6baSMatt Fleming } efi_boot_services_t;
306f30ca6baSMatt Fleming 
307dd5fc854SMatthew Garrett typedef enum {
308dd5fc854SMatthew Garrett 	EfiPciIoWidthUint8,
309dd5fc854SMatthew Garrett 	EfiPciIoWidthUint16,
310dd5fc854SMatthew Garrett 	EfiPciIoWidthUint32,
311dd5fc854SMatthew Garrett 	EfiPciIoWidthUint64,
312dd5fc854SMatthew Garrett 	EfiPciIoWidthFifoUint8,
313dd5fc854SMatthew Garrett 	EfiPciIoWidthFifoUint16,
314dd5fc854SMatthew Garrett 	EfiPciIoWidthFifoUint32,
315dd5fc854SMatthew Garrett 	EfiPciIoWidthFifoUint64,
316dd5fc854SMatthew Garrett 	EfiPciIoWidthFillUint8,
317dd5fc854SMatthew Garrett 	EfiPciIoWidthFillUint16,
318dd5fc854SMatthew Garrett 	EfiPciIoWidthFillUint32,
319dd5fc854SMatthew Garrett 	EfiPciIoWidthFillUint64,
320dd5fc854SMatthew Garrett 	EfiPciIoWidthMaximum
321dd5fc854SMatthew Garrett } EFI_PCI_IO_PROTOCOL_WIDTH;
322dd5fc854SMatthew Garrett 
323dd5fc854SMatthew Garrett typedef enum {
324dd5fc854SMatthew Garrett 	EfiPciIoAttributeOperationGet,
325dd5fc854SMatthew Garrett 	EfiPciIoAttributeOperationSet,
326dd5fc854SMatthew Garrett 	EfiPciIoAttributeOperationEnable,
327dd5fc854SMatthew Garrett 	EfiPciIoAttributeOperationDisable,
328dd5fc854SMatthew Garrett 	EfiPciIoAttributeOperationSupported,
329dd5fc854SMatthew Garrett     EfiPciIoAttributeOperationMaximum
330dd5fc854SMatthew Garrett } EFI_PCI_IO_PROTOCOL_ATTRIBUTE_OPERATION;
331dd5fc854SMatthew Garrett 
332677703ceSMatt Fleming typedef struct {
333677703ceSMatt Fleming 	u32 read;
334677703ceSMatt Fleming 	u32 write;
335677703ceSMatt Fleming } efi_pci_io_protocol_access_32_t;
336677703ceSMatt Fleming 
337677703ceSMatt Fleming typedef struct {
338677703ceSMatt Fleming 	u64 read;
339677703ceSMatt Fleming 	u64 write;
340677703ceSMatt Fleming } efi_pci_io_protocol_access_64_t;
341dd5fc854SMatthew Garrett 
342dd5fc854SMatthew Garrett typedef struct {
343dd5fc854SMatthew Garrett 	void *read;
344dd5fc854SMatthew Garrett 	void *write;
345dd5fc854SMatthew Garrett } efi_pci_io_protocol_access_t;
346dd5fc854SMatthew Garrett 
347dd5fc854SMatthew Garrett typedef struct {
348677703ceSMatt Fleming 	u32 poll_mem;
349677703ceSMatt Fleming 	u32 poll_io;
350677703ceSMatt Fleming 	efi_pci_io_protocol_access_32_t mem;
351677703ceSMatt Fleming 	efi_pci_io_protocol_access_32_t io;
352677703ceSMatt Fleming 	efi_pci_io_protocol_access_32_t pci;
353677703ceSMatt Fleming 	u32 copy_mem;
354677703ceSMatt Fleming 	u32 map;
355677703ceSMatt Fleming 	u32 unmap;
356677703ceSMatt Fleming 	u32 allocate_buffer;
357677703ceSMatt Fleming 	u32 free_buffer;
358677703ceSMatt Fleming 	u32 flush;
359677703ceSMatt Fleming 	u32 get_location;
360677703ceSMatt Fleming 	u32 attributes;
361677703ceSMatt Fleming 	u32 get_bar_attributes;
362677703ceSMatt Fleming 	u32 set_bar_attributes;
363677703ceSMatt Fleming 	uint64_t romsize;
364677703ceSMatt Fleming 	void *romimage;
365677703ceSMatt Fleming } efi_pci_io_protocol_32;
366677703ceSMatt Fleming 
367677703ceSMatt Fleming typedef struct {
368677703ceSMatt Fleming 	u64 poll_mem;
369677703ceSMatt Fleming 	u64 poll_io;
370677703ceSMatt Fleming 	efi_pci_io_protocol_access_64_t mem;
371677703ceSMatt Fleming 	efi_pci_io_protocol_access_64_t io;
372677703ceSMatt Fleming 	efi_pci_io_protocol_access_64_t pci;
373677703ceSMatt Fleming 	u64 copy_mem;
374677703ceSMatt Fleming 	u64 map;
375677703ceSMatt Fleming 	u64 unmap;
376677703ceSMatt Fleming 	u64 allocate_buffer;
377677703ceSMatt Fleming 	u64 free_buffer;
378677703ceSMatt Fleming 	u64 flush;
379677703ceSMatt Fleming 	u64 get_location;
380677703ceSMatt Fleming 	u64 attributes;
381677703ceSMatt Fleming 	u64 get_bar_attributes;
382677703ceSMatt Fleming 	u64 set_bar_attributes;
383677703ceSMatt Fleming 	uint64_t romsize;
384677703ceSMatt Fleming 	void *romimage;
385677703ceSMatt Fleming } efi_pci_io_protocol_64;
386677703ceSMatt Fleming 
387677703ceSMatt Fleming typedef struct {
388dd5fc854SMatthew Garrett 	void *poll_mem;
389dd5fc854SMatthew Garrett 	void *poll_io;
390dd5fc854SMatthew Garrett 	efi_pci_io_protocol_access_t mem;
391dd5fc854SMatthew Garrett 	efi_pci_io_protocol_access_t io;
392dd5fc854SMatthew Garrett 	efi_pci_io_protocol_access_t pci;
393dd5fc854SMatthew Garrett 	void *copy_mem;
394dd5fc854SMatthew Garrett 	void *map;
395dd5fc854SMatthew Garrett 	void *unmap;
396dd5fc854SMatthew Garrett 	void *allocate_buffer;
397dd5fc854SMatthew Garrett 	void *free_buffer;
398dd5fc854SMatthew Garrett 	void *flush;
399dd5fc854SMatthew Garrett 	void *get_location;
400dd5fc854SMatthew Garrett 	void *attributes;
401dd5fc854SMatthew Garrett 	void *get_bar_attributes;
402dd5fc854SMatthew Garrett 	void *set_bar_attributes;
403dd5fc854SMatthew Garrett 	uint64_t romsize;
404dd5fc854SMatthew Garrett 	void *romimage;
405dd5fc854SMatthew Garrett } efi_pci_io_protocol;
406dd5fc854SMatthew Garrett 
407dd5fc854SMatthew Garrett #define EFI_PCI_IO_ATTRIBUTE_ISA_MOTHERBOARD_IO 0x0001
408dd5fc854SMatthew Garrett #define EFI_PCI_IO_ATTRIBUTE_ISA_IO 0x0002
409dd5fc854SMatthew Garrett #define EFI_PCI_IO_ATTRIBUTE_VGA_PALETTE_IO 0x0004
410dd5fc854SMatthew Garrett #define EFI_PCI_IO_ATTRIBUTE_VGA_MEMORY 0x0008
411dd5fc854SMatthew Garrett #define EFI_PCI_IO_ATTRIBUTE_VGA_IO 0x0010
412dd5fc854SMatthew Garrett #define EFI_PCI_IO_ATTRIBUTE_IDE_PRIMARY_IO 0x0020
413dd5fc854SMatthew Garrett #define EFI_PCI_IO_ATTRIBUTE_IDE_SECONDARY_IO 0x0040
414dd5fc854SMatthew Garrett #define EFI_PCI_IO_ATTRIBUTE_MEMORY_WRITE_COMBINE 0x0080
415dd5fc854SMatthew Garrett #define EFI_PCI_IO_ATTRIBUTE_IO 0x0100
416dd5fc854SMatthew Garrett #define EFI_PCI_IO_ATTRIBUTE_MEMORY 0x0200
417dd5fc854SMatthew Garrett #define EFI_PCI_IO_ATTRIBUTE_BUS_MASTER 0x0400
418dd5fc854SMatthew Garrett #define EFI_PCI_IO_ATTRIBUTE_MEMORY_CACHED 0x0800
419dd5fc854SMatthew Garrett #define EFI_PCI_IO_ATTRIBUTE_MEMORY_DISABLE 0x1000
420dd5fc854SMatthew Garrett #define EFI_PCI_IO_ATTRIBUTE_EMBEDDED_DEVICE 0x2000
421dd5fc854SMatthew Garrett #define EFI_PCI_IO_ATTRIBUTE_EMBEDDED_ROM 0x4000
422dd5fc854SMatthew Garrett #define EFI_PCI_IO_ATTRIBUTE_DUAL_ADDRESS_CYCLE 0x8000
423dd5fc854SMatthew Garrett #define EFI_PCI_IO_ATTRIBUTE_ISA_IO_16 0x10000
424dd5fc854SMatthew Garrett #define EFI_PCI_IO_ATTRIBUTE_VGA_PALETTE_IO_16 0x20000
425dd5fc854SMatthew Garrett #define EFI_PCI_IO_ATTRIBUTE_VGA_IO_16 0x40000
426dd5fc854SMatthew Garrett 
427f30ca6baSMatt Fleming /*
4281da177e4SLinus Torvalds  * Types and defines for EFI ResetSystem
4291da177e4SLinus Torvalds  */
4301da177e4SLinus Torvalds #define EFI_RESET_COLD 0
4311da177e4SLinus Torvalds #define EFI_RESET_WARM 1
4321da177e4SLinus Torvalds #define EFI_RESET_SHUTDOWN 2
4331da177e4SLinus Torvalds 
4341da177e4SLinus Torvalds /*
4351da177e4SLinus Torvalds  * EFI Runtime Services table
4361da177e4SLinus Torvalds  */
4371da177e4SLinus Torvalds #define EFI_RUNTIME_SERVICES_SIGNATURE ((u64)0x5652453544e5552ULL)
4381da177e4SLinus Torvalds #define EFI_RUNTIME_SERVICES_REVISION  0x00010000
4391da177e4SLinus Torvalds 
4401da177e4SLinus Torvalds typedef struct {
4411da177e4SLinus Torvalds 	efi_table_hdr_t hdr;
442677703ceSMatt Fleming 	u32 get_time;
443677703ceSMatt Fleming 	u32 set_time;
444677703ceSMatt Fleming 	u32 get_wakeup_time;
445677703ceSMatt Fleming 	u32 set_wakeup_time;
446677703ceSMatt Fleming 	u32 set_virtual_address_map;
447677703ceSMatt Fleming 	u32 convert_pointer;
448677703ceSMatt Fleming 	u32 get_variable;
449677703ceSMatt Fleming 	u32 get_next_variable;
450677703ceSMatt Fleming 	u32 set_variable;
451677703ceSMatt Fleming 	u32 get_next_high_mono_count;
452677703ceSMatt Fleming 	u32 reset_system;
453677703ceSMatt Fleming 	u32 update_capsule;
454677703ceSMatt Fleming 	u32 query_capsule_caps;
455677703ceSMatt Fleming 	u32 query_variable_info;
456677703ceSMatt Fleming } efi_runtime_services_32_t;
457677703ceSMatt Fleming 
458677703ceSMatt Fleming typedef struct {
459677703ceSMatt Fleming 	efi_table_hdr_t hdr;
460677703ceSMatt Fleming 	u64 get_time;
461677703ceSMatt Fleming 	u64 set_time;
462677703ceSMatt Fleming 	u64 get_wakeup_time;
463677703ceSMatt Fleming 	u64 set_wakeup_time;
464677703ceSMatt Fleming 	u64 set_virtual_address_map;
465677703ceSMatt Fleming 	u64 convert_pointer;
466677703ceSMatt Fleming 	u64 get_variable;
467677703ceSMatt Fleming 	u64 get_next_variable;
468677703ceSMatt Fleming 	u64 set_variable;
469677703ceSMatt Fleming 	u64 get_next_high_mono_count;
470677703ceSMatt Fleming 	u64 reset_system;
471677703ceSMatt Fleming 	u64 update_capsule;
472677703ceSMatt Fleming 	u64 query_capsule_caps;
473677703ceSMatt Fleming 	u64 query_variable_info;
474677703ceSMatt Fleming } efi_runtime_services_64_t;
475677703ceSMatt Fleming 
476677703ceSMatt Fleming typedef struct {
477677703ceSMatt Fleming 	efi_table_hdr_t hdr;
47843ab0476SBorislav Petkov 	void *get_time;
47943ab0476SBorislav Petkov 	void *set_time;
48043ab0476SBorislav Petkov 	void *get_wakeup_time;
48143ab0476SBorislav Petkov 	void *set_wakeup_time;
48243ab0476SBorislav Petkov 	void *set_virtual_address_map;
48343ab0476SBorislav Petkov 	void *convert_pointer;
48443ab0476SBorislav Petkov 	void *get_variable;
48543ab0476SBorislav Petkov 	void *get_next_variable;
48643ab0476SBorislav Petkov 	void *set_variable;
48743ab0476SBorislav Petkov 	void *get_next_high_mono_count;
48843ab0476SBorislav Petkov 	void *reset_system;
48943ab0476SBorislav Petkov 	void *update_capsule;
49043ab0476SBorislav Petkov 	void *query_capsule_caps;
49143ab0476SBorislav Petkov 	void *query_variable_info;
4921da177e4SLinus Torvalds } efi_runtime_services_t;
4931da177e4SLinus Torvalds 
4941da177e4SLinus Torvalds typedef efi_status_t efi_get_time_t (efi_time_t *tm, efi_time_cap_t *tc);
4951da177e4SLinus Torvalds typedef efi_status_t efi_set_time_t (efi_time_t *tm);
4961da177e4SLinus Torvalds typedef efi_status_t efi_get_wakeup_time_t (efi_bool_t *enabled, efi_bool_t *pending,
4971da177e4SLinus Torvalds 					    efi_time_t *tm);
4981da177e4SLinus Torvalds typedef efi_status_t efi_set_wakeup_time_t (efi_bool_t enabled, efi_time_t *tm);
4991da177e4SLinus Torvalds typedef efi_status_t efi_get_variable_t (efi_char16_t *name, efi_guid_t *vendor, u32 *attr,
5001da177e4SLinus Torvalds 					 unsigned long *data_size, void *data);
5011da177e4SLinus Torvalds typedef efi_status_t efi_get_next_variable_t (unsigned long *name_size, efi_char16_t *name,
5021da177e4SLinus Torvalds 					      efi_guid_t *vendor);
5031da177e4SLinus Torvalds typedef efi_status_t efi_set_variable_t (efi_char16_t *name, efi_guid_t *vendor,
504f7a2d73fSMatthew Garrett 					 u32 attr, unsigned long data_size,
5051da177e4SLinus Torvalds 					 void *data);
506*6d80dba1SMatt Fleming typedef efi_status_t
507*6d80dba1SMatt Fleming efi_set_variable_nonblocking_t(efi_char16_t *name, efi_guid_t *vendor,
508*6d80dba1SMatt Fleming 			       u32 attr, unsigned long data_size, void *data);
509*6d80dba1SMatt Fleming 
5101da177e4SLinus Torvalds typedef efi_status_t efi_get_next_high_mono_count_t (u32 *count);
5111da177e4SLinus Torvalds typedef void efi_reset_system_t (int reset_type, efi_status_t status,
5121da177e4SLinus Torvalds 				 unsigned long data_size, efi_char16_t *data);
5131da177e4SLinus Torvalds typedef efi_status_t efi_set_virtual_address_map_t (unsigned long memory_map_size,
5141da177e4SLinus Torvalds 						unsigned long descriptor_size,
5151da177e4SLinus Torvalds 						u32 descriptor_version,
5161da177e4SLinus Torvalds 						efi_memory_desc_t *virtual_map);
5173b370237SMatthew Garrett typedef efi_status_t efi_query_variable_info_t(u32 attr,
5183b370237SMatthew Garrett 					       u64 *storage_space,
5193b370237SMatthew Garrett 					       u64 *remaining_space,
5203b370237SMatthew Garrett 					       u64 *max_variable_size);
5213b370237SMatthew Garrett typedef efi_status_t efi_update_capsule_t(efi_capsule_header_t **capsules,
5223b370237SMatthew Garrett 					  unsigned long count,
5233b370237SMatthew Garrett 					  unsigned long sg_list);
5243b370237SMatthew Garrett typedef efi_status_t efi_query_capsule_caps_t(efi_capsule_header_t **capsules,
5253b370237SMatthew Garrett 					      unsigned long count,
5263b370237SMatthew Garrett 					      u64 *max_size,
5273b370237SMatthew Garrett 					      int *reset_type);
528a6e4d5a0SMatt Fleming typedef efi_status_t efi_query_variable_store_t(u32 attributes, unsigned long size);
5291da177e4SLinus Torvalds 
530022ee6c5SArd Biesheuvel void efi_native_runtime_setup(void);
531022ee6c5SArd Biesheuvel 
5321da177e4SLinus Torvalds /*
5331da177e4SLinus Torvalds  *  EFI Configuration Table and GUID definitions
5341da177e4SLinus Torvalds  */
5351da177e4SLinus Torvalds #define NULL_GUID \
5361da177e4SLinus Torvalds     EFI_GUID(  0x00000000, 0x0000, 0x0000, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 )
5371da177e4SLinus Torvalds 
5381da177e4SLinus Torvalds #define MPS_TABLE_GUID    \
5391da177e4SLinus Torvalds     EFI_GUID(  0xeb9d2d2f, 0x2d88, 0x11d3, 0x9a, 0x16, 0x0, 0x90, 0x27, 0x3f, 0xc1, 0x4d )
5401da177e4SLinus Torvalds 
5411da177e4SLinus Torvalds #define ACPI_TABLE_GUID    \
5421da177e4SLinus Torvalds     EFI_GUID(  0xeb9d2d30, 0x2d88, 0x11d3, 0x9a, 0x16, 0x0, 0x90, 0x27, 0x3f, 0xc1, 0x4d )
5431da177e4SLinus Torvalds 
5441da177e4SLinus Torvalds #define ACPI_20_TABLE_GUID    \
5451da177e4SLinus Torvalds     EFI_GUID(  0x8868e871, 0xe4f1, 0x11d3, 0xbc, 0x22, 0x0, 0x80, 0xc7, 0x3c, 0x88, 0x81 )
5461da177e4SLinus Torvalds 
5471da177e4SLinus Torvalds #define SMBIOS_TABLE_GUID    \
5481da177e4SLinus Torvalds     EFI_GUID(  0xeb9d2d31, 0x2d88, 0x11d3, 0x9a, 0x16, 0x0, 0x90, 0x27, 0x3f, 0xc1, 0x4d )
5491da177e4SLinus Torvalds 
5501da177e4SLinus Torvalds #define SAL_SYSTEM_TABLE_GUID    \
5511da177e4SLinus Torvalds     EFI_GUID(  0xeb9d2d32, 0x2d88, 0x11d3, 0x9a, 0x16, 0x0, 0x90, 0x27, 0x3f, 0xc1, 0x4d )
5521da177e4SLinus Torvalds 
5531da177e4SLinus Torvalds #define HCDP_TABLE_GUID	\
5541da177e4SLinus Torvalds     EFI_GUID(  0xf951938d, 0x620b, 0x42ef, 0x82, 0x79, 0xa8, 0x4b, 0x79, 0x61, 0x78, 0x98 )
5551da177e4SLinus Torvalds 
5561da177e4SLinus Torvalds #define UGA_IO_PROTOCOL_GUID \
5571da177e4SLinus Torvalds     EFI_GUID(  0x61a4d49e, 0x6f68, 0x4f1b, 0xb9, 0x22, 0xa8, 0x6e, 0xed, 0xb, 0x7, 0xa2 )
5581da177e4SLinus Torvalds 
5591da177e4SLinus Torvalds #define EFI_GLOBAL_VARIABLE_GUID \
5601da177e4SLinus Torvalds     EFI_GUID(  0x8be4df61, 0x93ca, 0x11d2, 0xaa, 0x0d, 0x00, 0xe0, 0x98, 0x03, 0x2b, 0x8c )
5611da177e4SLinus Torvalds 
562a50f70b1SRuss Anderson #define UV_SYSTEM_TABLE_GUID \
563a50f70b1SRuss Anderson     EFI_GUID(  0x3b13a7d4, 0x633e, 0x11dd, 0x93, 0xec, 0xda, 0x25, 0x56, 0xd8, 0x95, 0x93 )
564a50f70b1SRuss Anderson 
5655ee9c198SMatthew Garrett #define LINUX_EFI_CRASH_GUID \
5665ee9c198SMatthew Garrett     EFI_GUID(  0xcfc8fc79, 0xbe2e, 0x4ddc, 0x97, 0xf0, 0x9f, 0x98, 0xbf, 0xe2, 0x98, 0xa0 )
5675ee9c198SMatthew Garrett 
5688e84f345SMatt Fleming #define LOADED_IMAGE_PROTOCOL_GUID \
5698e84f345SMatt Fleming     EFI_GUID(  0x5b1b31a1, 0x9562, 0x11d2, 0x8e, 0x3f, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b )
5708e84f345SMatt Fleming 
5710f7c5d47SMatt Fleming #define EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID \
5720f7c5d47SMatt Fleming     EFI_GUID(  0x9042a9de, 0x23dc, 0x4a38, 0x96, 0xfb, 0x7a, 0xde, 0xd0, 0x80, 0x51, 0x6a )
5730f7c5d47SMatt Fleming 
5740f7c5d47SMatt Fleming #define EFI_UGA_PROTOCOL_GUID \
5750f7c5d47SMatt Fleming     EFI_GUID(  0x982c298b, 0xf4fa, 0x41cb, 0xb8, 0x38, 0x77, 0xaa, 0x68, 0x8f, 0xb8, 0x39 )
5760f7c5d47SMatt Fleming 
5770f7c5d47SMatt Fleming #define EFI_PCI_IO_PROTOCOL_GUID \
5780f7c5d47SMatt Fleming     EFI_GUID(  0x4cf5b200, 0x68b8, 0x4ca5, 0x9e, 0xec, 0xb2, 0x3e, 0x3f, 0x50, 0x2, 0x9a )
5790f7c5d47SMatt Fleming 
58055839d51SMatt Fleming #define EFI_FILE_INFO_ID \
58155839d51SMatt Fleming     EFI_GUID(  0x9576e92, 0x6d3f, 0x11d2, 0x8e, 0x39, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b )
58255839d51SMatt Fleming 
58355839d51SMatt Fleming #define EFI_FILE_SYSTEM_GUID \
58455839d51SMatt Fleming     EFI_GUID(  0x964e5b22, 0x6459, 0x11d2, 0x8e, 0x39, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b )
58555839d51SMatt Fleming 
586263b4a30SRoy Franz #define DEVICE_TREE_GUID \
587263b4a30SRoy Franz     EFI_GUID(  0xb1b621d5, 0xf19c, 0x41a5, 0x83, 0x0b, 0xd9, 0x15, 0x2c, 0x69, 0xaa, 0xe0 )
588263b4a30SRoy Franz 
5891da177e4SLinus Torvalds typedef struct {
5901da177e4SLinus Torvalds 	efi_guid_t guid;
5911adbfa35SOlof Johansson 	u64 table;
5921adbfa35SOlof Johansson } efi_config_table_64_t;
5931adbfa35SOlof Johansson 
5941adbfa35SOlof Johansson typedef struct {
5951adbfa35SOlof Johansson 	efi_guid_t guid;
5961adbfa35SOlof Johansson 	u32 table;
5971adbfa35SOlof Johansson } efi_config_table_32_t;
5981adbfa35SOlof Johansson 
5991adbfa35SOlof Johansson typedef struct {
6001adbfa35SOlof Johansson 	efi_guid_t guid;
6011da177e4SLinus Torvalds 	unsigned long table;
6021da177e4SLinus Torvalds } efi_config_table_t;
6031da177e4SLinus Torvalds 
604272686bfSLeif Lindholm typedef struct {
605272686bfSLeif Lindholm 	efi_guid_t guid;
606272686bfSLeif Lindholm 	const char *name;
607272686bfSLeif Lindholm 	unsigned long *ptr;
608272686bfSLeif Lindholm } efi_config_table_type_t;
609272686bfSLeif Lindholm 
6101da177e4SLinus Torvalds #define EFI_SYSTEM_TABLE_SIGNATURE ((u64)0x5453595320494249ULL)
6111da177e4SLinus Torvalds 
6123b370237SMatthew Garrett #define EFI_2_30_SYSTEM_TABLE_REVISION  ((2 << 16) | (30))
6133b370237SMatthew Garrett #define EFI_2_20_SYSTEM_TABLE_REVISION  ((2 << 16) | (20))
6143b370237SMatthew Garrett #define EFI_2_10_SYSTEM_TABLE_REVISION  ((2 << 16) | (10))
6153b370237SMatthew Garrett #define EFI_2_00_SYSTEM_TABLE_REVISION  ((2 << 16) | (00))
6163b370237SMatthew Garrett #define EFI_1_10_SYSTEM_TABLE_REVISION  ((1 << 16) | (10))
6173b370237SMatthew Garrett #define EFI_1_02_SYSTEM_TABLE_REVISION  ((1 << 16) | (02))
6183b370237SMatthew Garrett 
6191da177e4SLinus Torvalds typedef struct {
6201da177e4SLinus Torvalds 	efi_table_hdr_t hdr;
6211adbfa35SOlof Johansson 	u64 fw_vendor;	/* physical addr of CHAR16 vendor string */
6221adbfa35SOlof Johansson 	u32 fw_revision;
6231adbfa35SOlof Johansson 	u32 __pad1;
6241adbfa35SOlof Johansson 	u64 con_in_handle;
6251adbfa35SOlof Johansson 	u64 con_in;
6261adbfa35SOlof Johansson 	u64 con_out_handle;
6271adbfa35SOlof Johansson 	u64 con_out;
6281adbfa35SOlof Johansson 	u64 stderr_handle;
6291adbfa35SOlof Johansson 	u64 stderr;
6301adbfa35SOlof Johansson 	u64 runtime;
6311adbfa35SOlof Johansson 	u64 boottime;
6321adbfa35SOlof Johansson 	u32 nr_tables;
6331adbfa35SOlof Johansson 	u32 __pad2;
6341adbfa35SOlof Johansson 	u64 tables;
6351adbfa35SOlof Johansson } efi_system_table_64_t;
6361adbfa35SOlof Johansson 
6371adbfa35SOlof Johansson typedef struct {
6381adbfa35SOlof Johansson 	efi_table_hdr_t hdr;
6391adbfa35SOlof Johansson 	u32 fw_vendor;	/* physical addr of CHAR16 vendor string */
6401adbfa35SOlof Johansson 	u32 fw_revision;
6411adbfa35SOlof Johansson 	u32 con_in_handle;
6421adbfa35SOlof Johansson 	u32 con_in;
6431adbfa35SOlof Johansson 	u32 con_out_handle;
6441adbfa35SOlof Johansson 	u32 con_out;
6451adbfa35SOlof Johansson 	u32 stderr_handle;
6461adbfa35SOlof Johansson 	u32 stderr;
6471adbfa35SOlof Johansson 	u32 runtime;
6481adbfa35SOlof Johansson 	u32 boottime;
6491adbfa35SOlof Johansson 	u32 nr_tables;
6501adbfa35SOlof Johansson 	u32 tables;
6511adbfa35SOlof Johansson } efi_system_table_32_t;
6521adbfa35SOlof Johansson 
6531adbfa35SOlof Johansson typedef struct {
6541adbfa35SOlof Johansson 	efi_table_hdr_t hdr;
6551da177e4SLinus Torvalds 	unsigned long fw_vendor;	/* physical addr of CHAR16 vendor string */
6561da177e4SLinus Torvalds 	u32 fw_revision;
6571da177e4SLinus Torvalds 	unsigned long con_in_handle;
6581da177e4SLinus Torvalds 	unsigned long con_in;
6591da177e4SLinus Torvalds 	unsigned long con_out_handle;
6601da177e4SLinus Torvalds 	unsigned long con_out;
6611da177e4SLinus Torvalds 	unsigned long stderr_handle;
6621da177e4SLinus Torvalds 	unsigned long stderr;
6631da177e4SLinus Torvalds 	efi_runtime_services_t *runtime;
664f30ca6baSMatt Fleming 	efi_boot_services_t *boottime;
6651da177e4SLinus Torvalds 	unsigned long nr_tables;
6661da177e4SLinus Torvalds 	unsigned long tables;
6671da177e4SLinus Torvalds } efi_system_table_t;
6681da177e4SLinus Torvalds 
6691da177e4SLinus Torvalds struct efi_memory_map {
6707ae65fd3SMatt Tolentino 	void *phys_map;
6717ae65fd3SMatt Tolentino 	void *map;
6727ae65fd3SMatt Tolentino 	void *map_end;
6731da177e4SLinus Torvalds 	int nr_map;
6741da177e4SLinus Torvalds 	unsigned long desc_version;
6757ae65fd3SMatt Tolentino 	unsigned long desc_size;
6761da177e4SLinus Torvalds };
6771da177e4SLinus Torvalds 
6780302f71cSMark Salter struct efi_fdt_params {
6790302f71cSMark Salter 	u64 system_table;
6800302f71cSMark Salter 	u64 mmap;
6810302f71cSMark Salter 	u32 mmap_size;
6820302f71cSMark Salter 	u32 desc_size;
6830302f71cSMark Salter 	u32 desc_ver;
6840302f71cSMark Salter };
6850302f71cSMark Salter 
6868e84f345SMatt Fleming typedef struct {
6878e84f345SMatt Fleming 	u32 revision;
688677703ceSMatt Fleming 	u32 parent_handle;
689677703ceSMatt Fleming 	u32 system_table;
690677703ceSMatt Fleming 	u32 device_handle;
691677703ceSMatt Fleming 	u32 file_path;
692677703ceSMatt Fleming 	u32 reserved;
693677703ceSMatt Fleming 	u32 load_options_size;
694677703ceSMatt Fleming 	u32 load_options;
695677703ceSMatt Fleming 	u32 image_base;
696677703ceSMatt Fleming 	__aligned_u64 image_size;
697677703ceSMatt Fleming 	unsigned int image_code_type;
698677703ceSMatt Fleming 	unsigned int image_data_type;
699677703ceSMatt Fleming 	unsigned long unload;
700677703ceSMatt Fleming } efi_loaded_image_32_t;
701677703ceSMatt Fleming 
702677703ceSMatt Fleming typedef struct {
703677703ceSMatt Fleming 	u32 revision;
704677703ceSMatt Fleming 	u64 parent_handle;
705677703ceSMatt Fleming 	u64 system_table;
706677703ceSMatt Fleming 	u64 device_handle;
707677703ceSMatt Fleming 	u64 file_path;
708677703ceSMatt Fleming 	u64 reserved;
709677703ceSMatt Fleming 	u32 load_options_size;
710677703ceSMatt Fleming 	u64 load_options;
711677703ceSMatt Fleming 	u64 image_base;
712677703ceSMatt Fleming 	__aligned_u64 image_size;
713677703ceSMatt Fleming 	unsigned int image_code_type;
714677703ceSMatt Fleming 	unsigned int image_data_type;
715677703ceSMatt Fleming 	unsigned long unload;
716677703ceSMatt Fleming } efi_loaded_image_64_t;
717677703ceSMatt Fleming 
718677703ceSMatt Fleming typedef struct {
719677703ceSMatt Fleming 	u32 revision;
7208e84f345SMatt Fleming 	void *parent_handle;
7218e84f345SMatt Fleming 	efi_system_table_t *system_table;
7228e84f345SMatt Fleming 	void *device_handle;
7238e84f345SMatt Fleming 	void *file_path;
7248e84f345SMatt Fleming 	void *reserved;
7258e84f345SMatt Fleming 	u32 load_options_size;
7268e84f345SMatt Fleming 	void *load_options;
7278e84f345SMatt Fleming 	void *image_base;
7288e84f345SMatt Fleming 	__aligned_u64 image_size;
7298e84f345SMatt Fleming 	unsigned int image_code_type;
7308e84f345SMatt Fleming 	unsigned int image_data_type;
7318e84f345SMatt Fleming 	unsigned long unload;
7328e84f345SMatt Fleming } efi_loaded_image_t;
7338e84f345SMatt Fleming 
73455839d51SMatt Fleming 
73555839d51SMatt Fleming typedef struct {
73655839d51SMatt Fleming 	u64 size;
73755839d51SMatt Fleming 	u64 file_size;
73855839d51SMatt Fleming 	u64 phys_size;
73955839d51SMatt Fleming 	efi_time_t create_time;
74055839d51SMatt Fleming 	efi_time_t last_access_time;
74155839d51SMatt Fleming 	efi_time_t modification_time;
74255839d51SMatt Fleming 	__aligned_u64 attribute;
74355839d51SMatt Fleming 	efi_char16_t filename[1];
74455839d51SMatt Fleming } efi_file_info_t;
74555839d51SMatt Fleming 
746677703ceSMatt Fleming typedef struct {
747677703ceSMatt Fleming 	u64 revision;
748677703ceSMatt Fleming 	u32 open;
749677703ceSMatt Fleming 	u32 close;
750677703ceSMatt Fleming 	u32 delete;
751677703ceSMatt Fleming 	u32 read;
752677703ceSMatt Fleming 	u32 write;
753677703ceSMatt Fleming 	u32 get_position;
754677703ceSMatt Fleming 	u32 set_position;
755677703ceSMatt Fleming 	u32 get_info;
756677703ceSMatt Fleming 	u32 set_info;
757677703ceSMatt Fleming 	u32 flush;
758677703ceSMatt Fleming } efi_file_handle_32_t;
759677703ceSMatt Fleming 
760677703ceSMatt Fleming typedef struct {
761677703ceSMatt Fleming 	u64 revision;
762677703ceSMatt Fleming 	u64 open;
763677703ceSMatt Fleming 	u64 close;
764677703ceSMatt Fleming 	u64 delete;
765677703ceSMatt Fleming 	u64 read;
766677703ceSMatt Fleming 	u64 write;
767677703ceSMatt Fleming 	u64 get_position;
768677703ceSMatt Fleming 	u64 set_position;
769677703ceSMatt Fleming 	u64 get_info;
770677703ceSMatt Fleming 	u64 set_info;
771677703ceSMatt Fleming 	u64 flush;
772677703ceSMatt Fleming } efi_file_handle_64_t;
773677703ceSMatt Fleming 
774ed37ddffSRoy Franz typedef struct _efi_file_handle {
77555839d51SMatt Fleming 	u64 revision;
776ed37ddffSRoy Franz 	efi_status_t (*open)(struct _efi_file_handle *,
777ed37ddffSRoy Franz 			     struct _efi_file_handle **,
778ed37ddffSRoy Franz 			     efi_char16_t *, u64, u64);
779ed37ddffSRoy Franz 	efi_status_t (*close)(struct _efi_file_handle *);
78055839d51SMatt Fleming 	void *delete;
781ed37ddffSRoy Franz 	efi_status_t (*read)(struct _efi_file_handle *, unsigned long *,
782ed37ddffSRoy Franz 			     void *);
78355839d51SMatt Fleming 	void *write;
78455839d51SMatt Fleming 	void *get_position;
78555839d51SMatt Fleming 	void *set_position;
786ed37ddffSRoy Franz 	efi_status_t (*get_info)(struct _efi_file_handle *, efi_guid_t *,
787ed37ddffSRoy Franz 			unsigned long *, void *);
78855839d51SMatt Fleming 	void *set_info;
78955839d51SMatt Fleming 	void *flush;
79055839d51SMatt Fleming } efi_file_handle_t;
79155839d51SMatt Fleming 
792ed37ddffSRoy Franz typedef struct _efi_file_io_interface {
793ed37ddffSRoy Franz 	u64 revision;
794ed37ddffSRoy Franz 	int (*open_volume)(struct _efi_file_io_interface *,
795ed37ddffSRoy Franz 			   efi_file_handle_t **);
796ed37ddffSRoy Franz } efi_file_io_interface_t;
797ed37ddffSRoy Franz 
79855839d51SMatt Fleming #define EFI_FILE_MODE_READ	0x0000000000000001
79955839d51SMatt Fleming #define EFI_FILE_MODE_WRITE	0x0000000000000002
80055839d51SMatt Fleming #define EFI_FILE_MODE_CREATE	0x8000000000000000
80155839d51SMatt Fleming 
802b2c99e3cSBjorn Helgaas #define EFI_INVALID_TABLE_ADDR		(~0UL)
803b2c99e3cSBjorn Helgaas 
8041da177e4SLinus Torvalds /*
8051da177e4SLinus Torvalds  * All runtime access to EFI goes through this structure:
8061da177e4SLinus Torvalds  */
8071da177e4SLinus Torvalds extern struct efi {
8081da177e4SLinus Torvalds 	efi_system_table_t *systab;	/* EFI system table */
8093b370237SMatthew Garrett 	unsigned int runtime_version;	/* Runtime services version */
810b2c99e3cSBjorn Helgaas 	unsigned long mps;		/* MPS table */
811b2c99e3cSBjorn Helgaas 	unsigned long acpi;		/* ACPI table  (IA64 ext 0.71) */
812b2c99e3cSBjorn Helgaas 	unsigned long acpi20;		/* ACPI table  (ACPI 2.0) */
813b2c99e3cSBjorn Helgaas 	unsigned long smbios;		/* SM BIOS table */
814b2c99e3cSBjorn Helgaas 	unsigned long sal_systab;	/* SAL system table */
815b2c99e3cSBjorn Helgaas 	unsigned long boot_info;	/* boot info table */
816b2c99e3cSBjorn Helgaas 	unsigned long hcdp;		/* HCDP table */
817b2c99e3cSBjorn Helgaas 	unsigned long uga;		/* UGA table */
818a50f70b1SRuss Anderson 	unsigned long uv_systab;	/* UV system table */
819a0998eb1SDave Young 	unsigned long fw_vendor;	/* fw_vendor */
820a0998eb1SDave Young 	unsigned long runtime;		/* runtime table */
821a0998eb1SDave Young 	unsigned long config_table;	/* config tables */
8221da177e4SLinus Torvalds 	efi_get_time_t *get_time;
8231da177e4SLinus Torvalds 	efi_set_time_t *set_time;
8241da177e4SLinus Torvalds 	efi_get_wakeup_time_t *get_wakeup_time;
8251da177e4SLinus Torvalds 	efi_set_wakeup_time_t *set_wakeup_time;
8261da177e4SLinus Torvalds 	efi_get_variable_t *get_variable;
8271da177e4SLinus Torvalds 	efi_get_next_variable_t *get_next_variable;
8281da177e4SLinus Torvalds 	efi_set_variable_t *set_variable;
829*6d80dba1SMatt Fleming 	efi_set_variable_nonblocking_t *set_variable_nonblocking;
8303b370237SMatthew Garrett 	efi_query_variable_info_t *query_variable_info;
8313b370237SMatthew Garrett 	efi_update_capsule_t *update_capsule;
8323b370237SMatthew Garrett 	efi_query_capsule_caps_t *query_capsule_caps;
8331da177e4SLinus Torvalds 	efi_get_next_high_mono_count_t *get_next_high_mono_count;
8341da177e4SLinus Torvalds 	efi_reset_system_t *reset_system;
8351da177e4SLinus Torvalds 	efi_set_virtual_address_map_t *set_virtual_address_map;
836258f6fd7SLeif Lindholm 	struct efi_memory_map *memmap;
8373e909599SMatt Fleming 	unsigned long flags;
8381da177e4SLinus Torvalds } efi;
8391da177e4SLinus Torvalds 
8401da177e4SLinus Torvalds static inline int
8411da177e4SLinus Torvalds efi_guidcmp (efi_guid_t left, efi_guid_t right)
8421da177e4SLinus Torvalds {
8431da177e4SLinus Torvalds 	return memcmp(&left, &right, sizeof (efi_guid_t));
8441da177e4SLinus Torvalds }
8451da177e4SLinus Torvalds 
8461da177e4SLinus Torvalds static inline char *
8471da177e4SLinus Torvalds efi_guid_unparse(efi_guid_t *guid, char *out)
8481da177e4SLinus Torvalds {
849925ede0bSJoe Perches 	sprintf(out, "%pUl", guid->b);
8501da177e4SLinus Torvalds         return out;
8511da177e4SLinus Torvalds }
8521da177e4SLinus Torvalds 
8531da177e4SLinus Torvalds extern void efi_init (void);
8541da177e4SLinus Torvalds extern void *efi_get_pal_addr (void);
8551da177e4SLinus Torvalds extern void efi_map_pal_code (void);
8561da177e4SLinus Torvalds extern void efi_memmap_walk (efi_freemem_callback_t callback, void *arg);
8571da177e4SLinus Torvalds extern void efi_gettimeofday (struct timespec *ts);
8581da177e4SLinus Torvalds extern void efi_enter_virtual_mode (void);	/* switch EFI to virtual mode, if possible */
85978510792SJosh Triplett #ifdef CONFIG_X86
8602223af38SJosh Triplett extern void efi_late_init(void);
86178510792SJosh Triplett extern void efi_free_boot_services(void);
862a6e4d5a0SMatt Fleming extern efi_status_t efi_query_variable_store(u32 attributes, unsigned long size);
86378510792SJosh Triplett #else
8642223af38SJosh Triplett static inline void efi_late_init(void) {}
86578510792SJosh Triplett static inline void efi_free_boot_services(void) {}
866a6e4d5a0SMatt Fleming 
867a6e4d5a0SMatt Fleming static inline efi_status_t efi_query_variable_store(u32 attributes, unsigned long size)
868a6e4d5a0SMatt Fleming {
869a6e4d5a0SMatt Fleming 	return EFI_SUCCESS;
870a6e4d5a0SMatt Fleming }
87178510792SJosh Triplett #endif
8727bc90e01SJosh Triplett extern void __iomem *efi_lookup_mapped_addr(u64 phys_addr);
873272686bfSLeif Lindholm extern int efi_config_init(efi_config_table_type_t *arch_tables);
8741da177e4SLinus Torvalds extern u64 efi_get_iobase (void);
8751da177e4SLinus Torvalds extern u32 efi_mem_type (unsigned long phys_addr);
8761da177e4SLinus Torvalds extern u64 efi_mem_attributes (unsigned long phys_addr);
87732e62c63SBjorn Helgaas extern u64 efi_mem_attribute (unsigned long phys_addr, unsigned long size);
8781da177e4SLinus Torvalds extern int __init efi_uart_console_only (void);
8791da177e4SLinus Torvalds extern void efi_initialize_iomem_resources(struct resource *code_resource,
88000bf4098SBernhard Walle 		struct resource *data_resource, struct resource *bss_resource);
8813565184eSDavid Vrabel extern void efi_get_time(struct timespec *now);
882916f676fSMatthew Garrett extern void efi_reserve_boot_services(void);
8830302f71cSMark Salter extern int efi_get_fdt_params(struct efi_fdt_params *params, int verbose);
8841da177e4SLinus Torvalds extern struct efi_memory_map memmap;
8851da177e4SLinus Torvalds 
88644be28e9SMatt Fleming extern int efi_reboot_quirk_mode;
8870c5ed61aSMatt Fleming extern bool efi_poweroff_required(void);
8880c5ed61aSMatt Fleming 
889e885cd80SMark Salter /* Iterate through an efi_memory_map */
890e885cd80SMark Salter #define for_each_efi_memory_desc(m, md)					   \
891e885cd80SMark Salter 	for ((md) = (m)->map;						   \
892e885cd80SMark Salter 	     (md) <= (efi_memory_desc_t *)((m)->map_end - (m)->desc_size); \
893e885cd80SMark Salter 	     (md) = (void *)(md) + (m)->desc_size)
894e885cd80SMark Salter 
89598d2a6caSLaszlo Ersek /*
89698d2a6caSLaszlo Ersek  * Format an EFI memory descriptor's type and attributes to a user-provided
89798d2a6caSLaszlo Ersek  * character buffer, as per snprintf(), and return the buffer.
89898d2a6caSLaszlo Ersek  */
89998d2a6caSLaszlo Ersek char * __init efi_md_typeattr_format(char *buf, size_t size,
90098d2a6caSLaszlo Ersek 				     const efi_memory_desc_t *md);
90198d2a6caSLaszlo Ersek 
9021da177e4SLinus Torvalds /**
9031da177e4SLinus Torvalds  * efi_range_is_wc - check the WC bit on an address range
9041da177e4SLinus Torvalds  * @start: starting kvirt address
9051da177e4SLinus Torvalds  * @len: length of range
9061da177e4SLinus Torvalds  *
9071da177e4SLinus Torvalds  * Consult the EFI memory map and make sure it's ok to set this range WC.
9081da177e4SLinus Torvalds  * Returns true or false.
9091da177e4SLinus Torvalds  */
9101da177e4SLinus Torvalds static inline int efi_range_is_wc(unsigned long start, unsigned long len)
9111da177e4SLinus Torvalds {
912986a80d5SJesper Juhl 	unsigned long i;
9131da177e4SLinus Torvalds 
9141da177e4SLinus Torvalds 	for (i = 0; i < len; i += (1UL << EFI_PAGE_SHIFT)) {
9151da177e4SLinus Torvalds 		unsigned long paddr = __pa(start + i);
9161da177e4SLinus Torvalds 		if (!(efi_mem_attributes(paddr) & EFI_MEMORY_WC))
9171da177e4SLinus Torvalds 			return 0;
9181da177e4SLinus Torvalds 	}
9191da177e4SLinus Torvalds 	/* The range checked out */
9201da177e4SLinus Torvalds 	return 1;
9211da177e4SLinus Torvalds }
9221da177e4SLinus Torvalds 
9231da177e4SLinus Torvalds #ifdef CONFIG_EFI_PCDP
9241da177e4SLinus Torvalds extern int __init efi_setup_pcdp_console(char *);
9251da177e4SLinus Torvalds #endif
9261da177e4SLinus Torvalds 
9271da177e4SLinus Torvalds /*
92883e68189SMatt Fleming  * We play games with efi_enabled so that the compiler will, if
92983e68189SMatt Fleming  * possible, remove EFI-related code altogether.
9301da177e4SLinus Torvalds  */
93183e68189SMatt Fleming #define EFI_BOOT		0	/* Were we booted from EFI? */
93283e68189SMatt Fleming #define EFI_SYSTEM_TABLES	1	/* Can we use EFI system tables? */
93383e68189SMatt Fleming #define EFI_CONFIG_TABLES	2	/* Can we use EFI config tables? */
93483e68189SMatt Fleming #define EFI_RUNTIME_SERVICES	3	/* Can we use runtime services? */
93583e68189SMatt Fleming #define EFI_MEMMAP		4	/* Can we use EFI memory map? */
93683e68189SMatt Fleming #define EFI_64BIT		5	/* Is the firmware 64-bit? */
9379f27bc54SDaniel Kiper #define EFI_PARAVIRT		6	/* Access is via a paravirt interface */
9389f27bc54SDaniel Kiper #define EFI_ARCH_1		7	/* First arch-specific bit */
93983e68189SMatt Fleming 
9401da177e4SLinus Torvalds #ifdef CONFIG_EFI
9413e909599SMatt Fleming /*
9423e909599SMatt Fleming  * Test whether the above EFI_* bits are enabled.
9433e909599SMatt Fleming  */
9443e909599SMatt Fleming static inline bool efi_enabled(int feature)
94583e68189SMatt Fleming {
9463e909599SMatt Fleming 	return test_bit(feature, &efi.flags) != 0;
9473e909599SMatt Fleming }
9488562c99cSMatt Fleming extern void efi_reboot(enum reboot_mode reboot_mode, const char *__unused);
9493e909599SMatt Fleming #else
9503e909599SMatt Fleming static inline bool efi_enabled(int feature)
9513e909599SMatt Fleming {
9523e909599SMatt Fleming 	return false;
95383e68189SMatt Fleming }
9548562c99cSMatt Fleming static inline void
9558562c99cSMatt Fleming efi_reboot(enum reboot_mode reboot_mode, const char *__unused) {}
9561da177e4SLinus Torvalds #endif
9571da177e4SLinus Torvalds 
9581da177e4SLinus Torvalds /*
9591da177e4SLinus Torvalds  * Variable Attributes
9601da177e4SLinus Torvalds  */
9611da177e4SLinus Torvalds #define EFI_VARIABLE_NON_VOLATILE       0x0000000000000001
9621da177e4SLinus Torvalds #define EFI_VARIABLE_BOOTSERVICE_ACCESS 0x0000000000000002
9631da177e4SLinus Torvalds #define EFI_VARIABLE_RUNTIME_ACCESS     0x0000000000000004
96441b3254cSMatthew Garrett #define EFI_VARIABLE_HARDWARE_ERROR_RECORD 0x0000000000000008
96541b3254cSMatthew Garrett #define EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS 0x0000000000000010
96641b3254cSMatthew Garrett #define EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS 0x0000000000000020
96741b3254cSMatthew Garrett #define EFI_VARIABLE_APPEND_WRITE	0x0000000000000040
9681da177e4SLinus Torvalds 
96941b3254cSMatthew Garrett #define EFI_VARIABLE_MASK 	(EFI_VARIABLE_NON_VOLATILE | \
97041b3254cSMatthew Garrett 				EFI_VARIABLE_BOOTSERVICE_ACCESS | \
97141b3254cSMatthew Garrett 				EFI_VARIABLE_RUNTIME_ACCESS | \
97241b3254cSMatthew Garrett 				EFI_VARIABLE_HARDWARE_ERROR_RECORD | \
97341b3254cSMatthew Garrett 				EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS | \
97441b3254cSMatthew Garrett 				EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS | \
97541b3254cSMatthew Garrett 				EFI_VARIABLE_APPEND_WRITE)
9761da177e4SLinus Torvalds /*
977e14ab23dSMatt Fleming  * Length of a GUID string (strlen("aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee"))
978e14ab23dSMatt Fleming  * not including trailing NUL
979e14ab23dSMatt Fleming  */
980e14ab23dSMatt Fleming #define EFI_VARIABLE_GUID_LEN 36
981e14ab23dSMatt Fleming 
982e14ab23dSMatt Fleming /*
983e2527a7cSMatt Fleming  * The type of search to perform when calling boottime->locate_handle
984e2527a7cSMatt Fleming  */
985e2527a7cSMatt Fleming #define EFI_LOCATE_ALL_HANDLES			0
986e2527a7cSMatt Fleming #define EFI_LOCATE_BY_REGISTER_NOTIFY		1
987e2527a7cSMatt Fleming #define EFI_LOCATE_BY_PROTOCOL			2
988e2527a7cSMatt Fleming 
989e2527a7cSMatt Fleming /*
9901da177e4SLinus Torvalds  * EFI Device Path information
9911da177e4SLinus Torvalds  */
9921da177e4SLinus Torvalds #define EFI_DEV_HW			0x01
9931da177e4SLinus Torvalds #define  EFI_DEV_PCI				 1
9941da177e4SLinus Torvalds #define  EFI_DEV_PCCARD				 2
9951da177e4SLinus Torvalds #define  EFI_DEV_MEM_MAPPED			 3
9961da177e4SLinus Torvalds #define  EFI_DEV_VENDOR				 4
9971da177e4SLinus Torvalds #define  EFI_DEV_CONTROLLER			 5
9981da177e4SLinus Torvalds #define EFI_DEV_ACPI			0x02
9991da177e4SLinus Torvalds #define   EFI_DEV_BASIC_ACPI			 1
10001da177e4SLinus Torvalds #define   EFI_DEV_EXPANDED_ACPI			 2
10011da177e4SLinus Torvalds #define EFI_DEV_MSG			0x03
10021da177e4SLinus Torvalds #define   EFI_DEV_MSG_ATAPI			 1
10031da177e4SLinus Torvalds #define   EFI_DEV_MSG_SCSI			 2
10041da177e4SLinus Torvalds #define   EFI_DEV_MSG_FC			 3
10051da177e4SLinus Torvalds #define   EFI_DEV_MSG_1394			 4
10061da177e4SLinus Torvalds #define   EFI_DEV_MSG_USB			 5
10071da177e4SLinus Torvalds #define   EFI_DEV_MSG_USB_CLASS			15
10081da177e4SLinus Torvalds #define   EFI_DEV_MSG_I20			 6
10091da177e4SLinus Torvalds #define   EFI_DEV_MSG_MAC			11
10101da177e4SLinus Torvalds #define   EFI_DEV_MSG_IPV4			12
10111da177e4SLinus Torvalds #define   EFI_DEV_MSG_IPV6			13
10121da177e4SLinus Torvalds #define   EFI_DEV_MSG_INFINIBAND		 9
10131da177e4SLinus Torvalds #define   EFI_DEV_MSG_UART			14
10141da177e4SLinus Torvalds #define   EFI_DEV_MSG_VENDOR			10
10151da177e4SLinus Torvalds #define EFI_DEV_MEDIA			0x04
10161da177e4SLinus Torvalds #define   EFI_DEV_MEDIA_HARD_DRIVE		 1
10171da177e4SLinus Torvalds #define   EFI_DEV_MEDIA_CDROM			 2
10181da177e4SLinus Torvalds #define   EFI_DEV_MEDIA_VENDOR			 3
10191da177e4SLinus Torvalds #define   EFI_DEV_MEDIA_FILE			 4
10201da177e4SLinus Torvalds #define   EFI_DEV_MEDIA_PROTOCOL		 5
10211da177e4SLinus Torvalds #define EFI_DEV_BIOS_BOOT		0x05
10221da177e4SLinus Torvalds #define EFI_DEV_END_PATH		0x7F
10231da177e4SLinus Torvalds #define EFI_DEV_END_PATH2		0xFF
10241da177e4SLinus Torvalds #define   EFI_DEV_END_INSTANCE			0x01
10251da177e4SLinus Torvalds #define   EFI_DEV_END_ENTIRE			0xFF
10261da177e4SLinus Torvalds 
10271da177e4SLinus Torvalds struct efi_generic_dev_path {
10281da177e4SLinus Torvalds 	u8 type;
10291da177e4SLinus Torvalds 	u8 sub_type;
10301da177e4SLinus Torvalds 	u16 length;
10311da177e4SLinus Torvalds } __attribute ((packed));
10321da177e4SLinus Torvalds 
10334a3575fdSHuang, Ying static inline void memrange_efi_to_native(u64 *addr, u64 *npages)
10344a3575fdSHuang, Ying {
10354a3575fdSHuang, Ying 	*npages = PFN_UP(*addr + (*npages<<EFI_PAGE_SHIFT)) - PFN_DOWN(*addr);
10364a3575fdSHuang, Ying 	*addr &= PAGE_MASK;
10374a3575fdSHuang, Ying }
10384a3575fdSHuang, Ying 
103904851772SMatt Fleming /*
10404fc756bdSMike Waychison  * EFI Variable support.
10414fc756bdSMike Waychison  *
10424fc756bdSMike Waychison  * Different firmware drivers can expose their EFI-like variables using
10434fc756bdSMike Waychison  * the following.
10444fc756bdSMike Waychison  */
10454fc756bdSMike Waychison 
10464fc756bdSMike Waychison struct efivar_operations {
10474fc756bdSMike Waychison 	efi_get_variable_t *get_variable;
10484fc756bdSMike Waychison 	efi_get_next_variable_t *get_next_variable;
10494fc756bdSMike Waychison 	efi_set_variable_t *set_variable;
1050*6d80dba1SMatt Fleming 	efi_set_variable_nonblocking_t *set_variable_nonblocking;
1051a6e4d5a0SMatt Fleming 	efi_query_variable_store_t *query_variable_store;
10524fc756bdSMike Waychison };
10534fc756bdSMike Waychison 
10544fc756bdSMike Waychison struct efivars {
10554fc756bdSMike Waychison 	/*
10564fc756bdSMike Waychison 	 * ->lock protects two things:
105782f990a8SMatt Fleming 	 * 1) efivarfs_list and efivars_sysfs_list
105882f990a8SMatt Fleming 	 * 2) ->ops calls
10594fc756bdSMike Waychison 	 */
10604fc756bdSMike Waychison 	spinlock_t lock;
10614fc756bdSMike Waychison 	struct kset *kset;
1062605e70c7SLee, Chun-Yi 	struct kobject *kobject;
10634fc756bdSMike Waychison 	const struct efivar_operations *ops;
10644fc756bdSMike Waychison };
10654fc756bdSMike Waychison 
1066e14ab23dSMatt Fleming /*
1067e14ab23dSMatt Fleming  * The maximum size of VariableName + Data = 1024
1068e14ab23dSMatt Fleming  * Therefore, it's reasonable to save that much
1069e14ab23dSMatt Fleming  * space in each part of the structure,
1070e14ab23dSMatt Fleming  * and we use a page for reading/writing.
1071e14ab23dSMatt Fleming  */
1072e14ab23dSMatt Fleming 
1073a5d92ad3SMatt Fleming #define EFI_VAR_NAME_LEN	1024
1074a5d92ad3SMatt Fleming 
1075e14ab23dSMatt Fleming struct efi_variable {
1076a5d92ad3SMatt Fleming 	efi_char16_t  VariableName[EFI_VAR_NAME_LEN/sizeof(efi_char16_t)];
1077e14ab23dSMatt Fleming 	efi_guid_t    VendorGuid;
1078e14ab23dSMatt Fleming 	unsigned long DataSize;
1079e14ab23dSMatt Fleming 	__u8          Data[1024];
1080e14ab23dSMatt Fleming 	efi_status_t  Status;
1081e14ab23dSMatt Fleming 	__u32         Attributes;
1082e14ab23dSMatt Fleming } __attribute__((packed));
1083e14ab23dSMatt Fleming 
1084e14ab23dSMatt Fleming struct efivar_entry {
1085e14ab23dSMatt Fleming 	struct efi_variable var;
1086e14ab23dSMatt Fleming 	struct list_head list;
1087e14ab23dSMatt Fleming 	struct kobject kobj;
1088e0d59733SSeiji Aguchi 	bool scanning;
1089e0d59733SSeiji Aguchi 	bool deleting;
1090e14ab23dSMatt Fleming };
1091e14ab23dSMatt Fleming 
1092677703ceSMatt Fleming struct efi_simple_text_output_protocol_32 {
1093677703ceSMatt Fleming 	u32 reset;
1094677703ceSMatt Fleming 	u32 output_string;
1095677703ceSMatt Fleming 	u32 test_string;
1096677703ceSMatt Fleming };
1097677703ceSMatt Fleming 
1098677703ceSMatt Fleming struct efi_simple_text_output_protocol_64 {
1099677703ceSMatt Fleming 	u64 reset;
1100677703ceSMatt Fleming 	u64 output_string;
1101677703ceSMatt Fleming 	u64 test_string;
1102677703ceSMatt Fleming };
1103ed37ddffSRoy Franz 
1104ed37ddffSRoy Franz struct efi_simple_text_output_protocol {
1105ed37ddffSRoy Franz 	void *reset;
1106ed37ddffSRoy Franz 	efi_status_t (*output_string)(void *, void *);
1107ed37ddffSRoy Franz 	void *test_string;
1108ed37ddffSRoy Franz };
1109ed37ddffSRoy Franz 
111004851772SMatt Fleming extern struct list_head efivar_sysfs_list;
111104851772SMatt Fleming 
111204851772SMatt Fleming static inline void
111304851772SMatt Fleming efivar_unregister(struct efivar_entry *var)
111404851772SMatt Fleming {
111504851772SMatt Fleming 	kobject_put(&var->kobj);
111604851772SMatt Fleming }
111704851772SMatt Fleming 
1118e14ab23dSMatt Fleming int efivars_register(struct efivars *efivars,
11194fc756bdSMike Waychison 		     const struct efivar_operations *ops,
1120e14ab23dSMatt Fleming 		     struct kobject *kobject);
1121e14ab23dSMatt Fleming int efivars_unregister(struct efivars *efivars);
1122e14ab23dSMatt Fleming struct kobject *efivars_kobject(void);
1123e14ab23dSMatt Fleming 
1124e14ab23dSMatt Fleming int efivar_init(int (*func)(efi_char16_t *, efi_guid_t, unsigned long, void *),
1125e14ab23dSMatt Fleming 		void *data, bool atomic, bool duplicates,
1126e14ab23dSMatt Fleming 		struct list_head *head);
1127e14ab23dSMatt Fleming 
1128e14ab23dSMatt Fleming void efivar_entry_add(struct efivar_entry *entry, struct list_head *head);
1129e14ab23dSMatt Fleming void efivar_entry_remove(struct efivar_entry *entry);
1130e14ab23dSMatt Fleming 
1131e14ab23dSMatt Fleming int __efivar_entry_delete(struct efivar_entry *entry);
1132e14ab23dSMatt Fleming int efivar_entry_delete(struct efivar_entry *entry);
1133e14ab23dSMatt Fleming 
1134e14ab23dSMatt Fleming int efivar_entry_size(struct efivar_entry *entry, unsigned long *size);
11358a415b8cSMatt Fleming int __efivar_entry_get(struct efivar_entry *entry, u32 *attributes,
11368a415b8cSMatt Fleming 		       unsigned long *size, void *data);
1137e14ab23dSMatt Fleming int efivar_entry_get(struct efivar_entry *entry, u32 *attributes,
1138e14ab23dSMatt Fleming 		     unsigned long *size, void *data);
1139e14ab23dSMatt Fleming int efivar_entry_set(struct efivar_entry *entry, u32 attributes,
1140e14ab23dSMatt Fleming 		     unsigned long size, void *data, struct list_head *head);
1141e14ab23dSMatt Fleming int efivar_entry_set_get_size(struct efivar_entry *entry, u32 attributes,
1142e14ab23dSMatt Fleming 			      unsigned long *size, void *data, bool *set);
1143e14ab23dSMatt Fleming int efivar_entry_set_safe(efi_char16_t *name, efi_guid_t vendor, u32 attributes,
1144e14ab23dSMatt Fleming 			  bool block, unsigned long size, void *data);
1145e14ab23dSMatt Fleming 
1146e14ab23dSMatt Fleming void efivar_entry_iter_begin(void);
1147e14ab23dSMatt Fleming void efivar_entry_iter_end(void);
1148e14ab23dSMatt Fleming 
1149e14ab23dSMatt Fleming int __efivar_entry_iter(int (*func)(struct efivar_entry *, void *),
1150e14ab23dSMatt Fleming 			struct list_head *head, void *data,
1151e14ab23dSMatt Fleming 			struct efivar_entry **prev);
1152e14ab23dSMatt Fleming int efivar_entry_iter(int (*func)(struct efivar_entry *, void *),
1153e14ab23dSMatt Fleming 		      struct list_head *head, void *data);
1154e14ab23dSMatt Fleming 
1155e14ab23dSMatt Fleming struct efivar_entry *efivar_entry_find(efi_char16_t *name, efi_guid_t guid,
1156e14ab23dSMatt Fleming 				       struct list_head *head, bool remove);
1157e14ab23dSMatt Fleming 
1158a5d92ad3SMatt Fleming bool efivar_validate(efi_char16_t *var_name, u8 *data, unsigned long len);
1159e14ab23dSMatt Fleming 
1160a9499fa7STom Gundersen extern struct work_struct efivar_work;
116104851772SMatt Fleming void efivar_run_worker(void);
116204851772SMatt Fleming 
1163a9499fa7STom Gundersen #if defined(CONFIG_EFI_VARS) || defined(CONFIG_EFI_VARS_MODULE)
1164e14ab23dSMatt Fleming int efivars_sysfs_init(void);
11654fc756bdSMike Waychison 
1166e0d59733SSeiji Aguchi #define EFIVARS_DATA_SIZE_MAX 1024
1167e0d59733SSeiji Aguchi 
11684fc756bdSMike Waychison #endif /* CONFIG_EFI_VARS */
11694fc756bdSMike Waychison 
1170926172d4SDave Young #ifdef CONFIG_EFI_RUNTIME_MAP
1171926172d4SDave Young int efi_runtime_map_init(struct kobject *);
1172926172d4SDave Young void efi_runtime_map_setup(void *, int, u32);
11736a2c20e7SVivek Goyal int efi_get_runtime_map_size(void);
11746a2c20e7SVivek Goyal int efi_get_runtime_map_desc_size(void);
11756a2c20e7SVivek Goyal int efi_runtime_map_copy(void *buf, size_t bufsz);
1176926172d4SDave Young #else
1177926172d4SDave Young static inline int efi_runtime_map_init(struct kobject *kobj)
1178926172d4SDave Young {
1179926172d4SDave Young 	return 0;
1180926172d4SDave Young }
1181926172d4SDave Young 
1182926172d4SDave Young static inline void
1183926172d4SDave Young efi_runtime_map_setup(void *map, int nr_entries, u32 desc_size) {}
11846a2c20e7SVivek Goyal 
11856a2c20e7SVivek Goyal static inline int efi_get_runtime_map_size(void)
11866a2c20e7SVivek Goyal {
11876a2c20e7SVivek Goyal 	return 0;
11886a2c20e7SVivek Goyal }
11896a2c20e7SVivek Goyal 
11906a2c20e7SVivek Goyal static inline int efi_get_runtime_map_desc_size(void)
11916a2c20e7SVivek Goyal {
11926a2c20e7SVivek Goyal 	return 0;
11936a2c20e7SVivek Goyal }
11946a2c20e7SVivek Goyal 
11956a2c20e7SVivek Goyal static inline int efi_runtime_map_copy(void *buf, size_t bufsz)
11966a2c20e7SVivek Goyal {
11976a2c20e7SVivek Goyal 	return 0;
11986a2c20e7SVivek Goyal }
11996a2c20e7SVivek Goyal 
1200926172d4SDave Young #endif
1201926172d4SDave Young 
1202bd669475SArd Biesheuvel /* prototypes shared between arch specific and generic stub code */
1203bd669475SArd Biesheuvel 
1204bd669475SArd Biesheuvel #define pr_efi(sys_table, msg)     efi_printk(sys_table, "EFI stub: "msg)
1205bd669475SArd Biesheuvel #define pr_efi_err(sys_table, msg) efi_printk(sys_table, "EFI stub: ERROR: "msg)
1206bd669475SArd Biesheuvel 
1207bd669475SArd Biesheuvel void efi_printk(efi_system_table_t *sys_table_arg, char *str);
1208bd669475SArd Biesheuvel 
1209bd669475SArd Biesheuvel void efi_free(efi_system_table_t *sys_table_arg, unsigned long size,
1210bd669475SArd Biesheuvel 	      unsigned long addr);
1211bd669475SArd Biesheuvel 
1212bd669475SArd Biesheuvel char *efi_convert_cmdline(efi_system_table_t *sys_table_arg,
1213bd669475SArd Biesheuvel 			  efi_loaded_image_t *image, int *cmd_line_len);
1214bd669475SArd Biesheuvel 
1215bd669475SArd Biesheuvel efi_status_t efi_get_memory_map(efi_system_table_t *sys_table_arg,
1216bd669475SArd Biesheuvel 				efi_memory_desc_t **map,
1217bd669475SArd Biesheuvel 				unsigned long *map_size,
1218bd669475SArd Biesheuvel 				unsigned long *desc_size,
1219bd669475SArd Biesheuvel 				u32 *desc_ver,
1220bd669475SArd Biesheuvel 				unsigned long *key_ptr);
1221bd669475SArd Biesheuvel 
1222bd669475SArd Biesheuvel efi_status_t efi_low_alloc(efi_system_table_t *sys_table_arg,
1223bd669475SArd Biesheuvel 			   unsigned long size, unsigned long align,
1224bd669475SArd Biesheuvel 			   unsigned long *addr);
1225bd669475SArd Biesheuvel 
1226bd669475SArd Biesheuvel efi_status_t efi_high_alloc(efi_system_table_t *sys_table_arg,
1227bd669475SArd Biesheuvel 			    unsigned long size, unsigned long align,
1228bd669475SArd Biesheuvel 			    unsigned long *addr, unsigned long max);
1229bd669475SArd Biesheuvel 
1230bd669475SArd Biesheuvel efi_status_t efi_relocate_kernel(efi_system_table_t *sys_table_arg,
1231bd669475SArd Biesheuvel 				 unsigned long *image_addr,
1232bd669475SArd Biesheuvel 				 unsigned long image_size,
1233bd669475SArd Biesheuvel 				 unsigned long alloc_size,
1234bd669475SArd Biesheuvel 				 unsigned long preferred_addr,
1235bd669475SArd Biesheuvel 				 unsigned long alignment);
1236bd669475SArd Biesheuvel 
1237bd669475SArd Biesheuvel efi_status_t handle_cmdline_files(efi_system_table_t *sys_table_arg,
1238bd669475SArd Biesheuvel 				  efi_loaded_image_t *image,
1239bd669475SArd Biesheuvel 				  char *cmd_line, char *option_string,
1240bd669475SArd Biesheuvel 				  unsigned long max_addr,
1241bd669475SArd Biesheuvel 				  unsigned long *load_addr,
1242bd669475SArd Biesheuvel 				  unsigned long *load_size);
1243bd669475SArd Biesheuvel 
12445a17dae4SMatt Fleming efi_status_t efi_parse_options(char *cmdline);
12455a17dae4SMatt Fleming 
1246b2e0a54aSDave Young bool efi_runtime_disabled(void);
12471da177e4SLinus Torvalds #endif /* _LINUX_EFI_H */
1248