blob: 8d9a40779de1c01de53281a45f973a9d497f0345 [file] [log] [blame]
Bryan Wu1394f032007-05-06 14:50:22 -07001/*
Mike Frysinger550d5532008-02-02 15:55:37 +08002 * arch/blackfin/kernel/setup.c
Bryan Wu1394f032007-05-06 14:50:22 -07003 *
Mike Frysinger550d5532008-02-02 15:55:37 +08004 * Copyright 2004-2006 Analog Devices Inc.
Bryan Wu1394f032007-05-06 14:50:22 -07005 *
Mike Frysinger550d5532008-02-02 15:55:37 +08006 * Enter bugs at http://blackfin.uclinux.org/
Bryan Wu1394f032007-05-06 14:50:22 -07007 *
Mike Frysinger550d5532008-02-02 15:55:37 +08008 * Licensed under the GPL-2 or later.
Bryan Wu1394f032007-05-06 14:50:22 -07009 */
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>
Bryan Wu1394f032007-05-06 14:50:22 -070017#include <linux/tty.h>
Yi Li856783b2008-02-09 02:26:01 +080018#include <linux/pfn.h>
Bryan Wu1394f032007-05-06 14:50:22 -070019
20#include <linux/ext2_fs.h>
21#include <linux/cramfs_fs.h>
22#include <linux/romfs_fs.h>
23
Robin Getz3bebca22007-10-10 23:55:26 +080024#include <asm/cplb.h>
Bryan Wu1394f032007-05-06 14:50:22 -070025#include <asm/cacheflush.h>
26#include <asm/blackfin.h>
27#include <asm/cplbinit.h>
Mike Frysinger1754a5d2007-11-23 11:28:11 +080028#include <asm/div64.h>
Bernd Schmidt7adfb582007-06-21 11:34:16 +080029#include <asm/fixed_code.h>
Robin Getzce3afa12007-10-09 17:28:36 +080030#include <asm/early_printk.h>
Bryan Wu1394f032007-05-06 14:50:22 -070031
Michael Hennerich6cda2e92008-02-02 15:10:51 +080032static DEFINE_PER_CPU(struct cpu, cpu_devices);
33
Mike Frysingera9c59c22007-05-21 18:09:32 +080034u16 _bfin_swrst;
35
Bryan Wu1394f032007-05-06 14:50:22 -070036unsigned long memory_start, memory_end, physical_mem_end;
37unsigned long reserved_mem_dcache_on;
38unsigned long reserved_mem_icache_on;
39EXPORT_SYMBOL(memory_start);
40EXPORT_SYMBOL(memory_end);
41EXPORT_SYMBOL(physical_mem_end);
42EXPORT_SYMBOL(_ramend);
43
44#ifdef CONFIG_MTD_UCLINUX
45unsigned long memory_mtd_end, memory_mtd_start, mtd_size;
46unsigned long _ebss;
47EXPORT_SYMBOL(memory_mtd_end);
48EXPORT_SYMBOL(memory_mtd_start);
49EXPORT_SYMBOL(mtd_size);
50#endif
51
Mike Frysinger5e10b4a2007-06-11 16:44:09 +080052char __initdata command_line[COMMAND_LINE_SIZE];
Bryan Wu1394f032007-05-06 14:50:22 -070053
Yi Li856783b2008-02-09 02:26:01 +080054/* boot memmap, for parsing "memmap=" */
55#define BFIN_MEMMAP_MAX 128 /* number of entries in bfin_memmap */
56#define BFIN_MEMMAP_RAM 1
57#define BFIN_MEMMAP_RESERVED 2
58struct bfin_memmap {
59 int nr_map;
60 struct bfin_memmap_entry {
61 unsigned long long addr; /* start of memory segment */
62 unsigned long long size;
63 unsigned long type;
64 } map[BFIN_MEMMAP_MAX];
65} bfin_memmap __initdata;
66
67/* for memmap sanitization */
68struct change_member {
69 struct bfin_memmap_entry *pentry; /* pointer to original entry */
70 unsigned long long addr; /* address for this change point */
71};
72static struct change_member change_point_list[2*BFIN_MEMMAP_MAX] __initdata;
73static struct change_member *change_point[2*BFIN_MEMMAP_MAX] __initdata;
74static struct bfin_memmap_entry *overlap_list[BFIN_MEMMAP_MAX] __initdata;
75static struct bfin_memmap_entry new_map[BFIN_MEMMAP_MAX] __initdata;
76
Bryan Wu1394f032007-05-06 14:50:22 -070077void __init bf53x_cache_init(void)
78{
Robin Getz3bebca22007-10-10 23:55:26 +080079#if defined(CONFIG_BFIN_DCACHE) || defined(CONFIG_BFIN_ICACHE)
Bryan Wu1394f032007-05-06 14:50:22 -070080 generate_cpl_tables();
81#endif
82
Robin Getz3bebca22007-10-10 23:55:26 +080083#ifdef CONFIG_BFIN_ICACHE
Bryan Wu1394f032007-05-06 14:50:22 -070084 bfin_icache_init();
85 printk(KERN_INFO "Instruction Cache Enabled\n");
86#endif
87
Robin Getz3bebca22007-10-10 23:55:26 +080088#ifdef CONFIG_BFIN_DCACHE
Bryan Wu1394f032007-05-06 14:50:22 -070089 bfin_dcache_init();
90 printk(KERN_INFO "Data Cache Enabled"
Robin Getz3bebca22007-10-10 23:55:26 +080091# if defined CONFIG_BFIN_WB
Bryan Wu1394f032007-05-06 14:50:22 -070092 " (write-back)"
Robin Getz3bebca22007-10-10 23:55:26 +080093# elif defined CONFIG_BFIN_WT
Bryan Wu1394f032007-05-06 14:50:22 -070094 " (write-through)"
95# endif
96 "\n");
97#endif
98}
99
Mike Frysinger52a07812007-06-11 15:31:30 +0800100void __init bf53x_relocate_l1_mem(void)
Bryan Wu1394f032007-05-06 14:50:22 -0700101{
102 unsigned long l1_code_length;
103 unsigned long l1_data_a_length;
104 unsigned long l1_data_b_length;
105
106 l1_code_length = _etext_l1 - _stext_l1;
107 if (l1_code_length > L1_CODE_LENGTH)
108 l1_code_length = L1_CODE_LENGTH;
109 /* cannot complain as printk is not available as yet.
110 * But we can continue booting and complain later!
111 */
112
113 /* Copy _stext_l1 to _etext_l1 to L1 instruction SRAM */
114 dma_memcpy(_stext_l1, _l1_lma_start, l1_code_length);
115
116 l1_data_a_length = _ebss_l1 - _sdata_l1;
117 if (l1_data_a_length > L1_DATA_A_LENGTH)
118 l1_data_a_length = L1_DATA_A_LENGTH;
119
120 /* Copy _sdata_l1 to _ebss_l1 to L1 data bank A SRAM */
121 dma_memcpy(_sdata_l1, _l1_lma_start + l1_code_length, l1_data_a_length);
122
123 l1_data_b_length = _ebss_b_l1 - _sdata_b_l1;
124 if (l1_data_b_length > L1_DATA_B_LENGTH)
125 l1_data_b_length = L1_DATA_B_LENGTH;
126
127 /* Copy _sdata_b_l1 to _ebss_b_l1 to L1 data bank B SRAM */
128 dma_memcpy(_sdata_b_l1, _l1_lma_start + l1_code_length +
129 l1_data_a_length, l1_data_b_length);
130
131}
132
Yi Li856783b2008-02-09 02:26:01 +0800133/* add_memory_region to memmap */
134static void __init add_memory_region(unsigned long long start,
135 unsigned long long size, int type)
136{
137 int i;
138
139 i = bfin_memmap.nr_map;
140
141 if (i == BFIN_MEMMAP_MAX) {
142 printk(KERN_ERR "Ooops! Too many entries in the memory map!\n");
143 return;
144 }
145
146 bfin_memmap.map[i].addr = start;
147 bfin_memmap.map[i].size = size;
148 bfin_memmap.map[i].type = type;
149 bfin_memmap.nr_map++;
150}
151
152/*
153 * Sanitize the boot memmap, removing overlaps.
154 */
155static int __init sanitize_memmap(struct bfin_memmap_entry *map, int *pnr_map)
156{
157 struct change_member *change_tmp;
158 unsigned long current_type, last_type;
159 unsigned long long last_addr;
160 int chgidx, still_changing;
161 int overlap_entries;
162 int new_entry;
163 int old_nr, new_nr, chg_nr;
164 int i;
165
166 /*
167 Visually we're performing the following (1,2,3,4 = memory types)
168
169 Sample memory map (w/overlaps):
170 ____22__________________
171 ______________________4_
172 ____1111________________
173 _44_____________________
174 11111111________________
175 ____________________33__
176 ___________44___________
177 __________33333_________
178 ______________22________
179 ___________________2222_
180 _________111111111______
181 _____________________11_
182 _________________4______
183
184 Sanitized equivalent (no overlap):
185 1_______________________
186 _44_____________________
187 ___1____________________
188 ____22__________________
189 ______11________________
190 _________1______________
191 __________3_____________
192 ___________44___________
193 _____________33_________
194 _______________2________
195 ________________1_______
196 _________________4______
197 ___________________2____
198 ____________________33__
199 ______________________4_
200 */
201 /* if there's only one memory region, don't bother */
202 if (*pnr_map < 2)
203 return -1;
204
205 old_nr = *pnr_map;
206
207 /* bail out if we find any unreasonable addresses in memmap */
208 for (i = 0; i < old_nr; i++)
209 if (map[i].addr + map[i].size < map[i].addr)
210 return -1;
211
212 /* create pointers for initial change-point information (for sorting) */
213 for (i = 0; i < 2*old_nr; i++)
214 change_point[i] = &change_point_list[i];
215
216 /* record all known change-points (starting and ending addresses),
217 omitting those that are for empty memory regions */
218 chgidx = 0;
219 for (i = 0; i < old_nr; i++) {
220 if (map[i].size != 0) {
221 change_point[chgidx]->addr = map[i].addr;
222 change_point[chgidx++]->pentry = &map[i];
223 change_point[chgidx]->addr = map[i].addr + map[i].size;
224 change_point[chgidx++]->pentry = &map[i];
225 }
226 }
227 chg_nr = chgidx; /* true number of change-points */
228
229 /* sort change-point list by memory addresses (low -> high) */
230 still_changing = 1;
231 while (still_changing) {
232 still_changing = 0;
233 for (i = 1; i < chg_nr; i++) {
234 /* if <current_addr> > <last_addr>, swap */
235 /* or, if current=<start_addr> & last=<end_addr>, swap */
236 if ((change_point[i]->addr < change_point[i-1]->addr) ||
237 ((change_point[i]->addr == change_point[i-1]->addr) &&
238 (change_point[i]->addr == change_point[i]->pentry->addr) &&
239 (change_point[i-1]->addr != change_point[i-1]->pentry->addr))
240 ) {
241 change_tmp = change_point[i];
242 change_point[i] = change_point[i-1];
243 change_point[i-1] = change_tmp;
244 still_changing = 1;
245 }
246 }
247 }
248
249 /* create a new memmap, removing overlaps */
250 overlap_entries = 0; /* number of entries in the overlap table */
251 new_entry = 0; /* index for creating new memmap entries */
252 last_type = 0; /* start with undefined memory type */
253 last_addr = 0; /* start with 0 as last starting address */
254 /* loop through change-points, determining affect on the new memmap */
255 for (chgidx = 0; chgidx < chg_nr; chgidx++) {
256 /* keep track of all overlapping memmap entries */
257 if (change_point[chgidx]->addr == change_point[chgidx]->pentry->addr) {
258 /* add map entry to overlap list (> 1 entry implies an overlap) */
259 overlap_list[overlap_entries++] = change_point[chgidx]->pentry;
260 } else {
261 /* remove entry from list (order independent, so swap with last) */
262 for (i = 0; i < overlap_entries; i++) {
263 if (overlap_list[i] == change_point[chgidx]->pentry)
264 overlap_list[i] = overlap_list[overlap_entries-1];
265 }
266 overlap_entries--;
267 }
268 /* if there are overlapping entries, decide which "type" to use */
269 /* (larger value takes precedence -- 1=usable, 2,3,4,4+=unusable) */
270 current_type = 0;
271 for (i = 0; i < overlap_entries; i++)
272 if (overlap_list[i]->type > current_type)
273 current_type = overlap_list[i]->type;
274 /* continue building up new memmap based on this information */
275 if (current_type != last_type) {
276 if (last_type != 0) {
277 new_map[new_entry].size =
278 change_point[chgidx]->addr - last_addr;
279 /* move forward only if the new size was non-zero */
280 if (new_map[new_entry].size != 0)
281 if (++new_entry >= BFIN_MEMMAP_MAX)
282 break; /* no more space left for new entries */
283 }
284 if (current_type != 0) {
285 new_map[new_entry].addr = change_point[chgidx]->addr;
286 new_map[new_entry].type = current_type;
287 last_addr = change_point[chgidx]->addr;
288 }
289 last_type = current_type;
290 }
291 }
292 new_nr = new_entry; /* retain count for new entries */
293
294 /* copy new mapping into original location */
295 memcpy(map, new_map, new_nr*sizeof(struct bfin_memmap_entry));
296 *pnr_map = new_nr;
297
298 return 0;
299}
300
301static void __init print_memory_map(char *who)
302{
303 int i;
304
305 for (i = 0; i < bfin_memmap.nr_map; i++) {
306 printk(KERN_DEBUG " %s: %016Lx - %016Lx ", who,
307 bfin_memmap.map[i].addr,
308 bfin_memmap.map[i].addr + bfin_memmap.map[i].size);
309 switch (bfin_memmap.map[i].type) {
310 case BFIN_MEMMAP_RAM:
311 printk("(usable)\n");
312 break;
313 case BFIN_MEMMAP_RESERVED:
314 printk("(reserved)\n");
315 break;
316 default: printk("type %lu\n", bfin_memmap.map[i].type);
317 break;
318 }
319 }
320}
321
322static __init int parse_memmap(char *arg)
323{
324 unsigned long long start_at, mem_size;
325
326 if (!arg)
327 return -EINVAL;
328
329 mem_size = memparse(arg, &arg);
330 if (*arg == '@') {
331 start_at = memparse(arg+1, &arg);
332 add_memory_region(start_at, mem_size, BFIN_MEMMAP_RAM);
333 } else if (*arg == '$') {
334 start_at = memparse(arg+1, &arg);
335 add_memory_region(start_at, mem_size, BFIN_MEMMAP_RESERVED);
336 }
337
338 return 0;
339}
340
Bryan Wu1394f032007-05-06 14:50:22 -0700341/*
342 * Initial parsing of the command line. Currently, we support:
343 * - Controlling the linux memory size: mem=xxx[KMG]
344 * - Controlling the physical memory size: max_mem=xxx[KMG][$][#]
345 * $ -> reserved memory is dcacheable
346 * # -> reserved memory is icacheable
Yi Li856783b2008-02-09 02:26:01 +0800347 * - "memmap=XXX[KkmM][@][$]XXX[KkmM]" defines a memory region
348 * @ from <start> to <start>+<mem>, type RAM
349 * $ from <start> to <start>+<mem>, type RESERVED
350 *
Bryan Wu1394f032007-05-06 14:50:22 -0700351 */
352static __init void parse_cmdline_early(char *cmdline_p)
353{
354 char c = ' ', *to = cmdline_p;
355 unsigned int memsize;
356 for (;;) {
357 if (c == ' ') {
Bryan Wu1394f032007-05-06 14:50:22 -0700358 if (!memcmp(to, "mem=", 4)) {
359 to += 4;
360 memsize = memparse(to, &to);
361 if (memsize)
362 _ramend = memsize;
363
364 } else if (!memcmp(to, "max_mem=", 8)) {
365 to += 8;
366 memsize = memparse(to, &to);
367 if (memsize) {
368 physical_mem_end = memsize;
369 if (*to != ' ') {
370 if (*to == '$'
371 || *(to + 1) == '$')
372 reserved_mem_dcache_on =
373 1;
374 if (*to == '#'
375 || *(to + 1) == '#')
376 reserved_mem_icache_on =
377 1;
378 }
379 }
Robin Getzce3afa12007-10-09 17:28:36 +0800380 } else if (!memcmp(to, "earlyprintk=", 12)) {
381 to += 12;
382 setup_early_printk(to);
Yi Li856783b2008-02-09 02:26:01 +0800383 } else if (!memcmp(to, "memmap=", 7)) {
384 to += 7;
385 parse_memmap(to);
Bryan Wu1394f032007-05-06 14:50:22 -0700386 }
Bryan Wu1394f032007-05-06 14:50:22 -0700387 }
388 c = *(to++);
389 if (!c)
390 break;
391 }
392}
393
Yi Li856783b2008-02-09 02:26:01 +0800394/*
395 * Setup memory defaults from user config.
396 * The physical memory layout looks like:
397 *
398 * [_rambase, _ramstart]: kernel image
399 * [memory_start, memory_end]: dynamic memory managed by kernel
400 * [memory_end, _ramend]: reserved memory
401 * [meory_mtd_start(memory_end),
402 * memory_mtd_start + mtd_size]: rootfs (if any)
403 * [_ramend - DMA_UNCACHED_REGION,
404 * _ramend]: uncached DMA region
405 * [_ramend, physical_mem_end]: memory not managed by kernel
406 *
407 */
408static __init void memory_setup(void)
Bryan Wu1394f032007-05-06 14:50:22 -0700409{
Yi Li856783b2008-02-09 02:26:01 +0800410 _rambase = (unsigned long)_stext;
Mike Frysingerb7627ac2008-02-02 15:53:17 +0800411 _ramstart = (unsigned long)_end;
Bryan Wu1394f032007-05-06 14:50:22 -0700412
Yi Li856783b2008-02-09 02:26:01 +0800413 if (DMA_UNCACHED_REGION > (_ramend - _ramstart)) {
414 console_init();
415 panic("DMA region exceeds memory limit: %lu.\n",
416 _ramend - _ramstart);
Mike Frysinger1aafd902007-07-25 11:19:14 +0800417 }
Bryan Wu1394f032007-05-06 14:50:22 -0700418 memory_end = _ramend - DMA_UNCACHED_REGION;
419
Bernd Schmidtb97b8a92008-01-27 18:39:16 +0800420#ifdef CONFIG_MPU
421 /* Round up to multiple of 4MB. */
422 memory_start = (_ramstart + 0x3fffff) & ~0x3fffff;
423#else
Bryan Wu1394f032007-05-06 14:50:22 -0700424 memory_start = PAGE_ALIGN(_ramstart);
Bernd Schmidtb97b8a92008-01-27 18:39:16 +0800425#endif
Bryan Wu1394f032007-05-06 14:50:22 -0700426
427#if defined(CONFIG_MTD_UCLINUX)
428 /* generic memory mapped MTD driver */
429 memory_mtd_end = memory_end;
430
431 mtd_phys = _ramstart;
432 mtd_size = PAGE_ALIGN(*((unsigned long *)(mtd_phys + 8)));
433
434# if defined(CONFIG_EXT2_FS) || defined(CONFIG_EXT3_FS)
435 if (*((unsigned short *)(mtd_phys + 0x438)) == EXT2_SUPER_MAGIC)
436 mtd_size =
437 PAGE_ALIGN(*((unsigned long *)(mtd_phys + 0x404)) << 10);
438# endif
439
440# if defined(CONFIG_CRAMFS)
441 if (*((unsigned long *)(mtd_phys)) == CRAMFS_MAGIC)
442 mtd_size = PAGE_ALIGN(*((unsigned long *)(mtd_phys + 0x4)));
443# endif
444
445# if defined(CONFIG_ROMFS_FS)
446 if (((unsigned long *)mtd_phys)[0] == ROMSB_WORD0
447 && ((unsigned long *)mtd_phys)[1] == ROMSB_WORD1)
448 mtd_size =
449 PAGE_ALIGN(be32_to_cpu(((unsigned long *)mtd_phys)[2]));
Robin Getz3bebca22007-10-10 23:55:26 +0800450# if (defined(CONFIG_BFIN_ICACHE) && ANOMALY_05000263)
Bryan Wu1394f032007-05-06 14:50:22 -0700451 /* Due to a Hardware Anomaly we need to limit the size of usable
452 * instruction memory to max 60MB, 56 if HUNT_FOR_ZERO is on
453 * 05000263 - Hardware loop corrupted when taking an ICPLB exception
454 */
455# if (defined(CONFIG_DEBUG_HUNT_FOR_ZERO))
456 if (memory_end >= 56 * 1024 * 1024)
457 memory_end = 56 * 1024 * 1024;
458# else
459 if (memory_end >= 60 * 1024 * 1024)
460 memory_end = 60 * 1024 * 1024;
461# endif /* CONFIG_DEBUG_HUNT_FOR_ZERO */
462# endif /* ANOMALY_05000263 */
463# endif /* CONFIG_ROMFS_FS */
464
465 memory_end -= mtd_size;
466
467 if (mtd_size == 0) {
468 console_init();
469 panic("Don't boot kernel without rootfs attached.\n");
470 }
471
472 /* Relocate MTD image to the top of memory after the uncached memory area */
Mike Frysingerb7627ac2008-02-02 15:53:17 +0800473 dma_memcpy((char *)memory_end, _end, mtd_size);
Bryan Wu1394f032007-05-06 14:50:22 -0700474
475 memory_mtd_start = memory_end;
476 _ebss = memory_mtd_start; /* define _ebss for compatible */
477#endif /* CONFIG_MTD_UCLINUX */
478
Robin Getz3bebca22007-10-10 23:55:26 +0800479#if (defined(CONFIG_BFIN_ICACHE) && ANOMALY_05000263)
Bryan Wu1394f032007-05-06 14:50:22 -0700480 /* Due to a Hardware Anomaly we need to limit the size of usable
481 * instruction memory to max 60MB, 56 if HUNT_FOR_ZERO is on
482 * 05000263 - Hardware loop corrupted when taking an ICPLB exception
483 */
484#if (defined(CONFIG_DEBUG_HUNT_FOR_ZERO))
485 if (memory_end >= 56 * 1024 * 1024)
486 memory_end = 56 * 1024 * 1024;
487#else
488 if (memory_end >= 60 * 1024 * 1024)
489 memory_end = 60 * 1024 * 1024;
490#endif /* CONFIG_DEBUG_HUNT_FOR_ZERO */
491 printk(KERN_NOTICE "Warning: limiting memory to %liMB due to hardware anomaly 05000263\n", memory_end >> 20);
492#endif /* ANOMALY_05000263 */
493
Bernd Schmidtb97b8a92008-01-27 18:39:16 +0800494#ifdef CONFIG_MPU
495 page_mask_nelts = ((_ramend >> PAGE_SHIFT) + 31) / 32;
496 page_mask_order = get_order(3 * page_mask_nelts * sizeof(long));
497#endif
498
Bryan Wu1394f032007-05-06 14:50:22 -0700499#if !defined(CONFIG_MTD_UCLINUX)
Yi Li856783b2008-02-09 02:26:01 +0800500 /*In case there is no valid CPLB behind memory_end make sure we don't get to close*/
501 memory_end -= SIZE_4K;
Bryan Wu1394f032007-05-06 14:50:22 -0700502#endif
Yi Li856783b2008-02-09 02:26:01 +0800503
Bryan Wu1394f032007-05-06 14:50:22 -0700504 init_mm.start_code = (unsigned long)_stext;
505 init_mm.end_code = (unsigned long)_etext;
506 init_mm.end_data = (unsigned long)_edata;
507 init_mm.brk = (unsigned long)0;
508
Yi Li856783b2008-02-09 02:26:01 +0800509 printk(KERN_INFO "Board Memory: %ldMB\n", physical_mem_end >> 20);
510 printk(KERN_INFO "Kernel Managed Memory: %ldMB\n", _ramend >> 20);
511
Mike Frysingerb7627ac2008-02-02 15:53:17 +0800512 printk(KERN_INFO "Memory map:\n"
Yi Li856783b2008-02-09 02:26:01 +0800513 KERN_INFO " text = 0x%p-0x%p\n"
514 KERN_INFO " rodata = 0x%p-0x%p\n"
Mike Frysingerb7627ac2008-02-02 15:53:17 +0800515 KERN_INFO " bss = 0x%p-0x%p\n"
Yi Li856783b2008-02-09 02:26:01 +0800516 KERN_INFO " data = 0x%p-0x%p\n"
517 KERN_INFO " stack = 0x%p-0x%p\n"
518 KERN_INFO " init = 0x%p-0x%p\n"
Yi Li856783b2008-02-09 02:26:01 +0800519 KERN_INFO " available = 0x%p-0x%p\n"
520#ifdef CONFIG_MTD_UCLINUX
521 KERN_INFO " rootfs = 0x%p-0x%p\n"
522#endif
523#if DMA_UNCACHED_REGION > 0
524 KERN_INFO " DMA Zone = 0x%p-0x%p\n"
525#endif
526 , _stext, _etext,
527 __start_rodata, __end_rodata,
Mike Frysingerb7627ac2008-02-02 15:53:17 +0800528 __bss_start, __bss_stop,
Yi Li856783b2008-02-09 02:26:01 +0800529 _sdata, _edata,
530 (void *)&init_thread_union,
531 (void *)((int)(&init_thread_union) + 0x2000),
Mike Frysingerb7627ac2008-02-02 15:53:17 +0800532 __init_begin, __init_end,
533 (void *)_ramstart, (void *)memory_end
Yi Li856783b2008-02-09 02:26:01 +0800534#ifdef CONFIG_MTD_UCLINUX
535 , (void *)memory_mtd_start, (void *)(memory_mtd_start + mtd_size)
536#endif
537#if DMA_UNCACHED_REGION > 0
538 , (void *)(_ramend - DMA_UNCACHED_REGION), (void *)(_ramend)
539#endif
540 );
541}
542
543static __init void setup_bootmem_allocator(void)
544{
545 int bootmap_size;
546 int i;
547 unsigned long min_pfn, max_pfn;
548 unsigned long curr_pfn, last_pfn, size;
549
550 /* mark memory between memory_start and memory_end usable */
551 add_memory_region(memory_start,
552 memory_end - memory_start, BFIN_MEMMAP_RAM);
553 /* sanity check for overlap */
554 sanitize_memmap(bfin_memmap.map, &bfin_memmap.nr_map);
555 print_memory_map("boot memmap");
556
557 min_pfn = PAGE_OFFSET >> PAGE_SHIFT;
558 max_pfn = memory_end >> PAGE_SHIFT;
559
560 /*
561 * give all the memory to the bootmap allocator, tell it to put the
562 * boot mem_map at the start of memory.
563 */
564 bootmap_size = init_bootmem_node(NODE_DATA(0),
565 memory_start >> PAGE_SHIFT, /* map goes here */
566 min_pfn, max_pfn);
567
568 /* register the memmap regions with the bootmem allocator */
569 for (i = 0; i < bfin_memmap.nr_map; i++) {
570 /*
571 * Reserve usable memory
572 */
573 if (bfin_memmap.map[i].type != BFIN_MEMMAP_RAM)
574 continue;
575 /*
576 * We are rounding up the start address of usable memory:
577 */
578 curr_pfn = PFN_UP(bfin_memmap.map[i].addr);
579 if (curr_pfn >= max_pfn)
580 continue;
581 /*
582 * ... and at the end of the usable range downwards:
583 */
584 last_pfn = PFN_DOWN(bfin_memmap.map[i].addr +
585 bfin_memmap.map[i].size);
586
587 if (last_pfn > max_pfn)
588 last_pfn = max_pfn;
589
590 /*
591 * .. finally, did all the rounding and playing
592 * around just make the area go away?
593 */
594 if (last_pfn <= curr_pfn)
595 continue;
596
597 size = last_pfn - curr_pfn;
598 free_bootmem(PFN_PHYS(curr_pfn), PFN_PHYS(size));
599 }
600
601 /* reserve memory before memory_start, including bootmap */
602 reserve_bootmem(PAGE_OFFSET,
603 memory_start + bootmap_size + PAGE_SIZE - 1 - PAGE_OFFSET,
604 BOOTMEM_DEFAULT);
605}
606
607void __init setup_arch(char **cmdline_p)
608{
609 unsigned long l1_length, sclk, cclk;
610#ifdef CONFIG_MTD_UCLINUX
611 unsigned long mtd_phys = 0;
612#endif
613
614#ifdef CONFIG_DUMMY_CONSOLE
615 conswitchp = &dummy_con;
616#endif
617
618#if defined(CONFIG_CMDLINE_BOOL)
619 strncpy(&command_line[0], CONFIG_CMDLINE, sizeof(command_line));
620 command_line[sizeof(command_line) - 1] = 0;
621#endif
622
623 /* Keep a copy of command line */
624 *cmdline_p = &command_line[0];
625 memcpy(boot_command_line, command_line, COMMAND_LINE_SIZE);
626 boot_command_line[COMMAND_LINE_SIZE - 1] = '\0';
627
628 /* setup memory defaults from the user config */
629 physical_mem_end = 0;
630 _ramend = CONFIG_MEM_SIZE * 1024 * 1024;
631
632 memset(&bfin_memmap, 0, sizeof(bfin_memmap));
633
634 parse_cmdline_early(&command_line[0]);
635
636 if (physical_mem_end == 0)
637 physical_mem_end = _ramend;
638
639 memory_setup();
640
641 cclk = get_cclk();
642 sclk = get_sclk();
643
644#if !defined(CONFIG_BFIN_KERNEL_CLOCK)
645 if (ANOMALY_05000273 && cclk == sclk)
646 panic("ANOMALY 05000273, SCLK can not be same as CCLK");
647#endif
648
649#ifdef BF561_FAMILY
650 if (ANOMALY_05000266) {
651 bfin_read_IMDMA_D0_IRQ_STATUS();
652 bfin_read_IMDMA_D1_IRQ_STATUS();
653 }
654#endif
655 printk(KERN_INFO "Hardware Trace ");
656 if (bfin_read_TBUFCTL() & 0x1)
657 printk("Active ");
658 else
659 printk("Off ");
660 if (bfin_read_TBUFCTL() & 0x2)
661 printk("and Enabled\n");
662 else
663 printk("and Disabled\n");
664
665#if defined(CONFIG_CHR_DEV_FLASH) || defined(CONFIG_BLK_DEV_FLASH)
666 /* we need to initialize the Flashrom device here since we might
667 * do things with flash early on in the boot
668 */
669 flash_probe();
670#endif
671
Robin Getz7728ec32007-10-29 18:12:15 +0800672 _bfin_swrst = bfin_read_SWRST();
673
674 if (_bfin_swrst & RESET_DOUBLE)
675 printk(KERN_INFO "Recovering from Double Fault event\n");
676 else if (_bfin_swrst & RESET_WDOG)
677 printk(KERN_INFO "Recovering from Watchdog event\n");
678 else if (_bfin_swrst & RESET_SOFTWARE)
679 printk(KERN_NOTICE "Reset caused by Software reset\n");
680
Mike Frysinger550d5532008-02-02 15:55:37 +0800681 printk(KERN_INFO "Blackfin support (C) 2004-2008 Analog Devices, Inc.\n");
Jie Zhangde3025f2007-06-25 18:04:12 +0800682 if (bfin_compiled_revid() == 0xffff)
683 printk(KERN_INFO "Compiled for ADSP-%s Rev any\n", CPU);
684 else if (bfin_compiled_revid() == -1)
685 printk(KERN_INFO "Compiled for ADSP-%s Rev none\n", CPU);
686 else
687 printk(KERN_INFO "Compiled for ADSP-%s Rev 0.%d\n", CPU, bfin_compiled_revid());
688 if (bfin_revid() != bfin_compiled_revid()) {
689 if (bfin_compiled_revid() == -1)
690 printk(KERN_ERR "Warning: Compiled for Rev none, but running on Rev %d\n",
691 bfin_revid());
692 else if (bfin_compiled_revid() != 0xffff)
693 printk(KERN_ERR "Warning: Compiled for Rev %d, but running on Rev %d\n",
694 bfin_compiled_revid(), bfin_revid());
695 }
Bryan Wu1394f032007-05-06 14:50:22 -0700696 if (bfin_revid() < SUPPORTED_REVID)
697 printk(KERN_ERR "Warning: Unsupported Chip Revision ADSP-%s Rev 0.%d detected\n",
698 CPU, bfin_revid());
699 printk(KERN_INFO "Blackfin Linux support by http://blackfin.uclinux.org/\n");
700
Mike Frysingerb5c0e2e2007-09-12 17:31:59 +0800701 printk(KERN_INFO "Processor Speed: %lu MHz core clock and %lu MHz System Clock\n",
Bryan Wu1394f032007-05-06 14:50:22 -0700702 cclk / 1000000, sclk / 1000000);
703
Mike Frysinger1aafd902007-07-25 11:19:14 +0800704 if (ANOMALY_05000273 && (cclk >> 1) <= sclk)
Bryan Wu1394f032007-05-06 14:50:22 -0700705 printk("\n\n\nANOMALY_05000273: CCLK must be >= 2*SCLK !!!\n\n\n");
Bryan Wu1394f032007-05-06 14:50:22 -0700706
Yi Li856783b2008-02-09 02:26:01 +0800707 setup_bootmem_allocator();
Bryan Wu1394f032007-05-06 14:50:22 -0700708
Bryan Wu1394f032007-05-06 14:50:22 -0700709 paging_init();
710
711 /* check the size of the l1 area */
712 l1_length = _etext_l1 - _stext_l1;
713 if (l1_length > L1_CODE_LENGTH)
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800714 panic("L1 code memory overflow\n");
Bryan Wu1394f032007-05-06 14:50:22 -0700715
716 l1_length = _ebss_l1 - _sdata_l1;
717 if (l1_length > L1_DATA_A_LENGTH)
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800718 panic("L1 data memory overflow\n");
Bryan Wu1394f032007-05-06 14:50:22 -0700719
Bernd Schmidt7adfb582007-06-21 11:34:16 +0800720 /* Copy atomic sequences to their fixed location, and sanity check that
721 these locations are the ones that we advertise to userspace. */
722 memcpy((void *)FIXED_CODE_START, &fixed_code_start,
723 FIXED_CODE_END - FIXED_CODE_START);
724 BUG_ON((char *)&sigreturn_stub - (char *)&fixed_code_start
725 != SIGRETURN_STUB - FIXED_CODE_START);
726 BUG_ON((char *)&atomic_xchg32 - (char *)&fixed_code_start
727 != ATOMIC_XCHG32 - FIXED_CODE_START);
728 BUG_ON((char *)&atomic_cas32 - (char *)&fixed_code_start
729 != ATOMIC_CAS32 - FIXED_CODE_START);
730 BUG_ON((char *)&atomic_add32 - (char *)&fixed_code_start
731 != ATOMIC_ADD32 - FIXED_CODE_START);
732 BUG_ON((char *)&atomic_sub32 - (char *)&fixed_code_start
733 != ATOMIC_SUB32 - FIXED_CODE_START);
734 BUG_ON((char *)&atomic_ior32 - (char *)&fixed_code_start
735 != ATOMIC_IOR32 - FIXED_CODE_START);
736 BUG_ON((char *)&atomic_and32 - (char *)&fixed_code_start
737 != ATOMIC_AND32 - FIXED_CODE_START);
738 BUG_ON((char *)&atomic_xor32 - (char *)&fixed_code_start
739 != ATOMIC_XOR32 - FIXED_CODE_START);
Robin Getz9f336a52007-10-29 18:23:28 +0800740 BUG_ON((char *)&safe_user_instruction - (char *)&fixed_code_start
741 != SAFE_USER_INSTRUCTION - FIXED_CODE_START);
Bernd Schmidt29440a22007-07-12 16:25:29 +0800742
Bernd Schmidt8be80ed2007-07-25 14:44:49 +0800743 init_exception_vectors();
Bernd Schmidt29440a22007-07-12 16:25:29 +0800744 bf53x_cache_init();
Bryan Wu1394f032007-05-06 14:50:22 -0700745}
746
Bryan Wu1394f032007-05-06 14:50:22 -0700747static int __init topology_init(void)
748{
Michael Hennerich6cda2e92008-02-02 15:10:51 +0800749 int cpu;
750
751 for_each_possible_cpu(cpu) {
752 struct cpu *c = &per_cpu(cpu_devices, cpu);
753
754 register_cpu(c, cpu);
755 }
756
Bryan Wu1394f032007-05-06 14:50:22 -0700757 return 0;
Bryan Wu1394f032007-05-06 14:50:22 -0700758}
759
760subsys_initcall(topology_init);
761
Mike Frysinger52a07812007-06-11 15:31:30 +0800762static u_long get_vco(void)
Bryan Wu1394f032007-05-06 14:50:22 -0700763{
764 u_long msel;
765 u_long vco;
766
767 msel = (bfin_read_PLL_CTL() >> 9) & 0x3F;
768 if (0 == msel)
769 msel = 64;
770
771 vco = CONFIG_CLKIN_HZ;
772 vco >>= (1 & bfin_read_PLL_CTL()); /* DF bit */
773 vco = msel * vco;
774 return vco;
775}
776
Mike Frysinger2f6cf7b2007-10-21 22:59:49 +0800777/* Get the Core clock */
Bryan Wu1394f032007-05-06 14:50:22 -0700778u_long get_cclk(void)
779{
780 u_long csel, ssel;
781 if (bfin_read_PLL_STAT() & 0x1)
782 return CONFIG_CLKIN_HZ;
783
784 ssel = bfin_read_PLL_DIV();
785 csel = ((ssel >> 4) & 0x03);
786 ssel &= 0xf;
787 if (ssel && ssel < (1 << csel)) /* SCLK > CCLK */
788 return get_vco() / ssel;
789 return get_vco() >> csel;
790}
Bryan Wu1394f032007-05-06 14:50:22 -0700791EXPORT_SYMBOL(get_cclk);
792
793/* Get the System clock */
794u_long get_sclk(void)
795{
796 u_long ssel;
797
798 if (bfin_read_PLL_STAT() & 0x1)
799 return CONFIG_CLKIN_HZ;
800
801 ssel = (bfin_read_PLL_DIV() & 0xf);
802 if (0 == ssel) {
803 printk(KERN_WARNING "Invalid System Clock\n");
804 ssel = 1;
805 }
806
807 return get_vco() / ssel;
808}
Bryan Wu1394f032007-05-06 14:50:22 -0700809EXPORT_SYMBOL(get_sclk);
810
Mike Frysinger2f6cf7b2007-10-21 22:59:49 +0800811unsigned long sclk_to_usecs(unsigned long sclk)
812{
Mike Frysinger1754a5d2007-11-23 11:28:11 +0800813 u64 tmp = USEC_PER_SEC * (u64)sclk;
814 do_div(tmp, get_sclk());
815 return tmp;
Mike Frysinger2f6cf7b2007-10-21 22:59:49 +0800816}
817EXPORT_SYMBOL(sclk_to_usecs);
818
819unsigned long usecs_to_sclk(unsigned long usecs)
820{
Mike Frysinger1754a5d2007-11-23 11:28:11 +0800821 u64 tmp = get_sclk() * (u64)usecs;
822 do_div(tmp, USEC_PER_SEC);
823 return tmp;
Mike Frysinger2f6cf7b2007-10-21 22:59:49 +0800824}
825EXPORT_SYMBOL(usecs_to_sclk);
826
Bryan Wu1394f032007-05-06 14:50:22 -0700827/*
828 * Get CPU information for use by the procfs.
829 */
830static int show_cpuinfo(struct seq_file *m, void *v)
831{
Mike Frysinger066954a2007-10-21 22:36:06 +0800832 char *cpu, *mmu, *fpu, *vendor, *cache;
Bryan Wu1394f032007-05-06 14:50:22 -0700833 uint32_t revid;
834
835 u_long cclk = 0, sclk = 0;
836 u_int dcache_size = 0, dsup_banks = 0;
837
838 cpu = CPU;
839 mmu = "none";
840 fpu = "none";
841 revid = bfin_revid();
Bryan Wu1394f032007-05-06 14:50:22 -0700842
843 cclk = get_cclk();
844 sclk = get_sclk();
845
Robin Getz73b0c0b2007-10-21 17:03:31 +0800846 switch (bfin_read_CHIPID() & CHIPID_MANUFACTURE) {
Mike Frysinger066954a2007-10-21 22:36:06 +0800847 case 0xca:
848 vendor = "Analog Devices";
Robin Getz73b0c0b2007-10-21 17:03:31 +0800849 break;
850 default:
Mike Frysinger066954a2007-10-21 22:36:06 +0800851 vendor = "unknown";
852 break;
Robin Getz73b0c0b2007-10-21 17:03:31 +0800853 }
Bryan Wu1394f032007-05-06 14:50:22 -0700854
Robin Getz73b0c0b2007-10-21 17:03:31 +0800855 seq_printf(m, "processor\t: %d\n"
856 "vendor_id\t: %s\n"
857 "cpu family\t: 0x%x\n"
858 "model name\t: ADSP-%s %lu(MHz CCLK) %lu(MHz SCLK)\n"
859 "stepping\t: %d\n",
860 0,
861 vendor,
862 (bfin_read_CHIPID() & CHIPID_FAMILY),
863 cpu, cclk/1000000, sclk/1000000,
864 revid);
Bryan Wu1394f032007-05-06 14:50:22 -0700865
Robin Getz73b0c0b2007-10-21 17:03:31 +0800866 seq_printf(m, "cpu MHz\t\t: %lu.%03lu/%lu.%03lu\n",
867 cclk/1000000, cclk%1000000,
868 sclk/1000000, sclk%1000000);
869 seq_printf(m, "bogomips\t: %lu.%02lu\n"
870 "Calibration\t: %lu loops\n",
871 (loops_per_jiffy * HZ) / 500000,
872 ((loops_per_jiffy * HZ) / 5000) % 100,
873 (loops_per_jiffy * HZ));
874
875 /* Check Cache configutation */
Mike Frysinger1f83b8f2007-07-12 22:58:21 +0800876 switch (bfin_read_DMEM_CONTROL() & (1 << DMC0_P | 1 << DMC1_P)) {
877 case ACACHE_BSRAM:
Mike Frysinger066954a2007-10-21 22:36:06 +0800878 cache = "dbank-A/B\t: cache/sram";
Mike Frysinger1f83b8f2007-07-12 22:58:21 +0800879 dcache_size = 16;
880 dsup_banks = 1;
881 break;
882 case ACACHE_BCACHE:
Mike Frysinger066954a2007-10-21 22:36:06 +0800883 cache = "dbank-A/B\t: cache/cache";
Mike Frysinger1f83b8f2007-07-12 22:58:21 +0800884 dcache_size = 32;
885 dsup_banks = 2;
886 break;
887 case ASRAM_BSRAM:
Mike Frysinger066954a2007-10-21 22:36:06 +0800888 cache = "dbank-A/B\t: sram/sram";
Mike Frysinger1f83b8f2007-07-12 22:58:21 +0800889 dcache_size = 0;
890 dsup_banks = 0;
891 break;
892 default:
Mike Frysinger066954a2007-10-21 22:36:06 +0800893 cache = "unknown";
Robin Getz73b0c0b2007-10-21 17:03:31 +0800894 dcache_size = 0;
895 dsup_banks = 0;
Bryan Wu1394f032007-05-06 14:50:22 -0700896 break;
897 }
898
Robin Getz73b0c0b2007-10-21 17:03:31 +0800899 /* Is it turned on? */
900 if (!((bfin_read_DMEM_CONTROL()) & (ENDCPLB | DMC_ENABLE)))
901 dcache_size = 0;
Bryan Wu1394f032007-05-06 14:50:22 -0700902
Robin Getz73b0c0b2007-10-21 17:03:31 +0800903 seq_printf(m, "cache size\t: %d KB(L1 icache) "
904 "%d KB(L1 dcache-%s) %d KB(L2 cache)\n",
905 BFIN_ICACHESIZE / 1024, dcache_size,
906#if defined CONFIG_BFIN_WB
907 "wb"
908#elif defined CONFIG_BFIN_WT
909 "wt"
910#endif
Mike Frysingerda27abb2007-10-22 10:55:35 +0800911 "", 0);
Robin Getz73b0c0b2007-10-21 17:03:31 +0800912
913 seq_printf(m, "%s\n", cache);
914
915 seq_printf(m, "icache setup\t: %d Sub-banks/%d Ways, %d Lines/Way\n",
Robin Getz3bebca22007-10-10 23:55:26 +0800916 BFIN_ISUBBANKS, BFIN_IWAYS, BFIN_ILINES);
Bryan Wu1394f032007-05-06 14:50:22 -0700917 seq_printf(m,
Robin Getz73b0c0b2007-10-21 17:03:31 +0800918 "dcache setup\t: %d Super-banks/%d Sub-banks/%d Ways, %d Lines/Way\n",
Robin Getz3bebca22007-10-10 23:55:26 +0800919 dsup_banks, BFIN_DSUBBANKS, BFIN_DWAYS,
920 BFIN_DLINES);
921#ifdef CONFIG_BFIN_ICACHE_LOCK
Bryan Wu1394f032007-05-06 14:50:22 -0700922 switch (read_iloc()) {
923 case WAY0_L:
924 seq_printf(m, "Way0 Locked-Down\n");
925 break;
926 case WAY1_L:
927 seq_printf(m, "Way1 Locked-Down\n");
928 break;
929 case WAY01_L:
930 seq_printf(m, "Way0,Way1 Locked-Down\n");
931 break;
932 case WAY2_L:
933 seq_printf(m, "Way2 Locked-Down\n");
934 break;
935 case WAY02_L:
936 seq_printf(m, "Way0,Way2 Locked-Down\n");
937 break;
938 case WAY12_L:
939 seq_printf(m, "Way1,Way2 Locked-Down\n");
940 break;
941 case WAY012_L:
942 seq_printf(m, "Way0,Way1 & Way2 Locked-Down\n");
943 break;
944 case WAY3_L:
945 seq_printf(m, "Way3 Locked-Down\n");
946 break;
947 case WAY03_L:
948 seq_printf(m, "Way0,Way3 Locked-Down\n");
949 break;
950 case WAY13_L:
951 seq_printf(m, "Way1,Way3 Locked-Down\n");
952 break;
953 case WAY013_L:
954 seq_printf(m, "Way 0,Way1,Way3 Locked-Down\n");
955 break;
956 case WAY32_L:
957 seq_printf(m, "Way3,Way2 Locked-Down\n");
958 break;
959 case WAY320_L:
960 seq_printf(m, "Way3,Way2,Way0 Locked-Down\n");
961 break;
962 case WAY321_L:
963 seq_printf(m, "Way3,Way2,Way1 Locked-Down\n");
964 break;
965 case WAYALL_L:
966 seq_printf(m, "All Ways are locked\n");
967 break;
968 default:
969 seq_printf(m, "No Ways are locked\n");
970 }
971#endif
Robin Getz73b0c0b2007-10-21 17:03:31 +0800972
Mike Frysinger066954a2007-10-21 22:36:06 +0800973 seq_printf(m, "board name\t: %s\n", bfin_board_name);
Robin Getz73b0c0b2007-10-21 17:03:31 +0800974 seq_printf(m, "board memory\t: %ld kB (0x%p -> 0x%p)\n",
975 physical_mem_end >> 10, (void *)0, (void *)physical_mem_end);
976 seq_printf(m, "kernel memory\t: %d kB (0x%p -> 0x%p)\n",
977 ((int)memory_end - (int)_stext) >> 10,
978 _stext,
979 (void *)memory_end);
980
Bryan Wu1394f032007-05-06 14:50:22 -0700981 return 0;
982}
983
984static void *c_start(struct seq_file *m, loff_t *pos)
985{
986 return *pos < NR_CPUS ? ((void *)0x12345678) : NULL;
987}
988
989static void *c_next(struct seq_file *m, void *v, loff_t *pos)
990{
991 ++*pos;
992 return c_start(m, pos);
993}
994
995static void c_stop(struct seq_file *m, void *v)
996{
997}
998
Jan Engelhardt03a44822008-02-08 04:21:19 -0800999const struct seq_operations cpuinfo_op = {
Bryan Wu1394f032007-05-06 14:50:22 -07001000 .start = c_start,
1001 .next = c_next,
1002 .stop = c_stop,
1003 .show = show_cpuinfo,
1004};
1005
Mike Frysinger5e10b4a2007-06-11 16:44:09 +08001006void __init cmdline_init(const char *r0)
Bryan Wu1394f032007-05-06 14:50:22 -07001007{
1008 if (r0)
Mike Frysinger52a07812007-06-11 15:31:30 +08001009 strncpy(command_line, r0, COMMAND_LINE_SIZE);
Bryan Wu1394f032007-05-06 14:50:22 -07001010}