armv7m: add memory protection unit support
Subsystems (3)
cover armv7m: add memory protection unit support
This patchset adds memory protection unit support(MPU) support & configures it for stm32f4 & stm32f7.
Vikas Manocha (4):
armv7m: correct mpu region size define for 8MB size
armv7m: add MPU configuration support
stm32: use armv7m MPU configuration support
stm32f7: configure mpu valid for f7 family
arch/arm/cpu/armv7m/Makefile | 2 +- arch/arm/cpu/armv7m/mpu.c | 82 +++++++++++++++++++++++++++++++++++++++ arch/arm/include/asm/armv7m.h | 19 --------- arch/arm/include/asm/armv7m_mpu.h | 67 ++++++++++++++++++++++++++++++++ arch/arm/mach-stm32/stm32f4/soc.c | 16 ++++---- arch/arm/mach-stm32/stm32f7/soc.c | 63 ++++++++---------------------- 6 files changed, 176 insertions(+), 73 deletions(-) create mode 100644 arch/arm/cpu/armv7m/mpu.c create mode 100644 arch/arm/include/asm/armv7m_mpu.h
Signature · 1 line
1.9.1
PATCH 1/4 armv7m: correct mpu region size define for 8MB size
--- arch/arm/include/asm/armv7m.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
arch/arm/include/asm/armv7m.h +2 -1
@@ -80,7 +80,8 @@ struct v7m_mpu {#define V7M_MPU_RASR_EN (1 << 0)#define V7M_MPU_RASR_SIZE_BITS 1#define V7M_MPU_RASR_SIZE_4GB (31 << V7M_MPU_RASR_SIZE_BITS) -#define V7M_MPU_RASR_SIZE_8MB (24 << V7M_MPU_RASR_SIZE_BITS) +#define V7M_MPU_RASR_SIZE_8MB (22 << V7M_MPU_RASR_SIZE_BITS) +#define V7M_MPU_RASR_TEX_SHIFT 19#define V7M_MPU_RASR_S_SHIFT 18#define V7M_MPU_RASR_C_SHIFT 17
Signature · 1 line
1.9.1
PATCH 1/4 armv7m: correct mpu region size define for 8MB size
Quoted 1 line · Vikas Manocha
Signed-off-by Vikas Manocha <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 819 bytes Desc: Digital signature URL: <http://lists.denx.de/pipermail/u-boot/attachments/20170512/9a1d34ab/attachment.sig>
PATCH 2/4 armv7m: add MPU configuration support
In reply to Vikas ManochaCortex-M archs support option memory protection unit (MPU). MPU is used to set the memory types, attributes, access permissions for different regions, cache policies of the device.
e.g. using MPU it is possible to configure memory region as device memory or strongly ordered, memory attributes like execute never, cache policies like write-back or write-through.
--- arch/arm/cpu/armv7m/Makefile | 2 +- arch/arm/cpu/armv7m/mpu.c | 82 +++++++++++++++++++++++++++++++++++++++ arch/arm/include/asm/armv7m.h | 20 ---------- arch/arm/include/asm/armv7m_mpu.h | 67 ++++++++++++++++++++++++++++++++ 4 files changed, 150 insertions(+), 21 deletions(-) create mode 100644 arch/arm/cpu/armv7m/mpu.c create mode 100644 arch/arm/include/asm/armv7m_mpu.h
arch/arm/cpu/armv7m/Makefile +1 -1
@@ -6,5 +6,5 @@ # extra-y := start.o -obj-y += cpu.o cache.o +obj-y += cpu.o cache.o mpu.o obj-$(CONFIG_SYS_ARCH_TIMER) += systick-timer.o
arch/arm/cpu/armv7m/mpu.c new file +82 -0
82 lines not on this page · raw message
arch/arm/include/asm/armv7m.h +0 -20
@@ -70,25 +70,5 @@ struct v7m_mpu { };#define V7M_MPU ((struct v7m_mpu *)V7M_MPU_BASE) -#define V7M_MPU_CTRL_ENABLE (1 << 0) -#define V7M_MPU_CTRL_HFNMIENA (1 << 1) - -#define V7M_MPU_CTRL_ENABLE (1 << 0) -#define V7M_MPU_CTRL_DISABLE (0 << 0) -#define V7M_MPU_CTRL_HFNMIENA (1 << 1) - -#define V7M_MPU_RASR_EN (1 << 0) -#define V7M_MPU_RASR_SIZE_BITS 1 -#define V7M_MPU_RASR_SIZE_4GB (31 << V7M_MPU_RASR_SIZE_BITS) -#define V7M_MPU_RASR_SIZE_8MB (22 << V7M_MPU_RASR_SIZE_BITS) - -#define V7M_MPU_RASR_TEX_SHIFT 19 -#define V7M_MPU_RASR_S_SHIFT 18 -#define V7M_MPU_RASR_C_SHIFT 17 -#define V7M_MPU_RASR_B_SHIFT 16 -#define V7M_MPU_RASR_AP_RW_RW (3 << 24) -#define V7M_MPU_RASR_XN_ENABLE (0 << 28) -#define V7M_MPU_RASR_XN_DISABLE (1 << 28) -#endif /* !defined(__ASSEMBLY__) */ #endif /* ARMV7M_H */
arch/arm/include/asm/armv7m_mpu.h new file +67 -0
67 lines not on this page · raw message
Signature · 1 line
1.9.1
PATCH 2/4 armv7m: add MPU configuration support
Quoted 9 lines · Vikas Manocha
Cortex-M archs support option memory protection unit (MPU). MPU is used to set the memory types, attributes, access permissions for different regions, cache policies of the device.
e.g. using MPU it is possible to configure memory region as device memory or strongly ordered, memory attributes like execute never, cache policies like write-back or write-through.
Signed-off-by Vikas Manocha <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 819 bytes Desc: Digital signature URL: <http://lists.denx.de/pipermail/u-boot/attachments/20170512/525eea3a/attachment.sig>
PATCH 3/4 stm32: use armv7m MPU configuration support
In reply to Vikas Manocha--- arch/arm/mach-stm32/stm32f4/soc.c | 16 +++++----- arch/arm/mach-stm32/stm32f7/soc.c | 64 ++++++++------------------------------- 2 files changed, 22 insertions(+), 58 deletions(-)
arch/arm/mach-stm32/stm32f4/soc.c +9 -7
@@ -7,7 +7,7 @@#include <common.h> #include <asm/io.h> -#include <asm/armv7m.h> +#include <asm/armv7m_mpu.h> #include <asm/arch/stm32.h> u32 get_cpu_rev (void )
@@ -17,17 +17,19 @@ u32 get_cpu_rev(void)int arch_cpu_init (void ) { +struct mpu_region_config stm32_region_config[] = { + {0x00000000 ,REGION_0 ,XN_DIS ,PRIV_RW_USR_RW , +STRONG_ORDER ,REGION_4GB }, + };configure_clocks (); -/* * Configure the memory protection unit (MPU) to allow full access to * the whole 4GB address space. */ -writel (0 , &V7M_MPU ->rnr); -writel (0 , &V7M_MPU ->rbar); -writel ((V7M_MPU_RASR_AP_RW_RW |V7M_MPU_RASR_SIZE_4GB - |V7M_MPU_RASR_EN ), &V7M_MPU ->rasr); -writel (V7M_MPU_CTRL_ENABLE |V7M_MPU_CTRL_HFNMIENA , &V7M_MPU ->ctrl); +disable_mpu (); +for (int i =0 ; i <ARRAY_SIZE (stm32_region_config); i++) +mpu_config (&stm32_region_config[i]); +enable_mpu ();return 0 ; }
arch/arm/mach-stm32/stm32f7/soc.c +13 -51
76 lines not on this page · raw message
Signature · 1 line
1.9.1
PATCH 3/4 stm32: use armv7m MPU configuration support
Quoted 1 line · Vikas Manocha
Signed-off-by Vikas Manocha <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 819 bytes Desc: Digital signature URL: <http://lists.denx.de/pipermail/u-boot/attachments/20170512/0e1540ff/attachment.sig>
PATCH 4/4 stm32f7: configure mpu valid for f7 family
In reply to Vikas ManochaThis configuration should be valid for all F7 family devices in general. Here is the regions info:
- Region0 : 4GB : cacheable & executable.
- Region1 : 512MB : text area : strogly ordered & executable.
- Region2 : 512MB : peripherals : device memory & non-executable.
- Region3 : 512MB : peripherals : device memory & non-executable.
- Region4 : 512MB : cortexM area: strongly ordered & non-executable.
Higher region number overrides the lower region configuration.
--- arch/arm/mach-stm32/stm32f7/soc.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-)
arch/arm/mach-stm32/stm32f7/soc.c +12 -3
@@ -19,10 +19,19 @@ int arch_cpu_init(void) {struct mpu_region_config stm32_region_config[] = { {0x00000000 ,REGION_0 ,XN_DIS ,PRIV_RW_USR_RW , -STRONG_ORDER ,REGION_4GB }, +O_I_WB_RD_WR_ALLOC ,REGION_4GB }, - {0xC0000000 ,REGION_1 ,XN_DIS ,PRIV_RW_USR_RW , -O_I_WB_RD_WR_ALLOC ,REGION_8MB }, + {0x00000000 ,REGION_1 ,XN_DIS ,PRIV_RW_USR_RW , +STRONG_ORDER ,REGION_512MB }, + + {0x40000000 ,REGION_2 ,XN_EN ,PRIV_RW_USR_RW , +DEVICE_NON_SHARED ,REGION_512MB }, + + {0xA0000000 ,REGION_3 ,XN_EN ,PRIV_RW_USR_RW , +DEVICE_NON_SHARED ,REGION_512MB }, + + {0xE0000000 ,REGION_4 ,XN_EN ,PRIV_RW_USR_RW , +STRONG_ORDER ,REGION_512MB }, };disable_mpu ();
Signature · 1 line
1.9.1
PATCH 4/4 stm32f7: configure mpu valid for f7 family
Quoted 9 lines · Vikas Manocha
This configuration should be valid for all F7 family devices in general. Here is the regions info:
- Region0 : 4GB : cacheable & executable.
- Region1 : 512MB : text area : strogly ordered & executable.
- Region2 : 512MB : peripherals : device memory & non-executable.
- Region3 : 512MB : peripherals : device memory & non-executable.
- Region4 : 512MB : cortexM area: strongly ordered & non-executable.
Quoted 3 lines
Higher region number overrides the lower region configuration.
Signed-off-by Vikas Manocha <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 819 bytes Desc: Digital signature URL: <http://lists.denx.de/pipermail/u-boot/attachments/20170512/0302db31/attachment.sig>