blob: cccc14f968875622926fed570cb1096e9d69329a [file] [log] [blame]
Manish V Badarkhe8a766032022-02-23 11:26:53 +00001/*
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
Manish Pandeyfef989c2022-06-21 15:36:45 +010012#include <assert.h>
Manish V Badarkhe8a766032022-02-23 11:26:53 +000013#include <lib/smccc.h>
14
Manish V Badarkhecc2c7432022-02-24 20:22:39 +000015#include "drtm_dma_prot.h"
16
Manish Pandeyfef989c2022-06-21 15:36:45 +010017#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
Manish V Badarkhe19b22f92022-06-17 11:42:17 +010034#define DL_ARGS_GET_PCR_SCHEMA(a) (((a)->features >> 1) & 0x3U)
35#define DL_ARGS_GET_DLME_ENTRY_POINT(a) \
36 (((a)->dlme_paddr + (a)->dlme_img_off + (a)->dlme_img_ep_off))
37
Manish V Badarkhe8a766032022-02-23 11:26:53 +000038enum drtm_retc {
39 SUCCESS = SMC_OK,
40 NOT_SUPPORTED = SMC_UNK,
41 INVALID_PARAMETERS = -2,
42 DENIED = -3,
43 NOT_FOUND = -4,
44 INTERNAL_ERROR = -5,
45 MEM_PROTECT_INVALID = -6,
46};
47
johpow01baa3e6c2022-03-11 17:50:58 -060048typedef struct {
49 uint64_t tpm_features;
50 uint64_t minimum_memory_requirement;
51 uint64_t dma_prot_features;
52 uint64_t boot_pe_id;
53 uint64_t tcb_hash_features;
54} drtm_features_t;
55
Manish Pandeyfef989c2022-06-21 15:36:45 +010056struct __packed drtm_dl_args_v1 {
57 uint16_t version; /* Must be 1. */
58 uint8_t __res[2];
59 uint32_t features;
60 uint64_t dlme_paddr;
61 uint64_t dlme_size;
62 uint64_t dlme_img_off;
63 uint64_t dlme_img_ep_off;
64 uint64_t dlme_img_size;
65 uint64_t dlme_data_off;
66 uint64_t dce_nwd_paddr;
67 uint64_t dce_nwd_size;
68 drtm_dl_dma_prot_args_v1_t dma_prot_args;
69} __aligned(__alignof(uint16_t /* First member's type, `uint16_t version' */));
70
johpow01baa3e6c2022-03-11 17:50:58 -060071drtm_memory_region_descriptor_table_t *drtm_build_address_map(void);
72uint64_t drtm_get_address_map_size(void);
73
Manish Pandeyfef989c2022-06-21 15:36:45 +010074/*
75 * Version-independent type. May be used to avoid excessive line of code
76 * changes when migrating to new struct versions.
77 */
78typedef struct drtm_dl_args_v1 struct_drtm_dl_args;
79
Manish V Badarkhe8a766032022-02-23 11:26:53 +000080#endif /* DRTM_MAIN_H */