cplbinit.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441
  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 u16 __init lock_kernel_check(u32 start, u32 end)
  157. {
  158. if (start >= (u32)_end || end <= (u32)_stext)
  159. return 0;
  160. /* This cplb block overlapped with kernel area. */
  161. return IN_KERNEL;
  162. }
  163. static unsigned short __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) == IN_KERNEL)
  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. return 0;
  195. }
  196. static unsigned short __init
  197. close_cplbtab(struct cplb_tab *table)
  198. {
  199. while (table->pos < table->size) {
  200. table->tab[table->pos++] = 0;
  201. table->tab[table->pos++] = 0; /* !CPLB_VALID */
  202. }
  203. return 0;
  204. }
  205. /* helper function */
  206. static void __init
  207. __fill_code_cplbtab(struct cplb_tab *t, int i, u32 a_start, u32 a_end)
  208. {
  209. if (cplb_data[i].psize) {
  210. fill_cplbtab(t,
  211. cplb_data[i].start,
  212. cplb_data[i].end,
  213. cplb_data[i].psize,
  214. cplb_data[i].i_conf);
  215. } else {
  216. #if defined(CONFIG_BFIN_ICACHE)
  217. if (ANOMALY_05000263 && i == SDRAM_KERN) {
  218. fill_cplbtab(t,
  219. cplb_data[i].start,
  220. cplb_data[i].end,
  221. SIZE_4M,
  222. cplb_data[i].i_conf);
  223. } else
  224. #endif
  225. {
  226. fill_cplbtab(t,
  227. cplb_data[i].start,
  228. a_start,
  229. SIZE_1M,
  230. cplb_data[i].i_conf);
  231. fill_cplbtab(t,
  232. a_start,
  233. a_end,
  234. SIZE_4M,
  235. cplb_data[i].i_conf);
  236. fill_cplbtab(t, a_end,
  237. cplb_data[i].end,
  238. SIZE_1M,
  239. cplb_data[i].i_conf);
  240. }
  241. }
  242. }
  243. static void __init
  244. __fill_data_cplbtab(struct cplb_tab *t, int i, u32 a_start, u32 a_end)
  245. {
  246. if (cplb_data[i].psize) {
  247. fill_cplbtab(t,
  248. cplb_data[i].start,
  249. cplb_data[i].end,
  250. cplb_data[i].psize,
  251. cplb_data[i].d_conf);
  252. } else {
  253. fill_cplbtab(t,
  254. cplb_data[i].start,
  255. a_start, SIZE_1M,
  256. cplb_data[i].d_conf);
  257. fill_cplbtab(t, a_start,
  258. a_end, SIZE_4M,
  259. cplb_data[i].d_conf);
  260. fill_cplbtab(t, a_end,
  261. cplb_data[i].end,
  262. SIZE_1M,
  263. cplb_data[i].d_conf);
  264. }
  265. }
  266. void __init generate_cplb_tables_cpu(unsigned int cpu)
  267. {
  268. u16 i, j, process;
  269. u32 a_start, a_end, as, ae, as_1m;
  270. struct cplb_tab *t_i = NULL;
  271. struct cplb_tab *t_d = NULL;
  272. struct s_cplb cplb;
  273. printk(KERN_INFO "NOMPU: setting up cplb tables for global access\n");
  274. cplb.init_i.size = CPLB_TBL_ENTRIES;
  275. cplb.init_d.size = CPLB_TBL_ENTRIES;
  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_tables[cpu];
  283. cplb.init_d.tab = dcplb_tables[cpu];
  284. cplb.switch_i.tab = ipdt_tables[cpu];
  285. cplb.switch_d.tab = dpdt_tables[cpu];
  286. cplb_data[L1I_MEM].start = get_l1_code_start_cpu(cpu);
  287. cplb_data[L1I_MEM].end = cplb_data[L1I_MEM].start + L1_CODE_LENGTH;
  288. cplb_data[L1D_MEM].start = get_l1_data_a_start_cpu(cpu);
  289. cplb_data[L1D_MEM].end = get_l1_data_b_start_cpu(cpu) + L1_DATA_B_LENGTH;
  290. cplb_data[SDRAM_KERN].end = memory_end;
  291. #ifdef CONFIG_MTD_UCLINUX
  292. cplb_data[SDRAM_RAM_MTD].start = memory_mtd_start;
  293. cplb_data[SDRAM_RAM_MTD].end = memory_mtd_start + mtd_size;
  294. cplb_data[SDRAM_RAM_MTD].valid = mtd_size > 0;
  295. # if defined(CONFIG_ROMFS_FS)
  296. cplb_data[SDRAM_RAM_MTD].attr |= I_CPLB;
  297. /*
  298. * The ROMFS_FS size is often not multiple of 1MB.
  299. * This can cause multiple CPLB sets covering the same memory area.
  300. * This will then cause multiple CPLB hit exceptions.
  301. * Workaround: We ensure a contiguous memory area by extending the kernel
  302. * memory section over the mtd section.
  303. * For ROMFS_FS memory must be covered with ICPLBs anyways.
  304. * So there is no difference between kernel and mtd memory setup.
  305. */
  306. cplb_data[SDRAM_KERN].end = memory_mtd_start + mtd_size;;
  307. cplb_data[SDRAM_RAM_MTD].valid = 0;
  308. # endif
  309. #else
  310. cplb_data[SDRAM_RAM_MTD].valid = 0;
  311. #endif
  312. cplb_data[SDRAM_DMAZ].start = _ramend - DMA_UNCACHED_REGION;
  313. cplb_data[SDRAM_DMAZ].end = _ramend;
  314. cplb_data[RES_MEM].start = _ramend;
  315. cplb_data[RES_MEM].end = physical_mem_end;
  316. if (reserved_mem_dcache_on)
  317. cplb_data[RES_MEM].d_conf = SDRAM_DGENERIC;
  318. else
  319. cplb_data[RES_MEM].d_conf = SDRAM_DNON_CHBL;
  320. if (reserved_mem_icache_on)
  321. cplb_data[RES_MEM].i_conf = SDRAM_IGENERIC;
  322. else
  323. cplb_data[RES_MEM].i_conf = SDRAM_INON_CHBL;
  324. for (i = ZERO_P; i < ARRAY_SIZE(cplb_data); ++i) {
  325. if (!cplb_data[i].valid)
  326. continue;
  327. as_1m = cplb_data[i].start % SIZE_1M;
  328. /* We need to make sure all sections are properly 1M aligned
  329. * However between Kernel Memory and the Kernel mtd section, depending on the
  330. * rootfs size, there can be overlapping memory areas.
  331. */
  332. if (as_1m && i != L1I_MEM && i != L1D_MEM) {
  333. #ifdef CONFIG_MTD_UCLINUX
  334. if (i == SDRAM_RAM_MTD) {
  335. if ((cplb_data[SDRAM_KERN].end + 1) > cplb_data[SDRAM_RAM_MTD].start)
  336. cplb_data[SDRAM_RAM_MTD].start = (cplb_data[i].start & (-2*SIZE_1M)) + SIZE_1M;
  337. else
  338. cplb_data[SDRAM_RAM_MTD].start = (cplb_data[i].start & (-2*SIZE_1M));
  339. } else
  340. #endif
  341. printk(KERN_WARNING "Unaligned Start of %s at 0x%X\n",
  342. cplb_data[i].name, cplb_data[i].start);
  343. }
  344. as = cplb_data[i].start % SIZE_4M;
  345. ae = cplb_data[i].end % SIZE_4M;
  346. if (as)
  347. a_start = cplb_data[i].start + (SIZE_4M - (as));
  348. else
  349. a_start = cplb_data[i].start;
  350. a_end = cplb_data[i].end - ae;
  351. for (j = INITIAL_T; j <= SWITCH_T; j++) {
  352. switch (j) {
  353. case INITIAL_T:
  354. if (cplb_data[i].attr & INITIAL_T) {
  355. t_i = &cplb.init_i;
  356. t_d = &cplb.init_d;
  357. process = 1;
  358. } else
  359. process = 0;
  360. break;
  361. case SWITCH_T:
  362. if (cplb_data[i].attr & SWITCH_T) {
  363. t_i = &cplb.switch_i;
  364. t_d = &cplb.switch_d;
  365. process = 1;
  366. } else
  367. process = 0;
  368. break;
  369. default:
  370. process = 0;
  371. break;
  372. }
  373. if (!process)
  374. continue;
  375. if (cplb_data[i].attr & I_CPLB)
  376. __fill_code_cplbtab(t_i, i, a_start, a_end);
  377. if (cplb_data[i].attr & D_CPLB)
  378. __fill_data_cplbtab(t_d, i, a_start, a_end);
  379. }
  380. }
  381. /* close tables */
  382. close_cplbtab(&cplb.init_i);
  383. close_cplbtab(&cplb.init_d);
  384. cplb.init_i.tab[cplb.init_i.pos] = -1;
  385. cplb.init_d.tab[cplb.init_d.pos] = -1;
  386. cplb.switch_i.tab[cplb.switch_i.pos] = -1;
  387. cplb.switch_d.tab[cplb.switch_d.pos] = -1;
  388. }
  389. #endif