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
);
36 unsigned long memory_start
, memory_end
, physical_mem_end
;
37 unsigned long reserved_mem_dcache_on
;
38 unsigned long reserved_mem_icache_on
;
39 EXPORT_SYMBOL(memory_start
);
40 EXPORT_SYMBOL(memory_end
);
41 EXPORT_SYMBOL(physical_mem_end
);
42 EXPORT_SYMBOL(_ramend
);
44 #ifdef CONFIG_MTD_UCLINUX
45 unsigned long memory_mtd_end
, memory_mtd_start
, mtd_size
;
47 EXPORT_SYMBOL(memory_mtd_end
);
48 EXPORT_SYMBOL(memory_mtd_start
);
49 EXPORT_SYMBOL(mtd_size
);
52 char __initdata command_line
[COMMAND_LINE_SIZE
];
54 /* boot memmap, for parsing "memmap=" */
55 #define BFIN_MEMMAP_MAX 128 /* number of entries in bfin_memmap */
56 #define BFIN_MEMMAP_RAM 1
57 #define BFIN_MEMMAP_RESERVED 2
60 struct bfin_memmap_entry
{
61 unsigned long long addr
; /* start of memory segment */
62 unsigned long long size
;
64 } map
[BFIN_MEMMAP_MAX
];
65 } bfin_memmap __initdata
;
67 /* for memmap sanitization */
68 struct change_member
{
69 struct bfin_memmap_entry
*pentry
; /* pointer to original entry */
70 unsigned long long addr
; /* address for this change point */
72 static struct change_member change_point_list
[2*BFIN_MEMMAP_MAX
] __initdata
;
73 static struct change_member
*change_point
[2*BFIN_MEMMAP_MAX
] __initdata
;
74 static struct bfin_memmap_entry
*overlap_list
[BFIN_MEMMAP_MAX
] __initdata
;
75 static struct bfin_memmap_entry new_map
[BFIN_MEMMAP_MAX
] __initdata
;
77 void __init
bf53x_cache_init(void)
79 #if defined(CONFIG_BFIN_DCACHE) || defined(CONFIG_BFIN_ICACHE)
80 generate_cpl_tables();
83 #ifdef CONFIG_BFIN_ICACHE
85 printk(KERN_INFO
"Instruction Cache Enabled\n");
88 #ifdef CONFIG_BFIN_DCACHE
90 printk(KERN_INFO
"Data Cache Enabled"
91 # if defined CONFIG_BFIN_WB
93 # elif defined CONFIG_BFIN_WT
100 void __init
bf53x_relocate_l1_mem(void)
102 unsigned long l1_code_length
;
103 unsigned long l1_data_a_length
;
104 unsigned long l1_data_b_length
;
106 l1_code_length
= _etext_l1
- _stext_l1
;
107 if (l1_code_length
> L1_CODE_LENGTH
)
108 l1_code_length
= L1_CODE_LENGTH
;
109 /* cannot complain as printk is not available as yet.
110 * But we can continue booting and complain later!
113 /* Copy _stext_l1 to _etext_l1 to L1 instruction SRAM */
114 dma_memcpy(_stext_l1
, _l1_lma_start
, l1_code_length
);
116 l1_data_a_length
= _ebss_l1
- _sdata_l1
;
117 if (l1_data_a_length
> L1_DATA_A_LENGTH
)
118 l1_data_a_length
= L1_DATA_A_LENGTH
;
120 /* Copy _sdata_l1 to _ebss_l1 to L1 data bank A SRAM */
121 dma_memcpy(_sdata_l1
, _l1_lma_start
+ l1_code_length
, l1_data_a_length
);
123 l1_data_b_length
= _ebss_b_l1
- _sdata_b_l1
;
124 if (l1_data_b_length
> L1_DATA_B_LENGTH
)
125 l1_data_b_length
= L1_DATA_B_LENGTH
;
127 /* Copy _sdata_b_l1 to _ebss_b_l1 to L1 data bank B SRAM */
128 dma_memcpy(_sdata_b_l1
, _l1_lma_start
+ l1_code_length
+
129 l1_data_a_length
, l1_data_b_length
);
133 /* add_memory_region to memmap */
134 static void __init
add_memory_region(unsigned long long start
,
135 unsigned long long size
, int type
)
139 i
= bfin_memmap
.nr_map
;
141 if (i
== BFIN_MEMMAP_MAX
) {
142 printk(KERN_ERR
"Ooops! Too many entries in the memory map!\n");
146 bfin_memmap
.map
[i
].addr
= start
;
147 bfin_memmap
.map
[i
].size
= size
;
148 bfin_memmap
.map
[i
].type
= type
;
149 bfin_memmap
.nr_map
++;
153 * Sanitize the boot memmap, removing overlaps.
155 static int __init
sanitize_memmap(struct bfin_memmap_entry
*map
, int *pnr_map
)
157 struct change_member
*change_tmp
;
158 unsigned long current_type
, last_type
;
159 unsigned long long last_addr
;
160 int chgidx
, still_changing
;
163 int old_nr
, new_nr
, chg_nr
;
167 Visually we're performing the following (1,2,3,4 = memory types)
169 Sample memory map (w/overlaps):
170 ____22__________________
171 ______________________4_
172 ____1111________________
173 _44_____________________
174 11111111________________
175 ____________________33__
176 ___________44___________
177 __________33333_________
178 ______________22________
179 ___________________2222_
180 _________111111111______
181 _____________________11_
182 _________________4______
184 Sanitized equivalent (no overlap):
185 1_______________________
186 _44_____________________
187 ___1____________________
188 ____22__________________
189 ______11________________
190 _________1______________
191 __________3_____________
192 ___________44___________
193 _____________33_________
194 _______________2________
195 ________________1_______
196 _________________4______
197 ___________________2____
198 ____________________33__
199 ______________________4_
201 /* if there's only one memory region, don't bother */
207 /* bail out if we find any unreasonable addresses in memmap */
208 for (i
= 0; i
< old_nr
; i
++)
209 if (map
[i
].addr
+ map
[i
].size
< map
[i
].addr
)
212 /* create pointers for initial change-point information (for sorting) */
213 for (i
= 0; i
< 2*old_nr
; i
++)
214 change_point
[i
] = &change_point_list
[i
];
216 /* record all known change-points (starting and ending addresses),
217 omitting those that are for empty memory regions */
219 for (i
= 0; i
< old_nr
; i
++) {
220 if (map
[i
].size
!= 0) {
221 change_point
[chgidx
]->addr
= map
[i
].addr
;
222 change_point
[chgidx
++]->pentry
= &map
[i
];
223 change_point
[chgidx
]->addr
= map
[i
].addr
+ map
[i
].size
;
224 change_point
[chgidx
++]->pentry
= &map
[i
];
227 chg_nr
= chgidx
; /* true number of change-points */
229 /* sort change-point list by memory addresses (low -> high) */
231 while (still_changing
) {
233 for (i
= 1; i
< chg_nr
; i
++) {
234 /* if <current_addr> > <last_addr>, swap */
235 /* or, if current=<start_addr> & last=<end_addr>, swap */
236 if ((change_point
[i
]->addr
< change_point
[i
-1]->addr
) ||
237 ((change_point
[i
]->addr
== change_point
[i
-1]->addr
) &&
238 (change_point
[i
]->addr
== change_point
[i
]->pentry
->addr
) &&
239 (change_point
[i
-1]->addr
!= change_point
[i
-1]->pentry
->addr
))
241 change_tmp
= change_point
[i
];
242 change_point
[i
] = change_point
[i
-1];
243 change_point
[i
-1] = change_tmp
;
249 /* create a new memmap, removing overlaps */
250 overlap_entries
= 0; /* number of entries in the overlap table */
251 new_entry
= 0; /* index for creating new memmap entries */
252 last_type
= 0; /* start with undefined memory type */
253 last_addr
= 0; /* start with 0 as last starting address */
254 /* loop through change-points, determining affect on the new memmap */
255 for (chgidx
= 0; chgidx
< chg_nr
; chgidx
++) {
256 /* keep track of all overlapping memmap entries */
257 if (change_point
[chgidx
]->addr
== change_point
[chgidx
]->pentry
->addr
) {
258 /* add map entry to overlap list (> 1 entry implies an overlap) */
259 overlap_list
[overlap_entries
++] = change_point
[chgidx
]->pentry
;
261 /* remove entry from list (order independent, so swap with last) */
262 for (i
= 0; i
< overlap_entries
; i
++) {
263 if (overlap_list
[i
] == change_point
[chgidx
]->pentry
)
264 overlap_list
[i
] = overlap_list
[overlap_entries
-1];
268 /* if there are overlapping entries, decide which "type" to use */
269 /* (larger value takes precedence -- 1=usable, 2,3,4,4+=unusable) */
271 for (i
= 0; i
< overlap_entries
; i
++)
272 if (overlap_list
[i
]->type
> current_type
)
273 current_type
= overlap_list
[i
]->type
;
274 /* continue building up new memmap based on this information */
275 if (current_type
!= last_type
) {
276 if (last_type
!= 0) {
277 new_map
[new_entry
].size
=
278 change_point
[chgidx
]->addr
- last_addr
;
279 /* move forward only if the new size was non-zero */
280 if (new_map
[new_entry
].size
!= 0)
281 if (++new_entry
>= BFIN_MEMMAP_MAX
)
282 break; /* no more space left for new entries */
284 if (current_type
!= 0) {
285 new_map
[new_entry
].addr
= change_point
[chgidx
]->addr
;
286 new_map
[new_entry
].type
= current_type
;
287 last_addr
= change_point
[chgidx
]->addr
;
289 last_type
= current_type
;
292 new_nr
= new_entry
; /* retain count for new entries */
294 /* copy new mapping into original location */
295 memcpy(map
, new_map
, new_nr
*sizeof(struct bfin_memmap_entry
));
301 static void __init
print_memory_map(char *who
)
305 for (i
= 0; i
< bfin_memmap
.nr_map
; i
++) {
306 printk(KERN_DEBUG
" %s: %016Lx - %016Lx ", who
,
307 bfin_memmap
.map
[i
].addr
,
308 bfin_memmap
.map
[i
].addr
+ bfin_memmap
.map
[i
].size
);
309 switch (bfin_memmap
.map
[i
].type
) {
310 case BFIN_MEMMAP_RAM
:
311 printk("(usable)\n");
313 case BFIN_MEMMAP_RESERVED
:
314 printk("(reserved)\n");
316 default: printk("type %lu\n", bfin_memmap
.map
[i
].type
);
322 static __init
int parse_memmap(char *arg
)
324 unsigned long long start_at
, mem_size
;
329 mem_size
= memparse(arg
, &arg
);
331 start_at
= memparse(arg
+1, &arg
);
332 add_memory_region(start_at
, mem_size
, BFIN_MEMMAP_RAM
);
333 } else if (*arg
== '$') {
334 start_at
= memparse(arg
+1, &arg
);
335 add_memory_region(start_at
, mem_size
, BFIN_MEMMAP_RESERVED
);
342 * Initial parsing of the command line. Currently, we support:
343 * - Controlling the linux memory size: mem=xxx[KMG]
344 * - Controlling the physical memory size: max_mem=xxx[KMG][$][#]
345 * $ -> reserved memory is dcacheable
346 * # -> reserved memory is icacheable
347 * - "memmap=XXX[KkmM][@][$]XXX[KkmM]" defines a memory region
348 * @ from <start> to <start>+<mem>, type RAM
349 * $ from <start> to <start>+<mem>, type RESERVED
352 static __init
void parse_cmdline_early(char *cmdline_p
)
354 char c
= ' ', *to
= cmdline_p
;
355 unsigned int memsize
;
358 if (!memcmp(to
, "mem=", 4)) {
360 memsize
= memparse(to
, &to
);
364 } else if (!memcmp(to
, "max_mem=", 8)) {
366 memsize
= memparse(to
, &to
);
368 physical_mem_end
= memsize
;
372 reserved_mem_dcache_on
=
376 reserved_mem_icache_on
=
380 } else if (!memcmp(to
, "earlyprintk=", 12)) {
382 setup_early_printk(to
);
383 } else if (!memcmp(to
, "memmap=", 7)) {
395 * Setup memory defaults from user config.
396 * The physical memory layout looks like:
398 * [_rambase, _ramstart]: kernel image
399 * [memory_start, memory_end]: dynamic memory managed by kernel
400 * [memory_end, _ramend]: reserved memory
401 * [meory_mtd_start(memory_end),
402 * memory_mtd_start + mtd_size]: rootfs (if any)
403 * [_ramend - DMA_UNCACHED_REGION,
404 * _ramend]: uncached DMA region
405 * [_ramend, physical_mem_end]: memory not managed by kernel
408 static __init
void memory_setup(void)
410 #ifdef CONFIG_MTD_UCLINUX
411 unsigned long mtd_phys
= 0;
414 _rambase
= (unsigned long)_stext
;
415 _ramstart
= (unsigned long)_end
;
417 if (DMA_UNCACHED_REGION
> (_ramend
- _ramstart
)) {
419 panic("DMA region exceeds memory limit: %lu.\n",
420 _ramend
- _ramstart
);
422 memory_end
= _ramend
- DMA_UNCACHED_REGION
;
425 /* Round up to multiple of 4MB. */
426 memory_start
= (_ramstart
+ 0x3fffff) & ~0x3fffff;
428 memory_start
= PAGE_ALIGN(_ramstart
);
431 #if defined(CONFIG_MTD_UCLINUX)
432 /* generic memory mapped MTD driver */
433 memory_mtd_end
= memory_end
;
435 mtd_phys
= _ramstart
;
436 mtd_size
= PAGE_ALIGN(*((unsigned long *)(mtd_phys
+ 8)));
438 # if defined(CONFIG_EXT2_FS) || defined(CONFIG_EXT3_FS)
439 if (*((unsigned short *)(mtd_phys
+ 0x438)) == EXT2_SUPER_MAGIC
)
441 PAGE_ALIGN(*((unsigned long *)(mtd_phys
+ 0x404)) << 10);
444 # if defined(CONFIG_CRAMFS)
445 if (*((unsigned long *)(mtd_phys
)) == CRAMFS_MAGIC
)
446 mtd_size
= PAGE_ALIGN(*((unsigned long *)(mtd_phys
+ 0x4)));
449 # if defined(CONFIG_ROMFS_FS)
450 if (((unsigned long *)mtd_phys
)[0] == ROMSB_WORD0
451 && ((unsigned long *)mtd_phys
)[1] == ROMSB_WORD1
)
453 PAGE_ALIGN(be32_to_cpu(((unsigned long *)mtd_phys
)[2]));
454 # if (defined(CONFIG_BFIN_ICACHE) && ANOMALY_05000263)
455 /* Due to a Hardware Anomaly we need to limit the size of usable
456 * instruction memory to max 60MB, 56 if HUNT_FOR_ZERO is on
457 * 05000263 - Hardware loop corrupted when taking an ICPLB exception
459 # if (defined(CONFIG_DEBUG_HUNT_FOR_ZERO))
460 if (memory_end
>= 56 * 1024 * 1024)
461 memory_end
= 56 * 1024 * 1024;
463 if (memory_end
>= 60 * 1024 * 1024)
464 memory_end
= 60 * 1024 * 1024;
465 # endif /* CONFIG_DEBUG_HUNT_FOR_ZERO */
466 # endif /* ANOMALY_05000263 */
467 # endif /* CONFIG_ROMFS_FS */
469 memory_end
-= mtd_size
;
473 panic("Don't boot kernel without rootfs attached.\n");
476 /* Relocate MTD image to the top of memory after the uncached memory area */
477 dma_memcpy((char *)memory_end
, _end
, mtd_size
);
479 memory_mtd_start
= memory_end
;
480 _ebss
= memory_mtd_start
; /* define _ebss for compatible */
481 #endif /* CONFIG_MTD_UCLINUX */
483 #if (defined(CONFIG_BFIN_ICACHE) && ANOMALY_05000263)
484 /* Due to a Hardware Anomaly we need to limit the size of usable
485 * instruction memory to max 60MB, 56 if HUNT_FOR_ZERO is on
486 * 05000263 - Hardware loop corrupted when taking an ICPLB exception
488 #if (defined(CONFIG_DEBUG_HUNT_FOR_ZERO))
489 if (memory_end
>= 56 * 1024 * 1024)
490 memory_end
= 56 * 1024 * 1024;
492 if (memory_end
>= 60 * 1024 * 1024)
493 memory_end
= 60 * 1024 * 1024;
494 #endif /* CONFIG_DEBUG_HUNT_FOR_ZERO */
495 printk(KERN_NOTICE
"Warning: limiting memory to %liMB due to hardware anomaly 05000263\n", memory_end
>> 20);
496 #endif /* ANOMALY_05000263 */
499 page_mask_nelts
= ((_ramend
>> PAGE_SHIFT
) + 31) / 32;
500 page_mask_order
= get_order(3 * page_mask_nelts
* sizeof(long));
503 #if !defined(CONFIG_MTD_UCLINUX)
504 /*In case there is no valid CPLB behind memory_end make sure we don't get to close*/
505 memory_end
-= SIZE_4K
;
508 init_mm
.start_code
= (unsigned long)_stext
;
509 init_mm
.end_code
= (unsigned long)_etext
;
510 init_mm
.end_data
= (unsigned long)_edata
;
511 init_mm
.brk
= (unsigned long)0;
513 printk(KERN_INFO
"Board Memory: %ldMB\n", physical_mem_end
>> 20);
514 printk(KERN_INFO
"Kernel Managed Memory: %ldMB\n", _ramend
>> 20);
516 printk(KERN_INFO
"Memory map:\n"
517 KERN_INFO
" text = 0x%p-0x%p\n"
518 KERN_INFO
" rodata = 0x%p-0x%p\n"
519 KERN_INFO
" bss = 0x%p-0x%p\n"
520 KERN_INFO
" data = 0x%p-0x%p\n"
521 KERN_INFO
" stack = 0x%p-0x%p\n"
522 KERN_INFO
" init = 0x%p-0x%p\n"
523 KERN_INFO
" available = 0x%p-0x%p\n"
524 #ifdef CONFIG_MTD_UCLINUX
525 KERN_INFO
" rootfs = 0x%p-0x%p\n"
527 #if DMA_UNCACHED_REGION > 0
528 KERN_INFO
" DMA Zone = 0x%p-0x%p\n"
531 __start_rodata
, __end_rodata
,
532 __bss_start
, __bss_stop
,
534 (void *)&init_thread_union
,
535 (void *)((int)(&init_thread_union
) + 0x2000),
536 __init_begin
, __init_end
,
537 (void *)_ramstart
, (void *)memory_end
538 #ifdef CONFIG_MTD_UCLINUX
539 , (void *)memory_mtd_start
, (void *)(memory_mtd_start
+ mtd_size
)
541 #if DMA_UNCACHED_REGION > 0
542 , (void *)(_ramend
- DMA_UNCACHED_REGION
), (void *)(_ramend
)
547 static __init
void setup_bootmem_allocator(void)
551 unsigned long min_pfn
, max_pfn
;
552 unsigned long curr_pfn
, last_pfn
, size
;
554 /* mark memory between memory_start and memory_end usable */
555 add_memory_region(memory_start
,
556 memory_end
- memory_start
, BFIN_MEMMAP_RAM
);
557 /* sanity check for overlap */
558 sanitize_memmap(bfin_memmap
.map
, &bfin_memmap
.nr_map
);
559 print_memory_map("boot memmap");
561 min_pfn
= PAGE_OFFSET
>> PAGE_SHIFT
;
562 max_pfn
= memory_end
>> PAGE_SHIFT
;
565 * give all the memory to the bootmap allocator, tell it to put the
566 * boot mem_map at the start of memory.
568 bootmap_size
= init_bootmem_node(NODE_DATA(0),
569 memory_start
>> PAGE_SHIFT
, /* map goes here */
572 /* register the memmap regions with the bootmem allocator */
573 for (i
= 0; i
< bfin_memmap
.nr_map
; i
++) {
575 * Reserve usable memory
577 if (bfin_memmap
.map
[i
].type
!= BFIN_MEMMAP_RAM
)
580 * We are rounding up the start address of usable memory:
582 curr_pfn
= PFN_UP(bfin_memmap
.map
[i
].addr
);
583 if (curr_pfn
>= max_pfn
)
586 * ... and at the end of the usable range downwards:
588 last_pfn
= PFN_DOWN(bfin_memmap
.map
[i
].addr
+
589 bfin_memmap
.map
[i
].size
);
591 if (last_pfn
> max_pfn
)
595 * .. finally, did all the rounding and playing
596 * around just make the area go away?
598 if (last_pfn
<= curr_pfn
)
601 size
= last_pfn
- curr_pfn
;
602 free_bootmem(PFN_PHYS(curr_pfn
), PFN_PHYS(size
));
605 /* reserve memory before memory_start, including bootmap */
606 reserve_bootmem(PAGE_OFFSET
,
607 memory_start
+ bootmap_size
+ PAGE_SIZE
- 1 - PAGE_OFFSET
,
611 void __init
setup_arch(char **cmdline_p
)
613 unsigned long l1_length
, sclk
, cclk
;
615 #ifdef CONFIG_DUMMY_CONSOLE
616 conswitchp
= &dummy_con
;
619 #if defined(CONFIG_CMDLINE_BOOL)
620 strncpy(&command_line
[0], CONFIG_CMDLINE
, sizeof(command_line
));
621 command_line
[sizeof(command_line
) - 1] = 0;
624 /* Keep a copy of command line */
625 *cmdline_p
= &command_line
[0];
626 memcpy(boot_command_line
, command_line
, COMMAND_LINE_SIZE
);
627 boot_command_line
[COMMAND_LINE_SIZE
- 1] = '\0';
629 /* setup memory defaults from the user config */
630 physical_mem_end
= 0;
631 _ramend
= CONFIG_MEM_SIZE
* 1024 * 1024;
633 memset(&bfin_memmap
, 0, sizeof(bfin_memmap
));
635 parse_cmdline_early(&command_line
[0]);
637 if (physical_mem_end
== 0)
638 physical_mem_end
= _ramend
;
645 #if !defined(CONFIG_BFIN_KERNEL_CLOCK)
646 if (ANOMALY_05000273
&& cclk
== sclk
)
647 panic("ANOMALY 05000273, SCLK can not be same as CCLK");
651 if (ANOMALY_05000266
) {
652 bfin_read_IMDMA_D0_IRQ_STATUS();
653 bfin_read_IMDMA_D1_IRQ_STATUS();
656 printk(KERN_INFO
"Hardware Trace ");
657 if (bfin_read_TBUFCTL() & 0x1)
661 if (bfin_read_TBUFCTL() & 0x2)
662 printk("and Enabled\n");
664 printk("and Disabled\n");
666 #if defined(CONFIG_CHR_DEV_FLASH) || defined(CONFIG_BLK_DEV_FLASH)
667 /* we need to initialize the Flashrom device here since we might
668 * do things with flash early on in the boot
673 _bfin_swrst
= bfin_read_SWRST();
675 if (_bfin_swrst
& RESET_DOUBLE
)
676 printk(KERN_INFO
"Recovering from Double Fault event\n");
677 else if (_bfin_swrst
& RESET_WDOG
)
678 printk(KERN_INFO
"Recovering from Watchdog event\n");
679 else if (_bfin_swrst
& RESET_SOFTWARE
)
680 printk(KERN_NOTICE
"Reset caused by Software reset\n");
682 printk(KERN_INFO
"Blackfin support (C) 2004-2008 Analog Devices, Inc.\n");
683 if (bfin_compiled_revid() == 0xffff)
684 printk(KERN_INFO
"Compiled for ADSP-%s Rev any\n", CPU
);
685 else if (bfin_compiled_revid() == -1)
686 printk(KERN_INFO
"Compiled for ADSP-%s Rev none\n", CPU
);
688 printk(KERN_INFO
"Compiled for ADSP-%s Rev 0.%d\n", CPU
, bfin_compiled_revid());
689 if (bfin_revid() != bfin_compiled_revid()) {
690 if (bfin_compiled_revid() == -1)
691 printk(KERN_ERR
"Warning: Compiled for Rev none, but running on Rev %d\n",
693 else if (bfin_compiled_revid() != 0xffff)
694 printk(KERN_ERR
"Warning: Compiled for Rev %d, but running on Rev %d\n",
695 bfin_compiled_revid(), bfin_revid());
697 if (bfin_revid() < SUPPORTED_REVID
)
698 printk(KERN_ERR
"Warning: Unsupported Chip Revision ADSP-%s Rev 0.%d detected\n",
700 printk(KERN_INFO
"Blackfin Linux support by http://blackfin.uclinux.org/\n");
702 printk(KERN_INFO
"Processor Speed: %lu MHz core clock and %lu MHz System Clock\n",
703 cclk
/ 1000000, sclk
/ 1000000);
705 if (ANOMALY_05000273
&& (cclk
>> 1) <= sclk
)
706 printk("\n\n\nANOMALY_05000273: CCLK must be >= 2*SCLK !!!\n\n\n");
708 setup_bootmem_allocator();
712 /* check the size of the l1 area */
713 l1_length
= _etext_l1
- _stext_l1
;
714 if (l1_length
> L1_CODE_LENGTH
)
715 panic("L1 code memory overflow\n");
717 l1_length
= _ebss_l1
- _sdata_l1
;
718 if (l1_length
> L1_DATA_A_LENGTH
)
719 panic("L1 data memory overflow\n");
721 /* Copy atomic sequences to their fixed location, and sanity check that
722 these locations are the ones that we advertise to userspace. */
723 memcpy((void *)FIXED_CODE_START
, &fixed_code_start
,
724 FIXED_CODE_END
- FIXED_CODE_START
);
725 BUG_ON((char *)&sigreturn_stub
- (char *)&fixed_code_start
726 != SIGRETURN_STUB
- FIXED_CODE_START
);
727 BUG_ON((char *)&atomic_xchg32
- (char *)&fixed_code_start
728 != ATOMIC_XCHG32
- FIXED_CODE_START
);
729 BUG_ON((char *)&atomic_cas32
- (char *)&fixed_code_start
730 != ATOMIC_CAS32
- FIXED_CODE_START
);
731 BUG_ON((char *)&atomic_add32
- (char *)&fixed_code_start
732 != ATOMIC_ADD32
- FIXED_CODE_START
);
733 BUG_ON((char *)&atomic_sub32
- (char *)&fixed_code_start
734 != ATOMIC_SUB32
- FIXED_CODE_START
);
735 BUG_ON((char *)&atomic_ior32
- (char *)&fixed_code_start
736 != ATOMIC_IOR32
- FIXED_CODE_START
);
737 BUG_ON((char *)&atomic_and32
- (char *)&fixed_code_start
738 != ATOMIC_AND32
- FIXED_CODE_START
);
739 BUG_ON((char *)&atomic_xor32
- (char *)&fixed_code_start
740 != ATOMIC_XOR32
- FIXED_CODE_START
);
741 BUG_ON((char *)&safe_user_instruction
- (char *)&fixed_code_start
742 != SAFE_USER_INSTRUCTION
- FIXED_CODE_START
);
744 init_exception_vectors();
748 static int __init
topology_init(void)
752 for_each_possible_cpu(cpu
) {
753 struct cpu
*c
= &per_cpu(cpu_devices
, cpu
);
755 register_cpu(c
, cpu
);
761 subsys_initcall(topology_init
);
763 static u_long
get_vco(void)
768 msel
= (bfin_read_PLL_CTL() >> 9) & 0x3F;
772 vco
= CONFIG_CLKIN_HZ
;
773 vco
>>= (1 & bfin_read_PLL_CTL()); /* DF bit */
778 /* Get the Core clock */
779 u_long
get_cclk(void)
782 if (bfin_read_PLL_STAT() & 0x1)
783 return CONFIG_CLKIN_HZ
;
785 ssel
= bfin_read_PLL_DIV();
786 csel
= ((ssel
>> 4) & 0x03);
788 if (ssel
&& ssel
< (1 << csel
)) /* SCLK > CCLK */
789 return get_vco() / ssel
;
790 return get_vco() >> csel
;
792 EXPORT_SYMBOL(get_cclk
);
794 /* Get the System clock */
795 u_long
get_sclk(void)
799 if (bfin_read_PLL_STAT() & 0x1)
800 return CONFIG_CLKIN_HZ
;
802 ssel
= (bfin_read_PLL_DIV() & 0xf);
804 printk(KERN_WARNING
"Invalid System Clock\n");
808 return get_vco() / ssel
;
810 EXPORT_SYMBOL(get_sclk
);
812 unsigned long sclk_to_usecs(unsigned long sclk
)
814 u64 tmp
= USEC_PER_SEC
* (u64
)sclk
;
815 do_div(tmp
, get_sclk());
818 EXPORT_SYMBOL(sclk_to_usecs
);
820 unsigned long usecs_to_sclk(unsigned long usecs
)
822 u64 tmp
= get_sclk() * (u64
)usecs
;
823 do_div(tmp
, USEC_PER_SEC
);
826 EXPORT_SYMBOL(usecs_to_sclk
);
829 * Get CPU information for use by the procfs.
831 static int show_cpuinfo(struct seq_file
*m
, void *v
)
833 char *cpu
, *mmu
, *fpu
, *vendor
, *cache
;
836 u_long cclk
= 0, sclk
= 0;
837 u_int dcache_size
= 0, dsup_banks
= 0;
842 revid
= bfin_revid();
847 switch (bfin_read_CHIPID() & CHIPID_MANUFACTURE
) {
849 vendor
= "Analog Devices";
856 seq_printf(m
, "processor\t: %d\n"
858 "cpu family\t: 0x%x\n"
859 "model name\t: ADSP-%s %lu(MHz CCLK) %lu(MHz SCLK)\n"
863 (bfin_read_CHIPID() & CHIPID_FAMILY
),
864 cpu
, cclk
/1000000, sclk
/1000000,
867 seq_printf(m
, "cpu MHz\t\t: %lu.%03lu/%lu.%03lu\n",
868 cclk
/1000000, cclk
%1000000,
869 sclk
/1000000, sclk
%1000000);
870 seq_printf(m
, "bogomips\t: %lu.%02lu\n"
871 "Calibration\t: %lu loops\n",
872 (loops_per_jiffy
* HZ
) / 500000,
873 ((loops_per_jiffy
* HZ
) / 5000) % 100,
874 (loops_per_jiffy
* HZ
));
876 /* Check Cache configutation */
877 switch (bfin_read_DMEM_CONTROL() & (1 << DMC0_P
| 1 << DMC1_P
)) {
879 cache
= "dbank-A/B\t: cache/sram";
884 cache
= "dbank-A/B\t: cache/cache";
889 cache
= "dbank-A/B\t: sram/sram";
900 /* Is it turned on? */
901 if (!((bfin_read_DMEM_CONTROL()) & (ENDCPLB
| DMC_ENABLE
)))
904 seq_printf(m
, "cache size\t: %d KB(L1 icache) "
905 "%d KB(L1 dcache-%s) %d KB(L2 cache)\n",
906 BFIN_ICACHESIZE
/ 1024, dcache_size
,
907 #if defined CONFIG_BFIN_WB
909 #elif defined CONFIG_BFIN_WT
914 seq_printf(m
, "%s\n", cache
);
916 seq_printf(m
, "icache setup\t: %d Sub-banks/%d Ways, %d Lines/Way\n",
917 BFIN_ISUBBANKS
, BFIN_IWAYS
, BFIN_ILINES
);
919 "dcache setup\t: %d Super-banks/%d Sub-banks/%d Ways, %d Lines/Way\n",
920 dsup_banks
, BFIN_DSUBBANKS
, BFIN_DWAYS
,
922 #ifdef CONFIG_BFIN_ICACHE_LOCK
923 switch (read_iloc()) {
925 seq_printf(m
, "Way0 Locked-Down\n");
928 seq_printf(m
, "Way1 Locked-Down\n");
931 seq_printf(m
, "Way0,Way1 Locked-Down\n");
934 seq_printf(m
, "Way2 Locked-Down\n");
937 seq_printf(m
, "Way0,Way2 Locked-Down\n");
940 seq_printf(m
, "Way1,Way2 Locked-Down\n");
943 seq_printf(m
, "Way0,Way1 & Way2 Locked-Down\n");
946 seq_printf(m
, "Way3 Locked-Down\n");
949 seq_printf(m
, "Way0,Way3 Locked-Down\n");
952 seq_printf(m
, "Way1,Way3 Locked-Down\n");
955 seq_printf(m
, "Way 0,Way1,Way3 Locked-Down\n");
958 seq_printf(m
, "Way3,Way2 Locked-Down\n");
961 seq_printf(m
, "Way3,Way2,Way0 Locked-Down\n");
964 seq_printf(m
, "Way3,Way2,Way1 Locked-Down\n");
967 seq_printf(m
, "All Ways are locked\n");
970 seq_printf(m
, "No Ways are locked\n");
974 seq_printf(m
, "board name\t: %s\n", bfin_board_name
);
975 seq_printf(m
, "board memory\t: %ld kB (0x%p -> 0x%p)\n",
976 physical_mem_end
>> 10, (void *)0, (void *)physical_mem_end
);
977 seq_printf(m
, "kernel memory\t: %d kB (0x%p -> 0x%p)\n",
978 ((int)memory_end
- (int)_stext
) >> 10,
985 static void *c_start(struct seq_file
*m
, loff_t
*pos
)
987 return *pos
< NR_CPUS
? ((void *)0x12345678) : NULL
;
990 static void *c_next(struct seq_file
*m
, void *v
, loff_t
*pos
)
993 return c_start(m
, pos
);
996 static void c_stop(struct seq_file
*m
, void *v
)
1000 const struct seq_operations cpuinfo_op
= {
1004 .show
= show_cpuinfo
,
1007 void __init
cmdline_init(const char *r0
)
1010 strncpy(command_line
, r0
, COMMAND_LINE_SIZE
);