2 * linux/arch/arm/plat-omap/sram.c
4 * OMAP SRAM detection and management
6 * Copyright (C) 2005 Nokia Corporation
7 * Written by Tony Lindgren <tony@atomide.com>
9 * Copyright (C) 2009-2012 Texas Instruments
10 * Added OMAP4/5 support - Santosh Shilimkar <santosh.shilimkar@ti.com>
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License version 2 as
14 * published by the Free Software Foundation.
18 #include <linux/module.h>
19 #include <linux/kernel.h>
20 #include <linux/init.h>
23 #include <asm/fncpy.h>
25 #include <asm/cacheflush.h>
27 #include <asm/mach/map.h>
29 #define ROUND_DOWN(value,boundary) ((value) & (~((boundary)-1)))
31 static void __iomem *omap_sram_base;
32 static unsigned long omap_sram_skip;
33 static unsigned long omap_sram_size;
34 static void __iomem *omap_sram_ceil;
37 * Memory allocator for SRAM: calculates the new ceiling address
38 * for pushing a function using the fncpy API.
40 * Note that fncpy requires the returned address to be aligned
41 * to an 8-byte boundary.
43 void *omap_sram_push_address(unsigned long size)
45 unsigned long available, new_ceil = (unsigned long)omap_sram_ceil;
47 available = omap_sram_ceil - (omap_sram_base + omap_sram_skip);
49 if (size > available) {
50 pr_err("Not enough space in SRAM\n");
55 new_ceil = ROUND_DOWN(new_ceil, FNCPY_ALIGN);
56 omap_sram_ceil = IOMEM(new_ceil);
58 return (void *)omap_sram_ceil;
62 * The SRAM context is lost during off-idle and stack
65 void omap_sram_reset(void)
67 omap_sram_ceil = omap_sram_base + omap_sram_size;
71 * Note that we cannot use ioremap for SRAM, as clock init needs SRAM early.
73 void __init omap_map_sram(unsigned long start, unsigned long size,
74 unsigned long skip, int cached)
79 start = ROUND_DOWN(start, PAGE_SIZE);
80 omap_sram_size = size;
81 omap_sram_skip = skip;
82 omap_sram_base = __arm_ioremap_exec(start, size, cached);
83 if (!omap_sram_base) {
84 pr_err("SRAM: Could not map\n");
91 * Looks like we need to preserve some bootloader code at the
92 * beginning of SRAM for jumping to flash for reboot to work...
94 memset_io(omap_sram_base + omap_sram_skip, 0,
95 omap_sram_size - omap_sram_skip);