sram.c 7.8 KB

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