blob: 9a5e692b8b845004c12c47715a8f606b89b2039a [file] [log] [blame]
Raymond Mao98983392023-07-25 07:53:35 -07001/*
Harrison Mutai4490cd02024-03-20 14:37:51 +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 */
Raymond Mao98983392023-07-25 07:53:35 -070032#define REGISTER_CONVENTION_VERSION_MASK (1 << 24)
33
34#ifndef __ASSEMBLER__
35
Raymond Mao60c3c972023-10-04 09:19:16 -070036#define TL_FLAGS_HAS_CHECKSUM BIT(0)
37
Raymond Mao98983392023-07-25 07:53:35 -070038enum transfer_list_tag_id {
39 TL_TAG_EMPTY = 0,
40 TL_TAG_FDT = 1,
41 TL_TAG_HOB_BLOCK = 2,
42 TL_TAG_HOB_LIST = 3,
43 TL_TAG_ACPI_TABLE_AGGREGATE = 4,
Raymond Mao60c3c972023-10-04 09:19:16 -070044 TL_TAG_OPTEE_PAGABLE_PART = 0x100,
Raymond Mao98983392023-07-25 07:53:35 -070045};
46
47enum transfer_list_ops {
Raymond Mao60c3c972023-10-04 09:19:16 -070048 TL_OPS_NON, /* invalid for any operation */
49 TL_OPS_ALL, /* valid for all operations */
50 TL_OPS_RO, /* valid for read only */
51 TL_OPS_CUS, /* abort or switch to special code to interpret */
Raymond Mao98983392023-07-25 07:53:35 -070052};
53
54struct transfer_list_header {
Raymond Mao60c3c972023-10-04 09:19:16 -070055 uint32_t signature;
56 uint8_t checksum;
57 uint8_t version;
58 uint8_t hdr_size;
59 uint8_t alignment; /* max alignment of TE data */
60 uint32_t size; /* TL header + all TEs */
61 uint32_t max_size;
62 uint32_t flags;
63 uint32_t reserved; /* spare bytes */
Raymond Mao98983392023-07-25 07:53:35 -070064 /*
65 * Commented out element used to visualize dynamic part of the
66 * data structure.
67 *
68 * Note that struct transfer_list_entry also is dynamic in size
69 * so the elements can't be indexed directly but instead must be
70 * traversed in order
71 *
72 * struct transfer_list_entry entries[];
73 */
74};
75
Harrison Mutai4490cd02024-03-20 14:37:51 +000076struct __attribute__((packed)) transfer_list_entry {
77 uint32_t tag_id : 24;
Raymond Mao60c3c972023-10-04 09:19:16 -070078 uint8_t hdr_size;
79 uint32_t data_size;
Raymond Mao98983392023-07-25 07:53:35 -070080 /*
81 * Commented out element used to visualize dynamic part of the
82 * data structure.
83 *
84 * Note that padding is added at the end of @data to make to reach
85 * a 8-byte boundary.
86 *
87 * uint8_t data[ROUNDUP(data_size, 8)];
88 */
89};
90
Harrison Mutai4490cd02024-03-20 14:37:51 +000091CASSERT(sizeof(struct transfer_list_entry) == U(0x8), assert_transfer_list_entry_size);
92
Raymond Mao98983392023-07-25 07:53:35 -070093void transfer_list_dump(struct transfer_list_header *tl);
Raymond Mao60c3c972023-10-04 09:19:16 -070094entry_point_info_t *
95transfer_list_set_handoff_args(struct transfer_list_header *tl,
96 entry_point_info_t *ep_info);
Raymond Mao98983392023-07-25 07:53:35 -070097struct transfer_list_header *transfer_list_init(void *addr, size_t max_size);
98
Raymond Mao60c3c972023-10-04 09:19:16 -070099struct transfer_list_header *
100transfer_list_relocate(struct transfer_list_header *tl, void *addr,
101 size_t max_size);
102enum transfer_list_ops
103transfer_list_check_header(const struct transfer_list_header *tl);
Raymond Mao98983392023-07-25 07:53:35 -0700104
105void transfer_list_update_checksum(struct transfer_list_header *tl);
106bool transfer_list_verify_checksum(const struct transfer_list_header *tl);
107
108bool transfer_list_set_data_size(struct transfer_list_header *tl,
109 struct transfer_list_entry *entry,
110 uint32_t new_data_size);
111
112void *transfer_list_entry_data(struct transfer_list_entry *entry);
Raymond Mao60c3c972023-10-04 09:19:16 -0700113bool transfer_list_rem(struct transfer_list_header *tl,
114 struct transfer_list_entry *entry);
Raymond Mao98983392023-07-25 07:53:35 -0700115
116struct transfer_list_entry *transfer_list_add(struct transfer_list_header *tl,
Harrison Mutai4490cd02024-03-20 14:37:51 +0000117 uint32_t tag_id,
Raymond Mao60c3c972023-10-04 09:19:16 -0700118 uint32_t data_size,
Raymond Mao98983392023-07-25 07:53:35 -0700119 const void *data);
120
Raymond Mao60c3c972023-10-04 09:19:16 -0700121struct transfer_list_entry *
Harrison Mutai4490cd02024-03-20 14:37:51 +0000122transfer_list_add_with_align(struct transfer_list_header *tl, uint32_t tag_id,
Raymond Mao60c3c972023-10-04 09:19:16 -0700123 uint32_t data_size, const void *data,
124 uint8_t alignment);
Raymond Mao98983392023-07-25 07:53:35 -0700125
Raymond Mao60c3c972023-10-04 09:19:16 -0700126struct transfer_list_entry *
127transfer_list_next(struct transfer_list_header *tl,
128 struct transfer_list_entry *last);
Raymond Mao98983392023-07-25 07:53:35 -0700129
130struct transfer_list_entry *transfer_list_find(struct transfer_list_header *tl,
Harrison Mutai4490cd02024-03-20 14:37:51 +0000131 uint32_t tag_id);
Raymond Mao98983392023-07-25 07:53:35 -0700132
133#endif /*__ASSEMBLER__*/
134#endif /*__TRANSFER_LIST_H*/