sram.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406
  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. #undef DEBUG
  14. #include <linux/module.h>
  15. #include <linux/kernel.h>
  16. #include <linux/init.h>
  17. #include <linux/io.h>
  18. #include <asm/tlb.h>
  19. #include <asm/cacheflush.h>
  20. #include <asm/mach/map.h>
  21. #include <mach/sram.h>
  22. #include <mach/board.h>
  23. #include <mach/cpu.h>
  24. #include <mach/control.h>
  25. #if defined(CONFIG_ARCH_OMAP2) || defined(CONFIG_ARCH_OMAP3)
  26. # include "../mach-omap2/prm.h"
  27. # include "../mach-omap2/cm.h"
  28. # include "../mach-omap2/sdrc.h"
  29. #endif
  30. #define OMAP1_SRAM_PA 0x20000000
  31. #define OMAP1_SRAM_VA VMALLOC_END
  32. #define OMAP2_SRAM_PA 0x40200000
  33. #define OMAP2_SRAM_PUB_PA 0x4020f800
  34. #define OMAP2_SRAM_VA VMALLOC_END
  35. #define OMAP2_SRAM_PUB_VA (VMALLOC_END + 0x800)
  36. #define OMAP3_SRAM_PA 0x40200000
  37. #define OMAP3_SRAM_VA 0xd7000000
  38. #define OMAP3_SRAM_PUB_PA 0x40208000
  39. #define OMAP3_SRAM_PUB_VA 0xd7008000
  40. #if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
  41. #define SRAM_BOOTLOADER_SZ 0x00
  42. #else
  43. #define SRAM_BOOTLOADER_SZ 0x80
  44. #endif
  45. #define OMAP24XX_VA_REQINFOPERM0 IO_ADDRESS(0x68005048)
  46. #define OMAP24XX_VA_READPERM0 IO_ADDRESS(0x68005050)
  47. #define OMAP24XX_VA_WRITEPERM0 IO_ADDRESS(0x68005058)
  48. #define OMAP34XX_VA_REQINFOPERM0 IO_ADDRESS(0x68012848)
  49. #define OMAP34XX_VA_READPERM0 IO_ADDRESS(0x68012850)
  50. #define OMAP34XX_VA_WRITEPERM0 IO_ADDRESS(0x68012858)
  51. #define OMAP34XX_VA_ADDR_MATCH2 IO_ADDRESS(0x68012880)
  52. #define OMAP34XX_VA_SMS_RG_ATT0 IO_ADDRESS(0x6C000048)
  53. #define OMAP34XX_VA_CONTROL_STAT IO_ADDRESS(0x480022F0)
  54. #define GP_DEVICE 0x300
  55. #define ROUND_DOWN(value,boundary) ((value) & (~((boundary)-1)))
  56. static unsigned long omap_sram_start;
  57. static unsigned long omap_sram_base;
  58. static unsigned long omap_sram_size;
  59. static unsigned long omap_sram_ceil;
  60. extern unsigned long omapfb_reserve_sram(unsigned long sram_pstart,
  61. unsigned long sram_vstart,
  62. unsigned long sram_size,
  63. unsigned long pstart_avail,
  64. unsigned long size_avail);
  65. /*
  66. * Depending on the target RAMFS firewall setup, the public usable amount of
  67. * SRAM varies. The default accessible size for all device types is 2k. A GP
  68. * device allows ARM11 but not other initiators for full size. This
  69. * functionality seems ok until some nice security API happens.
  70. */
  71. static int is_sram_locked(void)
  72. {
  73. int type = 0;
  74. if (cpu_is_omap242x())
  75. type = omap_rev() & OMAP2_DEVICETYPE_MASK;
  76. if (type == GP_DEVICE) {
  77. /* RAMFW: R/W access to all initiators for all qualifier sets */
  78. if (cpu_is_omap242x()) {
  79. __raw_writel(0xFF, OMAP24XX_VA_REQINFOPERM0); /* all q-vects */
  80. __raw_writel(0xCFDE, OMAP24XX_VA_READPERM0); /* all i-read */
  81. __raw_writel(0xCFDE, OMAP24XX_VA_WRITEPERM0); /* all i-write */
  82. }
  83. if (cpu_is_omap34xx()) {
  84. __raw_writel(0xFFFF, OMAP34XX_VA_REQINFOPERM0); /* all q-vects */
  85. __raw_writel(0xFFFF, OMAP34XX_VA_READPERM0); /* all i-read */
  86. __raw_writel(0xFFFF, OMAP34XX_VA_WRITEPERM0); /* all i-write */
  87. __raw_writel(0x0, OMAP34XX_VA_ADDR_MATCH2);
  88. __raw_writel(0xFFFFFFFF, OMAP34XX_VA_SMS_RG_ATT0);
  89. }
  90. return 0;
  91. } else
  92. return 1; /* assume locked with no PPA or security driver */
  93. }
  94. /*
  95. * The amount of SRAM depends on the core type.
  96. * Note that we cannot try to test for SRAM here because writes
  97. * to secure SRAM will hang the system. Also the SRAM is not
  98. * yet mapped at this point.
  99. */
  100. void __init omap_detect_sram(void)
  101. {
  102. unsigned long reserved;
  103. if (cpu_class_is_omap2()) {
  104. if (is_sram_locked()) {
  105. if (cpu_is_omap34xx()) {
  106. omap_sram_base = OMAP3_SRAM_PUB_VA;
  107. omap_sram_start = OMAP3_SRAM_PUB_PA;
  108. omap_sram_size = 0x8000; /* 32K */
  109. } else {
  110. omap_sram_base = OMAP2_SRAM_PUB_VA;
  111. omap_sram_start = OMAP2_SRAM_PUB_PA;
  112. omap_sram_size = 0x800; /* 2K */
  113. }
  114. } else {
  115. if (cpu_is_omap34xx()) {
  116. omap_sram_base = OMAP3_SRAM_VA;
  117. omap_sram_start = OMAP3_SRAM_PA;
  118. omap_sram_size = 0x10000; /* 64K */
  119. } else {
  120. omap_sram_base = OMAP2_SRAM_VA;
  121. omap_sram_start = OMAP2_SRAM_PA;
  122. if (cpu_is_omap242x())
  123. omap_sram_size = 0xa0000; /* 640K */
  124. else if (cpu_is_omap243x())
  125. omap_sram_size = 0x10000; /* 64K */
  126. }
  127. }
  128. } else {
  129. omap_sram_base = OMAP1_SRAM_VA;
  130. omap_sram_start = OMAP1_SRAM_PA;
  131. if (cpu_is_omap7xx())
  132. omap_sram_size = 0x32000; /* 200K */
  133. else if (cpu_is_omap15xx())
  134. omap_sram_size = 0x30000; /* 192K */
  135. else if (cpu_is_omap1610() || cpu_is_omap1621() ||
  136. cpu_is_omap1710())
  137. omap_sram_size = 0x4000; /* 16K */
  138. else if (cpu_is_omap1611())
  139. omap_sram_size = 0x3e800; /* 250K */
  140. else {
  141. printk(KERN_ERR "Could not detect SRAM size\n");
  142. omap_sram_size = 0x4000;
  143. }
  144. }
  145. reserved = omapfb_reserve_sram(omap_sram_start, omap_sram_base,
  146. omap_sram_size,
  147. omap_sram_start + SRAM_BOOTLOADER_SZ,
  148. omap_sram_size - SRAM_BOOTLOADER_SZ);
  149. omap_sram_size -= reserved;
  150. omap_sram_ceil = omap_sram_base + omap_sram_size;
  151. }
  152. static struct map_desc omap_sram_io_desc[] __initdata = {
  153. { /* .length gets filled in at runtime */
  154. .virtual = OMAP1_SRAM_VA,
  155. .pfn = __phys_to_pfn(OMAP1_SRAM_PA),
  156. .type = MT_MEMORY
  157. }
  158. };
  159. /*
  160. * Note that we cannot use ioremap for SRAM, as clock init needs SRAM early.
  161. */
  162. void __init omap_map_sram(void)
  163. {
  164. unsigned long base;
  165. if (omap_sram_size == 0)
  166. return;
  167. if (cpu_is_omap24xx()) {
  168. omap_sram_io_desc[0].virtual = OMAP2_SRAM_VA;
  169. base = OMAP2_SRAM_PA;
  170. base = ROUND_DOWN(base, PAGE_SIZE);
  171. omap_sram_io_desc[0].pfn = __phys_to_pfn(base);
  172. }
  173. if (cpu_is_omap34xx()) {
  174. omap_sram_io_desc[0].virtual = OMAP3_SRAM_VA;
  175. base = OMAP3_SRAM_PA;
  176. base = ROUND_DOWN(base, PAGE_SIZE);
  177. omap_sram_io_desc[0].pfn = __phys_to_pfn(base);
  178. /*
  179. * SRAM must be marked as non-cached on OMAP3 since the
  180. * CORE DPLL M2 divider change code (in SRAM) runs with the
  181. * SDRAM controller disabled, and if it is marked cached,
  182. * the ARM may attempt to write cache lines back to SDRAM
  183. * which will cause the system to hang.
  184. */
  185. omap_sram_io_desc[0].type = MT_MEMORY_NONCACHED;
  186. }
  187. omap_sram_io_desc[0].length = 1024 * 1024; /* Use section desc */
  188. iotable_init(omap_sram_io_desc, ARRAY_SIZE(omap_sram_io_desc));
  189. printk(KERN_INFO "SRAM: Mapped pa 0x%08lx to va 0x%08lx size: 0x%lx\n",
  190. __pfn_to_phys(omap_sram_io_desc[0].pfn),
  191. omap_sram_io_desc[0].virtual,
  192. omap_sram_io_desc[0].length);
  193. /*
  194. * Normally devicemaps_init() would flush caches and tlb after
  195. * mdesc->map_io(), but since we're called from map_io(), we
  196. * must do it here.
  197. */
  198. local_flush_tlb_all();
  199. flush_cache_all();
  200. /*
  201. * Looks like we need to preserve some bootloader code at the
  202. * beginning of SRAM for jumping to flash for reboot to work...
  203. */
  204. memset((void *)omap_sram_base + SRAM_BOOTLOADER_SZ, 0,
  205. omap_sram_size - SRAM_BOOTLOADER_SZ);
  206. }
  207. void * omap_sram_push(void * start, unsigned long size)
  208. {
  209. if (size > (omap_sram_ceil - (omap_sram_base + SRAM_BOOTLOADER_SZ))) {
  210. printk(KERN_ERR "Not enough space in SRAM\n");
  211. return NULL;
  212. }
  213. omap_sram_ceil -= size;
  214. omap_sram_ceil = ROUND_DOWN(omap_sram_ceil, sizeof(void *));
  215. memcpy((void *)omap_sram_ceil, start, size);
  216. flush_icache_range((unsigned long)start, (unsigned long)(start + size));
  217. return (void *)omap_sram_ceil;
  218. }
  219. #ifdef CONFIG_ARCH_OMAP1
  220. static void (*_omap_sram_reprogram_clock)(u32 dpllctl, u32 ckctl);
  221. void omap_sram_reprogram_clock(u32 dpllctl, u32 ckctl)
  222. {
  223. BUG_ON(!_omap_sram_reprogram_clock);
  224. _omap_sram_reprogram_clock(dpllctl, ckctl);
  225. }
  226. int __init omap1_sram_init(void)
  227. {
  228. _omap_sram_reprogram_clock =
  229. omap_sram_push(omap1_sram_reprogram_clock,
  230. omap1_sram_reprogram_clock_sz);
  231. return 0;
  232. }
  233. #else
  234. #define omap1_sram_init() do {} while (0)
  235. #endif
  236. #if defined(CONFIG_ARCH_OMAP2)
  237. static void (*_omap2_sram_ddr_init)(u32 *slow_dll_ctrl, u32 fast_dll_ctrl,
  238. u32 base_cs, u32 force_unlock);
  239. void omap2_sram_ddr_init(u32 *slow_dll_ctrl, u32 fast_dll_ctrl,
  240. u32 base_cs, u32 force_unlock)
  241. {
  242. BUG_ON(!_omap2_sram_ddr_init);
  243. _omap2_sram_ddr_init(slow_dll_ctrl, fast_dll_ctrl,
  244. base_cs, force_unlock);
  245. }
  246. static void (*_omap2_sram_reprogram_sdrc)(u32 perf_level, u32 dll_val,
  247. u32 mem_type);
  248. void omap2_sram_reprogram_sdrc(u32 perf_level, u32 dll_val, u32 mem_type)
  249. {
  250. BUG_ON(!_omap2_sram_reprogram_sdrc);
  251. _omap2_sram_reprogram_sdrc(perf_level, dll_val, mem_type);
  252. }
  253. static u32 (*_omap2_set_prcm)(u32 dpll_ctrl_val, u32 sdrc_rfr_val, int bypass);
  254. u32 omap2_set_prcm(u32 dpll_ctrl_val, u32 sdrc_rfr_val, int bypass)
  255. {
  256. BUG_ON(!_omap2_set_prcm);
  257. return _omap2_set_prcm(dpll_ctrl_val, sdrc_rfr_val, bypass);
  258. }
  259. #endif
  260. #ifdef CONFIG_ARCH_OMAP2420
  261. int __init omap242x_sram_init(void)
  262. {
  263. _omap2_sram_ddr_init = omap_sram_push(omap242x_sram_ddr_init,
  264. omap242x_sram_ddr_init_sz);
  265. _omap2_sram_reprogram_sdrc = omap_sram_push(omap242x_sram_reprogram_sdrc,
  266. omap242x_sram_reprogram_sdrc_sz);
  267. _omap2_set_prcm = omap_sram_push(omap242x_sram_set_prcm,
  268. omap242x_sram_set_prcm_sz);
  269. return 0;
  270. }
  271. #else
  272. static inline int omap242x_sram_init(void)
  273. {
  274. return 0;
  275. }
  276. #endif
  277. #ifdef CONFIG_ARCH_OMAP2430
  278. int __init omap243x_sram_init(void)
  279. {
  280. _omap2_sram_ddr_init = omap_sram_push(omap243x_sram_ddr_init,
  281. omap243x_sram_ddr_init_sz);
  282. _omap2_sram_reprogram_sdrc = omap_sram_push(omap243x_sram_reprogram_sdrc,
  283. omap243x_sram_reprogram_sdrc_sz);
  284. _omap2_set_prcm = omap_sram_push(omap243x_sram_set_prcm,
  285. omap243x_sram_set_prcm_sz);
  286. return 0;
  287. }
  288. #else
  289. static inline int omap243x_sram_init(void)
  290. {
  291. return 0;
  292. }
  293. #endif
  294. #ifdef CONFIG_ARCH_OMAP3
  295. static u32 (*_omap3_sram_configure_core_dpll)(u32 sdrc_rfr_ctrl,
  296. u32 sdrc_actim_ctrla,
  297. u32 sdrc_actim_ctrlb,
  298. u32 m2, u32 unlock_dll);
  299. u32 omap3_configure_core_dpll(u32 sdrc_rfr_ctrl, u32 sdrc_actim_ctrla,
  300. u32 sdrc_actim_ctrlb, u32 m2, u32 unlock_dll)
  301. {
  302. BUG_ON(!_omap3_sram_configure_core_dpll);
  303. return _omap3_sram_configure_core_dpll(sdrc_rfr_ctrl,
  304. sdrc_actim_ctrla,
  305. sdrc_actim_ctrlb, m2,
  306. unlock_dll);
  307. }
  308. /* REVISIT: Should this be same as omap34xx_sram_init() after off-idle? */
  309. void restore_sram_functions(void)
  310. {
  311. omap_sram_ceil = omap_sram_base + omap_sram_size;
  312. _omap3_sram_configure_core_dpll =
  313. omap_sram_push(omap3_sram_configure_core_dpll,
  314. omap3_sram_configure_core_dpll_sz);
  315. }
  316. int __init omap34xx_sram_init(void)
  317. {
  318. _omap3_sram_configure_core_dpll =
  319. omap_sram_push(omap3_sram_configure_core_dpll,
  320. omap3_sram_configure_core_dpll_sz);
  321. return 0;
  322. }
  323. #else
  324. static inline int omap34xx_sram_init(void)
  325. {
  326. return 0;
  327. }
  328. #endif
  329. int __init omap_sram_init(void)
  330. {
  331. omap_detect_sram();
  332. omap_map_sram();
  333. if (!(cpu_class_is_omap2()))
  334. omap1_sram_init();
  335. else if (cpu_is_omap242x())
  336. omap242x_sram_init();
  337. else if (cpu_is_omap2430())
  338. omap243x_sram_init();
  339. else if (cpu_is_omap34xx())
  340. omap34xx_sram_init();
  341. return 0;
  342. }