mm: fix exec activate_mm vs TLB shootdown and lazy tlb switching race
[linux/fpc-iii.git] / arch / arm / plat-omap / sram.c
blob921840acf65c83a5ac785ac5e514591a404a8a46
1 /*
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.
16 #undef DEBUG
18 #include <linux/module.h>
19 #include <linux/kernel.h>
20 #include <linux/init.h>
21 #include <linux/io.h>
23 #include <asm/fncpy.h>
24 #include <asm/tlb.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");
54 return NULL;
57 new_ceil -= size;
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)
66 void *sram;
67 unsigned long base;
68 int pages;
69 void *dst = NULL;
71 sram = omap_sram_push_address(size);
72 if (!sram)
73 return NULL;
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);
85 return dst;
89 * The SRAM context is lost during off-idle and stack
90 * needs to be reset.
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)
103 unsigned long base;
104 int pages;
106 if (size == 0)
107 return;
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");
115 return;
118 omap_sram_reset();
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);