J-Alves | 9f6f014 | 2020-06-17 15:37:59 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2018-2020, Arm Limited. All rights reserved. |
| 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | #include <assert.h> |
J-Alves | 9f6f014 | 2020-06-17 15:37:59 +0100 | [diff] [blame] | 7 | #include <debug.h> |
Max Shvetsov | 40eb6a2 | 2020-06-08 11:15:30 +0100 | [diff] [blame^] | 8 | #include <errno.h> |
J-Alves | 5aecd98 | 2020-06-11 10:25:33 +0100 | [diff] [blame] | 9 | #include <ffa_helpers.h> |
J-Alves | 9f6f014 | 2020-06-17 15:37:59 +0100 | [diff] [blame] | 10 | #include <sp_helpers.h> |
| 11 | |
| 12 | /* FFA version test helpers */ |
| 13 | #define FFA_MAJOR 1U |
| 14 | #define FFA_MINOR 0U |
| 15 | |
Max Shvetsov | 40eb6a2 | 2020-06-08 11:15:30 +0100 | [diff] [blame^] | 16 | struct feature_test { |
| 17 | const char *test_name; |
| 18 | unsigned int feature; |
| 19 | unsigned int expected_ret; |
| 20 | }; |
| 21 | |
| 22 | static const struct feature_test test_target[] = { |
| 23 | {"FFA_ERROR_32 check", FFA_ERROR, FFA_SUCCESS_SMC32}, |
| 24 | {"FFA_SUCCESS_32 check", FFA_SUCCESS_SMC32, FFA_SUCCESS_SMC32}, |
| 25 | {"FFA_INTERRUPT_32 check", FFA_INTERRUPT, FFA_SUCCESS_SMC32}, |
| 26 | {"FFA_VERSION_32 check", FFA_VERSION, FFA_SUCCESS_SMC32}, |
| 27 | {"FFA_FEATURES_32 check", FFA_FEATURES, FFA_SUCCESS_SMC32}, |
| 28 | {"FFA_RX_RELEASE_32 check", FFA_RX_RELEASE, FFA_SUCCESS_SMC32}, |
| 29 | {"FFA_RXTX_MAP_32 check", FFA_RXTX_MAP_SMC32, FFA_ERROR}, |
| 30 | {"FFA_RXTX_MAP_64 check", FFA_RXTX_MAP_SMC64, FFA_SUCCESS_SMC32}, |
| 31 | {"FFA_RXTX_UNMAP_32 check", FFA_RXTX_UNMAP, FFA_ERROR}, |
| 32 | {"FFA_PARTITION_INFO_GET_32 check", FFA_PARTITION_INFO_GET, FFA_SUCCESS_SMC32}, |
| 33 | {"FFA_ID_GET_32 check", FFA_ID_GET, FFA_SUCCESS_SMC32}, |
| 34 | {"FFA_MSG_POLL_32 check", FFA_MSG_POLL, FFA_SUCCESS_SMC32}, |
| 35 | {"FFA_MSG_WAIT_32 check", FFA_MSG_WAIT, FFA_SUCCESS_SMC32}, |
| 36 | {"FFA_YIELD_32 check", FFA_MSG_YIELD, FFA_SUCCESS_SMC32}, |
| 37 | {"FFA_RUN_32 check", FFA_MSG_RUN, FFA_SUCCESS_SMC32}, |
| 38 | {"FFA_MSG_SEND_32 check", FFA_MSG_SEND, FFA_SUCCESS_SMC32}, |
| 39 | {"FFA_MEM_DONATE_32 check", FFA_MEM_DONATE_SMC32, FFA_SUCCESS_SMC32}, |
| 40 | {"FFA_MEM_LEND_32 check", FFA_MEM_LEND_SMC32, FFA_SUCCESS_SMC32}, |
| 41 | {"FFA_MEM_SHARE_32 check", FFA_MEM_SHARE_SMC32, FFA_SUCCESS_SMC32}, |
| 42 | {"FFA_MEM_RETRIEVE_REQ_32 check", FFA_MEM_RETRIEVE_REQ_SMC32, FFA_SUCCESS_SMC32}, |
| 43 | {"FFA_MEM_RETRIEVE_RESP_32 check", FFA_MEM_RETRIEVE_RESP, FFA_SUCCESS_SMC32}, |
| 44 | {"FFA_MEM_RELINQUISH_32 check", FFA_MEM_RELINQUISH, FFA_SUCCESS_SMC32}, |
| 45 | {"FFA_MEM_RECLAIM_32 check", FFA_MEM_RECLAIM, FFA_SUCCESS_SMC32}, |
| 46 | {"Check non-existent command", 0xFFFF, FFA_ERROR} |
| 47 | }; |
| 48 | |
| 49 | /* |
| 50 | * Test FFA_FEATURES interface. |
| 51 | */ |
| 52 | static void ffa_features_test(void) |
| 53 | { |
| 54 | const char *test_features = "FFA Features interface"; |
| 55 | smc_ret_values ffa_ret; |
| 56 | unsigned int i, test_target_size = |
| 57 | sizeof(test_target) / sizeof(struct feature_test); |
| 58 | |
| 59 | announce_test_section_start(test_features); |
| 60 | |
| 61 | for (i = 0U; i < test_target_size; i++) { |
| 62 | announce_test_start(test_target[i].test_name); |
| 63 | |
| 64 | ffa_ret = ffa_features(test_target[i].feature); |
| 65 | expect(ffa_ret.ret0, test_target[i].expected_ret); |
| 66 | if (test_target[i].expected_ret == FFA_ERROR) { |
| 67 | expect(ffa_ret.ret2, FFA_ERROR_NOT_SUPPORTED); |
| 68 | } |
| 69 | |
| 70 | announce_test_end(test_target[i].test_name); |
| 71 | } |
| 72 | |
| 73 | announce_test_section_end(test_features); |
| 74 | } |
| 75 | |
J-Alves | 9f6f014 | 2020-06-17 15:37:59 +0100 | [diff] [blame] | 76 | void ffa_tests(void) |
| 77 | { |
| 78 | const char *test_ffa = "FFA Interfaces"; |
| 79 | const char *test_ffa_version = "FFA Version interface"; |
| 80 | |
| 81 | announce_test_section_start(test_ffa); |
| 82 | |
| 83 | announce_test_start(test_ffa_version); |
| 84 | |
| 85 | smc_ret_values ret = ffa_version(MAKE_FFA_VERSION(FFA_MAJOR, FFA_MINOR)); |
| 86 | uint32_t spm_version = (uint32_t)(0xFFFFFFFF & ret.ret0); |
| 87 | |
Max Shvetsov | 40eb6a2 | 2020-06-08 11:15:30 +0100 | [diff] [blame^] | 88 | bool ffa_version_compatible = |
| 89 | ((spm_version >> FFA_VERSION_MAJOR_SHIFT) == FFA_MAJOR && |
| 90 | (spm_version & FFA_VERSION_MINOR_MASK) >= FFA_MINOR); |
J-Alves | 9f6f014 | 2020-06-17 15:37:59 +0100 | [diff] [blame] | 91 | |
| 92 | NOTICE("FFA_VERSION returned %u.%u; Compatible: %i\n", |
| 93 | spm_version >> FFA_VERSION_MAJOR_SHIFT, |
| 94 | spm_version & FFA_VERSION_MINOR_MASK, |
| 95 | (int)ffa_version_compatible); |
| 96 | |
| 97 | expect((int)ffa_version_compatible, (int)true); |
| 98 | |
| 99 | announce_test_end(test_ffa_version); |
| 100 | |
Max Shvetsov | 40eb6a2 | 2020-06-08 11:15:30 +0100 | [diff] [blame^] | 101 | ffa_features_test(); |
| 102 | |
J-Alves | 9f6f014 | 2020-06-17 15:37:59 +0100 | [diff] [blame] | 103 | announce_test_section_end(test_ffa); |
| 104 | } |