setup.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906
  1. /*
  2. * File: arch/blackfin/kernel/setup.c
  3. * Based on:
  4. * Author:
  5. *
  6. * Created:
  7. * Description:
  8. *
  9. * Modified:
  10. * Copyright 2004-2006 Analog Devices Inc.
  11. *
  12. * Bugs: Enter bugs at http://blackfin.uclinux.org/
  13. *
  14. * This program is free software; you can redistribute it and/or modify
  15. * it under the terms of the GNU General Public License as published by
  16. * the Free Software Foundation; either version 2 of the License, or
  17. * (at your option) any later version.
  18. *
  19. * This program is distributed in the hope that it will be useful,
  20. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. * GNU General Public License for more details.
  23. *
  24. * You should have received a copy of the GNU General Public License
  25. * along with this program; if not, see the file COPYING, or write
  26. * to the Free Software Foundation, Inc.,
  27. * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  28. */
  29. #include <linux/delay.h>
  30. #include <linux/console.h>
  31. #include <linux/bootmem.h>
  32. #include <linux/seq_file.h>
  33. #include <linux/cpu.h>
  34. #include <linux/module.h>
  35. #include <linux/tty.h>
  36. #include <linux/ext2_fs.h>
  37. #include <linux/cramfs_fs.h>
  38. #include <linux/romfs_fs.h>
  39. #include <asm/cacheflush.h>
  40. #include <asm/blackfin.h>
  41. #include <asm/cplbinit.h>
  42. u16 _bfin_swrst;
  43. unsigned long memory_start, memory_end, physical_mem_end;
  44. unsigned long reserved_mem_dcache_on;
  45. unsigned long reserved_mem_icache_on;
  46. EXPORT_SYMBOL(memory_start);
  47. EXPORT_SYMBOL(memory_end);
  48. EXPORT_SYMBOL(physical_mem_end);
  49. EXPORT_SYMBOL(_ramend);
  50. #ifdef CONFIG_MTD_UCLINUX
  51. unsigned long memory_mtd_end, memory_mtd_start, mtd_size;
  52. unsigned long _ebss;
  53. EXPORT_SYMBOL(memory_mtd_end);
  54. EXPORT_SYMBOL(memory_mtd_start);
  55. EXPORT_SYMBOL(mtd_size);
  56. #endif
  57. char __initdata command_line[COMMAND_LINE_SIZE];
  58. #if defined(CONFIG_BLKFIN_DCACHE) || defined(CONFIG_BLKFIN_CACHE)
  59. static void generate_cpl_tables(void);
  60. #endif
  61. void __init bf53x_cache_init(void)
  62. {
  63. #if defined(CONFIG_BLKFIN_DCACHE) || defined(CONFIG_BLKFIN_CACHE)
  64. generate_cpl_tables();
  65. #endif
  66. #ifdef CONFIG_BLKFIN_CACHE
  67. bfin_icache_init();
  68. printk(KERN_INFO "Instruction Cache Enabled\n");
  69. #endif
  70. #ifdef CONFIG_BLKFIN_DCACHE
  71. bfin_dcache_init();
  72. printk(KERN_INFO "Data Cache Enabled"
  73. # if defined CONFIG_BLKFIN_WB
  74. " (write-back)"
  75. # elif defined CONFIG_BLKFIN_WT
  76. " (write-through)"
  77. # endif
  78. "\n");
  79. #endif
  80. }
  81. void __init bf53x_relocate_l1_mem(void)
  82. {
  83. unsigned long l1_code_length;
  84. unsigned long l1_data_a_length;
  85. unsigned long l1_data_b_length;
  86. l1_code_length = _etext_l1 - _stext_l1;
  87. if (l1_code_length > L1_CODE_LENGTH)
  88. l1_code_length = L1_CODE_LENGTH;
  89. /* cannot complain as printk is not available as yet.
  90. * But we can continue booting and complain later!
  91. */
  92. /* Copy _stext_l1 to _etext_l1 to L1 instruction SRAM */
  93. dma_memcpy(_stext_l1, _l1_lma_start, l1_code_length);
  94. l1_data_a_length = _ebss_l1 - _sdata_l1;
  95. if (l1_data_a_length > L1_DATA_A_LENGTH)
  96. l1_data_a_length = L1_DATA_A_LENGTH;
  97. /* Copy _sdata_l1 to _ebss_l1 to L1 data bank A SRAM */
  98. dma_memcpy(_sdata_l1, _l1_lma_start + l1_code_length, l1_data_a_length);
  99. l1_data_b_length = _ebss_b_l1 - _sdata_b_l1;
  100. if (l1_data_b_length > L1_DATA_B_LENGTH)
  101. l1_data_b_length = L1_DATA_B_LENGTH;
  102. /* Copy _sdata_b_l1 to _ebss_b_l1 to L1 data bank B SRAM */
  103. dma_memcpy(_sdata_b_l1, _l1_lma_start + l1_code_length +
  104. l1_data_a_length, l1_data_b_length);
  105. }
  106. /*
  107. * Initial parsing of the command line. Currently, we support:
  108. * - Controlling the linux memory size: mem=xxx[KMG]
  109. * - Controlling the physical memory size: max_mem=xxx[KMG][$][#]
  110. * $ -> reserved memory is dcacheable
  111. * # -> reserved memory is icacheable
  112. */
  113. static __init void parse_cmdline_early(char *cmdline_p)
  114. {
  115. char c = ' ', *to = cmdline_p;
  116. unsigned int memsize;
  117. for (;;) {
  118. if (c == ' ') {
  119. if (!memcmp(to, "mem=", 4)) {
  120. to += 4;
  121. memsize = memparse(to, &to);
  122. if (memsize)
  123. _ramend = memsize;
  124. } else if (!memcmp(to, "max_mem=", 8)) {
  125. to += 8;
  126. memsize = memparse(to, &to);
  127. if (memsize) {
  128. physical_mem_end = memsize;
  129. if (*to != ' ') {
  130. if (*to == '$'
  131. || *(to + 1) == '$')
  132. reserved_mem_dcache_on =
  133. 1;
  134. if (*to == '#'
  135. || *(to + 1) == '#')
  136. reserved_mem_icache_on =
  137. 1;
  138. }
  139. }
  140. }
  141. }
  142. c = *(to++);
  143. if (!c)
  144. break;
  145. }
  146. }
  147. void __init setup_arch(char **cmdline_p)
  148. {
  149. int bootmap_size;
  150. unsigned long l1_length, sclk, cclk;
  151. #ifdef CONFIG_MTD_UCLINUX
  152. unsigned long mtd_phys = 0;
  153. #endif
  154. #ifdef CONFIG_DUMMY_CONSOLE
  155. conswitchp = &dummy_con;
  156. #endif
  157. cclk = get_cclk();
  158. sclk = get_sclk();
  159. #if !defined(CONFIG_BFIN_KERNEL_CLOCK) && defined(ANOMALY_05000273)
  160. if (cclk == sclk)
  161. panic("ANOMALY 05000273, SCLK can not be same as CCLK");
  162. #endif
  163. #if defined(ANOMALY_05000266)
  164. bfin_read_IMDMA_D0_IRQ_STATUS();
  165. bfin_read_IMDMA_D1_IRQ_STATUS();
  166. #endif
  167. #ifdef DEBUG_SERIAL_EARLY_INIT
  168. bfin_console_init(); /* early console registration */
  169. /* this give a chance to get printk() working before crash. */
  170. #endif
  171. #if defined(CONFIG_CHR_DEV_FLASH) || defined(CONFIG_BLK_DEV_FLASH)
  172. /* we need to initialize the Flashrom device here since we might
  173. * do things with flash early on in the boot
  174. */
  175. flash_probe();
  176. #endif
  177. #if defined(CONFIG_CMDLINE_BOOL)
  178. strncpy(&command_line[0], CONFIG_CMDLINE, sizeof(command_line));
  179. command_line[sizeof(command_line) - 1] = 0;
  180. #endif
  181. /* Keep a copy of command line */
  182. *cmdline_p = &command_line[0];
  183. memcpy(boot_command_line, command_line, COMMAND_LINE_SIZE);
  184. boot_command_line[COMMAND_LINE_SIZE - 1] = '\0';
  185. /* setup memory defaults from the user config */
  186. physical_mem_end = 0;
  187. _ramend = CONFIG_MEM_SIZE * 1024 * 1024;
  188. parse_cmdline_early(&command_line[0]);
  189. if (physical_mem_end == 0)
  190. physical_mem_end = _ramend;
  191. /* by now the stack is part of the init task */
  192. memory_end = _ramend - DMA_UNCACHED_REGION;
  193. _ramstart = (unsigned long)__bss_stop;
  194. memory_start = PAGE_ALIGN(_ramstart);
  195. #if defined(CONFIG_MTD_UCLINUX)
  196. /* generic memory mapped MTD driver */
  197. memory_mtd_end = memory_end;
  198. mtd_phys = _ramstart;
  199. mtd_size = PAGE_ALIGN(*((unsigned long *)(mtd_phys + 8)));
  200. # if defined(CONFIG_EXT2_FS) || defined(CONFIG_EXT3_FS)
  201. if (*((unsigned short *)(mtd_phys + 0x438)) == EXT2_SUPER_MAGIC)
  202. mtd_size =
  203. PAGE_ALIGN(*((unsigned long *)(mtd_phys + 0x404)) << 10);
  204. # endif
  205. # if defined(CONFIG_CRAMFS)
  206. if (*((unsigned long *)(mtd_phys)) == CRAMFS_MAGIC)
  207. mtd_size = PAGE_ALIGN(*((unsigned long *)(mtd_phys + 0x4)));
  208. # endif
  209. # if defined(CONFIG_ROMFS_FS)
  210. if (((unsigned long *)mtd_phys)[0] == ROMSB_WORD0
  211. && ((unsigned long *)mtd_phys)[1] == ROMSB_WORD1)
  212. mtd_size =
  213. PAGE_ALIGN(be32_to_cpu(((unsigned long *)mtd_phys)[2]));
  214. # if (defined(CONFIG_BLKFIN_CACHE) && defined(ANOMALY_05000263))
  215. /* Due to a Hardware Anomaly we need to limit the size of usable
  216. * instruction memory to max 60MB, 56 if HUNT_FOR_ZERO is on
  217. * 05000263 - Hardware loop corrupted when taking an ICPLB exception
  218. */
  219. # if (defined(CONFIG_DEBUG_HUNT_FOR_ZERO))
  220. if (memory_end >= 56 * 1024 * 1024)
  221. memory_end = 56 * 1024 * 1024;
  222. # else
  223. if (memory_end >= 60 * 1024 * 1024)
  224. memory_end = 60 * 1024 * 1024;
  225. # endif /* CONFIG_DEBUG_HUNT_FOR_ZERO */
  226. # endif /* ANOMALY_05000263 */
  227. # endif /* CONFIG_ROMFS_FS */
  228. memory_end -= mtd_size;
  229. if (mtd_size == 0) {
  230. console_init();
  231. panic("Don't boot kernel without rootfs attached.\n");
  232. }
  233. /* Relocate MTD image to the top of memory after the uncached memory area */
  234. dma_memcpy((char *)memory_end, __bss_stop, mtd_size);
  235. memory_mtd_start = memory_end;
  236. _ebss = memory_mtd_start; /* define _ebss for compatible */
  237. #endif /* CONFIG_MTD_UCLINUX */
  238. #if (defined(CONFIG_BLKFIN_CACHE) && defined(ANOMALY_05000263))
  239. /* Due to a Hardware Anomaly we need to limit the size of usable
  240. * instruction memory to max 60MB, 56 if HUNT_FOR_ZERO is on
  241. * 05000263 - Hardware loop corrupted when taking an ICPLB exception
  242. */
  243. #if (defined(CONFIG_DEBUG_HUNT_FOR_ZERO))
  244. if (memory_end >= 56 * 1024 * 1024)
  245. memory_end = 56 * 1024 * 1024;
  246. #else
  247. if (memory_end >= 60 * 1024 * 1024)
  248. memory_end = 60 * 1024 * 1024;
  249. #endif /* CONFIG_DEBUG_HUNT_FOR_ZERO */
  250. printk(KERN_NOTICE "Warning: limiting memory to %liMB due to hardware anomaly 05000263\n", memory_end >> 20);
  251. #endif /* ANOMALY_05000263 */
  252. #if !defined(CONFIG_MTD_UCLINUX)
  253. memory_end -= SIZE_4K; /*In case there is no valid CPLB behind memory_end make sure we don't get to close*/
  254. #endif
  255. init_mm.start_code = (unsigned long)_stext;
  256. init_mm.end_code = (unsigned long)_etext;
  257. init_mm.end_data = (unsigned long)_edata;
  258. init_mm.brk = (unsigned long)0;
  259. init_leds();
  260. printk(KERN_INFO "Blackfin support (C) 2004-2007 Analog Devices, Inc.\n");
  261. printk(KERN_INFO "Compiled for ADSP-%s Rev 0.%d\n", CPU, bfin_compiled_revid());
  262. if (bfin_revid() != bfin_compiled_revid())
  263. printk(KERN_ERR "Warning: Compiled for Rev %d, but running on Rev %d\n",
  264. bfin_compiled_revid(), bfin_revid());
  265. if (bfin_revid() < SUPPORTED_REVID)
  266. printk(KERN_ERR "Warning: Unsupported Chip Revision ADSP-%s Rev 0.%d detected\n",
  267. CPU, bfin_revid());
  268. printk(KERN_INFO "Blackfin Linux support by http://blackfin.uclinux.org/\n");
  269. printk(KERN_INFO "Processor Speed: %lu MHz core clock and %lu Mhz System Clock\n",
  270. cclk / 1000000, sclk / 1000000);
  271. #if defined(ANOMALY_05000273)
  272. if ((cclk >> 1) <= sclk)
  273. printk("\n\n\nANOMALY_05000273: CCLK must be >= 2*SCLK !!!\n\n\n");
  274. #endif
  275. printk(KERN_INFO "Board Memory: %ldMB\n", physical_mem_end >> 20);
  276. printk(KERN_INFO "Kernel Managed Memory: %ldMB\n", _ramend >> 20);
  277. printk(KERN_INFO "Memory map:\n"
  278. KERN_INFO " text = 0x%p-0x%p\n"
  279. KERN_INFO " rodata = 0x%p-0x%p\n"
  280. KERN_INFO " data = 0x%p-0x%p\n"
  281. KERN_INFO " stack = 0x%p-0x%p\n"
  282. KERN_INFO " init = 0x%p-0x%p\n"
  283. KERN_INFO " bss = 0x%p-0x%p\n"
  284. KERN_INFO " available = 0x%p-0x%p\n"
  285. #ifdef CONFIG_MTD_UCLINUX
  286. KERN_INFO " rootfs = 0x%p-0x%p\n"
  287. #endif
  288. #if DMA_UNCACHED_REGION > 0
  289. KERN_INFO " DMA Zone = 0x%p-0x%p\n"
  290. #endif
  291. , _stext, _etext,
  292. __start_rodata, __end_rodata,
  293. _sdata, _edata,
  294. (void*)&init_thread_union, (void*)((int)(&init_thread_union) + 0x2000),
  295. __init_begin, __init_end,
  296. __bss_start, __bss_stop,
  297. (void*)_ramstart, (void*)memory_end
  298. #ifdef CONFIG_MTD_UCLINUX
  299. , (void*)memory_mtd_start, (void*)(memory_mtd_start + mtd_size)
  300. #endif
  301. #if DMA_UNCACHED_REGION > 0
  302. , (void*)(_ramend - DMA_UNCACHED_REGION), (void*)(_ramend)
  303. #endif
  304. );
  305. /*
  306. * give all the memory to the bootmap allocator, tell it to put the
  307. * boot mem_map at the start of memory
  308. */
  309. bootmap_size = init_bootmem_node(NODE_DATA(0), memory_start >> PAGE_SHIFT, /* map goes here */
  310. PAGE_OFFSET >> PAGE_SHIFT,
  311. memory_end >> PAGE_SHIFT);
  312. /*
  313. * free the usable memory, we have to make sure we do not free
  314. * the bootmem bitmap so we then reserve it after freeing it :-)
  315. */
  316. free_bootmem(memory_start, memory_end - memory_start);
  317. reserve_bootmem(memory_start, bootmap_size);
  318. /*
  319. * get kmalloc into gear
  320. */
  321. paging_init();
  322. /* check the size of the l1 area */
  323. l1_length = _etext_l1 - _stext_l1;
  324. if (l1_length > L1_CODE_LENGTH)
  325. panic("L1 memory overflow\n");
  326. l1_length = _ebss_l1 - _sdata_l1;
  327. if (l1_length > L1_DATA_A_LENGTH)
  328. panic("L1 memory overflow\n");
  329. #ifdef BF561_FAMILY
  330. _bfin_swrst = bfin_read_SICA_SWRST();
  331. #else
  332. _bfin_swrst = bfin_read_SWRST();
  333. #endif
  334. bf53x_cache_init();
  335. printk(KERN_INFO "Hardware Trace Enabled\n");
  336. bfin_write_TBUFCTL(0x03);
  337. }
  338. static int __init topology_init(void)
  339. {
  340. #if defined (CONFIG_BF561)
  341. static struct cpu cpu[2];
  342. register_cpu(&cpu[0], 0);
  343. register_cpu(&cpu[1], 1);
  344. return 0;
  345. #else
  346. static struct cpu cpu[1];
  347. return register_cpu(cpu, 0);
  348. #endif
  349. }
  350. subsys_initcall(topology_init);
  351. #if defined(CONFIG_BLKFIN_DCACHE) || defined(CONFIG_BLKFIN_CACHE)
  352. static u16 __init lock_kernel_check(u32 start, u32 end)
  353. {
  354. if ((start <= (u32) _stext && end >= (u32) _end)
  355. || (start >= (u32) _stext && end <= (u32) _end))
  356. return IN_KERNEL;
  357. return 0;
  358. }
  359. static unsigned short __init
  360. fill_cplbtab(struct cplb_tab *table,
  361. unsigned long start, unsigned long end,
  362. unsigned long block_size, unsigned long cplb_data)
  363. {
  364. int i;
  365. switch (block_size) {
  366. case SIZE_4M:
  367. i = 3;
  368. break;
  369. case SIZE_1M:
  370. i = 2;
  371. break;
  372. case SIZE_4K:
  373. i = 1;
  374. break;
  375. case SIZE_1K:
  376. default:
  377. i = 0;
  378. break;
  379. }
  380. cplb_data = (cplb_data & ~(3 << 16)) | (i << 16);
  381. while ((start < end) && (table->pos < table->size)) {
  382. table->tab[table->pos++] = start;
  383. if (lock_kernel_check(start, start + block_size) == IN_KERNEL)
  384. table->tab[table->pos++] =
  385. cplb_data | CPLB_LOCK | CPLB_DIRTY;
  386. else
  387. table->tab[table->pos++] = cplb_data;
  388. start += block_size;
  389. }
  390. return 0;
  391. }
  392. static unsigned short __init
  393. close_cplbtab(struct cplb_tab *table)
  394. {
  395. while (table->pos < table->size) {
  396. table->tab[table->pos++] = 0;
  397. table->tab[table->pos++] = 0; /* !CPLB_VALID */
  398. }
  399. return 0;
  400. }
  401. /* helper function */
  402. static void __fill_code_cplbtab(struct cplb_tab *t, int i,
  403. u32 a_start, u32 a_end)
  404. {
  405. if (cplb_data[i].psize) {
  406. fill_cplbtab(t,
  407. cplb_data[i].start,
  408. cplb_data[i].end,
  409. cplb_data[i].psize,
  410. cplb_data[i].i_conf);
  411. } else {
  412. #if (defined(CONFIG_BLKFIN_CACHE) && defined(ANOMALY_05000263))
  413. if (i == SDRAM_KERN) {
  414. fill_cplbtab(t,
  415. cplb_data[i].start,
  416. cplb_data[i].end,
  417. SIZE_4M,
  418. cplb_data[i].i_conf);
  419. } else {
  420. #endif
  421. fill_cplbtab(t,
  422. cplb_data[i].start,
  423. a_start,
  424. SIZE_1M,
  425. cplb_data[i].i_conf);
  426. fill_cplbtab(t,
  427. a_start,
  428. a_end,
  429. SIZE_4M,
  430. cplb_data[i].i_conf);
  431. fill_cplbtab(t, a_end,
  432. cplb_data[i].end,
  433. SIZE_1M,
  434. cplb_data[i].i_conf);
  435. }
  436. }
  437. }
  438. static void __fill_data_cplbtab(struct cplb_tab *t, int i,
  439. u32 a_start, u32 a_end)
  440. {
  441. if (cplb_data[i].psize) {
  442. fill_cplbtab(t,
  443. cplb_data[i].start,
  444. cplb_data[i].end,
  445. cplb_data[i].psize,
  446. cplb_data[i].d_conf);
  447. } else {
  448. fill_cplbtab(t,
  449. cplb_data[i].start,
  450. a_start, SIZE_1M,
  451. cplb_data[i].d_conf);
  452. fill_cplbtab(t, a_start,
  453. a_end, SIZE_4M,
  454. cplb_data[i].d_conf);
  455. fill_cplbtab(t, a_end,
  456. cplb_data[i].end,
  457. SIZE_1M,
  458. cplb_data[i].d_conf);
  459. }
  460. }
  461. static void __init generate_cpl_tables(void)
  462. {
  463. u16 i, j, process;
  464. u32 a_start, a_end, as, ae, as_1m;
  465. struct cplb_tab *t_i = NULL;
  466. struct cplb_tab *t_d = NULL;
  467. struct s_cplb cplb;
  468. cplb.init_i.size = MAX_CPLBS;
  469. cplb.init_d.size = MAX_CPLBS;
  470. cplb.switch_i.size = MAX_SWITCH_I_CPLBS;
  471. cplb.switch_d.size = MAX_SWITCH_D_CPLBS;
  472. cplb.init_i.pos = 0;
  473. cplb.init_d.pos = 0;
  474. cplb.switch_i.pos = 0;
  475. cplb.switch_d.pos = 0;
  476. cplb.init_i.tab = icplb_table;
  477. cplb.init_d.tab = dcplb_table;
  478. cplb.switch_i.tab = ipdt_table;
  479. cplb.switch_d.tab = dpdt_table;
  480. cplb_data[SDRAM_KERN].end = memory_end;
  481. #ifdef CONFIG_MTD_UCLINUX
  482. cplb_data[SDRAM_RAM_MTD].start = memory_mtd_start;
  483. cplb_data[SDRAM_RAM_MTD].end = memory_mtd_start + mtd_size;
  484. cplb_data[SDRAM_RAM_MTD].valid = mtd_size > 0;
  485. # if defined(CONFIG_ROMFS_FS)
  486. cplb_data[SDRAM_RAM_MTD].attr |= I_CPLB;
  487. /*
  488. * The ROMFS_FS size is often not multiple of 1MB.
  489. * This can cause multiple CPLB sets covering the same memory area.
  490. * This will then cause multiple CPLB hit exceptions.
  491. * Workaround: We ensure a contiguous memory area by extending the kernel
  492. * memory section over the mtd section.
  493. * For ROMFS_FS memory must be covered with ICPLBs anyways.
  494. * So there is no difference between kernel and mtd memory setup.
  495. */
  496. cplb_data[SDRAM_KERN].end = memory_mtd_start + mtd_size;;
  497. cplb_data[SDRAM_RAM_MTD].valid = 0;
  498. # endif
  499. #else
  500. cplb_data[SDRAM_RAM_MTD].valid = 0;
  501. #endif
  502. cplb_data[SDRAM_DMAZ].start = _ramend - DMA_UNCACHED_REGION;
  503. cplb_data[SDRAM_DMAZ].end = _ramend;
  504. cplb_data[RES_MEM].start = _ramend;
  505. cplb_data[RES_MEM].end = physical_mem_end;
  506. if (reserved_mem_dcache_on)
  507. cplb_data[RES_MEM].d_conf = SDRAM_DGENERIC;
  508. else
  509. cplb_data[RES_MEM].d_conf = SDRAM_DNON_CHBL;
  510. if (reserved_mem_icache_on)
  511. cplb_data[RES_MEM].i_conf = SDRAM_IGENERIC;
  512. else
  513. cplb_data[RES_MEM].i_conf = SDRAM_INON_CHBL;
  514. for (i = ZERO_P; i <= L2_MEM; i++) {
  515. if (!cplb_data[i].valid)
  516. continue;
  517. as_1m = cplb_data[i].start % SIZE_1M;
  518. /*
  519. * We need to make sure all sections are properly 1M aligned
  520. * However between Kernel Memory and the Kernel mtd section,
  521. * depending on the rootfs size, there can be overlapping
  522. * memory areas.
  523. */
  524. if (as_1m && i != L1I_MEM && i != L1D_MEM) {
  525. #ifdef CONFIG_MTD_UCLINUX
  526. if (i == SDRAM_RAM_MTD) {
  527. if ((cplb_data[SDRAM_KERN].end + 1) >
  528. cplb_data[SDRAM_RAM_MTD].start)
  529. cplb_data[SDRAM_RAM_MTD].start =
  530. (cplb_data[i].start &
  531. (-2*SIZE_1M)) + SIZE_1M;
  532. else
  533. cplb_data[SDRAM_RAM_MTD].start =
  534. (cplb_data[i].start &
  535. (-2*SIZE_1M));
  536. } else
  537. #endif
  538. printk(KERN_WARNING
  539. "Unaligned Start of %s at 0x%X\n",
  540. cplb_data[i].name, cplb_data[i].start);
  541. }
  542. as = cplb_data[i].start % SIZE_4M;
  543. ae = cplb_data[i].end % SIZE_4M;
  544. if (as)
  545. a_start = cplb_data[i].start + (SIZE_4M - (as));
  546. else
  547. a_start = cplb_data[i].start;
  548. a_end = cplb_data[i].end - ae;
  549. for (j = INITIAL_T; j <= SWITCH_T; j++) {
  550. switch (j) {
  551. case INITIAL_T:
  552. if (cplb_data[i].attr & INITIAL_T) {
  553. t_i = &cplb.init_i;
  554. t_d = &cplb.init_d;
  555. process = 1;
  556. } else
  557. process = 0;
  558. break;
  559. case SWITCH_T:
  560. if (cplb_data[i].attr & SWITCH_T) {
  561. t_i = &cplb.switch_i;
  562. t_d = &cplb.switch_d;
  563. process = 1;
  564. } else
  565. process = 0;
  566. break;
  567. default:
  568. process = 0;
  569. break;
  570. }
  571. if (!process)
  572. continue;
  573. if (cplb_data[i].attr & I_CPLB)
  574. __fill_code_cplbtab(t_i, i, a_start, a_end);
  575. if (cplb_data[i].attr & D_CPLB)
  576. __fill_data_cplbtab(t_d, i, a_start, a_end);
  577. }
  578. }
  579. /* close tables */
  580. close_cplbtab(&cplb.init_i);
  581. close_cplbtab(&cplb.init_d);
  582. cplb.init_i.tab[cplb.init_i.pos] = -1;
  583. cplb.init_d.tab[cplb.init_d.pos] = -1;
  584. cplb.switch_i.tab[cplb.switch_i.pos] = -1;
  585. cplb.switch_d.tab[cplb.switch_d.pos] = -1;
  586. }
  587. #endif
  588. static u_long get_vco(void)
  589. {
  590. u_long msel;
  591. u_long vco;
  592. msel = (bfin_read_PLL_CTL() >> 9) & 0x3F;
  593. if (0 == msel)
  594. msel = 64;
  595. vco = CONFIG_CLKIN_HZ;
  596. vco >>= (1 & bfin_read_PLL_CTL()); /* DF bit */
  597. vco = msel * vco;
  598. return vco;
  599. }
  600. /*Get the Core clock*/
  601. u_long get_cclk(void)
  602. {
  603. u_long csel, ssel;
  604. if (bfin_read_PLL_STAT() & 0x1)
  605. return CONFIG_CLKIN_HZ;
  606. ssel = bfin_read_PLL_DIV();
  607. csel = ((ssel >> 4) & 0x03);
  608. ssel &= 0xf;
  609. if (ssel && ssel < (1 << csel)) /* SCLK > CCLK */
  610. return get_vco() / ssel;
  611. return get_vco() >> csel;
  612. }
  613. EXPORT_SYMBOL(get_cclk);
  614. /* Get the System clock */
  615. u_long get_sclk(void)
  616. {
  617. u_long ssel;
  618. if (bfin_read_PLL_STAT() & 0x1)
  619. return CONFIG_CLKIN_HZ;
  620. ssel = (bfin_read_PLL_DIV() & 0xf);
  621. if (0 == ssel) {
  622. printk(KERN_WARNING "Invalid System Clock\n");
  623. ssel = 1;
  624. }
  625. return get_vco() / ssel;
  626. }
  627. EXPORT_SYMBOL(get_sclk);
  628. /*
  629. * Get CPU information for use by the procfs.
  630. */
  631. static int show_cpuinfo(struct seq_file *m, void *v)
  632. {
  633. char *cpu, *mmu, *fpu, *name;
  634. uint32_t revid;
  635. u_long cclk = 0, sclk = 0;
  636. u_int dcache_size = 0, dsup_banks = 0;
  637. cpu = CPU;
  638. mmu = "none";
  639. fpu = "none";
  640. revid = bfin_revid();
  641. name = bfin_board_name;
  642. cclk = get_cclk();
  643. sclk = get_sclk();
  644. seq_printf(m, "CPU:\t\tADSP-%s Rev. 0.%d\n"
  645. "MMU:\t\t%s\n"
  646. "FPU:\t\t%s\n"
  647. "Core Clock:\t%9lu Hz\n"
  648. "System Clock:\t%9lu Hz\n"
  649. "BogoMips:\t%lu.%02lu\n"
  650. "Calibration:\t%lu loops\n",
  651. cpu, revid, mmu, fpu,
  652. cclk,
  653. sclk,
  654. (loops_per_jiffy * HZ) / 500000,
  655. ((loops_per_jiffy * HZ) / 5000) % 100,
  656. (loops_per_jiffy * HZ));
  657. seq_printf(m, "Board Name:\t%s\n", name);
  658. seq_printf(m, "Board Memory:\t%ld MB\n", physical_mem_end >> 20);
  659. seq_printf(m, "Kernel Memory:\t%ld MB\n", (unsigned long)_ramend >> 20);
  660. if (bfin_read_IMEM_CONTROL() & (ENICPLB | IMC))
  661. seq_printf(m, "I-CACHE:\tON\n");
  662. else
  663. seq_printf(m, "I-CACHE:\tOFF\n");
  664. if ((bfin_read_DMEM_CONTROL()) & (ENDCPLB | DMC_ENABLE))
  665. seq_printf(m, "D-CACHE:\tON"
  666. #if defined CONFIG_BLKFIN_WB
  667. " (write-back)"
  668. #elif defined CONFIG_BLKFIN_WT
  669. " (write-through)"
  670. #endif
  671. "\n");
  672. else
  673. seq_printf(m, "D-CACHE:\tOFF\n");
  674. switch(bfin_read_DMEM_CONTROL() & (1 << DMC0_P | 1 << DMC1_P)) {
  675. case ACACHE_BSRAM:
  676. seq_printf(m, "DBANK-A:\tCACHE\n" "DBANK-B:\tSRAM\n");
  677. dcache_size = 16;
  678. dsup_banks = 1;
  679. break;
  680. case ACACHE_BCACHE:
  681. seq_printf(m, "DBANK-A:\tCACHE\n" "DBANK-B:\tCACHE\n");
  682. dcache_size = 32;
  683. dsup_banks = 2;
  684. break;
  685. case ASRAM_BSRAM:
  686. seq_printf(m, "DBANK-A:\tSRAM\n" "DBANK-B:\tSRAM\n");
  687. dcache_size = 0;
  688. dsup_banks = 0;
  689. break;
  690. default:
  691. break;
  692. }
  693. seq_printf(m, "I-CACHE Size:\t%dKB\n", BLKFIN_ICACHESIZE / 1024);
  694. seq_printf(m, "D-CACHE Size:\t%dKB\n", dcache_size);
  695. seq_printf(m, "I-CACHE Setup:\t%d Sub-banks/%d Ways, %d Lines/Way\n",
  696. BLKFIN_ISUBBANKS, BLKFIN_IWAYS, BLKFIN_ILINES);
  697. seq_printf(m,
  698. "D-CACHE Setup:\t%d Super-banks/%d Sub-banks/%d Ways, %d Lines/Way\n",
  699. dsup_banks, BLKFIN_DSUBBANKS, BLKFIN_DWAYS,
  700. BLKFIN_DLINES);
  701. #ifdef CONFIG_BLKFIN_CACHE_LOCK
  702. switch (read_iloc()) {
  703. case WAY0_L:
  704. seq_printf(m, "Way0 Locked-Down\n");
  705. break;
  706. case WAY1_L:
  707. seq_printf(m, "Way1 Locked-Down\n");
  708. break;
  709. case WAY01_L:
  710. seq_printf(m, "Way0,Way1 Locked-Down\n");
  711. break;
  712. case WAY2_L:
  713. seq_printf(m, "Way2 Locked-Down\n");
  714. break;
  715. case WAY02_L:
  716. seq_printf(m, "Way0,Way2 Locked-Down\n");
  717. break;
  718. case WAY12_L:
  719. seq_printf(m, "Way1,Way2 Locked-Down\n");
  720. break;
  721. case WAY012_L:
  722. seq_printf(m, "Way0,Way1 & Way2 Locked-Down\n");
  723. break;
  724. case WAY3_L:
  725. seq_printf(m, "Way3 Locked-Down\n");
  726. break;
  727. case WAY03_L:
  728. seq_printf(m, "Way0,Way3 Locked-Down\n");
  729. break;
  730. case WAY13_L:
  731. seq_printf(m, "Way1,Way3 Locked-Down\n");
  732. break;
  733. case WAY013_L:
  734. seq_printf(m, "Way 0,Way1,Way3 Locked-Down\n");
  735. break;
  736. case WAY32_L:
  737. seq_printf(m, "Way3,Way2 Locked-Down\n");
  738. break;
  739. case WAY320_L:
  740. seq_printf(m, "Way3,Way2,Way0 Locked-Down\n");
  741. break;
  742. case WAY321_L:
  743. seq_printf(m, "Way3,Way2,Way1 Locked-Down\n");
  744. break;
  745. case WAYALL_L:
  746. seq_printf(m, "All Ways are locked\n");
  747. break;
  748. default:
  749. seq_printf(m, "No Ways are locked\n");
  750. }
  751. #endif
  752. return 0;
  753. }
  754. static void *c_start(struct seq_file *m, loff_t *pos)
  755. {
  756. return *pos < NR_CPUS ? ((void *)0x12345678) : NULL;
  757. }
  758. static void *c_next(struct seq_file *m, void *v, loff_t *pos)
  759. {
  760. ++*pos;
  761. return c_start(m, pos);
  762. }
  763. static void c_stop(struct seq_file *m, void *v)
  764. {
  765. }
  766. struct seq_operations cpuinfo_op = {
  767. .start = c_start,
  768. .next = c_next,
  769. .stop = c_stop,
  770. .show = show_cpuinfo,
  771. };
  772. void __init cmdline_init(const char *r0)
  773. {
  774. if (r0)
  775. strncpy(command_line, r0, COMMAND_LINE_SIZE);
  776. }