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 l1_code_length = L1_CODE_LENGTH;
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 l1_data_a_length = L1_DATA_A_LENGTH;
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 l1_data_b_length = L1_DATA_B_LENGTH;
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);
135 /* add_memory_region to memmap */
136 static void __init add_memory_region(unsigned long long start,
137 unsigned long long size, int type)
141 i = bfin_memmap.nr_map;
143 if (i == BFIN_MEMMAP_MAX) {
144 printk(KERN_ERR "Ooops! Too many entries in the memory map!\n");
148 bfin_memmap.map[i].addr = start;
149 bfin_memmap.map[i].size = size;
150 bfin_memmap.map[i].type = type;
151 bfin_memmap.nr_map++;
155 * Sanitize the boot memmap, removing overlaps.
157 static int __init sanitize_memmap(struct bfin_memmap_entry *map, int *pnr_map)
159 struct change_member *change_tmp;
160 unsigned long current_type, last_type;
161 unsigned long long last_addr;
162 int chgidx, still_changing;
165 int old_nr, new_nr, chg_nr;
169 Visually we're performing the following (1,2,3,4 = memory types)
171 Sample memory map (w/overlaps):
172 ____22__________________
173 ______________________4_
174 ____1111________________
175 _44_____________________
176 11111111________________
177 ____________________33__
178 ___________44___________
179 __________33333_________
180 ______________22________
181 ___________________2222_
182 _________111111111______
183 _____________________11_
184 _________________4______
186 Sanitized equivalent (no overlap):
187 1_______________________
188 _44_____________________
189 ___1____________________
190 ____22__________________
191 ______11________________
192 _________1______________
193 __________3_____________
194 ___________44___________
195 _____________33_________
196 _______________2________
197 ________________1_______
198 _________________4______
199 ___________________2____
200 ____________________33__
201 ______________________4_
203 /* if there's only one memory region, don't bother */
209 /* bail out if we find any unreasonable addresses in memmap */
210 for (i = 0; i < old_nr; i++)
211 if (map[i].addr + map[i].size < map[i].addr)
214 /* create pointers for initial change-point information (for sorting) */
215 for (i = 0; i < 2*old_nr; i++)
216 change_point[i] = &change_point_list[i];
218 /* record all known change-points (starting and ending addresses),
219 omitting those that are for empty memory regions */
221 for (i = 0; i < old_nr; i++) {
222 if (map[i].size != 0) {
223 change_point[chgidx]->addr = map[i].addr;
224 change_point[chgidx++]->pentry = &map[i];
225 change_point[chgidx]->addr = map[i].addr + map[i].size;
226 change_point[chgidx++]->pentry = &map[i];
229 chg_nr = chgidx; /* true number of change-points */
231 /* sort change-point list by memory addresses (low -> high) */
233 while (still_changing) {
235 for (i = 1; i < chg_nr; i++) {
236 /* if <current_addr> > <last_addr>, swap */
237 /* or, if current=<start_addr> & last=<end_addr>, swap */
238 if ((change_point[i]->addr < change_point[i-1]->addr) ||
239 ((change_point[i]->addr == change_point[i-1]->addr) &&
240 (change_point[i]->addr == change_point[i]->pentry->addr) &&
241 (change_point[i-1]->addr != change_point[i-1]->pentry->addr))
243 change_tmp = change_point[i];
244 change_point[i] = change_point[i-1];
245 change_point[i-1] = change_tmp;
251 /* create a new memmap, removing overlaps */
252 overlap_entries = 0; /* number of entries in the overlap table */
253 new_entry = 0; /* index for creating new memmap entries */
254 last_type = 0; /* start with undefined memory type */
255 last_addr = 0; /* start with 0 as last starting address */
256 /* loop through change-points, determining affect on the new memmap */
257 for (chgidx = 0; chgidx < chg_nr; chgidx++) {
258 /* keep track of all overlapping memmap entries */
259 if (change_point[chgidx]->addr == change_point[chgidx]->pentry->addr) {
260 /* add map entry to overlap list (> 1 entry implies an overlap) */
261 overlap_list[overlap_entries++] = change_point[chgidx]->pentry;
263 /* remove entry from list (order independent, so swap with last) */
264 for (i = 0; i < overlap_entries; i++) {
265 if (overlap_list[i] == change_point[chgidx]->pentry)
266 overlap_list[i] = overlap_list[overlap_entries-1];
270 /* if there are overlapping entries, decide which "type" to use */
271 /* (larger value takes precedence -- 1=usable, 2,3,4,4+=unusable) */
273 for (i = 0; i < overlap_entries; i++)
274 if (overlap_list[i]->type > current_type)
275 current_type = overlap_list[i]->type;
276 /* continue building up new memmap based on this information */
277 if (current_type != last_type) {
278 if (last_type != 0) {
279 new_map[new_entry].size =
280 change_point[chgidx]->addr - last_addr;
281 /* move forward only if the new size was non-zero */
282 if (new_map[new_entry].size != 0)
283 if (++new_entry >= BFIN_MEMMAP_MAX)
284 break; /* no more space left for new entries */
286 if (current_type != 0) {
287 new_map[new_entry].addr = change_point[chgidx]->addr;
288 new_map[new_entry].type = current_type;
289 last_addr = change_point[chgidx]->addr;
291 last_type = current_type;
294 new_nr = new_entry; /* retain count for new entries */
296 /* copy new mapping into original location */
297 memcpy(map, new_map, new_nr*sizeof(struct bfin_memmap_entry));
303 static void __init print_memory_map(char *who)
307 for (i = 0; i < bfin_memmap.nr_map; i++) {
308 printk(KERN_DEBUG " %s: %016Lx - %016Lx ", who,
309 bfin_memmap.map[i].addr,
310 bfin_memmap.map[i].addr + bfin_memmap.map[i].size);
311 switch (bfin_memmap.map[i].type) {
312 case BFIN_MEMMAP_RAM:
313 printk("(usable)\n");
315 case BFIN_MEMMAP_RESERVED:
316 printk("(reserved)\n");
318 default: printk("type %lu\n", bfin_memmap.map[i].type);
324 static __init int parse_memmap(char *arg)
326 unsigned long long start_at, mem_size;
331 mem_size = memparse(arg, &arg);
333 start_at = memparse(arg+1, &arg);
334 add_memory_region(start_at, mem_size, BFIN_MEMMAP_RAM);
335 } else if (*arg == '$') {
336 start_at = memparse(arg+1, &arg);
337 add_memory_region(start_at, mem_size, BFIN_MEMMAP_RESERVED);
344 * Initial parsing of the command line. Currently, we support:
345 * - Controlling the linux memory size: mem=xxx[KMG]
346 * - Controlling the physical memory size: max_mem=xxx[KMG][$][#]
347 * $ -> reserved memory is dcacheable
348 * # -> reserved memory is icacheable
349 * - "memmap=XXX[KkmM][@][$]XXX[KkmM]" defines a memory region
350 * @ from <start> to <start>+<mem>, type RAM
351 * $ from <start> to <start>+<mem>, type RESERVED
354 static __init void parse_cmdline_early(char *cmdline_p)
356 char c = ' ', *to = cmdline_p;
357 unsigned int memsize;
360 if (!memcmp(to, "mem=", 4)) {
362 memsize = memparse(to, &to);
366 } else if (!memcmp(to, "max_mem=", 8)) {
368 memsize = memparse(to, &to);
370 physical_mem_end = memsize;
374 reserved_mem_dcache_on =
378 reserved_mem_icache_on =
382 } else if (!memcmp(to, "earlyprintk=", 12)) {
384 setup_early_printk(to);
385 } else if (!memcmp(to, "memmap=", 7)) {
397 * Setup memory defaults from user config.
398 * The physical memory layout looks like:
400 * [_rambase, _ramstart]: kernel image
401 * [memory_start, memory_end]: dynamic memory managed by kernel
402 * [memory_end, _ramend]: reserved memory
403 * [meory_mtd_start(memory_end),
404 * memory_mtd_start + mtd_size]: rootfs (if any)
405 * [_ramend - DMA_UNCACHED_REGION,
406 * _ramend]: uncached DMA region
407 * [_ramend, physical_mem_end]: memory not managed by kernel
410 static __init void memory_setup(void)
412 #ifdef CONFIG_MTD_UCLINUX
413 unsigned long mtd_phys = 0;
416 _rambase = (unsigned long)_stext;
417 _ramstart = (unsigned long)_end;
419 if (DMA_UNCACHED_REGION > (_ramend - _ramstart)) {
421 panic("DMA region exceeds memory limit: %lu.\n",
422 _ramend - _ramstart);
424 memory_end = _ramend - DMA_UNCACHED_REGION;
427 /* Round up to multiple of 4MB. */
428 memory_start = (_ramstart + 0x3fffff) & ~0x3fffff;
430 memory_start = PAGE_ALIGN(_ramstart);
433 #if defined(CONFIG_MTD_UCLINUX)
434 /* generic memory mapped MTD driver */
435 memory_mtd_end = memory_end;
437 mtd_phys = _ramstart;
438 mtd_size = PAGE_ALIGN(*((unsigned long *)(mtd_phys + 8)));
440 # if defined(CONFIG_EXT2_FS) || defined(CONFIG_EXT3_FS)
441 if (*((unsigned short *)(mtd_phys + 0x438)) == EXT2_SUPER_MAGIC)
443 PAGE_ALIGN(*((unsigned long *)(mtd_phys + 0x404)) << 10);
446 # if defined(CONFIG_CRAMFS)
447 if (*((unsigned long *)(mtd_phys)) == CRAMFS_MAGIC)
448 mtd_size = PAGE_ALIGN(*((unsigned long *)(mtd_phys + 0x4)));
451 # if defined(CONFIG_ROMFS_FS)
452 if (((unsigned long *)mtd_phys)[0] == ROMSB_WORD0
453 && ((unsigned long *)mtd_phys)[1] == ROMSB_WORD1)
455 PAGE_ALIGN(be32_to_cpu(((unsigned long *)mtd_phys)[2]));
456 # if (defined(CONFIG_BFIN_ICACHE) && ANOMALY_05000263)
457 /* Due to a Hardware Anomaly we need to limit the size of usable
458 * instruction memory to max 60MB, 56 if HUNT_FOR_ZERO is on
459 * 05000263 - Hardware loop corrupted when taking an ICPLB exception
461 # if (defined(CONFIG_DEBUG_HUNT_FOR_ZERO))
462 if (memory_end >= 56 * 1024 * 1024)
463 memory_end = 56 * 1024 * 1024;
465 if (memory_end >= 60 * 1024 * 1024)
466 memory_end = 60 * 1024 * 1024;
467 # endif /* CONFIG_DEBUG_HUNT_FOR_ZERO */
468 # endif /* ANOMALY_05000263 */
469 # endif /* CONFIG_ROMFS_FS */
471 memory_end -= mtd_size;
475 panic("Don't boot kernel without rootfs attached.\n");
478 /* Relocate MTD image to the top of memory after the uncached memory area */
479 dma_memcpy((char *)memory_end, _end, mtd_size);
481 memory_mtd_start = memory_end;
482 _ebss = memory_mtd_start; /* define _ebss for compatible */
483 #endif /* CONFIG_MTD_UCLINUX */
485 #if (defined(CONFIG_BFIN_ICACHE) && ANOMALY_05000263)
486 /* Due to a Hardware Anomaly we need to limit the size of usable
487 * instruction memory to max 60MB, 56 if HUNT_FOR_ZERO is on
488 * 05000263 - Hardware loop corrupted when taking an ICPLB exception
490 #if (defined(CONFIG_DEBUG_HUNT_FOR_ZERO))
491 if (memory_end >= 56 * 1024 * 1024)
492 memory_end = 56 * 1024 * 1024;
494 if (memory_end >= 60 * 1024 * 1024)
495 memory_end = 60 * 1024 * 1024;
496 #endif /* CONFIG_DEBUG_HUNT_FOR_ZERO */
497 printk(KERN_NOTICE "Warning: limiting memory to %liMB due to hardware anomaly 05000263\n", memory_end >> 20);
498 #endif /* ANOMALY_05000263 */
501 page_mask_nelts = ((_ramend >> PAGE_SHIFT) + 31) / 32;
502 page_mask_order = get_order(3 * page_mask_nelts * sizeof(long));
505 #if !defined(CONFIG_MTD_UCLINUX)
506 /*In case there is no valid CPLB behind memory_end make sure we don't get to close*/
507 memory_end -= SIZE_4K;
510 init_mm.start_code = (unsigned long)_stext;
511 init_mm.end_code = (unsigned long)_etext;
512 init_mm.end_data = (unsigned long)_edata;
513 init_mm.brk = (unsigned long)0;
515 printk(KERN_INFO "Board Memory: %ldMB\n", physical_mem_end >> 20);
516 printk(KERN_INFO "Kernel Managed Memory: %ldMB\n", _ramend >> 20);
518 printk(KERN_INFO "Memory map:\n"
519 KERN_INFO " fixedcode = 0x%p-0x%p\n"
520 KERN_INFO " text = 0x%p-0x%p\n"
521 KERN_INFO " rodata = 0x%p-0x%p\n"
522 KERN_INFO " bss = 0x%p-0x%p\n"
523 KERN_INFO " data = 0x%p-0x%p\n"
524 KERN_INFO " stack = 0x%p-0x%p\n"
525 KERN_INFO " init = 0x%p-0x%p\n"
526 KERN_INFO " available = 0x%p-0x%p\n"
527 #ifdef CONFIG_MTD_UCLINUX
528 KERN_INFO " rootfs = 0x%p-0x%p\n"
530 #if DMA_UNCACHED_REGION > 0
531 KERN_INFO " DMA Zone = 0x%p-0x%p\n"
533 , (void *)FIXED_CODE_START, (void *)FIXED_CODE_END,
535 __start_rodata, __end_rodata,
536 __bss_start, __bss_stop,
538 (void *)&init_thread_union,
539 (void *)((int)(&init_thread_union) + 0x2000),
540 __init_begin, __init_end,
541 (void *)_ramstart, (void *)memory_end
542 #ifdef CONFIG_MTD_UCLINUX
543 , (void *)memory_mtd_start, (void *)(memory_mtd_start + mtd_size)
545 #if DMA_UNCACHED_REGION > 0
546 , (void *)(_ramend - DMA_UNCACHED_REGION), (void *)(_ramend)
552 * Find the lowest, highest page frame number we have available
554 void __init find_min_max_pfn(void)
559 min_low_pfn = memory_end;
561 for (i = 0; i < bfin_memmap.nr_map; i++) {
562 unsigned long start, end;
564 if (bfin_memmap.map[i].type != BFIN_MEMMAP_RAM)
566 start = PFN_UP(bfin_memmap.map[i].addr);
567 end = PFN_DOWN(bfin_memmap.map[i].addr +
568 bfin_memmap.map[i].size);
573 if (start < min_low_pfn)
578 static __init void setup_bootmem_allocator(void)
582 unsigned long start_pfn, end_pfn;
583 unsigned long curr_pfn, last_pfn, size;
585 /* mark memory between memory_start and memory_end usable */
586 add_memory_region(memory_start,
587 memory_end - memory_start, BFIN_MEMMAP_RAM);
588 /* sanity check for overlap */
589 sanitize_memmap(bfin_memmap.map, &bfin_memmap.nr_map);
590 print_memory_map("boot memmap");
592 /* intialize globals in linux/bootmem.h */
594 /* pfn of the last usable page frame */
595 if (max_pfn > memory_end >> PAGE_SHIFT)
596 max_pfn = memory_end >> PAGE_SHIFT;
597 /* pfn of last page frame directly mapped by kernel */
598 max_low_pfn = max_pfn;
599 /* pfn of the first usable page frame after kernel image*/
600 if (min_low_pfn < memory_start >> PAGE_SHIFT)
601 min_low_pfn = memory_start >> PAGE_SHIFT;
603 start_pfn = PAGE_OFFSET >> PAGE_SHIFT;
604 end_pfn = memory_end >> PAGE_SHIFT;
607 * give all the memory to the bootmap allocator, tell it to put the
608 * boot mem_map at the start of memory.
610 bootmap_size = init_bootmem_node(NODE_DATA(0),
611 memory_start >> PAGE_SHIFT, /* map goes here */
614 /* register the memmap regions with the bootmem allocator */
615 for (i = 0; i < bfin_memmap.nr_map; i++) {
617 * Reserve usable memory
619 if (bfin_memmap.map[i].type != BFIN_MEMMAP_RAM)
622 * We are rounding up the start address of usable memory:
624 curr_pfn = PFN_UP(bfin_memmap.map[i].addr);
625 if (curr_pfn >= end_pfn)
628 * ... and at the end of the usable range downwards:
630 last_pfn = PFN_DOWN(bfin_memmap.map[i].addr +
631 bfin_memmap.map[i].size);
633 if (last_pfn > end_pfn)
637 * .. finally, did all the rounding and playing
638 * around just make the area go away?
640 if (last_pfn <= curr_pfn)
643 size = last_pfn - curr_pfn;
644 free_bootmem(PFN_PHYS(curr_pfn), PFN_PHYS(size));
647 /* reserve memory before memory_start, including bootmap */
648 reserve_bootmem(PAGE_OFFSET,
649 memory_start + bootmap_size + PAGE_SIZE - 1 - PAGE_OFFSET,
653 void __init setup_arch(char **cmdline_p)
655 unsigned long l1_length, sclk, cclk;
657 #ifdef CONFIG_DUMMY_CONSOLE
658 conswitchp = &dummy_con;
661 #if defined(CONFIG_CMDLINE_BOOL)
662 strncpy(&command_line[0], CONFIG_CMDLINE, sizeof(command_line));
663 command_line[sizeof(command_line) - 1] = 0;
666 /* Keep a copy of command line */
667 *cmdline_p = &command_line[0];
668 memcpy(boot_command_line, command_line, COMMAND_LINE_SIZE);
669 boot_command_line[COMMAND_LINE_SIZE - 1] = '\0';
671 /* setup memory defaults from the user config */
672 physical_mem_end = 0;
673 _ramend = CONFIG_MEM_SIZE * 1024 * 1024;
675 memset(&bfin_memmap, 0, sizeof(bfin_memmap));
677 parse_cmdline_early(&command_line[0]);
679 if (physical_mem_end == 0)
680 physical_mem_end = _ramend;
687 #if !defined(CONFIG_BFIN_KERNEL_CLOCK)
688 if (ANOMALY_05000273 && cclk == sclk)
689 panic("ANOMALY 05000273, SCLK can not be same as CCLK");
693 if (ANOMALY_05000266) {
694 bfin_read_IMDMA_D0_IRQ_STATUS();
695 bfin_read_IMDMA_D1_IRQ_STATUS();
698 printk(KERN_INFO "Hardware Trace ");
699 if (bfin_read_TBUFCTL() & 0x1)
703 if (bfin_read_TBUFCTL() & 0x2)
704 printk("and Enabled\n");
706 printk("and Disabled\n");
708 #if defined(CONFIG_CHR_DEV_FLASH) || defined(CONFIG_BLK_DEV_FLASH)
709 /* we need to initialize the Flashrom device here since we might
710 * do things with flash early on in the boot
715 _bfin_swrst = bfin_read_SWRST();
717 if (_bfin_swrst & RESET_DOUBLE)
718 printk(KERN_INFO "Recovering from Double Fault event\n");
719 else if (_bfin_swrst & RESET_WDOG)
720 printk(KERN_INFO "Recovering from Watchdog event\n");
721 else if (_bfin_swrst & RESET_SOFTWARE)
722 printk(KERN_NOTICE "Reset caused by Software reset\n");
724 printk(KERN_INFO "Blackfin support (C) 2004-2008 Analog Devices, Inc.\n");
725 if (bfin_compiled_revid() == 0xffff)
726 printk(KERN_INFO "Compiled for ADSP-%s Rev any\n", CPU);
727 else if (bfin_compiled_revid() == -1)
728 printk(KERN_INFO "Compiled for ADSP-%s Rev none\n", CPU);
730 printk(KERN_INFO "Compiled for ADSP-%s Rev 0.%d\n", CPU, bfin_compiled_revid());
731 if (bfin_revid() != bfin_compiled_revid()) {
732 if (bfin_compiled_revid() == -1)
733 printk(KERN_ERR "Warning: Compiled for Rev none, but running on Rev %d\n",
735 else if (bfin_compiled_revid() != 0xffff)
736 printk(KERN_ERR "Warning: Compiled for Rev %d, but running on Rev %d\n",
737 bfin_compiled_revid(), bfin_revid());
739 if (bfin_revid() < SUPPORTED_REVID)
740 printk(KERN_ERR "Warning: Unsupported Chip Revision ADSP-%s Rev 0.%d detected\n",
742 printk(KERN_INFO "Blackfin Linux support by http://blackfin.uclinux.org/\n");
744 printk(KERN_INFO "Processor Speed: %lu MHz core clock and %lu MHz System Clock\n",
745 cclk / 1000000, sclk / 1000000);
747 if (ANOMALY_05000273 && (cclk >> 1) <= sclk)
748 printk("\n\n\nANOMALY_05000273: CCLK must be >= 2*SCLK !!!\n\n\n");
750 setup_bootmem_allocator();
754 /* check the size of the l1 area */
755 l1_length = _etext_l1 - _stext_l1;
756 if (l1_length > L1_CODE_LENGTH)
757 panic("L1 code memory overflow\n");
759 l1_length = _ebss_l1 - _sdata_l1;
760 if (l1_length > L1_DATA_A_LENGTH)
761 panic("L1 data memory overflow\n");
763 /* Copy atomic sequences to their fixed location, and sanity check that
764 these locations are the ones that we advertise to userspace. */
765 memcpy((void *)FIXED_CODE_START, &fixed_code_start,
766 FIXED_CODE_END - FIXED_CODE_START);
767 BUG_ON((char *)&sigreturn_stub - (char *)&fixed_code_start
768 != SIGRETURN_STUB - FIXED_CODE_START);
769 BUG_ON((char *)&atomic_xchg32 - (char *)&fixed_code_start
770 != ATOMIC_XCHG32 - FIXED_CODE_START);
771 BUG_ON((char *)&atomic_cas32 - (char *)&fixed_code_start
772 != ATOMIC_CAS32 - FIXED_CODE_START);
773 BUG_ON((char *)&atomic_add32 - (char *)&fixed_code_start
774 != ATOMIC_ADD32 - FIXED_CODE_START);
775 BUG_ON((char *)&atomic_sub32 - (char *)&fixed_code_start
776 != ATOMIC_SUB32 - FIXED_CODE_START);
777 BUG_ON((char *)&atomic_ior32 - (char *)&fixed_code_start
778 != ATOMIC_IOR32 - FIXED_CODE_START);
779 BUG_ON((char *)&atomic_and32 - (char *)&fixed_code_start
780 != ATOMIC_AND32 - FIXED_CODE_START);
781 BUG_ON((char *)&atomic_xor32 - (char *)&fixed_code_start
782 != ATOMIC_XOR32 - FIXED_CODE_START);
783 BUG_ON((char *)&safe_user_instruction - (char *)&fixed_code_start
784 != SAFE_USER_INSTRUCTION - FIXED_CODE_START);
786 init_exception_vectors();
790 static int __init topology_init(void)
794 for_each_possible_cpu(cpu) {
795 struct cpu *c = &per_cpu(cpu_devices, cpu);
797 register_cpu(c, cpu);
803 subsys_initcall(topology_init);
805 static u_long get_vco(void)
810 msel = (bfin_read_PLL_CTL() >> 9) & 0x3F;
814 vco = CONFIG_CLKIN_HZ;
815 vco >>= (1 & bfin_read_PLL_CTL()); /* DF bit */
820 /* Get the Core clock */
821 u_long get_cclk(void)
824 if (bfin_read_PLL_STAT() & 0x1)
825 return CONFIG_CLKIN_HZ;
827 ssel = bfin_read_PLL_DIV();
828 csel = ((ssel >> 4) & 0x03);
830 if (ssel && ssel < (1 << csel)) /* SCLK > CCLK */
831 return get_vco() / ssel;
832 return get_vco() >> csel;
834 EXPORT_SYMBOL(get_cclk);
836 /* Get the System clock */
837 u_long get_sclk(void)
841 if (bfin_read_PLL_STAT() & 0x1)
842 return CONFIG_CLKIN_HZ;
844 ssel = (bfin_read_PLL_DIV() & 0xf);
846 printk(KERN_WARNING "Invalid System Clock\n");
850 return get_vco() / ssel;
852 EXPORT_SYMBOL(get_sclk);
854 unsigned long sclk_to_usecs(unsigned long sclk)
856 u64 tmp = USEC_PER_SEC * (u64)sclk;
857 do_div(tmp, get_sclk());
860 EXPORT_SYMBOL(sclk_to_usecs);
862 unsigned long usecs_to_sclk(unsigned long usecs)
864 u64 tmp = get_sclk() * (u64)usecs;
865 do_div(tmp, USEC_PER_SEC);
868 EXPORT_SYMBOL(usecs_to_sclk);
871 * Get CPU information for use by the procfs.
873 static int show_cpuinfo(struct seq_file *m, void *v)
875 char *cpu, *mmu, *fpu, *vendor, *cache;
878 u_long cclk = 0, sclk = 0;
879 u_int dcache_size = 0, dsup_banks = 0;
884 revid = bfin_revid();
889 switch (bfin_read_CHIPID() & CHIPID_MANUFACTURE) {
891 vendor = "Analog Devices";
898 seq_printf(m, "processor\t: %d\n"
900 "cpu family\t: 0x%x\n"
901 "model name\t: ADSP-%s %lu(MHz CCLK) %lu(MHz SCLK)\n"
905 (bfin_read_CHIPID() & CHIPID_FAMILY),
906 cpu, cclk/1000000, sclk/1000000,
909 seq_printf(m, "cpu MHz\t\t: %lu.%03lu/%lu.%03lu\n",
910 cclk/1000000, cclk%1000000,
911 sclk/1000000, sclk%1000000);
912 seq_printf(m, "bogomips\t: %lu.%02lu\n"
913 "Calibration\t: %lu loops\n",
914 (loops_per_jiffy * HZ) / 500000,
915 ((loops_per_jiffy * HZ) / 5000) % 100,
916 (loops_per_jiffy * HZ));
918 /* Check Cache configutation */
919 switch (bfin_read_DMEM_CONTROL() & (1 << DMC0_P | 1 << DMC1_P)) {
921 cache = "dbank-A/B\t: cache/sram";
926 cache = "dbank-A/B\t: cache/cache";
931 cache = "dbank-A/B\t: sram/sram";
942 /* Is it turned on? */
943 if (!((bfin_read_DMEM_CONTROL()) & (ENDCPLB | DMC_ENABLE)))
946 seq_printf(m, "cache size\t: %d KB(L1 icache) "
947 "%d KB(L1 dcache-%s) %d KB(L2 cache)\n",
948 BFIN_ICACHESIZE / 1024, dcache_size,
949 #if defined CONFIG_BFIN_WB
951 #elif defined CONFIG_BFIN_WT
956 seq_printf(m, "%s\n", cache);
958 seq_printf(m, "icache setup\t: %d Sub-banks/%d Ways, %d Lines/Way\n",
959 BFIN_ISUBBANKS, BFIN_IWAYS, BFIN_ILINES);
961 "dcache setup\t: %d Super-banks/%d Sub-banks/%d Ways, %d Lines/Way\n",
962 dsup_banks, BFIN_DSUBBANKS, BFIN_DWAYS,
964 #ifdef CONFIG_BFIN_ICACHE_LOCK
965 switch (read_iloc()) {
967 seq_printf(m, "Way0 Locked-Down\n");
970 seq_printf(m, "Way1 Locked-Down\n");
973 seq_printf(m, "Way0,Way1 Locked-Down\n");
976 seq_printf(m, "Way2 Locked-Down\n");
979 seq_printf(m, "Way0,Way2 Locked-Down\n");
982 seq_printf(m, "Way1,Way2 Locked-Down\n");
985 seq_printf(m, "Way0,Way1 & Way2 Locked-Down\n");
988 seq_printf(m, "Way3 Locked-Down\n");
991 seq_printf(m, "Way0,Way3 Locked-Down\n");
994 seq_printf(m, "Way1,Way3 Locked-Down\n");
997 seq_printf(m, "Way 0,Way1,Way3 Locked-Down\n");
1000 seq_printf(m, "Way3,Way2 Locked-Down\n");
1003 seq_printf(m, "Way3,Way2,Way0 Locked-Down\n");
1006 seq_printf(m, "Way3,Way2,Way1 Locked-Down\n");
1009 seq_printf(m, "All Ways are locked\n");
1012 seq_printf(m, "No Ways are locked\n");
1016 seq_printf(m, "board name\t: %s\n", bfin_board_name);
1017 seq_printf(m, "board memory\t: %ld kB (0x%p -> 0x%p)\n",
1018 physical_mem_end >> 10, (void *)0, (void *)physical_mem_end);
1019 seq_printf(m, "kernel memory\t: %d kB (0x%p -> 0x%p)\n",
1020 ((int)memory_end - (int)_stext) >> 10,
1022 (void *)memory_end);
1027 static void *c_start(struct seq_file *m, loff_t *pos)
1029 return *pos < NR_CPUS ? ((void *)0x12345678) : NULL;
1032 static void *c_next(struct seq_file *m, void *v, loff_t *pos)
1035 return c_start(m, pos);
1038 static void c_stop(struct seq_file *m, void *v)
1042 const struct seq_operations cpuinfo_op = {
1046 .show = show_cpuinfo,
1049 void __init cmdline_init(const char *r0)
1052 strncpy(command_line, r0, COMMAND_LINE_SIZE);