hob.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (C) 2014-2015, Bin Meng <bmeng.cn@gmail.com>
  4. */
  5. #include <common.h>
  6. #include <command.h>
  7. #include <efi.h>
  8. #include <uuid.h>
  9. #include <asm/global_data.h>
  10. #include <asm/hob.h>
  11. #include <asm/fsp/fsp_hob.h>
  12. DECLARE_GLOBAL_DATA_PTR;
  13. static char *hob_type[] = {
  14. "reserved",
  15. "Hand-off",
  16. "Mem Alloc",
  17. "Res Desc",
  18. "GUID Ext",
  19. "FV",
  20. "CPU",
  21. "Mem Pool",
  22. "reserved",
  23. "FV2",
  24. "Load PEIM",
  25. "Capsule",
  26. };
  27. static char *res_type[] = {
  28. "System",
  29. "Memory-mapped I/O",
  30. "I/O",
  31. "Firmware device",
  32. "Memory-mapped I/O port",
  33. "Reserved",
  34. "I/O reserved",
  35. };
  36. static struct guid_name {
  37. efi_guid_t guid;
  38. const char *name;
  39. } guid_name[] = {
  40. { FSP_HOB_RESOURCE_OWNER_TSEG_GUID, "TSEG" },
  41. { FSP_HOB_RESOURCE_OWNER_FSP_GUID, "FSP" },
  42. { FSP_HOB_RESOURCE_OWNER_SMM_PEI_SMRAM_GUID, "SMM PEI SMRAM" },
  43. { FSP_NON_VOLATILE_STORAGE_HOB_GUID, "NVS" },
  44. { FSP_VARIABLE_NV_DATA_HOB_GUID, "Variable NVS" },
  45. { FSP_GRAPHICS_INFO_HOB_GUID, "Graphics info" },
  46. { FSP_HOB_RESOURCE_OWNER_PCD_DATABASE_GUID1, "PCD database ea" },
  47. { FSP_HOB_RESOURCE_OWNER_PCD_DATABASE_GUID2, "PCD database 9b" },
  48. { FSP_HOB_RESOURCE_OWNER_PEIM_DXE_GUID, "PEIM Init DXE" },
  49. { FSP_HOB_RESOURCE_OWNER_ALLOC_STACK_GUID, "Alloc stack" },
  50. { FSP_HOB_RESOURCE_OWNER_SMBIOS_MEMORY_GUID, "SMBIOS memory" },
  51. { {}, "zero-guid" },
  52. {}
  53. };
  54. static const char *guid_to_name(const efi_guid_t *guid)
  55. {
  56. struct guid_name *entry;
  57. for (entry = guid_name; entry->name; entry++) {
  58. if (!guidcmp(guid, &entry->guid))
  59. return entry->name;
  60. }
  61. return NULL;
  62. }
  63. static void show_hob_details(const struct hob_header *hdr)
  64. {
  65. const void *ptr = hdr;
  66. switch (hdr->type) {
  67. case HOB_TYPE_RES_DESC: {
  68. const struct hob_res_desc *res = ptr;
  69. const char *typename;
  70. typename = res->type >= RES_SYS_MEM && res->type <= RES_MAX_MEM_TYPE ?
  71. res_type[res->type] : "unknown";
  72. printf(" base = %08llx, len = %08llx, end = %08llx, type = %d (%s)\n\n",
  73. res->phys_start, res->len, res->phys_start + res->len,
  74. res->type, typename);
  75. break;
  76. }
  77. }
  78. }
  79. static int do_hob(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
  80. {
  81. const struct hob_header *hdr;
  82. uint type;
  83. char *desc;
  84. int i = 0;
  85. efi_guid_t *guid;
  86. char uuid[UUID_STR_LEN + 1];
  87. bool verbose = false;
  88. int seq = -1; /* Show all by default */
  89. argc--;
  90. argv++;
  91. if (argc) {
  92. if (!strcmp("-v", *argv)) {
  93. verbose = true;
  94. argc--;
  95. argv++;
  96. }
  97. if (argc)
  98. seq = simple_strtol(*argv, NULL, 16);
  99. }
  100. hdr = gd->arch.hob_list;
  101. printf("HOB list address: 0x%08x\n\n", (unsigned int)hdr);
  102. printf("# | Address | Type | Len | ");
  103. printf("%36s\n", "GUID");
  104. printf("---|----------|-----------|------|-");
  105. printf("------------------------------------\n");
  106. for (i = 0; !end_of_hob(hdr); i++, hdr = get_next_hob(hdr)) {
  107. if (seq != -1 && seq != i)
  108. continue;
  109. printf("%02x | %08x | ", i, (unsigned int)hdr);
  110. type = hdr->type;
  111. if (type == HOB_TYPE_UNUSED)
  112. desc = "*Unused*";
  113. else if (type == HOB_TYPE_EOH)
  114. desc = "*EOH*";
  115. else if (type >= 0 && type <= ARRAY_SIZE(hob_type))
  116. desc = hob_type[type];
  117. else
  118. desc = "*Invalid*";
  119. printf("%-9s | %04x | ", desc, hdr->len);
  120. if (type == HOB_TYPE_MEM_ALLOC || type == HOB_TYPE_RES_DESC ||
  121. type == HOB_TYPE_GUID_EXT) {
  122. const char *name;
  123. guid = (efi_guid_t *)(hdr + 1);
  124. name = guid_to_name(guid);
  125. if (!name) {
  126. uuid_bin_to_str(guid->b, uuid,
  127. UUID_STR_FORMAT_GUID);
  128. name = uuid;
  129. }
  130. printf("%36s", name);
  131. } else {
  132. printf("%36s", "Not Available");
  133. }
  134. printf("\n");
  135. if (verbose)
  136. show_hob_details(hdr);
  137. }
  138. return 0;
  139. }
  140. U_BOOT_CMD(hob, 3, 1, do_hob,
  141. "[-v] [seq] Print Hand-Off Block (HOB) information",
  142. " -v - Show detailed HOB information where available\n"
  143. " seq - Record # to show (all by default)"
  144. );