setup.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904
  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. unsigned long memory_start, memory_end, physical_mem_end;
  43. unsigned long reserved_mem_dcache_on;
  44. unsigned long reserved_mem_icache_on;
  45. EXPORT_SYMBOL(memory_start);
  46. EXPORT_SYMBOL(memory_end);
  47. EXPORT_SYMBOL(physical_mem_end);
  48. EXPORT_SYMBOL(_ramend);
  49. #ifdef CONFIG_MTD_UCLINUX
  50. unsigned long memory_mtd_end, memory_mtd_start, mtd_size;
  51. unsigned long _ebss;
  52. EXPORT_SYMBOL(memory_mtd_end);
  53. EXPORT_SYMBOL(memory_mtd_start);
  54. EXPORT_SYMBOL(mtd_size);
  55. #endif
  56. char command_line[COMMAND_LINE_SIZE];
  57. #if defined(CONFIG_BLKFIN_DCACHE) || defined(CONFIG_BLKFIN_CACHE)
  58. static void generate_cpl_tables(void);
  59. #endif
  60. void __init bf53x_cache_init(void)
  61. {
  62. #if defined(CONFIG_BLKFIN_DCACHE) || defined(CONFIG_BLKFIN_CACHE)
  63. generate_cpl_tables();
  64. #endif
  65. #ifdef CONFIG_BLKFIN_CACHE
  66. bfin_icache_init();
  67. printk(KERN_INFO "Instruction Cache Enabled\n");
  68. #endif
  69. #ifdef CONFIG_BLKFIN_DCACHE
  70. bfin_dcache_init();
  71. printk(KERN_INFO "Data Cache Enabled"
  72. # if defined CONFIG_BLKFIN_WB
  73. " (write-back)"
  74. # elif defined CONFIG_BLKFIN_WT
  75. " (write-through)"
  76. # endif
  77. "\n");
  78. #endif
  79. }
  80. void bf53x_relocate_l1_mem(void)
  81. {
  82. unsigned long l1_code_length;
  83. unsigned long l1_data_a_length;
  84. unsigned long l1_data_b_length;
  85. l1_code_length = _etext_l1 - _stext_l1;
  86. if (l1_code_length > L1_CODE_LENGTH)
  87. l1_code_length = L1_CODE_LENGTH;
  88. /* cannot complain as printk is not available as yet.
  89. * But we can continue booting and complain later!
  90. */
  91. /* Copy _stext_l1 to _etext_l1 to L1 instruction SRAM */
  92. dma_memcpy(_stext_l1, _l1_lma_start, l1_code_length);
  93. l1_data_a_length = _ebss_l1 - _sdata_l1;
  94. if (l1_data_a_length > L1_DATA_A_LENGTH)
  95. l1_data_a_length = L1_DATA_A_LENGTH;
  96. /* Copy _sdata_l1 to _ebss_l1 to L1 data bank A SRAM */
  97. dma_memcpy(_sdata_l1, _l1_lma_start + l1_code_length, l1_data_a_length);
  98. l1_data_b_length = _ebss_b_l1 - _sdata_b_l1;
  99. if (l1_data_b_length > L1_DATA_B_LENGTH)
  100. l1_data_b_length = L1_DATA_B_LENGTH;
  101. /* Copy _sdata_b_l1 to _ebss_b_l1 to L1 data bank B SRAM */
  102. dma_memcpy(_sdata_b_l1, _l1_lma_start + l1_code_length +
  103. l1_data_a_length, l1_data_b_length);
  104. }
  105. /*
  106. * Initial parsing of the command line. Currently, we support:
  107. * - Controlling the linux memory size: mem=xxx[KMG]
  108. * - Controlling the physical memory size: max_mem=xxx[KMG][$][#]
  109. * $ -> reserved memory is dcacheable
  110. * # -> reserved memory is icacheable
  111. */
  112. static __init void parse_cmdline_early(char *cmdline_p)
  113. {
  114. char c = ' ', *to = cmdline_p;
  115. unsigned int memsize;
  116. for (;;) {
  117. if (c == ' ') {
  118. if (!memcmp(to, "mem=", 4)) {
  119. to += 4;
  120. memsize = memparse(to, &to);
  121. if (memsize)
  122. _ramend = memsize;
  123. } else if (!memcmp(to, "max_mem=", 8)) {
  124. to += 8;
  125. memsize = memparse(to, &to);
  126. if (memsize) {
  127. physical_mem_end = memsize;
  128. if (*to != ' ') {
  129. if (*to == '$'
  130. || *(to + 1) == '$')
  131. reserved_mem_dcache_on =
  132. 1;
  133. if (*to == '#'
  134. || *(to + 1) == '#')
  135. reserved_mem_icache_on =
  136. 1;
  137. }
  138. }
  139. }
  140. }
  141. c = *(to++);
  142. if (!c)
  143. break;
  144. }
  145. }
  146. void __init setup_arch(char **cmdline_p)
  147. {
  148. int bootmap_size;
  149. unsigned long l1_length, sclk, cclk;
  150. #ifdef CONFIG_MTD_UCLINUX
  151. unsigned long mtd_phys = 0;
  152. #endif
  153. #ifdef CONFIG_DUMMY_CONSOLE
  154. conswitchp = &dummy_con;
  155. #endif
  156. cclk = get_cclk();
  157. sclk = get_sclk();
  158. #if !defined(CONFIG_BFIN_KERNEL_CLOCK) && defined(ANOMALY_05000273)
  159. if (cclk == sclk)
  160. panic("ANOMALY 05000273, SCLK can not be same as CCLK");
  161. #endif
  162. #if defined(ANOMALY_05000266)
  163. bfin_read_IMDMA_D0_IRQ_STATUS();
  164. bfin_read_IMDMA_D1_IRQ_STATUS();
  165. #endif
  166. #ifdef DEBUG_SERIAL_EARLY_INIT
  167. bfin_console_init(); /* early console registration */
  168. /* this give a chance to get printk() working before crash. */
  169. #endif
  170. #if defined(CONFIG_CHR_DEV_FLASH) || defined(CONFIG_BLK_DEV_FLASH)
  171. /* we need to initialize the Flashrom device here since we might
  172. * do things with flash early on in the boot
  173. */
  174. flash_probe();
  175. #endif
  176. #if defined(CONFIG_CMDLINE_BOOL)
  177. memset(command_line, 0, sizeof(command_line));
  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 " init = 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 " bss = 0x%p-0x%p\n"
  283. KERN_INFO " available = 0x%p-0x%p\n"
  284. #ifdef CONFIG_MTD_UCLINUX
  285. KERN_INFO " rootfs = 0x%p-0x%p\n"
  286. #endif
  287. #if DMA_UNCACHED_REGION > 0
  288. KERN_INFO " DMA Zone = 0x%p-0x%p\n"
  289. #endif
  290. , _stext, _etext,
  291. __init_begin, __init_end,
  292. _sdata, _edata,
  293. (void*)&init_thread_union, (void*)((int)(&init_thread_union) + 0x2000),
  294. __bss_start, __bss_stop,
  295. (void*)_ramstart, (void*)memory_end
  296. #ifdef CONFIG_MTD_UCLINUX
  297. , (void*)memory_mtd_start, (void*)(memory_mtd_start + mtd_size)
  298. #endif
  299. #if DMA_UNCACHED_REGION > 0
  300. , (void*)(_ramend - DMA_UNCACHED_REGION), (void*)(_ramend)
  301. #endif
  302. );
  303. /*
  304. * give all the memory to the bootmap allocator, tell it to put the
  305. * boot mem_map at the start of memory
  306. */
  307. bootmap_size = init_bootmem_node(NODE_DATA(0), memory_start >> PAGE_SHIFT, /* map goes here */
  308. PAGE_OFFSET >> PAGE_SHIFT,
  309. memory_end >> PAGE_SHIFT);
  310. /*
  311. * free the usable memory, we have to make sure we do not free
  312. * the bootmem bitmap so we then reserve it after freeing it :-)
  313. */
  314. free_bootmem(memory_start, memory_end - memory_start);
  315. reserve_bootmem(memory_start, bootmap_size);
  316. /*
  317. * get kmalloc into gear
  318. */
  319. paging_init();
  320. /* check the size of the l1 area */
  321. l1_length = _etext_l1 - _stext_l1;
  322. if (l1_length > L1_CODE_LENGTH)
  323. panic("L1 memory overflow\n");
  324. l1_length = _ebss_l1 - _sdata_l1;
  325. if (l1_length > L1_DATA_A_LENGTH)
  326. panic("L1 memory overflow\n");
  327. bf53x_cache_init();
  328. #if defined(CONFIG_SMC91X) || defined(CONFIG_SMC91X_MODULE)
  329. # if defined(CONFIG_BFIN_SHARED_FLASH_ENET) && defined(CONFIG_BFIN533_STAMP)
  330. /* setup BF533_STAMP CPLD to route AMS3 to Ethernet MAC */
  331. bfin_write_FIO_DIR(bfin_read_FIO_DIR() | (1 << CONFIG_ENET_FLASH_PIN));
  332. bfin_write_FIO_FLAG_S(1 << CONFIG_ENET_FLASH_PIN);
  333. SSYNC();
  334. # endif
  335. # if defined (CONFIG_BFIN561_EZKIT)
  336. bfin_write_FIO0_DIR(bfin_read_FIO0_DIR() | (1 << 12));
  337. SSYNC();
  338. # endif /* defined (CONFIG_BFIN561_EZKIT) */
  339. #endif
  340. printk(KERN_INFO "Hardware Trace Enabled\n");
  341. bfin_write_TBUFCTL(0x03);
  342. }
  343. #if defined(CONFIG_BF561)
  344. static struct cpu cpu[2];
  345. #else
  346. static struct cpu cpu[1];
  347. #endif
  348. static int __init topology_init(void)
  349. {
  350. #if defined (CONFIG_BF561)
  351. register_cpu(&cpu[0], 0);
  352. register_cpu(&cpu[1], 1);
  353. return 0;
  354. #else
  355. return register_cpu(cpu, 0);
  356. #endif
  357. }
  358. subsys_initcall(topology_init);
  359. #if defined(CONFIG_BLKFIN_DCACHE) || defined(CONFIG_BLKFIN_CACHE)
  360. u16 lock_kernel_check(u32 start, u32 end)
  361. {
  362. if ((start <= (u32) _stext && end >= (u32) _end)
  363. || (start >= (u32) _stext && end <= (u32) _end))
  364. return IN_KERNEL;
  365. return 0;
  366. }
  367. static unsigned short __init
  368. fill_cplbtab(struct cplb_tab *table,
  369. unsigned long start, unsigned long end,
  370. unsigned long block_size, unsigned long cplb_data)
  371. {
  372. int i;
  373. switch (block_size) {
  374. case SIZE_4M:
  375. i = 3;
  376. break;
  377. case SIZE_1M:
  378. i = 2;
  379. break;
  380. case SIZE_4K:
  381. i = 1;
  382. break;
  383. case SIZE_1K:
  384. default:
  385. i = 0;
  386. break;
  387. }
  388. cplb_data = (cplb_data & ~(3 << 16)) | (i << 16);
  389. while ((start < end) && (table->pos < table->size)) {
  390. table->tab[table->pos++] = start;
  391. if (lock_kernel_check(start, start + block_size) == IN_KERNEL)
  392. table->tab[table->pos++] =
  393. cplb_data | CPLB_LOCK | CPLB_DIRTY;
  394. else
  395. table->tab[table->pos++] = cplb_data;
  396. start += block_size;
  397. }
  398. return 0;
  399. }
  400. static unsigned short __init
  401. close_cplbtab(struct cplb_tab *table)
  402. {
  403. while (table->pos < table->size) {
  404. table->tab[table->pos++] = 0;
  405. table->tab[table->pos++] = 0; /* !CPLB_VALID */
  406. }
  407. return 0;
  408. }
  409. static void __init generate_cpl_tables(void)
  410. {
  411. u16 i, j, process;
  412. u32 a_start, a_end, as, ae, as_1m;
  413. struct cplb_tab *t_i = NULL;
  414. struct cplb_tab *t_d = NULL;
  415. struct s_cplb cplb;
  416. cplb.init_i.size = MAX_CPLBS;
  417. cplb.init_d.size = MAX_CPLBS;
  418. cplb.switch_i.size = MAX_SWITCH_I_CPLBS;
  419. cplb.switch_d.size = MAX_SWITCH_D_CPLBS;
  420. cplb.init_i.pos = 0;
  421. cplb.init_d.pos = 0;
  422. cplb.switch_i.pos = 0;
  423. cplb.switch_d.pos = 0;
  424. cplb.init_i.tab = icplb_table;
  425. cplb.init_d.tab = dcplb_table;
  426. cplb.switch_i.tab = ipdt_table;
  427. cplb.switch_d.tab = dpdt_table;
  428. cplb_data[SDRAM_KERN].end = memory_end;
  429. #ifdef CONFIG_MTD_UCLINUX
  430. cplb_data[SDRAM_RAM_MTD].start = memory_mtd_start;
  431. cplb_data[SDRAM_RAM_MTD].end = memory_mtd_start + mtd_size;
  432. cplb_data[SDRAM_RAM_MTD].valid = mtd_size > 0;
  433. # if defined(CONFIG_ROMFS_FS)
  434. cplb_data[SDRAM_RAM_MTD].attr |= I_CPLB;
  435. /*
  436. * The ROMFS_FS size is often not multiple of 1MB.
  437. * This can cause multiple CPLB sets covering the same memory area.
  438. * This will then cause multiple CPLB hit exceptions.
  439. * Workaround: We ensure a contiguous memory area by extending the kernel
  440. * memory section over the mtd section.
  441. * For ROMFS_FS memory must be covered with ICPLBs anyways.
  442. * So there is no difference between kernel and mtd memory setup.
  443. */
  444. cplb_data[SDRAM_KERN].end = memory_mtd_start + mtd_size;;
  445. cplb_data[SDRAM_RAM_MTD].valid = 0;
  446. # endif
  447. #else
  448. cplb_data[SDRAM_RAM_MTD].valid = 0;
  449. #endif
  450. cplb_data[SDRAM_DMAZ].start = _ramend - DMA_UNCACHED_REGION;
  451. cplb_data[SDRAM_DMAZ].end = _ramend;
  452. cplb_data[RES_MEM].start = _ramend;
  453. cplb_data[RES_MEM].end = physical_mem_end;
  454. if (reserved_mem_dcache_on)
  455. cplb_data[RES_MEM].d_conf = SDRAM_DGENERIC;
  456. else
  457. cplb_data[RES_MEM].d_conf = SDRAM_DNON_CHBL;
  458. if (reserved_mem_icache_on)
  459. cplb_data[RES_MEM].i_conf = SDRAM_IGENERIC;
  460. else
  461. cplb_data[RES_MEM].i_conf = SDRAM_INON_CHBL;
  462. for (i = ZERO_P; i <= L2_MEM; i++) {
  463. if (cplb_data[i].valid) {
  464. as_1m = cplb_data[i].start % SIZE_1M;
  465. /* We need to make sure all sections are properly 1M aligned
  466. * However between Kernel Memory and the Kernel mtd section, depending on the
  467. * rootfs size, there can be overlapping memory areas.
  468. */
  469. if (as_1m && i!=L1I_MEM && i!=L1D_MEM) {
  470. #ifdef CONFIG_MTD_UCLINUX
  471. if (i == SDRAM_RAM_MTD) {
  472. if ((cplb_data[SDRAM_KERN].end + 1) > cplb_data[SDRAM_RAM_MTD].start)
  473. cplb_data[SDRAM_RAM_MTD].start = (cplb_data[i].start & (-2*SIZE_1M)) + SIZE_1M;
  474. else
  475. cplb_data[SDRAM_RAM_MTD].start = (cplb_data[i].start & (-2*SIZE_1M));
  476. } else
  477. #endif
  478. printk(KERN_WARNING "Unaligned Start of %s at 0x%X\n",
  479. cplb_data[i].name, cplb_data[i].start);
  480. }
  481. as = cplb_data[i].start % SIZE_4M;
  482. ae = cplb_data[i].end % SIZE_4M;
  483. if (as)
  484. a_start = cplb_data[i].start + (SIZE_4M - (as));
  485. else
  486. a_start = cplb_data[i].start;
  487. a_end = cplb_data[i].end - ae;
  488. for (j = INITIAL_T; j <= SWITCH_T; j++) {
  489. switch (j) {
  490. case INITIAL_T:
  491. if (cplb_data[i].attr & INITIAL_T) {
  492. t_i = &cplb.init_i;
  493. t_d = &cplb.init_d;
  494. process = 1;
  495. } else
  496. process = 0;
  497. break;
  498. case SWITCH_T:
  499. if (cplb_data[i].attr & SWITCH_T) {
  500. t_i = &cplb.switch_i;
  501. t_d = &cplb.switch_d;
  502. process = 1;
  503. } else
  504. process = 0;
  505. break;
  506. default:
  507. process = 0;
  508. break;
  509. }
  510. if (process) {
  511. if (cplb_data[i].attr & I_CPLB) {
  512. if (cplb_data[i].psize) {
  513. fill_cplbtab(t_i,
  514. cplb_data[i].start,
  515. cplb_data[i].end,
  516. cplb_data[i].psize,
  517. cplb_data[i].i_conf);
  518. } else {
  519. /*icplb_table */
  520. #if (defined(CONFIG_BLKFIN_CACHE) && defined(ANOMALY_05000263))
  521. if (i == SDRAM_KERN) {
  522. fill_cplbtab(t_i,
  523. cplb_data[i].start,
  524. cplb_data[i].end,
  525. SIZE_4M,
  526. cplb_data[i].i_conf);
  527. } else
  528. #endif
  529. {
  530. fill_cplbtab(t_i,
  531. cplb_data[i].start,
  532. a_start,
  533. SIZE_1M,
  534. cplb_data[i].i_conf);
  535. fill_cplbtab(t_i,
  536. a_start,
  537. a_end,
  538. SIZE_4M,
  539. cplb_data[i].i_conf);
  540. fill_cplbtab(t_i, a_end,
  541. cplb_data[i].end,
  542. SIZE_1M,
  543. cplb_data[i].i_conf);
  544. }
  545. }
  546. }
  547. if (cplb_data[i].attr & D_CPLB) {
  548. if (cplb_data[i].psize) {
  549. fill_cplbtab(t_d,
  550. cplb_data[i].start,
  551. cplb_data[i].end,
  552. cplb_data[i].psize,
  553. cplb_data[i].d_conf);
  554. } else {
  555. /*dcplb_table*/
  556. fill_cplbtab(t_d,
  557. cplb_data[i].start,
  558. a_start, SIZE_1M,
  559. cplb_data[i].d_conf);
  560. fill_cplbtab(t_d, a_start,
  561. a_end, SIZE_4M,
  562. cplb_data[i].d_conf);
  563. fill_cplbtab(t_d, a_end,
  564. cplb_data[i].end,
  565. SIZE_1M,
  566. cplb_data[i].d_conf);
  567. }
  568. }
  569. }
  570. }
  571. }
  572. }
  573. /* close tables */
  574. close_cplbtab(&cplb.init_i);
  575. close_cplbtab(&cplb.init_d);
  576. cplb.init_i.tab[cplb.init_i.pos] = -1;
  577. cplb.init_d.tab[cplb.init_d.pos] = -1;
  578. cplb.switch_i.tab[cplb.switch_i.pos] = -1;
  579. cplb.switch_d.tab[cplb.switch_d.pos] = -1;
  580. }
  581. #endif
  582. static inline u_long get_vco(void)
  583. {
  584. u_long msel;
  585. u_long vco;
  586. msel = (bfin_read_PLL_CTL() >> 9) & 0x3F;
  587. if (0 == msel)
  588. msel = 64;
  589. vco = CONFIG_CLKIN_HZ;
  590. vco >>= (1 & bfin_read_PLL_CTL()); /* DF bit */
  591. vco = msel * vco;
  592. return vco;
  593. }
  594. /*Get the Core clock*/
  595. u_long get_cclk(void)
  596. {
  597. u_long csel, ssel;
  598. if (bfin_read_PLL_STAT() & 0x1)
  599. return CONFIG_CLKIN_HZ;
  600. ssel = bfin_read_PLL_DIV();
  601. csel = ((ssel >> 4) & 0x03);
  602. ssel &= 0xf;
  603. if (ssel && ssel < (1 << csel)) /* SCLK > CCLK */
  604. return get_vco() / ssel;
  605. return get_vco() >> csel;
  606. }
  607. EXPORT_SYMBOL(get_cclk);
  608. /* Get the System clock */
  609. u_long get_sclk(void)
  610. {
  611. u_long ssel;
  612. if (bfin_read_PLL_STAT() & 0x1)
  613. return CONFIG_CLKIN_HZ;
  614. ssel = (bfin_read_PLL_DIV() & 0xf);
  615. if (0 == ssel) {
  616. printk(KERN_WARNING "Invalid System Clock\n");
  617. ssel = 1;
  618. }
  619. return get_vco() / ssel;
  620. }
  621. EXPORT_SYMBOL(get_sclk);
  622. /*
  623. * Get CPU information for use by the procfs.
  624. */
  625. static int show_cpuinfo(struct seq_file *m, void *v)
  626. {
  627. char *cpu, *mmu, *fpu, *name;
  628. uint32_t revid;
  629. u_long cclk = 0, sclk = 0;
  630. u_int dcache_size = 0, dsup_banks = 0;
  631. cpu = CPU;
  632. mmu = "none";
  633. fpu = "none";
  634. revid = bfin_revid();
  635. name = bfin_board_name;
  636. cclk = get_cclk();
  637. sclk = get_sclk();
  638. seq_printf(m, "CPU:\t\tADSP-%s Rev. 0.%d\n"
  639. "MMU:\t\t%s\n"
  640. "FPU:\t\t%s\n"
  641. "Core Clock:\t%9lu Hz\n"
  642. "System Clock:\t%9lu Hz\n"
  643. "BogoMips:\t%lu.%02lu\n"
  644. "Calibration:\t%lu loops\n",
  645. cpu, revid, mmu, fpu,
  646. cclk,
  647. sclk,
  648. (loops_per_jiffy * HZ) / 500000,
  649. ((loops_per_jiffy * HZ) / 5000) % 100,
  650. (loops_per_jiffy * HZ));
  651. seq_printf(m, "Board Name:\t%s\n", name);
  652. seq_printf(m, "Board Memory:\t%ld MB\n", physical_mem_end >> 20);
  653. seq_printf(m, "Kernel Memory:\t%ld MB\n", (unsigned long)_ramend >> 20);
  654. if (bfin_read_IMEM_CONTROL() & (ENICPLB | IMC))
  655. seq_printf(m, "I-CACHE:\tON\n");
  656. else
  657. seq_printf(m, "I-CACHE:\tOFF\n");
  658. if ((bfin_read_DMEM_CONTROL()) & (ENDCPLB | DMC_ENABLE))
  659. seq_printf(m, "D-CACHE:\tON"
  660. #if defined CONFIG_BLKFIN_WB
  661. " (write-back)"
  662. #elif defined CONFIG_BLKFIN_WT
  663. " (write-through)"
  664. #endif
  665. "\n");
  666. else
  667. seq_printf(m, "D-CACHE:\tOFF\n");
  668. switch(bfin_read_DMEM_CONTROL() & (1 << DMC0_P | 1 << DMC1_P)) {
  669. case ACACHE_BSRAM:
  670. seq_printf(m, "DBANK-A:\tCACHE\n" "DBANK-B:\tSRAM\n");
  671. dcache_size = 16;
  672. dsup_banks = 1;
  673. break;
  674. case ACACHE_BCACHE:
  675. seq_printf(m, "DBANK-A:\tCACHE\n" "DBANK-B:\tCACHE\n");
  676. dcache_size = 32;
  677. dsup_banks = 2;
  678. break;
  679. case ASRAM_BSRAM:
  680. seq_printf(m, "DBANK-A:\tSRAM\n" "DBANK-B:\tSRAM\n");
  681. dcache_size = 0;
  682. dsup_banks = 0;
  683. break;
  684. default:
  685. break;
  686. }
  687. seq_printf(m, "I-CACHE Size:\t%dKB\n", BLKFIN_ICACHESIZE / 1024);
  688. seq_printf(m, "D-CACHE Size:\t%dKB\n", dcache_size);
  689. seq_printf(m, "I-CACHE Setup:\t%d Sub-banks/%d Ways, %d Lines/Way\n",
  690. BLKFIN_ISUBBANKS, BLKFIN_IWAYS, BLKFIN_ILINES);
  691. seq_printf(m,
  692. "D-CACHE Setup:\t%d Super-banks/%d Sub-banks/%d Ways, %d Lines/Way\n",
  693. dsup_banks, BLKFIN_DSUBBANKS, BLKFIN_DWAYS,
  694. BLKFIN_DLINES);
  695. #ifdef CONFIG_BLKFIN_CACHE_LOCK
  696. switch (read_iloc()) {
  697. case WAY0_L:
  698. seq_printf(m, "Way0 Locked-Down\n");
  699. break;
  700. case WAY1_L:
  701. seq_printf(m, "Way1 Locked-Down\n");
  702. break;
  703. case WAY01_L:
  704. seq_printf(m, "Way0,Way1 Locked-Down\n");
  705. break;
  706. case WAY2_L:
  707. seq_printf(m, "Way2 Locked-Down\n");
  708. break;
  709. case WAY02_L:
  710. seq_printf(m, "Way0,Way2 Locked-Down\n");
  711. break;
  712. case WAY12_L:
  713. seq_printf(m, "Way1,Way2 Locked-Down\n");
  714. break;
  715. case WAY012_L:
  716. seq_printf(m, "Way0,Way1 & Way2 Locked-Down\n");
  717. break;
  718. case WAY3_L:
  719. seq_printf(m, "Way3 Locked-Down\n");
  720. break;
  721. case WAY03_L:
  722. seq_printf(m, "Way0,Way3 Locked-Down\n");
  723. break;
  724. case WAY13_L:
  725. seq_printf(m, "Way1,Way3 Locked-Down\n");
  726. break;
  727. case WAY013_L:
  728. seq_printf(m, "Way 0,Way1,Way3 Locked-Down\n");
  729. break;
  730. case WAY32_L:
  731. seq_printf(m, "Way3,Way2 Locked-Down\n");
  732. break;
  733. case WAY320_L:
  734. seq_printf(m, "Way3,Way2,Way0 Locked-Down\n");
  735. break;
  736. case WAY321_L:
  737. seq_printf(m, "Way3,Way2,Way1 Locked-Down\n");
  738. break;
  739. case WAYALL_L:
  740. seq_printf(m, "All Ways are locked\n");
  741. break;
  742. default:
  743. seq_printf(m, "No Ways are locked\n");
  744. }
  745. #endif
  746. return 0;
  747. }
  748. static void *c_start(struct seq_file *m, loff_t *pos)
  749. {
  750. return *pos < NR_CPUS ? ((void *)0x12345678) : NULL;
  751. }
  752. static void *c_next(struct seq_file *m, void *v, loff_t *pos)
  753. {
  754. ++*pos;
  755. return c_start(m, pos);
  756. }
  757. static void c_stop(struct seq_file *m, void *v)
  758. {
  759. }
  760. struct seq_operations cpuinfo_op = {
  761. .start = c_start,
  762. .next = c_next,
  763. .stop = c_stop,
  764. .show = show_cpuinfo,
  765. };
  766. void cmdline_init(unsigned long r0)
  767. {
  768. if (r0)
  769. strncpy(command_line, (char *)r0, COMMAND_LINE_SIZE);
  770. }