1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * Copyright (C) 2023 ARM Ltd.
6 #ifndef __ASM_RSI_CMDS_H
7 #define __ASM_RSI_CMDS_H
9 #include <linux/arm-smccc.h>
11 #include <asm/rsi_smc.h>
13 #define RSI_GRANULE_SHIFT 12
14 #define RSI_GRANULE_SIZE (_AC(1, UL) << RSI_GRANULE_SHIFT)
19 RSI_RIPAS_DESTROYED
= 2,
23 static inline unsigned long rsi_request_version(unsigned long req
,
24 unsigned long *out_lower
,
25 unsigned long *out_higher
)
27 struct arm_smccc_res res
;
29 arm_smccc_smc(SMC_RSI_ABI_VERSION
, req
, 0, 0, 0, 0, 0, 0, &res
);
39 static inline unsigned long rsi_get_realm_config(struct realm_config
*cfg
)
41 struct arm_smccc_res res
;
43 arm_smccc_smc(SMC_RSI_REALM_CONFIG
, virt_to_phys(cfg
),
44 0, 0, 0, 0, 0, 0, &res
);
48 static inline unsigned long rsi_ipa_state_get(phys_addr_t start
,
53 struct arm_smccc_res res
;
55 arm_smccc_smc(SMC_RSI_IPA_STATE_GET
,
56 start
, end
, 0, 0, 0, 0, 0,
59 if (res
.a0
== RSI_SUCCESS
) {
69 static inline long rsi_set_addr_range_state(phys_addr_t start
,
75 struct arm_smccc_res res
;
77 arm_smccc_smc(SMC_RSI_IPA_STATE_SET
, start
, end
, state
,
78 flags
, 0, 0, 0, &res
);
83 if (res
.a2
!= RSI_ACCEPT
)
90 * rsi_attestation_token_init - Initialise the operation to retrieve an
93 * @challenge: The challenge data to be used in the attestation token
95 * @size: Size of the challenge data in bytes.
97 * Initialises the attestation token generation and returns an upper bound
98 * on the attestation token size that can be used to allocate an adequate
99 * buffer. The caller is expected to subsequently call
100 * rsi_attestation_token_continue() to retrieve the attestation token data on
104 * On success, returns the upper limit of the attestation report size.
108 rsi_attestation_token_init(const u8
*challenge
, unsigned long size
)
110 struct arm_smccc_1_2_regs regs
= { 0 };
112 /* The challenge must be at least 32bytes and at most 64bytes */
113 if (!challenge
|| size
< 32 || size
> 64)
116 regs
.a0
= SMC_RSI_ATTESTATION_TOKEN_INIT
;
117 memcpy(®s
.a1
, challenge
, size
);
118 arm_smccc_1_2_smc(®s
, ®s
);
120 if (regs
.a0
== RSI_SUCCESS
)
127 * rsi_attestation_token_continue - Continue the operation to retrieve an
130 * @granule: {I}PA of the Granule to which the token will be written.
131 * @offset: Offset within Granule to start of buffer in bytes.
132 * @size: The size of the buffer.
133 * @len: The number of bytes written to the buffer.
135 * Retrieves up to a RSI_GRANULE_SIZE worth of token data per call. The caller
136 * is expected to call rsi_attestation_token_init() before calling this
137 * function to retrieve the attestation token.
140 * * %RSI_SUCCESS - Attestation token retrieved successfully.
141 * * %RSI_INCOMPLETE - Token generation is not complete.
142 * * %RSI_ERROR_INPUT - A parameter was not valid.
143 * * %RSI_ERROR_STATE - Attestation not in progress.
145 static inline unsigned long rsi_attestation_token_continue(phys_addr_t granule
,
146 unsigned long offset
,
150 struct arm_smccc_res res
;
152 arm_smccc_1_1_invoke(SMC_RSI_ATTESTATION_TOKEN_CONTINUE
,
153 granule
, offset
, size
, 0, &res
);
160 #endif /* __ASM_RSI_CMDS_H */