VServer 1.9.2 (patch-2.6.8.1-vs1.9.2.diff)
[linux-2.6.git] / arch / arm26 / kernel / setup.c
1 /*
2  *  linux/arch/arm/kernel/setup.c
3  *
4  *  Copyright (C) 1995-2001 Russell King
5  *  Copyright (C) 2003 Ian Molton
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License version 2 as
9  * published by the Free Software Foundation.
10  */
11 #include <linux/config.h>
12 #include <linux/kernel.h>
13 #include <linux/stddef.h>
14 #include <linux/ioport.h>
15 #include <linux/delay.h>
16 #include <linux/utsname.h>
17 #include <linux/blkdev.h>
18 #include <linux/console.h>
19 #include <linux/bootmem.h>
20 #include <linux/seq_file.h>
21 #include <linux/tty.h>
22 #include <linux/init.h>
23 #include <linux/root_dev.h>
24
25 #include <asm/elf.h>
26 #include <asm/hardware.h>
27 #include <asm/io.h>
28 #include <asm/procinfo.h>
29 #include <asm/setup.h>
30 #include <asm/mach-types.h>
31 #include <asm/tlbflush.h>
32
33 #include <asm/irqchip.h>
34
35 #ifndef MEM_SIZE
36 #define MEM_SIZE        (16*1024*1024)
37 #endif
38
39 #ifdef CONFIG_PREEMPT
40 spinlock_t kernel_flag = SPIN_LOCK_UNLOCKED;
41 #endif
42
43 #if defined(CONFIG_FPE_NWFPE)
44 char fpe_type[8];
45
46 static int __init fpe_setup(char *line)
47 {
48         memcpy(fpe_type, line, 8);
49         return 1;
50 }
51
52 __setup("fpe=", fpe_setup);
53 #endif
54
55 extern void paging_init(struct meminfo *);
56 extern void convert_to_tag_list(struct tag *tags);
57 extern void squash_mem_tags(struct tag *tag);
58 extern void bootmem_init(struct meminfo *);
59 extern int root_mountflags;
60 extern int _stext, _text, _etext, _edata, _end;
61 #ifdef CONFIG_XIP_KERNEL
62 extern int _endtext, _sdata;
63 #endif
64
65
66 unsigned int processor_id;
67 unsigned int __machine_arch_type;
68 unsigned int system_rev;
69 unsigned int system_serial_low;
70 unsigned int system_serial_high;
71 unsigned int elf_hwcap;
72 unsigned int memc_ctrl_reg;
73 unsigned int number_mfm_drives;
74
75 struct processor processor;
76
77 unsigned char aux_device_present;
78 char elf_platform[ELF_PLATFORM_SIZE];
79
80 unsigned long phys_initrd_start __initdata = 0;
81 unsigned long phys_initrd_size __initdata = 0;
82 static struct meminfo meminfo __initdata = { 0, };
83 static struct proc_info_item proc_info;
84 static const char *machine_name;
85 static char command_line[COMMAND_LINE_SIZE];
86
87 static char default_command_line[COMMAND_LINE_SIZE] __initdata = CONFIG_CMDLINE;
88
89 /*
90  * Standard memory resources
91  */
92 static struct resource mem_res[] = {
93         { "Video RAM",   0,     0,     IORESOURCE_MEM                   },
94         { "Kernel code", 0,     0,     IORESOURCE_MEM                   },
95         { "Kernel data", 0,     0,     IORESOURCE_MEM                   }
96 };
97
98 #define video_ram   mem_res[0]
99 #define kernel_code mem_res[1]
100 #define kernel_data mem_res[2]
101
102 static struct resource io_res[] = {
103         { "reserved",    0x3bc, 0x3be, IORESOURCE_IO | IORESOURCE_BUSY },
104         { "reserved",    0x378, 0x37f, IORESOURCE_IO | IORESOURCE_BUSY },
105         { "reserved",    0x278, 0x27f, IORESOURCE_IO | IORESOURCE_BUSY }
106 };
107
108 #define lp0 io_res[0]
109 #define lp1 io_res[1]
110 #define lp2 io_res[2]
111
112 #define dump_cpu_info() do { } while (0)
113
114 static void __init setup_processor(void)
115 {
116         extern struct proc_info_list __proc_info_begin, __proc_info_end;
117         struct proc_info_list *list;
118
119         /*
120          * locate processor in the list of supported processor
121          * types.  The linker builds this table for us from the
122          * entries in arch/arm/mm/proc-*.S
123          */
124         for (list = &__proc_info_begin; list < &__proc_info_end ; list++)
125                 if ((processor_id & list->cpu_mask) == list->cpu_val)
126                         break;
127
128         /*
129          * If processor type is unrecognised, then we
130          * can do nothing...
131          */
132         if (list >= &__proc_info_end) {
133                 printk("CPU configuration botched (ID %08x), unable "
134                        "to continue.\n", processor_id);
135                 while (1);
136         }
137
138         proc_info = *list->info;
139         processor = *list->proc;
140
141
142         printk("CPU: %s %s revision %d\n",
143                proc_info.manufacturer, proc_info.cpu_name,
144                (int)processor_id & 15);
145
146         dump_cpu_info();
147
148         sprintf(system_utsname.machine, "%s", list->arch_name);
149         sprintf(elf_platform, "%s", list->elf_name);
150         elf_hwcap = list->elf_hwcap;
151
152         cpu_proc_init();
153 }
154
155 /*
156  * Initial parsing of the command line.  We need to pick out the
157  * memory size.  We look for mem=size@start, where start and size
158  * are "size[KkMm]"
159  */
160 static void __init
161 parse_cmdline(struct meminfo *mi, char **cmdline_p, char *from)
162 {
163         char c = ' ', *to = command_line;
164         int usermem = 0, len = 0;
165
166         for (;;) {
167                 if (c == ' ' && !memcmp(from, "mem=", 4)) {
168                         unsigned long size, start;
169
170                         if (to != command_line)
171                                 to -= 1;
172
173                         /*
174                          * If the user specifies memory size, we
175                          * blow away any automatically generated
176                          * size.
177                          */
178                         if (usermem == 0) {
179                                 usermem = 1;
180                                 mi->nr_banks = 0;
181                         }
182
183                         start = PHYS_OFFSET;
184                         size  = memparse(from + 4, &from);
185                         if (*from == '@')
186                                 start = memparse(from + 1, &from);
187
188                         mi->bank[mi->nr_banks].start = start;
189                         mi->bank[mi->nr_banks].size  = size;
190                         mi->bank[mi->nr_banks].node  = PHYS_TO_NID(start);
191                         mi->nr_banks += 1;
192                 }
193                 c = *from++;
194                 if (!c)
195                         break;
196                 if (COMMAND_LINE_SIZE <= ++len)
197                         break;
198                 *to++ = c;
199         }
200         *to = '\0';
201         *cmdline_p = command_line;
202 }
203
204 static void __init
205 setup_ramdisk(int doload, int prompt, int image_start, unsigned int rd_sz)
206 {
207 #ifdef CONFIG_BLK_DEV_RAM
208         extern int rd_size, rd_image_start, rd_prompt, rd_doload;
209
210         rd_image_start = image_start;
211         rd_prompt = prompt;
212         rd_doload = doload;
213
214         if (rd_sz)
215                 rd_size = rd_sz;
216 #endif
217 }
218
219 static void __init
220 request_standard_resources(struct meminfo *mi)
221 {
222         struct resource *res;
223         int i;
224
225         kernel_code.start  = init_mm.start_code;
226         kernel_code.end    = init_mm.end_code - 1;
227 #ifdef CONFIG_XIP_KERNEL
228         kernel_data.start  = init_mm.start_data;
229 #else
230         kernel_data.start  = init_mm.end_code;
231 #endif
232         kernel_data.end    = init_mm.brk - 1;
233
234         for (i = 0; i < mi->nr_banks; i++) {
235                 unsigned long virt_start, virt_end;
236
237                 if (mi->bank[i].size == 0)
238                         continue;
239
240                 virt_start = mi->bank[i].start;
241                 virt_end   = virt_start + mi->bank[i].size - 1;
242
243                 res = alloc_bootmem_low(sizeof(*res));
244                 res->name  = "System RAM";
245                 res->start = virt_start;
246                 res->end   = virt_end;
247                 res->flags = IORESOURCE_MEM | IORESOURCE_BUSY;
248
249                 request_resource(&iomem_resource, res);
250
251                 if (kernel_code.start >= res->start &&
252                     kernel_code.end <= res->end)
253                         request_resource(res, &kernel_code);
254                 if (kernel_data.start >= res->start &&
255                     kernel_data.end <= res->end)
256                         request_resource(res, &kernel_data);
257         }
258
259 /*      FIXME - needed? if (mdesc->video_start) {
260                 video_ram.start = mdesc->video_start;
261                 video_ram.end   = mdesc->video_end;
262                 request_resource(&iomem_resource, &video_ram);
263         }*/
264
265         /*
266          * Some machines don't have the possibility of ever
267          * possessing lp1 or lp2
268          */
269         if (0)  /* FIXME - need to do this for A5k at least */
270                 request_resource(&ioport_resource, &lp0);
271 }
272
273 /*
274  *  Tag parsing.
275  *
276  * This is the new way of passing data to the kernel at boot time.  Rather
277  * than passing a fixed inflexible structure to the kernel, we pass a list
278  * of variable-sized tags to the kernel.  The first tag must be a ATAG_CORE
279  * tag for the list to be recognised (to distinguish the tagged list from
280  * a param_struct).  The list is terminated with a zero-length tag (this tag
281  * is not parsed in any way).
282  */
283 static int __init parse_tag_core(const struct tag *tag)
284 {
285         if (tag->hdr.size > 2) {
286                 if ((tag->u.core.flags & 1) == 0)
287                         root_mountflags &= ~MS_RDONLY;
288                 ROOT_DEV = old_decode_dev(tag->u.core.rootdev);
289         }
290         return 0;
291 }
292
293 __tagtable(ATAG_CORE, parse_tag_core);
294
295 static int __init parse_tag_mem32(const struct tag *tag)
296 {
297         if (meminfo.nr_banks >= NR_BANKS) {
298                 printk(KERN_WARNING
299                        "Ignoring memory bank 0x%08x size %dKB\n",
300                         tag->u.mem.start, tag->u.mem.size / 1024);
301                 return -EINVAL;
302         }
303         meminfo.bank[meminfo.nr_banks].start = tag->u.mem.start;
304         meminfo.bank[meminfo.nr_banks].size  = tag->u.mem.size;
305         meminfo.bank[meminfo.nr_banks].node  = PHYS_TO_NID(tag->u.mem.start);
306         meminfo.nr_banks += 1;
307
308         return 0;
309 }
310
311 __tagtable(ATAG_MEM, parse_tag_mem32);
312
313 #if defined(CONFIG_DUMMY_CONSOLE)
314 struct screen_info screen_info = {
315  .orig_video_lines      = 30,
316  .orig_video_cols       = 80,
317  .orig_video_mode       = 0,
318  .orig_video_ega_bx     = 0,
319  .orig_video_isVGA      = 1,
320  .orig_video_points     = 8
321 };
322
323 static int __init parse_tag_videotext(const struct tag *tag)
324 {
325         screen_info.orig_x            = tag->u.videotext.x;
326         screen_info.orig_y            = tag->u.videotext.y;
327         screen_info.orig_video_page   = tag->u.videotext.video_page;
328         screen_info.orig_video_mode   = tag->u.videotext.video_mode;
329         screen_info.orig_video_cols   = tag->u.videotext.video_cols;
330         screen_info.orig_video_ega_bx = tag->u.videotext.video_ega_bx;
331         screen_info.orig_video_lines  = tag->u.videotext.video_lines;
332         screen_info.orig_video_isVGA  = tag->u.videotext.video_isvga;
333         screen_info.orig_video_points = tag->u.videotext.video_points;
334         return 0;
335 }
336
337 __tagtable(ATAG_VIDEOTEXT, parse_tag_videotext);
338 #endif
339
340 static int __init parse_tag_acorn(const struct tag *tag)
341 {
342         memc_ctrl_reg = tag->u.acorn.memc_control_reg;
343         number_mfm_drives = tag->u.acorn.adfsdrives;
344         return 0;
345 }
346
347 __tagtable(ATAG_ACORN, parse_tag_acorn);
348
349 static int __init parse_tag_ramdisk(const struct tag *tag)
350 {
351         setup_ramdisk((tag->u.ramdisk.flags & 1) == 0,
352                       (tag->u.ramdisk.flags & 2) == 0,
353                       tag->u.ramdisk.start, tag->u.ramdisk.size);
354         return 0;
355 }
356
357 __tagtable(ATAG_RAMDISK, parse_tag_ramdisk);
358
359 static int __init parse_tag_initrd(const struct tag *tag)
360 {
361         printk(KERN_WARNING "ATAG_INITRD is deprecated; please update your bootloader. \n");
362         phys_initrd_start = (unsigned long)tag->u.initrd.start;
363         phys_initrd_size = (unsigned long)tag->u.initrd.size;
364         return 0;
365 }
366
367 __tagtable(ATAG_INITRD, parse_tag_initrd);
368
369 static int __init parse_tag_initrd2(const struct tag *tag)
370 {
371         printk(KERN_WARNING "ATAG_INITRD is deprecated; please update your bootloader. \n");
372         phys_initrd_start = (unsigned long)tag->u.initrd.start;
373         phys_initrd_size = (unsigned long)tag->u.initrd.size;
374         return 0;
375 }
376
377 __tagtable(ATAG_INITRD2, parse_tag_initrd2);
378
379 static int __init parse_tag_serialnr(const struct tag *tag)
380 {
381         system_serial_low = tag->u.serialnr.low;
382         system_serial_high = tag->u.serialnr.high;
383         return 0;
384 }
385
386 __tagtable(ATAG_SERIAL, parse_tag_serialnr);
387
388 static int __init parse_tag_revision(const struct tag *tag)
389 {
390         system_rev = tag->u.revision.rev;
391         return 0;
392 }
393
394 __tagtable(ATAG_REVISION, parse_tag_revision);
395
396 static int __init parse_tag_cmdline(const struct tag *tag)
397 {
398         strncpy(default_command_line, tag->u.cmdline.cmdline, COMMAND_LINE_SIZE);
399         default_command_line[COMMAND_LINE_SIZE - 1] = '\0';
400         return 0;
401 }
402
403 __tagtable(ATAG_CMDLINE, parse_tag_cmdline);
404
405 /*
406  * Scan the tag table for this tag, and call its parse function.
407  * The tag table is built by the linker from all the __tagtable
408  * declarations.
409  */
410 static int __init parse_tag(const struct tag *tag)
411 {
412         extern struct tagtable __tagtable_begin, __tagtable_end;
413         struct tagtable *t;
414
415         for (t = &__tagtable_begin; t < &__tagtable_end; t++)
416                 if (tag->hdr.tag == t->tag) {
417                         t->parse(tag);
418                         break;
419                 }
420
421         return t < &__tagtable_end;
422 }
423
424 /*
425  * Parse all tags in the list, checking both the global and architecture
426  * specific tag tables.
427  */
428 static void __init parse_tags(const struct tag *t)
429 {
430         for (; t->hdr.size; t = tag_next(t))
431                 if (!parse_tag(t))
432                         printk(KERN_WARNING
433                                 "Ignoring unrecognised tag 0x%08x\n",
434                                 t->hdr.tag);
435 }
436
437 /*
438  * This holds our defaults.
439  */
440 static struct init_tags {
441         struct tag_header hdr1;
442         struct tag_core   core;
443         struct tag_header hdr2;
444         struct tag_mem32  mem;
445         struct tag_header hdr3;
446 } init_tags __initdata = {
447         { tag_size(tag_core), ATAG_CORE },
448         { 1, PAGE_SIZE, 0xff },
449         { tag_size(tag_mem32), ATAG_MEM },
450         { MEM_SIZE, PHYS_OFFSET },
451         { 0, ATAG_NONE }
452 };
453
454 void __init setup_arch(char **cmdline_p)
455 {
456         struct tag *tags = (struct tag *)&init_tags;
457         char *from = default_command_line;
458
459         setup_processor();
460         if(machine_arch_type == MACH_TYPE_A5K)
461                 machine_name = "A5000";
462         else if(machine_arch_type == MACH_TYPE_ARCHIMEDES)
463                 machine_name = "Archimedes";
464         else
465                 machine_name = "UNKNOWN";
466
467         //FIXME - the tag struct is always copied here but this is a block
468         // of RAM that is accidentally reserved along with video RAM. perhaps
469         // it would be a good idea to explicitly reserve this?
470
471         tags = (struct tag *)0x0207c000;
472
473         /*
474          * If we have the old style parameters, convert them to
475          * a tag list.
476          */
477         if (tags->hdr.tag != ATAG_CORE)
478                 convert_to_tag_list(tags);
479         if (tags->hdr.tag != ATAG_CORE)
480                 tags = (struct tag *)&init_tags;
481         if (tags->hdr.tag == ATAG_CORE) {
482                 if (meminfo.nr_banks != 0)
483                         squash_mem_tags(tags);
484                 parse_tags(tags);
485         }
486
487         init_mm.start_code = (unsigned long) &_text;
488 #ifndef CONFIG_XIP_KERNEL
489         init_mm.end_code   = (unsigned long) &_etext;
490 #else
491         init_mm.end_code   = (unsigned long) &_endtext;
492         init_mm.start_data   = (unsigned long) &_sdata;
493 #endif
494         init_mm.end_data   = (unsigned long) &_edata;
495         init_mm.brk        = (unsigned long) &_end;
496
497         memcpy(saved_command_line, from, COMMAND_LINE_SIZE);
498         saved_command_line[COMMAND_LINE_SIZE-1] = '\0';
499         parse_cmdline(&meminfo, cmdline_p, from);
500         bootmem_init(&meminfo);
501         paging_init(&meminfo);
502         request_standard_resources(&meminfo);
503
504 #ifdef CONFIG_VT
505 #if defined(CONFIG_DUMMY_CONSOLE)
506         conswitchp = &dummy_con;
507 #endif
508 #endif
509 }
510
511 static const char *hwcap_str[] = {
512         "swp",
513         "half",
514         "thumb",
515         "26bit",
516         "fastmult",
517         "fpa",
518         "vfp",
519         "edsp",
520         NULL
521 };
522
523 static int c_show(struct seq_file *m, void *v)
524 {
525         int i;
526
527         seq_printf(m, "Processor\t: %s %s rev %d (%s)\n",
528                    proc_info.manufacturer, proc_info.cpu_name,
529                    (int)processor_id & 15, elf_platform);
530
531         seq_printf(m, "BogoMIPS\t: %lu.%02lu\n",
532                    loops_per_jiffy / (500000/HZ),
533                    (loops_per_jiffy / (5000/HZ)) % 100);
534
535         /* dump out the processor features */
536         seq_puts(m, "Features\t: ");
537
538         for (i = 0; hwcap_str[i]; i++)
539                 if (elf_hwcap & (1 << i))
540                         seq_printf(m, "%s ", hwcap_str[i]);
541
542         seq_puts(m, "\n");
543
544         seq_printf(m, "CPU part\t\t: %07x\n", processor_id >> 4);
545         seq_printf(m, "CPU revision\t: %d\n\n", processor_id & 15);
546         seq_printf(m, "Hardware\t: %s\n", machine_name);
547         seq_printf(m, "Revision\t: %04x\n", system_rev);
548         seq_printf(m, "Serial\t\t: %08x%08x\n",
549                    system_serial_high, system_serial_low);
550
551         return 0;
552 }
553
554 static void *c_start(struct seq_file *m, loff_t *pos)
555 {
556         return *pos < 1 ? (void *)1 : NULL;
557 }
558
559 static void *c_next(struct seq_file *m, void *v, loff_t *pos)
560 {
561         ++*pos;
562         return NULL;
563 }
564
565 static void c_stop(struct seq_file *m, void *v)
566 {
567 }
568
569 struct seq_operations cpuinfo_op = {
570         .start  = c_start,
571         .next   = c_next,
572         .stop   = c_stop,
573         .show   = c_show
574 };