lsefi.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. /*
  2. * GRUB -- GRand Unified Bootloader
  3. * Copyright (C) 2012 Free Software Foundation, Inc.
  4. *
  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.
  9. *
  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.
  14. *
  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/>.
  17. */
  18. #include <grub/types.h>
  19. #include <grub/mm.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>
  29. GRUB_MOD_LICENSE ("GPLv3+");
  30. static struct known_protocol
  31. {
  32. grub_guid_t guid;
  33. const char *name;
  34. } known_protocols[] =
  35. {
  36. { GRUB_EFI_DISK_IO_GUID, "disk" },
  37. { GRUB_EFI_BLOCK_IO_GUID, "block" },
  38. { GRUB_EFI_SERIAL_IO_GUID, "serial" },
  39. { GRUB_EFI_SIMPLE_NETWORK_GUID, "network" },
  40. { GRUB_EFI_PXE_GUID, "pxe" },
  41. { GRUB_EFI_DEVICE_PATH_GUID, "device path" },
  42. { GRUB_EFI_PCI_IO_GUID, "PCI" },
  43. { GRUB_EFI_PCI_ROOT_IO_GUID, "PCI root" },
  44. { GRUB_EFI_EDID_ACTIVE_GUID, "active EDID" },
  45. { GRUB_EFI_EDID_DISCOVERED_GUID, "discovered EDID" },
  46. { GRUB_EFI_EDID_OVERRIDE_GUID, "override EDID" },
  47. { GRUB_EFI_GOP_GUID, "GOP" },
  48. { GRUB_EFI_UGA_DRAW_GUID, "UGA draw" },
  49. { GRUB_EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL_GUID, "simple text output" },
  50. { GRUB_EFI_SIMPLE_TEXT_INPUT_PROTOCOL_GUID, "simple text input" },
  51. { GRUB_EFI_SIMPLE_POINTER_PROTOCOL_GUID, "simple pointer" },
  52. { GRUB_EFI_CONSOLE_CONTROL_GUID, "console control" },
  53. { GRUB_EFI_ABSOLUTE_POINTER_PROTOCOL_GUID, "absolute pointer" },
  54. { GRUB_EFI_DRIVER_BINDING_PROTOCOL_GUID, "EFI driver binding" },
  55. { GRUB_EFI_LOAD_FILE_PROTOCOL_GUID, "load file" },
  56. { GRUB_EFI_LOAD_FILE2_PROTOCOL_GUID, "load file2" },
  57. { GRUB_EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID, "simple FS" },
  58. { GRUB_EFI_TAPE_IO_PROTOCOL_GUID, "tape I/O" },
  59. { GRUB_EFI_UNICODE_COLLATION_PROTOCOL_GUID, "unicode collation" },
  60. { GRUB_EFI_SCSI_IO_PROTOCOL_GUID, "SCSI I/O" },
  61. { GRUB_EFI_USB2_HC_PROTOCOL_GUID, "USB host" },
  62. { GRUB_EFI_DEBUG_SUPPORT_PROTOCOL_GUID, "debug support" },
  63. { GRUB_EFI_DEBUGPORT_PROTOCOL_GUID, "debug port" },
  64. { GRUB_EFI_DECOMPRESS_PROTOCOL_GUID, "decompress" },
  65. { GRUB_EFI_LOADED_IMAGE_PROTOCOL_GUID, "loaded image" },
  66. { GRUB_EFI_DEVICE_PATH_TO_TEXT_PROTOCOL_GUID, "device path to text" },
  67. { GRUB_EFI_DEVICE_PATH_UTILITIES_PROTOCOL_GUID, "device path utilities" },
  68. { GRUB_EFI_DEVICE_PATH_FROM_TEXT_PROTOCOL_GUID, "device path from text" },
  69. { GRUB_EFI_HII_CONFIG_ROUTING_PROTOCOL_GUID, "HII config routing" },
  70. { GRUB_EFI_HII_DATABASE_PROTOCOL_GUID, "HII database" },
  71. { GRUB_EFI_HII_STRING_PROTOCOL_GUID, "HII string" },
  72. { GRUB_EFI_HII_IMAGE_PROTOCOL_GUID, "HII image" },
  73. { GRUB_EFI_HII_FONT_PROTOCOL_GUID, "HII font" },
  74. { GRUB_EFI_COMPONENT_NAME2_PROTOCOL_GUID, "component name 2" },
  75. { GRUB_EFI_HII_CONFIGURATION_ACCESS_PROTOCOL_GUID,
  76. "HII configuration access" },
  77. { GRUB_EFI_USB_IO_PROTOCOL_GUID, "USB I/O" },
  78. };
  79. static grub_err_t
  80. grub_cmd_lsefi (grub_command_t cmd __attribute__ ((unused)),
  81. int argc __attribute__ ((unused)),
  82. char **args __attribute__ ((unused)))
  83. {
  84. grub_efi_handle_t *handles;
  85. grub_efi_uintn_t num_handles;
  86. unsigned i, j, k;
  87. handles = grub_efi_locate_handle (GRUB_EFI_ALL_HANDLES,
  88. NULL, NULL, &num_handles);
  89. for (i = 0; i < num_handles; i++)
  90. {
  91. grub_efi_handle_t handle = handles[i];
  92. grub_efi_status_t status;
  93. grub_efi_uintn_t num_protocols;
  94. grub_packed_guid_t **protocols;
  95. grub_efi_device_path_t *dp;
  96. grub_printf ("Handle %p\n", handle);
  97. dp = grub_efi_get_device_path (handle);
  98. if (dp)
  99. {
  100. grub_printf (" ");
  101. grub_efi_print_device_path (dp);
  102. }
  103. status = grub_efi_system_table->boot_services->protocols_per_handle (handle,
  104. &protocols,
  105. &num_protocols);
  106. if (status != GRUB_EFI_SUCCESS) {
  107. grub_printf ("Unable to retrieve protocols\n");
  108. continue;
  109. }
  110. for (j = 0; j < num_protocols; j++)
  111. {
  112. for (k = 0; k < ARRAY_SIZE (known_protocols); k++)
  113. if (grub_memcmp (protocols[j], &known_protocols[k].guid,
  114. sizeof (known_protocols[k].guid)) == 0)
  115. break;
  116. if (k < ARRAY_SIZE (known_protocols))
  117. grub_printf (" %s\n", known_protocols[k].name);
  118. else
  119. grub_printf (" %pG\n", protocols[j]);
  120. }
  121. }
  122. return 0;
  123. }
  124. static grub_command_t cmd;
  125. GRUB_MOD_INIT(lsefi)
  126. {
  127. cmd = grub_register_command ("lsefi", grub_cmd_lsefi,
  128. NULL, "Display EFI handles.");
  129. }
  130. GRUB_MOD_FINI(lsefi)
  131. {
  132. grub_unregister_command (cmd);
  133. }