Software APIs
epmp_test_unlock.c
1 // Copyright lowRISC contributors (OpenTitan project).
2 // Licensed under the Apache License, Version 2.0, see LICENSE for details.
3 // SPDX-License-Identifier: Apache-2.0
4 
5 #include "sw/device/silicon_creator/lib/epmp_test_unlock.h"
6 
7 #include <assert.h>
8 #include <stddef.h>
9 
11 #include "sw/device/lib/base/csr.h"
12 
13 bool epmp_unlock_test_status(void) {
14  // PMP entry dedicated to test status (DV).
15  enum {
16  kEntry = 6,
17  };
18 
19  // Permissions to apply to test status address space.
20  const epmp_perm_t kPerm = kEpmpPermLockedReadWrite;
21 
22  // Check that address space is word aligned.
23  uintptr_t status_addr = device_test_status_address();
24  if (status_addr % sizeof(uint32_t) != 0) {
25  return false;
26  }
27 
28  // Update the shadow register values.
29  epmp_region_t region = {.start = status_addr,
30  .end = status_addr + sizeof(uint32_t)};
31  epmp_state_configure_na4(kEntry, region, kPerm);
32 
33  // Update the hardware registers.
34  static_assert(kEntry == 6, "PMP entry has changed, update CSR operations.");
35  CSR_WRITE(CSR_REG_PMPADDR6, status_addr / sizeof(uint32_t));
36  CSR_SET_BITS(CSR_REG_PMPCFG1, (kEpmpModeNa4 | kPerm)
37  << ((kEntry % sizeof(uint32_t)) * 8));
38 
39  // Double check that the shadow registers match.
40  if (!epmp_state_check()) {
41  return false;
42  }
43 
44  return true;
45 }