]> git.gag.com Git - debian/efibootmgr/blob - src/include/efi.h
Imported Upstream version 0.4.2
[debian/efibootmgr] / src / include / efi.h
1 /*
2   efi.[ch] - Manipulates EFI variables as exported in /proc/efi/vars
3  
4   Copyright (C) 2001 Dell Computer Corporation <Matt_Domsch@dell.com>
5  
6     This program is free software; you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation; either version 2 of the License, or
9     (at your option) any later version.
10
11     This program is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15
16     You should have received a copy of the GNU General Public License
17     along with this program; if not, write to the Free Software
18     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  */
20
21 #ifndef EFI_H
22 #define EFI_H
23
24 /*
25  * Extensible Firmware Interface
26  * Based on 'Extensible Firmware Interface Specification'
27  *      version 1.02, 12 December, 2000
28  */
29 #include <stdint.h>
30
31 #define BITS_PER_LONG (sizeof(unsigned long) * 8)
32
33 #define EFI_ERROR(x) ((x) | (1L << (BITS_PER_LONG - 1)))
34
35 #define EFI_SUCCESS             0
36 #define EFI_LOAD_ERROR          EFI_ERROR(1)
37 #define EFI_INVALID_PARAMETER   EFI_ERROR(2)
38 #define EFI_UNSUPPORTED         EFI_ERROR(3)
39 #define EFI_BAD_BUFFER_SIZE     EFI_ERROR(4)
40 #define EFI_BUFFER_TOO_SMALL    EFI_ERROR(5)
41 #define EFI_NOT_FOUND           EFI_ERROR(14)
42 #define EFI_OUT_OF_RESOURCES    EFI_ERROR(15)
43
44
45 /*******************************************************
46  * Boot Option Attributes
47  *******************************************************/
48 #define LOAD_OPTION_ACTIVE 0x00000001
49
50 /******************************************************
51  * EFI Variable Attributes
52  ******************************************************/
53 #define EFI_VARIABLE_NON_VOLATILE 0x0000000000000001
54 #define EFI_VARIABLE_BOOTSERVICE_ACCESS 0x0000000000000002
55 #define EFI_VARIABLE_RUNTIME_ACCESS 0x0000000000000004
56
57
58 typedef struct {
59         uint8_t  b[16];
60 } efi_guid_t;
61
62 #define EFI_GUID(a,b,c,d0,d1,d2,d3,d4,d5,d6,d7) \
63 ((efi_guid_t) \
64 {{ (a) & 0xff, ((a) >> 8) & 0xff, ((a) >> 16) & 0xff, ((a) >> 24) & 0xff, \
65   (b) & 0xff, ((b) >> 8) & 0xff, \
66   (c) & 0xff, ((c) >> 8) & 0xff, \
67   (d0), (d1), (d2), (d3), (d4), (d5), (d6), (d7) }})
68
69
70 /******************************************************
71  * GUIDs
72  ******************************************************/
73 #define DEVICE_PATH_PROTOCOL \
74 EFI_GUID( 0x09576e91, 0x6d3f, 0x11d2, 0x8e, 0x39, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b)
75 #define EFI_GLOBAL_VARIABLE \
76 EFI_GUID( 0x8BE4DF61, 0x93CA, 0x11d2, 0xAA, 0x0D, 0x00, 0xE0, 0x98, 0x03, 0x2B, 0x8C)
77 #define EDD10_HARDWARE_VENDOR_PATH_GUID \
78 EFI_GUID( 0xCF31FAC5, 0xC24E, 0x11d2, 0x85, 0xF3, 0x00, 0xA0, 0xC9, 0x3E, 0xC9, 0x3B)
79 #define BLKX_UNKNOWN_GUID \
80 EFI_GUID( 0x47c7b225, 0xc42a, 0x11d2, 0x8e, 0x57, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b)
81 #define DIR_UNKNOWN_GUID \
82 EFI_GUID( 0x47c7b227, 0xc42a, 0x11d2, 0x8e, 0x57, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b)
83 #define ESP_UNKNOWN_GUID \
84 EFI_GUID( 0x47c7b226, 0xc42a, 0x11d2, 0x8e, 0x57, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b)
85
86 static inline int
87 efi_guidcmp(efi_guid_t left, efi_guid_t right)
88 {
89         return memcmp(&left, &right, sizeof (efi_guid_t));
90 }
91
92
93 typedef unsigned long efi_status_t;
94 typedef uint8_t  efi_bool_t;
95 typedef uint16_t efi_char16_t;          /* UNICODE character */
96
97 typedef struct _efi_variable_t {
98         efi_char16_t  VariableName[1024/sizeof(efi_char16_t)];
99         efi_guid_t    VendorGuid;
100         uint64_t         DataSize;
101         uint8_t          Data[1024];
102         efi_status_t  Status;
103         uint32_t         Attributes;
104 } __attribute__((packed)) efi_variable_t;
105
106
107 typedef struct {
108         uint8_t  type;
109         uint8_t  subtype;
110         uint16_t length;
111         uint8_t  data[1];
112 } __attribute__((packed)) EFI_DEVICE_PATH;
113
114 typedef struct {
115         uint32_t attributes;
116         uint16_t file_path_list_length;
117         efi_char16_t description[1];
118         EFI_DEVICE_PATH _unused_file_path_list[1];
119 } __attribute__((packed)) EFI_LOAD_OPTION;
120
121
122 typedef struct {
123         uint8_t type;
124         uint8_t subtype;
125         uint16_t length;
126         uint32_t _HID;
127         uint32_t _UID;
128 } __attribute__((packed)) ACPI_DEVICE_PATH;
129
130 typedef struct {
131         uint8_t type;
132         uint8_t subtype;
133         uint16_t length;
134         efi_guid_t vendor_guid;
135         uint8_t data[1];
136 } __attribute__((packed)) VENDOR_DEVICE_PATH;
137
138 #define EDD10_HARDWARE_VENDOR_PATH_LENGTH 24
139
140 typedef struct {
141         uint8_t type;
142         uint8_t subtype;
143         uint16_t length;
144         uint8_t function;
145         uint8_t device;
146 } __attribute__((packed)) PCI_DEVICE_PATH;
147
148 typedef struct {
149         uint8_t type;
150         uint8_t subtype;
151         uint16_t length;
152         uint8_t  socket;
153 } __attribute__((packed)) PCCARD_DEVICE_PATH;
154
155 typedef struct {
156         uint8_t type;
157         uint8_t subtype;
158         uint16_t length;
159         uint32_t memory_type;
160         uint64_t start;
161         uint64_t end;
162 } __attribute__((packed)) MEMORY_MAPPED_DEVICE_PATH;
163
164 typedef struct {
165         uint8_t type;
166         uint8_t subtype;
167         uint16_t length;
168         uint32_t controller;
169 } __attribute__((packed)) CONTROLLER_DEVICE_PATH;
170
171
172 typedef struct {
173         uint8_t type;
174         uint8_t subtype;
175         uint16_t length;
176         uint16_t id;
177         uint16_t lun;
178 } __attribute__((packed)) SCSI_DEVICE_PATH;
179
180 typedef struct {
181         uint8_t type;
182         uint8_t subtype;
183         uint16_t length;
184         uint8_t  primary_secondary;
185         uint8_t  slave_master;
186         uint16_t lun;
187 } __attribute__((packed)) ATAPI_DEVICE_PATH;
188
189 typedef struct {
190         uint8_t type;
191         uint8_t subtype;
192         uint16_t length;
193         uint32_t reserved;
194         uint64_t wwn;
195         uint64_t lun;
196 } __attribute__((packed)) FIBRE_CHANNEL_DEVICE_PATH;
197
198 typedef struct {
199         uint8_t type;
200         uint8_t subtype;
201         uint16_t length;
202         uint32_t reserved;
203         uint64_t guid;
204 } __attribute__((packed)) I1394_DEVICE_PATH;
205
206 typedef struct {
207         uint8_t type;
208         uint8_t subtype;
209         uint16_t length;
210         uint8_t  port;
211         uint8_t  endpoint;
212 } __attribute__((packed)) USB_DEVICE_PATH;
213
214 typedef struct {
215         uint8_t type;
216         uint8_t subtype;
217         uint16_t length;
218         uint16_t vendor;
219         uint16_t product;
220         uint8_t  class;
221         uint8_t  subclass;
222         uint8_t  protocol;
223 } __attribute__((packed)) USB_CLASS_DEVICE_PATH;
224
225 typedef struct {
226         uint8_t type;
227         uint8_t subtype;
228         uint16_t length;
229         uint32_t tid;
230 } __attribute__((packed)) I2O_DEVICE_PATH;
231
232 typedef struct {
233         uint8_t type;
234         uint8_t subtype;
235         uint16_t length;
236         uint8_t macaddr[32];
237         uint8_t iftype;
238 } __attribute__((packed)) MAC_ADDR_DEVICE_PATH;
239
240 typedef struct {
241         uint8_t type;
242         uint8_t subtype;
243         uint16_t length;
244         uint32_t local_ip;
245         uint32_t remote_ip;
246         uint16_t local_port;
247         uint16_t remote_port;
248         uint16_t protocol;
249         uint8_t  static_addr;
250 } __attribute__((packed)) IPv4_DEVICE_PATH;
251
252 typedef struct {
253         uint8_t type;
254         uint8_t subtype;
255         uint16_t length;
256         uint8_t  local_ip[16];
257         uint8_t  remote_ip[16];
258         uint16_t local_port;
259         uint16_t remote_port;
260         uint16_t protocol;
261         uint8_t  static_addr;
262 } __attribute__((packed)) IPv6_DEVICE_PATH;
263
264 typedef struct {
265         uint8_t type;
266         uint8_t subtype;
267         uint16_t length;
268         uint32_t reserved;
269         uint64_t node_guid;
270         uint64_t ioc_guid;
271         uint64_t id; 
272 } __attribute__((packed)) INFINIBAND_DEVICE_PATH;
273
274 typedef struct {
275         uint8_t type;
276         uint8_t subtype;
277         uint16_t length;
278         uint32_t reserved;
279         uint64_t baud_rate;
280         uint8_t  data_bits;
281         uint8_t  parity;
282         uint8_t  stop_bits;
283 } __attribute__((packed)) UART_DEVICE_PATH;
284
285
286 typedef struct {
287         uint8_t type;
288         uint8_t subtype;
289         uint16_t length;
290         uint32_t part_num;
291         uint64_t start;
292         uint64_t size;
293         uint8_t  signature[16];
294         uint8_t  mbr_type;
295         uint8_t  signature_type;
296         uint8_t  padding[6]; /* Emperically needed */
297 } __attribute__((packed)) HARDDRIVE_DEVICE_PATH;
298
299 typedef struct {
300         uint8_t type;
301         uint8_t subtype;
302         uint16_t length;
303         uint32_t boot_entry;
304         uint64_t start;
305         uint64_t size;
306 } __attribute__((packed)) CDROM_DEVICE_PATH;
307
308 typedef struct {
309         uint8_t type;
310         uint8_t subtype;
311         uint16_t length;
312         efi_char16_t path_name[1];
313 } __attribute__((packed)) FILE_PATH_DEVICE_PATH;
314
315
316 typedef struct {
317         uint8_t type;
318         uint8_t subtype;
319         uint16_t length;
320         efi_guid_t guid;
321 } __attribute__((packed)) MEDIA_PROTOCOL_DEVICE_PATH;
322
323 typedef struct {
324         uint8_t type;
325         uint8_t subtype;
326         uint16_t length;
327         uint16_t device_type;
328         uint16_t status_flag;
329         uint8_t  description[1];
330 } __attribute__((packed)) BIOS_BOOT_SPEC_DEVICE_PATH;
331
332 typedef struct {
333         uint8_t  type;
334         uint8_t  subtype;
335         uint16_t length;
336 } __attribute__((packed)) END_DEVICE_PATH;
337
338
339 /* Used for ACPI _HID */
340 #define EISAID_PNP0A03 0xa0341d0
341
342 #define PROC_DIR_EFI_VARS "/proc/efi/vars/"
343
344
345
346 /* Exported functions */
347
348 efi_status_t read_variable(char *name, efi_variable_t *var);
349 efi_status_t write_variable(efi_variable_t *var);
350 int make_linux_efi_variable(efi_variable_t *var,
351                             unsigned int free_number);
352 char * efi_guid_unparse(efi_guid_t *guid, char *out);
353 EFI_DEVICE_PATH *load_option_path(EFI_LOAD_OPTION *option);
354
355
356
357
358
359 #endif /* _ASM_IA64_EFI_H */