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/div64.h>
47 #include <asm/fixed_code.h>
48 #include <asm/early_printk.h>
52 unsigned long memory_start, memory_end, physical_mem_end;
53 unsigned long reserved_mem_dcache_on;
54 unsigned long reserved_mem_icache_on;
55 EXPORT_SYMBOL(memory_start);
56 EXPORT_SYMBOL(memory_end);
57 EXPORT_SYMBOL(physical_mem_end);
58 EXPORT_SYMBOL(_ramend);
60 #ifdef CONFIG_MTD_UCLINUX
61 unsigned long memory_mtd_end, memory_mtd_start, mtd_size;
63 EXPORT_SYMBOL(memory_mtd_end);
64 EXPORT_SYMBOL(memory_mtd_start);
65 EXPORT_SYMBOL(mtd_size);
68 char __initdata command_line[COMMAND_LINE_SIZE];
70 void __init bf53x_cache_init(void)
72 #if defined(CONFIG_BFIN_DCACHE) || defined(CONFIG_BFIN_ICACHE)
73 generate_cpl_tables();
76 #ifdef CONFIG_BFIN_ICACHE
78 printk(KERN_INFO "Instruction Cache Enabled\n");
81 #ifdef CONFIG_BFIN_DCACHE
83 printk(KERN_INFO "Data Cache Enabled"
84 # if defined CONFIG_BFIN_WB
86 # elif defined CONFIG_BFIN_WT
93 void __init bf53x_relocate_l1_mem(void)
95 unsigned long l1_code_length;
96 unsigned long l1_data_a_length;
97 unsigned long l1_data_b_length;
99 l1_code_length = _etext_l1 - _stext_l1;
100 if (l1_code_length > L1_CODE_LENGTH)
101 l1_code_length = L1_CODE_LENGTH;
102 /* cannot complain as printk is not available as yet.
103 * But we can continue booting and complain later!
106 /* Copy _stext_l1 to _etext_l1 to L1 instruction SRAM */
107 dma_memcpy(_stext_l1, _l1_lma_start, l1_code_length);
109 l1_data_a_length = _ebss_l1 - _sdata_l1;
110 if (l1_data_a_length > L1_DATA_A_LENGTH)
111 l1_data_a_length = L1_DATA_A_LENGTH;
113 /* Copy _sdata_l1 to _ebss_l1 to L1 data bank A SRAM */
114 dma_memcpy(_sdata_l1, _l1_lma_start + l1_code_length, l1_data_a_length);
116 l1_data_b_length = _ebss_b_l1 - _sdata_b_l1;
117 if (l1_data_b_length > L1_DATA_B_LENGTH)
118 l1_data_b_length = L1_DATA_B_LENGTH;
120 /* Copy _sdata_b_l1 to _ebss_b_l1 to L1 data bank B SRAM */
121 dma_memcpy(_sdata_b_l1, _l1_lma_start + l1_code_length +
122 l1_data_a_length, l1_data_b_length);
127 * Initial parsing of the command line. Currently, we support:
128 * - Controlling the linux memory size: mem=xxx[KMG]
129 * - Controlling the physical memory size: max_mem=xxx[KMG][$][#]
130 * $ -> reserved memory is dcacheable
131 * # -> reserved memory is icacheable
133 static __init void parse_cmdline_early(char *cmdline_p)
135 char c = ' ', *to = cmdline_p;
136 unsigned int memsize;
140 if (!memcmp(to, "mem=", 4)) {
142 memsize = memparse(to, &to);
146 } else if (!memcmp(to, "max_mem=", 8)) {
148 memsize = memparse(to, &to);
150 physical_mem_end = memsize;
154 reserved_mem_dcache_on =
158 reserved_mem_icache_on =
162 } else if (!memcmp(to, "earlyprintk=", 12)) {
164 setup_early_printk(to);
173 void __init setup_arch(char **cmdline_p)
176 unsigned long l1_length, sclk, cclk;
177 #ifdef CONFIG_MTD_UCLINUX
178 unsigned long mtd_phys = 0;
181 #ifdef CONFIG_DUMMY_CONSOLE
182 conswitchp = &dummy_con;
185 #if defined(CONFIG_CMDLINE_BOOL)
186 strncpy(&command_line[0], CONFIG_CMDLINE, sizeof(command_line));
187 command_line[sizeof(command_line) - 1] = 0;
190 /* Keep a copy of command line */
191 *cmdline_p = &command_line[0];
192 memcpy(boot_command_line, command_line, COMMAND_LINE_SIZE);
193 boot_command_line[COMMAND_LINE_SIZE - 1] = '\0';
195 /* setup memory defaults from the user config */
196 physical_mem_end = 0;
197 _ramend = CONFIG_MEM_SIZE * 1024 * 1024;
199 parse_cmdline_early(&command_line[0]);
204 #if !defined(CONFIG_BFIN_KERNEL_CLOCK)
205 if (ANOMALY_05000273 && cclk == sclk)
206 panic("ANOMALY 05000273, SCLK can not be same as CCLK");
210 if (ANOMALY_05000266) {
211 bfin_read_IMDMA_D0_IRQ_STATUS();
212 bfin_read_IMDMA_D1_IRQ_STATUS();
216 printk(KERN_INFO "Hardware Trace ");
217 if (bfin_read_TBUFCTL() & 0x1 )
221 if (bfin_read_TBUFCTL() & 0x2)
222 printk("and Enabled\n");
224 printk("and Disabled\n");
227 #if defined(CONFIG_CHR_DEV_FLASH) || defined(CONFIG_BLK_DEV_FLASH)
228 /* we need to initialize the Flashrom device here since we might
229 * do things with flash early on in the boot
234 if (physical_mem_end == 0)
235 physical_mem_end = _ramend;
237 /* by now the stack is part of the init task */
238 memory_end = _ramend - DMA_UNCACHED_REGION;
240 _ramstart = (unsigned long)__bss_stop;
241 memory_start = PAGE_ALIGN(_ramstart);
243 #if defined(CONFIG_MTD_UCLINUX)
244 /* generic memory mapped MTD driver */
245 memory_mtd_end = memory_end;
247 mtd_phys = _ramstart;
248 mtd_size = PAGE_ALIGN(*((unsigned long *)(mtd_phys + 8)));
250 # if defined(CONFIG_EXT2_FS) || defined(CONFIG_EXT3_FS)
251 if (*((unsigned short *)(mtd_phys + 0x438)) == EXT2_SUPER_MAGIC)
253 PAGE_ALIGN(*((unsigned long *)(mtd_phys + 0x404)) << 10);
256 # if defined(CONFIG_CRAMFS)
257 if (*((unsigned long *)(mtd_phys)) == CRAMFS_MAGIC)
258 mtd_size = PAGE_ALIGN(*((unsigned long *)(mtd_phys + 0x4)));
261 # if defined(CONFIG_ROMFS_FS)
262 if (((unsigned long *)mtd_phys)[0] == ROMSB_WORD0
263 && ((unsigned long *)mtd_phys)[1] == ROMSB_WORD1)
265 PAGE_ALIGN(be32_to_cpu(((unsigned long *)mtd_phys)[2]));
266 # if (defined(CONFIG_BFIN_ICACHE) && ANOMALY_05000263)
267 /* Due to a Hardware Anomaly we need to limit the size of usable
268 * instruction memory to max 60MB, 56 if HUNT_FOR_ZERO is on
269 * 05000263 - Hardware loop corrupted when taking an ICPLB exception
271 # if (defined(CONFIG_DEBUG_HUNT_FOR_ZERO))
272 if (memory_end >= 56 * 1024 * 1024)
273 memory_end = 56 * 1024 * 1024;
275 if (memory_end >= 60 * 1024 * 1024)
276 memory_end = 60 * 1024 * 1024;
277 # endif /* CONFIG_DEBUG_HUNT_FOR_ZERO */
278 # endif /* ANOMALY_05000263 */
279 # endif /* CONFIG_ROMFS_FS */
281 memory_end -= mtd_size;
285 panic("Don't boot kernel without rootfs attached.\n");
288 /* Relocate MTD image to the top of memory after the uncached memory area */
289 dma_memcpy((char *)memory_end, __bss_stop, mtd_size);
291 memory_mtd_start = memory_end;
292 _ebss = memory_mtd_start; /* define _ebss for compatible */
293 #endif /* CONFIG_MTD_UCLINUX */
295 #if (defined(CONFIG_BFIN_ICACHE) && ANOMALY_05000263)
296 /* Due to a Hardware Anomaly we need to limit the size of usable
297 * instruction memory to max 60MB, 56 if HUNT_FOR_ZERO is on
298 * 05000263 - Hardware loop corrupted when taking an ICPLB exception
300 #if (defined(CONFIG_DEBUG_HUNT_FOR_ZERO))
301 if (memory_end >= 56 * 1024 * 1024)
302 memory_end = 56 * 1024 * 1024;
304 if (memory_end >= 60 * 1024 * 1024)
305 memory_end = 60 * 1024 * 1024;
306 #endif /* CONFIG_DEBUG_HUNT_FOR_ZERO */
307 printk(KERN_NOTICE "Warning: limiting memory to %liMB due to hardware anomaly 05000263\n", memory_end >> 20);
308 #endif /* ANOMALY_05000263 */
310 #if !defined(CONFIG_MTD_UCLINUX)
311 memory_end -= SIZE_4K; /*In case there is no valid CPLB behind memory_end make sure we don't get to close*/
313 init_mm.start_code = (unsigned long)_stext;
314 init_mm.end_code = (unsigned long)_etext;
315 init_mm.end_data = (unsigned long)_edata;
316 init_mm.brk = (unsigned long)0;
320 _bfin_swrst = bfin_read_SWRST();
322 if (_bfin_swrst & RESET_DOUBLE)
323 printk(KERN_INFO "Recovering from Double Fault event\n");
324 else if (_bfin_swrst & RESET_WDOG)
325 printk(KERN_INFO "Recovering from Watchdog event\n");
326 else if (_bfin_swrst & RESET_SOFTWARE)
327 printk(KERN_NOTICE "Reset caused by Software reset\n");
329 printk(KERN_INFO "Blackfin support (C) 2004-2007 Analog Devices, Inc.\n");
330 if (bfin_compiled_revid() == 0xffff)
331 printk(KERN_INFO "Compiled for ADSP-%s Rev any\n", CPU);
332 else if (bfin_compiled_revid() == -1)
333 printk(KERN_INFO "Compiled for ADSP-%s Rev none\n", CPU);
335 printk(KERN_INFO "Compiled for ADSP-%s Rev 0.%d\n", CPU, bfin_compiled_revid());
336 if (bfin_revid() != bfin_compiled_revid()) {
337 if (bfin_compiled_revid() == -1)
338 printk(KERN_ERR "Warning: Compiled for Rev none, but running on Rev %d\n",
340 else if (bfin_compiled_revid() != 0xffff)
341 printk(KERN_ERR "Warning: Compiled for Rev %d, but running on Rev %d\n",
342 bfin_compiled_revid(), bfin_revid());
344 if (bfin_revid() < SUPPORTED_REVID)
345 printk(KERN_ERR "Warning: Unsupported Chip Revision ADSP-%s Rev 0.%d detected\n",
347 printk(KERN_INFO "Blackfin Linux support by http://blackfin.uclinux.org/\n");
349 printk(KERN_INFO "Processor Speed: %lu MHz core clock and %lu MHz System Clock\n",
350 cclk / 1000000, sclk / 1000000);
352 if (ANOMALY_05000273 && (cclk >> 1) <= sclk)
353 printk("\n\n\nANOMALY_05000273: CCLK must be >= 2*SCLK !!!\n\n\n");
355 printk(KERN_INFO "Board Memory: %ldMB\n", physical_mem_end >> 20);
356 printk(KERN_INFO "Kernel Managed Memory: %ldMB\n", _ramend >> 20);
358 printk(KERN_INFO "Memory map:\n"
359 KERN_INFO " text = 0x%p-0x%p\n"
360 KERN_INFO " rodata = 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 " bss = 0x%p-0x%p\n"
365 KERN_INFO " available = 0x%p-0x%p\n"
366 #ifdef CONFIG_MTD_UCLINUX
367 KERN_INFO " rootfs = 0x%p-0x%p\n"
369 #if DMA_UNCACHED_REGION > 0
370 KERN_INFO " DMA Zone = 0x%p-0x%p\n"
373 __start_rodata, __end_rodata,
375 (void *)&init_thread_union, (void *)((int)(&init_thread_union) + 0x2000),
376 __init_begin, __init_end,
377 __bss_start, __bss_stop,
378 (void *)_ramstart, (void *)memory_end
379 #ifdef CONFIG_MTD_UCLINUX
380 , (void *)memory_mtd_start, (void *)(memory_mtd_start + mtd_size)
382 #if DMA_UNCACHED_REGION > 0
383 , (void *)(_ramend - DMA_UNCACHED_REGION), (void *)(_ramend)
388 * give all the memory to the bootmap allocator, tell it to put the
389 * boot mem_map at the start of memory
391 bootmap_size = init_bootmem_node(NODE_DATA(0), memory_start >> PAGE_SHIFT, /* map goes here */
392 PAGE_OFFSET >> PAGE_SHIFT,
393 memory_end >> PAGE_SHIFT);
395 * free the usable memory, we have to make sure we do not free
396 * the bootmem bitmap so we then reserve it after freeing it :-)
398 free_bootmem(memory_start, memory_end - memory_start);
400 reserve_bootmem(memory_start, bootmap_size);
402 * get kmalloc into gear
406 /* check the size of the l1 area */
407 l1_length = _etext_l1 - _stext_l1;
408 if (l1_length > L1_CODE_LENGTH)
409 panic("L1 code memory overflow\n");
411 l1_length = _ebss_l1 - _sdata_l1;
412 if (l1_length > L1_DATA_A_LENGTH)
413 panic("L1 data memory overflow\n");
415 /* Copy atomic sequences to their fixed location, and sanity check that
416 these locations are the ones that we advertise to userspace. */
417 memcpy((void *)FIXED_CODE_START, &fixed_code_start,
418 FIXED_CODE_END - FIXED_CODE_START);
419 BUG_ON((char *)&sigreturn_stub - (char *)&fixed_code_start
420 != SIGRETURN_STUB - FIXED_CODE_START);
421 BUG_ON((char *)&atomic_xchg32 - (char *)&fixed_code_start
422 != ATOMIC_XCHG32 - FIXED_CODE_START);
423 BUG_ON((char *)&atomic_cas32 - (char *)&fixed_code_start
424 != ATOMIC_CAS32 - FIXED_CODE_START);
425 BUG_ON((char *)&atomic_add32 - (char *)&fixed_code_start
426 != ATOMIC_ADD32 - FIXED_CODE_START);
427 BUG_ON((char *)&atomic_sub32 - (char *)&fixed_code_start
428 != ATOMIC_SUB32 - FIXED_CODE_START);
429 BUG_ON((char *)&atomic_ior32 - (char *)&fixed_code_start
430 != ATOMIC_IOR32 - FIXED_CODE_START);
431 BUG_ON((char *)&atomic_and32 - (char *)&fixed_code_start
432 != ATOMIC_AND32 - FIXED_CODE_START);
433 BUG_ON((char *)&atomic_xor32 - (char *)&fixed_code_start
434 != ATOMIC_XOR32 - FIXED_CODE_START);
435 BUG_ON((char *)&safe_user_instruction - (char *)&fixed_code_start
436 != SAFE_USER_INSTRUCTION - FIXED_CODE_START);
438 init_exception_vectors();
442 static int __init topology_init(void)
444 #if defined (CONFIG_BF561)
445 static struct cpu cpu[2];
446 register_cpu(&cpu[0], 0);
447 register_cpu(&cpu[1], 1);
450 static struct cpu cpu[1];
451 return register_cpu(cpu, 0);
455 subsys_initcall(topology_init);
457 static u_long get_vco(void)
462 msel = (bfin_read_PLL_CTL() >> 9) & 0x3F;
466 vco = CONFIG_CLKIN_HZ;
467 vco >>= (1 & bfin_read_PLL_CTL()); /* DF bit */
472 /* Get the Core clock */
473 u_long get_cclk(void)
476 if (bfin_read_PLL_STAT() & 0x1)
477 return CONFIG_CLKIN_HZ;
479 ssel = bfin_read_PLL_DIV();
480 csel = ((ssel >> 4) & 0x03);
482 if (ssel && ssel < (1 << csel)) /* SCLK > CCLK */
483 return get_vco() / ssel;
484 return get_vco() >> csel;
486 EXPORT_SYMBOL(get_cclk);
488 /* Get the System clock */
489 u_long get_sclk(void)
493 if (bfin_read_PLL_STAT() & 0x1)
494 return CONFIG_CLKIN_HZ;
496 ssel = (bfin_read_PLL_DIV() & 0xf);
498 printk(KERN_WARNING "Invalid System Clock\n");
502 return get_vco() / ssel;
504 EXPORT_SYMBOL(get_sclk);
506 unsigned long sclk_to_usecs(unsigned long sclk)
508 u64 tmp = USEC_PER_SEC * (u64)sclk;
509 do_div(tmp, get_sclk());
512 EXPORT_SYMBOL(sclk_to_usecs);
514 unsigned long usecs_to_sclk(unsigned long usecs)
516 u64 tmp = get_sclk() * (u64)usecs;
517 do_div(tmp, USEC_PER_SEC);
520 EXPORT_SYMBOL(usecs_to_sclk);
523 * Get CPU information for use by the procfs.
525 static int show_cpuinfo(struct seq_file *m, void *v)
527 char *cpu, *mmu, *fpu, *vendor, *cache;
530 u_long cclk = 0, sclk = 0;
531 u_int dcache_size = 0, dsup_banks = 0;
536 revid = bfin_revid();
541 switch (bfin_read_CHIPID() & CHIPID_MANUFACTURE) {
543 vendor = "Analog Devices";
550 seq_printf(m, "processor\t: %d\n"
552 "cpu family\t: 0x%x\n"
553 "model name\t: ADSP-%s %lu(MHz CCLK) %lu(MHz SCLK)\n"
557 (bfin_read_CHIPID() & CHIPID_FAMILY),
558 cpu, cclk/1000000, sclk/1000000,
561 seq_printf(m, "cpu MHz\t\t: %lu.%03lu/%lu.%03lu\n",
562 cclk/1000000, cclk%1000000,
563 sclk/1000000, sclk%1000000);
564 seq_printf(m, "bogomips\t: %lu.%02lu\n"
565 "Calibration\t: %lu loops\n",
566 (loops_per_jiffy * HZ) / 500000,
567 ((loops_per_jiffy * HZ) / 5000) % 100,
568 (loops_per_jiffy * HZ));
570 /* Check Cache configutation */
571 switch (bfin_read_DMEM_CONTROL() & (1 << DMC0_P | 1 << DMC1_P)) {
573 cache = "dbank-A/B\t: cache/sram";
578 cache = "dbank-A/B\t: cache/cache";
583 cache = "dbank-A/B\t: sram/sram";
594 /* Is it turned on? */
595 if (!((bfin_read_DMEM_CONTROL()) & (ENDCPLB | DMC_ENABLE)))
598 seq_printf(m, "cache size\t: %d KB(L1 icache) "
599 "%d KB(L1 dcache-%s) %d KB(L2 cache)\n",
600 BFIN_ICACHESIZE / 1024, dcache_size,
601 #if defined CONFIG_BFIN_WB
603 #elif defined CONFIG_BFIN_WT
608 seq_printf(m, "%s\n", cache);
610 seq_printf(m, "icache setup\t: %d Sub-banks/%d Ways, %d Lines/Way\n",
611 BFIN_ISUBBANKS, BFIN_IWAYS, BFIN_ILINES);
613 "dcache setup\t: %d Super-banks/%d Sub-banks/%d Ways, %d Lines/Way\n",
614 dsup_banks, BFIN_DSUBBANKS, BFIN_DWAYS,
616 #ifdef CONFIG_BFIN_ICACHE_LOCK
617 switch (read_iloc()) {
619 seq_printf(m, "Way0 Locked-Down\n");
622 seq_printf(m, "Way1 Locked-Down\n");
625 seq_printf(m, "Way0,Way1 Locked-Down\n");
628 seq_printf(m, "Way2 Locked-Down\n");
631 seq_printf(m, "Way0,Way2 Locked-Down\n");
634 seq_printf(m, "Way1,Way2 Locked-Down\n");
637 seq_printf(m, "Way0,Way1 & Way2 Locked-Down\n");
640 seq_printf(m, "Way3 Locked-Down\n");
643 seq_printf(m, "Way0,Way3 Locked-Down\n");
646 seq_printf(m, "Way1,Way3 Locked-Down\n");
649 seq_printf(m, "Way 0,Way1,Way3 Locked-Down\n");
652 seq_printf(m, "Way3,Way2 Locked-Down\n");
655 seq_printf(m, "Way3,Way2,Way0 Locked-Down\n");
658 seq_printf(m, "Way3,Way2,Way1 Locked-Down\n");
661 seq_printf(m, "All Ways are locked\n");
664 seq_printf(m, "No Ways are locked\n");
668 seq_printf(m, "board name\t: %s\n", bfin_board_name);
669 seq_printf(m, "board memory\t: %ld kB (0x%p -> 0x%p)\n",
670 physical_mem_end >> 10, (void *)0, (void *)physical_mem_end);
671 seq_printf(m, "kernel memory\t: %d kB (0x%p -> 0x%p)\n",
672 ((int)memory_end - (int)_stext) >> 10,
679 static void *c_start(struct seq_file *m, loff_t *pos)
681 return *pos < NR_CPUS ? ((void *)0x12345678) : NULL;
684 static void *c_next(struct seq_file *m, void *v, loff_t *pos)
687 return c_start(m, pos);
690 static void c_stop(struct seq_file *m, void *v)
694 struct seq_operations cpuinfo_op = {
698 .show = show_cpuinfo,
701 void __init cmdline_init(const char *r0)
704 strncpy(command_line, r0, COMMAND_LINE_SIZE);