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;
107 unsigned long l2_length;
109 l1_code_length = _etext_l1 - _stext_l1;
110 if (l1_code_length > L1_CODE_LENGTH)
111 panic("L1 Instruction SRAM Overflow\n");
112 /* cannot complain as printk is not available as yet.
113 * But we can continue booting and complain later!
116 /* Copy _stext_l1 to _etext_l1 to L1 instruction SRAM */
117 dma_memcpy(_stext_l1, _l1_lma_start, l1_code_length);
119 l1_data_a_length = _ebss_l1 - _sdata_l1;
120 if (l1_data_a_length > L1_DATA_A_LENGTH)
121 panic("L1 Data SRAM Bank A Overflow\n");
123 /* Copy _sdata_l1 to _ebss_l1 to L1 data bank A SRAM */
124 dma_memcpy(_sdata_l1, _l1_lma_start + l1_code_length, l1_data_a_length);
126 l1_data_b_length = _ebss_b_l1 - _sdata_b_l1;
127 if (l1_data_b_length > L1_DATA_B_LENGTH)
128 panic("L1 Data SRAM Bank B Overflow\n");
130 /* Copy _sdata_b_l1 to _ebss_b_l1 to L1 data bank B SRAM */
131 dma_memcpy(_sdata_b_l1, _l1_lma_start + l1_code_length +
132 l1_data_a_length, l1_data_b_length);
135 l2_length = _ebss_l2 - _stext_l2;
136 if (l2_length > L2_LENGTH)
137 panic("L2 SRAM Overflow\n");
139 /* Copy _stext_l2 to _edata_l2 to L2 SRAM */
140 dma_memcpy(_stext_l2, _l2_lma_start, l2_length);
144 /* add_memory_region to memmap */
145 static void __init add_memory_region(unsigned long long start,
146 unsigned long long size, int type)
150 i = bfin_memmap.nr_map;
152 if (i == BFIN_MEMMAP_MAX) {
153 printk(KERN_ERR "Ooops! Too many entries in the memory map!\n");
157 bfin_memmap.map[i].addr = start;
158 bfin_memmap.map[i].size = size;
159 bfin_memmap.map[i].type = type;
160 bfin_memmap.nr_map++;
164 * Sanitize the boot memmap, removing overlaps.
166 static int __init sanitize_memmap(struct bfin_memmap_entry *map, int *pnr_map)
168 struct change_member *change_tmp;
169 unsigned long current_type, last_type;
170 unsigned long long last_addr;
171 int chgidx, still_changing;
174 int old_nr, new_nr, chg_nr;
178 Visually we're performing the following (1,2,3,4 = memory types)
180 Sample memory map (w/overlaps):
181 ____22__________________
182 ______________________4_
183 ____1111________________
184 _44_____________________
185 11111111________________
186 ____________________33__
187 ___________44___________
188 __________33333_________
189 ______________22________
190 ___________________2222_
191 _________111111111______
192 _____________________11_
193 _________________4______
195 Sanitized equivalent (no overlap):
196 1_______________________
197 _44_____________________
198 ___1____________________
199 ____22__________________
200 ______11________________
201 _________1______________
202 __________3_____________
203 ___________44___________
204 _____________33_________
205 _______________2________
206 ________________1_______
207 _________________4______
208 ___________________2____
209 ____________________33__
210 ______________________4_
212 /* if there's only one memory region, don't bother */
218 /* bail out if we find any unreasonable addresses in memmap */
219 for (i = 0; i < old_nr; i++)
220 if (map[i].addr + map[i].size < map[i].addr)
223 /* create pointers for initial change-point information (for sorting) */
224 for (i = 0; i < 2*old_nr; i++)
225 change_point[i] = &change_point_list[i];
227 /* record all known change-points (starting and ending addresses),
228 omitting those that are for empty memory regions */
230 for (i = 0; i < old_nr; i++) {
231 if (map[i].size != 0) {
232 change_point[chgidx]->addr = map[i].addr;
233 change_point[chgidx++]->pentry = &map[i];
234 change_point[chgidx]->addr = map[i].addr + map[i].size;
235 change_point[chgidx++]->pentry = &map[i];
238 chg_nr = chgidx; /* true number of change-points */
240 /* sort change-point list by memory addresses (low -> high) */
242 while (still_changing) {
244 for (i = 1; i < chg_nr; i++) {
245 /* if <current_addr> > <last_addr>, swap */
246 /* or, if current=<start_addr> & last=<end_addr>, swap */
247 if ((change_point[i]->addr < change_point[i-1]->addr) ||
248 ((change_point[i]->addr == change_point[i-1]->addr) &&
249 (change_point[i]->addr == change_point[i]->pentry->addr) &&
250 (change_point[i-1]->addr != change_point[i-1]->pentry->addr))
252 change_tmp = change_point[i];
253 change_point[i] = change_point[i-1];
254 change_point[i-1] = change_tmp;
260 /* create a new memmap, removing overlaps */
261 overlap_entries = 0; /* number of entries in the overlap table */
262 new_entry = 0; /* index for creating new memmap entries */
263 last_type = 0; /* start with undefined memory type */
264 last_addr = 0; /* start with 0 as last starting address */
265 /* loop through change-points, determining affect on the new memmap */
266 for (chgidx = 0; chgidx < chg_nr; chgidx++) {
267 /* keep track of all overlapping memmap entries */
268 if (change_point[chgidx]->addr == change_point[chgidx]->pentry->addr) {
269 /* add map entry to overlap list (> 1 entry implies an overlap) */
270 overlap_list[overlap_entries++] = change_point[chgidx]->pentry;
272 /* remove entry from list (order independent, so swap with last) */
273 for (i = 0; i < overlap_entries; i++) {
274 if (overlap_list[i] == change_point[chgidx]->pentry)
275 overlap_list[i] = overlap_list[overlap_entries-1];
279 /* if there are overlapping entries, decide which "type" to use */
280 /* (larger value takes precedence -- 1=usable, 2,3,4,4+=unusable) */
282 for (i = 0; i < overlap_entries; i++)
283 if (overlap_list[i]->type > current_type)
284 current_type = overlap_list[i]->type;
285 /* continue building up new memmap based on this information */
286 if (current_type != last_type) {
287 if (last_type != 0) {
288 new_map[new_entry].size =
289 change_point[chgidx]->addr - last_addr;
290 /* move forward only if the new size was non-zero */
291 if (new_map[new_entry].size != 0)
292 if (++new_entry >= BFIN_MEMMAP_MAX)
293 break; /* no more space left for new entries */
295 if (current_type != 0) {
296 new_map[new_entry].addr = change_point[chgidx]->addr;
297 new_map[new_entry].type = current_type;
298 last_addr = change_point[chgidx]->addr;
300 last_type = current_type;
303 new_nr = new_entry; /* retain count for new entries */
305 /* copy new mapping into original location */
306 memcpy(map, new_map, new_nr*sizeof(struct bfin_memmap_entry));
312 static void __init print_memory_map(char *who)
316 for (i = 0; i < bfin_memmap.nr_map; i++) {
317 printk(KERN_DEBUG " %s: %016Lx - %016Lx ", who,
318 bfin_memmap.map[i].addr,
319 bfin_memmap.map[i].addr + bfin_memmap.map[i].size);
320 switch (bfin_memmap.map[i].type) {
321 case BFIN_MEMMAP_RAM:
322 printk("(usable)\n");
324 case BFIN_MEMMAP_RESERVED:
325 printk("(reserved)\n");
327 default: printk("type %lu\n", bfin_memmap.map[i].type);
333 static __init int parse_memmap(char *arg)
335 unsigned long long start_at, mem_size;
340 mem_size = memparse(arg, &arg);
342 start_at = memparse(arg+1, &arg);
343 add_memory_region(start_at, mem_size, BFIN_MEMMAP_RAM);
344 } else if (*arg == '$') {
345 start_at = memparse(arg+1, &arg);
346 add_memory_region(start_at, mem_size, BFIN_MEMMAP_RESERVED);
353 * Initial parsing of the command line. Currently, we support:
354 * - Controlling the linux memory size: mem=xxx[KMG]
355 * - Controlling the physical memory size: max_mem=xxx[KMG][$][#]
356 * $ -> reserved memory is dcacheable
357 * # -> reserved memory is icacheable
358 * - "memmap=XXX[KkmM][@][$]XXX[KkmM]" defines a memory region
359 * @ from <start> to <start>+<mem>, type RAM
360 * $ from <start> to <start>+<mem>, type RESERVED
363 static __init void parse_cmdline_early(char *cmdline_p)
365 char c = ' ', *to = cmdline_p;
366 unsigned int memsize;
369 if (!memcmp(to, "mem=", 4)) {
371 memsize = memparse(to, &to);
375 } else if (!memcmp(to, "max_mem=", 8)) {
377 memsize = memparse(to, &to);
379 physical_mem_end = memsize;
383 reserved_mem_dcache_on =
387 reserved_mem_icache_on =
391 } else if (!memcmp(to, "earlyprintk=", 12)) {
393 setup_early_printk(to);
394 } else if (!memcmp(to, "memmap=", 7)) {
406 * Setup memory defaults from user config.
407 * The physical memory layout looks like:
409 * [_rambase, _ramstart]: kernel image
410 * [memory_start, memory_end]: dynamic memory managed by kernel
411 * [memory_end, _ramend]: reserved memory
412 * [meory_mtd_start(memory_end),
413 * memory_mtd_start + mtd_size]: rootfs (if any)
414 * [_ramend - DMA_UNCACHED_REGION,
415 * _ramend]: uncached DMA region
416 * [_ramend, physical_mem_end]: memory not managed by kernel
419 static __init void memory_setup(void)
421 #ifdef CONFIG_MTD_UCLINUX
422 unsigned long mtd_phys = 0;
425 _rambase = (unsigned long)_stext;
426 _ramstart = (unsigned long)_end;
428 if (DMA_UNCACHED_REGION > (_ramend - _ramstart)) {
430 panic("DMA region exceeds memory limit: %lu.\n",
431 _ramend - _ramstart);
433 memory_end = _ramend - DMA_UNCACHED_REGION;
436 /* Round up to multiple of 4MB. */
437 memory_start = (_ramstart + 0x3fffff) & ~0x3fffff;
439 memory_start = PAGE_ALIGN(_ramstart);
442 #if defined(CONFIG_MTD_UCLINUX)
443 /* generic memory mapped MTD driver */
444 memory_mtd_end = memory_end;
446 mtd_phys = _ramstart;
447 mtd_size = PAGE_ALIGN(*((unsigned long *)(mtd_phys + 8)));
449 # if defined(CONFIG_EXT2_FS) || defined(CONFIG_EXT3_FS)
450 if (*((unsigned short *)(mtd_phys + 0x438)) == EXT2_SUPER_MAGIC)
452 PAGE_ALIGN(*((unsigned long *)(mtd_phys + 0x404)) << 10);
455 # if defined(CONFIG_CRAMFS)
456 if (*((unsigned long *)(mtd_phys)) == CRAMFS_MAGIC)
457 mtd_size = PAGE_ALIGN(*((unsigned long *)(mtd_phys + 0x4)));
460 # if defined(CONFIG_ROMFS_FS)
461 if (((unsigned long *)mtd_phys)[0] == ROMSB_WORD0
462 && ((unsigned long *)mtd_phys)[1] == ROMSB_WORD1)
464 PAGE_ALIGN(be32_to_cpu(((unsigned long *)mtd_phys)[2]));
465 # if (defined(CONFIG_BFIN_ICACHE) && ANOMALY_05000263)
466 /* Due to a Hardware Anomaly we need to limit the size of usable
467 * instruction memory to max 60MB, 56 if HUNT_FOR_ZERO is on
468 * 05000263 - Hardware loop corrupted when taking an ICPLB exception
470 # if (defined(CONFIG_DEBUG_HUNT_FOR_ZERO))
471 if (memory_end >= 56 * 1024 * 1024)
472 memory_end = 56 * 1024 * 1024;
474 if (memory_end >= 60 * 1024 * 1024)
475 memory_end = 60 * 1024 * 1024;
476 # endif /* CONFIG_DEBUG_HUNT_FOR_ZERO */
477 # endif /* ANOMALY_05000263 */
478 # endif /* CONFIG_ROMFS_FS */
480 memory_end -= mtd_size;
484 panic("Don't boot kernel without rootfs attached.\n");
487 /* Relocate MTD image to the top of memory after the uncached memory area */
488 dma_memcpy((char *)memory_end, _end, mtd_size);
490 memory_mtd_start = memory_end;
491 _ebss = memory_mtd_start; /* define _ebss for compatible */
492 #endif /* CONFIG_MTD_UCLINUX */
494 #if (defined(CONFIG_BFIN_ICACHE) && ANOMALY_05000263)
495 /* Due to a Hardware Anomaly we need to limit the size of usable
496 * instruction memory to max 60MB, 56 if HUNT_FOR_ZERO is on
497 * 05000263 - Hardware loop corrupted when taking an ICPLB exception
499 #if (defined(CONFIG_DEBUG_HUNT_FOR_ZERO))
500 if (memory_end >= 56 * 1024 * 1024)
501 memory_end = 56 * 1024 * 1024;
503 if (memory_end >= 60 * 1024 * 1024)
504 memory_end = 60 * 1024 * 1024;
505 #endif /* CONFIG_DEBUG_HUNT_FOR_ZERO */
506 printk(KERN_NOTICE "Warning: limiting memory to %liMB due to hardware anomaly 05000263\n", memory_end >> 20);
507 #endif /* ANOMALY_05000263 */
510 page_mask_nelts = ((_ramend >> PAGE_SHIFT) + 31) / 32;
511 page_mask_order = get_order(3 * page_mask_nelts * sizeof(long));
514 #if !defined(CONFIG_MTD_UCLINUX)
515 /*In case there is no valid CPLB behind memory_end make sure we don't get to close*/
516 memory_end -= SIZE_4K;
519 init_mm.start_code = (unsigned long)_stext;
520 init_mm.end_code = (unsigned long)_etext;
521 init_mm.end_data = (unsigned long)_edata;
522 init_mm.brk = (unsigned long)0;
524 printk(KERN_INFO "Board Memory: %ldMB\n", physical_mem_end >> 20);
525 printk(KERN_INFO "Kernel Managed Memory: %ldMB\n", _ramend >> 20);
527 printk(KERN_INFO "Memory map:\n"
528 KERN_INFO " fixedcode = 0x%p-0x%p\n"
529 KERN_INFO " text = 0x%p-0x%p\n"
530 KERN_INFO " rodata = 0x%p-0x%p\n"
531 KERN_INFO " bss = 0x%p-0x%p\n"
532 KERN_INFO " data = 0x%p-0x%p\n"
533 KERN_INFO " stack = 0x%p-0x%p\n"
534 KERN_INFO " init = 0x%p-0x%p\n"
535 KERN_INFO " available = 0x%p-0x%p\n"
536 #ifdef CONFIG_MTD_UCLINUX
537 KERN_INFO " rootfs = 0x%p-0x%p\n"
539 #if DMA_UNCACHED_REGION > 0
540 KERN_INFO " DMA Zone = 0x%p-0x%p\n"
542 , (void *)FIXED_CODE_START, (void *)FIXED_CODE_END,
544 __start_rodata, __end_rodata,
545 __bss_start, __bss_stop,
547 (void *)&init_thread_union,
548 (void *)((int)(&init_thread_union) + 0x2000),
549 __init_begin, __init_end,
550 (void *)_ramstart, (void *)memory_end
551 #ifdef CONFIG_MTD_UCLINUX
552 , (void *)memory_mtd_start, (void *)(memory_mtd_start + mtd_size)
554 #if DMA_UNCACHED_REGION > 0
555 , (void *)(_ramend - DMA_UNCACHED_REGION), (void *)(_ramend)
561 * Find the lowest, highest page frame number we have available
563 void __init find_min_max_pfn(void)
568 min_low_pfn = memory_end;
570 for (i = 0; i < bfin_memmap.nr_map; i++) {
571 unsigned long start, end;
573 if (bfin_memmap.map[i].type != BFIN_MEMMAP_RAM)
575 start = PFN_UP(bfin_memmap.map[i].addr);
576 end = PFN_DOWN(bfin_memmap.map[i].addr +
577 bfin_memmap.map[i].size);
582 if (start < min_low_pfn)
587 static __init void setup_bootmem_allocator(void)
591 unsigned long start_pfn, end_pfn;
592 unsigned long curr_pfn, last_pfn, size;
594 /* mark memory between memory_start and memory_end usable */
595 add_memory_region(memory_start,
596 memory_end - memory_start, BFIN_MEMMAP_RAM);
597 /* sanity check for overlap */
598 sanitize_memmap(bfin_memmap.map, &bfin_memmap.nr_map);
599 print_memory_map("boot memmap");
601 /* intialize globals in linux/bootmem.h */
603 /* pfn of the last usable page frame */
604 if (max_pfn > memory_end >> PAGE_SHIFT)
605 max_pfn = memory_end >> PAGE_SHIFT;
606 /* pfn of last page frame directly mapped by kernel */
607 max_low_pfn = max_pfn;
608 /* pfn of the first usable page frame after kernel image*/
609 if (min_low_pfn < memory_start >> PAGE_SHIFT)
610 min_low_pfn = memory_start >> PAGE_SHIFT;
612 start_pfn = PAGE_OFFSET >> PAGE_SHIFT;
613 end_pfn = memory_end >> PAGE_SHIFT;
616 * give all the memory to the bootmap allocator, tell it to put the
617 * boot mem_map at the start of memory.
619 bootmap_size = init_bootmem_node(NODE_DATA(0),
620 memory_start >> PAGE_SHIFT, /* map goes here */
623 /* register the memmap regions with the bootmem allocator */
624 for (i = 0; i < bfin_memmap.nr_map; i++) {
626 * Reserve usable memory
628 if (bfin_memmap.map[i].type != BFIN_MEMMAP_RAM)
631 * We are rounding up the start address of usable memory:
633 curr_pfn = PFN_UP(bfin_memmap.map[i].addr);
634 if (curr_pfn >= end_pfn)
637 * ... and at the end of the usable range downwards:
639 last_pfn = PFN_DOWN(bfin_memmap.map[i].addr +
640 bfin_memmap.map[i].size);
642 if (last_pfn > end_pfn)
646 * .. finally, did all the rounding and playing
647 * around just make the area go away?
649 if (last_pfn <= curr_pfn)
652 size = last_pfn - curr_pfn;
653 free_bootmem(PFN_PHYS(curr_pfn), PFN_PHYS(size));
656 /* reserve memory before memory_start, including bootmap */
657 reserve_bootmem(PAGE_OFFSET,
658 memory_start + bootmap_size + PAGE_SIZE - 1 - PAGE_OFFSET,
662 #define EBSZ_TO_MEG(ebsz) \
665 switch (ebsz & 0xf) { \
666 case 0x1: meg = 16; break; \
667 case 0x3: meg = 32; break; \
668 case 0x5: meg = 64; break; \
669 case 0x7: meg = 128; break; \
670 case 0x9: meg = 256; break; \
671 case 0xb: meg = 512; break; \
675 static inline int __init get_mem_size(void)
677 #if defined(EBIU_SDBCTL)
678 # if defined(BF561_FAMILY)
680 u32 sdbctl = bfin_read_EBIU_SDBCTL();
681 ret += EBSZ_TO_MEG(sdbctl >> 0);
682 ret += EBSZ_TO_MEG(sdbctl >> 8);
683 ret += EBSZ_TO_MEG(sdbctl >> 16);
684 ret += EBSZ_TO_MEG(sdbctl >> 24);
687 return EBSZ_TO_MEG(bfin_read_EBIU_SDBCTL());
689 #elif defined(EBIU_DDRCTL1)
690 u32 ddrctl = bfin_read_EBIU_DDRCTL1();
692 switch (ddrctl & 0xc0000) {
693 case DEVSZ_64: ret = 64 / 8;
694 case DEVSZ_128: ret = 128 / 8;
695 case DEVSZ_256: ret = 256 / 8;
696 case DEVSZ_512: ret = 512 / 8;
698 switch (ddrctl & 0x30000) {
699 case DEVWD_4: ret *= 2;
700 case DEVWD_8: ret *= 2;
701 case DEVWD_16: break;
703 if ((ddrctl & 0xc000) == 0x4000)
710 void __init setup_arch(char **cmdline_p)
712 unsigned long sclk, cclk;
714 #ifdef CONFIG_DUMMY_CONSOLE
715 conswitchp = &dummy_con;
718 #if defined(CONFIG_CMDLINE_BOOL)
719 strncpy(&command_line[0], CONFIG_CMDLINE, sizeof(command_line));
720 command_line[sizeof(command_line) - 1] = 0;
723 /* Keep a copy of command line */
724 *cmdline_p = &command_line[0];
725 memcpy(boot_command_line, command_line, COMMAND_LINE_SIZE);
726 boot_command_line[COMMAND_LINE_SIZE - 1] = '\0';
728 /* setup memory defaults from the user config */
729 physical_mem_end = 0;
730 _ramend = get_mem_size() * 1024 * 1024;
732 memset(&bfin_memmap, 0, sizeof(bfin_memmap));
734 parse_cmdline_early(&command_line[0]);
736 if (physical_mem_end == 0)
737 physical_mem_end = _ramend;
744 #if !defined(CONFIG_BFIN_KERNEL_CLOCK)
745 if (ANOMALY_05000273 && cclk == sclk)
746 panic("ANOMALY 05000273, SCLK can not be same as CCLK");
750 if (ANOMALY_05000266) {
751 bfin_read_IMDMA_D0_IRQ_STATUS();
752 bfin_read_IMDMA_D1_IRQ_STATUS();
755 printk(KERN_INFO "Hardware Trace ");
756 if (bfin_read_TBUFCTL() & 0x1)
760 if (bfin_read_TBUFCTL() & 0x2)
761 printk("and Enabled\n");
763 printk("and Disabled\n");
765 #if defined(CONFIG_CHR_DEV_FLASH) || defined(CONFIG_BLK_DEV_FLASH)
766 /* we need to initialize the Flashrom device here since we might
767 * do things with flash early on in the boot
772 _bfin_swrst = bfin_read_SWRST();
774 if (_bfin_swrst & RESET_DOUBLE)
775 printk(KERN_INFO "Recovering from Double Fault event\n");
776 else if (_bfin_swrst & RESET_WDOG)
777 printk(KERN_INFO "Recovering from Watchdog event\n");
778 else if (_bfin_swrst & RESET_SOFTWARE)
779 printk(KERN_NOTICE "Reset caused by Software reset\n");
781 printk(KERN_INFO "Blackfin support (C) 2004-2008 Analog Devices, Inc.\n");
782 if (bfin_compiled_revid() == 0xffff)
783 printk(KERN_INFO "Compiled for ADSP-%s Rev any\n", CPU);
784 else if (bfin_compiled_revid() == -1)
785 printk(KERN_INFO "Compiled for ADSP-%s Rev none\n", CPU);
787 printk(KERN_INFO "Compiled for ADSP-%s Rev 0.%d\n", CPU, bfin_compiled_revid());
788 if (bfin_revid() != bfin_compiled_revid()) {
789 if (bfin_compiled_revid() == -1)
790 printk(KERN_ERR "Warning: Compiled for Rev none, but running on Rev %d\n",
792 else if (bfin_compiled_revid() != 0xffff)
793 printk(KERN_ERR "Warning: Compiled for Rev %d, but running on Rev %d\n",
794 bfin_compiled_revid(), bfin_revid());
796 if (bfin_revid() < SUPPORTED_REVID)
797 printk(KERN_ERR "Warning: Unsupported Chip Revision ADSP-%s Rev 0.%d detected\n",
799 printk(KERN_INFO "Blackfin Linux support by http://blackfin.uclinux.org/\n");
801 printk(KERN_INFO "Processor Speed: %lu MHz core clock and %lu MHz System Clock\n",
802 cclk / 1000000, sclk / 1000000);
804 if (ANOMALY_05000273 && (cclk >> 1) <= sclk)
805 printk("\n\n\nANOMALY_05000273: CCLK must be >= 2*SCLK !!!\n\n\n");
807 setup_bootmem_allocator();
811 /* Copy atomic sequences to their fixed location, and sanity check that
812 these locations are the ones that we advertise to userspace. */
813 memcpy((void *)FIXED_CODE_START, &fixed_code_start,
814 FIXED_CODE_END - FIXED_CODE_START);
815 BUG_ON((char *)&sigreturn_stub - (char *)&fixed_code_start
816 != SIGRETURN_STUB - FIXED_CODE_START);
817 BUG_ON((char *)&atomic_xchg32 - (char *)&fixed_code_start
818 != ATOMIC_XCHG32 - FIXED_CODE_START);
819 BUG_ON((char *)&atomic_cas32 - (char *)&fixed_code_start
820 != ATOMIC_CAS32 - FIXED_CODE_START);
821 BUG_ON((char *)&atomic_add32 - (char *)&fixed_code_start
822 != ATOMIC_ADD32 - FIXED_CODE_START);
823 BUG_ON((char *)&atomic_sub32 - (char *)&fixed_code_start
824 != ATOMIC_SUB32 - FIXED_CODE_START);
825 BUG_ON((char *)&atomic_ior32 - (char *)&fixed_code_start
826 != ATOMIC_IOR32 - FIXED_CODE_START);
827 BUG_ON((char *)&atomic_and32 - (char *)&fixed_code_start
828 != ATOMIC_AND32 - FIXED_CODE_START);
829 BUG_ON((char *)&atomic_xor32 - (char *)&fixed_code_start
830 != ATOMIC_XOR32 - FIXED_CODE_START);
831 BUG_ON((char *)&safe_user_instruction - (char *)&fixed_code_start
832 != SAFE_USER_INSTRUCTION - FIXED_CODE_START);
834 init_exception_vectors();
838 static int __init topology_init(void)
842 for_each_possible_cpu(cpu) {
843 struct cpu *c = &per_cpu(cpu_devices, cpu);
845 register_cpu(c, cpu);
851 subsys_initcall(topology_init);
853 static u_long get_vco(void)
858 msel = (bfin_read_PLL_CTL() >> 9) & 0x3F;
862 vco = CONFIG_CLKIN_HZ;
863 vco >>= (1 & bfin_read_PLL_CTL()); /* DF bit */
868 /* Get the Core clock */
869 u_long get_cclk(void)
872 if (bfin_read_PLL_STAT() & 0x1)
873 return CONFIG_CLKIN_HZ;
875 ssel = bfin_read_PLL_DIV();
876 csel = ((ssel >> 4) & 0x03);
878 if (ssel && ssel < (1 << csel)) /* SCLK > CCLK */
879 return get_vco() / ssel;
880 return get_vco() >> csel;
882 EXPORT_SYMBOL(get_cclk);
884 /* Get the System clock */
885 u_long get_sclk(void)
889 if (bfin_read_PLL_STAT() & 0x1)
890 return CONFIG_CLKIN_HZ;
892 ssel = (bfin_read_PLL_DIV() & 0xf);
894 printk(KERN_WARNING "Invalid System Clock\n");
898 return get_vco() / ssel;
900 EXPORT_SYMBOL(get_sclk);
902 unsigned long sclk_to_usecs(unsigned long sclk)
904 u64 tmp = USEC_PER_SEC * (u64)sclk;
905 do_div(tmp, get_sclk());
908 EXPORT_SYMBOL(sclk_to_usecs);
910 unsigned long usecs_to_sclk(unsigned long usecs)
912 u64 tmp = get_sclk() * (u64)usecs;
913 do_div(tmp, USEC_PER_SEC);
916 EXPORT_SYMBOL(usecs_to_sclk);
919 * Get CPU information for use by the procfs.
921 static int show_cpuinfo(struct seq_file *m, void *v)
923 char *cpu, *mmu, *fpu, *vendor, *cache;
926 u_long cclk = 0, sclk = 0;
927 u_int dcache_size = 0, dsup_banks = 0;
932 revid = bfin_revid();
937 switch (bfin_read_CHIPID() & CHIPID_MANUFACTURE) {
939 vendor = "Analog Devices";
946 seq_printf(m, "processor\t: %d\n"
948 "cpu family\t: 0x%x\n"
949 "model name\t: ADSP-%s %lu(MHz CCLK) %lu(MHz SCLK) (%s)\n"
953 (bfin_read_CHIPID() & CHIPID_FAMILY),
954 cpu, cclk/1000000, sclk/1000000,
962 seq_printf(m, "cpu MHz\t\t: %lu.%03lu/%lu.%03lu\n",
963 cclk/1000000, cclk%1000000,
964 sclk/1000000, sclk%1000000);
965 seq_printf(m, "bogomips\t: %lu.%02lu\n"
966 "Calibration\t: %lu loops\n",
967 (loops_per_jiffy * HZ) / 500000,
968 ((loops_per_jiffy * HZ) / 5000) % 100,
969 (loops_per_jiffy * HZ));
971 /* Check Cache configutation */
972 switch (bfin_read_DMEM_CONTROL() & (1 << DMC0_P | 1 << DMC1_P)) {
974 cache = "dbank-A/B\t: cache/sram";
979 cache = "dbank-A/B\t: cache/cache";
984 cache = "dbank-A/B\t: sram/sram";
995 /* Is it turned on? */
996 if (!((bfin_read_DMEM_CONTROL()) & (ENDCPLB | DMC_ENABLE)))
999 seq_printf(m, "cache size\t: %d KB(L1 icache) "
1000 "%d KB(L1 dcache-%s) %d KB(L2 cache)\n",
1001 BFIN_ICACHESIZE / 1024, dcache_size,
1002 #if defined CONFIG_BFIN_WB
1004 #elif defined CONFIG_BFIN_WT
1009 seq_printf(m, "%s\n", cache);
1011 seq_printf(m, "icache setup\t: %d Sub-banks/%d Ways, %d Lines/Way\n",
1012 BFIN_ISUBBANKS, BFIN_IWAYS, BFIN_ILINES);
1014 "dcache setup\t: %d Super-banks/%d Sub-banks/%d Ways, %d Lines/Way\n",
1015 dsup_banks, BFIN_DSUBBANKS, BFIN_DWAYS,
1017 #ifdef CONFIG_BFIN_ICACHE_LOCK
1018 switch (read_iloc()) {
1020 seq_printf(m, "Way0 Locked-Down\n");
1023 seq_printf(m, "Way1 Locked-Down\n");
1026 seq_printf(m, "Way0,Way1 Locked-Down\n");
1029 seq_printf(m, "Way2 Locked-Down\n");
1032 seq_printf(m, "Way0,Way2 Locked-Down\n");
1035 seq_printf(m, "Way1,Way2 Locked-Down\n");
1038 seq_printf(m, "Way0,Way1 & Way2 Locked-Down\n");
1041 seq_printf(m, "Way3 Locked-Down\n");
1044 seq_printf(m, "Way0,Way3 Locked-Down\n");
1047 seq_printf(m, "Way1,Way3 Locked-Down\n");
1050 seq_printf(m, "Way 0,Way1,Way3 Locked-Down\n");
1053 seq_printf(m, "Way3,Way2 Locked-Down\n");
1056 seq_printf(m, "Way3,Way2,Way0 Locked-Down\n");
1059 seq_printf(m, "Way3,Way2,Way1 Locked-Down\n");
1062 seq_printf(m, "All Ways are locked\n");
1065 seq_printf(m, "No Ways are locked\n");
1068 seq_printf(m, "board name\t: %s\n", bfin_board_name);
1069 seq_printf(m, "board memory\t: %ld kB (0x%p -> 0x%p)\n",
1070 physical_mem_end >> 10, (void *)0, (void *)physical_mem_end);
1071 seq_printf(m, "kernel memory\t: %d kB (0x%p -> 0x%p)\n",
1072 ((int)memory_end - (int)_stext) >> 10,
1074 (void *)memory_end);
1079 static void *c_start(struct seq_file *m, loff_t *pos)
1081 return *pos < NR_CPUS ? ((void *)0x12345678) : NULL;
1084 static void *c_next(struct seq_file *m, void *v, loff_t *pos)
1087 return c_start(m, pos);
1090 static void c_stop(struct seq_file *m, void *v)
1094 const struct seq_operations cpuinfo_op = {
1098 .show = show_cpuinfo,
1101 void __init cmdline_init(const char *r0)
1104 strncpy(command_line, r0, COMMAND_LINE_SIZE);