diff options
author | J-Alves <joao.alves@arm.com> | 2021-02-19 14:33:54 +0000 |
---|---|---|
committer | J-Alves <joao.alves@arm.com> | 2021-03-12 12:57:11 +0000 |
commit | be1519aa2b3a629ea375f4ac068cd0ec9f8cac9d (patch) | |
tree | 823d9e7a3f22d44f93d7bf5f7357b3604cefed65 /spm/cactus/cactus_tests | |
parent | 4cb9dee51231982ac1e0ed608b16099a9b37a084 (diff) |
SPM: Tidying FF-A Memory Sharing tests
Moving code about memory sharing tests to comply with recent changes:
- Placed helper functions that can be used by TFTF and Cactus in files
spm_common.c/h.
- Removed 'ffa_memory_sharing_test' and added its body to handler of
test command CACTUS_MEM_SEND_CMD.
Signed-off-by: J-Alves <joao.alves@arm.com>
Change-Id: I58af9b475730d171306581741becbb0665e1859d
Diffstat (limited to 'spm/cactus/cactus_tests')
-rw-r--r-- | spm/cactus/cactus_tests/cactus_test_memory_sharing.c | 98 |
1 files changed, 89 insertions, 9 deletions
diff --git a/spm/cactus/cactus_tests/cactus_test_memory_sharing.c b/spm/cactus/cactus_tests/cactus_test_memory_sharing.c index 63c3d13..82cdac3 100644 --- a/spm/cactus/cactus_tests/cactus_test_memory_sharing.c +++ b/spm/cactus/cactus_tests/cactus_test_memory_sharing.c @@ -4,25 +4,101 @@ * SPDX-License-Identifier: BSD-3-Clause */ -#include "cactus_def.h" +#include <cactus_def.h> #include "cactus_test_cmds.h" #include "cactus_tests.h" #include <ffa_helpers.h> #include <sp_helpers.h> #include <xlat_tables_defs.h> +#include <lib/xlat_tables/xlat_tables_v2.h> /* Memory section to be used for memory share operations */ static __aligned(PAGE_SIZE) uint8_t share_page[PAGE_SIZE]; CACTUS_CMD_HANDLER(mem_send_cmd, CACTUS_MEM_SEND_CMD) { - ffa_memory_management_test( - mb, ffa_dir_msg_dest(*args), ffa_dir_msg_source(*args), - cactus_req_mem_send_get_mem_func(*args), - cactus_mem_send_get_handle(*args)); + struct ffa_memory_region *m; + struct ffa_composite_memory_region *composite; + int ret; + unsigned int mem_attrs; + uint32_t *ptr; + ffa_vm_id_t source = ffa_dir_msg_source(*args); + ffa_vm_id_t vm_id = ffa_dir_msg_dest(*args); + uint32_t mem_func = cactus_req_mem_send_get_mem_func(*args); + uint64_t handle = cactus_mem_send_get_handle(*args); + + expect(memory_retrieve(mb, &m, handle, source, vm_id, mem_func), true); + + composite = ffa_memory_region_get_composite(m, 0); + + VERBOSE("Address: %p; page_count: %x %x\n", + composite->constituents[0].address, + composite->constituents[0].page_count, PAGE_SIZE); + + /* This test is only concerned with RW permissions. */ + if (ffa_get_data_access_attr( + m->receivers[0].receiver_permissions.permissions) != + FFA_DATA_ACCESS_RW) { + ERROR("Permissions not expected!\n"); + return cactus_error_resp(vm_id, source, CACTUS_ERROR_TEST); + } + + mem_attrs = MT_RW_DATA | MT_EXECUTE_NEVER; + + if (!IS_SP_ID(source)) { + mem_attrs |= MT_NS; + } + + ret = mmap_add_dynamic_region( + (uint64_t)composite->constituents[0].address, + (uint64_t)composite->constituents[0].address, + composite->constituents[0].page_count * PAGE_SIZE, + mem_attrs); + + if (ret != 0) { + ERROR("Failed first mmap_add_dynamic_region!\n"); + return cactus_error_resp(vm_id, source, CACTUS_ERROR_TEST); + } + + VERBOSE("Memory has been mapped\n"); + + ptr = (uint32_t *) composite->constituents[0].address; - return cactus_success_resp(ffa_dir_msg_dest(*args), - ffa_dir_msg_source(*args), 0); + /* Write mem_func to retrieved memory region for validation purposes. */ + VERBOSE("Writing: %x\n", mem_func); + for (unsigned int i = 0U; i < 5U; i++) + ptr[i] = mem_func; + + /* + * A FFA_MEM_DONATE changes the ownership of the page, as such no + * relinquish is needed. + */ + if (mem_func != FFA_MEM_DONATE_SMC32) { + ret = mmap_remove_dynamic_region( + (uint64_t)composite->constituents[0].address, + composite->constituents[0].page_count * PAGE_SIZE); + + if (ret != 0) { + ERROR("Failed first mmap_add_dynamic_region!\n"); + return cactus_error_resp(vm_id, source, + CACTUS_ERROR_TEST); + } + + if (!memory_relinquish((struct ffa_mem_relinquish *)mb->send, + m->handle, vm_id)) { + return cactus_error_resp(vm_id, source, + CACTUS_ERROR_TEST); + } + } + + if (ffa_func_id(ffa_rx_release()) != FFA_SUCCESS_SMC32) { + ERROR("Failed to release buffer!\n"); + return cactus_error_resp(vm_id, source, + CACTUS_ERROR_FFA_CALL); + } + + return cactus_success_resp(vm_id, + source, 0); } CACTUS_CMD_HANDLER(req_mem_send_cmd, CACTUS_REQ_MEM_SEND_CMD) @@ -44,7 +120,7 @@ CACTUS_CMD_HANDLER(req_mem_send_cmd, CACTUS_REQ_MEM_SEND_CMD) const uint32_t constituents_count = (sizeof(constituents) / sizeof(constituents[0])); - handle = ffa_memory_init_and_send( + handle = memory_init_and_send( (struct ffa_memory_region *)mb->send, PAGE_SIZE, vm_id, receiver, constituents, constituents_count, mem_func); @@ -52,7 +128,11 @@ CACTUS_CMD_HANDLER(req_mem_send_cmd, CACTUS_REQ_MEM_SEND_CMD) /* * If returned an invalid handle, we should break the test. */ - expect(handle != FFA_MEMORY_HANDLE_INVALID, true); + if (handle == FFA_MEMORY_HANDLE_INVALID) { + ERROR("Received an invalid FF-A memory Handle!\n"); + return cactus_error_resp(vm_id, source, + CACTUS_ERROR_TEST); + } ffa_ret = cactus_mem_send_cmd(vm_id, receiver, mem_func, handle); |