MOXA linux-2.6.x / linux-2.6.19-uc1 from UC-7110-LX-BOOTLOADER-1.9_VERSION-4.2.tgz
[linux-2.6.19-moxart.git] / arch / sh / kernel / setup.c
bloba051b060f234b30a85e612c4aaea5cae55bedc39
1 /*
2 * linux/arch/sh/kernel/setup.c
4 * Copyright (C) 1999 Niibe Yutaka
5 * Copyright (C) 2002, 2003 Paul Mundt
6 */
8 /*
9 * This file handles the architecture-dependent parts of initialization
12 #include <linux/screen_info.h>
13 #include <linux/ioport.h>
14 #include <linux/init.h>
15 #include <linux/initrd.h>
16 #include <linux/console.h>
17 #include <linux/seq_file.h>
18 #include <linux/root_dev.h>
19 #include <linux/utsname.h>
20 #include <linux/cpu.h>
21 #include <linux/pfn.h>
22 #include <linux/fs.h>
23 #include <linux/bootmem.h>
24 #include <asm/uaccess.h>
25 #include <asm/io.h>
26 #include <asm/sections.h>
27 #include <asm/irq.h>
28 #include <asm/setup.h>
29 #include <asm/clock.h>
31 #ifdef CONFIG_SH_KGDB
32 #include <asm/kgdb.h>
33 static int kgdb_parse_options(char *options);
34 #endif
35 extern void * __rd_start, * __rd_end;
37 * Machine setup..
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.
45 struct sh_cpuinfo boot_cpu_data = { CPU_SH_NONE, 10000000, };
46 #ifdef CONFIG_VT
47 struct screen_info screen_info;
48 #endif
50 #if defined(CONFIG_SH_UNKNOWN)
51 struct sh_machine_vector sh_mv;
52 #endif
54 extern int root_mountflags;
56 #define MV_NAME_SIZE 32
58 static struct sh_machine_vector* __init get_mv_byname(const char* name);
61 * This is set up by the setup-routine at boot-time
63 #define PARAM ((unsigned char *)empty_zero_page)
65 #define MOUNT_ROOT_RDONLY (*(unsigned long *) (PARAM+0x000))
66 #define RAMDISK_FLAGS (*(unsigned long *) (PARAM+0x004))
67 #define ORIG_ROOT_DEV (*(unsigned long *) (PARAM+0x008))
68 #define LOADER_TYPE (*(unsigned long *) (PARAM+0x00c))
69 #define INITRD_START (*(unsigned long *) (PARAM+0x010))
70 #define INITRD_SIZE (*(unsigned long *) (PARAM+0x014))
71 /* ... */
72 #define COMMAND_LINE ((char *) (PARAM+0x100))
74 #define RAMDISK_IMAGE_START_MASK 0x07FF
75 #define RAMDISK_PROMPT_FLAG 0x8000
76 #define RAMDISK_LOAD_FLAG 0x4000
78 static char command_line[COMMAND_LINE_SIZE] = { 0, };
80 static struct resource code_resource = { .name = "Kernel code", };
81 static struct resource data_resource = { .name = "Kernel data", };
83 unsigned long memory_start, memory_end;
85 static inline void parse_cmdline (char ** cmdline_p, char mv_name[MV_NAME_SIZE],
86 struct sh_machine_vector** mvp,
87 unsigned long *mv_io_base,
88 int *mv_mmio_enable)
90 char c = ' ', *to = command_line, *from = COMMAND_LINE;
91 int len = 0;
93 /* Save unparsed command line copy for /proc/cmdline */
94 memcpy(saved_command_line, COMMAND_LINE, COMMAND_LINE_SIZE);
95 saved_command_line[COMMAND_LINE_SIZE-1] = '\0';
97 memory_start = (unsigned long)PAGE_OFFSET+__MEMORY_START;
98 memory_end = memory_start + __MEMORY_SIZE;
100 for (;;) {
102 * "mem=XXX[kKmM]" defines a size of memory.
104 if (c == ' ' && !memcmp(from, "mem=", 4)) {
105 if (to != command_line)
106 to--;
108 unsigned long mem_size;
110 mem_size = memparse(from+4, &from);
111 memory_end = memory_start + mem_size;
115 #ifdef CONFIG_EARLY_PRINTK
116 if (c == ' ' && !memcmp(from, "earlyprintk=", 12)) {
117 char *ep_end;
119 if (to != command_line)
120 to--;
122 from += 12;
123 ep_end = strchr(from, ' ');
125 setup_early_printk(from);
126 printk("early console enabled\n");
128 from = ep_end;
130 #endif
132 if (c == ' ' && !memcmp(from, "sh_mv=", 6)) {
133 char* mv_end;
134 char* mv_comma;
135 int mv_len;
136 if (to != command_line)
137 to--;
138 from += 6;
139 mv_end = strchr(from, ' ');
140 if (mv_end == NULL)
141 mv_end = from + strlen(from);
143 mv_comma = strchr(from, ',');
144 if ((mv_comma != NULL) && (mv_comma < mv_end)) {
145 int ints[3];
146 get_options(mv_comma+1, ARRAY_SIZE(ints), ints);
147 *mv_io_base = ints[1];
148 *mv_mmio_enable = ints[2];
149 mv_len = mv_comma - from;
150 } else {
151 mv_len = mv_end - from;
153 if (mv_len > (MV_NAME_SIZE-1))
154 mv_len = MV_NAME_SIZE-1;
155 memcpy(mv_name, from, mv_len);
156 mv_name[mv_len] = '\0';
157 from = mv_end;
159 *mvp = get_mv_byname(mv_name);
161 c = *(from++);
162 if (!c)
163 break;
164 if (COMMAND_LINE_SIZE <= ++len)
165 break;
166 *(to++) = c;
168 *to = '\0';
169 *cmdline_p = command_line;
172 static int __init sh_mv_setup(char **cmdline_p)
174 #ifdef CONFIG_SH_UNKNOWN
175 extern struct sh_machine_vector mv_unknown;
176 #endif
177 struct sh_machine_vector *mv = NULL;
178 char mv_name[MV_NAME_SIZE] = "";
179 unsigned long mv_io_base = 0;
180 int mv_mmio_enable = 0;
182 parse_cmdline(cmdline_p, mv_name, &mv, &mv_io_base, &mv_mmio_enable);
184 #ifdef CONFIG_SH_UNKNOWN
185 if (mv == NULL) {
186 mv = &mv_unknown;
187 if (*mv_name != '\0') {
188 printk("Warning: Unsupported machine %s, using unknown\n",
189 mv_name);
192 sh_mv = *mv;
193 #endif
196 * Manually walk the vec, fill in anything that the board hasn't yet
197 * by hand, wrapping to the generic implementation.
199 #define mv_set(elem) do { \
200 if (!sh_mv.mv_##elem) \
201 sh_mv.mv_##elem = generic_##elem; \
202 } while (0)
204 mv_set(inb); mv_set(inw); mv_set(inl);
205 mv_set(outb); mv_set(outw); mv_set(outl);
207 mv_set(inb_p); mv_set(inw_p); mv_set(inl_p);
208 mv_set(outb_p); mv_set(outw_p); mv_set(outl_p);
210 mv_set(insb); mv_set(insw); mv_set(insl);
211 mv_set(outsb); mv_set(outsw); mv_set(outsl);
213 mv_set(readb); mv_set(readw); mv_set(readl);
214 mv_set(writeb); mv_set(writew); mv_set(writel);
216 mv_set(ioport_map);
217 mv_set(ioport_unmap);
218 mv_set(irq_demux);
220 #ifdef CONFIG_SH_UNKNOWN
221 __set_io_port_base(mv_io_base);
222 #endif
224 if (!sh_mv.mv_nr_irqs)
225 sh_mv.mv_nr_irqs = NR_IRQS;
227 return 0;
230 void __init setup_arch(char **cmdline_p)
232 unsigned long bootmap_size;
233 unsigned long start_pfn, max_pfn, max_low_pfn;
235 #ifdef CONFIG_CMDLINE_BOOL
236 strcpy(COMMAND_LINE, CONFIG_CMDLINE);
237 #endif
239 ROOT_DEV = old_decode_dev(ORIG_ROOT_DEV);
241 #ifdef CONFIG_BLK_DEV_RAM
242 rd_image_start = RAMDISK_FLAGS & RAMDISK_IMAGE_START_MASK;
243 rd_prompt = ((RAMDISK_FLAGS & RAMDISK_PROMPT_FLAG) != 0);
244 rd_doload = ((RAMDISK_FLAGS & RAMDISK_LOAD_FLAG) != 0);
245 #endif
247 if (!MOUNT_ROOT_RDONLY)
248 root_mountflags &= ~MS_RDONLY;
249 init_mm.start_code = (unsigned long) _text;
250 init_mm.end_code = (unsigned long) _etext;
251 init_mm.end_data = (unsigned long) _edata;
252 init_mm.brk = (unsigned long) _end;
254 code_resource.start = (unsigned long)virt_to_phys(_text);
255 code_resource.end = (unsigned long)virt_to_phys(_etext)-1;
256 data_resource.start = (unsigned long)virt_to_phys(_etext);
257 data_resource.end = (unsigned long)virt_to_phys(_edata)-1;
259 sh_mv_setup(cmdline_p);
262 * Find the highest page frame number we have available
264 max_pfn = PFN_DOWN(__pa(memory_end));
267 * Determine low and high memory ranges:
269 max_low_pfn = max_pfn;
272 * Partially used pages are not usable - thus
273 * we are rounding upwards:
275 #if defined(CONFIG_BLK_DEV_INITRD) || defined(CONFIG_SH_CONCAT_FS)
276 if (INITRD_START == __pa(_end))
277 start_pfn = PFN_UP(__pa(_end) + INITRD_SIZE);
278 else
279 #endif
280 start_pfn = PFN_UP(__pa(_end));
283 * Find a proper area for the bootmem bitmap. After this
284 * bootstrap step all allocations (until the page allocator
285 * is intact) must be done via bootmem_alloc().
287 bootmap_size = init_bootmem_node(NODE_DATA(0), start_pfn,
288 __MEMORY_START>>PAGE_SHIFT,
289 max_low_pfn);
291 * Register fully available low RAM pages with the bootmem allocator.
294 unsigned long curr_pfn, last_pfn, pages;
297 * We are rounding up the start address of usable memory:
299 curr_pfn = PFN_UP(__MEMORY_START);
301 * ... and at the end of the usable range downwards:
303 last_pfn = PFN_DOWN(__pa(memory_end));
305 if (last_pfn > max_low_pfn)
306 last_pfn = max_low_pfn;
308 pages = last_pfn - curr_pfn;
309 free_bootmem_node(NODE_DATA(0), PFN_PHYS(curr_pfn),
310 PFN_PHYS(pages));
314 * Reserve the kernel text and
315 * Reserve the bootmem bitmap. We do this in two steps (first step
316 * was init_bootmem()), because this catches the (definitely buggy)
317 * case of us accidentally initializing the bootmem allocator with
318 * an invalid RAM area.
320 reserve_bootmem_node(NODE_DATA(0), __MEMORY_START+PAGE_SIZE,
321 (PFN_PHYS(start_pfn)+bootmap_size+PAGE_SIZE-1)-__MEMORY_START);
324 * reserve physical page 0 - it's a special BIOS page on many boxes,
325 * enabling clean reboots, SMP operation, laptop functions.
327 reserve_bootmem_node(NODE_DATA(0), __MEMORY_START, PAGE_SIZE);
329 #ifdef CONFIG_BLK_DEV_INITRD
330 ROOT_DEV = MKDEV(RAMDISK_MAJOR, 0);
331 if (&__rd_start != &__rd_end) {
332 LOADER_TYPE = 1;
333 INITRD_START = PHYSADDR((unsigned long)&__rd_start) - __MEMORY_START;
334 INITRD_SIZE = (unsigned long)&__rd_end - (unsigned long)&__rd_start;
337 if (LOADER_TYPE && INITRD_START) {
338 if (INITRD_START + INITRD_SIZE <= (max_low_pfn << PAGE_SHIFT)) {
339 if (INITRD_START == __pa(_end))
340 initrd_start = INITRD_START + PAGE_OFFSET;
341 else {
342 reserve_bootmem_node(NODE_DATA(0), INITRD_START+__MEMORY_START, INITRD_SIZE);
343 initrd_start =
344 INITRD_START ? INITRD_START + PAGE_OFFSET + __MEMORY_START : 0;
346 initrd_end = initrd_start + INITRD_SIZE;
347 } else {
348 printk("initrd extends beyond end of memory "
349 "(0x%08lx > 0x%08lx)\ndisabling initrd\n",
350 INITRD_START + INITRD_SIZE,
351 max_low_pfn << PAGE_SHIFT);
352 initrd_start = 0;
355 #endif
357 #ifdef CONFIG_DUMMY_CONSOLE
358 conswitchp = &dummy_con;
359 #endif
361 /* Perform the machine specific initialisation */
362 if (likely(sh_mv.mv_setup))
363 sh_mv.mv_setup(cmdline_p);
365 paging_init();
368 struct sh_machine_vector* __init get_mv_byname(const char* name)
370 extern long __machvec_start, __machvec_end;
371 struct sh_machine_vector *all_vecs =
372 (struct sh_machine_vector *)&__machvec_start;
374 int i, n = ((unsigned long)&__machvec_end
375 - (unsigned long)&__machvec_start)/
376 sizeof(struct sh_machine_vector);
378 for (i = 0; i < n; ++i) {
379 struct sh_machine_vector *mv = &all_vecs[i];
380 if (mv == NULL)
381 continue;
382 if (strcasecmp(name, get_system_type()) == 0) {
383 return mv;
386 return NULL;
389 static struct cpu cpu[NR_CPUS];
391 static int __init topology_init(void)
393 int cpu_id;
395 for_each_possible_cpu(cpu_id)
396 register_cpu(&cpu[cpu_id], cpu_id);
398 return 0;
401 subsys_initcall(topology_init);
403 static const char *cpu_name[] = {
404 [CPU_SH7604] = "SH7604", [CPU_SH7300] = "SH7300",
405 [CPU_SH7705] = "SH7705", [CPU_SH7706] = "SH7706",
406 [CPU_SH7707] = "SH7707", [CPU_SH7708] = "SH7708",
407 [CPU_SH7709] = "SH7709", [CPU_SH7710] = "SH7710",
408 [CPU_SH7729] = "SH7729", [CPU_SH7750] = "SH7750",
409 [CPU_SH7750S] = "SH7750S", [CPU_SH7750R] = "SH7750R",
410 [CPU_SH7751] = "SH7751", [CPU_SH7751R] = "SH7751R",
411 [CPU_SH7760] = "SH7760", [CPU_SH73180] = "SH73180",
412 [CPU_ST40RA] = "ST40RA", [CPU_ST40GX1] = "ST40GX1",
413 [CPU_SH4_202] = "SH4-202", [CPU_SH4_501] = "SH4-501",
414 [CPU_SH7770] = "SH7770", [CPU_SH7780] = "SH7780",
415 [CPU_SH7781] = "SH7781", [CPU_SH7343] = "SH7343",
416 [CPU_SH_NONE] = "Unknown"
419 const char *get_cpu_subtype(void)
421 return cpu_name[boot_cpu_data.type];
424 #ifdef CONFIG_PROC_FS
425 /* Symbolic CPU flags, keep in sync with asm/cpu-features.h */
426 static const char *cpu_flags[] = {
427 "none", "fpu", "p2flush", "mmuassoc", "dsp", "perfctr",
428 "ptea", "llsc", "l2", NULL
431 static void show_cpuflags(struct seq_file *m)
433 unsigned long i;
435 seq_printf(m, "cpu flags\t:");
437 if (!cpu_data->flags) {
438 seq_printf(m, " %s\n", cpu_flags[0]);
439 return;
442 for (i = 0; cpu_flags[i]; i++)
443 if ((cpu_data->flags & (1 << i)))
444 seq_printf(m, " %s", cpu_flags[i+1]);
446 seq_printf(m, "\n");
449 static void show_cacheinfo(struct seq_file *m, const char *type,
450 struct cache_info info)
452 unsigned int cache_size;
454 cache_size = info.ways * info.sets * info.linesz;
456 seq_printf(m, "%s size\t: %2dKiB (%d-way)\n",
457 type, cache_size >> 10, info.ways);
461 * Get CPU information for use by the procfs.
463 static int show_cpuinfo(struct seq_file *m, void *v)
465 unsigned int cpu = smp_processor_id();
467 if (!cpu && cpu_online(cpu))
468 seq_printf(m, "machine\t\t: %s\n", get_system_type());
470 seq_printf(m, "processor\t: %d\n", cpu);
471 seq_printf(m, "cpu family\t: %s\n", init_utsname()->machine);
472 seq_printf(m, "cpu type\t: %s\n", get_cpu_subtype());
474 show_cpuflags(m);
476 seq_printf(m, "cache type\t: ");
479 * Check for what type of cache we have, we support both the
480 * unified cache on the SH-2 and SH-3, as well as the harvard
481 * style cache on the SH-4.
483 if (boot_cpu_data.icache.flags & SH_CACHE_COMBINED) {
484 seq_printf(m, "unified\n");
485 show_cacheinfo(m, "cache", boot_cpu_data.icache);
486 } else {
487 seq_printf(m, "split (harvard)\n");
488 show_cacheinfo(m, "icache", boot_cpu_data.icache);
489 show_cacheinfo(m, "dcache", boot_cpu_data.dcache);
492 /* Optional secondary cache */
493 if (boot_cpu_data.flags & CPU_HAS_L2_CACHE)
494 show_cacheinfo(m, "scache", boot_cpu_data.scache);
496 seq_printf(m, "bogomips\t: %lu.%02lu\n",
497 boot_cpu_data.loops_per_jiffy/(500000/HZ),
498 (boot_cpu_data.loops_per_jiffy/(5000/HZ)) % 100);
500 return show_clocks(m);
503 static void *c_start(struct seq_file *m, loff_t *pos)
505 return *pos < NR_CPUS ? cpu_data + *pos : NULL;
507 static void *c_next(struct seq_file *m, void *v, loff_t *pos)
509 ++*pos;
510 return c_start(m, pos);
512 static void c_stop(struct seq_file *m, void *v)
515 struct seq_operations cpuinfo_op = {
516 .start = c_start,
517 .next = c_next,
518 .stop = c_stop,
519 .show = show_cpuinfo,
521 #endif /* CONFIG_PROC_FS */
523 #ifdef CONFIG_SH_KGDB
525 * Parse command-line kgdb options. By default KGDB is enabled,
526 * entered on error (or other action) using default serial info.
527 * The command-line option can include a serial port specification
528 * and an action to override default or configured behavior.
530 struct kgdb_sermap kgdb_sci_sermap =
531 { "ttySC", 5, kgdb_sci_setup, NULL };
533 struct kgdb_sermap *kgdb_serlist = &kgdb_sci_sermap;
534 struct kgdb_sermap *kgdb_porttype = &kgdb_sci_sermap;
536 void kgdb_register_sermap(struct kgdb_sermap *map)
538 struct kgdb_sermap *last;
540 for (last = kgdb_serlist; last->next; last = last->next)
542 last->next = map;
543 if (!map->namelen) {
544 map->namelen = strlen(map->name);
548 static int __init kgdb_parse_options(char *options)
550 char c;
551 int baud;
553 /* Check for port spec (or use default) */
555 /* Determine port type and instance */
556 if (!memcmp(options, "tty", 3)) {
557 struct kgdb_sermap *map = kgdb_serlist;
559 while (map && memcmp(options, map->name, map->namelen))
560 map = map->next;
562 if (!map) {
563 KGDB_PRINTK("unknown port spec in %s\n", options);
564 return -1;
567 kgdb_porttype = map;
568 kgdb_serial_setup = map->setup_fn;
569 kgdb_portnum = options[map->namelen] - '0';
570 options += map->namelen + 1;
572 options = (*options == ',') ? options+1 : options;
574 /* Read optional parameters (baud/parity/bits) */
575 baud = simple_strtoul(options, &options, 10);
576 if (baud != 0) {
577 kgdb_baud = baud;
579 c = toupper(*options);
580 if (c == 'E' || c == 'O' || c == 'N') {
581 kgdb_parity = c;
582 options++;
585 c = *options;
586 if (c == '7' || c == '8') {
587 kgdb_bits = c;
588 options++;
590 options = (*options == ',') ? options+1 : options;
594 /* Check for action specification */
595 if (!memcmp(options, "halt", 4)) {
596 kgdb_halt = 1;
597 options += 4;
598 } else if (!memcmp(options, "disabled", 8)) {
599 kgdb_enabled = 0;
600 options += 8;
603 if (*options) {
604 KGDB_PRINTK("ignored unknown options: %s\n", options);
605 return 0;
607 return 1;
609 __setup("kgdb=", kgdb_parse_options);
610 #endif /* CONFIG_SH_KGDB */
612 #if defined(CONFIG_SH_CONCAT_FS)
614 * do not call printk in here, bad things will happen, the kernel isn't
615 * actually up yet, we are called from head.S before BSS is cleared.
618 extern void copy_romfs(void);
619 void copy_romfs()
621 #ifdef CONFIG_SH_SECUREEDGE5410
622 volatile char dummy;
623 #define SERVICE_WATCHDOG() (dummy = * (volatile char *) 0xb8000000)
624 #else
625 #define SERVICE_WATCHDOG()
626 #endif
627 unsigned char *sp, *dp;
628 unsigned long len;
630 * we used to use __bss_start, but that is padded to 4K now and doesn't
631 * work, basically we need the last non-padded symbol before __bss_start
632 * and that is now __machvec_end
634 extern long __machvec_end;
635 #define CURRENT_ROMFS_LOC ((unsigned long)(&__machvec_end))
636 #ifdef CONFIG_SH_ROMBOOT
637 extern int _mem_start, _rom_store;
638 sp = (unsigned char *) CURRENT_ROMFS_LOC - ((_mem_start - _rom_store) / 4);
639 #else
640 sp = (unsigned char *) CURRENT_ROMFS_LOC;
641 #endif
642 dp = (unsigned char *) &_end[0];
644 if (memcmp(&sp[0], "-rom1fs-", 8) == 0) {
645 /* romfs */
646 memcpy(&len, sp, sizeof(len));
647 len = be32_to_cpu(len);
648 } else if (sp[0]==0x45 && sp[1]==0x3d && sp[2]==0xcd && sp[3]==0x28) {
649 /* cramfs */
650 memcpy(&len, &sp[4], sizeof(len));
651 } else {
652 *dp = 0; /* make sure we don't see an old FS there */
653 return;
656 len = (len + 0xfff) & ~0xfff; /* make it a multiple of a page */
657 LOADER_TYPE = 0;
658 INITRD_SIZE = len;
659 INITRD_START = __pa(_end);
661 sp += len;
662 dp += len;
664 /* copy backwards to avoid writing over ourselves */
665 SERVICE_WATCHDOG();
666 while (dp >= ((unsigned char *) (&_end[0]))) {
667 *dp-- = *sp--;
668 if ((((unsigned long) dp) & 0x7ffff) == 0)
669 SERVICE_WATCHDOG();
671 SERVICE_WATCHDOG();
673 #endif