Imported Debian patch 0.4.9-0.sarge.2
[debian/efibootmgr] / src / include / efi.h
1 /*
2   efi.[ch] - Extensible Firmware Interface definitions
3
4   Copyright (C) 2001, 2003 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 #include <dirent.h>
31
32 #define BITS_PER_LONG (sizeof(unsigned long) * 8)
33
34 #define EFI_ERROR(x) ((x) | (1L << (BITS_PER_LONG - 1)))
35
36 #define EFI_SUCCESS             0
37 #define EFI_LOAD_ERROR          EFI_ERROR(1)
38 #define EFI_INVALID_PARAMETER   EFI_ERROR(2)
39 #define EFI_UNSUPPORTED         EFI_ERROR(3)
40 #define EFI_BAD_BUFFER_SIZE     EFI_ERROR(4)
41 #define EFI_BUFFER_TOO_SMALL    EFI_ERROR(5)
42 #define EFI_NOT_FOUND           EFI_ERROR(14)
43 #define EFI_OUT_OF_RESOURCES    EFI_ERROR(15)
44
45
46 /*******************************************************
47  * Boot Option Attributes
48  *******************************************************/
49 #define LOAD_OPTION_ACTIVE 0x00000001
50
51 /******************************************************
52  * EFI Variable Attributes
53  ******************************************************/
54 #define EFI_VARIABLE_NON_VOLATILE 0x0000000000000001
55 #define EFI_VARIABLE_BOOTSERVICE_ACCESS 0x0000000000000002
56 #define EFI_VARIABLE_RUNTIME_ACCESS 0x0000000000000004
57
58
59 typedef struct {
60         uint8_t  b[16];
61 } efi_guid_t;
62
63 #define EFI_GUID(a,b,c,d0,d1,d2,d3,d4,d5,d6,d7) \
64 ((efi_guid_t) \
65 {{ (a) & 0xff, ((a) >> 8) & 0xff, ((a) >> 16) & 0xff, ((a) >> 24) & 0xff, \
66   (b) & 0xff, ((b) >> 8) & 0xff, \
67   (c) & 0xff, ((c) >> 8) & 0xff, \
68   (d0), (d1), (d2), (d3), (d4), (d5), (d6), (d7) }})
69
70
71 /******************************************************
72  * GUIDs
73  ******************************************************/
74 #define DEVICE_PATH_PROTOCOL \
75 EFI_GUID( 0x09576e91, 0x6d3f, 0x11d2, 0x8e, 0x39, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b)
76 #define EFI_GLOBAL_VARIABLE \
77 EFI_GUID( 0x8BE4DF61, 0x93CA, 0x11d2, 0xAA, 0x0D, 0x00, 0xE0, 0x98, 0x03, 0x2B, 0x8C)
78 #define EDD10_HARDWARE_VENDOR_PATH_GUID \
79 EFI_GUID( 0xCF31FAC5, 0xC24E, 0x11d2, 0x85, 0xF3, 0x00, 0xA0, 0xC9, 0x3E, 0xC9, 0x3B)
80 #define BLKX_UNKNOWN_GUID \
81 EFI_GUID( 0x47c7b225, 0xc42a, 0x11d2, 0x8e, 0x57, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b)
82 #define DIR_UNKNOWN_GUID \
83 EFI_GUID( 0x47c7b227, 0xc42a, 0x11d2, 0x8e, 0x57, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b)
84 #define ESP_UNKNOWN_GUID \
85 EFI_GUID( 0x47c7b226, 0xc42a, 0x11d2, 0x8e, 0x57, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b)
86
87 static inline int
88 efi_guidcmp(efi_guid_t left, efi_guid_t right)
89 {
90         return memcmp(&left, &right, sizeof (efi_guid_t));
91 }
92
93
94 typedef unsigned long efi_status_t;
95 typedef uint8_t  efi_bool_t;
96 typedef uint16_t efi_char16_t;          /* UNICODE character */
97
98 typedef struct _efi_variable_t {
99         efi_char16_t  VariableName[1024/sizeof(efi_char16_t)];
100         efi_guid_t    VendorGuid;
101         uint64_t         DataSize;
102         uint8_t          Data[1024];
103         efi_status_t  Status;
104         uint32_t         Attributes;
105 } __attribute__((packed)) efi_variable_t;
106
107
108 typedef struct {
109         uint8_t  type;
110         uint8_t  subtype;
111         uint16_t length;
112         uint8_t  data[1];
113 } __attribute__((packed)) EFI_DEVICE_PATH;
114
115 typedef struct {
116         uint32_t attributes;
117         uint16_t file_path_list_length;
118         efi_char16_t description[1];
119         EFI_DEVICE_PATH _unused_file_path_list[1];
120 } __attribute__((packed)) EFI_LOAD_OPTION;
121
122
123 typedef struct {
124         uint8_t type;
125         uint8_t subtype;
126         uint16_t length;
127         uint32_t _HID;
128         uint32_t _UID;
129 } __attribute__((packed)) ACPI_DEVICE_PATH;
130
131 typedef struct {
132         uint8_t type;
133         uint8_t subtype;
134         uint16_t length;
135         efi_guid_t vendor_guid;
136         uint8_t data[1];
137 } __attribute__((packed)) VENDOR_DEVICE_PATH;
138
139 #define EDD10_HARDWARE_VENDOR_PATH_LENGTH 24
140
141 typedef struct {
142         uint8_t type;
143         uint8_t subtype;
144         uint16_t length;
145         uint8_t function;
146         uint8_t device;
147 } __attribute__((packed)) PCI_DEVICE_PATH;
148
149 typedef struct {
150         uint8_t type;
151         uint8_t subtype;
152         uint16_t length;
153         uint8_t  socket;
154 } __attribute__((packed)) PCCARD_DEVICE_PATH;
155
156 typedef struct {
157         uint8_t type;
158         uint8_t subtype;
159         uint16_t length;
160         uint32_t memory_type;
161         uint64_t start;
162         uint64_t end;
163 } __attribute__((packed)) MEMORY_MAPPED_DEVICE_PATH;
164
165 typedef struct {
166         uint8_t type;
167         uint8_t subtype;
168         uint16_t length;
169         uint32_t controller;
170 } __attribute__((packed)) CONTROLLER_DEVICE_PATH;
171
172
173 typedef struct {
174         uint8_t type;
175         uint8_t subtype;
176         uint16_t length;
177         uint16_t id;
178         uint16_t lun;
179 } __attribute__((packed)) SCSI_DEVICE_PATH;
180
181 typedef struct {
182         uint8_t type;
183         uint8_t subtype;
184         uint16_t length;
185         uint8_t  primary_secondary;
186         uint8_t  slave_master;
187         uint16_t lun;
188 } __attribute__((packed)) ATAPI_DEVICE_PATH;
189
190 typedef struct {
191         uint8_t type;
192         uint8_t subtype;
193         uint16_t length;
194         uint32_t reserved;
195         uint64_t wwn;
196         uint64_t lun;
197 } __attribute__((packed)) FIBRE_CHANNEL_DEVICE_PATH;
198
199 typedef struct {
200         uint8_t type;
201         uint8_t subtype;
202         uint16_t length;
203         uint32_t reserved;
204         uint64_t guid;
205 } __attribute__((packed)) I1394_DEVICE_PATH;
206
207 typedef struct {
208         uint8_t type;
209         uint8_t subtype;
210         uint16_t length;
211         uint8_t  port;
212         uint8_t  endpoint;
213 } __attribute__((packed)) USB_DEVICE_PATH;
214
215 typedef struct {
216         uint8_t type;
217         uint8_t subtype;
218         uint16_t length;
219         uint16_t vendor;
220         uint16_t product;
221         uint8_t  class;
222         uint8_t  subclass;
223         uint8_t  protocol;
224 } __attribute__((packed)) USB_CLASS_DEVICE_PATH;
225
226 typedef struct {
227         uint8_t type;
228         uint8_t subtype;
229         uint16_t length;
230         uint32_t tid;
231 } __attribute__((packed)) I2O_DEVICE_PATH;
232
233 typedef struct {
234         uint8_t type;
235         uint8_t subtype;
236         uint16_t length;
237         uint8_t macaddr[32];
238         uint8_t iftype;
239 } __attribute__((packed)) MAC_ADDR_DEVICE_PATH;
240
241 typedef struct {
242         uint8_t type;
243         uint8_t subtype;
244         uint16_t length;
245         uint32_t local_ip;
246         uint32_t remote_ip;
247         uint16_t local_port;
248         uint16_t remote_port;
249         uint16_t protocol;
250         uint8_t  static_addr;
251 } __attribute__((packed)) IPv4_DEVICE_PATH;
252
253 typedef struct {
254         uint8_t type;
255         uint8_t subtype;
256         uint16_t length;
257         uint8_t  local_ip[16];
258         uint8_t  remote_ip[16];
259         uint16_t local_port;
260         uint16_t remote_port;
261         uint16_t protocol;
262         uint8_t  static_addr;
263 } __attribute__((packed)) IPv6_DEVICE_PATH;
264
265 typedef struct {
266         uint8_t type;
267         uint8_t subtype;
268         uint16_t length;
269         uint32_t reserved;
270         uint64_t node_guid;
271         uint64_t ioc_guid;
272         uint64_t id; 
273 } __attribute__((packed)) INFINIBAND_DEVICE_PATH;
274
275 typedef struct {
276         uint8_t type;
277         uint8_t subtype;
278         uint16_t length;
279         uint32_t reserved;
280         uint64_t baud_rate;
281         uint8_t  data_bits;
282         uint8_t  parity;
283         uint8_t  stop_bits;
284 } __attribute__((packed)) UART_DEVICE_PATH;
285
286
287 typedef struct {
288         uint8_t type;
289         uint8_t subtype;
290         uint16_t length;
291         uint32_t part_num;
292         uint64_t start;
293         uint64_t size;
294         uint8_t  signature[16];
295         uint8_t  mbr_type;
296         uint8_t  signature_type;
297         uint8_t  padding[6]; /* Emperically needed */
298 } __attribute__((packed)) HARDDRIVE_DEVICE_PATH;
299
300 typedef struct {
301         uint8_t type;
302         uint8_t subtype;
303         uint16_t length;
304         uint32_t boot_entry;
305         uint64_t start;
306         uint64_t size;
307 } __attribute__((packed)) CDROM_DEVICE_PATH;
308
309 typedef struct {
310         uint8_t type;
311         uint8_t subtype;
312         uint16_t length;
313         efi_char16_t path_name[1];
314 } __attribute__((packed)) FILE_PATH_DEVICE_PATH;
315
316
317 typedef struct {
318         uint8_t type;
319         uint8_t subtype;
320         uint16_t length;
321         efi_guid_t guid;
322 } __attribute__((packed)) MEDIA_PROTOCOL_DEVICE_PATH;
323
324 typedef struct {
325         uint8_t type;
326         uint8_t subtype;
327         uint16_t length;
328         uint16_t device_type;
329         uint16_t status_flag;
330         uint8_t  description[1];
331 } __attribute__((packed)) BIOS_BOOT_SPEC_DEVICE_PATH;
332
333 typedef struct {
334         uint8_t  type;
335         uint8_t  subtype;
336         uint16_t length;
337 } __attribute__((packed)) END_DEVICE_PATH;
338
339
340 struct efivar_kernel_calls {
341         efi_status_t (*read)(const char *name, efi_variable_t *var);
342         efi_status_t (*edit)(const char *name, efi_variable_t *var);
343         efi_status_t (*create)(efi_variable_t *var);
344         efi_status_t (*delete)(efi_variable_t *var);
345         char *path;
346 };
347
348
349 /* Used for ACPI _HID */
350 #define EISAID_PNP0A03 0xa0341d0
351
352 /* Exported functions */
353
354 extern int make_linux_efi_variable(efi_variable_t *var,
355                             unsigned int free_number);
356 extern char * efi_guid_unparse(efi_guid_t *guid, char *out);
357 extern EFI_DEVICE_PATH *load_option_path(EFI_LOAD_OPTION *option);
358
359 extern efi_status_t read_variable(const char *name, efi_variable_t *var);
360 extern efi_status_t edit_variable(efi_variable_t *var);
361 extern efi_status_t create_variable(efi_variable_t *var);
362 extern efi_status_t delete_variable(efi_variable_t *var);
363 extern efi_status_t create_or_edit_variable(efi_variable_t *var);
364
365 extern void set_fs_kernel_calls();
366 extern int read_boot_var_names(struct dirent ***namelist);
367 extern int variable_to_name(efi_variable_t *var, char *name);
368 extern int var_name_to_path(const char *name, char *path);
369
370 #endif /* EFI_H */