cplbinit.c 9.9 KB

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