sram.c 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  1. /*
  2. * linux/arch/arm/plat-omap/sram.c
  3. *
  4. * OMAP SRAM detection and management
  5. *
  6. * Copyright (C) 2005 Nokia Corporation
  7. * Written by Tony Lindgren <tony@atomide.com>
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License version 2 as
  11. * published by the Free Software Foundation.
  12. */
  13. #include <linux/module.h>
  14. #include <linux/kernel.h>
  15. #include <linux/init.h>
  16. #include <asm/tlb.h>
  17. #include <asm/io.h>
  18. #include <asm/cacheflush.h>
  19. #include <asm/mach/map.h>
  20. #include <asm/arch/sram.h>
  21. #include <asm/arch/board.h>
  22. #define OMAP1_SRAM_PA 0x20000000
  23. #define OMAP1_SRAM_VA 0xd0000000
  24. #define OMAP2_SRAM_PA 0x40200000
  25. #define OMAP2_SRAM_PUB_PA 0x4020f800
  26. #define OMAP2_SRAM_VA 0xd0000000
  27. #define OMAP2_SRAM_PUB_VA 0xd0000800
  28. #if defined(CONFIG_ARCH_OMAP24XX)
  29. #define SRAM_BOOTLOADER_SZ 0x00
  30. #else
  31. #define SRAM_BOOTLOADER_SZ 0x80
  32. #endif
  33. #define VA_REQINFOPERM0 IO_ADDRESS(0x68005048)
  34. #define VA_READPERM0 IO_ADDRESS(0x68005050)
  35. #define VA_WRITEPERM0 IO_ADDRESS(0x68005058)
  36. #define VA_CONTROL_STAT IO_ADDRESS(0x480002F8)
  37. #define GP_DEVICE 0x300
  38. #define TYPE_MASK 0x700
  39. #define ROUND_DOWN(value,boundary) ((value) & (~((boundary)-1)))
  40. static unsigned long omap_sram_start;
  41. static unsigned long omap_sram_base;
  42. static unsigned long omap_sram_size;
  43. static unsigned long omap_sram_ceil;
  44. extern unsigned long omapfb_reserve_sram(unsigned long sram_pstart,
  45. unsigned long sram_vstart,
  46. unsigned long sram_size,
  47. unsigned long pstart_avail,
  48. unsigned long size_avail);
  49. /*
  50. * Depending on the target RAMFS firewall setup, the public usable amount of
  51. * SRAM varies. The default accessible size for all device types is 2k. A GP
  52. * device allows ARM11 but not other initiators for full size. This
  53. * functionality seems ok until some nice security API happens.
  54. */
  55. static int is_sram_locked(void)
  56. {
  57. int type = 0;
  58. if (cpu_is_omap242x())
  59. type = __raw_readl(VA_CONTROL_STAT) & TYPE_MASK;
  60. if (type == GP_DEVICE) {
  61. /* RAMFW: R/W access to all initiators for all qualifier sets */
  62. if (cpu_is_omap242x()) {
  63. __raw_writel(0xFF, VA_REQINFOPERM0); /* all q-vects */
  64. __raw_writel(0xCFDE, VA_READPERM0); /* all i-read */
  65. __raw_writel(0xCFDE, VA_WRITEPERM0); /* all i-write */
  66. }
  67. return 0;
  68. } else
  69. return 1; /* assume locked with no PPA or security driver */
  70. }
  71. /*
  72. * The amount of SRAM depends on the core type.
  73. * Note that we cannot try to test for SRAM here because writes
  74. * to secure SRAM will hang the system. Also the SRAM is not
  75. * yet mapped at this point.
  76. */
  77. void __init omap_detect_sram(void)
  78. {
  79. unsigned long reserved;
  80. if (cpu_is_omap24xx()) {
  81. if (is_sram_locked()) {
  82. omap_sram_base = OMAP2_SRAM_PUB_VA;
  83. omap_sram_start = OMAP2_SRAM_PUB_PA;
  84. omap_sram_size = 0x800; /* 2K */
  85. } else {
  86. omap_sram_base = OMAP2_SRAM_VA;
  87. omap_sram_start = OMAP2_SRAM_PA;
  88. if (cpu_is_omap242x())
  89. omap_sram_size = 0xa0000; /* 640K */
  90. else if (cpu_is_omap243x())
  91. omap_sram_size = 0x10000; /* 64K */
  92. }
  93. } else {
  94. omap_sram_base = OMAP1_SRAM_VA;
  95. omap_sram_start = OMAP1_SRAM_PA;
  96. if (cpu_is_omap730())
  97. omap_sram_size = 0x32000; /* 200K */
  98. else if (cpu_is_omap15xx())
  99. omap_sram_size = 0x30000; /* 192K */
  100. else if (cpu_is_omap1610() || cpu_is_omap1621() ||
  101. cpu_is_omap1710())
  102. omap_sram_size = 0x4000; /* 16K */
  103. else if (cpu_is_omap1611())
  104. omap_sram_size = 0x3e800; /* 250K */
  105. else {
  106. printk(KERN_ERR "Could not detect SRAM size\n");
  107. omap_sram_size = 0x4000;
  108. }
  109. }
  110. reserved = omapfb_reserve_sram(omap_sram_start, omap_sram_base,
  111. omap_sram_size,
  112. omap_sram_start + SRAM_BOOTLOADER_SZ,
  113. omap_sram_size - SRAM_BOOTLOADER_SZ);
  114. omap_sram_size -= reserved;
  115. omap_sram_ceil = omap_sram_base + omap_sram_size;
  116. }
  117. static struct map_desc omap_sram_io_desc[] __initdata = {
  118. { /* .length gets filled in at runtime */
  119. .virtual = OMAP1_SRAM_VA,
  120. .pfn = __phys_to_pfn(OMAP1_SRAM_PA),
  121. .type = MT_MEMORY
  122. }
  123. };
  124. /*
  125. * Note that we cannot use ioremap for SRAM, as clock init needs SRAM early.
  126. */
  127. void __init omap_map_sram(void)
  128. {
  129. unsigned long base;
  130. if (omap_sram_size == 0)
  131. return;
  132. if (cpu_is_omap24xx()) {
  133. omap_sram_io_desc[0].virtual = OMAP2_SRAM_VA;
  134. base = OMAP2_SRAM_PA;
  135. base = ROUND_DOWN(base, PAGE_SIZE);
  136. omap_sram_io_desc[0].pfn = __phys_to_pfn(base);
  137. }
  138. omap_sram_io_desc[0].length = 1024 * 1024; /* Use section desc */
  139. iotable_init(omap_sram_io_desc, ARRAY_SIZE(omap_sram_io_desc));
  140. printk(KERN_INFO "SRAM: Mapped pa 0x%08lx to va 0x%08lx size: 0x%lx\n",
  141. __pfn_to_phys(omap_sram_io_desc[0].pfn),
  142. omap_sram_io_desc[0].virtual,
  143. omap_sram_io_desc[0].length);
  144. /*
  145. * Normally devicemaps_init() would flush caches and tlb after
  146. * mdesc->map_io(), but since we're called from map_io(), we
  147. * must do it here.
  148. */
  149. local_flush_tlb_all();
  150. flush_cache_all();
  151. /*
  152. * Looks like we need to preserve some bootloader code at the
  153. * beginning of SRAM for jumping to flash for reboot to work...
  154. */
  155. memset((void *)omap_sram_base + SRAM_BOOTLOADER_SZ, 0,
  156. omap_sram_size - SRAM_BOOTLOADER_SZ);
  157. }
  158. void * omap_sram_push(void * start, unsigned long size)
  159. {
  160. if (size > (omap_sram_ceil - (omap_sram_base + SRAM_BOOTLOADER_SZ))) {
  161. printk(KERN_ERR "Not enough space in SRAM\n");
  162. return NULL;
  163. }
  164. omap_sram_ceil -= size;
  165. omap_sram_ceil = ROUND_DOWN(omap_sram_ceil, sizeof(void *));
  166. memcpy((void *)omap_sram_ceil, start, size);
  167. return (void *)omap_sram_ceil;
  168. }
  169. static void omap_sram_error(void)
  170. {
  171. panic("Uninitialized SRAM function\n");
  172. }
  173. #ifdef CONFIG_ARCH_OMAP1
  174. static void (*_omap_sram_reprogram_clock)(u32 dpllctl, u32 ckctl);
  175. void omap_sram_reprogram_clock(u32 dpllctl, u32 ckctl)
  176. {
  177. if (!_omap_sram_reprogram_clock)
  178. omap_sram_error();
  179. return _omap_sram_reprogram_clock(dpllctl, ckctl);
  180. }
  181. int __init omap1_sram_init(void)
  182. {
  183. _omap_sram_reprogram_clock = omap_sram_push(sram_reprogram_clock,
  184. sram_reprogram_clock_sz);
  185. return 0;
  186. }
  187. #else
  188. #define omap1_sram_init() do {} while (0)
  189. #endif
  190. #ifdef CONFIG_ARCH_OMAP2
  191. static void (*_omap2_sram_ddr_init)(u32 *slow_dll_ctrl, u32 fast_dll_ctrl,
  192. u32 base_cs, u32 force_unlock);
  193. void omap2_sram_ddr_init(u32 *slow_dll_ctrl, u32 fast_dll_ctrl,
  194. u32 base_cs, u32 force_unlock)
  195. {
  196. if (!_omap2_sram_ddr_init)
  197. omap_sram_error();
  198. return _omap2_sram_ddr_init(slow_dll_ctrl, fast_dll_ctrl,
  199. base_cs, force_unlock);
  200. }
  201. static void (*_omap2_sram_reprogram_sdrc)(u32 perf_level, u32 dll_val,
  202. u32 mem_type);
  203. void omap2_sram_reprogram_sdrc(u32 perf_level, u32 dll_val, u32 mem_type)
  204. {
  205. if (!_omap2_sram_reprogram_sdrc)
  206. omap_sram_error();
  207. return _omap2_sram_reprogram_sdrc(perf_level, dll_val, mem_type);
  208. }
  209. static u32 (*_omap2_set_prcm)(u32 dpll_ctrl_val, u32 sdrc_rfr_val, int bypass);
  210. u32 omap2_set_prcm(u32 dpll_ctrl_val, u32 sdrc_rfr_val, int bypass)
  211. {
  212. if (!_omap2_set_prcm)
  213. omap_sram_error();
  214. return _omap2_set_prcm(dpll_ctrl_val, sdrc_rfr_val, bypass);
  215. }
  216. int __init omap2_sram_init(void)
  217. {
  218. _omap2_sram_ddr_init = omap_sram_push(sram_ddr_init, sram_ddr_init_sz);
  219. _omap2_sram_reprogram_sdrc = omap_sram_push(sram_reprogram_sdrc,
  220. sram_reprogram_sdrc_sz);
  221. _omap2_set_prcm = omap_sram_push(sram_set_prcm, sram_set_prcm_sz);
  222. return 0;
  223. }
  224. #else
  225. #define omap2_sram_init() do {} while (0)
  226. #endif
  227. int __init omap_sram_init(void)
  228. {
  229. omap_detect_sram();
  230. omap_map_sram();
  231. if (!cpu_is_omap24xx())
  232. omap1_sram_init();
  233. else
  234. omap2_sram_init();
  235. return 0;
  236. }