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>
17 #include <linux/module.h>
18 #include <linux/tty.h>
19 #include <linux/pfn.h>
21 #include <linux/ext2_fs.h>
22 #include <linux/cramfs_fs.h>
23 #include <linux/romfs_fs.h>
26 #include <asm/cacheflush.h>
27 #include <asm/blackfin.h>
28 #include <asm/cplbinit.h>
29 #include <asm/div64.h>
31 #include <asm/fixed_code.h>
32 #include <asm/early_printk.h>
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
);
45 EXPORT_SYMBOL(reserved_mem_dcache_on
);
47 #ifdef CONFIG_MTD_UCLINUX
48 unsigned long memory_mtd_end
, memory_mtd_start
, mtd_size
;
50 EXPORT_SYMBOL(memory_mtd_end
);
51 EXPORT_SYMBOL(memory_mtd_start
);
52 EXPORT_SYMBOL(mtd_size
);
55 char __initdata command_line
[COMMAND_LINE_SIZE
];
56 void __initdata
*init_retx
, *init_saved_retx
, *init_saved_seqstat
,
57 *init_saved_icplb_fault_addr
, *init_saved_dcplb_fault_addr
;
59 /* boot memmap, for parsing "memmap=" */
60 #define BFIN_MEMMAP_MAX 128 /* number of entries in bfin_memmap */
61 #define BFIN_MEMMAP_RAM 1
62 #define BFIN_MEMMAP_RESERVED 2
63 static struct bfin_memmap
{
65 struct bfin_memmap_entry
{
66 unsigned long long addr
; /* start of memory segment */
67 unsigned long long size
;
69 } map
[BFIN_MEMMAP_MAX
];
70 } bfin_memmap __initdata
;
72 /* for memmap sanitization */
73 struct change_member
{
74 struct bfin_memmap_entry
*pentry
; /* pointer to original entry */
75 unsigned long long addr
; /* address for this change point */
77 static struct change_member change_point_list
[2*BFIN_MEMMAP_MAX
] __initdata
;
78 static struct change_member
*change_point
[2*BFIN_MEMMAP_MAX
] __initdata
;
79 static struct bfin_memmap_entry
*overlap_list
[BFIN_MEMMAP_MAX
] __initdata
;
80 static struct bfin_memmap_entry new_map
[BFIN_MEMMAP_MAX
] __initdata
;
82 DEFINE_PER_CPU(struct blackfin_cpudata
, cpu_data
);
84 static int early_init_clkin_hz(char *buf
);
86 #if defined(CONFIG_BFIN_DCACHE) || defined(CONFIG_BFIN_ICACHE)
87 void __init
generate_cplb_tables(void)
91 generate_cplb_tables_all();
92 /* Generate per-CPU I&D CPLB tables */
93 for (cpu
= 0; cpu
< num_possible_cpus(); ++cpu
)
94 generate_cplb_tables_cpu(cpu
);
98 void __cpuinit
bfin_setup_caches(unsigned int cpu
)
100 #ifdef CONFIG_BFIN_ICACHE
101 bfin_icache_init(icplb_tbl
[cpu
]);
104 #ifdef CONFIG_BFIN_DCACHE
105 bfin_dcache_init(dcplb_tbl
[cpu
]);
109 * In cache coherence emulation mode, we need to have the
110 * D-cache enabled before running any atomic operation which
111 * might invove cache invalidation (i.e. spinlock, rwlock).
112 * So printk's are deferred until then.
114 #ifdef CONFIG_BFIN_ICACHE
115 printk(KERN_INFO
"Instruction Cache Enabled for CPU%u\n", cpu
);
117 #ifdef CONFIG_BFIN_DCACHE
118 printk(KERN_INFO
"Data Cache Enabled for CPU%u"
119 # if defined CONFIG_BFIN_WB
121 # elif defined CONFIG_BFIN_WT
128 void __cpuinit
bfin_setup_cpudata(unsigned int cpu
)
130 struct blackfin_cpudata
*cpudata
= &per_cpu(cpu_data
, cpu
);
132 cpudata
->idle
= current
;
133 cpudata
->loops_per_jiffy
= loops_per_jiffy
;
134 cpudata
->imemctl
= bfin_read_IMEM_CONTROL();
135 cpudata
->dmemctl
= bfin_read_DMEM_CONTROL();
138 void __init
bfin_cache_init(void)
140 #if defined(CONFIG_BFIN_DCACHE) || defined(CONFIG_BFIN_ICACHE)
141 generate_cplb_tables();
143 bfin_setup_caches(0);
146 void __init
bfin_relocate_l1_mem(void)
148 unsigned long l1_code_length
;
149 unsigned long l1_data_a_length
;
150 unsigned long l1_data_b_length
;
151 unsigned long l2_length
;
153 blackfin_dma_early_init();
155 l1_code_length
= _etext_l1
- _stext_l1
;
156 if (l1_code_length
> L1_CODE_LENGTH
)
157 panic("L1 Instruction SRAM Overflow\n");
158 /* cannot complain as printk is not available as yet.
159 * But we can continue booting and complain later!
162 /* Copy _stext_l1 to _etext_l1 to L1 instruction SRAM */
163 dma_memcpy(_stext_l1
, _l1_lma_start
, l1_code_length
);
165 l1_data_a_length
= _sbss_l1
- _sdata_l1
;
166 if (l1_data_a_length
> L1_DATA_A_LENGTH
)
167 panic("L1 Data SRAM Bank A Overflow\n");
169 /* Copy _sdata_l1 to _sbss_l1 to L1 data bank A SRAM */
170 dma_memcpy(_sdata_l1
, _l1_lma_start
+ l1_code_length
, l1_data_a_length
);
172 l1_data_b_length
= _sbss_b_l1
- _sdata_b_l1
;
173 if (l1_data_b_length
> L1_DATA_B_LENGTH
)
174 panic("L1 Data SRAM Bank B Overflow\n");
176 /* Copy _sdata_b_l1 to _sbss_b_l1 to L1 data bank B SRAM */
177 dma_memcpy(_sdata_b_l1
, _l1_lma_start
+ l1_code_length
+
178 l1_data_a_length
, l1_data_b_length
);
180 if (L2_LENGTH
!= 0) {
181 l2_length
= _sbss_l2
- _stext_l2
;
182 if (l2_length
> L2_LENGTH
)
183 panic("L2 SRAM Overflow\n");
185 /* Copy _stext_l2 to _edata_l2 to L2 SRAM */
186 dma_memcpy(_stext_l2
, _l2_lma_start
, l2_length
);
190 /* add_memory_region to memmap */
191 static void __init
add_memory_region(unsigned long long start
,
192 unsigned long long size
, int type
)
196 i
= bfin_memmap
.nr_map
;
198 if (i
== BFIN_MEMMAP_MAX
) {
199 printk(KERN_ERR
"Ooops! Too many entries in the memory map!\n");
203 bfin_memmap
.map
[i
].addr
= start
;
204 bfin_memmap
.map
[i
].size
= size
;
205 bfin_memmap
.map
[i
].type
= type
;
206 bfin_memmap
.nr_map
++;
210 * Sanitize the boot memmap, removing overlaps.
212 static int __init
sanitize_memmap(struct bfin_memmap_entry
*map
, int *pnr_map
)
214 struct change_member
*change_tmp
;
215 unsigned long current_type
, last_type
;
216 unsigned long long last_addr
;
217 int chgidx
, still_changing
;
220 int old_nr
, new_nr
, chg_nr
;
224 Visually we're performing the following (1,2,3,4 = memory types)
226 Sample memory map (w/overlaps):
227 ____22__________________
228 ______________________4_
229 ____1111________________
230 _44_____________________
231 11111111________________
232 ____________________33__
233 ___________44___________
234 __________33333_________
235 ______________22________
236 ___________________2222_
237 _________111111111______
238 _____________________11_
239 _________________4______
241 Sanitized equivalent (no overlap):
242 1_______________________
243 _44_____________________
244 ___1____________________
245 ____22__________________
246 ______11________________
247 _________1______________
248 __________3_____________
249 ___________44___________
250 _____________33_________
251 _______________2________
252 ________________1_______
253 _________________4______
254 ___________________2____
255 ____________________33__
256 ______________________4_
258 /* if there's only one memory region, don't bother */
264 /* bail out if we find any unreasonable addresses in memmap */
265 for (i
= 0; i
< old_nr
; i
++)
266 if (map
[i
].addr
+ map
[i
].size
< map
[i
].addr
)
269 /* create pointers for initial change-point information (for sorting) */
270 for (i
= 0; i
< 2*old_nr
; i
++)
271 change_point
[i
] = &change_point_list
[i
];
273 /* record all known change-points (starting and ending addresses),
274 omitting those that are for empty memory regions */
276 for (i
= 0; i
< old_nr
; i
++) {
277 if (map
[i
].size
!= 0) {
278 change_point
[chgidx
]->addr
= map
[i
].addr
;
279 change_point
[chgidx
++]->pentry
= &map
[i
];
280 change_point
[chgidx
]->addr
= map
[i
].addr
+ map
[i
].size
;
281 change_point
[chgidx
++]->pentry
= &map
[i
];
284 chg_nr
= chgidx
; /* true number of change-points */
286 /* sort change-point list by memory addresses (low -> high) */
288 while (still_changing
) {
290 for (i
= 1; i
< chg_nr
; i
++) {
291 /* if <current_addr> > <last_addr>, swap */
292 /* or, if current=<start_addr> & last=<end_addr>, swap */
293 if ((change_point
[i
]->addr
< change_point
[i
-1]->addr
) ||
294 ((change_point
[i
]->addr
== change_point
[i
-1]->addr
) &&
295 (change_point
[i
]->addr
== change_point
[i
]->pentry
->addr
) &&
296 (change_point
[i
-1]->addr
!= change_point
[i
-1]->pentry
->addr
))
298 change_tmp
= change_point
[i
];
299 change_point
[i
] = change_point
[i
-1];
300 change_point
[i
-1] = change_tmp
;
306 /* create a new memmap, removing overlaps */
307 overlap_entries
= 0; /* number of entries in the overlap table */
308 new_entry
= 0; /* index for creating new memmap entries */
309 last_type
= 0; /* start with undefined memory type */
310 last_addr
= 0; /* start with 0 as last starting address */
311 /* loop through change-points, determining affect on the new memmap */
312 for (chgidx
= 0; chgidx
< chg_nr
; chgidx
++) {
313 /* keep track of all overlapping memmap entries */
314 if (change_point
[chgidx
]->addr
== change_point
[chgidx
]->pentry
->addr
) {
315 /* add map entry to overlap list (> 1 entry implies an overlap) */
316 overlap_list
[overlap_entries
++] = change_point
[chgidx
]->pentry
;
318 /* remove entry from list (order independent, so swap with last) */
319 for (i
= 0; i
< overlap_entries
; i
++) {
320 if (overlap_list
[i
] == change_point
[chgidx
]->pentry
)
321 overlap_list
[i
] = overlap_list
[overlap_entries
-1];
325 /* if there are overlapping entries, decide which "type" to use */
326 /* (larger value takes precedence -- 1=usable, 2,3,4,4+=unusable) */
328 for (i
= 0; i
< overlap_entries
; i
++)
329 if (overlap_list
[i
]->type
> current_type
)
330 current_type
= overlap_list
[i
]->type
;
331 /* continue building up new memmap based on this information */
332 if (current_type
!= last_type
) {
333 if (last_type
!= 0) {
334 new_map
[new_entry
].size
=
335 change_point
[chgidx
]->addr
- last_addr
;
336 /* move forward only if the new size was non-zero */
337 if (new_map
[new_entry
].size
!= 0)
338 if (++new_entry
>= BFIN_MEMMAP_MAX
)
339 break; /* no more space left for new entries */
341 if (current_type
!= 0) {
342 new_map
[new_entry
].addr
= change_point
[chgidx
]->addr
;
343 new_map
[new_entry
].type
= current_type
;
344 last_addr
= change_point
[chgidx
]->addr
;
346 last_type
= current_type
;
349 new_nr
= new_entry
; /* retain count for new entries */
351 /* copy new mapping into original location */
352 memcpy(map
, new_map
, new_nr
*sizeof(struct bfin_memmap_entry
));
358 static void __init
print_memory_map(char *who
)
362 for (i
= 0; i
< bfin_memmap
.nr_map
; i
++) {
363 printk(KERN_DEBUG
" %s: %016Lx - %016Lx ", who
,
364 bfin_memmap
.map
[i
].addr
,
365 bfin_memmap
.map
[i
].addr
+ bfin_memmap
.map
[i
].size
);
366 switch (bfin_memmap
.map
[i
].type
) {
367 case BFIN_MEMMAP_RAM
:
368 printk("(usable)\n");
370 case BFIN_MEMMAP_RESERVED
:
371 printk("(reserved)\n");
373 default: printk("type %lu\n", bfin_memmap
.map
[i
].type
);
379 static __init
int parse_memmap(char *arg
)
381 unsigned long long start_at
, mem_size
;
386 mem_size
= memparse(arg
, &arg
);
388 start_at
= memparse(arg
+1, &arg
);
389 add_memory_region(start_at
, mem_size
, BFIN_MEMMAP_RAM
);
390 } else if (*arg
== '$') {
391 start_at
= memparse(arg
+1, &arg
);
392 add_memory_region(start_at
, mem_size
, BFIN_MEMMAP_RESERVED
);
399 * Initial parsing of the command line. Currently, we support:
400 * - Controlling the linux memory size: mem=xxx[KMG]
401 * - Controlling the physical memory size: max_mem=xxx[KMG][$][#]
402 * $ -> reserved memory is dcacheable
403 * # -> reserved memory is icacheable
404 * - "memmap=XXX[KkmM][@][$]XXX[KkmM]" defines a memory region
405 * @ from <start> to <start>+<mem>, type RAM
406 * $ from <start> to <start>+<mem>, type RESERVED
408 static __init
void parse_cmdline_early(char *cmdline_p
)
410 char c
= ' ', *to
= cmdline_p
;
411 unsigned int memsize
;
414 if (!memcmp(to
, "mem=", 4)) {
416 memsize
= memparse(to
, &to
);
420 } else if (!memcmp(to
, "max_mem=", 8)) {
422 memsize
= memparse(to
, &to
);
424 physical_mem_end
= memsize
;
428 reserved_mem_dcache_on
= 1;
431 reserved_mem_icache_on
= 1;
434 } else if (!memcmp(to
, "clkin_hz=", 9)) {
436 early_init_clkin_hz(to
);
437 } else if (!memcmp(to
, "earlyprintk=", 12)) {
439 setup_early_printk(to
);
440 } else if (!memcmp(to
, "memmap=", 7)) {
452 * Setup memory defaults from user config.
453 * The physical memory layout looks like:
455 * [_rambase, _ramstart]: kernel image
456 * [memory_start, memory_end]: dynamic memory managed by kernel
457 * [memory_end, _ramend]: reserved memory
458 * [memory_mtd_start(memory_end),
459 * memory_mtd_start + mtd_size]: rootfs (if any)
460 * [_ramend - DMA_UNCACHED_REGION,
461 * _ramend]: uncached DMA region
462 * [_ramend, physical_mem_end]: memory not managed by kernel
464 static __init
void memory_setup(void)
466 #ifdef CONFIG_MTD_UCLINUX
467 unsigned long mtd_phys
= 0;
470 _rambase
= (unsigned long)_stext
;
471 _ramstart
= (unsigned long)_end
;
473 if (DMA_UNCACHED_REGION
> (_ramend
- _ramstart
)) {
475 panic("DMA region exceeds memory limit: %lu.\n",
476 _ramend
- _ramstart
);
478 memory_end
= _ramend
- DMA_UNCACHED_REGION
;
481 /* Round up to multiple of 4MB */
482 memory_start
= (_ramstart
+ 0x3fffff) & ~0x3fffff;
484 memory_start
= PAGE_ALIGN(_ramstart
);
487 #if defined(CONFIG_MTD_UCLINUX)
488 /* generic memory mapped MTD driver */
489 memory_mtd_end
= memory_end
;
491 mtd_phys
= _ramstart
;
492 mtd_size
= PAGE_ALIGN(*((unsigned long *)(mtd_phys
+ 8)));
494 # if defined(CONFIG_EXT2_FS) || defined(CONFIG_EXT3_FS)
495 if (*((unsigned short *)(mtd_phys
+ 0x438)) == EXT2_SUPER_MAGIC
)
497 PAGE_ALIGN(*((unsigned long *)(mtd_phys
+ 0x404)) << 10);
500 # if defined(CONFIG_CRAMFS)
501 if (*((unsigned long *)(mtd_phys
)) == CRAMFS_MAGIC
)
502 mtd_size
= PAGE_ALIGN(*((unsigned long *)(mtd_phys
+ 0x4)));
505 # if defined(CONFIG_ROMFS_FS)
506 if (((unsigned long *)mtd_phys
)[0] == ROMSB_WORD0
507 && ((unsigned long *)mtd_phys
)[1] == ROMSB_WORD1
)
509 PAGE_ALIGN(be32_to_cpu(((unsigned long *)mtd_phys
)[2]));
510 # if (defined(CONFIG_BFIN_ICACHE) && ANOMALY_05000263)
511 /* Due to a Hardware Anomaly we need to limit the size of usable
512 * instruction memory to max 60MB, 56 if HUNT_FOR_ZERO is on
513 * 05000263 - Hardware loop corrupted when taking an ICPLB exception
515 # if (defined(CONFIG_DEBUG_HUNT_FOR_ZERO))
516 if (memory_end
>= 56 * 1024 * 1024)
517 memory_end
= 56 * 1024 * 1024;
519 if (memory_end
>= 60 * 1024 * 1024)
520 memory_end
= 60 * 1024 * 1024;
521 # endif /* CONFIG_DEBUG_HUNT_FOR_ZERO */
522 # endif /* ANOMALY_05000263 */
523 # endif /* CONFIG_ROMFS_FS */
525 memory_end
-= mtd_size
;
529 panic("Don't boot kernel without rootfs attached.\n");
532 /* Relocate MTD image to the top of memory after the uncached memory area */
533 dma_memcpy((char *)memory_end
, _end
, mtd_size
);
535 memory_mtd_start
= memory_end
;
536 _ebss
= memory_mtd_start
; /* define _ebss for compatible */
537 #endif /* CONFIG_MTD_UCLINUX */
539 #if (defined(CONFIG_BFIN_ICACHE) && ANOMALY_05000263)
540 /* Due to a Hardware Anomaly we need to limit the size of usable
541 * instruction memory to max 60MB, 56 if HUNT_FOR_ZERO is on
542 * 05000263 - Hardware loop corrupted when taking an ICPLB exception
544 #if (defined(CONFIG_DEBUG_HUNT_FOR_ZERO))
545 if (memory_end
>= 56 * 1024 * 1024)
546 memory_end
= 56 * 1024 * 1024;
548 if (memory_end
>= 60 * 1024 * 1024)
549 memory_end
= 60 * 1024 * 1024;
550 #endif /* CONFIG_DEBUG_HUNT_FOR_ZERO */
551 printk(KERN_NOTICE
"Warning: limiting memory to %liMB due to hardware anomaly 05000263\n", memory_end
>> 20);
552 #endif /* ANOMALY_05000263 */
555 page_mask_nelts
= ((_ramend
>> PAGE_SHIFT
) + 31) / 32;
556 page_mask_order
= get_order(3 * page_mask_nelts
* sizeof(long));
559 #if !defined(CONFIG_MTD_UCLINUX)
560 /*In case there is no valid CPLB behind memory_end make sure we don't get to close*/
561 memory_end
-= SIZE_4K
;
564 init_mm
.start_code
= (unsigned long)_stext
;
565 init_mm
.end_code
= (unsigned long)_etext
;
566 init_mm
.end_data
= (unsigned long)_edata
;
567 init_mm
.brk
= (unsigned long)0;
569 printk(KERN_INFO
"Board Memory: %ldMB\n", physical_mem_end
>> 20);
570 printk(KERN_INFO
"Kernel Managed Memory: %ldMB\n", _ramend
>> 20);
572 printk(KERN_INFO
"Memory map:\n"
573 KERN_INFO
" fixedcode = 0x%p-0x%p\n"
574 KERN_INFO
" text = 0x%p-0x%p\n"
575 KERN_INFO
" rodata = 0x%p-0x%p\n"
576 KERN_INFO
" bss = 0x%p-0x%p\n"
577 KERN_INFO
" data = 0x%p-0x%p\n"
578 KERN_INFO
" stack = 0x%p-0x%p\n"
579 KERN_INFO
" init = 0x%p-0x%p\n"
580 KERN_INFO
" available = 0x%p-0x%p\n"
581 #ifdef CONFIG_MTD_UCLINUX
582 KERN_INFO
" rootfs = 0x%p-0x%p\n"
584 #if DMA_UNCACHED_REGION > 0
585 KERN_INFO
" DMA Zone = 0x%p-0x%p\n"
587 , (void *)FIXED_CODE_START
, (void *)FIXED_CODE_END
,
589 __start_rodata
, __end_rodata
,
590 __bss_start
, __bss_stop
,
592 (void *)&init_thread_union
,
593 (void *)((int)(&init_thread_union
) + 0x2000),
594 __init_begin
, __init_end
,
595 (void *)_ramstart
, (void *)memory_end
596 #ifdef CONFIG_MTD_UCLINUX
597 , (void *)memory_mtd_start
, (void *)(memory_mtd_start
+ mtd_size
)
599 #if DMA_UNCACHED_REGION > 0
600 , (void *)(_ramend
- DMA_UNCACHED_REGION
), (void *)(_ramend
)
606 * Find the lowest, highest page frame number we have available
608 void __init
find_min_max_pfn(void)
613 min_low_pfn
= memory_end
;
615 for (i
= 0; i
< bfin_memmap
.nr_map
; i
++) {
616 unsigned long start
, end
;
618 if (bfin_memmap
.map
[i
].type
!= BFIN_MEMMAP_RAM
)
620 start
= PFN_UP(bfin_memmap
.map
[i
].addr
);
621 end
= PFN_DOWN(bfin_memmap
.map
[i
].addr
+
622 bfin_memmap
.map
[i
].size
);
627 if (start
< min_low_pfn
)
632 static __init
void setup_bootmem_allocator(void)
636 unsigned long start_pfn
, end_pfn
;
637 unsigned long curr_pfn
, last_pfn
, size
;
639 /* mark memory between memory_start and memory_end usable */
640 add_memory_region(memory_start
,
641 memory_end
- memory_start
, BFIN_MEMMAP_RAM
);
642 /* sanity check for overlap */
643 sanitize_memmap(bfin_memmap
.map
, &bfin_memmap
.nr_map
);
644 print_memory_map("boot memmap");
646 /* intialize globals in linux/bootmem.h */
648 /* pfn of the last usable page frame */
649 if (max_pfn
> memory_end
>> PAGE_SHIFT
)
650 max_pfn
= memory_end
>> PAGE_SHIFT
;
651 /* pfn of last page frame directly mapped by kernel */
652 max_low_pfn
= max_pfn
;
653 /* pfn of the first usable page frame after kernel image*/
654 if (min_low_pfn
< memory_start
>> PAGE_SHIFT
)
655 min_low_pfn
= memory_start
>> PAGE_SHIFT
;
657 start_pfn
= PAGE_OFFSET
>> PAGE_SHIFT
;
658 end_pfn
= memory_end
>> PAGE_SHIFT
;
661 * give all the memory to the bootmap allocator, tell it to put the
662 * boot mem_map at the start of memory.
664 bootmap_size
= init_bootmem_node(NODE_DATA(0),
665 memory_start
>> PAGE_SHIFT
, /* map goes here */
668 /* register the memmap regions with the bootmem allocator */
669 for (i
= 0; i
< bfin_memmap
.nr_map
; i
++) {
671 * Reserve usable memory
673 if (bfin_memmap
.map
[i
].type
!= BFIN_MEMMAP_RAM
)
676 * We are rounding up the start address of usable memory:
678 curr_pfn
= PFN_UP(bfin_memmap
.map
[i
].addr
);
679 if (curr_pfn
>= end_pfn
)
682 * ... and at the end of the usable range downwards:
684 last_pfn
= PFN_DOWN(bfin_memmap
.map
[i
].addr
+
685 bfin_memmap
.map
[i
].size
);
687 if (last_pfn
> end_pfn
)
691 * .. finally, did all the rounding and playing
692 * around just make the area go away?
694 if (last_pfn
<= curr_pfn
)
697 size
= last_pfn
- curr_pfn
;
698 free_bootmem(PFN_PHYS(curr_pfn
), PFN_PHYS(size
));
701 /* reserve memory before memory_start, including bootmap */
702 reserve_bootmem(PAGE_OFFSET
,
703 memory_start
+ bootmap_size
+ PAGE_SIZE
- 1 - PAGE_OFFSET
,
707 #define EBSZ_TO_MEG(ebsz) \
710 switch (ebsz & 0xf) { \
711 case 0x1: meg = 16; break; \
712 case 0x3: meg = 32; break; \
713 case 0x5: meg = 64; break; \
714 case 0x7: meg = 128; break; \
715 case 0x9: meg = 256; break; \
716 case 0xb: meg = 512; break; \
720 static inline int __init
get_mem_size(void)
722 #if defined(EBIU_SDBCTL)
723 # if defined(BF561_FAMILY)
725 u32 sdbctl
= bfin_read_EBIU_SDBCTL();
726 ret
+= EBSZ_TO_MEG(sdbctl
>> 0);
727 ret
+= EBSZ_TO_MEG(sdbctl
>> 8);
728 ret
+= EBSZ_TO_MEG(sdbctl
>> 16);
729 ret
+= EBSZ_TO_MEG(sdbctl
>> 24);
732 return EBSZ_TO_MEG(bfin_read_EBIU_SDBCTL());
734 #elif defined(EBIU_DDRCTL1)
735 u32 ddrctl
= bfin_read_EBIU_DDRCTL1();
737 switch (ddrctl
& 0xc0000) {
738 case DEVSZ_64
: ret
= 64 / 8;
739 case DEVSZ_128
: ret
= 128 / 8;
740 case DEVSZ_256
: ret
= 256 / 8;
741 case DEVSZ_512
: ret
= 512 / 8;
743 switch (ddrctl
& 0x30000) {
744 case DEVWD_4
: ret
*= 2;
745 case DEVWD_8
: ret
*= 2;
746 case DEVWD_16
: break;
748 if ((ddrctl
& 0xc000) == 0x4000)
755 void __init
setup_arch(char **cmdline_p
)
757 unsigned long sclk
, cclk
;
759 #ifdef CONFIG_DUMMY_CONSOLE
760 conswitchp
= &dummy_con
;
763 #if defined(CONFIG_CMDLINE_BOOL)
764 strncpy(&command_line
[0], CONFIG_CMDLINE
, sizeof(command_line
));
765 command_line
[sizeof(command_line
) - 1] = 0;
768 /* Keep a copy of command line */
769 *cmdline_p
= &command_line
[0];
770 memcpy(boot_command_line
, command_line
, COMMAND_LINE_SIZE
);
771 boot_command_line
[COMMAND_LINE_SIZE
- 1] = '\0';
773 /* setup memory defaults from the user config */
774 physical_mem_end
= 0;
775 _ramend
= get_mem_size() * 1024 * 1024;
777 memset(&bfin_memmap
, 0, sizeof(bfin_memmap
));
779 parse_cmdline_early(&command_line
[0]);
781 if (physical_mem_end
== 0)
782 physical_mem_end
= _ramend
;
786 /* Initialize Async memory banks */
787 bfin_write_EBIU_AMBCTL0(AMBCTL0VAL
);
788 bfin_write_EBIU_AMBCTL1(AMBCTL1VAL
);
789 bfin_write_EBIU_AMGCTL(AMGCTLVAL
);
790 #ifdef CONFIG_EBIU_MBSCTLVAL
791 bfin_write_EBIU_MBSCTL(CONFIG_EBIU_MBSCTLVAL
);
792 bfin_write_EBIU_MODE(CONFIG_EBIU_MODEVAL
);
793 bfin_write_EBIU_FCTL(CONFIG_EBIU_FCTLVAL
);
799 #if !defined(CONFIG_BFIN_KERNEL_CLOCK)
800 if (ANOMALY_05000273
&& cclk
== sclk
)
801 panic("ANOMALY 05000273, SCLK can not be same as CCLK");
805 if (ANOMALY_05000266
) {
806 bfin_read_IMDMA_D0_IRQ_STATUS();
807 bfin_read_IMDMA_D1_IRQ_STATUS();
810 printk(KERN_INFO
"Hardware Trace ");
811 if (bfin_read_TBUFCTL() & 0x1)
815 if (bfin_read_TBUFCTL() & 0x2)
816 printk("and Enabled\n");
818 printk("and Disabled\n");
820 #if defined(CONFIG_CHR_DEV_FLASH) || defined(CONFIG_BLK_DEV_FLASH)
821 /* we need to initialize the Flashrom device here since we might
822 * do things with flash early on in the boot
827 printk(KERN_INFO
"Boot Mode: %i\n", bfin_read_SYSCR() & 0xF);
829 /* Newer parts mirror SWRST bits in SYSCR */
830 #if defined(CONFIG_BF53x) || defined(CONFIG_BF561) || \
831 defined(CONFIG_BF538) || defined(CONFIG_BF539)
832 _bfin_swrst
= bfin_read_SWRST();
834 _bfin_swrst
= bfin_read_SYSCR();
837 #ifdef CONFIG_DEBUG_DOUBLEFAULT_PRINT
838 bfin_write_SWRST(_bfin_swrst
& ~DOUBLE_FAULT
);
840 #ifdef CONFIG_DEBUG_DOUBLEFAULT_RESET
841 bfin_write_SWRST(_bfin_swrst
| DOUBLE_FAULT
);
845 if (_bfin_swrst
& SWRST_DBL_FAULT_A
) {
847 if (_bfin_swrst
& RESET_DOUBLE
) {
849 printk(KERN_EMERG
"Recovering from DOUBLE FAULT event\n");
850 #ifdef CONFIG_DEBUG_DOUBLEFAULT
851 /* We assume the crashing kernel, and the current symbol table match */
852 printk(KERN_EMERG
" While handling exception (EXCAUSE = 0x%x) at %pF\n",
853 (int)init_saved_seqstat
& SEQSTAT_EXCAUSE
, init_saved_retx
);
854 printk(KERN_NOTICE
" DCPLB_FAULT_ADDR: %pF\n", init_saved_dcplb_fault_addr
);
855 printk(KERN_NOTICE
" ICPLB_FAULT_ADDR: %pF\n", init_saved_icplb_fault_addr
);
857 printk(KERN_NOTICE
" The instruction at %pF caused a double exception\n",
859 } else if (_bfin_swrst
& RESET_WDOG
)
860 printk(KERN_INFO
"Recovering from Watchdog event\n");
861 else if (_bfin_swrst
& RESET_SOFTWARE
)
862 printk(KERN_NOTICE
"Reset caused by Software reset\n");
864 printk(KERN_INFO
"Blackfin support (C) 2004-2009 Analog Devices, Inc.\n");
865 if (bfin_compiled_revid() == 0xffff)
866 printk(KERN_INFO
"Compiled for ADSP-%s Rev any\n", CPU
);
867 else if (bfin_compiled_revid() == -1)
868 printk(KERN_INFO
"Compiled for ADSP-%s Rev none\n", CPU
);
870 printk(KERN_INFO
"Compiled for ADSP-%s Rev 0.%d\n", CPU
, bfin_compiled_revid());
872 if (unlikely(CPUID
!= bfin_cpuid()))
873 printk(KERN_ERR
"ERROR: Not running on ADSP-%s: unknown CPUID 0x%04x Rev 0.%d\n",
874 CPU
, bfin_cpuid(), bfin_revid());
876 if (bfin_revid() != bfin_compiled_revid()) {
877 if (bfin_compiled_revid() == -1)
878 printk(KERN_ERR
"Warning: Compiled for Rev none, but running on Rev %d\n",
880 else if (bfin_compiled_revid() != 0xffff) {
881 printk(KERN_ERR
"Warning: Compiled for Rev %d, but running on Rev %d\n",
882 bfin_compiled_revid(), bfin_revid());
883 if (bfin_compiled_revid() > bfin_revid())
884 panic("Error: you are missing anomaly workarounds for this rev\n");
887 if (bfin_revid() < CONFIG_BF_REV_MIN
|| bfin_revid() > CONFIG_BF_REV_MAX
)
888 printk(KERN_ERR
"Warning: Unsupported Chip Revision ADSP-%s Rev 0.%d detected\n",
892 /* We can't run on BF548-0.1 due to ANOMALY 05000448 */
893 if (bfin_cpuid() == 0x27de && bfin_revid() == 1)
894 panic("You can't run on this processor due to 05000448\n");
896 printk(KERN_INFO
"Blackfin Linux support by http://blackfin.uclinux.org/\n");
898 printk(KERN_INFO
"Processor Speed: %lu MHz core clock and %lu MHz System Clock\n",
899 cclk
/ 1000000, sclk
/ 1000000);
901 if (ANOMALY_05000273
&& (cclk
>> 1) <= sclk
)
902 printk("\n\n\nANOMALY_05000273: CCLK must be >= 2*SCLK !!!\n\n\n");
904 setup_bootmem_allocator();
908 /* Copy atomic sequences to their fixed location, and sanity check that
909 these locations are the ones that we advertise to userspace. */
910 memcpy((void *)FIXED_CODE_START
, &fixed_code_start
,
911 FIXED_CODE_END
- FIXED_CODE_START
);
912 BUG_ON((char *)&sigreturn_stub
- (char *)&fixed_code_start
913 != SIGRETURN_STUB
- FIXED_CODE_START
);
914 BUG_ON((char *)&atomic_xchg32
- (char *)&fixed_code_start
915 != ATOMIC_XCHG32
- FIXED_CODE_START
);
916 BUG_ON((char *)&atomic_cas32
- (char *)&fixed_code_start
917 != ATOMIC_CAS32
- FIXED_CODE_START
);
918 BUG_ON((char *)&atomic_add32
- (char *)&fixed_code_start
919 != ATOMIC_ADD32
- FIXED_CODE_START
);
920 BUG_ON((char *)&atomic_sub32
- (char *)&fixed_code_start
921 != ATOMIC_SUB32
- FIXED_CODE_START
);
922 BUG_ON((char *)&atomic_ior32
- (char *)&fixed_code_start
923 != ATOMIC_IOR32
- FIXED_CODE_START
);
924 BUG_ON((char *)&atomic_and32
- (char *)&fixed_code_start
925 != ATOMIC_AND32
- FIXED_CODE_START
);
926 BUG_ON((char *)&atomic_xor32
- (char *)&fixed_code_start
927 != ATOMIC_XOR32
- FIXED_CODE_START
);
928 BUG_ON((char *)&safe_user_instruction
- (char *)&fixed_code_start
929 != SAFE_USER_INSTRUCTION
- FIXED_CODE_START
);
932 platform_init_cpus();
934 init_exception_vectors();
935 bfin_cache_init(); /* Initialize caches for the boot CPU */
938 static int __init
topology_init(void)
941 /* Record CPU-private information for the boot processor. */
942 bfin_setup_cpudata(0);
944 for_each_possible_cpu(cpu
) {
945 register_cpu(&per_cpu(cpu_data
, cpu
).cpu
, cpu
);
951 subsys_initcall(topology_init
);
953 /* Get the input clock frequency */
954 static u_long cached_clkin_hz
= CONFIG_CLKIN_HZ
;
955 static u_long
get_clkin_hz(void)
957 return cached_clkin_hz
;
959 static int __init
early_init_clkin_hz(char *buf
)
961 cached_clkin_hz
= simple_strtoul(buf
, NULL
, 0);
962 #ifdef BFIN_KERNEL_CLOCK
963 if (cached_clkin_hz
!= CONFIG_CLKIN_HZ
)
964 panic("cannot change clkin_hz when reprogramming clocks");
968 early_param("clkin_hz=", early_init_clkin_hz
);
970 /* Get the voltage input multiplier */
971 static u_long
get_vco(void)
973 static u_long cached_vco
;
974 u_long msel
, pll_ctl
;
976 /* The assumption here is that VCO never changes at runtime.
977 * If, someday, we support that, then we'll have to change this.
982 pll_ctl
= bfin_read_PLL_CTL();
983 msel
= (pll_ctl
>> 9) & 0x3F;
987 cached_vco
= get_clkin_hz();
988 cached_vco
>>= (1 & pll_ctl
); /* DF bit */
993 /* Get the Core clock */
994 u_long
get_cclk(void)
996 static u_long cached_cclk_pll_div
, cached_cclk
;
999 if (bfin_read_PLL_STAT() & 0x1)
1000 return get_clkin_hz();
1002 ssel
= bfin_read_PLL_DIV();
1003 if (ssel
== cached_cclk_pll_div
)
1006 cached_cclk_pll_div
= ssel
;
1008 csel
= ((ssel
>> 4) & 0x03);
1010 if (ssel
&& ssel
< (1 << csel
)) /* SCLK > CCLK */
1011 cached_cclk
= get_vco() / ssel
;
1013 cached_cclk
= get_vco() >> csel
;
1016 EXPORT_SYMBOL(get_cclk
);
1018 /* Get the System clock */
1019 u_long
get_sclk(void)
1021 static u_long cached_sclk
;
1024 /* The assumption here is that SCLK never changes at runtime.
1025 * If, someday, we support that, then we'll have to change this.
1030 if (bfin_read_PLL_STAT() & 0x1)
1031 return get_clkin_hz();
1033 ssel
= bfin_read_PLL_DIV() & 0xf;
1035 printk(KERN_WARNING
"Invalid System Clock\n");
1039 cached_sclk
= get_vco() / ssel
;
1042 EXPORT_SYMBOL(get_sclk
);
1044 unsigned long sclk_to_usecs(unsigned long sclk
)
1046 u64 tmp
= USEC_PER_SEC
* (u64
)sclk
;
1047 do_div(tmp
, get_sclk());
1050 EXPORT_SYMBOL(sclk_to_usecs
);
1052 unsigned long usecs_to_sclk(unsigned long usecs
)
1054 u64 tmp
= get_sclk() * (u64
)usecs
;
1055 do_div(tmp
, USEC_PER_SEC
);
1058 EXPORT_SYMBOL(usecs_to_sclk
);
1061 * Get CPU information for use by the procfs.
1063 static int show_cpuinfo(struct seq_file
*m
, void *v
)
1065 char *cpu
, *mmu
, *fpu
, *vendor
, *cache
;
1067 int cpu_num
= *(unsigned int *)v
;
1069 u_int icache_size
= BFIN_ICACHESIZE
/ 1024, dcache_size
= 0, dsup_banks
= 0;
1070 struct blackfin_cpudata
*cpudata
= &per_cpu(cpu_data
, cpu_num
);
1075 revid
= bfin_revid();
1080 switch (bfin_read_CHIPID() & CHIPID_MANUFACTURE
) {
1082 vendor
= "Analog Devices";
1089 seq_printf(m
, "processor\t: %d\n" "vendor_id\t: %s\n", cpu_num
, vendor
);
1091 if (CPUID
== bfin_cpuid())
1092 seq_printf(m
, "cpu family\t: 0x%04x\n", CPUID
);
1094 seq_printf(m
, "cpu family\t: Compiled for:0x%04x, running on:0x%04x\n",
1095 CPUID
, bfin_cpuid());
1097 seq_printf(m
, "model name\t: ADSP-%s %lu(MHz CCLK) %lu(MHz SCLK) (%s)\n"
1099 cpu
, cclk
/1000000, sclk
/1000000,
1107 seq_printf(m
, "cpu MHz\t\t: %lu.%03lu/%lu.%03lu\n",
1108 cclk
/1000000, cclk
%1000000,
1109 sclk
/1000000, sclk
%1000000);
1110 seq_printf(m
, "bogomips\t: %lu.%02lu\n"
1111 "Calibration\t: %lu loops\n",
1112 (cpudata
->loops_per_jiffy
* HZ
) / 500000,
1113 ((cpudata
->loops_per_jiffy
* HZ
) / 5000) % 100,
1114 (cpudata
->loops_per_jiffy
* HZ
));
1116 /* Check Cache configutation */
1117 switch (cpudata
->dmemctl
& (1 << DMC0_P
| 1 << DMC1_P
)) {
1119 cache
= "dbank-A/B\t: cache/sram";
1124 cache
= "dbank-A/B\t: cache/cache";
1129 cache
= "dbank-A/B\t: sram/sram";
1140 /* Is it turned on? */
1141 if ((cpudata
->dmemctl
& (ENDCPLB
| DMC_ENABLE
)) != (ENDCPLB
| DMC_ENABLE
))
1144 if ((cpudata
->imemctl
& (IMC
| ENICPLB
)) != (IMC
| ENICPLB
))
1147 seq_printf(m
, "cache size\t: %d KB(L1 icache) "
1148 "%d KB(L1 dcache%s) %d KB(L2 cache)\n",
1149 icache_size
, dcache_size
,
1150 #if defined CONFIG_BFIN_WB
1152 #elif defined CONFIG_BFIN_WT
1157 seq_printf(m
, "%s\n", cache
);
1160 seq_printf(m
, "icache setup\t: %d Sub-banks/%d Ways, %d Lines/Way\n",
1161 BFIN_ISUBBANKS
, BFIN_IWAYS
, BFIN_ILINES
);
1163 seq_printf(m
, "icache setup\t: off\n");
1166 "dcache setup\t: %d Super-banks/%d Sub-banks/%d Ways, %d Lines/Way\n",
1167 dsup_banks
, BFIN_DSUBBANKS
, BFIN_DWAYS
,
1169 #ifdef __ARCH_SYNC_CORE_DCACHE
1170 seq_printf(m
, "SMP Dcache Flushes\t: %lu\n\n", cpudata
->dcache_invld_count
);
1172 #ifdef CONFIG_BFIN_ICACHE_LOCK
1173 switch ((cpudata
->imemctl
>> 3) & WAYALL_L
) {
1175 seq_printf(m
, "Way0 Locked-Down\n");
1178 seq_printf(m
, "Way1 Locked-Down\n");
1181 seq_printf(m
, "Way0,Way1 Locked-Down\n");
1184 seq_printf(m
, "Way2 Locked-Down\n");
1187 seq_printf(m
, "Way0,Way2 Locked-Down\n");
1190 seq_printf(m
, "Way1,Way2 Locked-Down\n");
1193 seq_printf(m
, "Way0,Way1 & Way2 Locked-Down\n");
1196 seq_printf(m
, "Way3 Locked-Down\n");
1199 seq_printf(m
, "Way0,Way3 Locked-Down\n");
1202 seq_printf(m
, "Way1,Way3 Locked-Down\n");
1205 seq_printf(m
, "Way 0,Way1,Way3 Locked-Down\n");
1208 seq_printf(m
, "Way3,Way2 Locked-Down\n");
1211 seq_printf(m
, "Way3,Way2,Way0 Locked-Down\n");
1214 seq_printf(m
, "Way3,Way2,Way1 Locked-Down\n");
1217 seq_printf(m
, "All Ways are locked\n");
1220 seq_printf(m
, "No Ways are locked\n");
1224 if (cpu_num
!= num_possible_cpus() - 1)
1228 seq_printf(m
, "L2 SRAM\t\t: %dKB\n", L2_LENGTH
/0x400);
1229 seq_printf(m
, "board name\t: %s\n", bfin_board_name
);
1230 seq_printf(m
, "board memory\t: %ld kB (0x%p -> 0x%p)\n",
1231 physical_mem_end
>> 10, (void *)0, (void *)physical_mem_end
);
1232 seq_printf(m
, "kernel memory\t: %d kB (0x%p -> 0x%p)\n",
1233 ((int)memory_end
- (int)_stext
) >> 10,
1235 (void *)memory_end
);
1236 seq_printf(m
, "\n");
1241 static void *c_start(struct seq_file
*m
, loff_t
*pos
)
1244 *pos
= first_cpu(cpu_online_map
);
1245 if (*pos
>= num_online_cpus())
1251 static void *c_next(struct seq_file
*m
, void *v
, loff_t
*pos
)
1253 *pos
= next_cpu(*pos
, cpu_online_map
);
1255 return c_start(m
, pos
);
1258 static void c_stop(struct seq_file
*m
, void *v
)
1262 const struct seq_operations cpuinfo_op
= {
1266 .show
= show_cpuinfo
,
1269 void __init
cmdline_init(const char *r0
)
1272 strncpy(command_line
, r0
, COMMAND_LINE_SIZE
);