From 9d1724c3d495d4462e7b0f3c4f8352556b53f435 Mon Sep 17 00:00:00 2001 From: Arunachalam Ganapathy Date: Thu, 15 Apr 2021 11:00:55 +0100 Subject: [PATCH] arm-bsp/tc0: Update hafnium revision and add patches - Remove PSCI patches as those changes are upstreamed - Adds Theodul, GICR changes - Reverts FFA Set and verify allocator fix - Adds fix to fetch proper vCPU for UP SP Signed-off-by: Arunachalam Ganapathy Change-Id: I26a7b31558e5bc4ce2fea61b76a3a92615f3e641 --- ...condary-core-entry-point-at-SPMC-ini.patch | 276 ------------------ ...nd-verify-allocator-of-memory-handle.patch | 256 ++++++++++++++++ ...A-Cold-boot-and-wake-up-from-suspend.patch | 95 ------ ...to-fetch-proper-vCPU-index-for-UP-SP.patch | 99 +++++++ ...-A-Respond-to-PSCI_CPU_OFF-from-SPMD.patch | 115 -------- ...ch => 0003-tc0-Theodul-GICR-changes.patch} | 18 +- .../recipes-bsp/hafnium/hafnium-tc0.inc | 9 +- 7 files changed, 369 insertions(+), 499 deletions(-) delete mode 100644 meta-arm-bsp/recipes-bsp/hafnium/files/tc0/0001-FF-A-Register-secondary-core-entry-point-at-SPMC-ini.patch create mode 100644 meta-arm-bsp/recipes-bsp/hafnium/files/tc0/0001-Revert-FFA-Set-and-verify-allocator-of-memory-handle.patch delete mode 100644 meta-arm-bsp/recipes-bsp/hafnium/files/tc0/0002-FF-A-Cold-boot-and-wake-up-from-suspend.patch create mode 100644 meta-arm-bsp/recipes-bsp/hafnium/files/tc0/0002-FF-A-Fix-to-fetch-proper-vCPU-index-for-UP-SP.patch delete mode 100644 meta-arm-bsp/recipes-bsp/hafnium/files/tc0/0003-FF-A-Respond-to-PSCI_CPU_OFF-from-SPMD.patch rename meta-arm-bsp/recipes-bsp/hafnium/files/tc0/{0004-tc0-Add-Theodul-DSU-support.patch => 0003-tc0-Theodul-GICR-changes.patch} (59%) diff --git a/meta-arm-bsp/recipes-bsp/hafnium/files/tc0/0001-FF-A-Register-secondary-core-entry-point-at-SPMC-ini.patch b/meta-arm-bsp/recipes-bsp/hafnium/files/tc0/0001-FF-A-Register-secondary-core-entry-point-at-SPMC-ini.patch deleted file mode 100644 index f2219d0a..00000000 --- a/meta-arm-bsp/recipes-bsp/hafnium/files/tc0/0001-FF-A-Register-secondary-core-entry-point-at-SPMC-ini.patch +++ /dev/null @@ -1,276 +0,0 @@ -Upstream-Status: Pending [https://review.trustedfirmware.org/c/hafnium/hafnium/+/6009/27] -Signed-off-by: Arunachalam Ganapathy - -From 06e7602ddb383e0f88c19feaa216c24cf032a136 Mon Sep 17 00:00:00 2001 -From: Max Shvetsov -Date: Thu, 27 Aug 2020 12:37:57 +0100 -Subject: [PATCH 2/5] FF-A: Register secondary core entry point at SPMC init. - -When the primary physical core boots the SPMC registers its secondary -physical core entry points to the SPMD. All Secure Partition are then -initialized on their primary Execution Contexts. A Secure Partition -calls PSCI_CPU_ON from its first EC (trapped to the SPMC) passing -entry point addresses of secondary ECs. ECs are turned "on" in their -SPMC internal states, although they do not run yet (the service call -does not reach the EL3 PSCI layer). Later, when the NWd (Hypervisor -or OS Kernel) boots, it calls PSCI_CPU_ON for waking up physical cores -down to EL3. The PSCI layer calls into SPMD PM hooks, then the SPMD -calls into the SPMC by an exception return to the registered secondary -entry point. The target secondary core then reaches Hafnium vcpu_main. - -Change-Id: I2bd42ea54e1a7feebff20e878345ec196ff352e9 -Signed-off-by: Max Shvetsov -Signed-off-by: Olivier Deprez ---- - inc/hf/arch/init.h | 7 ++++ - inc/hf/arch/other_world.h | 2 ++ - src/arch/aarch64/hypervisor/other_world.c | 29 +++++++++++++++ - src/arch/aarch64/hypervisor/psci_handler.c | 40 +++++++++++++++++++++ - src/arch/aarch64/inc/hf/arch/spmd_helpers.h | 15 ++++++++ - src/cpu.c | 2 +- - src/init.c | 2 ++ - src/load.c | 3 ++ - src/main.c | 12 ++++--- - 9 files changed, 106 insertions(+), 6 deletions(-) - create mode 100644 src/arch/aarch64/inc/hf/arch/spmd_helpers.h - -diff --git a/inc/hf/arch/init.h b/inc/hf/arch/init.h -index 5205e4e..ef0e48f 100644 ---- a/inc/hf/arch/init.h -+++ b/inc/hf/arch/init.h -@@ -8,6 +8,8 @@ - - #pragma once - -+#include "hf/boot_params.h" -+ - /** - * Performs arch specific boot time initialization. - * -@@ -15,3 +17,8 @@ - * possible. - */ - void arch_one_time_init(void); -+ -+/** -+ * Sets up secondary cores. -+ */ -+void arch_psci_secondary_core_init(const struct boot_params *params); -diff --git a/inc/hf/arch/other_world.h b/inc/hf/arch/other_world.h -index 68c0b45..860a142 100644 ---- a/inc/hf/arch/other_world.h -+++ b/inc/hf/arch/other_world.h -@@ -20,3 +20,5 @@ bool arch_other_world_is_direct_request_valid(struct vcpu *current, - bool arch_other_world_is_direct_response_valid(struct vcpu *current, - ffa_vm_id_t sender_vm_id, - ffa_vm_id_t receiver_vm_id); -+void arch_other_world_init_ffa_id(void); -+ffa_vm_id_t arch_other_world_get_ffa_id(void); -diff --git a/src/arch/aarch64/hypervisor/other_world.c b/src/arch/aarch64/hypervisor/other_world.c -index 74a2bb1..6b5bb16 100644 ---- a/src/arch/aarch64/hypervisor/other_world.c -+++ b/src/arch/aarch64/hypervisor/other_world.c -@@ -23,6 +23,10 @@ - alignas(PAGE_SIZE) static uint8_t other_world_send_buffer[HF_MAILBOX_SIZE]; - alignas(PAGE_SIZE) static uint8_t other_world_recv_buffer[HF_MAILBOX_SIZE]; - -+#else -+ -+static ffa_vm_id_t physical_ffa_id; -+ - #endif - - void arch_other_world_init(void) -@@ -181,3 +185,28 @@ struct ffa_value arch_other_world_call(struct ffa_value args) - { - return smc_ffa_call(args); - } -+ -+#if SECURE_WORLD == 1 -+ -+ffa_vm_id_t arch_other_world_get_ffa_id(void) -+{ -+ return physical_ffa_id; -+} -+ -+void arch_other_world_init_ffa_id(void) -+{ -+ struct ffa_value res = -+ smc_ffa_call((struct ffa_value){.func = FFA_ID_GET_32}); -+ -+ if (res.func != FFA_SUCCESS_32) { -+ dlog_error("%s Failed to get SPMC's FFA-ID from SPMD.\n", -+ __func__); -+ physical_ffa_id = HF_INVALID_VM_ID; -+ return; -+ } -+ physical_ffa_id = res.arg2 & 0xFFFF; -+ -+ CHECK(physical_ffa_id == HF_TEE_VM_ID); -+} -+ -+#endif -diff --git a/src/arch/aarch64/hypervisor/psci_handler.c b/src/arch/aarch64/hypervisor/psci_handler.c -index f89a00b..b323faa 100644 ---- a/src/arch/aarch64/hypervisor/psci_handler.c -+++ b/src/arch/aarch64/hypervisor/psci_handler.c -@@ -10,10 +10,13 @@ - - #include - -+#include "hf/arch/other_world.h" - #include "hf/arch/plat/psci.h" -+#include "hf/arch/spmd_helpers.h" - #include "hf/arch/types.h" - - #include "hf/api.h" -+#include "hf/boot_params.h" - #include "hf/cpu.h" - #include "hf/dlog.h" - #include "hf/ffa.h" -@@ -53,6 +56,41 @@ void arch_one_time_init(void) - } - #else - el3_psci_version = PSCI_VERSION_1_1; -+ -+ arch_other_world_init_ffa_id(); -+#endif -+} -+ -+/** -+ * Register secondary physical core entry points to the SPMD. -+ */ -+void arch_psci_secondary_core_init(const struct boot_params *params) -+{ -+#if SECURE_WORLD == 1 -+ struct ffa_value res; -+ -+ for (uint32_t count = 0; count < params->cpu_count; count++) { -+ uint32_t id = params->cpu_ids[count]; -+ struct cpu *cpu = cpu_find(id); -+ const ffa_vm_id_t ffa_id = arch_other_world_get_ffa_id(); -+ -+ res = smc_ffa_call((struct ffa_value){ -+ .func = FFA_MSG_SEND_DIRECT_REQ_32, -+ .arg1 = ((uint64_t)ffa_id << 16) | SPMD_ID, -+ .arg3 = SPMD_DIRECT_MSG_SET_ENTRY_POINT, -+ .arg4 = params->cpu_ids[count], -+ .arg5 = (uintreg_t)&cpu_entry, -+ .arg6 = (uintreg_t)cpu}); -+ -+ if (res.func != FFA_SUCCESS_32) { -+ dlog_warning( -+ "%s Failed to initialize secondary core ID: " -+ "%u\n", -+ __func__, id); -+ } -+ -+ dlog_verbose("SPMD EP register returned %#x\n", res.func); -+ } - #endif - } - -@@ -353,11 +391,13 @@ bool psci_secondary_vm_handler(struct vcpu *vcpu, uint32_t func, uintreg_t arg0, - - if (vcpu_secondary_reset_and_start( - target_vcpu, entry_point_address, context_id)) { -+#if SECURE_WORLD == 0 - /* - * Tell the scheduler that it can start running the new - * vCPU now. - */ - *next = api_wake_up(vcpu, target_vcpu); -+#endif - *ret = PSCI_RETURN_SUCCESS; - } else { - *ret = PSCI_ERROR_ALREADY_ON; -diff --git a/src/arch/aarch64/inc/hf/arch/spmd_helpers.h b/src/arch/aarch64/inc/hf/arch/spmd_helpers.h -new file mode 100644 -index 0000000..6e11c36 ---- /dev/null -+++ b/src/arch/aarch64/inc/hf/arch/spmd_helpers.h -@@ -0,0 +1,15 @@ -+/* -+ * Copyright 2020 The Hafnium Authors. -+ * -+ * Use of this source code is governed by a BSD-style -+ * license that can be found in the LICENSE file or at -+ * https://opensource.org/licenses/BSD-3-Clause. -+ */ -+ -+#define SPMD_ID 0xFFFF -+#define SPMD_DIRECT_MSG_SET_ENTRY_POINT 1 -+ -+/** -+ * Get SPMC ID stored in the manifest. -+ */ -+ffa_vm_id_t get_ffa_id(void); -diff --git a/src/cpu.c b/src/cpu.c -index 0a3fc6f..0e0ee9a 100644 ---- a/src/cpu.c -+++ b/src/cpu.c -@@ -138,7 +138,7 @@ bool cpu_on(struct cpu *c, ipaddr_t entry, uintreg_t arg) - c->is_on = true; - sl_unlock(&c->lock); - -- if (!prev) { -+ if (!prev && vm_id_is_current_world(HF_PRIMARY_VM_ID)) { - struct vm *vm = vm_find(HF_PRIMARY_VM_ID); - struct vcpu *vcpu = vm_get_vcpu(vm, cpu_index(c)); - struct vcpu_locked vcpu_locked; -diff --git a/src/init.c b/src/init.c -index a5b48ab..0121213 100644 ---- a/src/init.c -+++ b/src/init.c -@@ -146,6 +146,8 @@ void one_time_init(void) - - cpu_module_init(params.cpu_ids, params.cpu_count); - -+ arch_psci_secondary_core_init(¶ms); -+ - /* Load all VMs. */ - update.reserved_ranges_count = 0; - if (!load_vms(mm_stage1_locked, &manifest, &cpio, ¶ms, &update, -diff --git a/src/load.c b/src/load.c -index 660d77c..7accc65 100644 ---- a/src/load.c -+++ b/src/load.c -@@ -286,6 +286,9 @@ static bool load_primary(struct mm_stage1_locked stage1_locked, - dlog_info("Loaded primary VM with %u vCPUs, entry at %#x.\n", - vm->vcpu_count, pa_addr(primary_begin)); - -+ /* Mark the primary to be the first booted VM */ -+ vm_update_boot(vm); -+ - vcpu_locked = vcpu_lock(vm_get_vcpu(vm, 0)); - vcpu_on(vcpu_locked, primary_entry, params->kernel_arg); - vcpu_unlock(&vcpu_locked); -diff --git a/src/main.c b/src/main.c -index 5f30aac..3cc932e 100644 ---- a/src/main.c -+++ b/src/main.c -@@ -15,14 +15,16 @@ - */ - struct vcpu *cpu_main(struct cpu *c) - { -+ struct vm *first_boot; - struct vcpu *vcpu; --#if SECURE_WORLD == 1 -- struct vm *first_boot = vm_get_first_boot(); -+ -+ /* -+ * This returns the PVM in the normal worls and the first -+ * booted Secure Partition in the secure world. -+ */ -+ first_boot = vm_get_first_boot(); - - vcpu = vm_get_vcpu(first_boot, cpu_index(c)); --#else -- vcpu = vm_get_vcpu(vm_find(HF_PRIMARY_VM_ID), cpu_index(c)); --#endif - - vcpu->cpu = c; - --- -2.29.2 - diff --git a/meta-arm-bsp/recipes-bsp/hafnium/files/tc0/0001-Revert-FFA-Set-and-verify-allocator-of-memory-handle.patch b/meta-arm-bsp/recipes-bsp/hafnium/files/tc0/0001-Revert-FFA-Set-and-verify-allocator-of-memory-handle.patch new file mode 100644 index 00000000..dcf7725d --- /dev/null +++ b/meta-arm-bsp/recipes-bsp/hafnium/files/tc0/0001-Revert-FFA-Set-and-verify-allocator-of-memory-handle.patch @@ -0,0 +1,256 @@ +From 7a8b0d634b23e77bb6c84f1b34c5cc031aa8c105 Mon Sep 17 00:00:00 2001 +From: Arunachalam Ganapathy +Date: Mon, 12 Apr 2021 10:08:29 +0100 +Subject: [PATCH 1/3] Revert "FFA: Set and verify allocator of memory handle" + +This reverts commit 917d2f2dc46b20625156e9067329e04c7fec587d. +Reverting this commit enables memory sharing between SPs + +Upstream-Status: Inappropriate [will not be submitted as its only required for ACK 5.4] +--- + inc/hf/arch/ffa_memory_handle.h | 25 ---------------- + inc/vmapi/hf/ffa.h | 14 ++++----- + src/api.c | 4 +-- + src/arch/aarch64/hypervisor/BUILD.gn | 1 - + .../aarch64/hypervisor/ffa_memory_handle.c | 29 ------------------- + src/arch/fake/hypervisor/BUILD.gn | 1 - + src/arch/fake/hypervisor/ffa_memory_handle.c | 20 ------------- + src/ffa_memory.c | 19 ++++-------- + 8 files changed, 14 insertions(+), 99 deletions(-) + delete mode 100644 inc/hf/arch/ffa_memory_handle.h + delete mode 100644 src/arch/aarch64/hypervisor/ffa_memory_handle.c + delete mode 100644 src/arch/fake/hypervisor/ffa_memory_handle.c + +diff --git a/inc/hf/arch/ffa_memory_handle.h b/inc/hf/arch/ffa_memory_handle.h +deleted file mode 100644 +index 9eba5d4..0000000 +--- a/inc/hf/arch/ffa_memory_handle.h ++++ /dev/null +@@ -1,25 +0,0 @@ +-/* +- * Copyright 2021 The Hafnium Authors. +- * +- * Use of this source code is governed by a BSD-style +- * license that can be found in the LICENSE file or at +- * https://opensource.org/licenses/BSD-3-Clause. +- */ +- +-#ifndef FFA_MEMORY_HANDLE_H +-#define FFA_MEMORY_HANDLE_H +- +-#include "hf/ffa.h" +- +-/** +- * Encodes memory handle according to section 5.10.2 of the FF-A v1.0 spec. +- */ +-ffa_memory_handle_t ffa_memory_handle_make(uint64_t index); +- +-/** +- * Checks whether given handle was allocated by current world, according to +- * handle encoding rules. +- */ +-bool ffa_memory_handle_allocated_by_current_world(ffa_memory_handle_t handle); +- +-#endif +diff --git a/inc/vmapi/hf/ffa.h b/inc/vmapi/hf/ffa.h +index a79f2eb..a948930 100644 +--- a/inc/vmapi/hf/ffa.h ++++ b/inc/vmapi/hf/ffa.h +@@ -189,23 +189,21 @@ ATTR_FUNCTION_SET(memory_shareability, ffa_memory_attributes_t, + ATTR_FUNCTION_GET(memory_shareability, ffa_memory_attributes_t, + FFA_MEMORY_SHAREABILITY_OFFSET, FFA_MEMORY_SHAREABILITY_MASK) + +-/** +- * A globally-unique ID assigned by the hypervisor for a region of memory being +- * sent between VMs. +- */ +-typedef uint64_t ffa_memory_handle_t; +- + #define FFA_MEMORY_HANDLE_ALLOCATOR_MASK \ + ((ffa_memory_handle_t)(UINT64_C(1) << 63)) + #define FFA_MEMORY_HANDLE_ALLOCATOR_HYPERVISOR \ + ((ffa_memory_handle_t)(UINT64_C(1) << 63)) +- +-#define FFA_MEMORY_HANDLE_ALLOCATOR_SPMC (UINT64_C(0) << 63) + #define FFA_MEMORY_HANDLE_INVALID (~UINT64_C(0)) + + /** The ID of a VM. These are assigned sequentially starting with an offset. */ + typedef uint16_t ffa_vm_id_t; + ++/** ++ * A globally-unique ID assigned by the hypervisor for a region of memory being ++ * sent between VMs. ++ */ ++typedef uint64_t ffa_memory_handle_t; ++ + /** + * A count of VMs. This has the same range as the VM IDs but we give it a + * different name to make the different semantics clear. +diff --git a/src/api.c b/src/api.c +index fa5c9b7..16626b6 100644 +--- a/src/api.c ++++ b/src/api.c +@@ -9,7 +9,6 @@ + #include "hf/api.h" + + #include "hf/arch/cpu.h" +-#include "hf/arch/ffa_memory_handle.h" + #include "hf/arch/mm.h" + #include "hf/arch/other_world.h" + #include "hf/arch/timer.h" +@@ -2158,7 +2157,8 @@ struct ffa_value api_ffa_mem_reclaim(ffa_memory_handle_t handle, + struct vm *to = current->vm; + struct ffa_value ret; + +- if (ffa_memory_handle_allocated_by_current_world(handle)) { ++ if ((handle & FFA_MEMORY_HANDLE_ALLOCATOR_MASK) == ++ FFA_MEMORY_HANDLE_ALLOCATOR_HYPERVISOR) { + struct vm_locked to_locked = vm_lock(to); + + ret = ffa_memory_reclaim(to_locked, handle, flags, +diff --git a/src/arch/aarch64/hypervisor/BUILD.gn b/src/arch/aarch64/hypervisor/BUILD.gn +index 8f57598..0f9c15e 100644 +--- a/src/arch/aarch64/hypervisor/BUILD.gn ++++ b/src/arch/aarch64/hypervisor/BUILD.gn +@@ -17,7 +17,6 @@ offset_size_header("offsets") { + source_set("other_world") { + public_configs = [ "//src/arch/aarch64:config" ] + sources = [ +- "ffa_memory_handle.c", + "other_world.c", + ] + deps = [ +diff --git a/src/arch/aarch64/hypervisor/ffa_memory_handle.c b/src/arch/aarch64/hypervisor/ffa_memory_handle.c +deleted file mode 100644 +index 647186d..0000000 +--- a/src/arch/aarch64/hypervisor/ffa_memory_handle.c ++++ /dev/null +@@ -1,29 +0,0 @@ +-/* +- * Copyright 2021 The Hafnium Authors. +- * +- * Use of this source code is governed by a BSD-style +- * license that can be found in the LICENSE file or at +- * https://opensource.org/licenses/BSD-3-Clause. +- */ +- +-#include "hf/arch/ffa_memory_handle.h" +- +-ffa_memory_handle_t ffa_memory_handle_make(uint64_t index) +-{ +-#if SECURE_WORLD == 1 +- return (index & ~FFA_MEMORY_HANDLE_ALLOCATOR_MASK) | +- FFA_MEMORY_HANDLE_ALLOCATOR_SPMC; +-#else +- return index | FFA_MEMORY_HANDLE_ALLOCATOR_HYPERVISOR; +-#endif +-} +- +-bool ffa_memory_handle_allocated_by_current_world(ffa_memory_handle_t handle) +-{ +- return (handle & FFA_MEMORY_HANDLE_ALLOCATOR_MASK) == +-#if SECURE_WORLD == 1 +- FFA_MEMORY_HANDLE_ALLOCATOR_SPMC; +-#else +- FFA_MEMORY_HANDLE_ALLOCATOR_HYPERVISOR; +-#endif +-} +diff --git a/src/arch/fake/hypervisor/BUILD.gn b/src/arch/fake/hypervisor/BUILD.gn +index 8f28802..97a82f6 100644 +--- a/src/arch/fake/hypervisor/BUILD.gn ++++ b/src/arch/fake/hypervisor/BUILD.gn +@@ -16,7 +16,6 @@ source_set("hypervisor") { + + source_set("other_world") { + sources = [ +- "ffa_memory_handle.c", + "other_world.c", + ] + } +diff --git a/src/arch/fake/hypervisor/ffa_memory_handle.c b/src/arch/fake/hypervisor/ffa_memory_handle.c +deleted file mode 100644 +index 9091295..0000000 +--- a/src/arch/fake/hypervisor/ffa_memory_handle.c ++++ /dev/null +@@ -1,20 +0,0 @@ +-/* +- * Copyright 2021 The Hafnium Authors. +- * +- * Use of this source code is governed by a BSD-style +- * license that can be found in the LICENSE file or at +- * https://opensource.org/licenses/BSD-3-Clause. +- */ +- +-#include "hf/arch/ffa_memory_handle.h" +- +-ffa_memory_handle_t ffa_memory_handle_make(uint64_t index) +-{ +- return index; +-} +- +-bool ffa_memory_handle_allocated_by_current_world(ffa_memory_handle_t handle) +-{ +- (void)handle; +- return true; +-} +diff --git a/src/ffa_memory.c b/src/ffa_memory.c +index 8b28191..00ec68c 100644 +--- a/src/ffa_memory.c ++++ b/src/ffa_memory.c +@@ -8,7 +8,6 @@ + + #include "hf/ffa_memory.h" + +-#include "hf/arch/ffa_memory_handle.h" + #include "hf/arch/other_world.h" + + #include "hf/api.h" +@@ -121,14 +120,6 @@ static struct ffa_memory_share_state share_states[MAX_MEM_SHARES]; + alignas(PAGE_SIZE) static uint8_t + tee_retrieve_buffer[HF_MAILBOX_SIZE * MAX_FRAGMENTS]; + +-/** +- * Extracts the index from a memory handle allocated by Hafnium's current world. +- */ +-uint64_t ffa_memory_handle_get_index(ffa_memory_handle_t handle) +-{ +- return handle & ~FFA_MEMORY_HANDLE_ALLOCATOR_MASK; +-} +- + /** + * Initialises the next available `struct ffa_memory_share_state` and sets + * `share_state_ret` to a pointer to it. If `handle` is +@@ -159,7 +150,8 @@ static bool allocate_share_state( + + if (handle == FFA_MEMORY_HANDLE_INVALID) { + memory_region->handle = +- ffa_memory_handle_make(i); ++ i | ++ FFA_MEMORY_HANDLE_ALLOCATOR_HYPERVISOR; + } else { + memory_region->handle = handle; + } +@@ -213,7 +205,7 @@ static bool get_share_state(struct share_states_locked share_states, + struct ffa_memory_share_state **share_state_ret) + { + struct ffa_memory_share_state *share_state; +- uint64_t index; ++ uint32_t index; + + CHECK(share_states.share_states != NULL); + CHECK(share_state_ret != NULL); +@@ -222,8 +214,9 @@ static bool get_share_state(struct share_states_locked share_states, + * First look for a share_state allocated by us, in which case the + * handle is based on the index. + */ +- if (ffa_memory_handle_allocated_by_current_world(handle)) { +- index = ffa_memory_handle_get_index(handle); ++ if ((handle & FFA_MEMORY_HANDLE_ALLOCATOR_MASK) == ++ FFA_MEMORY_HANDLE_ALLOCATOR_HYPERVISOR) { ++ index = handle & ~FFA_MEMORY_HANDLE_ALLOCATOR_MASK; + if (index < MAX_MEM_SHARES) { + share_state = &share_states.share_states[index]; + if (share_state->share_func != 0) { +-- +2.29.2 + diff --git a/meta-arm-bsp/recipes-bsp/hafnium/files/tc0/0002-FF-A-Cold-boot-and-wake-up-from-suspend.patch b/meta-arm-bsp/recipes-bsp/hafnium/files/tc0/0002-FF-A-Cold-boot-and-wake-up-from-suspend.patch deleted file mode 100644 index 6cce9ad8..00000000 --- a/meta-arm-bsp/recipes-bsp/hafnium/files/tc0/0002-FF-A-Cold-boot-and-wake-up-from-suspend.patch +++ /dev/null @@ -1,95 +0,0 @@ -Upstream-Status: Pending [https://review.trustedfirmware.org/c/hafnium/hafnium/+/6010/29] -Signed-off-by: Arunachalam Ganapathy - -From ebd568637627fa895e6e7f479675c650414cc240 Mon Sep 17 00:00:00 2001 -From: Max Shvetsov -Date: Thu, 27 Aug 2020 12:39:50 +0100 -Subject: [PATCH 3/5] FF-A: Cold boot and wake up from suspend. - -WIP: Currently there is zero entry-point passed with no arguments, This -will be reworked once a proper way to pass this information will be -defined. - -Change-Id: Ic6050af16d4081ca31729744995fbb999b170e11 -Signed-off-by: Max Shvetsov -Signed-off-by: Olivier Deprez ---- - inc/hf/vcpu.h | 2 ++ - src/arch/aarch64/hypervisor/psci_handler.c | 2 ++ - src/main.c | 20 ++++++++++++++++++++ - 3 files changed, 24 insertions(+) - -diff --git a/inc/hf/vcpu.h b/inc/hf/vcpu.h -index 5439719..98f3a50 100644 ---- a/inc/hf/vcpu.h -+++ b/inc/hf/vcpu.h -@@ -86,6 +86,8 @@ struct vcpu { - * a result of a prior FFA_MSG_SEND_DIRECT_REQ invocation. - */ - ffa_vm_id_t direct_request_origin_vm_id; -+ -+ ipaddr_t psci_handler[1]; - }; - - /** Encapsulates a vCPU whose lock is held. */ -diff --git a/src/arch/aarch64/hypervisor/psci_handler.c b/src/arch/aarch64/hypervisor/psci_handler.c -index b323faa..c892385 100644 ---- a/src/arch/aarch64/hypervisor/psci_handler.c -+++ b/src/arch/aarch64/hypervisor/psci_handler.c -@@ -389,6 +389,8 @@ bool psci_secondary_vm_handler(struct vcpu *vcpu, uint32_t func, uintreg_t arg0, - - target_vcpu = vm_get_vcpu(vm, target_vcpu_index); - -+ target_vcpu->psci_handler[0] = entry_point_address; -+ - if (vcpu_secondary_reset_and_start( - target_vcpu, entry_point_address, context_id)) { - #if SECURE_WORLD == 0 -diff --git a/src/main.c b/src/main.c -index 3cc932e..2c3d1a5 100644 ---- a/src/main.c -+++ b/src/main.c -@@ -7,6 +7,7 @@ - */ - - #include "hf/cpu.h" -+#include "hf/dlog.h" - #include "hf/vm.h" - - /** -@@ -18,6 +19,18 @@ struct vcpu *cpu_main(struct cpu *c) - struct vm *first_boot; - struct vcpu *vcpu; - -+#if SECURE_WORLD == 1 -+ if (c->is_on == false) { -+ /* -+ * This is the PSCI warm reset path (svc_cpu_on_finish -+ * handler relayed by SPMD). Notice currenty the "first_boot" -+ * VM is resumed on any CPU on event. -+ */ -+ (void)cpu_on(c, ipa_init(0UL), 0UL); -+ dlog_verbose("%s: cpu mpidr 0x%x on\n", __func__, c->id); -+ } -+#endif -+ - /* - * This returns the PVM in the normal worls and the first - * booted Secure Partition in the secure world. -@@ -26,6 +39,13 @@ struct vcpu *cpu_main(struct cpu *c) - - vcpu = vm_get_vcpu(first_boot, cpu_index(c)); - -+ if (vcpu->psci_handler[0].ipa) { -+ struct vcpu_locked vcpu_locked = vcpu_lock(vcpu); -+ -+ vcpu_on(vcpu_locked, vcpu->psci_handler[0], 0); -+ vcpu_unlock(&vcpu_locked); -+ } -+ - vcpu->cpu = c; - - arch_cpu_init(); --- -2.29.2 - diff --git a/meta-arm-bsp/recipes-bsp/hafnium/files/tc0/0002-FF-A-Fix-to-fetch-proper-vCPU-index-for-UP-SP.patch b/meta-arm-bsp/recipes-bsp/hafnium/files/tc0/0002-FF-A-Fix-to-fetch-proper-vCPU-index-for-UP-SP.patch new file mode 100644 index 00000000..894bb001 --- /dev/null +++ b/meta-arm-bsp/recipes-bsp/hafnium/files/tc0/0002-FF-A-Fix-to-fetch-proper-vCPU-index-for-UP-SP.patch @@ -0,0 +1,99 @@ +From f080a6ae839b48188131648363c9e050f496f205 Mon Sep 17 00:00:00 2001 +From: Arunachalam Ganapathy +Date: Mon, 12 Apr 2021 10:22:26 +0100 +Subject: [PATCH 3/3] FF-A: Fix to fetch proper vCPU index for UP SP + +When switching the context between SPs, fetch the vCPU index using +api_vm_get_vcpu() helper routine. This routine gets the vCPU at index 0 +for UP SP. + +Rename function api_ffa_msg_send_direct_get_receiver_vcpu() to +api_vm_get_vcpu() as it is used both in direct message request +and response. + +Signed-off-by: Arunachalam Ganapathy +Change-Id: I45a60427f8c2d1b5058443536d972495728ee0c2 +Upstream-Status: Pending [Not submitted to upstream yet] +--- + src/api.c | 44 +++++++++++++++++++++----------------------- + 1 file changed, 21 insertions(+), 23 deletions(-) + +diff --git a/src/api.c b/src/api.c +index 16626b6..4c8034e 100644 +--- a/src/api.c ++++ b/src/api.c +@@ -63,6 +63,25 @@ void api_init(struct mpool *ppool) + mpool_init_from(&api_page_pool, ppool); + } + ++/** ++ * Get target VM vCPU. ++ * If VM is UP then return first vCPU. ++ * If VM is MP then return vCPU whose index matches current CPU index. ++ */ ++static struct vcpu *api_vm_get_vcpu(struct vm *vm, struct vcpu *current) ++{ ++ ffa_vcpu_index_t current_cpu_index = cpu_index(current->cpu); ++ struct vcpu *vcpu = NULL; ++ ++ if (vm->vcpu_count == 1) { ++ vcpu = vm_get_vcpu(vm, 0); ++ } else if (current_cpu_index < vm->vcpu_count) { ++ vcpu = vm_get_vcpu(vm, current_cpu_index); ++ } ++ ++ return vcpu; ++} ++ + /** + * Switches the physical CPU back to the corresponding vCPU of the VM whose ID + * is given as argument of the function. +@@ -80,7 +99,7 @@ static struct vcpu *api_switch_to_vm(struct vcpu *current, + ffa_vm_id_t to_id) + { + struct vm *to_vm = vm_find(to_id); +- struct vcpu *next = vm_get_vcpu(to_vm, cpu_index(current->cpu)); ++ struct vcpu *next = api_vm_get_vcpu(to_vm, current); + + CHECK(next != NULL); + +@@ -1630,26 +1649,6 @@ struct ffa_value api_ffa_features(uint32_t function_id) + } + } + +-/** +- * Get target VM vCPU for direct messaging request. +- * If VM is UP then return first vCPU. +- * If VM is MP then return vCPU whose index matches current CPU index. +- */ +-static struct vcpu *api_ffa_msg_send_direct_get_receiver_vcpu( +- struct vm *vm, struct vcpu *current) +-{ +- ffa_vcpu_index_t current_cpu_index = cpu_index(current->cpu); +- struct vcpu *vcpu = NULL; +- +- if (vm->vcpu_count == 1) { +- vcpu = vm_get_vcpu(vm, 0); +- } else if (current_cpu_index < vm->vcpu_count) { +- vcpu = vm_get_vcpu(vm, current_cpu_index); +- } +- +- return vcpu; +-} +- + /** + * FF-A specification states that x2/w2 Must Be Zero for direct messaging + * interfaces. +@@ -1733,8 +1732,7 @@ struct ffa_value api_ffa_msg_send_direct_req(ffa_vm_id_t sender_vm_id, + * number of PEs in the system. It further states that MP partitions + * accepting direct request messages cannot migrate. + */ +- receiver_vcpu = +- api_ffa_msg_send_direct_get_receiver_vcpu(receiver_vm, current); ++ receiver_vcpu = api_vm_get_vcpu(receiver_vm, current); + if (receiver_vcpu == NULL) { + return ffa_error(FFA_INVALID_PARAMETERS); + } +-- +2.29.2 + diff --git a/meta-arm-bsp/recipes-bsp/hafnium/files/tc0/0003-FF-A-Respond-to-PSCI_CPU_OFF-from-SPMD.patch b/meta-arm-bsp/recipes-bsp/hafnium/files/tc0/0003-FF-A-Respond-to-PSCI_CPU_OFF-from-SPMD.patch deleted file mode 100644 index 87f2a43b..00000000 --- a/meta-arm-bsp/recipes-bsp/hafnium/files/tc0/0003-FF-A-Respond-to-PSCI_CPU_OFF-from-SPMD.patch +++ /dev/null @@ -1,115 +0,0 @@ -Upstream-Status: Pending [https://review.trustedfirmware.org/c/hafnium/hafnium/+/6011/29] -Signed-off-by: Arunachalam Ganapathy - -From 6a836b380265876a12b2edfb7f013523af89e754 Mon Sep 17 00:00:00 2001 -From: Max Shvetsov -Date: Fri, 18 Sep 2020 13:52:20 +0100 -Subject: [PATCH 4/5] FF-A: Respond to PSCI_CPU_OFF from SPMD. - -At run-time when a PSCI call is made from NWd, the corresponding SPMD PM -hooks gets called and is eventually routed to the SPMC. This change -implements a generic "SPMD handler" processing PM events that may be -conveyed from SPMD to SPMC such as core suspend, core off. - -Change-Id: Id288e26d9fbb8328acc71f5cf68c39e095a0e3da -Signed-off-by: Max Shvetsov -Signed-off-by: Olivier Deprez ---- - src/arch/aarch64/hypervisor/handler.c | 49 +++++++++++++++++++++++++-- - 1 file changed, 47 insertions(+), 2 deletions(-) - -diff --git a/src/arch/aarch64/hypervisor/handler.c b/src/arch/aarch64/hypervisor/handler.c -index b33298c..43a1404 100644 ---- a/src/arch/aarch64/hypervisor/handler.c -+++ b/src/arch/aarch64/hypervisor/handler.c -@@ -13,6 +13,7 @@ - #include "hf/arch/mmu.h" - #include "hf/arch/other_world.h" - #include "hf/arch/plat/smc.h" -+#include "hf/arch/spmd_helpers.h" - - #include "hf/api.h" - #include "hf/check.h" -@@ -261,6 +262,7 @@ static void set_virtual_interrupt_current(bool enable) - } - - #if SECURE_WORLD == 1 -+ - static bool sp_boot_next(struct vcpu *current, struct vcpu **next, - struct ffa_value *ffa_ret) - { -@@ -303,6 +305,41 @@ out: - vm_unlock(¤t_vm_locked); - return ret; - } -+ -+/** -+ * Handle special direct messages from SPMD to SPMC. For now related to power -+ * management only. -+ */ -+static bool spmd_handler(struct ffa_value *args, struct vcpu *current) -+{ -+ ffa_vm_id_t spmc_ffa_id = arch_other_world_get_ffa_id(); -+ ffa_vm_id_t sender = ffa_msg_send_sender(*args); -+ ffa_vm_id_t receiver = ffa_msg_send_receiver(*args); -+ ffa_vm_id_t current_vm_id = current->vm->id; -+ -+ if (!((sender == SPMD_ID) && (receiver == spmc_ffa_id) && -+ (current_vm_id == HF_OTHER_WORLD_ID))) { -+ return false; -+ } -+ -+ switch (args->arg3) { -+ case PSCI_CPU_OFF: -+ dlog_verbose("%s cpu off notification\n", __func__); -+ args->func = FFA_MSG_SEND_DIRECT_RESP_32; -+ args->arg1 = ((uint64_t)spmc_ffa_id << 16) | SPMD_ID; -+ args->arg2 = 0U; -+ -+ cpu_off(current->cpu); -+ break; -+ default: -+ dlog_verbose("%s message not handled %#x\n", __func__, -+ args->arg3); -+ return false; -+ } -+ -+ return true; -+} -+ - #endif - - /** -@@ -461,11 +498,17 @@ static bool ffa_handler(struct ffa_value *args, struct vcpu *current, - (args->arg4 >> 16) & 0xffff, - current); - return true; -- case FFA_MSG_SEND_DIRECT_REQ_32: -+ case FFA_MSG_SEND_DIRECT_REQ_32: { -+#if SECURE_WORLD == 1 -+ if (spmd_handler(args, current)) { -+ return true; -+ } -+#endif - *args = api_ffa_msg_send_direct_req( - ffa_msg_send_sender(*args), - ffa_msg_send_receiver(*args), *args, current, next); - return true; -+ } - case FFA_MSG_SEND_DIRECT_RESP_32: - *args = api_ffa_msg_send_direct_resp( - ffa_msg_send_sender(*args), -@@ -510,7 +553,9 @@ static void other_world_switch_loop(struct vcpu *other_world_vcpu, - * the result of the call back to EL3 unless the API handler - * sets *next to something different. - */ -- if (!ffa_handler(&other_world_args, other_world_vcpu, next)) { -+ -+ if (!spmd_handler(&other_world_args, other_world_vcpu) && -+ !ffa_handler(&other_world_args, other_world_vcpu, next)) { - other_world_args.func = SMCCC_ERROR_UNKNOWN; - } - } --- -2.29.2 - diff --git a/meta-arm-bsp/recipes-bsp/hafnium/files/tc0/0004-tc0-Add-Theodul-DSU-support.patch b/meta-arm-bsp/recipes-bsp/hafnium/files/tc0/0003-tc0-Theodul-GICR-changes.patch similarity index 59% rename from meta-arm-bsp/recipes-bsp/hafnium/files/tc0/0004-tc0-Add-Theodul-DSU-support.patch rename to meta-arm-bsp/recipes-bsp/hafnium/files/tc0/0003-tc0-Theodul-GICR-changes.patch index 4c0b5dd0..d3bb76b1 100644 --- a/meta-arm-bsp/recipes-bsp/hafnium/files/tc0/0004-tc0-Add-Theodul-DSU-support.patch +++ b/meta-arm-bsp/recipes-bsp/hafnium/files/tc0/0003-tc0-Theodul-GICR-changes.patch @@ -1,30 +1,32 @@ -From e8042fda56aa470cdda723757a957a81cd95dde8 Mon Sep 17 00:00:00 2001 +From fd177558a1da73fa7e10f8b2997864bb76d66dc8 Mon Sep 17 00:00:00 2001 From: Arunachalam Ganapathy -Date: Tue, 2 Feb 2021 12:12:32 +0000 -Subject: [PATCH] tc0: Add Theodul DSU support +Date: Thu, 15 Apr 2021 10:46:33 +0100 +Subject: [PATCH] tc0: Add Theodul DSU support and GICR changes Signed-off-by: Arunachalam Ganapathy -Upstream-Status: Pending [Not submitted to upstream yet] Change-Id: I4a9b7e4350410fdacccd8c12ff03a61b7e64e98b +Upstream-Status: Pending [Not submitted to upstream yet] --- project/reference/BUILD.gn | 4 ++-- - 1 file changed, 2 insertions(+), 2 deletions(-) + 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/project/reference/BUILD.gn b/project/reference/BUILD.gn index 5596009..ffcaab7 100644 --- a/project/reference/BUILD.gn +++ b/project/reference/BUILD.gn -@@ -159,8 +159,8 @@ aarch64_toolchains("secure_tc0") { +@@ -160,9 +160,9 @@ aarch64_toolchains("secure_tc0") { + iommu = "//src/iommu:absent" gic_version = 3 gicd_base_address = "0x30000000" - gicr_base_address = "0x30140000" +- gicr_base_address = "0x30140000" - heap_pages = 60 - max_cpus = 4 ++ gicr_base_address = "0x30080000" + heap_pages = 80 + max_cpus = 8 max_vms = 16 toolchain_args = { - secure_world = "1" + plat_psci = "//src/arch/aarch64/plat/psci:spmc" -- 2.29.2 diff --git a/meta-arm-bsp/recipes-bsp/hafnium/hafnium-tc0.inc b/meta-arm-bsp/recipes-bsp/hafnium/hafnium-tc0.inc index 9f14f738..e7eed112 100644 --- a/meta-arm-bsp/recipes-bsp/hafnium/hafnium-tc0.inc +++ b/meta-arm-bsp/recipes-bsp/hafnium/hafnium-tc0.inc @@ -1,16 +1,15 @@ # TC0 specific configuration # Intermediate SHA with 2.4 baseline version, required for OP-TEE SEL1 support -SRCREV = "fe7f737ec20add15d49c587ebeb55f7ea0118226" +SRCREV = "2904b2c5361f06d35c324f37d2e71e3278d351a7" PV = "2.4+git${SRCPV}" FILESEXTRAPATHS_prepend_tc0 := "${THISDIR}/files/tc0:" SRC_URI_append = " \ - file://0001-FF-A-Register-secondary-core-entry-point-at-SPMC-ini.patch \ - file://0002-FF-A-Cold-boot-and-wake-up-from-suspend.patch \ - file://0003-FF-A-Respond-to-PSCI_CPU_OFF-from-SPMD.patch \ - file://0004-tc0-Add-Theodul-DSU-support.patch \ + file://0001-Revert-FFA-Set-and-verify-allocator-of-memory-handle.patch \ + file://0002-FF-A-Fix-to-fetch-proper-vCPU-index-for-UP-SP.patch \ + file://0003-tc0-Theodul-GICR-changes.patch \ " COMPATIBLE_MACHINE = "tc0"