sram.c 13 KB

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