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 printk(KERN_INFO "Hardware Trace ");
196 if (bfin_read_TBUFCTL() & 0x1 )
200 if (bfin_read_TBUFCTL() & 0x2)
201 printk("and Enabled\n");
203 printk("and Disabled\n");
206 #if defined(CONFIG_CHR_DEV_FLASH) || defined(CONFIG_BLK_DEV_FLASH)
207 /* we need to initialize the Flashrom device here since we might
208 * do things with flash early on in the boot
213 #if defined(CONFIG_CMDLINE_BOOL)
214 strncpy(&command_line[0], CONFIG_CMDLINE, sizeof(command_line));
215 command_line[sizeof(command_line) - 1] = 0;
218 /* Keep a copy of command line */
219 *cmdline_p = &command_line[0];
220 memcpy(boot_command_line, command_line, COMMAND_LINE_SIZE);
221 boot_command_line[COMMAND_LINE_SIZE - 1] = '\0';
223 /* setup memory defaults from the user config */
224 physical_mem_end = 0;
225 _ramend = CONFIG_MEM_SIZE * 1024 * 1024;
227 parse_cmdline_early(&command_line[0]);
229 if (physical_mem_end == 0)
230 physical_mem_end = _ramend;
232 /* by now the stack is part of the init task */
233 memory_end = _ramend - DMA_UNCACHED_REGION;
235 _ramstart = (unsigned long)__bss_stop;
236 memory_start = PAGE_ALIGN(_ramstart);
238 #if defined(CONFIG_MTD_UCLINUX)
239 /* generic memory mapped MTD driver */
240 memory_mtd_end = memory_end;
242 mtd_phys = _ramstart;
243 mtd_size = PAGE_ALIGN(*((unsigned long *)(mtd_phys + 8)));
245 # if defined(CONFIG_EXT2_FS) || defined(CONFIG_EXT3_FS)
246 if (*((unsigned short *)(mtd_phys + 0x438)) == EXT2_SUPER_MAGIC)
248 PAGE_ALIGN(*((unsigned long *)(mtd_phys + 0x404)) << 10);
251 # if defined(CONFIG_CRAMFS)
252 if (*((unsigned long *)(mtd_phys)) == CRAMFS_MAGIC)
253 mtd_size = PAGE_ALIGN(*((unsigned long *)(mtd_phys + 0x4)));
256 # if defined(CONFIG_ROMFS_FS)
257 if (((unsigned long *)mtd_phys)[0] == ROMSB_WORD0
258 && ((unsigned long *)mtd_phys)[1] == ROMSB_WORD1)
260 PAGE_ALIGN(be32_to_cpu(((unsigned long *)mtd_phys)[2]));
261 # if (defined(CONFIG_BFIN_ICACHE) && ANOMALY_05000263)
262 /* Due to a Hardware Anomaly we need to limit the size of usable
263 * instruction memory to max 60MB, 56 if HUNT_FOR_ZERO is on
264 * 05000263 - Hardware loop corrupted when taking an ICPLB exception
266 # if (defined(CONFIG_DEBUG_HUNT_FOR_ZERO))
267 if (memory_end >= 56 * 1024 * 1024)
268 memory_end = 56 * 1024 * 1024;
270 if (memory_end >= 60 * 1024 * 1024)
271 memory_end = 60 * 1024 * 1024;
272 # endif /* CONFIG_DEBUG_HUNT_FOR_ZERO */
273 # endif /* ANOMALY_05000263 */
274 # endif /* CONFIG_ROMFS_FS */
276 memory_end -= mtd_size;
280 panic("Don't boot kernel without rootfs attached.\n");
283 /* Relocate MTD image to the top of memory after the uncached memory area */
284 dma_memcpy((char *)memory_end, __bss_stop, mtd_size);
286 memory_mtd_start = memory_end;
287 _ebss = memory_mtd_start; /* define _ebss for compatible */
288 #endif /* CONFIG_MTD_UCLINUX */
290 #if (defined(CONFIG_BFIN_ICACHE) && ANOMALY_05000263)
291 /* Due to a Hardware Anomaly we need to limit the size of usable
292 * instruction memory to max 60MB, 56 if HUNT_FOR_ZERO is on
293 * 05000263 - Hardware loop corrupted when taking an ICPLB exception
295 #if (defined(CONFIG_DEBUG_HUNT_FOR_ZERO))
296 if (memory_end >= 56 * 1024 * 1024)
297 memory_end = 56 * 1024 * 1024;
299 if (memory_end >= 60 * 1024 * 1024)
300 memory_end = 60 * 1024 * 1024;
301 #endif /* CONFIG_DEBUG_HUNT_FOR_ZERO */
302 printk(KERN_NOTICE "Warning: limiting memory to %liMB due to hardware anomaly 05000263\n", memory_end >> 20);
303 #endif /* ANOMALY_05000263 */
305 #if !defined(CONFIG_MTD_UCLINUX)
306 memory_end -= SIZE_4K; /*In case there is no valid CPLB behind memory_end make sure we don't get to close*/
308 init_mm.start_code = (unsigned long)_stext;
309 init_mm.end_code = (unsigned long)_etext;
310 init_mm.end_data = (unsigned long)_edata;
311 init_mm.brk = (unsigned long)0;
315 printk(KERN_INFO "Blackfin support (C) 2004-2007 Analog Devices, Inc.\n");
316 if (bfin_compiled_revid() == 0xffff)
317 printk(KERN_INFO "Compiled for ADSP-%s Rev any\n", CPU);
318 else if (bfin_compiled_revid() == -1)
319 printk(KERN_INFO "Compiled for ADSP-%s Rev none\n", CPU);
321 printk(KERN_INFO "Compiled for ADSP-%s Rev 0.%d\n", CPU, bfin_compiled_revid());
322 if (bfin_revid() != bfin_compiled_revid()) {
323 if (bfin_compiled_revid() == -1)
324 printk(KERN_ERR "Warning: Compiled for Rev none, but running on Rev %d\n",
326 else if (bfin_compiled_revid() != 0xffff)
327 printk(KERN_ERR "Warning: Compiled for Rev %d, but running on Rev %d\n",
328 bfin_compiled_revid(), bfin_revid());
330 if (bfin_revid() < SUPPORTED_REVID)
331 printk(KERN_ERR "Warning: Unsupported Chip Revision ADSP-%s Rev 0.%d detected\n",
333 printk(KERN_INFO "Blackfin Linux support by http://blackfin.uclinux.org/\n");
335 printk(KERN_INFO "Processor Speed: %lu MHz core clock and %lu MHz System Clock\n",
336 cclk / 1000000, sclk / 1000000);
338 if (ANOMALY_05000273 && (cclk >> 1) <= sclk)
339 printk("\n\n\nANOMALY_05000273: CCLK must be >= 2*SCLK !!!\n\n\n");
341 printk(KERN_INFO "Board Memory: %ldMB\n", physical_mem_end >> 20);
342 printk(KERN_INFO "Kernel Managed Memory: %ldMB\n", _ramend >> 20);
344 printk(KERN_INFO "Memory map:\n"
345 KERN_INFO " text = 0x%p-0x%p\n"
346 KERN_INFO " rodata = 0x%p-0x%p\n"
347 KERN_INFO " data = 0x%p-0x%p\n"
348 KERN_INFO " stack = 0x%p-0x%p\n"
349 KERN_INFO " init = 0x%p-0x%p\n"
350 KERN_INFO " bss = 0x%p-0x%p\n"
351 KERN_INFO " available = 0x%p-0x%p\n"
352 #ifdef CONFIG_MTD_UCLINUX
353 KERN_INFO " rootfs = 0x%p-0x%p\n"
355 #if DMA_UNCACHED_REGION > 0
356 KERN_INFO " DMA Zone = 0x%p-0x%p\n"
359 __start_rodata, __end_rodata,
361 (void *)&init_thread_union, (void *)((int)(&init_thread_union) + 0x2000),
362 __init_begin, __init_end,
363 __bss_start, __bss_stop,
364 (void *)_ramstart, (void *)memory_end
365 #ifdef CONFIG_MTD_UCLINUX
366 , (void *)memory_mtd_start, (void *)(memory_mtd_start + mtd_size)
368 #if DMA_UNCACHED_REGION > 0
369 , (void *)(_ramend - DMA_UNCACHED_REGION), (void *)(_ramend)
374 * give all the memory to the bootmap allocator, tell it to put the
375 * boot mem_map at the start of memory
377 bootmap_size = init_bootmem_node(NODE_DATA(0), memory_start >> PAGE_SHIFT, /* map goes here */
378 PAGE_OFFSET >> PAGE_SHIFT,
379 memory_end >> PAGE_SHIFT);
381 * free the usable memory, we have to make sure we do not free
382 * the bootmem bitmap so we then reserve it after freeing it :-)
384 free_bootmem(memory_start, memory_end - memory_start);
386 reserve_bootmem(memory_start, bootmap_size);
388 * get kmalloc into gear
392 /* check the size of the l1 area */
393 l1_length = _etext_l1 - _stext_l1;
394 if (l1_length > L1_CODE_LENGTH)
395 panic("L1 code memory overflow\n");
397 l1_length = _ebss_l1 - _sdata_l1;
398 if (l1_length > L1_DATA_A_LENGTH)
399 panic("L1 data memory overflow\n");
401 _bfin_swrst = bfin_read_SWRST();
403 /* Copy atomic sequences to their fixed location, and sanity check that
404 these locations are the ones that we advertise to userspace. */
405 memcpy((void *)FIXED_CODE_START, &fixed_code_start,
406 FIXED_CODE_END - FIXED_CODE_START);
407 BUG_ON((char *)&sigreturn_stub - (char *)&fixed_code_start
408 != SIGRETURN_STUB - FIXED_CODE_START);
409 BUG_ON((char *)&atomic_xchg32 - (char *)&fixed_code_start
410 != ATOMIC_XCHG32 - FIXED_CODE_START);
411 BUG_ON((char *)&atomic_cas32 - (char *)&fixed_code_start
412 != ATOMIC_CAS32 - FIXED_CODE_START);
413 BUG_ON((char *)&atomic_add32 - (char *)&fixed_code_start
414 != ATOMIC_ADD32 - FIXED_CODE_START);
415 BUG_ON((char *)&atomic_sub32 - (char *)&fixed_code_start
416 != ATOMIC_SUB32 - FIXED_CODE_START);
417 BUG_ON((char *)&atomic_ior32 - (char *)&fixed_code_start
418 != ATOMIC_IOR32 - FIXED_CODE_START);
419 BUG_ON((char *)&atomic_and32 - (char *)&fixed_code_start
420 != ATOMIC_AND32 - FIXED_CODE_START);
421 BUG_ON((char *)&atomic_xor32 - (char *)&fixed_code_start
422 != ATOMIC_XOR32 - FIXED_CODE_START);
424 init_exception_vectors();
428 static int __init topology_init(void)
430 #if defined (CONFIG_BF561)
431 static struct cpu cpu[2];
432 register_cpu(&cpu[0], 0);
433 register_cpu(&cpu[1], 1);
436 static struct cpu cpu[1];
437 return register_cpu(cpu, 0);
441 subsys_initcall(topology_init);
443 static u_long get_vco(void)
448 msel = (bfin_read_PLL_CTL() >> 9) & 0x3F;
452 vco = CONFIG_CLKIN_HZ;
453 vco >>= (1 & bfin_read_PLL_CTL()); /* DF bit */
458 /*Get the Core clock*/
459 u_long get_cclk(void)
462 if (bfin_read_PLL_STAT() & 0x1)
463 return CONFIG_CLKIN_HZ;
465 ssel = bfin_read_PLL_DIV();
466 csel = ((ssel >> 4) & 0x03);
468 if (ssel && ssel < (1 << csel)) /* SCLK > CCLK */
469 return get_vco() / ssel;
470 return get_vco() >> csel;
472 EXPORT_SYMBOL(get_cclk);
474 /* Get the System clock */
475 u_long get_sclk(void)
479 if (bfin_read_PLL_STAT() & 0x1)
480 return CONFIG_CLKIN_HZ;
482 ssel = (bfin_read_PLL_DIV() & 0xf);
484 printk(KERN_WARNING "Invalid System Clock\n");
488 return get_vco() / ssel;
490 EXPORT_SYMBOL(get_sclk);
493 * Get CPU information for use by the procfs.
495 static int show_cpuinfo(struct seq_file *m, void *v)
497 char *cpu, *mmu, *fpu, *name;
500 u_long cclk = 0, sclk = 0;
501 u_int dcache_size = 0, dsup_banks = 0;
506 revid = bfin_revid();
507 name = bfin_board_name;
512 seq_printf(m, "CPU:\t\tADSP-%s Rev. 0.%d\n"
515 "Core Clock:\t%9lu Hz\n"
516 "System Clock:\t%9lu Hz\n"
517 "BogoMips:\t%lu.%02lu\n"
518 "Calibration:\t%lu loops\n",
519 cpu, revid, mmu, fpu,
522 (loops_per_jiffy * HZ) / 500000,
523 ((loops_per_jiffy * HZ) / 5000) % 100,
524 (loops_per_jiffy * HZ));
525 seq_printf(m, "Board Name:\t%s\n", name);
526 seq_printf(m, "Board Memory:\t%ld MB\n", physical_mem_end >> 20);
527 seq_printf(m, "Kernel Memory:\t%ld MB\n", (unsigned long)_ramend >> 20);
528 if (bfin_read_IMEM_CONTROL() & (ENICPLB | IMC))
529 seq_printf(m, "I-CACHE:\tON\n");
531 seq_printf(m, "I-CACHE:\tOFF\n");
532 if ((bfin_read_DMEM_CONTROL()) & (ENDCPLB | DMC_ENABLE))
533 seq_printf(m, "D-CACHE:\tON"
534 #if defined CONFIG_BFIN_WB
536 #elif defined CONFIG_BFIN_WT
541 seq_printf(m, "D-CACHE:\tOFF\n");
544 switch (bfin_read_DMEM_CONTROL() & (1 << DMC0_P | 1 << DMC1_P)) {
546 seq_printf(m, "DBANK-A:\tCACHE\n" "DBANK-B:\tSRAM\n");
551 seq_printf(m, "DBANK-A:\tCACHE\n" "DBANK-B:\tCACHE\n");
556 seq_printf(m, "DBANK-A:\tSRAM\n" "DBANK-B:\tSRAM\n");
565 seq_printf(m, "I-CACHE Size:\t%dKB\n", BFIN_ICACHESIZE / 1024);
566 seq_printf(m, "D-CACHE Size:\t%dKB\n", dcache_size);
567 seq_printf(m, "I-CACHE Setup:\t%d Sub-banks/%d Ways, %d Lines/Way\n",
568 BFIN_ISUBBANKS, BFIN_IWAYS, BFIN_ILINES);
570 "D-CACHE Setup:\t%d Super-banks/%d Sub-banks/%d Ways, %d Lines/Way\n",
571 dsup_banks, BFIN_DSUBBANKS, BFIN_DWAYS,
573 #ifdef CONFIG_BFIN_ICACHE_LOCK
574 switch (read_iloc()) {
576 seq_printf(m, "Way0 Locked-Down\n");
579 seq_printf(m, "Way1 Locked-Down\n");
582 seq_printf(m, "Way0,Way1 Locked-Down\n");
585 seq_printf(m, "Way2 Locked-Down\n");
588 seq_printf(m, "Way0,Way2 Locked-Down\n");
591 seq_printf(m, "Way1,Way2 Locked-Down\n");
594 seq_printf(m, "Way0,Way1 & Way2 Locked-Down\n");
597 seq_printf(m, "Way3 Locked-Down\n");
600 seq_printf(m, "Way0,Way3 Locked-Down\n");
603 seq_printf(m, "Way1,Way3 Locked-Down\n");
606 seq_printf(m, "Way 0,Way1,Way3 Locked-Down\n");
609 seq_printf(m, "Way3,Way2 Locked-Down\n");
612 seq_printf(m, "Way3,Way2,Way0 Locked-Down\n");
615 seq_printf(m, "Way3,Way2,Way1 Locked-Down\n");
618 seq_printf(m, "All Ways are locked\n");
621 seq_printf(m, "No Ways are locked\n");
627 static void *c_start(struct seq_file *m, loff_t *pos)
629 return *pos < NR_CPUS ? ((void *)0x12345678) : NULL;
632 static void *c_next(struct seq_file *m, void *v, loff_t *pos)
635 return c_start(m, pos);
638 static void c_stop(struct seq_file *m, void *v)
642 struct seq_operations cpuinfo_op = {
646 .show = show_cpuinfo,
649 void __init cmdline_init(const char *r0)
652 strncpy(command_line, r0, COMMAND_LINE_SIZE);