2 * GRUB -- GRand Unified Bootloader
3 * Copyright (C) 2012 Free Software Foundation, Inc.
5 * GRUB is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * GRUB is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
18 #include <grub/types.h>
20 #include <grub/misc.h>
21 #include <grub/efi/api.h>
22 #include <grub/efi/edid.h>
23 #include <grub/efi/pci.h>
24 #include <grub/efi/efi.h>
25 #include <grub/efi/uga_draw.h>
26 #include <grub/efi/graphics_output.h>
27 #include <grub/efi/console_control.h>
28 #include <grub/command.h>
30 GRUB_MOD_LICENSE ("GPLv3+");
38 { GRUB_EFI_DISK_IO_GUID
, "disk" },
39 { GRUB_EFI_BLOCK_IO_GUID
, "block" },
40 { GRUB_EFI_SERIAL_IO_GUID
, "serial" },
41 { GRUB_EFI_SIMPLE_NETWORK_GUID
, "network" },
42 { GRUB_EFI_PXE_GUID
, "pxe" },
43 { GRUB_EFI_DEVICE_PATH_GUID
, "device path" },
44 { GRUB_EFI_PCI_IO_GUID
, "PCI" },
45 { GRUB_EFI_PCI_ROOT_IO_GUID
, "PCI root" },
46 { GRUB_EFI_EDID_ACTIVE_GUID
, "active EDID" },
47 { GRUB_EFI_EDID_DISCOVERED_GUID
, "discovered EDID" },
48 { GRUB_EFI_EDID_OVERRIDE_GUID
, "override EDID" },
49 { GRUB_EFI_GOP_GUID
, "GOP" },
50 { GRUB_EFI_UGA_DRAW_GUID
, "UGA draw" },
51 { GRUB_EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL_GUID
, "simple text output" },
52 { GRUB_EFI_SIMPLE_TEXT_INPUT_PROTOCOL_GUID
, "simple text input" },
53 { GRUB_EFI_SIMPLE_POINTER_PROTOCOL_GUID
, "simple pointer" },
54 { GRUB_EFI_CONSOLE_CONTROL_GUID
, "console control" },
55 { GRUB_EFI_ABSOLUTE_POINTER_PROTOCOL_GUID
, "absolute pointer" },
56 { GRUB_EFI_DRIVER_BINDING_PROTOCOL_GUID
, "EFI driver binding" },
57 { GRUB_EFI_LOAD_FILE_PROTOCOL_GUID
, "load file" },
58 { GRUB_EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID
, "simple FS" },
59 { GRUB_EFI_TAPE_IO_PROTOCOL_GUID
, "tape I/O" },
60 { GRUB_EFI_UNICODE_COLLATION_PROTOCOL_GUID
, "unicode collation" },
61 { GRUB_EFI_SCSI_IO_PROTOCOL_GUID
, "SCSI I/O" },
62 { GRUB_EFI_USB2_HC_PROTOCOL_GUID
, "USB host" },
63 { GRUB_EFI_DEBUG_SUPPORT_PROTOCOL_GUID
, "debug support" },
64 { GRUB_EFI_DEBUGPORT_PROTOCOL_GUID
, "debug port" },
65 { GRUB_EFI_DECOMPRESS_PROTOCOL_GUID
, "decompress" },
66 { GRUB_EFI_LOADED_IMAGE_PROTOCOL_GUID
, "loaded image" },
67 { GRUB_EFI_DEVICE_PATH_TO_TEXT_PROTOCOL_GUID
, "device path to text" },
68 { GRUB_EFI_DEVICE_PATH_UTILITIES_PROTOCOL_GUID
, "device path utilities" },
69 { GRUB_EFI_DEVICE_PATH_FROM_TEXT_PROTOCOL_GUID
, "device path from text" },
70 { GRUB_EFI_HII_CONFIG_ROUTING_PROTOCOL_GUID
, "HII config routing" },
71 { GRUB_EFI_HII_DATABASE_PROTOCOL_GUID
, "HII database" },
72 { GRUB_EFI_HII_STRING_PROTOCOL_GUID
, "HII string" },
73 { GRUB_EFI_HII_IMAGE_PROTOCOL_GUID
, "HII image" },
74 { GRUB_EFI_HII_FONT_PROTOCOL_GUID
, "HII font" },
75 { GRUB_EFI_COMPONENT_NAME2_PROTOCOL_GUID
, "component name 2" },
76 { GRUB_EFI_HII_CONFIGURATION_ACCESS_PROTOCOL_GUID
,
77 "HII configuration access" },
78 { GRUB_EFI_USB_IO_PROTOCOL_GUID
, "USB I/O" },
82 grub_cmd_lsefi (grub_command_t cmd
__attribute__ ((unused
)),
83 int argc
__attribute__ ((unused
)),
84 char **args
__attribute__ ((unused
)))
86 grub_efi_handle_t
*handles
;
87 grub_efi_uintn_t num_handles
;
90 handles
= grub_efi_locate_handle (GRUB_EFI_ALL_HANDLES
,
91 NULL
, NULL
, &num_handles
);
93 for (i
= 0; i
< num_handles
; i
++)
95 grub_efi_handle_t handle
= handles
[i
];
96 grub_efi_status_t status
;
97 grub_efi_uintn_t num_protocols
;
98 grub_efi_packed_guid_t
**protocols
;
99 grub_efi_device_path_t
*dp
;
101 grub_printf ("Handle %p\n", handle
);
103 dp
= grub_efi_get_device_path (handle
);
107 grub_efi_print_device_path (dp
);
110 status
= efi_call_3 (grub_efi_system_table
->boot_services
->protocols_per_handle
,
111 handle
, &protocols
, &num_protocols
);
112 if (status
!= GRUB_EFI_SUCCESS
)
113 grub_printf ("Unable to retrieve protocols\n");
114 for (j
= 0; j
< num_protocols
; j
++)
116 for (k
= 0; k
< ARRAY_SIZE (known_protocols
); k
++)
117 if (grub_memcmp (protocols
[j
], &known_protocols
[k
].guid
,
118 sizeof (known_protocols
[k
].guid
)) == 0)
120 if (k
< ARRAY_SIZE (known_protocols
))
121 grub_printf (" %s\n", known_protocols
[k
].name
);
123 grub_printf (" %08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x\n",
127 (unsigned) protocols
[j
]->data4
[0],
128 (unsigned) protocols
[j
]->data4
[1],
129 (unsigned) protocols
[j
]->data4
[2],
130 (unsigned) protocols
[j
]->data4
[3],
131 (unsigned) protocols
[j
]->data4
[4],
132 (unsigned) protocols
[j
]->data4
[5],
133 (unsigned) protocols
[j
]->data4
[6],
134 (unsigned) protocols
[j
]->data4
[7]);
142 static grub_command_t cmd
;
146 cmd
= grub_register_command ("lsefi", grub_cmd_lsefi
,
147 NULL
, "Display EFI handles.");
152 grub_unregister_command (cmd
);