cplbinit.c 11 KB

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