Software APIs
rom_epmp.h
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 #ifndef OPENTITAN_SW_DEVICE_SILICON_CREATOR_ROM_ROM_EPMP_H_
6 #define OPENTITAN_SW_DEVICE_SILICON_CREATOR_ROM_ROM_EPMP_H_
7 
8 #include <stdint.h>
9 
10 #include "sw/device/silicon_creator/lib/drivers/lifecycle.h"
11 #include "sw/device/silicon_creator/lib/epmp_state.h"
12 
13 #ifdef __cplusplus
14 extern "C" {
15 #endif // __cplusplus
16 
17 /**
18  * ROM enhanced Physical Memory Protection (ePMP) library.
19  *
20  * The ePMP configuration is managed in two parts:
21  *
22  * 1. The actual hardware configuration held in CSRs
23  * 2. The in-memory copy of register values in `epmp_state_t` that is used
24  * to verify the CSRs
25  *
26  * Every time the hardware configuration is updated the in-memory copy
27  * must also be updated. The hardware configuration is usually interacted
28  * with directly using the CSR library or assembly whereas the in-memory
29  * copy of the state should normally be modified using configuration functions
30  * from the silicon creator ePMP library.
31  *
32  * This separation of concerns allows the hardware configuration to be
33  * updated efficiently as needed (including before the C runtime is
34  * initialized) with the in-memory copy of the state used to double check the
35  * configuration as required.
36  */
37 
38 /**
39  * Initialise the ePMP in-memory copy of the register state to reflect the
40  * hardware configuration expected at entry to the ROM C code.
41  *
42  * The actual hardware configuration is performed separately, either by reset
43  * logic or in assembly. This code must be kept in sync with any changes
44  * to the hardware configuration.
45  *
46  * @param lc_state The current lifecycle state to check for debug enable.
47  */
48 void rom_epmp_state_init(lifecycle_state_t lc_state);
49 
50 /**
51  * Unlocks the provided ROM_EXT image region with read-execute permissions.
52  *
53  * The provided ePMP state is also updated to reflect the changes made to the
54  * hardware configuration.
55  *
56  * @param region Region for executable sections in ROM_EXT image.
57  */
58 void rom_epmp_unlock_rom_ext_rx(epmp_region_t region);
59 
60 /**
61  * Unlocks the provided ROM_EXT image region with read-only permissions.
62  *
63  * The provided ePMP state is also updated to reflect the changes made to the
64  * hardware configuration.
65  * The image size must be power of 2 as this function uses NAPOT
66  * (Naturally-Aligned-Power-Of-Two) addressing mode.
67  *
68  * @param region Region in the ROM_EXT image to receive read-only permission.
69  */
70 void rom_epmp_unlock_rom_ext_r(epmp_region_t region);
71 /**
72  * Configure the ePMP entry to manage access to Debug ROM based on life cycle
73  * state.
74  *
75  * @param lc_state The current lifecycle state to check for debug enable.
76  */
77 void rom_epmp_config_debug_rom(lifecycle_state_t lc_state);
78 
79 #ifdef __cplusplus
80 } // extern "C"
81 #endif // __cplusplus
82 
83 #endif // OPENTITAN_SW_DEVICE_SILICON_CREATOR_ROM_ROM_EPMP_H_