2 * arch/blackfin/kernel/setup.c
4 * Copyright 2004-2006 Analog Devices Inc.
6 * Enter bugs at http://blackfin.uclinux.org/
8 * Licensed under the GPL-2 or later.
11 #include <linux/delay.h>
12 #include <linux/console.h>
13 #include <linux/bootmem.h>
14 #include <linux/seq_file.h>
15 #include <linux/cpu.h>
16 #include <linux/module.h>
17 #include <linux/tty.h>
18 #include <linux/pfn.h>
20 #include <linux/ext2_fs.h>
21 #include <linux/cramfs_fs.h>
22 #include <linux/romfs_fs.h>
25 #include <asm/cacheflush.h>
26 #include <asm/blackfin.h>
27 #include <asm/cplbinit.h>
28 #include <asm/div64.h>
29 #include <asm/fixed_code.h>
30 #include <asm/early_printk.h>
32 static DEFINE_PER_CPU(struct cpu
, cpu_devices
);
35 EXPORT_SYMBOL(_bfin_swrst
);
37 unsigned long memory_start
, memory_end
, physical_mem_end
;
38 unsigned long _rambase
, _ramstart
, _ramend
;
39 unsigned long reserved_mem_dcache_on
;
40 unsigned long reserved_mem_icache_on
;
41 EXPORT_SYMBOL(memory_start
);
42 EXPORT_SYMBOL(memory_end
);
43 EXPORT_SYMBOL(physical_mem_end
);
44 EXPORT_SYMBOL(_ramend
);
46 #ifdef CONFIG_MTD_UCLINUX
47 unsigned long memory_mtd_end
, memory_mtd_start
, mtd_size
;
49 EXPORT_SYMBOL(memory_mtd_end
);
50 EXPORT_SYMBOL(memory_mtd_start
);
51 EXPORT_SYMBOL(mtd_size
);
54 char __initdata command_line
[COMMAND_LINE_SIZE
];
55 unsigned int __initdata
*__retx
;
57 /* boot memmap, for parsing "memmap=" */
58 #define BFIN_MEMMAP_MAX 128 /* number of entries in bfin_memmap */
59 #define BFIN_MEMMAP_RAM 1
60 #define BFIN_MEMMAP_RESERVED 2
63 struct bfin_memmap_entry
{
64 unsigned long long addr
; /* start of memory segment */
65 unsigned long long size
;
67 } map
[BFIN_MEMMAP_MAX
];
68 } bfin_memmap __initdata
;
70 /* for memmap sanitization */
71 struct change_member
{
72 struct bfin_memmap_entry
*pentry
; /* pointer to original entry */
73 unsigned long long addr
; /* address for this change point */
75 static struct change_member change_point_list
[2*BFIN_MEMMAP_MAX
] __initdata
;
76 static struct change_member
*change_point
[2*BFIN_MEMMAP_MAX
] __initdata
;
77 static struct bfin_memmap_entry
*overlap_list
[BFIN_MEMMAP_MAX
] __initdata
;
78 static struct bfin_memmap_entry new_map
[BFIN_MEMMAP_MAX
] __initdata
;
80 void __init
bf53x_cache_init(void)
82 #if defined(CONFIG_BFIN_DCACHE) || defined(CONFIG_BFIN_ICACHE)
83 generate_cpl_tables();
86 #ifdef CONFIG_BFIN_ICACHE
88 printk(KERN_INFO
"Instruction Cache Enabled\n");
91 #ifdef CONFIG_BFIN_DCACHE
93 printk(KERN_INFO
"Data Cache Enabled"
94 # if defined CONFIG_BFIN_WB
96 # elif defined CONFIG_BFIN_WT
103 void __init
bf53x_relocate_l1_mem(void)
105 unsigned long l1_code_length
;
106 unsigned long l1_data_a_length
;
107 unsigned long l1_data_b_length
;
108 unsigned long l2_length
;
110 l1_code_length
= _etext_l1
- _stext_l1
;
111 if (l1_code_length
> L1_CODE_LENGTH
)
112 panic("L1 Instruction SRAM Overflow\n");
113 /* cannot complain as printk is not available as yet.
114 * But we can continue booting and complain later!
117 /* Copy _stext_l1 to _etext_l1 to L1 instruction SRAM */
118 dma_memcpy(_stext_l1
, _l1_lma_start
, l1_code_length
);
120 l1_data_a_length
= _ebss_l1
- _sdata_l1
;
121 if (l1_data_a_length
> L1_DATA_A_LENGTH
)
122 panic("L1 Data SRAM Bank A Overflow\n");
124 /* Copy _sdata_l1 to _ebss_l1 to L1 data bank A SRAM */
125 dma_memcpy(_sdata_l1
, _l1_lma_start
+ l1_code_length
, l1_data_a_length
);
127 l1_data_b_length
= _ebss_b_l1
- _sdata_b_l1
;
128 if (l1_data_b_length
> L1_DATA_B_LENGTH
)
129 panic("L1 Data SRAM Bank B Overflow\n");
131 /* Copy _sdata_b_l1 to _ebss_b_l1 to L1 data bank B SRAM */
132 dma_memcpy(_sdata_b_l1
, _l1_lma_start
+ l1_code_length
+
133 l1_data_a_length
, l1_data_b_length
);
135 if (L2_LENGTH
!= 0) {
136 l2_length
= _ebss_l2
- _stext_l2
;
137 if (l2_length
> L2_LENGTH
)
138 panic("L2 SRAM Overflow\n");
140 /* Copy _stext_l2 to _edata_l2 to L2 SRAM */
141 dma_memcpy(_stext_l2
, _l2_lma_start
, l2_length
);
145 /* add_memory_region to memmap */
146 static void __init
add_memory_region(unsigned long long start
,
147 unsigned long long size
, int type
)
151 i
= bfin_memmap
.nr_map
;
153 if (i
== BFIN_MEMMAP_MAX
) {
154 printk(KERN_ERR
"Ooops! Too many entries in the memory map!\n");
158 bfin_memmap
.map
[i
].addr
= start
;
159 bfin_memmap
.map
[i
].size
= size
;
160 bfin_memmap
.map
[i
].type
= type
;
161 bfin_memmap
.nr_map
++;
165 * Sanitize the boot memmap, removing overlaps.
167 static int __init
sanitize_memmap(struct bfin_memmap_entry
*map
, int *pnr_map
)
169 struct change_member
*change_tmp
;
170 unsigned long current_type
, last_type
;
171 unsigned long long last_addr
;
172 int chgidx
, still_changing
;
175 int old_nr
, new_nr
, chg_nr
;
179 Visually we're performing the following (1,2,3,4 = memory types)
181 Sample memory map (w/overlaps):
182 ____22__________________
183 ______________________4_
184 ____1111________________
185 _44_____________________
186 11111111________________
187 ____________________33__
188 ___________44___________
189 __________33333_________
190 ______________22________
191 ___________________2222_
192 _________111111111______
193 _____________________11_
194 _________________4______
196 Sanitized equivalent (no overlap):
197 1_______________________
198 _44_____________________
199 ___1____________________
200 ____22__________________
201 ______11________________
202 _________1______________
203 __________3_____________
204 ___________44___________
205 _____________33_________
206 _______________2________
207 ________________1_______
208 _________________4______
209 ___________________2____
210 ____________________33__
211 ______________________4_
213 /* if there's only one memory region, don't bother */
219 /* bail out if we find any unreasonable addresses in memmap */
220 for (i
= 0; i
< old_nr
; i
++)
221 if (map
[i
].addr
+ map
[i
].size
< map
[i
].addr
)
224 /* create pointers for initial change-point information (for sorting) */
225 for (i
= 0; i
< 2*old_nr
; i
++)
226 change_point
[i
] = &change_point_list
[i
];
228 /* record all known change-points (starting and ending addresses),
229 omitting those that are for empty memory regions */
231 for (i
= 0; i
< old_nr
; i
++) {
232 if (map
[i
].size
!= 0) {
233 change_point
[chgidx
]->addr
= map
[i
].addr
;
234 change_point
[chgidx
++]->pentry
= &map
[i
];
235 change_point
[chgidx
]->addr
= map
[i
].addr
+ map
[i
].size
;
236 change_point
[chgidx
++]->pentry
= &map
[i
];
239 chg_nr
= chgidx
; /* true number of change-points */
241 /* sort change-point list by memory addresses (low -> high) */
243 while (still_changing
) {
245 for (i
= 1; i
< chg_nr
; i
++) {
246 /* if <current_addr> > <last_addr>, swap */
247 /* or, if current=<start_addr> & last=<end_addr>, swap */
248 if ((change_point
[i
]->addr
< change_point
[i
-1]->addr
) ||
249 ((change_point
[i
]->addr
== change_point
[i
-1]->addr
) &&
250 (change_point
[i
]->addr
== change_point
[i
]->pentry
->addr
) &&
251 (change_point
[i
-1]->addr
!= change_point
[i
-1]->pentry
->addr
))
253 change_tmp
= change_point
[i
];
254 change_point
[i
] = change_point
[i
-1];
255 change_point
[i
-1] = change_tmp
;
261 /* create a new memmap, removing overlaps */
262 overlap_entries
= 0; /* number of entries in the overlap table */
263 new_entry
= 0; /* index for creating new memmap entries */
264 last_type
= 0; /* start with undefined memory type */
265 last_addr
= 0; /* start with 0 as last starting address */
266 /* loop through change-points, determining affect on the new memmap */
267 for (chgidx
= 0; chgidx
< chg_nr
; chgidx
++) {
268 /* keep track of all overlapping memmap entries */
269 if (change_point
[chgidx
]->addr
== change_point
[chgidx
]->pentry
->addr
) {
270 /* add map entry to overlap list (> 1 entry implies an overlap) */
271 overlap_list
[overlap_entries
++] = change_point
[chgidx
]->pentry
;
273 /* remove entry from list (order independent, so swap with last) */
274 for (i
= 0; i
< overlap_entries
; i
++) {
275 if (overlap_list
[i
] == change_point
[chgidx
]->pentry
)
276 overlap_list
[i
] = overlap_list
[overlap_entries
-1];
280 /* if there are overlapping entries, decide which "type" to use */
281 /* (larger value takes precedence -- 1=usable, 2,3,4,4+=unusable) */
283 for (i
= 0; i
< overlap_entries
; i
++)
284 if (overlap_list
[i
]->type
> current_type
)
285 current_type
= overlap_list
[i
]->type
;
286 /* continue building up new memmap based on this information */
287 if (current_type
!= last_type
) {
288 if (last_type
!= 0) {
289 new_map
[new_entry
].size
=
290 change_point
[chgidx
]->addr
- last_addr
;
291 /* move forward only if the new size was non-zero */
292 if (new_map
[new_entry
].size
!= 0)
293 if (++new_entry
>= BFIN_MEMMAP_MAX
)
294 break; /* no more space left for new entries */
296 if (current_type
!= 0) {
297 new_map
[new_entry
].addr
= change_point
[chgidx
]->addr
;
298 new_map
[new_entry
].type
= current_type
;
299 last_addr
= change_point
[chgidx
]->addr
;
301 last_type
= current_type
;
304 new_nr
= new_entry
; /* retain count for new entries */
306 /* copy new mapping into original location */
307 memcpy(map
, new_map
, new_nr
*sizeof(struct bfin_memmap_entry
));
313 static void __init
print_memory_map(char *who
)
317 for (i
= 0; i
< bfin_memmap
.nr_map
; i
++) {
318 printk(KERN_DEBUG
" %s: %016Lx - %016Lx ", who
,
319 bfin_memmap
.map
[i
].addr
,
320 bfin_memmap
.map
[i
].addr
+ bfin_memmap
.map
[i
].size
);
321 switch (bfin_memmap
.map
[i
].type
) {
322 case BFIN_MEMMAP_RAM
:
323 printk("(usable)\n");
325 case BFIN_MEMMAP_RESERVED
:
326 printk("(reserved)\n");
328 default: printk("type %lu\n", bfin_memmap
.map
[i
].type
);
334 static __init
int parse_memmap(char *arg
)
336 unsigned long long start_at
, mem_size
;
341 mem_size
= memparse(arg
, &arg
);
343 start_at
= memparse(arg
+1, &arg
);
344 add_memory_region(start_at
, mem_size
, BFIN_MEMMAP_RAM
);
345 } else if (*arg
== '$') {
346 start_at
= memparse(arg
+1, &arg
);
347 add_memory_region(start_at
, mem_size
, BFIN_MEMMAP_RESERVED
);
354 * Initial parsing of the command line. Currently, we support:
355 * - Controlling the linux memory size: mem=xxx[KMG]
356 * - Controlling the physical memory size: max_mem=xxx[KMG][$][#]
357 * $ -> reserved memory is dcacheable
358 * # -> reserved memory is icacheable
359 * - "memmap=XXX[KkmM][@][$]XXX[KkmM]" defines a memory region
360 * @ from <start> to <start>+<mem>, type RAM
361 * $ from <start> to <start>+<mem>, type RESERVED
364 static __init
void parse_cmdline_early(char *cmdline_p
)
366 char c
= ' ', *to
= cmdline_p
;
367 unsigned int memsize
;
370 if (!memcmp(to
, "mem=", 4)) {
372 memsize
= memparse(to
, &to
);
376 } else if (!memcmp(to
, "max_mem=", 8)) {
378 memsize
= memparse(to
, &to
);
380 physical_mem_end
= memsize
;
384 reserved_mem_dcache_on
=
388 reserved_mem_icache_on
=
392 } else if (!memcmp(to
, "earlyprintk=", 12)) {
394 setup_early_printk(to
);
395 } else if (!memcmp(to
, "memmap=", 7)) {
407 * Setup memory defaults from user config.
408 * The physical memory layout looks like:
410 * [_rambase, _ramstart]: kernel image
411 * [memory_start, memory_end]: dynamic memory managed by kernel
412 * [memory_end, _ramend]: reserved memory
413 * [meory_mtd_start(memory_end),
414 * memory_mtd_start + mtd_size]: rootfs (if any)
415 * [_ramend - DMA_UNCACHED_REGION,
416 * _ramend]: uncached DMA region
417 * [_ramend, physical_mem_end]: memory not managed by kernel
420 static __init
void memory_setup(void)
422 #ifdef CONFIG_MTD_UCLINUX
423 unsigned long mtd_phys
= 0;
426 _rambase
= (unsigned long)_stext
;
427 _ramstart
= (unsigned long)_end
;
429 if (DMA_UNCACHED_REGION
> (_ramend
- _ramstart
)) {
431 panic("DMA region exceeds memory limit: %lu.\n",
432 _ramend
- _ramstart
);
434 memory_end
= _ramend
- DMA_UNCACHED_REGION
;
437 /* Round up to multiple of 4MB. */
438 memory_start
= (_ramstart
+ 0x3fffff) & ~0x3fffff;
440 memory_start
= PAGE_ALIGN(_ramstart
);
443 #if defined(CONFIG_MTD_UCLINUX)
444 /* generic memory mapped MTD driver */
445 memory_mtd_end
= memory_end
;
447 mtd_phys
= _ramstart
;
448 mtd_size
= PAGE_ALIGN(*((unsigned long *)(mtd_phys
+ 8)));
450 # if defined(CONFIG_EXT2_FS) || defined(CONFIG_EXT3_FS)
451 if (*((unsigned short *)(mtd_phys
+ 0x438)) == EXT2_SUPER_MAGIC
)
453 PAGE_ALIGN(*((unsigned long *)(mtd_phys
+ 0x404)) << 10);
456 # if defined(CONFIG_CRAMFS)
457 if (*((unsigned long *)(mtd_phys
)) == CRAMFS_MAGIC
)
458 mtd_size
= PAGE_ALIGN(*((unsigned long *)(mtd_phys
+ 0x4)));
461 # if defined(CONFIG_ROMFS_FS)
462 if (((unsigned long *)mtd_phys
)[0] == ROMSB_WORD0
463 && ((unsigned long *)mtd_phys
)[1] == ROMSB_WORD1
)
465 PAGE_ALIGN(be32_to_cpu(((unsigned long *)mtd_phys
)[2]));
466 # if (defined(CONFIG_BFIN_ICACHE) && ANOMALY_05000263)
467 /* Due to a Hardware Anomaly we need to limit the size of usable
468 * instruction memory to max 60MB, 56 if HUNT_FOR_ZERO is on
469 * 05000263 - Hardware loop corrupted when taking an ICPLB exception
471 # if (defined(CONFIG_DEBUG_HUNT_FOR_ZERO))
472 if (memory_end
>= 56 * 1024 * 1024)
473 memory_end
= 56 * 1024 * 1024;
475 if (memory_end
>= 60 * 1024 * 1024)
476 memory_end
= 60 * 1024 * 1024;
477 # endif /* CONFIG_DEBUG_HUNT_FOR_ZERO */
478 # endif /* ANOMALY_05000263 */
479 # endif /* CONFIG_ROMFS_FS */
481 memory_end
-= mtd_size
;
485 panic("Don't boot kernel without rootfs attached.\n");
488 /* Relocate MTD image to the top of memory after the uncached memory area */
489 dma_memcpy((char *)memory_end
, _end
, mtd_size
);
491 memory_mtd_start
= memory_end
;
492 _ebss
= memory_mtd_start
; /* define _ebss for compatible */
493 #endif /* CONFIG_MTD_UCLINUX */
495 #if (defined(CONFIG_BFIN_ICACHE) && ANOMALY_05000263)
496 /* Due to a Hardware Anomaly we need to limit the size of usable
497 * instruction memory to max 60MB, 56 if HUNT_FOR_ZERO is on
498 * 05000263 - Hardware loop corrupted when taking an ICPLB exception
500 #if (defined(CONFIG_DEBUG_HUNT_FOR_ZERO))
501 if (memory_end
>= 56 * 1024 * 1024)
502 memory_end
= 56 * 1024 * 1024;
504 if (memory_end
>= 60 * 1024 * 1024)
505 memory_end
= 60 * 1024 * 1024;
506 #endif /* CONFIG_DEBUG_HUNT_FOR_ZERO */
507 printk(KERN_NOTICE
"Warning: limiting memory to %liMB due to hardware anomaly 05000263\n", memory_end
>> 20);
508 #endif /* ANOMALY_05000263 */
511 page_mask_nelts
= ((_ramend
>> PAGE_SHIFT
) + 31) / 32;
512 page_mask_order
= get_order(3 * page_mask_nelts
* sizeof(long));
515 #if !defined(CONFIG_MTD_UCLINUX)
516 /*In case there is no valid CPLB behind memory_end make sure we don't get to close*/
517 memory_end
-= SIZE_4K
;
520 init_mm
.start_code
= (unsigned long)_stext
;
521 init_mm
.end_code
= (unsigned long)_etext
;
522 init_mm
.end_data
= (unsigned long)_edata
;
523 init_mm
.brk
= (unsigned long)0;
525 printk(KERN_INFO
"Board Memory: %ldMB\n", physical_mem_end
>> 20);
526 printk(KERN_INFO
"Kernel Managed Memory: %ldMB\n", _ramend
>> 20);
528 printk(KERN_INFO
"Memory map:\n"
529 KERN_INFO
" fixedcode = 0x%p-0x%p\n"
530 KERN_INFO
" text = 0x%p-0x%p\n"
531 KERN_INFO
" rodata = 0x%p-0x%p\n"
532 KERN_INFO
" bss = 0x%p-0x%p\n"
533 KERN_INFO
" data = 0x%p-0x%p\n"
534 KERN_INFO
" stack = 0x%p-0x%p\n"
535 KERN_INFO
" init = 0x%p-0x%p\n"
536 KERN_INFO
" available = 0x%p-0x%p\n"
537 #ifdef CONFIG_MTD_UCLINUX
538 KERN_INFO
" rootfs = 0x%p-0x%p\n"
540 #if DMA_UNCACHED_REGION > 0
541 KERN_INFO
" DMA Zone = 0x%p-0x%p\n"
543 , (void *)FIXED_CODE_START
, (void *)FIXED_CODE_END
,
545 __start_rodata
, __end_rodata
,
546 __bss_start
, __bss_stop
,
548 (void *)&init_thread_union
,
549 (void *)((int)(&init_thread_union
) + 0x2000),
550 __init_begin
, __init_end
,
551 (void *)_ramstart
, (void *)memory_end
552 #ifdef CONFIG_MTD_UCLINUX
553 , (void *)memory_mtd_start
, (void *)(memory_mtd_start
+ mtd_size
)
555 #if DMA_UNCACHED_REGION > 0
556 , (void *)(_ramend
- DMA_UNCACHED_REGION
), (void *)(_ramend
)
562 * Find the lowest, highest page frame number we have available
564 void __init
find_min_max_pfn(void)
569 min_low_pfn
= memory_end
;
571 for (i
= 0; i
< bfin_memmap
.nr_map
; i
++) {
572 unsigned long start
, end
;
574 if (bfin_memmap
.map
[i
].type
!= BFIN_MEMMAP_RAM
)
576 start
= PFN_UP(bfin_memmap
.map
[i
].addr
);
577 end
= PFN_DOWN(bfin_memmap
.map
[i
].addr
+
578 bfin_memmap
.map
[i
].size
);
583 if (start
< min_low_pfn
)
588 static __init
void setup_bootmem_allocator(void)
592 unsigned long start_pfn
, end_pfn
;
593 unsigned long curr_pfn
, last_pfn
, size
;
595 /* mark memory between memory_start and memory_end usable */
596 add_memory_region(memory_start
,
597 memory_end
- memory_start
, BFIN_MEMMAP_RAM
);
598 /* sanity check for overlap */
599 sanitize_memmap(bfin_memmap
.map
, &bfin_memmap
.nr_map
);
600 print_memory_map("boot memmap");
602 /* intialize globals in linux/bootmem.h */
604 /* pfn of the last usable page frame */
605 if (max_pfn
> memory_end
>> PAGE_SHIFT
)
606 max_pfn
= memory_end
>> PAGE_SHIFT
;
607 /* pfn of last page frame directly mapped by kernel */
608 max_low_pfn
= max_pfn
;
609 /* pfn of the first usable page frame after kernel image*/
610 if (min_low_pfn
< memory_start
>> PAGE_SHIFT
)
611 min_low_pfn
= memory_start
>> PAGE_SHIFT
;
613 start_pfn
= PAGE_OFFSET
>> PAGE_SHIFT
;
614 end_pfn
= memory_end
>> PAGE_SHIFT
;
617 * give all the memory to the bootmap allocator, tell it to put the
618 * boot mem_map at the start of memory.
620 bootmap_size
= init_bootmem_node(NODE_DATA(0),
621 memory_start
>> PAGE_SHIFT
, /* map goes here */
624 /* register the memmap regions with the bootmem allocator */
625 for (i
= 0; i
< bfin_memmap
.nr_map
; i
++) {
627 * Reserve usable memory
629 if (bfin_memmap
.map
[i
].type
!= BFIN_MEMMAP_RAM
)
632 * We are rounding up the start address of usable memory:
634 curr_pfn
= PFN_UP(bfin_memmap
.map
[i
].addr
);
635 if (curr_pfn
>= end_pfn
)
638 * ... and at the end of the usable range downwards:
640 last_pfn
= PFN_DOWN(bfin_memmap
.map
[i
].addr
+
641 bfin_memmap
.map
[i
].size
);
643 if (last_pfn
> end_pfn
)
647 * .. finally, did all the rounding and playing
648 * around just make the area go away?
650 if (last_pfn
<= curr_pfn
)
653 size
= last_pfn
- curr_pfn
;
654 free_bootmem(PFN_PHYS(curr_pfn
), PFN_PHYS(size
));
657 /* reserve memory before memory_start, including bootmap */
658 reserve_bootmem(PAGE_OFFSET
,
659 memory_start
+ bootmap_size
+ PAGE_SIZE
- 1 - PAGE_OFFSET
,
663 #define EBSZ_TO_MEG(ebsz) \
666 switch (ebsz & 0xf) { \
667 case 0x1: meg = 16; break; \
668 case 0x3: meg = 32; break; \
669 case 0x5: meg = 64; break; \
670 case 0x7: meg = 128; break; \
671 case 0x9: meg = 256; break; \
672 case 0xb: meg = 512; break; \
676 static inline int __init
get_mem_size(void)
678 #if defined(EBIU_SDBCTL)
679 # if defined(BF561_FAMILY)
681 u32 sdbctl
= bfin_read_EBIU_SDBCTL();
682 ret
+= EBSZ_TO_MEG(sdbctl
>> 0);
683 ret
+= EBSZ_TO_MEG(sdbctl
>> 8);
684 ret
+= EBSZ_TO_MEG(sdbctl
>> 16);
685 ret
+= EBSZ_TO_MEG(sdbctl
>> 24);
688 return EBSZ_TO_MEG(bfin_read_EBIU_SDBCTL());
690 #elif defined(EBIU_DDRCTL1)
691 u32 ddrctl
= bfin_read_EBIU_DDRCTL1();
693 switch (ddrctl
& 0xc0000) {
694 case DEVSZ_64
: ret
= 64 / 8;
695 case DEVSZ_128
: ret
= 128 / 8;
696 case DEVSZ_256
: ret
= 256 / 8;
697 case DEVSZ_512
: ret
= 512 / 8;
699 switch (ddrctl
& 0x30000) {
700 case DEVWD_4
: ret
*= 2;
701 case DEVWD_8
: ret
*= 2;
702 case DEVWD_16
: break;
704 if ((ddrctl
& 0xc000) == 0x4000)
711 void __init
setup_arch(char **cmdline_p
)
713 unsigned long sclk
, cclk
;
715 #ifdef CONFIG_DUMMY_CONSOLE
716 conswitchp
= &dummy_con
;
719 #if defined(CONFIG_CMDLINE_BOOL)
720 strncpy(&command_line
[0], CONFIG_CMDLINE
, sizeof(command_line
));
721 command_line
[sizeof(command_line
) - 1] = 0;
724 /* Keep a copy of command line */
725 *cmdline_p
= &command_line
[0];
726 memcpy(boot_command_line
, command_line
, COMMAND_LINE_SIZE
);
727 boot_command_line
[COMMAND_LINE_SIZE
- 1] = '\0';
729 /* setup memory defaults from the user config */
730 physical_mem_end
= 0;
731 _ramend
= get_mem_size() * 1024 * 1024;
733 memset(&bfin_memmap
, 0, sizeof(bfin_memmap
));
735 parse_cmdline_early(&command_line
[0]);
737 if (physical_mem_end
== 0)
738 physical_mem_end
= _ramend
;
742 /* Initialize Async memory banks */
743 bfin_write_EBIU_AMBCTL0(AMBCTL0VAL
);
744 bfin_write_EBIU_AMBCTL1(AMBCTL1VAL
);
745 bfin_write_EBIU_AMGCTL(AMGCTLVAL
);
746 #ifdef CONFIG_EBIU_MBSCTLVAL
747 bfin_write_EBIU_MBSCTL(CONFIG_EBIU_MBSCTLVAL
);
748 bfin_write_EBIU_MODE(CONFIG_EBIU_MODEVAL
);
749 bfin_write_EBIU_FCTL(CONFIG_EBIU_FCTLVAL
);
755 #if !defined(CONFIG_BFIN_KERNEL_CLOCK)
756 if (ANOMALY_05000273
&& cclk
== sclk
)
757 panic("ANOMALY 05000273, SCLK can not be same as CCLK");
761 if (ANOMALY_05000266
) {
762 bfin_read_IMDMA_D0_IRQ_STATUS();
763 bfin_read_IMDMA_D1_IRQ_STATUS();
766 printk(KERN_INFO
"Hardware Trace ");
767 if (bfin_read_TBUFCTL() & 0x1)
771 if (bfin_read_TBUFCTL() & 0x2)
772 printk("and Enabled\n");
774 printk("and Disabled\n");
776 #if defined(CONFIG_CHR_DEV_FLASH) || defined(CONFIG_BLK_DEV_FLASH)
777 /* we need to initialize the Flashrom device here since we might
778 * do things with flash early on in the boot
783 _bfin_swrst
= bfin_read_SWRST();
785 /* If we double fault, reset the system - otherwise we hang forever */
786 bfin_write_SWRST(DOUBLE_FAULT
);
788 if (_bfin_swrst
& RESET_DOUBLE
)
790 * don't decode the address, since you don't know if this
791 * kernel's symbol map is the same as the crashing kernel
793 printk(KERN_INFO
"Recovering from Double Fault event at %pF\n", __retx
);
794 else if (_bfin_swrst
& RESET_WDOG
)
795 printk(KERN_INFO
"Recovering from Watchdog event\n");
796 else if (_bfin_swrst
& RESET_SOFTWARE
)
797 printk(KERN_NOTICE
"Reset caused by Software reset\n");
799 printk(KERN_INFO
"Blackfin support (C) 2004-2008 Analog Devices, Inc.\n");
800 if (bfin_compiled_revid() == 0xffff)
801 printk(KERN_INFO
"Compiled for ADSP-%s Rev any\n", CPU
);
802 else if (bfin_compiled_revid() == -1)
803 printk(KERN_INFO
"Compiled for ADSP-%s Rev none\n", CPU
);
805 printk(KERN_INFO
"Compiled for ADSP-%s Rev 0.%d\n", CPU
, bfin_compiled_revid());
806 if (bfin_revid() != bfin_compiled_revid()) {
807 if (bfin_compiled_revid() == -1)
808 printk(KERN_ERR
"Warning: Compiled for Rev none, but running on Rev %d\n",
810 else if (bfin_compiled_revid() != 0xffff)
811 printk(KERN_ERR
"Warning: Compiled for Rev %d, but running on Rev %d\n",
812 bfin_compiled_revid(), bfin_revid());
814 if (bfin_revid() < SUPPORTED_REVID
)
815 printk(KERN_ERR
"Warning: Unsupported Chip Revision ADSP-%s Rev 0.%d detected\n",
817 printk(KERN_INFO
"Blackfin Linux support by http://blackfin.uclinux.org/\n");
819 printk(KERN_INFO
"Processor Speed: %lu MHz core clock and %lu MHz System Clock\n",
820 cclk
/ 1000000, sclk
/ 1000000);
822 if (ANOMALY_05000273
&& (cclk
>> 1) <= sclk
)
823 printk("\n\n\nANOMALY_05000273: CCLK must be >= 2*SCLK !!!\n\n\n");
825 setup_bootmem_allocator();
829 /* Copy atomic sequences to their fixed location, and sanity check that
830 these locations are the ones that we advertise to userspace. */
831 memcpy((void *)FIXED_CODE_START
, &fixed_code_start
,
832 FIXED_CODE_END
- FIXED_CODE_START
);
833 BUG_ON((char *)&sigreturn_stub
- (char *)&fixed_code_start
834 != SIGRETURN_STUB
- FIXED_CODE_START
);
835 BUG_ON((char *)&atomic_xchg32
- (char *)&fixed_code_start
836 != ATOMIC_XCHG32
- FIXED_CODE_START
);
837 BUG_ON((char *)&atomic_cas32
- (char *)&fixed_code_start
838 != ATOMIC_CAS32
- FIXED_CODE_START
);
839 BUG_ON((char *)&atomic_add32
- (char *)&fixed_code_start
840 != ATOMIC_ADD32
- FIXED_CODE_START
);
841 BUG_ON((char *)&atomic_sub32
- (char *)&fixed_code_start
842 != ATOMIC_SUB32
- FIXED_CODE_START
);
843 BUG_ON((char *)&atomic_ior32
- (char *)&fixed_code_start
844 != ATOMIC_IOR32
- FIXED_CODE_START
);
845 BUG_ON((char *)&atomic_and32
- (char *)&fixed_code_start
846 != ATOMIC_AND32
- FIXED_CODE_START
);
847 BUG_ON((char *)&atomic_xor32
- (char *)&fixed_code_start
848 != ATOMIC_XOR32
- FIXED_CODE_START
);
849 BUG_ON((char *)&safe_user_instruction
- (char *)&fixed_code_start
850 != SAFE_USER_INSTRUCTION
- FIXED_CODE_START
);
852 init_exception_vectors();
856 static int __init
topology_init(void)
860 for_each_possible_cpu(cpu
) {
861 struct cpu
*c
= &per_cpu(cpu_devices
, cpu
);
863 register_cpu(c
, cpu
);
869 subsys_initcall(topology_init
);
871 /* Get the voltage input multiplier */
872 static u_long cached_vco_pll_ctl
, cached_vco
;
873 static u_long
get_vco(void)
877 u_long pll_ctl
= bfin_read_PLL_CTL();
878 if (pll_ctl
== cached_vco_pll_ctl
)
881 cached_vco_pll_ctl
= pll_ctl
;
883 msel
= (pll_ctl
>> 9) & 0x3F;
887 cached_vco
= CONFIG_CLKIN_HZ
;
888 cached_vco
>>= (1 & pll_ctl
); /* DF bit */
893 /* Get the Core clock */
894 static u_long cached_cclk_pll_div
, cached_cclk
;
895 u_long
get_cclk(void)
899 if (bfin_read_PLL_STAT() & 0x1)
900 return CONFIG_CLKIN_HZ
;
902 ssel
= bfin_read_PLL_DIV();
903 if (ssel
== cached_cclk_pll_div
)
906 cached_cclk_pll_div
= ssel
;
908 csel
= ((ssel
>> 4) & 0x03);
910 if (ssel
&& ssel
< (1 << csel
)) /* SCLK > CCLK */
911 cached_cclk
= get_vco() / ssel
;
913 cached_cclk
= get_vco() >> csel
;
916 EXPORT_SYMBOL(get_cclk
);
918 /* Get the System clock */
919 static u_long cached_sclk_pll_div
, cached_sclk
;
920 u_long
get_sclk(void)
924 if (bfin_read_PLL_STAT() & 0x1)
925 return CONFIG_CLKIN_HZ
;
927 ssel
= bfin_read_PLL_DIV();
928 if (ssel
== cached_sclk_pll_div
)
931 cached_sclk_pll_div
= ssel
;
935 printk(KERN_WARNING
"Invalid System Clock\n");
939 cached_sclk
= get_vco() / ssel
;
942 EXPORT_SYMBOL(get_sclk
);
944 unsigned long sclk_to_usecs(unsigned long sclk
)
946 u64 tmp
= USEC_PER_SEC
* (u64
)sclk
;
947 do_div(tmp
, get_sclk());
950 EXPORT_SYMBOL(sclk_to_usecs
);
952 unsigned long usecs_to_sclk(unsigned long usecs
)
954 u64 tmp
= get_sclk() * (u64
)usecs
;
955 do_div(tmp
, USEC_PER_SEC
);
958 EXPORT_SYMBOL(usecs_to_sclk
);
961 * Get CPU information for use by the procfs.
963 static int show_cpuinfo(struct seq_file
*m
, void *v
)
965 char *cpu
, *mmu
, *fpu
, *vendor
, *cache
;
968 u_long cclk
= 0, sclk
= 0;
969 u_int icache_size
= BFIN_ICACHESIZE
/ 1024, dcache_size
= 0, dsup_banks
= 0;
974 revid
= bfin_revid();
979 switch (bfin_read_CHIPID() & CHIPID_MANUFACTURE
) {
981 vendor
= "Analog Devices";
988 seq_printf(m
, "processor\t: %d\n"
990 "cpu family\t: 0x%x\n"
991 "model name\t: ADSP-%s %lu(MHz CCLK) %lu(MHz SCLK) (%s)\n"
995 (bfin_read_CHIPID() & CHIPID_FAMILY
),
996 cpu
, cclk
/1000000, sclk
/1000000,
1004 seq_printf(m
, "cpu MHz\t\t: %lu.%03lu/%lu.%03lu\n",
1005 cclk
/1000000, cclk
%1000000,
1006 sclk
/1000000, sclk
%1000000);
1007 seq_printf(m
, "bogomips\t: %lu.%02lu\n"
1008 "Calibration\t: %lu loops\n",
1009 (loops_per_jiffy
* HZ
) / 500000,
1010 ((loops_per_jiffy
* HZ
) / 5000) % 100,
1011 (loops_per_jiffy
* HZ
));
1013 /* Check Cache configutation */
1014 switch (bfin_read_DMEM_CONTROL() & (1 << DMC0_P
| 1 << DMC1_P
)) {
1016 cache
= "dbank-A/B\t: cache/sram";
1021 cache
= "dbank-A/B\t: cache/cache";
1026 cache
= "dbank-A/B\t: sram/sram";
1037 /* Is it turned on? */
1038 if ((bfin_read_DMEM_CONTROL() & (ENDCPLB
| DMC_ENABLE
)) != (ENDCPLB
| DMC_ENABLE
))
1041 if ((bfin_read_IMEM_CONTROL() & (IMC
| ENICPLB
)) == (IMC
| ENICPLB
))
1044 seq_printf(m
, "cache size\t: %d KB(L1 icache) "
1045 "%d KB(L1 dcache-%s) %d KB(L2 cache)\n",
1046 icache_size
, dcache_size
,
1047 #if defined CONFIG_BFIN_WB
1049 #elif defined CONFIG_BFIN_WT
1054 seq_printf(m
, "%s\n", cache
);
1057 seq_printf(m
, "icache setup\t: %d Sub-banks/%d Ways, %d Lines/Way\n",
1058 BFIN_ISUBBANKS
, BFIN_IWAYS
, BFIN_ILINES
);
1060 seq_printf(m
, "icache setup\t: off\n");
1063 "dcache setup\t: %d Super-banks/%d Sub-banks/%d Ways, %d Lines/Way\n",
1064 dsup_banks
, BFIN_DSUBBANKS
, BFIN_DWAYS
,
1066 #ifdef CONFIG_BFIN_ICACHE_LOCK
1067 switch ((bfin_read_IMEM_CONTROL() >> 3) & WAYALL_L
) {
1069 seq_printf(m
, "Way0 Locked-Down\n");
1072 seq_printf(m
, "Way1 Locked-Down\n");
1075 seq_printf(m
, "Way0,Way1 Locked-Down\n");
1078 seq_printf(m
, "Way2 Locked-Down\n");
1081 seq_printf(m
, "Way0,Way2 Locked-Down\n");
1084 seq_printf(m
, "Way1,Way2 Locked-Down\n");
1087 seq_printf(m
, "Way0,Way1 & Way2 Locked-Down\n");
1090 seq_printf(m
, "Way3 Locked-Down\n");
1093 seq_printf(m
, "Way0,Way3 Locked-Down\n");
1096 seq_printf(m
, "Way1,Way3 Locked-Down\n");
1099 seq_printf(m
, "Way 0,Way1,Way3 Locked-Down\n");
1102 seq_printf(m
, "Way3,Way2 Locked-Down\n");
1105 seq_printf(m
, "Way3,Way2,Way0 Locked-Down\n");
1108 seq_printf(m
, "Way3,Way2,Way1 Locked-Down\n");
1111 seq_printf(m
, "All Ways are locked\n");
1114 seq_printf(m
, "No Ways are locked\n");
1117 seq_printf(m
, "board name\t: %s\n", bfin_board_name
);
1118 seq_printf(m
, "board memory\t: %ld kB (0x%p -> 0x%p)\n",
1119 physical_mem_end
>> 10, (void *)0, (void *)physical_mem_end
);
1120 seq_printf(m
, "kernel memory\t: %d kB (0x%p -> 0x%p)\n",
1121 ((int)memory_end
- (int)_stext
) >> 10,
1123 (void *)memory_end
);
1128 static void *c_start(struct seq_file
*m
, loff_t
*pos
)
1130 return *pos
< NR_CPUS
? ((void *)0x12345678) : NULL
;
1133 static void *c_next(struct seq_file
*m
, void *v
, loff_t
*pos
)
1136 return c_start(m
, pos
);
1139 static void c_stop(struct seq_file
*m
, void *v
)
1143 const struct seq_operations cpuinfo_op
= {
1147 .show
= show_cpuinfo
,
1150 void __init
cmdline_init(const char *r0
)
1153 strncpy(command_line
, r0
, COMMAND_LINE_SIZE
);