cplbinit.c 9.9 KB

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