cplbinit.c 10 KB

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