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>
50 unsigned long memory_start, memory_end, physical_mem_end;
51 unsigned long reserved_mem_dcache_on;
52 unsigned long reserved_mem_icache_on;
53 EXPORT_SYMBOL(memory_start);
54 EXPORT_SYMBOL(memory_end);
55 EXPORT_SYMBOL(physical_mem_end);
56 EXPORT_SYMBOL(_ramend);
58 #ifdef CONFIG_MTD_UCLINUX
59 unsigned long memory_mtd_end, memory_mtd_start, mtd_size;
61 EXPORT_SYMBOL(memory_mtd_end);
62 EXPORT_SYMBOL(memory_mtd_start);
63 EXPORT_SYMBOL(mtd_size);
66 char __initdata command_line[COMMAND_LINE_SIZE];
68 void __init bf53x_cache_init(void)
70 #if defined(CONFIG_BFIN_DCACHE) || defined(CONFIG_BFIN_ICACHE)
71 generate_cpl_tables();
74 #ifdef CONFIG_BFIN_ICACHE
76 printk(KERN_INFO "Instruction Cache Enabled\n");
79 #ifdef CONFIG_BFIN_DCACHE
81 printk(KERN_INFO "Data Cache Enabled"
82 # if defined CONFIG_BFIN_WB
84 # elif defined CONFIG_BFIN_WT
91 void __init bf53x_relocate_l1_mem(void)
93 unsigned long l1_code_length;
94 unsigned long l1_data_a_length;
95 unsigned long l1_data_b_length;
97 l1_code_length = _etext_l1 - _stext_l1;
98 if (l1_code_length > L1_CODE_LENGTH)
99 l1_code_length = L1_CODE_LENGTH;
100 /* cannot complain as printk is not available as yet.
101 * But we can continue booting and complain later!
104 /* Copy _stext_l1 to _etext_l1 to L1 instruction SRAM */
105 dma_memcpy(_stext_l1, _l1_lma_start, l1_code_length);
107 l1_data_a_length = _ebss_l1 - _sdata_l1;
108 if (l1_data_a_length > L1_DATA_A_LENGTH)
109 l1_data_a_length = L1_DATA_A_LENGTH;
111 /* Copy _sdata_l1 to _ebss_l1 to L1 data bank A SRAM */
112 dma_memcpy(_sdata_l1, _l1_lma_start + l1_code_length, l1_data_a_length);
114 l1_data_b_length = _ebss_b_l1 - _sdata_b_l1;
115 if (l1_data_b_length > L1_DATA_B_LENGTH)
116 l1_data_b_length = L1_DATA_B_LENGTH;
118 /* Copy _sdata_b_l1 to _ebss_b_l1 to L1 data bank B SRAM */
119 dma_memcpy(_sdata_b_l1, _l1_lma_start + l1_code_length +
120 l1_data_a_length, l1_data_b_length);
125 * Initial parsing of the command line. Currently, we support:
126 * - Controlling the linux memory size: mem=xxx[KMG]
127 * - Controlling the physical memory size: max_mem=xxx[KMG][$][#]
128 * $ -> reserved memory is dcacheable
129 * # -> reserved memory is icacheable
131 static __init void parse_cmdline_early(char *cmdline_p)
133 char c = ' ', *to = cmdline_p;
134 unsigned int memsize;
138 if (!memcmp(to, "mem=", 4)) {
140 memsize = memparse(to, &to);
144 } else if (!memcmp(to, "max_mem=", 8)) {
146 memsize = memparse(to, &to);
148 physical_mem_end = memsize;
152 reserved_mem_dcache_on =
156 reserved_mem_icache_on =
169 void __init setup_arch(char **cmdline_p)
172 unsigned long l1_length, sclk, cclk;
173 #ifdef CONFIG_MTD_UCLINUX
174 unsigned long mtd_phys = 0;
177 #ifdef CONFIG_DUMMY_CONSOLE
178 conswitchp = &dummy_con;
183 #if !defined(CONFIG_BFIN_KERNEL_CLOCK)
184 if (ANOMALY_05000273 && cclk == sclk)
185 panic("ANOMALY 05000273, SCLK can not be same as CCLK");
189 if (ANOMALY_05000266) {
190 bfin_read_IMDMA_D0_IRQ_STATUS();
191 bfin_read_IMDMA_D1_IRQ_STATUS();
195 #ifdef DEBUG_SERIAL_EARLY_INIT
196 bfin_console_init(); /* early console registration */
197 /* this give a chance to get printk() working before crash. */
200 printk(KERN_INFO "Hardware Trace ");
201 if (bfin_read_TBUFCTL() & 0x1 )
205 if (bfin_read_TBUFCTL() & 0x2)
206 printk("and Enabled\n");
208 printk("and Disabled\n");
211 #if defined(CONFIG_CHR_DEV_FLASH) || defined(CONFIG_BLK_DEV_FLASH)
212 /* we need to initialize the Flashrom device here since we might
213 * do things with flash early on in the boot
218 #if defined(CONFIG_CMDLINE_BOOL)
219 strncpy(&command_line[0], CONFIG_CMDLINE, sizeof(command_line));
220 command_line[sizeof(command_line) - 1] = 0;
223 /* Keep a copy of command line */
224 *cmdline_p = &command_line[0];
225 memcpy(boot_command_line, command_line, COMMAND_LINE_SIZE);
226 boot_command_line[COMMAND_LINE_SIZE - 1] = '\0';
228 /* setup memory defaults from the user config */
229 physical_mem_end = 0;
230 _ramend = CONFIG_MEM_SIZE * 1024 * 1024;
232 parse_cmdline_early(&command_line[0]);
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 printk(KERN_INFO "Blackfin support (C) 2004-2007 Analog Devices, Inc.\n");
321 if (bfin_compiled_revid() == 0xffff)
322 printk(KERN_INFO "Compiled for ADSP-%s Rev any\n", CPU);
323 else if (bfin_compiled_revid() == -1)
324 printk(KERN_INFO "Compiled for ADSP-%s Rev none\n", CPU);
326 printk(KERN_INFO "Compiled for ADSP-%s Rev 0.%d\n", CPU, bfin_compiled_revid());
327 if (bfin_revid() != bfin_compiled_revid()) {
328 if (bfin_compiled_revid() == -1)
329 printk(KERN_ERR "Warning: Compiled for Rev none, but running on Rev %d\n",
331 else if (bfin_compiled_revid() != 0xffff)
332 printk(KERN_ERR "Warning: Compiled for Rev %d, but running on Rev %d\n",
333 bfin_compiled_revid(), bfin_revid());
335 if (bfin_revid() < SUPPORTED_REVID)
336 printk(KERN_ERR "Warning: Unsupported Chip Revision ADSP-%s Rev 0.%d detected\n",
338 printk(KERN_INFO "Blackfin Linux support by http://blackfin.uclinux.org/\n");
340 printk(KERN_INFO "Processor Speed: %lu MHz core clock and %lu Mhz System Clock\n",
341 cclk / 1000000, sclk / 1000000);
343 if (ANOMALY_05000273 && (cclk >> 1) <= sclk)
344 printk("\n\n\nANOMALY_05000273: CCLK must be >= 2*SCLK !!!\n\n\n");
346 printk(KERN_INFO "Board Memory: %ldMB\n", physical_mem_end >> 20);
347 printk(KERN_INFO "Kernel Managed Memory: %ldMB\n", _ramend >> 20);
349 printk(KERN_INFO "Memory map:\n"
350 KERN_INFO " text = 0x%p-0x%p\n"
351 KERN_INFO " rodata = 0x%p-0x%p\n"
352 KERN_INFO " data = 0x%p-0x%p\n"
353 KERN_INFO " stack = 0x%p-0x%p\n"
354 KERN_INFO " init = 0x%p-0x%p\n"
355 KERN_INFO " bss = 0x%p-0x%p\n"
356 KERN_INFO " available = 0x%p-0x%p\n"
357 #ifdef CONFIG_MTD_UCLINUX
358 KERN_INFO " rootfs = 0x%p-0x%p\n"
360 #if DMA_UNCACHED_REGION > 0
361 KERN_INFO " DMA Zone = 0x%p-0x%p\n"
364 __start_rodata, __end_rodata,
366 (void *)&init_thread_union, (void *)((int)(&init_thread_union) + 0x2000),
367 __init_begin, __init_end,
368 __bss_start, __bss_stop,
369 (void *)_ramstart, (void *)memory_end
370 #ifdef CONFIG_MTD_UCLINUX
371 , (void *)memory_mtd_start, (void *)(memory_mtd_start + mtd_size)
373 #if DMA_UNCACHED_REGION > 0
374 , (void *)(_ramend - DMA_UNCACHED_REGION), (void *)(_ramend)
379 * give all the memory to the bootmap allocator, tell it to put the
380 * boot mem_map at the start of memory
382 bootmap_size = init_bootmem_node(NODE_DATA(0), memory_start >> PAGE_SHIFT, /* map goes here */
383 PAGE_OFFSET >> PAGE_SHIFT,
384 memory_end >> PAGE_SHIFT);
386 * free the usable memory, we have to make sure we do not free
387 * the bootmem bitmap so we then reserve it after freeing it :-)
389 free_bootmem(memory_start, memory_end - memory_start);
391 reserve_bootmem(memory_start, bootmap_size);
393 * get kmalloc into gear
397 /* check the size of the l1 area */
398 l1_length = _etext_l1 - _stext_l1;
399 if (l1_length > L1_CODE_LENGTH)
400 panic("L1 code memory overflow\n");
402 l1_length = _ebss_l1 - _sdata_l1;
403 if (l1_length > L1_DATA_A_LENGTH)
404 panic("L1 data memory overflow\n");
406 _bfin_swrst = bfin_read_SWRST();
408 /* Copy atomic sequences to their fixed location, and sanity check that
409 these locations are the ones that we advertise to userspace. */
410 memcpy((void *)FIXED_CODE_START, &fixed_code_start,
411 FIXED_CODE_END - FIXED_CODE_START);
412 BUG_ON((char *)&sigreturn_stub - (char *)&fixed_code_start
413 != SIGRETURN_STUB - FIXED_CODE_START);
414 BUG_ON((char *)&atomic_xchg32 - (char *)&fixed_code_start
415 != ATOMIC_XCHG32 - FIXED_CODE_START);
416 BUG_ON((char *)&atomic_cas32 - (char *)&fixed_code_start
417 != ATOMIC_CAS32 - FIXED_CODE_START);
418 BUG_ON((char *)&atomic_add32 - (char *)&fixed_code_start
419 != ATOMIC_ADD32 - FIXED_CODE_START);
420 BUG_ON((char *)&atomic_sub32 - (char *)&fixed_code_start
421 != ATOMIC_SUB32 - FIXED_CODE_START);
422 BUG_ON((char *)&atomic_ior32 - (char *)&fixed_code_start
423 != ATOMIC_IOR32 - FIXED_CODE_START);
424 BUG_ON((char *)&atomic_and32 - (char *)&fixed_code_start
425 != ATOMIC_AND32 - FIXED_CODE_START);
426 BUG_ON((char *)&atomic_xor32 - (char *)&fixed_code_start
427 != ATOMIC_XOR32 - FIXED_CODE_START);
429 init_exception_vectors();
433 static int __init topology_init(void)
435 #if defined (CONFIG_BF561)
436 static struct cpu cpu[2];
437 register_cpu(&cpu[0], 0);
438 register_cpu(&cpu[1], 1);
441 static struct cpu cpu[1];
442 return register_cpu(cpu, 0);
446 subsys_initcall(topology_init);
448 static u_long get_vco(void)
453 msel = (bfin_read_PLL_CTL() >> 9) & 0x3F;
457 vco = CONFIG_CLKIN_HZ;
458 vco >>= (1 & bfin_read_PLL_CTL()); /* DF bit */
463 /*Get the Core clock*/
464 u_long get_cclk(void)
467 if (bfin_read_PLL_STAT() & 0x1)
468 return CONFIG_CLKIN_HZ;
470 ssel = bfin_read_PLL_DIV();
471 csel = ((ssel >> 4) & 0x03);
473 if (ssel && ssel < (1 << csel)) /* SCLK > CCLK */
474 return get_vco() / ssel;
475 return get_vco() >> csel;
477 EXPORT_SYMBOL(get_cclk);
479 /* Get the System clock */
480 u_long get_sclk(void)
484 if (bfin_read_PLL_STAT() & 0x1)
485 return CONFIG_CLKIN_HZ;
487 ssel = (bfin_read_PLL_DIV() & 0xf);
489 printk(KERN_WARNING "Invalid System Clock\n");
493 return get_vco() / ssel;
495 EXPORT_SYMBOL(get_sclk);
498 * Get CPU information for use by the procfs.
500 static int show_cpuinfo(struct seq_file *m, void *v)
502 char *cpu, *mmu, *fpu, *name;
505 u_long cclk = 0, sclk = 0;
506 u_int dcache_size = 0, dsup_banks = 0;
511 revid = bfin_revid();
512 name = bfin_board_name;
517 seq_printf(m, "CPU:\t\tADSP-%s Rev. 0.%d\n"
520 "Core Clock:\t%9lu Hz\n"
521 "System Clock:\t%9lu Hz\n"
522 "BogoMips:\t%lu.%02lu\n"
523 "Calibration:\t%lu loops\n",
524 cpu, revid, mmu, fpu,
527 (loops_per_jiffy * HZ) / 500000,
528 ((loops_per_jiffy * HZ) / 5000) % 100,
529 (loops_per_jiffy * HZ));
530 seq_printf(m, "Board Name:\t%s\n", name);
531 seq_printf(m, "Board Memory:\t%ld MB\n", physical_mem_end >> 20);
532 seq_printf(m, "Kernel Memory:\t%ld MB\n", (unsigned long)_ramend >> 20);
533 if (bfin_read_IMEM_CONTROL() & (ENICPLB | IMC))
534 seq_printf(m, "I-CACHE:\tON\n");
536 seq_printf(m, "I-CACHE:\tOFF\n");
537 if ((bfin_read_DMEM_CONTROL()) & (ENDCPLB | DMC_ENABLE))
538 seq_printf(m, "D-CACHE:\tON"
539 #if defined CONFIG_BFIN_WB
541 #elif defined CONFIG_BFIN_WT
546 seq_printf(m, "D-CACHE:\tOFF\n");
549 switch (bfin_read_DMEM_CONTROL() & (1 << DMC0_P | 1 << DMC1_P)) {
551 seq_printf(m, "DBANK-A:\tCACHE\n" "DBANK-B:\tSRAM\n");
556 seq_printf(m, "DBANK-A:\tCACHE\n" "DBANK-B:\tCACHE\n");
561 seq_printf(m, "DBANK-A:\tSRAM\n" "DBANK-B:\tSRAM\n");
570 seq_printf(m, "I-CACHE Size:\t%dKB\n", BFIN_ICACHESIZE / 1024);
571 seq_printf(m, "D-CACHE Size:\t%dKB\n", dcache_size);
572 seq_printf(m, "I-CACHE Setup:\t%d Sub-banks/%d Ways, %d Lines/Way\n",
573 BFIN_ISUBBANKS, BFIN_IWAYS, BFIN_ILINES);
575 "D-CACHE Setup:\t%d Super-banks/%d Sub-banks/%d Ways, %d Lines/Way\n",
576 dsup_banks, BFIN_DSUBBANKS, BFIN_DWAYS,
578 #ifdef CONFIG_BFIN_ICACHE_LOCK
579 switch (read_iloc()) {
581 seq_printf(m, "Way0 Locked-Down\n");
584 seq_printf(m, "Way1 Locked-Down\n");
587 seq_printf(m, "Way0,Way1 Locked-Down\n");
590 seq_printf(m, "Way2 Locked-Down\n");
593 seq_printf(m, "Way0,Way2 Locked-Down\n");
596 seq_printf(m, "Way1,Way2 Locked-Down\n");
599 seq_printf(m, "Way0,Way1 & Way2 Locked-Down\n");
602 seq_printf(m, "Way3 Locked-Down\n");
605 seq_printf(m, "Way0,Way3 Locked-Down\n");
608 seq_printf(m, "Way1,Way3 Locked-Down\n");
611 seq_printf(m, "Way 0,Way1,Way3 Locked-Down\n");
614 seq_printf(m, "Way3,Way2 Locked-Down\n");
617 seq_printf(m, "Way3,Way2,Way0 Locked-Down\n");
620 seq_printf(m, "Way3,Way2,Way1 Locked-Down\n");
623 seq_printf(m, "All Ways are locked\n");
626 seq_printf(m, "No Ways are locked\n");
632 static void *c_start(struct seq_file *m, loff_t *pos)
634 return *pos < NR_CPUS ? ((void *)0x12345678) : NULL;
637 static void *c_next(struct seq_file *m, void *v, loff_t *pos)
640 return c_start(m, pos);
643 static void c_stop(struct seq_file *m, void *v)
647 struct seq_operations cpuinfo_op = {
651 .show = show_cpuinfo,
654 void __init cmdline_init(const char *r0)
657 strncpy(command_line, r0, COMMAND_LINE_SIZE);