blob: bdc63490bbd81306c8ad4d89de8ed8ef084b8158 [file] [log] [blame]
Raymond Mao98983392023-07-25 07:53:35 -07001/*
Harrison Mutai60438ee2023-12-01 14:57:57 +00002 * Copyright (c) 2023-2024, Linaro Limited and Contributors. All rights reserved.
Raymond Mao98983392023-07-25 07:53:35 -07003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#ifndef __TRANSFER_LIST_H
8#define __TRANSFER_LIST_H
9
10#include <stdbool.h>
11#include <stdint.h>
12
Raymond Mao60c3c972023-10-04 09:19:16 -070013#include <common/ep_info.h>
Raymond Mao98983392023-07-25 07:53:35 -070014#include <lib/utils_def.h>
15
Raymond Mao60c3c972023-10-04 09:19:16 -070016#define TRANSFER_LIST_SIGNATURE U(0x4a0fb10b)
17#define TRANSFER_LIST_VERSION U(0x0001)
Raymond Mao98983392023-07-25 07:53:35 -070018
Raymond Mao60c3c972023-10-04 09:19:16 -070019/*
20 * Init value of maximum alignment required by any TE data in the TL
21 * specified as a power of two
22 */
23#define TRANSFER_LIST_INIT_MAX_ALIGN U(3)
Raymond Mao98983392023-07-25 07:53:35 -070024
Raymond Mao60c3c972023-10-04 09:19:16 -070025/* Alignment required by TE header start address, in bytes */
26#define TRANSFER_LIST_GRANULE U(8)
Raymond Mao98983392023-07-25 07:53:35 -070027
Raymond Mao60c3c972023-10-04 09:19:16 -070028/*
29 * Version of the register convention used.
30 * Set to 1 for both AArch64 and AArch32 according to fw handoff spec v0.9
31 */
levi.yun010d2ae2024-05-13 10:27:17 +010032#define REGISTER_CONVENTION_VERSION_SHIFT_64 UL(32)
33#define REGISTER_CONVENTION_VERSION_SHIFT_32 UL(24)
34#define REGISTER_CONVENTION_VERSION_MASK UL(0xff)
35#define REGISTER_CONVENTION_VERSION UL(1)
36
37#define TRANSFER_LIST_HANDOFF_X1_VALUE(__version) \
38 ((TRANSFER_LIST_SIGNATURE & \
39 ((1UL << REGISTER_CONVENTION_VERSION_SHIFT_64) - 1)) | \
40 (((__version) & REGISTER_CONVENTION_VERSION_MASK) << \
41 REGISTER_CONVENTION_VERSION_SHIFT_64))
42
43#define TRANSFER_LIST_HANDOFF_R1_VALUE(__version) \
44 ((TRANSFER_LIST_SIGNATURE & \
45 ((1UL << REGISTER_CONVENTION_VERSION_SHIFT_32) - 1)) | \
46 (((__version) & REGISTER_CONVENTION_VERSION_MASK) << \
47 REGISTER_CONVENTION_VERSION_SHIFT_32))
Raymond Mao98983392023-07-25 07:53:35 -070048
49#ifndef __ASSEMBLER__
50
Raymond Mao60c3c972023-10-04 09:19:16 -070051#define TL_FLAGS_HAS_CHECKSUM BIT(0)
52
Raymond Mao98983392023-07-25 07:53:35 -070053enum transfer_list_tag_id {
54 TL_TAG_EMPTY = 0,
55 TL_TAG_FDT = 1,
56 TL_TAG_HOB_BLOCK = 2,
57 TL_TAG_HOB_LIST = 3,
58 TL_TAG_ACPI_TABLE_AGGREGATE = 4,
Raymond Mao1fccc722024-12-27 07:17:14 -080059 TL_TAG_TPM_EVLOG = 5,
Raymond Mao60c3c972023-10-04 09:19:16 -070060 TL_TAG_OPTEE_PAGABLE_PART = 0x100,
Harrison Mutai60438ee2023-12-01 14:57:57 +000061 TL_TAG_DT_SPMC_MANIFEST = 0x101,
62 TL_TAG_EXEC_EP_INFO64 = 0x102,
Harrison Mutai803d22b2024-01-04 16:25:47 +000063 TL_TAG_SRAM_LAYOUT64 = 0x104,
Harrison Mutai61aaf272024-11-06 14:21:00 +000064 TL_TAG_MBEDTLS_HEAP_INFO = 0x105,
Harrison Mutai802dc9e2024-12-16 12:52:29 +000065 TL_TAG_EXEC_EP_INFO32 = 0x106,
Harrison Mutaif6ef0772024-12-16 12:55:15 +000066 TL_TAG_SRAM_LAYOUT32 = 0x107,
Raymond Mao98983392023-07-25 07:53:35 -070067};
68
69enum transfer_list_ops {
Raymond Mao60c3c972023-10-04 09:19:16 -070070 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 */
Raymond Mao98983392023-07-25 07:53:35 -070074};
75
76struct transfer_list_header {
Raymond Mao60c3c972023-10-04 09:19:16 -070077 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 */
Raymond Mao98983392023-07-25 07:53:35 -070086 /*
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
Harrison Mutai4490cd02024-03-20 14:37:51 +000098struct __attribute__((packed)) transfer_list_entry {
99 uint32_t tag_id : 24;
Raymond Mao60c3c972023-10-04 09:19:16 -0700100 uint8_t hdr_size;
101 uint32_t data_size;
Raymond Mao98983392023-07-25 07:53:35 -0700102 /*
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 Mutai4490cd02024-03-20 14:37:51 +0000113CASSERT(sizeof(struct transfer_list_entry) == U(0x8), assert_transfer_list_entry_size);
114
Harrison Mutaicebad0e2024-12-13 09:14:59 +0000115void transfer_entry_dump(struct transfer_list_entry *te);
Raymond Mao98983392023-07-25 07:53:35 -0700116void transfer_list_dump(struct transfer_list_header *tl);
Harrison Mutaiae1f7802024-11-06 10:03:51 +0000117struct transfer_list_header *transfer_list_ensure(void *addr, size_t size);
Raymond Mao60c3c972023-10-04 09:19:16 -0700118entry_point_info_t *
119transfer_list_set_handoff_args(struct transfer_list_header *tl,
120 entry_point_info_t *ep_info);
Raymond Mao98983392023-07-25 07:53:35 -0700121struct transfer_list_header *transfer_list_init(void *addr, size_t max_size);
122
Raymond Mao60c3c972023-10-04 09:19:16 -0700123struct transfer_list_header *
124transfer_list_relocate(struct transfer_list_header *tl, void *addr,
125 size_t max_size);
126enum transfer_list_ops
127transfer_list_check_header(const struct transfer_list_header *tl);
Raymond Mao98983392023-07-25 07:53:35 -0700128
129void transfer_list_update_checksum(struct transfer_list_header *tl);
130bool transfer_list_verify_checksum(const struct transfer_list_header *tl);
131
132bool transfer_list_set_data_size(struct transfer_list_header *tl,
133 struct transfer_list_entry *entry,
134 uint32_t new_data_size);
135
136void *transfer_list_entry_data(struct transfer_list_entry *entry);
Raymond Mao60c3c972023-10-04 09:19:16 -0700137bool transfer_list_rem(struct transfer_list_header *tl,
138 struct transfer_list_entry *entry);
Raymond Mao98983392023-07-25 07:53:35 -0700139
140struct transfer_list_entry *transfer_list_add(struct transfer_list_header *tl,
Harrison Mutai4490cd02024-03-20 14:37:51 +0000141 uint32_t tag_id,
Raymond Mao60c3c972023-10-04 09:19:16 -0700142 uint32_t data_size,
Raymond Mao98983392023-07-25 07:53:35 -0700143 const void *data);
144
Raymond Mao60c3c972023-10-04 09:19:16 -0700145struct transfer_list_entry *
Harrison Mutai4490cd02024-03-20 14:37:51 +0000146transfer_list_add_with_align(struct transfer_list_header *tl, uint32_t tag_id,
Raymond Mao60c3c972023-10-04 09:19:16 -0700147 uint32_t data_size, const void *data,
148 uint8_t alignment);
Raymond Mao98983392023-07-25 07:53:35 -0700149
Raymond Mao60c3c972023-10-04 09:19:16 -0700150struct transfer_list_entry *
151transfer_list_next(struct transfer_list_header *tl,
152 struct transfer_list_entry *last);
Raymond Mao98983392023-07-25 07:53:35 -0700153
154struct transfer_list_entry *transfer_list_find(struct transfer_list_header *tl,
Harrison Mutai4490cd02024-03-20 14:37:51 +0000155 uint32_t tag_id);
Raymond Mao98983392023-07-25 07:53:35 -0700156
157#endif /*__ASSEMBLER__*/
158#endif /*__TRANSFER_LIST_H*/