blob: f32faf785604d0c2083595a83006ffc87d48c16d [file] [log] [blame]
Simon Glassbbd7bda2022-01-12 19:26:25 -07001/* SPDX-License-Identifier: GPL-2.0+ BSD-3-Clause */
Simon Glass712bd2d2018-11-15 18:43:50 -07002/*
3 * This provides a standard way of passing information between boot phases
4 * (TPL -> SPL -> U-Boot proper.)
5 *
Simon Glass30de28b2022-03-13 16:22:48 -06006 * 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 Glass703a5da2023-12-27 13:07:07 -080027 * 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 Glass30de28b2022-03-13 16:22:48 -060032 *
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 Glass712bd2d2018-11-15 18:43:50 -070066 *
67 * Copyright 2018 Google, Inc
68 * Written by Simon Glass <sjg@chromium.org>
Simon Glassc11758d2023-12-27 13:07:10 -080069 * Adjusted July 2023 to match Firmware handoff specification, Release 0.9
Simon Glass712bd2d2018-11-15 18:43:50 -070070 */
71
72#ifndef __BLOBLIST_H
73#define __BLOBLIST_H
74
Simon Glass9341a3f2022-01-12 19:26:16 -070075#include <mapmem.h>
76
Simon Glass712bd2d2018-11-15 18:43:50 -070077enum {
Simon Glassf182aa52023-12-27 13:07:02 -080078 BLOBLIST_VERSION = 1,
Simon Glass030a1f22023-12-27 13:07:01 -080079 BLOBLIST_MAGIC = 0x4a0fb10b,
Simon Glassc2aa4ef2023-12-27 13:07:00 -080080
Levi Yun5bfbd072024-07-10 14:53:20 +010081 BLOBLIST_REGCONV_SHIFT_64 = 32,
82 BLOBLIST_REGCONV_SHIFT_32 = 24,
83 BLOBLIST_REGCONV_MASK = 0xff,
84 BLOBLIST_REGCONV_VER = 1,
Raymond Maofe016b62024-02-03 08:36:20 -080085
Simon Glass703a5da2023-12-27 13:07:07 -080086 BLOBLIST_BLOB_ALIGN_LOG2 = 3,
87 BLOBLIST_BLOB_ALIGN = 1 << BLOBLIST_BLOB_ALIGN_LOG2,
88
Simon Glassc2aa4ef2023-12-27 13:07:00 -080089 BLOBLIST_ALIGN_LOG2 = 3,
90 BLOBLIST_ALIGN = 1 << BLOBLIST_ALIGN_LOG2,
Simon Glass712bd2d2018-11-15 18:43:50 -070091};
92
Simon Glassb936a972020-09-19 18:49:26 -060093/* Supported tags - add new ones to tag_name in bloblist.c */
Simon Glass712bd2d2018-11-15 18:43:50 -070094enum bloblist_tag_t {
Simon Glass871e5d02023-12-27 13:06:59 -080095 BLOBLISTT_VOID = 0,
Simon Glass712bd2d2018-11-15 18:43:50 -070096
Simon Glassfd20df42022-01-12 19:26:19 -070097 /*
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 Glass871e5d02023-12-27 13:06:59 -0800103 /*
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,
Patrick Rudolph2f6f8d92024-10-23 15:20:13 +0200113 BLOBLISTT_ACPI_PP = 7,
Simon Glassfd20df42022-01-12 19:26:19 -0700114
115 /* Standard area to allocate blobs used across firmware components */
Simon Glass871e5d02023-12-27 13:06:59 -0800116 BLOBLISTT_AREA_FIRMWARE = 0x10,
117 BLOBLISTT_TPM2_TCG_LOG = 0x10, /* TPM v2 log space */
118 BLOBLISTT_TCPA_LOG = 0x11, /* TPM log space */
Simon Glassfdf52632020-09-22 12:44:55 -0600119 /*
120 * Advanced Configuration and Power Interface Global Non-Volatile
121 * Sleeping table. This forms part of the ACPI tables passed to Linux.
122 */
Simon Glass871e5d02023-12-27 13:06:59 -0800123 BLOBLISTT_ACPI_GNVS = 0x12,
Simon Glassfd20df42022-01-12 19:26:19 -0700124
Simon Glass871e5d02023-12-27 13:06:59 -0800125 /* Standard area to allocate blobs used for Trusted Firmware */
126 BLOBLISTT_AREA_TF = 0x100,
127 BLOBLISTT_OPTEE_PAGABLE_PART = 0x100,
Simon Glassfd20df42022-01-12 19:26:19 -0700128
Simon Glass871e5d02023-12-27 13:06:59 -0800129 /* Other standard area to allocate blobs */
130 BLOBLISTT_AREA_OTHER = 0x200,
131 BLOBLISTT_INTEL_VBT = 0x200, /* Intel Video-BIOS table */
132 BLOBLISTT_SMBIOS_TABLES = 0x201, /* SMBIOS tables for x86 */
133 BLOBLISTT_VBOOT_CTX = 0x202, /* Chromium OS verified boot context */
Simon Glassfd20df42022-01-12 19:26:19 -0700134
135 /*
136 * Tags from here are on reserved for private use within a single
137 * firmware binary (i.e. a single executable or phase of a project).
138 * These tags can be passed between binaries within a local
139 * implementation, but cannot be used in upstream code. Allocate a
140 * tag in one of the areas above if you want that.
141 *
Simon Glass871e5d02023-12-27 13:06:59 -0800142 * Project-specific tags are permitted here. Projects can be open source
143 * or not, but the format of the data must be fuily documented in an
144 * open source project, including all fields, bits, etc. Naming should
145 * be: BLOBLISTT_<project>_<purpose_here>
146 *
147 * Vendor-specific tags are also permitted. Projects can be open source
148 * or not, but the format of the data must be fuily documented in an
149 * open source project, including all fields, bits, etc. Naming should
150 * be BLOBLISTT_<vendor>_<purpose_here>
Simon Glassfd20df42022-01-12 19:26:19 -0700151 */
Simon Glass871e5d02023-12-27 13:06:59 -0800152 BLOBLISTT_PRIVATE_AREA = 0xfff000,
153 BLOBLISTT_U_BOOT_SPL_HANDOFF = 0xfff000, /* Hand-off info from SPL */
154 BLOBLISTT_VBE = 0xfff001, /* VBE per-phase state */
155 BLOBLISTT_U_BOOT_VIDEO = 0xfff002, /* Video info from SPL */
Simon Glass712bd2d2018-11-15 18:43:50 -0700156};
157
158/**
159 * struct bloblist_hdr - header for the bloblist
160 *
161 * This is stored at the start of the bloblist which is always on a 16-byte
162 * boundary. Records follow this header. The bloblist normally stays in the
163 * same place in memory as SPL and U-Boot execute, but it can be safely moved
164 * around.
165 *
Simon Glass49ae4ad2022-01-12 19:26:24 -0700166 * None of the bloblist headers themselves contain pointers but it is possible
167 * to put pointers inside a bloblist record if desired. This is not encouraged,
Simon Glass712bd2d2018-11-15 18:43:50 -0700168 * since it can make part of the bloblist inaccessible if the pointer is
169 * no-longer valid. It is better to just store all the data inside a bloblist
170 * record.
171 *
172 * Each bloblist record is aligned to a 16-byte boundary and follows immediately
173 * from the last.
174 *
Simon Glass9341a3f2022-01-12 19:26:16 -0700175 * @magic: BLOBLIST_MAGIC
Simon Glass39d5ad32023-12-27 13:07:08 -0800176 * @chksum: checksum for the entire bloblist allocated area. Since any of the
177 * blobs can be altered after being created, this checksum is only valid
178 * when the bloblist is finalized before jumping to the next stage of boot.
179 * This is the value needed to make all checksummed bytes sum to 0
Simon Glass712bd2d2018-11-15 18:43:50 -0700180 * @version: BLOBLIST_VERSION
181 * @hdr_size: Size of this header, normally sizeof(struct bloblist_hdr). The
182 * first bloblist_rec starts at this offset from the start of the header
Simon Glass39d5ad32023-12-27 13:07:08 -0800183 * @align_log2: Power of two of the maximum alignment required by this list
184 * @used_size: Size allocated so far for this bloblist. This starts out as
Simon Glass712bd2d2018-11-15 18:43:50 -0700185 * sizeof(bloblist_hdr) since we need at least that much space to store a
186 * valid bloblist
Simon Glass39d5ad32023-12-27 13:07:08 -0800187 * @total_size: The number of total bytes that the bloblist can occupy.
188 * Any blob producer must check if there is sufficient space before adding
189 * a record to the bloblist.
190 * @flags: Space for BLOBLISTF... flags (none yet)
Simon Glassf98fd602020-09-19 18:49:30 -0600191 * @spare: Spare space (for future use)
Simon Glass712bd2d2018-11-15 18:43:50 -0700192 */
193struct bloblist_hdr {
Simon Glass9341a3f2022-01-12 19:26:16 -0700194 u32 magic;
Simon Glass39d5ad32023-12-27 13:07:08 -0800195 u8 chksum;
196 u8 version;
197 u8 hdr_size;
198 u8 align_log2;
199 u32 used_size;
200 u32 total_size;
Simon Glass712bd2d2018-11-15 18:43:50 -0700201 u32 flags;
Simon Glass712bd2d2018-11-15 18:43:50 -0700202 u32 spare;
Simon Glass712bd2d2018-11-15 18:43:50 -0700203};
204
205/**
206 * struct bloblist_rec - record for the bloblist
207 *
Simon Glass712bd2d2018-11-15 18:43:50 -0700208 * The bloblist contains a number of records each consisting of this record
209 * structure followed by the data contained. Each records is 16-byte aligned.
210 *
Simon Glass49ae4ad2022-01-12 19:26:24 -0700211 * NOTE: Only exported for testing purposes. Do not use this struct.
212 *
Simon Glass703a5da2023-12-27 13:07:07 -0800213 * @tag_and_hdr_size: Tag indicating what the record contains (bottom 24 bits), and
214 * size of this header (top 8 bits), normally sizeof(struct bloblist_rec).
215 * The record's data starts at this offset from the start of the record
Simon Glass712bd2d2018-11-15 18:43:50 -0700216 * @size: Size of record in bytes, excluding the header size. This does not
217 * need to be aligned (e.g. 3 is OK).
Simon Glass712bd2d2018-11-15 18:43:50 -0700218 */
219struct bloblist_rec {
Simon Glass703a5da2023-12-27 13:07:07 -0800220 u32 tag_and_hdr_size;
Simon Glass712bd2d2018-11-15 18:43:50 -0700221 u32 size;
Simon Glass703a5da2023-12-27 13:07:07 -0800222};
223
224enum {
225 BLOBLISTR_TAG_SHIFT = 0,
226 BLOBLISTR_TAG_MASK = 0xffffffU << BLOBLISTR_TAG_SHIFT,
227 BLOBLISTR_HDR_SIZE_SHIFT = 24,
228 BLOBLISTR_HDR_SIZE_MASK = 0xffU << BLOBLISTR_HDR_SIZE_SHIFT,
229
230 BLOBLIST_HDR_SIZE = sizeof(struct bloblist_hdr),
231 BLOBLIST_REC_HDR_SIZE = sizeof(struct bloblist_rec),
Simon Glass712bd2d2018-11-15 18:43:50 -0700232};
233
234/**
Simon Glass9341a3f2022-01-12 19:26:16 -0700235 * bloblist_check_magic() - return a bloblist if the magic matches
236 *
237 * @addr: Address to check
Simon Glass49ae4ad2022-01-12 19:26:24 -0700238 * Return: pointer to bloblist, if the magic matches, else NULL
Simon Glass9341a3f2022-01-12 19:26:16 -0700239 */
240static inline void *bloblist_check_magic(ulong addr)
241{
242 u32 *ptr;
243
244 if (!addr)
245 return NULL;
246 ptr = map_sysmem(addr, 0);
247 if (*ptr != BLOBLIST_MAGIC)
248 return NULL;
249
250 return ptr;
251}
252
Raymond Maoc6881f12025-01-27 06:49:34 -0800253#if CONFIG_IS_ENABLED(BLOBLIST)
254/**
255 * bloblist_get_blob() - Find a blob and get the size of it
256 *
257 * Searches the bloblist and returns the blob with the matching tag
258 *
259 * @tag: Tag to search for (enum bloblist_tag_t)
260 * @sizep: Size of the blob found
261 * Return: pointer to bloblist if found, or NULL if not found
262 */
263void *bloblist_get_blob(uint tag, int *sizep);
264#else
265static inline void *bloblist_get_blob(uint tag, int *sizep)
266{
267 return NULL;
268}
269#endif
270
Simon Glass9341a3f2022-01-12 19:26:16 -0700271/**
Simon Glass712bd2d2018-11-15 18:43:50 -0700272 * bloblist_find() - Find a blob
273 *
274 * Searches the bloblist and returns the blob with the matching tag
275 *
276 * @tag: Tag to search for (enum bloblist_tag_t)
Simon Glassf98fd602020-09-19 18:49:30 -0600277 * @size: Expected size of the blob, or 0 for any size
Simon Glass49ae4ad2022-01-12 19:26:24 -0700278 * Return: pointer to blob if found, or NULL if not found, or a blob was found
279 * but it is the wrong size
Simon Glass712bd2d2018-11-15 18:43:50 -0700280 */
281void *bloblist_find(uint tag, int size);
282
283/**
284 * bloblist_add() - Add a new blob
285 *
286 * Add a new blob to the bloblist
287 *
288 * This should only be called if you konw there is no existing blob for a
289 * particular tag. It is typically safe to call in the first phase of U-Boot
290 * (e.g. TPL or SPL). After that, bloblist_ensure() should be used instead.
291 *
292 * @tag: Tag to add (enum bloblist_tag_t)
293 * @size: Size of the blob
Simon Glassc2aa4ef2023-12-27 13:07:00 -0800294 * @align_log2: Alignment of the blob (in bytes log2), 0 for default
Simon Glass49ae4ad2022-01-12 19:26:24 -0700295 * Return: pointer to the newly added block, or NULL if there is not enough
296 * space for the blob
Simon Glass712bd2d2018-11-15 18:43:50 -0700297 */
Simon Glassc2aa4ef2023-12-27 13:07:00 -0800298void *bloblist_add(uint tag, int size, int align_log2);
Simon Glass712bd2d2018-11-15 18:43:50 -0700299
300/**
301 * bloblist_ensure_size() - Find or add a blob
302 *
303 * Find an existing blob, or add a new one if not found
304 *
305 * @tag: Tag to add (enum bloblist_tag_t)
306 * @size: Size of the blob
307 * @blobp: Returns a pointer to blob on success
Simon Glassc2aa4ef2023-12-27 13:07:00 -0800308 * @align_log2: Alignment of the blob (in bytes log2), 0 for default
Simon Glass49ae4ad2022-01-12 19:26:24 -0700309 * Return: 0 if OK, -ENOSPC if it is missing and could not be added due to lack
310 * of space, or -ESPIPE it exists but has the wrong size
Simon Glass712bd2d2018-11-15 18:43:50 -0700311 */
Simon Glassc2aa4ef2023-12-27 13:07:00 -0800312int bloblist_ensure_size(uint tag, int size, int align_log2, void **blobp);
Simon Glass712bd2d2018-11-15 18:43:50 -0700313
314/**
315 * bloblist_ensure() - Find or add a blob
316 *
317 * Find an existing blob, or add a new one if not found
318 *
319 * @tag: Tag to add (enum bloblist_tag_t)
320 * @size: Size of the blob
Simon Glass49ae4ad2022-01-12 19:26:24 -0700321 * Return: pointer to blob, or NULL if it is missing and could not be added due
322 * to lack of space, or it exists but has the wrong size
Simon Glass712bd2d2018-11-15 18:43:50 -0700323 */
324void *bloblist_ensure(uint tag, int size);
325
326/**
Simon Glass1e0304e2020-01-27 08:49:50 -0700327 * bloblist_ensure_size_ret() - Find or add a blob
328 *
329 * Find an existing blob, or add a new one if not found
330 *
331 * @tag: Tag to add (enum bloblist_tag_t)
332 * @sizep: Size of the blob to create; returns size of actual blob
333 * @blobp: Returns a pointer to blob on success
Simon Glass49ae4ad2022-01-12 19:26:24 -0700334 * Return: 0 if OK, -ENOSPC if it is missing and could not be added due to lack
335 * of space
Simon Glass1e0304e2020-01-27 08:49:50 -0700336 */
337int bloblist_ensure_size_ret(uint tag, int *sizep, void **blobp);
338
339/**
Simon Glassf20a1132021-07-05 16:32:53 -0600340 * bloblist_resize() - resize a blob
341 *
342 * Any blobs above this one are relocated up or down. The resized blob remains
343 * in the same place.
344 *
345 * @tag: Tag to add (enum bloblist_tag_t)
346 * @new_size: New size of the blob (>0 to expand, <0 to contract)
Simon Glass49ae4ad2022-01-12 19:26:24 -0700347 * Return: 0 if OK, -ENOSPC if the bloblist does not have enough space, -ENOENT
348 * if the tag is not found
Simon Glassf20a1132021-07-05 16:32:53 -0600349 */
350int bloblist_resize(uint tag, int new_size);
351
352/**
Simon Glass712bd2d2018-11-15 18:43:50 -0700353 * bloblist_new() - Create a new, empty bloblist of a given size
354 *
355 * @addr: Address of bloblist
356 * @size: Initial size for bloblist
357 * @flags: Flags to use for bloblist
Simon Glassaee5a9c2023-12-27 13:07:09 -0800358 * @align_log2: Log base 2 of maximum alignment provided by this bloblist
Simon Glass49ae4ad2022-01-12 19:26:24 -0700359 * Return: 0 if OK, -EFAULT if addr is not aligned correctly, -ENOSPC is the
360 * area is not large enough
Simon Glass712bd2d2018-11-15 18:43:50 -0700361 */
Simon Glassaee5a9c2023-12-27 13:07:09 -0800362int bloblist_new(ulong addr, uint size, uint flags, uint align_log2);
Simon Glass712bd2d2018-11-15 18:43:50 -0700363
364/**
365 * bloblist_check() - Check if a bloblist exists
366 *
367 * @addr: Address of bloblist
Raymond Maobc7f0ab2024-02-03 08:36:21 -0800368 * @size: Reserved space size for blobsize, or 0 to use the total size
Simon Glass49ae4ad2022-01-12 19:26:24 -0700369 * Return: 0 if OK, -ENOENT if the magic number doesn't match (indicating that
Raymond Maobc7f0ab2024-02-03 08:36:21 -0800370 * there problem is no bloblist at the given address) or any fields for header
371 * size, used size and total size do not match, -EPROTONOSUPPORT
Simon Glass49ae4ad2022-01-12 19:26:24 -0700372 * if the version does not match, -EIO if the checksum does not match,
Raymond Maobc7f0ab2024-02-03 08:36:21 -0800373 * -EFBIG if the reserved space size is small than the total size or total size
374 * is 0
Simon Glass712bd2d2018-11-15 18:43:50 -0700375 */
376int bloblist_check(ulong addr, uint size);
377
Evgeny Bachinin31041152024-12-02 16:45:22 +0300378#if CONFIG_IS_ENABLED(BLOBLIST)
Simon Glass712bd2d2018-11-15 18:43:50 -0700379/**
380 * bloblist_finish() - Set up the bloblist for the next U-Boot part
381 *
382 * This sets the correct checksum for the bloblist. This ensures that the
383 * bloblist will be detected correctly by the next phase of U-Boot.
384 *
Simon Glass49ae4ad2022-01-12 19:26:24 -0700385 * Return: 0
Simon Glass712bd2d2018-11-15 18:43:50 -0700386 */
387int bloblist_finish(void);
Evgeny Bachinin31041152024-12-02 16:45:22 +0300388#else
389static inline int bloblist_finish(void)
390{
391 return 0;
392}
393#endif /* BLOBLIST */
Simon Glass712bd2d2018-11-15 18:43:50 -0700394
395/**
Simon Glassb936a972020-09-19 18:49:26 -0600396 * bloblist_get_stats() - Get information about the bloblist
397 *
398 * This returns useful information about the bloblist
Simon Glass1834c3d2021-07-05 16:32:54 -0600399 *
400 * @basep: Returns base address of bloblist
Simon Glass39d5ad32023-12-27 13:07:08 -0800401 * @tsizep: Returns the total number of bytes of the bloblist
402 * @usizep: Returns the number of used bytes of the bloblist
Simon Glassb936a972020-09-19 18:49:26 -0600403 */
Simon Glass39d5ad32023-12-27 13:07:08 -0800404void bloblist_get_stats(ulong *basep, ulong *tsizep, ulong *usizep);
Simon Glassb936a972020-09-19 18:49:26 -0600405
406/**
Simon Glass01fd56a2022-01-12 19:26:23 -0700407 * bloblist_get_base() - Get the base address of the bloblist
408 *
Simon Glass49ae4ad2022-01-12 19:26:24 -0700409 * Return: base address of bloblist
Simon Glass01fd56a2022-01-12 19:26:23 -0700410 */
411ulong bloblist_get_base(void);
412
413/**
414 * bloblist_get_size() - Get the size of the bloblist
415 *
Simon Glass49ae4ad2022-01-12 19:26:24 -0700416 * Return: the size in bytes
Simon Glass01fd56a2022-01-12 19:26:23 -0700417 */
418ulong bloblist_get_size(void);
419
420/**
Simon Glass39d5ad32023-12-27 13:07:08 -0800421 * bloblist_get_total_size() - Get the total size of the bloblist
422 *
423 * Return: the size in bytes
424 */
425ulong bloblist_get_total_size(void);
426
427/**
Simon Glassb936a972020-09-19 18:49:26 -0600428 * bloblist_show_stats() - Show information about the bloblist
429 *
430 * This shows useful information about the bloblist on the console
431 */
432void bloblist_show_stats(void);
433
434/**
435 * bloblist_show_list() - Show a list of blobs in the bloblist
436 *
437 * This shows a list of blobs, showing their address, size and tag.
438 */
439void bloblist_show_list(void);
440
441/**
442 * bloblist_tag_name() - Get the name for a tag
443 *
444 * @tag: Tag to check
Simon Glass49ae4ad2022-01-12 19:26:24 -0700445 * Return: name of tag, or "invalid" if an invalid tag is provided
Simon Glassb936a972020-09-19 18:49:26 -0600446 */
447const char *bloblist_tag_name(enum bloblist_tag_t tag);
448
449/**
Simon Glassab7e7462021-01-13 20:29:43 -0700450 * bloblist_reloc() - Relocate the bloblist and optionally resize it
451 *
452 * @to: Pointer to new bloblist location (must not overlap old location)
Raymond Mao1a99d2c2024-02-03 08:36:22 -0800453 * @to_size: New size for bloblist
454 * Return: 0 if OK, -ENOSPC if the new size is small than the bloblist total
455 * size.
Simon Glassab7e7462021-01-13 20:29:43 -0700456 */
Raymond Mao1a99d2c2024-02-03 08:36:22 -0800457int bloblist_reloc(void *to, uint to_size);
Simon Glassab7e7462021-01-13 20:29:43 -0700458
459/**
Simon Glass712bd2d2018-11-15 18:43:50 -0700460 * bloblist_init() - Init the bloblist system with a single bloblist
461 *
Simon Glass49ae4ad2022-01-12 19:26:24 -0700462 * This locates and sets up the blocklist for use.
463 *
464 * If CONFIG_BLOBLIST_FIXED is selected, it uses CONFIG_BLOBLIST_ADDR and
465 * CONFIG_BLOBLIST_SIZE to set up a bloblist for use by U-Boot.
466 *
467 * If CONFIG_BLOBLIST_ALLOC is selected, it allocates memory for a bloblist of
468 * size CONFIG_BLOBLIST_SIZE.
469 *
Raymond Maob9319e42025-02-19 16:02:20 -0800470 * If CONFIG_BLOBLIST_PASSAGE_MANDATORY is selected, bloblist in the incoming
471 * standard passage is mandatorily required.
Simon Glass49ae4ad2022-01-12 19:26:24 -0700472 *
Simon Glassa28f39c2023-09-26 08:14:51 -0600473 * Sets GD_FLG_BLOBLIST_READY in global_data flags on success
474 *
Simon Glass49ae4ad2022-01-12 19:26:24 -0700475 * Return: 0 if OK, -ve on error
Simon Glass712bd2d2018-11-15 18:43:50 -0700476 */
477int bloblist_init(void);
478
Simon Glassa28f39c2023-09-26 08:14:51 -0600479#if CONFIG_IS_ENABLED(BLOBLIST)
480/**
481 * bloblist_maybe_init() - Init the bloblist system if not already done
482 *
Harrison Mutaib8d792d2025-02-04 17:58:39 +0000483 * Calls bloblist_init() if the GD_FLG_BLOBLIST_READY flag is not set
Simon Glassa28f39c2023-09-26 08:14:51 -0600484 *
485 * Return: 0 if OK, -ve on error
486 */
487int bloblist_maybe_init(void);
488#else
489static inline int bloblist_maybe_init(void)
490{
491 return 0;
492}
493#endif /* BLOBLIST */
494
Raymond Maofe016b62024-02-03 08:36:20 -0800495/**
496 * bloblist_check_reg_conv() - Check whether the bloblist is compliant to
497 * the register conventions according to the
498 * Firmware Handoff spec.
499 *
500 * @rfdt: Register that holds the FDT base address.
501 * @rzero: Register that must be zero.
502 * @rsig: Register that holds signature and register conventions version.
Raymond Maoba72dd12025-02-19 16:02:19 -0800503 * @xlist: Register that holds the transfer list.
Raymond Maofe016b62024-02-03 08:36:20 -0800504 * Return: 0 if OK, -EIO if the bloblist is not compliant to the register
505 * conventions.
506 */
Raymond Maoba72dd12025-02-19 16:02:19 -0800507int bloblist_check_reg_conv(ulong rfdt, ulong rzero, ulong rsig, ulong xlist);
Raymond Maofe016b62024-02-03 08:36:20 -0800508
Raymond Mao72c99cc2024-02-03 08:36:26 -0800509/**
Raymond Maoba72dd12025-02-19 16:02:19 -0800510 * xferlist_from_boot_arg() - Get bloblist from the boot args.
Raymond Mao72c99cc2024-02-03 08:36:26 -0800511 *
Raymond Maoba72dd12025-02-19 16:02:19 -0800512 * @addr: Address of the bloblist
Raymond Mao72c99cc2024-02-03 08:36:26 -0800513 * Return: 0 if OK, else on error
514 */
Raymond Maoba72dd12025-02-19 16:02:19 -0800515int xferlist_from_boot_arg(ulong *addr);
Raymond Mao72c99cc2024-02-03 08:36:26 -0800516
Simon Glass712bd2d2018-11-15 18:43:50 -0700517#endif /* __BLOBLIST_H */