1 #ifndef _LINUX_EFI_H
2 #define _LINUX_EFI_H
3
4 /*
5 * Extensible Firmware Interface
6 * Based on 'Extensible Firmware Interface Specification' version 0.9, April 30, 1999
7 *
8 * Copyright (C) 1999 VA Linux Systems
9 * Copyright (C) 1999 Walt Drummond <drummond@valinux.com>
10 * Copyright (C) 1999, 2002 Hewlett-Packard Co.
11 * David Mosberger-Tang <davidm@hpl.hp.com>
12 * Stephane Eranian <eranian@hpl.hp.com>
13 */
14 #include <linux/init.h>
15 #include <linux/string.h>
16 #include <linux/time.h>
17 #include <linux/types.h>
18 #include <linux/proc_fs.h>
19
20 #include <asm/page.h>
21 #include <asm/system.h>
22
23 #define EFI_SUCCESS 0
24 #define EFI_LOAD_ERROR (1L | (1L << 63))
25 #define EFI_INVALID_PARAMETER (2L | (1L << 63))
26 #define EFI_UNSUPPORTED (3L | (1L << 63))
27 #define EFI_BAD_BUFFER_SIZE (4L | (1L << 63))
28 #define EFI_BUFFER_TOO_SMALL (5L | (1L << 63))
29 #define EFI_NOT_FOUND (14L | (1L << 63))
30
31 typedef unsigned long efi_status_t;
32 typedef u8 efi_bool_t;
33 typedef u16 efi_char16_t; /* UNICODE character */
34
35
36 typedef struct {
37 u8 b[16];
38 } efi_guid_t;
39
40 #define EFI_GUID(a,b,c,d0,d1,d2,d3,d4,d5,d6,d7) \
41 ((efi_guid_t) \
42 {{ (a) & 0xff, ((a) >> 8) & 0xff, ((a) >> 16) & 0xff, ((a) >> 24) & 0xff, \
43 (b) & 0xff, ((b) >> 8) & 0xff, \
44 (c) & 0xff, ((c) >> 8) & 0xff, \
45 (d0), (d1), (d2), (d3), (d4), (d5), (d6), (d7) }})
46
47 /*
48 * Generic EFI table header
49 */
50 typedef struct {
51 u64 signature;
52 u32 revision;
53 u32 headersize;
54 u32 crc32;
55 u32 reserved;
56 } efi_table_hdr_t;
57
58 /*
59 * Memory map descriptor:
60 */
61
62 /* Memory types: */
63 #define EFI_RESERVED_TYPE 0
64 #define EFI_LOADER_CODE 1
65 #define EFI_LOADER_DATA 2
66 #define EFI_BOOT_SERVICES_CODE 3
67 #define EFI_BOOT_SERVICES_DATA 4
68 #define EFI_RUNTIME_SERVICES_CODE 5
69 #define EFI_RUNTIME_SERVICES_DATA 6
70 #define EFI_CONVENTIONAL_MEMORY 7
71 #define EFI_UNUSABLE_MEMORY 8
72 #define EFI_ACPI_RECLAIM_MEMORY 9
73 #define EFI_ACPI_MEMORY_NVS 10
74 #define EFI_MEMORY_MAPPED_IO 11
75 #define EFI_MEMORY_MAPPED_IO_PORT_SPACE 12
76 #define EFI_PAL_CODE 13
77 #define EFI_MAX_MEMORY_TYPE 14
78
79 /* Attribute values: */
80 #define EFI_MEMORY_UC 0x0000000000000001 /* uncached */
81 #define EFI_MEMORY_WC 0x0000000000000002 /* write-coalescing */
82 #define EFI_MEMORY_WT 0x0000000000000004 /* write-through */
83 #define EFI_MEMORY_WB 0x0000000000000008 /* write-back */
84 #define EFI_MEMORY_WP 0x0000000000001000 /* write-protect */
85 #define EFI_MEMORY_RP 0x0000000000002000 /* read-protect */
86 #define EFI_MEMORY_XP 0x0000000000004000 /* execute-protect */
87 #define EFI_MEMORY_RUNTIME 0x8000000000000000 /* range requires runtime mapping */
88 #define EFI_MEMORY_DESCRIPTOR_VERSION 1
89
90 #define EFI_PAGE_SHIFT 12
91
92 typedef struct {
93 u32 type;
94 u32 pad;
95 u64 phys_addr;
96 u64 virt_addr;
97 u64 num_pages;
98 u64 attribute;
99 } efi_memory_desc_t;
100
101 typedef int efi_freemem_callback_t (u64 start, u64 end, void *arg);
102
103 /*
104 * Types and defines for Time Services
105 */
106 #define EFI_TIME_ADJUST_DAYLIGHT 0x1
107 #define EFI_TIME_IN_DAYLIGHT 0x2
108 #define EFI_UNSPECIFIED_TIMEZONE 0x07ff
109
110 typedef struct {
111 u16 year;
112 u8 month;
113 u8 day;
114 u8 hour;
115 u8 minute;
116 u8 second;
117 u8 pad1;
118 u32 nanosecond;
119 s16 timezone;
120 u8 daylight;
121 u8 pad2;
122 } efi_time_t;
123
124 typedef struct {
125 u32 resolution;
126 u32 accuracy;
127 u8 sets_to_zero;
128 } efi_time_cap_t;
129
130 /*
131 * Types and defines for EFI ResetSystem
132 */
133 #define EFI_RESET_COLD 0
134 #define EFI_RESET_WARM 1
135
136 /*
137 * EFI Runtime Services table
138 */
139 #define EFI_RUNTIME_SERVICES_SIGNATURE 0x5652453544e5552
140 #define EFI_RUNTIME_SERVICES_REVISION 0x00010000
141
142 typedef struct {
143 efi_table_hdr_t hdr;
144 u64 get_time;
145 u64 set_time;
146 u64 get_wakeup_time;
147 u64 set_wakeup_time;
148 u64 set_virtual_address_map;
149 u64 convert_pointer;
150 u64 get_variable;
151 u64 get_next_variable;
152 u64 set_variable;
153 u64 get_next_high_mono_count;
154 u64 reset_system;
155 } efi_runtime_services_t;
156
157 typedef efi_status_t efi_get_time_t (efi_time_t *tm, efi_time_cap_t *tc);
158 typedef efi_status_t efi_set_time_t (efi_time_t *tm);
159 typedef efi_status_t efi_get_wakeup_time_t (efi_bool_t *enabled, efi_bool_t *pending,
160 efi_time_t *tm);
161 typedef efi_status_t efi_set_wakeup_time_t (efi_bool_t enabled, efi_time_t *tm);
162 typedef efi_status_t efi_get_variable_t (efi_char16_t *name, efi_guid_t *vendor, u32 *attr,
163 unsigned long *data_size, void *data);
164 typedef efi_status_t efi_get_next_variable_t (unsigned long *name_size, efi_char16_t *name,
165 efi_guid_t *vendor);
166 typedef efi_status_t efi_set_variable_t (efi_char16_t *name, efi_guid_t *vendor, u32 attr,
167 unsigned long data_size, void *data);
168 typedef efi_status_t efi_get_next_high_mono_count_t (u64 *count);
169 typedef void efi_reset_system_t (int reset_type, efi_status_t status,
170 unsigned long data_size, efi_char16_t *data);
171
172 /*
173 * EFI Configuration Table and GUID definitions
174 */
175 #define NULL_GUID \
176 EFI_GUID( 0x00000000, 0x0000, 0x0000, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 )
177
178 #define MPS_TABLE_GUID \
179 EFI_GUID( 0xeb9d2d2f, 0x2d88, 0x11d3, 0x9a, 0x16, 0x0, 0x90, 0x27, 0x3f, 0xc1, 0x4d )
180
181 #define ACPI_TABLE_GUID \
182 EFI_GUID( 0xeb9d2d30, 0x2d88, 0x11d3, 0x9a, 0x16, 0x0, 0x90, 0x27, 0x3f, 0xc1, 0x4d )
183
184 #define ACPI_20_TABLE_GUID \
185 EFI_GUID( 0x8868e871, 0xe4f1, 0x11d3, 0xbc, 0x22, 0x0, 0x80, 0xc7, 0x3c, 0x88, 0x81 )
186
187 #define SMBIOS_TABLE_GUID \
188 EFI_GUID( 0xeb9d2d31, 0x2d88, 0x11d3, 0x9a, 0x16, 0x0, 0x90, 0x27, 0x3f, 0xc1, 0x4d )
189
190 #define SAL_SYSTEM_TABLE_GUID \
191 EFI_GUID( 0xeb9d2d32, 0x2d88, 0x11d3, 0x9a, 0x16, 0x0, 0x90, 0x27, 0x3f, 0xc1, 0x4d )
192
193 #define HCDP_TABLE_GUID \
194 EFI_GUID( 0xf951938d, 0x620b, 0x42ef, 0x82, 0x79, 0xa8, 0x4b, 0x79, 0x61, 0x78, 0x98 )
195
196 typedef struct {
197 efi_guid_t guid;
198 u64 table;
199 } efi_config_table_t;
200
201 #define EFI_SYSTEM_TABLE_SIGNATURE 0x5453595320494249
202 #define EFI_SYSTEM_TABLE_REVISION ((1 << 16) | 00)
203
204 typedef struct {
205 efi_table_hdr_t hdr;
206 u64 fw_vendor; /* physical addr of CHAR16 vendor string */
207 u32 fw_revision;
208 u64 con_in_handle;
209 u64 con_in;
210 u64 con_out_handle;
211 u64 con_out;
212 u64 stderr_handle;
213 u64 stderr;
214 u64 runtime;
215 u64 boottime;
216 u64 nr_tables;
217 u64 tables;
218 } efi_system_table_t;
219
220 /*
221 * All runtime access to EFI goes through this structure:
222 */
223 extern struct efi {
224 efi_system_table_t *systab; /* EFI system table */
225 void *mps; /* MPS table */
226 void *acpi; /* ACPI table (IA64 ext 0.71) */
227 void *acpi20; /* ACPI table (ACPI 2.0) */
228 void *smbios; /* SM BIOS table */
229 void *sal_systab; /* SAL system table */
230 void *hcdp; /* HCDP table */
231 void *boot_info; /* boot info table */
232 efi_get_time_t *get_time;
233 efi_set_time_t *set_time;
234 efi_get_wakeup_time_t *get_wakeup_time;
235 efi_set_wakeup_time_t *set_wakeup_time;
236 efi_get_variable_t *get_variable;
237 efi_get_next_variable_t *get_next_variable;
238 efi_set_variable_t *set_variable;
239 efi_get_next_high_mono_count_t *get_next_high_mono_count;
240 efi_reset_system_t *reset_system;
241 } efi;
242
243 static inline int
efi_guidcmp(efi_guid_t left,efi_guid_t right)244 efi_guidcmp (efi_guid_t left, efi_guid_t right)
245 {
246 return memcmp(&left, &right, sizeof (efi_guid_t));
247 }
248
249 static inline char *
efi_guid_unparse(efi_guid_t * guid,char * out)250 efi_guid_unparse(efi_guid_t *guid, char *out)
251 {
252 sprintf(out, "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x",
253 guid->b[3], guid->b[2], guid->b[1], guid->b[0],
254 guid->b[5], guid->b[4], guid->b[7], guid->b[6],
255 guid->b[8], guid->b[9], guid->b[10], guid->b[11],
256 guid->b[12], guid->b[13], guid->b[14], guid->b[15]);
257 return out;
258 }
259
260 extern void efi_init (void);
261 extern void efi_map_pal_code (void);
262 extern void efi_memmap_walk (efi_freemem_callback_t callback, void *arg);
263 extern void efi_gettimeofday (struct timeval *tv);
264 extern void efi_enter_virtual_mode (void); /* switch EFI to virtual mode, if possible */
265 extern u64 efi_get_iobase (void);
266 extern u32 efi_mem_type (unsigned long phys_addr);
267 extern u64 efi_mem_attributes (unsigned long phys_addr);
268
269 /*
270 * Variable Attributes
271 */
272 #define EFI_VARIABLE_NON_VOLATILE 0x0000000000000001
273 #define EFI_VARIABLE_BOOTSERVICE_ACCESS 0x0000000000000002
274 #define EFI_VARIABLE_RUNTIME_ACCESS 0x0000000000000004
275
276
277 /*
278 * efi_dir is allocated in arch/ia64/kernel/efi.c.
279 */
280 #ifdef CONFIG_PROC_FS
281 extern struct proc_dir_entry *efi_dir;
282 #endif
283
284 #endif /* _LINUX_EFI_H */
285