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