sram.c 11 KB

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