2024-10-17 14:14:24 +01:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0-only */
|
|
|
|
/*
|
|
|
|
* Copyright (C) 2023 ARM Ltd.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __ASM_RSI_CMDS_H
|
|
|
|
#define __ASM_RSI_CMDS_H
|
|
|
|
|
|
|
|
#include <linux/arm-smccc.h>
|
2025-04-17 13:26:16 -03:00
|
|
|
#include <linux/string.h>
|
|
|
|
#include <asm/memory.h>
|
2024-10-17 14:14:24 +01:00
|
|
|
|
|
|
|
#include <asm/rsi_smc.h>
|
|
|
|
|
|
|
|
#define RSI_GRANULE_SHIFT 12
|
|
|
|
#define RSI_GRANULE_SIZE (_AC(1, UL) << RSI_GRANULE_SHIFT)
|
|
|
|
|
|
|
|
enum ripas {
|
|
|
|
RSI_RIPAS_EMPTY = 0,
|
|
|
|
RSI_RIPAS_RAM = 1,
|
|
|
|
RSI_RIPAS_DESTROYED = 2,
|
|
|
|
RSI_RIPAS_DEV = 3,
|
|
|
|
};
|
|
|
|
|
|
|
|
static inline unsigned long rsi_request_version(unsigned long req,
|
|
|
|
unsigned long *out_lower,
|
|
|
|
unsigned long *out_higher)
|
|
|
|
{
|
|
|
|
struct arm_smccc_res res;
|
|
|
|
|
|
|
|
arm_smccc_smc(SMC_RSI_ABI_VERSION, req, 0, 0, 0, 0, 0, 0, &res);
|
|
|
|
|
|
|
|
if (out_lower)
|
|
|
|
*out_lower = res.a1;
|
|
|
|
if (out_higher)
|
|
|
|
*out_higher = res.a2;
|
|
|
|
|
|
|
|
return res.a0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline unsigned long rsi_get_realm_config(struct realm_config *cfg)
|
|
|
|
{
|
|
|
|
struct arm_smccc_res res;
|
|
|
|
|
|
|
|
arm_smccc_smc(SMC_RSI_REALM_CONFIG, virt_to_phys(cfg),
|
|
|
|
0, 0, 0, 0, 0, 0, &res);
|
|
|
|
return res.a0;
|
|
|
|
}
|
|
|
|
|
arm64: rsi: Add support for checking whether an MMIO is protected
On Arm CCA, with RMM-v1.0, all MMIO regions are shared. However, in
the future, an Arm CCA-v1.0 compliant guest may be run in a lesser
privileged partition in the Realm World (with Arm CCA-v1.1 Planes
feature). In this case, some of the MMIO regions may be emulated
by a higher privileged component in the Realm world, i.e, protected.
Thus the guest must decide today, whether a given MMIO region is shared
vs Protected and create the stage1 mapping accordingly. On Arm CCA, this
detection is based on the "IPA State" (RIPAS == RIPAS_IO). Provide a
helper to run this check on a given range of MMIO.
Also, provide a arm64 helper which may be hooked in by other solutions.
Reviewed-by: Catalin Marinas <catalin.marinas@arm.com>
Reviewed-by: Gavin Shan <gshan@redhat.com>
Signed-off-by: Suzuki K Poulose <suzuki.poulose@arm.com>
Signed-off-by: Steven Price <steven.price@arm.com>
Link: https://lore.kernel.org/r/20241017131434.40935-5-steven.price@arm.com
Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
2024-10-17 14:14:27 +01:00
|
|
|
static inline unsigned long rsi_ipa_state_get(phys_addr_t start,
|
|
|
|
phys_addr_t end,
|
|
|
|
enum ripas *state,
|
|
|
|
phys_addr_t *top)
|
|
|
|
{
|
|
|
|
struct arm_smccc_res res;
|
|
|
|
|
|
|
|
arm_smccc_smc(SMC_RSI_IPA_STATE_GET,
|
|
|
|
start, end, 0, 0, 0, 0, 0,
|
|
|
|
&res);
|
|
|
|
|
|
|
|
if (res.a0 == RSI_SUCCESS) {
|
|
|
|
if (top)
|
|
|
|
*top = res.a1;
|
|
|
|
if (state)
|
|
|
|
*state = res.a2;
|
|
|
|
}
|
|
|
|
|
|
|
|
return res.a0;
|
|
|
|
}
|
|
|
|
|
2024-10-17 14:14:24 +01:00
|
|
|
static inline long rsi_set_addr_range_state(phys_addr_t start,
|
|
|
|
phys_addr_t end,
|
|
|
|
enum ripas state,
|
|
|
|
unsigned long flags,
|
|
|
|
phys_addr_t *top)
|
|
|
|
{
|
|
|
|
struct arm_smccc_res res;
|
|
|
|
|
|
|
|
arm_smccc_smc(SMC_RSI_IPA_STATE_SET, start, end, state,
|
|
|
|
flags, 0, 0, 0, &res);
|
|
|
|
|
|
|
|
if (top)
|
|
|
|
*top = res.a1;
|
|
|
|
|
|
|
|
if (res.a2 != RSI_ACCEPT)
|
|
|
|
return -EPERM;
|
|
|
|
|
|
|
|
return res.a0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* rsi_attestation_token_init - Initialise the operation to retrieve an
|
|
|
|
* attestation token.
|
|
|
|
*
|
|
|
|
* @challenge: The challenge data to be used in the attestation token
|
|
|
|
* generation.
|
|
|
|
* @size: Size of the challenge data in bytes.
|
|
|
|
*
|
|
|
|
* Initialises the attestation token generation and returns an upper bound
|
|
|
|
* on the attestation token size that can be used to allocate an adequate
|
|
|
|
* buffer. The caller is expected to subsequently call
|
|
|
|
* rsi_attestation_token_continue() to retrieve the attestation token data on
|
|
|
|
* the same CPU.
|
|
|
|
*
|
|
|
|
* Returns:
|
|
|
|
* On success, returns the upper limit of the attestation report size.
|
|
|
|
* Otherwise, -EINVAL
|
|
|
|
*/
|
|
|
|
static inline long
|
|
|
|
rsi_attestation_token_init(const u8 *challenge, unsigned long size)
|
|
|
|
{
|
|
|
|
struct arm_smccc_1_2_regs regs = { 0 };
|
|
|
|
|
|
|
|
/* The challenge must be at least 32bytes and at most 64bytes */
|
|
|
|
if (!challenge || size < 32 || size > 64)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
regs.a0 = SMC_RSI_ATTESTATION_TOKEN_INIT;
|
|
|
|
memcpy(®s.a1, challenge, size);
|
|
|
|
arm_smccc_1_2_smc(®s, ®s);
|
|
|
|
|
|
|
|
if (regs.a0 == RSI_SUCCESS)
|
|
|
|
return regs.a1;
|
|
|
|
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* rsi_attestation_token_continue - Continue the operation to retrieve an
|
|
|
|
* attestation token.
|
|
|
|
*
|
|
|
|
* @granule: {I}PA of the Granule to which the token will be written.
|
|
|
|
* @offset: Offset within Granule to start of buffer in bytes.
|
|
|
|
* @size: The size of the buffer.
|
|
|
|
* @len: The number of bytes written to the buffer.
|
|
|
|
*
|
|
|
|
* Retrieves up to a RSI_GRANULE_SIZE worth of token data per call. The caller
|
|
|
|
* is expected to call rsi_attestation_token_init() before calling this
|
|
|
|
* function to retrieve the attestation token.
|
|
|
|
*
|
|
|
|
* Return:
|
|
|
|
* * %RSI_SUCCESS - Attestation token retrieved successfully.
|
|
|
|
* * %RSI_INCOMPLETE - Token generation is not complete.
|
|
|
|
* * %RSI_ERROR_INPUT - A parameter was not valid.
|
|
|
|
* * %RSI_ERROR_STATE - Attestation not in progress.
|
|
|
|
*/
|
|
|
|
static inline unsigned long rsi_attestation_token_continue(phys_addr_t granule,
|
|
|
|
unsigned long offset,
|
|
|
|
unsigned long size,
|
|
|
|
unsigned long *len)
|
|
|
|
{
|
|
|
|
struct arm_smccc_res res;
|
|
|
|
|
|
|
|
arm_smccc_1_1_invoke(SMC_RSI_ATTESTATION_TOKEN_CONTINUE,
|
|
|
|
granule, offset, size, 0, &res);
|
|
|
|
|
|
|
|
if (len)
|
|
|
|
*len = res.a1;
|
|
|
|
return res.a0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* __ASM_RSI_CMDS_H */
|