lssal.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. /* lssal.c - Display EFI SAL systab. */
  2. /*
  3. * GRUB -- GRand Unified Bootloader
  4. * Copyright (C) 2008 Free Software Foundation, Inc.
  5. *
  6. * GRUB 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 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * GRUB 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 GRUB. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #include <grub/types.h>
  20. #include <grub/mm.h>
  21. #include <grub/misc.h>
  22. #include <grub/normal.h>
  23. #include <grub/charset.h>
  24. #include <grub/efi/api.h>
  25. #include <grub/efi/efi.h>
  26. #include <grub/dl.h>
  27. GRUB_MOD_LICENSE ("GPLv3+");
  28. static void
  29. disp_sal (void *table)
  30. {
  31. struct grub_efi_sal_system_table *t = table;
  32. void *desc;
  33. grub_uint32_t len, l, i;
  34. grub_printf ("SAL rev: %02x, signature: %x, len:%x\n",
  35. t->sal_rev, t->signature, t->total_table_len);
  36. grub_printf ("nbr entry: %d, chksum: %02x, SAL version A: %02x B: %02x\n",
  37. t->entry_count, t->checksum,
  38. t->sal_a_version, t->sal_b_version);
  39. grub_printf ("OEM-ID: %-32s\n", t->oem_id);
  40. grub_printf ("Product-ID: %-32s\n", t->product_id);
  41. desc = t->entries;
  42. len = t->total_table_len - sizeof (struct grub_efi_sal_system_table);
  43. if (t->total_table_len <= sizeof (struct grub_efi_sal_system_table))
  44. return;
  45. for (i = 0; i < t->entry_count; i++)
  46. {
  47. switch (*(grub_uint8_t *) desc)
  48. {
  49. case GRUB_EFI_SAL_SYSTEM_TABLE_TYPE_ENTRYPOINT_DESCRIPTOR:
  50. {
  51. struct grub_efi_sal_system_table_entrypoint_descriptor *c = desc;
  52. l = sizeof (*c);
  53. grub_printf (" Entry point: PAL=%016" PRIxGRUB_UINT64_T
  54. " SAL=%016" PRIxGRUB_UINT64_T " GP=%016"
  55. PRIxGRUB_UINT64_T "\n",
  56. c->pal_proc_addr, c->sal_proc_addr,
  57. c->global_data_ptr);
  58. }
  59. break;
  60. case GRUB_EFI_SAL_SYSTEM_TABLE_TYPE_MEMORY_DESCRIPTOR:
  61. {
  62. struct grub_efi_sal_system_table_memory_descriptor *c = desc;
  63. l = sizeof (*c);
  64. grub_printf (" Memory descriptor entry addr=%016" PRIxGRUB_UINT64_T
  65. " len=%" PRIuGRUB_UINT64_T "KB\n",
  66. c->addr, c->len * 4);
  67. grub_printf (" sal_used=%d attr=%x AR=%x attr_mask=%x "
  68. "type=%x usage=%x\n",
  69. c->sal_used, c->attr, c->ar, c->attr_mask, c->mem_type,
  70. c->usage);
  71. }
  72. break;
  73. case GRUB_EFI_SAL_SYSTEM_TABLE_TYPE_PLATFORM_FEATURES:
  74. {
  75. struct grub_efi_sal_system_table_platform_features *c = desc;
  76. l = sizeof (*c);
  77. grub_printf (" Platform features: %02x", c->flags);
  78. if (c->flags & GRUB_EFI_SAL_SYSTEM_TABLE_PLATFORM_FEATURE_BUSLOCK)
  79. grub_printf (" BusLock");
  80. if (c->flags & GRUB_EFI_SAL_SYSTEM_TABLE_PLATFORM_FEATURE_IRQREDIRECT)
  81. grub_printf (" IrqRedirect");
  82. if (c->flags & GRUB_EFI_SAL_SYSTEM_TABLE_PLATFORM_FEATURE_IPIREDIRECT)
  83. grub_printf (" IPIRedirect");
  84. if (c->flags & GRUB_EFI_SAL_SYSTEM_TABLE_PLATFORM_FEATURE_ITCDRIFT)
  85. grub_printf (" ITCDrift");
  86. grub_printf ("\n");
  87. }
  88. break;
  89. case GRUB_EFI_SAL_SYSTEM_TABLE_TYPE_TRANSLATION_REGISTER_DESCRIPTOR:
  90. {
  91. struct grub_efi_sal_system_table_translation_register_descriptor *c
  92. = desc;
  93. l = sizeof (*c);
  94. grub_printf (" TR type=%d num=%d va=%016" PRIxGRUB_UINT64_T
  95. " pte=%016" PRIxGRUB_UINT64_T "\n",
  96. c->register_type, c->register_number,
  97. c->addr, c->page_size);
  98. }
  99. break;
  100. case GRUB_EFI_SAL_SYSTEM_TABLE_TYPE_PURGE_TRANSLATION_COHERENCE:
  101. {
  102. struct grub_efi_sal_system_table_purge_translation_coherence *c
  103. = desc;
  104. l = sizeof (*c);
  105. grub_printf (" PTC coherence nbr=%d addr=%016" PRIxGRUB_UINT64_T "\n",
  106. c->ndomains, c->coherence);
  107. }
  108. break;
  109. case GRUB_EFI_SAL_SYSTEM_TABLE_TYPE_AP_WAKEUP:
  110. {
  111. struct grub_efi_sal_system_table_ap_wakeup *c = desc;
  112. l = sizeof (*c);
  113. grub_printf (" AP wake-up: mec=%d vect=%" PRIxGRUB_UINT64_T "\n",
  114. c->mechanism, c->vector);
  115. }
  116. break;
  117. default:
  118. grub_printf (" unknown entry 0x%x\n", *(grub_uint8_t *)desc);
  119. return;
  120. }
  121. desc = (grub_uint8_t *)desc + l;
  122. if (len <= l)
  123. return;
  124. len -= l;
  125. }
  126. }
  127. static grub_err_t
  128. grub_cmd_lssal (struct grub_command *cmd __attribute__ ((unused)),
  129. int argc __attribute__ ((unused)),
  130. char **args __attribute__ ((unused)))
  131. {
  132. const grub_efi_system_table_t *st = grub_efi_system_table;
  133. grub_efi_configuration_table_t *t = st->configuration_table;
  134. unsigned int i;
  135. grub_efi_packed_guid_t guid = GRUB_EFI_SAL_TABLE_GUID;
  136. for (i = 0; i < st->num_table_entries; i++)
  137. {
  138. if (grub_memcmp (&guid, &t->vendor_guid,
  139. sizeof (grub_efi_packed_guid_t)) == 0)
  140. {
  141. disp_sal (t->vendor_table);
  142. return GRUB_ERR_NONE;
  143. }
  144. t++;
  145. }
  146. grub_printf ("SAL not found\n");
  147. return GRUB_ERR_NONE;
  148. }
  149. static grub_command_t cmd;
  150. GRUB_MOD_INIT(lssal)
  151. {
  152. cmd = grub_register_command ("lssal", grub_cmd_lssal, "",
  153. "Display SAL system table.");
  154. }
  155. GRUB_MOD_FINI(lssal)
  156. {
  157. grub_unregister_command (cmd);
  158. }