xref: /aosp_15_r20/external/coreboot/src/drivers/intel/fsp2_0/hob_display.c (revision b9411a12aaaa7e1e6a6fb7c5e057f44ee179a49c)
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
3 #include <console/console.h>
4 #include <fsp/util.h>
5 
6 struct hob_type_name {
7 	uint16_t type;
8 	const char *name;
9 } __packed;
10 
11 static const struct hob_type_name hob_type_names[] = {
12 	{ HOB_TYPE_HANDOFF, "HOB_TYPE_HANDOFF" },
13 	{ HOB_TYPE_MEMORY_ALLOCATION, "HOB_TYPE_MEMORY_ALLOCATION" },
14 	{ HOB_TYPE_RESOURCE_DESCRIPTOR, "HOB_TYPE_RESOURCE_DESCRIPTOR" },
15 	{ HOB_TYPE_GUID_EXTENSION, "HOB_TYPE_GUID_EXTENSION" },
16 	{ HOB_TYPE_FV, "HOB_TYPE_FV" },
17 	{ HOB_TYPE_CPU, "HOB_TYPE_CPU" },
18 	{ HOB_TYPE_MEMORY_POOL, "HOB_TYPE_MEMORY_POOL" },
19 	{ HOB_TYPE_FV2, "HOB_TYPE_FV2" },
20 	{ HOB_TYPE_LOAD_PEIM_UNUSED, "HOB_TYPE_LOAD_PEIM_UNUSED" },
21 	{ HOB_TYPE_UCAPSULE, "HOB_TYPE_UCAPSULE" },
22 	{ HOB_TYPE_UNUSED, "HOB_TYPE_UNUSED" },
23 	{ HOB_TYPE_END_OF_HOB_LIST, "HOB_TYPE_END_OF_HOB_LIST" }
24 };
25 
26 static const char *resource_names[] = {
27 	[EFI_RESOURCE_SYSTEM_MEMORY]		= "SYSTEM_MEMORY",
28 	[EFI_RESOURCE_MEMORY_MAPPED_IO]		= "MMIO",
29 	[EFI_RESOURCE_IO]			= "IO",
30 	[EFI_RESOURCE_FIRMWARE_DEVICE]		= "FIRMWARE_DEVICE",
31 	[EFI_RESOURCE_MEMORY_MAPPED_IO_PORT]	= "MMIO_PORT",
32 	[EFI_RESOURCE_MEMORY_RESERVED]		= "MEMORY_RESERVED",
33 	[EFI_RESOURCE_IO_RESERVED]		= "IO_RESERVED",
34 };
35 
36 static const uint8_t bootloader_temp_memory_guid[16] = {
37 	0x6c, 0xf4, 0xcf, 0xbb, 0xd3, 0xc8, 0x13, 0x41,
38 	0x89, 0x85, 0xb9, 0xd4, 0xf3, 0xb3, 0xf6, 0x4e
39 };
40 
41 static const uint8_t empty_guid[16] = {
42 	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
43 };
44 
45 static const uint8_t fsp_graphics_info_guid[16] = {
46 	0xce, 0x2c, 0xf6, 0x39, 0x25, 0x68, 0x69, 0x46,
47 	0xbb, 0x56, 0x54, 0x1a, 0xba, 0x75, 0x3a, 0x07
48 };
49 
50 static const uint8_t fsp_info_header_guid[16] = {
51 	0xbe, 0x40, 0x27, 0x91, 0x84, 0x22, 0x34, 0x47,
52 	0xb9, 0x71, 0x84, 0xb0, 0x27, 0x35, 0x3f, 0x0c
53 };
54 
55 static const uint8_t smbios_memory_info_guid[16] = {
56 	0x8c, 0x10, 0xa1, 0x01, 0xee, 0x9d, 0x84, 0x49,
57 	0x88, 0xc3, 0xee, 0xe8, 0xc4, 0x9e, 0xfb, 0x89
58 };
59 
60 static const uint8_t tseg_guid[16] = {
61 	0x7c, 0x74, 0x38, 0xd0, 0x0c, 0xd0, 0x80, 0x49,
62 	0xb3, 0x19, 0x49, 0x01, 0x99, 0xa4, 0x7d, 0x55
63 };
64 
65 struct guid_name_map {
66 	const void *guid;
67 	const char *name;
68 };
69 
70 static const struct guid_name_map  guid_names[] = {
71 	{ bootloader_temp_memory_guid,	"FSP_BOOTLOADER_TEMP_MEMORY_HOB_GUID" },
72 	{ fsp_bootloader_tolum_guid,	"BOOTLOADER_TOLUM" },
73 	{ empty_guid,			"No GUID specified" },
74 	{ fsp_info_header_guid,		"FSP_INFO_HEADER_GUID" },
75 	{ fsp_reserved_memory_guid,	"FSP_RESERVED_MEMORY" },
76 	{ fsp_nv_storage_guid,		"FSP_NV_STORAGE" },
77 	{ fsp_graphics_info_guid,	"GRAPHICS INFO" },
78 	{ smbios_memory_info_guid,	"FSP_SMBIOS_MEMORY_INFO_GUID" },
79 	{ tseg_guid,			"TSEG" },
80 };
81 
resource_name(uint32_t type)82 static const char *resource_name(uint32_t type)
83 {
84 	if (type >= ARRAY_SIZE(resource_names))
85 		return "UNKNOWN";
86 	return resource_names[type];
87 }
88 
fsp_print_resource_descriptor(const void * base)89 void fsp_print_resource_descriptor(const void *base)
90 {
91 	const struct hob_resource *res;
92 
93 	res = fsp_hob_header_to_resource(base);
94 
95 	printk(BIOS_SPEW, "Resource %s, attribute %x\n",
96 			   resource_name(res->type), res->attribute_type);
97 	printk(BIOS_SPEW, "\t0x%08llx + 0x%08llx\n", res->addr, res->length);
98 	if (!fsp_guid_compare(res->owner_guid, empty_guid)) {
99 		printk(BIOS_SPEW, "\tOwner GUID: ");
100 		fsp_print_guid(BIOS_SPEW, res->owner_guid);
101 		printk(BIOS_SPEW, " (%s)\n",
102 			fsp_get_guid_name(res->owner_guid));
103 	}
104 }
105 
fsp_print_memory_resource_hobs(void)106 void fsp_print_memory_resource_hobs(void)
107 {
108 	const struct hob_header *hob = fsp_get_hob_list();
109 
110 	for (; hob->type != HOB_TYPE_END_OF_HOB_LIST;
111 		hob = fsp_next_hob(hob)) {
112 		if (hob->type == HOB_TYPE_RESOURCE_DESCRIPTOR)
113 			fsp_print_resource_descriptor(hob);
114 	}
115 }
116 
fsp_get_hob_type_name(const struct hob_header * hob)117 const char *fsp_get_hob_type_name(const struct hob_header *hob)
118 {
119 	size_t index;
120 	const char *name;
121 
122 	for (index = 0; index < ARRAY_SIZE(hob_type_names); index++)
123 		if (hob->type == hob_type_names[index].type)
124 			return hob_type_names[index].name;
125 
126 	/* Get name for SOC specific HOB */
127 	name = soc_get_hob_type_name(hob);
128 	if (name != NULL)
129 		return name;
130 	return "Unknown HOB type";
131 }
132 
fsp_get_guid_name(const uint8_t * guid)133 const char *fsp_get_guid_name(const uint8_t *guid)
134 {
135 	size_t index;
136 	const char *name;
137 
138 	/* Compare the GUID values in this module */
139 	for (index = 0; index < ARRAY_SIZE(guid_names); index++)
140 		if (fsp_guid_compare(guid, guid_names[index].guid))
141 			return guid_names[index].name;
142 
143 	/* Get GUID name from SOC */
144 	name = soc_get_guid_name(guid);
145 	if (name != NULL)
146 		return name;
147 	return "Unknown GUID";
148 }
149 
soc_get_hob_type_name(const struct hob_header * hob)150 __weak const char *soc_get_hob_type_name(
151 	const struct hob_header *hob)
152 {
153 	return NULL;
154 }
155 
fsp_print_guid_extension_hob(const struct hob_header * hob)156 void fsp_print_guid_extension_hob(const struct hob_header *hob)
157 {
158 	const struct hob_resource *res;
159 
160 	res = fsp_hob_header_to_resource(hob);
161 	printk(BIOS_SPEW, "\t");
162 	fsp_print_guid(BIOS_SPEW, res->owner_guid);
163 	printk(BIOS_SPEW, ": %s\n", fsp_get_guid_name(res->owner_guid));
164 
165 	/* Some of the SoC FSP specific HOBs are of type HOB_TYPE_GUID_EXTENSION */
166 	soc_display_hob(hob);
167 }
168 
soc_get_guid_name(const uint8_t * guid)169 __weak const char *soc_get_guid_name(const uint8_t *guid)
170 {
171 	return NULL;
172 }
173 
fsp_display_hobs(void)174 void fsp_display_hobs(void)
175 {
176 	const struct hob_header *hob = fsp_get_hob_list();
177 
178 	/* Display the HOB list pointer */
179 	printk(BIOS_SPEW, "\n=== FSP HOBs ===\n");
180 	printk(BIOS_SPEW, "%p: hob_list_ptr\n", hob);
181 
182 	/* Walk the list of HOBs */
183 	while (1) {
184 		/* Display the HOB header */
185 		printk(BIOS_SPEW, "%p, 0x%08x bytes: %s\n", hob, hob->length,
186 			fsp_get_hob_type_name(hob));
187 		switch (hob->type) {
188 		default:
189 			soc_display_hob(hob);
190 			break;
191 
192 		case HOB_TYPE_END_OF_HOB_LIST:
193 			printk(BIOS_SPEW, "=== End of FSP HOBs ===\n\n");
194 			return;
195 
196 		case HOB_TYPE_RESOURCE_DESCRIPTOR:
197 			fsp_print_resource_descriptor(hob);
198 			break;
199 
200 		case HOB_TYPE_GUID_EXTENSION:
201 			fsp_print_guid_extension_hob(hob);
202 			break;
203 		}
204 		hob = fsp_next_hob(hob);
205 	}
206 }
207 
soc_display_hob(const struct hob_header * hob)208 __weak void soc_display_hob(const struct hob_header *hob)
209 {
210 }
211