cplbinit.c 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433
  1. /*
  2. * Blackfin CPLB initialization
  3. *
  4. * Copyright 2004-2007 Analog Devices Inc.
  5. *
  6. * Bugs: Enter bugs at http://blackfin.uclinux.org/
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, see the file COPYING, or write
  20. * to the Free Software Foundation, Inc.,
  21. * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  22. */
  23. #include <linux/module.h>
  24. #include <asm/blackfin.h>
  25. #include <asm/cplbinit.h>
  26. u_long icplb_table[MAX_CPLBS+1];
  27. u_long dcplb_table[MAX_CPLBS+1];
  28. #ifdef CONFIG_CPLB_SWITCH_TAB_L1
  29. u_long ipdt_table[MAX_SWITCH_I_CPLBS+1]__attribute__((l1_data));
  30. u_long dpdt_table[MAX_SWITCH_D_CPLBS+1]__attribute__((l1_data));
  31. #ifdef CONFIG_CPLB_INFO
  32. u_long ipdt_swapcount_table[MAX_SWITCH_I_CPLBS]__attribute__((l1_data));
  33. u_long dpdt_swapcount_table[MAX_SWITCH_D_CPLBS]__attribute__((l1_data));
  34. #endif /* CONFIG_CPLB_INFO */
  35. #else
  36. u_long ipdt_table[MAX_SWITCH_I_CPLBS+1];
  37. u_long dpdt_table[MAX_SWITCH_D_CPLBS+1];
  38. #ifdef CONFIG_CPLB_INFO
  39. u_long ipdt_swapcount_table[MAX_SWITCH_I_CPLBS];
  40. u_long dpdt_swapcount_table[MAX_SWITCH_D_CPLBS];
  41. #endif /* CONFIG_CPLB_INFO */
  42. #endif /*CONFIG_CPLB_SWITCH_TAB_L1*/
  43. struct s_cplb {
  44. struct cplb_tab init_i;
  45. struct cplb_tab init_d;
  46. struct cplb_tab switch_i;
  47. struct cplb_tab switch_d;
  48. };
  49. #if defined(CONFIG_BLKFIN_DCACHE) || defined(CONFIG_BLKFIN_CACHE)
  50. static struct cplb_desc cplb_data[] = {
  51. {
  52. .start = 0,
  53. .end = SIZE_1K,
  54. .psize = SIZE_1K,
  55. .attr = INITIAL_T | SWITCH_T | I_CPLB | D_CPLB,
  56. .i_conf = SDRAM_OOPS,
  57. .d_conf = SDRAM_OOPS,
  58. #if defined(CONFIG_DEBUG_HUNT_FOR_ZERO)
  59. .valid = 1,
  60. #else
  61. .valid = 0,
  62. #endif
  63. .name = "ZERO Pointer Saveguard",
  64. },
  65. {
  66. .start = L1_CODE_START,
  67. .end = L1_CODE_START + L1_CODE_LENGTH,
  68. .psize = SIZE_4M,
  69. .attr = INITIAL_T | SWITCH_T | I_CPLB,
  70. .i_conf = L1_IMEMORY,
  71. .d_conf = 0,
  72. .valid = 1,
  73. .name = "L1 I-Memory",
  74. },
  75. {
  76. .start = L1_DATA_A_START,
  77. .end = L1_DATA_B_START + L1_DATA_B_LENGTH,
  78. .psize = SIZE_4M,
  79. .attr = INITIAL_T | SWITCH_T | D_CPLB,
  80. .i_conf = 0,
  81. .d_conf = L1_DMEMORY,
  82. #if ((L1_DATA_A_LENGTH > 0) || (L1_DATA_B_LENGTH > 0))
  83. .valid = 1,
  84. #else
  85. .valid = 0,
  86. #endif
  87. .name = "L1 D-Memory",
  88. },
  89. {
  90. .start = 0,
  91. .end = 0, /* dynamic */
  92. .psize = 0,
  93. .attr = INITIAL_T | SWITCH_T | I_CPLB | D_CPLB,
  94. .i_conf = SDRAM_IGENERIC,
  95. .d_conf = SDRAM_DGENERIC,
  96. .valid = 1,
  97. .name = "SDRAM Kernel",
  98. },
  99. {
  100. .start = 0, /* dynamic */
  101. .end = 0, /* dynamic */
  102. .psize = 0,
  103. .attr = INITIAL_T | SWITCH_T | D_CPLB,
  104. .i_conf = SDRAM_IGENERIC,
  105. .d_conf = SDRAM_DNON_CHBL,
  106. .valid = 1,
  107. .name = "SDRAM RAM MTD",
  108. },
  109. {
  110. .start = 0, /* dynamic */
  111. .end = 0, /* dynamic */
  112. .psize = SIZE_1M,
  113. .attr = INITIAL_T | SWITCH_T | D_CPLB,
  114. .d_conf = SDRAM_DNON_CHBL,
  115. .valid = 1,
  116. .name = "SDRAM Uncached DMA ZONE",
  117. },
  118. {
  119. .start = 0, /* dynamic */
  120. .end = 0, /* dynamic */
  121. .psize = 0,
  122. .attr = SWITCH_T | D_CPLB,
  123. .i_conf = 0, /* dynamic */
  124. .d_conf = 0, /* dynamic */
  125. .valid = 1,
  126. .name = "SDRAM Reserved Memory",
  127. },
  128. {
  129. .start = ASYNC_BANK0_BASE,
  130. .end = ASYNC_BANK3_BASE + ASYNC_BANK3_SIZE,
  131. .psize = 0,
  132. .attr = SWITCH_T | D_CPLB,
  133. .d_conf = SDRAM_EBIU,
  134. .valid = 1,
  135. .name = "ASYNC Memory",
  136. },
  137. {
  138. #if defined(CONFIG_BF561)
  139. .start = L2_SRAM,
  140. .end = L2_SRAM_END,
  141. .psize = SIZE_1M,
  142. .attr = SWITCH_T | D_CPLB,
  143. .i_conf = L2_MEMORY,
  144. .d_conf = L2_MEMORY,
  145. .valid = 1,
  146. #else
  147. .valid = 0,
  148. #endif
  149. .name = "L2 Memory",
  150. }
  151. };
  152. static u16 __init lock_kernel_check(u32 start, u32 end)
  153. {
  154. if ((start <= (u32) _stext && end >= (u32) _end)
  155. || (start >= (u32) _stext && end <= (u32) _end))
  156. return IN_KERNEL;
  157. return 0;
  158. }
  159. static unsigned short __init
  160. fill_cplbtab(struct cplb_tab *table,
  161. unsigned long start, unsigned long end,
  162. unsigned long block_size, unsigned long cplb_data)
  163. {
  164. int i;
  165. switch (block_size) {
  166. case SIZE_4M:
  167. i = 3;
  168. break;
  169. case SIZE_1M:
  170. i = 2;
  171. break;
  172. case SIZE_4K:
  173. i = 1;
  174. break;
  175. case SIZE_1K:
  176. default:
  177. i = 0;
  178. break;
  179. }
  180. cplb_data = (cplb_data & ~(3 << 16)) | (i << 16);
  181. while ((start < end) && (table->pos < table->size)) {
  182. table->tab[table->pos++] = start;
  183. if (lock_kernel_check(start, start + block_size) == IN_KERNEL)
  184. table->tab[table->pos++] =
  185. cplb_data | CPLB_LOCK | CPLB_DIRTY;
  186. else
  187. table->tab[table->pos++] = cplb_data;
  188. start += block_size;
  189. }
  190. return 0;
  191. }
  192. static unsigned short __init
  193. close_cplbtab(struct cplb_tab *table)
  194. {
  195. while (table->pos < table->size) {
  196. table->tab[table->pos++] = 0;
  197. table->tab[table->pos++] = 0; /* !CPLB_VALID */
  198. }
  199. return 0;
  200. }
  201. /* helper function */
  202. static void __fill_code_cplbtab(struct cplb_tab *t, int i, u32 a_start, u32 a_end)
  203. {
  204. if (cplb_data[i].psize) {
  205. fill_cplbtab(t,
  206. cplb_data[i].start,
  207. cplb_data[i].end,
  208. cplb_data[i].psize,
  209. cplb_data[i].i_conf);
  210. } else {
  211. #if (defined(CONFIG_BLKFIN_CACHE) && defined(ANOMALY_05000263))
  212. if (i == SDRAM_KERN) {
  213. fill_cplbtab(t,
  214. cplb_data[i].start,
  215. cplb_data[i].end,
  216. SIZE_4M,
  217. cplb_data[i].i_conf);
  218. } else
  219. #endif
  220. {
  221. fill_cplbtab(t,
  222. cplb_data[i].start,
  223. a_start,
  224. SIZE_1M,
  225. cplb_data[i].i_conf);
  226. fill_cplbtab(t,
  227. a_start,
  228. a_end,
  229. SIZE_4M,
  230. cplb_data[i].i_conf);
  231. fill_cplbtab(t, a_end,
  232. cplb_data[i].end,
  233. SIZE_1M,
  234. cplb_data[i].i_conf);
  235. }
  236. }
  237. }
  238. static void __fill_data_cplbtab(struct cplb_tab *t, int i, u32 a_start, u32 a_end)
  239. {
  240. if (cplb_data[i].psize) {
  241. fill_cplbtab(t,
  242. cplb_data[i].start,
  243. cplb_data[i].end,
  244. cplb_data[i].psize,
  245. cplb_data[i].d_conf);
  246. } else {
  247. fill_cplbtab(t,
  248. cplb_data[i].start,
  249. a_start, SIZE_1M,
  250. cplb_data[i].d_conf);
  251. fill_cplbtab(t, a_start,
  252. a_end, SIZE_4M,
  253. cplb_data[i].d_conf);
  254. fill_cplbtab(t, a_end,
  255. cplb_data[i].end,
  256. SIZE_1M,
  257. cplb_data[i].d_conf);
  258. }
  259. }
  260. void __init generate_cpl_tables(void)
  261. {
  262. u16 i, j, process;
  263. u32 a_start, a_end, as, ae, as_1m;
  264. struct cplb_tab *t_i = NULL;
  265. struct cplb_tab *t_d = NULL;
  266. struct s_cplb cplb;
  267. cplb.init_i.size = MAX_CPLBS;
  268. cplb.init_d.size = MAX_CPLBS;
  269. cplb.switch_i.size = MAX_SWITCH_I_CPLBS;
  270. cplb.switch_d.size = MAX_SWITCH_D_CPLBS;
  271. cplb.init_i.pos = 0;
  272. cplb.init_d.pos = 0;
  273. cplb.switch_i.pos = 0;
  274. cplb.switch_d.pos = 0;
  275. cplb.init_i.tab = icplb_table;
  276. cplb.init_d.tab = dcplb_table;
  277. cplb.switch_i.tab = ipdt_table;
  278. cplb.switch_d.tab = dpdt_table;
  279. cplb_data[SDRAM_KERN].end = memory_end;
  280. #ifdef CONFIG_MTD_UCLINUX
  281. cplb_data[SDRAM_RAM_MTD].start = memory_mtd_start;
  282. cplb_data[SDRAM_RAM_MTD].end = memory_mtd_start + mtd_size;
  283. cplb_data[SDRAM_RAM_MTD].valid = mtd_size > 0;
  284. # if defined(CONFIG_ROMFS_FS)
  285. cplb_data[SDRAM_RAM_MTD].attr |= I_CPLB;
  286. /*
  287. * The ROMFS_FS size is often not multiple of 1MB.
  288. * This can cause multiple CPLB sets covering the same memory area.
  289. * This will then cause multiple CPLB hit exceptions.
  290. * Workaround: We ensure a contiguous memory area by extending the kernel
  291. * memory section over the mtd section.
  292. * For ROMFS_FS memory must be covered with ICPLBs anyways.
  293. * So there is no difference between kernel and mtd memory setup.
  294. */
  295. cplb_data[SDRAM_KERN].end = memory_mtd_start + mtd_size;;
  296. cplb_data[SDRAM_RAM_MTD].valid = 0;
  297. # endif
  298. #else
  299. cplb_data[SDRAM_RAM_MTD].valid = 0;
  300. #endif
  301. cplb_data[SDRAM_DMAZ].start = _ramend - DMA_UNCACHED_REGION;
  302. cplb_data[SDRAM_DMAZ].end = _ramend;
  303. cplb_data[RES_MEM].start = _ramend;
  304. cplb_data[RES_MEM].end = physical_mem_end;
  305. if (reserved_mem_dcache_on)
  306. cplb_data[RES_MEM].d_conf = SDRAM_DGENERIC;
  307. else
  308. cplb_data[RES_MEM].d_conf = SDRAM_DNON_CHBL;
  309. if (reserved_mem_icache_on)
  310. cplb_data[RES_MEM].i_conf = SDRAM_IGENERIC;
  311. else
  312. cplb_data[RES_MEM].i_conf = SDRAM_INON_CHBL;
  313. for (i = ZERO_P; i <= L2_MEM; i++) {
  314. if (!cplb_data[i].valid)
  315. continue;
  316. as_1m = cplb_data[i].start % SIZE_1M;
  317. /* We need to make sure all sections are properly 1M aligned
  318. * However between Kernel Memory and the Kernel mtd section, depending on the
  319. * rootfs size, there can be overlapping memory areas.
  320. */
  321. if (as_1m && i != L1I_MEM && i != L1D_MEM) {
  322. #ifdef CONFIG_MTD_UCLINUX
  323. if (i == SDRAM_RAM_MTD) {
  324. if ((cplb_data[SDRAM_KERN].end + 1) > cplb_data[SDRAM_RAM_MTD].start)
  325. cplb_data[SDRAM_RAM_MTD].start = (cplb_data[i].start & (-2*SIZE_1M)) + SIZE_1M;
  326. else
  327. cplb_data[SDRAM_RAM_MTD].start = (cplb_data[i].start & (-2*SIZE_1M));
  328. } else
  329. #endif
  330. printk(KERN_WARNING "Unaligned Start of %s at 0x%X\n",
  331. cplb_data[i].name, cplb_data[i].start);
  332. }
  333. as = cplb_data[i].start % SIZE_4M;
  334. ae = cplb_data[i].end % SIZE_4M;
  335. if (as)
  336. a_start = cplb_data[i].start + (SIZE_4M - (as));
  337. else
  338. a_start = cplb_data[i].start;
  339. a_end = cplb_data[i].end - ae;
  340. for (j = INITIAL_T; j <= SWITCH_T; j++) {
  341. switch (j) {
  342. case INITIAL_T:
  343. if (cplb_data[i].attr & INITIAL_T) {
  344. t_i = &cplb.init_i;
  345. t_d = &cplb.init_d;
  346. process = 1;
  347. } else
  348. process = 0;
  349. break;
  350. case SWITCH_T:
  351. if (cplb_data[i].attr & SWITCH_T) {
  352. t_i = &cplb.switch_i;
  353. t_d = &cplb.switch_d;
  354. process = 1;
  355. } else
  356. process = 0;
  357. break;
  358. default:
  359. process = 0;
  360. break;
  361. }
  362. if (!process)
  363. continue;
  364. if (cplb_data[i].attr & I_CPLB)
  365. __fill_code_cplbtab(t_i, i, a_start, a_end);
  366. if (cplb_data[i].attr & D_CPLB)
  367. __fill_data_cplbtab(t_d, i, a_start, a_end);
  368. }
  369. }
  370. /* close tables */
  371. close_cplbtab(&cplb.init_i);
  372. close_cplbtab(&cplb.init_d);
  373. cplb.init_i.tab[cplb.init_i.pos] = -1;
  374. cplb.init_d.tab[cplb.init_d.pos] = -1;
  375. cplb.switch_i.tab[cplb.switch_i.pos] = -1;
  376. cplb.switch_d.tab[cplb.switch_d.pos] = -1;
  377. }
  378. #endif