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];
55 void __initdata *init_retx, *init_saved_retx, *init_saved_seqstat,
56 *init_saved_icplb_fault_addr, *init_saved_dcplb_fault_addr;
58 /* boot memmap, for parsing "memmap=" */
59 #define BFIN_MEMMAP_MAX 128 /* number of entries in bfin_memmap */
60 #define BFIN_MEMMAP_RAM 1
61 #define BFIN_MEMMAP_RESERVED 2
64 struct bfin_memmap_entry {
65 unsigned long long addr; /* start of memory segment */
66 unsigned long long size;
68 } map[BFIN_MEMMAP_MAX];
69 } bfin_memmap __initdata;
71 /* for memmap sanitization */
72 struct change_member {
73 struct bfin_memmap_entry *pentry; /* pointer to original entry */
74 unsigned long long addr; /* address for this change point */
76 static struct change_member change_point_list[2*BFIN_MEMMAP_MAX] __initdata;
77 static struct change_member *change_point[2*BFIN_MEMMAP_MAX] __initdata;
78 static struct bfin_memmap_entry *overlap_list[BFIN_MEMMAP_MAX] __initdata;
79 static struct bfin_memmap_entry new_map[BFIN_MEMMAP_MAX] __initdata;
81 void __init bfin_cache_init(void)
83 #if defined(CONFIG_BFIN_DCACHE) || defined(CONFIG_BFIN_ICACHE)
84 generate_cplb_tables();
87 #ifdef CONFIG_BFIN_ICACHE
89 printk(KERN_INFO "Instruction Cache Enabled\n");
92 #ifdef CONFIG_BFIN_DCACHE
94 printk(KERN_INFO "Data Cache Enabled"
95 # if defined CONFIG_BFIN_WB
97 # elif defined CONFIG_BFIN_WT
104 void __init bfin_relocate_l1_mem(void)
106 unsigned long l1_code_length;
107 unsigned long l1_data_a_length;
108 unsigned long l1_data_b_length;
109 unsigned long l2_length;
111 l1_code_length = _etext_l1 - _stext_l1;
112 if (l1_code_length > L1_CODE_LENGTH)
113 panic("L1 Instruction SRAM Overflow\n");
114 /* cannot complain as printk is not available as yet.
115 * But we can continue booting and complain later!
118 /* Copy _stext_l1 to _etext_l1 to L1 instruction SRAM */
119 dma_memcpy(_stext_l1, _l1_lma_start, l1_code_length);
121 l1_data_a_length = _ebss_l1 - _sdata_l1;
122 if (l1_data_a_length > L1_DATA_A_LENGTH)
123 panic("L1 Data SRAM Bank A Overflow\n");
125 /* Copy _sdata_l1 to _ebss_l1 to L1 data bank A SRAM */
126 dma_memcpy(_sdata_l1, _l1_lma_start + l1_code_length, l1_data_a_length);
128 l1_data_b_length = _ebss_b_l1 - _sdata_b_l1;
129 if (l1_data_b_length > L1_DATA_B_LENGTH)
130 panic("L1 Data SRAM Bank B Overflow\n");
132 /* Copy _sdata_b_l1 to _ebss_b_l1 to L1 data bank B SRAM */
133 dma_memcpy(_sdata_b_l1, _l1_lma_start + l1_code_length +
134 l1_data_a_length, l1_data_b_length);
136 if (L2_LENGTH != 0) {
137 l2_length = _ebss_l2 - _stext_l2;
138 if (l2_length > L2_LENGTH)
139 panic("L2 SRAM Overflow\n");
141 /* Copy _stext_l2 to _edata_l2 to L2 SRAM */
142 dma_memcpy(_stext_l2, _l2_lma_start, l2_length);
146 /* add_memory_region to memmap */
147 static void __init add_memory_region(unsigned long long start,
148 unsigned long long size, int type)
152 i = bfin_memmap.nr_map;
154 if (i == BFIN_MEMMAP_MAX) {
155 printk(KERN_ERR "Ooops! Too many entries in the memory map!\n");
159 bfin_memmap.map[i].addr = start;
160 bfin_memmap.map[i].size = size;
161 bfin_memmap.map[i].type = type;
162 bfin_memmap.nr_map++;
166 * Sanitize the boot memmap, removing overlaps.
168 static int __init sanitize_memmap(struct bfin_memmap_entry *map, int *pnr_map)
170 struct change_member *change_tmp;
171 unsigned long current_type, last_type;
172 unsigned long long last_addr;
173 int chgidx, still_changing;
176 int old_nr, new_nr, chg_nr;
180 Visually we're performing the following (1,2,3,4 = memory types)
182 Sample memory map (w/overlaps):
183 ____22__________________
184 ______________________4_
185 ____1111________________
186 _44_____________________
187 11111111________________
188 ____________________33__
189 ___________44___________
190 __________33333_________
191 ______________22________
192 ___________________2222_
193 _________111111111______
194 _____________________11_
195 _________________4______
197 Sanitized equivalent (no overlap):
198 1_______________________
199 _44_____________________
200 ___1____________________
201 ____22__________________
202 ______11________________
203 _________1______________
204 __________3_____________
205 ___________44___________
206 _____________33_________
207 _______________2________
208 ________________1_______
209 _________________4______
210 ___________________2____
211 ____________________33__
212 ______________________4_
214 /* if there's only one memory region, don't bother */
220 /* bail out if we find any unreasonable addresses in memmap */
221 for (i = 0; i < old_nr; i++)
222 if (map[i].addr + map[i].size < map[i].addr)
225 /* create pointers for initial change-point information (for sorting) */
226 for (i = 0; i < 2*old_nr; i++)
227 change_point[i] = &change_point_list[i];
229 /* record all known change-points (starting and ending addresses),
230 omitting those that are for empty memory regions */
232 for (i = 0; i < old_nr; i++) {
233 if (map[i].size != 0) {
234 change_point[chgidx]->addr = map[i].addr;
235 change_point[chgidx++]->pentry = &map[i];
236 change_point[chgidx]->addr = map[i].addr + map[i].size;
237 change_point[chgidx++]->pentry = &map[i];
240 chg_nr = chgidx; /* true number of change-points */
242 /* sort change-point list by memory addresses (low -> high) */
244 while (still_changing) {
246 for (i = 1; i < chg_nr; i++) {
247 /* if <current_addr> > <last_addr>, swap */
248 /* or, if current=<start_addr> & last=<end_addr>, swap */
249 if ((change_point[i]->addr < change_point[i-1]->addr) ||
250 ((change_point[i]->addr == change_point[i-1]->addr) &&
251 (change_point[i]->addr == change_point[i]->pentry->addr) &&
252 (change_point[i-1]->addr != change_point[i-1]->pentry->addr))
254 change_tmp = change_point[i];
255 change_point[i] = change_point[i-1];
256 change_point[i-1] = change_tmp;
262 /* create a new memmap, removing overlaps */
263 overlap_entries = 0; /* number of entries in the overlap table */
264 new_entry = 0; /* index for creating new memmap entries */
265 last_type = 0; /* start with undefined memory type */
266 last_addr = 0; /* start with 0 as last starting address */
267 /* loop through change-points, determining affect on the new memmap */
268 for (chgidx = 0; chgidx < chg_nr; chgidx++) {
269 /* keep track of all overlapping memmap entries */
270 if (change_point[chgidx]->addr == change_point[chgidx]->pentry->addr) {
271 /* add map entry to overlap list (> 1 entry implies an overlap) */
272 overlap_list[overlap_entries++] = change_point[chgidx]->pentry;
274 /* remove entry from list (order independent, so swap with last) */
275 for (i = 0; i < overlap_entries; i++) {
276 if (overlap_list[i] == change_point[chgidx]->pentry)
277 overlap_list[i] = overlap_list[overlap_entries-1];
281 /* if there are overlapping entries, decide which "type" to use */
282 /* (larger value takes precedence -- 1=usable, 2,3,4,4+=unusable) */
284 for (i = 0; i < overlap_entries; i++)
285 if (overlap_list[i]->type > current_type)
286 current_type = overlap_list[i]->type;
287 /* continue building up new memmap based on this information */
288 if (current_type != last_type) {
289 if (last_type != 0) {
290 new_map[new_entry].size =
291 change_point[chgidx]->addr - last_addr;
292 /* move forward only if the new size was non-zero */
293 if (new_map[new_entry].size != 0)
294 if (++new_entry >= BFIN_MEMMAP_MAX)
295 break; /* no more space left for new entries */
297 if (current_type != 0) {
298 new_map[new_entry].addr = change_point[chgidx]->addr;
299 new_map[new_entry].type = current_type;
300 last_addr = change_point[chgidx]->addr;
302 last_type = current_type;
305 new_nr = new_entry; /* retain count for new entries */
307 /* copy new mapping into original location */
308 memcpy(map, new_map, new_nr*sizeof(struct bfin_memmap_entry));
314 static void __init print_memory_map(char *who)
318 for (i = 0; i < bfin_memmap.nr_map; i++) {
319 printk(KERN_DEBUG " %s: %016Lx - %016Lx ", who,
320 bfin_memmap.map[i].addr,
321 bfin_memmap.map[i].addr + bfin_memmap.map[i].size);
322 switch (bfin_memmap.map[i].type) {
323 case BFIN_MEMMAP_RAM:
324 printk("(usable)\n");
326 case BFIN_MEMMAP_RESERVED:
327 printk("(reserved)\n");
329 default: printk("type %lu\n", bfin_memmap.map[i].type);
335 static __init int parse_memmap(char *arg)
337 unsigned long long start_at, mem_size;
342 mem_size = memparse(arg, &arg);
344 start_at = memparse(arg+1, &arg);
345 add_memory_region(start_at, mem_size, BFIN_MEMMAP_RAM);
346 } else if (*arg == '$') {
347 start_at = memparse(arg+1, &arg);
348 add_memory_region(start_at, mem_size, BFIN_MEMMAP_RESERVED);
355 * Initial parsing of the command line. Currently, we support:
356 * - Controlling the linux memory size: mem=xxx[KMG]
357 * - Controlling the physical memory size: max_mem=xxx[KMG][$][#]
358 * $ -> reserved memory is dcacheable
359 * # -> reserved memory is icacheable
360 * - "memmap=XXX[KkmM][@][$]XXX[KkmM]" defines a memory region
361 * @ from <start> to <start>+<mem>, type RAM
362 * $ from <start> to <start>+<mem>, type RESERVED
365 static __init void parse_cmdline_early(char *cmdline_p)
367 char c = ' ', *to = cmdline_p;
368 unsigned int memsize;
371 if (!memcmp(to, "mem=", 4)) {
373 memsize = memparse(to, &to);
377 } else if (!memcmp(to, "max_mem=", 8)) {
379 memsize = memparse(to, &to);
381 physical_mem_end = memsize;
385 reserved_mem_dcache_on =
389 reserved_mem_icache_on =
393 } else if (!memcmp(to, "earlyprintk=", 12)) {
395 setup_early_printk(to);
396 } else if (!memcmp(to, "memmap=", 7)) {
408 * Setup memory defaults from user config.
409 * The physical memory layout looks like:
411 * [_rambase, _ramstart]: kernel image
412 * [memory_start, memory_end]: dynamic memory managed by kernel
413 * [memory_end, _ramend]: reserved memory
414 * [meory_mtd_start(memory_end),
415 * memory_mtd_start + mtd_size]: rootfs (if any)
416 * [_ramend - DMA_UNCACHED_REGION,
417 * _ramend]: uncached DMA region
418 * [_ramend, physical_mem_end]: memory not managed by kernel
421 static __init void memory_setup(void)
423 #ifdef CONFIG_MTD_UCLINUX
424 unsigned long mtd_phys = 0;
427 _rambase = (unsigned long)_stext;
428 _ramstart = (unsigned long)_end;
430 if (DMA_UNCACHED_REGION > (_ramend - _ramstart)) {
432 panic("DMA region exceeds memory limit: %lu.\n",
433 _ramend - _ramstart);
435 memory_end = _ramend - DMA_UNCACHED_REGION;
438 /* Round up to multiple of 4MB. */
439 memory_start = (_ramstart + 0x3fffff) & ~0x3fffff;
441 memory_start = PAGE_ALIGN(_ramstart);
444 #if defined(CONFIG_MTD_UCLINUX)
445 /* generic memory mapped MTD driver */
446 memory_mtd_end = memory_end;
448 mtd_phys = _ramstart;
449 mtd_size = PAGE_ALIGN(*((unsigned long *)(mtd_phys + 8)));
451 # if defined(CONFIG_EXT2_FS) || defined(CONFIG_EXT3_FS)
452 if (*((unsigned short *)(mtd_phys + 0x438)) == EXT2_SUPER_MAGIC)
454 PAGE_ALIGN(*((unsigned long *)(mtd_phys + 0x404)) << 10);
457 # if defined(CONFIG_CRAMFS)
458 if (*((unsigned long *)(mtd_phys)) == CRAMFS_MAGIC)
459 mtd_size = PAGE_ALIGN(*((unsigned long *)(mtd_phys + 0x4)));
462 # if defined(CONFIG_ROMFS_FS)
463 if (((unsigned long *)mtd_phys)[0] == ROMSB_WORD0
464 && ((unsigned long *)mtd_phys)[1] == ROMSB_WORD1)
466 PAGE_ALIGN(be32_to_cpu(((unsigned long *)mtd_phys)[2]));
467 # if (defined(CONFIG_BFIN_ICACHE) && ANOMALY_05000263)
468 /* Due to a Hardware Anomaly we need to limit the size of usable
469 * instruction memory to max 60MB, 56 if HUNT_FOR_ZERO is on
470 * 05000263 - Hardware loop corrupted when taking an ICPLB exception
472 # if (defined(CONFIG_DEBUG_HUNT_FOR_ZERO))
473 if (memory_end >= 56 * 1024 * 1024)
474 memory_end = 56 * 1024 * 1024;
476 if (memory_end >= 60 * 1024 * 1024)
477 memory_end = 60 * 1024 * 1024;
478 # endif /* CONFIG_DEBUG_HUNT_FOR_ZERO */
479 # endif /* ANOMALY_05000263 */
480 # endif /* CONFIG_ROMFS_FS */
482 memory_end -= mtd_size;
486 panic("Don't boot kernel without rootfs attached.\n");
489 /* Relocate MTD image to the top of memory after the uncached memory area */
490 dma_memcpy((char *)memory_end, _end, mtd_size);
492 memory_mtd_start = memory_end;
493 _ebss = memory_mtd_start; /* define _ebss for compatible */
494 #endif /* CONFIG_MTD_UCLINUX */
496 #if (defined(CONFIG_BFIN_ICACHE) && ANOMALY_05000263)
497 /* Due to a Hardware Anomaly we need to limit the size of usable
498 * instruction memory to max 60MB, 56 if HUNT_FOR_ZERO is on
499 * 05000263 - Hardware loop corrupted when taking an ICPLB exception
501 #if (defined(CONFIG_DEBUG_HUNT_FOR_ZERO))
502 if (memory_end >= 56 * 1024 * 1024)
503 memory_end = 56 * 1024 * 1024;
505 if (memory_end >= 60 * 1024 * 1024)
506 memory_end = 60 * 1024 * 1024;
507 #endif /* CONFIG_DEBUG_HUNT_FOR_ZERO */
508 printk(KERN_NOTICE "Warning: limiting memory to %liMB due to hardware anomaly 05000263\n", memory_end >> 20);
509 #endif /* ANOMALY_05000263 */
512 page_mask_nelts = ((_ramend >> PAGE_SHIFT) + 31) / 32;
513 page_mask_order = get_order(3 * page_mask_nelts * sizeof(long));
516 #if !defined(CONFIG_MTD_UCLINUX)
517 /*In case there is no valid CPLB behind memory_end make sure we don't get to close*/
518 memory_end -= SIZE_4K;
521 init_mm.start_code = (unsigned long)_stext;
522 init_mm.end_code = (unsigned long)_etext;
523 init_mm.end_data = (unsigned long)_edata;
524 init_mm.brk = (unsigned long)0;
526 printk(KERN_INFO "Board Memory: %ldMB\n", physical_mem_end >> 20);
527 printk(KERN_INFO "Kernel Managed Memory: %ldMB\n", _ramend >> 20);
529 printk(KERN_INFO "Memory map:\n"
530 KERN_INFO " fixedcode = 0x%p-0x%p\n"
531 KERN_INFO " text = 0x%p-0x%p\n"
532 KERN_INFO " rodata = 0x%p-0x%p\n"
533 KERN_INFO " bss = 0x%p-0x%p\n"
534 KERN_INFO " data = 0x%p-0x%p\n"
535 KERN_INFO " stack = 0x%p-0x%p\n"
536 KERN_INFO " init = 0x%p-0x%p\n"
537 KERN_INFO " available = 0x%p-0x%p\n"
538 #ifdef CONFIG_MTD_UCLINUX
539 KERN_INFO " rootfs = 0x%p-0x%p\n"
541 #if DMA_UNCACHED_REGION > 0
542 KERN_INFO " DMA Zone = 0x%p-0x%p\n"
544 , (void *)FIXED_CODE_START, (void *)FIXED_CODE_END,
546 __start_rodata, __end_rodata,
547 __bss_start, __bss_stop,
549 (void *)&init_thread_union,
550 (void *)((int)(&init_thread_union) + 0x2000),
551 __init_begin, __init_end,
552 (void *)_ramstart, (void *)memory_end
553 #ifdef CONFIG_MTD_UCLINUX
554 , (void *)memory_mtd_start, (void *)(memory_mtd_start + mtd_size)
556 #if DMA_UNCACHED_REGION > 0
557 , (void *)(_ramend - DMA_UNCACHED_REGION), (void *)(_ramend)
563 * Find the lowest, highest page frame number we have available
565 void __init find_min_max_pfn(void)
570 min_low_pfn = memory_end;
572 for (i = 0; i < bfin_memmap.nr_map; i++) {
573 unsigned long start, end;
575 if (bfin_memmap.map[i].type != BFIN_MEMMAP_RAM)
577 start = PFN_UP(bfin_memmap.map[i].addr);
578 end = PFN_DOWN(bfin_memmap.map[i].addr +
579 bfin_memmap.map[i].size);
584 if (start < min_low_pfn)
589 static __init void setup_bootmem_allocator(void)
593 unsigned long start_pfn, end_pfn;
594 unsigned long curr_pfn, last_pfn, size;
596 /* mark memory between memory_start and memory_end usable */
597 add_memory_region(memory_start,
598 memory_end - memory_start, BFIN_MEMMAP_RAM);
599 /* sanity check for overlap */
600 sanitize_memmap(bfin_memmap.map, &bfin_memmap.nr_map);
601 print_memory_map("boot memmap");
603 /* intialize globals in linux/bootmem.h */
605 /* pfn of the last usable page frame */
606 if (max_pfn > memory_end >> PAGE_SHIFT)
607 max_pfn = memory_end >> PAGE_SHIFT;
608 /* pfn of last page frame directly mapped by kernel */
609 max_low_pfn = max_pfn;
610 /* pfn of the first usable page frame after kernel image*/
611 if (min_low_pfn < memory_start >> PAGE_SHIFT)
612 min_low_pfn = memory_start >> PAGE_SHIFT;
614 start_pfn = PAGE_OFFSET >> PAGE_SHIFT;
615 end_pfn = memory_end >> PAGE_SHIFT;
618 * give all the memory to the bootmap allocator, tell it to put the
619 * boot mem_map at the start of memory.
621 bootmap_size = init_bootmem_node(NODE_DATA(0),
622 memory_start >> PAGE_SHIFT, /* map goes here */
625 /* register the memmap regions with the bootmem allocator */
626 for (i = 0; i < bfin_memmap.nr_map; i++) {
628 * Reserve usable memory
630 if (bfin_memmap.map[i].type != BFIN_MEMMAP_RAM)
633 * We are rounding up the start address of usable memory:
635 curr_pfn = PFN_UP(bfin_memmap.map[i].addr);
636 if (curr_pfn >= end_pfn)
639 * ... and at the end of the usable range downwards:
641 last_pfn = PFN_DOWN(bfin_memmap.map[i].addr +
642 bfin_memmap.map[i].size);
644 if (last_pfn > end_pfn)
648 * .. finally, did all the rounding and playing
649 * around just make the area go away?
651 if (last_pfn <= curr_pfn)
654 size = last_pfn - curr_pfn;
655 free_bootmem(PFN_PHYS(curr_pfn), PFN_PHYS(size));
658 /* reserve memory before memory_start, including bootmap */
659 reserve_bootmem(PAGE_OFFSET,
660 memory_start + bootmap_size + PAGE_SIZE - 1 - PAGE_OFFSET,
664 #define EBSZ_TO_MEG(ebsz) \
667 switch (ebsz & 0xf) { \
668 case 0x1: meg = 16; break; \
669 case 0x3: meg = 32; break; \
670 case 0x5: meg = 64; break; \
671 case 0x7: meg = 128; break; \
672 case 0x9: meg = 256; break; \
673 case 0xb: meg = 512; break; \
677 static inline int __init get_mem_size(void)
679 #if defined(EBIU_SDBCTL)
680 # if defined(BF561_FAMILY)
682 u32 sdbctl = bfin_read_EBIU_SDBCTL();
683 ret += EBSZ_TO_MEG(sdbctl >> 0);
684 ret += EBSZ_TO_MEG(sdbctl >> 8);
685 ret += EBSZ_TO_MEG(sdbctl >> 16);
686 ret += EBSZ_TO_MEG(sdbctl >> 24);
689 return EBSZ_TO_MEG(bfin_read_EBIU_SDBCTL());
691 #elif defined(EBIU_DDRCTL1)
692 u32 ddrctl = bfin_read_EBIU_DDRCTL1();
694 switch (ddrctl & 0xc0000) {
695 case DEVSZ_64: ret = 64 / 8;
696 case DEVSZ_128: ret = 128 / 8;
697 case DEVSZ_256: ret = 256 / 8;
698 case DEVSZ_512: ret = 512 / 8;
700 switch (ddrctl & 0x30000) {
701 case DEVWD_4: ret *= 2;
702 case DEVWD_8: ret *= 2;
703 case DEVWD_16: break;
705 if ((ddrctl & 0xc000) == 0x4000)
712 void __init setup_arch(char **cmdline_p)
714 unsigned long sclk, cclk;
716 #ifdef CONFIG_DUMMY_CONSOLE
717 conswitchp = &dummy_con;
720 #if defined(CONFIG_CMDLINE_BOOL)
721 strncpy(&command_line[0], CONFIG_CMDLINE, sizeof(command_line));
722 command_line[sizeof(command_line) - 1] = 0;
725 /* Keep a copy of command line */
726 *cmdline_p = &command_line[0];
727 memcpy(boot_command_line, command_line, COMMAND_LINE_SIZE);
728 boot_command_line[COMMAND_LINE_SIZE - 1] = '\0';
730 /* setup memory defaults from the user config */
731 physical_mem_end = 0;
732 _ramend = get_mem_size() * 1024 * 1024;
734 memset(&bfin_memmap, 0, sizeof(bfin_memmap));
736 parse_cmdline_early(&command_line[0]);
738 if (physical_mem_end == 0)
739 physical_mem_end = _ramend;
743 /* Initialize Async memory banks */
744 bfin_write_EBIU_AMBCTL0(AMBCTL0VAL);
745 bfin_write_EBIU_AMBCTL1(AMBCTL1VAL);
746 bfin_write_EBIU_AMGCTL(AMGCTLVAL);
747 #ifdef CONFIG_EBIU_MBSCTLVAL
748 bfin_write_EBIU_MBSCTL(CONFIG_EBIU_MBSCTLVAL);
749 bfin_write_EBIU_MODE(CONFIG_EBIU_MODEVAL);
750 bfin_write_EBIU_FCTL(CONFIG_EBIU_FCTLVAL);
756 #if !defined(CONFIG_BFIN_KERNEL_CLOCK)
757 if (ANOMALY_05000273 && cclk == sclk)
758 panic("ANOMALY 05000273, SCLK can not be same as CCLK");
762 if (ANOMALY_05000266) {
763 bfin_read_IMDMA_D0_IRQ_STATUS();
764 bfin_read_IMDMA_D1_IRQ_STATUS();
767 printk(KERN_INFO "Hardware Trace ");
768 if (bfin_read_TBUFCTL() & 0x1)
772 if (bfin_read_TBUFCTL() & 0x2)
773 printk("and Enabled\n");
775 printk("and Disabled\n");
777 #if defined(CONFIG_CHR_DEV_FLASH) || defined(CONFIG_BLK_DEV_FLASH)
778 /* we need to initialize the Flashrom device here since we might
779 * do things with flash early on in the boot
784 _bfin_swrst = bfin_read_SWRST();
786 #ifdef CONFIG_DEBUG_DOUBLEFAULT_PRINT
787 bfin_write_SWRST(_bfin_swrst & ~DOUBLE_FAULT);
789 #ifdef CONFIG_DEBUG_DOUBLEFAULT_RESET
790 bfin_write_SWRST(_bfin_swrst | DOUBLE_FAULT);
793 if (_bfin_swrst & RESET_DOUBLE) {
794 printk(KERN_EMERG "Recovering from DOUBLE FAULT event\n");
795 #ifdef CONFIG_DEBUG_DOUBLEFAULT
796 /* We assume the crashing kernel, and the current symbol table match */
797 printk(KERN_EMERG " While handling exception (EXCAUSE = 0x%x) at %pF\n",
798 (int)init_saved_seqstat & SEQSTAT_EXCAUSE, init_saved_retx);
799 printk(KERN_NOTICE " DCPLB_FAULT_ADDR: %pF\n", init_saved_dcplb_fault_addr);
800 printk(KERN_NOTICE " ICPLB_FAULT_ADDR: %pF\n", init_saved_icplb_fault_addr);
802 printk(KERN_NOTICE " The instruction at %pF caused a double exception\n",
804 } else if (_bfin_swrst & RESET_WDOG)
805 printk(KERN_INFO "Recovering from Watchdog event\n");
806 else if (_bfin_swrst & RESET_SOFTWARE)
807 printk(KERN_NOTICE "Reset caused by Software reset\n");
809 printk(KERN_INFO "Blackfin support (C) 2004-2008 Analog Devices, Inc.\n");
810 if (bfin_compiled_revid() == 0xffff)
811 printk(KERN_INFO "Compiled for ADSP-%s Rev any\n", CPU);
812 else if (bfin_compiled_revid() == -1)
813 printk(KERN_INFO "Compiled for ADSP-%s Rev none\n", CPU);
815 printk(KERN_INFO "Compiled for ADSP-%s Rev 0.%d\n", CPU, bfin_compiled_revid());
816 if (bfin_revid() != bfin_compiled_revid()) {
817 if (bfin_compiled_revid() == -1)
818 printk(KERN_ERR "Warning: Compiled for Rev none, but running on Rev %d\n",
820 else if (bfin_compiled_revid() != 0xffff)
821 printk(KERN_ERR "Warning: Compiled for Rev %d, but running on Rev %d\n",
822 bfin_compiled_revid(), bfin_revid());
824 if (bfin_revid() < SUPPORTED_REVID)
825 printk(KERN_ERR "Warning: Unsupported Chip Revision ADSP-%s Rev 0.%d detected\n",
827 printk(KERN_INFO "Blackfin Linux support by http://blackfin.uclinux.org/\n");
829 printk(KERN_INFO "Processor Speed: %lu MHz core clock and %lu MHz System Clock\n",
830 cclk / 1000000, sclk / 1000000);
832 if (ANOMALY_05000273 && (cclk >> 1) <= sclk)
833 printk("\n\n\nANOMALY_05000273: CCLK must be >= 2*SCLK !!!\n\n\n");
835 setup_bootmem_allocator();
839 /* Copy atomic sequences to their fixed location, and sanity check that
840 these locations are the ones that we advertise to userspace. */
841 memcpy((void *)FIXED_CODE_START, &fixed_code_start,
842 FIXED_CODE_END - FIXED_CODE_START);
843 BUG_ON((char *)&sigreturn_stub - (char *)&fixed_code_start
844 != SIGRETURN_STUB - FIXED_CODE_START);
845 BUG_ON((char *)&atomic_xchg32 - (char *)&fixed_code_start
846 != ATOMIC_XCHG32 - FIXED_CODE_START);
847 BUG_ON((char *)&atomic_cas32 - (char *)&fixed_code_start
848 != ATOMIC_CAS32 - FIXED_CODE_START);
849 BUG_ON((char *)&atomic_add32 - (char *)&fixed_code_start
850 != ATOMIC_ADD32 - FIXED_CODE_START);
851 BUG_ON((char *)&atomic_sub32 - (char *)&fixed_code_start
852 != ATOMIC_SUB32 - FIXED_CODE_START);
853 BUG_ON((char *)&atomic_ior32 - (char *)&fixed_code_start
854 != ATOMIC_IOR32 - FIXED_CODE_START);
855 BUG_ON((char *)&atomic_and32 - (char *)&fixed_code_start
856 != ATOMIC_AND32 - FIXED_CODE_START);
857 BUG_ON((char *)&atomic_xor32 - (char *)&fixed_code_start
858 != ATOMIC_XOR32 - FIXED_CODE_START);
859 BUG_ON((char *)&safe_user_instruction - (char *)&fixed_code_start
860 != SAFE_USER_INSTRUCTION - FIXED_CODE_START);
862 init_exception_vectors();
866 static int __init topology_init(void)
870 for_each_possible_cpu(cpu) {
871 struct cpu *c = &per_cpu(cpu_devices, cpu);
873 register_cpu(c, cpu);
879 subsys_initcall(topology_init);
881 /* Get the voltage input multiplier */
882 static u_long cached_vco_pll_ctl, cached_vco;
883 static u_long get_vco(void)
887 u_long pll_ctl = bfin_read_PLL_CTL();
888 if (pll_ctl == cached_vco_pll_ctl)
891 cached_vco_pll_ctl = pll_ctl;
893 msel = (pll_ctl >> 9) & 0x3F;
897 cached_vco = CONFIG_CLKIN_HZ;
898 cached_vco >>= (1 & pll_ctl); /* DF bit */
903 /* Get the Core clock */
904 static u_long cached_cclk_pll_div, cached_cclk;
905 u_long get_cclk(void)
909 if (bfin_read_PLL_STAT() & 0x1)
910 return CONFIG_CLKIN_HZ;
912 ssel = bfin_read_PLL_DIV();
913 if (ssel == cached_cclk_pll_div)
916 cached_cclk_pll_div = ssel;
918 csel = ((ssel >> 4) & 0x03);
920 if (ssel && ssel < (1 << csel)) /* SCLK > CCLK */
921 cached_cclk = get_vco() / ssel;
923 cached_cclk = get_vco() >> csel;
926 EXPORT_SYMBOL(get_cclk);
928 /* Get the System clock */
929 static u_long cached_sclk_pll_div, cached_sclk;
930 u_long get_sclk(void)
934 if (bfin_read_PLL_STAT() & 0x1)
935 return CONFIG_CLKIN_HZ;
937 ssel = bfin_read_PLL_DIV();
938 if (ssel == cached_sclk_pll_div)
941 cached_sclk_pll_div = ssel;
945 printk(KERN_WARNING "Invalid System Clock\n");
949 cached_sclk = get_vco() / ssel;
952 EXPORT_SYMBOL(get_sclk);
954 unsigned long sclk_to_usecs(unsigned long sclk)
956 u64 tmp = USEC_PER_SEC * (u64)sclk;
957 do_div(tmp, get_sclk());
960 EXPORT_SYMBOL(sclk_to_usecs);
962 unsigned long usecs_to_sclk(unsigned long usecs)
964 u64 tmp = get_sclk() * (u64)usecs;
965 do_div(tmp, USEC_PER_SEC);
968 EXPORT_SYMBOL(usecs_to_sclk);
971 * Get CPU information for use by the procfs.
973 static int show_cpuinfo(struct seq_file *m, void *v)
975 char *cpu, *mmu, *fpu, *vendor, *cache;
978 u_long cclk = 0, sclk = 0;
979 u_int icache_size = BFIN_ICACHESIZE / 1024, dcache_size = 0, dsup_banks = 0;
984 revid = bfin_revid();
989 switch (bfin_read_CHIPID() & CHIPID_MANUFACTURE) {
991 vendor = "Analog Devices";
998 seq_printf(m, "processor\t: %d\n"
1000 "cpu family\t: 0x%x\n"
1001 "model name\t: ADSP-%s %lu(MHz CCLK) %lu(MHz SCLK) (%s)\n"
1005 (bfin_read_CHIPID() & CHIPID_FAMILY),
1006 cpu, cclk/1000000, sclk/1000000,
1014 seq_printf(m, "cpu MHz\t\t: %lu.%03lu/%lu.%03lu\n",
1015 cclk/1000000, cclk%1000000,
1016 sclk/1000000, sclk%1000000);
1017 seq_printf(m, "bogomips\t: %lu.%02lu\n"
1018 "Calibration\t: %lu loops\n",
1019 (loops_per_jiffy * HZ) / 500000,
1020 ((loops_per_jiffy * HZ) / 5000) % 100,
1021 (loops_per_jiffy * HZ));
1023 /* Check Cache configutation */
1024 switch (bfin_read_DMEM_CONTROL() & (1 << DMC0_P | 1 << DMC1_P)) {
1026 cache = "dbank-A/B\t: cache/sram";
1031 cache = "dbank-A/B\t: cache/cache";
1036 cache = "dbank-A/B\t: sram/sram";
1047 /* Is it turned on? */
1048 if ((bfin_read_DMEM_CONTROL() & (ENDCPLB | DMC_ENABLE)) != (ENDCPLB | DMC_ENABLE))
1051 if ((bfin_read_IMEM_CONTROL() & (IMC | ENICPLB)) != (IMC | ENICPLB))
1054 seq_printf(m, "cache size\t: %d KB(L1 icache) "
1055 "%d KB(L1 dcache-%s) %d KB(L2 cache)\n",
1056 icache_size, dcache_size,
1057 #if defined CONFIG_BFIN_WB
1059 #elif defined CONFIG_BFIN_WT
1064 seq_printf(m, "%s\n", cache);
1067 seq_printf(m, "icache setup\t: %d Sub-banks/%d Ways, %d Lines/Way\n",
1068 BFIN_ISUBBANKS, BFIN_IWAYS, BFIN_ILINES);
1070 seq_printf(m, "icache setup\t: off\n");
1073 "dcache setup\t: %d Super-banks/%d Sub-banks/%d Ways, %d Lines/Way\n",
1074 dsup_banks, BFIN_DSUBBANKS, BFIN_DWAYS,
1076 #ifdef CONFIG_BFIN_ICACHE_LOCK
1077 switch ((bfin_read_IMEM_CONTROL() >> 3) & WAYALL_L) {
1079 seq_printf(m, "Way0 Locked-Down\n");
1082 seq_printf(m, "Way1 Locked-Down\n");
1085 seq_printf(m, "Way0,Way1 Locked-Down\n");
1088 seq_printf(m, "Way2 Locked-Down\n");
1091 seq_printf(m, "Way0,Way2 Locked-Down\n");
1094 seq_printf(m, "Way1,Way2 Locked-Down\n");
1097 seq_printf(m, "Way0,Way1 & Way2 Locked-Down\n");
1100 seq_printf(m, "Way3 Locked-Down\n");
1103 seq_printf(m, "Way0,Way3 Locked-Down\n");
1106 seq_printf(m, "Way1,Way3 Locked-Down\n");
1109 seq_printf(m, "Way 0,Way1,Way3 Locked-Down\n");
1112 seq_printf(m, "Way3,Way2 Locked-Down\n");
1115 seq_printf(m, "Way3,Way2,Way0 Locked-Down\n");
1118 seq_printf(m, "Way3,Way2,Way1 Locked-Down\n");
1121 seq_printf(m, "All Ways are locked\n");
1124 seq_printf(m, "No Ways are locked\n");
1127 seq_printf(m, "board name\t: %s\n", bfin_board_name);
1128 seq_printf(m, "board memory\t: %ld kB (0x%p -> 0x%p)\n",
1129 physical_mem_end >> 10, (void *)0, (void *)physical_mem_end);
1130 seq_printf(m, "kernel memory\t: %d kB (0x%p -> 0x%p)\n",
1131 ((int)memory_end - (int)_stext) >> 10,
1133 (void *)memory_end);
1138 static void *c_start(struct seq_file *m, loff_t *pos)
1141 *pos = first_cpu(cpu_online_map);
1142 if (*pos >= num_online_cpus())
1148 static void *c_next(struct seq_file *m, void *v, loff_t *pos)
1150 *pos = next_cpu(*pos, cpu_online_map);
1152 return c_start(m, pos);
1155 static void c_stop(struct seq_file *m, void *v)
1159 const struct seq_operations cpuinfo_op = {
1163 .show = show_cpuinfo,
1166 void __init cmdline_init(const char *r0)
1169 strncpy(command_line, r0, COMMAND_LINE_SIZE);