ARM: omap: un-merge plat/sram.c
authorArnd Bergmann <arnd@arndb.de>
Fri, 20 Sep 2019 16:16:09 +0000 (18:16 +0200)
committerArnd Bergmann <arnd@arndb.de>
Fri, 22 Apr 2022 09:08:55 +0000 (11:08 +0200)
The sram initialization code is the only shared omap1/2 code that
is not a standalone driver, but it is very short. Having two copies
of this code means some duplication of the sources, but actually
saves object code size as it can be inlined better.

Acked-by: Tony Lindgren <tony@atomide.com>
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
arch/arm/mach-omap1/devices.c
arch/arm/mach-omap1/sram-init.c
arch/arm/mach-omap1/sram.h
arch/arm/mach-omap2/sram.c
arch/arm/mach-omap2/sram.h
arch/arm/plat-omap/Makefile
arch/arm/plat-omap/include/plat/sram.h [deleted file]
arch/arm/plat-omap/sram.c [deleted file]

index eb0f09edb3d149106a133165a826a7cbb7d6d6a7..6bc32ebda7a71f4694a460bb6afe9f235f02ed4e 100644 (file)
@@ -356,7 +356,7 @@ static int __init omap1_init_devices(void)
        if (!cpu_class_is_omap1())
                return -ENODEV;
 
-       omap_sram_init();
+       omap1_sram_init();
        omap1_clk_late_init();
 
        /* please keep these calls, and their implementations above,
index 3bd60708c34509de56128cbf0143f681011fc426..0e3ec32a008e221ce139d3fa7858093860253716 100644 (file)
@@ -14,6 +14,7 @@
 #include <asm/fncpy.h>
 #include <asm/tlb.h>
 #include <asm/cacheflush.h>
+#include <asm/set_memory.h>
 
 #include <asm/mach/map.h>
 
 
 #define OMAP1_SRAM_PA          0x20000000
 #define SRAM_BOOTLOADER_SZ     0x80
+#define ROUND_DOWN(value,boundary)     ((value) & (~((boundary)-1)))
+
+static void __iomem *omap_sram_base;
+static unsigned long omap_sram_start;
+static unsigned long omap_sram_skip;
+static unsigned long omap_sram_size;
+static void __iomem *omap_sram_ceil;
+
+/*
+ * Memory allocator for SRAM: calculates the new ceiling address
+ * for pushing a function using the fncpy API.
+ *
+ * Note that fncpy requires the returned address to be aligned
+ * to an 8-byte boundary.
+ */
+static void *omap_sram_push_address(unsigned long size)
+{
+       unsigned long available, new_ceil = (unsigned long)omap_sram_ceil;
+
+       available = omap_sram_ceil - (omap_sram_base + omap_sram_skip);
+
+       if (size > available) {
+               pr_err("Not enough space in SRAM\n");
+               return NULL;
+       }
+
+       new_ceil -= size;
+       new_ceil = ROUND_DOWN(new_ceil, FNCPY_ALIGN);
+       omap_sram_ceil = IOMEM(new_ceil);
+
+       return (void *)omap_sram_ceil;
+}
+
+void *omap_sram_push(void *funcp, unsigned long size)
+{
+       void *sram;
+       unsigned long base;
+       int pages;
+       void *dst = NULL;
+
+       sram = omap_sram_push_address(size);
+       if (!sram)
+               return NULL;
+
+       base = (unsigned long)sram & PAGE_MASK;
+       pages = PAGE_ALIGN(size) / PAGE_SIZE;
+
+       set_memory_rw(base, pages);
+
+       dst = fncpy(sram, funcp, size);
+
+       set_memory_ro(base, pages);
+       set_memory_x(base, pages);
+
+       return dst;
+}
 
 /*
  * The amount of SRAM depends on the core type.
  * Note that we cannot try to test for SRAM here because writes
  * to secure SRAM will hang the system. Also the SRAM is not
  * yet mapped at this point.
+ * Note that we cannot use ioremap for SRAM, as clock init needs SRAM early.
  */
 static void __init omap_detect_and_map_sram(void)
 {
-       unsigned long omap_sram_skip = SRAM_BOOTLOADER_SZ;
-       unsigned long omap_sram_start = OMAP1_SRAM_PA;
-       unsigned long omap_sram_size;
+       unsigned long base;
+       int pages;
+
+       omap_sram_skip = SRAM_BOOTLOADER_SZ;
+       omap_sram_start = OMAP1_SRAM_PA;
 
        if (cpu_is_omap7xx())
                omap_sram_size = 0x32000;       /* 200K */
@@ -47,8 +107,27 @@ static void __init omap_detect_and_map_sram(void)
                omap_sram_size = 0x4000;
        }
 
-       omap_map_sram(omap_sram_start, omap_sram_size,
-               omap_sram_skip, 1);
+       omap_sram_start = ROUND_DOWN(omap_sram_start, PAGE_SIZE);
+       omap_sram_base = __arm_ioremap_exec(omap_sram_start, omap_sram_size, 1);
+       if (!omap_sram_base) {
+               pr_err("SRAM: Could not map\n");
+               return;
+       }
+
+       omap_sram_ceil = omap_sram_base + omap_sram_size;
+
+       /*
+        * Looks like we need to preserve some bootloader code at the
+        * beginning of SRAM for jumping to flash for reboot to work...
+        */
+       memset_io(omap_sram_base + omap_sram_skip, 0,
+                 omap_sram_size - omap_sram_skip);
+
+       base = (unsigned long)omap_sram_base;
+       pages = PAGE_ALIGN(omap_sram_size) / PAGE_SIZE;
+
+       set_memory_ro(base, pages);
+       set_memory_x(base, pages);
 }
 
 static void (*_omap_sram_reprogram_clock)(u32 dpllctl, u32 ckctl);
@@ -62,7 +141,7 @@ void omap_sram_reprogram_clock(u32 dpllctl, u32 ckctl)
        _omap_sram_reprogram_clock(dpllctl, ckctl);
 }
 
-int __init omap_sram_init(void)
+int __init omap1_sram_init(void)
 {
        omap_detect_and_map_sram();
        _omap_sram_reprogram_clock =
index 73efabd119e80083bb134439330d3a628fc4dfb4..f45e6dd6d7e5653cac4e46535a628882dd4f5799 100644 (file)
@@ -1,8 +1,10 @@
 /* SPDX-License-Identifier: GPL-2.0 */
-#include <plat/sram.h>
 
 extern void omap_sram_reprogram_clock(u32 dpllctl, u32 ckctl);
 
+int omap1_sram_init(void);
+void *omap_sram_push(void *funcp, unsigned long size);
+
 /* Do not use these */
 extern void omap1_sram_reprogram_clock(u32 ckctl, u32 dpllctl);
 extern unsigned long omap1_sram_reprogram_clock_sz;
index c98855f5594b60c3bc9432961636563dd2e939af..c685afb8bd035d5acf579b61b75de4c43e5e1b20 100644 (file)
@@ -18,6 +18,7 @@
 #include <asm/fncpy.h>
 #include <asm/tlb.h>
 #include <asm/cacheflush.h>
+#include <asm/set_memory.h>
 
 #include <asm/mach/map.h>
 
 #define ROUND_DOWN(value,boundary)     ((value) & (~((boundary)-1)))
 
 static unsigned long omap_sram_start;
-static unsigned long omap_sram_skip;
 static unsigned long omap_sram_size;
+static void __iomem *omap_sram_base;
+static unsigned long omap_sram_skip;
+static void __iomem *omap_sram_ceil;
+
+/*
+ * Memory allocator for SRAM: calculates the new ceiling address
+ * for pushing a function using the fncpy API.
+ *
+ * Note that fncpy requires the returned address to be aligned
+ * to an 8-byte boundary.
+ */
+static void *omap_sram_push_address(unsigned long size)
+{
+       unsigned long available, new_ceil = (unsigned long)omap_sram_ceil;
+
+       available = omap_sram_ceil - (omap_sram_base + omap_sram_skip);
+
+       if (size > available) {
+               pr_err("Not enough space in SRAM\n");
+               return NULL;
+       }
+
+       new_ceil -= size;
+       new_ceil = ROUND_DOWN(new_ceil, FNCPY_ALIGN);
+       omap_sram_ceil = IOMEM(new_ceil);
+
+       return (void *)omap_sram_ceil;
+}
+
+void *omap_sram_push(void *funcp, unsigned long size)
+{
+       void *sram;
+       unsigned long base;
+       int pages;
+       void *dst = NULL;
+
+       sram = omap_sram_push_address(size);
+       if (!sram)
+               return NULL;
+
+       base = (unsigned long)sram & PAGE_MASK;
+       pages = PAGE_ALIGN(size) / PAGE_SIZE;
+
+       set_memory_rw(base, pages);
+
+       dst = fncpy(sram, funcp, size);
+
+       set_memory_ro(base, pages);
+       set_memory_x(base, pages);
+
+       return dst;
+}
+
+/*
+ * The SRAM context is lost during off-idle and stack
+ * needs to be reset.
+ */
+static void omap_sram_reset(void)
+{
+       omap_sram_ceil = omap_sram_base + omap_sram_size;
+}
 
 /*
  * Depending on the target RAMFS firewall setup, the public usable amount of
@@ -119,6 +180,8 @@ static void __init omap_detect_sram(void)
  */
 static void __init omap2_map_sram(void)
 {
+       unsigned long base;
+       int pages;
        int cached = 1;
 
        if (cpu_is_omap34xx()) {
@@ -132,8 +195,30 @@ static void __init omap2_map_sram(void)
                cached = 0;
        }
 
-       omap_map_sram(omap_sram_start, omap_sram_size,
-                       omap_sram_skip, cached);
+       if (omap_sram_size == 0)
+               return;
+
+       omap_sram_start = ROUND_DOWN(omap_sram_start, PAGE_SIZE);
+       omap_sram_base = __arm_ioremap_exec(omap_sram_start, omap_sram_size, cached);
+       if (!omap_sram_base) {
+               pr_err("SRAM: Could not map\n");
+               return;
+       }
+
+       omap_sram_reset();
+
+       /*
+        * Looks like we need to preserve some bootloader code at the
+        * beginning of SRAM for jumping to flash for reboot to work...
+        */
+       memset_io(omap_sram_base + omap_sram_skip, 0,
+                 omap_sram_size - omap_sram_skip);
+
+       base = (unsigned long)omap_sram_base;
+       pages = PAGE_ALIGN(omap_sram_size) / PAGE_SIZE;
+
+       set_memory_ro(base, pages);
+       set_memory_x(base, pages);
 }
 
 static void (*_omap2_sram_ddr_init)(u32 *slow_dll_ctrl, u32 fast_dll_ctrl,
index 447bd3eed0fd30e11c1c008b888773ea6326b60d..271062f23482221002e947cb25b589f7bd472a77 100644 (file)
@@ -4,7 +4,6 @@
  */
 
 #ifndef __ASSEMBLY__
-#include <plat/sram.h>
 
 extern void omap2_sram_ddr_init(u32 *slow_dll_ctrl, u32 fast_dll_ctrl,
                                u32 base_cs, u32 force_unlock);
@@ -14,6 +13,10 @@ extern u32 omap2_set_prcm(u32 dpll_ctrl_val, u32 sdrc_rfr_val, int bypass);
 
 extern void omap3_sram_restore_context(void);
 
+extern int __init omap_sram_init(void);
+
+extern void *omap_sram_push(void *funcp, unsigned long size);
+
 /* Do not use these */
 extern void omap24xx_sram_reprogram_clock(u32 ckctl, u32 dpllctl);
 extern unsigned long omap24xx_sram_reprogram_clock_sz;
index 5d55295a14eee0bd2c4833bb2ea3d6e4b0a27599..fefce2e1eaf34498a07d6e56d5bb8bbf419ed754 100644 (file)
@@ -6,4 +6,4 @@
 ccflags-$(CONFIG_ARCH_MULTIPLATFORM) := -I$(srctree)/arch/arm/plat-omap/include
 
 # Common support
-obj-y := sram.o
+obj-y :=
diff --git a/arch/arm/plat-omap/include/plat/sram.h b/arch/arm/plat-omap/include/plat/sram.h
deleted file mode 100644 (file)
index 30a0773..0000000
+++ /dev/null
@@ -1,8 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 */
-int omap_sram_init(void);
-
-void omap_map_sram(unsigned long start, unsigned long size,
-                       unsigned long skip, int cached);
-void omap_sram_reset(void);
-
-extern void *omap_sram_push(void *funcp, unsigned long size);
diff --git a/arch/arm/plat-omap/sram.c b/arch/arm/plat-omap/sram.c
deleted file mode 100644 (file)
index 0f1eaca..0000000
+++ /dev/null
@@ -1,129 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0-only
-/*
- * linux/arch/arm/plat-omap/sram.c
- *
- * OMAP SRAM detection and management
- *
- * Copyright (C) 2005 Nokia Corporation
- * Written by Tony Lindgren <tony@atomide.com>
- *
- * Copyright (C) 2009-2012 Texas Instruments
- * Added OMAP4/5 support - Santosh Shilimkar <santosh.shilimkar@ti.com>
- */
-#undef DEBUG
-
-#include <linux/module.h>
-#include <linux/kernel.h>
-#include <linux/init.h>
-#include <linux/io.h>
-
-#include <asm/fncpy.h>
-#include <asm/tlb.h>
-#include <asm/cacheflush.h>
-#include <asm/set_memory.h>
-
-#include <asm/mach/map.h>
-
-#include <plat/sram.h>
-
-#define ROUND_DOWN(value,boundary)     ((value) & (~((boundary)-1)))
-
-static void __iomem *omap_sram_base;
-static unsigned long omap_sram_skip;
-static unsigned long omap_sram_size;
-static void __iomem *omap_sram_ceil;
-
-/*
- * Memory allocator for SRAM: calculates the new ceiling address
- * for pushing a function using the fncpy API.
- *
- * Note that fncpy requires the returned address to be aligned
- * to an 8-byte boundary.
- */
-static void *omap_sram_push_address(unsigned long size)
-{
-       unsigned long available, new_ceil = (unsigned long)omap_sram_ceil;
-
-       available = omap_sram_ceil - (omap_sram_base + omap_sram_skip);
-
-       if (size > available) {
-               pr_err("Not enough space in SRAM\n");
-               return NULL;
-       }
-
-       new_ceil -= size;
-       new_ceil = ROUND_DOWN(new_ceil, FNCPY_ALIGN);
-       omap_sram_ceil = IOMEM(new_ceil);
-
-       return (void *)omap_sram_ceil;
-}
-
-void *omap_sram_push(void *funcp, unsigned long size)
-{
-       void *sram;
-       unsigned long base;
-       int pages;
-       void *dst = NULL;
-
-       sram = omap_sram_push_address(size);
-       if (!sram)
-               return NULL;
-
-       base = (unsigned long)sram & PAGE_MASK;
-       pages = PAGE_ALIGN(size) / PAGE_SIZE;
-
-       set_memory_rw(base, pages);
-
-       dst = fncpy(sram, funcp, size);
-
-       set_memory_ro(base, pages);
-       set_memory_x(base, pages);
-
-       return dst;
-}
-
-/*
- * The SRAM context is lost during off-idle and stack
- * needs to be reset.
- */
-void omap_sram_reset(void)
-{
-       omap_sram_ceil = omap_sram_base + omap_sram_size;
-}
-
-/*
- * Note that we cannot use ioremap for SRAM, as clock init needs SRAM early.
- */
-void __init omap_map_sram(unsigned long start, unsigned long size,
-                                unsigned long skip, int cached)
-{
-       unsigned long base;
-       int pages;
-
-       if (size == 0)
-               return;
-
-       start = ROUND_DOWN(start, PAGE_SIZE);
-       omap_sram_size = size;
-       omap_sram_skip = skip;
-       omap_sram_base = __arm_ioremap_exec(start, size, cached);
-       if (!omap_sram_base) {
-               pr_err("SRAM: Could not map\n");
-               return;
-       }
-
-       omap_sram_reset();
-
-       /*
-        * Looks like we need to preserve some bootloader code at the
-        * beginning of SRAM for jumping to flash for reboot to work...
-        */
-       memset_io(omap_sram_base + omap_sram_skip, 0,
-                 omap_sram_size - omap_sram_skip);
-
-       base = (unsigned long)omap_sram_base;
-       pages = PAGE_ALIGN(omap_sram_size) / PAGE_SIZE;
-
-       set_memory_ro(base, pages);
-       set_memory_x(base, pages);
-}