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>
26 #include <asm/set_memory.h>
28 #include <asm/mach/map.h>
30 #include <plat/sram.h>
32 #define ROUND_DOWN(value,boundary) ((value) & (~((boundary)-1)))
34 static void __iomem
*omap_sram_base
;
35 static unsigned long omap_sram_skip
;
36 static unsigned long omap_sram_size
;
37 static void __iomem
*omap_sram_ceil
;
40 * Memory allocator for SRAM: calculates the new ceiling address
41 * for pushing a function using the fncpy API.
43 * Note that fncpy requires the returned address to be aligned
44 * to an 8-byte boundary.
46 static void *omap_sram_push_address(unsigned long size
)
48 unsigned long available
, new_ceil
= (unsigned long)omap_sram_ceil
;
50 available
= omap_sram_ceil
- (omap_sram_base
+ omap_sram_skip
);
52 if (size
> available
) {
53 pr_err("Not enough space in SRAM\n");
58 new_ceil
= ROUND_DOWN(new_ceil
, FNCPY_ALIGN
);
59 omap_sram_ceil
= IOMEM(new_ceil
);
61 return (void *)omap_sram_ceil
;
64 void *omap_sram_push(void *funcp
, unsigned long size
)
71 sram
= omap_sram_push_address(size
);
75 base
= (unsigned long)sram
& PAGE_MASK
;
76 pages
= PAGE_ALIGN(size
) / PAGE_SIZE
;
78 set_memory_rw(base
, pages
);
80 dst
= fncpy(sram
, funcp
, size
);
82 set_memory_ro(base
, pages
);
83 set_memory_x(base
, pages
);
89 * The SRAM context is lost during off-idle and stack
92 void omap_sram_reset(void)
94 omap_sram_ceil
= omap_sram_base
+ omap_sram_size
;
98 * Note that we cannot use ioremap for SRAM, as clock init needs SRAM early.
100 void __init
omap_map_sram(unsigned long start
, unsigned long size
,
101 unsigned long skip
, int cached
)
109 start
= ROUND_DOWN(start
, PAGE_SIZE
);
110 omap_sram_size
= size
;
111 omap_sram_skip
= skip
;
112 omap_sram_base
= __arm_ioremap_exec(start
, size
, cached
);
113 if (!omap_sram_base
) {
114 pr_err("SRAM: Could not map\n");
121 * Looks like we need to preserve some bootloader code at the
122 * beginning of SRAM for jumping to flash for reboot to work...
124 memset_io(omap_sram_base
+ omap_sram_skip
, 0,
125 omap_sram_size
- omap_sram_skip
);
127 base
= (unsigned long)omap_sram_base
;
128 pages
= PAGE_ALIGN(omap_sram_size
) / PAGE_SIZE
;
130 set_memory_ro(base
, pages
);
131 set_memory_x(base
, pages
);