2 * File: arch/blackfin/kernel/setup.c
10 * Copyright 2004-2006 Analog Devices Inc.
12 * Bugs: Enter bugs at http://blackfin.uclinux.org/
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2 of the License, or
17 * (at your option) any later version.
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, see the file COPYING, or write
26 * to the Free Software Foundation, Inc.,
27 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
30 #include <linux/delay.h>
31 #include <linux/console.h>
32 #include <linux/bootmem.h>
33 #include <linux/seq_file.h>
34 #include <linux/cpu.h>
35 #include <linux/module.h>
36 #include <linux/tty.h>
37 #include <linux/pfn.h>
39 #include <linux/ext2_fs.h>
40 #include <linux/cramfs_fs.h>
41 #include <linux/romfs_fs.h>
44 #include <asm/cacheflush.h>
45 #include <asm/blackfin.h>
46 #include <asm/cplbinit.h>
47 #include <asm/div64.h>
48 #include <asm/fixed_code.h>
49 #include <asm/early_printk.h>
51 static DEFINE_PER_CPU(struct cpu, cpu_devices);
55 unsigned long memory_start, memory_end, physical_mem_end;
56 unsigned long reserved_mem_dcache_on;
57 unsigned long reserved_mem_icache_on;
58 EXPORT_SYMBOL(memory_start);
59 EXPORT_SYMBOL(memory_end);
60 EXPORT_SYMBOL(physical_mem_end);
61 EXPORT_SYMBOL(_ramend);
63 #ifdef CONFIG_MTD_UCLINUX
64 unsigned long memory_mtd_end, memory_mtd_start, mtd_size;
66 EXPORT_SYMBOL(memory_mtd_end);
67 EXPORT_SYMBOL(memory_mtd_start);
68 EXPORT_SYMBOL(mtd_size);
71 char __initdata command_line[COMMAND_LINE_SIZE];
73 /* boot memmap, for parsing "memmap=" */
74 #define BFIN_MEMMAP_MAX 128 /* number of entries in bfin_memmap */
75 #define BFIN_MEMMAP_RAM 1
76 #define BFIN_MEMMAP_RESERVED 2
79 struct bfin_memmap_entry {
80 unsigned long long addr; /* start of memory segment */
81 unsigned long long size;
83 } map[BFIN_MEMMAP_MAX];
84 } bfin_memmap __initdata;
86 /* for memmap sanitization */
87 struct change_member {
88 struct bfin_memmap_entry *pentry; /* pointer to original entry */
89 unsigned long long addr; /* address for this change point */
91 static struct change_member change_point_list[2*BFIN_MEMMAP_MAX] __initdata;
92 static struct change_member *change_point[2*BFIN_MEMMAP_MAX] __initdata;
93 static struct bfin_memmap_entry *overlap_list[BFIN_MEMMAP_MAX] __initdata;
94 static struct bfin_memmap_entry new_map[BFIN_MEMMAP_MAX] __initdata;
96 void __init bf53x_cache_init(void)
98 #if defined(CONFIG_BFIN_DCACHE) || defined(CONFIG_BFIN_ICACHE)
99 generate_cpl_tables();
102 #ifdef CONFIG_BFIN_ICACHE
104 printk(KERN_INFO "Instruction Cache Enabled\n");
107 #ifdef CONFIG_BFIN_DCACHE
109 printk(KERN_INFO "Data Cache Enabled"
110 # if defined CONFIG_BFIN_WB
112 # elif defined CONFIG_BFIN_WT
119 void __init bf53x_relocate_l1_mem(void)
121 unsigned long l1_code_length;
122 unsigned long l1_data_a_length;
123 unsigned long l1_data_b_length;
125 l1_code_length = _etext_l1 - _stext_l1;
126 if (l1_code_length > L1_CODE_LENGTH)
127 l1_code_length = L1_CODE_LENGTH;
128 /* cannot complain as printk is not available as yet.
129 * But we can continue booting and complain later!
132 /* Copy _stext_l1 to _etext_l1 to L1 instruction SRAM */
133 dma_memcpy(_stext_l1, _l1_lma_start, l1_code_length);
135 l1_data_a_length = _ebss_l1 - _sdata_l1;
136 if (l1_data_a_length > L1_DATA_A_LENGTH)
137 l1_data_a_length = L1_DATA_A_LENGTH;
139 /* Copy _sdata_l1 to _ebss_l1 to L1 data bank A SRAM */
140 dma_memcpy(_sdata_l1, _l1_lma_start + l1_code_length, l1_data_a_length);
142 l1_data_b_length = _ebss_b_l1 - _sdata_b_l1;
143 if (l1_data_b_length > L1_DATA_B_LENGTH)
144 l1_data_b_length = L1_DATA_B_LENGTH;
146 /* Copy _sdata_b_l1 to _ebss_b_l1 to L1 data bank B SRAM */
147 dma_memcpy(_sdata_b_l1, _l1_lma_start + l1_code_length +
148 l1_data_a_length, l1_data_b_length);
152 /* add_memory_region to memmap */
153 static void __init add_memory_region(unsigned long long start,
154 unsigned long long size, int type)
158 i = bfin_memmap.nr_map;
160 if (i == BFIN_MEMMAP_MAX) {
161 printk(KERN_ERR "Ooops! Too many entries in the memory map!\n");
165 bfin_memmap.map[i].addr = start;
166 bfin_memmap.map[i].size = size;
167 bfin_memmap.map[i].type = type;
168 bfin_memmap.nr_map++;
172 * Sanitize the boot memmap, removing overlaps.
174 static int __init sanitize_memmap(struct bfin_memmap_entry *map, int *pnr_map)
176 struct change_member *change_tmp;
177 unsigned long current_type, last_type;
178 unsigned long long last_addr;
179 int chgidx, still_changing;
182 int old_nr, new_nr, chg_nr;
186 Visually we're performing the following (1,2,3,4 = memory types)
188 Sample memory map (w/overlaps):
189 ____22__________________
190 ______________________4_
191 ____1111________________
192 _44_____________________
193 11111111________________
194 ____________________33__
195 ___________44___________
196 __________33333_________
197 ______________22________
198 ___________________2222_
199 _________111111111______
200 _____________________11_
201 _________________4______
203 Sanitized equivalent (no overlap):
204 1_______________________
205 _44_____________________
206 ___1____________________
207 ____22__________________
208 ______11________________
209 _________1______________
210 __________3_____________
211 ___________44___________
212 _____________33_________
213 _______________2________
214 ________________1_______
215 _________________4______
216 ___________________2____
217 ____________________33__
218 ______________________4_
220 /* if there's only one memory region, don't bother */
226 /* bail out if we find any unreasonable addresses in memmap */
227 for (i = 0; i < old_nr; i++)
228 if (map[i].addr + map[i].size < map[i].addr)
231 /* create pointers for initial change-point information (for sorting) */
232 for (i = 0; i < 2*old_nr; i++)
233 change_point[i] = &change_point_list[i];
235 /* record all known change-points (starting and ending addresses),
236 omitting those that are for empty memory regions */
238 for (i = 0; i < old_nr; i++) {
239 if (map[i].size != 0) {
240 change_point[chgidx]->addr = map[i].addr;
241 change_point[chgidx++]->pentry = &map[i];
242 change_point[chgidx]->addr = map[i].addr + map[i].size;
243 change_point[chgidx++]->pentry = &map[i];
246 chg_nr = chgidx; /* true number of change-points */
248 /* sort change-point list by memory addresses (low -> high) */
250 while (still_changing) {
252 for (i = 1; i < chg_nr; i++) {
253 /* if <current_addr> > <last_addr>, swap */
254 /* or, if current=<start_addr> & last=<end_addr>, swap */
255 if ((change_point[i]->addr < change_point[i-1]->addr) ||
256 ((change_point[i]->addr == change_point[i-1]->addr) &&
257 (change_point[i]->addr == change_point[i]->pentry->addr) &&
258 (change_point[i-1]->addr != change_point[i-1]->pentry->addr))
260 change_tmp = change_point[i];
261 change_point[i] = change_point[i-1];
262 change_point[i-1] = change_tmp;
268 /* create a new memmap, removing overlaps */
269 overlap_entries = 0; /* number of entries in the overlap table */
270 new_entry = 0; /* index for creating new memmap entries */
271 last_type = 0; /* start with undefined memory type */
272 last_addr = 0; /* start with 0 as last starting address */
273 /* loop through change-points, determining affect on the new memmap */
274 for (chgidx = 0; chgidx < chg_nr; chgidx++) {
275 /* keep track of all overlapping memmap entries */
276 if (change_point[chgidx]->addr == change_point[chgidx]->pentry->addr) {
277 /* add map entry to overlap list (> 1 entry implies an overlap) */
278 overlap_list[overlap_entries++] = change_point[chgidx]->pentry;
280 /* remove entry from list (order independent, so swap with last) */
281 for (i = 0; i < overlap_entries; i++) {
282 if (overlap_list[i] == change_point[chgidx]->pentry)
283 overlap_list[i] = overlap_list[overlap_entries-1];
287 /* if there are overlapping entries, decide which "type" to use */
288 /* (larger value takes precedence -- 1=usable, 2,3,4,4+=unusable) */
290 for (i = 0; i < overlap_entries; i++)
291 if (overlap_list[i]->type > current_type)
292 current_type = overlap_list[i]->type;
293 /* continue building up new memmap based on this information */
294 if (current_type != last_type) {
295 if (last_type != 0) {
296 new_map[new_entry].size =
297 change_point[chgidx]->addr - last_addr;
298 /* move forward only if the new size was non-zero */
299 if (new_map[new_entry].size != 0)
300 if (++new_entry >= BFIN_MEMMAP_MAX)
301 break; /* no more space left for new entries */
303 if (current_type != 0) {
304 new_map[new_entry].addr = change_point[chgidx]->addr;
305 new_map[new_entry].type = current_type;
306 last_addr = change_point[chgidx]->addr;
308 last_type = current_type;
311 new_nr = new_entry; /* retain count for new entries */
313 /* copy new mapping into original location */
314 memcpy(map, new_map, new_nr*sizeof(struct bfin_memmap_entry));
320 static void __init print_memory_map(char *who)
324 for (i = 0; i < bfin_memmap.nr_map; i++) {
325 printk(KERN_DEBUG " %s: %016Lx - %016Lx ", who,
326 bfin_memmap.map[i].addr,
327 bfin_memmap.map[i].addr + bfin_memmap.map[i].size);
328 switch (bfin_memmap.map[i].type) {
329 case BFIN_MEMMAP_RAM:
330 printk("(usable)\n");
332 case BFIN_MEMMAP_RESERVED:
333 printk("(reserved)\n");
335 default: printk("type %lu\n", bfin_memmap.map[i].type);
341 static __init int parse_memmap(char *arg)
343 unsigned long long start_at, mem_size;
348 mem_size = memparse(arg, &arg);
350 start_at = memparse(arg+1, &arg);
351 add_memory_region(start_at, mem_size, BFIN_MEMMAP_RAM);
352 } else if (*arg == '$') {
353 start_at = memparse(arg+1, &arg);
354 add_memory_region(start_at, mem_size, BFIN_MEMMAP_RESERVED);
361 * Initial parsing of the command line. Currently, we support:
362 * - Controlling the linux memory size: mem=xxx[KMG]
363 * - Controlling the physical memory size: max_mem=xxx[KMG][$][#]
364 * $ -> reserved memory is dcacheable
365 * # -> reserved memory is icacheable
366 * - "memmap=XXX[KkmM][@][$]XXX[KkmM]" defines a memory region
367 * @ from <start> to <start>+<mem>, type RAM
368 * $ from <start> to <start>+<mem>, type RESERVED
371 static __init void parse_cmdline_early(char *cmdline_p)
373 char c = ' ', *to = cmdline_p;
374 unsigned int memsize;
377 if (!memcmp(to, "mem=", 4)) {
379 memsize = memparse(to, &to);
383 } else if (!memcmp(to, "max_mem=", 8)) {
385 memsize = memparse(to, &to);
387 physical_mem_end = memsize;
391 reserved_mem_dcache_on =
395 reserved_mem_icache_on =
399 } else if (!memcmp(to, "earlyprintk=", 12)) {
401 setup_early_printk(to);
402 } else if (!memcmp(to, "memmap=", 7)) {
414 * Setup memory defaults from user config.
415 * The physical memory layout looks like:
417 * [_rambase, _ramstart]: kernel image
418 * [memory_start, memory_end]: dynamic memory managed by kernel
419 * [memory_end, _ramend]: reserved memory
420 * [meory_mtd_start(memory_end),
421 * memory_mtd_start + mtd_size]: rootfs (if any)
422 * [_ramend - DMA_UNCACHED_REGION,
423 * _ramend]: uncached DMA region
424 * [_ramend, physical_mem_end]: memory not managed by kernel
427 static __init void memory_setup(void)
429 _rambase = (unsigned long)_stext;
430 _ramstart = (unsigned long)_end;
432 if (DMA_UNCACHED_REGION > (_ramend - _ramstart)) {
434 panic("DMA region exceeds memory limit: %lu.\n",
435 _ramend - _ramstart);
437 memory_end = _ramend - DMA_UNCACHED_REGION;
440 /* Round up to multiple of 4MB. */
441 memory_start = (_ramstart + 0x3fffff) & ~0x3fffff;
443 memory_start = PAGE_ALIGN(_ramstart);
446 #if defined(CONFIG_MTD_UCLINUX)
447 /* generic memory mapped MTD driver */
448 memory_mtd_end = memory_end;
450 mtd_phys = _ramstart;
451 mtd_size = PAGE_ALIGN(*((unsigned long *)(mtd_phys + 8)));
453 # if defined(CONFIG_EXT2_FS) || defined(CONFIG_EXT3_FS)
454 if (*((unsigned short *)(mtd_phys + 0x438)) == EXT2_SUPER_MAGIC)
456 PAGE_ALIGN(*((unsigned long *)(mtd_phys + 0x404)) << 10);
459 # if defined(CONFIG_CRAMFS)
460 if (*((unsigned long *)(mtd_phys)) == CRAMFS_MAGIC)
461 mtd_size = PAGE_ALIGN(*((unsigned long *)(mtd_phys + 0x4)));
464 # if defined(CONFIG_ROMFS_FS)
465 if (((unsigned long *)mtd_phys)[0] == ROMSB_WORD0
466 && ((unsigned long *)mtd_phys)[1] == ROMSB_WORD1)
468 PAGE_ALIGN(be32_to_cpu(((unsigned long *)mtd_phys)[2]));
469 # if (defined(CONFIG_BFIN_ICACHE) && ANOMALY_05000263)
470 /* Due to a Hardware Anomaly we need to limit the size of usable
471 * instruction memory to max 60MB, 56 if HUNT_FOR_ZERO is on
472 * 05000263 - Hardware loop corrupted when taking an ICPLB exception
474 # if (defined(CONFIG_DEBUG_HUNT_FOR_ZERO))
475 if (memory_end >= 56 * 1024 * 1024)
476 memory_end = 56 * 1024 * 1024;
478 if (memory_end >= 60 * 1024 * 1024)
479 memory_end = 60 * 1024 * 1024;
480 # endif /* CONFIG_DEBUG_HUNT_FOR_ZERO */
481 # endif /* ANOMALY_05000263 */
482 # endif /* CONFIG_ROMFS_FS */
484 memory_end -= mtd_size;
488 panic("Don't boot kernel without rootfs attached.\n");
491 /* Relocate MTD image to the top of memory after the uncached memory area */
492 dma_memcpy((char *)memory_end, _end, mtd_size);
494 memory_mtd_start = memory_end;
495 _ebss = memory_mtd_start; /* define _ebss for compatible */
496 #endif /* CONFIG_MTD_UCLINUX */
498 #if (defined(CONFIG_BFIN_ICACHE) && ANOMALY_05000263)
499 /* Due to a Hardware Anomaly we need to limit the size of usable
500 * instruction memory to max 60MB, 56 if HUNT_FOR_ZERO is on
501 * 05000263 - Hardware loop corrupted when taking an ICPLB exception
503 #if (defined(CONFIG_DEBUG_HUNT_FOR_ZERO))
504 if (memory_end >= 56 * 1024 * 1024)
505 memory_end = 56 * 1024 * 1024;
507 if (memory_end >= 60 * 1024 * 1024)
508 memory_end = 60 * 1024 * 1024;
509 #endif /* CONFIG_DEBUG_HUNT_FOR_ZERO */
510 printk(KERN_NOTICE "Warning: limiting memory to %liMB due to hardware anomaly 05000263\n", memory_end >> 20);
511 #endif /* ANOMALY_05000263 */
514 page_mask_nelts = ((_ramend >> PAGE_SHIFT) + 31) / 32;
515 page_mask_order = get_order(3 * page_mask_nelts * sizeof(long));
518 #if !defined(CONFIG_MTD_UCLINUX)
519 /*In case there is no valid CPLB behind memory_end make sure we don't get to close*/
520 memory_end -= SIZE_4K;
523 init_mm.start_code = (unsigned long)_stext;
524 init_mm.end_code = (unsigned long)_etext;
525 init_mm.end_data = (unsigned long)_edata;
526 init_mm.brk = (unsigned long)0;
528 printk(KERN_INFO "Board Memory: %ldMB\n", physical_mem_end >> 20);
529 printk(KERN_INFO "Kernel Managed Memory: %ldMB\n", _ramend >> 20);
531 printk(KERN_INFO "Memory map:\n"
532 KERN_INFO " text = 0x%p-0x%p\n"
533 KERN_INFO " rodata = 0x%p-0x%p\n"
534 KERN_INFO " bss = 0x%p-0x%p\n"
535 KERN_INFO " data = 0x%p-0x%p\n"
536 KERN_INFO " stack = 0x%p-0x%p\n"
537 KERN_INFO " init = 0x%p-0x%p\n"
538 KERN_INFO " available = 0x%p-0x%p\n"
539 #ifdef CONFIG_MTD_UCLINUX
540 KERN_INFO " rootfs = 0x%p-0x%p\n"
542 #if DMA_UNCACHED_REGION > 0
543 KERN_INFO " DMA Zone = 0x%p-0x%p\n"
546 __start_rodata, __end_rodata,
547 __bss_start, __bss_stop,
549 (void *)&init_thread_union,
550 (void *)((int)(&init_thread_union) + 0x2000),
551 __init_begin, __init_end,
552 (void *)_ramstart, (void *)memory_end
553 #ifdef CONFIG_MTD_UCLINUX
554 , (void *)memory_mtd_start, (void *)(memory_mtd_start + mtd_size)
556 #if DMA_UNCACHED_REGION > 0
557 , (void *)(_ramend - DMA_UNCACHED_REGION), (void *)(_ramend)
562 static __init void setup_bootmem_allocator(void)
566 unsigned long min_pfn, max_pfn;
567 unsigned long curr_pfn, last_pfn, size;
569 /* mark memory between memory_start and memory_end usable */
570 add_memory_region(memory_start,
571 memory_end - memory_start, BFIN_MEMMAP_RAM);
572 /* sanity check for overlap */
573 sanitize_memmap(bfin_memmap.map, &bfin_memmap.nr_map);
574 print_memory_map("boot memmap");
576 min_pfn = PAGE_OFFSET >> PAGE_SHIFT;
577 max_pfn = memory_end >> PAGE_SHIFT;
580 * give all the memory to the bootmap allocator, tell it to put the
581 * boot mem_map at the start of memory.
583 bootmap_size = init_bootmem_node(NODE_DATA(0),
584 memory_start >> PAGE_SHIFT, /* map goes here */
587 /* register the memmap regions with the bootmem allocator */
588 for (i = 0; i < bfin_memmap.nr_map; i++) {
590 * Reserve usable memory
592 if (bfin_memmap.map[i].type != BFIN_MEMMAP_RAM)
595 * We are rounding up the start address of usable memory:
597 curr_pfn = PFN_UP(bfin_memmap.map[i].addr);
598 if (curr_pfn >= max_pfn)
601 * ... and at the end of the usable range downwards:
603 last_pfn = PFN_DOWN(bfin_memmap.map[i].addr +
604 bfin_memmap.map[i].size);
606 if (last_pfn > max_pfn)
610 * .. finally, did all the rounding and playing
611 * around just make the area go away?
613 if (last_pfn <= curr_pfn)
616 size = last_pfn - curr_pfn;
617 free_bootmem(PFN_PHYS(curr_pfn), PFN_PHYS(size));
620 /* reserve memory before memory_start, including bootmap */
621 reserve_bootmem(PAGE_OFFSET,
622 memory_start + bootmap_size + PAGE_SIZE - 1 - PAGE_OFFSET,
626 void __init setup_arch(char **cmdline_p)
628 unsigned long l1_length, sclk, cclk;
629 #ifdef CONFIG_MTD_UCLINUX
630 unsigned long mtd_phys = 0;
633 #ifdef CONFIG_DUMMY_CONSOLE
634 conswitchp = &dummy_con;
637 #if defined(CONFIG_CMDLINE_BOOL)
638 strncpy(&command_line[0], CONFIG_CMDLINE, sizeof(command_line));
639 command_line[sizeof(command_line) - 1] = 0;
642 /* Keep a copy of command line */
643 *cmdline_p = &command_line[0];
644 memcpy(boot_command_line, command_line, COMMAND_LINE_SIZE);
645 boot_command_line[COMMAND_LINE_SIZE - 1] = '\0';
647 /* setup memory defaults from the user config */
648 physical_mem_end = 0;
649 _ramend = CONFIG_MEM_SIZE * 1024 * 1024;
651 memset(&bfin_memmap, 0, sizeof(bfin_memmap));
653 parse_cmdline_early(&command_line[0]);
655 if (physical_mem_end == 0)
656 physical_mem_end = _ramend;
663 #if !defined(CONFIG_BFIN_KERNEL_CLOCK)
664 if (ANOMALY_05000273 && cclk == sclk)
665 panic("ANOMALY 05000273, SCLK can not be same as CCLK");
669 if (ANOMALY_05000266) {
670 bfin_read_IMDMA_D0_IRQ_STATUS();
671 bfin_read_IMDMA_D1_IRQ_STATUS();
674 printk(KERN_INFO "Hardware Trace ");
675 if (bfin_read_TBUFCTL() & 0x1)
679 if (bfin_read_TBUFCTL() & 0x2)
680 printk("and Enabled\n");
682 printk("and Disabled\n");
684 #if defined(CONFIG_CHR_DEV_FLASH) || defined(CONFIG_BLK_DEV_FLASH)
685 /* we need to initialize the Flashrom device here since we might
686 * do things with flash early on in the boot
691 _bfin_swrst = bfin_read_SWRST();
693 if (_bfin_swrst & RESET_DOUBLE)
694 printk(KERN_INFO "Recovering from Double Fault event\n");
695 else if (_bfin_swrst & RESET_WDOG)
696 printk(KERN_INFO "Recovering from Watchdog event\n");
697 else if (_bfin_swrst & RESET_SOFTWARE)
698 printk(KERN_NOTICE "Reset caused by Software reset\n");
700 printk(KERN_INFO "Blackfin support (C) 2004-2007 Analog Devices, Inc.\n");
701 if (bfin_compiled_revid() == 0xffff)
702 printk(KERN_INFO "Compiled for ADSP-%s Rev any\n", CPU);
703 else if (bfin_compiled_revid() == -1)
704 printk(KERN_INFO "Compiled for ADSP-%s Rev none\n", CPU);
706 printk(KERN_INFO "Compiled for ADSP-%s Rev 0.%d\n", CPU, bfin_compiled_revid());
707 if (bfin_revid() != bfin_compiled_revid()) {
708 if (bfin_compiled_revid() == -1)
709 printk(KERN_ERR "Warning: Compiled for Rev none, but running on Rev %d\n",
711 else if (bfin_compiled_revid() != 0xffff)
712 printk(KERN_ERR "Warning: Compiled for Rev %d, but running on Rev %d\n",
713 bfin_compiled_revid(), bfin_revid());
715 if (bfin_revid() < SUPPORTED_REVID)
716 printk(KERN_ERR "Warning: Unsupported Chip Revision ADSP-%s Rev 0.%d detected\n",
718 printk(KERN_INFO "Blackfin Linux support by http://blackfin.uclinux.org/\n");
720 printk(KERN_INFO "Processor Speed: %lu MHz core clock and %lu MHz System Clock\n",
721 cclk / 1000000, sclk / 1000000);
723 if (ANOMALY_05000273 && (cclk >> 1) <= sclk)
724 printk("\n\n\nANOMALY_05000273: CCLK must be >= 2*SCLK !!!\n\n\n");
726 setup_bootmem_allocator();
730 /* check the size of the l1 area */
731 l1_length = _etext_l1 - _stext_l1;
732 if (l1_length > L1_CODE_LENGTH)
733 panic("L1 code memory overflow\n");
735 l1_length = _ebss_l1 - _sdata_l1;
736 if (l1_length > L1_DATA_A_LENGTH)
737 panic("L1 data memory overflow\n");
739 /* Copy atomic sequences to their fixed location, and sanity check that
740 these locations are the ones that we advertise to userspace. */
741 memcpy((void *)FIXED_CODE_START, &fixed_code_start,
742 FIXED_CODE_END - FIXED_CODE_START);
743 BUG_ON((char *)&sigreturn_stub - (char *)&fixed_code_start
744 != SIGRETURN_STUB - FIXED_CODE_START);
745 BUG_ON((char *)&atomic_xchg32 - (char *)&fixed_code_start
746 != ATOMIC_XCHG32 - FIXED_CODE_START);
747 BUG_ON((char *)&atomic_cas32 - (char *)&fixed_code_start
748 != ATOMIC_CAS32 - FIXED_CODE_START);
749 BUG_ON((char *)&atomic_add32 - (char *)&fixed_code_start
750 != ATOMIC_ADD32 - FIXED_CODE_START);
751 BUG_ON((char *)&atomic_sub32 - (char *)&fixed_code_start
752 != ATOMIC_SUB32 - FIXED_CODE_START);
753 BUG_ON((char *)&atomic_ior32 - (char *)&fixed_code_start
754 != ATOMIC_IOR32 - FIXED_CODE_START);
755 BUG_ON((char *)&atomic_and32 - (char *)&fixed_code_start
756 != ATOMIC_AND32 - FIXED_CODE_START);
757 BUG_ON((char *)&atomic_xor32 - (char *)&fixed_code_start
758 != ATOMIC_XOR32 - FIXED_CODE_START);
759 BUG_ON((char *)&safe_user_instruction - (char *)&fixed_code_start
760 != SAFE_USER_INSTRUCTION - FIXED_CODE_START);
762 init_exception_vectors();
766 static int __init topology_init(void)
770 for_each_possible_cpu(cpu) {
771 struct cpu *c = &per_cpu(cpu_devices, cpu);
773 register_cpu(c, cpu);
779 subsys_initcall(topology_init);
781 static u_long get_vco(void)
786 msel = (bfin_read_PLL_CTL() >> 9) & 0x3F;
790 vco = CONFIG_CLKIN_HZ;
791 vco >>= (1 & bfin_read_PLL_CTL()); /* DF bit */
796 /* Get the Core clock */
797 u_long get_cclk(void)
800 if (bfin_read_PLL_STAT() & 0x1)
801 return CONFIG_CLKIN_HZ;
803 ssel = bfin_read_PLL_DIV();
804 csel = ((ssel >> 4) & 0x03);
806 if (ssel && ssel < (1 << csel)) /* SCLK > CCLK */
807 return get_vco() / ssel;
808 return get_vco() >> csel;
810 EXPORT_SYMBOL(get_cclk);
812 /* Get the System clock */
813 u_long get_sclk(void)
817 if (bfin_read_PLL_STAT() & 0x1)
818 return CONFIG_CLKIN_HZ;
820 ssel = (bfin_read_PLL_DIV() & 0xf);
822 printk(KERN_WARNING "Invalid System Clock\n");
826 return get_vco() / ssel;
828 EXPORT_SYMBOL(get_sclk);
830 unsigned long sclk_to_usecs(unsigned long sclk)
832 u64 tmp = USEC_PER_SEC * (u64)sclk;
833 do_div(tmp, get_sclk());
836 EXPORT_SYMBOL(sclk_to_usecs);
838 unsigned long usecs_to_sclk(unsigned long usecs)
840 u64 tmp = get_sclk() * (u64)usecs;
841 do_div(tmp, USEC_PER_SEC);
844 EXPORT_SYMBOL(usecs_to_sclk);
847 * Get CPU information for use by the procfs.
849 static int show_cpuinfo(struct seq_file *m, void *v)
851 char *cpu, *mmu, *fpu, *vendor, *cache;
854 u_long cclk = 0, sclk = 0;
855 u_int dcache_size = 0, dsup_banks = 0;
860 revid = bfin_revid();
865 switch (bfin_read_CHIPID() & CHIPID_MANUFACTURE) {
867 vendor = "Analog Devices";
874 seq_printf(m, "processor\t: %d\n"
876 "cpu family\t: 0x%x\n"
877 "model name\t: ADSP-%s %lu(MHz CCLK) %lu(MHz SCLK)\n"
881 (bfin_read_CHIPID() & CHIPID_FAMILY),
882 cpu, cclk/1000000, sclk/1000000,
885 seq_printf(m, "cpu MHz\t\t: %lu.%03lu/%lu.%03lu\n",
886 cclk/1000000, cclk%1000000,
887 sclk/1000000, sclk%1000000);
888 seq_printf(m, "bogomips\t: %lu.%02lu\n"
889 "Calibration\t: %lu loops\n",
890 (loops_per_jiffy * HZ) / 500000,
891 ((loops_per_jiffy * HZ) / 5000) % 100,
892 (loops_per_jiffy * HZ));
894 /* Check Cache configutation */
895 switch (bfin_read_DMEM_CONTROL() & (1 << DMC0_P | 1 << DMC1_P)) {
897 cache = "dbank-A/B\t: cache/sram";
902 cache = "dbank-A/B\t: cache/cache";
907 cache = "dbank-A/B\t: sram/sram";
918 /* Is it turned on? */
919 if (!((bfin_read_DMEM_CONTROL()) & (ENDCPLB | DMC_ENABLE)))
922 seq_printf(m, "cache size\t: %d KB(L1 icache) "
923 "%d KB(L1 dcache-%s) %d KB(L2 cache)\n",
924 BFIN_ICACHESIZE / 1024, dcache_size,
925 #if defined CONFIG_BFIN_WB
927 #elif defined CONFIG_BFIN_WT
932 seq_printf(m, "%s\n", cache);
934 seq_printf(m, "icache setup\t: %d Sub-banks/%d Ways, %d Lines/Way\n",
935 BFIN_ISUBBANKS, BFIN_IWAYS, BFIN_ILINES);
937 "dcache setup\t: %d Super-banks/%d Sub-banks/%d Ways, %d Lines/Way\n",
938 dsup_banks, BFIN_DSUBBANKS, BFIN_DWAYS,
940 #ifdef CONFIG_BFIN_ICACHE_LOCK
941 switch (read_iloc()) {
943 seq_printf(m, "Way0 Locked-Down\n");
946 seq_printf(m, "Way1 Locked-Down\n");
949 seq_printf(m, "Way0,Way1 Locked-Down\n");
952 seq_printf(m, "Way2 Locked-Down\n");
955 seq_printf(m, "Way0,Way2 Locked-Down\n");
958 seq_printf(m, "Way1,Way2 Locked-Down\n");
961 seq_printf(m, "Way0,Way1 & Way2 Locked-Down\n");
964 seq_printf(m, "Way3 Locked-Down\n");
967 seq_printf(m, "Way0,Way3 Locked-Down\n");
970 seq_printf(m, "Way1,Way3 Locked-Down\n");
973 seq_printf(m, "Way 0,Way1,Way3 Locked-Down\n");
976 seq_printf(m, "Way3,Way2 Locked-Down\n");
979 seq_printf(m, "Way3,Way2,Way0 Locked-Down\n");
982 seq_printf(m, "Way3,Way2,Way1 Locked-Down\n");
985 seq_printf(m, "All Ways are locked\n");
988 seq_printf(m, "No Ways are locked\n");
992 seq_printf(m, "board name\t: %s\n", bfin_board_name);
993 seq_printf(m, "board memory\t: %ld kB (0x%p -> 0x%p)\n",
994 physical_mem_end >> 10, (void *)0, (void *)physical_mem_end);
995 seq_printf(m, "kernel memory\t: %d kB (0x%p -> 0x%p)\n",
996 ((int)memory_end - (int)_stext) >> 10,
1003 static void *c_start(struct seq_file *m, loff_t *pos)
1005 return *pos < NR_CPUS ? ((void *)0x12345678) : NULL;
1008 static void *c_next(struct seq_file *m, void *v, loff_t *pos)
1011 return c_start(m, pos);
1014 static void c_stop(struct seq_file *m, void *v)
1018 const struct seq_operations cpuinfo_op = {
1022 .show = show_cpuinfo,
1025 void __init cmdline_init(const char *r0)
1028 strncpy(command_line, r0, COMMAND_LINE_SIZE);