arch: arm: pointer argument to MPU region re-programming functions
This commit refactors the MPU region re-programming functions, to take as argument an array of pointers to memory partition structures, instead of the whole array of the partitions. In this way the stack usage can be minimized, if the actual partition information is kept in statically allocated memory. instead of the map itself. Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
This commit is contained in:
parent
78b98ae895
commit
9611c9ab4d
|
@ -60,31 +60,44 @@ LOG_MODULE_REGISTER(mpu);
|
|||
*/
|
||||
void _arch_configure_static_mpu_regions(void)
|
||||
{
|
||||
/* Define a constant array of k_mem_partition objects
|
||||
* to hold the configuration of the respective static
|
||||
* MPU regions.
|
||||
*/
|
||||
const struct k_mem_partition static_regions[] = {
|
||||
#if defined(CONFIG_COVERAGE_GCOV) && defined(CONFIG_USERSPACE)
|
||||
const struct k_mem_partition gcov_region =
|
||||
{
|
||||
.start = (u32_t)&__gcov_bss_start,
|
||||
.size = (u32_t)&__gcov_bss_size,
|
||||
.attr = K_MEM_PARTITION_P_RW_U_RW,
|
||||
},
|
||||
};
|
||||
#endif /* CONFIG_COVERAGE_GCOV && CONFIG_USERSPACE */
|
||||
#if defined(CONFIG_NOCACHE_MEMORY)
|
||||
const struct k_mem_partition nocache_region =
|
||||
{
|
||||
.start = (u32_t)&_nocache_ram_start,
|
||||
.size = (u32_t)&_nocache_ram_size,
|
||||
.attr = K_MEM_PARTITION_P_RW_U_NA_NOCACHE,
|
||||
},
|
||||
};
|
||||
#endif /* CONFIG_NOCACHE_MEMORY */
|
||||
#if defined(CONFIG_ARCH_HAS_RAMFUNC_SUPPORT)
|
||||
const struct k_mem_partition ramfunc_region =
|
||||
{
|
||||
.start = (u32_t)&_ramfunc_ram_start,
|
||||
.size = (u32_t)&_ramfunc_ram_size,
|
||||
.attr = K_MEM_PARTITION_P_RX_U_RX,
|
||||
}
|
||||
};
|
||||
#endif /* CONFIG_ARCH_HAS_RAMFUNC_SUPPORT */
|
||||
|
||||
/* Define a constant array of k_mem_partition objects
|
||||
* to hold the configuration of the respective static
|
||||
* MPU regions.
|
||||
*/
|
||||
const struct k_mem_partition *static_regions[] = {
|
||||
#if defined(CONFIG_COVERAGE_GCOV) && defined(CONFIG_USERSPACE)
|
||||
&gcov_region,
|
||||
#endif /* CONFIG_COVERAGE_GCOV && CONFIG_USERSPACE */
|
||||
#if defined(CONFIG_NOCACHE_MEMORY)
|
||||
&nocache_region,
|
||||
#endif /* CONFIG_NOCACHE_MEMORY */
|
||||
#if defined(CONFIG_ARCH_HAS_RAMFUNC_SUPPORT)
|
||||
&ramfunc_region
|
||||
#endif /* CONFIG_ARCH_HAS_RAMFUNC_SUPPORT */
|
||||
};
|
||||
|
||||
|
@ -110,6 +123,7 @@ void _arch_configure_static_mpu_regions(void)
|
|||
.size = _MPU_DYNAMIC_REGIONS_AREA_SIZE,
|
||||
}
|
||||
};
|
||||
|
||||
arm_core_mpu_mark_areas_for_dynamic_regions(dyn_region_areas,
|
||||
ARRAY_SIZE(dyn_region_areas));
|
||||
#endif /* CONFIG_MPU_REQUIRES_NON_OVERLAPPING_REGIONS */
|
||||
|
@ -134,11 +148,13 @@ void _arch_configure_dynamic_mpu_regions(struct k_thread *thread)
|
|||
* the given thread. The array of partitions (along with its
|
||||
* actual size) will be supplied to the underlying MPU driver.
|
||||
*/
|
||||
struct k_mem_partition dynamic_regions[_MAX_DYNAMIC_MPU_REGIONS_NUM];
|
||||
struct k_mem_partition *dynamic_regions[_MAX_DYNAMIC_MPU_REGIONS_NUM];
|
||||
|
||||
u8_t region_num = 0;
|
||||
|
||||
#if defined(CONFIG_USERSPACE)
|
||||
struct k_mem_partition thread_stack;
|
||||
|
||||
/* Memory domain */
|
||||
LOG_DBG("configure thread %p's domain", thread);
|
||||
struct k_mem_domain *mem_domain = thread->mem_domain_info.mem_domain;
|
||||
|
@ -163,7 +179,8 @@ void _arch_configure_dynamic_mpu_regions(struct k_thread *thread)
|
|||
partition.start, partition.size);
|
||||
__ASSERT(region_num < _MAX_DYNAMIC_MPU_REGIONS_NUM,
|
||||
"Out-of-bounds error for dynamic region map.");
|
||||
dynamic_regions[region_num] = partition;
|
||||
dynamic_regions[region_num] =
|
||||
&mem_domain->partitions[i];
|
||||
|
||||
region_num++;
|
||||
num_partitions--;
|
||||
|
@ -187,14 +204,18 @@ void _arch_configure_dynamic_mpu_regions(struct k_thread *thread)
|
|||
#endif
|
||||
__ASSERT(region_num < _MAX_DYNAMIC_MPU_REGIONS_NUM,
|
||||
"Out-of-bounds error for dynamic region map.");
|
||||
dynamic_regions[region_num] = (const struct k_mem_partition)
|
||||
thread_stack = (const struct k_mem_partition)
|
||||
{base, size, K_MEM_PARTITION_P_RW_U_RW};
|
||||
|
||||
dynamic_regions[region_num] = &thread_stack;
|
||||
|
||||
region_num++;
|
||||
}
|
||||
#endif /* CONFIG_USERSPACE */
|
||||
|
||||
#if defined(CONFIG_MPU_STACK_GUARD)
|
||||
struct k_mem_partition guard;
|
||||
|
||||
/* Privileged stack guard */
|
||||
u32_t guard_start;
|
||||
#if defined(CONFIG_USERSPACE)
|
||||
|
@ -214,18 +235,20 @@ void _arch_configure_dynamic_mpu_regions(struct k_thread *thread)
|
|||
|
||||
__ASSERT(region_num < _MAX_DYNAMIC_MPU_REGIONS_NUM,
|
||||
"Out-of-bounds error for dynamic region map.");
|
||||
dynamic_regions[region_num] = (const struct k_mem_partition)
|
||||
guard = (const struct k_mem_partition)
|
||||
{
|
||||
guard_start,
|
||||
MPU_GUARD_ALIGN_AND_SIZE,
|
||||
K_MEM_PARTITION_P_RO_U_NA
|
||||
};
|
||||
dynamic_regions[region_num] = &guard;
|
||||
|
||||
region_num++;
|
||||
#endif /* CONFIG_MPU_STACK_GUARD */
|
||||
|
||||
/* Configure the dynamic MPU regions */
|
||||
arm_core_mpu_configure_dynamic_mpu_regions(dynamic_regions,
|
||||
arm_core_mpu_configure_dynamic_mpu_regions(
|
||||
(const struct k_mem_partition **)dynamic_regions,
|
||||
region_num);
|
||||
}
|
||||
|
||||
|
|
|
@ -241,19 +241,19 @@ static int _mpu_configure_regions(const struct k_mem_partition
|
|||
int reg_index = start_reg_index;
|
||||
|
||||
for (i = 0; i < regions_num; i++) {
|
||||
if (regions[i].size == 0) {
|
||||
if (regions[i]->size == 0) {
|
||||
continue;
|
||||
}
|
||||
/* Non-empty region. */
|
||||
|
||||
if (do_sanity_check &&
|
||||
(!_mpu_partition_is_valid(®ions[i]))) {
|
||||
(!_mpu_partition_is_valid(regions[i]))) {
|
||||
LOG_ERR("Partition %u: sanity check failed.", i);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
#if defined(CONFIG_MPU_STACK_GUARD)
|
||||
if (regions[i].attr.ap_attr == MPU_REGION_SU_RX) {
|
||||
if (regions[i]->attr.ap_attr == MPU_REGION_SU_RX) {
|
||||
|
||||
/* Attempt to configure an MPU Stack Guard region; this
|
||||
* will require splitting of the underlying SRAM region
|
||||
|
@ -261,7 +261,7 @@ static int _mpu_configure_regions(const struct k_mem_partition
|
|||
* be programmed afterwards.
|
||||
*/
|
||||
reg_index =
|
||||
_mpu_sram_partitioning(reg_index, ®ions[i]);
|
||||
_mpu_sram_partitioning(reg_index, regions[i]);
|
||||
}
|
||||
#endif /* CONFIG_MPU_STACK_GUARD */
|
||||
|
||||
|
@ -269,7 +269,7 @@ static int _mpu_configure_regions(const struct k_mem_partition
|
|||
return reg_index;
|
||||
}
|
||||
|
||||
reg_index = _mpu_configure_region(reg_index, ®ions[i]);
|
||||
reg_index = _mpu_configure_region(reg_index, regions[i]);
|
||||
|
||||
if (reg_index == -EINVAL) {
|
||||
return reg_index;
|
||||
|
|
|
@ -126,7 +126,8 @@ void arm_core_mpu_disable(void);
|
|||
*
|
||||
* The function shall be invoked once, upon system initialization.
|
||||
*
|
||||
* @param static_regions[] an array of memory partitions to be programmed
|
||||
* @param static_regions[] an array of pointers to memory partitions
|
||||
* to be programmed
|
||||
* @param regions_num the number of regions to be programmed
|
||||
* @param background_area_start the start address of the background memory area
|
||||
* @param background_area_end the end address of the background memory area
|
||||
|
@ -139,7 +140,7 @@ void arm_core_mpu_disable(void);
|
|||
* requirements of the MPU hardware.
|
||||
*/
|
||||
void arm_core_mpu_configure_static_mpu_regions(
|
||||
const struct k_mem_partition static_regions[], const u8_t regions_num,
|
||||
const struct k_mem_partition *static_regions[], const u8_t regions_num,
|
||||
const u32_t background_area_start, const u32_t background_area_end);
|
||||
|
||||
#if defined(CONFIG_MPU_REQUIRES_NON_OVERLAPPING_REGIONS)
|
||||
|
@ -182,7 +183,8 @@ void arm_core_mpu_mark_areas_for_dynamic_regions(
|
|||
* within a (background) memory area. The total number of HW MPU regions
|
||||
* to be programmed depends on the MPU architecture.
|
||||
*
|
||||
* @param dynamic_regions[] an array of memory partitions to be programmed
|
||||
* @param dynamic_regions[] an array of pointers to memory partitions
|
||||
* to be programmed
|
||||
* @param regions_num the number of regions to be programmed
|
||||
*
|
||||
* The function shall assert if the operation cannot be not performed
|
||||
|
@ -190,7 +192,7 @@ void arm_core_mpu_mark_areas_for_dynamic_regions(
|
|||
* not exceed the number of (currently) available MPU indices.
|
||||
*/
|
||||
void arm_core_mpu_configure_dynamic_mpu_regions(
|
||||
const struct k_mem_partition dynamic_regions[], u8_t regions_num);
|
||||
const struct k_mem_partition *dynamic_regions[], u8_t regions_num);
|
||||
|
||||
#if defined(CONFIG_USERSPACE)
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue