blob: 911962e1a008c0d5825de2bfce04b65f0da8ddce [file] [log] [blame]
Manish Pandey09d28232023-04-24 09:48:45 +01001/*
2 * Copyright (c) 2023, Arm Limited. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7
8#include <arch_helpers.h>
9#include <arm_arch_svc.h>
10#include <debug.h>
11#include <mmio.h>
12#include <tftf_lib.h>
13#include <smccc.h>
14#include <xlat_tables_v2.h>
15
16#define TEST_ADDRESS UL(0x7FFFF000)
17
18/*
19 * Purpose of these tests is to ensure EA from lower EL trap/handled in EL3.
20 *
21 * Tests HANDLE_EA_EL3_FIRST_NS feature(SCR_EL3.EA = 1) of TF-A
22 *
23 * Works in conjunction with PLATFORM_TEST_EA_FFH macro in TF-A.
24 */
25
26/*
27 * This test maps a non-existent memory as Device memory and reads it.
28 * Memory is mapped as device and cause an error on bus and trap as an Sync EA.
29 */
30test_result_t test_inject_syncEA(void)
31{
32 int rc;
33
34 rc = mmap_add_dynamic_region(TEST_ADDRESS, TEST_ADDRESS, PAGE_SIZE,
35 MT_DEVICE | MT_RO | MT_NS);
36 if (rc != 0) {
37 tftf_testcase_printf("%d: mapping address %lu(%d) failed\n",
38 __LINE__, TEST_ADDRESS, rc);
39 return TEST_RESULT_FAIL;
40 }
41
42 /*
43 * Try reading invalid address, which will cause an exception to be handled in EL3.
44 * EL3 after handling the exception returns to the next instruction to avoid
45 * continous exceptions.
46 */
47 rc = mmio_read_32(TEST_ADDRESS);
48
49 rc = mmap_remove_dynamic_region(TEST_ADDRESS, PAGE_SIZE);
50 if (rc != 0) {
51 tftf_testcase_printf("%d: mmap_remove_dynamic_region() = %d\n", __LINE__, rc);
52 return TEST_RESULT_FAIL;
53 }
54
55 return TEST_RESULT_SUCCESS;
56}
57
58/*
59 * This test maps a non-existent memory as Device memory and write to it.
60 * Memory is mapped as device and cause an error on bus and trap as an SError.
61 */
62test_result_t test_inject_serror(void)
63{
64 int rc;
65
66 rc = mmap_add_dynamic_region(TEST_ADDRESS, TEST_ADDRESS, PAGE_SIZE,
67 MT_DEVICE | MT_RW | MT_NS);
68 if (rc != 0) {
69 tftf_testcase_printf("%d: mapping address %lu(%d) failed\n",
70 __LINE__, TEST_ADDRESS, rc);
71 return TEST_RESULT_FAIL;
72 }
73
74 /* Try writing to invalid address */
75 mmio_write_32(TEST_ADDRESS, 1);
76
77 rc = mmap_remove_dynamic_region(TEST_ADDRESS, PAGE_SIZE);
78 if (rc != 0) {
79 tftf_testcase_printf("%d: mmap_remove_dynamic_region() = %d\n", __LINE__, rc);
80 return TEST_RESULT_FAIL;
81 }
82
83 return TEST_RESULT_SUCCESS;
84}