Merge to Fedora kernel-2.6.18-1.2224_FC5 patched with stable patch-2.6.18.1-vs2.0...
[linux-2.6.git] / arch / sh / kernel / setup.c
1 /* $Id: setup.c,v 1.30 2003/10/13 07:21:19 lethal Exp $
2  *
3  *  linux/arch/sh/kernel/setup.c
4  *
5  *  Copyright (C) 1999  Niibe Yutaka
6  *  Copyright (C) 2002, 2003  Paul Mundt
7  */
8
9 /*
10  * This file handles the architecture-dependent parts of initialization
11  */
12
13 #include <linux/screen_info.h>
14 #include <linux/ioport.h>
15 #include <linux/init.h>
16 #include <linux/initrd.h>
17 #include <linux/bootmem.h>
18 #include <linux/console.h>
19 #include <linux/seq_file.h>
20 #include <linux/root_dev.h>
21 #include <linux/utsname.h>
22 #include <linux/cpu.h>
23 #include <linux/pfn.h>
24 #include <linux/vs_cvirt.h>
25 #include <asm/uaccess.h>
26 #include <asm/io.h>
27 #include <asm/sections.h>
28 #include <asm/irq.h>
29 #include <asm/setup.h>
30 #include <asm/clock.h>
31
32 #ifdef CONFIG_SH_KGDB
33 #include <asm/kgdb.h>
34 static int kgdb_parse_options(char *options);
35 #endif
36 extern void * __rd_start, * __rd_end;
37 /*
38  * Machine setup..
39  */
40
41 /*
42  * Initialize loops_per_jiffy as 10000000 (1000MIPS).
43  * This value will be used at the very early stage of serial setup.
44  * The bigger value means no problem.
45  */
46 struct sh_cpuinfo boot_cpu_data = { CPU_SH_NONE, 10000000, };
47 struct screen_info screen_info;
48
49 #if defined(CONFIG_SH_UNKNOWN)
50 struct sh_machine_vector sh_mv;
51 #endif
52
53 /* We need this to satisfy some external references. */
54 struct screen_info screen_info = {
55         0, 25,                  /* orig-x, orig-y */
56         0,                      /* unused */
57         0,                      /* orig-video-page */
58         0,                      /* orig-video-mode */
59         80,                     /* orig-video-cols */
60         0,0,0,                  /* ega_ax, ega_bx, ega_cx */
61         25,                     /* orig-video-lines */
62         0,                      /* orig-video-isVGA */
63         16                      /* orig-video-points */
64 };
65
66 extern void platform_setup(void);
67 extern char *get_system_type(void);
68 extern int root_mountflags;
69
70 #define MV_NAME_SIZE 32
71
72 static struct sh_machine_vector* __init get_mv_byname(const char* name);
73
74 /*
75  * This is set up by the setup-routine at boot-time
76  */
77 #define PARAM   ((unsigned char *)empty_zero_page)
78
79 #define MOUNT_ROOT_RDONLY (*(unsigned long *) (PARAM+0x000))
80 #define RAMDISK_FLAGS (*(unsigned long *) (PARAM+0x004))
81 #define ORIG_ROOT_DEV (*(unsigned long *) (PARAM+0x008))
82 #define LOADER_TYPE (*(unsigned long *) (PARAM+0x00c))
83 #define INITRD_START (*(unsigned long *) (PARAM+0x010))
84 #define INITRD_SIZE (*(unsigned long *) (PARAM+0x014))
85 /* ... */
86 #define COMMAND_LINE ((char *) (PARAM+0x100))
87
88 #define RAMDISK_IMAGE_START_MASK        0x07FF
89 #define RAMDISK_PROMPT_FLAG             0x8000
90 #define RAMDISK_LOAD_FLAG               0x4000
91
92 static char command_line[COMMAND_LINE_SIZE] = { 0, };
93
94 struct resource standard_io_resources[] = {
95         { "dma1", 0x00, 0x1f },
96         { "pic1", 0x20, 0x3f },
97         { "timer", 0x40, 0x5f },
98         { "keyboard", 0x60, 0x6f },
99         { "dma page reg", 0x80, 0x8f },
100         { "pic2", 0xa0, 0xbf },
101         { "dma2", 0xc0, 0xdf },
102         { "fpu", 0xf0, 0xff }
103 };
104
105 #define STANDARD_IO_RESOURCES (sizeof(standard_io_resources)/sizeof(struct resource))
106
107 /* System RAM - interrupted by the 640kB-1M hole */
108 #define code_resource (ram_resources[3])
109 #define data_resource (ram_resources[4])
110 static struct resource ram_resources[] = {
111         { "System RAM", 0x000000, 0x09ffff, IORESOURCE_BUSY },
112         { "System RAM", 0x100000, 0x100000, IORESOURCE_BUSY },
113         { "Video RAM area", 0x0a0000, 0x0bffff },
114         { "Kernel code", 0x100000, 0 },
115         { "Kernel data", 0, 0 }
116 };
117
118 unsigned long memory_start, memory_end;
119
120 static inline void parse_cmdline (char ** cmdline_p, char mv_name[MV_NAME_SIZE],
121                                   struct sh_machine_vector** mvp,
122                                   unsigned long *mv_io_base,
123                                   int *mv_mmio_enable)
124 {
125         char c = ' ', *to = command_line, *from = COMMAND_LINE;
126         int len = 0;
127
128         /* Save unparsed command line copy for /proc/cmdline */
129         memcpy(saved_command_line, COMMAND_LINE, COMMAND_LINE_SIZE);
130         saved_command_line[COMMAND_LINE_SIZE-1] = '\0';
131
132         memory_start = (unsigned long)PAGE_OFFSET+__MEMORY_START;
133         memory_end = memory_start + __MEMORY_SIZE;
134
135         for (;;) {
136                 /*
137                  * "mem=XXX[kKmM]" defines a size of memory.
138                  */
139                 if (c == ' ' && !memcmp(from, "mem=", 4)) {
140                         if (to != command_line)
141                                 to--;
142                         {
143                                 unsigned long mem_size;
144
145                                 mem_size = memparse(from+4, &from);
146                                 memory_end = memory_start + mem_size;
147                         }
148                 }
149                 if (c == ' ' && !memcmp(from, "sh_mv=", 6)) {
150                         char* mv_end;
151                         char* mv_comma;
152                         int mv_len;
153                         if (to != command_line)
154                                 to--;
155                         from += 6;
156                         mv_end = strchr(from, ' ');
157                         if (mv_end == NULL)
158                                 mv_end = from + strlen(from);
159
160                         mv_comma = strchr(from, ',');
161                         if ((mv_comma != NULL) && (mv_comma < mv_end)) {
162                                 int ints[3];
163                                 get_options(mv_comma+1, ARRAY_SIZE(ints), ints);
164                                 *mv_io_base = ints[1];
165                                 *mv_mmio_enable = ints[2];
166                                 mv_len = mv_comma - from;
167                         } else {
168                                 mv_len = mv_end - from;
169                         }
170                         if (mv_len > (MV_NAME_SIZE-1))
171                                 mv_len = MV_NAME_SIZE-1;
172                         memcpy(mv_name, from, mv_len);
173                         mv_name[mv_len] = '\0';
174                         from = mv_end;
175
176                         *mvp = get_mv_byname(mv_name);
177                 }
178                 c = *(from++);
179                 if (!c)
180                         break;
181                 if (COMMAND_LINE_SIZE <= ++len)
182                         break;
183                 *(to++) = c;
184         }
185         *to = '\0';
186         *cmdline_p = command_line;
187 }
188
189 static int __init sh_mv_setup(char **cmdline_p)
190 {
191 #ifdef CONFIG_SH_UNKNOWN
192         extern struct sh_machine_vector mv_unknown;
193 #endif
194         struct sh_machine_vector *mv = NULL;
195         char mv_name[MV_NAME_SIZE] = "";
196         unsigned long mv_io_base = 0;
197         int mv_mmio_enable = 0;
198
199         parse_cmdline(cmdline_p, mv_name, &mv, &mv_io_base, &mv_mmio_enable);
200
201 #ifdef CONFIG_SH_UNKNOWN
202         if (mv == NULL) {
203                 mv = &mv_unknown;
204                 if (*mv_name != '\0') {
205                         printk("Warning: Unsupported machine %s, using unknown\n",
206                                mv_name);
207                 }
208         }
209         sh_mv = *mv;
210 #endif
211
212         /*
213          * Manually walk the vec, fill in anything that the board hasn't yet
214          * by hand, wrapping to the generic implementation.
215          */
216 #define mv_set(elem) do { \
217         if (!sh_mv.mv_##elem) \
218                 sh_mv.mv_##elem = generic_##elem; \
219 } while (0)
220
221         mv_set(inb);    mv_set(inw);    mv_set(inl);
222         mv_set(outb);   mv_set(outw);   mv_set(outl);
223
224         mv_set(inb_p);  mv_set(inw_p);  mv_set(inl_p);
225         mv_set(outb_p); mv_set(outw_p); mv_set(outl_p);
226
227         mv_set(insb);   mv_set(insw);   mv_set(insl);
228         mv_set(outsb);  mv_set(outsw);  mv_set(outsl);
229
230         mv_set(readb);  mv_set(readw);  mv_set(readl);
231         mv_set(writeb); mv_set(writew); mv_set(writel);
232
233         mv_set(ioport_map);
234         mv_set(ioport_unmap);
235         mv_set(irq_demux);
236
237 #ifdef CONFIG_SH_UNKNOWN
238         __set_io_port_base(mv_io_base);
239 #endif
240
241         return 0;
242 }
243
244 void __init setup_arch(char **cmdline_p)
245 {
246         unsigned long bootmap_size;
247         unsigned long start_pfn, max_pfn, max_low_pfn;
248
249 #ifdef CONFIG_EARLY_PRINTK
250         extern void enable_early_printk(void);
251
252         enable_early_printk();
253 #endif
254 #ifdef CONFIG_CMDLINE_BOOL
255         strcpy(COMMAND_LINE, CONFIG_CMDLINE);
256 #endif
257
258         ROOT_DEV = old_decode_dev(ORIG_ROOT_DEV);
259
260 #ifdef CONFIG_BLK_DEV_RAM
261         rd_image_start = RAMDISK_FLAGS & RAMDISK_IMAGE_START_MASK;
262         rd_prompt = ((RAMDISK_FLAGS & RAMDISK_PROMPT_FLAG) != 0);
263         rd_doload = ((RAMDISK_FLAGS & RAMDISK_LOAD_FLAG) != 0);
264 #endif
265
266         if (!MOUNT_ROOT_RDONLY)
267                 root_mountflags &= ~MS_RDONLY;
268         init_mm.start_code = (unsigned long) _text;
269         init_mm.end_code = (unsigned long) _etext;
270         init_mm.end_data = (unsigned long) _edata;
271         init_mm.brk = (unsigned long) _end;
272
273         code_resource.start = (unsigned long)virt_to_phys(_text);
274         code_resource.end = (unsigned long)virt_to_phys(_etext)-1;
275         data_resource.start = (unsigned long)virt_to_phys(_etext);
276         data_resource.end = (unsigned long)virt_to_phys(_edata)-1;
277
278         sh_mv_setup(cmdline_p);
279
280         /*
281          * Find the highest page frame number we have available
282          */
283         max_pfn = PFN_DOWN(__pa(memory_end));
284
285         /*
286          * Determine low and high memory ranges:
287          */
288         max_low_pfn = max_pfn;
289
290         /*
291          * Partially used pages are not usable - thus
292          * we are rounding upwards:
293          */
294         start_pfn = PFN_UP(__pa(_end));
295
296         /*
297          * Find a proper area for the bootmem bitmap. After this
298          * bootstrap step all allocations (until the page allocator
299          * is intact) must be done via bootmem_alloc().
300          */
301         bootmap_size = init_bootmem_node(NODE_DATA(0), start_pfn,
302                                          __MEMORY_START>>PAGE_SHIFT,
303                                          max_low_pfn);
304         /*
305          * Register fully available low RAM pages with the bootmem allocator.
306          */
307         {
308                 unsigned long curr_pfn, last_pfn, pages;
309
310                 /*
311                  * We are rounding up the start address of usable memory:
312                  */
313                 curr_pfn = PFN_UP(__MEMORY_START);
314                 /*
315                  * ... and at the end of the usable range downwards:
316                  */
317                 last_pfn = PFN_DOWN(__pa(memory_end));
318
319                 if (last_pfn > max_low_pfn)
320                         last_pfn = max_low_pfn;
321
322                 pages = last_pfn - curr_pfn;
323                 free_bootmem_node(NODE_DATA(0), PFN_PHYS(curr_pfn),
324                                   PFN_PHYS(pages));
325         }
326
327         /*
328          * Reserve the kernel text and
329          * Reserve the bootmem bitmap. We do this in two steps (first step
330          * was init_bootmem()), because this catches the (definitely buggy)
331          * case of us accidentally initializing the bootmem allocator with
332          * an invalid RAM area.
333          */
334         reserve_bootmem_node(NODE_DATA(0), __MEMORY_START+PAGE_SIZE,
335                 (PFN_PHYS(start_pfn)+bootmap_size+PAGE_SIZE-1)-__MEMORY_START);
336
337         /*
338          * reserve physical page 0 - it's a special BIOS page on many boxes,
339          * enabling clean reboots, SMP operation, laptop functions.
340          */
341         reserve_bootmem_node(NODE_DATA(0), __MEMORY_START, PAGE_SIZE);
342
343 #ifdef CONFIG_BLK_DEV_INITRD
344         ROOT_DEV = MKDEV(RAMDISK_MAJOR, 0);
345         if (&__rd_start != &__rd_end) {
346                 LOADER_TYPE = 1;
347                 INITRD_START = PHYSADDR((unsigned long)&__rd_start) - __MEMORY_START;
348                 INITRD_SIZE = (unsigned long)&__rd_end - (unsigned long)&__rd_start;
349         }
350
351         if (LOADER_TYPE && INITRD_START) {
352                 if (INITRD_START + INITRD_SIZE <= (max_low_pfn << PAGE_SHIFT)) {
353                         reserve_bootmem_node(NODE_DATA(0), INITRD_START+__MEMORY_START, INITRD_SIZE);
354                         initrd_start =
355                                 INITRD_START ? INITRD_START + PAGE_OFFSET + __MEMORY_START : 0;
356                         initrd_end = initrd_start + INITRD_SIZE;
357                 } else {
358                         printk("initrd extends beyond end of memory "
359                             "(0x%08lx > 0x%08lx)\ndisabling initrd\n",
360                                     INITRD_START + INITRD_SIZE,
361                                     max_low_pfn << PAGE_SHIFT);
362                         initrd_start = 0;
363                 }
364         }
365 #endif
366
367 #ifdef CONFIG_DUMMY_CONSOLE
368         conswitchp = &dummy_con;
369 #endif
370
371         /* Perform the machine specific initialisation */
372         platform_setup();
373
374         paging_init();
375 }
376
377 struct sh_machine_vector* __init get_mv_byname(const char* name)
378 {
379         extern int strcasecmp(const char *, const char *);
380         extern long __machvec_start, __machvec_end;
381         struct sh_machine_vector *all_vecs =
382                 (struct sh_machine_vector *)&__machvec_start;
383
384         int i, n = ((unsigned long)&__machvec_end
385                     - (unsigned long)&__machvec_start)/
386                 sizeof(struct sh_machine_vector);
387
388         for (i = 0; i < n; ++i) {
389                 struct sh_machine_vector *mv = &all_vecs[i];
390                 if (mv == NULL)
391                         continue;
392                 if (strcasecmp(name, get_system_type()) == 0) {
393                         return mv;
394                 }
395         }
396         return NULL;
397 }
398
399 static struct cpu cpu[NR_CPUS];
400
401 static int __init topology_init(void)
402 {
403         int cpu_id;
404
405         for_each_possible_cpu(cpu_id)
406                 register_cpu(&cpu[cpu_id], cpu_id);
407
408         return 0;
409 }
410
411 subsys_initcall(topology_init);
412
413 static const char *cpu_name[] = {
414         [CPU_SH7604]    = "SH7604",
415         [CPU_SH7705]    = "SH7705",
416         [CPU_SH7708]    = "SH7708",
417         [CPU_SH7729]    = "SH7729",
418         [CPU_SH7300]    = "SH7300",
419         [CPU_SH7750]    = "SH7750",
420         [CPU_SH7750S]   = "SH7750S",
421         [CPU_SH7750R]   = "SH7750R",
422         [CPU_SH7751]    = "SH7751",
423         [CPU_SH7751R]   = "SH7751R",
424         [CPU_SH7760]    = "SH7760",
425         [CPU_SH73180]   = "SH73180",
426         [CPU_ST40RA]    = "ST40RA",
427         [CPU_ST40GX1]   = "ST40GX1",
428         [CPU_SH4_202]   = "SH4-202",
429         [CPU_SH4_501]   = "SH4-501",
430         [CPU_SH7770]    = "SH7770",
431         [CPU_SH7780]    = "SH7780",
432         [CPU_SH7781]    = "SH7781",
433         [CPU_SH_NONE]   = "Unknown"
434 };
435
436 const char *get_cpu_subtype(void)
437 {
438         return cpu_name[boot_cpu_data.type];
439 }
440
441 #ifdef CONFIG_PROC_FS
442 static const char *cpu_flags[] = {
443         "none", "fpu", "p2flush", "mmuassoc", "dsp", "perfctr", "ptea", NULL
444 };
445
446 static void show_cpuflags(struct seq_file *m)
447 {
448         unsigned long i;
449
450         seq_printf(m, "cpu flags\t:");
451
452         if (!cpu_data->flags) {
453                 seq_printf(m, " %s\n", cpu_flags[0]);
454                 return;
455         }
456
457         for (i = 0; cpu_flags[i]; i++)
458                 if ((cpu_data->flags & (1 << i)))
459                         seq_printf(m, " %s", cpu_flags[i+1]);
460
461         seq_printf(m, "\n");
462 }
463
464 static void show_cacheinfo(struct seq_file *m, const char *type, struct cache_info info)
465 {
466         unsigned int cache_size;
467
468         cache_size = info.ways * info.sets * info.linesz;
469
470         seq_printf(m, "%s size\t: %2dKiB (%d-way)\n",
471                    type, cache_size >> 10, info.ways);
472 }
473
474 /*
475  *      Get CPU information for use by the procfs.
476  */
477 static int show_cpuinfo(struct seq_file *m, void *v)
478 {
479         unsigned int cpu = smp_processor_id();
480
481         if (!cpu && cpu_online(cpu))
482                 seq_printf(m, "machine\t\t: %s\n", get_system_type());
483
484         seq_printf(m, "processor\t: %d\n", cpu);
485         seq_printf(m, "cpu family\t: %s\n", vx_new_uts(machine));
486         seq_printf(m, "cpu type\t: %s\n", get_cpu_subtype());
487
488         show_cpuflags(m);
489
490         seq_printf(m, "cache type\t: ");
491
492         /*
493          * Check for what type of cache we have, we support both the
494          * unified cache on the SH-2 and SH-3, as well as the harvard
495          * style cache on the SH-4.
496          */
497         if (test_bit(SH_CACHE_COMBINED, &(boot_cpu_data.icache.flags))) {
498                 seq_printf(m, "unified\n");
499                 show_cacheinfo(m, "cache", boot_cpu_data.icache);
500         } else {
501                 seq_printf(m, "split (harvard)\n");
502                 show_cacheinfo(m, "icache", boot_cpu_data.icache);
503                 show_cacheinfo(m, "dcache", boot_cpu_data.dcache);
504         }
505
506         seq_printf(m, "bogomips\t: %lu.%02lu\n",
507                      boot_cpu_data.loops_per_jiffy/(500000/HZ),
508                      (boot_cpu_data.loops_per_jiffy/(5000/HZ)) % 100);
509
510         return show_clocks(m);
511 }
512
513 static void *c_start(struct seq_file *m, loff_t *pos)
514 {
515         return *pos < NR_CPUS ? cpu_data + *pos : NULL;
516 }
517 static void *c_next(struct seq_file *m, void *v, loff_t *pos)
518 {
519         ++*pos;
520         return c_start(m, pos);
521 }
522 static void c_stop(struct seq_file *m, void *v)
523 {
524 }
525 struct seq_operations cpuinfo_op = {
526         .start  = c_start,
527         .next   = c_next,
528         .stop   = c_stop,
529         .show   = show_cpuinfo,
530 };
531 #endif /* CONFIG_PROC_FS */
532
533 #ifdef CONFIG_SH_KGDB
534 /*
535  * Parse command-line kgdb options.  By default KGDB is enabled,
536  * entered on error (or other action) using default serial info.
537  * The command-line option can include a serial port specification
538  * and an action to override default or configured behavior.
539  */
540 struct kgdb_sermap kgdb_sci_sermap =
541 { "ttySC", 5, kgdb_sci_setup, NULL };
542
543 struct kgdb_sermap *kgdb_serlist = &kgdb_sci_sermap;
544 struct kgdb_sermap *kgdb_porttype = &kgdb_sci_sermap;
545
546 void kgdb_register_sermap(struct kgdb_sermap *map)
547 {
548         struct kgdb_sermap *last;
549
550         for (last = kgdb_serlist; last->next; last = last->next)
551                 ;
552         last->next = map;
553         if (!map->namelen) {
554                 map->namelen = strlen(map->name);
555         }
556 }
557
558 static int __init kgdb_parse_options(char *options)
559 {
560         char c;
561         int baud;
562
563         /* Check for port spec (or use default) */
564
565         /* Determine port type and instance */
566         if (!memcmp(options, "tty", 3)) {
567                 struct kgdb_sermap *map = kgdb_serlist;
568
569                 while (map && memcmp(options, map->name, map->namelen))
570                         map = map->next;
571
572                 if (!map) {
573                         KGDB_PRINTK("unknown port spec in %s\n", options);
574                         return -1;
575                 }
576
577                 kgdb_porttype = map;
578                 kgdb_serial_setup = map->setup_fn;
579                 kgdb_portnum = options[map->namelen] - '0';
580                 options += map->namelen + 1;
581
582                 options = (*options == ',') ? options+1 : options;
583
584                 /* Read optional parameters (baud/parity/bits) */
585                 baud = simple_strtoul(options, &options, 10);
586                 if (baud != 0) {
587                         kgdb_baud = baud;
588
589                         c = toupper(*options);
590                         if (c == 'E' || c == 'O' || c == 'N') {
591                                 kgdb_parity = c;
592                                 options++;
593                         }
594
595                         c = *options;
596                         if (c == '7' || c == '8') {
597                                 kgdb_bits = c;
598                                 options++;
599                         }
600                         options = (*options == ',') ? options+1 : options;
601                 }
602         }
603
604         /* Check for action specification */
605         if (!memcmp(options, "halt", 4)) {
606                 kgdb_halt = 1;
607                 options += 4;
608         } else if (!memcmp(options, "disabled", 8)) {
609                 kgdb_enabled = 0;
610                 options += 8;
611         }
612
613         if (*options) {
614                 KGDB_PRINTK("ignored unknown options: %s\n", options);
615                 return 0;
616         }
617         return 1;
618 }
619 __setup("kgdb=", kgdb_parse_options);
620 #endif /* CONFIG_SH_KGDB */
621