Park, Aiden | 538aec9 | 2019-08-03 08:30:31 +0000 | [diff] [blame] | 1 | /* SPDX-License-Identifier: Intel */ |
| 2 | /* |
| 3 | * Copyright (C) 2013, Intel Corporation |
| 4 | * Copyright (C) 2014, Bin Meng <bmeng.cn@gmail.com> |
| 5 | */ |
| 6 | |
| 7 | #ifndef __HOB_H__ |
| 8 | #define __HOB_H__ |
| 9 | |
| 10 | #include <efi.h> |
| 11 | #include <efi_loader.h> |
| 12 | |
| 13 | /* Type of HOB Header */ |
| 14 | #define HOB_TYPE_MEM_ALLOC 0x0002 |
| 15 | #define HOB_TYPE_RES_DESC 0x0003 |
| 16 | #define HOB_TYPE_GUID_EXT 0x0004 |
| 17 | #define HOB_TYPE_UNUSED 0xFFFE |
| 18 | #define HOB_TYPE_EOH 0xFFFF |
| 19 | |
| 20 | /* Value of ResourceType in HOB_RES_DESC */ |
| 21 | #define RES_SYS_MEM 0x00000000 |
| 22 | #define RES_MMAP_IO 0x00000001 |
| 23 | #define RES_IO 0x00000002 |
| 24 | #define RES_FW_DEVICE 0x00000003 |
| 25 | #define RES_MMAP_IO_PORT 0x00000004 |
| 26 | #define RES_MEM_RESERVED 0x00000005 |
| 27 | #define RES_IO_RESERVED 0x00000006 |
| 28 | #define RES_MAX_MEM_TYPE 0x00000007 |
| 29 | |
| 30 | /* |
| 31 | * These types can be ORed together as needed. |
| 32 | * |
| 33 | * The first three enumerations describe settings |
| 34 | * The rest of the settings describe capabilities |
| 35 | */ |
| 36 | #define RES_ATTR_PRESENT 0x00000001 |
| 37 | #define RES_ATTR_INITIALIZED 0x00000002 |
| 38 | #define RES_ATTR_TESTED 0x00000004 |
| 39 | #define RES_ATTR_SINGLE_BIT_ECC 0x00000008 |
| 40 | #define RES_ATTR_MULTIPLE_BIT_ECC 0x00000010 |
| 41 | #define RES_ATTR_ECC_RESERVED_1 0x00000020 |
| 42 | #define RES_ATTR_ECC_RESERVED_2 0x00000040 |
| 43 | #define RES_ATTR_READ_PROTECTED 0x00000080 |
| 44 | #define RES_ATTR_WRITE_PROTECTED 0x00000100 |
| 45 | #define RES_ATTR_EXECUTION_PROTECTED 0x00000200 |
| 46 | #define RES_ATTR_UNCACHEABLE 0x00000400 |
| 47 | #define RES_ATTR_WRITE_COMBINEABLE 0x00000800 |
| 48 | #define RES_ATTR_WRITE_THROUGH_CACHEABLE 0x00001000 |
| 49 | #define RES_ATTR_WRITE_BACK_CACHEABLE 0x00002000 |
| 50 | #define RES_ATTR_16_BIT_IO 0x00004000 |
| 51 | #define RES_ATTR_32_BIT_IO 0x00008000 |
| 52 | #define RES_ATTR_64_BIT_IO 0x00010000 |
| 53 | #define RES_ATTR_UNCACHED_EXPORTED 0x00020000 |
| 54 | |
| 55 | /* |
| 56 | * Describes the format and size of the data inside the HOB. |
| 57 | * All HOBs must contain this generic HOB header. |
| 58 | */ |
| 59 | struct hob_header { |
| 60 | u16 type; /* HOB type */ |
| 61 | u16 len; /* HOB length */ |
| 62 | u32 reserved; /* always zero */ |
| 63 | }; |
| 64 | |
| 65 | /* |
| 66 | * Describes all memory ranges used during the HOB producer phase that |
| 67 | * exist outside the HOB list. This HOB type describes how memory is used, |
| 68 | * not the physical attributes of memory. |
| 69 | */ |
| 70 | struct hob_mem_alloc { |
| 71 | struct hob_header hdr; |
| 72 | /* |
| 73 | * A GUID that defines the memory allocation region's type and purpose, |
| 74 | * as well as other fields within the memory allocation HOB. This GUID |
| 75 | * is used to define the additional data within the HOB that may be |
| 76 | * present for the memory allocation HOB. Type efi_guid_t is defined in |
| 77 | * InstallProtocolInterface() in the UEFI 2.0 specification. |
| 78 | */ |
| 79 | efi_guid_t name; |
| 80 | /* |
| 81 | * The base address of memory allocated by this HOB. |
| 82 | * Type phys_addr_t is defined in AllocatePages() in the UEFI 2.0 |
| 83 | * specification. |
| 84 | */ |
| 85 | phys_addr_t mem_base; |
| 86 | /* The length in bytes of memory allocated by this HOB */ |
| 87 | phys_size_t mem_len; |
| 88 | /* |
| 89 | * Defines the type of memory allocated by this HOB. |
| 90 | * The memory type definition follows the EFI_MEMORY_TYPE definition. |
| 91 | * Type EFI_MEMORY_TYPE is defined in AllocatePages() in the UEFI 2.0 |
| 92 | * specification. |
| 93 | */ |
| 94 | enum efi_mem_type mem_type; |
| 95 | /* padding */ |
| 96 | u8 reserved[4]; |
| 97 | }; |
| 98 | |
| 99 | /* |
| 100 | * Describes the resource properties of all fixed, nonrelocatable resource |
| 101 | * ranges found on the processor host bus during the HOB producer phase. |
| 102 | */ |
| 103 | struct hob_res_desc { |
| 104 | struct hob_header hdr; |
| 105 | /* |
| 106 | * A GUID representing the owner of the resource. This GUID is |
| 107 | * used by HOB consumer phase components to correlate device |
| 108 | * ownership of a resource. |
| 109 | */ |
| 110 | efi_guid_t owner; |
| 111 | u32 type; |
| 112 | u32 attr; |
| 113 | /* The physical start address of the resource region */ |
| 114 | phys_addr_t phys_start; |
| 115 | /* The number of bytes of the resource region */ |
| 116 | phys_size_t len; |
| 117 | }; |
| 118 | |
| 119 | /* |
| 120 | * Allows writers of executable content in the HOB producer phase to |
| 121 | * maintain and manage HOBs with specific GUID. |
| 122 | */ |
| 123 | struct hob_guid { |
| 124 | struct hob_header hdr; |
| 125 | /* A GUID that defines the contents of this HOB */ |
| 126 | efi_guid_t name; |
| 127 | /* GUID specific data goes here */ |
| 128 | }; |
| 129 | |
| 130 | /** |
| 131 | * get_next_hob() - return a pointer to the next HOB in the HOB list |
| 132 | * |
| 133 | * This macro returns a pointer to HOB that follows the HOB specified by hob |
| 134 | * in the HOB List. |
| 135 | * |
| 136 | * @hdr: A pointer to a HOB. |
| 137 | * |
Simon Glass | e464d6e | 2019-08-25 10:10:59 -0600 | [diff] [blame] | 138 | * @return A pointer to the next HOB in the HOB list. |
Park, Aiden | 538aec9 | 2019-08-03 08:30:31 +0000 | [diff] [blame] | 139 | */ |
| 140 | static inline const struct hob_header *get_next_hob(const struct hob_header |
| 141 | *hdr) |
| 142 | { |
| 143 | return (const struct hob_header *)((uintptr_t)hdr + hdr->len); |
| 144 | } |
| 145 | |
| 146 | /** |
| 147 | * end_of_hob() - determine if a HOB is the last HOB in the HOB list |
| 148 | * |
| 149 | * This macro determine if the HOB specified by hob is the last HOB in the |
| 150 | * HOB list. If hob is last HOB in the HOB list, then true is returned. |
| 151 | * Otherwise, false is returned. |
| 152 | * |
| 153 | * @hdr: A pointer to a HOB. |
| 154 | * |
Simon Glass | e464d6e | 2019-08-25 10:10:59 -0600 | [diff] [blame] | 155 | * @return true: The HOB specified by hdr is the last HOB in the HOB list. |
| 156 | * @return false: The HOB specified by hdr is not the last HOB in the HOB list. |
Park, Aiden | 538aec9 | 2019-08-03 08:30:31 +0000 | [diff] [blame] | 157 | */ |
| 158 | static inline bool end_of_hob(const struct hob_header *hdr) |
| 159 | { |
| 160 | return hdr->type == HOB_TYPE_EOH; |
| 161 | } |
| 162 | |
| 163 | /** |
| 164 | * get_guid_hob_data() - return a pointer to data buffer from a HOB of |
| 165 | * type HOB_TYPE_GUID_EXT |
| 166 | * |
| 167 | * This macro returns a pointer to the data buffer in a HOB specified by hob. |
| 168 | * hob is assumed to be a HOB of type HOB_TYPE_GUID_EXT. |
| 169 | * |
| 170 | * @hdr: A pointer to a HOB. |
| 171 | * |
Simon Glass | e464d6e | 2019-08-25 10:10:59 -0600 | [diff] [blame] | 172 | * @return A pointer to the data buffer in a HOB. |
Park, Aiden | 538aec9 | 2019-08-03 08:30:31 +0000 | [diff] [blame] | 173 | */ |
| 174 | static inline void *get_guid_hob_data(const struct hob_header *hdr) |
| 175 | { |
| 176 | return (void *)((uintptr_t)hdr + sizeof(struct hob_guid)); |
| 177 | } |
| 178 | |
| 179 | /** |
| 180 | * get_guid_hob_data_size() - return the size of the data buffer from a HOB |
| 181 | * of type HOB_TYPE_GUID_EXT |
| 182 | * |
| 183 | * This macro returns the size, in bytes, of the data buffer in a HOB |
| 184 | * specified by hob. hob is assumed to be a HOB of type HOB_TYPE_GUID_EXT. |
| 185 | * |
| 186 | * @hdr: A pointer to a HOB. |
| 187 | * |
Simon Glass | e464d6e | 2019-08-25 10:10:59 -0600 | [diff] [blame] | 188 | * @return The size of the data buffer. |
Park, Aiden | 538aec9 | 2019-08-03 08:30:31 +0000 | [diff] [blame] | 189 | */ |
| 190 | static inline u16 get_guid_hob_data_size(const struct hob_header *hdr) |
| 191 | { |
| 192 | return hdr->len - sizeof(struct hob_guid); |
| 193 | } |
| 194 | |
| 195 | /** |
| 196 | * Returns the next instance of a HOB type from the starting HOB. |
| 197 | * |
| 198 | * @type: HOB type to search |
| 199 | * @hob_list: A pointer to the HOB list |
| 200 | * |
Simon Glass | e464d6e | 2019-08-25 10:10:59 -0600 | [diff] [blame] | 201 | * @return A HOB object with matching type; Otherwise NULL. |
Park, Aiden | 538aec9 | 2019-08-03 08:30:31 +0000 | [diff] [blame] | 202 | */ |
| 203 | const struct hob_header *hob_get_next_hob(uint type, const void *hob_list); |
| 204 | |
| 205 | /** |
| 206 | * Returns the next instance of the matched GUID HOB from the starting HOB. |
| 207 | * |
| 208 | * @guid: GUID to search |
| 209 | * @hob_list: A pointer to the HOB list |
| 210 | * |
Simon Glass | e464d6e | 2019-08-25 10:10:59 -0600 | [diff] [blame] | 211 | * @return A HOB object with matching GUID; Otherwise NULL. |
Park, Aiden | 538aec9 | 2019-08-03 08:30:31 +0000 | [diff] [blame] | 212 | */ |
| 213 | const struct hob_header *hob_get_next_guid_hob(const efi_guid_t *guid, |
| 214 | const void *hob_list); |
| 215 | |
| 216 | /** |
| 217 | * This function retrieves a GUID HOB data buffer and size. |
| 218 | * |
| 219 | * @hob_list: A HOB list pointer. |
| 220 | * @len: A pointer to the GUID HOB data buffer length. |
| 221 | * If the GUID HOB is located, the length will be updated. |
| 222 | * @guid A pointer to HOB GUID. |
| 223 | * |
Simon Glass | e464d6e | 2019-08-25 10:10:59 -0600 | [diff] [blame] | 224 | * @return NULL: Failed to find the GUID HOB. |
| 225 | * @return others: GUID HOB data buffer pointer. |
Park, Aiden | 538aec9 | 2019-08-03 08:30:31 +0000 | [diff] [blame] | 226 | */ |
| 227 | void *hob_get_guid_hob_data(const void *hob_list, u32 *len, |
| 228 | const efi_guid_t *guid); |
| 229 | |
| 230 | #endif /* __HOB_H__ */ |