Skip to content

Commit a1f5db0

Browse files
ioannisgandrewboie
authored andcommitted
arch: arm: mpu: allow optional region gap filling in the ARMv8-M MPU
We allow the run-time, full paritioning of the SRAM space by the ARMv8-M MPU driver to be an optional feature. Signed-off-by: Ioannis Glaropoulos <[email protected]>
1 parent f103c68 commit a1f5db0

File tree

3 files changed

+31
-6
lines changed

3 files changed

+31
-6
lines changed

arch/arm/core/cortex_m/mpu/arm_core_mpu_dev.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ struct k_thread;
2929
* @param mpu_regions_num the number of available HW MPU regions.
3030
*/
3131
#if defined(CONFIG_MPU_REQUIRES_NON_OVERLAPPING_REGIONS) && \
32-
!defined(CONFIG_MPU_SKIP_BACKGROUND_SRAM_FILLING)
32+
defined(CONFIG_MPU_GAP_FILLING)
3333
/*
3434
* For ARM MPU architectures, where the domain partitions cannot be defined
3535
* on top of the statically configured memory regions, the maximum number of
@@ -55,7 +55,7 @@ struct k_thread;
5555
* memory region for (user) Thread Stack.
5656
*/
5757
#if defined(CONFIG_MPU_REQUIRES_NON_OVERLAPPING_REGIONS) && \
58-
!defined(CONFIG_MPU_SKIP_BACKGROUND_SRAM_FILLING)
58+
defined(CONFIG_MPU_GAP_FILLING)
5959
/* When dynamic regions may not be defined on top of statically
6060
* allocated memory regions, defining a region for a thread stack
6161
* requires two additional MPU regions to be configured; one for
@@ -76,7 +76,7 @@ struct k_thread;
7676
* memory region for a (supervisor) Thread Stack Guard.
7777
*/
7878
#if (defined(CONFIG_MPU_REQUIRES_NON_OVERLAPPING_REGIONS) && \
79-
!defined(CONFIG_MPU_SKIP_BACKGROUND_SRAM_FILLING)) \
79+
defined(CONFIG_MPU_GAP_FILLING)) \
8080
|| defined(CONFIG_CPU_HAS_NXP_MPU)
8181
/*
8282
* When dynamic regions may not be defined on top of statically

arch/arm/core/cortex_m/mpu/arm_mpu.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ static int mpu_configure_region(const u8_t index,
101101
}
102102

103103
#if !defined(CONFIG_MPU_REQUIRES_NON_OVERLAPPING_REGIONS) || \
104-
!defined(CONFIG_MPU_SRAM_GAP_FILLING)
104+
!defined(CONFIG_MPU_GAP_FILLING)
105105
/* This internal function programs a set of given MPU regions
106106
* over a background memory area, optionally performing a
107107
* sanity check of the memory regions to be programmed.

arch/arm/core/cortex_m/mpu/arm_mpu_v8_internal.h

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -318,11 +318,20 @@ static int region_allocate_and_init(const u8_t index,
318318
static int mpu_configure_region(const u8_t index,
319319
const struct k_mem_partition *new_region);
320320

321+
#if !defined(CONFIG_MPU_GAP_FILLING)
322+
static int mpu_configure_regions(const struct k_mem_partition
323+
*regions[], u8_t regions_num, u8_t start_reg_index,
324+
bool do_sanity_check);
325+
#endif
326+
321327
/* This internal function programs a set of given MPU regions
322328
* over a background memory area, optionally performing a
323329
* sanity check of the memory regions to be programmed.
330+
*
331+
* The function performs a full partition of the background memory
332+
* area, effectively, leaving no space in this area uncovered by MPU.
324333
*/
325-
static int mpu_configure_regions(const struct k_mem_partition
334+
static int mpu_configure_regions_and_partition(const struct k_mem_partition
326335
*regions[], u8_t regions_num, u8_t start_reg_index,
327336
bool do_sanity_check)
328337
{
@@ -472,7 +481,7 @@ static int mpu_configure_static_mpu_regions(const struct k_mem_partition
472481
ARG_UNUSED(background_area_base);
473482
ARG_UNUSED(background_area_end);
474483

475-
mpu_reg_index = mpu_configure_regions(static_regions,
484+
mpu_reg_index = mpu_configure_regions_and_partition(static_regions,
476485
regions_num, mpu_reg_index, true);
477486

478487
static_regions_num = mpu_reg_index;
@@ -539,6 +548,7 @@ static int mpu_configure_dynamic_mpu_regions(const struct k_mem_partition
539548
ARM_MPU_ClrRegion(i);
540549
}
541550

551+
#if defined(CONFIG_MPU_GAP_FILLING)
542552
/* Reset MPU regions inside which dynamic memory regions may
543553
* be programmed.
544554
*/
@@ -551,10 +561,25 @@ static int mpu_configure_dynamic_mpu_regions(const struct k_mem_partition
551561
* forming a full partition of the background area, specified by the
552562
* given boundaries.
553563
*/
564+
mpu_reg_index = mpu_configure_regions_and_partition(dynamic_regions,
565+
regions_num, mpu_reg_index, true);
566+
#else
567+
568+
/* We are going to skip the full partition of the background areas.
569+
* So we can disable MPU regions inside which dynamic memroy regions
570+
* may be programmed.
571+
*/
572+
for (int i = 0; i < MPU_DYNAMIC_REGION_AREAS_NUM; i++) {
573+
ARM_MPU_ClrRegion(dyn_reg_info[i].index);
574+
}
554575

576+
/* The dynamic regions are now programmed on top of
577+
* existing SRAM region configuration.
578+
*/
555579
mpu_reg_index = mpu_configure_regions(dynamic_regions,
556580
regions_num, mpu_reg_index, true);
557581

582+
#endif /* CONFIG_MPU_GAP_FILLING */
558583
return mpu_reg_index;
559584
}
560585

0 commit comments

Comments
 (0)