vserver 1.9.3
[linux-2.6.git] / arch / s390 / kernel / setup.c
1 /*
2  *  arch/s390/kernel/setup.c
3  *
4  *  S390 version
5  *    Copyright (C) 1999,2000 IBM Deutschland Entwicklung GmbH, IBM Corporation
6  *    Author(s): Hartmut Penner (hp@de.ibm.com),
7  *               Martin Schwidefsky (schwidefsky@de.ibm.com)
8  *
9  *  Derived from "arch/i386/kernel/setup.c"
10  *    Copyright (C) 1995, Linus Torvalds
11  */
12
13 /*
14  * This file handles the architecture-dependent parts of initialization
15  */
16
17 #include <linux/errno.h>
18 #include <linux/module.h>
19 #include <linux/sched.h>
20 #include <linux/kernel.h>
21 #include <linux/mm.h>
22 #include <linux/stddef.h>
23 #include <linux/unistd.h>
24 #include <linux/ptrace.h>
25 #include <linux/slab.h>
26 #include <linux/user.h>
27 #include <linux/a.out.h>
28 #include <linux/tty.h>
29 #include <linux/ioport.h>
30 #include <linux/delay.h>
31 #include <linux/config.h>
32 #include <linux/init.h>
33 #include <linux/initrd.h>
34 #include <linux/bootmem.h>
35 #include <linux/root_dev.h>
36 #include <linux/console.h>
37 #include <linux/seq_file.h>
38 #include <linux/kernel_stat.h>
39
40 #include <asm/uaccess.h>
41 #include <asm/system.h>
42 #include <asm/smp.h>
43 #include <asm/mmu_context.h>
44 #include <asm/cpcmd.h>
45 #include <asm/lowcore.h>
46 #include <asm/irq.h>
47
48 /*
49  * Machine setup..
50  */
51 unsigned int console_mode = 0;
52 unsigned int console_devno = -1;
53 unsigned int console_irq = -1;
54 unsigned long memory_size = 0;
55 unsigned long machine_flags = 0;
56 unsigned int default_storage_key = 0;
57 struct {
58         unsigned long addr, size, type;
59 } memory_chunk[MEMORY_CHUNKS] = { { 0 } };
60 #define CHUNK_READ_WRITE 0
61 #define CHUNK_READ_ONLY 1
62 volatile int __cpu_logical_map[NR_CPUS]; /* logical cpu to cpu address */
63
64 /*
65  * Setup options
66  */
67 extern int _text,_etext, _edata, _end;
68
69 /*
70  * This is set up by the setup-routine at boot-time
71  * for S390 need to find out, what we have to setup
72  * using address 0x10400 ...
73  */
74
75 #include <asm/setup.h>
76
77 static char command_line[COMMAND_LINE_SIZE] = { 0, };
78
79 static struct resource code_resource = { "Kernel code", 0x100000, 0 };
80 static struct resource data_resource = { "Kernel data", 0, 0 };
81
82 /*
83  * cpu_init() initializes state that is per-CPU.
84  */
85 void __devinit cpu_init (void)
86 {
87         int addr = hard_smp_processor_id();
88
89         /*
90          * Store processor id in lowcore (used e.g. in timer_interrupt)
91          */
92         asm volatile ("stidp %0": "=m" (S390_lowcore.cpu_data.cpu_id));
93         S390_lowcore.cpu_data.cpu_addr = addr;
94
95         /*
96          * Force FPU initialization:
97          */
98         clear_thread_flag(TIF_USEDFPU);
99         current->used_math = 0;
100
101         /* Setup active_mm for idle_task  */
102         atomic_inc(&init_mm.mm_count);
103         current->active_mm = &init_mm;
104         if (current->mm)
105                 BUG();
106         enter_lazy_tlb(&init_mm, current);
107 }
108
109 /*
110  * VM halt and poweroff setup routines
111  */
112 char vmhalt_cmd[128] = "";
113 char vmpoff_cmd[128] = "";
114
115 static inline void strncpy_skip_quote(char *dst, char *src, int n)
116 {
117         int sx, dx;
118
119         dx = 0;
120         for (sx = 0; src[sx] != 0; sx++) {
121                 if (src[sx] == '"') continue;
122                 dst[dx++] = src[sx];
123                 if (dx >= n) break;
124         }
125 }
126
127 static int __init vmhalt_setup(char *str)
128 {
129         strncpy_skip_quote(vmhalt_cmd, str, 127);
130         vmhalt_cmd[127] = 0;
131         return 1;
132 }
133
134 __setup("vmhalt=", vmhalt_setup);
135
136 static int __init vmpoff_setup(char *str)
137 {
138         strncpy_skip_quote(vmpoff_cmd, str, 127);
139         vmpoff_cmd[127] = 0;
140         return 1;
141 }
142
143 __setup("vmpoff=", vmpoff_setup);
144
145 /*
146  * condev= and conmode= setup parameter.
147  */
148
149 static int __init condev_setup(char *str)
150 {
151         int vdev;
152
153         vdev = simple_strtoul(str, &str, 0);
154         if (vdev >= 0 && vdev < 65536) {
155                 console_devno = vdev;
156                 console_irq = -1;
157         }
158         return 1;
159 }
160
161 __setup("condev=", condev_setup);
162
163 static int __init conmode_setup(char *str)
164 {
165 #if defined(CONFIG_SCLP_CONSOLE)
166         if (strncmp(str, "hwc", 4) == 0 || strncmp(str, "sclp", 5) == 0)
167                 SET_CONSOLE_SCLP;
168 #endif
169 #if defined(CONFIG_TN3215_CONSOLE)
170         if (strncmp(str, "3215", 5) == 0)
171                 SET_CONSOLE_3215;
172 #endif
173 #if defined(CONFIG_TN3270_CONSOLE)
174         if (strncmp(str, "3270", 5) == 0)
175                 SET_CONSOLE_3270;
176 #endif
177         return 1;
178 }
179
180 __setup("conmode=", conmode_setup);
181
182 static void __init conmode_default(void)
183 {
184         char query_buffer[1024];
185         char *ptr;
186
187         if (MACHINE_IS_VM) {
188                 cpcmd("QUERY CONSOLE", query_buffer, 1024);
189                 console_devno = simple_strtoul(query_buffer + 5, NULL, 16);
190                 ptr = strstr(query_buffer, "SUBCHANNEL =");
191                 console_irq = simple_strtoul(ptr + 13, NULL, 16);
192                 cpcmd("QUERY TERM", query_buffer, 1024);
193                 ptr = strstr(query_buffer, "CONMODE");
194                 /*
195                  * Set the conmode to 3215 so that the device recognition 
196                  * will set the cu_type of the console to 3215. If the
197                  * conmode is 3270 and we don't set it back then both
198                  * 3215 and the 3270 driver will try to access the console
199                  * device (3215 as console and 3270 as normal tty).
200                  */
201                 cpcmd("TERM CONMODE 3215", NULL, 0);
202                 if (ptr == NULL) {
203 #if defined(CONFIG_SCLP_CONSOLE)
204                         SET_CONSOLE_SCLP;
205 #endif
206                         return;
207                 }
208                 if (strncmp(ptr + 8, "3270", 4) == 0) {
209 #if defined(CONFIG_TN3270_CONSOLE)
210                         SET_CONSOLE_3270;
211 #elif defined(CONFIG_TN3215_CONSOLE)
212                         SET_CONSOLE_3215;
213 #elif defined(CONFIG_SCLP_CONSOLE)
214                         SET_CONSOLE_SCLP;
215 #endif
216                 } else if (strncmp(ptr + 8, "3215", 4) == 0) {
217 #if defined(CONFIG_TN3215_CONSOLE)
218                         SET_CONSOLE_3215;
219 #elif defined(CONFIG_TN3270_CONSOLE)
220                         SET_CONSOLE_3270;
221 #elif defined(CONFIG_SCLP_CONSOLE)
222                         SET_CONSOLE_SCLP;
223 #endif
224                 }
225         } else if (MACHINE_IS_P390) {
226 #if defined(CONFIG_TN3215_CONSOLE)
227                 SET_CONSOLE_3215;
228 #elif defined(CONFIG_TN3270_CONSOLE)
229                 SET_CONSOLE_3270;
230 #endif
231         } else {
232 #if defined(CONFIG_SCLP_CONSOLE)
233                 SET_CONSOLE_SCLP;
234 #endif
235         }
236 }
237
238 #ifdef CONFIG_SMP
239 extern void machine_restart_smp(char *);
240 extern void machine_halt_smp(void);
241 extern void machine_power_off_smp(void);
242
243 void (*_machine_restart)(char *command) = machine_restart_smp;
244 void (*_machine_halt)(void) = machine_halt_smp;
245 void (*_machine_power_off)(void) = machine_power_off_smp;
246 #else
247 /*
248  * Reboot, halt and power_off routines for non SMP.
249  */
250 extern void reipl(unsigned long devno);
251 static void do_machine_restart_nonsmp(char * __unused)
252 {
253         if (MACHINE_IS_VM)
254                 cpcmd ("IPL", NULL, 0);
255         else
256                 reipl (0x10000 | S390_lowcore.ipl_device);
257 }
258
259 static void do_machine_halt_nonsmp(void)
260 {
261         if (MACHINE_IS_VM && strlen(vmhalt_cmd) > 0)
262                 cpcmd(vmhalt_cmd, NULL, 0);
263         signal_processor(smp_processor_id(), sigp_stop_and_store_status);
264 }
265
266 static void do_machine_power_off_nonsmp(void)
267 {
268         if (MACHINE_IS_VM && strlen(vmpoff_cmd) > 0)
269                 cpcmd(vmpoff_cmd, NULL, 0);
270         signal_processor(smp_processor_id(), sigp_stop_and_store_status);
271 }
272
273 void (*_machine_restart)(char *command) = do_machine_restart_nonsmp;
274 void (*_machine_halt)(void) = do_machine_halt_nonsmp;
275 void (*_machine_power_off)(void) = do_machine_power_off_nonsmp;
276 #endif
277
278  /*
279  * Reboot, halt and power_off stubs. They just call _machine_restart,
280  * _machine_halt or _machine_power_off. 
281  */
282
283 void machine_restart(char *command)
284 {
285         console_unblank();
286         _machine_restart(command);
287 }
288
289 EXPORT_SYMBOL(machine_restart);
290
291 void machine_halt(void)
292 {
293         console_unblank();
294         _machine_halt();
295 }
296
297 EXPORT_SYMBOL(machine_halt);
298
299 void machine_power_off(void)
300 {
301         console_unblank();
302         _machine_power_off();
303 }
304
305 EXPORT_SYMBOL(machine_power_off);
306
307 /*
308  * Setup function called from init/main.c just after the banner
309  * was printed.
310  */
311 extern char _pstart, _pend, _stext;
312
313 void __init setup_arch(char **cmdline_p)
314 {
315         unsigned long bootmap_size;
316         unsigned long memory_start, memory_end;
317         char c = ' ', cn, *to = command_line, *from = COMMAND_LINE;
318         struct resource *res;
319         unsigned long start_pfn, end_pfn;
320         static unsigned int smptrap=0;
321         unsigned long delay = 0;
322         struct _lowcore *lc;
323         int i;
324
325         if (smptrap)
326                 return;
327         smptrap=1;
328
329         /*
330          * print what head.S has found out about the machine 
331          */
332 #ifndef CONFIG_ARCH_S390X
333         printk((MACHINE_IS_VM) ?
334                "We are running under VM (31 bit mode)\n" :
335                "We are running native (31 bit mode)\n");
336         printk((MACHINE_HAS_IEEE) ?
337                "This machine has an IEEE fpu\n" :
338                "This machine has no IEEE fpu\n");
339 #else /* CONFIG_ARCH_S390X */
340         printk((MACHINE_IS_VM) ?
341                "We are running under VM (64 bit mode)\n" :
342                "We are running native (64 bit mode)\n");
343 #endif /* CONFIG_ARCH_S390X */
344
345         ROOT_DEV = Root_RAM0;
346         memory_start = (unsigned long) &_end;    /* fixit if use $CODELO etc*/
347 #ifndef CONFIG_ARCH_S390X
348         memory_end = memory_size & ~0x400000UL;  /* align memory end to 4MB */
349         /*
350          * We need some free virtual space to be able to do vmalloc.
351          * On a machine with 2GB memory we make sure that we have at
352          * least 128 MB free space for vmalloc.
353          */
354         if (memory_end > 1920*1024*1024)
355                 memory_end = 1920*1024*1024;
356 #else /* CONFIG_ARCH_S390X */
357         memory_end = memory_size & ~0x200000UL;  /* detected in head.s */
358 #endif /* CONFIG_ARCH_S390X */
359         init_mm.start_code = PAGE_OFFSET;
360         init_mm.end_code = (unsigned long) &_etext;
361         init_mm.end_data = (unsigned long) &_edata;
362         init_mm.brk = (unsigned long) &_end;
363
364         code_resource.start = (unsigned long) &_text;
365         code_resource.end = (unsigned long) &_etext - 1;
366         data_resource.start = (unsigned long) &_etext;
367         data_resource.end = (unsigned long) &_edata - 1;
368
369         /* Save unparsed command line copy for /proc/cmdline */
370         memcpy(saved_command_line, COMMAND_LINE, COMMAND_LINE_SIZE);
371         saved_command_line[COMMAND_LINE_SIZE-1] = '\0';
372
373         for (;;) {
374                 /*
375                  * "mem=XXX[kKmM]" sets memsize 
376                  */
377                 if (c == ' ' && strncmp(from, "mem=", 4) == 0) {
378                         memory_end = simple_strtoul(from+4, &from, 0);
379                         if ( *from == 'K' || *from == 'k' ) {
380                                 memory_end = memory_end << 10;
381                                 from++;
382                         } else if ( *from == 'M' || *from == 'm' ) {
383                                 memory_end = memory_end << 20;
384                                 from++;
385                         }
386                 }
387                 /*
388                  * "ipldelay=XXX[sm]" sets ipl delay in seconds or minutes
389                  */
390                 if (c == ' ' && strncmp(from, "ipldelay=", 9) == 0) {
391                         delay = simple_strtoul(from+9, &from, 0);
392                         if (*from == 's' || *from == 'S') {
393                                 delay = delay*1000000;
394                                 from++;
395                         } else if (*from == 'm' || *from == 'M') {
396                                 delay = delay*60*1000000;
397                                 from++;
398                         }
399                         /* now wait for the requested amount of time */
400                         udelay(delay);
401                 }
402                 cn = *(from++);
403                 if (!cn)
404                         break;
405                 if (cn == '\n')
406                         cn = ' ';  /* replace newlines with space */
407                 if (cn == 0x0d)
408                         cn = ' ';  /* replace 0x0d with space */
409                 if (cn == ' ' && c == ' ')
410                         continue;  /* remove additional spaces */
411                 c = cn;
412                 if (to - command_line >= COMMAND_LINE_SIZE)
413                         break;
414                 *(to++) = c;
415         }
416         if (c == ' ' && to > command_line) to--;
417         *to = '\0';
418         *cmdline_p = command_line;
419
420         /*
421          * partially used pages are not usable - thus
422          * we are rounding upwards:
423          */
424         start_pfn = (__pa(&_end) + PAGE_SIZE - 1) >> PAGE_SHIFT;
425         end_pfn = max_pfn = memory_end >> PAGE_SHIFT;
426
427         /*
428          * Initialize the boot-time allocator (with low memory only):
429          */
430         bootmap_size = init_bootmem(start_pfn, end_pfn);
431
432         /*
433          * Register RAM areas with the bootmem allocator.
434          */
435         for (i = 0; i < 16 && memory_chunk[i].size > 0; i++) {
436                 unsigned long start_chunk, end_chunk;
437
438                 if (memory_chunk[i].type != CHUNK_READ_WRITE)
439                         continue;
440                 start_chunk = (memory_chunk[i].addr + PAGE_SIZE - 1);
441                 start_chunk >>= PAGE_SHIFT;
442                 end_chunk = (memory_chunk[i].addr + memory_chunk[i].size);
443                 end_chunk >>= PAGE_SHIFT;
444                 if (start_chunk < start_pfn)
445                         start_chunk = start_pfn;
446                 if (end_chunk > end_pfn)
447                         end_chunk = end_pfn;
448                 if (start_chunk < end_chunk)
449                         free_bootmem(start_chunk << PAGE_SHIFT,
450                                      (end_chunk - start_chunk) << PAGE_SHIFT);
451         }
452
453         /*
454          * Reserve the bootmem bitmap itself as well. We do this in two
455          * steps (first step was init_bootmem()) because this catches
456          * the (very unlikely) case of us accidentally initializing the
457          * bootmem allocator with an invalid RAM area.
458          */
459         reserve_bootmem(start_pfn << PAGE_SHIFT, bootmap_size);
460
461 #ifdef CONFIG_BLK_DEV_INITRD
462         if (INITRD_START) {
463                 if (INITRD_START + INITRD_SIZE <= memory_end) {
464                         reserve_bootmem(INITRD_START, INITRD_SIZE);
465                         initrd_start = INITRD_START;
466                         initrd_end = initrd_start + INITRD_SIZE;
467                 } else {
468                         printk("initrd extends beyond end of memory "
469                                "(0x%08lx > 0x%08lx)\ndisabling initrd\n",
470                                initrd_start + INITRD_SIZE, memory_end);
471                         initrd_start = initrd_end = 0;
472                 }
473         }
474 #endif
475
476         /*
477          * Setup lowcore for boot cpu
478          */
479 #ifndef CONFIG_ARCH_S390X
480         lc = (struct _lowcore *) __alloc_bootmem(PAGE_SIZE, PAGE_SIZE, 0);
481         memset(lc, 0, PAGE_SIZE);
482 #else /* CONFIG_ARCH_S390X */
483         lc = (struct _lowcore *) __alloc_bootmem(2*PAGE_SIZE, 2*PAGE_SIZE, 0);
484         memset(lc, 0, 2*PAGE_SIZE);
485 #endif /* CONFIG_ARCH_S390X */
486         lc->restart_psw.mask = PSW_BASE_BITS;
487         lc->restart_psw.addr =
488                 PSW_ADDR_AMODE | (unsigned long) restart_int_handler;
489         lc->external_new_psw.mask = PSW_KERNEL_BITS;
490         lc->external_new_psw.addr =
491                 PSW_ADDR_AMODE | (unsigned long) ext_int_handler;
492         lc->svc_new_psw.mask = PSW_KERNEL_BITS | PSW_MASK_IO | PSW_MASK_EXT;
493         lc->svc_new_psw.addr = PSW_ADDR_AMODE | (unsigned long) system_call;
494         lc->program_new_psw.mask = PSW_KERNEL_BITS;
495         lc->program_new_psw.addr =
496                 PSW_ADDR_AMODE | (unsigned long)pgm_check_handler;
497         lc->mcck_new_psw.mask = PSW_KERNEL_BITS;
498         lc->mcck_new_psw.addr =
499                 PSW_ADDR_AMODE | (unsigned long) mcck_int_handler;
500         lc->io_new_psw.mask = PSW_KERNEL_BITS;
501         lc->io_new_psw.addr = PSW_ADDR_AMODE | (unsigned long) io_int_handler;
502         lc->ipl_device = S390_lowcore.ipl_device;
503         lc->jiffy_timer = -1LL;
504         lc->kernel_stack = ((unsigned long) &init_thread_union) + THREAD_SIZE;
505         lc->async_stack = (unsigned long)
506                 __alloc_bootmem(ASYNC_SIZE, ASYNC_SIZE, 0) + ASYNC_SIZE;
507 #ifdef CONFIG_CHECK_STACK
508         lc->panic_stack = (unsigned long)
509                 __alloc_bootmem(PAGE_SIZE, PAGE_SIZE, 0) + PAGE_SIZE;
510 #endif
511         lc->current_task = (unsigned long) init_thread_union.thread_info.task;
512         lc->thread_info = (unsigned long) &init_thread_union;
513 #ifdef CONFIG_ARCH_S390X
514         if (MACHINE_HAS_DIAG44)
515                 lc->diag44_opcode = 0x83000044;
516         else
517                 lc->diag44_opcode = 0x07000700;
518 #endif /* CONFIG_ARCH_S390X */
519         set_prefix((u32)(unsigned long) lc);
520         cpu_init();
521         __cpu_logical_map[0] = S390_lowcore.cpu_data.cpu_addr;
522
523         /*
524          * Create kernel page tables and switch to virtual addressing.
525          */
526         paging_init();
527
528         res = alloc_bootmem_low(sizeof(struct resource));
529         res->start = 0;
530         res->end = memory_end;
531         res->flags = IORESOURCE_MEM | IORESOURCE_BUSY;
532         request_resource(&iomem_resource, res);
533         request_resource(res, &code_resource);
534         request_resource(res, &data_resource);
535
536         /* Setup default console */
537         conmode_default();
538 }
539
540 void print_cpu_info(struct cpuinfo_S390 *cpuinfo)
541 {
542    printk("cpu %d "
543 #ifdef CONFIG_SMP
544            "phys_idx=%d "
545 #endif
546            "vers=%02X ident=%06X machine=%04X unused=%04X\n",
547            cpuinfo->cpu_nr,
548 #ifdef CONFIG_SMP
549            cpuinfo->cpu_addr,
550 #endif
551            cpuinfo->cpu_id.version,
552            cpuinfo->cpu_id.ident,
553            cpuinfo->cpu_id.machine,
554            cpuinfo->cpu_id.unused);
555 }
556
557 /*
558  * show_cpuinfo - Get information on one CPU for use by procfs.
559  */
560
561 static int show_cpuinfo(struct seq_file *m, void *v)
562 {
563         struct cpuinfo_S390 *cpuinfo;
564         unsigned long n = (unsigned long) v - 1;
565
566         if (!n) {
567                 seq_printf(m, "vendor_id       : IBM/S390\n"
568                                "# processors    : %i\n"
569                                "bogomips per cpu: %lu.%02lu\n",
570                                num_online_cpus(), loops_per_jiffy/(500000/HZ),
571                                (loops_per_jiffy/(5000/HZ))%100);
572         }
573         if (cpu_online(n)) {
574 #ifdef CONFIG_SMP
575                 if (smp_processor_id() == n)
576                         cpuinfo = &S390_lowcore.cpu_data;
577                 else
578                         cpuinfo = &lowcore_ptr[n]->cpu_data;
579 #else
580                 cpuinfo = &S390_lowcore.cpu_data;
581 #endif
582                 seq_printf(m, "processor %li: "
583                                "version = %02X,  "
584                                "identification = %06X,  "
585                                "machine = %04X\n",
586                                n, cpuinfo->cpu_id.version,
587                                cpuinfo->cpu_id.ident,
588                                cpuinfo->cpu_id.machine);
589         }
590         return 0;
591 }
592
593 static void *c_start(struct seq_file *m, loff_t *pos)
594 {
595         return *pos < NR_CPUS ? (void *)((unsigned long) *pos + 1) : NULL;
596 }
597 static void *c_next(struct seq_file *m, void *v, loff_t *pos)
598 {
599         ++*pos;
600         return c_start(m, pos);
601 }
602 static void c_stop(struct seq_file *m, void *v)
603 {
604 }
605 struct seq_operations cpuinfo_op = {
606         .start  = c_start,
607         .next   = c_next,
608         .stop   = c_stop,
609         .show   = show_cpuinfo,
610 };
611