setup.c 24 KB

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