rk: mem: protect memory region that specified by uboot on kernel booting
authorCMY <cmy@rock-chips.com>
Thu, 11 Dec 2014 04:58:09 +0000 (12:58 +0800)
committerCMY <cmy@rock-chips.com>
Thu, 11 Dec 2014 04:59:21 +0000 (12:59 +0800)
arch/arm/mach-rockchip/common.c
arch/arm/mach-rockchip/rk312x.c
arch/arm/mach-rockchip/rk3288.c
include/linux/rockchip/common.h

index 9ee976af9b7e9d7c27f3a3f3d4e3be0c67e29d2d..e2fa463f8c56a1ce065b94ac8dbd93ba5f8a5c22 100755 (executable)
@@ -24,6 +24,7 @@
 #include <asm/hardware/cache-l2x0.h>
 #include <linux/rockchip/common.h>
 #include <linux/rockchip/pmu.h>
+#include <linux/memblock.h>
 #include "cpu_axi.h"
 #include "loader.h"
 #include "sram.h"
@@ -294,3 +295,62 @@ static int __init rockchip_jtag_enable(char *__unused)
        return 1;
 }
 __setup("rockchip_jtag", rockchip_jtag_enable);
+
+phys_addr_t uboot_logo_base=0;
+phys_addr_t uboot_logo_size=0;
+phys_addr_t uboot_logo_offset=0;
+
+void __init rockchip_uboot_mem_reserve(void)
+{
+       if (uboot_logo_size) {
+               if (!memblock_is_region_reserved(uboot_logo_base, uboot_logo_size)
+                       && !memblock_reserve(uboot_logo_base, uboot_logo_size)){
+                       pr_info("%s: reserve %zx@%zx for uboot logo\n", __func__,
+                               uboot_logo_size, uboot_logo_base);
+               } else {
+                       pr_err("%s: reserve of %zx@%zx failed\n", __func__,
+                              uboot_logo_size, uboot_logo_base);
+               }
+       }
+}
+
+static int __init rockchip_uboot_logo_setup(char *p)
+{
+       char *endp;
+
+       uboot_logo_size = memparse(p, &endp);
+       if (*endp == '@') {
+               uboot_logo_base = memparse(endp + 1, &endp);
+               if (*endp == ':') {
+                       uboot_logo_offset = memparse(endp + 1, NULL);
+               }
+       }
+
+       pr_info("%s: mem: %zx@%zx, offset:%zx\n", __func__,
+               uboot_logo_size, uboot_logo_base, uboot_logo_offset);
+
+       return 0;
+}
+early_param("uboot_logo", rockchip_uboot_logo_setup);
+
+static int __init rockchip_uboot_mem_late_init(void)
+{
+       phys_addr_t addr = 0;
+       phys_addr_t end = 0;
+
+       if (uboot_logo_size) {
+               addr = PAGE_ALIGN(uboot_logo_base);
+               end = (uboot_logo_base+uboot_logo_size)&PAGE_MASK;
+
+               pr_info("%s: Freeing uboot logo memory: %zx@%zx\n", __func__,
+                       uboot_logo_size, uboot_logo_base);
+
+               memblock_free(uboot_logo_base, uboot_logo_size);
+
+               for (; addr < end; addr += PAGE_SIZE)
+                       free_reserved_page(pfn_to_page(addr >> PAGE_SHIFT));
+       }
+
+       return 0;
+}
+late_initcall(rockchip_uboot_mem_late_init);
index 6ff7f52c9548162ac7add2be1ed3c9f7caf37a5c..aaef664d42f9509b8dc3e37dd71f36f5b8fa1c53 100755 (executable)
@@ -353,6 +353,9 @@ static void __init rk312x_dt_init_timer(void)
 
 static void __init rk312x_reserve(void)
 {
+       /* reserve memory for uboot */
+       rockchip_uboot_mem_reserve();
+
        /* reserve memory for ION */
        rockchip_ion_reserve();
 }
index 100327c3129d7aab25ef2866918a9c2bffe55340..d44709321c6235fcd2cc69093600ffd2a542663e 100755 (executable)
@@ -435,6 +435,9 @@ static void __init rk3288_dt_init_timer(void)
 
 static void __init rk3288_reserve(void)
 {
+       /* reserve memory for uboot */
+       rockchip_uboot_mem_reserve();
+
        /* reserve memory for ION */
        rockchip_ion_reserve();
 }
index cf51a1ce95c1b4d3bdcc4b95e8bf37deb4c01b78..282e25bdfbc05be21dd28eefc7e005c211def753 100644 (file)
@@ -58,6 +58,7 @@ void rockchip_restart_get_boot_mode(const char *cmd, u32 *flag, u32 *mode);
 void __init rockchip_efuse_init(void);
 void __init rockchip_suspend_init(void);
 void __init rockchip_ion_reserve(void);
+void __init rockchip_uboot_mem_reserve(void);
 
 enum rockchip_pm_policy {
        ROCKCHIP_PM_POLICY_PERFORMANCE = 0,