1 /* $Id: setup.c,v 1.30 2003/10/13 07:21:19 lethal Exp $
3 * linux/arch/sh/kernel/setup.c
5 * Copyright (C) 1999 Niibe Yutaka
6 * Copyright (C) 2002, 2003 Paul Mundt
10 * This file handles the architecture-dependent parts of initialization
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>
25 #include <asm/io_generic.h>
26 #include <asm/sections.h>
28 #ifdef CONFIG_SH_EARLY_PRINTK
29 #include <asm/sh_bios.h>
34 static int kgdb_parse_options(char *options);
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.
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;
50 #if defined(CONFIG_SH_UNKNOWN)
51 struct sh_machine_vector sh_mv;
54 /* We need this to satisfy some external references. */
55 struct screen_info screen_info = {
56 0, 25, /* orig-x, orig-y */
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 */
67 extern void platform_setup(void);
68 extern char *get_system_type(void);
69 extern int root_mountflags;
71 #define MV_NAME_SIZE 32
73 static struct sh_machine_vector* __init get_mv_byname(const char* name);
76 * This is set up by the setup-routine at boot-time
78 #define PARAM ((unsigned char *)empty_zero_page)
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))
87 #define COMMAND_LINE ((char *) (PARAM+0x100))
88 #define COMMAND_LINE_SIZE 256
90 #define RAMDISK_IMAGE_START_MASK 0x07FF
91 #define RAMDISK_PROMPT_FLAG 0x8000
92 #define RAMDISK_LOAD_FLAG 0x4000
94 static char command_line[COMMAND_LINE_SIZE] = { 0, };
95 char saved_command_line[COMMAND_LINE_SIZE];
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 }
108 #define STANDARD_IO_RESOURCES (sizeof(standard_io_resources)/sizeof(struct resource))
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 }
121 unsigned long memory_start, memory_end;
123 /* XXX: MRB-remove - blatant hack */
125 #define SCIF_REG 0xffe80000
127 static void scif_sercon_putc(int c)
129 while (!(ctrl_inw(SCIF_REG + 0x10) & 0x20)) ;
131 ctrl_outb(c, SCIF_REG + 12);
132 ctrl_outw((ctrl_inw(SCIF_REG + 0x10) & 0x9f), SCIF_REG + 0x10);
135 scif_sercon_putc('\r');
138 static void scif_sercon_flush(void)
140 ctrl_outw((ctrl_inw(SCIF_REG + 0x10) & 0xbf), SCIF_REG + 0x10);
142 while (!(ctrl_inw(SCIF_REG + 0x10) & 0x40)) ;
144 ctrl_outw((ctrl_inw(SCIF_REG + 0x10) & 0xbf), SCIF_REG + 0x10);
147 static void scif_sercon_write(struct console *con, const char *s, unsigned count)
150 scif_sercon_putc(*s++);
155 static int __init scif_sercon_setup(struct console *con, char *options)
157 con->cflag = CREAD | HUPCL | CLOCAL | B57600 | CS8;
162 static struct console scif_sercon = {
164 .write = scif_sercon_write,
165 .setup = scif_sercon_setup,
166 .flags = CON_PRINTBUFFER,
170 void scif_sercon_init(int baud)
172 ctrl_outw(0, SCIF_REG + 8);
173 ctrl_outw(0, SCIF_REG);
176 ctrl_outb((50000000 / (32 * baud)) - 1, SCIF_REG + 4);
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);
185 register_console(&scif_sercon);
188 void scif_sercon_unregister(void)
190 unregister_console(&scif_sercon);
194 #ifdef CONFIG_SH_EARLY_PRINTK
196 * Print a string through the BIOS
198 static void sh_console_write(struct console *co, const char *s,
201 sh_bios_console_write(s, count);
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.
210 static int __init sh_console_setup(struct console *co, char *options)
212 int cflag = CREAD | HUPCL | CLOCAL;
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.
220 cflag |= B115200 | CS8 | /*no parity*/0;
227 static struct console sh_console = {
229 .write = sh_console_write,
230 .setup = sh_console_setup,
231 .flags = CON_PRINTBUFFER,
235 void sh_console_init(void)
237 register_console(&sh_console);
240 void sh_console_unregister(void)
242 unregister_console(&sh_console);
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,
252 char c = ' ', *to = command_line, *from = COMMAND_LINE;
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';
259 memory_start = (unsigned long)PAGE_OFFSET+__MEMORY_START;
260 memory_end = memory_start + __MEMORY_SIZE;
264 * "mem=XXX[kKmM]" defines a size of memory.
266 if (c == ' ' && !memcmp(from, "mem=", 4)) {
267 if (to != command_line)
270 unsigned long mem_size;
272 mem_size = memparse(from+4, &from);
273 memory_end = memory_start + mem_size;
276 if (c == ' ' && !memcmp(from, "sh_mv=", 6)) {
280 if (to != command_line)
283 mv_end = strchr(from, ' ');
285 mv_end = from + strlen(from);
287 mv_comma = strchr(from, ',');
288 if ((mv_comma != NULL) && (mv_comma < mv_end)) {
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;
295 mv_len = mv_end - from;
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';
303 *mvp = get_mv_byname(mv_name);
308 if (COMMAND_LINE_SIZE <= ++len)
313 *cmdline_p = command_line;
316 static int __init sh_mv_setup(char **cmdline_p)
318 #if defined(CONFIG_SH_UNKNOWN)
319 extern struct sh_machine_vector mv_unknown;
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;
326 parse_cmdline(cmdline_p, mv_name, &mv, &mv_io_base, &mv_mmio_enable);
328 #ifdef CONFIG_CMDLINE_BOOL
329 sprintf(*cmdline_p, CONFIG_CMDLINE);
332 #ifdef CONFIG_SH_GENERIC
335 if (*mv_name != '\0') {
336 printk("Warning: Unsupported machine %s, using unknown\n",
342 #ifdef CONFIG_SH_UNKNOWN
347 * Manually walk the vec, fill in anything that the board hasn't yet
348 * by hand, wrapping to the generic implementation.
350 #define mv_set(elem) do { \
351 if (!sh_mv.mv_##elem) \
352 sh_mv.mv_##elem = generic_##elem; \
355 mv_set(inb); mv_set(inw); mv_set(inl);
356 mv_set(outb); mv_set(outw); mv_set(outl);
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);
361 mv_set(insb); mv_set(insw); mv_set(insl);
362 mv_set(outsb); mv_set(outsw); mv_set(outsl);
364 mv_set(readb); mv_set(readw); mv_set(readl);
365 mv_set(writeb); mv_set(writew); mv_set(writel);
370 mv_set(isa_port2addr);
373 #ifdef CONFIG_SH_UNKNOWN
374 __set_io_port_base(mv_io_base);
380 void __init setup_arch(char **cmdline_p)
382 unsigned long bootmap_size;
383 unsigned long start_pfn, max_pfn, max_low_pfn;
385 /* XXX: MRB-remove */
387 scif_sercon_init(57600);
389 #ifdef CONFIG_SH_EARLY_PRINTK
393 ROOT_DEV = old_decode_dev(ORIG_ROOT_DEV);
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);
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;
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;
413 sh_mv_setup(cmdline_p);
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)
419 #ifdef CONFIG_DISCONTIGMEM
420 NODE_DATA(0)->bdata = &discontig_node_bdata[0];
421 NODE_DATA(1)->bdata = &discontig_node_bdata[1];
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);
432 * Find the highest page frame number we have available
434 max_pfn = PFN_DOWN(__pa(memory_end));
437 * Determine low and high memory ranges:
439 max_low_pfn = max_pfn;
442 * Partially used pages are not usable - thus
443 * we are rounding upwards:
445 start_pfn = PFN_UP(__pa(_end));
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().
452 bootmap_size = init_bootmem_node(NODE_DATA(0), start_pfn,
453 __MEMORY_START>>PAGE_SHIFT,
456 * Register fully available low RAM pages with the bootmem allocator.
459 unsigned long curr_pfn, last_pfn, pages;
462 * We are rounding up the start address of usable memory:
464 curr_pfn = PFN_UP(__MEMORY_START);
466 * ... and at the end of the usable range downwards:
468 last_pfn = PFN_DOWN(__pa(memory_end));
470 if (last_pfn > max_low_pfn)
471 last_pfn = max_low_pfn;
473 pages = last_pfn - curr_pfn;
474 free_bootmem_node(NODE_DATA(0), PFN_PHYS(curr_pfn),
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.
485 reserve_bootmem_node(NODE_DATA(0), __MEMORY_START+PAGE_SIZE,
486 (PFN_PHYS(start_pfn)+bootmap_size+PAGE_SIZE-1)-__MEMORY_START);
489 * reserve physical page 0 - it's a special BIOS page on many boxes,
490 * enabling clean reboots, SMP operation, laptop functions.
492 reserve_bootmem_node(NODE_DATA(0), __MEMORY_START, PAGE_SIZE);
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);
499 INITRD_START ? INITRD_START + PAGE_OFFSET + __MEMORY_START : 0;
500 initrd_end = initrd_start + INITRD_SIZE;
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);
511 #ifdef CONFIG_DUMMY_CONSOLE
512 conswitchp = &dummy_con;
515 /* Perform the machine specific initialisation */
521 struct sh_machine_vector* __init get_mv_byname(const char* name)
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;
528 int i, n = ((unsigned long)&__machvec_end
529 - (unsigned long)&__machvec_start)/
530 sizeof(struct sh_machine_vector);
532 for (i = 0; i < n; ++i) {
533 struct sh_machine_vector *mv = &all_vecs[i];
536 if (strcasecmp(name, get_system_type()) == 0) {
543 static struct cpu cpu[NR_CPUS];
545 static int __init topology_init(void)
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);
556 subsys_initcall(topology_init);
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"
575 const char *get_cpu_subtype(void)
577 return cpu_name[boot_cpu_data.type];
580 #ifdef CONFIG_PROC_FS
581 static const char *cpu_flags[] = {
582 "none", "fpu", "p2flush", "mmuassoc", "dsp",
585 static void show_cpuflags(struct seq_file *m)
589 seq_printf(m, "cpu flags\t:");
591 if (!cpu_data->flags) {
592 seq_printf(m, " %s\n", cpu_flags[0]);
596 for (i = 0; i < cpu_data->flags; i++)
597 if ((cpu_data->flags & (1 << i)))
598 seq_printf(m, " %s", cpu_flags[i]);
603 static void show_cacheinfo(struct seq_file *m, const char *type, struct cache_info info)
605 unsigned int cache_size;
607 cache_size = info.ways * info.sets * info.linesz;
609 seq_printf(m, "%s size\t: %dKiB\n", type, cache_size >> 10);
613 * Get CPU information for use by the procfs.
615 static int show_cpuinfo(struct seq_file *m, void *v)
617 unsigned int cpu = smp_processor_id();
619 if (!cpu && cpu_online(cpu))
620 seq_printf(m, "machine\t\t: %s\n", get_system_type());
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());
628 seq_printf(m, "cache type\t: ");
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.
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);
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);
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);
648 #define PRINT_CLOCK(name, value) \
649 seq_printf(m, name " clock\t: %d.%02dMHz\n", \
650 ((value) / 1000000), ((value) % 1000000)/10000)
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);
657 PRINT_CLOCK("module", boot_cpu_data.module_clock);
663 static void *c_start(struct seq_file *m, loff_t *pos)
665 return *pos < NR_CPUS ? cpu_data + *pos : NULL;
667 static void *c_next(struct seq_file *m, void *v, loff_t *pos)
670 return c_start(m, pos);
672 static void c_stop(struct seq_file *m, void *v)
675 struct seq_operations cpuinfo_op = {
679 .show = show_cpuinfo,
681 #endif /* CONFIG_PROC_FS */
683 #ifdef CONFIG_SH_KGDB
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.
690 struct kgdb_sermap kgdb_sci_sermap =
691 { "ttySC", 5, kgdb_sci_setup, NULL };
693 struct kgdb_sermap *kgdb_serlist = &kgdb_sci_sermap;
694 struct kgdb_sermap *kgdb_porttype = &kgdb_sci_sermap;
696 void kgdb_register_sermap(struct kgdb_sermap *map)
698 struct kgdb_sermap *last;
700 for (last = kgdb_serlist; last->next; last = last->next)
704 map->namelen = strlen(map->name);
708 static int __init kgdb_parse_options(char *options)
713 /* Check for port spec (or use default) */
715 /* Determine port type and instance */
716 if (!memcmp(options, "tty", 3)) {
717 struct kgdb_sermap *map = kgdb_serlist;
719 while (map && memcmp(options, map->name, map->namelen))
723 KGDB_PRINTK("unknown port spec in %s\n", options);
728 kgdb_serial_setup = map->setup_fn;
729 kgdb_portnum = options[map->namelen] - '0';
730 options += map->namelen + 1;
732 options = (*options == ',') ? options+1 : options;
734 /* Read optional parameters (baud/parity/bits) */
735 baud = simple_strtoul(options, &options, 10);
739 c = toupper(*options);
740 if (c == 'E' || c == 'O' || c == 'N') {
746 if (c == '7' || c == '8') {
750 options = (*options == ',') ? options+1 : options;
754 /* Check for action specification */
755 if (!memcmp(options, "halt", 4)) {
758 } else if (!memcmp(options, "disabled", 8)) {
764 KGDB_PRINTK("ignored unknown options: %s\n", options);
769 __setup("kgdb=", kgdb_parse_options);
770 #endif /* CONFIG_SH_KGDB */