blob: a7d053f1774cb8866917333d9feb54e29c2bd3ac [file] [log] [blame]
Manish V Badarkhe8a766032022-02-23 11:26:53 +00001/*
Stuart Yoder8ee38522024-01-09 17:51:38 -06002 * Copyright (c) 2022-2024 Arm Limited. All rights reserved.
Manish V Badarkhe8a766032022-02-23 11:26:53 +00003 *
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 Badarkhead035ce2022-06-21 18:08:50 +010034#define DL_ARGS_GET_DMA_PROT_TYPE(a) (((a)->features >> 3) & 0x7U)
Manish V Badarkhe19b22f92022-06-17 11:42:17 +010035#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
Manish V Badarkhe24cb9202022-09-21 10:04:16 +010039/*
40 * Range(Min/Max) of DRTM parameter structure versions supported
41 */
42#define ARM_DRTM_PARAMS_MIN_VERSION U(1)
43#define ARM_DRTM_PARAMS_MAX_VERSION U(1)
44
Manish Pandeycabcad52022-06-23 10:43:31 +010045enum drtm_dlme_el {
46 DLME_AT_EL1 = MODE_EL1,
47 DLME_AT_EL2 = MODE_EL2
48};
49
Manish V Badarkhe8a766032022-02-23 11:26:53 +000050enum drtm_retc {
51 SUCCESS = SMC_OK,
52 NOT_SUPPORTED = SMC_UNK,
53 INVALID_PARAMETERS = -2,
54 DENIED = -3,
55 NOT_FOUND = -4,
56 INTERNAL_ERROR = -5,
57 MEM_PROTECT_INVALID = -6,
Stuart Yoder8ee38522024-01-09 17:51:38 -060058 COPROCESSOR_ERROR = -7,
59 OUT_OF_RESOURCE = -8,
60 INVALID_DATA = -9,
61 SECONDARY_PE_NOT_OFF = -10,
62 ALREADY_CLOSED = -11,
63 TPM_ERROR = -12
Manish V Badarkhe8a766032022-02-23 11:26:53 +000064};
65
johpow01baa3e6c2022-03-11 17:50:58 -060066typedef struct {
67 uint64_t tpm_features;
68 uint64_t minimum_memory_requirement;
69 uint64_t dma_prot_features;
70 uint64_t boot_pe_id;
71 uint64_t tcb_hash_features;
72} drtm_features_t;
73
Manish Pandeyfef989c2022-06-21 15:36:45 +010074struct __packed drtm_dl_args_v1 {
Manish V Badarkhea28563e2022-06-22 13:11:14 +010075 uint16_t version; /* Must be 1. */
Manish Pandeyfef989c2022-06-21 15:36:45 +010076 uint8_t __res[2];
77 uint32_t features;
78 uint64_t dlme_paddr;
79 uint64_t dlme_size;
80 uint64_t dlme_img_off;
81 uint64_t dlme_img_ep_off;
82 uint64_t dlme_img_size;
83 uint64_t dlme_data_off;
84 uint64_t dce_nwd_paddr;
85 uint64_t dce_nwd_size;
86 drtm_dl_dma_prot_args_v1_t dma_prot_args;
87} __aligned(__alignof(uint16_t /* First member's type, `uint16_t version' */));
88
Manish V Badarkhea28563e2022-06-22 13:11:14 +010089struct __packed dlme_data_header_v1 {
90 uint16_t version; /* Must be 1. */
91 uint16_t this_hdr_size;
92 uint8_t __res[4];
93 uint64_t dlme_data_size;
94 uint64_t dlme_prot_regions_size;
95 uint64_t dlme_addr_map_size;
96 uint64_t dlme_tpm_log_size;
97 uint64_t dlme_tcb_hashes_table_size;
Stuart Yoderbb0d9c52024-01-10 14:10:45 -060098 uint64_t dlme_acpi_tables_region_size;
Manish V Badarkhea28563e2022-06-22 13:11:14 +010099 uint64_t dlme_impdef_region_size;
100} __aligned(__alignof(uint16_t /* First member's type, `uint16_t version'. */));
101
102typedef struct dlme_data_header_v1 struct_dlme_data_header;
103
johpow01baa3e6c2022-03-11 17:50:58 -0600104drtm_memory_region_descriptor_table_t *drtm_build_address_map(void);
105uint64_t drtm_get_address_map_size(void);
106
Manish Pandeyfef989c2022-06-21 15:36:45 +0100107/*
108 * Version-independent type. May be used to avoid excessive line of code
109 * changes when migrating to new struct versions.
110 */
111typedef struct drtm_dl_args_v1 struct_drtm_dl_args;
112
Manish V Badarkhe8a766032022-02-23 11:26:53 +0000113#endif /* DRTM_MAIN_H */