1 /* 2 * Copyright 2021 The Hafnium Authors. 3 * 4 * Use of this source code is governed by a BSD-style 5 * license that can be found in the LICENSE file or at 6 * https://opensource.org/licenses/BSD-3-Clause. 7 */ 8 9 #include "hf/ffa.h" 10 11 #include "hf/check.h" 12 #include "hf/ffa/setup_and_discovery.h" 13 #include "hf/panic.h" 14 #include "hf/vm_ids.h" 15 16 #include "smc.h" 17 18 static ffa_id_t spmc_id = HF_INVALID_VM_ID; 19 20 /** 21 * Returns the SPMC ID returned from the SPMD. 22 */ arch_ffa_spmc_id_get(void)23ffa_id_t arch_ffa_spmc_id_get(void) 24 { 25 return spmc_id; 26 } 27 28 /** 29 * Initialize the platform FF-A module in the context of running the SPMC. 30 * In particular it fetches the SPMC ID to prevent SMC calls everytime 31 * FFA_SPM_ID_GET is invoked. 32 */ arch_ffa_init(void)33void arch_ffa_init(void) 34 { 35 struct ffa_value ret = ffa_setup_spmc_id_get(); 36 37 if (ret.func == FFA_SUCCESS_32) { 38 spmc_id = ret.arg2; 39 } else if (ret.func == (uint64_t)SMCCC_ERROR_UNKNOWN || 40 (ret.func == FFA_ERROR_32 && 41 ffa_error_code(ret) == FFA_NOT_SUPPORTED)) { 42 spmc_id = HF_SPMC_VM_ID; 43 } else { 44 panic("Failed to get SPMC ID\n"); 45 } 46 47 /* 48 * Check that spmc_id is equal to HF_SPMC_VM_ID. 49 */ 50 CHECK(spmc_id == HF_SPMC_VM_ID); 51 } 52