transfer_list.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. /*
  2. * Copyright (c) 2023-2024, Linaro Limited and Contributors. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #ifndef __TRANSFER_LIST_H
  7. #define __TRANSFER_LIST_H
  8. #include <stdbool.h>
  9. #include <stdint.h>
  10. #include <common/ep_info.h>
  11. #include <lib/utils_def.h>
  12. #define TRANSFER_LIST_SIGNATURE U(0x4a0fb10b)
  13. #define TRANSFER_LIST_VERSION U(0x0001)
  14. /*
  15. * Init value of maximum alignment required by any TE data in the TL
  16. * specified as a power of two
  17. */
  18. #define TRANSFER_LIST_INIT_MAX_ALIGN U(3)
  19. /* Alignment required by TE header start address, in bytes */
  20. #define TRANSFER_LIST_GRANULE U(8)
  21. /*
  22. * Version of the register convention used.
  23. * Set to 1 for both AArch64 and AArch32 according to fw handoff spec v0.9
  24. */
  25. #define REGISTER_CONVENTION_VERSION_SHIFT_64 UL(32)
  26. #define REGISTER_CONVENTION_VERSION_SHIFT_32 UL(24)
  27. #define REGISTER_CONVENTION_VERSION_MASK UL(0xff)
  28. #define REGISTER_CONVENTION_VERSION UL(1)
  29. #define TRANSFER_LIST_HANDOFF_X1_VALUE(__version) \
  30. ((TRANSFER_LIST_SIGNATURE & \
  31. ((1UL << REGISTER_CONVENTION_VERSION_SHIFT_64) - 1)) | \
  32. (((__version) & REGISTER_CONVENTION_VERSION_MASK) << \
  33. REGISTER_CONVENTION_VERSION_SHIFT_64))
  34. #define TRANSFER_LIST_HANDOFF_R1_VALUE(__version) \
  35. ((TRANSFER_LIST_SIGNATURE & \
  36. ((1UL << REGISTER_CONVENTION_VERSION_SHIFT_32) - 1)) | \
  37. (((__version) & REGISTER_CONVENTION_VERSION_MASK) << \
  38. REGISTER_CONVENTION_VERSION_SHIFT_32))
  39. #ifndef __ASSEMBLER__
  40. #define TL_FLAGS_HAS_CHECKSUM BIT(0)
  41. enum transfer_list_tag_id {
  42. TL_TAG_EMPTY = 0,
  43. TL_TAG_FDT = 1,
  44. TL_TAG_HOB_BLOCK = 2,
  45. TL_TAG_HOB_LIST = 3,
  46. TL_TAG_ACPI_TABLE_AGGREGATE = 4,
  47. TL_TAG_OPTEE_PAGABLE_PART = 0x100,
  48. TL_TAG_DT_SPMC_MANIFEST = 0x101,
  49. TL_TAG_EXEC_EP_INFO64 = 0x102,
  50. TL_TAG_TB_FW_CONFIG = 0x103,
  51. TL_TAG_SRAM_LAYOUT64 = 0x104,
  52. };
  53. enum transfer_list_ops {
  54. TL_OPS_NON, /* invalid for any operation */
  55. TL_OPS_ALL, /* valid for all operations */
  56. TL_OPS_RO, /* valid for read only */
  57. TL_OPS_CUS, /* abort or switch to special code to interpret */
  58. };
  59. struct transfer_list_header {
  60. uint32_t signature;
  61. uint8_t checksum;
  62. uint8_t version;
  63. uint8_t hdr_size;
  64. uint8_t alignment; /* max alignment of TE data */
  65. uint32_t size; /* TL header + all TEs */
  66. uint32_t max_size;
  67. uint32_t flags;
  68. uint32_t reserved; /* spare bytes */
  69. /*
  70. * Commented out element used to visualize dynamic part of the
  71. * data structure.
  72. *
  73. * Note that struct transfer_list_entry also is dynamic in size
  74. * so the elements can't be indexed directly but instead must be
  75. * traversed in order
  76. *
  77. * struct transfer_list_entry entries[];
  78. */
  79. };
  80. struct __attribute__((packed)) transfer_list_entry {
  81. uint32_t tag_id : 24;
  82. uint8_t hdr_size;
  83. uint32_t data_size;
  84. /*
  85. * Commented out element used to visualize dynamic part of the
  86. * data structure.
  87. *
  88. * Note that padding is added at the end of @data to make to reach
  89. * a 8-byte boundary.
  90. *
  91. * uint8_t data[ROUNDUP(data_size, 8)];
  92. */
  93. };
  94. CASSERT(sizeof(struct transfer_list_entry) == U(0x8), assert_transfer_list_entry_size);
  95. void transfer_list_dump(struct transfer_list_header *tl);
  96. entry_point_info_t *
  97. transfer_list_set_handoff_args(struct transfer_list_header *tl,
  98. entry_point_info_t *ep_info);
  99. struct transfer_list_header *transfer_list_init(void *addr, size_t max_size);
  100. struct transfer_list_header *
  101. transfer_list_relocate(struct transfer_list_header *tl, void *addr,
  102. size_t max_size);
  103. enum transfer_list_ops
  104. transfer_list_check_header(const struct transfer_list_header *tl);
  105. void transfer_list_update_checksum(struct transfer_list_header *tl);
  106. bool transfer_list_verify_checksum(const struct transfer_list_header *tl);
  107. bool transfer_list_set_data_size(struct transfer_list_header *tl,
  108. struct transfer_list_entry *entry,
  109. uint32_t new_data_size);
  110. void *transfer_list_entry_data(struct transfer_list_entry *entry);
  111. bool transfer_list_rem(struct transfer_list_header *tl,
  112. struct transfer_list_entry *entry);
  113. struct transfer_list_entry *transfer_list_add(struct transfer_list_header *tl,
  114. uint32_t tag_id,
  115. uint32_t data_size,
  116. const void *data);
  117. struct transfer_list_entry *
  118. transfer_list_add_with_align(struct transfer_list_header *tl, uint32_t tag_id,
  119. uint32_t data_size, const void *data,
  120. uint8_t alignment);
  121. struct transfer_list_entry *
  122. transfer_list_next(struct transfer_list_header *tl,
  123. struct transfer_list_entry *last);
  124. struct transfer_list_entry *transfer_list_find(struct transfer_list_header *tl,
  125. uint32_t tag_id);
  126. #endif /*__ASSEMBLER__*/
  127. #endif /*__TRANSFER_LIST_H*/