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