blob: eb300550e0938974d79b94ba4bbb7718008d3323 [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 Getzcd8fb8d2008-08-14 14:44:33 +080055unsigned int __initdata *__retx;
Bryan Wu1394f032007-05-06 14:50:22 -070056
Yi Li856783b2008-02-09 02:26:01 +080057/* boot memmap, for parsing "memmap=" */
58#define BFIN_MEMMAP_MAX 128 /* number of entries in bfin_memmap */
59#define BFIN_MEMMAP_RAM 1
60#define BFIN_MEMMAP_RESERVED 2
61struct bfin_memmap {
62 int nr_map;
63 struct bfin_memmap_entry {
64 unsigned long long addr; /* start of memory segment */
65 unsigned long long size;
66 unsigned long type;
67 } map[BFIN_MEMMAP_MAX];
68} bfin_memmap __initdata;
69
70/* for memmap sanitization */
71struct change_member {
72 struct bfin_memmap_entry *pentry; /* pointer to original entry */
73 unsigned long long addr; /* address for this change point */
74};
75static struct change_member change_point_list[2*BFIN_MEMMAP_MAX] __initdata;
76static struct change_member *change_point[2*BFIN_MEMMAP_MAX] __initdata;
77static struct bfin_memmap_entry *overlap_list[BFIN_MEMMAP_MAX] __initdata;
78static struct bfin_memmap_entry new_map[BFIN_MEMMAP_MAX] __initdata;
79
Bryan Wu1394f032007-05-06 14:50:22 -070080void __init bf53x_cache_init(void)
81{
Robin Getz3bebca22007-10-10 23:55:26 +080082#if defined(CONFIG_BFIN_DCACHE) || defined(CONFIG_BFIN_ICACHE)
Bryan Wu1394f032007-05-06 14:50:22 -070083 generate_cpl_tables();
84#endif
85
Robin Getz3bebca22007-10-10 23:55:26 +080086#ifdef CONFIG_BFIN_ICACHE
Bryan Wu1394f032007-05-06 14:50:22 -070087 bfin_icache_init();
88 printk(KERN_INFO "Instruction Cache Enabled\n");
89#endif
90
Robin Getz3bebca22007-10-10 23:55:26 +080091#ifdef CONFIG_BFIN_DCACHE
Bryan Wu1394f032007-05-06 14:50:22 -070092 bfin_dcache_init();
93 printk(KERN_INFO "Data Cache Enabled"
Robin Getz3bebca22007-10-10 23:55:26 +080094# if defined CONFIG_BFIN_WB
Bryan Wu1394f032007-05-06 14:50:22 -070095 " (write-back)"
Robin Getz3bebca22007-10-10 23:55:26 +080096# elif defined CONFIG_BFIN_WT
Bryan Wu1394f032007-05-06 14:50:22 -070097 " (write-through)"
98# endif
99 "\n");
100#endif
101}
102
Mike Frysinger52a07812007-06-11 15:31:30 +0800103void __init bf53x_relocate_l1_mem(void)
Bryan Wu1394f032007-05-06 14:50:22 -0700104{
105 unsigned long l1_code_length;
106 unsigned long l1_data_a_length;
107 unsigned long l1_data_b_length;
Sonic Zhang262c3822008-07-19 15:42:41 +0800108 unsigned long l2_length;
Bryan Wu1394f032007-05-06 14:50:22 -0700109
110 l1_code_length = _etext_l1 - _stext_l1;
111 if (l1_code_length > L1_CODE_LENGTH)
Sonic Zhangb85b82d2008-04-24 06:13:37 +0800112 panic("L1 Instruction SRAM Overflow\n");
Bryan Wu1394f032007-05-06 14:50:22 -0700113 /* cannot complain as printk is not available as yet.
114 * But we can continue booting and complain later!
115 */
116
117 /* Copy _stext_l1 to _etext_l1 to L1 instruction SRAM */
118 dma_memcpy(_stext_l1, _l1_lma_start, l1_code_length);
119
120 l1_data_a_length = _ebss_l1 - _sdata_l1;
121 if (l1_data_a_length > L1_DATA_A_LENGTH)
Sonic Zhangb85b82d2008-04-24 06:13:37 +0800122 panic("L1 Data SRAM Bank A Overflow\n");
Bryan Wu1394f032007-05-06 14:50:22 -0700123
124 /* Copy _sdata_l1 to _ebss_l1 to L1 data bank A SRAM */
125 dma_memcpy(_sdata_l1, _l1_lma_start + l1_code_length, l1_data_a_length);
126
127 l1_data_b_length = _ebss_b_l1 - _sdata_b_l1;
128 if (l1_data_b_length > L1_DATA_B_LENGTH)
Sonic Zhangb85b82d2008-04-24 06:13:37 +0800129 panic("L1 Data SRAM Bank B Overflow\n");
Bryan Wu1394f032007-05-06 14:50:22 -0700130
131 /* Copy _sdata_b_l1 to _ebss_b_l1 to L1 data bank B SRAM */
132 dma_memcpy(_sdata_b_l1, _l1_lma_start + l1_code_length +
133 l1_data_a_length, l1_data_b_length);
Sonic Zhang262c3822008-07-19 15:42:41 +0800134
Mike Frysinger07aa7be2008-08-13 16:16:11 +0800135 if (L2_LENGTH != 0) {
136 l2_length = _ebss_l2 - _stext_l2;
137 if (l2_length > L2_LENGTH)
138 panic("L2 SRAM Overflow\n");
Sonic Zhang262c3822008-07-19 15:42:41 +0800139
Mike Frysinger07aa7be2008-08-13 16:16:11 +0800140 /* Copy _stext_l2 to _edata_l2 to L2 SRAM */
141 dma_memcpy(_stext_l2, _l2_lma_start, l2_length);
142 }
Bryan Wu1394f032007-05-06 14:50:22 -0700143}
144
Yi Li856783b2008-02-09 02:26:01 +0800145/* add_memory_region to memmap */
146static void __init add_memory_region(unsigned long long start,
147 unsigned long long size, int type)
148{
149 int i;
150
151 i = bfin_memmap.nr_map;
152
153 if (i == BFIN_MEMMAP_MAX) {
154 printk(KERN_ERR "Ooops! Too many entries in the memory map!\n");
155 return;
156 }
157
158 bfin_memmap.map[i].addr = start;
159 bfin_memmap.map[i].size = size;
160 bfin_memmap.map[i].type = type;
161 bfin_memmap.nr_map++;
162}
163
164/*
165 * Sanitize the boot memmap, removing overlaps.
166 */
167static int __init sanitize_memmap(struct bfin_memmap_entry *map, int *pnr_map)
168{
169 struct change_member *change_tmp;
170 unsigned long current_type, last_type;
171 unsigned long long last_addr;
172 int chgidx, still_changing;
173 int overlap_entries;
174 int new_entry;
175 int old_nr, new_nr, chg_nr;
176 int i;
177
178 /*
179 Visually we're performing the following (1,2,3,4 = memory types)
180
181 Sample memory map (w/overlaps):
182 ____22__________________
183 ______________________4_
184 ____1111________________
185 _44_____________________
186 11111111________________
187 ____________________33__
188 ___________44___________
189 __________33333_________
190 ______________22________
191 ___________________2222_
192 _________111111111______
193 _____________________11_
194 _________________4______
195
196 Sanitized equivalent (no overlap):
197 1_______________________
198 _44_____________________
199 ___1____________________
200 ____22__________________
201 ______11________________
202 _________1______________
203 __________3_____________
204 ___________44___________
205 _____________33_________
206 _______________2________
207 ________________1_______
208 _________________4______
209 ___________________2____
210 ____________________33__
211 ______________________4_
212 */
213 /* if there's only one memory region, don't bother */
214 if (*pnr_map < 2)
215 return -1;
216
217 old_nr = *pnr_map;
218
219 /* bail out if we find any unreasonable addresses in memmap */
220 for (i = 0; i < old_nr; i++)
221 if (map[i].addr + map[i].size < map[i].addr)
222 return -1;
223
224 /* create pointers for initial change-point information (for sorting) */
225 for (i = 0; i < 2*old_nr; i++)
226 change_point[i] = &change_point_list[i];
227
228 /* record all known change-points (starting and ending addresses),
229 omitting those that are for empty memory regions */
230 chgidx = 0;
231 for (i = 0; i < old_nr; i++) {
232 if (map[i].size != 0) {
233 change_point[chgidx]->addr = map[i].addr;
234 change_point[chgidx++]->pentry = &map[i];
235 change_point[chgidx]->addr = map[i].addr + map[i].size;
236 change_point[chgidx++]->pentry = &map[i];
237 }
238 }
239 chg_nr = chgidx; /* true number of change-points */
240
241 /* sort change-point list by memory addresses (low -> high) */
242 still_changing = 1;
243 while (still_changing) {
244 still_changing = 0;
245 for (i = 1; i < chg_nr; i++) {
246 /* if <current_addr> > <last_addr>, swap */
247 /* or, if current=<start_addr> & last=<end_addr>, swap */
248 if ((change_point[i]->addr < change_point[i-1]->addr) ||
249 ((change_point[i]->addr == change_point[i-1]->addr) &&
250 (change_point[i]->addr == change_point[i]->pentry->addr) &&
251 (change_point[i-1]->addr != change_point[i-1]->pentry->addr))
252 ) {
253 change_tmp = change_point[i];
254 change_point[i] = change_point[i-1];
255 change_point[i-1] = change_tmp;
256 still_changing = 1;
257 }
258 }
259 }
260
261 /* create a new memmap, removing overlaps */
262 overlap_entries = 0; /* number of entries in the overlap table */
263 new_entry = 0; /* index for creating new memmap entries */
264 last_type = 0; /* start with undefined memory type */
265 last_addr = 0; /* start with 0 as last starting address */
266 /* loop through change-points, determining affect on the new memmap */
267 for (chgidx = 0; chgidx < chg_nr; chgidx++) {
268 /* keep track of all overlapping memmap entries */
269 if (change_point[chgidx]->addr == change_point[chgidx]->pentry->addr) {
270 /* add map entry to overlap list (> 1 entry implies an overlap) */
271 overlap_list[overlap_entries++] = change_point[chgidx]->pentry;
272 } else {
273 /* remove entry from list (order independent, so swap with last) */
274 for (i = 0; i < overlap_entries; i++) {
275 if (overlap_list[i] == change_point[chgidx]->pentry)
276 overlap_list[i] = overlap_list[overlap_entries-1];
277 }
278 overlap_entries--;
279 }
280 /* if there are overlapping entries, decide which "type" to use */
281 /* (larger value takes precedence -- 1=usable, 2,3,4,4+=unusable) */
282 current_type = 0;
283 for (i = 0; i < overlap_entries; i++)
284 if (overlap_list[i]->type > current_type)
285 current_type = overlap_list[i]->type;
286 /* continue building up new memmap based on this information */
287 if (current_type != last_type) {
288 if (last_type != 0) {
289 new_map[new_entry].size =
290 change_point[chgidx]->addr - last_addr;
291 /* move forward only if the new size was non-zero */
292 if (new_map[new_entry].size != 0)
293 if (++new_entry >= BFIN_MEMMAP_MAX)
294 break; /* no more space left for new entries */
295 }
296 if (current_type != 0) {
297 new_map[new_entry].addr = change_point[chgidx]->addr;
298 new_map[new_entry].type = current_type;
299 last_addr = change_point[chgidx]->addr;
300 }
301 last_type = current_type;
302 }
303 }
304 new_nr = new_entry; /* retain count for new entries */
305
306 /* copy new mapping into original location */
307 memcpy(map, new_map, new_nr*sizeof(struct bfin_memmap_entry));
308 *pnr_map = new_nr;
309
310 return 0;
311}
312
313static void __init print_memory_map(char *who)
314{
315 int i;
316
317 for (i = 0; i < bfin_memmap.nr_map; i++) {
318 printk(KERN_DEBUG " %s: %016Lx - %016Lx ", who,
319 bfin_memmap.map[i].addr,
320 bfin_memmap.map[i].addr + bfin_memmap.map[i].size);
321 switch (bfin_memmap.map[i].type) {
322 case BFIN_MEMMAP_RAM:
323 printk("(usable)\n");
324 break;
325 case BFIN_MEMMAP_RESERVED:
326 printk("(reserved)\n");
327 break;
328 default: printk("type %lu\n", bfin_memmap.map[i].type);
329 break;
330 }
331 }
332}
333
334static __init int parse_memmap(char *arg)
335{
336 unsigned long long start_at, mem_size;
337
338 if (!arg)
339 return -EINVAL;
340
341 mem_size = memparse(arg, &arg);
342 if (*arg == '@') {
343 start_at = memparse(arg+1, &arg);
344 add_memory_region(start_at, mem_size, BFIN_MEMMAP_RAM);
345 } else if (*arg == '$') {
346 start_at = memparse(arg+1, &arg);
347 add_memory_region(start_at, mem_size, BFIN_MEMMAP_RESERVED);
348 }
349
350 return 0;
351}
352
Bryan Wu1394f032007-05-06 14:50:22 -0700353/*
354 * Initial parsing of the command line. Currently, we support:
355 * - Controlling the linux memory size: mem=xxx[KMG]
356 * - Controlling the physical memory size: max_mem=xxx[KMG][$][#]
357 * $ -> reserved memory is dcacheable
358 * # -> reserved memory is icacheable
Yi Li856783b2008-02-09 02:26:01 +0800359 * - "memmap=XXX[KkmM][@][$]XXX[KkmM]" defines a memory region
360 * @ from <start> to <start>+<mem>, type RAM
361 * $ from <start> to <start>+<mem>, type RESERVED
362 *
Bryan Wu1394f032007-05-06 14:50:22 -0700363 */
364static __init void parse_cmdline_early(char *cmdline_p)
365{
366 char c = ' ', *to = cmdline_p;
367 unsigned int memsize;
368 for (;;) {
369 if (c == ' ') {
Bryan Wu1394f032007-05-06 14:50:22 -0700370 if (!memcmp(to, "mem=", 4)) {
371 to += 4;
372 memsize = memparse(to, &to);
373 if (memsize)
374 _ramend = memsize;
375
376 } else if (!memcmp(to, "max_mem=", 8)) {
377 to += 8;
378 memsize = memparse(to, &to);
379 if (memsize) {
380 physical_mem_end = memsize;
381 if (*to != ' ') {
382 if (*to == '$'
383 || *(to + 1) == '$')
384 reserved_mem_dcache_on =
385 1;
386 if (*to == '#'
387 || *(to + 1) == '#')
388 reserved_mem_icache_on =
389 1;
390 }
391 }
Robin Getzce3afa12007-10-09 17:28:36 +0800392 } else if (!memcmp(to, "earlyprintk=", 12)) {
393 to += 12;
394 setup_early_printk(to);
Yi Li856783b2008-02-09 02:26:01 +0800395 } else if (!memcmp(to, "memmap=", 7)) {
396 to += 7;
397 parse_memmap(to);
Bryan Wu1394f032007-05-06 14:50:22 -0700398 }
Bryan Wu1394f032007-05-06 14:50:22 -0700399 }
400 c = *(to++);
401 if (!c)
402 break;
403 }
404}
405
Yi Li856783b2008-02-09 02:26:01 +0800406/*
407 * Setup memory defaults from user config.
408 * The physical memory layout looks like:
409 *
410 * [_rambase, _ramstart]: kernel image
411 * [memory_start, memory_end]: dynamic memory managed by kernel
412 * [memory_end, _ramend]: reserved memory
413 * [meory_mtd_start(memory_end),
414 * memory_mtd_start + mtd_size]: rootfs (if any)
415 * [_ramend - DMA_UNCACHED_REGION,
416 * _ramend]: uncached DMA region
417 * [_ramend, physical_mem_end]: memory not managed by kernel
418 *
419 */
420static __init void memory_setup(void)
Bryan Wu1394f032007-05-06 14:50:22 -0700421{
Mike Frysingerc0eab3b2008-02-02 15:36:11 +0800422#ifdef CONFIG_MTD_UCLINUX
423 unsigned long mtd_phys = 0;
424#endif
425
Yi Li856783b2008-02-09 02:26:01 +0800426 _rambase = (unsigned long)_stext;
Mike Frysingerb7627ac2008-02-02 15:53:17 +0800427 _ramstart = (unsigned long)_end;
Bryan Wu1394f032007-05-06 14:50:22 -0700428
Yi Li856783b2008-02-09 02:26:01 +0800429 if (DMA_UNCACHED_REGION > (_ramend - _ramstart)) {
430 console_init();
431 panic("DMA region exceeds memory limit: %lu.\n",
432 _ramend - _ramstart);
Mike Frysinger1aafd902007-07-25 11:19:14 +0800433 }
Bryan Wu1394f032007-05-06 14:50:22 -0700434 memory_end = _ramend - DMA_UNCACHED_REGION;
435
Bernd Schmidtb97b8a92008-01-27 18:39:16 +0800436#ifdef CONFIG_MPU
437 /* Round up to multiple of 4MB. */
438 memory_start = (_ramstart + 0x3fffff) & ~0x3fffff;
439#else
Bryan Wu1394f032007-05-06 14:50:22 -0700440 memory_start = PAGE_ALIGN(_ramstart);
Bernd Schmidtb97b8a92008-01-27 18:39:16 +0800441#endif
Bryan Wu1394f032007-05-06 14:50:22 -0700442
443#if defined(CONFIG_MTD_UCLINUX)
444 /* generic memory mapped MTD driver */
445 memory_mtd_end = memory_end;
446
447 mtd_phys = _ramstart;
448 mtd_size = PAGE_ALIGN(*((unsigned long *)(mtd_phys + 8)));
449
450# if defined(CONFIG_EXT2_FS) || defined(CONFIG_EXT3_FS)
451 if (*((unsigned short *)(mtd_phys + 0x438)) == EXT2_SUPER_MAGIC)
452 mtd_size =
453 PAGE_ALIGN(*((unsigned long *)(mtd_phys + 0x404)) << 10);
454# endif
455
456# if defined(CONFIG_CRAMFS)
457 if (*((unsigned long *)(mtd_phys)) == CRAMFS_MAGIC)
458 mtd_size = PAGE_ALIGN(*((unsigned long *)(mtd_phys + 0x4)));
459# endif
460
461# if defined(CONFIG_ROMFS_FS)
462 if (((unsigned long *)mtd_phys)[0] == ROMSB_WORD0
463 && ((unsigned long *)mtd_phys)[1] == ROMSB_WORD1)
464 mtd_size =
465 PAGE_ALIGN(be32_to_cpu(((unsigned long *)mtd_phys)[2]));
Robin Getz3bebca22007-10-10 23:55:26 +0800466# if (defined(CONFIG_BFIN_ICACHE) && ANOMALY_05000263)
Bryan Wu1394f032007-05-06 14:50:22 -0700467 /* Due to a Hardware Anomaly we need to limit the size of usable
468 * instruction memory to max 60MB, 56 if HUNT_FOR_ZERO is on
469 * 05000263 - Hardware loop corrupted when taking an ICPLB exception
470 */
471# if (defined(CONFIG_DEBUG_HUNT_FOR_ZERO))
472 if (memory_end >= 56 * 1024 * 1024)
473 memory_end = 56 * 1024 * 1024;
474# else
475 if (memory_end >= 60 * 1024 * 1024)
476 memory_end = 60 * 1024 * 1024;
477# endif /* CONFIG_DEBUG_HUNT_FOR_ZERO */
478# endif /* ANOMALY_05000263 */
479# endif /* CONFIG_ROMFS_FS */
480
481 memory_end -= mtd_size;
482
483 if (mtd_size == 0) {
484 console_init();
485 panic("Don't boot kernel without rootfs attached.\n");
486 }
487
488 /* Relocate MTD image to the top of memory after the uncached memory area */
Mike Frysingerb7627ac2008-02-02 15:53:17 +0800489 dma_memcpy((char *)memory_end, _end, mtd_size);
Bryan Wu1394f032007-05-06 14:50:22 -0700490
491 memory_mtd_start = memory_end;
492 _ebss = memory_mtd_start; /* define _ebss for compatible */
493#endif /* CONFIG_MTD_UCLINUX */
494
Robin Getz3bebca22007-10-10 23:55:26 +0800495#if (defined(CONFIG_BFIN_ICACHE) && ANOMALY_05000263)
Bryan Wu1394f032007-05-06 14:50:22 -0700496 /* Due to a Hardware Anomaly we need to limit the size of usable
497 * instruction memory to max 60MB, 56 if HUNT_FOR_ZERO is on
498 * 05000263 - Hardware loop corrupted when taking an ICPLB exception
499 */
500#if (defined(CONFIG_DEBUG_HUNT_FOR_ZERO))
501 if (memory_end >= 56 * 1024 * 1024)
502 memory_end = 56 * 1024 * 1024;
503#else
504 if (memory_end >= 60 * 1024 * 1024)
505 memory_end = 60 * 1024 * 1024;
506#endif /* CONFIG_DEBUG_HUNT_FOR_ZERO */
507 printk(KERN_NOTICE "Warning: limiting memory to %liMB due to hardware anomaly 05000263\n", memory_end >> 20);
508#endif /* ANOMALY_05000263 */
509
Bernd Schmidtb97b8a92008-01-27 18:39:16 +0800510#ifdef CONFIG_MPU
511 page_mask_nelts = ((_ramend >> PAGE_SHIFT) + 31) / 32;
512 page_mask_order = get_order(3 * page_mask_nelts * sizeof(long));
513#endif
514
Bryan Wu1394f032007-05-06 14:50:22 -0700515#if !defined(CONFIG_MTD_UCLINUX)
Yi Li856783b2008-02-09 02:26:01 +0800516 /*In case there is no valid CPLB behind memory_end make sure we don't get to close*/
517 memory_end -= SIZE_4K;
Bryan Wu1394f032007-05-06 14:50:22 -0700518#endif
Yi Li856783b2008-02-09 02:26:01 +0800519
Bryan Wu1394f032007-05-06 14:50:22 -0700520 init_mm.start_code = (unsigned long)_stext;
521 init_mm.end_code = (unsigned long)_etext;
522 init_mm.end_data = (unsigned long)_edata;
523 init_mm.brk = (unsigned long)0;
524
Yi Li856783b2008-02-09 02:26:01 +0800525 printk(KERN_INFO "Board Memory: %ldMB\n", physical_mem_end >> 20);
526 printk(KERN_INFO "Kernel Managed Memory: %ldMB\n", _ramend >> 20);
527
Mike Frysingerb7627ac2008-02-02 15:53:17 +0800528 printk(KERN_INFO "Memory map:\n"
Mike Frysinger8929ecf82008-02-22 16:35:20 +0800529 KERN_INFO " fixedcode = 0x%p-0x%p\n"
Yi Li856783b2008-02-09 02:26:01 +0800530 KERN_INFO " text = 0x%p-0x%p\n"
531 KERN_INFO " rodata = 0x%p-0x%p\n"
Mike Frysingerb7627ac2008-02-02 15:53:17 +0800532 KERN_INFO " bss = 0x%p-0x%p\n"
Yi Li856783b2008-02-09 02:26:01 +0800533 KERN_INFO " data = 0x%p-0x%p\n"
534 KERN_INFO " stack = 0x%p-0x%p\n"
535 KERN_INFO " init = 0x%p-0x%p\n"
Yi Li856783b2008-02-09 02:26:01 +0800536 KERN_INFO " available = 0x%p-0x%p\n"
537#ifdef CONFIG_MTD_UCLINUX
538 KERN_INFO " rootfs = 0x%p-0x%p\n"
539#endif
540#if DMA_UNCACHED_REGION > 0
541 KERN_INFO " DMA Zone = 0x%p-0x%p\n"
542#endif
Mike Frysinger8929ecf82008-02-22 16:35:20 +0800543 , (void *)FIXED_CODE_START, (void *)FIXED_CODE_END,
544 _stext, _etext,
Yi Li856783b2008-02-09 02:26:01 +0800545 __start_rodata, __end_rodata,
Mike Frysingerb7627ac2008-02-02 15:53:17 +0800546 __bss_start, __bss_stop,
Yi Li856783b2008-02-09 02:26:01 +0800547 _sdata, _edata,
548 (void *)&init_thread_union,
549 (void *)((int)(&init_thread_union) + 0x2000),
Mike Frysingerb7627ac2008-02-02 15:53:17 +0800550 __init_begin, __init_end,
551 (void *)_ramstart, (void *)memory_end
Yi Li856783b2008-02-09 02:26:01 +0800552#ifdef CONFIG_MTD_UCLINUX
553 , (void *)memory_mtd_start, (void *)(memory_mtd_start + mtd_size)
554#endif
555#if DMA_UNCACHED_REGION > 0
556 , (void *)(_ramend - DMA_UNCACHED_REGION), (void *)(_ramend)
557#endif
558 );
559}
560
Yi Li2e8d7962008-03-26 07:08:12 +0800561/*
562 * Find the lowest, highest page frame number we have available
563 */
564void __init find_min_max_pfn(void)
565{
566 int i;
567
568 max_pfn = 0;
569 min_low_pfn = memory_end;
570
571 for (i = 0; i < bfin_memmap.nr_map; i++) {
572 unsigned long start, end;
573 /* RAM? */
574 if (bfin_memmap.map[i].type != BFIN_MEMMAP_RAM)
575 continue;
576 start = PFN_UP(bfin_memmap.map[i].addr);
577 end = PFN_DOWN(bfin_memmap.map[i].addr +
578 bfin_memmap.map[i].size);
579 if (start >= end)
580 continue;
581 if (end > max_pfn)
582 max_pfn = end;
583 if (start < min_low_pfn)
584 min_low_pfn = start;
585 }
586}
587
Yi Li856783b2008-02-09 02:26:01 +0800588static __init void setup_bootmem_allocator(void)
589{
590 int bootmap_size;
591 int i;
Yi Li2e8d7962008-03-26 07:08:12 +0800592 unsigned long start_pfn, end_pfn;
Yi Li856783b2008-02-09 02:26:01 +0800593 unsigned long curr_pfn, last_pfn, size;
594
595 /* mark memory between memory_start and memory_end usable */
596 add_memory_region(memory_start,
597 memory_end - memory_start, BFIN_MEMMAP_RAM);
598 /* sanity check for overlap */
599 sanitize_memmap(bfin_memmap.map, &bfin_memmap.nr_map);
600 print_memory_map("boot memmap");
601
Yi Li2e8d7962008-03-26 07:08:12 +0800602 /* intialize globals in linux/bootmem.h */
603 find_min_max_pfn();
604 /* pfn of the last usable page frame */
605 if (max_pfn > memory_end >> PAGE_SHIFT)
606 max_pfn = memory_end >> PAGE_SHIFT;
607 /* pfn of last page frame directly mapped by kernel */
608 max_low_pfn = max_pfn;
609 /* pfn of the first usable page frame after kernel image*/
610 if (min_low_pfn < memory_start >> PAGE_SHIFT)
611 min_low_pfn = memory_start >> PAGE_SHIFT;
612
613 start_pfn = PAGE_OFFSET >> PAGE_SHIFT;
614 end_pfn = memory_end >> PAGE_SHIFT;
Yi Li856783b2008-02-09 02:26:01 +0800615
616 /*
617 * give all the memory to the bootmap allocator, tell it to put the
618 * boot mem_map at the start of memory.
619 */
620 bootmap_size = init_bootmem_node(NODE_DATA(0),
621 memory_start >> PAGE_SHIFT, /* map goes here */
Yi Li2e8d7962008-03-26 07:08:12 +0800622 start_pfn, end_pfn);
Yi Li856783b2008-02-09 02:26:01 +0800623
624 /* register the memmap regions with the bootmem allocator */
625 for (i = 0; i < bfin_memmap.nr_map; i++) {
626 /*
627 * Reserve usable memory
628 */
629 if (bfin_memmap.map[i].type != BFIN_MEMMAP_RAM)
630 continue;
631 /*
632 * We are rounding up the start address of usable memory:
633 */
634 curr_pfn = PFN_UP(bfin_memmap.map[i].addr);
Yi Li2e8d7962008-03-26 07:08:12 +0800635 if (curr_pfn >= end_pfn)
Yi Li856783b2008-02-09 02:26:01 +0800636 continue;
637 /*
638 * ... and at the end of the usable range downwards:
639 */
640 last_pfn = PFN_DOWN(bfin_memmap.map[i].addr +
641 bfin_memmap.map[i].size);
642
Yi Li2e8d7962008-03-26 07:08:12 +0800643 if (last_pfn > end_pfn)
644 last_pfn = end_pfn;
Yi Li856783b2008-02-09 02:26:01 +0800645
646 /*
647 * .. finally, did all the rounding and playing
648 * around just make the area go away?
649 */
650 if (last_pfn <= curr_pfn)
651 continue;
652
653 size = last_pfn - curr_pfn;
654 free_bootmem(PFN_PHYS(curr_pfn), PFN_PHYS(size));
655 }
656
657 /* reserve memory before memory_start, including bootmap */
658 reserve_bootmem(PAGE_OFFSET,
659 memory_start + bootmap_size + PAGE_SIZE - 1 - PAGE_OFFSET,
660 BOOTMEM_DEFAULT);
661}
662
Mike Frysingera086ee22008-04-25 02:04:05 +0800663#define EBSZ_TO_MEG(ebsz) \
664({ \
665 int meg = 0; \
666 switch (ebsz & 0xf) { \
667 case 0x1: meg = 16; break; \
668 case 0x3: meg = 32; break; \
669 case 0x5: meg = 64; break; \
670 case 0x7: meg = 128; break; \
671 case 0x9: meg = 256; break; \
672 case 0xb: meg = 512; break; \
673 } \
674 meg; \
675})
676static inline int __init get_mem_size(void)
677{
Michael Hennerich99d95bb2008-07-14 17:04:14 +0800678#if defined(EBIU_SDBCTL)
679# if defined(BF561_FAMILY)
Mike Frysingera086ee22008-04-25 02:04:05 +0800680 int ret = 0;
681 u32 sdbctl = bfin_read_EBIU_SDBCTL();
682 ret += EBSZ_TO_MEG(sdbctl >> 0);
683 ret += EBSZ_TO_MEG(sdbctl >> 8);
684 ret += EBSZ_TO_MEG(sdbctl >> 16);
685 ret += EBSZ_TO_MEG(sdbctl >> 24);
686 return ret;
Michael Hennerich99d95bb2008-07-14 17:04:14 +0800687# else
Mike Frysingera086ee22008-04-25 02:04:05 +0800688 return EBSZ_TO_MEG(bfin_read_EBIU_SDBCTL());
Michael Hennerich99d95bb2008-07-14 17:04:14 +0800689# endif
690#elif defined(EBIU_DDRCTL1)
Michael Hennerich1e780422008-04-25 04:31:23 +0800691 u32 ddrctl = bfin_read_EBIU_DDRCTL1();
692 int ret = 0;
693 switch (ddrctl & 0xc0000) {
694 case DEVSZ_64: ret = 64 / 8;
695 case DEVSZ_128: ret = 128 / 8;
696 case DEVSZ_256: ret = 256 / 8;
697 case DEVSZ_512: ret = 512 / 8;
Mike Frysingera086ee22008-04-25 02:04:05 +0800698 }
Michael Hennerich1e780422008-04-25 04:31:23 +0800699 switch (ddrctl & 0x30000) {
700 case DEVWD_4: ret *= 2;
701 case DEVWD_8: ret *= 2;
702 case DEVWD_16: break;
703 }
Mike Frysingerb1b154e2008-07-26 18:02:05 +0800704 if ((ddrctl & 0xc000) == 0x4000)
705 ret *= 2;
Michael Hennerich1e780422008-04-25 04:31:23 +0800706 return ret;
Mike Frysingera086ee22008-04-25 02:04:05 +0800707#endif
708 BUG();
709}
710
Yi Li856783b2008-02-09 02:26:01 +0800711void __init setup_arch(char **cmdline_p)
712{
Mike Frysinger9f8e8952008-04-24 06:20:11 +0800713 unsigned long sclk, cclk;
Yi Li856783b2008-02-09 02:26:01 +0800714
715#ifdef CONFIG_DUMMY_CONSOLE
716 conswitchp = &dummy_con;
717#endif
718
719#if defined(CONFIG_CMDLINE_BOOL)
720 strncpy(&command_line[0], CONFIG_CMDLINE, sizeof(command_line));
721 command_line[sizeof(command_line) - 1] = 0;
722#endif
723
724 /* Keep a copy of command line */
725 *cmdline_p = &command_line[0];
726 memcpy(boot_command_line, command_line, COMMAND_LINE_SIZE);
727 boot_command_line[COMMAND_LINE_SIZE - 1] = '\0';
728
729 /* setup memory defaults from the user config */
730 physical_mem_end = 0;
Mike Frysingera086ee22008-04-25 02:04:05 +0800731 _ramend = get_mem_size() * 1024 * 1024;
Yi Li856783b2008-02-09 02:26:01 +0800732
733 memset(&bfin_memmap, 0, sizeof(bfin_memmap));
734
735 parse_cmdline_early(&command_line[0]);
736
737 if (physical_mem_end == 0)
738 physical_mem_end = _ramend;
739
740 memory_setup();
741
Mike Frysinger7e64aca2008-08-06 17:17:10 +0800742 /* Initialize Async memory banks */
743 bfin_write_EBIU_AMBCTL0(AMBCTL0VAL);
744 bfin_write_EBIU_AMBCTL1(AMBCTL1VAL);
745 bfin_write_EBIU_AMGCTL(AMGCTLVAL);
746#ifdef CONFIG_EBIU_MBSCTLVAL
747 bfin_write_EBIU_MBSCTL(CONFIG_EBIU_MBSCTLVAL);
748 bfin_write_EBIU_MODE(CONFIG_EBIU_MODEVAL);
749 bfin_write_EBIU_FCTL(CONFIG_EBIU_FCTLVAL);
750#endif
751
Yi Li856783b2008-02-09 02:26:01 +0800752 cclk = get_cclk();
753 sclk = get_sclk();
754
755#if !defined(CONFIG_BFIN_KERNEL_CLOCK)
756 if (ANOMALY_05000273 && cclk == sclk)
757 panic("ANOMALY 05000273, SCLK can not be same as CCLK");
758#endif
759
760#ifdef BF561_FAMILY
761 if (ANOMALY_05000266) {
762 bfin_read_IMDMA_D0_IRQ_STATUS();
763 bfin_read_IMDMA_D1_IRQ_STATUS();
764 }
765#endif
766 printk(KERN_INFO "Hardware Trace ");
767 if (bfin_read_TBUFCTL() & 0x1)
768 printk("Active ");
769 else
770 printk("Off ");
771 if (bfin_read_TBUFCTL() & 0x2)
772 printk("and Enabled\n");
773 else
774 printk("and Disabled\n");
775
776#if defined(CONFIG_CHR_DEV_FLASH) || defined(CONFIG_BLK_DEV_FLASH)
777 /* we need to initialize the Flashrom device here since we might
778 * do things with flash early on in the boot
779 */
780 flash_probe();
781#endif
782
Robin Getz7728ec32007-10-29 18:12:15 +0800783 _bfin_swrst = bfin_read_SWRST();
784
Robin Getz2d200982008-07-26 19:41:40 +0800785 /* If we double fault, reset the system - otherwise we hang forever */
786 bfin_write_SWRST(DOUBLE_FAULT);
787
Robin Getz7728ec32007-10-29 18:12:15 +0800788 if (_bfin_swrst & RESET_DOUBLE)
Robin Getzcd8fb8d2008-08-14 14:44:33 +0800789 /*
790 * don't decode the address, since you don't know if this
791 * kernel's symbol map is the same as the crashing kernel
792 */
793 printk(KERN_INFO "Recovering from Double Fault event at %p\n", __retx);
Robin Getz7728ec32007-10-29 18:12:15 +0800794 else if (_bfin_swrst & RESET_WDOG)
795 printk(KERN_INFO "Recovering from Watchdog event\n");
796 else if (_bfin_swrst & RESET_SOFTWARE)
797 printk(KERN_NOTICE "Reset caused by Software reset\n");
798
Mike Frysinger550d5532008-02-02 15:55:37 +0800799 printk(KERN_INFO "Blackfin support (C) 2004-2008 Analog Devices, Inc.\n");
Jie Zhangde3025f2007-06-25 18:04:12 +0800800 if (bfin_compiled_revid() == 0xffff)
801 printk(KERN_INFO "Compiled for ADSP-%s Rev any\n", CPU);
802 else if (bfin_compiled_revid() == -1)
803 printk(KERN_INFO "Compiled for ADSP-%s Rev none\n", CPU);
804 else
805 printk(KERN_INFO "Compiled for ADSP-%s Rev 0.%d\n", CPU, bfin_compiled_revid());
806 if (bfin_revid() != bfin_compiled_revid()) {
807 if (bfin_compiled_revid() == -1)
808 printk(KERN_ERR "Warning: Compiled for Rev none, but running on Rev %d\n",
809 bfin_revid());
810 else if (bfin_compiled_revid() != 0xffff)
811 printk(KERN_ERR "Warning: Compiled for Rev %d, but running on Rev %d\n",
812 bfin_compiled_revid(), bfin_revid());
813 }
Bryan Wu1394f032007-05-06 14:50:22 -0700814 if (bfin_revid() < SUPPORTED_REVID)
815 printk(KERN_ERR "Warning: Unsupported Chip Revision ADSP-%s Rev 0.%d detected\n",
816 CPU, bfin_revid());
817 printk(KERN_INFO "Blackfin Linux support by http://blackfin.uclinux.org/\n");
818
Mike Frysingerb5c0e2e2007-09-12 17:31:59 +0800819 printk(KERN_INFO "Processor Speed: %lu MHz core clock and %lu MHz System Clock\n",
Bryan Wu1394f032007-05-06 14:50:22 -0700820 cclk / 1000000, sclk / 1000000);
821
Mike Frysinger1aafd902007-07-25 11:19:14 +0800822 if (ANOMALY_05000273 && (cclk >> 1) <= sclk)
Bryan Wu1394f032007-05-06 14:50:22 -0700823 printk("\n\n\nANOMALY_05000273: CCLK must be >= 2*SCLK !!!\n\n\n");
Bryan Wu1394f032007-05-06 14:50:22 -0700824
Yi Li856783b2008-02-09 02:26:01 +0800825 setup_bootmem_allocator();
Bryan Wu1394f032007-05-06 14:50:22 -0700826
Bryan Wu1394f032007-05-06 14:50:22 -0700827 paging_init();
828
Bernd Schmidt7adfb582007-06-21 11:34:16 +0800829 /* Copy atomic sequences to their fixed location, and sanity check that
830 these locations are the ones that we advertise to userspace. */
831 memcpy((void *)FIXED_CODE_START, &fixed_code_start,
832 FIXED_CODE_END - FIXED_CODE_START);
833 BUG_ON((char *)&sigreturn_stub - (char *)&fixed_code_start
834 != SIGRETURN_STUB - FIXED_CODE_START);
835 BUG_ON((char *)&atomic_xchg32 - (char *)&fixed_code_start
836 != ATOMIC_XCHG32 - FIXED_CODE_START);
837 BUG_ON((char *)&atomic_cas32 - (char *)&fixed_code_start
838 != ATOMIC_CAS32 - FIXED_CODE_START);
839 BUG_ON((char *)&atomic_add32 - (char *)&fixed_code_start
840 != ATOMIC_ADD32 - FIXED_CODE_START);
841 BUG_ON((char *)&atomic_sub32 - (char *)&fixed_code_start
842 != ATOMIC_SUB32 - FIXED_CODE_START);
843 BUG_ON((char *)&atomic_ior32 - (char *)&fixed_code_start
844 != ATOMIC_IOR32 - FIXED_CODE_START);
845 BUG_ON((char *)&atomic_and32 - (char *)&fixed_code_start
846 != ATOMIC_AND32 - FIXED_CODE_START);
847 BUG_ON((char *)&atomic_xor32 - (char *)&fixed_code_start
848 != ATOMIC_XOR32 - FIXED_CODE_START);
Robin Getz9f336a52007-10-29 18:23:28 +0800849 BUG_ON((char *)&safe_user_instruction - (char *)&fixed_code_start
850 != SAFE_USER_INSTRUCTION - FIXED_CODE_START);
Bernd Schmidt29440a22007-07-12 16:25:29 +0800851
Bernd Schmidt8be80ed2007-07-25 14:44:49 +0800852 init_exception_vectors();
Bernd Schmidt29440a22007-07-12 16:25:29 +0800853 bf53x_cache_init();
Bryan Wu1394f032007-05-06 14:50:22 -0700854}
855
Bryan Wu1394f032007-05-06 14:50:22 -0700856static int __init topology_init(void)
857{
Michael Hennerich6cda2e92008-02-02 15:10:51 +0800858 int cpu;
859
860 for_each_possible_cpu(cpu) {
861 struct cpu *c = &per_cpu(cpu_devices, cpu);
862
863 register_cpu(c, cpu);
864 }
865
Bryan Wu1394f032007-05-06 14:50:22 -0700866 return 0;
Bryan Wu1394f032007-05-06 14:50:22 -0700867}
868
869subsys_initcall(topology_init);
870
Mike Frysinger3a2521f2008-07-26 18:52:56 +0800871/* Get the voltage input multiplier */
872static u_long cached_vco_pll_ctl, cached_vco;
Mike Frysinger52a07812007-06-11 15:31:30 +0800873static u_long get_vco(void)
Bryan Wu1394f032007-05-06 14:50:22 -0700874{
875 u_long msel;
Bryan Wu1394f032007-05-06 14:50:22 -0700876
Mike Frysinger3a2521f2008-07-26 18:52:56 +0800877 u_long pll_ctl = bfin_read_PLL_CTL();
878 if (pll_ctl == cached_vco_pll_ctl)
879 return cached_vco;
880 else
881 cached_vco_pll_ctl = pll_ctl;
882
883 msel = (pll_ctl >> 9) & 0x3F;
Bryan Wu1394f032007-05-06 14:50:22 -0700884 if (0 == msel)
885 msel = 64;
886
Mike Frysinger3a2521f2008-07-26 18:52:56 +0800887 cached_vco = CONFIG_CLKIN_HZ;
888 cached_vco >>= (1 & pll_ctl); /* DF bit */
889 cached_vco *= msel;
890 return cached_vco;
Bryan Wu1394f032007-05-06 14:50:22 -0700891}
892
Mike Frysinger2f6cf7b2007-10-21 22:59:49 +0800893/* Get the Core clock */
Mike Frysinger3a2521f2008-07-26 18:52:56 +0800894static u_long cached_cclk_pll_div, cached_cclk;
Bryan Wu1394f032007-05-06 14:50:22 -0700895u_long get_cclk(void)
896{
897 u_long csel, ssel;
Mike Frysinger3a2521f2008-07-26 18:52:56 +0800898
Bryan Wu1394f032007-05-06 14:50:22 -0700899 if (bfin_read_PLL_STAT() & 0x1)
900 return CONFIG_CLKIN_HZ;
901
902 ssel = bfin_read_PLL_DIV();
Mike Frysinger3a2521f2008-07-26 18:52:56 +0800903 if (ssel == cached_cclk_pll_div)
904 return cached_cclk;
905 else
906 cached_cclk_pll_div = ssel;
907
Bryan Wu1394f032007-05-06 14:50:22 -0700908 csel = ((ssel >> 4) & 0x03);
909 ssel &= 0xf;
910 if (ssel && ssel < (1 << csel)) /* SCLK > CCLK */
Mike Frysinger3a2521f2008-07-26 18:52:56 +0800911 cached_cclk = get_vco() / ssel;
912 else
913 cached_cclk = get_vco() >> csel;
914 return cached_cclk;
Bryan Wu1394f032007-05-06 14:50:22 -0700915}
Bryan Wu1394f032007-05-06 14:50:22 -0700916EXPORT_SYMBOL(get_cclk);
917
918/* Get the System clock */
Mike Frysinger3a2521f2008-07-26 18:52:56 +0800919static u_long cached_sclk_pll_div, cached_sclk;
Bryan Wu1394f032007-05-06 14:50:22 -0700920u_long get_sclk(void)
921{
922 u_long ssel;
923
924 if (bfin_read_PLL_STAT() & 0x1)
925 return CONFIG_CLKIN_HZ;
926
Mike Frysinger3a2521f2008-07-26 18:52:56 +0800927 ssel = bfin_read_PLL_DIV();
928 if (ssel == cached_sclk_pll_div)
929 return cached_sclk;
930 else
931 cached_sclk_pll_div = ssel;
932
933 ssel &= 0xf;
Bryan Wu1394f032007-05-06 14:50:22 -0700934 if (0 == ssel) {
935 printk(KERN_WARNING "Invalid System Clock\n");
936 ssel = 1;
937 }
938
Mike Frysinger3a2521f2008-07-26 18:52:56 +0800939 cached_sclk = get_vco() / ssel;
940 return cached_sclk;
Bryan Wu1394f032007-05-06 14:50:22 -0700941}
Bryan Wu1394f032007-05-06 14:50:22 -0700942EXPORT_SYMBOL(get_sclk);
943
Mike Frysinger2f6cf7b2007-10-21 22:59:49 +0800944unsigned long sclk_to_usecs(unsigned long sclk)
945{
Mike Frysinger1754a5d2007-11-23 11:28:11 +0800946 u64 tmp = USEC_PER_SEC * (u64)sclk;
947 do_div(tmp, get_sclk());
948 return tmp;
Mike Frysinger2f6cf7b2007-10-21 22:59:49 +0800949}
950EXPORT_SYMBOL(sclk_to_usecs);
951
952unsigned long usecs_to_sclk(unsigned long usecs)
953{
Mike Frysinger1754a5d2007-11-23 11:28:11 +0800954 u64 tmp = get_sclk() * (u64)usecs;
955 do_div(tmp, USEC_PER_SEC);
956 return tmp;
Mike Frysinger2f6cf7b2007-10-21 22:59:49 +0800957}
958EXPORT_SYMBOL(usecs_to_sclk);
959
Bryan Wu1394f032007-05-06 14:50:22 -0700960/*
961 * Get CPU information for use by the procfs.
962 */
963static int show_cpuinfo(struct seq_file *m, void *v)
964{
Mike Frysinger066954a2007-10-21 22:36:06 +0800965 char *cpu, *mmu, *fpu, *vendor, *cache;
Bryan Wu1394f032007-05-06 14:50:22 -0700966 uint32_t revid;
967
968 u_long cclk = 0, sclk = 0;
Robin Getz9de3a0b2008-07-26 19:39:19 +0800969 u_int icache_size = BFIN_ICACHESIZE / 1024, dcache_size = 0, dsup_banks = 0;
Bryan Wu1394f032007-05-06 14:50:22 -0700970
971 cpu = CPU;
972 mmu = "none";
973 fpu = "none";
974 revid = bfin_revid();
Bryan Wu1394f032007-05-06 14:50:22 -0700975
976 cclk = get_cclk();
977 sclk = get_sclk();
978
Robin Getz73b0c0b2007-10-21 17:03:31 +0800979 switch (bfin_read_CHIPID() & CHIPID_MANUFACTURE) {
Mike Frysinger066954a2007-10-21 22:36:06 +0800980 case 0xca:
981 vendor = "Analog Devices";
Robin Getz73b0c0b2007-10-21 17:03:31 +0800982 break;
983 default:
Mike Frysinger066954a2007-10-21 22:36:06 +0800984 vendor = "unknown";
985 break;
Robin Getz73b0c0b2007-10-21 17:03:31 +0800986 }
Bryan Wu1394f032007-05-06 14:50:22 -0700987
Robin Getz73b0c0b2007-10-21 17:03:31 +0800988 seq_printf(m, "processor\t: %d\n"
989 "vendor_id\t: %s\n"
990 "cpu family\t: 0x%x\n"
Robin Getz253bcf42008-04-24 05:57:13 +0800991 "model name\t: ADSP-%s %lu(MHz CCLK) %lu(MHz SCLK) (%s)\n"
Robin Getz73b0c0b2007-10-21 17:03:31 +0800992 "stepping\t: %d\n",
993 0,
994 vendor,
995 (bfin_read_CHIPID() & CHIPID_FAMILY),
996 cpu, cclk/1000000, sclk/1000000,
Robin Getz253bcf42008-04-24 05:57:13 +0800997#ifdef CONFIG_MPU
998 "mpu on",
999#else
1000 "mpu off",
1001#endif
Robin Getz73b0c0b2007-10-21 17:03:31 +08001002 revid);
Bryan Wu1394f032007-05-06 14:50:22 -07001003
Robin Getz73b0c0b2007-10-21 17:03:31 +08001004 seq_printf(m, "cpu MHz\t\t: %lu.%03lu/%lu.%03lu\n",
1005 cclk/1000000, cclk%1000000,
1006 sclk/1000000, sclk%1000000);
1007 seq_printf(m, "bogomips\t: %lu.%02lu\n"
1008 "Calibration\t: %lu loops\n",
1009 (loops_per_jiffy * HZ) / 500000,
1010 ((loops_per_jiffy * HZ) / 5000) % 100,
1011 (loops_per_jiffy * HZ));
1012
1013 /* Check Cache configutation */
Mike Frysinger1f83b8f2007-07-12 22:58:21 +08001014 switch (bfin_read_DMEM_CONTROL() & (1 << DMC0_P | 1 << DMC1_P)) {
1015 case ACACHE_BSRAM:
Mike Frysinger066954a2007-10-21 22:36:06 +08001016 cache = "dbank-A/B\t: cache/sram";
Mike Frysinger1f83b8f2007-07-12 22:58:21 +08001017 dcache_size = 16;
1018 dsup_banks = 1;
1019 break;
1020 case ACACHE_BCACHE:
Mike Frysinger066954a2007-10-21 22:36:06 +08001021 cache = "dbank-A/B\t: cache/cache";
Mike Frysinger1f83b8f2007-07-12 22:58:21 +08001022 dcache_size = 32;
1023 dsup_banks = 2;
1024 break;
1025 case ASRAM_BSRAM:
Mike Frysinger066954a2007-10-21 22:36:06 +08001026 cache = "dbank-A/B\t: sram/sram";
Mike Frysinger1f83b8f2007-07-12 22:58:21 +08001027 dcache_size = 0;
1028 dsup_banks = 0;
1029 break;
1030 default:
Mike Frysinger066954a2007-10-21 22:36:06 +08001031 cache = "unknown";
Robin Getz73b0c0b2007-10-21 17:03:31 +08001032 dcache_size = 0;
1033 dsup_banks = 0;
Bryan Wu1394f032007-05-06 14:50:22 -07001034 break;
1035 }
1036
Robin Getz73b0c0b2007-10-21 17:03:31 +08001037 /* Is it turned on? */
Robin Getz2d200982008-07-26 19:41:40 +08001038 if ((bfin_read_DMEM_CONTROL() & (ENDCPLB | DMC_ENABLE)) != (ENDCPLB | DMC_ENABLE))
Robin Getz73b0c0b2007-10-21 17:03:31 +08001039 dcache_size = 0;
Bryan Wu1394f032007-05-06 14:50:22 -07001040
Robin Getz2d200982008-07-26 19:41:40 +08001041 if ((bfin_read_IMEM_CONTROL() & (IMC | ENICPLB)) == (IMC | ENICPLB))
Robin Getz9de3a0b2008-07-26 19:39:19 +08001042 icache_size = 0;
1043
Robin Getz73b0c0b2007-10-21 17:03:31 +08001044 seq_printf(m, "cache size\t: %d KB(L1 icache) "
1045 "%d KB(L1 dcache-%s) %d KB(L2 cache)\n",
Robin Getz9de3a0b2008-07-26 19:39:19 +08001046 icache_size, dcache_size,
Robin Getz73b0c0b2007-10-21 17:03:31 +08001047#if defined CONFIG_BFIN_WB
1048 "wb"
1049#elif defined CONFIG_BFIN_WT
1050 "wt"
1051#endif
Mike Frysingerda27abb2007-10-22 10:55:35 +08001052 "", 0);
Robin Getz73b0c0b2007-10-21 17:03:31 +08001053
1054 seq_printf(m, "%s\n", cache);
1055
Robin Getz9de3a0b2008-07-26 19:39:19 +08001056 if (icache_size)
1057 seq_printf(m, "icache setup\t: %d Sub-banks/%d Ways, %d Lines/Way\n",
1058 BFIN_ISUBBANKS, BFIN_IWAYS, BFIN_ILINES);
1059 else
1060 seq_printf(m, "icache setup\t: off\n");
1061
Bryan Wu1394f032007-05-06 14:50:22 -07001062 seq_printf(m,
Robin Getz73b0c0b2007-10-21 17:03:31 +08001063 "dcache setup\t: %d Super-banks/%d Sub-banks/%d Ways, %d Lines/Way\n",
Robin Getz3bebca22007-10-10 23:55:26 +08001064 dsup_banks, BFIN_DSUBBANKS, BFIN_DWAYS,
1065 BFIN_DLINES);
1066#ifdef CONFIG_BFIN_ICACHE_LOCK
Mike Frysinger0e06b502008-08-14 14:29:57 +08001067 switch ((bfin_read_IMEM_CONTROL() >> 3) & WAYALL_L) {
Bryan Wu1394f032007-05-06 14:50:22 -07001068 case WAY0_L:
1069 seq_printf(m, "Way0 Locked-Down\n");
1070 break;
1071 case WAY1_L:
1072 seq_printf(m, "Way1 Locked-Down\n");
1073 break;
1074 case WAY01_L:
1075 seq_printf(m, "Way0,Way1 Locked-Down\n");
1076 break;
1077 case WAY2_L:
1078 seq_printf(m, "Way2 Locked-Down\n");
1079 break;
1080 case WAY02_L:
1081 seq_printf(m, "Way0,Way2 Locked-Down\n");
1082 break;
1083 case WAY12_L:
1084 seq_printf(m, "Way1,Way2 Locked-Down\n");
1085 break;
1086 case WAY012_L:
1087 seq_printf(m, "Way0,Way1 & Way2 Locked-Down\n");
1088 break;
1089 case WAY3_L:
1090 seq_printf(m, "Way3 Locked-Down\n");
1091 break;
1092 case WAY03_L:
1093 seq_printf(m, "Way0,Way3 Locked-Down\n");
1094 break;
1095 case WAY13_L:
1096 seq_printf(m, "Way1,Way3 Locked-Down\n");
1097 break;
1098 case WAY013_L:
1099 seq_printf(m, "Way 0,Way1,Way3 Locked-Down\n");
1100 break;
1101 case WAY32_L:
1102 seq_printf(m, "Way3,Way2 Locked-Down\n");
1103 break;
1104 case WAY320_L:
1105 seq_printf(m, "Way3,Way2,Way0 Locked-Down\n");
1106 break;
1107 case WAY321_L:
1108 seq_printf(m, "Way3,Way2,Way1 Locked-Down\n");
1109 break;
1110 case WAYALL_L:
1111 seq_printf(m, "All Ways are locked\n");
1112 break;
1113 default:
1114 seq_printf(m, "No Ways are locked\n");
1115 }
1116#endif
Mike Frysinger066954a2007-10-21 22:36:06 +08001117 seq_printf(m, "board name\t: %s\n", bfin_board_name);
Robin Getz73b0c0b2007-10-21 17:03:31 +08001118 seq_printf(m, "board memory\t: %ld kB (0x%p -> 0x%p)\n",
1119 physical_mem_end >> 10, (void *)0, (void *)physical_mem_end);
1120 seq_printf(m, "kernel memory\t: %d kB (0x%p -> 0x%p)\n",
1121 ((int)memory_end - (int)_stext) >> 10,
1122 _stext,
1123 (void *)memory_end);
1124
Bryan Wu1394f032007-05-06 14:50:22 -07001125 return 0;
1126}
1127
1128static void *c_start(struct seq_file *m, loff_t *pos)
1129{
1130 return *pos < NR_CPUS ? ((void *)0x12345678) : NULL;
1131}
1132
1133static void *c_next(struct seq_file *m, void *v, loff_t *pos)
1134{
1135 ++*pos;
1136 return c_start(m, pos);
1137}
1138
1139static void c_stop(struct seq_file *m, void *v)
1140{
1141}
1142
Jan Engelhardt03a44822008-02-08 04:21:19 -08001143const struct seq_operations cpuinfo_op = {
Bryan Wu1394f032007-05-06 14:50:22 -07001144 .start = c_start,
1145 .next = c_next,
1146 .stop = c_stop,
1147 .show = show_cpuinfo,
1148};
1149
Mike Frysinger5e10b4a2007-06-11 16:44:09 +08001150void __init cmdline_init(const char *r0)
Bryan Wu1394f032007-05-06 14:50:22 -07001151{
1152 if (r0)
Mike Frysinger52a07812007-06-11 15:31:30 +08001153 strncpy(command_line, r0, COMMAND_LINE_SIZE);
Bryan Wu1394f032007-05-06 14:50:22 -07001154}