]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blob - arch/blackfin/kernel/setup.c
fafaccb321fa03dff4b8be93ee3ce312f73027b7
[linux-2.6-omap-h63xx.git] / arch / blackfin / kernel / setup.c
1 /*
2  * arch/blackfin/kernel/setup.c
3  *
4  * Copyright 2004-2006 Analog Devices Inc.
5  *
6  * Enter bugs at http://blackfin.uclinux.org/
7  *
8  * Licensed under the GPL-2 or later.
9  */
10
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>
19
20 #include <linux/ext2_fs.h>
21 #include <linux/cramfs_fs.h>
22 #include <linux/romfs_fs.h>
23
24 #include <asm/cplb.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>
31
32 static DEFINE_PER_CPU(struct cpu, cpu_devices);
33
34 u16 _bfin_swrst;
35 EXPORT_SYMBOL(_bfin_swrst);
36
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
46 #ifdef CONFIG_MTD_UCLINUX
47 unsigned long memory_mtd_end, memory_mtd_start, mtd_size;
48 unsigned long _ebss;
49 EXPORT_SYMBOL(memory_mtd_end);
50 EXPORT_SYMBOL(memory_mtd_start);
51 EXPORT_SYMBOL(mtd_size);
52 #endif
53
54 char __initdata command_line[COMMAND_LINE_SIZE];
55
56 /* boot memmap, for parsing "memmap=" */
57 #define BFIN_MEMMAP_MAX         128 /* number of entries in bfin_memmap */
58 #define BFIN_MEMMAP_RAM         1
59 #define BFIN_MEMMAP_RESERVED    2
60 struct bfin_memmap {
61         int nr_map;
62         struct bfin_memmap_entry {
63                 unsigned long long addr; /* start of memory segment */
64                 unsigned long long size;
65                 unsigned long type;
66         } map[BFIN_MEMMAP_MAX];
67 } bfin_memmap __initdata;
68
69 /* for memmap sanitization */
70 struct change_member {
71         struct bfin_memmap_entry *pentry; /* pointer to original entry */
72         unsigned long long addr; /* address for this change point */
73 };
74 static struct change_member change_point_list[2*BFIN_MEMMAP_MAX] __initdata;
75 static struct change_member *change_point[2*BFIN_MEMMAP_MAX] __initdata;
76 static struct bfin_memmap_entry *overlap_list[BFIN_MEMMAP_MAX] __initdata;
77 static struct bfin_memmap_entry new_map[BFIN_MEMMAP_MAX] __initdata;
78
79 void __init bf53x_cache_init(void)
80 {
81 #if defined(CONFIG_BFIN_DCACHE) || defined(CONFIG_BFIN_ICACHE)
82         generate_cpl_tables();
83 #endif
84
85 #ifdef CONFIG_BFIN_ICACHE
86         bfin_icache_init();
87         printk(KERN_INFO "Instruction Cache Enabled\n");
88 #endif
89
90 #ifdef CONFIG_BFIN_DCACHE
91         bfin_dcache_init();
92         printk(KERN_INFO "Data Cache Enabled"
93 # if defined CONFIG_BFIN_WB
94                 " (write-back)"
95 # elif defined CONFIG_BFIN_WT
96                 " (write-through)"
97 # endif
98                 "\n");
99 #endif
100 }
101
102 void __init bf53x_relocate_l1_mem(void)
103 {
104         unsigned long l1_code_length;
105         unsigned long l1_data_a_length;
106         unsigned long l1_data_b_length;
107
108         l1_code_length = _etext_l1 - _stext_l1;
109         if (l1_code_length > L1_CODE_LENGTH)
110                 l1_code_length = L1_CODE_LENGTH;
111         /* cannot complain as printk is not available as yet.
112          * But we can continue booting and complain later!
113          */
114
115         /* Copy _stext_l1 to _etext_l1 to L1 instruction SRAM */
116         dma_memcpy(_stext_l1, _l1_lma_start, l1_code_length);
117
118         l1_data_a_length = _ebss_l1 - _sdata_l1;
119         if (l1_data_a_length > L1_DATA_A_LENGTH)
120                 l1_data_a_length = L1_DATA_A_LENGTH;
121
122         /* Copy _sdata_l1 to _ebss_l1 to L1 data bank A SRAM */
123         dma_memcpy(_sdata_l1, _l1_lma_start + l1_code_length, l1_data_a_length);
124
125         l1_data_b_length = _ebss_b_l1 - _sdata_b_l1;
126         if (l1_data_b_length > L1_DATA_B_LENGTH)
127                 l1_data_b_length = L1_DATA_B_LENGTH;
128
129         /* Copy _sdata_b_l1 to _ebss_b_l1 to L1 data bank B SRAM */
130         dma_memcpy(_sdata_b_l1, _l1_lma_start + l1_code_length +
131                         l1_data_a_length, l1_data_b_length);
132
133 }
134
135 /* add_memory_region to memmap */
136 static void __init add_memory_region(unsigned long long start,
137                               unsigned long long size, int type)
138 {
139         int i;
140
141         i = bfin_memmap.nr_map;
142
143         if (i == BFIN_MEMMAP_MAX) {
144                 printk(KERN_ERR "Ooops! Too many entries in the memory map!\n");
145                 return;
146         }
147
148         bfin_memmap.map[i].addr = start;
149         bfin_memmap.map[i].size = size;
150         bfin_memmap.map[i].type = type;
151         bfin_memmap.nr_map++;
152 }
153
154 /*
155  * Sanitize the boot memmap, removing overlaps.
156  */
157 static int __init sanitize_memmap(struct bfin_memmap_entry *map, int *pnr_map)
158 {
159         struct change_member *change_tmp;
160         unsigned long current_type, last_type;
161         unsigned long long last_addr;
162         int chgidx, still_changing;
163         int overlap_entries;
164         int new_entry;
165         int old_nr, new_nr, chg_nr;
166         int i;
167
168         /*
169                 Visually we're performing the following (1,2,3,4 = memory types)
170
171                 Sample memory map (w/overlaps):
172                    ____22__________________
173                    ______________________4_
174                    ____1111________________
175                    _44_____________________
176                    11111111________________
177                    ____________________33__
178                    ___________44___________
179                    __________33333_________
180                    ______________22________
181                    ___________________2222_
182                    _________111111111______
183                    _____________________11_
184                    _________________4______
185
186                 Sanitized equivalent (no overlap):
187                    1_______________________
188                    _44_____________________
189                    ___1____________________
190                    ____22__________________
191                    ______11________________
192                    _________1______________
193                    __________3_____________
194                    ___________44___________
195                    _____________33_________
196                    _______________2________
197                    ________________1_______
198                    _________________4______
199                    ___________________2____
200                    ____________________33__
201                    ______________________4_
202         */
203         /* if there's only one memory region, don't bother */
204         if (*pnr_map < 2)
205                 return -1;
206
207         old_nr = *pnr_map;
208
209         /* bail out if we find any unreasonable addresses in memmap */
210         for (i = 0; i < old_nr; i++)
211                 if (map[i].addr + map[i].size < map[i].addr)
212                         return -1;
213
214         /* create pointers for initial change-point information (for sorting) */
215         for (i = 0; i < 2*old_nr; i++)
216                 change_point[i] = &change_point_list[i];
217
218         /* record all known change-points (starting and ending addresses),
219            omitting those that are for empty memory regions */
220         chgidx = 0;
221         for (i = 0; i < old_nr; i++)    {
222                 if (map[i].size != 0) {
223                         change_point[chgidx]->addr = map[i].addr;
224                         change_point[chgidx++]->pentry = &map[i];
225                         change_point[chgidx]->addr = map[i].addr + map[i].size;
226                         change_point[chgidx++]->pentry = &map[i];
227                 }
228         }
229         chg_nr = chgidx;        /* true number of change-points */
230
231         /* sort change-point list by memory addresses (low -> high) */
232         still_changing = 1;
233         while (still_changing)  {
234                 still_changing = 0;
235                 for (i = 1; i < chg_nr; i++)  {
236                         /* if <current_addr> > <last_addr>, swap */
237                         /* or, if current=<start_addr> & last=<end_addr>, swap */
238                         if ((change_point[i]->addr < change_point[i-1]->addr) ||
239                                 ((change_point[i]->addr == change_point[i-1]->addr) &&
240                                  (change_point[i]->addr == change_point[i]->pentry->addr) &&
241                                  (change_point[i-1]->addr != change_point[i-1]->pentry->addr))
242                            ) {
243                                 change_tmp = change_point[i];
244                                 change_point[i] = change_point[i-1];
245                                 change_point[i-1] = change_tmp;
246                                 still_changing = 1;
247                         }
248                 }
249         }
250
251         /* create a new memmap, removing overlaps */
252         overlap_entries = 0;     /* number of entries in the overlap table */
253         new_entry = 0;   /* index for creating new memmap entries */
254         last_type = 0;           /* start with undefined memory type */
255         last_addr = 0;           /* start with 0 as last starting address */
256         /* loop through change-points, determining affect on the new memmap */
257         for (chgidx = 0; chgidx < chg_nr; chgidx++) {
258                 /* keep track of all overlapping memmap entries */
259                 if (change_point[chgidx]->addr == change_point[chgidx]->pentry->addr) {
260                         /* add map entry to overlap list (> 1 entry implies an overlap) */
261                         overlap_list[overlap_entries++] = change_point[chgidx]->pentry;
262                 } else {
263                         /* remove entry from list (order independent, so swap with last) */
264                         for (i = 0; i < overlap_entries; i++) {
265                                 if (overlap_list[i] == change_point[chgidx]->pentry)
266                                         overlap_list[i] = overlap_list[overlap_entries-1];
267                         }
268                         overlap_entries--;
269                 }
270                 /* if there are overlapping entries, decide which "type" to use */
271                 /* (larger value takes precedence -- 1=usable, 2,3,4,4+=unusable) */
272                 current_type = 0;
273                 for (i = 0; i < overlap_entries; i++)
274                         if (overlap_list[i]->type > current_type)
275                                 current_type = overlap_list[i]->type;
276                 /* continue building up new memmap based on this information */
277                 if (current_type != last_type)  {
278                         if (last_type != 0) {
279                                 new_map[new_entry].size =
280                                         change_point[chgidx]->addr - last_addr;
281                                 /* move forward only if the new size was non-zero */
282                                 if (new_map[new_entry].size != 0)
283                                         if (++new_entry >= BFIN_MEMMAP_MAX)
284                                                 break;  /* no more space left for new entries */
285                         }
286                         if (current_type != 0) {
287                                 new_map[new_entry].addr = change_point[chgidx]->addr;
288                                 new_map[new_entry].type = current_type;
289                                 last_addr = change_point[chgidx]->addr;
290                         }
291                         last_type = current_type;
292                 }
293         }
294         new_nr = new_entry;   /* retain count for new entries */
295
296         /* copy new  mapping into original location */
297         memcpy(map, new_map, new_nr*sizeof(struct bfin_memmap_entry));
298         *pnr_map = new_nr;
299
300         return 0;
301 }
302
303 static void __init print_memory_map(char *who)
304 {
305         int i;
306
307         for (i = 0; i < bfin_memmap.nr_map; i++) {
308                 printk(KERN_DEBUG " %s: %016Lx - %016Lx ", who,
309                         bfin_memmap.map[i].addr,
310                         bfin_memmap.map[i].addr + bfin_memmap.map[i].size);
311                 switch (bfin_memmap.map[i].type) {
312                 case BFIN_MEMMAP_RAM:
313                                 printk("(usable)\n");
314                                 break;
315                 case BFIN_MEMMAP_RESERVED:
316                                 printk("(reserved)\n");
317                                 break;
318                 default:        printk("type %lu\n", bfin_memmap.map[i].type);
319                                 break;
320                 }
321         }
322 }
323
324 static __init int parse_memmap(char *arg)
325 {
326         unsigned long long start_at, mem_size;
327
328         if (!arg)
329                 return -EINVAL;
330
331         mem_size = memparse(arg, &arg);
332         if (*arg == '@') {
333                 start_at = memparse(arg+1, &arg);
334                 add_memory_region(start_at, mem_size, BFIN_MEMMAP_RAM);
335         } else if (*arg == '$') {
336                 start_at = memparse(arg+1, &arg);
337                 add_memory_region(start_at, mem_size, BFIN_MEMMAP_RESERVED);
338         }
339
340         return 0;
341 }
342
343 /*
344  * Initial parsing of the command line.  Currently, we support:
345  *  - Controlling the linux memory size: mem=xxx[KMG]
346  *  - Controlling the physical memory size: max_mem=xxx[KMG][$][#]
347  *       $ -> reserved memory is dcacheable
348  *       # -> reserved memory is icacheable
349  *  - "memmap=XXX[KkmM][@][$]XXX[KkmM]" defines a memory region
350  *       @ from <start> to <start>+<mem>, type RAM
351  *       $ from <start> to <start>+<mem>, type RESERVED
352  *
353  */
354 static __init void parse_cmdline_early(char *cmdline_p)
355 {
356         char c = ' ', *to = cmdline_p;
357         unsigned int memsize;
358         for (;;) {
359                 if (c == ' ') {
360                         if (!memcmp(to, "mem=", 4)) {
361                                 to += 4;
362                                 memsize = memparse(to, &to);
363                                 if (memsize)
364                                         _ramend = memsize;
365
366                         } else if (!memcmp(to, "max_mem=", 8)) {
367                                 to += 8;
368                                 memsize = memparse(to, &to);
369                                 if (memsize) {
370                                         physical_mem_end = memsize;
371                                         if (*to != ' ') {
372                                                 if (*to == '$'
373                                                     || *(to + 1) == '$')
374                                                         reserved_mem_dcache_on =
375                                                             1;
376                                                 if (*to == '#'
377                                                     || *(to + 1) == '#')
378                                                         reserved_mem_icache_on =
379                                                             1;
380                                         }
381                                 }
382                         } else if (!memcmp(to, "earlyprintk=", 12)) {
383                                 to += 12;
384                                 setup_early_printk(to);
385                         } else if (!memcmp(to, "memmap=", 7)) {
386                                 to += 7;
387                                 parse_memmap(to);
388                         }
389                 }
390                 c = *(to++);
391                 if (!c)
392                         break;
393         }
394 }
395
396 /*
397  * Setup memory defaults from user config.
398  * The physical memory layout looks like:
399  *
400  *  [_rambase, _ramstart]:              kernel image
401  *  [memory_start, memory_end]:         dynamic memory managed by kernel
402  *  [memory_end, _ramend]:              reserved memory
403  *      [meory_mtd_start(memory_end),
404  *              memory_mtd_start + mtd_size]:   rootfs (if any)
405  *      [_ramend - DMA_UNCACHED_REGION,
406  *              _ramend]:                       uncached DMA region
407  *  [_ramend, physical_mem_end]:        memory not managed by kernel
408  *
409  */
410 static __init void  memory_setup(void)
411 {
412 #ifdef CONFIG_MTD_UCLINUX
413         unsigned long mtd_phys = 0;
414 #endif
415
416         _rambase = (unsigned long)_stext;
417         _ramstart = (unsigned long)_end;
418
419         if (DMA_UNCACHED_REGION > (_ramend - _ramstart)) {
420                 console_init();
421                 panic("DMA region exceeds memory limit: %lu.\n",
422                         _ramend - _ramstart);
423         }
424         memory_end = _ramend - DMA_UNCACHED_REGION;
425
426 #ifdef CONFIG_MPU
427         /* Round up to multiple of 4MB.  */
428         memory_start = (_ramstart + 0x3fffff) & ~0x3fffff;
429 #else
430         memory_start = PAGE_ALIGN(_ramstart);
431 #endif
432
433 #if defined(CONFIG_MTD_UCLINUX)
434         /* generic memory mapped MTD driver */
435         memory_mtd_end = memory_end;
436
437         mtd_phys = _ramstart;
438         mtd_size = PAGE_ALIGN(*((unsigned long *)(mtd_phys + 8)));
439
440 # if defined(CONFIG_EXT2_FS) || defined(CONFIG_EXT3_FS)
441         if (*((unsigned short *)(mtd_phys + 0x438)) == EXT2_SUPER_MAGIC)
442                 mtd_size =
443                     PAGE_ALIGN(*((unsigned long *)(mtd_phys + 0x404)) << 10);
444 # endif
445
446 # if defined(CONFIG_CRAMFS)
447         if (*((unsigned long *)(mtd_phys)) == CRAMFS_MAGIC)
448                 mtd_size = PAGE_ALIGN(*((unsigned long *)(mtd_phys + 0x4)));
449 # endif
450
451 # if defined(CONFIG_ROMFS_FS)
452         if (((unsigned long *)mtd_phys)[0] == ROMSB_WORD0
453             && ((unsigned long *)mtd_phys)[1] == ROMSB_WORD1)
454                 mtd_size =
455                     PAGE_ALIGN(be32_to_cpu(((unsigned long *)mtd_phys)[2]));
456 #  if (defined(CONFIG_BFIN_ICACHE) && ANOMALY_05000263)
457         /* Due to a Hardware Anomaly we need to limit the size of usable
458          * instruction memory to max 60MB, 56 if HUNT_FOR_ZERO is on
459          * 05000263 - Hardware loop corrupted when taking an ICPLB exception
460          */
461 #   if (defined(CONFIG_DEBUG_HUNT_FOR_ZERO))
462         if (memory_end >= 56 * 1024 * 1024)
463                 memory_end = 56 * 1024 * 1024;
464 #   else
465         if (memory_end >= 60 * 1024 * 1024)
466                 memory_end = 60 * 1024 * 1024;
467 #   endif                               /* CONFIG_DEBUG_HUNT_FOR_ZERO */
468 #  endif                                /* ANOMALY_05000263 */
469 # endif                         /* CONFIG_ROMFS_FS */
470
471         memory_end -= mtd_size;
472
473         if (mtd_size == 0) {
474                 console_init();
475                 panic("Don't boot kernel without rootfs attached.\n");
476         }
477
478         /* Relocate MTD image to the top of memory after the uncached memory area */
479         dma_memcpy((char *)memory_end, _end, mtd_size);
480
481         memory_mtd_start = memory_end;
482         _ebss = memory_mtd_start;       /* define _ebss for compatible */
483 #endif                          /* CONFIG_MTD_UCLINUX */
484
485 #if (defined(CONFIG_BFIN_ICACHE) && ANOMALY_05000263)
486         /* Due to a Hardware Anomaly we need to limit the size of usable
487          * instruction memory to max 60MB, 56 if HUNT_FOR_ZERO is on
488          * 05000263 - Hardware loop corrupted when taking an ICPLB exception
489          */
490 #if (defined(CONFIG_DEBUG_HUNT_FOR_ZERO))
491         if (memory_end >= 56 * 1024 * 1024)
492                 memory_end = 56 * 1024 * 1024;
493 #else
494         if (memory_end >= 60 * 1024 * 1024)
495                 memory_end = 60 * 1024 * 1024;
496 #endif                          /* CONFIG_DEBUG_HUNT_FOR_ZERO */
497         printk(KERN_NOTICE "Warning: limiting memory to %liMB due to hardware anomaly 05000263\n", memory_end >> 20);
498 #endif                          /* ANOMALY_05000263 */
499
500 #ifdef CONFIG_MPU
501         page_mask_nelts = ((_ramend >> PAGE_SHIFT) + 31) / 32;
502         page_mask_order = get_order(3 * page_mask_nelts * sizeof(long));
503 #endif
504
505 #if !defined(CONFIG_MTD_UCLINUX)
506         /*In case there is no valid CPLB behind memory_end make sure we don't get to close*/
507         memory_end -= SIZE_4K;
508 #endif
509
510         init_mm.start_code = (unsigned long)_stext;
511         init_mm.end_code = (unsigned long)_etext;
512         init_mm.end_data = (unsigned long)_edata;
513         init_mm.brk = (unsigned long)0;
514
515         printk(KERN_INFO "Board Memory: %ldMB\n", physical_mem_end >> 20);
516         printk(KERN_INFO "Kernel Managed Memory: %ldMB\n", _ramend >> 20);
517
518         printk(KERN_INFO "Memory map:\n"
519                 KERN_INFO "  fixedcode = 0x%p-0x%p\n"
520                 KERN_INFO "  text      = 0x%p-0x%p\n"
521                 KERN_INFO "  rodata    = 0x%p-0x%p\n"
522                 KERN_INFO "  bss       = 0x%p-0x%p\n"
523                 KERN_INFO "  data      = 0x%p-0x%p\n"
524                 KERN_INFO "    stack   = 0x%p-0x%p\n"
525                 KERN_INFO "  init      = 0x%p-0x%p\n"
526                 KERN_INFO "  available = 0x%p-0x%p\n"
527 #ifdef CONFIG_MTD_UCLINUX
528                 KERN_INFO "  rootfs    = 0x%p-0x%p\n"
529 #endif
530 #if DMA_UNCACHED_REGION > 0
531                 KERN_INFO "  DMA Zone  = 0x%p-0x%p\n"
532 #endif
533                 , (void *)FIXED_CODE_START, (void *)FIXED_CODE_END,
534                 _stext, _etext,
535                 __start_rodata, __end_rodata,
536                 __bss_start, __bss_stop,
537                 _sdata, _edata,
538                 (void *)&init_thread_union,
539                 (void *)((int)(&init_thread_union) + 0x2000),
540                 __init_begin, __init_end,
541                 (void *)_ramstart, (void *)memory_end
542 #ifdef CONFIG_MTD_UCLINUX
543                 , (void *)memory_mtd_start, (void *)(memory_mtd_start + mtd_size)
544 #endif
545 #if DMA_UNCACHED_REGION > 0
546                 , (void *)(_ramend - DMA_UNCACHED_REGION), (void *)(_ramend)
547 #endif
548                 );
549 }
550
551 /*
552  * Find the lowest, highest page frame number we have available
553  */
554 void __init find_min_max_pfn(void)
555 {
556         int i;
557
558         max_pfn = 0;
559         min_low_pfn = memory_end;
560
561         for (i = 0; i < bfin_memmap.nr_map; i++) {
562                 unsigned long start, end;
563                 /* RAM? */
564                 if (bfin_memmap.map[i].type != BFIN_MEMMAP_RAM)
565                         continue;
566                 start = PFN_UP(bfin_memmap.map[i].addr);
567                 end = PFN_DOWN(bfin_memmap.map[i].addr +
568                                 bfin_memmap.map[i].size);
569                 if (start >= end)
570                         continue;
571                 if (end > max_pfn)
572                         max_pfn = end;
573                 if (start < min_low_pfn)
574                         min_low_pfn = start;
575         }
576 }
577
578 static __init void setup_bootmem_allocator(void)
579 {
580         int bootmap_size;
581         int i;
582         unsigned long start_pfn, end_pfn;
583         unsigned long curr_pfn, last_pfn, size;
584
585         /* mark memory between memory_start and memory_end usable */
586         add_memory_region(memory_start,
587                 memory_end - memory_start, BFIN_MEMMAP_RAM);
588         /* sanity check for overlap */
589         sanitize_memmap(bfin_memmap.map, &bfin_memmap.nr_map);
590         print_memory_map("boot memmap");
591
592         /* intialize globals in linux/bootmem.h */
593         find_min_max_pfn();
594         /* pfn of the last usable page frame */
595         if (max_pfn > memory_end >> PAGE_SHIFT)
596                 max_pfn = memory_end >> PAGE_SHIFT;
597         /* pfn of last page frame directly mapped by kernel */
598         max_low_pfn = max_pfn;
599         /* pfn of the first usable page frame after kernel image*/
600         if (min_low_pfn < memory_start >> PAGE_SHIFT)
601                 min_low_pfn = memory_start >> PAGE_SHIFT;
602
603         start_pfn = PAGE_OFFSET >> PAGE_SHIFT;
604         end_pfn = memory_end >> PAGE_SHIFT;
605
606         /*
607          * give all the memory to the bootmap allocator,  tell it to put the
608          * boot mem_map at the start of memory.
609          */
610         bootmap_size = init_bootmem_node(NODE_DATA(0),
611                         memory_start >> PAGE_SHIFT,     /* map goes here */
612                         start_pfn, end_pfn);
613
614         /* register the memmap regions with the bootmem allocator */
615         for (i = 0; i < bfin_memmap.nr_map; i++) {
616                 /*
617                  * Reserve usable memory
618                  */
619                 if (bfin_memmap.map[i].type != BFIN_MEMMAP_RAM)
620                         continue;
621                 /*
622                  * We are rounding up the start address of usable memory:
623                  */
624                 curr_pfn = PFN_UP(bfin_memmap.map[i].addr);
625                 if (curr_pfn >= end_pfn)
626                         continue;
627                 /*
628                  * ... and at the end of the usable range downwards:
629                  */
630                 last_pfn = PFN_DOWN(bfin_memmap.map[i].addr +
631                                          bfin_memmap.map[i].size);
632
633                 if (last_pfn > end_pfn)
634                         last_pfn = end_pfn;
635
636                 /*
637                  * .. finally, did all the rounding and playing
638                  * around just make the area go away?
639                  */
640                 if (last_pfn <= curr_pfn)
641                         continue;
642
643                 size = last_pfn - curr_pfn;
644                 free_bootmem(PFN_PHYS(curr_pfn), PFN_PHYS(size));
645         }
646
647         /* reserve memory before memory_start, including bootmap */
648         reserve_bootmem(PAGE_OFFSET,
649                 memory_start + bootmap_size + PAGE_SIZE - 1 - PAGE_OFFSET,
650                 BOOTMEM_DEFAULT);
651 }
652
653 void __init setup_arch(char **cmdline_p)
654 {
655         unsigned long l1_length, sclk, cclk;
656
657 #ifdef CONFIG_DUMMY_CONSOLE
658         conswitchp = &dummy_con;
659 #endif
660
661 #if defined(CONFIG_CMDLINE_BOOL)
662         strncpy(&command_line[0], CONFIG_CMDLINE, sizeof(command_line));
663         command_line[sizeof(command_line) - 1] = 0;
664 #endif
665
666         /* Keep a copy of command line */
667         *cmdline_p = &command_line[0];
668         memcpy(boot_command_line, command_line, COMMAND_LINE_SIZE);
669         boot_command_line[COMMAND_LINE_SIZE - 1] = '\0';
670
671         /* setup memory defaults from the user config */
672         physical_mem_end = 0;
673         _ramend = CONFIG_MEM_SIZE * 1024 * 1024;
674
675         memset(&bfin_memmap, 0, sizeof(bfin_memmap));
676
677         parse_cmdline_early(&command_line[0]);
678
679         if (physical_mem_end == 0)
680                 physical_mem_end = _ramend;
681
682         memory_setup();
683
684         cclk = get_cclk();
685         sclk = get_sclk();
686
687 #if !defined(CONFIG_BFIN_KERNEL_CLOCK)
688         if (ANOMALY_05000273 && cclk == sclk)
689                 panic("ANOMALY 05000273, SCLK can not be same as CCLK");
690 #endif
691
692 #ifdef BF561_FAMILY
693         if (ANOMALY_05000266) {
694                 bfin_read_IMDMA_D0_IRQ_STATUS();
695                 bfin_read_IMDMA_D1_IRQ_STATUS();
696         }
697 #endif
698         printk(KERN_INFO "Hardware Trace ");
699         if (bfin_read_TBUFCTL() & 0x1)
700                 printk("Active ");
701         else
702                 printk("Off ");
703         if (bfin_read_TBUFCTL() & 0x2)
704                 printk("and Enabled\n");
705         else
706         printk("and Disabled\n");
707
708 #if defined(CONFIG_CHR_DEV_FLASH) || defined(CONFIG_BLK_DEV_FLASH)
709         /* we need to initialize the Flashrom device here since we might
710          * do things with flash early on in the boot
711          */
712         flash_probe();
713 #endif
714
715         _bfin_swrst = bfin_read_SWRST();
716
717         if (_bfin_swrst & RESET_DOUBLE)
718                 printk(KERN_INFO "Recovering from Double Fault event\n");
719         else if (_bfin_swrst & RESET_WDOG)
720                 printk(KERN_INFO "Recovering from Watchdog event\n");
721         else if (_bfin_swrst & RESET_SOFTWARE)
722                 printk(KERN_NOTICE "Reset caused by Software reset\n");
723
724         printk(KERN_INFO "Blackfin support (C) 2004-2008 Analog Devices, Inc.\n");
725         if (bfin_compiled_revid() == 0xffff)
726                 printk(KERN_INFO "Compiled for ADSP-%s Rev any\n", CPU);
727         else if (bfin_compiled_revid() == -1)
728                 printk(KERN_INFO "Compiled for ADSP-%s Rev none\n", CPU);
729         else
730                 printk(KERN_INFO "Compiled for ADSP-%s Rev 0.%d\n", CPU, bfin_compiled_revid());
731         if (bfin_revid() != bfin_compiled_revid()) {
732                 if (bfin_compiled_revid() == -1)
733                         printk(KERN_ERR "Warning: Compiled for Rev none, but running on Rev %d\n",
734                                bfin_revid());
735                 else if (bfin_compiled_revid() != 0xffff)
736                         printk(KERN_ERR "Warning: Compiled for Rev %d, but running on Rev %d\n",
737                                bfin_compiled_revid(), bfin_revid());
738         }
739         if (bfin_revid() < SUPPORTED_REVID)
740                 printk(KERN_ERR "Warning: Unsupported Chip Revision ADSP-%s Rev 0.%d detected\n",
741                        CPU, bfin_revid());
742         printk(KERN_INFO "Blackfin Linux support by http://blackfin.uclinux.org/\n");
743
744         printk(KERN_INFO "Processor Speed: %lu MHz core clock and %lu MHz System Clock\n",
745                cclk / 1000000,  sclk / 1000000);
746
747         if (ANOMALY_05000273 && (cclk >> 1) <= sclk)
748                 printk("\n\n\nANOMALY_05000273: CCLK must be >= 2*SCLK !!!\n\n\n");
749
750         setup_bootmem_allocator();
751
752         paging_init();
753
754         /* check the size of the l1 area */
755         l1_length = _etext_l1 - _stext_l1;
756         if (l1_length > L1_CODE_LENGTH)
757                 panic("L1 code memory overflow\n");
758
759         l1_length = _ebss_l1 - _sdata_l1;
760         if (l1_length > L1_DATA_A_LENGTH)
761                 panic("L1 data memory overflow\n");
762
763         /* Copy atomic sequences to their fixed location, and sanity check that
764            these locations are the ones that we advertise to userspace.  */
765         memcpy((void *)FIXED_CODE_START, &fixed_code_start,
766                FIXED_CODE_END - FIXED_CODE_START);
767         BUG_ON((char *)&sigreturn_stub - (char *)&fixed_code_start
768                != SIGRETURN_STUB - FIXED_CODE_START);
769         BUG_ON((char *)&atomic_xchg32 - (char *)&fixed_code_start
770                != ATOMIC_XCHG32 - FIXED_CODE_START);
771         BUG_ON((char *)&atomic_cas32 - (char *)&fixed_code_start
772                != ATOMIC_CAS32 - FIXED_CODE_START);
773         BUG_ON((char *)&atomic_add32 - (char *)&fixed_code_start
774                != ATOMIC_ADD32 - FIXED_CODE_START);
775         BUG_ON((char *)&atomic_sub32 - (char *)&fixed_code_start
776                != ATOMIC_SUB32 - FIXED_CODE_START);
777         BUG_ON((char *)&atomic_ior32 - (char *)&fixed_code_start
778                != ATOMIC_IOR32 - FIXED_CODE_START);
779         BUG_ON((char *)&atomic_and32 - (char *)&fixed_code_start
780                != ATOMIC_AND32 - FIXED_CODE_START);
781         BUG_ON((char *)&atomic_xor32 - (char *)&fixed_code_start
782                != ATOMIC_XOR32 - FIXED_CODE_START);
783         BUG_ON((char *)&safe_user_instruction - (char *)&fixed_code_start
784                 != SAFE_USER_INSTRUCTION - FIXED_CODE_START);
785
786         init_exception_vectors();
787         bf53x_cache_init();
788 }
789
790 static int __init topology_init(void)
791 {
792         int cpu;
793
794         for_each_possible_cpu(cpu) {
795                 struct cpu *c = &per_cpu(cpu_devices, cpu);
796
797                 register_cpu(c, cpu);
798         }
799
800         return 0;
801 }
802
803 subsys_initcall(topology_init);
804
805 static u_long get_vco(void)
806 {
807         u_long msel;
808         u_long vco;
809
810         msel = (bfin_read_PLL_CTL() >> 9) & 0x3F;
811         if (0 == msel)
812                 msel = 64;
813
814         vco = CONFIG_CLKIN_HZ;
815         vco >>= (1 & bfin_read_PLL_CTL());      /* DF bit */
816         vco = msel * vco;
817         return vco;
818 }
819
820 /* Get the Core clock */
821 u_long get_cclk(void)
822 {
823         u_long csel, ssel;
824         if (bfin_read_PLL_STAT() & 0x1)
825                 return CONFIG_CLKIN_HZ;
826
827         ssel = bfin_read_PLL_DIV();
828         csel = ((ssel >> 4) & 0x03);
829         ssel &= 0xf;
830         if (ssel && ssel < (1 << csel)) /* SCLK > CCLK */
831                 return get_vco() / ssel;
832         return get_vco() >> csel;
833 }
834 EXPORT_SYMBOL(get_cclk);
835
836 /* Get the System clock */
837 u_long get_sclk(void)
838 {
839         u_long ssel;
840
841         if (bfin_read_PLL_STAT() & 0x1)
842                 return CONFIG_CLKIN_HZ;
843
844         ssel = (bfin_read_PLL_DIV() & 0xf);
845         if (0 == ssel) {
846                 printk(KERN_WARNING "Invalid System Clock\n");
847                 ssel = 1;
848         }
849
850         return get_vco() / ssel;
851 }
852 EXPORT_SYMBOL(get_sclk);
853
854 unsigned long sclk_to_usecs(unsigned long sclk)
855 {
856         u64 tmp = USEC_PER_SEC * (u64)sclk;
857         do_div(tmp, get_sclk());
858         return tmp;
859 }
860 EXPORT_SYMBOL(sclk_to_usecs);
861
862 unsigned long usecs_to_sclk(unsigned long usecs)
863 {
864         u64 tmp = get_sclk() * (u64)usecs;
865         do_div(tmp, USEC_PER_SEC);
866         return tmp;
867 }
868 EXPORT_SYMBOL(usecs_to_sclk);
869
870 /*
871  *      Get CPU information for use by the procfs.
872  */
873 static int show_cpuinfo(struct seq_file *m, void *v)
874 {
875         char *cpu, *mmu, *fpu, *vendor, *cache;
876         uint32_t revid;
877
878         u_long cclk = 0, sclk = 0;
879         u_int dcache_size = 0, dsup_banks = 0;
880
881         cpu = CPU;
882         mmu = "none";
883         fpu = "none";
884         revid = bfin_revid();
885
886         cclk = get_cclk();
887         sclk = get_sclk();
888
889         switch (bfin_read_CHIPID() & CHIPID_MANUFACTURE) {
890         case 0xca:
891                 vendor = "Analog Devices";
892                 break;
893         default:
894                 vendor = "unknown";
895                 break;
896         }
897
898         seq_printf(m, "processor\t: %d\n"
899                 "vendor_id\t: %s\n"
900                 "cpu family\t: 0x%x\n"
901                 "model name\t: ADSP-%s %lu(MHz CCLK) %lu(MHz SCLK) (%s)\n"
902                 "stepping\t: %d\n",
903                 0,
904                 vendor,
905                 (bfin_read_CHIPID() & CHIPID_FAMILY),
906                 cpu, cclk/1000000, sclk/1000000,
907 #ifdef CONFIG_MPU
908                 "mpu on",
909 #else
910                 "mpu off",
911 #endif
912                 revid);
913
914         seq_printf(m, "cpu MHz\t\t: %lu.%03lu/%lu.%03lu\n",
915                 cclk/1000000, cclk%1000000,
916                 sclk/1000000, sclk%1000000);
917         seq_printf(m, "bogomips\t: %lu.%02lu\n"
918                 "Calibration\t: %lu loops\n",
919                 (loops_per_jiffy * HZ) / 500000,
920                 ((loops_per_jiffy * HZ) / 5000) % 100,
921                 (loops_per_jiffy * HZ));
922
923         /* Check Cache configutation */
924         switch (bfin_read_DMEM_CONTROL() & (1 << DMC0_P | 1 << DMC1_P)) {
925         case ACACHE_BSRAM:
926                 cache = "dbank-A/B\t: cache/sram";
927                 dcache_size = 16;
928                 dsup_banks = 1;
929                 break;
930         case ACACHE_BCACHE:
931                 cache = "dbank-A/B\t: cache/cache";
932                 dcache_size = 32;
933                 dsup_banks = 2;
934                 break;
935         case ASRAM_BSRAM:
936                 cache = "dbank-A/B\t: sram/sram";
937                 dcache_size = 0;
938                 dsup_banks = 0;
939                 break;
940         default:
941                 cache = "unknown";
942                 dcache_size = 0;
943                 dsup_banks = 0;
944                 break;
945         }
946
947         /* Is it turned on? */
948         if (!((bfin_read_DMEM_CONTROL()) & (ENDCPLB | DMC_ENABLE)))
949                 dcache_size = 0;
950
951         seq_printf(m, "cache size\t: %d KB(L1 icache) "
952                 "%d KB(L1 dcache-%s) %d KB(L2 cache)\n",
953                 BFIN_ICACHESIZE / 1024, dcache_size,
954 #if defined CONFIG_BFIN_WB
955                 "wb"
956 #elif defined CONFIG_BFIN_WT
957                 "wt"
958 #endif
959                 "", 0);
960
961         seq_printf(m, "%s\n", cache);
962
963         seq_printf(m, "icache setup\t: %d Sub-banks/%d Ways, %d Lines/Way\n",
964                    BFIN_ISUBBANKS, BFIN_IWAYS, BFIN_ILINES);
965         seq_printf(m,
966                    "dcache setup\t: %d Super-banks/%d Sub-banks/%d Ways, %d Lines/Way\n",
967                    dsup_banks, BFIN_DSUBBANKS, BFIN_DWAYS,
968                    BFIN_DLINES);
969 #ifdef CONFIG_BFIN_ICACHE_LOCK
970         switch (read_iloc()) {
971         case WAY0_L:
972                 seq_printf(m, "Way0 Locked-Down\n");
973                 break;
974         case WAY1_L:
975                 seq_printf(m, "Way1 Locked-Down\n");
976                 break;
977         case WAY01_L:
978                 seq_printf(m, "Way0,Way1 Locked-Down\n");
979                 break;
980         case WAY2_L:
981                 seq_printf(m, "Way2 Locked-Down\n");
982                 break;
983         case WAY02_L:
984                 seq_printf(m, "Way0,Way2 Locked-Down\n");
985                 break;
986         case WAY12_L:
987                 seq_printf(m, "Way1,Way2 Locked-Down\n");
988                 break;
989         case WAY012_L:
990                 seq_printf(m, "Way0,Way1 & Way2 Locked-Down\n");
991                 break;
992         case WAY3_L:
993                 seq_printf(m, "Way3 Locked-Down\n");
994                 break;
995         case WAY03_L:
996                 seq_printf(m, "Way0,Way3 Locked-Down\n");
997                 break;
998         case WAY13_L:
999                 seq_printf(m, "Way1,Way3 Locked-Down\n");
1000                 break;
1001         case WAY013_L:
1002                 seq_printf(m, "Way 0,Way1,Way3 Locked-Down\n");
1003                 break;
1004         case WAY32_L:
1005                 seq_printf(m, "Way3,Way2 Locked-Down\n");
1006                 break;
1007         case WAY320_L:
1008                 seq_printf(m, "Way3,Way2,Way0 Locked-Down\n");
1009                 break;
1010         case WAY321_L:
1011                 seq_printf(m, "Way3,Way2,Way1 Locked-Down\n");
1012                 break;
1013         case WAYALL_L:
1014                 seq_printf(m, "All Ways are locked\n");
1015                 break;
1016         default:
1017                 seq_printf(m, "No Ways are locked\n");
1018         }
1019 #endif
1020         seq_printf(m, "board name\t: %s\n", bfin_board_name);
1021         seq_printf(m, "board memory\t: %ld kB (0x%p -> 0x%p)\n",
1022                  physical_mem_end >> 10, (void *)0, (void *)physical_mem_end);
1023         seq_printf(m, "kernel memory\t: %d kB (0x%p -> 0x%p)\n",
1024                 ((int)memory_end - (int)_stext) >> 10,
1025                 _stext,
1026                 (void *)memory_end);
1027
1028         return 0;
1029 }
1030
1031 static void *c_start(struct seq_file *m, loff_t *pos)
1032 {
1033         return *pos < NR_CPUS ? ((void *)0x12345678) : NULL;
1034 }
1035
1036 static void *c_next(struct seq_file *m, void *v, loff_t *pos)
1037 {
1038         ++*pos;
1039         return c_start(m, pos);
1040 }
1041
1042 static void c_stop(struct seq_file *m, void *v)
1043 {
1044 }
1045
1046 const struct seq_operations cpuinfo_op = {
1047         .start = c_start,
1048         .next = c_next,
1049         .stop = c_stop,
1050         .show = show_cpuinfo,
1051 };
1052
1053 void __init cmdline_init(const char *r0)
1054 {
1055         if (r0)
1056                 strncpy(command_line, r0, COMMAND_LINE_SIZE);
1057 }