1 /*
2  * Copyright (c) 2022 Arm Limited. All rights reserved.
3  *
4  * SPDX-License-Identifier:    BSD-3-Clause
5  *
6  */
7 #ifndef DRTM_DMA_PROT_H
8 #define DRTM_DMA_PROT_H
9 
10 #include <stdint.h>
11 #include <plat/common/platform.h>
12 #include <services/drtm_svc.h>
13 
14 struct __packed drtm_dl_dma_prot_args_v1 {
15 	uint64_t dma_prot_table_paddr;
16 	uint64_t dma_prot_table_size;
17 };
18 
19 /* Values for DRTM_PROTECT_MEMORY */
20 enum dma_prot_type {
21 	PROTECT_NONE    = -1,
22 	PROTECT_MEM_ALL = 0,
23 	PROTECT_MEM_REGION = 2,
24 };
25 
26 struct dma_prot {
27 	enum dma_prot_type type;
28 };
29 
30 #define DRTM_MEM_REGION_PAGES_AND_TYPE(pages, type) \
31 	(((uint64_t)(pages) & (((uint64_t)1 << 52) - 1)) \
32 	 | (((uint64_t)(type) & 0x7) << 52))
33 
34 #define PAGES_AND_TYPE(pages, type) \
35 		.region_size_type = DRTM_MEM_REGION_PAGES_AND_TYPE(pages, type)
36 
37 /* Opaque / encapsulated type. */
38 typedef struct drtm_dl_dma_prot_args_v1 drtm_dl_dma_prot_args_v1_t;
39 
40 bool drtm_dma_prot_init(void);
41 enum drtm_retc drtm_dma_prot_check_args(const drtm_dl_dma_prot_args_v1_t *a,
42 					int a_dma_prot_type,
43 					drtm_mem_region_t p);
44 enum drtm_retc drtm_dma_prot_engage(const drtm_dl_dma_prot_args_v1_t *a,
45 				    int a_dma_prot_type);
46 enum drtm_retc drtm_dma_prot_disengage(void);
47 uint64_t drtm_unprotect_mem(void *ctx);
48 void drtm_dma_prot_serialise_table(uint8_t *dst, size_t *size_out);
49 
50 #endif /* DRTM_DMA_PROT_H */
51