<div dir="ltr"><div>From 4d2a4662da9b0988c9e871490ed4ca466940754b Mon Sep 17 00:00:00 2001</div><div>From: Hesham AL-Matary <<a href="mailto:heshamelmatary@gmail.com">heshamelmatary@gmail.com</a>></div><div>Date: Sun, 15 Sep 2013 12:37:25 +0200</div>
<div>Subject: [PATCH 2/3] shared MMU initialization for ARM BSPs</div><div><br></div><div>The newly added ORed flag: ARM_CP15_CTRL_XP is vital to get RaspberryPi</div><div>MMU working properly and to share the container function between various</div>
<div>ARM BSPs. The new ORed flags do not affect the current BSPs that make use</div><div>of arm_cp15_start_setup_translation_table_and_enable_mmu_and_cache function.</div><div><br></div><div>The rest is of the patch targets MMU initialization for ARM architectures,</div>
<div>desgined to be shared. Later patches make use of shared mminit implementation.</div><div>---</div><div> .../lib/libbsp/arm/shared/include/arm-cp15-start.h | 12 +++++----</div><div> c/src/lib/libbsp/arm/shared/mminit.c               | 27 +++++++++++++++++++</div>
<div> c/src/lib/libbsp/shared/include/mm.h               | 31 ++++++++++++++++++++++</div><div> 3 files changed, 65 insertions(+), 5 deletions(-)</div><div> create mode 100644 c/src/lib/libbsp/arm/shared/mminit.c</div><div>
 create mode 100644 c/src/lib/libbsp/shared/include/mm.h</div><div><br></div><div>diff --git a/c/src/lib/libbsp/arm/shared/include/arm-cp15-start.h b/c/src/lib/libbsp/arm/shared/include/arm-cp15-start.h</div><div>index 01f3104..70b0f60 100644</div>
<div>--- a/c/src/lib/libbsp/arm/shared/include/arm-cp15-start.h</div><div>+++ b/c/src/lib/libbsp/arm/shared/include/arm-cp15-start.h</div><div>@@ -1,4 +1,5 @@</div><div>-/*</div><div>+/* </div><div>+ * Copyright (c) 2013 Hesham AL-Matary.</div>
<div>  * Copyright (c) 2009-2013 embedded brains GmbH.  All rights reserved.</div><div>  *</div><div>  *  embedded brains GmbH</div><div>@@ -16,7 +17,6 @@</div><div> #define LIBBSP_ARM_SHARED_ARM_CP15_START_H</div><div> </div>
<div> #include <libcpu/arm-cp15.h></div><div>-</div><div> #include <bsp/start.h></div><div> </div><div> #ifdef __cplusplus</div><div>@@ -87,9 +87,9 @@ arm_cp15_start_setup_translation_table_and_enable_mmu_and_cache(</div>
<div>   arm_cp15_set_domain_access_control(dac);</div><div>   arm_cp15_set_translation_table_base(ttb);</div><div> </div><div>-  /* Initialize translation table with invalid entries */</div><div>+  /* Initialize translation table with fixed-map read-write entries */</div>
<div>   for (i = 0; i < ARM_MMU_TRANSLATION_TABLE_ENTRY_COUNT; ++i) {</div><div>-    ttb [i] = 0;</div><div>+    ttb [i] = (i << ARM_MMU_SECT_BASE_SHIFT) | ARMV7_MMU_DATA_READ_WRITE;</div><div>   }</div><div> </div>
<div>   for (i = 0; i < config_count; ++i) {</div><div>@@ -97,7 +97,9 @@ arm_cp15_start_setup_translation_table_and_enable_mmu_and_cache(</div><div>   }</div><div> </div><div>   /* Enable MMU and cache */</div><div>-  ctrl |= ARM_CP15_CTRL_I | ARM_CP15_CTRL_C | ARM_CP15_CTRL_M;</div>
<div>+  ctrl |= ARM_CP15_CTRL_AFE | ARM_CP15_CTRL_S | ARM_CP15_CTRL_I |</div><div>+          ARM_CP15_CTRL_C | ARM_CP15_CTRL_M  | ARM_CP15_CTRL_XP;</div><div>+</div><div>   arm_cp15_set_control(ctrl);</div><div> }</div><div>
 </div><div>diff --git a/c/src/lib/libbsp/arm/shared/mminit.c b/c/src/lib/libbsp/arm/shared/mminit.c</div><div>new file mode 100644</div><div>index 0000000..c3d9f16</div><div>--- /dev/null</div><div>+++ b/c/src/lib/libbsp/arm/shared/mminit.c</div>
<div>@@ -0,0 +1,27 @@</div><div>+/* </div><div>+ * Copyright (c) 2013 Hesham AL-Matary.</div><div>+ * </div><div>+ * The license and distribution terms for this file may be</div><div>+ * found in the file LICENSE in this distribution or at</div>
<div>+ * <a href="http://www.rtems.com/license/LICENSE">http://www.rtems.com/license/LICENSE</a>.</div><div>+ */</div><div>+#include <bsp/arm-cp15-start.h></div><div>+#include <bsp/linker-symbols.h></div><div>
+#include <bsp/mm.h></div><div>+#include <bsp/start.h></div><div>+</div><div>+extern const arm_cp15_start_section_config bsp_mm_config_table[];</div><div>+extern const size_t bsp_mm_config_table_size;</div><div>
+</div><div>+BSP_START_TEXT_SECTION void bsp_memory_management_initialize(void)</div><div>+{</div><div>+  uint32_t ctrl = arm_cp15_get_control();</div><div>+</div><div>+  arm_cp15_start_setup_translation_table_and_enable_mmu_and_cache(</div>
<div>+    ctrl,</div><div>+    (uint32_t *) bsp_translation_table_base,</div><div>+    ARM_MMU_DEFAULT_CLIENT_DOMAIN,</div><div>+    &bsp_mm_config_table[0],</div><div>+    bsp_mm_config_table_size</div><div>+  );</div>
<div>+}</div><div>diff --git a/c/src/lib/libbsp/shared/include/mm.h b/c/src/lib/libbsp/shared/include/mm.h</div><div>new file mode 100644</div><div>index 0000000..476c288</div><div>--- /dev/null</div><div>+++ b/c/src/lib/libbsp/shared/include/mm.h</div>
<div>@@ -0,0 +1,31 @@</div><div>+/*</div><div>+ * Copyright (c) 2013 Hesham AL-Matary.</div><div>+ * Copyright (c) 2013 Gedare Bloom.</div><div>+ *</div><div>+ * The license and distribution terms for this file may be</div>
<div>+ * found in the file LICENSE in this distribution or at</div><div>+ * <a href="http://www.rtems.com/license/LICENSE">http://www.rtems.com/license/LICENSE</a>.</div><div>+ */</div><div>+</div><div>+#ifndef __LIBBSP_MM_H</div>
<div>+#define __LIBBSP_MM_H</div><div>+</div><div>+#include <stdint.h></div><div>+#include <stdlib.h></div><div>+</div><div>+#ifdef __cplusplus</div><div>+extern "C" {</div><div>+#endif</div><div>+</div>
<div>+void bsp_memory_management_initialize(void);</div><div>+</div><div>+void bsp_memory_management_set_attributes(</div><div>+  uintptr_t base,</div><div>+  size_t size,</div><div>+  uint32_t attr</div><div>+);</div><div>
+</div><div>+#ifdef __cplusplus</div><div>+}</div><div>+#endif</div><div>+#endif</div><div>-- </div><div>1.8.3.1</div><div><br></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Mon, Sep 16, 2013 at 6:17 PM, Hesham AL-Matary <span dir="ltr"><<a href="mailto:heshamelmatary@gmail.com" target="_blank">heshamelmatary@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">The newly added ORed flag: ARM_CP15_CTRL_XP is vital to get RaspberryPi<br>
MMU working properly and to share the container function between various<br>
ARM BSPs. The new ORed flags do not affect the current BSPs that make use<br>
of arm_cp15_start_setup_translation_table_and_enable_mmu_and_cache function.<br>
<br>
The rest is of the patch targets MMU initialization for ARM architectures,<br>
desgined to be shared. Later patches make use of shared mminit implementation.<br>
<br>
---<br>
 c/src/lib/libbsp/arm/shared/mminit.c | 27 +++++++++++++++++++++++++++<br>
 c/src/lib/libbsp/shared/include/mm.h | 31 +++++++++++++++++++++++++++++++<br>
 2 files changed, 58 insertions(+)<br>
 create mode 100644 c/src/lib/libbsp/arm/shared/mminit.c<br>
 create mode 100644 c/src/lib/libbsp/shared/include/mm.h<br>
<br>
diff --git a/c/src/lib/libbsp/arm/shared/mminit.c b/c/src/lib/libbsp/arm/shared/mminit.c<br>
new file mode 100644<br>
index 0000000..c3d9f16<br>
--- /dev/null<br>
+++ b/c/src/lib/libbsp/arm/shared/mminit.c<br>
@@ -0,0 +1,27 @@<br>
+/*<br>
+ * Copyright (c) 2013 Hesham AL-Matary.<br>
+ *<br>
+ * The license and distribution terms for this file may be<br>
+ * found in the file LICENSE in this distribution or at<br>
+ * <a href="http://www.rtems.com/license/LICENSE" target="_blank">http://www.rtems.com/license/LICENSE</a>.<br>
+ */<br>
+#include <bsp/arm-cp15-start.h><br>
+#include <bsp/linker-symbols.h><br>
+#include <bsp/mm.h><br>
+#include <bsp/start.h><br>
+<br>
+extern const arm_cp15_start_section_config bsp_mm_config_table[];<br>
+extern const size_t bsp_mm_config_table_size;<br>
+<br>
+BSP_START_TEXT_SECTION void bsp_memory_management_initialize(void)<br>
+{<br>
+  uint32_t ctrl = arm_cp15_get_control();<br>
+<br>
+  arm_cp15_start_setup_translation_table_and_enable_mmu_and_cache(<br>
+    ctrl,<br>
+    (uint32_t *) bsp_translation_table_base,<br>
+    ARM_MMU_DEFAULT_CLIENT_DOMAIN,<br>
+    &bsp_mm_config_table[0],<br>
+    bsp_mm_config_table_size<br>
+  );<br>
+}<br>
diff --git a/c/src/lib/libbsp/shared/include/mm.h b/c/src/lib/libbsp/shared/include/mm.h<br>
new file mode 100644<br>
index 0000000..476c288<br>
--- /dev/null<br>
+++ b/c/src/lib/libbsp/shared/include/mm.h<br>
@@ -0,0 +1,31 @@<br>
+/*<br>
+ * Copyright (c) 2013 Hesham AL-Matary.<br>
+ * Copyright (c) 2013 Gedare Bloom.<br>
+ *<br>
+ * The license and distribution terms for this file may be<br>
+ * found in the file LICENSE in this distribution or at<br>
+ * <a href="http://www.rtems.com/license/LICENSE" target="_blank">http://www.rtems.com/license/LICENSE</a>.<br>
+ */<br>
+<br>
+#ifndef __LIBBSP_MM_H<br>
+#define __LIBBSP_MM_H<br>
+<br>
+#include <stdint.h><br>
+#include <stdlib.h><br>
+<br>
+#ifdef __cplusplus<br>
+extern "C" {<br>
+#endif<br>
+<br>
+void bsp_memory_management_initialize(void);<br>
+<br>
+void bsp_memory_management_set_attributes(<br>
+  uintptr_t base,<br>
+  size_t size,<br>
+  uint32_t attr<br>
+);<br>
+<br>
+#ifdef __cplusplus<br>
+}<br>
+#endif<br>
+#endif<br>
<span class="HOEnZb"><font color="#888888">--<br>
1.8.3.1<br>
<br>
</font></span></blockquote></div><br></div>