1 /* 2 * Copyright (c) 2022 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 enum drtm_retc { 35 SUCCESS = SMC_OK, 36 NOT_SUPPORTED = SMC_UNK, 37 INVALID_PARAMETERS = -2, 38 DENIED = -3, 39 NOT_FOUND = -4, 40 INTERNAL_ERROR = -5, 41 MEM_PROTECT_INVALID = -6, 42 }; 43 44 typedef struct { 45 uint64_t tpm_features; 46 uint64_t minimum_memory_requirement; 47 uint64_t dma_prot_features; 48 uint64_t boot_pe_id; 49 uint64_t tcb_hash_features; 50 } drtm_features_t; 51 52 struct __packed drtm_dl_args_v1 { 53 uint16_t version; /* Must be 1. */ 54 uint8_t __res[2]; 55 uint32_t features; 56 uint64_t dlme_paddr; 57 uint64_t dlme_size; 58 uint64_t dlme_img_off; 59 uint64_t dlme_img_ep_off; 60 uint64_t dlme_img_size; 61 uint64_t dlme_data_off; 62 uint64_t dce_nwd_paddr; 63 uint64_t dce_nwd_size; 64 drtm_dl_dma_prot_args_v1_t dma_prot_args; 65 } __aligned(__alignof(uint16_t /* First member's type, `uint16_t version' */)); 66 67 drtm_memory_region_descriptor_table_t *drtm_build_address_map(void); 68 uint64_t drtm_get_address_map_size(void); 69 70 /* 71 * Version-independent type. May be used to avoid excessive line of code 72 * changes when migrating to new struct versions. 73 */ 74 typedef struct drtm_dl_args_v1 struct_drtm_dl_args; 75 76 #endif /* DRTM_MAIN_H */ 77