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>
30 #include <asm/fixed_code.h>
31 #include <asm/early_printk.h>
34 EXPORT_SYMBOL(_bfin_swrst);
36 unsigned long memory_start, memory_end, physical_mem_end;
37 unsigned long _rambase, _ramstart, _ramend;
38 unsigned long reserved_mem_dcache_on;
39 unsigned long reserved_mem_icache_on;
40 EXPORT_SYMBOL(memory_start);
41 EXPORT_SYMBOL(memory_end);
42 EXPORT_SYMBOL(physical_mem_end);
43 EXPORT_SYMBOL(_ramend);
44 EXPORT_SYMBOL(reserved_mem_dcache_on);
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 DEFINE_PER_CPU(struct blackfin_cpudata, cpu_data);
83 #if defined(CONFIG_BFIN_DCACHE) || defined(CONFIG_BFIN_ICACHE)
84 void __init generate_cplb_tables(void)
88 /* Generate per-CPU I&D CPLB tables */
89 for (cpu = 0; cpu < num_possible_cpus(); ++cpu)
90 generate_cplb_tables_cpu(cpu);
94 void __cpuinit bfin_setup_caches(unsigned int cpu)
96 #ifdef CONFIG_BFIN_ICACHE
98 bfin_icache_init(icplb_tbl[cpu]);
100 bfin_icache_init(icplb_tables[cpu]);
104 #ifdef CONFIG_BFIN_DCACHE
106 bfin_dcache_init(dcplb_tbl[cpu]);
108 bfin_dcache_init(dcplb_tables[cpu]);
113 * In cache coherence emulation mode, we need to have the
114 * D-cache enabled before running any atomic operation which
115 * might invove cache invalidation (i.e. spinlock, rwlock).
116 * So printk's are deferred until then.
118 #ifdef CONFIG_BFIN_ICACHE
119 printk(KERN_INFO "Instruction Cache Enabled for CPU%u\n", cpu);
121 #ifdef CONFIG_BFIN_DCACHE
122 printk(KERN_INFO "Data Cache Enabled for CPU%u"
123 # if defined CONFIG_BFIN_WB
125 # elif defined CONFIG_BFIN_WT
132 void __cpuinit bfin_setup_cpudata(unsigned int cpu)
134 struct blackfin_cpudata *cpudata = &per_cpu(cpu_data, cpu);
136 cpudata->idle = current;
137 cpudata->loops_per_jiffy = loops_per_jiffy;
138 cpudata->imemctl = bfin_read_IMEM_CONTROL();
139 cpudata->dmemctl = bfin_read_DMEM_CONTROL();
142 void __init bfin_cache_init(void)
144 #if defined(CONFIG_BFIN_DCACHE) || defined(CONFIG_BFIN_ICACHE)
145 generate_cplb_tables();
147 bfin_setup_caches(0);
150 void __init bfin_relocate_l1_mem(void)
152 unsigned long l1_code_length;
153 unsigned long l1_data_a_length;
154 unsigned long l1_data_b_length;
155 unsigned long l2_length;
157 l1_code_length = _etext_l1 - _stext_l1;
158 if (l1_code_length > L1_CODE_LENGTH)
159 panic("L1 Instruction SRAM Overflow\n");
160 /* cannot complain as printk is not available as yet.
161 * But we can continue booting and complain later!
164 /* Copy _stext_l1 to _etext_l1 to L1 instruction SRAM */
165 dma_memcpy(_stext_l1, _l1_lma_start, l1_code_length);
167 l1_data_a_length = _sbss_l1 - _sdata_l1;
168 if (l1_data_a_length > L1_DATA_A_LENGTH)
169 panic("L1 Data SRAM Bank A Overflow\n");
171 /* Copy _sdata_l1 to _sbss_l1 to L1 data bank A SRAM */
172 dma_memcpy(_sdata_l1, _l1_lma_start + l1_code_length, l1_data_a_length);
174 l1_data_b_length = _sbss_b_l1 - _sdata_b_l1;
175 if (l1_data_b_length > L1_DATA_B_LENGTH)
176 panic("L1 Data SRAM Bank B Overflow\n");
178 /* Copy _sdata_b_l1 to _sbss_b_l1 to L1 data bank B SRAM */
179 dma_memcpy(_sdata_b_l1, _l1_lma_start + l1_code_length +
180 l1_data_a_length, l1_data_b_length);
182 if (L2_LENGTH != 0) {
183 l2_length = _sbss_l2 - _stext_l2;
184 if (l2_length > L2_LENGTH)
185 panic("L2 SRAM Overflow\n");
187 /* Copy _stext_l2 to _edata_l2 to L2 SRAM */
188 dma_memcpy(_stext_l2, _l2_lma_start, l2_length);
192 /* add_memory_region to memmap */
193 static void __init add_memory_region(unsigned long long start,
194 unsigned long long size, int type)
198 i = bfin_memmap.nr_map;
200 if (i == BFIN_MEMMAP_MAX) {
201 printk(KERN_ERR "Ooops! Too many entries in the memory map!\n");
205 bfin_memmap.map[i].addr = start;
206 bfin_memmap.map[i].size = size;
207 bfin_memmap.map[i].type = type;
208 bfin_memmap.nr_map++;
212 * Sanitize the boot memmap, removing overlaps.
214 static int __init sanitize_memmap(struct bfin_memmap_entry *map, int *pnr_map)
216 struct change_member *change_tmp;
217 unsigned long current_type, last_type;
218 unsigned long long last_addr;
219 int chgidx, still_changing;
222 int old_nr, new_nr, chg_nr;
226 Visually we're performing the following (1,2,3,4 = memory types)
228 Sample memory map (w/overlaps):
229 ____22__________________
230 ______________________4_
231 ____1111________________
232 _44_____________________
233 11111111________________
234 ____________________33__
235 ___________44___________
236 __________33333_________
237 ______________22________
238 ___________________2222_
239 _________111111111______
240 _____________________11_
241 _________________4______
243 Sanitized equivalent (no overlap):
244 1_______________________
245 _44_____________________
246 ___1____________________
247 ____22__________________
248 ______11________________
249 _________1______________
250 __________3_____________
251 ___________44___________
252 _____________33_________
253 _______________2________
254 ________________1_______
255 _________________4______
256 ___________________2____
257 ____________________33__
258 ______________________4_
260 /* if there's only one memory region, don't bother */
266 /* bail out if we find any unreasonable addresses in memmap */
267 for (i = 0; i < old_nr; i++)
268 if (map[i].addr + map[i].size < map[i].addr)
271 /* create pointers for initial change-point information (for sorting) */
272 for (i = 0; i < 2*old_nr; i++)
273 change_point[i] = &change_point_list[i];
275 /* record all known change-points (starting and ending addresses),
276 omitting those that are for empty memory regions */
278 for (i = 0; i < old_nr; i++) {
279 if (map[i].size != 0) {
280 change_point[chgidx]->addr = map[i].addr;
281 change_point[chgidx++]->pentry = &map[i];
282 change_point[chgidx]->addr = map[i].addr + map[i].size;
283 change_point[chgidx++]->pentry = &map[i];
286 chg_nr = chgidx; /* true number of change-points */
288 /* sort change-point list by memory addresses (low -> high) */
290 while (still_changing) {
292 for (i = 1; i < chg_nr; i++) {
293 /* if <current_addr> > <last_addr>, swap */
294 /* or, if current=<start_addr> & last=<end_addr>, swap */
295 if ((change_point[i]->addr < change_point[i-1]->addr) ||
296 ((change_point[i]->addr == change_point[i-1]->addr) &&
297 (change_point[i]->addr == change_point[i]->pentry->addr) &&
298 (change_point[i-1]->addr != change_point[i-1]->pentry->addr))
300 change_tmp = change_point[i];
301 change_point[i] = change_point[i-1];
302 change_point[i-1] = change_tmp;
308 /* create a new memmap, removing overlaps */
309 overlap_entries = 0; /* number of entries in the overlap table */
310 new_entry = 0; /* index for creating new memmap entries */
311 last_type = 0; /* start with undefined memory type */
312 last_addr = 0; /* start with 0 as last starting address */
313 /* loop through change-points, determining affect on the new memmap */
314 for (chgidx = 0; chgidx < chg_nr; chgidx++) {
315 /* keep track of all overlapping memmap entries */
316 if (change_point[chgidx]->addr == change_point[chgidx]->pentry->addr) {
317 /* add map entry to overlap list (> 1 entry implies an overlap) */
318 overlap_list[overlap_entries++] = change_point[chgidx]->pentry;
320 /* remove entry from list (order independent, so swap with last) */
321 for (i = 0; i < overlap_entries; i++) {
322 if (overlap_list[i] == change_point[chgidx]->pentry)
323 overlap_list[i] = overlap_list[overlap_entries-1];
327 /* if there are overlapping entries, decide which "type" to use */
328 /* (larger value takes precedence -- 1=usable, 2,3,4,4+=unusable) */
330 for (i = 0; i < overlap_entries; i++)
331 if (overlap_list[i]->type > current_type)
332 current_type = overlap_list[i]->type;
333 /* continue building up new memmap based on this information */
334 if (current_type != last_type) {
335 if (last_type != 0) {
336 new_map[new_entry].size =
337 change_point[chgidx]->addr - last_addr;
338 /* move forward only if the new size was non-zero */
339 if (new_map[new_entry].size != 0)
340 if (++new_entry >= BFIN_MEMMAP_MAX)
341 break; /* no more space left for new entries */
343 if (current_type != 0) {
344 new_map[new_entry].addr = change_point[chgidx]->addr;
345 new_map[new_entry].type = current_type;
346 last_addr = change_point[chgidx]->addr;
348 last_type = current_type;
351 new_nr = new_entry; /* retain count for new entries */
353 /* copy new mapping into original location */
354 memcpy(map, new_map, new_nr*sizeof(struct bfin_memmap_entry));
360 static void __init print_memory_map(char *who)
364 for (i = 0; i < bfin_memmap.nr_map; i++) {
365 printk(KERN_DEBUG " %s: %016Lx - %016Lx ", who,
366 bfin_memmap.map[i].addr,
367 bfin_memmap.map[i].addr + bfin_memmap.map[i].size);
368 switch (bfin_memmap.map[i].type) {
369 case BFIN_MEMMAP_RAM:
370 printk("(usable)\n");
372 case BFIN_MEMMAP_RESERVED:
373 printk("(reserved)\n");
375 default: printk("type %lu\n", bfin_memmap.map[i].type);
381 static __init int parse_memmap(char *arg)
383 unsigned long long start_at, mem_size;
388 mem_size = memparse(arg, &arg);
390 start_at = memparse(arg+1, &arg);
391 add_memory_region(start_at, mem_size, BFIN_MEMMAP_RAM);
392 } else if (*arg == '$') {
393 start_at = memparse(arg+1, &arg);
394 add_memory_region(start_at, mem_size, BFIN_MEMMAP_RESERVED);
401 * Initial parsing of the command line. Currently, we support:
402 * - Controlling the linux memory size: mem=xxx[KMG]
403 * - Controlling the physical memory size: max_mem=xxx[KMG][$][#]
404 * $ -> reserved memory is dcacheable
405 * # -> reserved memory is icacheable
406 * - "memmap=XXX[KkmM][@][$]XXX[KkmM]" defines a memory region
407 * @ from <start> to <start>+<mem>, type RAM
408 * $ from <start> to <start>+<mem>, type RESERVED
410 static __init void parse_cmdline_early(char *cmdline_p)
412 char c = ' ', *to = cmdline_p;
413 unsigned int memsize;
416 if (!memcmp(to, "mem=", 4)) {
418 memsize = memparse(to, &to);
422 } else if (!memcmp(to, "max_mem=", 8)) {
424 memsize = memparse(to, &to);
426 physical_mem_end = memsize;
430 reserved_mem_dcache_on = 1;
433 reserved_mem_icache_on = 1;
436 } else if (!memcmp(to, "earlyprintk=", 12)) {
438 setup_early_printk(to);
439 } else if (!memcmp(to, "memmap=", 7)) {
451 * Setup memory defaults from user config.
452 * The physical memory layout looks like:
454 * [_rambase, _ramstart]: kernel image
455 * [memory_start, memory_end]: dynamic memory managed by kernel
456 * [memory_end, _ramend]: reserved memory
457 * [memory_mtd_start(memory_end),
458 * memory_mtd_start + mtd_size]: rootfs (if any)
459 * [_ramend - DMA_UNCACHED_REGION,
460 * _ramend]: uncached DMA region
461 * [_ramend, physical_mem_end]: memory not managed by kernel
463 static __init void memory_setup(void)
465 #ifdef CONFIG_MTD_UCLINUX
466 unsigned long mtd_phys = 0;
469 _rambase = (unsigned long)_stext;
470 _ramstart = (unsigned long)_end;
472 if (DMA_UNCACHED_REGION > (_ramend - _ramstart)) {
474 panic("DMA region exceeds memory limit: %lu.\n",
475 _ramend - _ramstart);
477 memory_end = _ramend - DMA_UNCACHED_REGION;
480 /* Round up to multiple of 4MB */
481 memory_start = (_ramstart + 0x3fffff) & ~0x3fffff;
483 memory_start = PAGE_ALIGN(_ramstart);
486 #if defined(CONFIG_MTD_UCLINUX)
487 /* generic memory mapped MTD driver */
488 memory_mtd_end = memory_end;
490 mtd_phys = _ramstart;
491 mtd_size = PAGE_ALIGN(*((unsigned long *)(mtd_phys + 8)));
493 # if defined(CONFIG_EXT2_FS) || defined(CONFIG_EXT3_FS)
494 if (*((unsigned short *)(mtd_phys + 0x438)) == EXT2_SUPER_MAGIC)
496 PAGE_ALIGN(*((unsigned long *)(mtd_phys + 0x404)) << 10);
499 # if defined(CONFIG_CRAMFS)
500 if (*((unsigned long *)(mtd_phys)) == CRAMFS_MAGIC)
501 mtd_size = PAGE_ALIGN(*((unsigned long *)(mtd_phys + 0x4)));
504 # if defined(CONFIG_ROMFS_FS)
505 if (((unsigned long *)mtd_phys)[0] == ROMSB_WORD0
506 && ((unsigned long *)mtd_phys)[1] == ROMSB_WORD1)
508 PAGE_ALIGN(be32_to_cpu(((unsigned long *)mtd_phys)[2]));
509 # if (defined(CONFIG_BFIN_ICACHE) && ANOMALY_05000263)
510 /* Due to a Hardware Anomaly we need to limit the size of usable
511 * instruction memory to max 60MB, 56 if HUNT_FOR_ZERO is on
512 * 05000263 - Hardware loop corrupted when taking an ICPLB exception
514 # if (defined(CONFIG_DEBUG_HUNT_FOR_ZERO))
515 if (memory_end >= 56 * 1024 * 1024)
516 memory_end = 56 * 1024 * 1024;
518 if (memory_end >= 60 * 1024 * 1024)
519 memory_end = 60 * 1024 * 1024;
520 # endif /* CONFIG_DEBUG_HUNT_FOR_ZERO */
521 # endif /* ANOMALY_05000263 */
522 # endif /* CONFIG_ROMFS_FS */
524 memory_end -= mtd_size;
528 panic("Don't boot kernel without rootfs attached.\n");
531 /* Relocate MTD image to the top of memory after the uncached memory area */
532 dma_memcpy((char *)memory_end, _end, mtd_size);
534 memory_mtd_start = memory_end;
535 _ebss = memory_mtd_start; /* define _ebss for compatible */
536 #endif /* CONFIG_MTD_UCLINUX */
538 #if (defined(CONFIG_BFIN_ICACHE) && ANOMALY_05000263)
539 /* Due to a Hardware Anomaly we need to limit the size of usable
540 * instruction memory to max 60MB, 56 if HUNT_FOR_ZERO is on
541 * 05000263 - Hardware loop corrupted when taking an ICPLB exception
543 #if (defined(CONFIG_DEBUG_HUNT_FOR_ZERO))
544 if (memory_end >= 56 * 1024 * 1024)
545 memory_end = 56 * 1024 * 1024;
547 if (memory_end >= 60 * 1024 * 1024)
548 memory_end = 60 * 1024 * 1024;
549 #endif /* CONFIG_DEBUG_HUNT_FOR_ZERO */
550 printk(KERN_NOTICE "Warning: limiting memory to %liMB due to hardware anomaly 05000263\n", memory_end >> 20);
551 #endif /* ANOMALY_05000263 */
554 page_mask_nelts = ((_ramend >> PAGE_SHIFT) + 31) / 32;
555 page_mask_order = get_order(3 * page_mask_nelts * sizeof(long));
558 #if !defined(CONFIG_MTD_UCLINUX)
559 /*In case there is no valid CPLB behind memory_end make sure we don't get to close*/
560 memory_end -= SIZE_4K;
563 init_mm.start_code = (unsigned long)_stext;
564 init_mm.end_code = (unsigned long)_etext;
565 init_mm.end_data = (unsigned long)_edata;
566 init_mm.brk = (unsigned long)0;
568 printk(KERN_INFO "Board Memory: %ldMB\n", physical_mem_end >> 20);
569 printk(KERN_INFO "Kernel Managed Memory: %ldMB\n", _ramend >> 20);
571 printk(KERN_INFO "Memory map:\n"
572 KERN_INFO " fixedcode = 0x%p-0x%p\n"
573 KERN_INFO " text = 0x%p-0x%p\n"
574 KERN_INFO " rodata = 0x%p-0x%p\n"
575 KERN_INFO " bss = 0x%p-0x%p\n"
576 KERN_INFO " data = 0x%p-0x%p\n"
577 KERN_INFO " stack = 0x%p-0x%p\n"
578 KERN_INFO " init = 0x%p-0x%p\n"
579 KERN_INFO " available = 0x%p-0x%p\n"
580 #ifdef CONFIG_MTD_UCLINUX
581 KERN_INFO " rootfs = 0x%p-0x%p\n"
583 #if DMA_UNCACHED_REGION > 0
584 KERN_INFO " DMA Zone = 0x%p-0x%p\n"
586 , (void *)FIXED_CODE_START, (void *)FIXED_CODE_END,
588 __start_rodata, __end_rodata,
589 __bss_start, __bss_stop,
591 (void *)&init_thread_union,
592 (void *)((int)(&init_thread_union) + 0x2000),
593 __init_begin, __init_end,
594 (void *)_ramstart, (void *)memory_end
595 #ifdef CONFIG_MTD_UCLINUX
596 , (void *)memory_mtd_start, (void *)(memory_mtd_start + mtd_size)
598 #if DMA_UNCACHED_REGION > 0
599 , (void *)(_ramend - DMA_UNCACHED_REGION), (void *)(_ramend)
605 * Find the lowest, highest page frame number we have available
607 void __init find_min_max_pfn(void)
612 min_low_pfn = memory_end;
614 for (i = 0; i < bfin_memmap.nr_map; i++) {
615 unsigned long start, end;
617 if (bfin_memmap.map[i].type != BFIN_MEMMAP_RAM)
619 start = PFN_UP(bfin_memmap.map[i].addr);
620 end = PFN_DOWN(bfin_memmap.map[i].addr +
621 bfin_memmap.map[i].size);
626 if (start < min_low_pfn)
631 static __init void setup_bootmem_allocator(void)
635 unsigned long start_pfn, end_pfn;
636 unsigned long curr_pfn, last_pfn, size;
638 /* mark memory between memory_start and memory_end usable */
639 add_memory_region(memory_start,
640 memory_end - memory_start, BFIN_MEMMAP_RAM);
641 /* sanity check for overlap */
642 sanitize_memmap(bfin_memmap.map, &bfin_memmap.nr_map);
643 print_memory_map("boot memmap");
645 /* intialize globals in linux/bootmem.h */
647 /* pfn of the last usable page frame */
648 if (max_pfn > memory_end >> PAGE_SHIFT)
649 max_pfn = memory_end >> PAGE_SHIFT;
650 /* pfn of last page frame directly mapped by kernel */
651 max_low_pfn = max_pfn;
652 /* pfn of the first usable page frame after kernel image*/
653 if (min_low_pfn < memory_start >> PAGE_SHIFT)
654 min_low_pfn = memory_start >> PAGE_SHIFT;
656 start_pfn = PAGE_OFFSET >> PAGE_SHIFT;
657 end_pfn = memory_end >> PAGE_SHIFT;
660 * give all the memory to the bootmap allocator, tell it to put the
661 * boot mem_map at the start of memory.
663 bootmap_size = init_bootmem_node(NODE_DATA(0),
664 memory_start >> PAGE_SHIFT, /* map goes here */
667 /* register the memmap regions with the bootmem allocator */
668 for (i = 0; i < bfin_memmap.nr_map; i++) {
670 * Reserve usable memory
672 if (bfin_memmap.map[i].type != BFIN_MEMMAP_RAM)
675 * We are rounding up the start address of usable memory:
677 curr_pfn = PFN_UP(bfin_memmap.map[i].addr);
678 if (curr_pfn >= end_pfn)
681 * ... and at the end of the usable range downwards:
683 last_pfn = PFN_DOWN(bfin_memmap.map[i].addr +
684 bfin_memmap.map[i].size);
686 if (last_pfn > end_pfn)
690 * .. finally, did all the rounding and playing
691 * around just make the area go away?
693 if (last_pfn <= curr_pfn)
696 size = last_pfn - curr_pfn;
697 free_bootmem(PFN_PHYS(curr_pfn), PFN_PHYS(size));
700 /* reserve memory before memory_start, including bootmap */
701 reserve_bootmem(PAGE_OFFSET,
702 memory_start + bootmap_size + PAGE_SIZE - 1 - PAGE_OFFSET,
706 #define EBSZ_TO_MEG(ebsz) \
709 switch (ebsz & 0xf) { \
710 case 0x1: meg = 16; break; \
711 case 0x3: meg = 32; break; \
712 case 0x5: meg = 64; break; \
713 case 0x7: meg = 128; break; \
714 case 0x9: meg = 256; break; \
715 case 0xb: meg = 512; break; \
719 static inline int __init get_mem_size(void)
721 #if defined(EBIU_SDBCTL)
722 # if defined(BF561_FAMILY)
724 u32 sdbctl = bfin_read_EBIU_SDBCTL();
725 ret += EBSZ_TO_MEG(sdbctl >> 0);
726 ret += EBSZ_TO_MEG(sdbctl >> 8);
727 ret += EBSZ_TO_MEG(sdbctl >> 16);
728 ret += EBSZ_TO_MEG(sdbctl >> 24);
731 return EBSZ_TO_MEG(bfin_read_EBIU_SDBCTL());
733 #elif defined(EBIU_DDRCTL1)
734 u32 ddrctl = bfin_read_EBIU_DDRCTL1();
736 switch (ddrctl & 0xc0000) {
737 case DEVSZ_64: ret = 64 / 8;
738 case DEVSZ_128: ret = 128 / 8;
739 case DEVSZ_256: ret = 256 / 8;
740 case DEVSZ_512: ret = 512 / 8;
742 switch (ddrctl & 0x30000) {
743 case DEVWD_4: ret *= 2;
744 case DEVWD_8: ret *= 2;
745 case DEVWD_16: break;
747 if ((ddrctl & 0xc000) == 0x4000)
754 void __init setup_arch(char **cmdline_p)
756 unsigned long sclk, cclk;
758 #ifdef CONFIG_DUMMY_CONSOLE
759 conswitchp = &dummy_con;
762 #if defined(CONFIG_CMDLINE_BOOL)
763 strncpy(&command_line[0], CONFIG_CMDLINE, sizeof(command_line));
764 command_line[sizeof(command_line) - 1] = 0;
767 /* Keep a copy of command line */
768 *cmdline_p = &command_line[0];
769 memcpy(boot_command_line, command_line, COMMAND_LINE_SIZE);
770 boot_command_line[COMMAND_LINE_SIZE - 1] = '\0';
772 /* setup memory defaults from the user config */
773 physical_mem_end = 0;
774 _ramend = get_mem_size() * 1024 * 1024;
776 memset(&bfin_memmap, 0, sizeof(bfin_memmap));
778 parse_cmdline_early(&command_line[0]);
780 if (physical_mem_end == 0)
781 physical_mem_end = _ramend;
785 /* Initialize Async memory banks */
786 bfin_write_EBIU_AMBCTL0(AMBCTL0VAL);
787 bfin_write_EBIU_AMBCTL1(AMBCTL1VAL);
788 bfin_write_EBIU_AMGCTL(AMGCTLVAL);
789 #ifdef CONFIG_EBIU_MBSCTLVAL
790 bfin_write_EBIU_MBSCTL(CONFIG_EBIU_MBSCTLVAL);
791 bfin_write_EBIU_MODE(CONFIG_EBIU_MODEVAL);
792 bfin_write_EBIU_FCTL(CONFIG_EBIU_FCTLVAL);
798 #if !defined(CONFIG_BFIN_KERNEL_CLOCK)
799 if (ANOMALY_05000273 && cclk == sclk)
800 panic("ANOMALY 05000273, SCLK can not be same as CCLK");
804 if (ANOMALY_05000266) {
805 bfin_read_IMDMA_D0_IRQ_STATUS();
806 bfin_read_IMDMA_D1_IRQ_STATUS();
809 printk(KERN_INFO "Hardware Trace ");
810 if (bfin_read_TBUFCTL() & 0x1)
814 if (bfin_read_TBUFCTL() & 0x2)
815 printk("and Enabled\n");
817 printk("and Disabled\n");
819 #if defined(CONFIG_CHR_DEV_FLASH) || defined(CONFIG_BLK_DEV_FLASH)
820 /* we need to initialize the Flashrom device here since we might
821 * do things with flash early on in the boot
826 _bfin_swrst = bfin_read_SWRST();
828 #ifdef CONFIG_DEBUG_DOUBLEFAULT_PRINT
829 bfin_write_SWRST(_bfin_swrst & ~DOUBLE_FAULT);
831 #ifdef CONFIG_DEBUG_DOUBLEFAULT_RESET
832 bfin_write_SWRST(_bfin_swrst | DOUBLE_FAULT);
836 if (_bfin_swrst & SWRST_DBL_FAULT_A) {
838 if (_bfin_swrst & RESET_DOUBLE) {
840 printk(KERN_EMERG "Recovering from DOUBLE FAULT event\n");
841 #ifdef CONFIG_DEBUG_DOUBLEFAULT
842 /* We assume the crashing kernel, and the current symbol table match */
843 printk(KERN_EMERG " While handling exception (EXCAUSE = 0x%x) at %pF\n",
844 (int)init_saved_seqstat & SEQSTAT_EXCAUSE, init_saved_retx);
845 printk(KERN_NOTICE " DCPLB_FAULT_ADDR: %pF\n", init_saved_dcplb_fault_addr);
846 printk(KERN_NOTICE " ICPLB_FAULT_ADDR: %pF\n", init_saved_icplb_fault_addr);
848 printk(KERN_NOTICE " The instruction at %pF caused a double exception\n",
850 } else if (_bfin_swrst & RESET_WDOG)
851 printk(KERN_INFO "Recovering from Watchdog event\n");
852 else if (_bfin_swrst & RESET_SOFTWARE)
853 printk(KERN_NOTICE "Reset caused by Software reset\n");
855 printk(KERN_INFO "Blackfin support (C) 2004-2008 Analog Devices, Inc.\n");
856 if (bfin_compiled_revid() == 0xffff)
857 printk(KERN_INFO "Compiled for ADSP-%s Rev any\n", CPU);
858 else if (bfin_compiled_revid() == -1)
859 printk(KERN_INFO "Compiled for ADSP-%s Rev none\n", CPU);
861 printk(KERN_INFO "Compiled for ADSP-%s Rev 0.%d\n", CPU, bfin_compiled_revid());
863 if (unlikely(CPUID != bfin_cpuid()))
864 printk(KERN_ERR "ERROR: Not running on ADSP-%s: unknown CPUID 0x%04x Rev 0.%d\n",
865 CPU, bfin_cpuid(), bfin_revid());
867 if (bfin_revid() != bfin_compiled_revid()) {
868 if (bfin_compiled_revid() == -1)
869 printk(KERN_ERR "Warning: Compiled for Rev none, but running on Rev %d\n",
871 else if (bfin_compiled_revid() != 0xffff)
872 printk(KERN_ERR "Warning: Compiled for Rev %d, but running on Rev %d\n",
873 bfin_compiled_revid(), bfin_revid());
875 if (bfin_revid() < CONFIG_BF_REV_MIN || bfin_revid() > CONFIG_BF_REV_MAX)
876 printk(KERN_ERR "Warning: Unsupported Chip Revision ADSP-%s Rev 0.%d detected\n",
880 printk(KERN_INFO "Blackfin Linux support by http://blackfin.uclinux.org/\n");
882 printk(KERN_INFO "Processor Speed: %lu MHz core clock and %lu MHz System Clock\n",
883 cclk / 1000000, sclk / 1000000);
885 if (ANOMALY_05000273 && (cclk >> 1) <= sclk)
886 printk("\n\n\nANOMALY_05000273: CCLK must be >= 2*SCLK !!!\n\n\n");
888 setup_bootmem_allocator();
892 /* Copy atomic sequences to their fixed location, and sanity check that
893 these locations are the ones that we advertise to userspace. */
894 memcpy((void *)FIXED_CODE_START, &fixed_code_start,
895 FIXED_CODE_END - FIXED_CODE_START);
896 BUG_ON((char *)&sigreturn_stub - (char *)&fixed_code_start
897 != SIGRETURN_STUB - FIXED_CODE_START);
898 BUG_ON((char *)&atomic_xchg32 - (char *)&fixed_code_start
899 != ATOMIC_XCHG32 - FIXED_CODE_START);
900 BUG_ON((char *)&atomic_cas32 - (char *)&fixed_code_start
901 != ATOMIC_CAS32 - FIXED_CODE_START);
902 BUG_ON((char *)&atomic_add32 - (char *)&fixed_code_start
903 != ATOMIC_ADD32 - FIXED_CODE_START);
904 BUG_ON((char *)&atomic_sub32 - (char *)&fixed_code_start
905 != ATOMIC_SUB32 - FIXED_CODE_START);
906 BUG_ON((char *)&atomic_ior32 - (char *)&fixed_code_start
907 != ATOMIC_IOR32 - FIXED_CODE_START);
908 BUG_ON((char *)&atomic_and32 - (char *)&fixed_code_start
909 != ATOMIC_AND32 - FIXED_CODE_START);
910 BUG_ON((char *)&atomic_xor32 - (char *)&fixed_code_start
911 != ATOMIC_XOR32 - FIXED_CODE_START);
912 BUG_ON((char *)&safe_user_instruction - (char *)&fixed_code_start
913 != SAFE_USER_INSTRUCTION - FIXED_CODE_START);
916 platform_init_cpus();
918 init_exception_vectors();
919 bfin_cache_init(); /* Initialize caches for the boot CPU */
922 static int __init topology_init(void)
925 /* Record CPU-private information for the boot processor. */
926 bfin_setup_cpudata(0);
928 for_each_possible_cpu(cpu) {
929 register_cpu(&per_cpu(cpu_data, cpu).cpu, cpu);
935 subsys_initcall(topology_init);
937 /* Get the voltage input multiplier */
938 static u_long cached_vco_pll_ctl, cached_vco;
939 static u_long get_vco(void)
943 u_long pll_ctl = bfin_read_PLL_CTL();
944 if (pll_ctl == cached_vco_pll_ctl)
947 cached_vco_pll_ctl = pll_ctl;
949 msel = (pll_ctl >> 9) & 0x3F;
953 cached_vco = CONFIG_CLKIN_HZ;
954 cached_vco >>= (1 & pll_ctl); /* DF bit */
959 /* Get the Core clock */
960 static u_long cached_cclk_pll_div, cached_cclk;
961 u_long get_cclk(void)
965 if (bfin_read_PLL_STAT() & 0x1)
966 return CONFIG_CLKIN_HZ;
968 ssel = bfin_read_PLL_DIV();
969 if (ssel == cached_cclk_pll_div)
972 cached_cclk_pll_div = ssel;
974 csel = ((ssel >> 4) & 0x03);
976 if (ssel && ssel < (1 << csel)) /* SCLK > CCLK */
977 cached_cclk = get_vco() / ssel;
979 cached_cclk = get_vco() >> csel;
982 EXPORT_SYMBOL(get_cclk);
984 /* Get the System clock */
985 static u_long cached_sclk_pll_div, cached_sclk;
986 u_long get_sclk(void)
990 if (bfin_read_PLL_STAT() & 0x1)
991 return CONFIG_CLKIN_HZ;
993 ssel = bfin_read_PLL_DIV();
994 if (ssel == cached_sclk_pll_div)
997 cached_sclk_pll_div = ssel;
1001 printk(KERN_WARNING "Invalid System Clock\n");
1005 cached_sclk = get_vco() / ssel;
1008 EXPORT_SYMBOL(get_sclk);
1010 unsigned long sclk_to_usecs(unsigned long sclk)
1012 u64 tmp = USEC_PER_SEC * (u64)sclk;
1013 do_div(tmp, get_sclk());
1016 EXPORT_SYMBOL(sclk_to_usecs);
1018 unsigned long usecs_to_sclk(unsigned long usecs)
1020 u64 tmp = get_sclk() * (u64)usecs;
1021 do_div(tmp, USEC_PER_SEC);
1024 EXPORT_SYMBOL(usecs_to_sclk);
1027 * Get CPU information for use by the procfs.
1029 static int show_cpuinfo(struct seq_file *m, void *v)
1031 char *cpu, *mmu, *fpu, *vendor, *cache;
1035 u_int icache_size = BFIN_ICACHESIZE / 1024, dcache_size = 0, dsup_banks = 0;
1036 struct blackfin_cpudata *cpudata = &per_cpu(cpu_data, *(unsigned int *)v);
1041 revid = bfin_revid();
1046 switch (bfin_read_CHIPID() & CHIPID_MANUFACTURE) {
1048 vendor = "Analog Devices";
1055 seq_printf(m, "processor\t: %d\n" "vendor_id\t: %s\n",
1056 *(unsigned int *)v, vendor);
1058 if (CPUID == bfin_cpuid())
1059 seq_printf(m, "cpu family\t: 0x%04x\n", CPUID);
1061 seq_printf(m, "cpu family\t: Compiled for:0x%04x, running on:0x%04x\n",
1062 CPUID, bfin_cpuid());
1064 seq_printf(m, "model name\t: ADSP-%s %lu(MHz CCLK) %lu(MHz SCLK) (%s)\n"
1066 cpu, cclk/1000000, sclk/1000000,
1074 seq_printf(m, "cpu MHz\t\t: %lu.%03lu/%lu.%03lu\n",
1075 cclk/1000000, cclk%1000000,
1076 sclk/1000000, sclk%1000000);
1077 seq_printf(m, "bogomips\t: %lu.%02lu\n"
1078 "Calibration\t: %lu loops\n",
1079 (cpudata->loops_per_jiffy * HZ) / 500000,
1080 ((cpudata->loops_per_jiffy * HZ) / 5000) % 100,
1081 (cpudata->loops_per_jiffy * HZ));
1083 /* Check Cache configutation */
1084 switch (cpudata->dmemctl & (1 << DMC0_P | 1 << DMC1_P)) {
1086 cache = "dbank-A/B\t: cache/sram";
1091 cache = "dbank-A/B\t: cache/cache";
1096 cache = "dbank-A/B\t: sram/sram";
1107 /* Is it turned on? */
1108 if ((cpudata->dmemctl & (ENDCPLB | DMC_ENABLE)) != (ENDCPLB | DMC_ENABLE))
1111 if ((cpudata->imemctl & (IMC | ENICPLB)) != (IMC | ENICPLB))
1114 seq_printf(m, "cache size\t: %d KB(L1 icache) "
1115 "%d KB(L1 dcache-%s) %d KB(L2 cache)\n",
1116 icache_size, dcache_size,
1117 #if defined CONFIG_BFIN_WB
1119 #elif defined CONFIG_BFIN_WT
1124 seq_printf(m, "%s\n", cache);
1127 seq_printf(m, "icache setup\t: %d Sub-banks/%d Ways, %d Lines/Way\n",
1128 BFIN_ISUBBANKS, BFIN_IWAYS, BFIN_ILINES);
1130 seq_printf(m, "icache setup\t: off\n");
1133 "dcache setup\t: %d Super-banks/%d Sub-banks/%d Ways, %d Lines/Way\n",
1134 dsup_banks, BFIN_DSUBBANKS, BFIN_DWAYS,
1136 #ifdef __ARCH_SYNC_CORE_DCACHE
1138 "SMP Dcache Flushes\t: %lu\n\n",
1139 per_cpu(cpu_data, *(unsigned int *)v).dcache_invld_count);
1141 #ifdef CONFIG_BFIN_ICACHE_LOCK
1142 switch ((cpudata->imemctl >> 3) & WAYALL_L) {
1144 seq_printf(m, "Way0 Locked-Down\n");
1147 seq_printf(m, "Way1 Locked-Down\n");
1150 seq_printf(m, "Way0,Way1 Locked-Down\n");
1153 seq_printf(m, "Way2 Locked-Down\n");
1156 seq_printf(m, "Way0,Way2 Locked-Down\n");
1159 seq_printf(m, "Way1,Way2 Locked-Down\n");
1162 seq_printf(m, "Way0,Way1 & Way2 Locked-Down\n");
1165 seq_printf(m, "Way3 Locked-Down\n");
1168 seq_printf(m, "Way0,Way3 Locked-Down\n");
1171 seq_printf(m, "Way1,Way3 Locked-Down\n");
1174 seq_printf(m, "Way 0,Way1,Way3 Locked-Down\n");
1177 seq_printf(m, "Way3,Way2 Locked-Down\n");
1180 seq_printf(m, "Way3,Way2,Way0 Locked-Down\n");
1183 seq_printf(m, "Way3,Way2,Way1 Locked-Down\n");
1186 seq_printf(m, "All Ways are locked\n");
1189 seq_printf(m, "No Ways are locked\n");
1192 if (*(unsigned int *)v != NR_CPUS-1)
1196 seq_printf(m, "L2 SRAM\t\t: %dKB\n", L2_LENGTH/0x400);
1198 seq_printf(m, "board name\t: %s\n", bfin_board_name);
1199 seq_printf(m, "board memory\t: %ld kB (0x%p -> 0x%p)\n",
1200 physical_mem_end >> 10, (void *)0, (void *)physical_mem_end);
1201 seq_printf(m, "kernel memory\t: %d kB (0x%p -> 0x%p)\n",
1202 ((int)memory_end - (int)_stext) >> 10,
1204 (void *)memory_end);
1205 seq_printf(m, "\n");
1210 static void *c_start(struct seq_file *m, loff_t *pos)
1213 *pos = first_cpu(cpu_online_map);
1214 if (*pos >= num_online_cpus())
1220 static void *c_next(struct seq_file *m, void *v, loff_t *pos)
1222 *pos = next_cpu(*pos, cpu_online_map);
1224 return c_start(m, pos);
1227 static void c_stop(struct seq_file *m, void *v)
1231 const struct seq_operations cpuinfo_op = {
1235 .show = show_cpuinfo,
1238 void __init cmdline_init(const char *r0)
1241 strncpy(command_line, r0, COMMAND_LINE_SIZE);