Raymond Mao | 9898339 | 2023-07-25 07:53:35 -0700 | [diff] [blame] | 1 | /* |
Harrison Mutai | 60438ee | 2023-12-01 14:57:57 +0000 | [diff] [blame] | 2 | * Copyright (c) 2023-2024, Linaro Limited and Contributors. All rights reserved. |
Raymond Mao | 9898339 | 2023-07-25 07:53:35 -0700 | [diff] [blame] | 3 | * |
| 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 Mao | 60c3c97 | 2023-10-04 09:19:16 -0700 | [diff] [blame] | 13 | #include <common/ep_info.h> |
Raymond Mao | 9898339 | 2023-07-25 07:53:35 -0700 | [diff] [blame] | 14 | #include <lib/utils_def.h> |
| 15 | |
Raymond Mao | 60c3c97 | 2023-10-04 09:19:16 -0700 | [diff] [blame] | 16 | #define TRANSFER_LIST_SIGNATURE U(0x4a0fb10b) |
| 17 | #define TRANSFER_LIST_VERSION U(0x0001) |
Raymond Mao | 9898339 | 2023-07-25 07:53:35 -0700 | [diff] [blame] | 18 | |
Raymond Mao | 60c3c97 | 2023-10-04 09:19:16 -0700 | [diff] [blame] | 19 | /* |
| 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 Mao | 9898339 | 2023-07-25 07:53:35 -0700 | [diff] [blame] | 24 | |
Raymond Mao | 60c3c97 | 2023-10-04 09:19:16 -0700 | [diff] [blame] | 25 | /* Alignment required by TE header start address, in bytes */ |
| 26 | #define TRANSFER_LIST_GRANULE U(8) |
Raymond Mao | 9898339 | 2023-07-25 07:53:35 -0700 | [diff] [blame] | 27 | |
Raymond Mao | 60c3c97 | 2023-10-04 09:19:16 -0700 | [diff] [blame] | 28 | /* |
| 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 Mao | 9898339 | 2023-07-25 07:53:35 -0700 | [diff] [blame] | 32 | #define REGISTER_CONVENTION_VERSION_MASK (1 << 24) |
| 33 | |
| 34 | #ifndef __ASSEMBLER__ |
| 35 | |
Raymond Mao | 60c3c97 | 2023-10-04 09:19:16 -0700 | [diff] [blame] | 36 | #define TL_FLAGS_HAS_CHECKSUM BIT(0) |
| 37 | |
Raymond Mao | 9898339 | 2023-07-25 07:53:35 -0700 | [diff] [blame] | 38 | enum 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 Mao | 60c3c97 | 2023-10-04 09:19:16 -0700 | [diff] [blame] | 44 | TL_TAG_OPTEE_PAGABLE_PART = 0x100, |
Harrison Mutai | 60438ee | 2023-12-01 14:57:57 +0000 | [diff] [blame] | 45 | TL_TAG_DT_SPMC_MANIFEST = 0x101, |
| 46 | TL_TAG_EXEC_EP_INFO64 = 0x102, |
Raymond Mao | 9898339 | 2023-07-25 07:53:35 -0700 | [diff] [blame] | 47 | }; |
| 48 | |
| 49 | enum transfer_list_ops { |
Raymond Mao | 60c3c97 | 2023-10-04 09:19:16 -0700 | [diff] [blame] | 50 | TL_OPS_NON, /* invalid for any operation */ |
| 51 | TL_OPS_ALL, /* valid for all operations */ |
| 52 | TL_OPS_RO, /* valid for read only */ |
| 53 | TL_OPS_CUS, /* abort or switch to special code to interpret */ |
Raymond Mao | 9898339 | 2023-07-25 07:53:35 -0700 | [diff] [blame] | 54 | }; |
| 55 | |
| 56 | struct transfer_list_header { |
Raymond Mao | 60c3c97 | 2023-10-04 09:19:16 -0700 | [diff] [blame] | 57 | uint32_t signature; |
| 58 | uint8_t checksum; |
| 59 | uint8_t version; |
| 60 | uint8_t hdr_size; |
| 61 | uint8_t alignment; /* max alignment of TE data */ |
| 62 | uint32_t size; /* TL header + all TEs */ |
| 63 | uint32_t max_size; |
| 64 | uint32_t flags; |
| 65 | uint32_t reserved; /* spare bytes */ |
Raymond Mao | 9898339 | 2023-07-25 07:53:35 -0700 | [diff] [blame] | 66 | /* |
| 67 | * Commented out element used to visualize dynamic part of the |
| 68 | * data structure. |
| 69 | * |
| 70 | * Note that struct transfer_list_entry also is dynamic in size |
| 71 | * so the elements can't be indexed directly but instead must be |
| 72 | * traversed in order |
| 73 | * |
| 74 | * struct transfer_list_entry entries[]; |
| 75 | */ |
| 76 | }; |
| 77 | |
Harrison Mutai | 4490cd0 | 2024-03-20 14:37:51 +0000 | [diff] [blame] | 78 | struct __attribute__((packed)) transfer_list_entry { |
| 79 | uint32_t tag_id : 24; |
Raymond Mao | 60c3c97 | 2023-10-04 09:19:16 -0700 | [diff] [blame] | 80 | uint8_t hdr_size; |
| 81 | uint32_t data_size; |
Raymond Mao | 9898339 | 2023-07-25 07:53:35 -0700 | [diff] [blame] | 82 | /* |
| 83 | * Commented out element used to visualize dynamic part of the |
| 84 | * data structure. |
| 85 | * |
| 86 | * Note that padding is added at the end of @data to make to reach |
| 87 | * a 8-byte boundary. |
| 88 | * |
| 89 | * uint8_t data[ROUNDUP(data_size, 8)]; |
| 90 | */ |
| 91 | }; |
| 92 | |
Harrison Mutai | 4490cd0 | 2024-03-20 14:37:51 +0000 | [diff] [blame] | 93 | CASSERT(sizeof(struct transfer_list_entry) == U(0x8), assert_transfer_list_entry_size); |
| 94 | |
Raymond Mao | 9898339 | 2023-07-25 07:53:35 -0700 | [diff] [blame] | 95 | void transfer_list_dump(struct transfer_list_header *tl); |
Raymond Mao | 60c3c97 | 2023-10-04 09:19:16 -0700 | [diff] [blame] | 96 | entry_point_info_t * |
| 97 | transfer_list_set_handoff_args(struct transfer_list_header *tl, |
| 98 | entry_point_info_t *ep_info); |
Raymond Mao | 9898339 | 2023-07-25 07:53:35 -0700 | [diff] [blame] | 99 | struct transfer_list_header *transfer_list_init(void *addr, size_t max_size); |
| 100 | |
Raymond Mao | 60c3c97 | 2023-10-04 09:19:16 -0700 | [diff] [blame] | 101 | struct transfer_list_header * |
| 102 | transfer_list_relocate(struct transfer_list_header *tl, void *addr, |
| 103 | size_t max_size); |
| 104 | enum transfer_list_ops |
| 105 | transfer_list_check_header(const struct transfer_list_header *tl); |
Raymond Mao | 9898339 | 2023-07-25 07:53:35 -0700 | [diff] [blame] | 106 | |
| 107 | void transfer_list_update_checksum(struct transfer_list_header *tl); |
| 108 | bool transfer_list_verify_checksum(const struct transfer_list_header *tl); |
| 109 | |
| 110 | bool transfer_list_set_data_size(struct transfer_list_header *tl, |
| 111 | struct transfer_list_entry *entry, |
| 112 | uint32_t new_data_size); |
| 113 | |
| 114 | void *transfer_list_entry_data(struct transfer_list_entry *entry); |
Raymond Mao | 60c3c97 | 2023-10-04 09:19:16 -0700 | [diff] [blame] | 115 | bool transfer_list_rem(struct transfer_list_header *tl, |
| 116 | struct transfer_list_entry *entry); |
Raymond Mao | 9898339 | 2023-07-25 07:53:35 -0700 | [diff] [blame] | 117 | |
| 118 | struct transfer_list_entry *transfer_list_add(struct transfer_list_header *tl, |
Harrison Mutai | 4490cd0 | 2024-03-20 14:37:51 +0000 | [diff] [blame] | 119 | uint32_t tag_id, |
Raymond Mao | 60c3c97 | 2023-10-04 09:19:16 -0700 | [diff] [blame] | 120 | uint32_t data_size, |
Raymond Mao | 9898339 | 2023-07-25 07:53:35 -0700 | [diff] [blame] | 121 | const void *data); |
| 122 | |
Raymond Mao | 60c3c97 | 2023-10-04 09:19:16 -0700 | [diff] [blame] | 123 | struct transfer_list_entry * |
Harrison Mutai | 4490cd0 | 2024-03-20 14:37:51 +0000 | [diff] [blame] | 124 | transfer_list_add_with_align(struct transfer_list_header *tl, uint32_t tag_id, |
Raymond Mao | 60c3c97 | 2023-10-04 09:19:16 -0700 | [diff] [blame] | 125 | uint32_t data_size, const void *data, |
| 126 | uint8_t alignment); |
Raymond Mao | 9898339 | 2023-07-25 07:53:35 -0700 | [diff] [blame] | 127 | |
Raymond Mao | 60c3c97 | 2023-10-04 09:19:16 -0700 | [diff] [blame] | 128 | struct transfer_list_entry * |
| 129 | transfer_list_next(struct transfer_list_header *tl, |
| 130 | struct transfer_list_entry *last); |
Raymond Mao | 9898339 | 2023-07-25 07:53:35 -0700 | [diff] [blame] | 131 | |
| 132 | struct transfer_list_entry *transfer_list_find(struct transfer_list_header *tl, |
Harrison Mutai | 4490cd0 | 2024-03-20 14:37:51 +0000 | [diff] [blame] | 133 | uint32_t tag_id); |
Raymond Mao | 9898339 | 2023-07-25 07:53:35 -0700 | [diff] [blame] | 134 | |
| 135 | #endif /*__ASSEMBLER__*/ |
| 136 | #endif /*__TRANSFER_LIST_H*/ |