Varun Wadekar | be5fade | 2020-06-02 22:54:42 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2020, NVIDIA CORPORATION. All rights reserved. |
| 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | |
| 7 | #include <arch_helpers.h> |
| 8 | #include <debug.h> |
anzhou | 42f4d19 | 2020-06-16 20:56:07 +0800 | [diff] [blame] | 9 | #include <smccc.h> |
Varun Wadekar | be5fade | 2020-06-02 22:54:42 -0700 | [diff] [blame] | 10 | #include <tftf_lib.h> |
| 11 | #include <xlat_tables_v2.h> |
| 12 | |
| 13 | #include <platform_def.h> |
| 14 | |
| 15 | /******************************************************************************* |
| 16 | * Common Tegra SiP SMCs |
| 17 | ******************************************************************************/ |
| 18 | #define TEGRA_SIP_NEW_VIDEOMEM_REGION 0x82000003ULL |
anzhou | 42f4d19 | 2020-06-16 20:56:07 +0800 | [diff] [blame] | 19 | #define TEGRA_SIP_GET_SMMU_PER 0xC200FF00ULL |
Varun Wadekar | be5fade | 2020-06-02 22:54:42 -0700 | [diff] [blame] | 20 | |
| 21 | /* |
| 22 | * @Test_Aim@ Test to issue VideoMem SiP SMC function IDs. |
| 23 | * |
| 24 | * This test runs on the lead CPU and issues TEGRA_SIP_NEW_VIDEOMEM_REGION |
| 25 | * SMC to resize the memory region. |
| 26 | */ |
| 27 | test_result_t test_sip_videomem_resize(void) |
| 28 | { |
| 29 | uint32_t size_in_bytes = (4U << 20); |
| 30 | uint32_t offset = (8U << 20); |
| 31 | uint64_t vidmem_base = DRAM_END, mem; |
| 32 | uint64_t buf[] = { 0xCAFEBABE, 0xCAFEBABE, 0xCAFEBABE, 0xCAFEBABE }; |
| 33 | smc_args args = { TEGRA_SIP_NEW_VIDEOMEM_REGION, vidmem_base, size_in_bytes }; |
| 34 | smc_ret_values ret; |
| 35 | test_result_t result = TEST_RESULT_SUCCESS; |
| 36 | int err; |
| 37 | |
| 38 | /* Map dummy memory region for the test */ |
| 39 | err = mmap_add_dynamic_region(vidmem_base, vidmem_base, size_in_bytes << 2, |
| 40 | MT_DEVICE | MT_RW | MT_NS | MT_EXECUTE_NEVER); |
| 41 | if (err != 0) { |
| 42 | tftf_testcase_printf("%s: could not map memory (%d)\n", __func__, err); |
| 43 | return TEST_RESULT_FAIL; |
| 44 | } |
| 45 | |
| 46 | /* copy sample data before setting up the memory protections */ |
| 47 | memcpy((char *)vidmem_base, (void *)buf, sizeof(buf)); |
| 48 | flush_dcache_range(vidmem_base, sizeof(buf)); |
| 49 | |
| 50 | /* Issue the SMC to program videomem and expect success */ |
| 51 | ret = tftf_smc(&args); |
| 52 | if (ret.ret0 != 0UL) { |
| 53 | tftf_testcase_printf("%s failed. Expected 0, received %ld\n", |
| 54 | __func__, (long int)ret.ret0); |
| 55 | result = TEST_RESULT_FAIL; |
| 56 | goto exit; |
| 57 | } |
| 58 | |
| 59 | /* copy sample data before setting up the memory protections */ |
| 60 | memcpy((char *)vidmem_base + offset, (void *)buf, sizeof(buf)); |
| 61 | flush_dcache_range(vidmem_base + offset, sizeof(buf)); |
| 62 | |
| 63 | /* Issue request to "move" the protected memory region */ |
| 64 | args.arg1 = vidmem_base + offset; |
| 65 | args.arg2 = (u_register_t)size_in_bytes; |
| 66 | ret = tftf_smc(&args); |
| 67 | if (ret.ret0 != 0UL) { |
| 68 | tftf_testcase_printf("%s failed. Expected 0, received %ld\n", |
| 69 | __func__, (long int)ret.ret0); |
| 70 | result = TEST_RESULT_FAIL; |
| 71 | goto exit; |
| 72 | } |
| 73 | |
| 74 | /* Verify that memory in the open has been cleared */ |
| 75 | mem = vidmem_base; |
| 76 | for (unsigned int i = 0U; i < (size_in_bytes / 8); i++, mem += 8) { |
| 77 | if (*(uint64_t *)(void *)mem != 0ULL) { |
| 78 | tftf_testcase_printf("%s failed. Memory is non-zero (%llx:%llx)\n", |
| 79 | __func__, mem, *(uint64_t *)(void *)mem); |
| 80 | result = TEST_RESULT_FAIL; |
| 81 | goto exit; |
| 82 | } |
| 83 | } |
| 84 | |
| 85 | /* copy sample data before setting up the memory protections */ |
| 86 | memcpy((char *)vidmem_base, (void *)buf, sizeof(buf)); |
| 87 | flush_dcache_range(vidmem_base, sizeof(buf)); |
| 88 | |
| 89 | /* Issue request to "move" the protected memory region */ |
| 90 | args.arg1 = vidmem_base; |
| 91 | args.arg2 = (u_register_t)size_in_bytes; |
| 92 | ret = tftf_smc(&args); |
| 93 | if (ret.ret0 != 0UL) { |
| 94 | tftf_testcase_printf("%s failed. Expected 0, received %ld\n", |
| 95 | __func__, (long int)ret.ret0); |
| 96 | result = TEST_RESULT_FAIL; |
| 97 | goto exit; |
| 98 | } |
| 99 | |
| 100 | /* Verify that memory in the open has been cleared */ |
| 101 | mem = vidmem_base + offset; |
| 102 | for (unsigned int i = 0U; i < (size_in_bytes / 8); i++, mem += 8) { |
| 103 | if (*(uint64_t *)(void *)mem != 0U) { |
| 104 | tftf_testcase_printf("%s failed. Memory is non-zero (%llx:%llx)\n", |
| 105 | __func__, mem, *(uint64_t *)(void *)mem); |
| 106 | result = TEST_RESULT_FAIL; |
| 107 | goto exit; |
| 108 | } |
| 109 | } |
| 110 | |
| 111 | exit: |
| 112 | /* unmap dummy memory region */ |
| 113 | err = mmap_remove_dynamic_region(vidmem_base, size_in_bytes << 2); |
| 114 | if (err != 0) { |
| 115 | tftf_testcase_printf("%s: could not unmap memory (%d)\n", |
| 116 | __func__, err); |
| 117 | result = TEST_RESULT_FAIL; |
| 118 | } |
| 119 | |
| 120 | return result; |
| 121 | } |
| 122 | |
| 123 | /* |
| 124 | * @Test_Aim@ Test to issue common SiP SMC function IDs. |
| 125 | * |
| 126 | * This test runs on the lead CPU and issues TEGRA_SIP_NEW_VIDEOMEM_REGION |
| 127 | * and tests positive and negative scenarios. |
| 128 | */ |
| 129 | test_result_t test_sip_videomem_incorrect_inputs(void) |
| 130 | { |
| 131 | smc_args args = { TEGRA_SIP_NEW_VIDEOMEM_REGION }; |
| 132 | smc_ret_values ret; |
| 133 | |
| 134 | /* Issue the SMC with no input parameters and expect error */ |
| 135 | ret = tftf_smc(&args); |
| 136 | if (ret.ret0 == 0UL) { |
| 137 | tftf_testcase_printf("%s failed. Expected -1, received %ld\n", |
| 138 | __func__, (long int)ret.ret0); |
| 139 | return TEST_RESULT_FAIL; |
| 140 | } |
| 141 | |
| 142 | /* Issue the SMC with incorrect parameters and expect error */ |
| 143 | args.arg1 = 0x10000000ULL; |
| 144 | args.arg2 = 4ULL << 20; |
| 145 | |
| 146 | ret = tftf_smc(&args); |
| 147 | if (ret.ret0 == 0UL) { |
| 148 | tftf_testcase_printf("%s failed. Expected -1, received %ld\n", |
| 149 | __func__, (long int)ret.ret0); |
| 150 | return TEST_RESULT_FAIL; |
| 151 | } |
| 152 | |
| 153 | /* Issue the SMC with incorrect parameters and expect error */ |
| 154 | args.arg1 = 0x40000000ULL; |
| 155 | args.arg2 = 4ULL << 20; |
| 156 | |
| 157 | ret = tftf_smc(&args); |
| 158 | if (ret.ret0 == 0UL) { |
| 159 | tftf_testcase_printf("%s failed. Expected -1, received %ld\n", |
| 160 | __func__, (long int)ret.ret0); |
| 161 | return TEST_RESULT_FAIL; |
| 162 | } |
| 163 | |
| 164 | /* Issue the SMC with incorrect parameters and expect error */ |
| 165 | args.arg1 = DRAM_END - (4U << 20); |
| 166 | args.arg2 = 0x100ULL; |
| 167 | |
| 168 | ret = tftf_smc(&args); |
| 169 | if (ret.ret0 == 0UL) { |
| 170 | tftf_testcase_printf("%s failed. Expected -1, received %ld\n", |
| 171 | __func__, (long int)ret.ret0); |
| 172 | return TEST_RESULT_FAIL; |
| 173 | } |
| 174 | |
| 175 | /* Issue the SMC with incorrect parameters and expect error */ |
| 176 | args.arg1 = DRAM_END - (4U << 20); |
| 177 | args.arg2 = 0ULL; |
| 178 | |
| 179 | ret = tftf_smc(&args); |
| 180 | if (ret.ret0 == 0UL) { |
| 181 | tftf_testcase_printf("%s failed. Expected -1, received %ld\n", |
| 182 | __func__, (long int)ret.ret0); |
| 183 | return TEST_RESULT_FAIL; |
| 184 | } |
| 185 | |
| 186 | /* Issue the SMC with incorrect parameters and expect error */ |
| 187 | args.arg1 = 0ULL; |
| 188 | args.arg2 = 4ULL << 20; |
| 189 | |
| 190 | ret = tftf_smc(&args); |
| 191 | if (ret.ret0 == 0UL) { |
| 192 | tftf_testcase_printf("%s failed. Expected -1, received %ld\n", |
| 193 | __func__, (long int)ret.ret0); |
| 194 | return TEST_RESULT_FAIL; |
| 195 | } |
| 196 | |
| 197 | return TEST_RESULT_SUCCESS; |
| 198 | } |
anzhou | 42f4d19 | 2020-06-16 20:56:07 +0800 | [diff] [blame] | 199 | |
| 200 | /** |
| 201 | * @Test_Aim@ Test to read the SMMU_PER register contents and print the |
| 202 | * values. |
| 203 | */ |
| 204 | test_result_t test_get_smmu_per(void) |
| 205 | { |
| 206 | smc_args tegra_sip_smc = { TEGRA_SIP_GET_SMMU_PER, 0ULL, 0ULL, 0ULL, 0ULL }; |
| 207 | smc_ret_values ret; |
| 208 | |
| 209 | tftf_testcase_printf("Tegra SIP GET SMMU PER test\n"); |
| 210 | |
| 211 | ret = tftf_smc(&tegra_sip_smc); |
| 212 | |
| 213 | if (ret.ret0 != SMC_OK) { |
| 214 | tftf_testcase_printf("GET_SMMU_PER test Fail, got %ld\n", (long int)ret.ret0); |
| 215 | return TEST_RESULT_FAIL; |
| 216 | } |
| 217 | |
| 218 | tftf_testcase_printf("GET_SMMU_PER per[0] = %lu\n", ret.ret1); |
| 219 | tftf_testcase_printf("GET_SMMU_PER per[1] = %lu\n", ret.ret2); |
| 220 | tftf_testcase_printf("GET_SMMU_PER per[2] = %lu\n", ret.ret3); |
| 221 | |
| 222 | return TEST_RESULT_SUCCESS; |
| 223 | } |