xref: /openbmc/u-boot/include/efi.h (revision e35171e9)
104a0f563SHeinrich Schuchardt /* SPDX-License-Identifier: GPL-2.0 */
2867a6ac8SSimon Glass /*
3867a6ac8SSimon Glass  * Extensible Firmware Interface
4867a6ac8SSimon Glass  * Based on 'Extensible Firmware Interface Specification' version 0.9,
5867a6ac8SSimon Glass  * April 30, 1999
6867a6ac8SSimon Glass  *
7867a6ac8SSimon Glass  * Copyright (C) 1999 VA Linux Systems
8867a6ac8SSimon Glass  * Copyright (C) 1999 Walt Drummond <drummond@valinux.com>
9867a6ac8SSimon Glass  * Copyright (C) 1999, 2002-2003 Hewlett-Packard Co.
10867a6ac8SSimon Glass  *	David Mosberger-Tang <davidm@hpl.hp.com>
11867a6ac8SSimon Glass  *	Stephane Eranian <eranian@hpl.hp.com>
12867a6ac8SSimon Glass  *
13867a6ac8SSimon Glass  * From include/linux/efi.h in kernel 4.1 with some additions/subtractions
14867a6ac8SSimon Glass  */
15867a6ac8SSimon Glass 
16867a6ac8SSimon Glass #ifndef _EFI_H
17867a6ac8SSimon Glass #define _EFI_H
18867a6ac8SSimon Glass 
19a0b49bc3SSimon Glass #include <linux/linkage.h>
20867a6ac8SSimon Glass #include <linux/string.h>
21867a6ac8SSimon Glass #include <linux/types.h>
22867a6ac8SSimon Glass 
2301866446SAlexander Graf /*
2401866446SAlexander Graf  * EFI on x86_64 uses the Microsoft ABI which is not the default for GCC.
2501866446SAlexander Graf  *
2601866446SAlexander Graf  * There are two scenarios for EFI on x86_64: building a 64-bit EFI stub
2701866446SAlexander Graf  * codes (CONFIG_EFI_STUB_64BIT) and building a 64-bit U-Boot (CONFIG_X86_64).
2801866446SAlexander Graf  * Either needs to be properly built with the '-m64' compiler flag, and hence
2901866446SAlexander Graf  * it is enough to only check the compiler provided define __x86_64__ here.
3001866446SAlexander Graf  */
3101866446SAlexander Graf #ifdef __x86_64__
3296a8d409SSimon Glass #define EFIAPI __attribute__((ms_abi))
33beb077a2SAlexander Graf #define efi_va_list __builtin_ms_va_list
34beb077a2SAlexander Graf #define efi_va_start __builtin_ms_va_start
35beb077a2SAlexander Graf #define efi_va_arg __builtin_va_arg
36beb077a2SAlexander Graf #define efi_va_end __builtin_ms_va_end
3796a8d409SSimon Glass #else
38a0b49bc3SSimon Glass #define EFIAPI asmlinkage
39beb077a2SAlexander Graf #define efi_va_list va_list
40beb077a2SAlexander Graf #define efi_va_start va_start
41beb077a2SAlexander Graf #define efi_va_arg va_arg
42beb077a2SAlexander Graf #define efi_va_end va_end
4301866446SAlexander Graf #endif /* __x86_64__ */
4496a8d409SSimon Glass 
451fdeacd3SBin Meng #define EFI32_LOADER_SIGNATURE	"EL32"
461fdeacd3SBin Meng #define EFI64_LOADER_SIGNATURE	"EL64"
471fdeacd3SBin Meng 
48867a6ac8SSimon Glass struct efi_device_path;
49867a6ac8SSimon Glass 
500d6ab32eSRob Clark typedef struct {
510d6ab32eSRob Clark 	u8 b[16];
52*4b05fe9cSHeinrich Schuchardt } efi_guid_t __attribute__((aligned(8)));
530d6ab32eSRob Clark 
5401866446SAlexander Graf #define EFI_BITS_PER_LONG	(sizeof(long) * 8)
553e6cc35fSBin Meng 
563c8ffb68Sxypron.glpk@gmx.de /* Bit mask for EFI status code with error */
573c8ffb68Sxypron.glpk@gmx.de #define EFI_ERROR_MASK (1UL << (EFI_BITS_PER_LONG - 1))
583c8ffb68Sxypron.glpk@gmx.de /* Status codes returned by EFI protocols */
59867a6ac8SSimon Glass #define EFI_SUCCESS			0
603c8ffb68Sxypron.glpk@gmx.de #define EFI_LOAD_ERROR			(EFI_ERROR_MASK | 1)
613c8ffb68Sxypron.glpk@gmx.de #define EFI_INVALID_PARAMETER		(EFI_ERROR_MASK | 2)
623c8ffb68Sxypron.glpk@gmx.de #define EFI_UNSUPPORTED			(EFI_ERROR_MASK | 3)
633c8ffb68Sxypron.glpk@gmx.de #define EFI_BAD_BUFFER_SIZE		(EFI_ERROR_MASK | 4)
643c8ffb68Sxypron.glpk@gmx.de #define EFI_BUFFER_TOO_SMALL		(EFI_ERROR_MASK | 5)
653c8ffb68Sxypron.glpk@gmx.de #define EFI_NOT_READY			(EFI_ERROR_MASK | 6)
663c8ffb68Sxypron.glpk@gmx.de #define EFI_DEVICE_ERROR		(EFI_ERROR_MASK | 7)
673c8ffb68Sxypron.glpk@gmx.de #define EFI_WRITE_PROTECTED		(EFI_ERROR_MASK | 8)
683c8ffb68Sxypron.glpk@gmx.de #define EFI_OUT_OF_RESOURCES		(EFI_ERROR_MASK | 9)
693c8ffb68Sxypron.glpk@gmx.de #define EFI_VOLUME_CORRUPTED		(EFI_ERROR_MASK | 10)
703c8ffb68Sxypron.glpk@gmx.de #define EFI_VOLUME_FULL			(EFI_ERROR_MASK | 11)
713c8ffb68Sxypron.glpk@gmx.de #define EFI_NO_MEDIA			(EFI_ERROR_MASK | 12)
723c8ffb68Sxypron.glpk@gmx.de #define EFI_MEDIA_CHANGED		(EFI_ERROR_MASK | 13)
733c8ffb68Sxypron.glpk@gmx.de #define EFI_NOT_FOUND			(EFI_ERROR_MASK | 14)
743c8ffb68Sxypron.glpk@gmx.de #define EFI_ACCESS_DENIED		(EFI_ERROR_MASK | 15)
753c8ffb68Sxypron.glpk@gmx.de #define EFI_NO_RESPONSE			(EFI_ERROR_MASK | 16)
763c8ffb68Sxypron.glpk@gmx.de #define EFI_NO_MAPPING			(EFI_ERROR_MASK | 17)
773c8ffb68Sxypron.glpk@gmx.de #define EFI_TIMEOUT			(EFI_ERROR_MASK | 18)
783c8ffb68Sxypron.glpk@gmx.de #define EFI_NOT_STARTED			(EFI_ERROR_MASK | 19)
793c8ffb68Sxypron.glpk@gmx.de #define EFI_ALREADY_STARTED		(EFI_ERROR_MASK | 20)
803c8ffb68Sxypron.glpk@gmx.de #define EFI_ABORTED			(EFI_ERROR_MASK | 21)
813c8ffb68Sxypron.glpk@gmx.de #define EFI_ICMP_ERROR			(EFI_ERROR_MASK | 22)
823c8ffb68Sxypron.glpk@gmx.de #define EFI_TFTP_ERROR			(EFI_ERROR_MASK | 23)
833c8ffb68Sxypron.glpk@gmx.de #define EFI_PROTOCOL_ERROR		(EFI_ERROR_MASK | 24)
843c8ffb68Sxypron.glpk@gmx.de #define EFI_INCOMPATIBLE_VERSION	(EFI_ERROR_MASK | 25)
853c8ffb68Sxypron.glpk@gmx.de #define EFI_SECURITY_VIOLATION		(EFI_ERROR_MASK | 26)
863c8ffb68Sxypron.glpk@gmx.de #define EFI_CRC_ERROR			(EFI_ERROR_MASK | 27)
873c8ffb68Sxypron.glpk@gmx.de #define EFI_END_OF_MEDIA		(EFI_ERROR_MASK | 28)
883c8ffb68Sxypron.glpk@gmx.de #define EFI_END_OF_FILE			(EFI_ERROR_MASK | 31)
893c8ffb68Sxypron.glpk@gmx.de #define EFI_INVALID_LANGUAGE		(EFI_ERROR_MASK | 32)
903c8ffb68Sxypron.glpk@gmx.de #define EFI_COMPROMISED_DATA		(EFI_ERROR_MASK | 33)
913c8ffb68Sxypron.glpk@gmx.de #define EFI_IP_ADDRESS_CONFLICT		(EFI_ERROR_MASK | 34)
923c8ffb68Sxypron.glpk@gmx.de #define EFI_HTTP_ERROR			(EFI_ERROR_MASK | 35)
93867a6ac8SSimon Glass 
942a92080dSRob Clark #define EFI_WARN_DELETE_FAILURE	2
952a92080dSRob Clark 
96867a6ac8SSimon Glass typedef unsigned long efi_status_t;
97867a6ac8SSimon Glass typedef u64 efi_physical_addr_t;
98867a6ac8SSimon Glass typedef u64 efi_virtual_addr_t;
99faea1041SHeinrich Schuchardt typedef struct efi_object *efi_handle_t;
100867a6ac8SSimon Glass 
101867a6ac8SSimon Glass #define EFI_GUID(a, b, c, d0, d1, d2, d3, d4, d5, d6, d7) \
102867a6ac8SSimon Glass 	{{ (a) & 0xff, ((a) >> 8) & 0xff, ((a) >> 16) & 0xff, \
103867a6ac8SSimon Glass 		((a) >> 24) & 0xff, \
104867a6ac8SSimon Glass 		(b) & 0xff, ((b) >> 8) & 0xff, \
105867a6ac8SSimon Glass 		(c) & 0xff, ((c) >> 8) & 0xff, \
10644ab2d32SHeinrich Schuchardt 		(d0), (d1), (d2), (d3), (d4), (d5), (d6), (d7) } }
107867a6ac8SSimon Glass 
108867a6ac8SSimon Glass /* Generic EFI table header */
109867a6ac8SSimon Glass struct efi_table_hdr {
110867a6ac8SSimon Glass 	u64 signature;
111867a6ac8SSimon Glass 	u32 revision;
112867a6ac8SSimon Glass 	u32 headersize;
113867a6ac8SSimon Glass 	u32 crc32;
114867a6ac8SSimon Glass 	u32 reserved;
115867a6ac8SSimon Glass };
116867a6ac8SSimon Glass 
117867a6ac8SSimon Glass /* Enumeration of memory types introduced in UEFI */
118867a6ac8SSimon Glass enum efi_mem_type {
119867a6ac8SSimon Glass 	EFI_RESERVED_MEMORY_TYPE,
120867a6ac8SSimon Glass 	/*
121867a6ac8SSimon Glass 	 * The code portions of a loaded application.
122867a6ac8SSimon Glass 	 * (Note that UEFI OS loaders are UEFI applications.)
123867a6ac8SSimon Glass 	 */
124867a6ac8SSimon Glass 	EFI_LOADER_CODE,
125867a6ac8SSimon Glass 	/*
126867a6ac8SSimon Glass 	 * The data portions of a loaded application and
127867a6ac8SSimon Glass 	 * the default data allocation type used by an application
128867a6ac8SSimon Glass 	 * to allocate pool memory.
129867a6ac8SSimon Glass 	 */
130867a6ac8SSimon Glass 	EFI_LOADER_DATA,
131867a6ac8SSimon Glass 	/* The code portions of a loaded Boot Services Driver */
132867a6ac8SSimon Glass 	EFI_BOOT_SERVICES_CODE,
133867a6ac8SSimon Glass 	/*
13429f1a367SHeinrich Schuchardt 	 * The data portions of a loaded Boot Services Driver and
135867a6ac8SSimon Glass 	 * the default data allocation type used by a Boot Services
136867a6ac8SSimon Glass 	 * Driver to allocate pool memory.
137867a6ac8SSimon Glass 	 */
138867a6ac8SSimon Glass 	EFI_BOOT_SERVICES_DATA,
139867a6ac8SSimon Glass 	/* The code portions of a loaded Runtime Services Driver */
140867a6ac8SSimon Glass 	EFI_RUNTIME_SERVICES_CODE,
141867a6ac8SSimon Glass 	/*
142867a6ac8SSimon Glass 	 * The data portions of a loaded Runtime Services Driver and
143867a6ac8SSimon Glass 	 * the default data allocation type used by a Runtime Services
144867a6ac8SSimon Glass 	 * Driver to allocate pool memory.
145867a6ac8SSimon Glass 	 */
146867a6ac8SSimon Glass 	EFI_RUNTIME_SERVICES_DATA,
147867a6ac8SSimon Glass 	/* Free (unallocated) memory */
148867a6ac8SSimon Glass 	EFI_CONVENTIONAL_MEMORY,
149867a6ac8SSimon Glass 	/* Memory in which errors have been detected */
150867a6ac8SSimon Glass 	EFI_UNUSABLE_MEMORY,
151867a6ac8SSimon Glass 	/* Memory that holds the ACPI tables */
152867a6ac8SSimon Glass 	EFI_ACPI_RECLAIM_MEMORY,
153867a6ac8SSimon Glass 	/* Address space reserved for use by the firmware */
154867a6ac8SSimon Glass 	EFI_ACPI_MEMORY_NVS,
155867a6ac8SSimon Glass 	/*
156867a6ac8SSimon Glass 	 * Used by system firmware to request that a memory-mapped IO region
157867a6ac8SSimon Glass 	 * be mapped by the OS to a virtual address so it can be accessed by
158867a6ac8SSimon Glass 	 * EFI runtime services.
159867a6ac8SSimon Glass 	 */
160867a6ac8SSimon Glass 	EFI_MMAP_IO,
161867a6ac8SSimon Glass 	/*
162867a6ac8SSimon Glass 	 * System memory-mapped IO region that is used to translate
163867a6ac8SSimon Glass 	 * memory cycles to IO cycles by the processor.
164867a6ac8SSimon Glass 	 */
165867a6ac8SSimon Glass 	EFI_MMAP_IO_PORT,
166867a6ac8SSimon Glass 	/*
167867a6ac8SSimon Glass 	 * Address space reserved by the firmware for code that is
168867a6ac8SSimon Glass 	 * part of the processor.
169867a6ac8SSimon Glass 	 */
170867a6ac8SSimon Glass 	EFI_PAL_CODE,
171867a6ac8SSimon Glass 
172867a6ac8SSimon Glass 	EFI_MAX_MEMORY_TYPE,
173867a6ac8SSimon Glass 	EFI_TABLE_END,	/* For efi_build_mem_table() */
174867a6ac8SSimon Glass };
175867a6ac8SSimon Glass 
176867a6ac8SSimon Glass /* Attribute values */
1779b89183bSEugeniu Rosca #define EFI_MEMORY_UC		((u64)0x0000000000000001ULL)	/* uncached */
1789b89183bSEugeniu Rosca #define EFI_MEMORY_WC		((u64)0x0000000000000002ULL)	/* write-coalescing */
1799b89183bSEugeniu Rosca #define EFI_MEMORY_WT		((u64)0x0000000000000004ULL)	/* write-through */
1809b89183bSEugeniu Rosca #define EFI_MEMORY_WB		((u64)0x0000000000000008ULL)	/* write-back */
1819b89183bSEugeniu Rosca #define EFI_MEMORY_UCE		((u64)0x0000000000000010ULL)	/* uncached, exported */
1829b89183bSEugeniu Rosca #define EFI_MEMORY_WP		((u64)0x0000000000001000ULL)	/* write-protect */
1839b89183bSEugeniu Rosca #define EFI_MEMORY_RP		((u64)0x0000000000002000ULL)	/* read-protect */
1849b89183bSEugeniu Rosca #define EFI_MEMORY_XP		((u64)0x0000000000004000ULL)	/* execute-protect */
185c3a40cceSEugeniu Rosca #define EFI_MEMORY_NV		((u64)0x0000000000008000ULL)	/* non-volatile */
186c3a40cceSEugeniu Rosca #define EFI_MEMORY_MORE_RELIABLE \
187c3a40cceSEugeniu Rosca 				((u64)0x0000000000010000ULL)	/* higher reliability */
188c3a40cceSEugeniu Rosca #define EFI_MEMORY_RO		((u64)0x0000000000020000ULL)	/* read-only */
1899b89183bSEugeniu Rosca #define EFI_MEMORY_RUNTIME	((u64)0x8000000000000000ULL)	/* range requires runtime mapping */
1909b89183bSEugeniu Rosca #define EFI_MEM_DESC_VERSION	1
191867a6ac8SSimon Glass 
192867a6ac8SSimon Glass #define EFI_PAGE_SHIFT		12
193867a6ac8SSimon Glass #define EFI_PAGE_SIZE		(1UL << EFI_PAGE_SHIFT)
1942bb9b79dSAlexander Graf #define EFI_PAGE_MASK		(EFI_PAGE_SIZE - 1)
195867a6ac8SSimon Glass 
196867a6ac8SSimon Glass struct efi_mem_desc {
197867a6ac8SSimon Glass 	u32 type;
198867a6ac8SSimon Glass 	u32 reserved;
199867a6ac8SSimon Glass 	efi_physical_addr_t physical_start;
200867a6ac8SSimon Glass 	efi_virtual_addr_t virtual_start;
201867a6ac8SSimon Glass 	u64 num_pages;
202867a6ac8SSimon Glass 	u64 attribute;
203867a6ac8SSimon Glass };
204867a6ac8SSimon Glass 
2054c02c11dSMian Yousaf Kaukab #define EFI_MEMORY_DESCRIPTOR_VERSION 1
2064c02c11dSMian Yousaf Kaukab 
207867a6ac8SSimon Glass /* Allocation types for calls to boottime->allocate_pages*/
208867a6ac8SSimon Glass #define EFI_ALLOCATE_ANY_PAGES		0
209867a6ac8SSimon Glass #define EFI_ALLOCATE_MAX_ADDRESS	1
210867a6ac8SSimon Glass #define EFI_ALLOCATE_ADDRESS		2
211867a6ac8SSimon Glass #define EFI_MAX_ALLOCATE_TYPE		3
212867a6ac8SSimon Glass 
213867a6ac8SSimon Glass /* Types and defines for Time Services */
214867a6ac8SSimon Glass #define EFI_TIME_ADJUST_DAYLIGHT 0x1
215867a6ac8SSimon Glass #define EFI_TIME_IN_DAYLIGHT     0x2
216867a6ac8SSimon Glass #define EFI_UNSPECIFIED_TIMEZONE 0x07ff
217867a6ac8SSimon Glass 
218867a6ac8SSimon Glass struct efi_time {
219867a6ac8SSimon Glass 	u16 year;
220867a6ac8SSimon Glass 	u8 month;
221867a6ac8SSimon Glass 	u8 day;
222867a6ac8SSimon Glass 	u8 hour;
223867a6ac8SSimon Glass 	u8 minute;
224867a6ac8SSimon Glass 	u8 second;
225867a6ac8SSimon Glass 	u8 pad1;
226867a6ac8SSimon Glass 	u32 nanosecond;
227867a6ac8SSimon Glass 	s16 timezone;
228867a6ac8SSimon Glass 	u8 daylight;
229867a6ac8SSimon Glass 	u8 pad2;
230867a6ac8SSimon Glass };
231867a6ac8SSimon Glass 
232867a6ac8SSimon Glass struct efi_time_cap {
233867a6ac8SSimon Glass 	u32 resolution;
234867a6ac8SSimon Glass 	u32 accuracy;
235867a6ac8SSimon Glass 	u8 sets_to_zero;
236867a6ac8SSimon Glass };
237867a6ac8SSimon Glass 
238867a6ac8SSimon Glass enum efi_locate_search_type {
2399f0770ffSHeinrich Schuchardt 	ALL_HANDLES,
2409f0770ffSHeinrich Schuchardt 	BY_REGISTER_NOTIFY,
2419f0770ffSHeinrich Schuchardt 	BY_PROTOCOL
242867a6ac8SSimon Glass };
243867a6ac8SSimon Glass 
244867a6ac8SSimon Glass struct efi_open_protocol_info_entry {
245867a6ac8SSimon Glass 	efi_handle_t agent_handle;
246867a6ac8SSimon Glass 	efi_handle_t controller_handle;
247867a6ac8SSimon Glass 	u32 attributes;
248867a6ac8SSimon Glass 	u32 open_count;
249867a6ac8SSimon Glass };
250867a6ac8SSimon Glass 
251867a6ac8SSimon Glass enum efi_entry_t {
252867a6ac8SSimon Glass 	EFIET_END,	/* Signals this is the last (empty) entry */
253867a6ac8SSimon Glass 	EFIET_MEMORY_MAP,
254d1fe9927SBin Meng 	EFIET_GOP_MODE,
255cbe503fbSBin Meng 	EFIET_SYS_TABLE,
256867a6ac8SSimon Glass 
257867a6ac8SSimon Glass 	/* Number of entries */
258867a6ac8SSimon Glass 	EFIET_MEMORY_COUNT,
259867a6ac8SSimon Glass };
260867a6ac8SSimon Glass 
261867a6ac8SSimon Glass #define EFI_TABLE_VERSION	1
262867a6ac8SSimon Glass 
263867a6ac8SSimon Glass /**
264867a6ac8SSimon Glass  * struct efi_info_hdr - Header for the EFI info table
265867a6ac8SSimon Glass  *
266867a6ac8SSimon Glass  * @version:	EFI_TABLE_VERSION
267867a6ac8SSimon Glass  * @hdr_size:	Size of this struct in bytes
268867a6ac8SSimon Glass  * @total_size:	Total size of this header plus following data
269867a6ac8SSimon Glass  * @spare:	Spare space for expansion
270867a6ac8SSimon Glass  */
271867a6ac8SSimon Glass struct efi_info_hdr {
272867a6ac8SSimon Glass 	u32 version;
273867a6ac8SSimon Glass 	u32 hdr_size;
274867a6ac8SSimon Glass 	u32 total_size;
275867a6ac8SSimon Glass 	u32 spare[5];
276867a6ac8SSimon Glass };
277867a6ac8SSimon Glass 
278867a6ac8SSimon Glass /**
279867a6ac8SSimon Glass  * struct efi_entry_hdr - Header for a table entry
280867a6ac8SSimon Glass  *
281867a6ac8SSimon Glass  * @type:	enum eft_entry_t
282867a6ac8SSimon Glass  * @size	size of entry bytes excluding header and padding
283867a6ac8SSimon Glass  * @addr:	address of this entry (0 if it follows the header )
284867a6ac8SSimon Glass  * @link:	size of entry including header and padding
285867a6ac8SSimon Glass  * @spare1:	Spare space for expansion
286867a6ac8SSimon Glass  * @spare2:	Spare space for expansion
287867a6ac8SSimon Glass  */
288867a6ac8SSimon Glass struct efi_entry_hdr {
289867a6ac8SSimon Glass 	u32 type;
290867a6ac8SSimon Glass 	u32 size;
291867a6ac8SSimon Glass 	u64 addr;
292867a6ac8SSimon Glass 	u32 link;
293867a6ac8SSimon Glass 	u32 spare1;
294867a6ac8SSimon Glass 	u64 spare2;
295867a6ac8SSimon Glass };
296867a6ac8SSimon Glass 
297867a6ac8SSimon Glass /**
298867a6ac8SSimon Glass  * struct efi_entry_memmap - a memory map table passed to U-Boot
299867a6ac8SSimon Glass  *
300867a6ac8SSimon Glass  * @version:	EFI's memory map table version
301867a6ac8SSimon Glass  * @desc_size:	EFI's size of each memory descriptor
302867a6ac8SSimon Glass  * @spare:	Spare space for expansion
303867a6ac8SSimon Glass  * @desc:	An array of descriptors, each @desc_size bytes apart
304867a6ac8SSimon Glass  */
305867a6ac8SSimon Glass struct efi_entry_memmap {
306867a6ac8SSimon Glass 	u32 version;
307867a6ac8SSimon Glass 	u32 desc_size;
308867a6ac8SSimon Glass 	u64 spare;
309867a6ac8SSimon Glass 	struct efi_mem_desc desc[];
310867a6ac8SSimon Glass };
311867a6ac8SSimon Glass 
312d1fe9927SBin Meng /**
313d1fe9927SBin Meng  * struct efi_entry_gopmode - a GOP mode table passed to U-Boot
314d1fe9927SBin Meng  *
315d1fe9927SBin Meng  * @fb_base:	EFI's framebuffer base address
316d1fe9927SBin Meng  * @fb_size:	EFI's framebuffer size
317d1fe9927SBin Meng  * @info_size:	GOP mode info structure size
318d1fe9927SBin Meng  * @info:	Start address of the GOP mode info structure
319d1fe9927SBin Meng  */
320d1fe9927SBin Meng struct efi_entry_gopmode {
321d1fe9927SBin Meng 	efi_physical_addr_t fb_base;
322d1fe9927SBin Meng 	/*
323d1fe9927SBin Meng 	 * Not like the ones in 'struct efi_gop_mode' which are 'unsigned
324d1fe9927SBin Meng 	 * long', @fb_size and @info_size have to be 'u64' here. As the EFI
325d1fe9927SBin Meng 	 * stub codes may have different bit size from the U-Boot payload,
326d1fe9927SBin Meng 	 * using 'long' will cause mismatch between the producer (stub) and
327d1fe9927SBin Meng 	 * the consumer (payload).
328d1fe9927SBin Meng 	 */
329d1fe9927SBin Meng 	u64 fb_size;
330d1fe9927SBin Meng 	u64 info_size;
331d1fe9927SBin Meng 	/*
332d1fe9927SBin Meng 	 * We cannot directly use 'struct efi_gop_mode_info info[]' here as
333d1fe9927SBin Meng 	 * it causes compiler to complain: array type has incomplete element
334d1fe9927SBin Meng 	 * type 'struct efi_gop_mode_info'.
335d1fe9927SBin Meng 	 */
336d1fe9927SBin Meng 	struct /* efi_gop_mode_info */ {
337d1fe9927SBin Meng 		u32 version;
338d1fe9927SBin Meng 		u32 width;
339d1fe9927SBin Meng 		u32 height;
340d1fe9927SBin Meng 		u32 pixel_format;
341d1fe9927SBin Meng 		u32 pixel_bitmask[4];
342d1fe9927SBin Meng 		u32 pixels_per_scanline;
343d1fe9927SBin Meng 	} info[];
344d1fe9927SBin Meng };
345d1fe9927SBin Meng 
346cbe503fbSBin Meng /**
347cbe503fbSBin Meng  * struct efi_entry_systable - system table passed to U-Boot
348cbe503fbSBin Meng  *
349cbe503fbSBin Meng  * @sys_table:	EFI system table address
350cbe503fbSBin Meng  */
351cbe503fbSBin Meng struct efi_entry_systable {
352cbe503fbSBin Meng 	efi_physical_addr_t sys_table;
353cbe503fbSBin Meng };
354cbe503fbSBin Meng 
efi_get_next_mem_desc(struct efi_entry_memmap * map,struct efi_mem_desc * desc)355867a6ac8SSimon Glass static inline struct efi_mem_desc *efi_get_next_mem_desc(
356867a6ac8SSimon Glass 		struct efi_entry_memmap *map, struct efi_mem_desc *desc)
357867a6ac8SSimon Glass {
358867a6ac8SSimon Glass 	return (struct efi_mem_desc *)((ulong)desc + map->desc_size);
359867a6ac8SSimon Glass }
360867a6ac8SSimon Glass 
361867a6ac8SSimon Glass struct efi_priv {
362867a6ac8SSimon Glass 	efi_handle_t parent_image;
363867a6ac8SSimon Glass 	struct efi_device_path *device_path;
364867a6ac8SSimon Glass 	struct efi_system_table *sys_table;
365867a6ac8SSimon Glass 	struct efi_boot_services *boot;
366867a6ac8SSimon Glass 	struct efi_runtime_services *run;
367867a6ac8SSimon Glass 	bool use_pool_for_malloc;
368867a6ac8SSimon Glass 	unsigned long ram_base;
369867a6ac8SSimon Glass 	unsigned int image_data_type;
370867a6ac8SSimon Glass 	struct efi_info_hdr *info;
371867a6ac8SSimon Glass 	unsigned int info_size;
372867a6ac8SSimon Glass 	void *next_hdr;
373867a6ac8SSimon Glass };
374867a6ac8SSimon Glass 
375867a6ac8SSimon Glass /* Base address of the EFI image */
376867a6ac8SSimon Glass extern char image_base[];
377867a6ac8SSimon Glass 
378476476e7SSimon Glass /* Start and end of U-Boot image (for payload) */
3793dc51ab0SBin Meng extern char _binary_u_boot_bin_start[], _binary_u_boot_bin_end[];
380476476e7SSimon Glass 
381ad644e7cSRob Clark /*
382ad644e7cSRob Clark  * Variable Attributes
383ad644e7cSRob Clark  */
384ad644e7cSRob Clark #define EFI_VARIABLE_NON_VOLATILE       0x0000000000000001
385ad644e7cSRob Clark #define EFI_VARIABLE_BOOTSERVICE_ACCESS 0x0000000000000002
386ad644e7cSRob Clark #define EFI_VARIABLE_RUNTIME_ACCESS     0x0000000000000004
387ad644e7cSRob Clark #define EFI_VARIABLE_HARDWARE_ERROR_RECORD 0x0000000000000008
388ad644e7cSRob Clark #define EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS 0x0000000000000010
389ad644e7cSRob Clark #define EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS 0x0000000000000020
390ad644e7cSRob Clark #define EFI_VARIABLE_APPEND_WRITE	0x0000000000000040
391ad644e7cSRob Clark 
392ad644e7cSRob Clark #define EFI_VARIABLE_MASK	(EFI_VARIABLE_NON_VOLATILE | \
393ad644e7cSRob Clark 				EFI_VARIABLE_BOOTSERVICE_ACCESS | \
394ad644e7cSRob Clark 				EFI_VARIABLE_RUNTIME_ACCESS | \
395ad644e7cSRob Clark 				EFI_VARIABLE_HARDWARE_ERROR_RECORD | \
396ad644e7cSRob Clark 				EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS | \
397ad644e7cSRob Clark 				EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS | \
398ad644e7cSRob Clark 				EFI_VARIABLE_APPEND_WRITE)
399ad644e7cSRob Clark 
400867a6ac8SSimon Glass /**
401867a6ac8SSimon Glass  * efi_get_sys_table() - Get access to the main EFI system table
402867a6ac8SSimon Glass  *
403867a6ac8SSimon Glass  * @return pointer to EFI system table
404867a6ac8SSimon Glass  */
405476476e7SSimon Glass 
406867a6ac8SSimon Glass struct efi_system_table *efi_get_sys_table(void);
407867a6ac8SSimon Glass 
408867a6ac8SSimon Glass /**
409867a6ac8SSimon Glass  * efi_get_ram_base() - Find the base of RAM
410867a6ac8SSimon Glass  *
411867a6ac8SSimon Glass  * This is used when U-Boot is built as an EFI application.
412867a6ac8SSimon Glass  *
413867a6ac8SSimon Glass  * @return the base of RAM as known to U-Boot
414867a6ac8SSimon Glass  */
415867a6ac8SSimon Glass unsigned long efi_get_ram_base(void);
416867a6ac8SSimon Glass 
417867a6ac8SSimon Glass /**
418867a6ac8SSimon Glass  * efi_init() - Set up ready for use of EFI boot services
419867a6ac8SSimon Glass  *
420867a6ac8SSimon Glass  * @priv:	Pointer to our private EFI structure to fill in
421867a6ac8SSimon Glass  * @banner:	Banner to display when starting
422867a6ac8SSimon Glass  * @image:	The image handle passed to efi_main()
423867a6ac8SSimon Glass  * @sys_table:	The EFI system table pointer passed to efi_main()
424867a6ac8SSimon Glass  */
425867a6ac8SSimon Glass int efi_init(struct efi_priv *priv, const char *banner, efi_handle_t image,
426867a6ac8SSimon Glass 	     struct efi_system_table *sys_table);
427867a6ac8SSimon Glass 
428867a6ac8SSimon Glass /**
429867a6ac8SSimon Glass  * efi_malloc() - Allocate some memory from EFI
430867a6ac8SSimon Glass  *
431867a6ac8SSimon Glass  * @priv:	Pointer to private EFI structure
432867a6ac8SSimon Glass  * @size:	Number of bytes to allocate
433867a6ac8SSimon Glass  * @retp:	Return EFI status result
434867a6ac8SSimon Glass  * @return pointer to memory allocated, or NULL on error
435867a6ac8SSimon Glass  */
436867a6ac8SSimon Glass void *efi_malloc(struct efi_priv *priv, int size, efi_status_t *retp);
437867a6ac8SSimon Glass 
438867a6ac8SSimon Glass /**
439867a6ac8SSimon Glass  * efi_free() - Free memory allocated from EFI
440867a6ac8SSimon Glass  *
441867a6ac8SSimon Glass  * @priv:	Pointer to private EFI structure
442867a6ac8SSimon Glass  * @ptr:	Pointer to memory to free
443867a6ac8SSimon Glass  */
444867a6ac8SSimon Glass void efi_free(struct efi_priv *priv, void *ptr);
445867a6ac8SSimon Glass 
446867a6ac8SSimon Glass /**
447867a6ac8SSimon Glass  * efi_puts() - Write out a string to the EFI console
448867a6ac8SSimon Glass  *
449867a6ac8SSimon Glass  * @priv:	Pointer to private EFI structure
450867a6ac8SSimon Glass  * @str:	String to write (note this is a ASCII, not unicode)
451867a6ac8SSimon Glass  */
452867a6ac8SSimon Glass void efi_puts(struct efi_priv *priv, const char *str);
453867a6ac8SSimon Glass 
454867a6ac8SSimon Glass /**
455867a6ac8SSimon Glass  * efi_putc() - Write out a character to the EFI console
456867a6ac8SSimon Glass  *
457867a6ac8SSimon Glass  * @priv:	Pointer to private EFI structure
458867a6ac8SSimon Glass  * @ch:		Character to write (note this is not unicode)
459867a6ac8SSimon Glass  */
460867a6ac8SSimon Glass void efi_putc(struct efi_priv *priv, const char ch);
461867a6ac8SSimon Glass 
462867a6ac8SSimon Glass /**
463867a6ac8SSimon Glass  * efi_info_get() - get an entry from an EFI table
464867a6ac8SSimon Glass  *
465867a6ac8SSimon Glass  * @type:	Entry type to search for
466867a6ac8SSimon Glass  * @datap:	Returns pointer to entry data
467867a6ac8SSimon Glass  * @sizep:	Returns pointer to entry size
468867a6ac8SSimon Glass  * @return 0 if OK, -ENODATA if there is no table, -ENOENT if there is no entry
469867a6ac8SSimon Glass  * of the requested type, -EPROTONOSUPPORT if the table has the wrong version
470867a6ac8SSimon Glass  */
471867a6ac8SSimon Glass int efi_info_get(enum efi_entry_t type, void **datap, int *sizep);
472867a6ac8SSimon Glass 
473867a6ac8SSimon Glass /**
474867a6ac8SSimon Glass  * efi_build_mem_table() - make a sorted copy of the memory table
475867a6ac8SSimon Glass  *
476867a6ac8SSimon Glass  * @map:	Pointer to EFI memory map table
477867a6ac8SSimon Glass  * @size:	Size of table in bytes
478867a6ac8SSimon Glass  * @skip_bs:	True to skip boot-time memory and merge it with conventional
479867a6ac8SSimon Glass  *		memory. This will significantly reduce the number of table
480867a6ac8SSimon Glass  *		entries.
481867a6ac8SSimon Glass  * @return pointer to the new table. It should be freed with free() by the
482867a6ac8SSimon Glass  *	   caller
483867a6ac8SSimon Glass  */
484867a6ac8SSimon Glass void *efi_build_mem_table(struct efi_entry_memmap *map, int size, bool skip_bs);
485867a6ac8SSimon Glass 
486867a6ac8SSimon Glass #endif /* _LINUX_EFI_H */
487