cplbinit.c 11 KB

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