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