Skip to content

Commit 3a6a23d

Browse files
crafcat7xiaoxiang781216
authored andcommitted
xtensa_mpu:Modify the specified Region attributes
Due to the xtensa mpu feature, the size of the Region depends on the Base of the next Region. e.g. Region[1] = 0x20000000 Region[0] = 0x30000000 Then Region[1] length = Region[0] - Region[1] So this approach is not suitable to implement the behavior of cleaning up the Region and such a configuration will result in affecting the very beginning (the higher) Region Therefore, to address this feature, in this change we return the Region value and implement the ability to modify the target Region's attributes Signed-off-by: chenrun1 <[email protected]>
1 parent 054c564 commit 3a6a23d

File tree

2 files changed

+244
-72
lines changed

2 files changed

+244
-72
lines changed

arch/xtensa/src/common/mpu.h

Lines changed: 129 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,14 @@
5050
(((ENCODE_MEMORY_TYPE(memtype)) << (12)) | \
5151
(((access) & (0xf)) << (8)))
5252

53+
struct mpu_region_s
54+
{
55+
uintptr_t base; /* Region Base Address */
56+
size_t size; /* Unused */
57+
uint32_t acc; /* Access permissions */
58+
uint32_t memtype; /* memory type */
59+
};
60+
5361
/****************************************************************************
5462
* MPU access rights constants
5563
****************************************************************************/
@@ -185,7 +193,18 @@ extern "C"
185193
* Name: mpu_allocregion
186194
*
187195
* Description:
188-
* Allocate the next region
196+
* Allocate the next region
197+
*
198+
* Assumptions:
199+
* - Regions are never deallocated
200+
* - Regions are only allocated early in initialization, so no special
201+
* protection against re-entrancy is required;
202+
*
203+
* Input Parameters:
204+
* None.
205+
*
206+
* Returned Value:
207+
* The index of the allocated region.
189208
*
190209
****************************************************************************/
191210

@@ -197,20 +216,91 @@ unsigned int mpu_allocregion(void);
197216
* Description:
198217
* Configure and enable (or disable) the MPU
199218
*
219+
* Input Parameters:
220+
* enable - Flag indicating whether to enable the MPU.
221+
*
222+
* Returned Value:
223+
* None.
224+
*
200225
****************************************************************************/
201226

202227
void mpu_control(bool enable);
203228

229+
/****************************************************************************
230+
* Name: mpu_modify_region
231+
*
232+
* Description:
233+
* Modify a region for privileged, strongly ordered memory
234+
*
235+
* Input Parameters:
236+
* region - Region number to modify.
237+
* base - Base address of the region.
238+
* size - Unused.
239+
* acc - A uint32_t value representing the access permissions of
240+
* the region.
241+
* memtype - A uint32_t value representing the memory type of the region.
242+
*
243+
* Returned Value:
244+
* None.
245+
*
246+
****************************************************************************/
247+
248+
void mpu_modify_region(unsigned int region, uintptr_t base, size_t size,
249+
uint32_t acc, uint32_t memtype);
250+
204251
/****************************************************************************
205252
* Name: mpu_configure_region
206253
*
207254
* Description:
255+
* Configure a region
256+
*
257+
* Input Parameters:
258+
* base - Base address of the region.
259+
* size - Unused.
260+
* acc - A uint32_t value representing the access permissions of
261+
* the region.
262+
* memtype - A uint32_t value representing the memory type of the region.
263+
*
264+
* Returned Value:
265+
* The region number allocated for the configured region.
266+
*
267+
****************************************************************************/
268+
269+
unsigned int mpu_configure_region(uintptr_t base, size_t size,
270+
uint32_t acc, uint32_t memtype);
271+
272+
/****************************************************************************
273+
* Name: mpu_initialize
274+
*
275+
* Description:
208276
* Configure a region for privileged, strongly ordered memory
209277
*
278+
* Input Parameters:
279+
* table - MPU initialization table.
280+
* count - Initialize the number of entries in the region table.
281+
*
282+
* Returned Value:
283+
* NULL.
284+
*
285+
****************************************************************************/
286+
287+
void mpu_initialize(const struct mpu_region_s *table, size_t count);
288+
289+
/****************************************************************************
290+
* Name: mpu_dump_region
291+
*
292+
* Description:
293+
* Dump the region that has been used.
294+
*
295+
* Input Parameters:
296+
* None.
297+
*
298+
* Returned Value:
299+
* None.
300+
*
210301
****************************************************************************/
211302

212-
void mpu_configure_region(uintptr_t base, size_t size,
213-
uint32_t acc, uint32_t memtype);
303+
void mpu_dump_region(void);
214304

215305
/****************************************************************************
216306
* Name: mpu_priv_stronglyordered
@@ -221,13 +311,10 @@ void mpu_configure_region(uintptr_t base, size_t size,
221311
****************************************************************************/
222312

223313
#define mpu_priv_stronglyordered(base, size) \
224-
do \
225-
{ \
226-
/* The configure the region */ \
227-
mpu_configure_region(base, size, \
228-
MPU_AR_RWX, \
229-
MPU_MEM_DEVICE); \
230-
} while (0)
314+
/* The configure the region */ \
315+
mpu_configure_region(base, size, \
316+
MPU_AR_RWX, \
317+
MPU_MEM_DEVICE)
231318

232319
/****************************************************************************
233320
* Name: mpu_user_flash
@@ -238,13 +325,10 @@ void mpu_configure_region(uintptr_t base, size_t size,
238325
****************************************************************************/
239326

240327
#define mpu_user_flash(base, size) \
241-
do \
242-
{ \
243-
/* The configure the region */ \
244-
mpu_configure_region(base, size, \
245-
MPU_AR_RXrx, \
246-
MPU_MEM_WRITEBACK);\
247-
} while (0)
328+
/* The configure the region */ \
329+
mpu_configure_region(base, size, \
330+
MPU_AR_RXrx, \
331+
MPU_MEM_WRITEBACK)
248332

249333
/****************************************************************************
250334
* Name: mpu_priv_flash
@@ -255,13 +339,10 @@ void mpu_configure_region(uintptr_t base, size_t size,
255339
****************************************************************************/
256340

257341
#define mpu_priv_flash(base, size) \
258-
do \
259-
{ \
260-
/* The configure the region */ \
261-
mpu_configure_region(base, size, \
262-
MPU_AR_RX, \
263-
MPU_MEM_WRITEBACK);\
264-
} while (0)
342+
/* The configure the region */ \
343+
mpu_configure_region(base, size, \
344+
MPU_AR_RX, \
345+
MPU_MEM_WRITEBACK)
265346

266347
/****************************************************************************
267348
* Name: mpu_user_intsram
@@ -272,13 +353,10 @@ void mpu_configure_region(uintptr_t base, size_t size,
272353
****************************************************************************/
273354

274355
#define mpu_user_intsram(base, size) \
275-
do \
276-
{ \
277-
/* The configure the region */ \
278-
mpu_configure_region(base, size, \
279-
MPU_AR_RWXrwx, \
280-
MPU_MEM_WRITEBACK);\
281-
} while (0)
356+
/* The configure the region */ \
357+
mpu_configure_region(base, size, \
358+
MPU_AR_RWXrwx, \
359+
MPU_MEM_WRITEBACK)
282360

283361
/****************************************************************************
284362
* Name: mpu_priv_intsram
@@ -289,13 +367,10 @@ void mpu_configure_region(uintptr_t base, size_t size,
289367
****************************************************************************/
290368

291369
#define mpu_priv_intsram(base, size) \
292-
do \
293-
{ \
294-
/* The configure the region */ \
295-
mpu_configure_region(base, size,\
296-
MPU_AR_RWX, \
297-
MPU_MEM_WRITEBACK);\
298-
} while (0)
370+
/* The configure the region */ \
371+
mpu_configure_region(base, size,\
372+
MPU_AR_RWX, \
373+
MPU_MEM_WRITEBACK)
299374

300375
/****************************************************************************
301376
* Name: mpu_user_extsram
@@ -306,13 +381,10 @@ void mpu_configure_region(uintptr_t base, size_t size,
306381
****************************************************************************/
307382

308383
#define mpu_user_extsram(base, size) \
309-
do \
310-
{ \
311-
/* The configure the region */ \
312-
mpu_configure_region(base, size, \
313-
MPU_AR_RWXrwx, \
314-
MPU_MEM_WRITEBACK);\
315-
} while (0)
384+
/* The configure the region */ \
385+
mpu_configure_region(base, size, \
386+
MPU_AR_RWXrwx, \
387+
MPU_MEM_WRITEBACK)
316388

317389
/****************************************************************************
318390
* Name: mpu_priv_extsram
@@ -323,13 +395,10 @@ void mpu_configure_region(uintptr_t base, size_t size,
323395
****************************************************************************/
324396

325397
#define mpu_priv_extsram(base, size) \
326-
do \
327-
{ \
328-
/* The configure the region */ \
329-
mpu_configure_region(base, size, \
330-
MPU_AR_RWX, \
331-
MPU_MEM_WRITEBACK);\
332-
} while (0)
398+
/* The configure the region */ \
399+
mpu_configure_region(base, size, \
400+
MPU_AR_RWX, \
401+
MPU_MEM_WRITEBACK)
333402

334403
/****************************************************************************
335404
* Name: mpu_peripheral
@@ -340,13 +409,10 @@ void mpu_configure_region(uintptr_t base, size_t size,
340409
****************************************************************************/
341410

342411
#define mpu_peripheral(base, size) \
343-
do \
344-
{ \
345-
/* Then configure the region */ \
346-
mpu_configure_region(base, size, \
347-
MPU_AR_RW, \
348-
MPU_MEM_DEVICE);\
349-
} while (0)
412+
/* Then configure the region */ \
413+
mpu_configure_region(base, size, \
414+
MPU_AR_RW, \
415+
MPU_MEM_DEVICE)
350416

351417
/****************************************************************************
352418
* Name: mpu_user_peripheral
@@ -357,13 +423,10 @@ void mpu_configure_region(uintptr_t base, size_t size,
357423
****************************************************************************/
358424

359425
#define mpu_user_peripheral(base, size) \
360-
do \
361-
{ \
362-
/* Then configure the region */ \
363-
mpu_configure_region(base, size, \
364-
MPU_AR_RWrw, \
365-
MPU_MEM_DEVICE);\
366-
} while (0)
426+
/* Then configure the region */ \
427+
mpu_configure_region(base, size, \
428+
MPU_AR_RWrw, \
429+
MPU_MEM_DEVICE)
367430

368431
#undef EXTERN
369432
#if defined(__cplusplus)

0 commit comments

Comments
 (0)