setup.c 23 KB

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