1 /*
2  * SPDX-FileCopyrightText: 2020-2021 Espressif Systems (Shanghai) CO LTD
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #pragma once
8 
9 #include "soc/cache_memory.h"
10 #include "soc/memprot_defs.h"
11 #include "hal/memprot_types.h"
12 
13 #ifdef __cplusplus
14 extern "C" {
15 #endif
16 
17 /* ******************************************************************************************************
18  * *** COMMON ***
19  * ******************************************************************************************************/
memprot_ll_set_iram0_dram0_split_line_lock(void)20 static inline void memprot_ll_set_iram0_dram0_split_line_lock(void)
21 {
22     REG_WRITE(SENSITIVE_CORE_X_IRAM0_DRAM0_DMA_SPLIT_LINE_CONSTRAIN_0_REG, 1);
23 }
24 
memprot_ll_get_iram0_dram0_split_line_lock(void)25 static inline bool memprot_ll_get_iram0_dram0_split_line_lock(void)
26 {
27     return REG_READ(SENSITIVE_CORE_X_IRAM0_DRAM0_DMA_SPLIT_LINE_CONSTRAIN_0_REG) == 1;
28 }
29 
memprot_ll_get_split_addr_from_reg(uint32_t regval,uint32_t base)30 static inline void *memprot_ll_get_split_addr_from_reg(uint32_t regval, uint32_t base)
31 {
32     constrain_reg_fields_t reg_val;
33     reg_val.val = regval;
34 
35     uint32_t off = reg_val.splitaddr << 9;
36 
37     if (reg_val.cat0 == 0x1 || reg_val.cat0 == 0x2) {
38         return (void *)(base + off);
39     } else if (reg_val.cat1 == 0x1 || reg_val.cat1 == 0x2) {
40         return (void *)(base + I_D_SRAM_SEGMENT_SIZE + off);
41     } else if (reg_val.cat2 == 0x1 || reg_val.cat2 == 0x2) {
42         return (void *)(base + (2 * I_D_SRAM_SEGMENT_SIZE) + off);
43     } else {
44         /* Either the register was not configured at all or incorrectly configured */
45         return NULL;
46     }
47 }
48 
49 /* ******************************************************************************************************
50  * *** IRAM0 ***
51  * ******************************************************************************************************/
memprot_ll_iram0_get_intr_source_num(void)52 static inline uint32_t memprot_ll_iram0_get_intr_source_num(void)
53 {
54     return ETS_CORE0_IRAM0_PMS_INTR_SOURCE;
55 }
56 
57 /* ********************************
58  * IRAM0 - SPLIT LINES
59  *
60  * NOTES:
61  * 1. IRAM0/DRAM0 split-lines must be aligned to 512B boundaries (PMS module restriction)
62  * 2. split address must fall into appropriate IRAM0/DRAM0 region
63  */
memprot_ll_set_iram0_split_line(const void * line_addr,uint32_t sensitive_reg)64 static inline memprot_ll_err_t memprot_ll_set_iram0_split_line(const void *line_addr, uint32_t sensitive_reg)
65 {
66     uint32_t addr = (uint32_t)line_addr;
67 
68     if (addr < IRAM0_SRAM_LEVEL_1_LOW || addr > IRAM0_SRAM_LEVEL_3_HIGH) {
69         return MEMP_LL_ERR_SPLIT_ADDR_OUT_OF_RANGE;
70     }
71 
72     if (addr % 0x200 != 0) {
73         return MEMP_LL_ERR_SPLIT_ADDR_UNALIGNED;
74     }
75 
76     uint32_t category[3] = {0};
77     if (addr <= IRAM0_SRAM_LEVEL_1_HIGH) {
78         category[0] = 0x2;
79         category[1] = category[2] = 0x3;
80     } else if (addr >= IRAM0_SRAM_LEVEL_2_LOW && addr <= IRAM0_SRAM_LEVEL_2_HIGH) {
81         category[1] = 0x2;
82         category[2] = 0x3;
83     } else {
84         category[2] = 0x2;
85     }
86 
87     //NOTE: category & split line address bits are the same for all the areas
88     uint32_t category_bits =
89         (category[0] << SENSITIVE_CORE_X_IRAM0_DRAM0_DMA_SRAM_CATEGORY_0_S) |
90         (category[1] << SENSITIVE_CORE_X_IRAM0_DRAM0_DMA_SRAM_CATEGORY_1_S) |
91         (category[2] << SENSITIVE_CORE_X_IRAM0_DRAM0_DMA_SRAM_CATEGORY_2_S);
92 
93     uint32_t conf_addr = ((addr >> I_D_SPLIT_LINE_SHIFT) & SENSITIVE_CORE_X_IRAM0_DRAM0_DMA_SRAM_SPLITADDR_V) << SENSITIVE_CORE_X_IRAM0_DRAM0_DMA_SRAM_SPLITADDR_S;
94     uint32_t reg_cfg = conf_addr | category_bits;
95 
96     REG_WRITE(sensitive_reg, reg_cfg);
97 
98     return MEMP_LL_OK;
99 }
100 
101 /* can be both IRAM0/DRAM0 address */
memprot_ll_set_iram0_split_line_main_I_D(const void * line_addr)102 static inline memprot_ll_err_t memprot_ll_set_iram0_split_line_main_I_D(const void *line_addr)
103 {
104     return memprot_ll_set_iram0_split_line(line_addr, SENSITIVE_CORE_X_IRAM0_DRAM0_DMA_SPLIT_LINE_CONSTRAIN_1_REG);
105 }
106 
memprot_ll_set_iram0_split_line_I_0(const void * line_addr)107 static inline memprot_ll_err_t memprot_ll_set_iram0_split_line_I_0(const void *line_addr)
108 {
109     return memprot_ll_set_iram0_split_line(line_addr, SENSITIVE_CORE_X_IRAM0_DRAM0_DMA_SPLIT_LINE_CONSTRAIN_2_REG);
110 }
111 
memprot_ll_set_iram0_split_line_I_1(const void * line_addr)112 static inline memprot_ll_err_t memprot_ll_set_iram0_split_line_I_1(const void *line_addr)
113 {
114     return memprot_ll_set_iram0_split_line(line_addr, SENSITIVE_CORE_X_IRAM0_DRAM0_DMA_SPLIT_LINE_CONSTRAIN_3_REG);
115 }
116 
memprot_ll_get_iram0_split_line_main_I_D_cat(void)117 static inline uint32_t memprot_ll_get_iram0_split_line_main_I_D_cat(void)
118 {
119     return REG_READ(SENSITIVE_CORE_X_IRAM0_DRAM0_DMA_SPLIT_LINE_CONSTRAIN_1_REG) & 0x3F;
120 }
121 
memprot_ll_get_iram0_split_line_I_0_cat(void)122 static inline uint32_t memprot_ll_get_iram0_split_line_I_0_cat(void)
123 {
124     return REG_READ(SENSITIVE_CORE_X_IRAM0_DRAM0_DMA_SPLIT_LINE_CONSTRAIN_2_REG) & 0x3F;
125 }
126 
memprot_ll_get_iram0_split_line_I_1_cat(void)127 static inline uint32_t memprot_ll_get_iram0_split_line_I_1_cat(void)
128 {
129     return REG_READ(SENSITIVE_CORE_X_IRAM0_DRAM0_DMA_SPLIT_LINE_CONSTRAIN_3_REG) & 0x3F;
130 }
131 
memprot_ll_get_iram0_split_line_main_I_D(void)132 static inline void *memprot_ll_get_iram0_split_line_main_I_D(void)
133 {
134     return memprot_ll_get_split_addr_from_reg(REG_READ(SENSITIVE_CORE_X_IRAM0_DRAM0_DMA_SPLIT_LINE_CONSTRAIN_1_REG), SOC_DIRAM_IRAM_LOW);
135 }
136 
memprot_ll_get_iram0_split_line_I_0(void)137 static inline void *memprot_ll_get_iram0_split_line_I_0(void)
138 {
139     return memprot_ll_get_split_addr_from_reg(REG_READ(SENSITIVE_CORE_X_IRAM0_DRAM0_DMA_SPLIT_LINE_CONSTRAIN_2_REG), SOC_DIRAM_IRAM_LOW);
140 }
141 
memprot_ll_get_iram0_split_line_I_1(void)142 static inline void *memprot_ll_get_iram0_split_line_I_1(void)
143 {
144     return memprot_ll_get_split_addr_from_reg(REG_READ(SENSITIVE_CORE_X_IRAM0_DRAM0_DMA_SPLIT_LINE_CONSTRAIN_3_REG), SOC_DIRAM_IRAM_LOW);
145 }
146 
147 ///////////////////////////////////
148 // IRAM0 - PMS CONFIGURATION
149 
150 // lock
memprot_ll_iram0_set_pms_lock(void)151 static inline void memprot_ll_iram0_set_pms_lock(void)
152 {
153     REG_WRITE(SENSITIVE_CORE_X_IRAM0_PMS_CONSTRAIN_0_REG, 1);
154 }
155 
memprot_ll_iram0_get_pms_lock(void)156 static inline bool memprot_ll_iram0_get_pms_lock(void)
157 {
158     return REG_READ(SENSITIVE_CORE_X_IRAM0_PMS_CONSTRAIN_0_REG) == 1;
159 }
160 
161 // permission settings
memprot_ll_iram0_set_permissions(bool r,bool w,bool x)162 static inline uint32_t memprot_ll_iram0_set_permissions(bool r, bool w, bool x)
163 {
164     uint32_t permissions = 0;
165     if (r) {
166         permissions |= SENSITIVE_CORE_X_IRAM0_PMS_CONSTRAIN_SRAM_WORLD_X_R;
167     }
168     if (w) {
169         permissions |= SENSITIVE_CORE_X_IRAM0_PMS_CONSTRAIN_SRAM_WORLD_X_W;
170     }
171     if (x) {
172         permissions |= SENSITIVE_CORE_X_IRAM0_PMS_CONSTRAIN_SRAM_WORLD_X_F;
173     }
174 
175     return permissions;
176 }
177 
memprot_ll_iram0_set_pms_area_0(bool r,bool w,bool x)178 static inline void memprot_ll_iram0_set_pms_area_0(bool r, bool w, bool x)
179 {
180     REG_SET_FIELD(SENSITIVE_CORE_X_IRAM0_PMS_CONSTRAIN_2_REG, SENSITIVE_CORE_X_IRAM0_PMS_CONSTRAIN_SRAM_WORLD_0_PMS_0, memprot_ll_iram0_set_permissions(r, w, x));
181 }
182 
memprot_ll_iram0_set_pms_area_1(bool r,bool w,bool x)183 static inline void memprot_ll_iram0_set_pms_area_1(bool r, bool w, bool x)
184 {
185     REG_SET_FIELD(SENSITIVE_CORE_X_IRAM0_PMS_CONSTRAIN_2_REG, SENSITIVE_CORE_X_IRAM0_PMS_CONSTRAIN_SRAM_WORLD_0_PMS_1, memprot_ll_iram0_set_permissions(r, w, x));
186 }
187 
memprot_ll_iram0_set_pms_area_2(bool r,bool w,bool x)188 static inline void memprot_ll_iram0_set_pms_area_2(bool r, bool w, bool x)
189 {
190     REG_SET_FIELD(SENSITIVE_CORE_X_IRAM0_PMS_CONSTRAIN_2_REG, SENSITIVE_CORE_X_IRAM0_PMS_CONSTRAIN_SRAM_WORLD_0_PMS_2, memprot_ll_iram0_set_permissions(r, w, x));
191 }
192 
memprot_ll_iram0_set_pms_area_3(bool r,bool w,bool x)193 static inline void memprot_ll_iram0_set_pms_area_3(bool r, bool w, bool x)
194 {
195     REG_SET_FIELD(SENSITIVE_CORE_X_IRAM0_PMS_CONSTRAIN_2_REG, SENSITIVE_CORE_X_IRAM0_PMS_CONSTRAIN_SRAM_WORLD_0_PMS_3, memprot_ll_iram0_set_permissions(r, w, x));
196 }
197 
memprot_ll_iram0_get_permissions(uint32_t perms,bool * r,bool * w,bool * x)198 static inline void memprot_ll_iram0_get_permissions(uint32_t perms, bool *r, bool *w, bool *x)
199 {
200     *r = perms & SENSITIVE_CORE_X_IRAM0_PMS_CONSTRAIN_SRAM_WORLD_X_R;
201     *w = perms & SENSITIVE_CORE_X_IRAM0_PMS_CONSTRAIN_SRAM_WORLD_X_W;
202     *x = perms & SENSITIVE_CORE_X_IRAM0_PMS_CONSTRAIN_SRAM_WORLD_X_F;
203 }
204 
memprot_ll_iram0_get_pms_area_0(bool * r,bool * w,bool * x)205 static inline void memprot_ll_iram0_get_pms_area_0(bool *r, bool *w, bool *x)
206 {
207     uint32_t permissions = REG_GET_FIELD(SENSITIVE_CORE_X_IRAM0_PMS_CONSTRAIN_2_REG, SENSITIVE_CORE_X_IRAM0_PMS_CONSTRAIN_SRAM_WORLD_0_PMS_0);
208     memprot_ll_iram0_get_permissions(permissions, r, w, x);
209 }
210 
memprot_ll_iram0_get_pms_area_1(bool * r,bool * w,bool * x)211 static inline void memprot_ll_iram0_get_pms_area_1(bool *r, bool *w, bool *x)
212 {
213     uint32_t permissions = REG_GET_FIELD(SENSITIVE_CORE_X_IRAM0_PMS_CONSTRAIN_2_REG, SENSITIVE_CORE_X_IRAM0_PMS_CONSTRAIN_SRAM_WORLD_0_PMS_1);
214     memprot_ll_iram0_get_permissions(permissions, r, w, x);
215 }
216 
memprot_ll_iram0_get_pms_area_2(bool * r,bool * w,bool * x)217 static inline void memprot_ll_iram0_get_pms_area_2(bool *r, bool *w, bool *x)
218 {
219     uint32_t permissions = REG_GET_FIELD(SENSITIVE_CORE_X_IRAM0_PMS_CONSTRAIN_2_REG, SENSITIVE_CORE_X_IRAM0_PMS_CONSTRAIN_SRAM_WORLD_0_PMS_2);
220     memprot_ll_iram0_get_permissions(permissions, r, w, x);
221 }
222 
memprot_ll_iram0_get_pms_area_3(bool * r,bool * w,bool * x)223 static inline void memprot_ll_iram0_get_pms_area_3(bool *r, bool *w, bool *x)
224 {
225     uint32_t permissions = REG_GET_FIELD(SENSITIVE_CORE_X_IRAM0_PMS_CONSTRAIN_2_REG, SENSITIVE_CORE_X_IRAM0_PMS_CONSTRAIN_SRAM_WORLD_0_PMS_3);
226     memprot_ll_iram0_get_permissions(permissions, r, w, x);
227 }
228 
229 
230 ///////////////////////////////////
231 // IRAM0 - MONITOR
232 
233 // lock
memprot_ll_iram0_set_monitor_lock(void)234 static inline void memprot_ll_iram0_set_monitor_lock(void)
235 {
236     REG_WRITE(SENSITIVE_CORE_0_IRAM0_PMS_MONITOR_0_REG, 1);
237 }
238 
memprot_ll_iram0_get_monitor_lock(void)239 static inline bool memprot_ll_iram0_get_monitor_lock(void)
240 {
241     return REG_READ(SENSITIVE_CORE_0_IRAM0_PMS_MONITOR_0_REG) == 1;
242 }
243 
244 // interrupt enable/clear
memprot_ll_iram0_set_monitor_en(bool enable)245 static inline void memprot_ll_iram0_set_monitor_en(bool enable)
246 {
247     if (enable) {
248         REG_SET_BIT(SENSITIVE_CORE_0_IRAM0_PMS_MONITOR_1_REG, SENSITIVE_CORE_0_IRAM0_PMS_MONITOR_VIOLATE_EN);
249     } else {
250         REG_CLR_BIT(SENSITIVE_CORE_0_IRAM0_PMS_MONITOR_1_REG, SENSITIVE_CORE_0_IRAM0_PMS_MONITOR_VIOLATE_EN);
251     }
252 }
253 
memprot_ll_iram0_get_monitor_intrclr(void)254 static inline bool memprot_ll_iram0_get_monitor_intrclr(void)
255 {
256     return REG_GET_BIT(SENSITIVE_CORE_0_IRAM0_PMS_MONITOR_1_REG, SENSITIVE_CORE_0_IRAM0_PMS_MONITOR_VIOLATE_CLR) > 0;
257 }
258 
memprot_ll_iram0_get_monitor_en(void)259 static inline bool memprot_ll_iram0_get_monitor_en(void)
260 {
261     return REG_GET_FIELD(SENSITIVE_CORE_0_IRAM0_PMS_MONITOR_1_REG, SENSITIVE_CORE_0_IRAM0_PMS_MONITOR_VIOLATE_EN) == 1;
262 }
263 
memprot_ll_iram0_set_monitor_intrclr(void)264 static inline void memprot_ll_iram0_set_monitor_intrclr(void)
265 {
266     REG_SET_BIT(SENSITIVE_CORE_0_IRAM0_PMS_MONITOR_1_REG, SENSITIVE_CORE_0_IRAM0_PMS_MONITOR_VIOLATE_CLR);
267 }
268 
memprot_ll_iram0_reset_monitor_intrclr(void)269 static inline void memprot_ll_iram0_reset_monitor_intrclr(void)
270 {
271     REG_CLR_BIT(SENSITIVE_CORE_0_IRAM0_PMS_MONITOR_1_REG, SENSITIVE_CORE_0_IRAM0_PMS_MONITOR_VIOLATE_CLR);
272 }
273 
memprot_ll_iram0_get_monitor_enable_register(void)274 static inline uint32_t memprot_ll_iram0_get_monitor_enable_register(void)
275 {
276     return REG_READ(SENSITIVE_CORE_0_IRAM0_PMS_MONITOR_1_REG);
277 }
278 
279 // permission violation status
memprot_ll_iram0_get_monitor_status_intr(void)280 static inline uint32_t memprot_ll_iram0_get_monitor_status_intr(void)
281 {
282     return REG_GET_FIELD(SENSITIVE_CORE_0_IRAM0_PMS_MONITOR_2_REG, SENSITIVE_CORE_0_IRAM0_PMS_MONITOR_VIOLATE_INTR);
283 }
284 
memprot_ll_iram0_get_monitor_status_fault_wr(void)285 static inline uint32_t memprot_ll_iram0_get_monitor_status_fault_wr(void)
286 {
287     return REG_GET_FIELD(SENSITIVE_CORE_0_IRAM0_PMS_MONITOR_2_REG, SENSITIVE_CORE_0_IRAM0_PMS_MONITOR_VIOLATE_STATUS_WR);
288 }
289 
memprot_ll_iram0_get_monitor_status_fault_loadstore(void)290 static inline uint32_t memprot_ll_iram0_get_monitor_status_fault_loadstore(void)
291 {
292     return REG_GET_FIELD(SENSITIVE_CORE_0_IRAM0_PMS_MONITOR_2_REG, SENSITIVE_CORE_0_IRAM0_PMS_MONITOR_VIOLATE_STATUS_LOADSTORE);
293 }
294 
memprot_ll_iram0_get_monitor_status_fault_world(void)295 static inline uint32_t memprot_ll_iram0_get_monitor_status_fault_world(void)
296 {
297     return REG_GET_FIELD(SENSITIVE_CORE_0_IRAM0_PMS_MONITOR_2_REG, SENSITIVE_CORE_0_IRAM0_PMS_MONITOR_VIOLATE_STATUS_WORLD);
298 }
299 
memprot_ll_iram0_get_monitor_status_fault_addr(void)300 static inline intptr_t memprot_ll_iram0_get_monitor_status_fault_addr(void)
301 {
302     uint32_t addr = REG_GET_FIELD(SENSITIVE_CORE_0_IRAM0_PMS_MONITOR_2_REG, SENSITIVE_CORE_0_IRAM0_PMS_MONITOR_VIOLATE_STATUS_ADDR);
303     return (intptr_t)(addr > 0 ? (addr << I_D_FAULT_ADDR_SHIFT) + IRAM0_ADDRESS_LOW : 0);
304 }
305 
memprot_ll_iram0_get_monitor_status_register(void)306 static inline uint32_t memprot_ll_iram0_get_monitor_status_register(void)
307 {
308     return REG_READ(SENSITIVE_CORE_0_IRAM0_PMS_MONITOR_2_REG);
309 }
310 
311 
312 /* ******************************************************************************************************
313  * *** RTC_FAST ***
314  */
315 
memprot_ll_rtcfast_get_intr_source_num(void)316 static inline uint32_t memprot_ll_rtcfast_get_intr_source_num(void)
317 {
318     return ETS_CORE0_PIF_PMS_INTR_SOURCE;
319 }
320 
321 //shared PIF PMS lock
322 //!!!: use after ALL the constraints have been set
memprot_ll_set_pif_constraint_lock(void)323 static inline void memprot_ll_set_pif_constraint_lock(void)
324 {
325     REG_WRITE(SENSITIVE_CORE_0_PIF_PMS_CONSTRAIN_0_REG, 1);
326 }
327 
memprot_ll_get_pif_constraint_lock(void)328 static inline bool memprot_ll_get_pif_constraint_lock(void)
329 {
330     return REG_READ(SENSITIVE_CORE_0_PIF_PMS_CONSTRAIN_0_REG) == 1;
331 }
332 
memprot_ll_rtcfast_get_splitaddr_register(void)333 static inline uint32_t memprot_ll_rtcfast_get_splitaddr_register(void)
334 {
335     return REG_READ(SENSITIVE_CORE_0_PIF_PMS_CONSTRAIN_9_REG);
336 }
337 
338 /* ********************************
339  * IRAM0 RTCFAST - SPLIT LINES
340  *
341  * NOTES:
342  * 1. there is only 1 split line for RTCFAST/WORLD
343  * 2. RTCFAST split-line must be aligned to 4B boundaries (PMS stores 11 bits of 13-bit offset in 8kB RTCFAST region)
344  * 3. RTCFAST has weird section structure (text -> dummy (!) -> force -> data) - .dummy section seems to have wrong mapping (it doesn't fall inline with .rtctext)
345  */
memprot_ll_set_rtcfast_split_line(const void * line_addr,memprot_ll_world_t world)346 static inline memprot_ll_err_t memprot_ll_set_rtcfast_split_line(const void *line_addr, memprot_ll_world_t world)
347 {
348     uint32_t addr = (uint32_t)line_addr;
349     uint32_t mask;
350 
351     if (addr < SOC_RTC_IRAM_LOW || addr >= SOC_RTC_IRAM_HIGH) {
352         return MEMP_LL_ERR_SPLIT_ADDR_OUT_OF_RANGE;
353     }
354 
355     if (addr % 0x4 != 0) {
356         return MEMP_LL_ERR_SPLIT_ADDR_UNALIGNED;
357     }
358 
359     switch (world) {
360     case MEMP_LL_WORLD_0:
361         mask = SENSITIVE_CORE_0_PIF_PMS_CONSTRAIN_RTCFAST_SPLTADDR_WORLD_0_M;
362         break;
363     case MEMP_LL_WORLD_1:
364         mask = SENSITIVE_CORE_0_PIF_PMS_CONSTRAIN_RTCFAST_SPLTADDR_WORLD_1_M;
365         break;
366     default:
367         return MEMP_LL_ERR_WORLD_INVALID;
368     }
369 
370     //offset bits to store are the same width for both worlds -> using SENSITIVE_CORE_0_PIF_PMS_CONSTRAIN_RTCFAST_SPLTADDR_WORLD_0_V
371     CLEAR_PERI_REG_MASK(SENSITIVE_CORE_0_PIF_PMS_CONSTRAIN_9_REG, mask);
372     REG_SET_BITS(SENSITIVE_CORE_0_PIF_PMS_CONSTRAIN_9_REG, mask, (addr >> 2) & SENSITIVE_CORE_0_PIF_PMS_CONSTRAIN_RTCFAST_SPLTADDR_WORLD_0_V);
373 
374     return MEMP_LL_OK;
375 }
376 
memprot_ll_get_rtcfast_split_line(memprot_ll_world_t world,void ** line_addr)377 static inline memprot_ll_err_t memprot_ll_get_rtcfast_split_line(memprot_ll_world_t world, void **line_addr)
378 {
379     uint32_t reg_addr = REG_READ(SENSITIVE_CORE_0_PIF_PMS_CONSTRAIN_9_REG);
380     uint32_t mask = 0;
381     uint32_t shift = 0;
382 
383     switch (world) {
384     case MEMP_LL_WORLD_0:
385         mask = SENSITIVE_CORE_0_PIF_PMS_CONSTRAIN_RTCFAST_SPLTADDR_WORLD_0_M;
386         shift = SENSITIVE_CORE_0_PIF_PMS_CONSTRAIN_RTCFAST_SPLTADDR_WORLD_0_S;
387         break;
388     case MEMP_LL_WORLD_1:
389         mask = SENSITIVE_CORE_0_PIF_PMS_CONSTRAIN_RTCFAST_SPLTADDR_WORLD_1_M;
390         shift = SENSITIVE_CORE_0_PIF_PMS_CONSTRAIN_RTCFAST_SPLTADDR_WORLD_1_S;
391         break;
392     default:
393         return MEMP_LL_ERR_WORLD_INVALID;
394     }
395 
396     *line_addr = (void *)((((reg_addr & mask) >> shift) << 2) + SOC_RTC_IRAM_LOW);
397 
398     return MEMP_LL_OK;
399 }
400 
401 ///////////////////////////////////
402 // RTC_FAST - PMS CONFIGURATION
403 
404 // permission settings
memprot_ll_rtcfast_set_permissions(bool r,bool w,bool x)405 static inline uint32_t memprot_ll_rtcfast_set_permissions(bool r, bool w, bool x)
406 {
407     uint32_t permissions = 0;
408     if (r) {
409         permissions |= SENSITIVE_CORE_0_PIF_PMS_CONSTRAIN_RTCFAST_WORLD_X_R;
410     }
411     if (w) {
412         permissions |= SENSITIVE_CORE_0_PIF_PMS_CONSTRAIN_RTCFAST_WORLD_X_W;
413     }
414     if (x) {
415         permissions |= SENSITIVE_CORE_0_PIF_PMS_CONSTRAIN_RTCFAST_WORLD_X_F;
416     }
417 
418     return permissions;
419 }
420 
memprot_ll_rtcfast_set_pms_area(bool r,bool w,bool x,memprot_ll_world_t world,memprot_ll_area_t area)421 static inline memprot_ll_err_t memprot_ll_rtcfast_set_pms_area(bool r, bool w, bool x, memprot_ll_world_t world, memprot_ll_area_t area)
422 {
423     uint32_t bits = 0;
424     uint32_t mask = 0;
425 
426     switch (world) {
427     case MEMP_LL_WORLD_0: {
428         switch (area) {
429         case MEMP_LL_AREA_LOW:
430             bits = memprot_ll_rtcfast_set_permissions(r, w, x) << SENSITIVE_CORE_0_PIF_PMS_CONSTRAIN_RTCFAST_WORLD_0_L_S;
431             mask = SENSITIVE_CORE_0_PIF_PMS_CONSTRAIN_RTCFAST_WORLD_0_L_M;
432             break;
433         case MEMP_LL_AREA_HIGH:
434             bits = memprot_ll_rtcfast_set_permissions(r, w, x) << SENSITIVE_CORE_0_PIF_PMS_CONSTRAIN_RTCFAST_WORLD_0_H_S;
435             mask = SENSITIVE_CORE_0_PIF_PMS_CONSTRAIN_RTCFAST_WORLD_0_H_M;
436             break;
437         default:
438             return MEMP_LL_ERR_AREA_INVALID;
439         }
440     } break;
441     case MEMP_LL_WORLD_1: {
442         switch (area) {
443         case MEMP_LL_AREA_LOW:
444             bits = memprot_ll_rtcfast_set_permissions(r, w, x) << SENSITIVE_CORE_0_PIF_PMS_CONSTRAIN_RTCFAST_WORLD_1_L_S;
445             mask = SENSITIVE_CORE_0_PIF_PMS_CONSTRAIN_RTCFAST_WORLD_1_L_M;
446             break;
447         case MEMP_LL_AREA_HIGH:
448             bits = memprot_ll_rtcfast_set_permissions(r, w, x) << SENSITIVE_CORE_0_PIF_PMS_CONSTRAIN_RTCFAST_WORLD_1_H_S;
449             mask = SENSITIVE_CORE_0_PIF_PMS_CONSTRAIN_RTCFAST_WORLD_1_H_M;
450             break;
451         default:
452             return MEMP_LL_ERR_AREA_INVALID;
453         }
454     } break;
455     default:
456         return MEMP_LL_ERR_WORLD_INVALID;
457     }
458 
459     CLEAR_PERI_REG_MASK(SENSITIVE_CORE_0_PIF_PMS_CONSTRAIN_10_REG, mask);
460     REG_SET_BITS(SENSITIVE_CORE_0_PIF_PMS_CONSTRAIN_10_REG, bits, mask);
461 
462     return MEMP_LL_OK;
463 }
464 
memprot_ll_rtcfast_get_permissions(uint32_t perms,bool * r,bool * w,bool * x)465 static inline void memprot_ll_rtcfast_get_permissions(uint32_t perms, bool *r, bool *w, bool *x)
466 {
467     *r = perms & SENSITIVE_CORE_0_PIF_PMS_CONSTRAIN_RTCFAST_WORLD_X_R;
468     *w = perms & SENSITIVE_CORE_0_PIF_PMS_CONSTRAIN_RTCFAST_WORLD_X_W;
469     *x = perms & SENSITIVE_CORE_0_PIF_PMS_CONSTRAIN_RTCFAST_WORLD_X_F;
470 }
471 
memprot_ll_rtcfast_get_pms_area(bool * r,bool * w,bool * x,memprot_ll_world_t world,memprot_ll_area_t area)472 static inline memprot_ll_err_t memprot_ll_rtcfast_get_pms_area(bool *r, bool *w, bool *x, memprot_ll_world_t world, memprot_ll_area_t area)
473 {
474     uint32_t permissions = 0;
475 
476     switch (world) {
477     case MEMP_LL_WORLD_0: {
478         switch (area) {
479         case MEMP_LL_AREA_LOW:
480             permissions = REG_GET_FIELD(SENSITIVE_CORE_0_PIF_PMS_CONSTRAIN_10_REG, SENSITIVE_CORE_0_PIF_PMS_CONSTRAIN_RTCFAST_WORLD_0_L);
481             break;
482         case MEMP_LL_AREA_HIGH:
483             permissions = REG_GET_FIELD(SENSITIVE_CORE_0_PIF_PMS_CONSTRAIN_10_REG, SENSITIVE_CORE_0_PIF_PMS_CONSTRAIN_RTCFAST_WORLD_0_H);
484             break;
485         default:
486             return MEMP_LL_ERR_AREA_INVALID;
487         }
488     } break;
489     case MEMP_LL_WORLD_1: {
490         switch (area) {
491         case MEMP_LL_AREA_LOW:
492             permissions = REG_GET_FIELD(SENSITIVE_CORE_0_PIF_PMS_CONSTRAIN_10_REG, SENSITIVE_CORE_0_PIF_PMS_CONSTRAIN_RTCFAST_WORLD_1_L);
493             break;
494         case MEMP_LL_AREA_HIGH:
495             permissions = REG_GET_FIELD(SENSITIVE_CORE_0_PIF_PMS_CONSTRAIN_10_REG, SENSITIVE_CORE_0_PIF_PMS_CONSTRAIN_RTCFAST_WORLD_1_H);
496             break;
497         default:
498             return MEMP_LL_ERR_AREA_INVALID;
499         }
500     } break;
501     default:
502         return MEMP_LL_ERR_WORLD_INVALID;
503     }
504 
505     memprot_ll_rtcfast_get_permissions(permissions, r, w, x);
506 
507     return MEMP_LL_OK;
508 }
509 
memprot_ll_rtcfast_get_permission_register(void)510 static inline uint32_t memprot_ll_rtcfast_get_permission_register(void)
511 {
512     return REG_READ(SENSITIVE_CORE_0_PIF_PMS_CONSTRAIN_10_REG);
513 }
514 
515 ///////////////////////////////////
516 // RTC_FAST - MONITOR
517 
518 // lock
memprot_ll_rtcfast_set_monitor_lock(void)519 static inline void memprot_ll_rtcfast_set_monitor_lock(void)
520 {
521     REG_WRITE(SENSITIVE_CORE_0_PIF_PMS_MONITOR_0_REG, 1);
522 }
523 
memprot_ll_rtcfast_get_monitor_lock(void)524 static inline bool memprot_ll_rtcfast_get_monitor_lock(void)
525 {
526     return REG_READ(SENSITIVE_CORE_0_PIF_PMS_MONITOR_0_REG) == 1;
527 }
528 
529 // interrupt enable/clear
memprot_ll_rtcfast_set_monitor_en(bool enable)530 static inline void memprot_ll_rtcfast_set_monitor_en(bool enable)
531 {
532     if (enable) {
533         REG_SET_BIT(SENSITIVE_CORE_0_PIF_PMS_MONITOR_1_REG, SENSITIVE_CORE_0_PIF_PMS_MONITOR_VIOLATE_EN);
534     } else {
535         REG_CLR_BIT(SENSITIVE_CORE_0_PIF_PMS_MONITOR_1_REG, SENSITIVE_CORE_0_PIF_PMS_MONITOR_VIOLATE_EN);
536     }
537 }
538 
memprot_ll_rtcfast_get_monitor_en(void)539 static inline bool memprot_ll_rtcfast_get_monitor_en(void)
540 {
541     return REG_GET_FIELD(SENSITIVE_CORE_0_PIF_PMS_MONITOR_1_REG, SENSITIVE_CORE_0_PIF_PMS_MONITOR_VIOLATE_EN) > 0;
542 }
543 
memprot_ll_rtcfast_get_monitor_intrclr(void)544 static inline bool memprot_ll_rtcfast_get_monitor_intrclr(void)
545 {
546     return REG_GET_BIT(SENSITIVE_CORE_0_PIF_PMS_MONITOR_1_REG, SENSITIVE_CORE_0_PIF_PMS_MONITOR_VIOLATE_CLR) > 0;
547 }
548 
memprot_ll_rtcfast_set_monitor_intrclr(void)549 static inline void memprot_ll_rtcfast_set_monitor_intrclr(void)
550 {
551     REG_SET_BIT(SENSITIVE_CORE_0_PIF_PMS_MONITOR_1_REG, SENSITIVE_CORE_0_PIF_PMS_MONITOR_VIOLATE_CLR);
552 }
553 
memprot_ll_rtcfast_reset_monitor_intrclr(void)554 static inline void memprot_ll_rtcfast_reset_monitor_intrclr(void)
555 {
556     REG_CLR_BIT(SENSITIVE_CORE_0_PIF_PMS_MONITOR_1_REG, SENSITIVE_CORE_0_PIF_PMS_MONITOR_VIOLATE_CLR);
557 }
558 
memprot_ll_rtcfast_get_monitor_register(void)559 static inline uint32_t memprot_ll_rtcfast_get_monitor_register(void)
560 {
561     return REG_READ(SENSITIVE_CORE_0_PIF_PMS_MONITOR_1_REG);
562 }
563 
564 // permission violation status
memprot_ll_rtcfast_get_monitor_status_intr(void)565 static inline uint32_t memprot_ll_rtcfast_get_monitor_status_intr(void)
566 {
567     return REG_GET_FIELD(SENSITIVE_CORE_0_PIF_PMS_MONITOR_2_REG, SENSITIVE_CORE_0_PIF_PMS_MONITOR_VIOLATE_INTR);
568 }
569 
memprot_ll_rtcfast_get_monitor_status_fault_addr(void)570 static inline intptr_t memprot_ll_rtcfast_get_monitor_status_fault_addr(void)
571 {
572     //full address SENSITIVE_CORE_0_PIF_PMS_MONITOR_VIOLATE_STATUS_HADDR
573     return (intptr_t)REG_READ(SENSITIVE_CORE_0_PIF_PMS_MONITOR_3_REG);
574 }
575 
memprot_ll_rtcfast_get_monitor_status_fault_world(void)576 static inline uint32_t memprot_ll_rtcfast_get_monitor_status_fault_world(void)
577 {
578     return REG_GET_FIELD(SENSITIVE_CORE_0_PIF_PMS_MONITOR_2_REG, SENSITIVE_CORE_0_PIF_PMS_MONITOR_VIOLATE_STATUS_HWORLD);
579 }
580 
memprot_ll_rtcfast_get_monitor_status_fault_loadstore(void)581 static inline uint32_t memprot_ll_rtcfast_get_monitor_status_fault_loadstore(void)
582 {
583     return REG_GET_FIELD(SENSITIVE_CORE_0_PIF_PMS_MONITOR_2_REG, SENSITIVE_CORE_0_PIF_PMS_MONITOR_VIOLATE_STATUS_HPORT_0);
584 }
585 
memprot_ll_rtcfast_get_monitor_status_fault_wr(void)586 static inline uint32_t memprot_ll_rtcfast_get_monitor_status_fault_wr(void)
587 {
588     return REG_GET_FIELD(SENSITIVE_CORE_0_PIF_PMS_MONITOR_2_REG, SENSITIVE_CORE_0_PIF_PMS_MONITOR_VIOLATE_STATUS_HWRITE);
589 }
590 
591 
592 /* ******************************************************************************************************
593  * *** DRAM0 ***
594  * ******************************************************************************************************/
595 
memprot_ll_dram0_get_intr_source_num(void)596 static inline uint32_t memprot_ll_dram0_get_intr_source_num(void)
597 {
598     return ETS_CORE0_DRAM0_PMS_INTR_SOURCE;
599 }
600 
601 ///////////////////////////////////
602 // DRAM0 - SPLIT LINES
603 
memprot_ll_set_dram0_split_line(const void * line_addr,uint32_t sensitive_reg)604 static inline memprot_ll_err_t memprot_ll_set_dram0_split_line(const void *line_addr, uint32_t sensitive_reg)
605 {
606     uint32_t addr = (uint32_t)line_addr;
607 
608     //sanity check: split address required above unified mgmt region & 32bit aligned
609     if (addr < DRAM0_SRAM_LEVEL_1_LOW || addr > DRAM0_SRAM_LEVEL_3_HIGH) {
610         return MEMP_LL_ERR_SPLIT_ADDR_OUT_OF_RANGE;
611     }
612     //split-line must be divisible by 512 (PMS module restriction)
613     if (addr % 0x200 != 0) {
614         return MEMP_LL_ERR_SPLIT_ADDR_UNALIGNED;
615     }
616 
617     uint32_t category[3] = {0};
618     if (addr <= DRAM0_SRAM_LEVEL_1_HIGH) {
619         category[0] = 0x2;
620         category[1] = category[2] = 0x3;
621     } else if (addr >= DRAM0_SRAM_LEVEL_2_LOW && addr <= DRAM0_SRAM_LEVEL_2_HIGH) {
622         category[1] = 0x2;
623         category[2] = 0x3;
624     } else {
625         category[2] = 0x2;
626     }
627 
628     //NOTE: line address & category bits, shifts and masks are the same for all the areas
629     uint32_t category_bits =
630         (category[0] << SENSITIVE_CORE_X_IRAM0_DRAM0_DMA_SRAM_CATEGORY_0_S) |
631         (category[1] << SENSITIVE_CORE_X_IRAM0_DRAM0_DMA_SRAM_CATEGORY_1_S) |
632         (category[2] << SENSITIVE_CORE_X_IRAM0_DRAM0_DMA_SRAM_CATEGORY_2_S);
633 
634     uint32_t conf_addr = ((addr >> I_D_SPLIT_LINE_SHIFT) & SENSITIVE_CORE_X_IRAM0_DRAM0_DMA_SRAM_SPLITADDR_V) << SENSITIVE_CORE_X_IRAM0_DRAM0_DMA_SRAM_SPLITADDR_S;
635     uint32_t reg_cfg = conf_addr | category_bits;
636 
637     REG_WRITE(sensitive_reg, reg_cfg);
638 
639     return MEMP_LL_OK;
640 }
641 
memprot_ll_set_dram0_split_line_D_0(const void * line_addr)642 static inline memprot_ll_err_t memprot_ll_set_dram0_split_line_D_0(const void *line_addr)
643 {
644     return memprot_ll_set_dram0_split_line(line_addr, SENSITIVE_CORE_X_IRAM0_DRAM0_DMA_SPLIT_LINE_CONSTRAIN_4_REG);
645 }
646 
memprot_ll_set_dram0_split_line_D_1(const void * line_addr)647 static inline memprot_ll_err_t memprot_ll_set_dram0_split_line_D_1(const void *line_addr)
648 {
649     return memprot_ll_set_dram0_split_line(line_addr, SENSITIVE_CORE_X_IRAM0_DRAM0_DMA_SPLIT_LINE_CONSTRAIN_5_REG);
650 }
651 
memprot_ll_get_dram0_split_line_D_0(void)652 static inline void *memprot_ll_get_dram0_split_line_D_0(void)
653 {
654     return memprot_ll_get_split_addr_from_reg(REG_READ(SENSITIVE_CORE_X_IRAM0_DRAM0_DMA_SPLIT_LINE_CONSTRAIN_4_REG), SOC_DIRAM_DRAM_LOW);
655 }
656 
memprot_ll_get_dram0_split_line_D_1(void)657 static inline void *memprot_ll_get_dram0_split_line_D_1(void)
658 {
659     return memprot_ll_get_split_addr_from_reg(REG_READ(SENSITIVE_CORE_X_IRAM0_DRAM0_DMA_SPLIT_LINE_CONSTRAIN_5_REG), SOC_DIRAM_DRAM_LOW);
660 }
661 
memprot_ll_get_dram0_split_line_D_0_cat(void)662 static inline uint32_t memprot_ll_get_dram0_split_line_D_0_cat(void)
663 {
664     return REG_READ(SENSITIVE_CORE_X_IRAM0_DRAM0_DMA_SPLIT_LINE_CONSTRAIN_4_REG) & 0x3F;
665 }
666 
memprot_ll_get_dram0_split_line_D_1_cat(void)667 static inline uint32_t memprot_ll_get_dram0_split_line_D_1_cat(void)
668 {
669     return REG_READ(SENSITIVE_CORE_X_IRAM0_DRAM0_DMA_SPLIT_LINE_CONSTRAIN_5_REG) & 0x3F;
670 }
671 
672 ///////////////////////////////////
673 // DRAM0 - PMS CONFIGURATION
674 
675 // lock
memprot_ll_dram0_set_pms_lock(void)676 static inline void memprot_ll_dram0_set_pms_lock(void)
677 {
678     REG_WRITE(SENSITIVE_CORE_X_DRAM0_PMS_CONSTRAIN_0_REG, 1);
679 }
680 
memprot_ll_dram0_get_pms_lock(void)681 static inline bool memprot_ll_dram0_get_pms_lock(void)
682 {
683     return REG_READ(SENSITIVE_CORE_X_DRAM0_PMS_CONSTRAIN_0_REG) == 1;
684 }
685 
686 // permission settings
memprot_ll_dram0_set_permissions(bool r,bool w)687 static inline uint32_t memprot_ll_dram0_set_permissions(bool r, bool w)
688 {
689     uint32_t permissions = 0;
690     if (r) {
691         permissions |= SENSITIVE_CORE_X_IRAM0_PMS_CONSTRAIN_SRAM_WORLD_X_R;
692     }
693     if (w) {
694         permissions |= SENSITIVE_CORE_X_IRAM0_PMS_CONSTRAIN_SRAM_WORLD_X_W;
695     }
696 
697     return permissions;
698 }
699 
memprot_ll_dram0_set_pms_area_0(bool r,bool w)700 static inline void memprot_ll_dram0_set_pms_area_0(bool r, bool w)
701 {
702     REG_SET_FIELD(SENSITIVE_CORE_X_DRAM0_PMS_CONSTRAIN_1_REG, SENSITIVE_CORE_X_DRAM0_PMS_CONSTRAIN_SRAM_WORLD_0_PMS_0, memprot_ll_dram0_set_permissions(r, w));
703 }
704 
memprot_ll_dram0_set_pms_area_1(bool r,bool w)705 static inline void memprot_ll_dram0_set_pms_area_1(bool r, bool w)
706 {
707     REG_SET_FIELD(SENSITIVE_CORE_X_DRAM0_PMS_CONSTRAIN_1_REG, SENSITIVE_CORE_X_DRAM0_PMS_CONSTRAIN_SRAM_WORLD_0_PMS_1, memprot_ll_dram0_set_permissions(r, w));
708 }
709 
memprot_ll_dram0_set_pms_area_2(bool r,bool w)710 static inline void memprot_ll_dram0_set_pms_area_2(bool r, bool w)
711 {
712     REG_SET_FIELD(SENSITIVE_CORE_X_DRAM0_PMS_CONSTRAIN_1_REG, SENSITIVE_CORE_X_DRAM0_PMS_CONSTRAIN_SRAM_WORLD_0_PMS_2, memprot_ll_dram0_set_permissions(r, w));
713 }
714 
memprot_ll_dram0_set_pms_area_3(bool r,bool w)715 static inline void memprot_ll_dram0_set_pms_area_3(bool r, bool w)
716 {
717     REG_SET_FIELD(SENSITIVE_CORE_X_DRAM0_PMS_CONSTRAIN_1_REG, SENSITIVE_CORE_X_DRAM0_PMS_CONSTRAIN_SRAM_WORLD_0_PMS_3, memprot_ll_dram0_set_permissions(r, w));
718 }
719 
memprot_ll_dram0_get_permissions(uint32_t perms,bool * r,bool * w)720 static inline void memprot_ll_dram0_get_permissions(uint32_t perms, bool *r, bool *w )
721 {
722     *r = perms & SENSITIVE_CORE_X_DRAM0_PMS_CONSTRAIN_SRAM_WORLD_X_R;
723     *w = perms & SENSITIVE_CORE_X_DRAM0_PMS_CONSTRAIN_SRAM_WORLD_X_W;
724 }
725 
memprot_ll_dram0_get_pms_area_0(bool * r,bool * w)726 static inline void memprot_ll_dram0_get_pms_area_0(bool *r, bool *w)
727 {
728     uint32_t permissions = REG_GET_FIELD(SENSITIVE_CORE_X_DRAM0_PMS_CONSTRAIN_1_REG, SENSITIVE_CORE_X_DRAM0_PMS_CONSTRAIN_SRAM_WORLD_0_PMS_0);
729     memprot_ll_dram0_get_permissions(permissions, r, w);
730 }
731 
memprot_ll_dram0_get_pms_area_1(bool * r,bool * w)732 static inline void memprot_ll_dram0_get_pms_area_1(bool *r, bool *w)
733 {
734     uint32_t permissions = REG_GET_FIELD(SENSITIVE_CORE_X_DRAM0_PMS_CONSTRAIN_1_REG, SENSITIVE_CORE_X_DRAM0_PMS_CONSTRAIN_SRAM_WORLD_0_PMS_1);
735     memprot_ll_dram0_get_permissions(permissions, r, w);
736 }
737 
memprot_ll_dram0_get_pms_area_2(bool * r,bool * w)738 static inline void memprot_ll_dram0_get_pms_area_2(bool *r, bool *w)
739 {
740     uint32_t permissions = REG_GET_FIELD(SENSITIVE_CORE_X_DRAM0_PMS_CONSTRAIN_1_REG, SENSITIVE_CORE_X_DRAM0_PMS_CONSTRAIN_SRAM_WORLD_0_PMS_2);
741     memprot_ll_dram0_get_permissions(permissions, r, w);
742 }
743 
memprot_ll_dram0_get_pms_area_3(bool * r,bool * w)744 static inline void memprot_ll_dram0_get_pms_area_3(bool *r, bool *w)
745 {
746     uint32_t permissions = REG_GET_FIELD(SENSITIVE_CORE_X_DRAM0_PMS_CONSTRAIN_1_REG, SENSITIVE_CORE_X_DRAM0_PMS_CONSTRAIN_SRAM_WORLD_0_PMS_3);
747     memprot_ll_dram0_get_permissions(permissions, r, w);
748 }
749 
750 ///////////////////////////////////
751 // DRAM0 - MONITOR
752 
753 // lock
memprot_ll_dram0_set_monitor_lock(void)754 static inline void memprot_ll_dram0_set_monitor_lock(void)
755 {
756     REG_WRITE(SENSITIVE_CORE_0_DRAM0_PMS_MONITOR_0_REG, 1);
757 }
758 
memprot_ll_dram0_get_monitor_lock(void)759 static inline bool memprot_ll_dram0_get_monitor_lock(void)
760 {
761     return REG_READ(SENSITIVE_CORE_0_DRAM0_PMS_MONITOR_0_REG) == 1;
762 }
763 
764 // interrupt enable/clear
memprot_ll_dram0_set_monitor_en(bool enable)765 static inline void memprot_ll_dram0_set_monitor_en(bool enable)
766 {
767     if (enable) {
768         REG_SET_BIT(SENSITIVE_CORE_0_DRAM0_PMS_MONITOR_1_REG, SENSITIVE_CORE_0_DRAM0_PMS_MONITOR_VIOLATE_EN);
769     } else {
770         REG_CLR_BIT(SENSITIVE_CORE_0_DRAM0_PMS_MONITOR_1_REG, SENSITIVE_CORE_0_DRAM0_PMS_MONITOR_VIOLATE_EN);
771     }
772 }
773 
memprot_ll_dram0_get_monitor_en(void)774 static inline bool memprot_ll_dram0_get_monitor_en(void)
775 {
776     return REG_GET_BIT(SENSITIVE_CORE_0_DRAM0_PMS_MONITOR_1_REG, SENSITIVE_CORE_0_DRAM0_PMS_MONITOR_VIOLATE_EN) > 0;
777 }
778 
memprot_ll_dram0_set_monitor_intrclr(void)779 static inline void memprot_ll_dram0_set_monitor_intrclr(void)
780 {
781     REG_SET_BIT(SENSITIVE_CORE_0_DRAM0_PMS_MONITOR_1_REG, SENSITIVE_CORE_0_DRAM0_PMS_MONITOR_VIOLATE_CLR);
782 }
783 
memprot_ll_dram0_reset_monitor_intrclr(void)784 static inline void memprot_ll_dram0_reset_monitor_intrclr(void)
785 {
786     REG_CLR_BIT(SENSITIVE_CORE_0_DRAM0_PMS_MONITOR_1_REG, SENSITIVE_CORE_0_DRAM0_PMS_MONITOR_VIOLATE_CLR);
787 }
788 
memprot_ll_dram0_get_monitor_intrclr(void)789 static inline bool memprot_ll_dram0_get_monitor_intrclr(void)
790 {
791     return REG_GET_BIT(SENSITIVE_CORE_0_DRAM0_PMS_MONITOR_1_REG, SENSITIVE_CORE_0_DRAM0_PMS_MONITOR_VIOLATE_CLR) > 0;
792 }
793 
memprot_ll_dram0_get_monitor_enable_register(void)794 static inline uint32_t memprot_ll_dram0_get_monitor_enable_register(void)
795 {
796     return REG_READ(SENSITIVE_CORE_0_DRAM0_PMS_MONITOR_1_REG);
797 }
798 
799 // permission violation status
memprot_ll_dram0_get_monitor_status_intr(void)800 static inline uint32_t memprot_ll_dram0_get_monitor_status_intr(void)
801 {
802     return REG_GET_FIELD(SENSITIVE_CORE_0_DRAM0_PMS_MONITOR_2_REG, SENSITIVE_CORE_0_DRAM0_PMS_MONITOR_VIOLATE_INTR);
803 }
804 
memprot_ll_dram0_get_monitor_status_fault_lock(void)805 static inline uint32_t memprot_ll_dram0_get_monitor_status_fault_lock(void)
806 {
807     return REG_GET_FIELD(SENSITIVE_CORE_0_DRAM0_PMS_MONITOR_2_REG, SENSITIVE_CORE_0_DRAM0_PMS_MONITOR_VIOLATE_STATUS_LOCK);
808 }
809 
memprot_ll_dram0_get_monitor_status_fault_world(void)810 static inline uint32_t memprot_ll_dram0_get_monitor_status_fault_world(void)
811 {
812     return REG_GET_FIELD(SENSITIVE_CORE_0_DRAM0_PMS_MONITOR_2_REG, SENSITIVE_CORE_0_DRAM0_PMS_MONITOR_VIOLATE_STATUS_WORLD);
813 }
814 
memprot_ll_dram0_get_monitor_status_fault_addr(void)815 static inline uint32_t memprot_ll_dram0_get_monitor_status_fault_addr(void)
816 {
817     uint32_t addr = REG_GET_FIELD(SENSITIVE_CORE_0_DRAM0_PMS_MONITOR_2_REG, SENSITIVE_CORE_0_DRAM0_PMS_MONITOR_VIOLATE_STATUS_ADDR);
818     return addr > 0 ? (addr << I_D_FAULT_ADDR_SHIFT) + DRAM0_ADDRESS_LOW : 0;
819 }
820 
memprot_ll_dram0_get_monitor_status_fault_wr(void)821 static inline uint32_t memprot_ll_dram0_get_monitor_status_fault_wr(void)
822 {
823     return REG_GET_FIELD(SENSITIVE_CORE_0_DRAM0_PMS_MONITOR_3_REG, SENSITIVE_CORE_0_DRAM0_PMS_MONITOR_VIOLATE_STATUS_WR);
824 }
825 
memprot_ll_dram0_get_monitor_status_fault_byte_en(void)826 static inline uint32_t memprot_ll_dram0_get_monitor_status_fault_byte_en(void)
827 {
828     return REG_GET_FIELD(SENSITIVE_CORE_0_DRAM0_PMS_MONITOR_2_REG, SENSITIVE_CORE_0_DRAM0_PMS_MONITOR_VIOLATE_STATUS_BYTEEN);
829 }
830 
memprot_ll_dram0_get_monitor_status_register_1(void)831 static inline uint32_t memprot_ll_dram0_get_monitor_status_register_1(void)
832 {
833     return REG_READ(SENSITIVE_CORE_0_DRAM0_PMS_MONITOR_2_REG);
834 }
835 
memprot_ll_dram0_get_monitor_status_register_2(void)836 static inline uint32_t memprot_ll_dram0_get_monitor_status_register_2(void)
837 {
838     return REG_READ(SENSITIVE_CORE_0_DRAM0_PMS_MONITOR_3_REG);
839 }
840 
841 #ifdef __cplusplus
842 }
843 #endif
844