Code refactor for ARM bsp MMU initialization
Rohini Kulkarni
krohini1593 at gmail.com
Wed Jul 8 12:44:20 UTC 2015
Hi,
It has been suggested that the function bsp_memory_management_
initialize() in mminit.c be modified so that it is shareable between more
arm variants ( will be useful only for those that support cp15 model ).
I think currently only the raspberry pi uses it, and was not suitable for
Pi 2 either.
I have made some changes. I request you to review it for further changes as
needed.
Thanks!
---
c/src/lib/libbsp/arm/
raspberrypi/include/bsp.h | 3 ++
.../libbsp/arm/raspberrypi/startup/bspstarthooks.c | 8 ++---
.../libbsp/arm/raspberrypi/startup/bspstartmmu.c | 30 +++++++++++++++++
c/src/lib/libbsp/arm/shared/mminit.c | 35
++++----------------
c/src/lib/libbsp/shared/include/mm.h | 4 +++
5 files changed, 48 insertions(+), 32 deletions(-)
create mode 100644 c/src/lib/libbsp/arm/raspberrypi/startup/bspstartmmu.c
diff --git a/c/src/lib/libbsp/arm/raspberrypi/include/bsp.h
b/c/src/lib/libbsp/arm/raspberrypi/include/bsp.h
index c05a410..d9e86d8 100644
--- a/c/src/lib/libbsp/arm/raspberrypi/include/bsp.h
+++ b/c/src/lib/libbsp/arm/raspberrypi/include/bsp.h
@@ -47,3 +47,6 @@ extern "C" {
* @brief Raspberry Pi support package
*
*/
+
+void raspberrypi_setup_mmu_and_cache(void);
+
diff --git a/c/src/lib/libbsp/arm/raspberrypi/startup/bspstarthooks.c
b/c/src/lib/libbsp/arm/raspberrypi/startup/bspstarthooks.c
index 047c8ad..107649f 100644
--- a/c/src/lib/libbsp/arm/raspberrypi/startup/bspstarthooks.c
+++ b/c/src/lib/libbsp/arm/raspberrypi/startup/bspstarthooks.c
@@ -26,15 +26,15 @@
#include <bsp/start.h>
#include <bsp/raspberrypi.h>
#include <bsp/mm.h>
+#include <bsp.h>
void BSP_START_TEXT_SECTION bsp_start_hook_0(void)
-{
+{
}
-
void BSP_START_TEXT_SECTION bsp_start_hook_1(void)
{
bsp_start_copy_sections();
- bsp_memory_management_initialize();
+ raspberrypi_setup_mmu_and_cache();
bsp_start_clear_bss();
-}
+}
\ No newline at end of file
diff --git a/c/src/lib/libbsp/arm/raspberrypi/startup/bspstartmmu.c
b/c/src/lib/libbsp/arm/raspberrypi/startup/bspstartmmu.c
new file mode 100644
index 0000000..506346e
--- /dev/null
+++ b/c/src/lib/libbsp/arm/raspberrypi/startup/bspstartmmu.c
@@ -0,0 +1,30 @@
+#define ARM_CP15_TEXT_SECTION BSP_START_TEXT_SECTION
+
+#include <bsp/start.h>
+#include <bsp/arm-cp15-start.h>
+#include <bsp/linker-symbols.h>
+#include <libcpu/arm-cp15.h>
+#include <bsp/mm.h>
+#include <bsp.h>
+
+uint32_t bsp_initial_mmu_ctrl_set;
+uint32_t bsp_initial_mmu_ctrl_clear;
+uint32_t domain_set;
+
+void raspberrypi_setup_mmu_and_cache(void)
+{
+#if (BSP_IS_RPI2 == 1)
+ /* Enable SMP in auxiliary control */
+ uint32_t actlr = arm_cp15_get_auxiliary_control();
+ actlr |= ARM_CORTEX_A9_ACTL_SMP;
+ arm_cp15_set_auxiliary_control(actlr);
+ bsp_initial_mmu_ctrl_clear = ARM_CP15_CTRL_A;
+ bsp_initial_mmu_ctrl_set = ARM_CP15_CTRL_AFE | ARM_CP15_CTRL_Z;
+#else
+ bsp_initial_mmu_ctrl_clear = 0;
+ bsp_initial_mmu_ctrl_set = ARM_CP15_CTRL_AFE | ARM_CP15_CTRL_S |
ARM_CP15_CTRL_XP;
+#endif
+ domain_set = ARM_MMU_DEFAULT_CLIENT_DOMAIN;
+
+ bsp_memory_management_initialize();
+}
\ No newline at end of file
diff --git a/c/src/lib/libbsp/arm/shared/mminit.c
b/c/src/lib/libbsp/arm/shared/mminit.c
index 96ca1ec..c9d42e4 100644
--- a/c/src/lib/libbsp/arm/shared/mminit.c
+++ b/c/src/lib/libbsp/arm/shared/mminit.c
@@ -11,42 +11,21 @@
#include <bsp/start.h>
#include <bsp/arm-cp15-start.h>
#include <bsp/linker-symbols.h>
+#include <libcpu/arm-cp15.h>
#include <bsp/mm.h>
-#if (BSP_IS_RPI2 == 1)
-BSP_START_TEXT_SECTION void bsp_memory_management_initialize(void)
-{
- /* Enable SMP in auxiliary control */
- uint32_t actlr = arm_cp15_get_auxiliary_control();
- actlr |= ARM_CORTEX_A9_ACTL_SMP;
- arm_cp15_set_auxiliary_control(actlr);
+BSP_START_TEXT_SECTION void bsp_memory_management_initialize()
+{
uint32_t ctrl = arm_cp15_start_setup_mmu_and_cache(
- ARM_CP15_CTRL_A,
- ARM_CP15_CTRL_AFE| ARM_CP15_CTRL_Z
- );
+ bsp_initial_mmu_ctrl_clear,
+ bsp_initial_mmu_ctrl_set );
arm_cp15_start_setup_translation_table_and_enable_mmu_and_cache(
ctrl,
(uint32_t *) bsp_translation_table_base,
- ARM_MMU_DEFAULT_CLIENT_DOMAIN,
- &arm_cp15_start_mmu_config_table[0],
- arm_cp15_start_mmu_config_table_size
- );
-}
-#else
-BSP_START_TEXT_SECTION void bsp_memory_management_initialize(void)
-{
- uint32_t ctrl = arm_cp15_get_control();
-
- ctrl |= ARM_CP15_CTRL_AFE | ARM_CP15_CTRL_S | ARM_CP15_CTRL_XP;
-
- arm_cp15_start_setup_translation_table_and_enable_mmu_and_cache(
- ctrl,
- (uint32_t *) bsp_translation_table_base,
- ARM_MMU_DEFAULT_CLIENT_DOMAIN,
+ domain_set,
&arm_cp15_start_mmu_config_table[0],
arm_cp15_start_mmu_config_table_size
);
-}
-#endif
\ No newline at end of file
+}
\ No newline at end of file
diff --git a/c/src/lib/libbsp/shared/include/mm.h
b/c/src/lib/libbsp/shared/include/mm.h
index 2152f68..299b6c5 100644
--- a/c/src/lib/libbsp/shared/include/mm.h
+++ b/c/src/lib/libbsp/shared/include/mm.h
@@ -33,6 +33,10 @@ extern "C" {
* @brief MM Support Package
*/
+extern uint32_t bsp_initial_mmu_ctrl_set;
+extern uint32_t bsp_initial_mmu_ctrl_clear;
+extern uint32_t domain_set;
+
void bsp_memory_management_initialize(void);
#ifdef __cplusplus
--
1.7.9.5
--
Rohini Kulkarni
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.rtems.org/pipermail/devel/attachments/20150708/7ad0c9f6/attachment.html>
More information about the devel
mailing list