cplbinit.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445
  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/cacheflush.h>
  26. #include <asm/cplb.h>
  27. #include <asm/cplbinit.h>
  28. #include <asm/mem_map.h>
  29. u_long icplb_tables[NR_CPUS][CPLB_TBL_ENTRIES+1];
  30. u_long dcplb_tables[NR_CPUS][CPLB_TBL_ENTRIES+1];
  31. #ifdef CONFIG_CPLB_SWITCH_TAB_L1
  32. #define PDT_ATTR __attribute__((l1_data))
  33. #else
  34. #define PDT_ATTR
  35. #endif
  36. u_long ipdt_tables[NR_CPUS][MAX_SWITCH_I_CPLBS+1] PDT_ATTR;
  37. u_long dpdt_tables[NR_CPUS][MAX_SWITCH_D_CPLBS+1] PDT_ATTR;
  38. #ifdef CONFIG_CPLB_INFO
  39. u_long ipdt_swapcount_tables[NR_CPUS][MAX_SWITCH_I_CPLBS] PDT_ATTR;
  40. u_long dpdt_swapcount_tables[NR_CPUS][MAX_SWITCH_D_CPLBS] PDT_ATTR;
  41. #endif
  42. struct s_cplb {
  43. struct cplb_tab init_i;
  44. struct cplb_tab init_d;
  45. struct cplb_tab switch_i;
  46. struct cplb_tab switch_d;
  47. };
  48. #if defined(CONFIG_BFIN_DCACHE) || defined(CONFIG_BFIN_ICACHE)
  49. static struct cplb_desc cplb_data[] = {
  50. {
  51. .start = 0,
  52. .end = SIZE_1K,
  53. .psize = SIZE_1K,
  54. .attr = INITIAL_T | SWITCH_T | I_CPLB | D_CPLB,
  55. .i_conf = SDRAM_OOPS,
  56. .d_conf = SDRAM_OOPS,
  57. #if defined(CONFIG_DEBUG_HUNT_FOR_ZERO)
  58. .valid = 1,
  59. #else
  60. .valid = 0,
  61. #endif
  62. .name = "Zero Pointer Guard Page",
  63. },
  64. {
  65. .start = 0, /* dyanmic */
  66. .end = 0, /* dynamic */
  67. .psize = SIZE_4M,
  68. .attr = INITIAL_T | SWITCH_T | I_CPLB,
  69. .i_conf = L1_IMEMORY,
  70. .d_conf = 0,
  71. .valid = 1,
  72. .name = "L1 I-Memory",
  73. },
  74. {
  75. .start = 0, /* dynamic */
  76. .end = 0, /* dynamic */
  77. .psize = SIZE_4M,
  78. .attr = INITIAL_T | SWITCH_T | D_CPLB,
  79. .i_conf = 0,
  80. .d_conf = L1_DMEMORY,
  81. #if ((L1_DATA_A_LENGTH > 0) || (L1_DATA_B_LENGTH > 0))
  82. .valid = 1,
  83. #else
  84. .valid = 0,
  85. #endif
  86. .name = "L1 D-Memory",
  87. },
  88. {
  89. .start = L2_START,
  90. .end = L2_START + L2_LENGTH,
  91. .psize = SIZE_1M,
  92. .attr = L2_ATTR,
  93. .i_conf = L2_IMEMORY,
  94. .d_conf = L2_DMEMORY,
  95. .valid = (L2_LENGTH > 0),
  96. .name = "L2 Memory",
  97. },
  98. {
  99. .start = 0,
  100. .end = 0, /* dynamic */
  101. .psize = 0,
  102. .attr = INITIAL_T | SWITCH_T | I_CPLB | D_CPLB,
  103. .i_conf = SDRAM_IGENERIC,
  104. .d_conf = SDRAM_DGENERIC,
  105. .valid = 1,
  106. .name = "Kernel Memory",
  107. },
  108. {
  109. .start = 0, /* dynamic */
  110. .end = 0, /* dynamic */
  111. .psize = 0,
  112. .attr = INITIAL_T | SWITCH_T | D_CPLB,
  113. .i_conf = SDRAM_IGENERIC,
  114. .d_conf = SDRAM_DNON_CHBL,
  115. .valid = 1,
  116. .name = "uClinux MTD Memory",
  117. },
  118. {
  119. .start = 0, /* dynamic */
  120. .end = 0, /* dynamic */
  121. .psize = SIZE_1M,
  122. .attr = INITIAL_T | SWITCH_T | D_CPLB,
  123. .d_conf = SDRAM_DNON_CHBL,
  124. .valid = 1,
  125. .name = "Uncached DMA Zone",
  126. },
  127. {
  128. .start = 0, /* dynamic */
  129. .end = 0, /* dynamic */
  130. .psize = 0,
  131. .attr = SWITCH_T | D_CPLB,
  132. .i_conf = 0, /* dynamic */
  133. .d_conf = 0, /* dynamic */
  134. .valid = 1,
  135. .name = "Reserved Memory",
  136. },
  137. {
  138. .start = ASYNC_BANK0_BASE,
  139. .end = ASYNC_BANK3_BASE + ASYNC_BANK3_SIZE,
  140. .psize = 0,
  141. .attr = SWITCH_T | D_CPLB,
  142. .d_conf = SDRAM_EBIU,
  143. .valid = 1,
  144. .name = "Asynchronous Memory Banks",
  145. },
  146. {
  147. .start = BOOT_ROM_START,
  148. .end = BOOT_ROM_START + BOOT_ROM_LENGTH,
  149. .psize = SIZE_1M,
  150. .attr = SWITCH_T | I_CPLB | D_CPLB,
  151. .i_conf = SDRAM_IGENERIC,
  152. .d_conf = SDRAM_DGENERIC,
  153. .valid = 1,
  154. .name = "On-Chip BootROM",
  155. },
  156. };
  157. static bool __init lock_kernel_check(u32 start, u32 end)
  158. {
  159. if (start >= (u32)__init_begin || end <= (u32)_stext)
  160. return false;
  161. /* This cplb block overlapped with kernel area. */
  162. return true;
  163. }
  164. static void __init
  165. fill_cplbtab(struct cplb_tab *table,
  166. unsigned long start, unsigned long end,
  167. unsigned long block_size, unsigned long cplb_data)
  168. {
  169. int i;
  170. switch (block_size) {
  171. case SIZE_4M:
  172. i = 3;
  173. break;
  174. case SIZE_1M:
  175. i = 2;
  176. break;
  177. case SIZE_4K:
  178. i = 1;
  179. break;
  180. case SIZE_1K:
  181. default:
  182. i = 0;
  183. break;
  184. }
  185. cplb_data = (cplb_data & ~(3 << 16)) | (i << 16);
  186. while ((start < end) && (table->pos < table->size)) {
  187. table->tab[table->pos++] = start;
  188. if (lock_kernel_check(start, start + block_size))
  189. table->tab[table->pos++] =
  190. cplb_data | CPLB_LOCK | CPLB_DIRTY;
  191. else
  192. table->tab[table->pos++] = cplb_data;
  193. start += block_size;
  194. }
  195. }
  196. static void __init close_cplbtab(struct cplb_tab *table)
  197. {
  198. while (table->pos < table->size)
  199. table->tab[table->pos++] = 0;
  200. }
  201. /* helper function */
  202. static void __init
  203. __fill_code_cplbtab(struct cplb_tab *t, int i, u32 a_start, u32 a_end)
  204. {
  205. if (cplb_data[i].psize) {
  206. fill_cplbtab(t,
  207. cplb_data[i].start,
  208. cplb_data[i].end,
  209. cplb_data[i].psize,
  210. cplb_data[i].i_conf);
  211. } else {
  212. #if defined(CONFIG_BFIN_ICACHE)
  213. if (ANOMALY_05000263 && i == SDRAM_KERN) {
  214. fill_cplbtab(t,
  215. cplb_data[i].start,
  216. cplb_data[i].end,
  217. SIZE_4M,
  218. cplb_data[i].i_conf);
  219. } else
  220. #endif
  221. {
  222. fill_cplbtab(t,
  223. cplb_data[i].start,
  224. a_start,
  225. SIZE_1M,
  226. cplb_data[i].i_conf);
  227. fill_cplbtab(t,
  228. a_start,
  229. a_end,
  230. SIZE_4M,
  231. cplb_data[i].i_conf);
  232. fill_cplbtab(t, a_end,
  233. cplb_data[i].end,
  234. SIZE_1M,
  235. cplb_data[i].i_conf);
  236. }
  237. }
  238. }
  239. static void __init
  240. __fill_data_cplbtab(struct cplb_tab *t, int i, u32 a_start, u32 a_end)
  241. {
  242. if (cplb_data[i].psize) {
  243. fill_cplbtab(t,
  244. cplb_data[i].start,
  245. cplb_data[i].end,
  246. cplb_data[i].psize,
  247. cplb_data[i].d_conf);
  248. } else {
  249. fill_cplbtab(t,
  250. cplb_data[i].start,
  251. a_start, SIZE_1M,
  252. cplb_data[i].d_conf);
  253. fill_cplbtab(t, a_start,
  254. a_end, SIZE_4M,
  255. cplb_data[i].d_conf);
  256. fill_cplbtab(t, a_end,
  257. cplb_data[i].end,
  258. SIZE_1M,
  259. cplb_data[i].d_conf);
  260. }
  261. }
  262. void __init generate_cplb_tables_cpu(unsigned int cpu)
  263. {
  264. u16 i, j, process;
  265. u32 a_start, a_end, as, ae, as_1m;
  266. struct cplb_tab *t_i = NULL;
  267. struct cplb_tab *t_d = NULL;
  268. struct s_cplb cplb;
  269. printk(KERN_INFO "NOMPU: setting up cplb tables for global access\n");
  270. cplb.init_i.size = CPLB_TBL_ENTRIES;
  271. cplb.init_d.size = CPLB_TBL_ENTRIES;
  272. cplb.switch_i.size = MAX_SWITCH_I_CPLBS;
  273. cplb.switch_d.size = MAX_SWITCH_D_CPLBS;
  274. cplb.init_i.pos = 0;
  275. cplb.init_d.pos = 0;
  276. cplb.switch_i.pos = 0;
  277. cplb.switch_d.pos = 0;
  278. cplb.init_i.tab = icplb_tables[cpu];
  279. cplb.init_d.tab = dcplb_tables[cpu];
  280. cplb.switch_i.tab = ipdt_tables[cpu];
  281. cplb.switch_d.tab = dpdt_tables[cpu];
  282. cplb_data[L1I_MEM].start = get_l1_code_start_cpu(cpu);
  283. cplb_data[L1I_MEM].end = cplb_data[L1I_MEM].start + L1_CODE_LENGTH;
  284. cplb_data[L1D_MEM].start = get_l1_data_a_start_cpu(cpu);
  285. cplb_data[L1D_MEM].end = get_l1_data_b_start_cpu(cpu) + L1_DATA_B_LENGTH;
  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. /* make sure we locked the kernel start */
  378. BUG_ON(cplb.init_i.pos < 2 + cplb_data[ZERO_P].valid);
  379. BUG_ON(cplb.init_d.pos < 1 + cplb_data[ZERO_P].valid + cplb_data[L1D_MEM].valid);
  380. /* make sure we didnt overflow the table */
  381. BUG_ON(cplb.init_i.size < cplb.init_i.pos);
  382. BUG_ON(cplb.init_d.size < cplb.init_d.pos);
  383. BUG_ON(cplb.switch_i.size < cplb.switch_i.pos);
  384. BUG_ON(cplb.switch_d.size < cplb.switch_d.pos);
  385. /* close tables */
  386. close_cplbtab(&cplb.init_i);
  387. close_cplbtab(&cplb.init_d);
  388. cplb.init_i.tab[cplb.init_i.pos] = -1;
  389. cplb.init_d.tab[cplb.init_d.pos] = -1;
  390. cplb.switch_i.tab[cplb.switch_i.pos] = -1;
  391. cplb.switch_d.tab[cplb.switch_d.pos] = -1;
  392. }
  393. #endif