setup.c 35.9 KB
Newer Older
Bryan Wu's avatar
Bryan Wu committed
1
/*
2
 * arch/blackfin/kernel/setup.c
Bryan Wu's avatar
Bryan Wu committed
3
 *
4
 * Copyright 2004-2006 Analog Devices Inc.
Bryan Wu's avatar
Bryan Wu committed
5
 *
6
 * Enter bugs at http://blackfin.uclinux.org/
Bryan Wu's avatar
Bryan Wu committed
7
 *
8
 * Licensed under the GPL-2 or later.
Bryan Wu's avatar
Bryan Wu committed
9
10
11
12
13
14
15
 */

#include <linux/delay.h>
#include <linux/console.h>
#include <linux/bootmem.h>
#include <linux/seq_file.h>
#include <linux/cpu.h>
16
#include <linux/mm.h>
Bryan Wu's avatar
Bryan Wu committed
17
18
#include <linux/module.h>
#include <linux/tty.h>
19
#include <linux/pfn.h>
Bryan Wu's avatar
Bryan Wu committed
20

21
22
#ifdef CONFIG_MTD_UCLINUX
#include <linux/mtd/map.h>
Bryan Wu's avatar
Bryan Wu committed
23
24
25
#include <linux/ext2_fs.h>
#include <linux/cramfs_fs.h>
#include <linux/romfs_fs.h>
26
#endif
Bryan Wu's avatar
Bryan Wu committed
27

28
#include <asm/cplb.h>
Bryan Wu's avatar
Bryan Wu committed
29
30
31
#include <asm/cacheflush.h>
#include <asm/blackfin.h>
#include <asm/cplbinit.h>
32
#include <asm/div64.h>
33
#include <asm/cpu.h>
34
#include <asm/fixed_code.h>
35
#include <asm/early_printk.h>
Bryan Wu's avatar
Bryan Wu committed
36

37
u16 _bfin_swrst;
38
EXPORT_SYMBOL(_bfin_swrst);
39

Bryan Wu's avatar
Bryan Wu committed
40
unsigned long memory_start, memory_end, physical_mem_end;
41
unsigned long _rambase, _ramstart, _ramend;
Bryan Wu's avatar
Bryan Wu committed
42
43
44
45
46
47
unsigned long reserved_mem_dcache_on;
unsigned long reserved_mem_icache_on;
EXPORT_SYMBOL(memory_start);
EXPORT_SYMBOL(memory_end);
EXPORT_SYMBOL(physical_mem_end);
EXPORT_SYMBOL(_ramend);
48
EXPORT_SYMBOL(reserved_mem_dcache_on);
Bryan Wu's avatar
Bryan Wu committed
49
50

#ifdef CONFIG_MTD_UCLINUX
51
extern struct map_info uclinux_ram_map;
Bryan Wu's avatar
Bryan Wu committed
52
53
54
55
56
57
58
unsigned long memory_mtd_end, memory_mtd_start, mtd_size;
unsigned long _ebss;
EXPORT_SYMBOL(memory_mtd_end);
EXPORT_SYMBOL(memory_mtd_start);
EXPORT_SYMBOL(mtd_size);
#endif

59
char __initdata command_line[COMMAND_LINE_SIZE];
60
61
void __initdata *init_retx, *init_saved_retx, *init_saved_seqstat,
	*init_saved_icplb_fault_addr, *init_saved_dcplb_fault_addr;
Bryan Wu's avatar
Bryan Wu committed
62

63
64
65
66
/* boot memmap, for parsing "memmap=" */
#define BFIN_MEMMAP_MAX		128 /* number of entries in bfin_memmap */
#define BFIN_MEMMAP_RAM		1
#define BFIN_MEMMAP_RESERVED	2
67
static struct bfin_memmap {
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
	int nr_map;
	struct bfin_memmap_entry {
		unsigned long long addr; /* start of memory segment */
		unsigned long long size;
		unsigned long type;
	} map[BFIN_MEMMAP_MAX];
} bfin_memmap __initdata;

/* for memmap sanitization */
struct change_member {
	struct bfin_memmap_entry *pentry; /* pointer to original entry */
	unsigned long long addr; /* address for this change point */
};
static struct change_member change_point_list[2*BFIN_MEMMAP_MAX] __initdata;
static struct change_member *change_point[2*BFIN_MEMMAP_MAX] __initdata;
static struct bfin_memmap_entry *overlap_list[BFIN_MEMMAP_MAX] __initdata;
static struct bfin_memmap_entry new_map[BFIN_MEMMAP_MAX] __initdata;

86
87
DEFINE_PER_CPU(struct blackfin_cpudata, cpu_data);

88
89
static int early_init_clkin_hz(char *buf);

90
#if defined(CONFIG_BFIN_DCACHE) || defined(CONFIG_BFIN_ICACHE)
91
92
93
94
void __init generate_cplb_tables(void)
{
	unsigned int cpu;

95
	generate_cplb_tables_all();
96
97
98
99
	/* Generate per-CPU I&D CPLB tables */
	for (cpu = 0; cpu < num_possible_cpus(); ++cpu)
		generate_cplb_tables_cpu(cpu);
}
Bryan Wu's avatar
Bryan Wu committed
100
101
#endif

102
103
void __cpuinit bfin_setup_caches(unsigned int cpu)
{
104
#ifdef CONFIG_BFIN_ICACHE
105
	bfin_icache_init(icplb_tbl[cpu]);
Bryan Wu's avatar
Bryan Wu committed
106
107
#endif

108
#ifdef CONFIG_BFIN_DCACHE
109
110
111
112
113
114
	bfin_dcache_init(dcplb_tbl[cpu]);
#endif

	/*
	 * In cache coherence emulation mode, we need to have the
	 * D-cache enabled before running any atomic operation which
115
	 * might involve cache invalidation (i.e. spinlock, rwlock).
116
117
118
119
	 * So printk's are deferred until then.
	 */
#ifdef CONFIG_BFIN_ICACHE
	printk(KERN_INFO "Instruction Cache Enabled for CPU%u\n", cpu);
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
	printk(KERN_INFO "  External memory:"
# ifdef CONFIG_BFIN_EXTMEM_ICACHEABLE
	       " cacheable"
# else
	       " uncacheable"
# endif
	       " in instruction cache\n");
	if (L2_LENGTH)
		printk(KERN_INFO "  L2 SRAM        :"
# ifdef CONFIG_BFIN_L2_ICACHEABLE
		       " cacheable"
# else
		       " uncacheable"
# endif
		       " in instruction cache\n");

#else
	printk(KERN_INFO "Instruction Cache Disabled for CPU%u\n", cpu);
138
#endif
139

140
#ifdef CONFIG_BFIN_DCACHE
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
	printk(KERN_INFO "Data Cache Enabled for CPU%u\n", cpu);
	printk(KERN_INFO "  External memory:"
# if defined CONFIG_BFIN_EXTMEM_WRITEBACK
	       " cacheable (write-back)"
# elif defined CONFIG_BFIN_EXTMEM_WRITETHROUGH
	       " cacheable (write-through)"
# else
	       " uncacheable"
# endif
	       " in data cache\n");
	if (L2_LENGTH)
		printk(KERN_INFO "  L2 SRAM        :"
# if defined CONFIG_BFIN_L2_WRITEBACK
		       " cacheable (write-back)"
# elif defined CONFIG_BFIN_L2_WRITETHROUGH
		       " cacheable (write-through)"
# else
		       " uncacheable"
Bryan Wu's avatar
Bryan Wu committed
159
# endif
160
161
162
		       " in data cache\n");
#else
	printk(KERN_INFO "Data Cache Disabled for CPU%u\n", cpu);
Bryan Wu's avatar
Bryan Wu committed
163
164
165
#endif
}

166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
void __cpuinit bfin_setup_cpudata(unsigned int cpu)
{
	struct blackfin_cpudata *cpudata = &per_cpu(cpu_data, cpu);

	cpudata->idle = current;
	cpudata->imemctl = bfin_read_IMEM_CONTROL();
	cpudata->dmemctl = bfin_read_DMEM_CONTROL();
}

void __init bfin_cache_init(void)
{
#if defined(CONFIG_BFIN_DCACHE) || defined(CONFIG_BFIN_ICACHE)
	generate_cplb_tables();
#endif
	bfin_setup_caches(0);
}

183
void __init bfin_relocate_l1_mem(void)
Bryan Wu's avatar
Bryan Wu committed
184
185
186
187
{
	unsigned long l1_code_length;
	unsigned long l1_data_a_length;
	unsigned long l1_data_b_length;
188
	unsigned long l2_length;
Bryan Wu's avatar
Bryan Wu committed
189

190
191
	early_shadow_stamp();

192
193
194
195
196
197
198
199
200
201
202
203
204
205
	/*
	 * due to the ALIGN(4) in the arch/blackfin/kernel/vmlinux.lds.S
	 * we know that everything about l1 text/data is nice and aligned,
	 * so copy by 4 byte chunks, and don't worry about overlapping
	 * src/dest.
	 *
	 * We can't use the dma_memcpy functions, since they can call
	 * scheduler functions which might be in L1 :( and core writes
	 * into L1 instruction cause bad access errors, so we are stuck,
	 * we are required to use DMA, but can't use the common dma
	 * functions. We can't use memcpy either - since that might be
	 * going to be in the relocated L1
	 */

206
207
	blackfin_dma_early_init();

208
	/* if necessary, copy _stext_l1 to _etext_l1 to L1 instruction SRAM */
Bryan Wu's avatar
Bryan Wu committed
209
	l1_code_length = _etext_l1 - _stext_l1;
210
211
	if (l1_code_length)
		early_dma_memcpy(_stext_l1, _l1_lma_start, l1_code_length);
Bryan Wu's avatar
Bryan Wu committed
212

213
	/* if necessary, copy _sdata_l1 to _sbss_l1 to L1 data bank A SRAM */
214
	l1_data_a_length = _sbss_l1 - _sdata_l1;
215
216
	if (l1_data_a_length)
		early_dma_memcpy(_sdata_l1, _l1_lma_start + l1_code_length, l1_data_a_length);
Bryan Wu's avatar
Bryan Wu committed
217

218
	/* if necessary, copy _sdata_b_l1 to _sbss_b_l1 to L1 data bank B SRAM */
219
	l1_data_b_length = _sbss_b_l1 - _sdata_b_l1;
220
221
	if (l1_data_b_length)
		early_dma_memcpy(_sdata_b_l1, _l1_lma_start + l1_code_length +
Bryan Wu's avatar
Bryan Wu committed
222
			l1_data_a_length, l1_data_b_length);
223

224
225
226
	early_dma_memcpy_done();

	/* if necessary, copy _stext_l2 to _edata_l2 to L2 SRAM */
227
	if (L2_LENGTH != 0) {
228
		l2_length = _sbss_l2 - _stext_l2;
229
230
		if (l2_length)
			memcpy(_stext_l2, _l2_lma_start, l2_length);
231
	}
Bryan Wu's avatar
Bryan Wu committed
232
233
}

234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
/* add_memory_region to memmap */
static void __init add_memory_region(unsigned long long start,
			      unsigned long long size, int type)
{
	int i;

	i = bfin_memmap.nr_map;

	if (i == BFIN_MEMMAP_MAX) {
		printk(KERN_ERR "Ooops! Too many entries in the memory map!\n");
		return;
	}

	bfin_memmap.map[i].addr = start;
	bfin_memmap.map[i].size = size;
	bfin_memmap.map[i].type = type;
	bfin_memmap.nr_map++;
}

/*
 * Sanitize the boot memmap, removing overlaps.
 */
static int __init sanitize_memmap(struct bfin_memmap_entry *map, int *pnr_map)
{
	struct change_member *change_tmp;
	unsigned long current_type, last_type;
	unsigned long long last_addr;
	int chgidx, still_changing;
	int overlap_entries;
	int new_entry;
	int old_nr, new_nr, chg_nr;
	int i;

	/*
		Visually we're performing the following (1,2,3,4 = memory types)

		Sample memory map (w/overlaps):
		   ____22__________________
		   ______________________4_
		   ____1111________________
		   _44_____________________
		   11111111________________
		   ____________________33__
		   ___________44___________
		   __________33333_________
		   ______________22________
		   ___________________2222_
		   _________111111111______
		   _____________________11_
		   _________________4______

		Sanitized equivalent (no overlap):
		   1_______________________
		   _44_____________________
		   ___1____________________
		   ____22__________________
		   ______11________________
		   _________1______________
		   __________3_____________
		   ___________44___________
		   _____________33_________
		   _______________2________
		   ________________1_______
		   _________________4______
		   ___________________2____
		   ____________________33__
		   ______________________4_
	*/
	/* if there's only one memory region, don't bother */
	if (*pnr_map < 2)
		return -1;

	old_nr = *pnr_map;

	/* bail out if we find any unreasonable addresses in memmap */
	for (i = 0; i < old_nr; i++)
		if (map[i].addr + map[i].size < map[i].addr)
			return -1;

	/* create pointers for initial change-point information (for sorting) */
	for (i = 0; i < 2*old_nr; i++)
		change_point[i] = &change_point_list[i];

	/* record all known change-points (starting and ending addresses),
	   omitting those that are for empty memory regions */
	chgidx = 0;
320
	for (i = 0; i < old_nr; i++) {
321
322
323
324
325
326
327
		if (map[i].size != 0) {
			change_point[chgidx]->addr = map[i].addr;
			change_point[chgidx++]->pentry = &map[i];
			change_point[chgidx]->addr = map[i].addr + map[i].size;
			change_point[chgidx++]->pentry = &map[i];
		}
	}
328
	chg_nr = chgidx;	/* true number of change-points */
329
330
331

	/* sort change-point list by memory addresses (low -> high) */
	still_changing = 1;
332
	while (still_changing) {
333
		still_changing = 0;
334
		for (i = 1; i < chg_nr; i++) {
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
			/* if <current_addr> > <last_addr>, swap */
			/* or, if current=<start_addr> & last=<end_addr>, swap */
			if ((change_point[i]->addr < change_point[i-1]->addr) ||
				((change_point[i]->addr == change_point[i-1]->addr) &&
				 (change_point[i]->addr == change_point[i]->pentry->addr) &&
				 (change_point[i-1]->addr != change_point[i-1]->pentry->addr))
			   ) {
				change_tmp = change_point[i];
				change_point[i] = change_point[i-1];
				change_point[i-1] = change_tmp;
				still_changing = 1;
			}
		}
	}

	/* create a new memmap, removing overlaps */
351
352
353
354
	overlap_entries = 0;	/* number of entries in the overlap table */
	new_entry = 0;		/* index for creating new memmap entries */
	last_type = 0;		/* start with undefined memory type */
	last_addr = 0;		/* start with 0 as last starting address */
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
	/* loop through change-points, determining affect on the new memmap */
	for (chgidx = 0; chgidx < chg_nr; chgidx++) {
		/* keep track of all overlapping memmap entries */
		if (change_point[chgidx]->addr == change_point[chgidx]->pentry->addr) {
			/* add map entry to overlap list (> 1 entry implies an overlap) */
			overlap_list[overlap_entries++] = change_point[chgidx]->pentry;
		} else {
			/* remove entry from list (order independent, so swap with last) */
			for (i = 0; i < overlap_entries; i++) {
				if (overlap_list[i] == change_point[chgidx]->pentry)
					overlap_list[i] = overlap_list[overlap_entries-1];
			}
			overlap_entries--;
		}
		/* if there are overlapping entries, decide which "type" to use */
		/* (larger value takes precedence -- 1=usable, 2,3,4,4+=unusable) */
		current_type = 0;
		for (i = 0; i < overlap_entries; i++)
			if (overlap_list[i]->type > current_type)
				current_type = overlap_list[i]->type;
		/* continue building up new memmap based on this information */
376
		if (current_type != last_type) {
377
378
379
380
381
382
			if (last_type != 0) {
				new_map[new_entry].size =
					change_point[chgidx]->addr - last_addr;
				/* move forward only if the new size was non-zero */
				if (new_map[new_entry].size != 0)
					if (++new_entry >= BFIN_MEMMAP_MAX)
383
						break;	/* no more space left for new entries */
384
385
386
387
388
389
390
391
392
			}
			if (current_type != 0) {
				new_map[new_entry].addr = change_point[chgidx]->addr;
				new_map[new_entry].type = current_type;
				last_addr = change_point[chgidx]->addr;
			}
			last_type = current_type;
		}
	}
393
	new_nr = new_entry;	/* retain count for new entries */
394

395
	/* copy new mapping into original location */
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
	memcpy(map, new_map, new_nr*sizeof(struct bfin_memmap_entry));
	*pnr_map = new_nr;

	return 0;
}

static void __init print_memory_map(char *who)
{
	int i;

	for (i = 0; i < bfin_memmap.nr_map; i++) {
		printk(KERN_DEBUG " %s: %016Lx - %016Lx ", who,
			bfin_memmap.map[i].addr,
			bfin_memmap.map[i].addr + bfin_memmap.map[i].size);
		switch (bfin_memmap.map[i].type) {
		case BFIN_MEMMAP_RAM:
412
413
			printk(KERN_CONT "(usable)\n");
			break;
414
		case BFIN_MEMMAP_RESERVED:
415
416
417
418
419
			printk(KERN_CONT "(reserved)\n");
			break;
		default:
			printk(KERN_CONT "type %lu\n", bfin_memmap.map[i].type);
			break;
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
		}
	}
}

static __init int parse_memmap(char *arg)
{
	unsigned long long start_at, mem_size;

	if (!arg)
		return -EINVAL;

	mem_size = memparse(arg, &arg);
	if (*arg == '@') {
		start_at = memparse(arg+1, &arg);
		add_memory_region(start_at, mem_size, BFIN_MEMMAP_RAM);
	} else if (*arg == '$') {
		start_at = memparse(arg+1, &arg);
		add_memory_region(start_at, mem_size, BFIN_MEMMAP_RESERVED);
	}

	return 0;
}

Bryan Wu's avatar
Bryan Wu committed
443
444
445
446
447
448
/*
 * Initial parsing of the command line.  Currently, we support:
 *  - Controlling the linux memory size: mem=xxx[KMG]
 *  - Controlling the physical memory size: max_mem=xxx[KMG][$][#]
 *       $ -> reserved memory is dcacheable
 *       # -> reserved memory is icacheable
449
450
451
 *  - "memmap=XXX[KkmM][@][$]XXX[KkmM]" defines a memory region
 *       @ from <start> to <start>+<mem>, type RAM
 *       $ from <start> to <start>+<mem>, type RESERVED
Bryan Wu's avatar
Bryan Wu committed
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
 */
static __init void parse_cmdline_early(char *cmdline_p)
{
	char c = ' ', *to = cmdline_p;
	unsigned int memsize;
	for (;;) {
		if (c == ' ') {
			if (!memcmp(to, "mem=", 4)) {
				to += 4;
				memsize = memparse(to, &to);
				if (memsize)
					_ramend = memsize;

			} else if (!memcmp(to, "max_mem=", 8)) {
				to += 8;
				memsize = memparse(to, &to);
				if (memsize) {
					physical_mem_end = memsize;
					if (*to != ' ') {
						if (*to == '$'
						    || *(to + 1) == '$')
473
							reserved_mem_dcache_on = 1;
Bryan Wu's avatar
Bryan Wu committed
474
475
						if (*to == '#'
						    || *(to + 1) == '#')
476
							reserved_mem_icache_on = 1;
Bryan Wu's avatar
Bryan Wu committed
477
478
					}
				}
479
480
481
			} else if (!memcmp(to, "clkin_hz=", 9)) {
				to += 9;
				early_init_clkin_hz(to);
482
#ifdef CONFIG_EARLY_PRINTK
483
484
485
			} else if (!memcmp(to, "earlyprintk=", 12)) {
				to += 12;
				setup_early_printk(to);
486
#endif
487
488
489
			} else if (!memcmp(to, "memmap=", 7)) {
				to += 7;
				parse_memmap(to);
Bryan Wu's avatar
Bryan Wu committed
490
491
492
493
494
495
496
497
			}
		}
		c = *(to++);
		if (!c)
			break;
	}
}

498
499
500
501
502
503
504
/*
 * Setup memory defaults from user config.
 * The physical memory layout looks like:
 *
 *  [_rambase, _ramstart]:		kernel image
 *  [memory_start, memory_end]:		dynamic memory managed by kernel
 *  [memory_end, _ramend]:		reserved memory
505
 *  	[memory_mtd_start(memory_end),
506
507
508
509
510
 *  		memory_mtd_start + mtd_size]:	rootfs (if any)
 *	[_ramend - DMA_UNCACHED_REGION,
 *		_ramend]:			uncached DMA region
 *  [_ramend, physical_mem_end]:	memory not managed by kernel
 */
511
static __init void memory_setup(void)
Bryan Wu's avatar
Bryan Wu committed
512
{
513
514
515
#ifdef CONFIG_MTD_UCLINUX
	unsigned long mtd_phys = 0;
#endif
516
	unsigned long max_mem;
517

518
	_rambase = (unsigned long)_stext;
519
	_ramstart = (unsigned long)_end;
Bryan Wu's avatar
Bryan Wu committed
520

521
522
	if (DMA_UNCACHED_REGION > (_ramend - _ramstart)) {
		console_init();
523
		panic("DMA region exceeds memory limit: %lu.",
524
			_ramend - _ramstart);
525
	}
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
	max_mem = memory_end = _ramend - DMA_UNCACHED_REGION;

#if (defined(CONFIG_BFIN_EXTMEM_ICACHEABLE) && ANOMALY_05000263)
	/* Due to a Hardware Anomaly we need to limit the size of usable
	 * instruction memory to max 60MB, 56 if HUNT_FOR_ZERO is on
	 * 05000263 - Hardware loop corrupted when taking an ICPLB exception
	 */
# if (defined(CONFIG_DEBUG_HUNT_FOR_ZERO))
	if (max_mem >= 56 * 1024 * 1024)
		max_mem = 56 * 1024 * 1024;
# else
	if (max_mem >= 60 * 1024 * 1024)
		max_mem = 60 * 1024 * 1024;
# endif				/* CONFIG_DEBUG_HUNT_FOR_ZERO */
#endif				/* ANOMALY_05000263 */

Bryan Wu's avatar
Bryan Wu committed
542

543
#ifdef CONFIG_MPU
544
	/* Round up to multiple of 4MB */
545
546
	memory_start = (_ramstart + 0x3fffff) & ~0x3fffff;
#else
Bryan Wu's avatar
Bryan Wu committed
547
	memory_start = PAGE_ALIGN(_ramstart);
548
#endif
Bryan Wu's avatar
Bryan Wu committed
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569

#if defined(CONFIG_MTD_UCLINUX)
	/* generic memory mapped MTD driver */
	memory_mtd_end = memory_end;

	mtd_phys = _ramstart;
	mtd_size = PAGE_ALIGN(*((unsigned long *)(mtd_phys + 8)));

# if defined(CONFIG_EXT2_FS) || defined(CONFIG_EXT3_FS)
	if (*((unsigned short *)(mtd_phys + 0x438)) == EXT2_SUPER_MAGIC)
		mtd_size =
		    PAGE_ALIGN(*((unsigned long *)(mtd_phys + 0x404)) << 10);
# endif

# if defined(CONFIG_CRAMFS)
	if (*((unsigned long *)(mtd_phys)) == CRAMFS_MAGIC)
		mtd_size = PAGE_ALIGN(*((unsigned long *)(mtd_phys + 0x4)));
# endif

# if defined(CONFIG_ROMFS_FS)
	if (((unsigned long *)mtd_phys)[0] == ROMSB_WORD0
570
	    && ((unsigned long *)mtd_phys)[1] == ROMSB_WORD1) {
Bryan Wu's avatar
Bryan Wu committed
571
572
		mtd_size =
		    PAGE_ALIGN(be32_to_cpu(((unsigned long *)mtd_phys)[2]));
573
574
575
576
577
578
579

		/* ROM_FS is XIP, so if we found it, we need to limit memory */
		if (memory_end > max_mem) {
			pr_info("Limiting kernel memory to %liMB due to anomaly 05000263\n", max_mem >> 20);
			memory_end = max_mem;
		}
	}
Bryan Wu's avatar
Bryan Wu committed
580
581
# endif				/* CONFIG_ROMFS_FS */

582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
	/* Since the default MTD_UCLINUX has no magic number, we just blindly
	 * read 8 past the end of the kernel's image, and look at it.
	 * When no image is attached, mtd_size is set to a random number
	 * Do some basic sanity checks before operating on things
	 */
	if (mtd_size == 0 || memory_end <= mtd_size) {
		pr_emerg("Could not find valid ram mtd attached.\n");
	} else {
		memory_end -= mtd_size;

		/* Relocate MTD image to the top of memory after the uncached memory area */
		uclinux_ram_map.phys = memory_mtd_start = memory_end;
		uclinux_ram_map.size = mtd_size;
		pr_info("Found mtd parition at 0x%p, (len=0x%lx), moving to 0x%p\n",
			_end, mtd_size, (void *)memory_mtd_start);
		dma_memcpy((void *)uclinux_ram_map.phys, _end, uclinux_ram_map.size);
Bryan Wu's avatar
Bryan Wu committed
598
599
600
	}
#endif				/* CONFIG_MTD_UCLINUX */

601
602
603
	/* We need lo limit memory, since everything could have a text section
	 * of userspace in it, and expose anomaly 05000263. If the anomaly
	 * doesn't exist, or we don't need to - then dont.
Bryan Wu's avatar
Bryan Wu committed
604
	 */
605
606
607
608
	if (memory_end > max_mem) {
		pr_info("Limiting kernel memory to %liMB due to anomaly 05000263\n", max_mem >> 20);
		memory_end = max_mem;
	}
Bryan Wu's avatar
Bryan Wu committed
609

610
611
612
613
614
#ifdef CONFIG_MPU
	page_mask_nelts = ((_ramend >> PAGE_SHIFT) + 31) / 32;
	page_mask_order = get_order(3 * page_mask_nelts * sizeof(long));
#endif

Bryan Wu's avatar
Bryan Wu committed
615
#if !defined(CONFIG_MTD_UCLINUX)
616
617
	/*In case there is no valid CPLB behind memory_end make sure we don't get to close*/
	memory_end -= SIZE_4K;
Bryan Wu's avatar
Bryan Wu committed
618
#endif
619

Bryan Wu's avatar
Bryan Wu committed
620
621
622
623
624
	init_mm.start_code = (unsigned long)_stext;
	init_mm.end_code = (unsigned long)_etext;
	init_mm.end_data = (unsigned long)_edata;
	init_mm.brk = (unsigned long)0;

625
626
627
	printk(KERN_INFO "Board Memory: %ldMB\n", physical_mem_end >> 20);
	printk(KERN_INFO "Kernel Managed Memory: %ldMB\n", _ramend >> 20);

628
	printk(KERN_INFO "Memory map:\n"
629
630
631
632
633
634
635
636
	       "  fixedcode = 0x%p-0x%p\n"
	       "  text      = 0x%p-0x%p\n"
	       "  rodata    = 0x%p-0x%p\n"
	       "  bss       = 0x%p-0x%p\n"
	       "  data      = 0x%p-0x%p\n"
	       "    stack   = 0x%p-0x%p\n"
	       "  init      = 0x%p-0x%p\n"
	       "  available = 0x%p-0x%p\n"
637
#ifdef CONFIG_MTD_UCLINUX
638
	       "  rootfs    = 0x%p-0x%p\n"
639
640
#endif
#if DMA_UNCACHED_REGION > 0
641
	       "  DMA Zone  = 0x%p-0x%p\n"
642
#endif
643
644
		, (void *)FIXED_CODE_START, (void *)FIXED_CODE_END,
		_stext, _etext,
645
		__start_rodata, __end_rodata,
646
		__bss_start, __bss_stop,
647
648
649
		_sdata, _edata,
		(void *)&init_thread_union,
		(void *)((int)(&init_thread_union) + 0x2000),
650
651
		__init_begin, __init_end,
		(void *)_ramstart, (void *)memory_end
652
653
654
655
656
657
658
659
660
#ifdef CONFIG_MTD_UCLINUX
		, (void *)memory_mtd_start, (void *)(memory_mtd_start + mtd_size)
#endif
#if DMA_UNCACHED_REGION > 0
		, (void *)(_ramend - DMA_UNCACHED_REGION), (void *)(_ramend)
#endif
		);
}

661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
/*
 * Find the lowest, highest page frame number we have available
 */
void __init find_min_max_pfn(void)
{
	int i;

	max_pfn = 0;
	min_low_pfn = memory_end;

	for (i = 0; i < bfin_memmap.nr_map; i++) {
		unsigned long start, end;
		/* RAM? */
		if (bfin_memmap.map[i].type != BFIN_MEMMAP_RAM)
			continue;
		start = PFN_UP(bfin_memmap.map[i].addr);
		end = PFN_DOWN(bfin_memmap.map[i].addr +
				bfin_memmap.map[i].size);
		if (start >= end)
			continue;
		if (end > max_pfn)
			max_pfn = end;
		if (start < min_low_pfn)
			min_low_pfn = start;
	}
}

688
689
690
691
static __init void setup_bootmem_allocator(void)
{
	int bootmap_size;
	int i;
692
	unsigned long start_pfn, end_pfn;
693
694
695
696
697
698
699
700
701
	unsigned long curr_pfn, last_pfn, size;

	/* mark memory between memory_start and memory_end usable */
	add_memory_region(memory_start,
		memory_end - memory_start, BFIN_MEMMAP_RAM);
	/* sanity check for overlap */
	sanitize_memmap(bfin_memmap.map, &bfin_memmap.nr_map);
	print_memory_map("boot memmap");

702
	/* initialize globals in linux/bootmem.h */
703
704
705
706
707
708
709
710
711
712
713
714
	find_min_max_pfn();
	/* pfn of the last usable page frame */
	if (max_pfn > memory_end >> PAGE_SHIFT)
		max_pfn = memory_end >> PAGE_SHIFT;
	/* pfn of last page frame directly mapped by kernel */
	max_low_pfn = max_pfn;
	/* pfn of the first usable page frame after kernel image*/
	if (min_low_pfn < memory_start >> PAGE_SHIFT)
		min_low_pfn = memory_start >> PAGE_SHIFT;

	start_pfn = PAGE_OFFSET >> PAGE_SHIFT;
	end_pfn = memory_end >> PAGE_SHIFT;
715
716

	/*
717
	 * give all the memory to the bootmap allocator, tell it to put the
718
719
720
721
	 * boot mem_map at the start of memory.
	 */
	bootmap_size = init_bootmem_node(NODE_DATA(0),
			memory_start >> PAGE_SHIFT,	/* map goes here */
722
			start_pfn, end_pfn);
723
724
725
726
727
728
729
730
731
732
733
734

	/* register the memmap regions with the bootmem allocator */
	for (i = 0; i < bfin_memmap.nr_map; i++) {
		/*
		 * Reserve usable memory
		 */
		if (bfin_memmap.map[i].type != BFIN_MEMMAP_RAM)
			continue;
		/*
		 * We are rounding up the start address of usable memory:
		 */
		curr_pfn = PFN_UP(bfin_memmap.map[i].addr);
735
		if (curr_pfn >= end_pfn)
736
737
738
739
740
741
742
			continue;
		/*
		 * ... and at the end of the usable range downwards:
		 */
		last_pfn = PFN_DOWN(bfin_memmap.map[i].addr +
					 bfin_memmap.map[i].size);

743
744
		if (last_pfn > end_pfn)
			last_pfn = end_pfn;
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762

		/*
		 * .. finally, did all the rounding and playing
		 * around just make the area go away?
		 */
		if (last_pfn <= curr_pfn)
			continue;

		size = last_pfn - curr_pfn;
		free_bootmem(PFN_PHYS(curr_pfn), PFN_PHYS(size));
	}

	/* reserve memory before memory_start, including bootmap */
	reserve_bootmem(PAGE_OFFSET,
		memory_start + bootmap_size + PAGE_SIZE - 1 - PAGE_OFFSET,
		BOOTMEM_DEFAULT);
}

763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
#define EBSZ_TO_MEG(ebsz) \
({ \
	int meg = 0; \
	switch (ebsz & 0xf) { \
		case 0x1: meg =  16; break; \
		case 0x3: meg =  32; break; \
		case 0x5: meg =  64; break; \
		case 0x7: meg = 128; break; \
		case 0x9: meg = 256; break; \
		case 0xb: meg = 512; break; \
	} \
	meg; \
})
static inline int __init get_mem_size(void)
{
778
779
#if defined(EBIU_SDBCTL)
# if defined(BF561_FAMILY)
780
781
782
783
784
785
786
	int ret = 0;
	u32 sdbctl = bfin_read_EBIU_SDBCTL();
	ret += EBSZ_TO_MEG(sdbctl >>  0);
	ret += EBSZ_TO_MEG(sdbctl >>  8);
	ret += EBSZ_TO_MEG(sdbctl >> 16);
	ret += EBSZ_TO_MEG(sdbctl >> 24);
	return ret;
787
# else
788
	return EBSZ_TO_MEG(bfin_read_EBIU_SDBCTL());
789
790
# endif
#elif defined(EBIU_DDRCTL1)
791
792
793
794
795
796
797
798
799
800
801
802
	u32 ddrctl = bfin_read_EBIU_DDRCTL1();
	int ret = 0;
	switch (ddrctl & 0xc0000) {
		case DEVSZ_64:  ret = 64 / 8;
		case DEVSZ_128: ret = 128 / 8;
		case DEVSZ_256: ret = 256 / 8;
		case DEVSZ_512: ret = 512 / 8;
	}
	switch (ddrctl & 0x30000) {
		case DEVWD_4:  ret *= 2;
		case DEVWD_8:  ret *= 2;
		case DEVWD_16: break;
803
	}
804
805
	if ((ddrctl & 0xc000) == 0x4000)
		ret *= 2;
806
	return ret;
807
808
809
810
#endif
	BUG();
}

811
812
void __init setup_arch(char **cmdline_p)
{
813
	unsigned long sclk, cclk;
814

815
816
	enable_shadow_console();

817
818
819
820
821
	/* Check to make sure we are running on the right processor */
	if (unlikely(CPUID != bfin_cpuid()))
		printk(KERN_ERR "ERROR: Not running on ADSP-%s: unknown CPUID 0x%04x Rev 0.%d\n",
			CPU, bfin_cpuid(), bfin_revid());

822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
#ifdef CONFIG_DUMMY_CONSOLE
	conswitchp = &dummy_con;
#endif

#if defined(CONFIG_CMDLINE_BOOL)
	strncpy(&command_line[0], CONFIG_CMDLINE, sizeof(command_line));
	command_line[sizeof(command_line) - 1] = 0;
#endif

	/* Keep a copy of command line */
	*cmdline_p = &command_line[0];
	memcpy(boot_command_line, command_line, COMMAND_LINE_SIZE);
	boot_command_line[COMMAND_LINE_SIZE - 1] = '\0';

	memset(&bfin_memmap, 0, sizeof(bfin_memmap));

838
839
840
841
	/* If the user does not specify things on the command line, use
	 * what the bootloader set things up as
	 */
	physical_mem_end = 0;
842
843
	parse_cmdline_early(&command_line[0]);

844
845
846
	if (_ramend == 0)
		_ramend = get_mem_size() * 1024 * 1024;

847
848
849
850
851
	if (physical_mem_end == 0)
		physical_mem_end = _ramend;

	memory_setup();

852
853
854
855
856
857
858
859
860
861
	/* Initialize Async memory banks */
	bfin_write_EBIU_AMBCTL0(AMBCTL0VAL);
	bfin_write_EBIU_AMBCTL1(AMBCTL1VAL);
	bfin_write_EBIU_AMGCTL(AMGCTLVAL);
#ifdef CONFIG_EBIU_MBSCTLVAL
	bfin_write_EBIU_MBSCTL(CONFIG_EBIU_MBSCTLVAL);
	bfin_write_EBIU_MODE(CONFIG_EBIU_MODEVAL);
	bfin_write_EBIU_FCTL(CONFIG_EBIU_FCTLVAL);
#endif

862
863
864
	cclk = get_cclk();
	sclk = get_sclk();

865
866
	if ((ANOMALY_05000273 || ANOMALY_05000274) && (cclk >> 1) < sclk)
		panic("ANOMALY 05000273 or 05000274: CCLK must be >= 2*SCLK");
867
868
869
870
871
872
873
874
875

#ifdef BF561_FAMILY
	if (ANOMALY_05000266) {
		bfin_read_IMDMA_D0_IRQ_STATUS();
		bfin_read_IMDMA_D1_IRQ_STATUS();
	}
#endif
	printk(KERN_INFO "Hardware Trace ");
	if (bfin_read_TBUFCTL() & 0x1)
876
		printk(KERN_CONT "Active ");
877
	else
878
		printk(KERN_CONT "Off ");
879
	if (bfin_read_TBUFCTL() & 0x2)
880
		printk(KERN_CONT "and Enabled\n");
881
	else
882
		printk(KERN_CONT "and Disabled\n");
883

884
885
	printk(KERN_INFO "Boot Mode: %i\n", bfin_read_SYSCR() & 0xF);

886
887
888
	/* Newer parts mirror SWRST bits in SYSCR */
#if defined(CONFIG_BF53x) || defined(CONFIG_BF561) || \
    defined(CONFIG_BF538) || defined(CONFIG_BF539)
889
	_bfin_swrst = bfin_read_SWRST();
890
#else
891
892
	/* Clear boot mode field */
	_bfin_swrst = bfin_read_SYSCR() & ~0xf;
893
#endif
894

895
896
897
898
899
900
#ifdef CONFIG_DEBUG_DOUBLEFAULT_PRINT
	bfin_write_SWRST(_bfin_swrst & ~DOUBLE_FAULT);
#endif
#ifdef CONFIG_DEBUG_DOUBLEFAULT_RESET
	bfin_write_SWRST(_bfin_swrst | DOUBLE_FAULT);
#endif
901

902
903
904
#ifdef CONFIG_SMP
	if (_bfin_swrst & SWRST_DBL_FAULT_A) {
#else
905
	if (_bfin_swrst & RESET_DOUBLE) {
906
#endif
907
908
909
910
911
912
913
914
915
916
917
		printk(KERN_EMERG "Recovering from DOUBLE FAULT event\n");
#ifdef CONFIG_DEBUG_DOUBLEFAULT
		/* We assume the crashing kernel, and the current symbol table match */
		printk(KERN_EMERG " While handling exception (EXCAUSE = 0x%x) at %pF\n",
			(int)init_saved_seqstat & SEQSTAT_EXCAUSE, init_saved_retx);
		printk(KERN_NOTICE "   DCPLB_FAULT_ADDR: %pF\n", init_saved_dcplb_fault_addr);
		printk(KERN_NOTICE "   ICPLB_FAULT_ADDR: %pF\n", init_saved_icplb_fault_addr);
#endif
		printk(KERN_NOTICE " The instruction at %pF caused a double exception\n",
			init_retx);
	} else if (_bfin_swrst & RESET_WDOG)
918
919
920
921
		printk(KERN_INFO "Recovering from Watchdog event\n");
	else if (_bfin_swrst & RESET_SOFTWARE)
		printk(KERN_NOTICE "Reset caused by Software reset\n");

922
	printk(KERN_INFO "Blackfin support (C) 2004-2009 Analog Devices, Inc.\n");
923
924
925
926
927
928
	if (bfin_compiled_revid() == 0xffff)
		printk(KERN_INFO "Compiled for ADSP-%s Rev any\n", CPU);
	else if (bfin_compiled_revid() == -1)
		printk(KERN_INFO "Compiled for ADSP-%s Rev none\n", CPU);
	else
		printk(KERN_INFO "Compiled for ADSP-%s Rev 0.%d\n", CPU, bfin_compiled_revid());
929

930
	if (likely(CPUID == bfin_cpuid())) {
931
932
933
934
		if (bfin_revid() != bfin_compiled_revid()) {
			if (bfin_compiled_revid() == -1)
				printk(KERN_ERR "Warning: Compiled for Rev none, but running on Rev %d\n",
				       bfin_revid());
935
			else if (bfin_compiled_revid() != 0xffff) {
936
937
				printk(KERN_ERR "Warning: Compiled for Rev %d, but running on Rev %d\n",
				       bfin_compiled_revid(), bfin_revid());
938
				if (bfin_compiled_revid() > bfin_revid())
939
					panic("Error: you are missing anomaly workarounds for this rev");
940
			}
941
		}
942
		if (bfin_revid() < CONFIG_BF_REV_MIN || bfin_revid() > CONFIG_BF_REV_MAX)
943
944
			printk(KERN_ERR "Warning: Unsupported Chip Revision ADSP-%s Rev 0.%d detected\n",
			       CPU, bfin_revid());
945
	}
946

Bryan Wu's avatar
Bryan Wu committed
947
948
	printk(KERN_INFO "Blackfin Linux support by http://blackfin.uclinux.org/\n");

949
	printk(KERN_INFO "Processor Speed: %lu MHz core clock and %lu MHz System Clock\n",
950
	       cclk / 1000000, sclk / 1000000);
Bryan Wu's avatar
Bryan Wu committed
951

952
	setup_bootmem_allocator();
Bryan Wu's avatar
Bryan Wu committed
953
954
955

	paging_init();

956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
	/* Copy atomic sequences to their fixed location, and sanity check that
	   these locations are the ones that we advertise to userspace.  */
	memcpy((void *)FIXED_CODE_START, &fixed_code_start,
	       FIXED_CODE_END - FIXED_CODE_START);
	BUG_ON((char *)&sigreturn_stub - (char *)&fixed_code_start
	       != SIGRETURN_STUB - FIXED_CODE_START);
	BUG_ON((char *)&atomic_xchg32 - (char *)&fixed_code_start
	       != ATOMIC_XCHG32 - FIXED_CODE_START);
	BUG_ON((char *)&atomic_cas32 - (char *)&fixed_code_start
	       != ATOMIC_CAS32 - FIXED_CODE_START);
	BUG_ON((char *)&atomic_add32 - (char *)&fixed_code_start
	       != ATOMIC_ADD32 - FIXED_CODE_START);
	BUG_ON((char *)&atomic_sub32 - (char *)&fixed_code_start
	       != ATOMIC_SUB32 - FIXED_CODE_START);
	BUG_ON((char *)&atomic_ior32 - (char *)&fixed_code_start
	       != ATOMIC_IOR32 - FIXED_CODE_START);
	BUG_ON((char *)&atomic_and32 - (char *)&fixed_code_start
	       != ATOMIC_AND32 - FIXED_CODE_START);
	BUG_ON((char *)&atomic_xor32 - (char *)&fixed_code_start
	       != ATOMIC_XOR32 - FIXED_CODE_START);
976
977
	BUG_ON((char *)&safe_user_instruction - (char *)&fixed_code_start
		!= SAFE_USER_INSTRUCTION - FIXED_CODE_START);
978

979
980
981
#ifdef CONFIG_SMP
	platform_init_cpus();
#endif
982
	init_exception_vectors();
983
	bfin_cache_init();	/* Initialize caches for the boot CPU */
Bryan Wu's avatar
Bryan Wu committed
984
985
986
987
}

static int __init topology_init(void)
{
988
989
990
	unsigned int cpu;
	/* Record CPU-private information for the boot processor. */
	bfin_setup_cpudata(0);
991
992

	for_each_possible_cpu(cpu) {
993
		register_cpu(&per_cpu(cpu_data, cpu).cpu, cpu);
994
995
	}

Bryan Wu's avatar
Bryan Wu committed
996
997
998
999
1000
	return 0;
}

subsys_initcall(topology_init);

1001
1002
1003
1004
1005
1006
1007
1008
1009
/* Get the input clock frequency */
static u_long cached_clkin_hz = CONFIG_CLKIN_HZ;
static u_long get_clkin_hz(void)
{
	return cached_clkin_hz;
}
static int __init early_init_clkin_hz(char *buf)
{
	cached_clkin_hz = simple_strtoul(buf, NULL, 0);
1010
1011
1012
1013
#ifdef BFIN_KERNEL_CLOCK
	if (cached_clkin_hz != CONFIG_CLKIN_HZ)
		panic("cannot change clkin_hz when reprogramming clocks");
#endif
1014
1015
1016
1017
	return 1;
}
early_param("clkin_hz=", early_init_clkin_hz);

1018
/* Get the voltage input multiplier */
1019
static u_long get_vco(void)
Bryan Wu's avatar
Bryan Wu committed
1020
{
1021
1022
	static u_long cached_vco;
	u_long msel, pll_ctl;
Bryan Wu's avatar
Bryan Wu committed
1023

1024
1025
1026
1027
	/* The assumption here is that VCO never changes at runtime.
	 * If, someday, we support that, then we'll have to change this.
	 */
	if (cached_vco)
1028
1029
		return cached_vco;

1030
	pll_ctl = bfin_read_PLL_CTL();
1031
	msel = (pll_ctl >> 9) & 0x3F;
Bryan Wu's avatar
Bryan Wu committed
1032
1033
1034
	if (0 == msel)
		msel = 64;

1035
	cached_vco = get_clkin_hz();
1036
1037
1038
	cached_vco >>= (1 & pll_ctl);	/* DF bit */
	cached_vco *= msel;
	return cached_vco;
Bryan Wu's avatar
Bryan Wu committed
1039
1040
}

1041
/* Get the Core clock */
Bryan Wu's avatar
Bryan Wu committed
1042
1043
u_long get_cclk(void)
{
1044
	static u_long cached_cclk_pll_div, cached_cclk;
Bryan Wu's avatar
Bryan Wu committed
1045
	u_long csel, ssel;
1046

Bryan Wu's avatar
Bryan Wu committed
1047
	if (bfin_read_PLL_STAT() & 0x1)
1048
		return get_clkin_hz();
Bryan Wu's avatar
Bryan Wu committed
1049
1050

	ssel = bfin_read_PLL_DIV();
1051
1052
1053
1054
1055
	if (ssel == cached_cclk_pll_div)
		return cached_cclk;
	else
		cached_cclk_pll_div = ssel;

Bryan Wu's avatar
Bryan Wu committed
1056
1057
1058
	csel = ((ssel >> 4) & 0x03);
	ssel &= 0xf;
	if (ssel && ssel < (1 << csel))	/* SCLK > CCLK */
1059
1060
1061
1062
		cached_cclk = get_vco() / ssel;
	else
		cached_cclk = get_vco() >> csel;
	return cached_cclk;
Bryan Wu's avatar
Bryan Wu committed
1063
1064
1065
1066
1067
1068
}
EXPORT_SYMBOL(get_cclk);

/* Get the System clock */
u_long get_sclk(void)
{
1069
	static u_long cached_sclk;
Bryan Wu's avatar
Bryan Wu committed
1070
1071
	u_long ssel;

1072
1073
1074
1075
1076
1077
	/* The assumption here is that SCLK never changes at runtime.
	 * If, someday, we support that, then we'll have to change this.
	 */
	if (cached_sclk)
		return cached_sclk;

Bryan Wu's avatar
Bryan Wu committed
1078
	if (bfin_read_PLL_STAT() & 0x1)
1079
		return get_clkin_hz();
Bryan Wu's avatar
Bryan Wu committed
1080

1081
	ssel = bfin_read_PLL_DIV() & 0xf;
Bryan Wu's avatar
Bryan Wu committed
1082
1083
1084
1085
1086
	if (0 == ssel) {
		printk(KERN_WARNING "Invalid System Clock\n");
		ssel = 1;
	}

1087
1088
	cached_sclk = get_vco() / ssel;
	return cached_sclk;
Bryan Wu's avatar
Bryan Wu committed
1089
1090
1091
}
EXPORT_SYMBOL(get_sclk);

1092
1093
unsigned long sclk_to_usecs(unsigned long sclk)
{
1094
1095
1096
	u64 tmp = USEC_PER_SEC * (u64)sclk;
	do_div(tmp, get_sclk());
	return tmp;
1097
1098
1099
1100
1101
}
EXPORT_SYMBOL(sclk_to_usecs);

unsigned long usecs_to_sclk(unsigned long usecs)
{
1102
1103
1104
	u64 tmp = get_sclk() * (u64)usecs;
	do_div(tmp, USEC_PER_SEC);
	return tmp;
1105
1106
1107
}
EXPORT_SYMBOL(usecs_to_sclk);

Bryan Wu's avatar
Bryan Wu committed
1108
1109
1110
1111
1112
/*
 *	Get CPU information for use by the procfs.
 */
static int show_cpuinfo(struct seq_file *m, void *v)
{
1113
	char *cpu, *mmu, *fpu, *vendor, *cache;
Bryan Wu's avatar
Bryan Wu committed
1114
	uint32_t revid;
1115
	int cpu_num = *(unsigned int *)v;
1116
	u_long sclk, cclk;
1117
	u_int icache_size = BFIN_ICACHESIZE / 1024, dcache_size = 0, dsup_banks = 0;
1118
	struct blackfin_cpudata *cpudata = &per_cpu(cpu_data, cpu_num);
Bryan Wu's avatar
Bryan Wu committed
1119
1120
1121
1122
1123
1124
1125

	cpu = CPU;
	mmu = "none";
	fpu = "none";
	revid = bfin_revid();

	sclk = get_sclk();
1126
	cclk = get_cclk();
Bryan Wu's avatar
Bryan Wu committed
1127

1128
	switch (bfin_read_CHIPID() & CHIPID_MANUFACTURE) {
1129
1130
	case 0xca:
		vendor = "Analog Devices";
1131
1132
		break;
	default:
1133
1134
		vendor = "unknown";
		break;
1135
	}
Bryan Wu's avatar
Bryan Wu committed
1136

1137
	seq_printf(m, "processor\t: %d\n" "vendor_id\t: %s\n", cpu_num, vendor);
1138
1139
1140
1141
1142
1143
1144
1145

	if (CPUID == bfin_cpuid())
		seq_printf(m, "cpu family\t: 0x%04x\n", CPUID);
	else
		seq_printf(m, "cpu family\t: Compiled for:0x%04x, running on:0x%04x\n",
			CPUID, bfin_cpuid());

	seq_printf(m, "model name\t: ADSP-%s %lu(MHz CCLK) %lu(MHz SCLK) (%s)\n"
1146
		"stepping\t: %d ",
1147
		cpu, cclk/1000000, sclk/1000000,
1148
1149
1150
1151
1152
#ifdef CONFIG_MPU
		"mpu on",
#else
		"mpu off",
#endif
1153
1154
		revid);

1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
	if (bfin_revid() != bfin_compiled_revid()) {
		if (bfin_compiled_revid() == -1)
			seq_printf(m, "(Compiled for Rev none)");
		else if (bfin_compiled_revid() == 0xffff)
			seq_printf(m, "(Compiled for Rev any)");
		else
			seq_printf(m, "(Compiled for Rev %d)", bfin_compiled_revid());
	}

	seq_printf(m, "\ncpu MHz\t\t: %lu.%03lu/%lu.%03lu\n",
1165
		cclk/1000000, cclk%1000000,
1166
1167
1168
		sclk/1000000, sclk%1000000);
	seq_printf(m, "bogomips\t: %lu.%02lu\n"
		"Calibration\t: %lu loops\n",
1169
1170
1171
		(loops_per_jiffy * HZ) / 500000,
		((loops_per_jiffy * HZ) / 5000) % 100,
		(loops_per_jiffy * HZ));
1172
1173

	/* Check Cache configutation */
1174
	switch (cpudata->dmemctl & (1 << DMC0_P | 1 << DMC1_P)) {
1175
	case ACACHE_BSRAM:
1176
		cache = "dbank-A/B\t: cache/sram";
1177
1178
1179
1180
		dcache_size = 16;
		dsup_banks = 1;
		break;
	case ACACHE_BCACHE:
1181
		cache = "dbank-A/B\t: cache/cache";
1182
1183
1184
1185
		dcache_size = 32;
		dsup_banks = 2;
		break;
	case ASRAM_BSRAM:
1186
		cache = "dbank-A/B\t: sram/sram";
1187
1188
1189
1190
		dcache_size = 0;
		dsup_banks = 0;
		break;
	default:
1191
		cache = "unknown";
1192
1193
		dcache_size = 0;
		dsup_banks = 0;
Bryan Wu's avatar
Bryan Wu committed
1194
1195
1196
		break;
	}

1197
	/* Is it turned on? */
1198
	if ((cpudata->dmemctl & (ENDCPLB | DMC_ENABLE)) != (ENDCPLB | DMC_ENABLE))
1199
		dcache_size = 0;
Bryan Wu's avatar
Bryan Wu committed
1200

1201
	if ((cpudata->imemctl & (IMC | ENICPLB)) != (IMC | ENICPLB))
1202
1203
		icache_size = 0;

1204
	seq_printf(m, "cache size\t: %d KB(L1 icache) "
1205
1206
		"%d KB(L1 dcache) %d KB(L2 cache)\n",
		icache_size, dcache_size, 0);
1207
	seq_printf(m, "%s\n", cache);
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
	seq_printf(m, "external memory\t: "
#if defined(CONFIG_BFIN_EXTMEM_ICACHEABLE)
		   "cacheable"
#else
		   "uncacheable"
#endif
		   " in instruction cache\n");
	seq_printf(m, "external memory\t: "
#if defined(CONFIG_BFIN_EXTMEM_WRITEBACK)
		      "cacheable (write-back)"
#elif defined(CONFIG_BFIN_EXTMEM_WRITETHROUGH)
		      "cacheable (write-through)"
#else
		      "uncacheable"
#endif
		      " in data cache\n");
1224

1225
1226
1227
1228
1229
1230
	if (icache_size)
		seq_printf(m, "icache setup\t: %d Sub-banks/%d Ways, %d Lines/Way\n",
			   BFIN_ISUBBANKS, BFIN_IWAYS, BFIN_ILINES);
	else
		seq_printf(m, "icache setup\t: off\n");

Bryan Wu's avatar
Bryan Wu committed
1231
	seq_printf(m,
1232
		   "dcache setup\t: %d Super-banks/%d Sub-banks/%d Ways, %d Lines/Way\n",
1233
1234
		   dsup_banks, BFIN_DSUBBANKS, BFIN_DWAYS,
		   BFIN_DLINES);
1235
#ifdef __ARCH_SYNC_CORE_DCACHE
1236
	seq_printf(m, "SMP Dcache Flushes\t: %lu\n\n", cpudata->dcache_invld_count);
1237
#endif
1238
1239
1240
#ifdef __ARCH_SYNC_CORE_ICACHE
	seq_printf(m, "SMP Icache Flushes\t: %lu\n\n", cpudata->icache_invld_count);
#endif
1241
1242

	if (cpu_num != num_possible_cpus() - 1)
1243
1244
		return 0;

1245
	if (L2_LENGTH) {
1246
		seq_printf(m, "L2 SRAM\t\t: %dKB\n", L2_LENGTH/0x400);
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
		seq_printf(m, "L2 SRAM\t\t: "
#if defined(CONFIG_BFIN_L2_ICACHEABLE)
			      "cacheable"
#else
			      "uncacheable"
#endif
			      " in instruction cache\n");
		seq_printf(m, "L2 SRAM\t\t: "
#if defined(CONFIG_BFIN_L2_WRITEBACK)
			      "cacheable (write-back)"
#elif defined(CONFIG_BFIN_L2_WRITETHROUGH)
			      "cacheable (write-through)"
#else
			      "uncacheable"
#endif
			      " in data cache\n");
	}
1264
	seq_printf(m, "board name\t: %s\n", bfin_board_name);
1265
1266
1267
1268
1269
1270
	seq_printf(m, "board memory\t: %ld kB (0x%p -> 0x%p)\n",
		 physical_mem_end >> 10, (void *)0, (void *)physical_mem_end);
	seq_printf(m, "kernel memory\t: %d kB (0x%p -> 0x%p)\n",
		((int)memory_end - (int)_stext) >> 10