]> git.proxmox.com Git - grub2.git/blame - kern/efi/efi.c
2008-07-17 Pavel Roskin <proski@gnu.org>
[grub2.git] / kern / efi / efi.c
CommitLineData
83709125 1/* efi.c - generic EFI support */
2/*
3 * GRUB -- GRand Unified Bootloader
f714229e 4 * Copyright (C) 2006,2007,2008 Free Software Foundation, Inc.
83709125 5 *
5a79f472 6 * GRUB is free software: you can redistribute it and/or modify
83709125 7 * it under the terms of the GNU General Public License as published by
5a79f472 8 * the Free Software Foundation, either version 3 of the License, or
83709125 9 * (at your option) any later version.
10 *
5a79f472 11 * GRUB is distributed in the hope that it will be useful,
83709125 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
5a79f472 17 * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
83709125 18 */
19
20#include <grub/misc.h>
21#include <grub/efi/api.h>
22#include <grub/efi/efi.h>
23#include <grub/efi/console_control.h>
2eab1c0d 24#include <grub/efi/pe32.h>
976a4ea0 25#include <grub/machine/time.h>
26#include <grub/term.h>
2eab1c0d 27#include <grub/kernel.h>
9cacaa17 28#include <grub/mm.h>
83709125 29
30/* The handle of GRUB itself. Filled in by the startup code. */
31grub_efi_handle_t grub_efi_image_handle;
32
33/* The pointer to a system table. Filled in by the startup code. */
34grub_efi_system_table_t *grub_efi_system_table;
35
9cacaa17 36static grub_efi_guid_t console_control_guid = GRUB_EFI_CONSOLE_CONTROL_GUID;
37static grub_efi_guid_t loaded_image_guid = GRUB_EFI_LOADED_IMAGE_GUID;
7f362539 38static grub_efi_guid_t device_path_guid = GRUB_EFI_DEVICE_PATH_GUID;
83709125 39
40void *
41grub_efi_locate_protocol (grub_efi_guid_t *protocol, void *registration)
42{
43 void *interface;
44 grub_efi_status_t status;
45
20011694 46 status = efi_call_3 (grub_efi_system_table->boot_services->locate_protocol,
47 protocol, registration, &interface);
83709125 48 if (status != GRUB_EFI_SUCCESS)
49 return 0;
50
51 return interface;
52}
53
9cacaa17 54/* Return the array of handles which meet the requirement. If successful,
55 the number of handles is stored in NUM_HANDLES. The array is allocated
56 from the heap. */
57grub_efi_handle_t *
58grub_efi_locate_handle (grub_efi_locate_search_type_t search_type,
59 grub_efi_guid_t *protocol,
60 void *search_key,
61 grub_efi_uintn_t *num_handles)
62{
63 grub_efi_boot_services_t *b;
64 grub_efi_status_t status;
65 grub_efi_handle_t *buffer;
66 grub_efi_uintn_t buffer_size = 8 * sizeof (grub_efi_handle_t);
67
68 buffer = grub_malloc (buffer_size);
69 if (! buffer)
70 return 0;
71
72 b = grub_efi_system_table->boot_services;
20011694 73 status = efi_call_5 (b->locate_handle, search_type, protocol, search_key,
9cacaa17 74 &buffer_size, buffer);
75 if (status == GRUB_EFI_BUFFER_TOO_SMALL)
76 {
77 grub_free (buffer);
78 buffer = grub_malloc (buffer_size);
79 if (! buffer)
80 return 0;
81
20011694 82 status = efi_call_5 (b->locate_handle, search_type, protocol, search_key,
9cacaa17 83 &buffer_size, buffer);
84 }
85
86 if (status != GRUB_EFI_SUCCESS)
87 {
88 grub_free (buffer);
89 return 0;
90 }
91
92 *num_handles = buffer_size / sizeof (grub_efi_handle_t);
93 return buffer;
94}
95
96void *
97grub_efi_open_protocol (grub_efi_handle_t handle,
98 grub_efi_guid_t *protocol,
99 grub_efi_uint32_t attributes)
100{
101 grub_efi_boot_services_t *b;
102 grub_efi_status_t status;
103 void *interface;
104
105 b = grub_efi_system_table->boot_services;
20011694 106 status = efi_call_6 (b->open_protocol, handle,
107 protocol,
108 &interface,
109 grub_efi_image_handle,
110 0,
111 attributes);
9cacaa17 112 if (status != GRUB_EFI_SUCCESS)
113 return 0;
114
115 return interface;
116}
117
83709125 118int
119grub_efi_set_text_mode (int on)
120{
121 grub_efi_console_control_protocol_t *c;
122 grub_efi_screen_mode_t mode, new_mode;
123
9cacaa17 124 c = grub_efi_locate_protocol (&console_control_guid, 0);
83709125 125 if (! c)
bc8c036d 126 /* No console control protocol instance available, assume it is
127 already in text mode. */
128 return 1;
83709125 129
20011694 130 if (efi_call_4 (c->get_mode, c, &mode, 0, 0) != GRUB_EFI_SUCCESS)
83709125 131 return 0;
132
133 new_mode = on ? GRUB_EFI_SCREEN_TEXT : GRUB_EFI_SCREEN_GRAPHICS;
134 if (mode != new_mode)
20011694 135 if (efi_call_2 (c->set_mode, c, new_mode) != GRUB_EFI_SUCCESS)
83709125 136 return 0;
137
138 return 1;
139}
140
976a4ea0 141void
142grub_efi_stall (grub_efi_uintn_t microseconds)
83709125 143{
20011694 144 efi_call_1 (grub_efi_system_table->boot_services->stall, microseconds);
976a4ea0 145}
83709125 146
2eab1c0d 147grub_efi_loaded_image_t *
7f362539 148grub_efi_get_loaded_image (grub_efi_handle_t image_handle)
2eab1c0d 149{
7f362539 150 return grub_efi_open_protocol (image_handle,
9cacaa17 151 &loaded_image_guid,
152 GRUB_EFI_OPEN_PROTOCOL_GET_PROTOCOL);
2eab1c0d 153}
154
976a4ea0 155void
9cacaa17 156grub_exit (void)
976a4ea0 157{
2965c7cc 158 grub_efi_fini ();
20011694 159 efi_call_4 (grub_efi_system_table->boot_services->exit,
160 grub_efi_image_handle, GRUB_EFI_SUCCESS, 0, 0);
83709125 161}
162
f714229e 163void
164grub_reboot (void)
165{
166 grub_efi_fini ();
20011694 167 efi_call_4 (grub_efi_system_table->runtime_services->reset_system,
168 GRUB_EFI_RESET_COLD, GRUB_EFI_SUCCESS, 0, NULL);
f714229e 169}
170
171void
172grub_halt (void)
173{
174 grub_efi_fini ();
20011694 175 efi_call_4 (grub_efi_system_table->runtime_services->reset_system,
176 GRUB_EFI_RESET_SHUTDOWN, GRUB_EFI_SUCCESS, 0, NULL);
f714229e 177}
178
89a7d726 179int
180grub_efi_exit_boot_services (grub_efi_uintn_t map_key)
181{
182 grub_efi_boot_services_t *b;
183 grub_efi_status_t status;
184
185 b = grub_efi_system_table->boot_services;
20011694 186 status = efi_call_2 (b->exit_boot_services, grub_efi_image_handle, map_key);
89a7d726 187 return status == GRUB_EFI_SUCCESS;
188}
189
976a4ea0 190grub_uint32_t
191grub_get_rtc (void)
192{
193 grub_efi_time_t time;
194 grub_efi_runtime_services_t *r;
195
196 r = grub_efi_system_table->runtime_services;
20011694 197 if (efi_call_2 (r->get_time, &time, 0) != GRUB_EFI_SUCCESS)
976a4ea0 198 /* What is possible in this case? */
199 return 0;
200
201 return (((time.minute * 60 + time.second) * 1000
202 + time.nanosecond / 1000000)
203 * GRUB_TICKS_PER_SECOND / 1000);
204}
2eab1c0d 205
206/* Search the mods section from the PE32/PE32+ image. This code uses
207 a PE32 header, but should work with PE32+ as well. */
208grub_addr_t
209grub_arch_modules_addr (void)
210{
211 grub_efi_loaded_image_t *image;
212 struct grub_pe32_header *header;
213 struct grub_pe32_coff_header *coff_header;
214 struct grub_pe32_section_table *sections;
215 struct grub_pe32_section_table *section;
216 struct grub_module_info *info;
217 grub_uint16_t i;
218
7f362539 219 image = grub_efi_get_loaded_image (grub_efi_image_handle);
2eab1c0d 220 if (! image)
221 return 0;
222
223 header = image->image_base;
224 coff_header = &(header->coff_header);
225 sections
226 = (struct grub_pe32_section_table *) ((char *) coff_header
227 + sizeof (*coff_header)
228 + coff_header->optional_header_size);
229
230 for (i = 0, section = sections;
231 i < coff_header->num_sections;
232 i++, section++)
233 {
234 if (grub_strcmp (section->name, "mods") == 0)
235 break;
236 }
237
238 if (i == coff_header->num_sections)
239 return 0;
240
241 info = (struct grub_module_info *) ((char *) image->image_base
242 + section->virtual_address);
243 if (info->magic != GRUB_MODULE_MAGIC)
244 return 0;
245
246 return (grub_addr_t) info;
247}
9cacaa17 248
2965c7cc 249char *
250grub_efi_get_filename (grub_efi_device_path_t *dp)
251{
252 char *name = 0;
253
254 while (1)
255 {
256 grub_efi_uint8_t type = GRUB_EFI_DEVICE_PATH_TYPE (dp);
257 grub_efi_uint8_t subtype = GRUB_EFI_DEVICE_PATH_SUBTYPE (dp);
258
259 if (type == GRUB_EFI_END_DEVICE_PATH_TYPE)
260 break;
261 else if (type == GRUB_EFI_MEDIA_DEVICE_PATH_TYPE
262 && subtype == GRUB_EFI_FILE_PATH_DEVICE_PATH_SUBTYPE)
263 {
264 grub_efi_file_path_device_path_t *fp;
265 grub_efi_uint16_t len;
266 char *p;
267 grub_size_t size;
268
269 if (name)
270 {
271 size = grub_strlen (name);
272 name[size] = '/';
273 size++;
274 }
275 else
276 size = 0;
277
7f362539 278 len = ((GRUB_EFI_DEVICE_PATH_LENGTH (dp) - 4)
279 / sizeof (grub_efi_char16_t));
2965c7cc 280 p = grub_realloc (name, size + len * 4 + 1);
281 if (! p)
282 {
283 grub_free (name);
284 return 0;
285 }
286
287 name = p;
288 fp = (grub_efi_file_path_device_path_t *) dp;
289 *grub_utf16_to_utf8 ((grub_uint8_t *) name + size,
290 fp->path_name, len) = '\0';
291 }
292
293 dp = GRUB_EFI_NEXT_DEVICE_PATH (dp);
294 }
295
296 if (name)
297 {
298 /* EFI breaks paths with backslashes. */
299 char *p;
300
301 for (p = name; *p; p++)
302 if (*p == '\\')
303 *p = '/';
304 }
305
306 return name;
307}
308
7f362539 309grub_efi_device_path_t *
310grub_efi_get_device_path (grub_efi_handle_t handle)
311{
312 return grub_efi_open_protocol (handle, &device_path_guid,
313 GRUB_EFI_OPEN_PROTOCOL_GET_PROTOCOL);
314}
315
9cacaa17 316/* Print the chain of Device Path nodes. This is mainly for debugging. */
317void
2965c7cc 318grub_efi_print_device_path (grub_efi_device_path_t *dp)
9cacaa17 319{
320 while (1)
321 {
322 grub_efi_uint8_t type = GRUB_EFI_DEVICE_PATH_TYPE (dp);
323 grub_efi_uint8_t subtype = GRUB_EFI_DEVICE_PATH_SUBTYPE (dp);
324 grub_efi_uint16_t len = GRUB_EFI_DEVICE_PATH_LENGTH (dp);
325
326 switch (type)
327 {
328 case GRUB_EFI_END_DEVICE_PATH_TYPE:
329 switch (subtype)
330 {
331 case GRUB_EFI_END_ENTIRE_DEVICE_PATH_SUBTYPE:
7f362539 332 grub_printf ("/EndEntire\n");
333 //grub_putchar ('\n');
9cacaa17 334 break;
335 case GRUB_EFI_END_THIS_DEVICE_PATH_SUBTYPE:
7f362539 336 grub_printf ("/EndThis\n");
337 //grub_putchar ('\n');
9cacaa17 338 break;
339 default:
340 grub_printf ("/EndUnknown(%x)\n", (unsigned) subtype);
341 break;
342 }
343 break;
344
345 case GRUB_EFI_HARDWARE_DEVICE_PATH_TYPE:
346 switch (subtype)
347 {
348 case GRUB_EFI_PCI_DEVICE_PATH_SUBTYPE:
349 {
350 grub_efi_pci_device_path_t pci;
351 grub_memcpy (&pci, dp, len);
352 grub_printf ("/PCI(%x,%x)",
353 (unsigned) pci.function, (unsigned) pci.device);
354 }
355 break;
356 case GRUB_EFI_PCCARD_DEVICE_PATH_SUBTYPE:
357 {
358 grub_efi_pccard_device_path_t pccard;
359 grub_memcpy (&pccard, dp, len);
360 grub_printf ("/PCCARD(%x)",
361 (unsigned) pccard.function);
362 }
363 break;
364 case GRUB_EFI_MEMORY_MAPPED_DEVICE_PATH_SUBTYPE:
365 {
366 grub_efi_memory_mapped_device_path_t mmapped;
367 grub_memcpy (&mmapped, dp, len);
368 grub_printf ("/MMap(%x,%llx,%llx)",
369 (unsigned) mmapped.memory_type,
4ad2d049 370 (unsigned long long) mmapped.start_address,
371 (unsigned long long) mmapped.end_address);
9cacaa17 372 }
373 break;
374 case GRUB_EFI_VENDOR_DEVICE_PATH_SUBTYPE:
375 {
376 grub_efi_vendor_device_path_t vendor;
377 grub_memcpy (&vendor, dp, sizeof (vendor));
378 grub_printf ("/Vendor(%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x)",
379 (unsigned) vendor.vendor_guid.data1,
380 (unsigned) vendor.vendor_guid.data2,
381 (unsigned) vendor.vendor_guid.data3,
382 (unsigned) vendor.vendor_guid.data4[0],
383 (unsigned) vendor.vendor_guid.data4[1],
384 (unsigned) vendor.vendor_guid.data4[2],
385 (unsigned) vendor.vendor_guid.data4[3],
386 (unsigned) vendor.vendor_guid.data4[4],
387 (unsigned) vendor.vendor_guid.data4[5],
388 (unsigned) vendor.vendor_guid.data4[6],
389 (unsigned) vendor.vendor_guid.data4[7]);
390 }
391 break;
392 case GRUB_EFI_CONTROLLER_DEVICE_PATH_SUBTYPE:
393 {
394 grub_efi_controller_device_path_t controller;
395 grub_memcpy (&controller, dp, len);
396 grub_printf ("/Ctrl(%x)",
397 (unsigned) controller.controller_number);
398 }
399 break;
400 default:
401 grub_printf ("/UnknownHW(%x)", (unsigned) subtype);
402 break;
403 }
404 break;
405
406 case GRUB_EFI_ACPI_DEVICE_PATH_TYPE:
407 switch (subtype)
408 {
409 case GRUB_EFI_ACPI_DEVICE_PATH_SUBTYPE:
410 {
411 grub_efi_acpi_device_path_t acpi;
412 grub_memcpy (&acpi, dp, len);
413 grub_printf ("/ACPI(%x,%x)",
414 (unsigned) acpi.hid,
415 (unsigned) acpi.uid);
416 }
417 break;
418 case GRUB_EFI_EXPANDED_ACPI_DEVICE_PATH_SUBTYPE:
419 {
420 grub_efi_expanded_acpi_device_path_t eacpi;
421 grub_memcpy (&eacpi, dp, sizeof (eacpi));
422 grub_printf ("/ACPI(");
423
424 if (GRUB_EFI_EXPANDED_ACPI_HIDSTR (dp)[0] == '\0')
425 grub_printf ("%x,", (unsigned) eacpi.hid);
426 else
427 grub_printf ("%s,", GRUB_EFI_EXPANDED_ACPI_HIDSTR (dp));
428
429 if (GRUB_EFI_EXPANDED_ACPI_UIDSTR (dp)[0] == '\0')
430 grub_printf ("%x,", (unsigned) eacpi.uid);
431 else
432 grub_printf ("%s,", GRUB_EFI_EXPANDED_ACPI_UIDSTR (dp));
433
434 if (GRUB_EFI_EXPANDED_ACPI_CIDSTR (dp)[0] == '\0')
435 grub_printf ("%x)", (unsigned) eacpi.cid);
436 else
437 grub_printf ("%s)", GRUB_EFI_EXPANDED_ACPI_CIDSTR (dp));
438 }
439 break;
440 default:
441 grub_printf ("/UnknownACPI(%x)", (unsigned) subtype);
442 break;
443 }
444 break;
445
446 case GRUB_EFI_MESSAGING_DEVICE_PATH_TYPE:
447 switch (subtype)
448 {
449 case GRUB_EFI_ATAPI_DEVICE_PATH_SUBTYPE:
450 {
451 grub_efi_atapi_device_path_t atapi;
452 grub_memcpy (&atapi, dp, len);
453 grub_printf ("/ATAPI(%x,%x,%x)",
454 (unsigned) atapi.primary_secondary,
455 (unsigned) atapi.slave_master,
456 (unsigned) atapi.lun);
457 }
458 break;
459 case GRUB_EFI_SCSI_DEVICE_PATH_SUBTYPE:
460 {
461 grub_efi_scsi_device_path_t scsi;
462 grub_memcpy (&scsi, dp, len);
463 grub_printf ("/SCSI(%x,%x)",
464 (unsigned) scsi.pun,
465 (unsigned) scsi.lun);
466 }
467 break;
468 case GRUB_EFI_FIBRE_CHANNEL_DEVICE_PATH_SUBTYPE:
469 {
470 grub_efi_fibre_channel_device_path_t fc;
471 grub_memcpy (&fc, dp, len);
472 grub_printf ("/FibreChannel(%llx,%llx)",
4ad2d049 473 (unsigned long long) fc.wwn,
474 (unsigned long long) fc.lun);
9cacaa17 475 }
476 break;
477 case GRUB_EFI_1394_DEVICE_PATH_SUBTYPE:
478 {
479 grub_efi_1394_device_path_t firewire;
480 grub_memcpy (&firewire, dp, len);
4ad2d049 481 grub_printf ("/1394(%llx)", (unsigned long long) firewire.guid);
9cacaa17 482 }
483 break;
484 case GRUB_EFI_USB_DEVICE_PATH_SUBTYPE:
485 {
486 grub_efi_usb_device_path_t usb;
487 grub_memcpy (&usb, dp, len);
488 grub_printf ("/USB(%x,%x)",
489 (unsigned) usb.parent_port_number,
490 (unsigned) usb.interface);
491 }
492 break;
493 case GRUB_EFI_USB_CLASS_DEVICE_PATH_SUBTYPE:
494 {
495 grub_efi_usb_class_device_path_t usb_class;
496 grub_memcpy (&usb_class, dp, len);
497 grub_printf ("/USBClass(%x,%x,%x,%x,%x)",
498 (unsigned) usb_class.vendor_id,
499 (unsigned) usb_class.product_id,
500 (unsigned) usb_class.device_class,
501 (unsigned) usb_class.device_subclass,
502 (unsigned) usb_class.device_protocol);
503 }
504 break;
505 case GRUB_EFI_I2O_DEVICE_PATH_SUBTYPE:
506 {
507 grub_efi_i2o_device_path_t i2o;
508 grub_memcpy (&i2o, dp, len);
509 grub_printf ("/I2O(%x)", (unsigned) i2o.tid);
510 }
511 break;
512 case GRUB_EFI_MAC_ADDRESS_DEVICE_PATH_SUBTYPE:
513 {
514 grub_efi_mac_address_device_path_t mac;
515 grub_memcpy (&mac, dp, len);
516 grub_printf ("/MacAddr(%02x:%02x:%02x:%02x:%02x:%02x,%x)",
517 (unsigned) mac.mac_address[0],
518 (unsigned) mac.mac_address[1],
519 (unsigned) mac.mac_address[2],
520 (unsigned) mac.mac_address[3],
521 (unsigned) mac.mac_address[4],
522 (unsigned) mac.mac_address[5],
523 (unsigned) mac.if_type);
524 }
525 break;
526 case GRUB_EFI_IPV4_DEVICE_PATH_SUBTYPE:
527 {
528 grub_efi_ipv4_device_path_t ipv4;
529 grub_memcpy (&ipv4, dp, len);
530 grub_printf ("/IPv4(%u.%u.%u.%u,%u.%u.%u.%u,%u,%u,%x,%x)",
531 (unsigned) ipv4.local_ip_address[0],
532 (unsigned) ipv4.local_ip_address[1],
533 (unsigned) ipv4.local_ip_address[2],
534 (unsigned) ipv4.local_ip_address[3],
535 (unsigned) ipv4.remote_ip_address[0],
536 (unsigned) ipv4.remote_ip_address[1],
537 (unsigned) ipv4.remote_ip_address[2],
538 (unsigned) ipv4.remote_ip_address[3],
539 (unsigned) ipv4.local_port,
540 (unsigned) ipv4.remote_port,
541 (unsigned) ipv4.protocol,
542 (unsigned) ipv4.static_ip_address);
543 }
544 break;
545 case GRUB_EFI_IPV6_DEVICE_PATH_SUBTYPE:
546 {
547 grub_efi_ipv6_device_path_t ipv6;
548 grub_memcpy (&ipv6, dp, len);
549 grub_printf ("/IPv6(%x:%x:%x:%x:%x:%x:%x:%x,%x:%x:%x:%x:%x:%x:%x:%x,%u,%u,%x,%x)",
550 (unsigned) ipv6.local_ip_address[0],
551 (unsigned) ipv6.local_ip_address[1],
552 (unsigned) ipv6.local_ip_address[2],
553 (unsigned) ipv6.local_ip_address[3],
554 (unsigned) ipv6.local_ip_address[4],
555 (unsigned) ipv6.local_ip_address[5],
556 (unsigned) ipv6.local_ip_address[6],
557 (unsigned) ipv6.local_ip_address[7],
558 (unsigned) ipv6.remote_ip_address[0],
559 (unsigned) ipv6.remote_ip_address[1],
560 (unsigned) ipv6.remote_ip_address[2],
561 (unsigned) ipv6.remote_ip_address[3],
562 (unsigned) ipv6.remote_ip_address[4],
563 (unsigned) ipv6.remote_ip_address[5],
564 (unsigned) ipv6.remote_ip_address[6],
565 (unsigned) ipv6.remote_ip_address[7],
566 (unsigned) ipv6.local_port,
567 (unsigned) ipv6.remote_port,
568 (unsigned) ipv6.protocol,
569 (unsigned) ipv6.static_ip_address);
570 }
571 break;
572 case GRUB_EFI_INFINIBAND_DEVICE_PATH_SUBTYPE:
573 {
574 grub_efi_infiniband_device_path_t ib;
575 grub_memcpy (&ib, dp, len);
576 grub_printf ("/InfiniBand(%x,%llx,%llx,%llx)",
577 (unsigned) ib.port_gid[0], /* XXX */
4ad2d049 578 (unsigned long long) ib.remote_id,
579 (unsigned long long) ib.target_port_id,
580 (unsigned long long) ib.device_id);
9cacaa17 581 }
582 break;
583 case GRUB_EFI_UART_DEVICE_PATH_SUBTYPE:
584 {
585 grub_efi_uart_device_path_t uart;
586 grub_memcpy (&uart, dp, len);
587 grub_printf ("/UART(%llu,%u,%x,%x)",
4ad2d049 588 (unsigned long long) uart.baud_rate,
9cacaa17 589 uart.data_bits,
590 uart.parity,
591 uart.stop_bits);
592 }
593 break;
594 case GRUB_EFI_VENDOR_MESSAGING_DEVICE_PATH_SUBTYPE:
595 {
596 grub_efi_vendor_messaging_device_path_t vendor;
597 grub_memcpy (&vendor, dp, sizeof (vendor));
598 grub_printf ("/Vendor(%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x)",
599 (unsigned) vendor.vendor_guid.data1,
600 (unsigned) vendor.vendor_guid.data2,
601 (unsigned) vendor.vendor_guid.data3,
602 (unsigned) vendor.vendor_guid.data4[0],
603 (unsigned) vendor.vendor_guid.data4[1],
604 (unsigned) vendor.vendor_guid.data4[2],
605 (unsigned) vendor.vendor_guid.data4[3],
606 (unsigned) vendor.vendor_guid.data4[4],
607 (unsigned) vendor.vendor_guid.data4[5],
608 (unsigned) vendor.vendor_guid.data4[6],
609 (unsigned) vendor.vendor_guid.data4[7]);
610 }
611 break;
612 default:
613 grub_printf ("/UnknownMessaging(%x)", (unsigned) subtype);
614 break;
615 }
616 break;
617
618 case GRUB_EFI_MEDIA_DEVICE_PATH_TYPE:
619 switch (subtype)
620 {
621 case GRUB_EFI_HARD_DRIVE_DEVICE_PATH_SUBTYPE:
622 {
623 grub_efi_hard_drive_device_path_t hd;
624 grub_memcpy (&hd, dp, len);
625 grub_printf ("/HD(%u,%llx,%llx,%02x%02x%02x%02x%02x%02x%02x%02x,%x,%x)",
626 hd.partition_number,
4ad2d049 627 (unsigned long long) hd.partition_start,
628 (unsigned long long) hd.partition_size,
9cacaa17 629 (unsigned) hd.partition_signature[0],
630 (unsigned) hd.partition_signature[1],
631 (unsigned) hd.partition_signature[2],
632 (unsigned) hd.partition_signature[3],
633 (unsigned) hd.partition_signature[4],
634 (unsigned) hd.partition_signature[5],
635 (unsigned) hd.partition_signature[6],
636 (unsigned) hd.partition_signature[7],
637 (unsigned) hd.mbr_type,
638 (unsigned) hd.signature_type);
639 }
640 break;
641 case GRUB_EFI_CDROM_DEVICE_PATH_SUBTYPE:
642 {
643 grub_efi_cdrom_device_path_t cd;
644 grub_memcpy (&cd, dp, len);
645 grub_printf ("/CD(%u,%llx,%llx)",
646 cd.boot_entry,
4ad2d049 647 (unsigned long long) cd.partition_start,
648 (unsigned long long) cd.partition_size);
9cacaa17 649 }
650 break;
651 case GRUB_EFI_VENDOR_MEDIA_DEVICE_PATH_SUBTYPE:
652 {
653 grub_efi_vendor_media_device_path_t vendor;
654 grub_memcpy (&vendor, dp, sizeof (vendor));
655 grub_printf ("/Vendor(%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x)",
656 (unsigned) vendor.vendor_guid.data1,
657 (unsigned) vendor.vendor_guid.data2,
658 (unsigned) vendor.vendor_guid.data3,
659 (unsigned) vendor.vendor_guid.data4[0],
660 (unsigned) vendor.vendor_guid.data4[1],
661 (unsigned) vendor.vendor_guid.data4[2],
662 (unsigned) vendor.vendor_guid.data4[3],
663 (unsigned) vendor.vendor_guid.data4[4],
664 (unsigned) vendor.vendor_guid.data4[5],
665 (unsigned) vendor.vendor_guid.data4[6],
666 (unsigned) vendor.vendor_guid.data4[7]);
667 }
668 break;
669 case GRUB_EFI_FILE_PATH_DEVICE_PATH_SUBTYPE:
670 {
671 grub_efi_file_path_device_path_t *fp;
7f362539 672 grub_uint8_t buf[(len - 4) * 2 + 1];
9cacaa17 673 fp = (grub_efi_file_path_device_path_t *) dp;
7f362539 674 *grub_utf16_to_utf8 (buf, fp->path_name,
675 (len - 4) / sizeof (grub_efi_char16_t))
676 = '\0';
9cacaa17 677 grub_printf ("/File(%s)", buf);
678 }
679 break;
680 case GRUB_EFI_PROTOCOL_DEVICE_PATH_SUBTYPE:
681 {
682 grub_efi_protocol_device_path_t proto;
683 grub_memcpy (&proto, dp, sizeof (proto));
684 grub_printf ("/Protocol(%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x)",
685 (unsigned) proto.guid.data1,
686 (unsigned) proto.guid.data2,
687 (unsigned) proto.guid.data3,
688 (unsigned) proto.guid.data4[0],
689 (unsigned) proto.guid.data4[1],
690 (unsigned) proto.guid.data4[2],
691 (unsigned) proto.guid.data4[3],
692 (unsigned) proto.guid.data4[4],
693 (unsigned) proto.guid.data4[5],
694 (unsigned) proto.guid.data4[6],
695 (unsigned) proto.guid.data4[7]);
696 }
697 break;
698 default:
699 grub_printf ("/UnknownMedia(%x)", (unsigned) subtype);
700 break;
701 }
702 break;
703
704 case GRUB_EFI_BIOS_DEVICE_PATH_TYPE:
705 switch (subtype)
706 {
707 case GRUB_EFI_BIOS_DEVICE_PATH_SUBTYPE:
708 {
709 grub_efi_bios_device_path_t bios;
710 grub_memcpy (&bios, dp, sizeof (bios));
711 grub_printf ("/BIOS(%x,%x,%s)",
712 (unsigned) bios.device_type,
713 (unsigned) bios.status_flags,
714 (char *) (dp + 1));
715 }
716 break;
717 default:
718 grub_printf ("/UnknownBIOS(%x)", (unsigned) subtype);
719 break;
720 }
721 break;
722
723 default:
724 grub_printf ("/UnknownType(%x,%x)\n",
725 (unsigned) type,
726 (unsigned) subtype);
727 return;
728 break;
729 }
730
731 if (GRUB_EFI_END_ENTIRE_DEVICE_PATH (dp))
732 break;
733
734 dp = (grub_efi_device_path_t *) ((char *) dp + len);
735 }
736}