blob: 0d9b5a31f4061ec04a3d23250d33954900382724 [file] [log] [blame]
Manish Pandey65fe3642025-03-21 12:44:42 +00001/*
2 * Copyright The Transfer List Library Contributors
3 *
4 * SPDX-License-Identifier: MIT OR GPL-2.0-or-later
5 */
6
7#ifndef TRANSFER_LIST_H
8#define TRANSFER_LIST_H
9
10#include <assert.h>
11#include <stdbool.h>
Harrison Mutaie0bc2c82025-05-08 15:36:08 +000012#include <stddef.h>
Manish Pandey65fe3642025-03-21 12:44:42 +000013#include <stdint.h>
14
15#define TRANSFER_LIST_SIGNATURE 0x4a0fb10b
16#define TRANSFER_LIST_VERSION 0x0001
17
18/*
19 * Init value of maximum alignment required by any TE data in the TL
20 * specified as a power of two
21 */
22#define TRANSFER_LIST_INIT_MAX_ALIGN 3U
23
24/* Alignment required by TE header start address, in bytes */
25#define TRANSFER_LIST_GRANULE 8U
26
27/*
28 * Version of the register convention used.
29 * Set to 1 for both AArch64 and AArch32 according to fw handoff spec v0.9
30 */
31#define REGISTER_CONVENTION_VERSION_SHIFT_64 32UL
32#define REGISTER_CONVENTION_VERSION_SHIFT_32 24UL
33#define REGISTER_CONVENTION_VERSION_MASK 0xffUL
34#define REGISTER_CONVENTION_VERSION 1UL
35
36#define TRANSFER_LIST_HANDOFF_X1_VALUE(__version) \
37 ((TRANSFER_LIST_SIGNATURE & \
38 ((1UL << REGISTER_CONVENTION_VERSION_SHIFT_64) - 1)) | \
39 (((__version)&REGISTER_CONVENTION_VERSION_MASK) \
40 << REGISTER_CONVENTION_VERSION_SHIFT_64))
41
42#define TRANSFER_LIST_HANDOFF_R1_VALUE(__version) \
43 ((TRANSFER_LIST_SIGNATURE & \
44 ((1UL << REGISTER_CONVENTION_VERSION_SHIFT_32) - 1)) | \
45 (((__version)&REGISTER_CONVENTION_VERSION_MASK) \
46 << REGISTER_CONVENTION_VERSION_SHIFT_32))
47
48#ifndef __ASSEMBLER__
49
50#define TL_FLAGS_HAS_CHECKSUM (1U << 0U)
51
52enum transfer_list_tag_id {
53 TL_TAG_EMPTY = 0,
54 TL_TAG_FDT = 1,
55 TL_TAG_HOB_BLOCK = 2,
56 TL_TAG_HOB_LIST = 3,
57 TL_TAG_ACPI_TABLE_AGGREGATE = 4,
Harrison Mutai1171f832025-03-21 15:33:17 +000058 TL_TAG_TPM_EVLOG = 5,
Manish Pandey65fe3642025-03-21 12:44:42 +000059 TL_TAG_OPTEE_PAGABLE_PART = 0x100,
60 TL_TAG_DT_SPMC_MANIFEST = 0x101,
61 TL_TAG_EXEC_EP_INFO64 = 0x102,
Manish Pandey65fe3642025-03-21 12:44:42 +000062 TL_TAG_SRAM_LAYOUT64 = 0x104,
63 TL_TAG_MBEDTLS_HEAP_INFO = 0x105,
Yeoreum Yune25480f2025-06-02 20:40:23 +010064 TL_TAG_DT_FFA_MANIFEST = 0x106,
Harrison Mutai1171f832025-03-21 15:33:17 +000065 TL_TAG_SRAM_LAYOUT32 = 0x107,
Yeoreum Yune25480f2025-06-02 20:40:23 +010066 TL_TAG_EXEC_EP_INFO32 = 0x108,
Manish Pandey65fe3642025-03-21 12:44:42 +000067};
68
69enum transfer_list_ops {
70 TL_OPS_NON, /* invalid for any operation */
71 TL_OPS_ALL, /* valid for all operations */
72 TL_OPS_RO, /* valid for read only */
73 TL_OPS_CUS, /* abort or switch to special code to interpret */
74};
75
76struct transfer_list_header {
77 uint32_t signature;
78 uint8_t checksum;
79 uint8_t version;
80 uint8_t hdr_size;
81 uint8_t alignment; /* max alignment of TE data */
82 uint32_t size; /* TL header + all TEs */
83 uint32_t max_size;
84 uint32_t flags;
85 uint32_t reserved; /* spare bytes */
86 /*
87 * Commented out element used to visualize dynamic part of the
88 * data structure.
89 *
90 * Note that struct transfer_list_entry also is dynamic in size
91 * so the elements can't be indexed directly but instead must be
92 * traversed in order
93 *
94 * struct transfer_list_entry entries[];
95 */
96};
97
98struct __attribute__((packed)) transfer_list_entry {
99 uint32_t tag_id : 24;
100 uint8_t hdr_size;
101 uint32_t data_size;
102 /*
103 * Commented out element used to visualize dynamic part of the
104 * data structure.
105 *
106 * Note that padding is added at the end of @data to make to reach
107 * a 8-byte boundary.
108 *
109 * uint8_t data[ROUNDUP(data_size, 8)];
110 */
111};
112
Harrison Mutai736f1952025-05-01 08:08:20 +0000113/*
114 * Provide a backward-compatible implementation of static_assert.
115 * This keyword was introduced in C11, so it may be unavailable in
116 * projects targeting older C standards.
117 */
118#if __STDC_VERSION__ >= 201112L
119#define LIBTL_STATIC_ASSERT(cond, msg) _Static_assert(cond, #msg)
120#else
121#define LIBTL_STATIC_ASSERT(cond, msg) \
122 typedef char static_assertion_##msg[(cond) ? 1 : -1]
123#endif
124
125LIBTL_STATIC_ASSERT(sizeof(struct transfer_list_entry) == 0x8U,
126 assert_transfer_list_entry_size);
Manish Pandey65fe3642025-03-21 12:44:42 +0000127
128void transfer_list_dump(struct transfer_list_header *tl);
Harrison Mutaidb83bfa2025-03-21 15:24:55 +0000129void transfer_entry_dump(struct transfer_list_entry *te);
130struct transfer_list_header *transfer_list_ensure(void *addr, size_t size);
Manish Pandey65fe3642025-03-21 12:44:42 +0000131struct transfer_list_header *transfer_list_init(void *addr, size_t max_size);
132
133struct transfer_list_header *
134transfer_list_relocate(struct transfer_list_header *tl, void *addr,
135 size_t max_size);
136enum transfer_list_ops
137transfer_list_check_header(const struct transfer_list_header *tl);
138
139void transfer_list_update_checksum(struct transfer_list_header *tl);
140bool transfer_list_verify_checksum(const struct transfer_list_header *tl);
141
142bool transfer_list_set_data_size(struct transfer_list_header *tl,
143 struct transfer_list_entry *entry,
144 uint32_t new_data_size);
145
146void *transfer_list_entry_data(struct transfer_list_entry *entry);
147bool transfer_list_rem(struct transfer_list_header *tl,
148 struct transfer_list_entry *entry);
149
150struct transfer_list_entry *transfer_list_add(struct transfer_list_header *tl,
151 uint32_t tag_id,
152 uint32_t data_size,
153 const void *data);
154
155struct transfer_list_entry *
156transfer_list_add_with_align(struct transfer_list_header *tl, uint32_t tag_id,
157 uint32_t data_size, const void *data,
158 uint8_t alignment);
159
160struct transfer_list_entry *
161transfer_list_next(struct transfer_list_header *tl,
162 struct transfer_list_entry *last);
163
164struct transfer_list_entry *transfer_list_find(struct transfer_list_header *tl,
165 uint32_t tag_id);
166
Harrison Mutaie0bc2c82025-05-08 15:36:08 +0000167struct entry_point_info *
168transfer_list_set_handoff_args(struct transfer_list_header *tl,
169 struct entry_point_info *ep_info);
170
Manish Pandey65fe3642025-03-21 12:44:42 +0000171#endif /* __ASSEMBLER__ */
172#endif /* TRANSFER_LIST_H */