2 * File: arch/blackfin/kernel/setup.c
10 * Copyright 2004-2006 Analog Devices Inc.
12 * Bugs: Enter bugs at http://blackfin.uclinux.org/
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.
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.
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
30 #include <linux/delay.h>
31 #include <linux/console.h>
32 #include <linux/bootmem.h>
33 #include <linux/seq_file.h>
34 #include <linux/cpu.h>
35 #include <linux/module.h>
36 #include <linux/tty.h>
38 #include <linux/ext2_fs.h>
39 #include <linux/cramfs_fs.h>
40 #include <linux/romfs_fs.h>
43 #include <asm/cacheflush.h>
44 #include <asm/blackfin.h>
45 #include <asm/cplbinit.h>
46 #include <asm/fixed_code.h>
47 #include <asm/early_printk.h>
51 unsigned long memory_start, memory_end, physical_mem_end;
52 unsigned long reserved_mem_dcache_on;
53 unsigned long reserved_mem_icache_on;
54 EXPORT_SYMBOL(memory_start);
55 EXPORT_SYMBOL(memory_end);
56 EXPORT_SYMBOL(physical_mem_end);
57 EXPORT_SYMBOL(_ramend);
59 #ifdef CONFIG_MTD_UCLINUX
60 unsigned long memory_mtd_end, memory_mtd_start, mtd_size;
62 EXPORT_SYMBOL(memory_mtd_end);
63 EXPORT_SYMBOL(memory_mtd_start);
64 EXPORT_SYMBOL(mtd_size);
67 char __initdata command_line[COMMAND_LINE_SIZE];
69 void __init bf53x_cache_init(void)
71 #if defined(CONFIG_BFIN_DCACHE) || defined(CONFIG_BFIN_ICACHE)
72 generate_cpl_tables();
75 #ifdef CONFIG_BFIN_ICACHE
77 printk(KERN_INFO "Instruction Cache Enabled\n");
80 #ifdef CONFIG_BFIN_DCACHE
82 printk(KERN_INFO "Data Cache Enabled"
83 # if defined CONFIG_BFIN_WB
85 # elif defined CONFIG_BFIN_WT
92 void __init bf53x_relocate_l1_mem(void)
94 unsigned long l1_code_length;
95 unsigned long l1_data_a_length;
96 unsigned long l1_data_b_length;
98 l1_code_length = _etext_l1 - _stext_l1;
99 if (l1_code_length > L1_CODE_LENGTH)
100 l1_code_length = L1_CODE_LENGTH;
101 /* cannot complain as printk is not available as yet.
102 * But we can continue booting and complain later!
105 /* Copy _stext_l1 to _etext_l1 to L1 instruction SRAM */
106 dma_memcpy(_stext_l1, _l1_lma_start, l1_code_length);
108 l1_data_a_length = _ebss_l1 - _sdata_l1;
109 if (l1_data_a_length > L1_DATA_A_LENGTH)
110 l1_data_a_length = L1_DATA_A_LENGTH;
112 /* Copy _sdata_l1 to _ebss_l1 to L1 data bank A SRAM */
113 dma_memcpy(_sdata_l1, _l1_lma_start + l1_code_length, l1_data_a_length);
115 l1_data_b_length = _ebss_b_l1 - _sdata_b_l1;
116 if (l1_data_b_length > L1_DATA_B_LENGTH)
117 l1_data_b_length = L1_DATA_B_LENGTH;
119 /* Copy _sdata_b_l1 to _ebss_b_l1 to L1 data bank B SRAM */
120 dma_memcpy(_sdata_b_l1, _l1_lma_start + l1_code_length +
121 l1_data_a_length, l1_data_b_length);
126 * Initial parsing of the command line. Currently, we support:
127 * - Controlling the linux memory size: mem=xxx[KMG]
128 * - Controlling the physical memory size: max_mem=xxx[KMG][$][#]
129 * $ -> reserved memory is dcacheable
130 * # -> reserved memory is icacheable
132 static __init void parse_cmdline_early(char *cmdline_p)
134 char c = ' ', *to = cmdline_p;
135 unsigned int memsize;
139 if (!memcmp(to, "mem=", 4)) {
141 memsize = memparse(to, &to);
145 } else if (!memcmp(to, "max_mem=", 8)) {
147 memsize = memparse(to, &to);
149 physical_mem_end = memsize;
153 reserved_mem_dcache_on =
157 reserved_mem_icache_on =
161 } else if (!memcmp(to, "earlyprintk=", 12)) {
163 setup_early_printk(to);
172 void __init setup_arch(char **cmdline_p)
175 unsigned long l1_length, sclk, cclk;
176 #ifdef CONFIG_MTD_UCLINUX
177 unsigned long mtd_phys = 0;
180 #ifdef CONFIG_DUMMY_CONSOLE
181 conswitchp = &dummy_con;
184 #if defined(CONFIG_CMDLINE_BOOL)
185 strncpy(&command_line[0], CONFIG_CMDLINE, sizeof(command_line));
186 command_line[sizeof(command_line) - 1] = 0;
189 /* Keep a copy of command line */
190 *cmdline_p = &command_line[0];
191 memcpy(boot_command_line, command_line, COMMAND_LINE_SIZE);
192 boot_command_line[COMMAND_LINE_SIZE - 1] = '\0';
194 /* setup memory defaults from the user config */
195 physical_mem_end = 0;
196 _ramend = CONFIG_MEM_SIZE * 1024 * 1024;
198 parse_cmdline_early(&command_line[0]);
203 #if !defined(CONFIG_BFIN_KERNEL_CLOCK)
204 if (ANOMALY_05000273 && cclk == sclk)
205 panic("ANOMALY 05000273, SCLK can not be same as CCLK");
209 if (ANOMALY_05000266) {
210 bfin_read_IMDMA_D0_IRQ_STATUS();
211 bfin_read_IMDMA_D1_IRQ_STATUS();
215 printk(KERN_INFO "Hardware Trace ");
216 if (bfin_read_TBUFCTL() & 0x1 )
220 if (bfin_read_TBUFCTL() & 0x2)
221 printk("and Enabled\n");
223 printk("and Disabled\n");
226 #if defined(CONFIG_CHR_DEV_FLASH) || defined(CONFIG_BLK_DEV_FLASH)
227 /* we need to initialize the Flashrom device here since we might
228 * do things with flash early on in the boot
233 if (physical_mem_end == 0)
234 physical_mem_end = _ramend;
236 /* by now the stack is part of the init task */
237 memory_end = _ramend - DMA_UNCACHED_REGION;
239 _ramstart = (unsigned long)_end;
240 memory_start = PAGE_ALIGN(_ramstart);
242 #if defined(CONFIG_MTD_UCLINUX)
243 /* generic memory mapped MTD driver */
244 memory_mtd_end = memory_end;
246 mtd_phys = _ramstart;
247 mtd_size = PAGE_ALIGN(*((unsigned long *)(mtd_phys + 8)));
249 # if defined(CONFIG_EXT2_FS) || defined(CONFIG_EXT3_FS)
250 if (*((unsigned short *)(mtd_phys + 0x438)) == EXT2_SUPER_MAGIC)
252 PAGE_ALIGN(*((unsigned long *)(mtd_phys + 0x404)) << 10);
255 # if defined(CONFIG_CRAMFS)
256 if (*((unsigned long *)(mtd_phys)) == CRAMFS_MAGIC)
257 mtd_size = PAGE_ALIGN(*((unsigned long *)(mtd_phys + 0x4)));
260 # if defined(CONFIG_ROMFS_FS)
261 if (((unsigned long *)mtd_phys)[0] == ROMSB_WORD0
262 && ((unsigned long *)mtd_phys)[1] == ROMSB_WORD1)
264 PAGE_ALIGN(be32_to_cpu(((unsigned long *)mtd_phys)[2]));
265 # if (defined(CONFIG_BFIN_ICACHE) && ANOMALY_05000263)
266 /* Due to a Hardware Anomaly we need to limit the size of usable
267 * instruction memory to max 60MB, 56 if HUNT_FOR_ZERO is on
268 * 05000263 - Hardware loop corrupted when taking an ICPLB exception
270 # if (defined(CONFIG_DEBUG_HUNT_FOR_ZERO))
271 if (memory_end >= 56 * 1024 * 1024)
272 memory_end = 56 * 1024 * 1024;
274 if (memory_end >= 60 * 1024 * 1024)
275 memory_end = 60 * 1024 * 1024;
276 # endif /* CONFIG_DEBUG_HUNT_FOR_ZERO */
277 # endif /* ANOMALY_05000263 */
278 # endif /* CONFIG_ROMFS_FS */
280 memory_end -= mtd_size;
284 panic("Don't boot kernel without rootfs attached.\n");
287 /* Relocate MTD image to the top of memory after the uncached memory area */
288 dma_memcpy((char *)memory_end, _end, mtd_size);
290 memory_mtd_start = memory_end;
291 _ebss = memory_mtd_start; /* define _ebss for compatible */
292 #endif /* CONFIG_MTD_UCLINUX */
294 #if (defined(CONFIG_BFIN_ICACHE) && ANOMALY_05000263)
295 /* Due to a Hardware Anomaly we need to limit the size of usable
296 * instruction memory to max 60MB, 56 if HUNT_FOR_ZERO is on
297 * 05000263 - Hardware loop corrupted when taking an ICPLB exception
299 #if (defined(CONFIG_DEBUG_HUNT_FOR_ZERO))
300 if (memory_end >= 56 * 1024 * 1024)
301 memory_end = 56 * 1024 * 1024;
303 if (memory_end >= 60 * 1024 * 1024)
304 memory_end = 60 * 1024 * 1024;
305 #endif /* CONFIG_DEBUG_HUNT_FOR_ZERO */
306 printk(KERN_NOTICE "Warning: limiting memory to %liMB due to hardware anomaly 05000263\n", memory_end >> 20);
307 #endif /* ANOMALY_05000263 */
309 #if !defined(CONFIG_MTD_UCLINUX)
310 memory_end -= SIZE_4K; /*In case there is no valid CPLB behind memory_end make sure we don't get to close*/
312 init_mm.start_code = (unsigned long)_stext;
313 init_mm.end_code = (unsigned long)_etext;
314 init_mm.end_data = (unsigned long)_edata;
315 init_mm.brk = (unsigned long)0;
319 _bfin_swrst = bfin_read_SWRST();
321 if (_bfin_swrst & RESET_DOUBLE)
322 printk(KERN_INFO "Recovering from Double Fault event\n");
323 else if (_bfin_swrst & RESET_WDOG)
324 printk(KERN_INFO "Recovering from Watchdog event\n");
325 else if (_bfin_swrst & RESET_SOFTWARE)
326 printk(KERN_NOTICE "Reset caused by Software reset\n");
328 printk(KERN_INFO "Blackfin support (C) 2004-2007 Analog Devices, Inc.\n");
329 if (bfin_compiled_revid() == 0xffff)
330 printk(KERN_INFO "Compiled for ADSP-%s Rev any\n", CPU);
331 else if (bfin_compiled_revid() == -1)
332 printk(KERN_INFO "Compiled for ADSP-%s Rev none\n", CPU);
334 printk(KERN_INFO "Compiled for ADSP-%s Rev 0.%d\n", CPU, bfin_compiled_revid());
335 if (bfin_revid() != bfin_compiled_revid()) {
336 if (bfin_compiled_revid() == -1)
337 printk(KERN_ERR "Warning: Compiled for Rev none, but running on Rev %d\n",
339 else if (bfin_compiled_revid() != 0xffff)
340 printk(KERN_ERR "Warning: Compiled for Rev %d, but running on Rev %d\n",
341 bfin_compiled_revid(), bfin_revid());
343 if (bfin_revid() < SUPPORTED_REVID)
344 printk(KERN_ERR "Warning: Unsupported Chip Revision ADSP-%s Rev 0.%d detected\n",
346 printk(KERN_INFO "Blackfin Linux support by http://blackfin.uclinux.org/\n");
348 printk(KERN_INFO "Processor Speed: %lu MHz core clock and %lu MHz System Clock\n",
349 cclk / 1000000, sclk / 1000000);
351 if (ANOMALY_05000273 && (cclk >> 1) <= sclk)
352 printk("\n\n\nANOMALY_05000273: CCLK must be >= 2*SCLK !!!\n\n\n");
354 printk(KERN_INFO "Board Memory: %ldMB\n", physical_mem_end >> 20);
355 printk(KERN_INFO "Kernel Managed Memory: %ldMB\n", _ramend >> 20);
357 printk(KERN_INFO "Memory map:\n"
358 KERN_INFO " text = 0x%p-0x%p\n"
359 KERN_INFO " rodata = 0x%p-0x%p\n"
360 KERN_INFO " bss = 0x%p-0x%p\n"
361 KERN_INFO " data = 0x%p-0x%p\n"
362 KERN_INFO " stack = 0x%p-0x%p\n"
363 KERN_INFO " init = 0x%p-0x%p\n"
364 KERN_INFO " available = 0x%p-0x%p\n"
365 #ifdef CONFIG_MTD_UCLINUX
366 KERN_INFO " rootfs = 0x%p-0x%p\n"
368 #if DMA_UNCACHED_REGION > 0
369 KERN_INFO " DMA Zone = 0x%p-0x%p\n"
372 __start_rodata, __end_rodata,
373 __bss_start, __bss_stop,
375 (void *)&init_thread_union, (void *)((int)(&init_thread_union) + 0x2000),
376 __init_begin, __init_end,
377 (void *)_ramstart, (void *)memory_end
378 #ifdef CONFIG_MTD_UCLINUX
379 , (void *)memory_mtd_start, (void *)(memory_mtd_start + mtd_size)
381 #if DMA_UNCACHED_REGION > 0
382 , (void *)(_ramend - DMA_UNCACHED_REGION), (void *)(_ramend)
387 * give all the memory to the bootmap allocator, tell it to put the
388 * boot mem_map at the start of memory
390 bootmap_size = init_bootmem_node(NODE_DATA(0), memory_start >> PAGE_SHIFT, /* map goes here */
391 PAGE_OFFSET >> PAGE_SHIFT,
392 memory_end >> PAGE_SHIFT);
394 * free the usable memory, we have to make sure we do not free
395 * the bootmem bitmap so we then reserve it after freeing it :-)
397 free_bootmem(memory_start, memory_end - memory_start);
399 reserve_bootmem(memory_start, bootmap_size);
401 * get kmalloc into gear
405 /* check the size of the l1 area */
406 l1_length = _etext_l1 - _stext_l1;
407 if (l1_length > L1_CODE_LENGTH)
408 panic("L1 code memory overflow\n");
410 l1_length = _ebss_l1 - _sdata_l1;
411 if (l1_length > L1_DATA_A_LENGTH)
412 panic("L1 data memory overflow\n");
414 /* Copy atomic sequences to their fixed location, and sanity check that
415 these locations are the ones that we advertise to userspace. */
416 memcpy((void *)FIXED_CODE_START, &fixed_code_start,
417 FIXED_CODE_END - FIXED_CODE_START);
418 BUG_ON((char *)&sigreturn_stub - (char *)&fixed_code_start
419 != SIGRETURN_STUB - FIXED_CODE_START);
420 BUG_ON((char *)&atomic_xchg32 - (char *)&fixed_code_start
421 != ATOMIC_XCHG32 - FIXED_CODE_START);
422 BUG_ON((char *)&atomic_cas32 - (char *)&fixed_code_start
423 != ATOMIC_CAS32 - FIXED_CODE_START);
424 BUG_ON((char *)&atomic_add32 - (char *)&fixed_code_start
425 != ATOMIC_ADD32 - FIXED_CODE_START);
426 BUG_ON((char *)&atomic_sub32 - (char *)&fixed_code_start
427 != ATOMIC_SUB32 - FIXED_CODE_START);
428 BUG_ON((char *)&atomic_ior32 - (char *)&fixed_code_start
429 != ATOMIC_IOR32 - FIXED_CODE_START);
430 BUG_ON((char *)&atomic_and32 - (char *)&fixed_code_start
431 != ATOMIC_AND32 - FIXED_CODE_START);
432 BUG_ON((char *)&atomic_xor32 - (char *)&fixed_code_start
433 != ATOMIC_XOR32 - FIXED_CODE_START);
434 BUG_ON((char *)&safe_user_instruction - (char *)&fixed_code_start
435 != SAFE_USER_INSTRUCTION - FIXED_CODE_START);
437 init_exception_vectors();
441 static int __init topology_init(void)
443 #if defined (CONFIG_BF561)
444 static struct cpu cpu[2];
445 register_cpu(&cpu[0], 0);
446 register_cpu(&cpu[1], 1);
449 static struct cpu cpu[1];
450 return register_cpu(cpu, 0);
454 subsys_initcall(topology_init);
456 static u_long get_vco(void)
461 msel = (bfin_read_PLL_CTL() >> 9) & 0x3F;
465 vco = CONFIG_CLKIN_HZ;
466 vco >>= (1 & bfin_read_PLL_CTL()); /* DF bit */
471 /* Get the Core clock */
472 u_long get_cclk(void)
475 if (bfin_read_PLL_STAT() & 0x1)
476 return CONFIG_CLKIN_HZ;
478 ssel = bfin_read_PLL_DIV();
479 csel = ((ssel >> 4) & 0x03);
481 if (ssel && ssel < (1 << csel)) /* SCLK > CCLK */
482 return get_vco() / ssel;
483 return get_vco() >> csel;
485 EXPORT_SYMBOL(get_cclk);
487 /* Get the System clock */
488 u_long get_sclk(void)
492 if (bfin_read_PLL_STAT() & 0x1)
493 return CONFIG_CLKIN_HZ;
495 ssel = (bfin_read_PLL_DIV() & 0xf);
497 printk(KERN_WARNING "Invalid System Clock\n");
501 return get_vco() / ssel;
503 EXPORT_SYMBOL(get_sclk);
505 unsigned long sclk_to_usecs(unsigned long sclk)
507 return (USEC_PER_SEC * (u64)sclk) / get_sclk();
509 EXPORT_SYMBOL(sclk_to_usecs);
511 unsigned long usecs_to_sclk(unsigned long usecs)
513 return (get_sclk() * (u64)usecs) / USEC_PER_SEC;
515 EXPORT_SYMBOL(usecs_to_sclk);
518 * Get CPU information for use by the procfs.
520 static int show_cpuinfo(struct seq_file *m, void *v)
522 char *cpu, *mmu, *fpu, *vendor, *cache;
525 u_long cclk = 0, sclk = 0;
526 u_int dcache_size = 0, dsup_banks = 0;
531 revid = bfin_revid();
536 switch (bfin_read_CHIPID() & CHIPID_MANUFACTURE) {
538 vendor = "Analog Devices";
545 seq_printf(m, "processor\t: %d\n"
547 "cpu family\t: 0x%x\n"
548 "model name\t: ADSP-%s %lu(MHz CCLK) %lu(MHz SCLK)\n"
552 (bfin_read_CHIPID() & CHIPID_FAMILY),
553 cpu, cclk/1000000, sclk/1000000,
556 seq_printf(m, "cpu MHz\t\t: %lu.%03lu/%lu.%03lu\n",
557 cclk/1000000, cclk%1000000,
558 sclk/1000000, sclk%1000000);
559 seq_printf(m, "bogomips\t: %lu.%02lu\n"
560 "Calibration\t: %lu loops\n",
561 (loops_per_jiffy * HZ) / 500000,
562 ((loops_per_jiffy * HZ) / 5000) % 100,
563 (loops_per_jiffy * HZ));
565 /* Check Cache configutation */
566 switch (bfin_read_DMEM_CONTROL() & (1 << DMC0_P | 1 << DMC1_P)) {
568 cache = "dbank-A/B\t: cache/sram";
573 cache = "dbank-A/B\t: cache/cache";
578 cache = "dbank-A/B\t: sram/sram";
589 /* Is it turned on? */
590 if (!((bfin_read_DMEM_CONTROL()) & (ENDCPLB | DMC_ENABLE)))
593 seq_printf(m, "cache size\t: %d KB(L1 icache) "
594 "%d KB(L1 dcache-%s) %d KB(L2 cache)\n",
595 BFIN_ICACHESIZE / 1024, dcache_size,
596 #if defined CONFIG_BFIN_WB
598 #elif defined CONFIG_BFIN_WT
603 seq_printf(m, "%s\n", cache);
605 seq_printf(m, "icache setup\t: %d Sub-banks/%d Ways, %d Lines/Way\n",
606 BFIN_ISUBBANKS, BFIN_IWAYS, BFIN_ILINES);
608 "dcache setup\t: %d Super-banks/%d Sub-banks/%d Ways, %d Lines/Way\n",
609 dsup_banks, BFIN_DSUBBANKS, BFIN_DWAYS,
611 #ifdef CONFIG_BFIN_ICACHE_LOCK
612 switch (read_iloc()) {
614 seq_printf(m, "Way0 Locked-Down\n");
617 seq_printf(m, "Way1 Locked-Down\n");
620 seq_printf(m, "Way0,Way1 Locked-Down\n");
623 seq_printf(m, "Way2 Locked-Down\n");
626 seq_printf(m, "Way0,Way2 Locked-Down\n");
629 seq_printf(m, "Way1,Way2 Locked-Down\n");
632 seq_printf(m, "Way0,Way1 & Way2 Locked-Down\n");
635 seq_printf(m, "Way3 Locked-Down\n");
638 seq_printf(m, "Way0,Way3 Locked-Down\n");
641 seq_printf(m, "Way1,Way3 Locked-Down\n");
644 seq_printf(m, "Way 0,Way1,Way3 Locked-Down\n");
647 seq_printf(m, "Way3,Way2 Locked-Down\n");
650 seq_printf(m, "Way3,Way2,Way0 Locked-Down\n");
653 seq_printf(m, "Way3,Way2,Way1 Locked-Down\n");
656 seq_printf(m, "All Ways are locked\n");
659 seq_printf(m, "No Ways are locked\n");
663 seq_printf(m, "board name\t: %s\n", bfin_board_name);
664 seq_printf(m, "board memory\t: %ld kB (0x%p -> 0x%p)\n",
665 physical_mem_end >> 10, (void *)0, (void *)physical_mem_end);
666 seq_printf(m, "kernel memory\t: %d kB (0x%p -> 0x%p)\n",
667 ((int)memory_end - (int)_stext) >> 10,
674 static void *c_start(struct seq_file *m, loff_t *pos)
676 return *pos < NR_CPUS ? ((void *)0x12345678) : NULL;
679 static void *c_next(struct seq_file *m, void *v, loff_t *pos)
682 return c_start(m, pos);
685 static void c_stop(struct seq_file *m, void *v)
689 struct seq_operations cpuinfo_op = {
693 .show = show_cpuinfo,
696 void __init cmdline_init(const char *r0)
699 strncpy(command_line, r0, COMMAND_LINE_SIZE);