blob: cba1f63e989cf55cc84bf4b9cd933a654c3fa042 [file] [log] [blame] [edit]
/* SPDX-License-Identifier: GPL-2.0-only */
/*
* Copyright (C) 2022 - Google LLC
* Author: Andrew Walbran <qwandor@google.com>
*/
#ifndef __KVM_HYP_FFA_H
#define __KVM_HYP_FFA_H
#include <asm/kvm_host.h>
#include <nvhe/pkvm.h>
#include "trap_handler.h"
#define FFA_MIN_FUNC_NUM 0x60
#define FFA_MAX_FUNC_NUM 0x7F
/*
* "ID value 0 must be returned at the Non-secure physical FF-A instance"
* We share this ID with the host.
*/
#define HOST_FFA_ID 0
/*
* The maximum number of secure partitions.
*/
#define FFA_MAX_SPS 8
#define FFA_MSG_FLAGS_VM_CREATED 0x80000004
#define FFA_MSG_FLAGS_VM_DESTROYED 0x80000006
#define FFA_PROP_VM_EVENT_SUB (1 << 6)
enum kvm_ffa_vm_event_type { MSG_VM_CREATED, MSG_VM_DESTROYED };
int hyp_ffa_init(void *pages);
void hyp_ffa_post_rxtx_init(void);
bool kvm_host_ffa_handler(struct kvm_cpu_context *host_ctxt);
int kvm_guest_ffa_handler(struct pkvm_hyp_vcpu *hyp_vcpu, u64 *exit_code);
static inline bool is_ffa_call(u64 func_id)
{
return ARM_SMCCC_IS_FAST_CALL(func_id) &&
ARM_SMCCC_OWNER_NUM(func_id) == ARM_SMCCC_OWNER_STANDARD &&
ARM_SMCCC_FUNC_NUM(func_id) >= FFA_MIN_FUNC_NUM &&
ARM_SMCCC_FUNC_NUM(func_id) <= FFA_MAX_FUNC_NUM;
}
static inline bool is_ffa_error(struct kvm_vcpu *vcpu)
{
struct kvm_cpu_context *ctxt = &vcpu->arch.ctxt;
return (cpu_reg(ctxt, 0) == FFA_ERROR);
}
bool hyp_ffa_release_buffers(struct pkvm_hyp_vcpu *vcpu, int vmid, void *addr);
int queue_vm_messages(u16 vmid, enum kvm_ffa_vm_event_type event);
int guest_ffa_reclaim_memory(struct pkvm_hyp_vm *vm);
#endif /* __KVM_HYP_FFA_H */