From 27cfde9968e137f245b8c916408a863eec4f43ca Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 31 Aug 2017 08:49:21 -0600 Subject: [PATCH] Protected/Kernel Builds: Review us of kmm_addregion vs. kumm_addregsion in other configurations. --- arch/arm/src/imx1/imx_allocateheap.c | 17 ++--------- arch/arm/src/lpc17xx/lpc17_allocateheap.c | 35 ++++++++++++++--------- arch/arm/src/lpc31xx/lpc31_allocateheap.c | 35 ++++++++++++++++------- 3 files changed, 49 insertions(+), 38 deletions(-) diff --git a/arch/arm/src/imx1/imx_allocateheap.c b/arch/arm/src/imx1/imx_allocateheap.c index 550a26e471..b2e05a0d1f 100644 --- a/arch/arm/src/imx1/imx_allocateheap.c +++ b/arch/arm/src/imx1/imx_allocateheap.c @@ -52,18 +52,6 @@ #include "up_arch.h" #include "up_internal.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -107,11 +95,12 @@ void up_addregion(void) */ #if !defined(CONFIG_BOOT_RUNFROMFLASH) && !defined(CONFIG_BOOT_COPYTORAM) -# if (CONFIG_RAM_NUTTXENTRY & 0xffff0000) != CONFIG_RAM_VSTART +#if (CONFIG_RAM_NUTTXENTRY & 0xffff0000) != CONFIG_RAM_VSTART uint32_t start = CONFIG_RAM_VSTART + 0x1000; uint32_t end = (CONFIG_RAM_NUTTXENTRY & 0xffff0000); + kmm_addregion((FAR void *)start, end - start); -# endif +#endif #endif /* Check for any additional memory regions */ diff --git a/arch/arm/src/lpc17xx/lpc17_allocateheap.c b/arch/arm/src/lpc17xx/lpc17_allocateheap.c index dd1652bf18..35fe14dced 100644 --- a/arch/arm/src/lpc17xx/lpc17_allocateheap.c +++ b/arch/arm/src/lpc17xx/lpc17_allocateheap.c @@ -177,14 +177,6 @@ # endif #endif -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -339,25 +331,42 @@ void up_addregion(void) /* Yes.. allow user-mode access to the AHB SRAM user heap memory */ - lpc17_mpu_uheap((uintptr_t)LPC17_AHB_HEAPBASE, LPC17_AHB_HEAPSIZE); + lpc17_mpu_uheap((uintptr_t)LPC17_AHB_HEAPBASE, LPC17_AHB_HEAPSIZE); #endif /* Add the AHB SRAM user heap region. */ - kumm_addregion((FAR void *)LPC17_AHB_HEAPBASE, LPC17_AHB_HEAPSIZE); + kumm_addregion((FAR void *)LPC17_AHB_HEAPBASE, LPC17_AHB_HEAPSIZE); #endif #if CONFIG_MM_REGIONS >= 3 #if defined(CONFIG_LPC17_EXTDRAM) && defined(CONFIG_LPC17_EXTDRAMHEAP) - kmm_addregion((FAR void *)LPC17_EXTDRAM_CS0, CONFIG_LPC17_EXTDRAMSIZE); +#if defined(CONFIG_BUILD_PROTECTED) && defined(CONFIG_MM_KERNEL_HEAP) + /* Allow user-mode access to external DRAM heap memory */ + + lpc17_mpu_uheap((uintptr_t)LPC17_EXTDRAM_CS0, CONFIG_LPC17_EXTDRAMSIZE); + #endif + /* Add external DRAM heap memory to the user heap */ + + kumm_addregion((FAR void *)LPC17_EXTDRAM_CS0, CONFIG_LPC17_EXTDRAMSIZE); +#endif + #if !defined(CONFIG_LPC17_EXTDRAMHEAP) || (CONFIG_MM_REGIONS >= 4) #if defined(CONFIG_LPC17_EXTSRAM0) && defined(CONFIG_LPC17_EXTSRAM0HEAP) - kmm_addregion((FAR void *)LPC17_EXTSRAM_CS0, CONFIG_LPC17_EXTSRAM0SIZE); -#endif +#if defined(CONFIG_BUILD_PROTECTED) && defined(CONFIG_MM_KERNEL_HEAP) + /* Allow user-mode access to external SRAM heap memory */ + + lpc17_mpu_uheap((uintptr_t)LPC17_EXTSRAM_CS0, CONFIG_LPC17_EXTSRAM0SIZE); + +#endif + /* Add external SRAM heap memory to the user heap */ + + kumm_addregion((FAR void *)LPC17_EXTSRAM_CS0, CONFIG_LPC17_EXTSRAM0SIZE); #endif #endif +#endif /* CONFIG_MM_REGIONS >= 3 */ } #endif diff --git a/arch/arm/src/lpc31xx/lpc31_allocateheap.c b/arch/arm/src/lpc31xx/lpc31_allocateheap.c index 9c54871eaf..348285cf0c 100644 --- a/arch/arm/src/lpc31xx/lpc31_allocateheap.c +++ b/arch/arm/src/lpc31xx/lpc31_allocateheap.c @@ -63,6 +63,27 @@ ****************************************************************************/ /* Configuration ********************************************************/ +/* Terminology. In the flat build (CONFIG_BUILD_FLAT=y), there is only a + * single heap access with the standard allocations (malloc/free). This + * heap is referred to as the user heap. In the protected build + * (CONFIG_BUILD_PROTECTED=y) where an MPU is used to protect a region of + * otherwise flat memory, there will be two allocators: One that allocates + * protected (kernel) memory and one that allocates unprotected (user) + * memory. These are referred to as the kernel and user heaps, + * respectively. + * + * The ARM has no MPU but does have an MMU. With this MMU, it can support + * the kernel build (CONFIG_BUILD_KERNEL=y). In this configuration, there + * is one kernel heap but multiple user heaps: One per task group. However, + * in this case, we need only be concerned about initializing the single + * kernel heap here. + */ + +#if defined(CONFIG_BUILD_KERNEL) +# define MM_ADDREGION kmm_addregion +#else +# define MM_ADDREGION umm_addregion +#endif /* Some sanity checking. If external memory regions are defined, verify * that CONFIG_MM_REGIONS is set to match, exactly, the number of external @@ -142,14 +163,6 @@ # endif #endif -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -198,15 +211,15 @@ void up_allocate_heap(FAR void **heap_start, size_t *heap_size) void up_addregion(void) { #if defined(CONFIG_LPC31_EXTSRAM0) && defined(CONFIG_LPC31_EXTSRAM0HEAP) - kmm_addregion((FAR void *)LPC31_EXTSRAM0_VSECTION, CONFIG_LPC31_EXTSRAM0SIZE); + MM_ADDREGION((FAR void *)LPC31_EXTSRAM0_VSECTION, CONFIG_LPC31_EXTSRAM0SIZE); #endif #if defined(CONFIG_LPC31_EXTSRAM1) && defined(CONFIG_LPC31_EXTSRAM1HEAP) - kmm_addregion((FAR void *)LPC31_EXTSRAM1_VSECTION, CONFIG_LPC31_EXTSRAM1SIZE); + MM_ADDREGION((FAR void *)LPC31_EXTSRAM1_VSECTION, CONFIG_LPC31_EXTSRAM1SIZE); #endif #if defined(CONFIG_LPC31_EXTDRAM) && defined(CONFIG_LPC31_EXTDRAMHEAP) - kmm_addregion((FAR void *)LPC31_EXTSDRAM_VSECTION, CONFIG_LPC31_EXTDRAMSIZE); + MM_ADDREGION((FAR void *)LPC31_EXTSDRAM_VSECTION, CONFIG_LPC31_EXTDRAMSIZE); #endif } #endif