2 * arch/blackfin/kernel/setup.c
4 * Copyright 2004-2006 Analog Devices Inc.
6 * Enter bugs at http://blackfin.uclinux.org/
8 * Licensed under the GPL-2 or later.
11 #include <linux/delay.h>
12 #include <linux/console.h>
13 #include <linux/bootmem.h>
14 #include <linux/seq_file.h>
15 #include <linux/cpu.h>
16 #include <linux/module.h>
17 #include <linux/tty.h>
18 #include <linux/pfn.h>
20 #include <linux/ext2_fs.h>
21 #include <linux/cramfs_fs.h>
22 #include <linux/romfs_fs.h>
25 #include <asm/cacheflush.h>
26 #include <asm/blackfin.h>
27 #include <asm/cplbinit.h>
28 #include <asm/div64.h>
29 #include <asm/fixed_code.h>
30 #include <asm/early_printk.h>
32 static DEFINE_PER_CPU(struct cpu, cpu_devices);
35 EXPORT_SYMBOL(_bfin_swrst);
37 unsigned long memory_start, memory_end, physical_mem_end;
38 unsigned long _rambase, _ramstart, _ramend;
39 unsigned long reserved_mem_dcache_on;
40 unsigned long reserved_mem_icache_on;
41 EXPORT_SYMBOL(memory_start);
42 EXPORT_SYMBOL(memory_end);
43 EXPORT_SYMBOL(physical_mem_end);
44 EXPORT_SYMBOL(_ramend);
46 #ifdef CONFIG_MTD_UCLINUX
47 unsigned long memory_mtd_end, memory_mtd_start, mtd_size;
49 EXPORT_SYMBOL(memory_mtd_end);
50 EXPORT_SYMBOL(memory_mtd_start);
51 EXPORT_SYMBOL(mtd_size);
54 char __initdata command_line[COMMAND_LINE_SIZE];
56 /* boot memmap, for parsing "memmap=" */
57 #define BFIN_MEMMAP_MAX 128 /* number of entries in bfin_memmap */
58 #define BFIN_MEMMAP_RAM 1
59 #define BFIN_MEMMAP_RESERVED 2
62 struct bfin_memmap_entry {
63 unsigned long long addr; /* start of memory segment */
64 unsigned long long size;
66 } map[BFIN_MEMMAP_MAX];
67 } bfin_memmap __initdata;
69 /* for memmap sanitization */
70 struct change_member {
71 struct bfin_memmap_entry *pentry; /* pointer to original entry */
72 unsigned long long addr; /* address for this change point */
74 static struct change_member change_point_list[2*BFIN_MEMMAP_MAX] __initdata;
75 static struct change_member *change_point[2*BFIN_MEMMAP_MAX] __initdata;
76 static struct bfin_memmap_entry *overlap_list[BFIN_MEMMAP_MAX] __initdata;
77 static struct bfin_memmap_entry new_map[BFIN_MEMMAP_MAX] __initdata;
79 void __init bf53x_cache_init(void)
81 #if defined(CONFIG_BFIN_DCACHE) || defined(CONFIG_BFIN_ICACHE)
82 generate_cpl_tables();
85 #ifdef CONFIG_BFIN_ICACHE
87 printk(KERN_INFO "Instruction Cache Enabled\n");
90 #ifdef CONFIG_BFIN_DCACHE
92 printk(KERN_INFO "Data Cache Enabled"
93 # if defined CONFIG_BFIN_WB
95 # elif defined CONFIG_BFIN_WT
102 void __init bf53x_relocate_l1_mem(void)
104 unsigned long l1_code_length;
105 unsigned long l1_data_a_length;
106 unsigned long l1_data_b_length;
108 l1_code_length = _etext_l1 - _stext_l1;
109 if (l1_code_length > L1_CODE_LENGTH)
110 panic("L1 Instruction SRAM Overflow\n");
111 /* cannot complain as printk is not available as yet.
112 * But we can continue booting and complain later!
115 /* Copy _stext_l1 to _etext_l1 to L1 instruction SRAM */
116 dma_memcpy(_stext_l1, _l1_lma_start, l1_code_length);
118 l1_data_a_length = _ebss_l1 - _sdata_l1;
119 if (l1_data_a_length > L1_DATA_A_LENGTH)
120 panic("L1 Data SRAM Bank A Overflow\n");
122 /* Copy _sdata_l1 to _ebss_l1 to L1 data bank A SRAM */
123 dma_memcpy(_sdata_l1, _l1_lma_start + l1_code_length, l1_data_a_length);
125 l1_data_b_length = _ebss_b_l1 - _sdata_b_l1;
126 if (l1_data_b_length > L1_DATA_B_LENGTH)
127 panic("L1 Data SRAM Bank B Overflow\n");
129 /* Copy _sdata_b_l1 to _ebss_b_l1 to L1 data bank B SRAM */
130 dma_memcpy(_sdata_b_l1, _l1_lma_start + l1_code_length +
131 l1_data_a_length, l1_data_b_length);
134 /* add_memory_region to memmap */
135 static void __init add_memory_region(unsigned long long start,
136 unsigned long long size, int type)
140 i = bfin_memmap.nr_map;
142 if (i == BFIN_MEMMAP_MAX) {
143 printk(KERN_ERR "Ooops! Too many entries in the memory map!\n");
147 bfin_memmap.map[i].addr = start;
148 bfin_memmap.map[i].size = size;
149 bfin_memmap.map[i].type = type;
150 bfin_memmap.nr_map++;
154 * Sanitize the boot memmap, removing overlaps.
156 static int __init sanitize_memmap(struct bfin_memmap_entry *map, int *pnr_map)
158 struct change_member *change_tmp;
159 unsigned long current_type, last_type;
160 unsigned long long last_addr;
161 int chgidx, still_changing;
164 int old_nr, new_nr, chg_nr;
168 Visually we're performing the following (1,2,3,4 = memory types)
170 Sample memory map (w/overlaps):
171 ____22__________________
172 ______________________4_
173 ____1111________________
174 _44_____________________
175 11111111________________
176 ____________________33__
177 ___________44___________
178 __________33333_________
179 ______________22________
180 ___________________2222_
181 _________111111111______
182 _____________________11_
183 _________________4______
185 Sanitized equivalent (no overlap):
186 1_______________________
187 _44_____________________
188 ___1____________________
189 ____22__________________
190 ______11________________
191 _________1______________
192 __________3_____________
193 ___________44___________
194 _____________33_________
195 _______________2________
196 ________________1_______
197 _________________4______
198 ___________________2____
199 ____________________33__
200 ______________________4_
202 /* if there's only one memory region, don't bother */
208 /* bail out if we find any unreasonable addresses in memmap */
209 for (i = 0; i < old_nr; i++)
210 if (map[i].addr + map[i].size < map[i].addr)
213 /* create pointers for initial change-point information (for sorting) */
214 for (i = 0; i < 2*old_nr; i++)
215 change_point[i] = &change_point_list[i];
217 /* record all known change-points (starting and ending addresses),
218 omitting those that are for empty memory regions */
220 for (i = 0; i < old_nr; i++) {
221 if (map[i].size != 0) {
222 change_point[chgidx]->addr = map[i].addr;
223 change_point[chgidx++]->pentry = &map[i];
224 change_point[chgidx]->addr = map[i].addr + map[i].size;
225 change_point[chgidx++]->pentry = &map[i];
228 chg_nr = chgidx; /* true number of change-points */
230 /* sort change-point list by memory addresses (low -> high) */
232 while (still_changing) {
234 for (i = 1; i < chg_nr; i++) {
235 /* if <current_addr> > <last_addr>, swap */
236 /* or, if current=<start_addr> & last=<end_addr>, swap */
237 if ((change_point[i]->addr < change_point[i-1]->addr) ||
238 ((change_point[i]->addr == change_point[i-1]->addr) &&
239 (change_point[i]->addr == change_point[i]->pentry->addr) &&
240 (change_point[i-1]->addr != change_point[i-1]->pentry->addr))
242 change_tmp = change_point[i];
243 change_point[i] = change_point[i-1];
244 change_point[i-1] = change_tmp;
250 /* create a new memmap, removing overlaps */
251 overlap_entries = 0; /* number of entries in the overlap table */
252 new_entry = 0; /* index for creating new memmap entries */
253 last_type = 0; /* start with undefined memory type */
254 last_addr = 0; /* start with 0 as last starting address */
255 /* loop through change-points, determining affect on the new memmap */
256 for (chgidx = 0; chgidx < chg_nr; chgidx++) {
257 /* keep track of all overlapping memmap entries */
258 if (change_point[chgidx]->addr == change_point[chgidx]->pentry->addr) {
259 /* add map entry to overlap list (> 1 entry implies an overlap) */
260 overlap_list[overlap_entries++] = change_point[chgidx]->pentry;
262 /* remove entry from list (order independent, so swap with last) */
263 for (i = 0; i < overlap_entries; i++) {
264 if (overlap_list[i] == change_point[chgidx]->pentry)
265 overlap_list[i] = overlap_list[overlap_entries-1];
269 /* if there are overlapping entries, decide which "type" to use */
270 /* (larger value takes precedence -- 1=usable, 2,3,4,4+=unusable) */
272 for (i = 0; i < overlap_entries; i++)
273 if (overlap_list[i]->type > current_type)
274 current_type = overlap_list[i]->type;
275 /* continue building up new memmap based on this information */
276 if (current_type != last_type) {
277 if (last_type != 0) {
278 new_map[new_entry].size =
279 change_point[chgidx]->addr - last_addr;
280 /* move forward only if the new size was non-zero */
281 if (new_map[new_entry].size != 0)
282 if (++new_entry >= BFIN_MEMMAP_MAX)
283 break; /* no more space left for new entries */
285 if (current_type != 0) {
286 new_map[new_entry].addr = change_point[chgidx]->addr;
287 new_map[new_entry].type = current_type;
288 last_addr = change_point[chgidx]->addr;
290 last_type = current_type;
293 new_nr = new_entry; /* retain count for new entries */
295 /* copy new mapping into original location */
296 memcpy(map, new_map, new_nr*sizeof(struct bfin_memmap_entry));
302 static void __init print_memory_map(char *who)
306 for (i = 0; i < bfin_memmap.nr_map; i++) {
307 printk(KERN_DEBUG " %s: %016Lx - %016Lx ", who,
308 bfin_memmap.map[i].addr,
309 bfin_memmap.map[i].addr + bfin_memmap.map[i].size);
310 switch (bfin_memmap.map[i].type) {
311 case BFIN_MEMMAP_RAM:
312 printk("(usable)\n");
314 case BFIN_MEMMAP_RESERVED:
315 printk("(reserved)\n");
317 default: printk("type %lu\n", bfin_memmap.map[i].type);
323 static __init int parse_memmap(char *arg)
325 unsigned long long start_at, mem_size;
330 mem_size = memparse(arg, &arg);
332 start_at = memparse(arg+1, &arg);
333 add_memory_region(start_at, mem_size, BFIN_MEMMAP_RAM);
334 } else if (*arg == '$') {
335 start_at = memparse(arg+1, &arg);
336 add_memory_region(start_at, mem_size, BFIN_MEMMAP_RESERVED);
343 * Initial parsing of the command line. Currently, we support:
344 * - Controlling the linux memory size: mem=xxx[KMG]
345 * - Controlling the physical memory size: max_mem=xxx[KMG][$][#]
346 * $ -> reserved memory is dcacheable
347 * # -> reserved memory is icacheable
348 * - "memmap=XXX[KkmM][@][$]XXX[KkmM]" defines a memory region
349 * @ from <start> to <start>+<mem>, type RAM
350 * $ from <start> to <start>+<mem>, type RESERVED
353 static __init void parse_cmdline_early(char *cmdline_p)
355 char c = ' ', *to = cmdline_p;
356 unsigned int memsize;
359 if (!memcmp(to, "mem=", 4)) {
361 memsize = memparse(to, &to);
365 } else if (!memcmp(to, "max_mem=", 8)) {
367 memsize = memparse(to, &to);
369 physical_mem_end = memsize;
373 reserved_mem_dcache_on =
377 reserved_mem_icache_on =
381 } else if (!memcmp(to, "earlyprintk=", 12)) {
383 setup_early_printk(to);
384 } else if (!memcmp(to, "memmap=", 7)) {
396 * Setup memory defaults from user config.
397 * The physical memory layout looks like:
399 * [_rambase, _ramstart]: kernel image
400 * [memory_start, memory_end]: dynamic memory managed by kernel
401 * [memory_end, _ramend]: reserved memory
402 * [meory_mtd_start(memory_end),
403 * memory_mtd_start + mtd_size]: rootfs (if any)
404 * [_ramend - DMA_UNCACHED_REGION,
405 * _ramend]: uncached DMA region
406 * [_ramend, physical_mem_end]: memory not managed by kernel
409 static __init void memory_setup(void)
411 #ifdef CONFIG_MTD_UCLINUX
412 unsigned long mtd_phys = 0;
415 _rambase = (unsigned long)_stext;
416 _ramstart = (unsigned long)_end;
418 if (DMA_UNCACHED_REGION > (_ramend - _ramstart)) {
420 panic("DMA region exceeds memory limit: %lu.\n",
421 _ramend - _ramstart);
423 memory_end = _ramend - DMA_UNCACHED_REGION;
426 /* Round up to multiple of 4MB. */
427 memory_start = (_ramstart + 0x3fffff) & ~0x3fffff;
429 memory_start = PAGE_ALIGN(_ramstart);
432 #if defined(CONFIG_MTD_UCLINUX)
433 /* generic memory mapped MTD driver */
434 memory_mtd_end = memory_end;
436 mtd_phys = _ramstart;
437 mtd_size = PAGE_ALIGN(*((unsigned long *)(mtd_phys + 8)));
439 # if defined(CONFIG_EXT2_FS) || defined(CONFIG_EXT3_FS)
440 if (*((unsigned short *)(mtd_phys + 0x438)) == EXT2_SUPER_MAGIC)
442 PAGE_ALIGN(*((unsigned long *)(mtd_phys + 0x404)) << 10);
445 # if defined(CONFIG_CRAMFS)
446 if (*((unsigned long *)(mtd_phys)) == CRAMFS_MAGIC)
447 mtd_size = PAGE_ALIGN(*((unsigned long *)(mtd_phys + 0x4)));
450 # if defined(CONFIG_ROMFS_FS)
451 if (((unsigned long *)mtd_phys)[0] == ROMSB_WORD0
452 && ((unsigned long *)mtd_phys)[1] == ROMSB_WORD1)
454 PAGE_ALIGN(be32_to_cpu(((unsigned long *)mtd_phys)[2]));
455 # if (defined(CONFIG_BFIN_ICACHE) && ANOMALY_05000263)
456 /* Due to a Hardware Anomaly we need to limit the size of usable
457 * instruction memory to max 60MB, 56 if HUNT_FOR_ZERO is on
458 * 05000263 - Hardware loop corrupted when taking an ICPLB exception
460 # if (defined(CONFIG_DEBUG_HUNT_FOR_ZERO))
461 if (memory_end >= 56 * 1024 * 1024)
462 memory_end = 56 * 1024 * 1024;
464 if (memory_end >= 60 * 1024 * 1024)
465 memory_end = 60 * 1024 * 1024;
466 # endif /* CONFIG_DEBUG_HUNT_FOR_ZERO */
467 # endif /* ANOMALY_05000263 */
468 # endif /* CONFIG_ROMFS_FS */
470 memory_end -= mtd_size;
474 panic("Don't boot kernel without rootfs attached.\n");
477 /* Relocate MTD image to the top of memory after the uncached memory area */
478 dma_memcpy((char *)memory_end, _end, mtd_size);
480 memory_mtd_start = memory_end;
481 _ebss = memory_mtd_start; /* define _ebss for compatible */
482 #endif /* CONFIG_MTD_UCLINUX */
484 #if (defined(CONFIG_BFIN_ICACHE) && ANOMALY_05000263)
485 /* Due to a Hardware Anomaly we need to limit the size of usable
486 * instruction memory to max 60MB, 56 if HUNT_FOR_ZERO is on
487 * 05000263 - Hardware loop corrupted when taking an ICPLB exception
489 #if (defined(CONFIG_DEBUG_HUNT_FOR_ZERO))
490 if (memory_end >= 56 * 1024 * 1024)
491 memory_end = 56 * 1024 * 1024;
493 if (memory_end >= 60 * 1024 * 1024)
494 memory_end = 60 * 1024 * 1024;
495 #endif /* CONFIG_DEBUG_HUNT_FOR_ZERO */
496 printk(KERN_NOTICE "Warning: limiting memory to %liMB due to hardware anomaly 05000263\n", memory_end >> 20);
497 #endif /* ANOMALY_05000263 */
500 page_mask_nelts = ((_ramend >> PAGE_SHIFT) + 31) / 32;
501 page_mask_order = get_order(3 * page_mask_nelts * sizeof(long));
504 #if !defined(CONFIG_MTD_UCLINUX)
505 /*In case there is no valid CPLB behind memory_end make sure we don't get to close*/
506 memory_end -= SIZE_4K;
509 init_mm.start_code = (unsigned long)_stext;
510 init_mm.end_code = (unsigned long)_etext;
511 init_mm.end_data = (unsigned long)_edata;
512 init_mm.brk = (unsigned long)0;
514 printk(KERN_INFO "Board Memory: %ldMB\n", physical_mem_end >> 20);
515 printk(KERN_INFO "Kernel Managed Memory: %ldMB\n", _ramend >> 20);
517 printk(KERN_INFO "Memory map:\n"
518 KERN_INFO " fixedcode = 0x%p-0x%p\n"
519 KERN_INFO " text = 0x%p-0x%p\n"
520 KERN_INFO " rodata = 0x%p-0x%p\n"
521 KERN_INFO " bss = 0x%p-0x%p\n"
522 KERN_INFO " data = 0x%p-0x%p\n"
523 KERN_INFO " stack = 0x%p-0x%p\n"
524 KERN_INFO " init = 0x%p-0x%p\n"
525 KERN_INFO " available = 0x%p-0x%p\n"
526 #ifdef CONFIG_MTD_UCLINUX
527 KERN_INFO " rootfs = 0x%p-0x%p\n"
529 #if DMA_UNCACHED_REGION > 0
530 KERN_INFO " DMA Zone = 0x%p-0x%p\n"
532 , (void *)FIXED_CODE_START, (void *)FIXED_CODE_END,
534 __start_rodata, __end_rodata,
535 __bss_start, __bss_stop,
537 (void *)&init_thread_union,
538 (void *)((int)(&init_thread_union) + 0x2000),
539 __init_begin, __init_end,
540 (void *)_ramstart, (void *)memory_end
541 #ifdef CONFIG_MTD_UCLINUX
542 , (void *)memory_mtd_start, (void *)(memory_mtd_start + mtd_size)
544 #if DMA_UNCACHED_REGION > 0
545 , (void *)(_ramend - DMA_UNCACHED_REGION), (void *)(_ramend)
551 * Find the lowest, highest page frame number we have available
553 void __init find_min_max_pfn(void)
558 min_low_pfn = memory_end;
560 for (i = 0; i < bfin_memmap.nr_map; i++) {
561 unsigned long start, end;
563 if (bfin_memmap.map[i].type != BFIN_MEMMAP_RAM)
565 start = PFN_UP(bfin_memmap.map[i].addr);
566 end = PFN_DOWN(bfin_memmap.map[i].addr +
567 bfin_memmap.map[i].size);
572 if (start < min_low_pfn)
577 static __init void setup_bootmem_allocator(void)
581 unsigned long start_pfn, end_pfn;
582 unsigned long curr_pfn, last_pfn, size;
584 /* mark memory between memory_start and memory_end usable */
585 add_memory_region(memory_start,
586 memory_end - memory_start, BFIN_MEMMAP_RAM);
587 /* sanity check for overlap */
588 sanitize_memmap(bfin_memmap.map, &bfin_memmap.nr_map);
589 print_memory_map("boot memmap");
591 /* intialize globals in linux/bootmem.h */
593 /* pfn of the last usable page frame */
594 if (max_pfn > memory_end >> PAGE_SHIFT)
595 max_pfn = memory_end >> PAGE_SHIFT;
596 /* pfn of last page frame directly mapped by kernel */
597 max_low_pfn = max_pfn;
598 /* pfn of the first usable page frame after kernel image*/
599 if (min_low_pfn < memory_start >> PAGE_SHIFT)
600 min_low_pfn = memory_start >> PAGE_SHIFT;
602 start_pfn = PAGE_OFFSET >> PAGE_SHIFT;
603 end_pfn = memory_end >> PAGE_SHIFT;
606 * give all the memory to the bootmap allocator, tell it to put the
607 * boot mem_map at the start of memory.
609 bootmap_size = init_bootmem_node(NODE_DATA(0),
610 memory_start >> PAGE_SHIFT, /* map goes here */
613 /* register the memmap regions with the bootmem allocator */
614 for (i = 0; i < bfin_memmap.nr_map; i++) {
616 * Reserve usable memory
618 if (bfin_memmap.map[i].type != BFIN_MEMMAP_RAM)
621 * We are rounding up the start address of usable memory:
623 curr_pfn = PFN_UP(bfin_memmap.map[i].addr);
624 if (curr_pfn >= end_pfn)
627 * ... and at the end of the usable range downwards:
629 last_pfn = PFN_DOWN(bfin_memmap.map[i].addr +
630 bfin_memmap.map[i].size);
632 if (last_pfn > end_pfn)
636 * .. finally, did all the rounding and playing
637 * around just make the area go away?
639 if (last_pfn <= curr_pfn)
642 size = last_pfn - curr_pfn;
643 free_bootmem(PFN_PHYS(curr_pfn), PFN_PHYS(size));
646 /* reserve memory before memory_start, including bootmap */
647 reserve_bootmem(PAGE_OFFSET,
648 memory_start + bootmap_size + PAGE_SIZE - 1 - PAGE_OFFSET,
652 #define EBSZ_TO_MEG(ebsz) \
655 switch (ebsz & 0xf) { \
656 case 0x1: meg = 16; break; \
657 case 0x3: meg = 32; break; \
658 case 0x5: meg = 64; break; \
659 case 0x7: meg = 128; break; \
660 case 0x9: meg = 256; break; \
661 case 0xb: meg = 512; break; \
665 static inline int __init get_mem_size(void)
667 #ifdef CONFIG_MEM_SIZE
668 return CONFIG_MEM_SIZE;
670 # if defined(EBIU_SDBCTL)
671 # if defined(BF561_FAMILY)
673 u32 sdbctl = bfin_read_EBIU_SDBCTL();
674 ret += EBSZ_TO_MEG(sdbctl >> 0);
675 ret += EBSZ_TO_MEG(sdbctl >> 8);
676 ret += EBSZ_TO_MEG(sdbctl >> 16);
677 ret += EBSZ_TO_MEG(sdbctl >> 24);
680 return EBSZ_TO_MEG(bfin_read_EBIU_SDBCTL());
682 # elif defined(EBIU_DDRCTL1)
683 u32 ddrctl = bfin_read_EBIU_DDRCTL1();
685 switch (ddrctl & 0xc0000) {
686 case DEVSZ_64: ret = 64 / 8;
687 case DEVSZ_128: ret = 128 / 8;
688 case DEVSZ_256: ret = 256 / 8;
689 case DEVSZ_512: ret = 512 / 8;
691 switch (ddrctl & 0x30000) {
692 case DEVWD_4: ret *= 2;
693 case DEVWD_8: ret *= 2;
694 case DEVWD_16: break;
702 void __init setup_arch(char **cmdline_p)
704 unsigned long sclk, cclk;
706 #ifdef CONFIG_DUMMY_CONSOLE
707 conswitchp = &dummy_con;
710 #if defined(CONFIG_CMDLINE_BOOL)
711 strncpy(&command_line[0], CONFIG_CMDLINE, sizeof(command_line));
712 command_line[sizeof(command_line) - 1] = 0;
715 /* Keep a copy of command line */
716 *cmdline_p = &command_line[0];
717 memcpy(boot_command_line, command_line, COMMAND_LINE_SIZE);
718 boot_command_line[COMMAND_LINE_SIZE - 1] = '\0';
720 /* setup memory defaults from the user config */
721 physical_mem_end = 0;
722 _ramend = get_mem_size() * 1024 * 1024;
724 memset(&bfin_memmap, 0, sizeof(bfin_memmap));
726 parse_cmdline_early(&command_line[0]);
728 if (physical_mem_end == 0)
729 physical_mem_end = _ramend;
736 #if !defined(CONFIG_BFIN_KERNEL_CLOCK)
737 if (ANOMALY_05000273 && cclk == sclk)
738 panic("ANOMALY 05000273, SCLK can not be same as CCLK");
742 if (ANOMALY_05000266) {
743 bfin_read_IMDMA_D0_IRQ_STATUS();
744 bfin_read_IMDMA_D1_IRQ_STATUS();
747 printk(KERN_INFO "Hardware Trace ");
748 if (bfin_read_TBUFCTL() & 0x1)
752 if (bfin_read_TBUFCTL() & 0x2)
753 printk("and Enabled\n");
755 printk("and Disabled\n");
757 #if defined(CONFIG_CHR_DEV_FLASH) || defined(CONFIG_BLK_DEV_FLASH)
758 /* we need to initialize the Flashrom device here since we might
759 * do things with flash early on in the boot
764 _bfin_swrst = bfin_read_SWRST();
766 if (_bfin_swrst & RESET_DOUBLE)
767 printk(KERN_INFO "Recovering from Double Fault event\n");
768 else if (_bfin_swrst & RESET_WDOG)
769 printk(KERN_INFO "Recovering from Watchdog event\n");
770 else if (_bfin_swrst & RESET_SOFTWARE)
771 printk(KERN_NOTICE "Reset caused by Software reset\n");
773 printk(KERN_INFO "Blackfin support (C) 2004-2008 Analog Devices, Inc.\n");
774 if (bfin_compiled_revid() == 0xffff)
775 printk(KERN_INFO "Compiled for ADSP-%s Rev any\n", CPU);
776 else if (bfin_compiled_revid() == -1)
777 printk(KERN_INFO "Compiled for ADSP-%s Rev none\n", CPU);
779 printk(KERN_INFO "Compiled for ADSP-%s Rev 0.%d\n", CPU, bfin_compiled_revid());
780 if (bfin_revid() != bfin_compiled_revid()) {
781 if (bfin_compiled_revid() == -1)
782 printk(KERN_ERR "Warning: Compiled for Rev none, but running on Rev %d\n",
784 else if (bfin_compiled_revid() != 0xffff)
785 printk(KERN_ERR "Warning: Compiled for Rev %d, but running on Rev %d\n",
786 bfin_compiled_revid(), bfin_revid());
788 if (bfin_revid() < SUPPORTED_REVID)
789 printk(KERN_ERR "Warning: Unsupported Chip Revision ADSP-%s Rev 0.%d detected\n",
791 printk(KERN_INFO "Blackfin Linux support by http://blackfin.uclinux.org/\n");
793 printk(KERN_INFO "Processor Speed: %lu MHz core clock and %lu MHz System Clock\n",
794 cclk / 1000000, sclk / 1000000);
796 if (ANOMALY_05000273 && (cclk >> 1) <= sclk)
797 printk("\n\n\nANOMALY_05000273: CCLK must be >= 2*SCLK !!!\n\n\n");
799 setup_bootmem_allocator();
803 /* Copy atomic sequences to their fixed location, and sanity check that
804 these locations are the ones that we advertise to userspace. */
805 memcpy((void *)FIXED_CODE_START, &fixed_code_start,
806 FIXED_CODE_END - FIXED_CODE_START);
807 BUG_ON((char *)&sigreturn_stub - (char *)&fixed_code_start
808 != SIGRETURN_STUB - FIXED_CODE_START);
809 BUG_ON((char *)&atomic_xchg32 - (char *)&fixed_code_start
810 != ATOMIC_XCHG32 - FIXED_CODE_START);
811 BUG_ON((char *)&atomic_cas32 - (char *)&fixed_code_start
812 != ATOMIC_CAS32 - FIXED_CODE_START);
813 BUG_ON((char *)&atomic_add32 - (char *)&fixed_code_start
814 != ATOMIC_ADD32 - FIXED_CODE_START);
815 BUG_ON((char *)&atomic_sub32 - (char *)&fixed_code_start
816 != ATOMIC_SUB32 - FIXED_CODE_START);
817 BUG_ON((char *)&atomic_ior32 - (char *)&fixed_code_start
818 != ATOMIC_IOR32 - FIXED_CODE_START);
819 BUG_ON((char *)&atomic_and32 - (char *)&fixed_code_start
820 != ATOMIC_AND32 - FIXED_CODE_START);
821 BUG_ON((char *)&atomic_xor32 - (char *)&fixed_code_start
822 != ATOMIC_XOR32 - FIXED_CODE_START);
823 BUG_ON((char *)&safe_user_instruction - (char *)&fixed_code_start
824 != SAFE_USER_INSTRUCTION - FIXED_CODE_START);
826 init_exception_vectors();
830 static int __init topology_init(void)
834 for_each_possible_cpu(cpu) {
835 struct cpu *c = &per_cpu(cpu_devices, cpu);
837 register_cpu(c, cpu);
843 subsys_initcall(topology_init);
845 static u_long get_vco(void)
850 msel = (bfin_read_PLL_CTL() >> 9) & 0x3F;
854 vco = CONFIG_CLKIN_HZ;
855 vco >>= (1 & bfin_read_PLL_CTL()); /* DF bit */
860 /* Get the Core clock */
861 u_long get_cclk(void)
864 if (bfin_read_PLL_STAT() & 0x1)
865 return CONFIG_CLKIN_HZ;
867 ssel = bfin_read_PLL_DIV();
868 csel = ((ssel >> 4) & 0x03);
870 if (ssel && ssel < (1 << csel)) /* SCLK > CCLK */
871 return get_vco() / ssel;
872 return get_vco() >> csel;
874 EXPORT_SYMBOL(get_cclk);
876 /* Get the System clock */
877 u_long get_sclk(void)
881 if (bfin_read_PLL_STAT() & 0x1)
882 return CONFIG_CLKIN_HZ;
884 ssel = (bfin_read_PLL_DIV() & 0xf);
886 printk(KERN_WARNING "Invalid System Clock\n");
890 return get_vco() / ssel;
892 EXPORT_SYMBOL(get_sclk);
894 unsigned long sclk_to_usecs(unsigned long sclk)
896 u64 tmp = USEC_PER_SEC * (u64)sclk;
897 do_div(tmp, get_sclk());
900 EXPORT_SYMBOL(sclk_to_usecs);
902 unsigned long usecs_to_sclk(unsigned long usecs)
904 u64 tmp = get_sclk() * (u64)usecs;
905 do_div(tmp, USEC_PER_SEC);
908 EXPORT_SYMBOL(usecs_to_sclk);
911 * Get CPU information for use by the procfs.
913 static int show_cpuinfo(struct seq_file *m, void *v)
915 char *cpu, *mmu, *fpu, *vendor, *cache;
918 u_long cclk = 0, sclk = 0;
919 u_int dcache_size = 0, dsup_banks = 0;
924 revid = bfin_revid();
929 switch (bfin_read_CHIPID() & CHIPID_MANUFACTURE) {
931 vendor = "Analog Devices";
938 seq_printf(m, "processor\t: %d\n"
940 "cpu family\t: 0x%x\n"
941 "model name\t: ADSP-%s %lu(MHz CCLK) %lu(MHz SCLK) (%s)\n"
945 (bfin_read_CHIPID() & CHIPID_FAMILY),
946 cpu, cclk/1000000, sclk/1000000,
954 seq_printf(m, "cpu MHz\t\t: %lu.%03lu/%lu.%03lu\n",
955 cclk/1000000, cclk%1000000,
956 sclk/1000000, sclk%1000000);
957 seq_printf(m, "bogomips\t: %lu.%02lu\n"
958 "Calibration\t: %lu loops\n",
959 (loops_per_jiffy * HZ) / 500000,
960 ((loops_per_jiffy * HZ) / 5000) % 100,
961 (loops_per_jiffy * HZ));
963 /* Check Cache configutation */
964 switch (bfin_read_DMEM_CONTROL() & (1 << DMC0_P | 1 << DMC1_P)) {
966 cache = "dbank-A/B\t: cache/sram";
971 cache = "dbank-A/B\t: cache/cache";
976 cache = "dbank-A/B\t: sram/sram";
987 /* Is it turned on? */
988 if (!((bfin_read_DMEM_CONTROL()) & (ENDCPLB | DMC_ENABLE)))
991 seq_printf(m, "cache size\t: %d KB(L1 icache) "
992 "%d KB(L1 dcache-%s) %d KB(L2 cache)\n",
993 BFIN_ICACHESIZE / 1024, dcache_size,
994 #if defined CONFIG_BFIN_WB
996 #elif defined CONFIG_BFIN_WT
1001 seq_printf(m, "%s\n", cache);
1003 seq_printf(m, "icache setup\t: %d Sub-banks/%d Ways, %d Lines/Way\n",
1004 BFIN_ISUBBANKS, BFIN_IWAYS, BFIN_ILINES);
1006 "dcache setup\t: %d Super-banks/%d Sub-banks/%d Ways, %d Lines/Way\n",
1007 dsup_banks, BFIN_DSUBBANKS, BFIN_DWAYS,
1009 #ifdef CONFIG_BFIN_ICACHE_LOCK
1010 switch (read_iloc()) {
1012 seq_printf(m, "Way0 Locked-Down\n");
1015 seq_printf(m, "Way1 Locked-Down\n");
1018 seq_printf(m, "Way0,Way1 Locked-Down\n");
1021 seq_printf(m, "Way2 Locked-Down\n");
1024 seq_printf(m, "Way0,Way2 Locked-Down\n");
1027 seq_printf(m, "Way1,Way2 Locked-Down\n");
1030 seq_printf(m, "Way0,Way1 & Way2 Locked-Down\n");
1033 seq_printf(m, "Way3 Locked-Down\n");
1036 seq_printf(m, "Way0,Way3 Locked-Down\n");
1039 seq_printf(m, "Way1,Way3 Locked-Down\n");
1042 seq_printf(m, "Way 0,Way1,Way3 Locked-Down\n");
1045 seq_printf(m, "Way3,Way2 Locked-Down\n");
1048 seq_printf(m, "Way3,Way2,Way0 Locked-Down\n");
1051 seq_printf(m, "Way3,Way2,Way1 Locked-Down\n");
1054 seq_printf(m, "All Ways are locked\n");
1057 seq_printf(m, "No Ways are locked\n");
1060 seq_printf(m, "board name\t: %s\n", bfin_board_name);
1061 seq_printf(m, "board memory\t: %ld kB (0x%p -> 0x%p)\n",
1062 physical_mem_end >> 10, (void *)0, (void *)physical_mem_end);
1063 seq_printf(m, "kernel memory\t: %d kB (0x%p -> 0x%p)\n",
1064 ((int)memory_end - (int)_stext) >> 10,
1066 (void *)memory_end);
1071 static void *c_start(struct seq_file *m, loff_t *pos)
1073 return *pos < NR_CPUS ? ((void *)0x12345678) : NULL;
1076 static void *c_next(struct seq_file *m, void *v, loff_t *pos)
1079 return c_start(m, pos);
1082 static void c_stop(struct seq_file *m, void *v)
1086 const struct seq_operations cpuinfo_op = {
1090 .show = show_cpuinfo,
1093 void __init cmdline_init(const char *r0)
1096 strncpy(command_line, r0, COMMAND_LINE_SIZE);