7 #include "sw/device/lib/runtime/irq.h"
8 #include "sw/device/lib/runtime/pmp.h"
9 #include "sw/device/lib/testing/test_framework/check.h"
11 #include "sw/device/silicon_creator/lib/epmp_state.h"
32 #define PMP_LOAD_REGION_ID 7
34 #define PMP_LOAD_RANGE_BUFFER_SIZE 1024
35 #define PMP_LOAD_RANGE_SIZE 512
36 #define PMP_LOAD_RANGE_BOTTOM_OFFSET 0
37 #define PMP_LOAD_RANGE_TOP_OFFSET \
38 (PMP_LOAD_RANGE_BOTTOM_OFFSET + PMP_LOAD_RANGE_SIZE - 1)
44 static volatile bool pmp_load_exception;
49 __attribute__((aligned(PMP_LOAD_RANGE_SIZE)))
50 static volatile char pmp_load_test_data[PMP_LOAD_RANGE_BUFFER_SIZE];
52 void ottf_load_store_fault_handler(uint32_t *exc_info) {
53 pmp_load_exception =
true;
56 static void pmp_configure_load_tor(
void) {
57 uintptr_t load_range_start =
58 (uintptr_t)&pmp_load_test_data[PMP_LOAD_RANGE_BOTTOM_OFFSET];
61 uintptr_t load_range_end =
62 (uintptr_t)&pmp_load_test_data[PMP_LOAD_RANGE_SIZE];
65 .
lock = kPmpRegionLockLocked,
66 .permissions = kPmpRegionPermissionsNone,
69 pmp_region_configure_result_t result = pmp_region_configure_tor(
70 PMP_LOAD_REGION_ID, config, load_range_start, load_range_end);
71 CHECK(result == kPmpRegionConfigureOk,
72 "Load configuration failed, error code = %d", result);
75 OTTF_DEFINE_TEST_CONFIG();
80 for (pmp_region_index_t region = PMP_LOAD_REGION_ID - 1;
81 region <= PMP_LOAD_REGION_ID; region++) {
83 pmp_region_configure_result_t result =
84 pmp_region_is_configured(region, &configured);
85 CHECK(result == kPmpRegionConfigureOk,
86 "PMP region %d cfg read failed, error code = %d", region, result);
87 CHECK(!configured,
"PMP region %d is already configured", region);
90 pmp_load_exception =
false;
91 char load = pmp_load_test_data[PMP_LOAD_RANGE_BOTTOM_OFFSET];
92 CHECK(!pmp_load_exception,
"Load access violation before PMP configuration");
94 pmp_configure_load_tor();
96 pmp_load_exception =
false;
97 load = pmp_load_test_data[PMP_LOAD_RANGE_BOTTOM_OFFSET];
98 CHECK(pmp_load_exception,
99 "No load access violation on the bottom of the range load");
101 pmp_load_exception =
false;
102 load = pmp_load_test_data[PMP_LOAD_RANGE_TOP_OFFSET];
103 CHECK(pmp_load_exception,
104 "No load access violation on the top of the range load");
106 pmp_load_exception =
false;
107 load = pmp_load_test_data[PMP_LOAD_RANGE_TOP_OFFSET + 1];
108 CHECK(!pmp_load_exception,
"Load access violation on top of the range + 1");