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>
30 #include <asm/fixed_code.h>
31 #include <asm/early_printk.h>
34 EXPORT_SYMBOL(_bfin_swrst
);
36 unsigned long memory_start
, memory_end
, physical_mem_end
;
37 unsigned long _rambase
, _ramstart
, _ramend
;
38 unsigned long reserved_mem_dcache_on
;
39 unsigned long reserved_mem_icache_on
;
40 EXPORT_SYMBOL(memory_start
);
41 EXPORT_SYMBOL(memory_end
);
42 EXPORT_SYMBOL(physical_mem_end
);
43 EXPORT_SYMBOL(_ramend
);
44 EXPORT_SYMBOL(reserved_mem_dcache_on
);
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 void __initdata
*init_retx
, *init_saved_retx
, *init_saved_seqstat
,
56 *init_saved_icplb_fault_addr
, *init_saved_dcplb_fault_addr
;
58 /* boot memmap, for parsing "memmap=" */
59 #define BFIN_MEMMAP_MAX 128 /* number of entries in bfin_memmap */
60 #define BFIN_MEMMAP_RAM 1
61 #define BFIN_MEMMAP_RESERVED 2
64 struct bfin_memmap_entry
{
65 unsigned long long addr
; /* start of memory segment */
66 unsigned long long size
;
68 } map
[BFIN_MEMMAP_MAX
];
69 } bfin_memmap __initdata
;
71 /* for memmap sanitization */
72 struct change_member
{
73 struct bfin_memmap_entry
*pentry
; /* pointer to original entry */
74 unsigned long long addr
; /* address for this change point */
76 static struct change_member change_point_list
[2*BFIN_MEMMAP_MAX
] __initdata
;
77 static struct change_member
*change_point
[2*BFIN_MEMMAP_MAX
] __initdata
;
78 static struct bfin_memmap_entry
*overlap_list
[BFIN_MEMMAP_MAX
] __initdata
;
79 static struct bfin_memmap_entry new_map
[BFIN_MEMMAP_MAX
] __initdata
;
81 DEFINE_PER_CPU(struct blackfin_cpudata
, cpu_data
);
83 #if defined(CONFIG_BFIN_DCACHE) || defined(CONFIG_BFIN_ICACHE)
84 void __init
generate_cplb_tables(void)
88 /* Generate per-CPU I&D CPLB tables */
89 for (cpu
= 0; cpu
< num_possible_cpus(); ++cpu
)
90 generate_cplb_tables_cpu(cpu
);
94 void __cpuinit
bfin_setup_caches(unsigned int cpu
)
96 #ifdef CONFIG_BFIN_ICACHE
98 bfin_icache_init(icplb_tbl
[cpu
]);
100 bfin_icache_init(icplb_tables
[cpu
]);
104 #ifdef CONFIG_BFIN_DCACHE
106 bfin_dcache_init(dcplb_tbl
[cpu
]);
108 bfin_dcache_init(dcplb_tables
[cpu
]);
113 * In cache coherence emulation mode, we need to have the
114 * D-cache enabled before running any atomic operation which
115 * might invove cache invalidation (i.e. spinlock, rwlock).
116 * So printk's are deferred until then.
118 #ifdef CONFIG_BFIN_ICACHE
119 printk(KERN_INFO
"Instruction Cache Enabled for CPU%u\n", cpu
);
121 #ifdef CONFIG_BFIN_DCACHE
122 printk(KERN_INFO
"Data Cache Enabled for CPU%u"
123 # if defined CONFIG_BFIN_WB
125 # elif defined CONFIG_BFIN_WT
132 void __cpuinit
bfin_setup_cpudata(unsigned int cpu
)
134 struct blackfin_cpudata
*cpudata
= &per_cpu(cpu_data
, cpu
);
136 cpudata
->idle
= current
;
137 cpudata
->loops_per_jiffy
= loops_per_jiffy
;
138 cpudata
->cclk
= get_cclk();
139 cpudata
->imemctl
= bfin_read_IMEM_CONTROL();
140 cpudata
->dmemctl
= bfin_read_DMEM_CONTROL();
143 void __init
bfin_cache_init(void)
145 #if defined(CONFIG_BFIN_DCACHE) || defined(CONFIG_BFIN_ICACHE)
146 generate_cplb_tables();
148 bfin_setup_caches(0);
151 void __init
bfin_relocate_l1_mem(void)
153 unsigned long l1_code_length
;
154 unsigned long l1_data_a_length
;
155 unsigned long l1_data_b_length
;
156 unsigned long l2_length
;
158 l1_code_length
= _etext_l1
- _stext_l1
;
159 if (l1_code_length
> L1_CODE_LENGTH
)
160 panic("L1 Instruction SRAM Overflow\n");
161 /* cannot complain as printk is not available as yet.
162 * But we can continue booting and complain later!
165 /* Copy _stext_l1 to _etext_l1 to L1 instruction SRAM */
166 dma_memcpy(_stext_l1
, _l1_lma_start
, l1_code_length
);
168 l1_data_a_length
= _sbss_l1
- _sdata_l1
;
169 if (l1_data_a_length
> L1_DATA_A_LENGTH
)
170 panic("L1 Data SRAM Bank A Overflow\n");
172 /* Copy _sdata_l1 to _sbss_l1 to L1 data bank A SRAM */
173 dma_memcpy(_sdata_l1
, _l1_lma_start
+ l1_code_length
, l1_data_a_length
);
175 l1_data_b_length
= _sbss_b_l1
- _sdata_b_l1
;
176 if (l1_data_b_length
> L1_DATA_B_LENGTH
)
177 panic("L1 Data SRAM Bank B Overflow\n");
179 /* Copy _sdata_b_l1 to _sbss_b_l1 to L1 data bank B SRAM */
180 dma_memcpy(_sdata_b_l1
, _l1_lma_start
+ l1_code_length
+
181 l1_data_a_length
, l1_data_b_length
);
183 if (L2_LENGTH
!= 0) {
184 l2_length
= _sbss_l2
- _stext_l2
;
185 if (l2_length
> L2_LENGTH
)
186 panic("L2 SRAM Overflow\n");
188 /* Copy _stext_l2 to _edata_l2 to L2 SRAM */
189 dma_memcpy(_stext_l2
, _l2_lma_start
, l2_length
);
193 /* add_memory_region to memmap */
194 static void __init
add_memory_region(unsigned long long start
,
195 unsigned long long size
, int type
)
199 i
= bfin_memmap
.nr_map
;
201 if (i
== BFIN_MEMMAP_MAX
) {
202 printk(KERN_ERR
"Ooops! Too many entries in the memory map!\n");
206 bfin_memmap
.map
[i
].addr
= start
;
207 bfin_memmap
.map
[i
].size
= size
;
208 bfin_memmap
.map
[i
].type
= type
;
209 bfin_memmap
.nr_map
++;
213 * Sanitize the boot memmap, removing overlaps.
215 static int __init
sanitize_memmap(struct bfin_memmap_entry
*map
, int *pnr_map
)
217 struct change_member
*change_tmp
;
218 unsigned long current_type
, last_type
;
219 unsigned long long last_addr
;
220 int chgidx
, still_changing
;
223 int old_nr
, new_nr
, chg_nr
;
227 Visually we're performing the following (1,2,3,4 = memory types)
229 Sample memory map (w/overlaps):
230 ____22__________________
231 ______________________4_
232 ____1111________________
233 _44_____________________
234 11111111________________
235 ____________________33__
236 ___________44___________
237 __________33333_________
238 ______________22________
239 ___________________2222_
240 _________111111111______
241 _____________________11_
242 _________________4______
244 Sanitized equivalent (no overlap):
245 1_______________________
246 _44_____________________
247 ___1____________________
248 ____22__________________
249 ______11________________
250 _________1______________
251 __________3_____________
252 ___________44___________
253 _____________33_________
254 _______________2________
255 ________________1_______
256 _________________4______
257 ___________________2____
258 ____________________33__
259 ______________________4_
261 /* if there's only one memory region, don't bother */
267 /* bail out if we find any unreasonable addresses in memmap */
268 for (i
= 0; i
< old_nr
; i
++)
269 if (map
[i
].addr
+ map
[i
].size
< map
[i
].addr
)
272 /* create pointers for initial change-point information (for sorting) */
273 for (i
= 0; i
< 2*old_nr
; i
++)
274 change_point
[i
] = &change_point_list
[i
];
276 /* record all known change-points (starting and ending addresses),
277 omitting those that are for empty memory regions */
279 for (i
= 0; i
< old_nr
; i
++) {
280 if (map
[i
].size
!= 0) {
281 change_point
[chgidx
]->addr
= map
[i
].addr
;
282 change_point
[chgidx
++]->pentry
= &map
[i
];
283 change_point
[chgidx
]->addr
= map
[i
].addr
+ map
[i
].size
;
284 change_point
[chgidx
++]->pentry
= &map
[i
];
287 chg_nr
= chgidx
; /* true number of change-points */
289 /* sort change-point list by memory addresses (low -> high) */
291 while (still_changing
) {
293 for (i
= 1; i
< chg_nr
; i
++) {
294 /* if <current_addr> > <last_addr>, swap */
295 /* or, if current=<start_addr> & last=<end_addr>, swap */
296 if ((change_point
[i
]->addr
< change_point
[i
-1]->addr
) ||
297 ((change_point
[i
]->addr
== change_point
[i
-1]->addr
) &&
298 (change_point
[i
]->addr
== change_point
[i
]->pentry
->addr
) &&
299 (change_point
[i
-1]->addr
!= change_point
[i
-1]->pentry
->addr
))
301 change_tmp
= change_point
[i
];
302 change_point
[i
] = change_point
[i
-1];
303 change_point
[i
-1] = change_tmp
;
309 /* create a new memmap, removing overlaps */
310 overlap_entries
= 0; /* number of entries in the overlap table */
311 new_entry
= 0; /* index for creating new memmap entries */
312 last_type
= 0; /* start with undefined memory type */
313 last_addr
= 0; /* start with 0 as last starting address */
314 /* loop through change-points, determining affect on the new memmap */
315 for (chgidx
= 0; chgidx
< chg_nr
; chgidx
++) {
316 /* keep track of all overlapping memmap entries */
317 if (change_point
[chgidx
]->addr
== change_point
[chgidx
]->pentry
->addr
) {
318 /* add map entry to overlap list (> 1 entry implies an overlap) */
319 overlap_list
[overlap_entries
++] = change_point
[chgidx
]->pentry
;
321 /* remove entry from list (order independent, so swap with last) */
322 for (i
= 0; i
< overlap_entries
; i
++) {
323 if (overlap_list
[i
] == change_point
[chgidx
]->pentry
)
324 overlap_list
[i
] = overlap_list
[overlap_entries
-1];
328 /* if there are overlapping entries, decide which "type" to use */
329 /* (larger value takes precedence -- 1=usable, 2,3,4,4+=unusable) */
331 for (i
= 0; i
< overlap_entries
; i
++)
332 if (overlap_list
[i
]->type
> current_type
)
333 current_type
= overlap_list
[i
]->type
;
334 /* continue building up new memmap based on this information */
335 if (current_type
!= last_type
) {
336 if (last_type
!= 0) {
337 new_map
[new_entry
].size
=
338 change_point
[chgidx
]->addr
- last_addr
;
339 /* move forward only if the new size was non-zero */
340 if (new_map
[new_entry
].size
!= 0)
341 if (++new_entry
>= BFIN_MEMMAP_MAX
)
342 break; /* no more space left for new entries */
344 if (current_type
!= 0) {
345 new_map
[new_entry
].addr
= change_point
[chgidx
]->addr
;
346 new_map
[new_entry
].type
= current_type
;
347 last_addr
= change_point
[chgidx
]->addr
;
349 last_type
= current_type
;
352 new_nr
= new_entry
; /* retain count for new entries */
354 /* copy new mapping into original location */
355 memcpy(map
, new_map
, new_nr
*sizeof(struct bfin_memmap_entry
));
361 static void __init
print_memory_map(char *who
)
365 for (i
= 0; i
< bfin_memmap
.nr_map
; i
++) {
366 printk(KERN_DEBUG
" %s: %016Lx - %016Lx ", who
,
367 bfin_memmap
.map
[i
].addr
,
368 bfin_memmap
.map
[i
].addr
+ bfin_memmap
.map
[i
].size
);
369 switch (bfin_memmap
.map
[i
].type
) {
370 case BFIN_MEMMAP_RAM
:
371 printk("(usable)\n");
373 case BFIN_MEMMAP_RESERVED
:
374 printk("(reserved)\n");
376 default: printk("type %lu\n", bfin_memmap
.map
[i
].type
);
382 static __init
int parse_memmap(char *arg
)
384 unsigned long long start_at
, mem_size
;
389 mem_size
= memparse(arg
, &arg
);
391 start_at
= memparse(arg
+1, &arg
);
392 add_memory_region(start_at
, mem_size
, BFIN_MEMMAP_RAM
);
393 } else if (*arg
== '$') {
394 start_at
= memparse(arg
+1, &arg
);
395 add_memory_region(start_at
, mem_size
, BFIN_MEMMAP_RESERVED
);
402 * Initial parsing of the command line. Currently, we support:
403 * - Controlling the linux memory size: mem=xxx[KMG]
404 * - Controlling the physical memory size: max_mem=xxx[KMG][$][#]
405 * $ -> reserved memory is dcacheable
406 * # -> reserved memory is icacheable
407 * - "memmap=XXX[KkmM][@][$]XXX[KkmM]" defines a memory region
408 * @ from <start> to <start>+<mem>, type RAM
409 * $ from <start> to <start>+<mem>, type RESERVED
411 static __init
void parse_cmdline_early(char *cmdline_p
)
413 char c
= ' ', *to
= cmdline_p
;
414 unsigned int memsize
;
417 if (!memcmp(to
, "mem=", 4)) {
419 memsize
= memparse(to
, &to
);
423 } else if (!memcmp(to
, "max_mem=", 8)) {
425 memsize
= memparse(to
, &to
);
427 physical_mem_end
= memsize
;
431 reserved_mem_dcache_on
= 1;
434 reserved_mem_icache_on
= 1;
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 _bfin_swrst
= bfin_read_SWRST();
829 #ifdef CONFIG_DEBUG_DOUBLEFAULT_PRINT
830 bfin_write_SWRST(_bfin_swrst
& ~DOUBLE_FAULT
);
832 #ifdef CONFIG_DEBUG_DOUBLEFAULT_RESET
833 bfin_write_SWRST(_bfin_swrst
| DOUBLE_FAULT
);
837 if (_bfin_swrst
& SWRST_DBL_FAULT_A
) {
839 if (_bfin_swrst
& RESET_DOUBLE
) {
841 printk(KERN_EMERG
"Recovering from DOUBLE FAULT event\n");
842 #ifdef CONFIG_DEBUG_DOUBLEFAULT
843 /* We assume the crashing kernel, and the current symbol table match */
844 printk(KERN_EMERG
" While handling exception (EXCAUSE = 0x%x) at %pF\n",
845 (int)init_saved_seqstat
& SEQSTAT_EXCAUSE
, init_saved_retx
);
846 printk(KERN_NOTICE
" DCPLB_FAULT_ADDR: %pF\n", init_saved_dcplb_fault_addr
);
847 printk(KERN_NOTICE
" ICPLB_FAULT_ADDR: %pF\n", init_saved_icplb_fault_addr
);
849 printk(KERN_NOTICE
" The instruction at %pF caused a double exception\n",
851 } else if (_bfin_swrst
& RESET_WDOG
)
852 printk(KERN_INFO
"Recovering from Watchdog event\n");
853 else if (_bfin_swrst
& RESET_SOFTWARE
)
854 printk(KERN_NOTICE
"Reset caused by Software reset\n");
856 printk(KERN_INFO
"Blackfin support (C) 2004-2008 Analog Devices, Inc.\n");
857 if (bfin_compiled_revid() == 0xffff)
858 printk(KERN_INFO
"Compiled for ADSP-%s Rev any\n", CPU
);
859 else if (bfin_compiled_revid() == -1)
860 printk(KERN_INFO
"Compiled for ADSP-%s Rev none\n", CPU
);
862 printk(KERN_INFO
"Compiled for ADSP-%s Rev 0.%d\n", CPU
, bfin_compiled_revid());
864 if (unlikely(CPUID
!= bfin_cpuid()))
865 printk(KERN_ERR
"ERROR: Not running on ADSP-%s: unknown CPUID 0x%04x Rev 0.%d\n",
866 CPU
, bfin_cpuid(), bfin_revid());
868 if (bfin_revid() != bfin_compiled_revid()) {
869 if (bfin_compiled_revid() == -1)
870 printk(KERN_ERR
"Warning: Compiled for Rev none, but running on Rev %d\n",
872 else if (bfin_compiled_revid() != 0xffff)
873 printk(KERN_ERR
"Warning: Compiled for Rev %d, but running on Rev %d\n",
874 bfin_compiled_revid(), bfin_revid());
876 if (bfin_revid() < CONFIG_BF_REV_MIN
|| bfin_revid() > CONFIG_BF_REV_MAX
)
877 printk(KERN_ERR
"Warning: Unsupported Chip Revision ADSP-%s Rev 0.%d detected\n",
881 printk(KERN_INFO
"Blackfin Linux support by http://blackfin.uclinux.org/\n");
883 printk(KERN_INFO
"Processor Speed: %lu MHz core clock and %lu MHz System Clock\n",
884 cclk
/ 1000000, sclk
/ 1000000);
886 if (ANOMALY_05000273
&& (cclk
>> 1) <= sclk
)
887 printk("\n\n\nANOMALY_05000273: CCLK must be >= 2*SCLK !!!\n\n\n");
889 setup_bootmem_allocator();
893 /* Copy atomic sequences to their fixed location, and sanity check that
894 these locations are the ones that we advertise to userspace. */
895 memcpy((void *)FIXED_CODE_START
, &fixed_code_start
,
896 FIXED_CODE_END
- FIXED_CODE_START
);
897 BUG_ON((char *)&sigreturn_stub
- (char *)&fixed_code_start
898 != SIGRETURN_STUB
- FIXED_CODE_START
);
899 BUG_ON((char *)&atomic_xchg32
- (char *)&fixed_code_start
900 != ATOMIC_XCHG32
- FIXED_CODE_START
);
901 BUG_ON((char *)&atomic_cas32
- (char *)&fixed_code_start
902 != ATOMIC_CAS32
- FIXED_CODE_START
);
903 BUG_ON((char *)&atomic_add32
- (char *)&fixed_code_start
904 != ATOMIC_ADD32
- FIXED_CODE_START
);
905 BUG_ON((char *)&atomic_sub32
- (char *)&fixed_code_start
906 != ATOMIC_SUB32
- FIXED_CODE_START
);
907 BUG_ON((char *)&atomic_ior32
- (char *)&fixed_code_start
908 != ATOMIC_IOR32
- FIXED_CODE_START
);
909 BUG_ON((char *)&atomic_and32
- (char *)&fixed_code_start
910 != ATOMIC_AND32
- FIXED_CODE_START
);
911 BUG_ON((char *)&atomic_xor32
- (char *)&fixed_code_start
912 != ATOMIC_XOR32
- FIXED_CODE_START
);
913 BUG_ON((char *)&safe_user_instruction
- (char *)&fixed_code_start
914 != SAFE_USER_INSTRUCTION
- FIXED_CODE_START
);
917 platform_init_cpus();
919 init_exception_vectors();
920 bfin_cache_init(); /* Initialize caches for the boot CPU */
923 static int __init
topology_init(void)
926 /* Record CPU-private information for the boot processor. */
927 bfin_setup_cpudata(0);
929 for_each_possible_cpu(cpu
) {
930 register_cpu(&per_cpu(cpu_data
, cpu
).cpu
, cpu
);
936 subsys_initcall(topology_init
);
938 /* Get the voltage input multiplier */
939 static u_long cached_vco_pll_ctl
, cached_vco
;
940 static u_long
get_vco(void)
944 u_long pll_ctl
= bfin_read_PLL_CTL();
945 if (pll_ctl
== cached_vco_pll_ctl
)
948 cached_vco_pll_ctl
= pll_ctl
;
950 msel
= (pll_ctl
>> 9) & 0x3F;
954 cached_vco
= CONFIG_CLKIN_HZ
;
955 cached_vco
>>= (1 & pll_ctl
); /* DF bit */
960 /* Get the Core clock */
961 static u_long cached_cclk_pll_div
, cached_cclk
;
962 u_long
get_cclk(void)
966 if (bfin_read_PLL_STAT() & 0x1)
967 return CONFIG_CLKIN_HZ
;
969 ssel
= bfin_read_PLL_DIV();
970 if (ssel
== cached_cclk_pll_div
)
973 cached_cclk_pll_div
= ssel
;
975 csel
= ((ssel
>> 4) & 0x03);
977 if (ssel
&& ssel
< (1 << csel
)) /* SCLK > CCLK */
978 cached_cclk
= get_vco() / ssel
;
980 cached_cclk
= get_vco() >> csel
;
983 EXPORT_SYMBOL(get_cclk
);
985 /* Get the System clock */
986 static u_long cached_sclk_pll_div
, cached_sclk
;
987 u_long
get_sclk(void)
991 if (bfin_read_PLL_STAT() & 0x1)
992 return CONFIG_CLKIN_HZ
;
994 ssel
= bfin_read_PLL_DIV();
995 if (ssel
== cached_sclk_pll_div
)
998 cached_sclk_pll_div
= ssel
;
1002 printk(KERN_WARNING
"Invalid System Clock\n");
1006 cached_sclk
= get_vco() / ssel
;
1009 EXPORT_SYMBOL(get_sclk
);
1011 unsigned long sclk_to_usecs(unsigned long sclk
)
1013 u64 tmp
= USEC_PER_SEC
* (u64
)sclk
;
1014 do_div(tmp
, get_sclk());
1017 EXPORT_SYMBOL(sclk_to_usecs
);
1019 unsigned long usecs_to_sclk(unsigned long usecs
)
1021 u64 tmp
= get_sclk() * (u64
)usecs
;
1022 do_div(tmp
, USEC_PER_SEC
);
1025 EXPORT_SYMBOL(usecs_to_sclk
);
1028 * Get CPU information for use by the procfs.
1030 static int show_cpuinfo(struct seq_file
*m
, void *v
)
1032 char *cpu
, *mmu
, *fpu
, *vendor
, *cache
;
1036 u_int icache_size
= BFIN_ICACHESIZE
/ 1024, dcache_size
= 0, dsup_banks
= 0;
1037 struct blackfin_cpudata
*cpudata
= &per_cpu(cpu_data
, *(unsigned int *)v
);
1042 revid
= bfin_revid();
1046 switch (bfin_read_CHIPID() & CHIPID_MANUFACTURE
) {
1048 vendor
= "Analog Devices";
1055 seq_printf(m
, "processor\t: %d\n" "vendor_id\t: %s\n",
1056 *(unsigned int *)v
, vendor
);
1058 if (CPUID
== bfin_cpuid())
1059 seq_printf(m
, "cpu family\t: 0x%04x\n", CPUID
);
1061 seq_printf(m
, "cpu family\t: Compiled for:0x%04x, running on:0x%04x\n",
1062 CPUID
, bfin_cpuid());
1064 seq_printf(m
, "model name\t: ADSP-%s %lu(MHz CCLK) %lu(MHz SCLK) (%s)\n"
1066 cpu
, cpudata
->cclk
/1000000, sclk
/1000000,
1074 seq_printf(m
, "cpu MHz\t\t: %lu.%03lu/%lu.%03lu\n",
1075 cpudata
->cclk
/1000000, cpudata
->cclk
%1000000,
1076 sclk
/1000000, sclk
%1000000);
1077 seq_printf(m
, "bogomips\t: %lu.%02lu\n"
1078 "Calibration\t: %lu loops\n",
1079 (cpudata
->loops_per_jiffy
* HZ
) / 500000,
1080 ((cpudata
->loops_per_jiffy
* HZ
) / 5000) % 100,
1081 (cpudata
->loops_per_jiffy
* HZ
));
1083 /* Check Cache configutation */
1084 switch (cpudata
->dmemctl
& (1 << DMC0_P
| 1 << DMC1_P
)) {
1086 cache
= "dbank-A/B\t: cache/sram";
1091 cache
= "dbank-A/B\t: cache/cache";
1096 cache
= "dbank-A/B\t: sram/sram";
1107 /* Is it turned on? */
1108 if ((cpudata
->dmemctl
& (ENDCPLB
| DMC_ENABLE
)) != (ENDCPLB
| DMC_ENABLE
))
1111 if ((cpudata
->imemctl
& (IMC
| ENICPLB
)) != (IMC
| ENICPLB
))
1114 seq_printf(m
, "cache size\t: %d KB(L1 icache) "
1115 "%d KB(L1 dcache-%s) %d KB(L2 cache)\n",
1116 icache_size
, dcache_size
,
1117 #if defined CONFIG_BFIN_WB
1119 #elif defined CONFIG_BFIN_WT
1124 seq_printf(m
, "%s\n", cache
);
1127 seq_printf(m
, "icache setup\t: %d Sub-banks/%d Ways, %d Lines/Way\n",
1128 BFIN_ISUBBANKS
, BFIN_IWAYS
, BFIN_ILINES
);
1130 seq_printf(m
, "icache setup\t: off\n");
1133 "dcache setup\t: %d Super-banks/%d Sub-banks/%d Ways, %d Lines/Way\n",
1134 dsup_banks
, BFIN_DSUBBANKS
, BFIN_DWAYS
,
1136 #ifdef __ARCH_SYNC_CORE_DCACHE
1138 "SMP Dcache Flushes\t: %lu\n\n",
1139 per_cpu(cpu_data
, *(unsigned int *)v
).dcache_invld_count
);
1141 #ifdef CONFIG_BFIN_ICACHE_LOCK
1142 switch ((cpudata
->imemctl
>> 3) & WAYALL_L
) {
1144 seq_printf(m
, "Way0 Locked-Down\n");
1147 seq_printf(m
, "Way1 Locked-Down\n");
1150 seq_printf(m
, "Way0,Way1 Locked-Down\n");
1153 seq_printf(m
, "Way2 Locked-Down\n");
1156 seq_printf(m
, "Way0,Way2 Locked-Down\n");
1159 seq_printf(m
, "Way1,Way2 Locked-Down\n");
1162 seq_printf(m
, "Way0,Way1 & Way2 Locked-Down\n");
1165 seq_printf(m
, "Way3 Locked-Down\n");
1168 seq_printf(m
, "Way0,Way3 Locked-Down\n");
1171 seq_printf(m
, "Way1,Way3 Locked-Down\n");
1174 seq_printf(m
, "Way 0,Way1,Way3 Locked-Down\n");
1177 seq_printf(m
, "Way3,Way2 Locked-Down\n");
1180 seq_printf(m
, "Way3,Way2,Way0 Locked-Down\n");
1183 seq_printf(m
, "Way3,Way2,Way1 Locked-Down\n");
1186 seq_printf(m
, "All Ways are locked\n");
1189 seq_printf(m
, "No Ways are locked\n");
1192 if (*(unsigned int *)v
!= NR_CPUS
-1)
1196 seq_printf(m
, "L2 SRAM\t\t: %dKB\n", L2_LENGTH
/0x400);
1198 seq_printf(m
, "board name\t: %s\n", bfin_board_name
);
1199 seq_printf(m
, "board memory\t: %ld kB (0x%p -> 0x%p)\n",
1200 physical_mem_end
>> 10, (void *)0, (void *)physical_mem_end
);
1201 seq_printf(m
, "kernel memory\t: %d kB (0x%p -> 0x%p)\n",
1202 ((int)memory_end
- (int)_stext
) >> 10,
1204 (void *)memory_end
);
1205 seq_printf(m
, "\n");
1210 static void *c_start(struct seq_file
*m
, loff_t
*pos
)
1213 *pos
= first_cpu(cpu_online_map
);
1214 if (*pos
>= num_online_cpus())
1220 static void *c_next(struct seq_file
*m
, void *v
, loff_t
*pos
)
1222 *pos
= next_cpu(*pos
, cpu_online_map
);
1224 return c_start(m
, pos
);
1227 static void c_stop(struct seq_file
*m
, void *v
)
1231 const struct seq_operations cpuinfo_op
= {
1235 .show
= show_cpuinfo
,
1238 void __init
cmdline_init(const char *r0
)
1241 strncpy(command_line
, r0
, COMMAND_LINE_SIZE
);