KVM
Macros | Functions
ffa.h File Reference
#include <asm/kvm_host.h>
Include dependency graph for ffa.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define FFA_MIN_FUNC_NUM   0x60
 
#define FFA_MAX_FUNC_NUM   0x7F
 

Functions

int hyp_ffa_init (void *pages)
 
bool kvm_host_ffa_handler (struct kvm_cpu_context *host_ctxt, u32 func_id)
 

Macro Definition Documentation

◆ FFA_MAX_FUNC_NUM

#define FFA_MAX_FUNC_NUM   0x7F

Definition at line 12 of file ffa.h.

◆ FFA_MIN_FUNC_NUM

#define FFA_MIN_FUNC_NUM   0x60

Definition at line 11 of file ffa.h.

Function Documentation

◆ hyp_ffa_init()

int hyp_ffa_init ( void *  pages)

Definition at line 700 of file ffa.c.

701 {
702  struct arm_smccc_res res;
703  size_t min_rxtx_sz;
704  void *tx, *rx;
705 
706  if (kvm_host_psci_config.smccc_version < ARM_SMCCC_VERSION_1_2)
707  return 0;
708 
709  arm_smccc_1_1_smc(FFA_VERSION, FFA_VERSION_1_0, 0, 0, 0, 0, 0, 0, &res);
710  if (res.a0 == FFA_RET_NOT_SUPPORTED)
711  return 0;
712 
713  /*
714  * Firmware returns the maximum supported version of the FF-A
715  * implementation. Check that the returned version is
716  * backwards-compatible with the hyp according to the rules in DEN0077A
717  * v1.1 REL0 13.2.1.
718  *
719  * Of course, things are never simple when dealing with firmware. v1.1
720  * broke ABI with v1.0 on several structures, which is itself
721  * incompatible with the aforementioned versioning scheme. The
722  * expectation is that v1.x implementations that do not support the v1.0
723  * ABI return NOT_SUPPORTED rather than a version number, according to
724  * DEN0077A v1.1 REL0 18.6.4.
725  */
726  if (FFA_MAJOR_VERSION(res.a0) != 1)
727  return -EOPNOTSUPP;
728 
729  arm_smccc_1_1_smc(FFA_ID_GET, 0, 0, 0, 0, 0, 0, 0, &res);
730  if (res.a0 != FFA_SUCCESS)
731  return -EOPNOTSUPP;
732 
733  if (res.a2 != HOST_FFA_ID)
734  return -EINVAL;
735 
736  arm_smccc_1_1_smc(FFA_FEATURES, FFA_FN64_RXTX_MAP,
737  0, 0, 0, 0, 0, 0, &res);
738  if (res.a0 != FFA_SUCCESS)
739  return -EOPNOTSUPP;
740 
741  switch (res.a2) {
742  case FFA_FEAT_RXTX_MIN_SZ_4K:
743  min_rxtx_sz = SZ_4K;
744  break;
745  case FFA_FEAT_RXTX_MIN_SZ_16K:
746  min_rxtx_sz = SZ_16K;
747  break;
748  case FFA_FEAT_RXTX_MIN_SZ_64K:
749  min_rxtx_sz = SZ_64K;
750  break;
751  default:
752  return -EINVAL;
753  }
754 
755  if (min_rxtx_sz > PAGE_SIZE)
756  return -EOPNOTSUPP;
757 
758  tx = pages;
759  pages += KVM_FFA_MBOX_NR_PAGES * PAGE_SIZE;
760  rx = pages;
761  pages += KVM_FFA_MBOX_NR_PAGES * PAGE_SIZE;
762 
764  .buf = pages,
765  .len = PAGE_SIZE *
766  (hyp_ffa_proxy_pages() - (2 * KVM_FFA_MBOX_NR_PAGES)),
767  };
768 
769  hyp_buffers = (struct kvm_ffa_buffers) {
771  .tx = tx,
772  .rx = rx,
773  };
774 
775  host_buffers = (struct kvm_ffa_buffers) {
777  };
778 
779  return 0;
780 }
#define HOST_FFA_ID
Definition: ffa.c:43
static struct kvm_ffa_buffers host_buffers
Definition: ffa.c:69
static struct kvm_ffa_buffers hyp_buffers
Definition: ffa.c:68
static struct kvm_ffa_descriptor_buffer ffa_desc_buf
Definition: ffa.c:55
struct kvm_host_psci_config __ro_after_init kvm_host_psci_config
Definition: psci-relay.c:23
#define __HYP_SPIN_LOCK_UNLOCKED
Definition: spinlock.h:34
void * tx
Definition: ffa.c:59
hyp_spinlock_t lock
Definition: ffa.c:58
void * rx
Definition: ffa.c:60
Here is the caller graph for this function:

◆ kvm_host_ffa_handler()

bool kvm_host_ffa_handler ( struct kvm_cpu_context *  host_ctxt,
u32  func_id 
)

Definition at line 643 of file ffa.c.

644 {
645  struct arm_smccc_res res;
646 
647  /*
648  * There's no way we can tell what a non-standard SMC call might
649  * be up to. Ideally, we would terminate these here and return
650  * an error to the host, but sadly devices make use of custom
651  * firmware calls for things like power management, debugging,
652  * RNG access and crash reporting.
653  *
654  * Given that the architecture requires us to trust EL3 anyway,
655  * we forward unrecognised calls on under the assumption that
656  * the firmware doesn't expose a mechanism to access arbitrary
657  * non-secure memory. Short of a per-device table of SMCs, this
658  * is the best we can do.
659  */
660  if (!is_ffa_call(func_id))
661  return false;
662 
663  switch (func_id) {
664  case FFA_FEATURES:
665  if (!do_ffa_features(&res, host_ctxt))
666  return false;
667  goto out_handled;
668  /* Memory management */
669  case FFA_FN64_RXTX_MAP:
670  do_ffa_rxtx_map(&res, host_ctxt);
671  goto out_handled;
672  case FFA_RXTX_UNMAP:
673  do_ffa_rxtx_unmap(&res, host_ctxt);
674  goto out_handled;
675  case FFA_MEM_SHARE:
676  case FFA_FN64_MEM_SHARE:
677  do_ffa_mem_xfer(FFA_FN64_MEM_SHARE, &res, host_ctxt);
678  goto out_handled;
679  case FFA_MEM_RECLAIM:
680  do_ffa_mem_reclaim(&res, host_ctxt);
681  goto out_handled;
682  case FFA_MEM_LEND:
683  case FFA_FN64_MEM_LEND:
684  do_ffa_mem_xfer(FFA_FN64_MEM_LEND, &res, host_ctxt);
685  goto out_handled;
686  case FFA_MEM_FRAG_TX:
687  do_ffa_mem_frag_tx(&res, host_ctxt);
688  goto out_handled;
689  }
690 
691  if (ffa_call_supported(func_id))
692  return false; /* Pass through */
693 
694  ffa_to_smccc_error(&res, FFA_RET_NOT_SUPPORTED);
695 out_handled:
696  ffa_set_retval(host_ctxt, &res);
697  return true;
698 }
static bool do_ffa_features(struct arm_smccc_res *res, struct kvm_cpu_context *ctxt)
Definition: ffa.c:614
static void ffa_to_smccc_error(struct arm_smccc_res *res, u64 ffa_errno)
Definition: ffa.c:71
static void do_ffa_rxtx_map(struct arm_smccc_res *res, struct kvm_cpu_context *ctxt)
Definition: ffa.c:180
static void ffa_set_retval(struct kvm_cpu_context *ctxt, struct arm_smccc_res *res)
Definition: ffa.c:94
static void do_ffa_mem_reclaim(struct arm_smccc_res *res, struct kvm_cpu_context *ctxt)
Definition: ffa.c:504
static __always_inline void do_ffa_mem_xfer(const u64 func_id, struct arm_smccc_res *res, struct kvm_cpu_context *ctxt)
Definition: ffa.c:418
static void do_ffa_rxtx_unmap(struct arm_smccc_res *res, struct kvm_cpu_context *ctxt)
Definition: ffa.c:259
static void do_ffa_mem_frag_tx(struct arm_smccc_res *res, struct kvm_cpu_context *ctxt)
Definition: ffa.c:360
static bool ffa_call_supported(u64 func_id)
Definition: ffa.c:587
static bool is_ffa_call(u64 func_id)
Definition: ffa.c:103
Here is the call graph for this function:
Here is the caller graph for this function: