ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[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/tty.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 <asm/uaccess.h>
24 #include <asm/io.h>
25 #include <asm/io_generic.h>
26 #include <asm/sections.h>
27 #include <asm/irq.h>
28 #ifdef CONFIG_SH_EARLY_PRINTK
29 #include <asm/sh_bios.h>
30 #endif
31
32 #ifdef CONFIG_SH_KGDB
33 #include <asm/kgdb.h>
34 static int kgdb_parse_options(char *options);
35 #endif
36
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, 0, 10000000, };
47 struct screen_info screen_info;
48 unsigned char aux_device_present = 0xaa;
49
50 #if defined(CONFIG_SH_UNKNOWN)
51 struct sh_machine_vector sh_mv;
52 #endif
53
54 /* We need this to satisfy some external references. */
55 struct screen_info screen_info = {
56         0, 25,                  /* orig-x, orig-y */
57         0,                      /* unused */
58         0,                      /* orig-video-page */
59         0,                      /* orig-video-mode */
60         80,                     /* orig-video-cols */
61         0,0,0,                  /* ega_ax, ega_bx, ega_cx */
62         25,                     /* orig-video-lines */
63         0,                      /* orig-video-isVGA */
64         16                      /* orig-video-points */
65 };
66
67 extern void platform_setup(void);
68 extern char *get_system_type(void);
69 extern int root_mountflags;
70
71 #define MV_NAME_SIZE 32
72
73 static struct sh_machine_vector* __init get_mv_byname(const char* name);
74
75 /*
76  * This is set up by the setup-routine at boot-time
77  */
78 #define PARAM   ((unsigned char *)empty_zero_page)
79
80 #define MOUNT_ROOT_RDONLY (*(unsigned long *) (PARAM+0x000))
81 #define RAMDISK_FLAGS (*(unsigned long *) (PARAM+0x004))
82 #define ORIG_ROOT_DEV (*(unsigned long *) (PARAM+0x008))
83 #define LOADER_TYPE (*(unsigned long *) (PARAM+0x00c))
84 #define INITRD_START (*(unsigned long *) (PARAM+0x010))
85 #define INITRD_SIZE (*(unsigned long *) (PARAM+0x014))
86 /* ... */
87 #define COMMAND_LINE ((char *) (PARAM+0x100))
88 #define COMMAND_LINE_SIZE 256
89
90 #define RAMDISK_IMAGE_START_MASK        0x07FF
91 #define RAMDISK_PROMPT_FLAG             0x8000
92 #define RAMDISK_LOAD_FLAG               0x4000  
93
94 static char command_line[COMMAND_LINE_SIZE] = { 0, };
95        char saved_command_line[COMMAND_LINE_SIZE];
96
97 struct resource standard_io_resources[] = {
98         { "dma1", 0x00, 0x1f },
99         { "pic1", 0x20, 0x3f },
100         { "timer", 0x40, 0x5f },
101         { "keyboard", 0x60, 0x6f },
102         { "dma page reg", 0x80, 0x8f },
103         { "pic2", 0xa0, 0xbf },
104         { "dma2", 0xc0, 0xdf },
105         { "fpu", 0xf0, 0xff }
106 };
107
108 #define STANDARD_IO_RESOURCES (sizeof(standard_io_resources)/sizeof(struct resource))
109
110 /* System RAM - interrupted by the 640kB-1M hole */
111 #define code_resource (ram_resources[3])
112 #define data_resource (ram_resources[4])
113 static struct resource ram_resources[] = {
114         { "System RAM", 0x000000, 0x09ffff, IORESOURCE_BUSY },
115         { "System RAM", 0x100000, 0x100000, IORESOURCE_BUSY },
116         { "Video RAM area", 0x0a0000, 0x0bffff },
117         { "Kernel code", 0x100000, 0 },
118         { "Kernel data", 0, 0 }
119 };
120
121 unsigned long memory_start, memory_end;
122
123 /* XXX: MRB-remove - blatant hack */
124 #if 1
125 #define SCIF_REG        0xffe80000
126
127 static void scif_sercon_putc(int c)
128 {
129         while (!(ctrl_inw(SCIF_REG + 0x10) & 0x20)) ;
130
131         ctrl_outb(c, SCIF_REG + 12);
132         ctrl_outw((ctrl_inw(SCIF_REG + 0x10) & 0x9f), SCIF_REG + 0x10);
133
134         if (c == '\n')
135                 scif_sercon_putc('\r');
136 }
137
138 static void scif_sercon_flush(void)
139 {
140         ctrl_outw((ctrl_inw(SCIF_REG + 0x10) & 0xbf), SCIF_REG + 0x10);
141
142         while (!(ctrl_inw(SCIF_REG + 0x10) & 0x40)) ;
143
144         ctrl_outw((ctrl_inw(SCIF_REG + 0x10) & 0xbf), SCIF_REG + 0x10);
145 }
146
147 static void scif_sercon_write(struct console *con, const char *s, unsigned count)
148 {
149         while (count-- > 0)
150                 scif_sercon_putc(*s++);
151
152         scif_sercon_flush();
153 }
154
155 static int __init scif_sercon_setup(struct console *con, char *options)
156 {
157         con->cflag = CREAD | HUPCL | CLOCAL | B57600 | CS8;
158
159         return 0;
160 }
161
162 static struct console scif_sercon = {
163         .name           = "sercon",
164         .write          = scif_sercon_write,
165         .setup          = scif_sercon_setup,
166         .flags          = CON_PRINTBUFFER,
167         .index          = -1,
168 };
169
170 void scif_sercon_init(int baud)
171 {
172         ctrl_outw(0, SCIF_REG + 8);
173         ctrl_outw(0, SCIF_REG);
174
175         /* Set baud rate */
176         ctrl_outb((50000000 / (32 * baud)) - 1, SCIF_REG + 4);
177
178         ctrl_outw(12, SCIF_REG + 24);
179         ctrl_outw(8, SCIF_REG + 24);
180         ctrl_outw(0, SCIF_REG + 32);
181         ctrl_outw(0x60, SCIF_REG + 16);
182         ctrl_outw(0, SCIF_REG + 36);
183         ctrl_outw(0x30, SCIF_REG + 8);
184
185         register_console(&scif_sercon);
186 }
187
188 void scif_sercon_unregister(void)
189 {
190         unregister_console(&scif_sercon);
191 }
192 #endif
193
194 #ifdef CONFIG_SH_EARLY_PRINTK
195 /*
196  *      Print a string through the BIOS
197  */
198 static void sh_console_write(struct console *co, const char *s,
199                                  unsigned count)
200 {
201         sh_bios_console_write(s, count);
202 }
203
204 /*
205  *      Setup initial baud/bits/parity. We do two things here:
206  *      - construct a cflag setting for the first rs_open()
207  *      - initialize the serial port
208  *      Return non-zero if we didn't find a serial port.
209  */
210 static int __init sh_console_setup(struct console *co, char *options)
211 {
212         int     cflag = CREAD | HUPCL | CLOCAL;
213
214         /*
215          *      Now construct a cflag setting.
216          *      TODO: this is a totally bogus cflag, as we have
217          *      no idea what serial settings the BIOS is using, or
218          *      even if its using the serial port at all.
219          */
220         cflag |= B115200 | CS8 | /*no parity*/0;
221
222         co->cflag = cflag;
223
224         return 0;
225 }
226
227 static struct console sh_console = {
228         .name           = "bios",
229         .write          = sh_console_write,
230         .setup          = sh_console_setup,
231         .flags          = CON_PRINTBUFFER,
232         .index          = -1,
233 };
234
235 void sh_console_init(void)
236 {
237         register_console(&sh_console);
238 }
239
240 void sh_console_unregister(void)
241 {
242         unregister_console(&sh_console);
243 }
244
245 #endif
246
247 static inline void parse_cmdline (char ** cmdline_p, char mv_name[MV_NAME_SIZE],
248                                   struct sh_machine_vector** mvp,
249                                   unsigned long *mv_io_base,
250                                   int *mv_mmio_enable)
251 {
252         char c = ' ', *to = command_line, *from = COMMAND_LINE;
253         int len = 0;
254
255         /* Save unparsed command line copy for /proc/cmdline */
256         memcpy(saved_command_line, COMMAND_LINE, COMMAND_LINE_SIZE);
257         saved_command_line[COMMAND_LINE_SIZE-1] = '\0';
258
259         memory_start = (unsigned long)PAGE_OFFSET+__MEMORY_START;
260         memory_end = memory_start + __MEMORY_SIZE;
261
262         for (;;) {
263                 /*
264                  * "mem=XXX[kKmM]" defines a size of memory.
265                  */
266                 if (c == ' ' && !memcmp(from, "mem=", 4)) {
267                         if (to != command_line)
268                                 to--;
269                         {
270                                 unsigned long mem_size;
271
272                                 mem_size = memparse(from+4, &from);
273                                 memory_end = memory_start + mem_size;
274                         }
275                 }
276                 if (c == ' ' && !memcmp(from, "sh_mv=", 6)) {
277                         char* mv_end;
278                         char* mv_comma;
279                         int mv_len;
280                         if (to != command_line)
281                                 to--;
282                         from += 6;
283                         mv_end = strchr(from, ' ');
284                         if (mv_end == NULL)
285                                 mv_end = from + strlen(from);
286
287                         mv_comma = strchr(from, ',');
288                         if ((mv_comma != NULL) && (mv_comma < mv_end)) {
289                                 int ints[3];
290                                 get_options(mv_comma+1, ARRAY_SIZE(ints), ints);
291                                 *mv_io_base = ints[1];
292                                 *mv_mmio_enable = ints[2];
293                                 mv_len = mv_comma - from;
294                         } else {
295                                 mv_len = mv_end - from;
296                         }
297                         if (mv_len > (MV_NAME_SIZE-1))
298                                 mv_len = MV_NAME_SIZE-1;
299                         memcpy(mv_name, from, mv_len);
300                         mv_name[mv_len] = '\0';
301                         from = mv_end;
302
303                         *mvp = get_mv_byname(mv_name);
304                 }
305                 c = *(from++);
306                 if (!c)
307                         break;
308                 if (COMMAND_LINE_SIZE <= ++len)
309                         break;
310                 *(to++) = c;
311         }
312         *to = '\0';
313         *cmdline_p = command_line;
314 }
315
316 static int __init sh_mv_setup(char **cmdline_p)
317 {
318 #if defined(CONFIG_SH_UNKNOWN)
319         extern struct sh_machine_vector mv_unknown;
320 #endif
321         struct sh_machine_vector *mv = NULL;
322         char mv_name[MV_NAME_SIZE] = "";
323         unsigned long mv_io_base = 0;
324         int mv_mmio_enable = 0;
325
326         parse_cmdline(cmdline_p, mv_name, &mv, &mv_io_base, &mv_mmio_enable);
327
328 #ifdef CONFIG_CMDLINE_BOOL
329         sprintf(*cmdline_p, CONFIG_CMDLINE);
330 #endif
331
332 #ifdef CONFIG_SH_GENERIC
333         if (mv == NULL) {
334                 mv = &mv_unknown;
335                 if (*mv_name != '\0') {
336                         printk("Warning: Unsupported machine %s, using unknown\n",
337                                mv_name);
338                 }
339         }
340         sh_mv = *mv;
341 #endif
342 #ifdef CONFIG_SH_UNKNOWN
343         sh_mv = mv_unknown;
344 #endif
345
346         /*
347          * Manually walk the vec, fill in anything that the board hasn't yet
348          * by hand, wrapping to the generic implementation.
349          */
350 #define mv_set(elem) do { \
351         if (!sh_mv.mv_##elem) \
352                 sh_mv.mv_##elem = generic_##elem; \
353 } while (0)
354
355         mv_set(inb);    mv_set(inw);    mv_set(inl);
356         mv_set(outb);   mv_set(outw);   mv_set(outl);
357
358         mv_set(inb_p);  mv_set(inw_p);  mv_set(inl_p);
359         mv_set(outb_p); mv_set(outw_p); mv_set(outl_p);
360
361         mv_set(insb);   mv_set(insw);   mv_set(insl);
362         mv_set(outsb);  mv_set(outsw);  mv_set(outsl);
363
364         mv_set(readb);  mv_set(readw);  mv_set(readl);
365         mv_set(writeb); mv_set(writew); mv_set(writel);
366
367         mv_set(ioremap);
368         mv_set(iounmap);
369
370         mv_set(isa_port2addr);
371         mv_set(irq_demux);
372
373 #ifdef CONFIG_SH_UNKNOWN
374         __set_io_port_base(mv_io_base);
375 #endif
376
377         return 0;
378 }
379
380 void __init setup_arch(char **cmdline_p)
381 {
382         unsigned long bootmap_size;
383         unsigned long start_pfn, max_pfn, max_low_pfn;
384
385 /* XXX: MRB-remove */
386 #if 0
387         scif_sercon_init(57600);
388 #endif
389 #ifdef CONFIG_SH_EARLY_PRINTK
390         sh_console_init();
391 #endif
392         
393         ROOT_DEV = old_decode_dev(ORIG_ROOT_DEV);
394
395 #ifdef CONFIG_BLK_DEV_RAM
396         rd_image_start = RAMDISK_FLAGS & RAMDISK_IMAGE_START_MASK;
397         rd_prompt = ((RAMDISK_FLAGS & RAMDISK_PROMPT_FLAG) != 0);
398         rd_doload = ((RAMDISK_FLAGS & RAMDISK_LOAD_FLAG) != 0);
399 #endif
400
401         if (!MOUNT_ROOT_RDONLY)
402                 root_mountflags &= ~MS_RDONLY;
403         init_mm.start_code = (unsigned long) _text;
404         init_mm.end_code = (unsigned long) _etext;
405         init_mm.end_data = (unsigned long) _edata;
406         init_mm.brk = (unsigned long) _end;
407
408         code_resource.start = virt_to_bus(_text);
409         code_resource.end = virt_to_bus(_etext)-1;
410         data_resource.start = virt_to_bus(_etext);
411         data_resource.end = virt_to_bus(_edata)-1;
412
413         sh_mv_setup(cmdline_p);
414
415 #define PFN_UP(x)       (((x) + PAGE_SIZE-1) >> PAGE_SHIFT)
416 #define PFN_DOWN(x)     ((x) >> PAGE_SHIFT)
417 #define PFN_PHYS(x)     ((x) << PAGE_SHIFT)
418
419 #ifdef CONFIG_DISCONTIGMEM
420         NODE_DATA(0)->bdata = &discontig_node_bdata[0];
421         NODE_DATA(1)->bdata = &discontig_node_bdata[1];
422
423         bootmap_size = init_bootmem_node(NODE_DATA(1), 
424                                          PFN_UP(__MEMORY_START_2ND),
425                                          PFN_UP(__MEMORY_START_2ND),
426                                          PFN_DOWN(__MEMORY_START_2ND+__MEMORY_SIZE_2ND));
427         free_bootmem_node(NODE_DATA(1), __MEMORY_START_2ND, __MEMORY_SIZE_2ND);
428         reserve_bootmem_node(NODE_DATA(1), __MEMORY_START_2ND, bootmap_size);
429 #endif
430
431         /*
432          * Find the highest page frame number we have available
433          */
434         max_pfn = PFN_DOWN(__pa(memory_end));
435
436         /*
437          * Determine low and high memory ranges:
438          */
439         max_low_pfn = max_pfn;
440
441         /*
442          * Partially used pages are not usable - thus
443          * we are rounding upwards:
444          */
445         start_pfn = PFN_UP(__pa(_end));
446
447         /*
448          * Find a proper area for the bootmem bitmap. After this
449          * bootstrap step all allocations (until the page allocator
450          * is intact) must be done via bootmem_alloc().
451          */
452         bootmap_size = init_bootmem_node(NODE_DATA(0), start_pfn,
453                                          __MEMORY_START>>PAGE_SHIFT,
454                                          max_low_pfn);
455         /*
456          * Register fully available low RAM pages with the bootmem allocator.
457          */
458         {
459                 unsigned long curr_pfn, last_pfn, pages;
460
461                 /*
462                  * We are rounding up the start address of usable memory:
463                  */
464                 curr_pfn = PFN_UP(__MEMORY_START);
465                 /*
466                  * ... and at the end of the usable range downwards:
467                  */
468                 last_pfn = PFN_DOWN(__pa(memory_end));
469
470                 if (last_pfn > max_low_pfn)
471                         last_pfn = max_low_pfn;
472
473                 pages = last_pfn - curr_pfn;
474                 free_bootmem_node(NODE_DATA(0), PFN_PHYS(curr_pfn),
475                                   PFN_PHYS(pages));
476         }
477
478         /*
479          * Reserve the kernel text and
480          * Reserve the bootmem bitmap. We do this in two steps (first step
481          * was init_bootmem()), because this catches the (definitely buggy)
482          * case of us accidentally initializing the bootmem allocator with
483          * an invalid RAM area.
484          */
485         reserve_bootmem_node(NODE_DATA(0), __MEMORY_START+PAGE_SIZE,
486                 (PFN_PHYS(start_pfn)+bootmap_size+PAGE_SIZE-1)-__MEMORY_START);
487
488         /*
489          * reserve physical page 0 - it's a special BIOS page on many boxes,
490          * enabling clean reboots, SMP operation, laptop functions.
491          */
492         reserve_bootmem_node(NODE_DATA(0), __MEMORY_START, PAGE_SIZE);
493
494 #ifdef CONFIG_BLK_DEV_INITRD
495         if (LOADER_TYPE && INITRD_START) {
496                 if (INITRD_START + INITRD_SIZE <= (max_low_pfn << PAGE_SHIFT)) {
497                         reserve_bootmem_node(NODE_DATA(0), INITRD_START+__MEMORY_START, INITRD_SIZE);
498                         initrd_start =
499                                 INITRD_START ? INITRD_START + PAGE_OFFSET + __MEMORY_START : 0;
500                         initrd_end = initrd_start + INITRD_SIZE;
501                 } else {
502                         printk("initrd extends beyond end of memory "
503                             "(0x%08lx > 0x%08lx)\ndisabling initrd\n",
504                                     INITRD_START + INITRD_SIZE,
505                                     max_low_pfn << PAGE_SHIFT);
506                         initrd_start = 0;
507                 }
508         }
509 #endif
510
511 #ifdef CONFIG_DUMMY_CONSOLE
512         conswitchp = &dummy_con;
513 #endif
514
515         /* Perform the machine specific initialisation */
516         platform_setup();
517
518         paging_init();
519 }
520
521 struct sh_machine_vector* __init get_mv_byname(const char* name)
522 {
523         extern int strcasecmp(const char *, const char *);
524         extern long __machvec_start, __machvec_end;
525         struct sh_machine_vector *all_vecs =
526                 (struct sh_machine_vector *)&__machvec_start;
527
528         int i, n = ((unsigned long)&__machvec_end
529                     - (unsigned long)&__machvec_start)/
530                 sizeof(struct sh_machine_vector);
531
532         for (i = 0; i < n; ++i) {
533                 struct sh_machine_vector *mv = &all_vecs[i];
534                 if (mv == NULL)
535                         continue;
536                 if (strcasecmp(name, get_system_type()) == 0) {
537                         return mv;
538                 }
539         }
540         return NULL;
541 }
542
543 static struct cpu cpu[NR_CPUS];
544
545 static int __init topology_init(void)
546 {
547         int cpu_id;
548
549         for (cpu_id = 0; cpu_id < NR_CPUS; cpu_id++)
550                 if (cpu_possible(cpu_id))
551                         register_cpu(&cpu[cpu_id], cpu_id, NULL);
552
553         return 0;
554 }
555
556 subsys_initcall(topology_init);
557
558 static const char *cpu_name[] = {
559         [CPU_SH7604]    = "SH7604",
560         [CPU_SH7708]    = "SH7708",
561         [CPU_SH7729]    = "SH7729",
562         [CPU_SH7750]    = "SH7750",
563         [CPU_SH7750S]   = "SH7750S",
564         [CPU_SH7750R]   = "SH7750R",
565         [CPU_SH7751]    = "SH7751",
566         [CPU_SH7751R]   = "SH7751R",
567         [CPU_SH7760]    = "SH7760",
568         [CPU_ST40RA]    = "ST40RA",
569         [CPU_ST40GX1]   = "ST40GX1",
570         [CPU_SH4_202]   = "SH4-202",
571         [CPU_SH4_501]   = "SH4-501",
572         [CPU_SH_NONE]   = "Unknown"
573 };
574
575 const char *get_cpu_subtype(void)
576 {
577         return cpu_name[boot_cpu_data.type];
578 }
579
580 #ifdef CONFIG_PROC_FS
581 static const char *cpu_flags[] = {
582         "none", "fpu", "p2flush", "mmuassoc", "dsp",
583 };
584
585 static void show_cpuflags(struct seq_file *m)
586 {
587         unsigned long i;
588
589         seq_printf(m, "cpu flags\t:");
590
591         if (!cpu_data->flags) {
592                 seq_printf(m, " %s\n", cpu_flags[0]);
593                 return;
594         }
595
596         for (i = 0; i < cpu_data->flags; i++)
597                 if ((cpu_data->flags & (1 << i)))
598                         seq_printf(m, " %s", cpu_flags[i]);
599         
600         seq_printf(m, "\n");
601 }
602
603 static void show_cacheinfo(struct seq_file *m, const char *type, struct cache_info info)
604 {
605         unsigned int cache_size;
606
607         cache_size = info.ways * info.sets * info.linesz;
608
609         seq_printf(m, "%s size\t: %dKiB\n", type, cache_size >> 10);
610 }
611
612 /*
613  *      Get CPU information for use by the procfs.
614  */
615 static int show_cpuinfo(struct seq_file *m, void *v)
616 {
617         unsigned int cpu = smp_processor_id();
618
619         if (!cpu && cpu_online(cpu))
620                 seq_printf(m, "machine\t\t: %s\n", get_system_type());
621
622         seq_printf(m, "processor\t: %d\n", cpu);
623         seq_printf(m, "cpu family\t: %s\n", system_utsname.machine);
624         seq_printf(m, "cpu type\t: %s\n", get_cpu_subtype());
625
626         show_cpuflags(m);
627
628         seq_printf(m, "cache type\t: ");
629
630         /*
631          * Check for what type of cache we have, we support both the
632          * unified cache on the SH-2 and SH-3, as well as the harvard
633          * style cache on the SH-4.
634          */
635         if (test_bit(SH_CACHE_COMBINED, &(boot_cpu_data.icache.flags))) {
636                 seq_printf(m, "unified\n");
637                 show_cacheinfo(m, "cache", boot_cpu_data.icache);
638         } else {
639                 seq_printf(m, "split (harvard)\n");
640                 show_cacheinfo(m, "icache", boot_cpu_data.icache);
641                 show_cacheinfo(m, "dcache", boot_cpu_data.dcache);
642         }
643
644         seq_printf(m, "bogomips\t: %lu.%02lu\n",
645                      boot_cpu_data.loops_per_jiffy/(500000/HZ),
646                      (boot_cpu_data.loops_per_jiffy/(5000/HZ)) % 100);
647
648 #define PRINT_CLOCK(name, value) \
649         seq_printf(m, name " clock\t: %d.%02dMHz\n", \
650                      ((value) / 1000000), ((value) % 1000000)/10000)
651         
652         PRINT_CLOCK("cpu", boot_cpu_data.cpu_clock);
653         PRINT_CLOCK("bus", boot_cpu_data.bus_clock);
654 #ifdef CONFIG_CPU_SUBTYPE_ST40STB1
655         PRINT_CLOCK("memory", boot_cpu_data.memory_clock);
656 #endif
657         PRINT_CLOCK("module", boot_cpu_data.module_clock);
658
659         return 0;
660 }
661
662
663 static void *c_start(struct seq_file *m, loff_t *pos)
664 {
665         return *pos < NR_CPUS ? cpu_data + *pos : NULL;
666 }
667 static void *c_next(struct seq_file *m, void *v, loff_t *pos)
668 {
669         ++*pos;
670         return c_start(m, pos);
671 }
672 static void c_stop(struct seq_file *m, void *v)
673 {
674 }
675 struct seq_operations cpuinfo_op = {
676         .start  = c_start,
677         .next   = c_next,
678         .stop   = c_stop,
679         .show   = show_cpuinfo,
680 };
681 #endif /* CONFIG_PROC_FS */
682
683 #ifdef CONFIG_SH_KGDB
684 /*
685  * Parse command-line kgdb options.  By default KGDB is enabled,
686  * entered on error (or other action) using default serial info.
687  * The command-line option can include a serial port specification
688  * and an action to override default or configured behavior.
689  */
690 struct kgdb_sermap kgdb_sci_sermap =
691 { "ttySC", 5, kgdb_sci_setup, NULL };
692
693 struct kgdb_sermap *kgdb_serlist = &kgdb_sci_sermap;
694 struct kgdb_sermap *kgdb_porttype = &kgdb_sci_sermap;
695
696 void kgdb_register_sermap(struct kgdb_sermap *map)
697 {
698         struct kgdb_sermap *last;
699
700         for (last = kgdb_serlist; last->next; last = last->next)
701                 ;
702         last->next = map;
703         if (!map->namelen) {
704                 map->namelen = strlen(map->name);
705         }
706 }
707
708 static int __init kgdb_parse_options(char *options)
709 {
710         char c;
711         int baud;
712
713         /* Check for port spec (or use default) */
714
715         /* Determine port type and instance */
716         if (!memcmp(options, "tty", 3)) {
717                 struct kgdb_sermap *map = kgdb_serlist;
718
719                 while (map && memcmp(options, map->name, map->namelen))
720                         map = map->next;
721
722                 if (!map) {
723                         KGDB_PRINTK("unknown port spec in %s\n", options);
724                         return -1;
725                 }
726
727                 kgdb_porttype = map;
728                 kgdb_serial_setup = map->setup_fn;
729                 kgdb_portnum = options[map->namelen] - '0';
730                 options += map->namelen + 1;
731
732                 options = (*options == ',') ? options+1 : options;
733                 
734                 /* Read optional parameters (baud/parity/bits) */
735                 baud = simple_strtoul(options, &options, 10);
736                 if (baud != 0) {
737                         kgdb_baud = baud;
738
739                         c = toupper(*options);
740                         if (c == 'E' || c == 'O' || c == 'N') {
741                                 kgdb_parity = c;
742                                 options++;
743                         }
744
745                         c = *options;
746                         if (c == '7' || c == '8') {
747                                 kgdb_bits = c;
748                                 options++;
749                         }
750                         options = (*options == ',') ? options+1 : options;
751                 }
752         }
753
754         /* Check for action specification */
755         if (!memcmp(options, "halt", 4)) {
756                 kgdb_halt = 1;
757                 options += 4;
758         } else if (!memcmp(options, "disabled", 8)) {
759                 kgdb_enabled = 0;
760                 options += 8;
761         }
762
763         if (*options) {
764                 KGDB_PRINTK("ignored unknown options: %s\n", options);
765                 return 0;
766         }
767         return 1;
768 }
769 __setup("kgdb=", kgdb_parse_options);
770 #endif /* CONFIG_SH_KGDB */
771