blob: 7054594831c512ab998d84ab06956fa8affd2fb2 [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;
Mike Frysingerd45118b2008-02-25 12:24:44 +080035EXPORT_SYMBOL(_bfin_swrst);
Mike Frysingera9c59c22007-05-21 18:09:32 +080036
Bryan Wu1394f032007-05-06 14:50:22 -070037unsigned long memory_start, memory_end, physical_mem_end;
Mike Frysinger3132b582008-04-24 05:12:09 +080038unsigned long _rambase, _ramstart, _ramend;
Bryan Wu1394f032007-05-06 14:50:22 -070039unsigned long reserved_mem_dcache_on;
40unsigned long reserved_mem_icache_on;
41EXPORT_SYMBOL(memory_start);
42EXPORT_SYMBOL(memory_end);
43EXPORT_SYMBOL(physical_mem_end);
44EXPORT_SYMBOL(_ramend);
45
46#ifdef CONFIG_MTD_UCLINUX
47unsigned long memory_mtd_end, memory_mtd_start, mtd_size;
48unsigned long _ebss;
49EXPORT_SYMBOL(memory_mtd_end);
50EXPORT_SYMBOL(memory_mtd_start);
51EXPORT_SYMBOL(mtd_size);
52#endif
53
Mike Frysinger5e10b4a2007-06-11 16:44:09 +080054char __initdata command_line[COMMAND_LINE_SIZE];
Robin Getz0c7a6b22008-10-08 16:27:12 +080055void __initdata *init_retx, *init_saved_retx, *init_saved_seqstat,
56 *init_saved_icplb_fault_addr, *init_saved_dcplb_fault_addr;
Bryan Wu1394f032007-05-06 14:50:22 -070057
Yi Li856783b2008-02-09 02:26:01 +080058/* boot memmap, for parsing "memmap=" */
59#define BFIN_MEMMAP_MAX 128 /* number of entries in bfin_memmap */
60#define BFIN_MEMMAP_RAM 1
61#define BFIN_MEMMAP_RESERVED 2
62struct bfin_memmap {
63 int nr_map;
64 struct bfin_memmap_entry {
65 unsigned long long addr; /* start of memory segment */
66 unsigned long long size;
67 unsigned long type;
68 } map[BFIN_MEMMAP_MAX];
69} bfin_memmap __initdata;
70
71/* for memmap sanitization */
72struct change_member {
73 struct bfin_memmap_entry *pentry; /* pointer to original entry */
74 unsigned long long addr; /* address for this change point */
75};
76static struct change_member change_point_list[2*BFIN_MEMMAP_MAX] __initdata;
77static struct change_member *change_point[2*BFIN_MEMMAP_MAX] __initdata;
78static struct bfin_memmap_entry *overlap_list[BFIN_MEMMAP_MAX] __initdata;
79static struct bfin_memmap_entry new_map[BFIN_MEMMAP_MAX] __initdata;
80
Graf Yang5b04f272008-10-08 17:32:57 +080081void __init bfin_cache_init(void)
Bryan Wu1394f032007-05-06 14:50:22 -070082{
Robin Getz3bebca22007-10-10 23:55:26 +080083#if defined(CONFIG_BFIN_DCACHE) || defined(CONFIG_BFIN_ICACHE)
Graf Yang5b04f272008-10-08 17:32:57 +080084 generate_cplb_tables();
Bryan Wu1394f032007-05-06 14:50:22 -070085#endif
86
Robin Getz3bebca22007-10-10 23:55:26 +080087#ifdef CONFIG_BFIN_ICACHE
Bryan Wu1394f032007-05-06 14:50:22 -070088 bfin_icache_init();
89 printk(KERN_INFO "Instruction Cache Enabled\n");
90#endif
91
Robin Getz3bebca22007-10-10 23:55:26 +080092#ifdef CONFIG_BFIN_DCACHE
Bryan Wu1394f032007-05-06 14:50:22 -070093 bfin_dcache_init();
94 printk(KERN_INFO "Data Cache Enabled"
Robin Getz3bebca22007-10-10 23:55:26 +080095# if defined CONFIG_BFIN_WB
Bryan Wu1394f032007-05-06 14:50:22 -070096 " (write-back)"
Robin Getz3bebca22007-10-10 23:55:26 +080097# elif defined CONFIG_BFIN_WT
Bryan Wu1394f032007-05-06 14:50:22 -070098 " (write-through)"
99# endif
100 "\n");
101#endif
102}
103
Graf Yang5b04f272008-10-08 17:32:57 +0800104void __init bfin_relocate_l1_mem(void)
Bryan Wu1394f032007-05-06 14:50:22 -0700105{
106 unsigned long l1_code_length;
107 unsigned long l1_data_a_length;
108 unsigned long l1_data_b_length;
Sonic Zhang262c3822008-07-19 15:42:41 +0800109 unsigned long l2_length;
Bryan Wu1394f032007-05-06 14:50:22 -0700110
111 l1_code_length = _etext_l1 - _stext_l1;
112 if (l1_code_length > L1_CODE_LENGTH)
Sonic Zhangb85b82d2008-04-24 06:13:37 +0800113 panic("L1 Instruction SRAM Overflow\n");
Bryan Wu1394f032007-05-06 14:50:22 -0700114 /* cannot complain as printk is not available as yet.
115 * But we can continue booting and complain later!
116 */
117
118 /* Copy _stext_l1 to _etext_l1 to L1 instruction SRAM */
119 dma_memcpy(_stext_l1, _l1_lma_start, l1_code_length);
120
121 l1_data_a_length = _ebss_l1 - _sdata_l1;
122 if (l1_data_a_length > L1_DATA_A_LENGTH)
Sonic Zhangb85b82d2008-04-24 06:13:37 +0800123 panic("L1 Data SRAM Bank A Overflow\n");
Bryan Wu1394f032007-05-06 14:50:22 -0700124
125 /* Copy _sdata_l1 to _ebss_l1 to L1 data bank A SRAM */
126 dma_memcpy(_sdata_l1, _l1_lma_start + l1_code_length, l1_data_a_length);
127
128 l1_data_b_length = _ebss_b_l1 - _sdata_b_l1;
129 if (l1_data_b_length > L1_DATA_B_LENGTH)
Sonic Zhangb85b82d2008-04-24 06:13:37 +0800130 panic("L1 Data SRAM Bank B Overflow\n");
Bryan Wu1394f032007-05-06 14:50:22 -0700131
132 /* Copy _sdata_b_l1 to _ebss_b_l1 to L1 data bank B SRAM */
133 dma_memcpy(_sdata_b_l1, _l1_lma_start + l1_code_length +
134 l1_data_a_length, l1_data_b_length);
Sonic Zhang262c3822008-07-19 15:42:41 +0800135
Mike Frysinger07aa7be2008-08-13 16:16:11 +0800136 if (L2_LENGTH != 0) {
137 l2_length = _ebss_l2 - _stext_l2;
138 if (l2_length > L2_LENGTH)
139 panic("L2 SRAM Overflow\n");
Sonic Zhang262c3822008-07-19 15:42:41 +0800140
Mike Frysinger07aa7be2008-08-13 16:16:11 +0800141 /* Copy _stext_l2 to _edata_l2 to L2 SRAM */
142 dma_memcpy(_stext_l2, _l2_lma_start, l2_length);
143 }
Bryan Wu1394f032007-05-06 14:50:22 -0700144}
145
Yi Li856783b2008-02-09 02:26:01 +0800146/* add_memory_region to memmap */
147static void __init add_memory_region(unsigned long long start,
148 unsigned long long size, int type)
149{
150 int i;
151
152 i = bfin_memmap.nr_map;
153
154 if (i == BFIN_MEMMAP_MAX) {
155 printk(KERN_ERR "Ooops! Too many entries in the memory map!\n");
156 return;
157 }
158
159 bfin_memmap.map[i].addr = start;
160 bfin_memmap.map[i].size = size;
161 bfin_memmap.map[i].type = type;
162 bfin_memmap.nr_map++;
163}
164
165/*
166 * Sanitize the boot memmap, removing overlaps.
167 */
168static int __init sanitize_memmap(struct bfin_memmap_entry *map, int *pnr_map)
169{
170 struct change_member *change_tmp;
171 unsigned long current_type, last_type;
172 unsigned long long last_addr;
173 int chgidx, still_changing;
174 int overlap_entries;
175 int new_entry;
176 int old_nr, new_nr, chg_nr;
177 int i;
178
179 /*
180 Visually we're performing the following (1,2,3,4 = memory types)
181
182 Sample memory map (w/overlaps):
183 ____22__________________
184 ______________________4_
185 ____1111________________
186 _44_____________________
187 11111111________________
188 ____________________33__
189 ___________44___________
190 __________33333_________
191 ______________22________
192 ___________________2222_
193 _________111111111______
194 _____________________11_
195 _________________4______
196
197 Sanitized equivalent (no overlap):
198 1_______________________
199 _44_____________________
200 ___1____________________
201 ____22__________________
202 ______11________________
203 _________1______________
204 __________3_____________
205 ___________44___________
206 _____________33_________
207 _______________2________
208 ________________1_______
209 _________________4______
210 ___________________2____
211 ____________________33__
212 ______________________4_
213 */
214 /* if there's only one memory region, don't bother */
215 if (*pnr_map < 2)
216 return -1;
217
218 old_nr = *pnr_map;
219
220 /* bail out if we find any unreasonable addresses in memmap */
221 for (i = 0; i < old_nr; i++)
222 if (map[i].addr + map[i].size < map[i].addr)
223 return -1;
224
225 /* create pointers for initial change-point information (for sorting) */
226 for (i = 0; i < 2*old_nr; i++)
227 change_point[i] = &change_point_list[i];
228
229 /* record all known change-points (starting and ending addresses),
230 omitting those that are for empty memory regions */
231 chgidx = 0;
232 for (i = 0; i < old_nr; i++) {
233 if (map[i].size != 0) {
234 change_point[chgidx]->addr = map[i].addr;
235 change_point[chgidx++]->pentry = &map[i];
236 change_point[chgidx]->addr = map[i].addr + map[i].size;
237 change_point[chgidx++]->pentry = &map[i];
238 }
239 }
240 chg_nr = chgidx; /* true number of change-points */
241
242 /* sort change-point list by memory addresses (low -> high) */
243 still_changing = 1;
244 while (still_changing) {
245 still_changing = 0;
246 for (i = 1; i < chg_nr; i++) {
247 /* if <current_addr> > <last_addr>, swap */
248 /* or, if current=<start_addr> & last=<end_addr>, swap */
249 if ((change_point[i]->addr < change_point[i-1]->addr) ||
250 ((change_point[i]->addr == change_point[i-1]->addr) &&
251 (change_point[i]->addr == change_point[i]->pentry->addr) &&
252 (change_point[i-1]->addr != change_point[i-1]->pentry->addr))
253 ) {
254 change_tmp = change_point[i];
255 change_point[i] = change_point[i-1];
256 change_point[i-1] = change_tmp;
257 still_changing = 1;
258 }
259 }
260 }
261
262 /* create a new memmap, removing overlaps */
263 overlap_entries = 0; /* number of entries in the overlap table */
264 new_entry = 0; /* index for creating new memmap entries */
265 last_type = 0; /* start with undefined memory type */
266 last_addr = 0; /* start with 0 as last starting address */
267 /* loop through change-points, determining affect on the new memmap */
268 for (chgidx = 0; chgidx < chg_nr; chgidx++) {
269 /* keep track of all overlapping memmap entries */
270 if (change_point[chgidx]->addr == change_point[chgidx]->pentry->addr) {
271 /* add map entry to overlap list (> 1 entry implies an overlap) */
272 overlap_list[overlap_entries++] = change_point[chgidx]->pentry;
273 } else {
274 /* remove entry from list (order independent, so swap with last) */
275 for (i = 0; i < overlap_entries; i++) {
276 if (overlap_list[i] == change_point[chgidx]->pentry)
277 overlap_list[i] = overlap_list[overlap_entries-1];
278 }
279 overlap_entries--;
280 }
281 /* if there are overlapping entries, decide which "type" to use */
282 /* (larger value takes precedence -- 1=usable, 2,3,4,4+=unusable) */
283 current_type = 0;
284 for (i = 0; i < overlap_entries; i++)
285 if (overlap_list[i]->type > current_type)
286 current_type = overlap_list[i]->type;
287 /* continue building up new memmap based on this information */
288 if (current_type != last_type) {
289 if (last_type != 0) {
290 new_map[new_entry].size =
291 change_point[chgidx]->addr - last_addr;
292 /* move forward only if the new size was non-zero */
293 if (new_map[new_entry].size != 0)
294 if (++new_entry >= BFIN_MEMMAP_MAX)
295 break; /* no more space left for new entries */
296 }
297 if (current_type != 0) {
298 new_map[new_entry].addr = change_point[chgidx]->addr;
299 new_map[new_entry].type = current_type;
300 last_addr = change_point[chgidx]->addr;
301 }
302 last_type = current_type;
303 }
304 }
305 new_nr = new_entry; /* retain count for new entries */
306
307 /* copy new mapping into original location */
308 memcpy(map, new_map, new_nr*sizeof(struct bfin_memmap_entry));
309 *pnr_map = new_nr;
310
311 return 0;
312}
313
314static void __init print_memory_map(char *who)
315{
316 int i;
317
318 for (i = 0; i < bfin_memmap.nr_map; i++) {
319 printk(KERN_DEBUG " %s: %016Lx - %016Lx ", who,
320 bfin_memmap.map[i].addr,
321 bfin_memmap.map[i].addr + bfin_memmap.map[i].size);
322 switch (bfin_memmap.map[i].type) {
323 case BFIN_MEMMAP_RAM:
324 printk("(usable)\n");
325 break;
326 case BFIN_MEMMAP_RESERVED:
327 printk("(reserved)\n");
328 break;
329 default: printk("type %lu\n", bfin_memmap.map[i].type);
330 break;
331 }
332 }
333}
334
335static __init int parse_memmap(char *arg)
336{
337 unsigned long long start_at, mem_size;
338
339 if (!arg)
340 return -EINVAL;
341
342 mem_size = memparse(arg, &arg);
343 if (*arg == '@') {
344 start_at = memparse(arg+1, &arg);
345 add_memory_region(start_at, mem_size, BFIN_MEMMAP_RAM);
346 } else if (*arg == '$') {
347 start_at = memparse(arg+1, &arg);
348 add_memory_region(start_at, mem_size, BFIN_MEMMAP_RESERVED);
349 }
350
351 return 0;
352}
353
Bryan Wu1394f032007-05-06 14:50:22 -0700354/*
355 * Initial parsing of the command line. Currently, we support:
356 * - Controlling the linux memory size: mem=xxx[KMG]
357 * - Controlling the physical memory size: max_mem=xxx[KMG][$][#]
358 * $ -> reserved memory is dcacheable
359 * # -> reserved memory is icacheable
Yi Li856783b2008-02-09 02:26:01 +0800360 * - "memmap=XXX[KkmM][@][$]XXX[KkmM]" defines a memory region
361 * @ from <start> to <start>+<mem>, type RAM
362 * $ from <start> to <start>+<mem>, type RESERVED
363 *
Bryan Wu1394f032007-05-06 14:50:22 -0700364 */
365static __init void parse_cmdline_early(char *cmdline_p)
366{
367 char c = ' ', *to = cmdline_p;
368 unsigned int memsize;
369 for (;;) {
370 if (c == ' ') {
Bryan Wu1394f032007-05-06 14:50:22 -0700371 if (!memcmp(to, "mem=", 4)) {
372 to += 4;
373 memsize = memparse(to, &to);
374 if (memsize)
375 _ramend = memsize;
376
377 } else if (!memcmp(to, "max_mem=", 8)) {
378 to += 8;
379 memsize = memparse(to, &to);
380 if (memsize) {
381 physical_mem_end = memsize;
382 if (*to != ' ') {
383 if (*to == '$'
384 || *(to + 1) == '$')
385 reserved_mem_dcache_on =
386 1;
387 if (*to == '#'
388 || *(to + 1) == '#')
389 reserved_mem_icache_on =
390 1;
391 }
392 }
Robin Getzce3afa12007-10-09 17:28:36 +0800393 } else if (!memcmp(to, "earlyprintk=", 12)) {
394 to += 12;
395 setup_early_printk(to);
Yi Li856783b2008-02-09 02:26:01 +0800396 } else if (!memcmp(to, "memmap=", 7)) {
397 to += 7;
398 parse_memmap(to);
Bryan Wu1394f032007-05-06 14:50:22 -0700399 }
Bryan Wu1394f032007-05-06 14:50:22 -0700400 }
401 c = *(to++);
402 if (!c)
403 break;
404 }
405}
406
Yi Li856783b2008-02-09 02:26:01 +0800407/*
408 * Setup memory defaults from user config.
409 * The physical memory layout looks like:
410 *
411 * [_rambase, _ramstart]: kernel image
412 * [memory_start, memory_end]: dynamic memory managed by kernel
413 * [memory_end, _ramend]: reserved memory
Bryan Wu3094c982008-10-10 21:22:01 +0800414 * [memory_mtd_start(memory_end),
Yi Li856783b2008-02-09 02:26:01 +0800415 * memory_mtd_start + mtd_size]: rootfs (if any)
416 * [_ramend - DMA_UNCACHED_REGION,
417 * _ramend]: uncached DMA region
418 * [_ramend, physical_mem_end]: memory not managed by kernel
419 *
420 */
421static __init void memory_setup(void)
Bryan Wu1394f032007-05-06 14:50:22 -0700422{
Mike Frysingerc0eab3b2008-02-02 15:36:11 +0800423#ifdef CONFIG_MTD_UCLINUX
424 unsigned long mtd_phys = 0;
425#endif
426
Yi Li856783b2008-02-09 02:26:01 +0800427 _rambase = (unsigned long)_stext;
Mike Frysingerb7627ac2008-02-02 15:53:17 +0800428 _ramstart = (unsigned long)_end;
Bryan Wu1394f032007-05-06 14:50:22 -0700429
Yi Li856783b2008-02-09 02:26:01 +0800430 if (DMA_UNCACHED_REGION > (_ramend - _ramstart)) {
431 console_init();
432 panic("DMA region exceeds memory limit: %lu.\n",
433 _ramend - _ramstart);
Mike Frysinger1aafd902007-07-25 11:19:14 +0800434 }
Bryan Wu1394f032007-05-06 14:50:22 -0700435 memory_end = _ramend - DMA_UNCACHED_REGION;
436
Bernd Schmidtb97b8a92008-01-27 18:39:16 +0800437#ifdef CONFIG_MPU
438 /* Round up to multiple of 4MB. */
439 memory_start = (_ramstart + 0x3fffff) & ~0x3fffff;
440#else
Bryan Wu1394f032007-05-06 14:50:22 -0700441 memory_start = PAGE_ALIGN(_ramstart);
Bernd Schmidtb97b8a92008-01-27 18:39:16 +0800442#endif
Bryan Wu1394f032007-05-06 14:50:22 -0700443
444#if defined(CONFIG_MTD_UCLINUX)
445 /* generic memory mapped MTD driver */
446 memory_mtd_end = memory_end;
447
448 mtd_phys = _ramstart;
449 mtd_size = PAGE_ALIGN(*((unsigned long *)(mtd_phys + 8)));
450
451# if defined(CONFIG_EXT2_FS) || defined(CONFIG_EXT3_FS)
452 if (*((unsigned short *)(mtd_phys + 0x438)) == EXT2_SUPER_MAGIC)
453 mtd_size =
454 PAGE_ALIGN(*((unsigned long *)(mtd_phys + 0x404)) << 10);
455# endif
456
457# if defined(CONFIG_CRAMFS)
458 if (*((unsigned long *)(mtd_phys)) == CRAMFS_MAGIC)
459 mtd_size = PAGE_ALIGN(*((unsigned long *)(mtd_phys + 0x4)));
460# endif
461
462# if defined(CONFIG_ROMFS_FS)
463 if (((unsigned long *)mtd_phys)[0] == ROMSB_WORD0
464 && ((unsigned long *)mtd_phys)[1] == ROMSB_WORD1)
465 mtd_size =
466 PAGE_ALIGN(be32_to_cpu(((unsigned long *)mtd_phys)[2]));
Robin Getz3bebca22007-10-10 23:55:26 +0800467# if (defined(CONFIG_BFIN_ICACHE) && ANOMALY_05000263)
Bryan Wu1394f032007-05-06 14:50:22 -0700468 /* Due to a Hardware Anomaly we need to limit the size of usable
469 * instruction memory to max 60MB, 56 if HUNT_FOR_ZERO is on
470 * 05000263 - Hardware loop corrupted when taking an ICPLB exception
471 */
472# if (defined(CONFIG_DEBUG_HUNT_FOR_ZERO))
473 if (memory_end >= 56 * 1024 * 1024)
474 memory_end = 56 * 1024 * 1024;
475# else
476 if (memory_end >= 60 * 1024 * 1024)
477 memory_end = 60 * 1024 * 1024;
478# endif /* CONFIG_DEBUG_HUNT_FOR_ZERO */
479# endif /* ANOMALY_05000263 */
480# endif /* CONFIG_ROMFS_FS */
481
482 memory_end -= mtd_size;
483
484 if (mtd_size == 0) {
485 console_init();
486 panic("Don't boot kernel without rootfs attached.\n");
487 }
488
489 /* Relocate MTD image to the top of memory after the uncached memory area */
Mike Frysingerb7627ac2008-02-02 15:53:17 +0800490 dma_memcpy((char *)memory_end, _end, mtd_size);
Bryan Wu1394f032007-05-06 14:50:22 -0700491
492 memory_mtd_start = memory_end;
493 _ebss = memory_mtd_start; /* define _ebss for compatible */
494#endif /* CONFIG_MTD_UCLINUX */
495
Robin Getz3bebca22007-10-10 23:55:26 +0800496#if (defined(CONFIG_BFIN_ICACHE) && ANOMALY_05000263)
Bryan Wu1394f032007-05-06 14:50:22 -0700497 /* Due to a Hardware Anomaly we need to limit the size of usable
498 * instruction memory to max 60MB, 56 if HUNT_FOR_ZERO is on
499 * 05000263 - Hardware loop corrupted when taking an ICPLB exception
500 */
501#if (defined(CONFIG_DEBUG_HUNT_FOR_ZERO))
502 if (memory_end >= 56 * 1024 * 1024)
503 memory_end = 56 * 1024 * 1024;
504#else
505 if (memory_end >= 60 * 1024 * 1024)
506 memory_end = 60 * 1024 * 1024;
507#endif /* CONFIG_DEBUG_HUNT_FOR_ZERO */
508 printk(KERN_NOTICE "Warning: limiting memory to %liMB due to hardware anomaly 05000263\n", memory_end >> 20);
509#endif /* ANOMALY_05000263 */
510
Bernd Schmidtb97b8a92008-01-27 18:39:16 +0800511#ifdef CONFIG_MPU
512 page_mask_nelts = ((_ramend >> PAGE_SHIFT) + 31) / 32;
513 page_mask_order = get_order(3 * page_mask_nelts * sizeof(long));
514#endif
515
Bryan Wu1394f032007-05-06 14:50:22 -0700516#if !defined(CONFIG_MTD_UCLINUX)
Yi Li856783b2008-02-09 02:26:01 +0800517 /*In case there is no valid CPLB behind memory_end make sure we don't get to close*/
518 memory_end -= SIZE_4K;
Bryan Wu1394f032007-05-06 14:50:22 -0700519#endif
Yi Li856783b2008-02-09 02:26:01 +0800520
Bryan Wu1394f032007-05-06 14:50:22 -0700521 init_mm.start_code = (unsigned long)_stext;
522 init_mm.end_code = (unsigned long)_etext;
523 init_mm.end_data = (unsigned long)_edata;
524 init_mm.brk = (unsigned long)0;
525
Yi Li856783b2008-02-09 02:26:01 +0800526 printk(KERN_INFO "Board Memory: %ldMB\n", physical_mem_end >> 20);
527 printk(KERN_INFO "Kernel Managed Memory: %ldMB\n", _ramend >> 20);
528
Mike Frysingerb7627ac2008-02-02 15:53:17 +0800529 printk(KERN_INFO "Memory map:\n"
Mike Frysinger8929ecf82008-02-22 16:35:20 +0800530 KERN_INFO " fixedcode = 0x%p-0x%p\n"
Yi Li856783b2008-02-09 02:26:01 +0800531 KERN_INFO " text = 0x%p-0x%p\n"
532 KERN_INFO " rodata = 0x%p-0x%p\n"
Mike Frysingerb7627ac2008-02-02 15:53:17 +0800533 KERN_INFO " bss = 0x%p-0x%p\n"
Yi Li856783b2008-02-09 02:26:01 +0800534 KERN_INFO " data = 0x%p-0x%p\n"
535 KERN_INFO " stack = 0x%p-0x%p\n"
536 KERN_INFO " init = 0x%p-0x%p\n"
Yi Li856783b2008-02-09 02:26:01 +0800537 KERN_INFO " available = 0x%p-0x%p\n"
538#ifdef CONFIG_MTD_UCLINUX
539 KERN_INFO " rootfs = 0x%p-0x%p\n"
540#endif
541#if DMA_UNCACHED_REGION > 0
542 KERN_INFO " DMA Zone = 0x%p-0x%p\n"
543#endif
Mike Frysinger8929ecf82008-02-22 16:35:20 +0800544 , (void *)FIXED_CODE_START, (void *)FIXED_CODE_END,
545 _stext, _etext,
Yi Li856783b2008-02-09 02:26:01 +0800546 __start_rodata, __end_rodata,
Mike Frysingerb7627ac2008-02-02 15:53:17 +0800547 __bss_start, __bss_stop,
Yi Li856783b2008-02-09 02:26:01 +0800548 _sdata, _edata,
549 (void *)&init_thread_union,
550 (void *)((int)(&init_thread_union) + 0x2000),
Mike Frysingerb7627ac2008-02-02 15:53:17 +0800551 __init_begin, __init_end,
552 (void *)_ramstart, (void *)memory_end
Yi Li856783b2008-02-09 02:26:01 +0800553#ifdef CONFIG_MTD_UCLINUX
554 , (void *)memory_mtd_start, (void *)(memory_mtd_start + mtd_size)
555#endif
556#if DMA_UNCACHED_REGION > 0
557 , (void *)(_ramend - DMA_UNCACHED_REGION), (void *)(_ramend)
558#endif
559 );
560}
561
Yi Li2e8d7962008-03-26 07:08:12 +0800562/*
563 * Find the lowest, highest page frame number we have available
564 */
565void __init find_min_max_pfn(void)
566{
567 int i;
568
569 max_pfn = 0;
570 min_low_pfn = memory_end;
571
572 for (i = 0; i < bfin_memmap.nr_map; i++) {
573 unsigned long start, end;
574 /* RAM? */
575 if (bfin_memmap.map[i].type != BFIN_MEMMAP_RAM)
576 continue;
577 start = PFN_UP(bfin_memmap.map[i].addr);
578 end = PFN_DOWN(bfin_memmap.map[i].addr +
579 bfin_memmap.map[i].size);
580 if (start >= end)
581 continue;
582 if (end > max_pfn)
583 max_pfn = end;
584 if (start < min_low_pfn)
585 min_low_pfn = start;
586 }
587}
588
Yi Li856783b2008-02-09 02:26:01 +0800589static __init void setup_bootmem_allocator(void)
590{
591 int bootmap_size;
592 int i;
Yi Li2e8d7962008-03-26 07:08:12 +0800593 unsigned long start_pfn, end_pfn;
Yi Li856783b2008-02-09 02:26:01 +0800594 unsigned long curr_pfn, last_pfn, size;
595
596 /* mark memory between memory_start and memory_end usable */
597 add_memory_region(memory_start,
598 memory_end - memory_start, BFIN_MEMMAP_RAM);
599 /* sanity check for overlap */
600 sanitize_memmap(bfin_memmap.map, &bfin_memmap.nr_map);
601 print_memory_map("boot memmap");
602
Yi Li2e8d7962008-03-26 07:08:12 +0800603 /* intialize globals in linux/bootmem.h */
604 find_min_max_pfn();
605 /* pfn of the last usable page frame */
606 if (max_pfn > memory_end >> PAGE_SHIFT)
607 max_pfn = memory_end >> PAGE_SHIFT;
608 /* pfn of last page frame directly mapped by kernel */
609 max_low_pfn = max_pfn;
610 /* pfn of the first usable page frame after kernel image*/
611 if (min_low_pfn < memory_start >> PAGE_SHIFT)
612 min_low_pfn = memory_start >> PAGE_SHIFT;
613
614 start_pfn = PAGE_OFFSET >> PAGE_SHIFT;
615 end_pfn = memory_end >> PAGE_SHIFT;
Yi Li856783b2008-02-09 02:26:01 +0800616
617 /*
618 * give all the memory to the bootmap allocator, tell it to put the
619 * boot mem_map at the start of memory.
620 */
621 bootmap_size = init_bootmem_node(NODE_DATA(0),
622 memory_start >> PAGE_SHIFT, /* map goes here */
Yi Li2e8d7962008-03-26 07:08:12 +0800623 start_pfn, end_pfn);
Yi Li856783b2008-02-09 02:26:01 +0800624
625 /* register the memmap regions with the bootmem allocator */
626 for (i = 0; i < bfin_memmap.nr_map; i++) {
627 /*
628 * Reserve usable memory
629 */
630 if (bfin_memmap.map[i].type != BFIN_MEMMAP_RAM)
631 continue;
632 /*
633 * We are rounding up the start address of usable memory:
634 */
635 curr_pfn = PFN_UP(bfin_memmap.map[i].addr);
Yi Li2e8d7962008-03-26 07:08:12 +0800636 if (curr_pfn >= end_pfn)
Yi Li856783b2008-02-09 02:26:01 +0800637 continue;
638 /*
639 * ... and at the end of the usable range downwards:
640 */
641 last_pfn = PFN_DOWN(bfin_memmap.map[i].addr +
642 bfin_memmap.map[i].size);
643
Yi Li2e8d7962008-03-26 07:08:12 +0800644 if (last_pfn > end_pfn)
645 last_pfn = end_pfn;
Yi Li856783b2008-02-09 02:26:01 +0800646
647 /*
648 * .. finally, did all the rounding and playing
649 * around just make the area go away?
650 */
651 if (last_pfn <= curr_pfn)
652 continue;
653
654 size = last_pfn - curr_pfn;
655 free_bootmem(PFN_PHYS(curr_pfn), PFN_PHYS(size));
656 }
657
658 /* reserve memory before memory_start, including bootmap */
659 reserve_bootmem(PAGE_OFFSET,
660 memory_start + bootmap_size + PAGE_SIZE - 1 - PAGE_OFFSET,
661 BOOTMEM_DEFAULT);
662}
663
Mike Frysingera086ee22008-04-25 02:04:05 +0800664#define EBSZ_TO_MEG(ebsz) \
665({ \
666 int meg = 0; \
667 switch (ebsz & 0xf) { \
668 case 0x1: meg = 16; break; \
669 case 0x3: meg = 32; break; \
670 case 0x5: meg = 64; break; \
671 case 0x7: meg = 128; break; \
672 case 0x9: meg = 256; break; \
673 case 0xb: meg = 512; break; \
674 } \
675 meg; \
676})
677static inline int __init get_mem_size(void)
678{
Michael Hennerich99d95bb2008-07-14 17:04:14 +0800679#if defined(EBIU_SDBCTL)
680# if defined(BF561_FAMILY)
Mike Frysingera086ee22008-04-25 02:04:05 +0800681 int ret = 0;
682 u32 sdbctl = bfin_read_EBIU_SDBCTL();
683 ret += EBSZ_TO_MEG(sdbctl >> 0);
684 ret += EBSZ_TO_MEG(sdbctl >> 8);
685 ret += EBSZ_TO_MEG(sdbctl >> 16);
686 ret += EBSZ_TO_MEG(sdbctl >> 24);
687 return ret;
Michael Hennerich99d95bb2008-07-14 17:04:14 +0800688# else
Mike Frysingera086ee22008-04-25 02:04:05 +0800689 return EBSZ_TO_MEG(bfin_read_EBIU_SDBCTL());
Michael Hennerich99d95bb2008-07-14 17:04:14 +0800690# endif
691#elif defined(EBIU_DDRCTL1)
Michael Hennerich1e780422008-04-25 04:31:23 +0800692 u32 ddrctl = bfin_read_EBIU_DDRCTL1();
693 int ret = 0;
694 switch (ddrctl & 0xc0000) {
695 case DEVSZ_64: ret = 64 / 8;
696 case DEVSZ_128: ret = 128 / 8;
697 case DEVSZ_256: ret = 256 / 8;
698 case DEVSZ_512: ret = 512 / 8;
Mike Frysingera086ee22008-04-25 02:04:05 +0800699 }
Michael Hennerich1e780422008-04-25 04:31:23 +0800700 switch (ddrctl & 0x30000) {
701 case DEVWD_4: ret *= 2;
702 case DEVWD_8: ret *= 2;
703 case DEVWD_16: break;
704 }
Mike Frysingerb1b154e2008-07-26 18:02:05 +0800705 if ((ddrctl & 0xc000) == 0x4000)
706 ret *= 2;
Michael Hennerich1e780422008-04-25 04:31:23 +0800707 return ret;
Mike Frysingera086ee22008-04-25 02:04:05 +0800708#endif
709 BUG();
710}
711
Yi Li856783b2008-02-09 02:26:01 +0800712void __init setup_arch(char **cmdline_p)
713{
Mike Frysinger9f8e8952008-04-24 06:20:11 +0800714 unsigned long sclk, cclk;
Yi Li856783b2008-02-09 02:26:01 +0800715
716#ifdef CONFIG_DUMMY_CONSOLE
717 conswitchp = &dummy_con;
718#endif
719
720#if defined(CONFIG_CMDLINE_BOOL)
721 strncpy(&command_line[0], CONFIG_CMDLINE, sizeof(command_line));
722 command_line[sizeof(command_line) - 1] = 0;
723#endif
724
725 /* Keep a copy of command line */
726 *cmdline_p = &command_line[0];
727 memcpy(boot_command_line, command_line, COMMAND_LINE_SIZE);
728 boot_command_line[COMMAND_LINE_SIZE - 1] = '\0';
729
730 /* setup memory defaults from the user config */
731 physical_mem_end = 0;
Mike Frysingera086ee22008-04-25 02:04:05 +0800732 _ramend = get_mem_size() * 1024 * 1024;
Yi Li856783b2008-02-09 02:26:01 +0800733
734 memset(&bfin_memmap, 0, sizeof(bfin_memmap));
735
736 parse_cmdline_early(&command_line[0]);
737
738 if (physical_mem_end == 0)
739 physical_mem_end = _ramend;
740
741 memory_setup();
742
Mike Frysinger7e64aca2008-08-06 17:17:10 +0800743 /* Initialize Async memory banks */
744 bfin_write_EBIU_AMBCTL0(AMBCTL0VAL);
745 bfin_write_EBIU_AMBCTL1(AMBCTL1VAL);
746 bfin_write_EBIU_AMGCTL(AMGCTLVAL);
747#ifdef CONFIG_EBIU_MBSCTLVAL
748 bfin_write_EBIU_MBSCTL(CONFIG_EBIU_MBSCTLVAL);
749 bfin_write_EBIU_MODE(CONFIG_EBIU_MODEVAL);
750 bfin_write_EBIU_FCTL(CONFIG_EBIU_FCTLVAL);
751#endif
752
Yi Li856783b2008-02-09 02:26:01 +0800753 cclk = get_cclk();
754 sclk = get_sclk();
755
756#if !defined(CONFIG_BFIN_KERNEL_CLOCK)
757 if (ANOMALY_05000273 && cclk == sclk)
758 panic("ANOMALY 05000273, SCLK can not be same as CCLK");
759#endif
760
761#ifdef BF561_FAMILY
762 if (ANOMALY_05000266) {
763 bfin_read_IMDMA_D0_IRQ_STATUS();
764 bfin_read_IMDMA_D1_IRQ_STATUS();
765 }
766#endif
767 printk(KERN_INFO "Hardware Trace ");
768 if (bfin_read_TBUFCTL() & 0x1)
769 printk("Active ");
770 else
771 printk("Off ");
772 if (bfin_read_TBUFCTL() & 0x2)
773 printk("and Enabled\n");
774 else
775 printk("and Disabled\n");
776
777#if defined(CONFIG_CHR_DEV_FLASH) || defined(CONFIG_BLK_DEV_FLASH)
778 /* we need to initialize the Flashrom device here since we might
779 * do things with flash early on in the boot
780 */
781 flash_probe();
782#endif
783
Robin Getz7728ec32007-10-29 18:12:15 +0800784 _bfin_swrst = bfin_read_SWRST();
785
Robin Getz0c7a6b22008-10-08 16:27:12 +0800786#ifdef CONFIG_DEBUG_DOUBLEFAULT_PRINT
787 bfin_write_SWRST(_bfin_swrst & ~DOUBLE_FAULT);
788#endif
789#ifdef CONFIG_DEBUG_DOUBLEFAULT_RESET
790 bfin_write_SWRST(_bfin_swrst | DOUBLE_FAULT);
791#endif
Robin Getz2d200982008-07-26 19:41:40 +0800792
Robin Getz0c7a6b22008-10-08 16:27:12 +0800793 if (_bfin_swrst & RESET_DOUBLE) {
794 printk(KERN_EMERG "Recovering from DOUBLE FAULT event\n");
795#ifdef CONFIG_DEBUG_DOUBLEFAULT
796 /* We assume the crashing kernel, and the current symbol table match */
797 printk(KERN_EMERG " While handling exception (EXCAUSE = 0x%x) at %pF\n",
798 (int)init_saved_seqstat & SEQSTAT_EXCAUSE, init_saved_retx);
799 printk(KERN_NOTICE " DCPLB_FAULT_ADDR: %pF\n", init_saved_dcplb_fault_addr);
800 printk(KERN_NOTICE " ICPLB_FAULT_ADDR: %pF\n", init_saved_icplb_fault_addr);
801#endif
802 printk(KERN_NOTICE " The instruction at %pF caused a double exception\n",
803 init_retx);
804 } else if (_bfin_swrst & RESET_WDOG)
Robin Getz7728ec32007-10-29 18:12:15 +0800805 printk(KERN_INFO "Recovering from Watchdog event\n");
806 else if (_bfin_swrst & RESET_SOFTWARE)
807 printk(KERN_NOTICE "Reset caused by Software reset\n");
808
Mike Frysinger550d5532008-02-02 15:55:37 +0800809 printk(KERN_INFO "Blackfin support (C) 2004-2008 Analog Devices, Inc.\n");
Jie Zhangde3025f2007-06-25 18:04:12 +0800810 if (bfin_compiled_revid() == 0xffff)
811 printk(KERN_INFO "Compiled for ADSP-%s Rev any\n", CPU);
812 else if (bfin_compiled_revid() == -1)
813 printk(KERN_INFO "Compiled for ADSP-%s Rev none\n", CPU);
814 else
815 printk(KERN_INFO "Compiled for ADSP-%s Rev 0.%d\n", CPU, bfin_compiled_revid());
Robin Getze482cad2008-10-10 18:21:45 +0800816
817 if (unlikely(CPUID != bfin_cpuid()))
818 printk(KERN_ERR "ERROR: Not running on ADSP-%s: unknown CPUID 0x%04x Rev 0.%d\n",
819 CPU, bfin_cpuid(), bfin_revid());
820 else {
821 if (bfin_revid() != bfin_compiled_revid()) {
822 if (bfin_compiled_revid() == -1)
823 printk(KERN_ERR "Warning: Compiled for Rev none, but running on Rev %d\n",
824 bfin_revid());
825 else if (bfin_compiled_revid() != 0xffff)
826 printk(KERN_ERR "Warning: Compiled for Rev %d, but running on Rev %d\n",
827 bfin_compiled_revid(), bfin_revid());
828 }
829 if (bfin_revid() <= CONFIG_BF_REV_MIN || bfin_revid() > CONFIG_BF_REV_MAX)
830 printk(KERN_ERR "Warning: Unsupported Chip Revision ADSP-%s Rev 0.%d detected\n",
831 CPU, bfin_revid());
Jie Zhangde3025f2007-06-25 18:04:12 +0800832 }
Mike Frysinger0c0497c2008-10-09 17:32:28 +0800833
Bryan Wu1394f032007-05-06 14:50:22 -0700834 printk(KERN_INFO "Blackfin Linux support by http://blackfin.uclinux.org/\n");
835
Mike Frysingerb5c0e2e2007-09-12 17:31:59 +0800836 printk(KERN_INFO "Processor Speed: %lu MHz core clock and %lu MHz System Clock\n",
Bryan Wu1394f032007-05-06 14:50:22 -0700837 cclk / 1000000, sclk / 1000000);
838
Mike Frysinger1aafd902007-07-25 11:19:14 +0800839 if (ANOMALY_05000273 && (cclk >> 1) <= sclk)
Bryan Wu1394f032007-05-06 14:50:22 -0700840 printk("\n\n\nANOMALY_05000273: CCLK must be >= 2*SCLK !!!\n\n\n");
Bryan Wu1394f032007-05-06 14:50:22 -0700841
Yi Li856783b2008-02-09 02:26:01 +0800842 setup_bootmem_allocator();
Bryan Wu1394f032007-05-06 14:50:22 -0700843
Bryan Wu1394f032007-05-06 14:50:22 -0700844 paging_init();
845
Bernd Schmidt7adfb582007-06-21 11:34:16 +0800846 /* Copy atomic sequences to their fixed location, and sanity check that
847 these locations are the ones that we advertise to userspace. */
848 memcpy((void *)FIXED_CODE_START, &fixed_code_start,
849 FIXED_CODE_END - FIXED_CODE_START);
850 BUG_ON((char *)&sigreturn_stub - (char *)&fixed_code_start
851 != SIGRETURN_STUB - FIXED_CODE_START);
852 BUG_ON((char *)&atomic_xchg32 - (char *)&fixed_code_start
853 != ATOMIC_XCHG32 - FIXED_CODE_START);
854 BUG_ON((char *)&atomic_cas32 - (char *)&fixed_code_start
855 != ATOMIC_CAS32 - FIXED_CODE_START);
856 BUG_ON((char *)&atomic_add32 - (char *)&fixed_code_start
857 != ATOMIC_ADD32 - FIXED_CODE_START);
858 BUG_ON((char *)&atomic_sub32 - (char *)&fixed_code_start
859 != ATOMIC_SUB32 - FIXED_CODE_START);
860 BUG_ON((char *)&atomic_ior32 - (char *)&fixed_code_start
861 != ATOMIC_IOR32 - FIXED_CODE_START);
862 BUG_ON((char *)&atomic_and32 - (char *)&fixed_code_start
863 != ATOMIC_AND32 - FIXED_CODE_START);
864 BUG_ON((char *)&atomic_xor32 - (char *)&fixed_code_start
865 != ATOMIC_XOR32 - FIXED_CODE_START);
Robin Getz9f336a52007-10-29 18:23:28 +0800866 BUG_ON((char *)&safe_user_instruction - (char *)&fixed_code_start
867 != SAFE_USER_INSTRUCTION - FIXED_CODE_START);
Bernd Schmidt29440a22007-07-12 16:25:29 +0800868
Bernd Schmidt8be80ed2007-07-25 14:44:49 +0800869 init_exception_vectors();
Graf Yang5b04f272008-10-08 17:32:57 +0800870 bfin_cache_init();
Bryan Wu1394f032007-05-06 14:50:22 -0700871}
872
Bryan Wu1394f032007-05-06 14:50:22 -0700873static int __init topology_init(void)
874{
Michael Hennerich6cda2e92008-02-02 15:10:51 +0800875 int cpu;
876
877 for_each_possible_cpu(cpu) {
878 struct cpu *c = &per_cpu(cpu_devices, cpu);
879
880 register_cpu(c, cpu);
881 }
882
Bryan Wu1394f032007-05-06 14:50:22 -0700883 return 0;
Bryan Wu1394f032007-05-06 14:50:22 -0700884}
885
886subsys_initcall(topology_init);
887
Mike Frysinger3a2521f2008-07-26 18:52:56 +0800888/* Get the voltage input multiplier */
889static u_long cached_vco_pll_ctl, cached_vco;
Mike Frysinger52a07812007-06-11 15:31:30 +0800890static u_long get_vco(void)
Bryan Wu1394f032007-05-06 14:50:22 -0700891{
892 u_long msel;
Bryan Wu1394f032007-05-06 14:50:22 -0700893
Mike Frysinger3a2521f2008-07-26 18:52:56 +0800894 u_long pll_ctl = bfin_read_PLL_CTL();
895 if (pll_ctl == cached_vco_pll_ctl)
896 return cached_vco;
897 else
898 cached_vco_pll_ctl = pll_ctl;
899
900 msel = (pll_ctl >> 9) & 0x3F;
Bryan Wu1394f032007-05-06 14:50:22 -0700901 if (0 == msel)
902 msel = 64;
903
Mike Frysinger3a2521f2008-07-26 18:52:56 +0800904 cached_vco = CONFIG_CLKIN_HZ;
905 cached_vco >>= (1 & pll_ctl); /* DF bit */
906 cached_vco *= msel;
907 return cached_vco;
Bryan Wu1394f032007-05-06 14:50:22 -0700908}
909
Mike Frysinger2f6cf7b2007-10-21 22:59:49 +0800910/* Get the Core clock */
Mike Frysinger3a2521f2008-07-26 18:52:56 +0800911static u_long cached_cclk_pll_div, cached_cclk;
Bryan Wu1394f032007-05-06 14:50:22 -0700912u_long get_cclk(void)
913{
914 u_long csel, ssel;
Mike Frysinger3a2521f2008-07-26 18:52:56 +0800915
Bryan Wu1394f032007-05-06 14:50:22 -0700916 if (bfin_read_PLL_STAT() & 0x1)
917 return CONFIG_CLKIN_HZ;
918
919 ssel = bfin_read_PLL_DIV();
Mike Frysinger3a2521f2008-07-26 18:52:56 +0800920 if (ssel == cached_cclk_pll_div)
921 return cached_cclk;
922 else
923 cached_cclk_pll_div = ssel;
924
Bryan Wu1394f032007-05-06 14:50:22 -0700925 csel = ((ssel >> 4) & 0x03);
926 ssel &= 0xf;
927 if (ssel && ssel < (1 << csel)) /* SCLK > CCLK */
Mike Frysinger3a2521f2008-07-26 18:52:56 +0800928 cached_cclk = get_vco() / ssel;
929 else
930 cached_cclk = get_vco() >> csel;
931 return cached_cclk;
Bryan Wu1394f032007-05-06 14:50:22 -0700932}
Bryan Wu1394f032007-05-06 14:50:22 -0700933EXPORT_SYMBOL(get_cclk);
934
935/* Get the System clock */
Mike Frysinger3a2521f2008-07-26 18:52:56 +0800936static u_long cached_sclk_pll_div, cached_sclk;
Bryan Wu1394f032007-05-06 14:50:22 -0700937u_long get_sclk(void)
938{
939 u_long ssel;
940
941 if (bfin_read_PLL_STAT() & 0x1)
942 return CONFIG_CLKIN_HZ;
943
Mike Frysinger3a2521f2008-07-26 18:52:56 +0800944 ssel = bfin_read_PLL_DIV();
945 if (ssel == cached_sclk_pll_div)
946 return cached_sclk;
947 else
948 cached_sclk_pll_div = ssel;
949
950 ssel &= 0xf;
Bryan Wu1394f032007-05-06 14:50:22 -0700951 if (0 == ssel) {
952 printk(KERN_WARNING "Invalid System Clock\n");
953 ssel = 1;
954 }
955
Mike Frysinger3a2521f2008-07-26 18:52:56 +0800956 cached_sclk = get_vco() / ssel;
957 return cached_sclk;
Bryan Wu1394f032007-05-06 14:50:22 -0700958}
Bryan Wu1394f032007-05-06 14:50:22 -0700959EXPORT_SYMBOL(get_sclk);
960
Mike Frysinger2f6cf7b2007-10-21 22:59:49 +0800961unsigned long sclk_to_usecs(unsigned long sclk)
962{
Mike Frysinger1754a5d2007-11-23 11:28:11 +0800963 u64 tmp = USEC_PER_SEC * (u64)sclk;
964 do_div(tmp, get_sclk());
965 return tmp;
Mike Frysinger2f6cf7b2007-10-21 22:59:49 +0800966}
967EXPORT_SYMBOL(sclk_to_usecs);
968
969unsigned long usecs_to_sclk(unsigned long usecs)
970{
Mike Frysinger1754a5d2007-11-23 11:28:11 +0800971 u64 tmp = get_sclk() * (u64)usecs;
972 do_div(tmp, USEC_PER_SEC);
973 return tmp;
Mike Frysinger2f6cf7b2007-10-21 22:59:49 +0800974}
975EXPORT_SYMBOL(usecs_to_sclk);
976
Bryan Wu1394f032007-05-06 14:50:22 -0700977/*
978 * Get CPU information for use by the procfs.
979 */
980static int show_cpuinfo(struct seq_file *m, void *v)
981{
Mike Frysinger066954a2007-10-21 22:36:06 +0800982 char *cpu, *mmu, *fpu, *vendor, *cache;
Bryan Wu1394f032007-05-06 14:50:22 -0700983 uint32_t revid;
984
985 u_long cclk = 0, sclk = 0;
Robin Getz9de3a0b2008-07-26 19:39:19 +0800986 u_int icache_size = BFIN_ICACHESIZE / 1024, dcache_size = 0, dsup_banks = 0;
Bryan Wu1394f032007-05-06 14:50:22 -0700987
988 cpu = CPU;
989 mmu = "none";
990 fpu = "none";
991 revid = bfin_revid();
Bryan Wu1394f032007-05-06 14:50:22 -0700992
993 cclk = get_cclk();
994 sclk = get_sclk();
995
Robin Getz73b0c0b2007-10-21 17:03:31 +0800996 switch (bfin_read_CHIPID() & CHIPID_MANUFACTURE) {
Mike Frysinger066954a2007-10-21 22:36:06 +0800997 case 0xca:
998 vendor = "Analog Devices";
Robin Getz73b0c0b2007-10-21 17:03:31 +0800999 break;
1000 default:
Mike Frysinger066954a2007-10-21 22:36:06 +08001001 vendor = "unknown";
1002 break;
Robin Getz73b0c0b2007-10-21 17:03:31 +08001003 }
Bryan Wu1394f032007-05-06 14:50:22 -07001004
Robin Getz73b0c0b2007-10-21 17:03:31 +08001005 seq_printf(m, "processor\t: %d\n"
Robin Getze482cad2008-10-10 18:21:45 +08001006 "vendor_id\t: %s\n",
Graf Yang55f2fea2008-10-09 15:37:47 +08001007 *(unsigned int *)v,
Robin Getze482cad2008-10-10 18:21:45 +08001008 vendor);
1009
1010 if (CPUID == bfin_cpuid())
1011 seq_printf(m, "cpu family\t: 0x%04x\n", CPUID);
1012 else
1013 seq_printf(m, "cpu family\t: Compiled for:0x%04x, running on:0x%04x\n",
1014 CPUID, bfin_cpuid());
1015
1016 seq_printf(m, "model name\t: ADSP-%s %lu(MHz CCLK) %lu(MHz SCLK) (%s)\n"
1017 "stepping\t: %d\n",
Robin Getz73b0c0b2007-10-21 17:03:31 +08001018 cpu, cclk/1000000, sclk/1000000,
Robin Getz253bcf42008-04-24 05:57:13 +08001019#ifdef CONFIG_MPU
1020 "mpu on",
1021#else
1022 "mpu off",
1023#endif
Robin Getz73b0c0b2007-10-21 17:03:31 +08001024 revid);
Bryan Wu1394f032007-05-06 14:50:22 -07001025
Robin Getz73b0c0b2007-10-21 17:03:31 +08001026 seq_printf(m, "cpu MHz\t\t: %lu.%03lu/%lu.%03lu\n",
1027 cclk/1000000, cclk%1000000,
1028 sclk/1000000, sclk%1000000);
1029 seq_printf(m, "bogomips\t: %lu.%02lu\n"
1030 "Calibration\t: %lu loops\n",
1031 (loops_per_jiffy * HZ) / 500000,
1032 ((loops_per_jiffy * HZ) / 5000) % 100,
1033 (loops_per_jiffy * HZ));
1034
1035 /* Check Cache configutation */
Mike Frysinger1f83b8f2007-07-12 22:58:21 +08001036 switch (bfin_read_DMEM_CONTROL() & (1 << DMC0_P | 1 << DMC1_P)) {
1037 case ACACHE_BSRAM:
Mike Frysinger066954a2007-10-21 22:36:06 +08001038 cache = "dbank-A/B\t: cache/sram";
Mike Frysinger1f83b8f2007-07-12 22:58:21 +08001039 dcache_size = 16;
1040 dsup_banks = 1;
1041 break;
1042 case ACACHE_BCACHE:
Mike Frysinger066954a2007-10-21 22:36:06 +08001043 cache = "dbank-A/B\t: cache/cache";
Mike Frysinger1f83b8f2007-07-12 22:58:21 +08001044 dcache_size = 32;
1045 dsup_banks = 2;
1046 break;
1047 case ASRAM_BSRAM:
Mike Frysinger066954a2007-10-21 22:36:06 +08001048 cache = "dbank-A/B\t: sram/sram";
Mike Frysinger1f83b8f2007-07-12 22:58:21 +08001049 dcache_size = 0;
1050 dsup_banks = 0;
1051 break;
1052 default:
Mike Frysinger066954a2007-10-21 22:36:06 +08001053 cache = "unknown";
Robin Getz73b0c0b2007-10-21 17:03:31 +08001054 dcache_size = 0;
1055 dsup_banks = 0;
Bryan Wu1394f032007-05-06 14:50:22 -07001056 break;
1057 }
1058
Robin Getz73b0c0b2007-10-21 17:03:31 +08001059 /* Is it turned on? */
Robin Getz2d200982008-07-26 19:41:40 +08001060 if ((bfin_read_DMEM_CONTROL() & (ENDCPLB | DMC_ENABLE)) != (ENDCPLB | DMC_ENABLE))
Robin Getz73b0c0b2007-10-21 17:03:31 +08001061 dcache_size = 0;
Bryan Wu1394f032007-05-06 14:50:22 -07001062
Graf Yang55f2fea2008-10-09 15:37:47 +08001063 if ((bfin_read_IMEM_CONTROL() & (IMC | ENICPLB)) != (IMC | ENICPLB))
Robin Getz9de3a0b2008-07-26 19:39:19 +08001064 icache_size = 0;
1065
Robin Getz73b0c0b2007-10-21 17:03:31 +08001066 seq_printf(m, "cache size\t: %d KB(L1 icache) "
1067 "%d KB(L1 dcache-%s) %d KB(L2 cache)\n",
Robin Getz9de3a0b2008-07-26 19:39:19 +08001068 icache_size, dcache_size,
Robin Getz73b0c0b2007-10-21 17:03:31 +08001069#if defined CONFIG_BFIN_WB
1070 "wb"
1071#elif defined CONFIG_BFIN_WT
1072 "wt"
1073#endif
Mike Frysingerda27abb2007-10-22 10:55:35 +08001074 "", 0);
Robin Getz73b0c0b2007-10-21 17:03:31 +08001075
1076 seq_printf(m, "%s\n", cache);
1077
Robin Getz9de3a0b2008-07-26 19:39:19 +08001078 if (icache_size)
1079 seq_printf(m, "icache setup\t: %d Sub-banks/%d Ways, %d Lines/Way\n",
1080 BFIN_ISUBBANKS, BFIN_IWAYS, BFIN_ILINES);
1081 else
1082 seq_printf(m, "icache setup\t: off\n");
1083
Bryan Wu1394f032007-05-06 14:50:22 -07001084 seq_printf(m,
Robin Getz73b0c0b2007-10-21 17:03:31 +08001085 "dcache setup\t: %d Super-banks/%d Sub-banks/%d Ways, %d Lines/Way\n",
Robin Getz3bebca22007-10-10 23:55:26 +08001086 dsup_banks, BFIN_DSUBBANKS, BFIN_DWAYS,
1087 BFIN_DLINES);
1088#ifdef CONFIG_BFIN_ICACHE_LOCK
Mike Frysinger0e06b502008-08-14 14:29:57 +08001089 switch ((bfin_read_IMEM_CONTROL() >> 3) & WAYALL_L) {
Bryan Wu1394f032007-05-06 14:50:22 -07001090 case WAY0_L:
1091 seq_printf(m, "Way0 Locked-Down\n");
1092 break;
1093 case WAY1_L:
1094 seq_printf(m, "Way1 Locked-Down\n");
1095 break;
1096 case WAY01_L:
1097 seq_printf(m, "Way0,Way1 Locked-Down\n");
1098 break;
1099 case WAY2_L:
1100 seq_printf(m, "Way2 Locked-Down\n");
1101 break;
1102 case WAY02_L:
1103 seq_printf(m, "Way0,Way2 Locked-Down\n");
1104 break;
1105 case WAY12_L:
1106 seq_printf(m, "Way1,Way2 Locked-Down\n");
1107 break;
1108 case WAY012_L:
1109 seq_printf(m, "Way0,Way1 & Way2 Locked-Down\n");
1110 break;
1111 case WAY3_L:
1112 seq_printf(m, "Way3 Locked-Down\n");
1113 break;
1114 case WAY03_L:
1115 seq_printf(m, "Way0,Way3 Locked-Down\n");
1116 break;
1117 case WAY13_L:
1118 seq_printf(m, "Way1,Way3 Locked-Down\n");
1119 break;
1120 case WAY013_L:
1121 seq_printf(m, "Way 0,Way1,Way3 Locked-Down\n");
1122 break;
1123 case WAY32_L:
1124 seq_printf(m, "Way3,Way2 Locked-Down\n");
1125 break;
1126 case WAY320_L:
1127 seq_printf(m, "Way3,Way2,Way0 Locked-Down\n");
1128 break;
1129 case WAY321_L:
1130 seq_printf(m, "Way3,Way2,Way1 Locked-Down\n");
1131 break;
1132 case WAYALL_L:
1133 seq_printf(m, "All Ways are locked\n");
1134 break;
1135 default:
1136 seq_printf(m, "No Ways are locked\n");
1137 }
1138#endif
Mike Frysinger066954a2007-10-21 22:36:06 +08001139 seq_printf(m, "board name\t: %s\n", bfin_board_name);
Robin Getz73b0c0b2007-10-21 17:03:31 +08001140 seq_printf(m, "board memory\t: %ld kB (0x%p -> 0x%p)\n",
1141 physical_mem_end >> 10, (void *)0, (void *)physical_mem_end);
1142 seq_printf(m, "kernel memory\t: %d kB (0x%p -> 0x%p)\n",
1143 ((int)memory_end - (int)_stext) >> 10,
1144 _stext,
1145 (void *)memory_end);
1146
Bryan Wu1394f032007-05-06 14:50:22 -07001147 return 0;
1148}
1149
1150static void *c_start(struct seq_file *m, loff_t *pos)
1151{
Graf Yang55f2fea2008-10-09 15:37:47 +08001152 if (*pos == 0)
1153 *pos = first_cpu(cpu_online_map);
1154 if (*pos >= num_online_cpus())
1155 return NULL;
1156
1157 return pos;
Bryan Wu1394f032007-05-06 14:50:22 -07001158}
1159
1160static void *c_next(struct seq_file *m, void *v, loff_t *pos)
1161{
Graf Yang55f2fea2008-10-09 15:37:47 +08001162 *pos = next_cpu(*pos, cpu_online_map);
1163
Bryan Wu1394f032007-05-06 14:50:22 -07001164 return c_start(m, pos);
1165}
1166
1167static void c_stop(struct seq_file *m, void *v)
1168{
1169}
1170
Jan Engelhardt03a44822008-02-08 04:21:19 -08001171const struct seq_operations cpuinfo_op = {
Bryan Wu1394f032007-05-06 14:50:22 -07001172 .start = c_start,
1173 .next = c_next,
1174 .stop = c_stop,
1175 .show = show_cpuinfo,
1176};
1177
Mike Frysinger5e10b4a2007-06-11 16:44:09 +08001178void __init cmdline_init(const char *r0)
Bryan Wu1394f032007-05-06 14:50:22 -07001179{
1180 if (r0)
Mike Frysinger52a07812007-06-11 15:31:30 +08001181 strncpy(command_line, r0, COMMAND_LINE_SIZE);
Bryan Wu1394f032007-05-06 14:50:22 -07001182}