blob: 4fa3cf379dafa4bf10d350135a2e6d0d1dd7b189 [file] [log] [blame]
Kathleen Capellabde3eab2024-12-09 14:04:43 -05001/*
2 * Copyright (c) 2024, Arm Limited and Contributors. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
Kathleen Capella8808a942025-01-07 15:45:39 -05007#include <assert.h>
Kathleen Capellabde3eab2024-12-09 14:04:43 -05008#include <stddef.h>
Kathleen Capella8808a942025-01-07 15:45:39 -05009#include <stdint.h>
Kathleen Capellabde3eab2024-12-09 14:04:43 -050010#include <stdio.h>
Kathleen Capella8808a942025-01-07 15:45:39 -050011#include <debug.h>
Kathleen Capellabde3eab2024-12-09 14:04:43 -050012#include <lib/hob/hob.h>
13#include <lib/hob/hob_guid.h>
14#include <lib/hob/mmram.h>
Kathleen Capella8808a942025-01-07 15:45:39 -050015#include <lib/utils/uuid_utils.h>
Kathleen Capellabde3eab2024-12-09 14:04:43 -050016#include <lib/utils_def.h>
17
18#define ALIGN_UP(x, a) ((x + (a - 1)) & ~(a - 1))
19
Kathleen Capella8808a942025-01-07 15:45:39 -050020void dump_hob_generic_header(struct efi_hob_generic_header *h)
Kathleen Capellabde3eab2024-12-09 14:04:43 -050021{
Kathleen Capella8808a942025-01-07 15:45:39 -050022 assert(h != NULL);
23 INFO("Hob Type: 0x%x\n", h->hob_type);
24 INFO("Hob Length: 0x%x\n", h->hob_length);
25}
26
27void dump_efi_mmram_descriptor(struct efi_mmram_descriptor *m)
28{
29 INFO(" Physical start: 0x%llx\n", m->physical_start);
30 INFO(" CPU start: 0x%llx\n", m->cpu_start);
31 INFO(" Physical size: 0x%llx\n", m->physical_size);
32 INFO(" Region state: 0x%llx\n", m->region_state);
33}
34
35void dump_efi_hob_firmware_volume(struct efi_hob_firmware_volume *fv)
36{
37 dump_hob_generic_header(&fv->header);
38 INFO(" Base_address: 0x%llx\n", fv->base_address);
39 INFO(" Length: 0x%llx\n", fv->length);
40}
41
42static void dump_efi_guid(struct efi_guid guid)
43{
44 INFO(" Time low: 0x%x\n", guid.time_low);
45 INFO(" Time mid: 0x%x\n", guid.time_mid);
46 INFO(" Time hi and version: 0x%x\n", guid.time_hi_and_version);
47 INFO(" Clock_seq_and_node: [0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x]\n",
48 guid.clock_seq_and_node[0],
49 guid.clock_seq_and_node[1],
50 guid.clock_seq_and_node[2],
51 guid.clock_seq_and_node[3],
52 guid.clock_seq_and_node[4],
53 guid.clock_seq_and_node[5],
54 guid.clock_seq_and_node[6],
55 guid.clock_seq_and_node[7]);
56}
57
58static void dump_guid_hob_data(struct efi_hob_guid_type *guid_hob)
59{
60 union uuid_helper_t uuid_name = {.efi_guid = guid_hob->name};
61 union uuid_helper_t mmram_mem_resv_guid = {
62 .efi_guid = (struct efi_guid)MM_PEI_MMRAM_MEMORY_RESERVE_GUID};
63 union uuid_helper_t ns_buffer_guid = {
64 .efi_guid = (struct efi_guid)MM_NS_BUFFER_GUID};
65 uintptr_t guid_data = (uintptr_t)(&guid_hob->name + 1);
66
67 /* Dump GUID HOB data according to GUID type. */
68 if (uuid_equal(&uuid_name.uuid_struct,
69 &mmram_mem_resv_guid.uuid_struct)) {
70 struct efi_mmram_hob_descriptor_block *mmram_desc_block =
71 (struct efi_mmram_hob_descriptor_block *)guid_data;
72 INFO(" MM_PEI_MMRAM_MEMORY_RESERVE_GUID with %u regions\n",
73 mmram_desc_block->number_of_mm_reserved_regions);
74 for (uint32_t i = 0;
75 i < mmram_desc_block->number_of_mm_reserved_regions; i++) {
76 INFO(" MMRAM_DESC[%u]:\n", i);
77 dump_efi_mmram_descriptor(
78 &mmram_desc_block->descriptor[i]);
79 }
80 } else if (uuid_equal(&uuid_name.uuid_struct,
81 &ns_buffer_guid.uuid_struct)) {
82 INFO(" MM_NS_BUFFER_GUID\n");
83 dump_efi_mmram_descriptor(
84 (struct efi_mmram_descriptor *)guid_data);
85 }
86}
87
88static void dump_guid_hob(struct efi_hob_guid_type *guid_hob)
89{
90 dump_hob_generic_header(&guid_hob->header);
91 dump_efi_guid(guid_hob->name);
92 dump_guid_hob_data(guid_hob);
93}
94
95void dump_hob_list(struct efi_hob_handoff_info_table *hob_list)
96{
97 uintptr_t next_hob_addr;
98 struct efi_hob_generic_header *next;
99
100 assert(hob_list != NULL);
101 dump_hob_generic_header(&hob_list->header);
102 INFO(" Version: %u\n", hob_list->version);
103 INFO(" Boot Mode: %u\n", hob_list->boot_mode);
104 INFO(" EFI Memory Top: 0x%llx\n", hob_list->efi_memory_top);
105 INFO(" EFI Memory Bottom: 0x%llx\n", hob_list->efi_memory_bottom);
106 INFO(" EFI Free Memory Top: 0x%llx\n", hob_list->efi_free_memory_top);
107 INFO(" EFI Free Memory Bottom: 0x%llx\n", hob_list->efi_free_memory_bottom);
108 INFO(" EFI End of Hob List: 0x%llx\n", hob_list->efi_end_of_hob_list);
109
110 next_hob_addr = (uintptr_t)(hob_list) + (uintptr_t)hob_list->header.hob_length;
111 assert(next_hob_addr < (uintptr_t)hob_list->efi_end_of_hob_list);
112 next = (struct efi_hob_generic_header *)next_hob_addr;
113
114 while (next != NULL) {
115 assert(next->hob_type != 0x0);
116 switch (next->hob_type) {
117 case EFI_HOB_TYPE_GUID_EXTENSION:
118 dump_guid_hob((struct efi_hob_guid_type *)next);
119 break;
120 case EFI_HOB_TYPE_FV:
121 dump_efi_hob_firmware_volume((struct
122 efi_hob_firmware_volume *)next);
123 break;
124 default:
125 dump_hob_generic_header(next);
126 }
127
128 if (next->hob_type == EFI_HOB_TYPE_END_OF_HOB_LIST) {
129 break;
130 }
131
132 next_hob_addr = (uintptr_t)(next) + (uintptr_t)next->hob_length;
133
134 if (next_hob_addr >= (uintptr_t) hob_list->efi_end_of_hob_list) {
135 next = NULL;
136 } else {
137 assert(next_hob_addr < (uintptr_t)hob_list->efi_end_of_hob_list);
138 next = (struct efi_hob_generic_header *)next_hob_addr;
139 }
140 }
141
Kathleen Capellabde3eab2024-12-09 14:04:43 -0500142}