Simon Glass | 6c9e3d1 | 2022-01-12 19:26:25 -0700 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0+ BSD-3-Clause */ |
Simon Glass | 9f407d4 | 2018-11-15 18:43:50 -0700 | [diff] [blame] | 2 | /* |
| 3 | * This provides a standard way of passing information between boot phases |
| 4 | * (TPL -> SPL -> U-Boot proper.) |
| 5 | * |
Simon Glass | 68ff6d3 | 2022-03-13 16:22:48 -0600 | [diff] [blame] | 6 | * It consists of a list of blobs of data, tagged with their owner / contents. |
| 7 | * The list resides in memory and can be updated by SPL, U-Boot, etc. |
| 8 | * |
| 9 | * Design goals for bloblist: |
| 10 | * |
| 11 | * 1. Small and efficient structure. This avoids UUIDs or 16-byte name fields, |
| 12 | * since a 32-bit tag provides enough space for all the tags we will even need. |
| 13 | * If UUIDs are desired, they can be added inside a particular blob. |
| 14 | * |
| 15 | * 2. Avoids use of pointers, so the structure can be relocated in memory. The |
| 16 | * data in each blob is inline, rather than using pointers. |
| 17 | * |
| 18 | * 3. Bloblist is designed to start small in TPL or SPL, when only a few things |
| 19 | * are needed, like the memory size or whether console output should be enabled. |
| 20 | * Then it can grow in U-Boot proper, e.g. to include space for ACPI tables. |
| 21 | * |
| 22 | * 4. The bloblist structure is simple enough that it can be implemented in a |
| 23 | * small amount of C code. The API does not require use of strings or UUIDs, |
| 24 | * which would add to code size. For Thumb-2 the code size needed in SPL is |
| 25 | * approximately 940 bytes (e.g. for chromebook_bob). |
| 26 | * |
Simon Glass | b6e8382 | 2023-12-27 13:07:07 -0800 | [diff] [blame] | 27 | * 5. Bloblist uses 8-byte alignment internally and is designed to start on a |
| 28 | * 8-byte boundary. Its headers are 8 bytes long. It is possible to achieve |
| 29 | * larger alignment (e.g. 16 bytes) by adding a dummy header, For use in SPL and |
| 30 | * TPL the alignment can be relaxed, since it can be relocated to an aligned |
| 31 | * address in U-Boot proper. |
Simon Glass | 68ff6d3 | 2022-03-13 16:22:48 -0600 | [diff] [blame] | 32 | * |
| 33 | * 6. Bloblist is designed to be passed to Linux as reserved memory. While linux |
| 34 | * doesn't understand the bloblist header, it can be passed the indivdual blobs. |
| 35 | * For example, ACPI tables can reside in a blob and the address of those is |
| 36 | * passed to Linux, without Linux ever being away of the existence of a |
| 37 | * bloblist. Having all the blobs contiguous in memory simplifies the |
| 38 | * reserved-memory space. |
| 39 | * |
| 40 | * 7. Bloblist tags are defined in the enum below. There is an area for |
| 41 | * project-specific stuff (e.g. U-Boot, TF-A) and vendor-specific stuff, e.g. |
| 42 | * something used only on a particular SoC. There is also a private area for |
| 43 | * temporary, local use. |
| 44 | * |
| 45 | * 8. Bloblist includes a simple checksum, so that each boot phase can update |
| 46 | * this and allow the next phase to check that all is well. While the bloblist |
| 47 | * is small, this is quite cheap to calculate. When it grows (e.g. in U-Boot\ |
| 48 | * proper), the CPU is likely running faster, so it is not prohibitive. Having |
| 49 | * said that, U-Boot is often the last phase that uses bloblist, so calculating |
| 50 | * the checksum there may not be necessary. |
| 51 | * |
| 52 | * 9. It would be possible to extend bloblist to support a non-contiguous |
| 53 | * structure, e.g. by creating a blob type that points to the next bloblist. |
| 54 | * This does not seem necessary for now. It adds complexity and code. We can |
| 55 | * always just copy it. |
| 56 | * |
| 57 | * 10. Bloblist is designed for simple structures, those that can be defined by |
| 58 | * a single C struct. More complex structures should be passed in a device tree. |
| 59 | * There are some exceptions, chiefly the various binary structures that Intel |
| 60 | * is fond of creating. But device tree provides a dictionary-type format which |
| 61 | * is fairly efficient (for use in U-Boot proper and Linux at least), along with |
| 62 | * a schema and a good set of tools. New formats should be designed around |
| 63 | * device tree rather than creating new binary formats, unless they are needed |
| 64 | * early in boot (where libfdt's 3KB of overhead is too large) and are trival |
| 65 | * enough to be described by a C struct. |
Simon Glass | 9f407d4 | 2018-11-15 18:43:50 -0700 | [diff] [blame] | 66 | * |
| 67 | * Copyright 2018 Google, Inc |
| 68 | * Written by Simon Glass <sjg@chromium.org> |
Simon Glass | e266d27 | 2023-12-27 13:07:10 -0800 | [diff] [blame] | 69 | * Adjusted July 2023 to match Firmware handoff specification, Release 0.9 |
Simon Glass | 9f407d4 | 2018-11-15 18:43:50 -0700 | [diff] [blame] | 70 | */ |
| 71 | |
| 72 | #ifndef __BLOBLIST_H |
| 73 | #define __BLOBLIST_H |
| 74 | |
Simon Glass | ff3bd49 | 2022-01-12 19:26:16 -0700 | [diff] [blame] | 75 | #include <mapmem.h> |
| 76 | |
Simon Glass | 9f407d4 | 2018-11-15 18:43:50 -0700 | [diff] [blame] | 77 | enum { |
Simon Glass | 0b9f77f | 2023-12-27 13:07:02 -0800 | [diff] [blame] | 78 | BLOBLIST_VERSION = 1, |
Simon Glass | 5a53e56 | 2023-12-27 13:07:01 -0800 | [diff] [blame] | 79 | BLOBLIST_MAGIC = 0x4a0fb10b, |
Simon Glass | 1a2e02f | 2023-12-27 13:07:00 -0800 | [diff] [blame] | 80 | |
Levi Yun | 84ab75f | 2024-07-10 14:53:20 +0100 | [diff] [blame^] | 81 | BLOBLIST_REGCONV_SHIFT_64 = 32, |
| 82 | BLOBLIST_REGCONV_SHIFT_32 = 24, |
| 83 | BLOBLIST_REGCONV_MASK = 0xff, |
| 84 | BLOBLIST_REGCONV_VER = 1, |
Raymond Mao | 1c4751f | 2024-02-03 08:36:20 -0800 | [diff] [blame] | 85 | |
Simon Glass | b6e8382 | 2023-12-27 13:07:07 -0800 | [diff] [blame] | 86 | BLOBLIST_BLOB_ALIGN_LOG2 = 3, |
| 87 | BLOBLIST_BLOB_ALIGN = 1 << BLOBLIST_BLOB_ALIGN_LOG2, |
| 88 | |
Simon Glass | 1a2e02f | 2023-12-27 13:07:00 -0800 | [diff] [blame] | 89 | BLOBLIST_ALIGN_LOG2 = 3, |
| 90 | BLOBLIST_ALIGN = 1 << BLOBLIST_ALIGN_LOG2, |
Simon Glass | 9f407d4 | 2018-11-15 18:43:50 -0700 | [diff] [blame] | 91 | }; |
| 92 | |
Simon Glass | 4aed227 | 2020-09-19 18:49:26 -0600 | [diff] [blame] | 93 | /* Supported tags - add new ones to tag_name in bloblist.c */ |
Simon Glass | 9f407d4 | 2018-11-15 18:43:50 -0700 | [diff] [blame] | 94 | enum bloblist_tag_t { |
Simon Glass | e748e4b | 2023-12-27 13:06:59 -0800 | [diff] [blame] | 95 | BLOBLISTT_VOID = 0, |
Simon Glass | 9f407d4 | 2018-11-15 18:43:50 -0700 | [diff] [blame] | 96 | |
Simon Glass | f16ec77 | 2022-01-12 19:26:19 -0700 | [diff] [blame] | 97 | /* |
| 98 | * Standard area to allocate blobs used across firmware components, for |
| 99 | * things that are very commonly used, particularly in multiple |
| 100 | * projects. |
| 101 | */ |
| 102 | BLOBLISTT_AREA_FIRMWARE_TOP = 0x1, |
Simon Glass | e748e4b | 2023-12-27 13:06:59 -0800 | [diff] [blame] | 103 | /* |
| 104 | * Devicetree for use by firmware. On some platforms this is passed to |
| 105 | * the OS also |
| 106 | */ |
| 107 | BLOBLISTT_CONTROL_FDT = 1, |
| 108 | BLOBLISTT_HOB_BLOCK = 2, |
| 109 | BLOBLISTT_HOB_LIST = 3, |
| 110 | BLOBLISTT_ACPI_TABLES = 4, |
| 111 | BLOBLISTT_TPM_EVLOG = 5, |
| 112 | BLOBLISTT_TPM_CRB_BASE = 6, |
Simon Glass | f16ec77 | 2022-01-12 19:26:19 -0700 | [diff] [blame] | 113 | |
| 114 | /* Standard area to allocate blobs used across firmware components */ |
Simon Glass | e748e4b | 2023-12-27 13:06:59 -0800 | [diff] [blame] | 115 | BLOBLISTT_AREA_FIRMWARE = 0x10, |
| 116 | BLOBLISTT_TPM2_TCG_LOG = 0x10, /* TPM v2 log space */ |
| 117 | BLOBLISTT_TCPA_LOG = 0x11, /* TPM log space */ |
Simon Glass | 99e555a | 2020-09-22 12:44:55 -0600 | [diff] [blame] | 118 | /* |
| 119 | * Advanced Configuration and Power Interface Global Non-Volatile |
| 120 | * Sleeping table. This forms part of the ACPI tables passed to Linux. |
| 121 | */ |
Simon Glass | e748e4b | 2023-12-27 13:06:59 -0800 | [diff] [blame] | 122 | BLOBLISTT_ACPI_GNVS = 0x12, |
Simon Glass | 4aed227 | 2020-09-19 18:49:26 -0600 | [diff] [blame] | 123 | |
Simon Glass | e748e4b | 2023-12-27 13:06:59 -0800 | [diff] [blame] | 124 | /* Standard area to allocate blobs used for Trusted Firmware */ |
| 125 | BLOBLISTT_AREA_TF = 0x100, |
| 126 | BLOBLISTT_OPTEE_PAGABLE_PART = 0x100, |
Simon Glass | f16ec77 | 2022-01-12 19:26:19 -0700 | [diff] [blame] | 127 | |
Simon Glass | e748e4b | 2023-12-27 13:06:59 -0800 | [diff] [blame] | 128 | /* Other standard area to allocate blobs */ |
| 129 | BLOBLISTT_AREA_OTHER = 0x200, |
| 130 | BLOBLISTT_INTEL_VBT = 0x200, /* Intel Video-BIOS table */ |
| 131 | BLOBLISTT_SMBIOS_TABLES = 0x201, /* SMBIOS tables for x86 */ |
| 132 | BLOBLISTT_VBOOT_CTX = 0x202, /* Chromium OS verified boot context */ |
Simon Glass | f16ec77 | 2022-01-12 19:26:19 -0700 | [diff] [blame] | 133 | |
| 134 | /* |
| 135 | * Tags from here are on reserved for private use within a single |
| 136 | * firmware binary (i.e. a single executable or phase of a project). |
| 137 | * These tags can be passed between binaries within a local |
| 138 | * implementation, but cannot be used in upstream code. Allocate a |
| 139 | * tag in one of the areas above if you want that. |
| 140 | * |
Simon Glass | e748e4b | 2023-12-27 13:06:59 -0800 | [diff] [blame] | 141 | * Project-specific tags are permitted here. Projects can be open source |
| 142 | * or not, but the format of the data must be fuily documented in an |
| 143 | * open source project, including all fields, bits, etc. Naming should |
| 144 | * be: BLOBLISTT_<project>_<purpose_here> |
| 145 | * |
| 146 | * Vendor-specific tags are also permitted. Projects can be open source |
| 147 | * or not, but the format of the data must be fuily documented in an |
| 148 | * open source project, including all fields, bits, etc. Naming should |
| 149 | * be BLOBLISTT_<vendor>_<purpose_here> |
Simon Glass | f16ec77 | 2022-01-12 19:26:19 -0700 | [diff] [blame] | 150 | */ |
Simon Glass | e748e4b | 2023-12-27 13:06:59 -0800 | [diff] [blame] | 151 | BLOBLISTT_PRIVATE_AREA = 0xfff000, |
| 152 | BLOBLISTT_U_BOOT_SPL_HANDOFF = 0xfff000, /* Hand-off info from SPL */ |
| 153 | BLOBLISTT_VBE = 0xfff001, /* VBE per-phase state */ |
| 154 | BLOBLISTT_U_BOOT_VIDEO = 0xfff002, /* Video info from SPL */ |
Simon Glass | 9f407d4 | 2018-11-15 18:43:50 -0700 | [diff] [blame] | 155 | }; |
| 156 | |
| 157 | /** |
| 158 | * struct bloblist_hdr - header for the bloblist |
| 159 | * |
| 160 | * This is stored at the start of the bloblist which is always on a 16-byte |
| 161 | * boundary. Records follow this header. The bloblist normally stays in the |
| 162 | * same place in memory as SPL and U-Boot execute, but it can be safely moved |
| 163 | * around. |
| 164 | * |
Simon Glass | 20a1493 | 2022-01-12 19:26:24 -0700 | [diff] [blame] | 165 | * None of the bloblist headers themselves contain pointers but it is possible |
| 166 | * to put pointers inside a bloblist record if desired. This is not encouraged, |
Simon Glass | 9f407d4 | 2018-11-15 18:43:50 -0700 | [diff] [blame] | 167 | * since it can make part of the bloblist inaccessible if the pointer is |
| 168 | * no-longer valid. It is better to just store all the data inside a bloblist |
| 169 | * record. |
| 170 | * |
| 171 | * Each bloblist record is aligned to a 16-byte boundary and follows immediately |
| 172 | * from the last. |
| 173 | * |
Simon Glass | ff3bd49 | 2022-01-12 19:26:16 -0700 | [diff] [blame] | 174 | * @magic: BLOBLIST_MAGIC |
Simon Glass | b86b2d9 | 2023-12-27 13:07:08 -0800 | [diff] [blame] | 175 | * @chksum: checksum for the entire bloblist allocated area. Since any of the |
| 176 | * blobs can be altered after being created, this checksum is only valid |
| 177 | * when the bloblist is finalized before jumping to the next stage of boot. |
| 178 | * This is the value needed to make all checksummed bytes sum to 0 |
Simon Glass | 9f407d4 | 2018-11-15 18:43:50 -0700 | [diff] [blame] | 179 | * @version: BLOBLIST_VERSION |
| 180 | * @hdr_size: Size of this header, normally sizeof(struct bloblist_hdr). The |
| 181 | * first bloblist_rec starts at this offset from the start of the header |
Simon Glass | b86b2d9 | 2023-12-27 13:07:08 -0800 | [diff] [blame] | 182 | * @align_log2: Power of two of the maximum alignment required by this list |
| 183 | * @used_size: Size allocated so far for this bloblist. This starts out as |
Simon Glass | 9f407d4 | 2018-11-15 18:43:50 -0700 | [diff] [blame] | 184 | * sizeof(bloblist_hdr) since we need at least that much space to store a |
| 185 | * valid bloblist |
Simon Glass | b86b2d9 | 2023-12-27 13:07:08 -0800 | [diff] [blame] | 186 | * @total_size: The number of total bytes that the bloblist can occupy. |
| 187 | * Any blob producer must check if there is sufficient space before adding |
| 188 | * a record to the bloblist. |
| 189 | * @flags: Space for BLOBLISTF... flags (none yet) |
Simon Glass | e9b6b2c | 2020-09-19 18:49:30 -0600 | [diff] [blame] | 190 | * @spare: Spare space (for future use) |
Simon Glass | 9f407d4 | 2018-11-15 18:43:50 -0700 | [diff] [blame] | 191 | */ |
| 192 | struct bloblist_hdr { |
Simon Glass | ff3bd49 | 2022-01-12 19:26:16 -0700 | [diff] [blame] | 193 | u32 magic; |
Simon Glass | b86b2d9 | 2023-12-27 13:07:08 -0800 | [diff] [blame] | 194 | u8 chksum; |
| 195 | u8 version; |
| 196 | u8 hdr_size; |
| 197 | u8 align_log2; |
| 198 | u32 used_size; |
| 199 | u32 total_size; |
Simon Glass | 9f407d4 | 2018-11-15 18:43:50 -0700 | [diff] [blame] | 200 | u32 flags; |
Simon Glass | 9f407d4 | 2018-11-15 18:43:50 -0700 | [diff] [blame] | 201 | u32 spare; |
Simon Glass | 9f407d4 | 2018-11-15 18:43:50 -0700 | [diff] [blame] | 202 | }; |
| 203 | |
| 204 | /** |
| 205 | * struct bloblist_rec - record for the bloblist |
| 206 | * |
Simon Glass | 9f407d4 | 2018-11-15 18:43:50 -0700 | [diff] [blame] | 207 | * The bloblist contains a number of records each consisting of this record |
| 208 | * structure followed by the data contained. Each records is 16-byte aligned. |
| 209 | * |
Simon Glass | 20a1493 | 2022-01-12 19:26:24 -0700 | [diff] [blame] | 210 | * NOTE: Only exported for testing purposes. Do not use this struct. |
| 211 | * |
Simon Glass | b6e8382 | 2023-12-27 13:07:07 -0800 | [diff] [blame] | 212 | * @tag_and_hdr_size: Tag indicating what the record contains (bottom 24 bits), and |
| 213 | * size of this header (top 8 bits), normally sizeof(struct bloblist_rec). |
| 214 | * The record's data starts at this offset from the start of the record |
Simon Glass | 9f407d4 | 2018-11-15 18:43:50 -0700 | [diff] [blame] | 215 | * @size: Size of record in bytes, excluding the header size. This does not |
| 216 | * need to be aligned (e.g. 3 is OK). |
Simon Glass | 9f407d4 | 2018-11-15 18:43:50 -0700 | [diff] [blame] | 217 | */ |
| 218 | struct bloblist_rec { |
Simon Glass | b6e8382 | 2023-12-27 13:07:07 -0800 | [diff] [blame] | 219 | u32 tag_and_hdr_size; |
Simon Glass | 9f407d4 | 2018-11-15 18:43:50 -0700 | [diff] [blame] | 220 | u32 size; |
Simon Glass | b6e8382 | 2023-12-27 13:07:07 -0800 | [diff] [blame] | 221 | }; |
| 222 | |
| 223 | enum { |
| 224 | BLOBLISTR_TAG_SHIFT = 0, |
| 225 | BLOBLISTR_TAG_MASK = 0xffffffU << BLOBLISTR_TAG_SHIFT, |
| 226 | BLOBLISTR_HDR_SIZE_SHIFT = 24, |
| 227 | BLOBLISTR_HDR_SIZE_MASK = 0xffU << BLOBLISTR_HDR_SIZE_SHIFT, |
| 228 | |
| 229 | BLOBLIST_HDR_SIZE = sizeof(struct bloblist_hdr), |
| 230 | BLOBLIST_REC_HDR_SIZE = sizeof(struct bloblist_rec), |
Simon Glass | 9f407d4 | 2018-11-15 18:43:50 -0700 | [diff] [blame] | 231 | }; |
| 232 | |
| 233 | /** |
Simon Glass | ff3bd49 | 2022-01-12 19:26:16 -0700 | [diff] [blame] | 234 | * bloblist_check_magic() - return a bloblist if the magic matches |
| 235 | * |
| 236 | * @addr: Address to check |
Simon Glass | 20a1493 | 2022-01-12 19:26:24 -0700 | [diff] [blame] | 237 | * Return: pointer to bloblist, if the magic matches, else NULL |
Simon Glass | ff3bd49 | 2022-01-12 19:26:16 -0700 | [diff] [blame] | 238 | */ |
| 239 | static inline void *bloblist_check_magic(ulong addr) |
| 240 | { |
| 241 | u32 *ptr; |
| 242 | |
| 243 | if (!addr) |
| 244 | return NULL; |
| 245 | ptr = map_sysmem(addr, 0); |
| 246 | if (*ptr != BLOBLIST_MAGIC) |
| 247 | return NULL; |
| 248 | |
| 249 | return ptr; |
| 250 | } |
| 251 | |
| 252 | /** |
Simon Glass | 9f407d4 | 2018-11-15 18:43:50 -0700 | [diff] [blame] | 253 | * bloblist_find() - Find a blob |
| 254 | * |
| 255 | * Searches the bloblist and returns the blob with the matching tag |
| 256 | * |
| 257 | * @tag: Tag to search for (enum bloblist_tag_t) |
Simon Glass | e9b6b2c | 2020-09-19 18:49:30 -0600 | [diff] [blame] | 258 | * @size: Expected size of the blob, or 0 for any size |
Simon Glass | 20a1493 | 2022-01-12 19:26:24 -0700 | [diff] [blame] | 259 | * Return: pointer to blob if found, or NULL if not found, or a blob was found |
| 260 | * but it is the wrong size |
Simon Glass | 9f407d4 | 2018-11-15 18:43:50 -0700 | [diff] [blame] | 261 | */ |
| 262 | void *bloblist_find(uint tag, int size); |
| 263 | |
| 264 | /** |
| 265 | * bloblist_add() - Add a new blob |
| 266 | * |
| 267 | * Add a new blob to the bloblist |
| 268 | * |
| 269 | * This should only be called if you konw there is no existing blob for a |
| 270 | * particular tag. It is typically safe to call in the first phase of U-Boot |
| 271 | * (e.g. TPL or SPL). After that, bloblist_ensure() should be used instead. |
| 272 | * |
| 273 | * @tag: Tag to add (enum bloblist_tag_t) |
| 274 | * @size: Size of the blob |
Simon Glass | 1a2e02f | 2023-12-27 13:07:00 -0800 | [diff] [blame] | 275 | * @align_log2: Alignment of the blob (in bytes log2), 0 for default |
Simon Glass | 20a1493 | 2022-01-12 19:26:24 -0700 | [diff] [blame] | 276 | * Return: pointer to the newly added block, or NULL if there is not enough |
| 277 | * space for the blob |
Simon Glass | 9f407d4 | 2018-11-15 18:43:50 -0700 | [diff] [blame] | 278 | */ |
Simon Glass | 1a2e02f | 2023-12-27 13:07:00 -0800 | [diff] [blame] | 279 | void *bloblist_add(uint tag, int size, int align_log2); |
Simon Glass | 9f407d4 | 2018-11-15 18:43:50 -0700 | [diff] [blame] | 280 | |
| 281 | /** |
| 282 | * bloblist_ensure_size() - Find or add a blob |
| 283 | * |
| 284 | * Find an existing blob, or add a new one if not found |
| 285 | * |
| 286 | * @tag: Tag to add (enum bloblist_tag_t) |
| 287 | * @size: Size of the blob |
| 288 | * @blobp: Returns a pointer to blob on success |
Simon Glass | 1a2e02f | 2023-12-27 13:07:00 -0800 | [diff] [blame] | 289 | * @align_log2: Alignment of the blob (in bytes log2), 0 for default |
Simon Glass | 20a1493 | 2022-01-12 19:26:24 -0700 | [diff] [blame] | 290 | * Return: 0 if OK, -ENOSPC if it is missing and could not be added due to lack |
| 291 | * of space, or -ESPIPE it exists but has the wrong size |
Simon Glass | 9f407d4 | 2018-11-15 18:43:50 -0700 | [diff] [blame] | 292 | */ |
Simon Glass | 1a2e02f | 2023-12-27 13:07:00 -0800 | [diff] [blame] | 293 | int bloblist_ensure_size(uint tag, int size, int align_log2, void **blobp); |
Simon Glass | 9f407d4 | 2018-11-15 18:43:50 -0700 | [diff] [blame] | 294 | |
| 295 | /** |
| 296 | * bloblist_ensure() - Find or add a blob |
| 297 | * |
| 298 | * Find an existing blob, or add a new one if not found |
| 299 | * |
| 300 | * @tag: Tag to add (enum bloblist_tag_t) |
| 301 | * @size: Size of the blob |
Simon Glass | 20a1493 | 2022-01-12 19:26:24 -0700 | [diff] [blame] | 302 | * Return: pointer to blob, or NULL if it is missing and could not be added due |
| 303 | * to lack of space, or it exists but has the wrong size |
Simon Glass | 9f407d4 | 2018-11-15 18:43:50 -0700 | [diff] [blame] | 304 | */ |
| 305 | void *bloblist_ensure(uint tag, int size); |
| 306 | |
| 307 | /** |
Simon Glass | 5b04454 | 2020-01-27 08:49:50 -0700 | [diff] [blame] | 308 | * bloblist_ensure_size_ret() - Find or add a blob |
| 309 | * |
| 310 | * Find an existing blob, or add a new one if not found |
| 311 | * |
| 312 | * @tag: Tag to add (enum bloblist_tag_t) |
| 313 | * @sizep: Size of the blob to create; returns size of actual blob |
| 314 | * @blobp: Returns a pointer to blob on success |
Simon Glass | 20a1493 | 2022-01-12 19:26:24 -0700 | [diff] [blame] | 315 | * Return: 0 if OK, -ENOSPC if it is missing and could not be added due to lack |
| 316 | * of space |
Simon Glass | 5b04454 | 2020-01-27 08:49:50 -0700 | [diff] [blame] | 317 | */ |
| 318 | int bloblist_ensure_size_ret(uint tag, int *sizep, void **blobp); |
| 319 | |
| 320 | /** |
Simon Glass | 1fe5937 | 2021-07-05 16:32:53 -0600 | [diff] [blame] | 321 | * bloblist_resize() - resize a blob |
| 322 | * |
| 323 | * Any blobs above this one are relocated up or down. The resized blob remains |
| 324 | * in the same place. |
| 325 | * |
| 326 | * @tag: Tag to add (enum bloblist_tag_t) |
| 327 | * @new_size: New size of the blob (>0 to expand, <0 to contract) |
Simon Glass | 20a1493 | 2022-01-12 19:26:24 -0700 | [diff] [blame] | 328 | * Return: 0 if OK, -ENOSPC if the bloblist does not have enough space, -ENOENT |
| 329 | * if the tag is not found |
Simon Glass | 1fe5937 | 2021-07-05 16:32:53 -0600 | [diff] [blame] | 330 | */ |
| 331 | int bloblist_resize(uint tag, int new_size); |
| 332 | |
| 333 | /** |
Simon Glass | 9f407d4 | 2018-11-15 18:43:50 -0700 | [diff] [blame] | 334 | * bloblist_new() - Create a new, empty bloblist of a given size |
| 335 | * |
| 336 | * @addr: Address of bloblist |
| 337 | * @size: Initial size for bloblist |
| 338 | * @flags: Flags to use for bloblist |
Simon Glass | 7d790a8 | 2023-12-27 13:07:09 -0800 | [diff] [blame] | 339 | * @align_log2: Log base 2 of maximum alignment provided by this bloblist |
Simon Glass | 20a1493 | 2022-01-12 19:26:24 -0700 | [diff] [blame] | 340 | * Return: 0 if OK, -EFAULT if addr is not aligned correctly, -ENOSPC is the |
| 341 | * area is not large enough |
Simon Glass | 9f407d4 | 2018-11-15 18:43:50 -0700 | [diff] [blame] | 342 | */ |
Simon Glass | 7d790a8 | 2023-12-27 13:07:09 -0800 | [diff] [blame] | 343 | int bloblist_new(ulong addr, uint size, uint flags, uint align_log2); |
Simon Glass | 9f407d4 | 2018-11-15 18:43:50 -0700 | [diff] [blame] | 344 | |
| 345 | /** |
| 346 | * bloblist_check() - Check if a bloblist exists |
| 347 | * |
| 348 | * @addr: Address of bloblist |
Raymond Mao | 6725421 | 2024-02-03 08:36:21 -0800 | [diff] [blame] | 349 | * @size: Reserved space size for blobsize, or 0 to use the total size |
Simon Glass | 20a1493 | 2022-01-12 19:26:24 -0700 | [diff] [blame] | 350 | * Return: 0 if OK, -ENOENT if the magic number doesn't match (indicating that |
Raymond Mao | 6725421 | 2024-02-03 08:36:21 -0800 | [diff] [blame] | 351 | * there problem is no bloblist at the given address) or any fields for header |
| 352 | * size, used size and total size do not match, -EPROTONOSUPPORT |
Simon Glass | 20a1493 | 2022-01-12 19:26:24 -0700 | [diff] [blame] | 353 | * if the version does not match, -EIO if the checksum does not match, |
Raymond Mao | 6725421 | 2024-02-03 08:36:21 -0800 | [diff] [blame] | 354 | * -EFBIG if the reserved space size is small than the total size or total size |
| 355 | * is 0 |
Simon Glass | 9f407d4 | 2018-11-15 18:43:50 -0700 | [diff] [blame] | 356 | */ |
| 357 | int bloblist_check(ulong addr, uint size); |
| 358 | |
| 359 | /** |
| 360 | * bloblist_finish() - Set up the bloblist for the next U-Boot part |
| 361 | * |
| 362 | * This sets the correct checksum for the bloblist. This ensures that the |
| 363 | * bloblist will be detected correctly by the next phase of U-Boot. |
| 364 | * |
Simon Glass | 20a1493 | 2022-01-12 19:26:24 -0700 | [diff] [blame] | 365 | * Return: 0 |
Simon Glass | 9f407d4 | 2018-11-15 18:43:50 -0700 | [diff] [blame] | 366 | */ |
| 367 | int bloblist_finish(void); |
| 368 | |
| 369 | /** |
Simon Glass | 4aed227 | 2020-09-19 18:49:26 -0600 | [diff] [blame] | 370 | * bloblist_get_stats() - Get information about the bloblist |
| 371 | * |
| 372 | * This returns useful information about the bloblist |
Simon Glass | faff554 | 2021-07-05 16:32:54 -0600 | [diff] [blame] | 373 | * |
| 374 | * @basep: Returns base address of bloblist |
Simon Glass | b86b2d9 | 2023-12-27 13:07:08 -0800 | [diff] [blame] | 375 | * @tsizep: Returns the total number of bytes of the bloblist |
| 376 | * @usizep: Returns the number of used bytes of the bloblist |
Simon Glass | 4aed227 | 2020-09-19 18:49:26 -0600 | [diff] [blame] | 377 | */ |
Simon Glass | b86b2d9 | 2023-12-27 13:07:08 -0800 | [diff] [blame] | 378 | void bloblist_get_stats(ulong *basep, ulong *tsizep, ulong *usizep); |
Simon Glass | 4aed227 | 2020-09-19 18:49:26 -0600 | [diff] [blame] | 379 | |
| 380 | /** |
Simon Glass | e50a24a | 2022-01-12 19:26:23 -0700 | [diff] [blame] | 381 | * bloblist_get_base() - Get the base address of the bloblist |
| 382 | * |
Simon Glass | 20a1493 | 2022-01-12 19:26:24 -0700 | [diff] [blame] | 383 | * Return: base address of bloblist |
Simon Glass | e50a24a | 2022-01-12 19:26:23 -0700 | [diff] [blame] | 384 | */ |
| 385 | ulong bloblist_get_base(void); |
| 386 | |
| 387 | /** |
| 388 | * bloblist_get_size() - Get the size of the bloblist |
| 389 | * |
Simon Glass | 20a1493 | 2022-01-12 19:26:24 -0700 | [diff] [blame] | 390 | * Return: the size in bytes |
Simon Glass | e50a24a | 2022-01-12 19:26:23 -0700 | [diff] [blame] | 391 | */ |
| 392 | ulong bloblist_get_size(void); |
| 393 | |
| 394 | /** |
Simon Glass | b86b2d9 | 2023-12-27 13:07:08 -0800 | [diff] [blame] | 395 | * bloblist_get_total_size() - Get the total size of the bloblist |
| 396 | * |
| 397 | * Return: the size in bytes |
| 398 | */ |
| 399 | ulong bloblist_get_total_size(void); |
| 400 | |
| 401 | /** |
Simon Glass | 4aed227 | 2020-09-19 18:49:26 -0600 | [diff] [blame] | 402 | * bloblist_show_stats() - Show information about the bloblist |
| 403 | * |
| 404 | * This shows useful information about the bloblist on the console |
| 405 | */ |
| 406 | void bloblist_show_stats(void); |
| 407 | |
| 408 | /** |
| 409 | * bloblist_show_list() - Show a list of blobs in the bloblist |
| 410 | * |
| 411 | * This shows a list of blobs, showing their address, size and tag. |
| 412 | */ |
| 413 | void bloblist_show_list(void); |
| 414 | |
| 415 | /** |
| 416 | * bloblist_tag_name() - Get the name for a tag |
| 417 | * |
| 418 | * @tag: Tag to check |
Simon Glass | 20a1493 | 2022-01-12 19:26:24 -0700 | [diff] [blame] | 419 | * Return: name of tag, or "invalid" if an invalid tag is provided |
Simon Glass | 4aed227 | 2020-09-19 18:49:26 -0600 | [diff] [blame] | 420 | */ |
| 421 | const char *bloblist_tag_name(enum bloblist_tag_t tag); |
| 422 | |
| 423 | /** |
Simon Glass | 9fe0646 | 2021-01-13 20:29:43 -0700 | [diff] [blame] | 424 | * bloblist_reloc() - Relocate the bloblist and optionally resize it |
| 425 | * |
| 426 | * @to: Pointer to new bloblist location (must not overlap old location) |
Raymond Mao | 1ef43f3 | 2024-02-03 08:36:22 -0800 | [diff] [blame] | 427 | * @to_size: New size for bloblist |
| 428 | * Return: 0 if OK, -ENOSPC if the new size is small than the bloblist total |
| 429 | * size. |
Simon Glass | 9fe0646 | 2021-01-13 20:29:43 -0700 | [diff] [blame] | 430 | */ |
Raymond Mao | 1ef43f3 | 2024-02-03 08:36:22 -0800 | [diff] [blame] | 431 | int bloblist_reloc(void *to, uint to_size); |
Simon Glass | 9fe0646 | 2021-01-13 20:29:43 -0700 | [diff] [blame] | 432 | |
| 433 | /** |
Simon Glass | 9f407d4 | 2018-11-15 18:43:50 -0700 | [diff] [blame] | 434 | * bloblist_init() - Init the bloblist system with a single bloblist |
| 435 | * |
Simon Glass | 20a1493 | 2022-01-12 19:26:24 -0700 | [diff] [blame] | 436 | * This locates and sets up the blocklist for use. |
| 437 | * |
| 438 | * If CONFIG_BLOBLIST_FIXED is selected, it uses CONFIG_BLOBLIST_ADDR and |
| 439 | * CONFIG_BLOBLIST_SIZE to set up a bloblist for use by U-Boot. |
| 440 | * |
| 441 | * If CONFIG_BLOBLIST_ALLOC is selected, it allocates memory for a bloblist of |
| 442 | * size CONFIG_BLOBLIST_SIZE. |
| 443 | * |
| 444 | * If CONFIG_BLOBLIST_PASSAGE is selected, it uses the bloblist in the incoming |
| 445 | * standard passage. The size is detected automatically so CONFIG_BLOBLIST_SIZE |
| 446 | * can be 0. |
| 447 | * |
Simon Glass | 3d65318 | 2023-09-26 08:14:51 -0600 | [diff] [blame] | 448 | * Sets GD_FLG_BLOBLIST_READY in global_data flags on success |
| 449 | * |
Simon Glass | 20a1493 | 2022-01-12 19:26:24 -0700 | [diff] [blame] | 450 | * Return: 0 if OK, -ve on error |
Simon Glass | 9f407d4 | 2018-11-15 18:43:50 -0700 | [diff] [blame] | 451 | */ |
| 452 | int bloblist_init(void); |
| 453 | |
Simon Glass | 3d65318 | 2023-09-26 08:14:51 -0600 | [diff] [blame] | 454 | #if CONFIG_IS_ENABLED(BLOBLIST) |
| 455 | /** |
| 456 | * bloblist_maybe_init() - Init the bloblist system if not already done |
| 457 | * |
| 458 | * Calls bloblist_init() if the GD_FLG_BLOBLIST_READY flag is not et |
| 459 | * |
| 460 | * Return: 0 if OK, -ve on error |
| 461 | */ |
| 462 | int bloblist_maybe_init(void); |
| 463 | #else |
| 464 | static inline int bloblist_maybe_init(void) |
| 465 | { |
| 466 | return 0; |
| 467 | } |
| 468 | #endif /* BLOBLIST */ |
| 469 | |
Raymond Mao | 1c4751f | 2024-02-03 08:36:20 -0800 | [diff] [blame] | 470 | /** |
| 471 | * bloblist_check_reg_conv() - Check whether the bloblist is compliant to |
| 472 | * the register conventions according to the |
| 473 | * Firmware Handoff spec. |
| 474 | * |
| 475 | * @rfdt: Register that holds the FDT base address. |
| 476 | * @rzero: Register that must be zero. |
| 477 | * @rsig: Register that holds signature and register conventions version. |
| 478 | * Return: 0 if OK, -EIO if the bloblist is not compliant to the register |
| 479 | * conventions. |
| 480 | */ |
| 481 | int bloblist_check_reg_conv(ulong rfdt, ulong rzero, ulong rsig); |
| 482 | |
Raymond Mao | 6613131 | 2024-02-03 08:36:26 -0800 | [diff] [blame] | 483 | /** |
| 484 | * xferlist_from_boot_arg() - Get bloblist from the boot args and relocate it |
| 485 | * to the specified address. |
| 486 | * |
| 487 | * @addr: Address for the bloblist |
| 488 | * @size: Size of space reserved for the bloblist |
| 489 | * Return: 0 if OK, else on error |
| 490 | */ |
| 491 | int xferlist_from_boot_arg(ulong addr, ulong size); |
| 492 | |
Simon Glass | 9f407d4 | 2018-11-15 18:43:50 -0700 | [diff] [blame] | 493 | #endif /* __BLOBLIST_H */ |