Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2013, Intel Corporation |
| 3 | * Copyright (C) 2014, Bin Meng <bmeng.cn@gmail.com> |
| 4 | * |
| 5 | * SPDX-License-Identifier: Intel |
| 6 | */ |
| 7 | |
| 8 | #ifndef __FSP_HOB_H__ |
| 9 | #define __FSP_HOB_H__ |
| 10 | |
| 11 | /* Type of HOB Header */ |
| 12 | #define HOB_TYPE_MEM_ALLOC 0x0002 |
| 13 | #define HOB_TYPE_RES_DESC 0x0003 |
| 14 | #define HOB_TYPE_GUID_EXT 0x0004 |
| 15 | #define HOB_TYPE_UNUSED 0xFFFE |
| 16 | #define HOB_TYPE_EOH 0xFFFF |
| 17 | |
| 18 | /* |
| 19 | * Describes the format and size of the data inside the HOB. |
| 20 | * All HOBs must contain this generic HOB header. |
| 21 | */ |
Bin Meng | db60d86 | 2014-12-17 15:50:49 +0800 | [diff] [blame] | 22 | struct hob_header { |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 23 | u16 type; /* HOB type */ |
| 24 | u16 len; /* HOB length */ |
| 25 | u32 reserved; /* always zero */ |
| 26 | }; |
| 27 | |
| 28 | /* Enumeration of memory types introduced in UEFI */ |
Bin Meng | db60d86 | 2014-12-17 15:50:49 +0800 | [diff] [blame] | 29 | enum efi_mem_type { |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 30 | EFI_RESERVED_MEMORY_TYPE, |
| 31 | /* |
| 32 | * The code portions of a loaded application. |
| 33 | * (Note that UEFI OS loaders are UEFI applications.) |
| 34 | */ |
| 35 | EFI_LOADER_CODE, |
| 36 | /* |
| 37 | * The data portions of a loaded application and |
| 38 | * the default data allocation type used by an application |
| 39 | * to allocate pool memory. |
| 40 | */ |
| 41 | EFI_LOADER_DATA, |
| 42 | /* The code portions of a loaded Boot Services Driver */ |
| 43 | EFI_BOOT_SERVICES_CODE, |
| 44 | /* |
| 45 | * The data portions of a loaded Boot Serves Driver and |
| 46 | * the default data allocation type used by a Boot Services |
| 47 | * Driver to allocate pool memory. |
| 48 | */ |
| 49 | EFI_BOOT_SERVICES_DATA, |
| 50 | /* The code portions of a loaded Runtime Services Driver */ |
| 51 | EFI_RUNTIME_SERVICES_CODE, |
| 52 | /* |
| 53 | * The data portions of a loaded Runtime Services Driver and |
| 54 | * the default data allocation type used by a Runtime Services |
| 55 | * Driver to allocate pool memory. |
| 56 | */ |
| 57 | EFI_RUNTIME_SERVICES_DATA, |
| 58 | /* Free (unallocated) memory */ |
| 59 | EFI_CONVENTIONAL_MEMORY, |
| 60 | /* Memory in which errors have been detected */ |
| 61 | EFI_UNUSABLE_MEMORY, |
| 62 | /* Memory that holds the ACPI tables */ |
| 63 | EFI_ACPI_RECLAIM_MEMORY, |
| 64 | /* Address space reserved for use by the firmware */ |
| 65 | EFI_ACPI_MEMORY_NVS, |
| 66 | /* |
| 67 | * Used by system firmware to request that a memory-mapped IO region |
| 68 | * be mapped by the OS to a virtual address so it can be accessed by |
| 69 | * EFI runtime services. |
| 70 | */ |
| 71 | EFI_MMAP_IO, |
| 72 | /* |
| 73 | * System memory-mapped IO region that is used to translate |
| 74 | * memory cycles to IO cycles by the processor. |
| 75 | */ |
| 76 | EFI_MMAP_IO_PORT, |
| 77 | /* |
| 78 | * Address space reserved by the firmware for code that is |
| 79 | * part of the processor. |
| 80 | */ |
| 81 | EFI_PAL_CODE, |
| 82 | EFI_MAX_MEMORY_TYPE |
| 83 | }; |
| 84 | |
| 85 | /* |
| 86 | * Describes all memory ranges used during the HOB producer phase that |
| 87 | * exist outside the HOB list. This HOB type describes how memory is used, |
| 88 | * not the physical attributes of memory. |
| 89 | */ |
Bin Meng | db60d86 | 2014-12-17 15:50:49 +0800 | [diff] [blame] | 90 | struct hob_mem_alloc { |
| 91 | struct hob_header hdr; |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 92 | /* |
| 93 | * A GUID that defines the memory allocation region's type and purpose, |
| 94 | * as well as other fields within the memory allocation HOB. This GUID |
| 95 | * is used to define the additional data within the HOB that may be |
Bin Meng | db60d86 | 2014-12-17 15:50:49 +0800 | [diff] [blame] | 96 | * present for the memory allocation HOB. Type efi_guid is defined in |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 97 | * InstallProtocolInterface() in the UEFI 2.0 specification. |
| 98 | */ |
Bin Meng | db60d86 | 2014-12-17 15:50:49 +0800 | [diff] [blame] | 99 | struct efi_guid name; |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 100 | /* |
| 101 | * The base address of memory allocated by this HOB. |
| 102 | * Type phys_addr_t is defined in AllocatePages() in the UEFI 2.0 |
| 103 | * specification. |
| 104 | */ |
| 105 | phys_addr_t mem_base; |
| 106 | /* The length in bytes of memory allocated by this HOB */ |
| 107 | phys_size_t mem_len; |
| 108 | /* |
| 109 | * Defines the type of memory allocated by this HOB. |
| 110 | * The memory type definition follows the EFI_MEMORY_TYPE definition. |
| 111 | * Type EFI_MEMORY_TYPE is defined in AllocatePages() in the UEFI 2.0 |
| 112 | * specification. |
| 113 | */ |
Bin Meng | db60d86 | 2014-12-17 15:50:49 +0800 | [diff] [blame] | 114 | enum efi_mem_type mem_type; |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 115 | /* padding */ |
| 116 | u8 reserved[4]; |
| 117 | }; |
| 118 | |
| 119 | /* Value of ResourceType in HOB_RES_DESC */ |
| 120 | #define RES_SYS_MEM 0x00000000 |
| 121 | #define RES_MMAP_IO 0x00000001 |
| 122 | #define RES_IO 0x00000002 |
| 123 | #define RES_FW_DEVICE 0x00000003 |
| 124 | #define RES_MMAP_IO_PORT 0x00000004 |
| 125 | #define RES_MEM_RESERVED 0x00000005 |
| 126 | #define RES_IO_RESERVED 0x00000006 |
| 127 | #define RES_MAX_MEM_TYPE 0x00000007 |
| 128 | |
| 129 | /* |
| 130 | * These types can be ORed together as needed. |
| 131 | * |
| 132 | * The first three enumerations describe settings |
| 133 | * The rest of the settings describe capabilities |
| 134 | */ |
| 135 | #define RES_ATTR_PRESENT 0x00000001 |
| 136 | #define RES_ATTR_INITIALIZED 0x00000002 |
| 137 | #define RES_ATTR_TESTED 0x00000004 |
| 138 | #define RES_ATTR_SINGLE_BIT_ECC 0x00000008 |
| 139 | #define RES_ATTR_MULTIPLE_BIT_ECC 0x00000010 |
| 140 | #define RES_ATTR_ECC_RESERVED_1 0x00000020 |
| 141 | #define RES_ATTR_ECC_RESERVED_2 0x00000040 |
| 142 | #define RES_ATTR_READ_PROTECTED 0x00000080 |
| 143 | #define RES_ATTR_WRITE_PROTECTED 0x00000100 |
| 144 | #define RES_ATTR_EXECUTION_PROTECTED 0x00000200 |
| 145 | #define RES_ATTR_UNCACHEABLE 0x00000400 |
| 146 | #define RES_ATTR_WRITE_COMBINEABLE 0x00000800 |
| 147 | #define RES_ATTR_WRITE_THROUGH_CACHEABLE 0x00001000 |
| 148 | #define RES_ATTR_WRITE_BACK_CACHEABLE 0x00002000 |
| 149 | #define RES_ATTR_16_BIT_IO 0x00004000 |
| 150 | #define RES_ATTR_32_BIT_IO 0x00008000 |
| 151 | #define RES_ATTR_64_BIT_IO 0x00010000 |
| 152 | #define RES_ATTR_UNCACHED_EXPORTED 0x00020000 |
| 153 | |
| 154 | /* |
| 155 | * Describes the resource properties of all fixed, nonrelocatable resource |
| 156 | * ranges found on the processor host bus during the HOB producer phase. |
| 157 | */ |
Bin Meng | db60d86 | 2014-12-17 15:50:49 +0800 | [diff] [blame] | 158 | struct hob_res_desc { |
| 159 | struct hob_header hdr; |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 160 | /* |
| 161 | * A GUID representing the owner of the resource. This GUID is |
| 162 | * used by HOB consumer phase components to correlate device |
| 163 | * ownership of a resource. |
| 164 | */ |
Bin Meng | db60d86 | 2014-12-17 15:50:49 +0800 | [diff] [blame] | 165 | struct efi_guid owner; |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 166 | u32 type; |
| 167 | u32 attr; |
| 168 | /* The physical start address of the resource region */ |
| 169 | phys_addr_t phys_start; |
| 170 | /* The number of bytes of the resource region */ |
| 171 | phys_size_t len; |
| 172 | }; |
| 173 | |
| 174 | /* |
| 175 | * Allows writers of executable content in the HOB producer phase to |
| 176 | * maintain and manage HOBs with specific GUID. |
| 177 | */ |
Bin Meng | db60d86 | 2014-12-17 15:50:49 +0800 | [diff] [blame] | 178 | struct hob_guid { |
| 179 | struct hob_header hdr; |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 180 | /* A GUID that defines the contents of this HOB */ |
Bin Meng | db60d86 | 2014-12-17 15:50:49 +0800 | [diff] [blame] | 181 | struct efi_guid name; |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 182 | /* GUID specific data goes here */ |
| 183 | }; |
| 184 | |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 185 | /** |
Bin Meng | db60d86 | 2014-12-17 15:50:49 +0800 | [diff] [blame] | 186 | * get_next_hob() - return a pointer to the next HOB in the HOB list |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 187 | * |
| 188 | * This macro returns a pointer to HOB that follows the HOB specified by hob |
| 189 | * in the HOB List. |
| 190 | * |
Bin Meng | 2b21598 | 2014-12-30 16:02:05 +0800 | [diff] [blame] | 191 | * @hdr: A pointer to a HOB. |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 192 | * |
| 193 | * @return: A pointer to the next HOB in the HOB list. |
| 194 | */ |
Bin Meng | 2b21598 | 2014-12-30 16:02:05 +0800 | [diff] [blame] | 195 | static inline const struct hob_header *get_next_hob(const struct hob_header *hdr) |
Bin Meng | db60d86 | 2014-12-17 15:50:49 +0800 | [diff] [blame] | 196 | { |
Bin Meng | 2f848bc | 2015-01-06 14:04:36 +0800 | [diff] [blame] | 197 | return (const struct hob_header *)((u32)hdr + hdr->len); |
Bin Meng | db60d86 | 2014-12-17 15:50:49 +0800 | [diff] [blame] | 198 | } |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 199 | |
| 200 | /** |
Bin Meng | db60d86 | 2014-12-17 15:50:49 +0800 | [diff] [blame] | 201 | * end_of_hob() - determine if a HOB is the last HOB in the HOB list |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 202 | * |
| 203 | * This macro determine if the HOB specified by hob is the last HOB in the |
Bin Meng | db60d86 | 2014-12-17 15:50:49 +0800 | [diff] [blame] | 204 | * HOB list. If hob is last HOB in the HOB list, then true is returned. |
| 205 | * Otherwise, false is returned. |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 206 | * |
Bin Meng | 2b21598 | 2014-12-30 16:02:05 +0800 | [diff] [blame] | 207 | * @hdr: A pointer to a HOB. |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 208 | * |
Bin Meng | 2b21598 | 2014-12-30 16:02:05 +0800 | [diff] [blame] | 209 | * @retval true: The HOB specified by hdr is the last HOB in the HOB list. |
| 210 | * @retval false: The HOB specified by hdr is not the last HOB in the HOB list. |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 211 | */ |
Bin Meng | 2b21598 | 2014-12-30 16:02:05 +0800 | [diff] [blame] | 212 | static inline bool end_of_hob(const struct hob_header *hdr) |
Bin Meng | db60d86 | 2014-12-17 15:50:49 +0800 | [diff] [blame] | 213 | { |
Bin Meng | 2f848bc | 2015-01-06 14:04:36 +0800 | [diff] [blame] | 214 | return hdr->type == HOB_TYPE_EOH; |
Bin Meng | db60d86 | 2014-12-17 15:50:49 +0800 | [diff] [blame] | 215 | } |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 216 | |
| 217 | /** |
Bin Meng | db60d86 | 2014-12-17 15:50:49 +0800 | [diff] [blame] | 218 | * get_guid_hob_data() - return a pointer to data buffer from a HOB of |
| 219 | * type HOB_TYPE_GUID_EXT |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 220 | * |
| 221 | * This macro returns a pointer to the data buffer in a HOB specified by hob. |
| 222 | * hob is assumed to be a HOB of type HOB_TYPE_GUID_EXT. |
| 223 | * |
Bin Meng | 2b21598 | 2014-12-30 16:02:05 +0800 | [diff] [blame] | 224 | * @hdr: A pointer to a HOB. |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 225 | * |
| 226 | * @return: A pointer to the data buffer in a HOB. |
| 227 | */ |
Bin Meng | 2b21598 | 2014-12-30 16:02:05 +0800 | [diff] [blame] | 228 | static inline void *get_guid_hob_data(const struct hob_header *hdr) |
Bin Meng | db60d86 | 2014-12-17 15:50:49 +0800 | [diff] [blame] | 229 | { |
Bin Meng | 2b21598 | 2014-12-30 16:02:05 +0800 | [diff] [blame] | 230 | return (void *)((u32)hdr + sizeof(struct hob_guid)); |
Bin Meng | db60d86 | 2014-12-17 15:50:49 +0800 | [diff] [blame] | 231 | } |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 232 | |
| 233 | /** |
Bin Meng | db60d86 | 2014-12-17 15:50:49 +0800 | [diff] [blame] | 234 | * get_guid_hob_data_size() - return the size of the data buffer from a HOB |
| 235 | * of type HOB_TYPE_GUID_EXT |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 236 | * |
| 237 | * This macro returns the size, in bytes, of the data buffer in a HOB |
| 238 | * specified by hob. hob is assumed to be a HOB of type HOB_TYPE_GUID_EXT. |
| 239 | * |
Bin Meng | 2b21598 | 2014-12-30 16:02:05 +0800 | [diff] [blame] | 240 | * @hdr: A pointer to a HOB. |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 241 | * |
| 242 | * @return: The size of the data buffer. |
| 243 | */ |
Bin Meng | 2b21598 | 2014-12-30 16:02:05 +0800 | [diff] [blame] | 244 | static inline u16 get_guid_hob_data_size(const struct hob_header *hdr) |
Bin Meng | db60d86 | 2014-12-17 15:50:49 +0800 | [diff] [blame] | 245 | { |
Bin Meng | 2f848bc | 2015-01-06 14:04:36 +0800 | [diff] [blame] | 246 | return hdr->len - sizeof(struct hob_guid); |
Bin Meng | db60d86 | 2014-12-17 15:50:49 +0800 | [diff] [blame] | 247 | } |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 248 | |
| 249 | /* FSP specific GUID HOB definitions */ |
Bin Meng | db60d86 | 2014-12-17 15:50:49 +0800 | [diff] [blame] | 250 | #define FSP_GUID_DATA1 0x912740be |
| 251 | #define FSP_GUID_DATA2 0x2284 |
| 252 | #define FSP_GUID_DATA3 0x4734 |
| 253 | #define FSP_GUID_DATA4_0 0xb9 |
| 254 | #define FSP_GUID_DATA4_1 0x71 |
| 255 | #define FSP_GUID_DATA4_2 0x84 |
| 256 | #define FSP_GUID_DATA4_3 0xb0 |
| 257 | #define FSP_GUID_DATA4_4 0x27 |
| 258 | #define FSP_GUID_DATA4_5 0x35 |
| 259 | #define FSP_GUID_DATA4_6 0x3f |
| 260 | #define FSP_GUID_DATA4_7 0x0c |
| 261 | |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 262 | #define FSP_HEADER_GUID \ |
| 263 | { \ |
Bin Meng | db60d86 | 2014-12-17 15:50:49 +0800 | [diff] [blame] | 264 | FSP_GUID_DATA1, FSP_GUID_DATA2, FSP_GUID_DATA3, \ |
| 265 | { FSP_GUID_DATA4_0, FSP_GUID_DATA4_1, FSP_GUID_DATA4_2, \ |
| 266 | FSP_GUID_DATA4_3, FSP_GUID_DATA4_4, FSP_GUID_DATA4_5, \ |
| 267 | FSP_GUID_DATA4_6, FSP_GUID_DATA4_7 } \ |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 268 | } |
| 269 | |
| 270 | #define FSP_NON_VOLATILE_STORAGE_HOB_GUID \ |
| 271 | { \ |
| 272 | 0x721acf02, 0x4d77, 0x4c2a, \ |
| 273 | { 0xb3, 0xdc, 0x27, 0xb, 0x7b, 0xa9, 0xe4, 0xb0 } \ |
| 274 | } |
| 275 | |
| 276 | #define FSP_BOOTLOADER_TEMP_MEM_HOB_GUID \ |
| 277 | { \ |
| 278 | 0xbbcff46c, 0xc8d3, 0x4113, \ |
| 279 | { 0x89, 0x85, 0xb9, 0xd4, 0xf3, 0xb3, 0xf6, 0x4e } \ |
| 280 | } |
| 281 | |
| 282 | #define FSP_HOB_RESOURCE_OWNER_FSP_GUID \ |
| 283 | { \ |
| 284 | 0x69a79759, 0x1373, 0x4367, \ |
| 285 | { 0xa6, 0xc4, 0xc7, 0xf5, 0x9e, 0xfd, 0x98, 0x6e } \ |
| 286 | } |
| 287 | |
| 288 | #define FSP_HOB_RESOURCE_OWNER_TSEG_GUID \ |
| 289 | { \ |
| 290 | 0xd038747c, 0xd00c, 0x4980, \ |
| 291 | { 0xb3, 0x19, 0x49, 0x01, 0x99, 0xa4, 0x7d, 0x55 } \ |
| 292 | } |
| 293 | |
| 294 | #define FSP_HOB_RESOURCE_OWNER_GRAPHICS_GUID \ |
| 295 | { \ |
| 296 | 0x9c7c3aa7, 0x5332, 0x4917, \ |
| 297 | { 0x82, 0xb9, 0x56, 0xa5, 0xf3, 0xe6, 0x2a, 0x07 } \ |
| 298 | } |
| 299 | |
| 300 | #endif |