setup.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917
  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. if (bfin_compiled_revid() == 0xffff)
  262. printk(KERN_INFO "Compiled for ADSP-%s Rev any\n", CPU);
  263. else if (bfin_compiled_revid() == -1)
  264. printk(KERN_INFO "Compiled for ADSP-%s Rev none\n", CPU);
  265. else
  266. printk(KERN_INFO "Compiled for ADSP-%s Rev 0.%d\n", CPU, bfin_compiled_revid());
  267. if (bfin_revid() != bfin_compiled_revid()) {
  268. if (bfin_compiled_revid() == -1)
  269. printk(KERN_ERR "Warning: Compiled for Rev none, but running on Rev %d\n",
  270. bfin_revid());
  271. else if (bfin_compiled_revid() != 0xffff)
  272. printk(KERN_ERR "Warning: Compiled for Rev %d, but running on Rev %d\n",
  273. bfin_compiled_revid(), bfin_revid());
  274. }
  275. if (bfin_revid() < SUPPORTED_REVID)
  276. printk(KERN_ERR "Warning: Unsupported Chip Revision ADSP-%s Rev 0.%d detected\n",
  277. CPU, bfin_revid());
  278. printk(KERN_INFO "Blackfin Linux support by http://blackfin.uclinux.org/\n");
  279. printk(KERN_INFO "Processor Speed: %lu MHz core clock and %lu Mhz System Clock\n",
  280. cclk / 1000000, sclk / 1000000);
  281. #if defined(ANOMALY_05000273)
  282. if ((cclk >> 1) <= sclk)
  283. printk("\n\n\nANOMALY_05000273: CCLK must be >= 2*SCLK !!!\n\n\n");
  284. #endif
  285. printk(KERN_INFO "Board Memory: %ldMB\n", physical_mem_end >> 20);
  286. printk(KERN_INFO "Kernel Managed Memory: %ldMB\n", _ramend >> 20);
  287. printk(KERN_INFO "Memory map:\n"
  288. KERN_INFO " text = 0x%p-0x%p\n"
  289. KERN_INFO " rodata = 0x%p-0x%p\n"
  290. KERN_INFO " data = 0x%p-0x%p\n"
  291. KERN_INFO " stack = 0x%p-0x%p\n"
  292. KERN_INFO " init = 0x%p-0x%p\n"
  293. KERN_INFO " bss = 0x%p-0x%p\n"
  294. KERN_INFO " available = 0x%p-0x%p\n"
  295. #ifdef CONFIG_MTD_UCLINUX
  296. KERN_INFO " rootfs = 0x%p-0x%p\n"
  297. #endif
  298. #if DMA_UNCACHED_REGION > 0
  299. KERN_INFO " DMA Zone = 0x%p-0x%p\n"
  300. #endif
  301. , _stext, _etext,
  302. __start_rodata, __end_rodata,
  303. _sdata, _edata,
  304. (void*)&init_thread_union, (void*)((int)(&init_thread_union) + 0x2000),
  305. __init_begin, __init_end,
  306. __bss_start, __bss_stop,
  307. (void*)_ramstart, (void*)memory_end
  308. #ifdef CONFIG_MTD_UCLINUX
  309. , (void*)memory_mtd_start, (void*)(memory_mtd_start + mtd_size)
  310. #endif
  311. #if DMA_UNCACHED_REGION > 0
  312. , (void*)(_ramend - DMA_UNCACHED_REGION), (void*)(_ramend)
  313. #endif
  314. );
  315. /*
  316. * give all the memory to the bootmap allocator, tell it to put the
  317. * boot mem_map at the start of memory
  318. */
  319. bootmap_size = init_bootmem_node(NODE_DATA(0), memory_start >> PAGE_SHIFT, /* map goes here */
  320. PAGE_OFFSET >> PAGE_SHIFT,
  321. memory_end >> PAGE_SHIFT);
  322. /*
  323. * free the usable memory, we have to make sure we do not free
  324. * the bootmem bitmap so we then reserve it after freeing it :-)
  325. */
  326. free_bootmem(memory_start, memory_end - memory_start);
  327. reserve_bootmem(memory_start, bootmap_size);
  328. /*
  329. * get kmalloc into gear
  330. */
  331. paging_init();
  332. /* check the size of the l1 area */
  333. l1_length = _etext_l1 - _stext_l1;
  334. if (l1_length > L1_CODE_LENGTH)
  335. panic("L1 memory overflow\n");
  336. l1_length = _ebss_l1 - _sdata_l1;
  337. if (l1_length > L1_DATA_A_LENGTH)
  338. panic("L1 memory overflow\n");
  339. #ifdef BF561_FAMILY
  340. _bfin_swrst = bfin_read_SICA_SWRST();
  341. #else
  342. _bfin_swrst = bfin_read_SWRST();
  343. #endif
  344. bf53x_cache_init();
  345. printk(KERN_INFO "Hardware Trace Enabled\n");
  346. bfin_write_TBUFCTL(0x03);
  347. }
  348. static int __init topology_init(void)
  349. {
  350. #if defined (CONFIG_BF561)
  351. static struct cpu cpu[2];
  352. register_cpu(&cpu[0], 0);
  353. register_cpu(&cpu[1], 1);
  354. return 0;
  355. #else
  356. static struct cpu cpu[1];
  357. return register_cpu(cpu, 0);
  358. #endif
  359. }
  360. subsys_initcall(topology_init);
  361. #if defined(CONFIG_BLKFIN_DCACHE) || defined(CONFIG_BLKFIN_CACHE)
  362. static u16 __init lock_kernel_check(u32 start, u32 end)
  363. {
  364. if ((start <= (u32) _stext && end >= (u32) _end)
  365. || (start >= (u32) _stext && end <= (u32) _end))
  366. return IN_KERNEL;
  367. return 0;
  368. }
  369. static unsigned short __init
  370. fill_cplbtab(struct cplb_tab *table,
  371. unsigned long start, unsigned long end,
  372. unsigned long block_size, unsigned long cplb_data)
  373. {
  374. int i;
  375. switch (block_size) {
  376. case SIZE_4M:
  377. i = 3;
  378. break;
  379. case SIZE_1M:
  380. i = 2;
  381. break;
  382. case SIZE_4K:
  383. i = 1;
  384. break;
  385. case SIZE_1K:
  386. default:
  387. i = 0;
  388. break;
  389. }
  390. cplb_data = (cplb_data & ~(3 << 16)) | (i << 16);
  391. while ((start < end) && (table->pos < table->size)) {
  392. table->tab[table->pos++] = start;
  393. if (lock_kernel_check(start, start + block_size) == IN_KERNEL)
  394. table->tab[table->pos++] =
  395. cplb_data | CPLB_LOCK | CPLB_DIRTY;
  396. else
  397. table->tab[table->pos++] = cplb_data;
  398. start += block_size;
  399. }
  400. return 0;
  401. }
  402. static unsigned short __init
  403. close_cplbtab(struct cplb_tab *table)
  404. {
  405. while (table->pos < table->size) {
  406. table->tab[table->pos++] = 0;
  407. table->tab[table->pos++] = 0; /* !CPLB_VALID */
  408. }
  409. return 0;
  410. }
  411. /* helper function */
  412. static void __fill_code_cplbtab(struct cplb_tab *t, int i,
  413. u32 a_start, u32 a_end)
  414. {
  415. if (cplb_data[i].psize) {
  416. fill_cplbtab(t,
  417. cplb_data[i].start,
  418. cplb_data[i].end,
  419. cplb_data[i].psize,
  420. cplb_data[i].i_conf);
  421. } else {
  422. #if (defined(CONFIG_BLKFIN_CACHE) && defined(ANOMALY_05000263))
  423. if (i == SDRAM_KERN) {
  424. fill_cplbtab(t,
  425. cplb_data[i].start,
  426. cplb_data[i].end,
  427. SIZE_4M,
  428. cplb_data[i].i_conf);
  429. } else
  430. #endif
  431. {
  432. fill_cplbtab(t,
  433. cplb_data[i].start,
  434. a_start,
  435. SIZE_1M,
  436. cplb_data[i].i_conf);
  437. fill_cplbtab(t,
  438. a_start,
  439. a_end,
  440. SIZE_4M,
  441. cplb_data[i].i_conf);
  442. fill_cplbtab(t, a_end,
  443. cplb_data[i].end,
  444. SIZE_1M,
  445. cplb_data[i].i_conf);
  446. }
  447. }
  448. }
  449. static void __fill_data_cplbtab(struct cplb_tab *t, int i,
  450. u32 a_start, u32 a_end)
  451. {
  452. if (cplb_data[i].psize) {
  453. fill_cplbtab(t,
  454. cplb_data[i].start,
  455. cplb_data[i].end,
  456. cplb_data[i].psize,
  457. cplb_data[i].d_conf);
  458. } else {
  459. fill_cplbtab(t,
  460. cplb_data[i].start,
  461. a_start, SIZE_1M,
  462. cplb_data[i].d_conf);
  463. fill_cplbtab(t, a_start,
  464. a_end, SIZE_4M,
  465. cplb_data[i].d_conf);
  466. fill_cplbtab(t, a_end,
  467. cplb_data[i].end,
  468. SIZE_1M,
  469. cplb_data[i].d_conf);
  470. }
  471. }
  472. static void __init generate_cpl_tables(void)
  473. {
  474. u16 i, j, process;
  475. u32 a_start, a_end, as, ae, as_1m;
  476. struct cplb_tab *t_i = NULL;
  477. struct cplb_tab *t_d = NULL;
  478. struct s_cplb cplb;
  479. cplb.init_i.size = MAX_CPLBS;
  480. cplb.init_d.size = MAX_CPLBS;
  481. cplb.switch_i.size = MAX_SWITCH_I_CPLBS;
  482. cplb.switch_d.size = MAX_SWITCH_D_CPLBS;
  483. cplb.init_i.pos = 0;
  484. cplb.init_d.pos = 0;
  485. cplb.switch_i.pos = 0;
  486. cplb.switch_d.pos = 0;
  487. cplb.init_i.tab = icplb_table;
  488. cplb.init_d.tab = dcplb_table;
  489. cplb.switch_i.tab = ipdt_table;
  490. cplb.switch_d.tab = dpdt_table;
  491. cplb_data[SDRAM_KERN].end = memory_end;
  492. #ifdef CONFIG_MTD_UCLINUX
  493. cplb_data[SDRAM_RAM_MTD].start = memory_mtd_start;
  494. cplb_data[SDRAM_RAM_MTD].end = memory_mtd_start + mtd_size;
  495. cplb_data[SDRAM_RAM_MTD].valid = mtd_size > 0;
  496. # if defined(CONFIG_ROMFS_FS)
  497. cplb_data[SDRAM_RAM_MTD].attr |= I_CPLB;
  498. /*
  499. * The ROMFS_FS size is often not multiple of 1MB.
  500. * This can cause multiple CPLB sets covering the same memory area.
  501. * This will then cause multiple CPLB hit exceptions.
  502. * Workaround: We ensure a contiguous memory area by extending the kernel
  503. * memory section over the mtd section.
  504. * For ROMFS_FS memory must be covered with ICPLBs anyways.
  505. * So there is no difference between kernel and mtd memory setup.
  506. */
  507. cplb_data[SDRAM_KERN].end = memory_mtd_start + mtd_size;;
  508. cplb_data[SDRAM_RAM_MTD].valid = 0;
  509. # endif
  510. #else
  511. cplb_data[SDRAM_RAM_MTD].valid = 0;
  512. #endif
  513. cplb_data[SDRAM_DMAZ].start = _ramend - DMA_UNCACHED_REGION;
  514. cplb_data[SDRAM_DMAZ].end = _ramend;
  515. cplb_data[RES_MEM].start = _ramend;
  516. cplb_data[RES_MEM].end = physical_mem_end;
  517. if (reserved_mem_dcache_on)
  518. cplb_data[RES_MEM].d_conf = SDRAM_DGENERIC;
  519. else
  520. cplb_data[RES_MEM].d_conf = SDRAM_DNON_CHBL;
  521. if (reserved_mem_icache_on)
  522. cplb_data[RES_MEM].i_conf = SDRAM_IGENERIC;
  523. else
  524. cplb_data[RES_MEM].i_conf = SDRAM_INON_CHBL;
  525. for (i = ZERO_P; i <= L2_MEM; i++) {
  526. if (!cplb_data[i].valid)
  527. continue;
  528. as_1m = cplb_data[i].start % SIZE_1M;
  529. /*
  530. * We need to make sure all sections are properly 1M aligned
  531. * However between Kernel Memory and the Kernel mtd section,
  532. * depending on the rootfs size, there can be overlapping
  533. * memory areas.
  534. */
  535. if (as_1m && i != L1I_MEM && i != L1D_MEM) {
  536. #ifdef CONFIG_MTD_UCLINUX
  537. if (i == SDRAM_RAM_MTD) {
  538. if ((cplb_data[SDRAM_KERN].end + 1) >
  539. cplb_data[SDRAM_RAM_MTD].start)
  540. cplb_data[SDRAM_RAM_MTD].start =
  541. (cplb_data[i].start &
  542. (-2*SIZE_1M)) + SIZE_1M;
  543. else
  544. cplb_data[SDRAM_RAM_MTD].start =
  545. (cplb_data[i].start &
  546. (-2*SIZE_1M));
  547. } else
  548. #endif
  549. printk(KERN_WARNING
  550. "Unaligned Start of %s at 0x%X\n",
  551. cplb_data[i].name, cplb_data[i].start);
  552. }
  553. as = cplb_data[i].start % SIZE_4M;
  554. ae = cplb_data[i].end % SIZE_4M;
  555. if (as)
  556. a_start = cplb_data[i].start + (SIZE_4M - (as));
  557. else
  558. a_start = cplb_data[i].start;
  559. a_end = cplb_data[i].end - ae;
  560. for (j = INITIAL_T; j <= SWITCH_T; j++) {
  561. switch (j) {
  562. case INITIAL_T:
  563. if (cplb_data[i].attr & INITIAL_T) {
  564. t_i = &cplb.init_i;
  565. t_d = &cplb.init_d;
  566. process = 1;
  567. } else
  568. process = 0;
  569. break;
  570. case SWITCH_T:
  571. if (cplb_data[i].attr & SWITCH_T) {
  572. t_i = &cplb.switch_i;
  573. t_d = &cplb.switch_d;
  574. process = 1;
  575. } else
  576. process = 0;
  577. break;
  578. default:
  579. process = 0;
  580. break;
  581. }
  582. if (!process)
  583. continue;
  584. if (cplb_data[i].attr & I_CPLB)
  585. __fill_code_cplbtab(t_i, i, a_start, a_end);
  586. if (cplb_data[i].attr & D_CPLB)
  587. __fill_data_cplbtab(t_d, i, a_start, a_end);
  588. }
  589. }
  590. /* close tables */
  591. close_cplbtab(&cplb.init_i);
  592. close_cplbtab(&cplb.init_d);
  593. cplb.init_i.tab[cplb.init_i.pos] = -1;
  594. cplb.init_d.tab[cplb.init_d.pos] = -1;
  595. cplb.switch_i.tab[cplb.switch_i.pos] = -1;
  596. cplb.switch_d.tab[cplb.switch_d.pos] = -1;
  597. }
  598. #endif
  599. static u_long get_vco(void)
  600. {
  601. u_long msel;
  602. u_long vco;
  603. msel = (bfin_read_PLL_CTL() >> 9) & 0x3F;
  604. if (0 == msel)
  605. msel = 64;
  606. vco = CONFIG_CLKIN_HZ;
  607. vco >>= (1 & bfin_read_PLL_CTL()); /* DF bit */
  608. vco = msel * vco;
  609. return vco;
  610. }
  611. /*Get the Core clock*/
  612. u_long get_cclk(void)
  613. {
  614. u_long csel, ssel;
  615. if (bfin_read_PLL_STAT() & 0x1)
  616. return CONFIG_CLKIN_HZ;
  617. ssel = bfin_read_PLL_DIV();
  618. csel = ((ssel >> 4) & 0x03);
  619. ssel &= 0xf;
  620. if (ssel && ssel < (1 << csel)) /* SCLK > CCLK */
  621. return get_vco() / ssel;
  622. return get_vco() >> csel;
  623. }
  624. EXPORT_SYMBOL(get_cclk);
  625. /* Get the System clock */
  626. u_long get_sclk(void)
  627. {
  628. u_long ssel;
  629. if (bfin_read_PLL_STAT() & 0x1)
  630. return CONFIG_CLKIN_HZ;
  631. ssel = (bfin_read_PLL_DIV() & 0xf);
  632. if (0 == ssel) {
  633. printk(KERN_WARNING "Invalid System Clock\n");
  634. ssel = 1;
  635. }
  636. return get_vco() / ssel;
  637. }
  638. EXPORT_SYMBOL(get_sclk);
  639. /*
  640. * Get CPU information for use by the procfs.
  641. */
  642. static int show_cpuinfo(struct seq_file *m, void *v)
  643. {
  644. char *cpu, *mmu, *fpu, *name;
  645. uint32_t revid;
  646. u_long cclk = 0, sclk = 0;
  647. u_int dcache_size = 0, dsup_banks = 0;
  648. cpu = CPU;
  649. mmu = "none";
  650. fpu = "none";
  651. revid = bfin_revid();
  652. name = bfin_board_name;
  653. cclk = get_cclk();
  654. sclk = get_sclk();
  655. seq_printf(m, "CPU:\t\tADSP-%s Rev. 0.%d\n"
  656. "MMU:\t\t%s\n"
  657. "FPU:\t\t%s\n"
  658. "Core Clock:\t%9lu Hz\n"
  659. "System Clock:\t%9lu Hz\n"
  660. "BogoMips:\t%lu.%02lu\n"
  661. "Calibration:\t%lu loops\n",
  662. cpu, revid, mmu, fpu,
  663. cclk,
  664. sclk,
  665. (loops_per_jiffy * HZ) / 500000,
  666. ((loops_per_jiffy * HZ) / 5000) % 100,
  667. (loops_per_jiffy * HZ));
  668. seq_printf(m, "Board Name:\t%s\n", name);
  669. seq_printf(m, "Board Memory:\t%ld MB\n", physical_mem_end >> 20);
  670. seq_printf(m, "Kernel Memory:\t%ld MB\n", (unsigned long)_ramend >> 20);
  671. if (bfin_read_IMEM_CONTROL() & (ENICPLB | IMC))
  672. seq_printf(m, "I-CACHE:\tON\n");
  673. else
  674. seq_printf(m, "I-CACHE:\tOFF\n");
  675. if ((bfin_read_DMEM_CONTROL()) & (ENDCPLB | DMC_ENABLE))
  676. seq_printf(m, "D-CACHE:\tON"
  677. #if defined CONFIG_BLKFIN_WB
  678. " (write-back)"
  679. #elif defined CONFIG_BLKFIN_WT
  680. " (write-through)"
  681. #endif
  682. "\n");
  683. else
  684. seq_printf(m, "D-CACHE:\tOFF\n");
  685. switch(bfin_read_DMEM_CONTROL() & (1 << DMC0_P | 1 << DMC1_P)) {
  686. case ACACHE_BSRAM:
  687. seq_printf(m, "DBANK-A:\tCACHE\n" "DBANK-B:\tSRAM\n");
  688. dcache_size = 16;
  689. dsup_banks = 1;
  690. break;
  691. case ACACHE_BCACHE:
  692. seq_printf(m, "DBANK-A:\tCACHE\n" "DBANK-B:\tCACHE\n");
  693. dcache_size = 32;
  694. dsup_banks = 2;
  695. break;
  696. case ASRAM_BSRAM:
  697. seq_printf(m, "DBANK-A:\tSRAM\n" "DBANK-B:\tSRAM\n");
  698. dcache_size = 0;
  699. dsup_banks = 0;
  700. break;
  701. default:
  702. break;
  703. }
  704. seq_printf(m, "I-CACHE Size:\t%dKB\n", BLKFIN_ICACHESIZE / 1024);
  705. seq_printf(m, "D-CACHE Size:\t%dKB\n", dcache_size);
  706. seq_printf(m, "I-CACHE Setup:\t%d Sub-banks/%d Ways, %d Lines/Way\n",
  707. BLKFIN_ISUBBANKS, BLKFIN_IWAYS, BLKFIN_ILINES);
  708. seq_printf(m,
  709. "D-CACHE Setup:\t%d Super-banks/%d Sub-banks/%d Ways, %d Lines/Way\n",
  710. dsup_banks, BLKFIN_DSUBBANKS, BLKFIN_DWAYS,
  711. BLKFIN_DLINES);
  712. #ifdef CONFIG_BLKFIN_CACHE_LOCK
  713. switch (read_iloc()) {
  714. case WAY0_L:
  715. seq_printf(m, "Way0 Locked-Down\n");
  716. break;
  717. case WAY1_L:
  718. seq_printf(m, "Way1 Locked-Down\n");
  719. break;
  720. case WAY01_L:
  721. seq_printf(m, "Way0,Way1 Locked-Down\n");
  722. break;
  723. case WAY2_L:
  724. seq_printf(m, "Way2 Locked-Down\n");
  725. break;
  726. case WAY02_L:
  727. seq_printf(m, "Way0,Way2 Locked-Down\n");
  728. break;
  729. case WAY12_L:
  730. seq_printf(m, "Way1,Way2 Locked-Down\n");
  731. break;
  732. case WAY012_L:
  733. seq_printf(m, "Way0,Way1 & Way2 Locked-Down\n");
  734. break;
  735. case WAY3_L:
  736. seq_printf(m, "Way3 Locked-Down\n");
  737. break;
  738. case WAY03_L:
  739. seq_printf(m, "Way0,Way3 Locked-Down\n");
  740. break;
  741. case WAY13_L:
  742. seq_printf(m, "Way1,Way3 Locked-Down\n");
  743. break;
  744. case WAY013_L:
  745. seq_printf(m, "Way 0,Way1,Way3 Locked-Down\n");
  746. break;
  747. case WAY32_L:
  748. seq_printf(m, "Way3,Way2 Locked-Down\n");
  749. break;
  750. case WAY320_L:
  751. seq_printf(m, "Way3,Way2,Way0 Locked-Down\n");
  752. break;
  753. case WAY321_L:
  754. seq_printf(m, "Way3,Way2,Way1 Locked-Down\n");
  755. break;
  756. case WAYALL_L:
  757. seq_printf(m, "All Ways are locked\n");
  758. break;
  759. default:
  760. seq_printf(m, "No Ways are locked\n");
  761. }
  762. #endif
  763. return 0;
  764. }
  765. static void *c_start(struct seq_file *m, loff_t *pos)
  766. {
  767. return *pos < NR_CPUS ? ((void *)0x12345678) : NULL;
  768. }
  769. static void *c_next(struct seq_file *m, void *v, loff_t *pos)
  770. {
  771. ++*pos;
  772. return c_start(m, pos);
  773. }
  774. static void c_stop(struct seq_file *m, void *v)
  775. {
  776. }
  777. struct seq_operations cpuinfo_op = {
  778. .start = c_start,
  779. .next = c_next,
  780. .stop = c_stop,
  781. .show = show_cpuinfo,
  782. };
  783. void __init cmdline_init(const char *r0)
  784. {
  785. if (r0)
  786. strncpy(command_line, r0, COMMAND_LINE_SIZE);
  787. }