blob: 1dbc3b77b42f6429e2a73ca23798a36d0e7f83a4 [file] [log] [blame]
Simon Glass867a6ac2015-07-31 09:31:36 -06001/*
2 * Extensible Firmware Interface
3 * Based on 'Extensible Firmware Interface Specification' version 0.9,
4 * April 30, 1999
5 *
6 * Copyright (C) 1999 VA Linux Systems
7 * Copyright (C) 1999 Walt Drummond <drummond@valinux.com>
8 * Copyright (C) 1999, 2002-2003 Hewlett-Packard Co.
9 * David Mosberger-Tang <davidm@hpl.hp.com>
10 * Stephane Eranian <eranian@hpl.hp.com>
11 *
12 * From include/linux/efi.h in kernel 4.1 with some additions/subtractions
13 */
14
15#ifndef _EFI_H
16#define _EFI_H
17
18#include <linux/string.h>
19#include <linux/types.h>
20
Simon Glass96a8d402015-08-04 12:33:56 -060021#ifdef CONFIG_EFI_STUB_64BIT
22/* EFI uses the Microsoft ABI which is not the default for GCC */
23#define EFIAPI __attribute__((ms_abi))
24#else
25#define EFIAPI
26#endif
27
Simon Glass867a6ac2015-07-31 09:31:36 -060028struct efi_device_path;
29
30#define EFI_SUCCESS 0
31#define EFI_LOAD_ERROR (1 | (1UL << (BITS_PER_LONG - 1)))
32#define EFI_INVALID_PARAMETER (2 | (1UL << (BITS_PER_LONG - 1)))
33#define EFI_UNSUPPORTED (3 | (1UL << (BITS_PER_LONG - 1)))
34#define EFI_BAD_BUFFER_SIZE (4 | (1UL << (BITS_PER_LONG - 1)))
35#define EFI_BUFFER_TOO_SMALL (5 | (1UL << (BITS_PER_LONG - 1)))
36#define EFI_NOT_READY (6 | (1UL << (BITS_PER_LONG - 1)))
37#define EFI_DEVICE_ERROR (7 | (1UL << (BITS_PER_LONG - 1)))
38#define EFI_WRITE_PROTECTED (8 | (1UL << (BITS_PER_LONG - 1)))
39#define EFI_OUT_OF_RESOURCES (9 | (1UL << (BITS_PER_LONG - 1)))
40#define EFI_NOT_FOUND (14 | (1UL << (BITS_PER_LONG - 1)))
Alexander Graf2bb9b792016-03-04 01:09:57 +010041#define EFI_ACCESS_DENIED (15 | (1UL << (BITS_PER_LONG - 1)))
Simon Glass867a6ac2015-07-31 09:31:36 -060042#define EFI_SECURITY_VIOLATION (26 | (1UL << (BITS_PER_LONG - 1)))
43
44typedef unsigned long efi_status_t;
45typedef u64 efi_physical_addr_t;
46typedef u64 efi_virtual_addr_t;
47typedef void *efi_handle_t;
48
49#define EFI_GUID(a, b, c, d0, d1, d2, d3, d4, d5, d6, d7) \
50 ((efi_guid_t) \
51 {{ (a) & 0xff, ((a) >> 8) & 0xff, ((a) >> 16) & 0xff, \
52 ((a) >> 24) & 0xff, \
53 (b) & 0xff, ((b) >> 8) & 0xff, \
54 (c) & 0xff, ((c) >> 8) & 0xff, \
55 (d0), (d1), (d2), (d3), (d4), (d5), (d6), (d7) } })
56
57/* Generic EFI table header */
58struct efi_table_hdr {
59 u64 signature;
60 u32 revision;
61 u32 headersize;
62 u32 crc32;
63 u32 reserved;
64};
65
66/* Enumeration of memory types introduced in UEFI */
67enum efi_mem_type {
68 EFI_RESERVED_MEMORY_TYPE,
69 /*
70 * The code portions of a loaded application.
71 * (Note that UEFI OS loaders are UEFI applications.)
72 */
73 EFI_LOADER_CODE,
74 /*
75 * The data portions of a loaded application and
76 * the default data allocation type used by an application
77 * to allocate pool memory.
78 */
79 EFI_LOADER_DATA,
80 /* The code portions of a loaded Boot Services Driver */
81 EFI_BOOT_SERVICES_CODE,
82 /*
83 * The data portions of a loaded Boot Serves Driver and
84 * the default data allocation type used by a Boot Services
85 * Driver to allocate pool memory.
86 */
87 EFI_BOOT_SERVICES_DATA,
88 /* The code portions of a loaded Runtime Services Driver */
89 EFI_RUNTIME_SERVICES_CODE,
90 /*
91 * The data portions of a loaded Runtime Services Driver and
92 * the default data allocation type used by a Runtime Services
93 * Driver to allocate pool memory.
94 */
95 EFI_RUNTIME_SERVICES_DATA,
96 /* Free (unallocated) memory */
97 EFI_CONVENTIONAL_MEMORY,
98 /* Memory in which errors have been detected */
99 EFI_UNUSABLE_MEMORY,
100 /* Memory that holds the ACPI tables */
101 EFI_ACPI_RECLAIM_MEMORY,
102 /* Address space reserved for use by the firmware */
103 EFI_ACPI_MEMORY_NVS,
104 /*
105 * Used by system firmware to request that a memory-mapped IO region
106 * be mapped by the OS to a virtual address so it can be accessed by
107 * EFI runtime services.
108 */
109 EFI_MMAP_IO,
110 /*
111 * System memory-mapped IO region that is used to translate
112 * memory cycles to IO cycles by the processor.
113 */
114 EFI_MMAP_IO_PORT,
115 /*
116 * Address space reserved by the firmware for code that is
117 * part of the processor.
118 */
119 EFI_PAL_CODE,
120
121 EFI_MAX_MEMORY_TYPE,
122 EFI_TABLE_END, /* For efi_build_mem_table() */
123};
124
125/* Attribute values */
126enum {
127 EFI_MEMORY_UC_SHIFT = 0, /* uncached */
128 EFI_MEMORY_WC_SHIFT = 1, /* write-coalescing */
129 EFI_MEMORY_WT_SHIFT = 2, /* write-through */
130 EFI_MEMORY_WB_SHIFT = 3, /* write-back */
131 EFI_MEMORY_UCE_SHIFT = 4, /* uncached, exported */
132 EFI_MEMORY_WP_SHIFT = 12, /* write-protect */
133 EFI_MEMORY_RP_SHIFT = 13, /* read-protect */
134 EFI_MEMORY_XP_SHIFT = 14, /* execute-protect */
135 EFI_MEMORY_RUNTIME_SHIFT = 63, /* range requires runtime mapping */
136
137 EFI_MEMORY_RUNTIME = 1ULL << EFI_MEMORY_RUNTIME_SHIFT,
138 EFI_MEM_DESC_VERSION = 1,
139};
140
141#define EFI_PAGE_SHIFT 12
142#define EFI_PAGE_SIZE (1UL << EFI_PAGE_SHIFT)
Alexander Graf2bb9b792016-03-04 01:09:57 +0100143#define EFI_PAGE_MASK (EFI_PAGE_SIZE - 1)
Simon Glass867a6ac2015-07-31 09:31:36 -0600144
145struct efi_mem_desc {
146 u32 type;
147 u32 reserved;
148 efi_physical_addr_t physical_start;
149 efi_virtual_addr_t virtual_start;
150 u64 num_pages;
151 u64 attribute;
152};
153
154/* Allocation types for calls to boottime->allocate_pages*/
155#define EFI_ALLOCATE_ANY_PAGES 0
156#define EFI_ALLOCATE_MAX_ADDRESS 1
157#define EFI_ALLOCATE_ADDRESS 2
158#define EFI_MAX_ALLOCATE_TYPE 3
159
160/* Types and defines for Time Services */
161#define EFI_TIME_ADJUST_DAYLIGHT 0x1
162#define EFI_TIME_IN_DAYLIGHT 0x2
163#define EFI_UNSPECIFIED_TIMEZONE 0x07ff
164
165struct efi_time {
166 u16 year;
167 u8 month;
168 u8 day;
169 u8 hour;
170 u8 minute;
171 u8 second;
172 u8 pad1;
173 u32 nanosecond;
174 s16 timezone;
175 u8 daylight;
176 u8 pad2;
177};
178
179struct efi_time_cap {
180 u32 resolution;
181 u32 accuracy;
182 u8 sets_to_zero;
183};
184
185enum efi_locate_search_type {
186 all_handles,
187 by_register_notify,
188 by_protocol
189};
190
191struct efi_open_protocol_info_entry {
192 efi_handle_t agent_handle;
193 efi_handle_t controller_handle;
194 u32 attributes;
195 u32 open_count;
196};
197
198enum efi_entry_t {
199 EFIET_END, /* Signals this is the last (empty) entry */
200 EFIET_MEMORY_MAP,
201
202 /* Number of entries */
203 EFIET_MEMORY_COUNT,
204};
205
206#define EFI_TABLE_VERSION 1
207
208/**
209 * struct efi_info_hdr - Header for the EFI info table
210 *
211 * @version: EFI_TABLE_VERSION
212 * @hdr_size: Size of this struct in bytes
213 * @total_size: Total size of this header plus following data
214 * @spare: Spare space for expansion
215 */
216struct efi_info_hdr {
217 u32 version;
218 u32 hdr_size;
219 u32 total_size;
220 u32 spare[5];
221};
222
223/**
224 * struct efi_entry_hdr - Header for a table entry
225 *
226 * @type: enum eft_entry_t
227 * @size size of entry bytes excluding header and padding
228 * @addr: address of this entry (0 if it follows the header )
229 * @link: size of entry including header and padding
230 * @spare1: Spare space for expansion
231 * @spare2: Spare space for expansion
232 */
233struct efi_entry_hdr {
234 u32 type;
235 u32 size;
236 u64 addr;
237 u32 link;
238 u32 spare1;
239 u64 spare2;
240};
241
242/**
243 * struct efi_entry_memmap - a memory map table passed to U-Boot
244 *
245 * @version: EFI's memory map table version
246 * @desc_size: EFI's size of each memory descriptor
247 * @spare: Spare space for expansion
248 * @desc: An array of descriptors, each @desc_size bytes apart
249 */
250struct efi_entry_memmap {
251 u32 version;
252 u32 desc_size;
253 u64 spare;
254 struct efi_mem_desc desc[];
255};
256
257static inline struct efi_mem_desc *efi_get_next_mem_desc(
258 struct efi_entry_memmap *map, struct efi_mem_desc *desc)
259{
260 return (struct efi_mem_desc *)((ulong)desc + map->desc_size);
261}
262
263struct efi_priv {
264 efi_handle_t parent_image;
265 struct efi_device_path *device_path;
266 struct efi_system_table *sys_table;
267 struct efi_boot_services *boot;
268 struct efi_runtime_services *run;
269 bool use_pool_for_malloc;
270 unsigned long ram_base;
271 unsigned int image_data_type;
272 struct efi_info_hdr *info;
273 unsigned int info_size;
274 void *next_hdr;
275};
276
277/* Base address of the EFI image */
278extern char image_base[];
279
Simon Glass476476e2015-08-04 12:33:52 -0600280/* Start and end of U-Boot image (for payload) */
281extern char _binary_u_boot_dtb_bin_start[], _binary_u_boot_dtb_bin_end[];
282
Simon Glass867a6ac2015-07-31 09:31:36 -0600283/**
284 * efi_get_sys_table() - Get access to the main EFI system table
285 *
286 * @return pointer to EFI system table
287 */
Simon Glass476476e2015-08-04 12:33:52 -0600288
Simon Glass867a6ac2015-07-31 09:31:36 -0600289struct efi_system_table *efi_get_sys_table(void);
290
291/**
292 * efi_get_ram_base() - Find the base of RAM
293 *
294 * This is used when U-Boot is built as an EFI application.
295 *
296 * @return the base of RAM as known to U-Boot
297 */
298unsigned long efi_get_ram_base(void);
299
300/**
301 * efi_init() - Set up ready for use of EFI boot services
302 *
303 * @priv: Pointer to our private EFI structure to fill in
304 * @banner: Banner to display when starting
305 * @image: The image handle passed to efi_main()
306 * @sys_table: The EFI system table pointer passed to efi_main()
307 */
308int efi_init(struct efi_priv *priv, const char *banner, efi_handle_t image,
309 struct efi_system_table *sys_table);
310
311/**
312 * efi_malloc() - Allocate some memory from EFI
313 *
314 * @priv: Pointer to private EFI structure
315 * @size: Number of bytes to allocate
316 * @retp: Return EFI status result
317 * @return pointer to memory allocated, or NULL on error
318 */
319void *efi_malloc(struct efi_priv *priv, int size, efi_status_t *retp);
320
321/**
322 * efi_free() - Free memory allocated from EFI
323 *
324 * @priv: Pointer to private EFI structure
325 * @ptr: Pointer to memory to free
326 */
327void efi_free(struct efi_priv *priv, void *ptr);
328
329/**
330 * efi_puts() - Write out a string to the EFI console
331 *
332 * @priv: Pointer to private EFI structure
333 * @str: String to write (note this is a ASCII, not unicode)
334 */
335void efi_puts(struct efi_priv *priv, const char *str);
336
337/**
338 * efi_putc() - Write out a character to the EFI console
339 *
340 * @priv: Pointer to private EFI structure
341 * @ch: Character to write (note this is not unicode)
342 */
343void efi_putc(struct efi_priv *priv, const char ch);
344
345/**
346 * efi_info_get() - get an entry from an EFI table
347 *
348 * @type: Entry type to search for
349 * @datap: Returns pointer to entry data
350 * @sizep: Returns pointer to entry size
351 * @return 0 if OK, -ENODATA if there is no table, -ENOENT if there is no entry
352 * of the requested type, -EPROTONOSUPPORT if the table has the wrong version
353 */
354int efi_info_get(enum efi_entry_t type, void **datap, int *sizep);
355
356/**
357 * efi_build_mem_table() - make a sorted copy of the memory table
358 *
359 * @map: Pointer to EFI memory map table
360 * @size: Size of table in bytes
361 * @skip_bs: True to skip boot-time memory and merge it with conventional
362 * memory. This will significantly reduce the number of table
363 * entries.
364 * @return pointer to the new table. It should be freed with free() by the
365 * caller
366 */
367void *efi_build_mem_table(struct efi_entry_memmap *map, int size, bool skip_bs);
368
369#endif /* _LINUX_EFI_H */