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