drtm_main.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /*
  2. * Copyright (c) 2022-2024 Arm Limited. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. *
  6. */
  7. #ifndef DRTM_MAIN_H
  8. #define DRTM_MAIN_H
  9. #include <stdint.h>
  10. #include <assert.h>
  11. #include <lib/smccc.h>
  12. #include "drtm_dma_prot.h"
  13. #define ALIGNED_UP(x, a) __extension__ ({ \
  14. __typeof__(a) _a = (a); \
  15. __typeof__(a) _one = 1; \
  16. assert(IS_POWER_OF_TWO(_a)); \
  17. ((x) + (_a - _one)) & ~(_a - _one); \
  18. })
  19. #define ALIGNED_DOWN(x, a) __extension__ ({ \
  20. __typeof__(a) _a = (a); \
  21. __typeof__(a) _one = 1; \
  22. assert(IS_POWER_OF_TWO(_a)); \
  23. (x) & ~(_a - _one); \
  24. })
  25. #define DRTM_PAGE_SIZE (4 * (1 << 10))
  26. #define DRTM_PAGE_SIZE_STR "4-KiB"
  27. #define DL_ARGS_GET_DMA_PROT_TYPE(a) (((a)->features >> 3) & 0x7U)
  28. #define DL_ARGS_GET_PCR_SCHEMA(a) (((a)->features >> 1) & 0x3U)
  29. #define DL_ARGS_GET_DLME_ENTRY_POINT(a) \
  30. (((a)->dlme_paddr + (a)->dlme_img_off + (a)->dlme_img_ep_off))
  31. /*
  32. * Range(Min/Max) of DRTM parameter structure versions supported
  33. */
  34. #define ARM_DRTM_PARAMS_MIN_VERSION U(1)
  35. #define ARM_DRTM_PARAMS_MAX_VERSION U(1)
  36. enum drtm_dlme_el {
  37. DLME_AT_EL1 = MODE_EL1,
  38. DLME_AT_EL2 = MODE_EL2
  39. };
  40. enum drtm_retc {
  41. SUCCESS = SMC_OK,
  42. NOT_SUPPORTED = SMC_UNK,
  43. INVALID_PARAMETERS = -2,
  44. DENIED = -3,
  45. NOT_FOUND = -4,
  46. INTERNAL_ERROR = -5,
  47. MEM_PROTECT_INVALID = -6,
  48. COPROCESSOR_ERROR = -7,
  49. OUT_OF_RESOURCE = -8,
  50. INVALID_DATA = -9,
  51. SECONDARY_PE_NOT_OFF = -10,
  52. ALREADY_CLOSED = -11,
  53. TPM_ERROR = -12
  54. };
  55. typedef struct {
  56. uint64_t tpm_features;
  57. uint64_t minimum_memory_requirement;
  58. uint64_t dma_prot_features;
  59. uint64_t boot_pe_id;
  60. uint64_t tcb_hash_features;
  61. } drtm_features_t;
  62. struct __packed drtm_dl_args_v1 {
  63. uint16_t version; /* Must be 1. */
  64. uint8_t __res[2];
  65. uint32_t features;
  66. uint64_t dlme_paddr;
  67. uint64_t dlme_size;
  68. uint64_t dlme_img_off;
  69. uint64_t dlme_img_ep_off;
  70. uint64_t dlme_img_size;
  71. uint64_t dlme_data_off;
  72. uint64_t dce_nwd_paddr;
  73. uint64_t dce_nwd_size;
  74. drtm_dl_dma_prot_args_v1_t dma_prot_args;
  75. } __aligned(__alignof(uint16_t /* First member's type, `uint16_t version' */));
  76. struct __packed dlme_data_header_v1 {
  77. uint16_t version; /* Must be 1. */
  78. uint16_t this_hdr_size;
  79. uint8_t __res[4];
  80. uint64_t dlme_data_size;
  81. uint64_t dlme_prot_regions_size;
  82. uint64_t dlme_addr_map_size;
  83. uint64_t dlme_tpm_log_size;
  84. uint64_t dlme_tcb_hashes_table_size;
  85. uint64_t dlme_acpi_tables_region_size;
  86. uint64_t dlme_impdef_region_size;
  87. } __aligned(__alignof(uint16_t /* First member's type, `uint16_t version'. */));
  88. typedef struct dlme_data_header_v1 struct_dlme_data_header;
  89. drtm_memory_region_descriptor_table_t *drtm_build_address_map(void);
  90. uint64_t drtm_get_address_map_size(void);
  91. /*
  92. * Version-independent type. May be used to avoid excessive line of code
  93. * changes when migrating to new struct versions.
  94. */
  95. typedef struct drtm_dl_args_v1 struct_drtm_dl_args;
  96. #endif /* DRTM_MAIN_H */