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