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 #include <asm/setup.h>
32 static int kgdb_parse_options(char *options);
34 extern void * __rd_start, * __rd_end;
40 * Initialize loops_per_jiffy as 10000000 (1000MIPS).
41 * This value will be used at the very early stage of serial setup.
42 * The bigger value means no problem.
44 struct sh_cpuinfo boot_cpu_data = { CPU_SH_NONE, 0, 10000000, };
45 struct screen_info screen_info;
47 #if defined(CONFIG_SH_UNKNOWN)
48 struct sh_machine_vector sh_mv;
51 /* We need this to satisfy some external references. */
52 struct screen_info screen_info = {
53 0, 25, /* orig-x, orig-y */
55 0, /* orig-video-page */
56 0, /* orig-video-mode */
57 80, /* orig-video-cols */
58 0,0,0, /* ega_ax, ega_bx, ega_cx */
59 25, /* orig-video-lines */
60 0, /* orig-video-isVGA */
61 16 /* orig-video-points */
64 extern void platform_setup(void);
65 extern char *get_system_type(void);
66 extern int root_mountflags;
68 #define MV_NAME_SIZE 32
70 static struct sh_machine_vector* __init get_mv_byname(const char* name);
73 * This is set up by the setup-routine at boot-time
75 #define PARAM ((unsigned char *)empty_zero_page)
77 #define MOUNT_ROOT_RDONLY (*(unsigned long *) (PARAM+0x000))
78 #define RAMDISK_FLAGS (*(unsigned long *) (PARAM+0x004))
79 #define ORIG_ROOT_DEV (*(unsigned long *) (PARAM+0x008))
80 #define LOADER_TYPE (*(unsigned long *) (PARAM+0x00c))
81 #define INITRD_START (*(unsigned long *) (PARAM+0x010))
82 #define INITRD_SIZE (*(unsigned long *) (PARAM+0x014))
84 #define COMMAND_LINE ((char *) (PARAM+0x100))
86 #define RAMDISK_IMAGE_START_MASK 0x07FF
87 #define RAMDISK_PROMPT_FLAG 0x8000
88 #define RAMDISK_LOAD_FLAG 0x4000
90 static char command_line[COMMAND_LINE_SIZE] = { 0, };
92 struct resource standard_io_resources[] = {
93 { "dma1", 0x00, 0x1f },
94 { "pic1", 0x20, 0x3f },
95 { "timer", 0x40, 0x5f },
96 { "keyboard", 0x60, 0x6f },
97 { "dma page reg", 0x80, 0x8f },
98 { "pic2", 0xa0, 0xbf },
99 { "dma2", 0xc0, 0xdf },
100 { "fpu", 0xf0, 0xff }
103 #define STANDARD_IO_RESOURCES (sizeof(standard_io_resources)/sizeof(struct resource))
105 /* System RAM - interrupted by the 640kB-1M hole */
106 #define code_resource (ram_resources[3])
107 #define data_resource (ram_resources[4])
108 static struct resource ram_resources[] = {
109 { "System RAM", 0x000000, 0x09ffff, IORESOURCE_BUSY },
110 { "System RAM", 0x100000, 0x100000, IORESOURCE_BUSY },
111 { "Video RAM area", 0x0a0000, 0x0bffff },
112 { "Kernel code", 0x100000, 0 },
113 { "Kernel data", 0, 0 }
116 unsigned long memory_start, memory_end;
118 static inline void parse_cmdline (char ** cmdline_p, char mv_name[MV_NAME_SIZE],
119 struct sh_machine_vector** mvp,
120 unsigned long *mv_io_base,
123 char c = ' ', *to = command_line, *from = COMMAND_LINE;
126 /* Save unparsed command line copy for /proc/cmdline */
127 memcpy(saved_command_line, COMMAND_LINE, COMMAND_LINE_SIZE);
128 saved_command_line[COMMAND_LINE_SIZE-1] = '\0';
130 memory_start = (unsigned long)PAGE_OFFSET+__MEMORY_START;
131 memory_end = memory_start + __MEMORY_SIZE;
135 * "mem=XXX[kKmM]" defines a size of memory.
137 if (c == ' ' && !memcmp(from, "mem=", 4)) {
138 if (to != command_line)
141 unsigned long mem_size;
143 mem_size = memparse(from+4, &from);
144 memory_end = memory_start + mem_size;
147 if (c == ' ' && !memcmp(from, "sh_mv=", 6)) {
151 if (to != command_line)
154 mv_end = strchr(from, ' ');
156 mv_end = from + strlen(from);
158 mv_comma = strchr(from, ',');
159 if ((mv_comma != NULL) && (mv_comma < mv_end)) {
161 get_options(mv_comma+1, ARRAY_SIZE(ints), ints);
162 *mv_io_base = ints[1];
163 *mv_mmio_enable = ints[2];
164 mv_len = mv_comma - from;
166 mv_len = mv_end - from;
168 if (mv_len > (MV_NAME_SIZE-1))
169 mv_len = MV_NAME_SIZE-1;
170 memcpy(mv_name, from, mv_len);
171 mv_name[mv_len] = '\0';
174 *mvp = get_mv_byname(mv_name);
179 if (COMMAND_LINE_SIZE <= ++len)
184 *cmdline_p = command_line;
187 static int __init sh_mv_setup(char **cmdline_p)
189 #if defined(CONFIG_SH_UNKNOWN)
190 extern struct sh_machine_vector mv_unknown;
192 struct sh_machine_vector *mv = NULL;
193 char mv_name[MV_NAME_SIZE] = "";
194 unsigned long mv_io_base = 0;
195 int mv_mmio_enable = 0;
197 parse_cmdline(cmdline_p, mv_name, &mv, &mv_io_base, &mv_mmio_enable);
199 #ifdef CONFIG_SH_GENERIC
202 if (*mv_name != '\0') {
203 printk("Warning: Unsupported machine %s, using unknown\n",
209 #ifdef CONFIG_SH_UNKNOWN
214 * Manually walk the vec, fill in anything that the board hasn't yet
215 * by hand, wrapping to the generic implementation.
217 #define mv_set(elem) do { \
218 if (!sh_mv.mv_##elem) \
219 sh_mv.mv_##elem = generic_##elem; \
222 mv_set(inb); mv_set(inw); mv_set(inl);
223 mv_set(outb); mv_set(outw); mv_set(outl);
225 mv_set(inb_p); mv_set(inw_p); mv_set(inl_p);
226 mv_set(outb_p); mv_set(outw_p); mv_set(outl_p);
228 mv_set(insb); mv_set(insw); mv_set(insl);
229 mv_set(outsb); mv_set(outsw); mv_set(outsl);
231 mv_set(readb); mv_set(readw); mv_set(readl);
232 mv_set(writeb); mv_set(writew); mv_set(writel);
237 mv_set(isa_port2addr);
240 #ifdef CONFIG_SH_UNKNOWN
241 __set_io_port_base(mv_io_base);
247 void __init setup_arch(char **cmdline_p)
249 unsigned long bootmap_size;
250 unsigned long start_pfn, max_pfn, max_low_pfn;
252 #ifdef CONFIG_EARLY_PRINTK
253 extern void enable_early_printk(void);
255 enable_early_printk();
257 #ifdef CONFIG_CMDLINE_BOOL
258 strcpy(COMMAND_LINE, CONFIG_CMDLINE);
261 ROOT_DEV = old_decode_dev(ORIG_ROOT_DEV);
263 #ifdef CONFIG_BLK_DEV_RAM
264 rd_image_start = RAMDISK_FLAGS & RAMDISK_IMAGE_START_MASK;
265 rd_prompt = ((RAMDISK_FLAGS & RAMDISK_PROMPT_FLAG) != 0);
266 rd_doload = ((RAMDISK_FLAGS & RAMDISK_LOAD_FLAG) != 0);
269 if (!MOUNT_ROOT_RDONLY)
270 root_mountflags &= ~MS_RDONLY;
271 init_mm.start_code = (unsigned long) _text;
272 init_mm.end_code = (unsigned long) _etext;
273 init_mm.end_data = (unsigned long) _edata;
274 init_mm.brk = (unsigned long) _end;
276 code_resource.start = virt_to_bus(_text);
277 code_resource.end = virt_to_bus(_etext)-1;
278 data_resource.start = virt_to_bus(_etext);
279 data_resource.end = virt_to_bus(_edata)-1;
281 sh_mv_setup(cmdline_p);
283 #define PFN_UP(x) (((x) + PAGE_SIZE-1) >> PAGE_SHIFT)
284 #define PFN_DOWN(x) ((x) >> PAGE_SHIFT)
285 #define PFN_PHYS(x) ((x) << PAGE_SHIFT)
288 * Find the highest page frame number we have available
290 max_pfn = PFN_DOWN(__pa(memory_end));
293 * Determine low and high memory ranges:
295 max_low_pfn = max_pfn;
298 * Partially used pages are not usable - thus
299 * we are rounding upwards:
301 start_pfn = PFN_UP(__pa(_end));
304 * Find a proper area for the bootmem bitmap. After this
305 * bootstrap step all allocations (until the page allocator
306 * is intact) must be done via bootmem_alloc().
308 bootmap_size = init_bootmem_node(NODE_DATA(0), start_pfn,
309 __MEMORY_START>>PAGE_SHIFT,
312 * Register fully available low RAM pages with the bootmem allocator.
315 unsigned long curr_pfn, last_pfn, pages;
318 * We are rounding up the start address of usable memory:
320 curr_pfn = PFN_UP(__MEMORY_START);
322 * ... and at the end of the usable range downwards:
324 last_pfn = PFN_DOWN(__pa(memory_end));
326 if (last_pfn > max_low_pfn)
327 last_pfn = max_low_pfn;
329 pages = last_pfn - curr_pfn;
330 free_bootmem_node(NODE_DATA(0), PFN_PHYS(curr_pfn),
335 * Reserve the kernel text and
336 * Reserve the bootmem bitmap. We do this in two steps (first step
337 * was init_bootmem()), because this catches the (definitely buggy)
338 * case of us accidentally initializing the bootmem allocator with
339 * an invalid RAM area.
341 reserve_bootmem_node(NODE_DATA(0), __MEMORY_START+PAGE_SIZE,
342 (PFN_PHYS(start_pfn)+bootmap_size+PAGE_SIZE-1)-__MEMORY_START);
345 * reserve physical page 0 - it's a special BIOS page on many boxes,
346 * enabling clean reboots, SMP operation, laptop functions.
348 reserve_bootmem_node(NODE_DATA(0), __MEMORY_START, PAGE_SIZE);
350 #ifdef CONFIG_BLK_DEV_INITRD
351 ROOT_DEV = MKDEV(RAMDISK_MAJOR, 0);
352 if (&__rd_start != &__rd_end) {
354 INITRD_START = PHYSADDR((unsigned long)&__rd_start) - __MEMORY_START;
355 INITRD_SIZE = (unsigned long)&__rd_end - (unsigned long)&__rd_start;
358 if (LOADER_TYPE && INITRD_START) {
359 if (INITRD_START + INITRD_SIZE <= (max_low_pfn << PAGE_SHIFT)) {
360 reserve_bootmem_node(NODE_DATA(0), INITRD_START+__MEMORY_START, INITRD_SIZE);
362 INITRD_START ? INITRD_START + PAGE_OFFSET + __MEMORY_START : 0;
363 initrd_end = initrd_start + INITRD_SIZE;
365 printk("initrd extends beyond end of memory "
366 "(0x%08lx > 0x%08lx)\ndisabling initrd\n",
367 INITRD_START + INITRD_SIZE,
368 max_low_pfn << PAGE_SHIFT);
374 #ifdef CONFIG_DUMMY_CONSOLE
375 conswitchp = &dummy_con;
378 /* Perform the machine specific initialisation */
384 struct sh_machine_vector* __init get_mv_byname(const char* name)
386 extern int strcasecmp(const char *, const char *);
387 extern long __machvec_start, __machvec_end;
388 struct sh_machine_vector *all_vecs =
389 (struct sh_machine_vector *)&__machvec_start;
391 int i, n = ((unsigned long)&__machvec_end
392 - (unsigned long)&__machvec_start)/
393 sizeof(struct sh_machine_vector);
395 for (i = 0; i < n; ++i) {
396 struct sh_machine_vector *mv = &all_vecs[i];
399 if (strcasecmp(name, get_system_type()) == 0) {
406 static struct cpu cpu[NR_CPUS];
408 static int __init topology_init(void)
412 for (cpu_id = 0; cpu_id < NR_CPUS; cpu_id++)
413 if (cpu_possible(cpu_id))
414 register_cpu(&cpu[cpu_id], cpu_id, NULL);
419 subsys_initcall(topology_init);
421 static const char *cpu_name[] = {
422 [CPU_SH7604] = "SH7604",
423 [CPU_SH7705] = "SH7705",
424 [CPU_SH7708] = "SH7708",
425 [CPU_SH7729] = "SH7729",
426 [CPU_SH7300] = "SH7300",
427 [CPU_SH7750] = "SH7750",
428 [CPU_SH7750S] = "SH7750S",
429 [CPU_SH7750R] = "SH7750R",
430 [CPU_SH7751] = "SH7751",
431 [CPU_SH7751R] = "SH7751R",
432 [CPU_SH7760] = "SH7760",
433 [CPU_SH73180] = "SH73180",
434 [CPU_ST40RA] = "ST40RA",
435 [CPU_ST40GX1] = "ST40GX1",
436 [CPU_SH4_202] = "SH4-202",
437 [CPU_SH4_501] = "SH4-501",
438 [CPU_SH_NONE] = "Unknown"
441 const char *get_cpu_subtype(void)
443 return cpu_name[boot_cpu_data.type];
446 #ifdef CONFIG_PROC_FS
447 static const char *cpu_flags[] = {
448 "none", "fpu", "p2flush", "mmuassoc", "dsp", "perfctr",
451 static void show_cpuflags(struct seq_file *m)
455 seq_printf(m, "cpu flags\t:");
457 if (!cpu_data->flags) {
458 seq_printf(m, " %s\n", cpu_flags[0]);
462 for (i = 0; i < cpu_data->flags; i++)
463 if ((cpu_data->flags & (1 << i)))
464 seq_printf(m, " %s", cpu_flags[i+1]);
469 static void show_cacheinfo(struct seq_file *m, const char *type, struct cache_info info)
471 unsigned int cache_size;
473 cache_size = info.ways * info.sets * info.linesz;
475 seq_printf(m, "%s size\t: %dKiB\n", type, cache_size >> 10);
479 * Get CPU information for use by the procfs.
481 static int show_cpuinfo(struct seq_file *m, void *v)
483 unsigned int cpu = smp_processor_id();
485 if (!cpu && cpu_online(cpu))
486 seq_printf(m, "machine\t\t: %s\n", get_system_type());
488 seq_printf(m, "processor\t: %d\n", cpu);
489 seq_printf(m, "cpu family\t: %s\n", system_utsname.machine);
490 seq_printf(m, "cpu type\t: %s\n", get_cpu_subtype());
494 seq_printf(m, "cache type\t: ");
497 * Check for what type of cache we have, we support both the
498 * unified cache on the SH-2 and SH-3, as well as the harvard
499 * style cache on the SH-4.
501 if (test_bit(SH_CACHE_COMBINED, &(boot_cpu_data.icache.flags))) {
502 seq_printf(m, "unified\n");
503 show_cacheinfo(m, "cache", boot_cpu_data.icache);
505 seq_printf(m, "split (harvard)\n");
506 show_cacheinfo(m, "icache", boot_cpu_data.icache);
507 show_cacheinfo(m, "dcache", boot_cpu_data.dcache);
510 seq_printf(m, "bogomips\t: %lu.%02lu\n",
511 boot_cpu_data.loops_per_jiffy/(500000/HZ),
512 (boot_cpu_data.loops_per_jiffy/(5000/HZ)) % 100);
514 #define PRINT_CLOCK(name, value) \
515 seq_printf(m, name " clock\t: %d.%02dMHz\n", \
516 ((value) / 1000000), ((value) % 1000000)/10000)
518 PRINT_CLOCK("cpu", boot_cpu_data.cpu_clock);
519 PRINT_CLOCK("bus", boot_cpu_data.bus_clock);
520 #ifdef CONFIG_CPU_SUBTYPE_ST40STB1
521 PRINT_CLOCK("memory", boot_cpu_data.memory_clock);
523 PRINT_CLOCK("module", boot_cpu_data.module_clock);
529 static void *c_start(struct seq_file *m, loff_t *pos)
531 return *pos < NR_CPUS ? cpu_data + *pos : NULL;
533 static void *c_next(struct seq_file *m, void *v, loff_t *pos)
536 return c_start(m, pos);
538 static void c_stop(struct seq_file *m, void *v)
541 struct seq_operations cpuinfo_op = {
545 .show = show_cpuinfo,
547 #endif /* CONFIG_PROC_FS */
549 #ifdef CONFIG_SH_KGDB
551 * Parse command-line kgdb options. By default KGDB is enabled,
552 * entered on error (or other action) using default serial info.
553 * The command-line option can include a serial port specification
554 * and an action to override default or configured behavior.
556 struct kgdb_sermap kgdb_sci_sermap =
557 { "ttySC", 5, kgdb_sci_setup, NULL };
559 struct kgdb_sermap *kgdb_serlist = &kgdb_sci_sermap;
560 struct kgdb_sermap *kgdb_porttype = &kgdb_sci_sermap;
562 void kgdb_register_sermap(struct kgdb_sermap *map)
564 struct kgdb_sermap *last;
566 for (last = kgdb_serlist; last->next; last = last->next)
570 map->namelen = strlen(map->name);
574 static int __init kgdb_parse_options(char *options)
579 /* Check for port spec (or use default) */
581 /* Determine port type and instance */
582 if (!memcmp(options, "tty", 3)) {
583 struct kgdb_sermap *map = kgdb_serlist;
585 while (map && memcmp(options, map->name, map->namelen))
589 KGDB_PRINTK("unknown port spec in %s\n", options);
594 kgdb_serial_setup = map->setup_fn;
595 kgdb_portnum = options[map->namelen] - '0';
596 options += map->namelen + 1;
598 options = (*options == ',') ? options+1 : options;
600 /* Read optional parameters (baud/parity/bits) */
601 baud = simple_strtoul(options, &options, 10);
605 c = toupper(*options);
606 if (c == 'E' || c == 'O' || c == 'N') {
612 if (c == '7' || c == '8') {
616 options = (*options == ',') ? options+1 : options;
620 /* Check for action specification */
621 if (!memcmp(options, "halt", 4)) {
624 } else if (!memcmp(options, "disabled", 8)) {
630 KGDB_PRINTK("ignored unknown options: %s\n", options);
635 __setup("kgdb=", kgdb_parse_options);
636 #endif /* CONFIG_SH_KGDB */