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