]> git.sur5r.net Git - u-boot/blob - include/efi.h
efi: stub: Pass EFI GOP information to U-Boot payload
[u-boot] / include / efi.h
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/linkage.h>
19 #include <linux/string.h>
20 #include <linux/types.h>
21
22 #if CONFIG_EFI_STUB_64BIT || (!defined(CONFIG_EFI_STUB) && defined(__x86_64__))
23 /* EFI uses the Microsoft ABI which is not the default for GCC */
24 #define EFIAPI __attribute__((ms_abi))
25 #else
26 #define EFIAPI asmlinkage
27 #endif
28
29 struct efi_device_path;
30
31 typedef struct {
32         u8 b[16];
33 } efi_guid_t;
34
35 #define EFI_BITS_PER_LONG       BITS_PER_LONG
36
37 /*
38  * With 64-bit EFI stub, EFI_BITS_PER_LONG has to be 64. EFI_STUB is set
39  * in lib/efi/Makefile, when building the stub.
40  */
41 #if defined(CONFIG_EFI_STUB_64BIT) && defined(EFI_STUB)
42 #undef EFI_BITS_PER_LONG
43 #define EFI_BITS_PER_LONG       64
44 #endif
45
46 /* Bit mask for EFI status code with error */
47 #define EFI_ERROR_MASK (1UL << (EFI_BITS_PER_LONG - 1))
48 /* Status codes returned by EFI protocols */
49 #define EFI_SUCCESS                     0
50 #define EFI_LOAD_ERROR                  (EFI_ERROR_MASK | 1)
51 #define EFI_INVALID_PARAMETER           (EFI_ERROR_MASK | 2)
52 #define EFI_UNSUPPORTED                 (EFI_ERROR_MASK | 3)
53 #define EFI_BAD_BUFFER_SIZE             (EFI_ERROR_MASK | 4)
54 #define EFI_BUFFER_TOO_SMALL            (EFI_ERROR_MASK | 5)
55 #define EFI_NOT_READY                   (EFI_ERROR_MASK | 6)
56 #define EFI_DEVICE_ERROR                (EFI_ERROR_MASK | 7)
57 #define EFI_WRITE_PROTECTED             (EFI_ERROR_MASK | 8)
58 #define EFI_OUT_OF_RESOURCES            (EFI_ERROR_MASK | 9)
59 #define EFI_VOLUME_CORRUPTED            (EFI_ERROR_MASK | 10)
60 #define EFI_VOLUME_FULL                 (EFI_ERROR_MASK | 11)
61 #define EFI_NO_MEDIA                    (EFI_ERROR_MASK | 12)
62 #define EFI_MEDIA_CHANGED               (EFI_ERROR_MASK | 13)
63 #define EFI_NOT_FOUND                   (EFI_ERROR_MASK | 14)
64 #define EFI_ACCESS_DENIED               (EFI_ERROR_MASK | 15)
65 #define EFI_NO_RESPONSE                 (EFI_ERROR_MASK | 16)
66 #define EFI_NO_MAPPING                  (EFI_ERROR_MASK | 17)
67 #define EFI_TIMEOUT                     (EFI_ERROR_MASK | 18)
68 #define EFI_NOT_STARTED                 (EFI_ERROR_MASK | 19)
69 #define EFI_ALREADY_STARTED             (EFI_ERROR_MASK | 20)
70 #define EFI_ABORTED                     (EFI_ERROR_MASK | 21)
71 #define EFI_ICMP_ERROR                  (EFI_ERROR_MASK | 22)
72 #define EFI_TFTP_ERROR                  (EFI_ERROR_MASK | 23)
73 #define EFI_PROTOCOL_ERROR              (EFI_ERROR_MASK | 24)
74 #define EFI_INCOMPATIBLE_VERSION        (EFI_ERROR_MASK | 25)
75 #define EFI_SECURITY_VIOLATION          (EFI_ERROR_MASK | 26)
76 #define EFI_CRC_ERROR                   (EFI_ERROR_MASK | 27)
77 #define EFI_END_OF_MEDIA                (EFI_ERROR_MASK | 28)
78 #define EFI_END_OF_FILE                 (EFI_ERROR_MASK | 31)
79 #define EFI_INVALID_LANGUAGE            (EFI_ERROR_MASK | 32)
80 #define EFI_COMPROMISED_DATA            (EFI_ERROR_MASK | 33)
81 #define EFI_IP_ADDRESS_CONFLICT         (EFI_ERROR_MASK | 34)
82 #define EFI_HTTP_ERROR                  (EFI_ERROR_MASK | 35)
83
84 #define EFI_WARN_DELETE_FAILURE 2
85
86 typedef unsigned long efi_status_t;
87 typedef u64 efi_physical_addr_t;
88 typedef u64 efi_virtual_addr_t;
89 typedef void *efi_handle_t;
90
91 #define EFI_GUID(a, b, c, d0, d1, d2, d3, d4, d5, d6, d7) \
92         {{ (a) & 0xff, ((a) >> 8) & 0xff, ((a) >> 16) & 0xff, \
93                 ((a) >> 24) & 0xff, \
94                 (b) & 0xff, ((b) >> 8) & 0xff, \
95                 (c) & 0xff, ((c) >> 8) & 0xff, \
96                 (d0), (d1), (d2), (d3), (d4), (d5), (d6), (d7) } }
97
98 /* Generic EFI table header */
99 struct efi_table_hdr {
100         u64 signature;
101         u32 revision;
102         u32 headersize;
103         u32 crc32;
104         u32 reserved;
105 };
106
107 /* Enumeration of memory types introduced in UEFI */
108 enum efi_mem_type {
109         EFI_RESERVED_MEMORY_TYPE,
110         /*
111          * The code portions of a loaded application.
112          * (Note that UEFI OS loaders are UEFI applications.)
113          */
114         EFI_LOADER_CODE,
115         /*
116          * The data portions of a loaded application and
117          * the default data allocation type used by an application
118          * to allocate pool memory.
119          */
120         EFI_LOADER_DATA,
121         /* The code portions of a loaded Boot Services Driver */
122         EFI_BOOT_SERVICES_CODE,
123         /*
124          * The data portions of a loaded Boot Services Driver and
125          * the default data allocation type used by a Boot Services
126          * Driver to allocate pool memory.
127          */
128         EFI_BOOT_SERVICES_DATA,
129         /* The code portions of a loaded Runtime Services Driver */
130         EFI_RUNTIME_SERVICES_CODE,
131         /*
132          * The data portions of a loaded Runtime Services Driver and
133          * the default data allocation type used by a Runtime Services
134          * Driver to allocate pool memory.
135          */
136         EFI_RUNTIME_SERVICES_DATA,
137         /* Free (unallocated) memory */
138         EFI_CONVENTIONAL_MEMORY,
139         /* Memory in which errors have been detected */
140         EFI_UNUSABLE_MEMORY,
141         /* Memory that holds the ACPI tables */
142         EFI_ACPI_RECLAIM_MEMORY,
143         /* Address space reserved for use by the firmware */
144         EFI_ACPI_MEMORY_NVS,
145         /*
146          * Used by system firmware to request that a memory-mapped IO region
147          * be mapped by the OS to a virtual address so it can be accessed by
148          * EFI runtime services.
149          */
150         EFI_MMAP_IO,
151         /*
152          * System memory-mapped IO region that is used to translate
153          * memory cycles to IO cycles by the processor.
154          */
155         EFI_MMAP_IO_PORT,
156         /*
157          * Address space reserved by the firmware for code that is
158          * part of the processor.
159          */
160         EFI_PAL_CODE,
161
162         EFI_MAX_MEMORY_TYPE,
163         EFI_TABLE_END,  /* For efi_build_mem_table() */
164 };
165
166 /* Attribute values */
167 enum {
168         EFI_MEMORY_UC_SHIFT     = 0,    /* uncached */
169         EFI_MEMORY_WC_SHIFT     = 1,    /* write-coalescing */
170         EFI_MEMORY_WT_SHIFT     = 2,    /* write-through */
171         EFI_MEMORY_WB_SHIFT     = 3,    /* write-back */
172         EFI_MEMORY_UCE_SHIFT    = 4,    /* uncached, exported */
173         EFI_MEMORY_WP_SHIFT     = 12,   /* write-protect */
174         EFI_MEMORY_RP_SHIFT     = 13,   /* read-protect */
175         EFI_MEMORY_XP_SHIFT     = 14,   /* execute-protect */
176         EFI_MEMORY_RUNTIME_SHIFT = 63,  /* range requires runtime mapping */
177
178         EFI_MEMORY_RUNTIME = 1ULL << EFI_MEMORY_RUNTIME_SHIFT,
179         EFI_MEM_DESC_VERSION    = 1,
180 };
181
182 #define EFI_PAGE_SHIFT          12
183 #define EFI_PAGE_SIZE           (1UL << EFI_PAGE_SHIFT)
184 #define EFI_PAGE_MASK           (EFI_PAGE_SIZE - 1)
185
186 struct efi_mem_desc {
187         u32 type;
188         u32 reserved;
189         efi_physical_addr_t physical_start;
190         efi_virtual_addr_t virtual_start;
191         u64 num_pages;
192         u64 attribute;
193 };
194
195 #define EFI_MEMORY_DESCRIPTOR_VERSION 1
196
197 /* Allocation types for calls to boottime->allocate_pages*/
198 #define EFI_ALLOCATE_ANY_PAGES          0
199 #define EFI_ALLOCATE_MAX_ADDRESS        1
200 #define EFI_ALLOCATE_ADDRESS            2
201 #define EFI_MAX_ALLOCATE_TYPE           3
202
203 /* Types and defines for Time Services */
204 #define EFI_TIME_ADJUST_DAYLIGHT 0x1
205 #define EFI_TIME_IN_DAYLIGHT     0x2
206 #define EFI_UNSPECIFIED_TIMEZONE 0x07ff
207
208 struct efi_time {
209         u16 year;
210         u8 month;
211         u8 day;
212         u8 hour;
213         u8 minute;
214         u8 second;
215         u8 pad1;
216         u32 nanosecond;
217         s16 timezone;
218         u8 daylight;
219         u8 pad2;
220 };
221
222 struct efi_time_cap {
223         u32 resolution;
224         u32 accuracy;
225         u8 sets_to_zero;
226 };
227
228 enum efi_locate_search_type {
229         ALL_HANDLES,
230         BY_REGISTER_NOTIFY,
231         BY_PROTOCOL
232 };
233
234 struct efi_open_protocol_info_entry {
235         efi_handle_t agent_handle;
236         efi_handle_t controller_handle;
237         u32 attributes;
238         u32 open_count;
239 };
240
241 enum efi_entry_t {
242         EFIET_END,      /* Signals this is the last (empty) entry */
243         EFIET_MEMORY_MAP,
244         EFIET_GOP_MODE,
245
246         /* Number of entries */
247         EFIET_MEMORY_COUNT,
248 };
249
250 #define EFI_TABLE_VERSION       1
251
252 /**
253  * struct efi_info_hdr - Header for the EFI info table
254  *
255  * @version:    EFI_TABLE_VERSION
256  * @hdr_size:   Size of this struct in bytes
257  * @total_size: Total size of this header plus following data
258  * @spare:      Spare space for expansion
259  */
260 struct efi_info_hdr {
261         u32 version;
262         u32 hdr_size;
263         u32 total_size;
264         u32 spare[5];
265 };
266
267 /**
268  * struct efi_entry_hdr - Header for a table entry
269  *
270  * @type:       enum eft_entry_t
271  * @size        size of entry bytes excluding header and padding
272  * @addr:       address of this entry (0 if it follows the header )
273  * @link:       size of entry including header and padding
274  * @spare1:     Spare space for expansion
275  * @spare2:     Spare space for expansion
276  */
277 struct efi_entry_hdr {
278         u32 type;
279         u32 size;
280         u64 addr;
281         u32 link;
282         u32 spare1;
283         u64 spare2;
284 };
285
286 /**
287  * struct efi_entry_memmap - a memory map table passed to U-Boot
288  *
289  * @version:    EFI's memory map table version
290  * @desc_size:  EFI's size of each memory descriptor
291  * @spare:      Spare space for expansion
292  * @desc:       An array of descriptors, each @desc_size bytes apart
293  */
294 struct efi_entry_memmap {
295         u32 version;
296         u32 desc_size;
297         u64 spare;
298         struct efi_mem_desc desc[];
299 };
300
301 /**
302  * struct efi_entry_gopmode - a GOP mode table passed to U-Boot
303  *
304  * @fb_base:    EFI's framebuffer base address
305  * @fb_size:    EFI's framebuffer size
306  * @info_size:  GOP mode info structure size
307  * @info:       Start address of the GOP mode info structure
308  */
309 struct efi_entry_gopmode {
310         efi_physical_addr_t fb_base;
311         /*
312          * Not like the ones in 'struct efi_gop_mode' which are 'unsigned
313          * long', @fb_size and @info_size have to be 'u64' here. As the EFI
314          * stub codes may have different bit size from the U-Boot payload,
315          * using 'long' will cause mismatch between the producer (stub) and
316          * the consumer (payload).
317          */
318         u64 fb_size;
319         u64 info_size;
320         /*
321          * We cannot directly use 'struct efi_gop_mode_info info[]' here as
322          * it causes compiler to complain: array type has incomplete element
323          * type 'struct efi_gop_mode_info'.
324          */
325         struct /* efi_gop_mode_info */ {
326                 u32 version;
327                 u32 width;
328                 u32 height;
329                 u32 pixel_format;
330                 u32 pixel_bitmask[4];
331                 u32 pixels_per_scanline;
332         } info[];
333 };
334
335 static inline struct efi_mem_desc *efi_get_next_mem_desc(
336                 struct efi_entry_memmap *map, struct efi_mem_desc *desc)
337 {
338         return (struct efi_mem_desc *)((ulong)desc + map->desc_size);
339 }
340
341 struct efi_priv {
342         efi_handle_t parent_image;
343         struct efi_device_path *device_path;
344         struct efi_system_table *sys_table;
345         struct efi_boot_services *boot;
346         struct efi_runtime_services *run;
347         bool use_pool_for_malloc;
348         unsigned long ram_base;
349         unsigned int image_data_type;
350         struct efi_info_hdr *info;
351         unsigned int info_size;
352         void *next_hdr;
353 };
354
355 /* Base address of the EFI image */
356 extern char image_base[];
357
358 /* Start and end of U-Boot image (for payload) */
359 extern char _binary_u_boot_bin_start[], _binary_u_boot_bin_end[];
360
361 /*
362  * Variable Attributes
363  */
364 #define EFI_VARIABLE_NON_VOLATILE       0x0000000000000001
365 #define EFI_VARIABLE_BOOTSERVICE_ACCESS 0x0000000000000002
366 #define EFI_VARIABLE_RUNTIME_ACCESS     0x0000000000000004
367 #define EFI_VARIABLE_HARDWARE_ERROR_RECORD 0x0000000000000008
368 #define EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS 0x0000000000000010
369 #define EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS 0x0000000000000020
370 #define EFI_VARIABLE_APPEND_WRITE       0x0000000000000040
371
372 #define EFI_VARIABLE_MASK       (EFI_VARIABLE_NON_VOLATILE | \
373                                 EFI_VARIABLE_BOOTSERVICE_ACCESS | \
374                                 EFI_VARIABLE_RUNTIME_ACCESS | \
375                                 EFI_VARIABLE_HARDWARE_ERROR_RECORD | \
376                                 EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS | \
377                                 EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS | \
378                                 EFI_VARIABLE_APPEND_WRITE)
379
380 /**
381  * efi_get_sys_table() - Get access to the main EFI system table
382  *
383  * @return pointer to EFI system table
384  */
385
386 struct efi_system_table *efi_get_sys_table(void);
387
388 /**
389  * efi_get_ram_base() - Find the base of RAM
390  *
391  * This is used when U-Boot is built as an EFI application.
392  *
393  * @return the base of RAM as known to U-Boot
394  */
395 unsigned long efi_get_ram_base(void);
396
397 /**
398  * efi_init() - Set up ready for use of EFI boot services
399  *
400  * @priv:       Pointer to our private EFI structure to fill in
401  * @banner:     Banner to display when starting
402  * @image:      The image handle passed to efi_main()
403  * @sys_table:  The EFI system table pointer passed to efi_main()
404  */
405 int efi_init(struct efi_priv *priv, const char *banner, efi_handle_t image,
406              struct efi_system_table *sys_table);
407
408 /**
409  * efi_malloc() - Allocate some memory from EFI
410  *
411  * @priv:       Pointer to private EFI structure
412  * @size:       Number of bytes to allocate
413  * @retp:       Return EFI status result
414  * @return pointer to memory allocated, or NULL on error
415  */
416 void *efi_malloc(struct efi_priv *priv, int size, efi_status_t *retp);
417
418 /**
419  * efi_free() - Free memory allocated from EFI
420  *
421  * @priv:       Pointer to private EFI structure
422  * @ptr:        Pointer to memory to free
423  */
424 void efi_free(struct efi_priv *priv, void *ptr);
425
426 /**
427  * efi_puts() - Write out a string to the EFI console
428  *
429  * @priv:       Pointer to private EFI structure
430  * @str:        String to write (note this is a ASCII, not unicode)
431  */
432 void efi_puts(struct efi_priv *priv, const char *str);
433
434 /**
435  * efi_putc() - Write out a character to the EFI console
436  *
437  * @priv:       Pointer to private EFI structure
438  * @ch:         Character to write (note this is not unicode)
439  */
440 void efi_putc(struct efi_priv *priv, const char ch);
441
442 /**
443  * efi_info_get() - get an entry from an EFI table
444  *
445  * @type:       Entry type to search for
446  * @datap:      Returns pointer to entry data
447  * @sizep:      Returns pointer to entry size
448  * @return 0 if OK, -ENODATA if there is no table, -ENOENT if there is no entry
449  * of the requested type, -EPROTONOSUPPORT if the table has the wrong version
450  */
451 int efi_info_get(enum efi_entry_t type, void **datap, int *sizep);
452
453 /**
454  * efi_build_mem_table() - make a sorted copy of the memory table
455  *
456  * @map:        Pointer to EFI memory map table
457  * @size:       Size of table in bytes
458  * @skip_bs:    True to skip boot-time memory and merge it with conventional
459  *              memory. This will significantly reduce the number of table
460  *              entries.
461  * @return pointer to the new table. It should be freed with free() by the
462  *         caller
463  */
464 void *efi_build_mem_table(struct efi_entry_memmap *map, int size, bool skip_bs);
465
466 #endif /* _LINUX_EFI_H */