Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2013-2014 Sage Electronic Engineering, LLC. |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame^] | 5 | * Copyright (C) 2015 Intel Corp. |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; version 2 of the License. |
| 10 | * |
| 11 | * This program 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 this program; if not, write to the Free Software |
Patrick Georgi | b890a12 | 2015-03-26 15:17:45 +0100 | [diff] [blame] | 18 | * Foundation, Inc. |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 19 | */ |
| 20 | |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame^] | 21 | #include <arch/early_variables.h> |
| 22 | #include <arch/hlt.h> |
| 23 | #include <bootstate.h> |
| 24 | #include <cbmem.h> |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 25 | #include <console/console.h> |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 26 | #include "fsp_util.h" |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame^] | 27 | #include <ip_checksum.h> |
| 28 | #include <lib.h> // hexdump |
| 29 | #include <string.h> |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 30 | |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame^] | 31 | /* |
| 32 | * Reads a 64-bit value from memory that may be unaligned. |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 33 | * |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame^] | 34 | * This function returns the 64-bit value pointed to by buffer. The |
| 35 | * function guarantees that the read operation does not produce an |
| 36 | * alignment fault. |
| 37 | * |
| 38 | * If buffer is NULL, then ASSERT(). |
| 39 | * |
| 40 | * buffer: Pointer to a 64-bit value that may be unaligned. |
| 41 | * |
| 42 | * Returns the 64-bit value read from buffer. |
| 43 | * |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 44 | */ |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame^] | 45 | static |
| 46 | uint64_t |
| 47 | read_unaligned_64( |
| 48 | const uint64_t *buffer |
| 49 | ) |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 50 | { |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame^] | 51 | ASSERT(buffer != NULL); |
| 52 | |
| 53 | return *buffer; |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 54 | } |
| 55 | |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame^] | 56 | /* |
| 57 | * Compares two GUIDs. |
| 58 | * |
| 59 | * This function compares guid1 to guid2. If the GUIDs are identical then |
| 60 | * TRUE is returned. If there are any bit differences in the two GUIDs, |
| 61 | * then FALSE is returned. |
| 62 | * |
| 63 | * If guid1 is NULL, then ASSERT(). |
| 64 | * If guid2 is NULL, then ASSERT(). |
| 65 | * |
| 66 | * guid1: A pointer to a 128 bit GUID. |
| 67 | * guid2: A pointer to a 128 bit GUID. |
| 68 | * |
| 69 | * Returns non-zero if guid1 and guid2 are identical, otherwise returns 0. |
| 70 | * |
| 71 | */ |
| 72 | static |
| 73 | long |
| 74 | compare_guid( |
| 75 | const EFI_GUID * guid1, |
| 76 | const EFI_GUID * guid2 |
| 77 | ) |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 78 | { |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame^] | 79 | uint64_t low_part_of_guid1; |
| 80 | uint64_t low_part_of_guid2; |
| 81 | uint64_t high_part_of_guid1; |
| 82 | uint64_t high_part_of_guid2; |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 83 | |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame^] | 84 | low_part_of_guid1 = read_unaligned_64((const uint64_t *) guid1); |
| 85 | low_part_of_guid2 = read_unaligned_64((const uint64_t *) guid2); |
| 86 | high_part_of_guid1 = read_unaligned_64((const uint64_t *) guid1 + 1); |
| 87 | high_part_of_guid2 = read_unaligned_64((const uint64_t *) guid2 + 1); |
| 88 | |
| 89 | return ((low_part_of_guid1 == low_part_of_guid2) |
| 90 | && (high_part_of_guid1 == high_part_of_guid2)); |
| 91 | } |
| 92 | |
| 93 | /* Returns the pointer to the HOB list. */ |
| 94 | VOID * |
| 95 | EFIAPI |
| 96 | get_hob_list( |
| 97 | VOID |
| 98 | ) |
| 99 | { |
| 100 | void *hob_list; |
| 101 | |
| 102 | hob_list = fsp_get_hob_list(); |
| 103 | if (hob_list == NULL) |
| 104 | die("Call fsp_set_runtime() before this call!\n"); |
| 105 | return hob_list; |
| 106 | } |
| 107 | |
| 108 | /* Returns the next instance of a HOB type from the starting HOB. */ |
| 109 | VOID * |
| 110 | EFIAPI |
| 111 | get_next_hob( |
| 112 | UINT16 type, |
| 113 | CONST VOID *hob_start |
| 114 | ) |
| 115 | { |
| 116 | EFI_PEI_HOB_POINTERS hob; |
| 117 | |
| 118 | ASSERT(hob_start != NULL); |
| 119 | |
| 120 | hob.Raw = (UINT8 *)hob_start; |
| 121 | |
| 122 | /* Parse the HOB list until end of list or matching type is found. */ |
| 123 | while (!END_OF_HOB_LIST(hob.Raw)) { |
| 124 | if (hob.Header->HobType == type) |
| 125 | return hob.Raw; |
| 126 | if (GET_HOB_LENGTH(hob.Raw) < sizeof(*hob.Header)) |
| 127 | break; |
| 128 | hob.Raw = GET_NEXT_HOB(hob.Raw); |
| 129 | } |
| 130 | return NULL; |
| 131 | } |
| 132 | |
| 133 | /* Returns the first instance of a HOB type among the whole HOB list. */ |
| 134 | VOID * |
| 135 | EFIAPI |
| 136 | get_first_hob( |
| 137 | UINT16 type |
| 138 | ) |
| 139 | { |
| 140 | VOID *hob_list; |
| 141 | |
| 142 | hob_list = get_hob_list(); |
| 143 | return get_next_hob(type, hob_list); |
| 144 | } |
| 145 | |
| 146 | /* Returns the next instance of the matched GUID HOB from the starting HOB. */ |
| 147 | VOID * |
| 148 | EFIAPI |
| 149 | get_next_guid_hob( |
| 150 | CONST EFI_GUID * guid, |
| 151 | CONST VOID *hob_start |
| 152 | ) |
| 153 | { |
| 154 | EFI_PEI_HOB_POINTERS hob; |
| 155 | |
| 156 | hob.Raw = (UINT8 *)hob_start; |
| 157 | while ((hob.Raw = get_next_hob(EFI_HOB_TYPE_GUID_EXTENSION, hob.Raw)) |
| 158 | != NULL) { |
| 159 | if (compare_guid(guid, &hob.Guid->Name)) |
| 160 | break; |
| 161 | hob.Raw = GET_NEXT_HOB(hob.Raw); |
| 162 | } |
| 163 | return hob.Raw; |
| 164 | } |
| 165 | |
| 166 | /* |
| 167 | * Returns the first instance of the matched GUID HOB among the whole HOB list. |
| 168 | */ |
| 169 | VOID * |
| 170 | EFIAPI |
| 171 | get_first_guid_hob( |
| 172 | CONST EFI_GUID * guid |
| 173 | ) |
| 174 | { |
| 175 | return get_next_guid_hob(guid, get_hob_list()); |
| 176 | } |
| 177 | |
| 178 | /* |
| 179 | * Returns the next instance of the matching resource HOB from the starting HOB. |
| 180 | */ |
| 181 | void *get_next_resource_hob(const EFI_GUID *guid, const void *hob_start) |
| 182 | { |
| 183 | EFI_PEI_HOB_POINTERS hob; |
| 184 | |
| 185 | hob.Raw = (UINT8 *)hob_start; |
| 186 | while ((hob.Raw = get_next_hob(EFI_HOB_TYPE_RESOURCE_DESCRIPTOR, |
| 187 | hob.Raw)) != NULL) { |
| 188 | if (compare_guid(guid, &hob.ResourceDescriptor->Owner)) |
| 189 | break; |
| 190 | hob.Raw = GET_NEXT_HOB(hob.Raw); |
| 191 | } |
| 192 | return hob.Raw; |
| 193 | } |
| 194 | |
| 195 | /* |
| 196 | * Returns the first instance of the matching resource HOB among the whole HOB |
| 197 | * list. |
| 198 | */ |
| 199 | void *get_first_resource_hob(const EFI_GUID *guid) |
| 200 | { |
| 201 | return get_next_resource_hob(guid, get_hob_list()); |
| 202 | } |
| 203 | |
| 204 | static void print_hob_mem_attributes(void *hob_ptr) |
| 205 | { |
| 206 | EFI_HOB_MEMORY_ALLOCATION *hob_memory_ptr = |
| 207 | (EFI_HOB_MEMORY_ALLOCATION *)hob_ptr; |
| 208 | EFI_MEMORY_TYPE hob_mem_type = |
| 209 | hob_memory_ptr->AllocDescriptor.MemoryType; |
| 210 | u64 hob_mem_addr = hob_memory_ptr->AllocDescriptor.MemoryBaseAddress; |
| 211 | u64 hob_mem_length = hob_memory_ptr->AllocDescriptor.MemoryLength; |
| 212 | const char *hob_mem_type_names[15]; |
| 213 | |
| 214 | hob_mem_type_names[0] = "EfiReservedMemoryType"; |
| 215 | hob_mem_type_names[1] = "EfiLoaderCode"; |
| 216 | hob_mem_type_names[2] = "EfiLoaderData"; |
| 217 | hob_mem_type_names[3] = "EfiBootServicesCode"; |
| 218 | hob_mem_type_names[4] = "EfiBootServicesData"; |
| 219 | hob_mem_type_names[5] = "EfiRuntimeServicesCode"; |
| 220 | hob_mem_type_names[6] = "EfiRuntimeServicesData"; |
| 221 | hob_mem_type_names[7] = "EfiConventionalMemory"; |
| 222 | hob_mem_type_names[8] = "EfiUnusableMemory"; |
| 223 | hob_mem_type_names[9] = "EfiACPIReclaimMemory"; |
| 224 | hob_mem_type_names[10] = "EfiACPIMemoryNVS"; |
| 225 | hob_mem_type_names[11] = "EfiMemoryMappedIO"; |
| 226 | hob_mem_type_names[12] = "EfiMemoryMappedIOPortSpace"; |
| 227 | hob_mem_type_names[13] = "EfiPalCode"; |
| 228 | hob_mem_type_names[14] = "EfiMaxMemoryType"; |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 229 | |
| 230 | printk(BIOS_SPEW, " Memory type %s (0x%x)\n", |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame^] | 231 | hob_mem_type_names[(u32)hob_mem_type], |
| 232 | (u32)hob_mem_type); |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 233 | printk(BIOS_SPEW, " at location 0x%0lx with length 0x%0lx\n", |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame^] | 234 | (unsigned long)hob_mem_addr, |
| 235 | (unsigned long)hob_mem_length); |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 236 | } |
| 237 | |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame^] | 238 | static void print_hob_resource_attributes(void *hob_ptr) |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 239 | { |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame^] | 240 | EFI_HOB_RESOURCE_DESCRIPTOR *hob_resource_ptr = |
| 241 | (EFI_HOB_RESOURCE_DESCRIPTOR *)hob_ptr; |
| 242 | u32 hob_res_type = hob_resource_ptr->ResourceType; |
| 243 | u32 hob_res_attr = hob_resource_ptr->ResourceAttribute; |
| 244 | u64 hob_res_addr = hob_resource_ptr->PhysicalStart; |
| 245 | u64 hob_res_length = hob_resource_ptr->ResourceLength; |
| 246 | const char *hob_res_type_str = NULL; |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 247 | |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame^] | 248 | /* HOB Resource Types */ |
| 249 | switch (hob_res_type) { |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 250 | case EFI_RESOURCE_SYSTEM_MEMORY: |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame^] | 251 | hob_res_type_str = "EFI_RESOURCE_SYSTEM_MEMORY"; |
| 252 | break; |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 253 | case EFI_RESOURCE_MEMORY_MAPPED_IO: |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame^] | 254 | hob_res_type_str = "EFI_RESOURCE_MEMORY_MAPPED_IO"; |
| 255 | break; |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 256 | case EFI_RESOURCE_IO: |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame^] | 257 | hob_res_type_str = "EFI_RESOURCE_IO"; |
| 258 | break; |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 259 | case EFI_RESOURCE_FIRMWARE_DEVICE: |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame^] | 260 | hob_res_type_str = "EFI_RESOURCE_FIRMWARE_DEVICE"; |
| 261 | break; |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 262 | case EFI_RESOURCE_MEMORY_MAPPED_IO_PORT: |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame^] | 263 | hob_res_type_str = "EFI_RESOURCE_MEMORY_MAPPED_IO_PORT"; |
| 264 | break; |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 265 | case EFI_RESOURCE_MEMORY_RESERVED: |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame^] | 266 | hob_res_type_str = "EFI_RESOURCE_MEMORY_RESERVED"; |
| 267 | break; |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 268 | case EFI_RESOURCE_IO_RESERVED: |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame^] | 269 | hob_res_type_str = "EFI_RESOURCE_IO_RESERVED"; |
| 270 | break; |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 271 | case EFI_RESOURCE_MAX_MEMORY_TYPE: |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame^] | 272 | hob_res_type_str = "EFI_RESOURCE_MAX_MEMORY_TYPE"; |
| 273 | break; |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 274 | default: |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame^] | 275 | hob_res_type_str = "EFI_RESOURCE_UNKNOWN"; |
| 276 | break; |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 277 | } |
| 278 | |
| 279 | printk(BIOS_SPEW, " Resource %s (0x%0x) has attributes 0x%0x\n", |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame^] | 280 | hob_res_type_str, hob_res_type, hob_res_attr); |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 281 | printk(BIOS_SPEW, " at location 0x%0lx with length 0x%0lx\n", |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame^] | 282 | (unsigned long)hob_res_addr, |
| 283 | (unsigned long)hob_res_length); |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 284 | } |
| 285 | |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame^] | 286 | static const char *get_hob_type_string(void *hob_ptr) |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 287 | { |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame^] | 288 | EFI_PEI_HOB_POINTERS hob; |
| 289 | const char *hob_type_string = NULL; |
| 290 | const EFI_GUID fsp_reserved_guid = |
| 291 | FSP_RESERVED_MEMORY_RESOURCE_HOB_GUID; |
| 292 | const EFI_GUID mrc_guid = FSP_NON_VOLATILE_STORAGE_HOB_GUID; |
| 293 | const EFI_GUID bootldr_tmp_mem_guid = |
| 294 | FSP_BOOTLOADER_TEMP_MEMORY_HOB_GUID; |
| 295 | const EFI_GUID bootldr_tolum_guid = FSP_BOOTLOADER_TOLUM_HOB_GUID; |
| 296 | const EFI_GUID graphics_info_guid = EFI_PEI_GRAPHICS_INFO_HOB_GUID; |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 297 | |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame^] | 298 | hob.Header = (EFI_HOB_GENERIC_HEADER *)hob_ptr; |
| 299 | switch (hob.Header->HobType) { |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 300 | case EFI_HOB_TYPE_HANDOFF: |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame^] | 301 | hob_type_string = "EFI_HOB_TYPE_HANDOFF"; |
| 302 | break; |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 303 | case EFI_HOB_TYPE_MEMORY_ALLOCATION: |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame^] | 304 | hob_type_string = "EFI_HOB_TYPE_MEMORY_ALLOCATION"; |
| 305 | break; |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 306 | case EFI_HOB_TYPE_RESOURCE_DESCRIPTOR: |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame^] | 307 | hob_type_string = "EFI_HOB_TYPE_RESOURCE_DESCRIPTOR"; |
| 308 | break; |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 309 | case EFI_HOB_TYPE_GUID_EXTENSION: |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame^] | 310 | hob_type_string = "EFI_HOB_TYPE_GUID_EXTENSION"; |
| 311 | if (compare_guid(&bootldr_tmp_mem_guid, &hob.Guid->Name)) |
| 312 | hob_type_string = "FSP_BOOTLOADER_TEMP_MEMORY_HOB"; |
| 313 | else if (compare_guid(&fsp_reserved_guid, &hob.Guid->Name)) |
| 314 | hob_type_string = "FSP_RESERVED_MEMORY_RESOURCE_HOB"; |
| 315 | else if (compare_guid(&mrc_guid, &hob.Guid->Name)) |
| 316 | hob_type_string = "FSP_NON_VOLATILE_STORAGE_HOB"; |
| 317 | else if (compare_guid(&bootldr_tolum_guid, &hob.Guid->Name)) |
| 318 | hob_type_string = "FSP_BOOTLOADER_TOLUM_HOB_GUID"; |
| 319 | else if (compare_guid(&graphics_info_guid, &hob.Guid->Name)) |
| 320 | hob_type_string = "EFI_PEI_GRAPHICS_INFO_HOB_GUID"; |
| 321 | break; |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 322 | case EFI_HOB_TYPE_MEMORY_POOL: |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame^] | 323 | hob_type_string = "EFI_HOB_TYPE_MEMORY_POOL"; |
| 324 | break; |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 325 | case EFI_HOB_TYPE_UNUSED: |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame^] | 326 | hob_type_string = "EFI_HOB_TYPE_UNUSED"; |
| 327 | break; |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 328 | case EFI_HOB_TYPE_END_OF_HOB_LIST: |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame^] | 329 | hob_type_string = "EFI_HOB_TYPE_END_OF_HOB_LIST"; |
| 330 | break; |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 331 | default: |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame^] | 332 | hob_type_string = "EFI_HOB_TYPE_UNRECOGNIZED"; |
| 333 | break; |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 334 | } |
| 335 | |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame^] | 336 | return hob_type_string; |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 337 | } |
| 338 | |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame^] | 339 | /* |
| 340 | * Print out a structure of all the HOBs |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 341 | * that match a certain type: |
| 342 | * Print all types (0x0000) |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame^] | 343 | * EFI_HOB_TYPE_HANDOFF (0x0001) |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 344 | * EFI_HOB_TYPE_MEMORY_ALLOCATION (0x0002) |
| 345 | * EFI_HOB_TYPE_RESOURCE_DESCRIPTOR (0x0003) |
| 346 | * EFI_HOB_TYPE_GUID_EXTENSION (0x0004) |
| 347 | * EFI_HOB_TYPE_MEMORY_POOL (0x0007) |
| 348 | * EFI_HOB_TYPE_UNUSED (0xFFFE) |
| 349 | * EFI_HOB_TYPE_END_OF_HOB_LIST (0xFFFF) |
| 350 | */ |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame^] | 351 | void print_hob_type_structure(u16 hob_type, void *hob_list_ptr) |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 352 | { |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame^] | 353 | u32 *current_hob; |
| 354 | u32 *next_hob = 0; |
| 355 | u8 last_hob = 0; |
| 356 | u32 current_type; |
| 357 | const char *current_type_str; |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 358 | |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame^] | 359 | current_hob = hob_list_ptr; |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 360 | |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame^] | 361 | /* |
| 362 | * Print out HOBs of our desired type until |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 363 | * the end of the HOB list |
| 364 | */ |
| 365 | printk(BIOS_DEBUG, "\n=== FSP HOB Data Structure ===\n"); |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame^] | 366 | printk(BIOS_DEBUG, "0x%p: hob_list_ptr\n", hob_list_ptr); |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 367 | do { |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame^] | 368 | EFI_HOB_GENERIC_HEADER *current_header_ptr = |
| 369 | (EFI_HOB_GENERIC_HEADER *)current_hob; |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 370 | |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame^] | 371 | /* Get the type of this HOB */ |
| 372 | current_type = current_header_ptr->HobType; |
| 373 | current_type_str = get_hob_type_string(current_hob); |
| 374 | |
| 375 | if (current_type == hob_type || hob_type == 0x0000) { |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 376 | printk(BIOS_DEBUG, "HOB 0x%0x is an %s (type 0x%0x)\n", |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame^] | 377 | (u32)current_hob, current_type_str, |
| 378 | current_type); |
| 379 | switch (current_type) { |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 380 | case EFI_HOB_TYPE_MEMORY_ALLOCATION: |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame^] | 381 | print_hob_mem_attributes(current_hob); |
| 382 | break; |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 383 | case EFI_HOB_TYPE_RESOURCE_DESCRIPTOR: |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame^] | 384 | print_hob_resource_attributes(current_hob); |
| 385 | break; |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 386 | } |
| 387 | } |
| 388 | |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame^] | 389 | /* Check for end of HOB list */ |
| 390 | last_hob = END_OF_HOB_LIST(current_hob); |
| 391 | if (!last_hob) { |
| 392 | /* Get next HOB pointer */ |
| 393 | next_hob = GET_NEXT_HOB(current_hob); |
| 394 | |
| 395 | /* Start on next HOB */ |
| 396 | current_hob = next_hob; |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 397 | } |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame^] | 398 | } while (!last_hob); |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 399 | printk(BIOS_DEBUG, "=== End of FSP HOB Data Structure ===\n\n"); |
| 400 | } |
| 401 | |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame^] | 402 | #if IS_ENABLED(CONFIG_ENABLE_MRC_CACHE) |
| 403 | /* |
| 404 | * Save the FSP memory HOB (mrc data) to the MRC area in CBMEM |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 405 | */ |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame^] | 406 | int save_mrc_data(void *hob_start) |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 407 | { |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame^] | 408 | u32 *mrc_hob; |
| 409 | u32 *mrc_hob_data; |
| 410 | u32 mrc_hob_size; |
| 411 | struct mrc_data_container *mrc_data; |
| 412 | int output_len; |
| 413 | const EFI_GUID mrc_guid = FSP_NON_VOLATILE_STORAGE_HOB_GUID; |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 414 | |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame^] | 415 | mrc_hob = get_next_guid_hob(&mrc_guid, hob_start); |
| 416 | if (mrc_hob == NULL) { |
| 417 | printk(BIOS_DEBUG, |
| 418 | "Memory Configure Data Hob is not present\n"); |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 419 | return 0; |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame^] | 420 | } |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 421 | |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame^] | 422 | mrc_hob_data = GET_GUID_HOB_DATA(mrc_hob); |
| 423 | mrc_hob_size = (u32) GET_HOB_LENGTH(mrc_hob); |
| 424 | |
| 425 | printk(BIOS_DEBUG, "Memory Configure Data Hob at %p (size = 0x%x).\n", |
| 426 | (void *)mrc_hob_data, mrc_hob_size); |
| 427 | |
| 428 | output_len = ALIGN(mrc_hob_size, 16); |
| 429 | |
| 430 | /* Save the MRC S3/fast boot/ADR restore data to cbmem */ |
| 431 | mrc_data = cbmem_add(CBMEM_ID_MRCDATA, |
| 432 | output_len + sizeof(struct mrc_data_container)); |
| 433 | |
| 434 | /* Just return if there was a problem with getting CBMEM */ |
| 435 | if (mrc_data == NULL) { |
| 436 | printk(BIOS_WARNING, |
| 437 | "CBMEM was not available to save the fast boot cache data.\n"); |
| 438 | return 0; |
| 439 | } |
| 440 | |
| 441 | printk(BIOS_DEBUG, |
| 442 | "Copy FSP MRC DATA to HOB (source addr %p, dest addr %p, %u bytes)\n", |
| 443 | (void *)mrc_hob_data, mrc_data, output_len); |
| 444 | |
| 445 | mrc_data->mrc_signature = MRC_DATA_SIGNATURE; |
| 446 | mrc_data->mrc_data_size = output_len; |
| 447 | mrc_data->reserved = 0; |
| 448 | memcpy(mrc_data->mrc_data, (const void *)mrc_hob_data, mrc_hob_size); |
| 449 | |
| 450 | /* Zero the unused space in aligned buffer. */ |
| 451 | if (output_len > mrc_hob_size) |
| 452 | memset((mrc_data->mrc_data + mrc_hob_size), 0, |
| 453 | output_len - mrc_hob_size); |
| 454 | |
| 455 | mrc_data->mrc_checksum = compute_ip_checksum(mrc_data->mrc_data, |
| 456 | mrc_data->mrc_data_size); |
| 457 | |
| 458 | #if IS_ENABLED(CONFIG_DISPLAY_FAST_BOOT_DATA) |
| 459 | printk(BIOS_SPEW, "Fast boot data (includes align and checksum):\n"); |
| 460 | hexdump32(BIOS_SPEW, (void *)mrc_data->mrc_data, output_len); |
| 461 | #endif |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 462 | return 1; |
| 463 | } |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame^] | 464 | |
| 465 | void __attribute__ ((weak)) update_mrc_cache(void *unused) |
| 466 | { |
| 467 | printk(BIOS_ERR, "Add routine %s to save the MRC data.\n", __func__); |
| 468 | } |
| 469 | #endif /* CONFIG_ENABLE_MRC_CACHE */ |
| 470 | |
| 471 | #if ENV_RAMSTAGE |
| 472 | |
| 473 | static void find_fsp_hob_update_mrc(void *unused) |
| 474 | { |
| 475 | void *hob_list_ptr; |
| 476 | |
| 477 | /* 0x0000: Print all types */ |
| 478 | hob_list_ptr = get_hob_list(); |
| 479 | #if IS_ENABLED(CONFIG_DISPLAY_HOBS) |
| 480 | print_hob_type_structure(0x000, hob_list_ptr); |
| 481 | #endif |
| 482 | |
| 483 | #if IS_ENABLED(CONFIG_ENABLE_MRC_CACHE) |
| 484 | if (save_mrc_data(hob_list_ptr)) |
| 485 | update_mrc_cache(NULL); |
| 486 | else |
| 487 | printk(BIOS_DEBUG, "Not updating MRC data in flash.\n"); |
| 488 | #endif |
| 489 | } |
| 490 | |
| 491 | /* Update the MRC/fast boot cache as part of the late table writing stage */ |
| 492 | BOOT_STATE_INIT_ENTRY(BS_WRITE_TABLES, BS_ON_ENTRY, |
| 493 | find_fsp_hob_update_mrc, NULL); |
| 494 | |
| 495 | #endif /* ENV_RAMSTAGE */ |