sram.c 8.0 KB

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