Commit | Line | Data |
---|---|---|
1da177e4 LT |
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> | |
1da177e4 LT |
31 | #include <linux/init.h> |
32 | #include <linux/initrd.h> | |
33 | #include <linux/bootmem.h> | |
34 | #include <linux/root_dev.h> | |
35 | #include <linux/console.h> | |
36 | #include <linux/seq_file.h> | |
37 | #include <linux/kernel_stat.h> | |
1e8e3383 | 38 | #include <linux/device.h> |
585c3047 | 39 | #include <linux/notifier.h> |
65912a84 | 40 | #include <linux/pfn.h> |
fe355b7f | 41 | #include <linux/ctype.h> |
2b67fc46 | 42 | #include <linux/reboot.h> |
1da177e4 LT |
43 | |
44 | #include <asm/uaccess.h> | |
45 | #include <asm/system.h> | |
46 | #include <asm/smp.h> | |
47 | #include <asm/mmu_context.h> | |
48 | #include <asm/cpcmd.h> | |
49 | #include <asm/lowcore.h> | |
50 | #include <asm/irq.h> | |
0b642ede PO |
51 | #include <asm/page.h> |
52 | #include <asm/ptrace.h> | |
cc13ad62 | 53 | #include <asm/sections.h> |
fe355b7f | 54 | #include <asm/ebcdic.h> |
c1821c2e GS |
55 | #include <asm/compat.h> |
56 | ||
57 | long psw_kernel_bits = (PSW_BASE_BITS | PSW_MASK_DAT | PSW_ASC_PRIMARY | | |
58 | PSW_MASK_MCHECK | PSW_DEFAULT_KEY); | |
59 | long psw_user_bits = (PSW_BASE_BITS | PSW_MASK_DAT | PSW_ASC_HOME | | |
60 | PSW_MASK_IO | PSW_MASK_EXT | PSW_MASK_MCHECK | | |
61 | PSW_MASK_PSTATE | PSW_DEFAULT_KEY); | |
1da177e4 | 62 | |
d02765d1 GS |
63 | /* |
64 | * User copy operations. | |
65 | */ | |
66 | struct uaccess_ops uaccess; | |
67 | EXPORT_SYMBOL_GPL(uaccess); | |
68 | ||
1da177e4 LT |
69 | /* |
70 | * Machine setup.. | |
71 | */ | |
72 | unsigned int console_mode = 0; | |
73 | unsigned int console_devno = -1; | |
74 | unsigned int console_irq = -1; | |
1da177e4 | 75 | unsigned long machine_flags = 0; |
36a2bd42 | 76 | |
f4eb07c1 | 77 | struct mem_chunk __initdata memory_chunk[MEMORY_CHUNKS]; |
1da177e4 | 78 | volatile int __cpu_logical_map[NR_CPUS]; /* logical cpu to cpu address */ |
c9e37353 | 79 | static unsigned long __initdata memory_end; |
1da177e4 | 80 | |
1da177e4 LT |
81 | /* |
82 | * This is set up by the setup-routine at boot-time | |
83 | * for S390 need to find out, what we have to setup | |
84 | * using address 0x10400 ... | |
85 | */ | |
86 | ||
87 | #include <asm/setup.h> | |
88 | ||
1da177e4 LT |
89 | static struct resource code_resource = { |
90 | .name = "Kernel code", | |
91 | .flags = IORESOURCE_BUSY | IORESOURCE_MEM, | |
92 | }; | |
93 | ||
94 | static struct resource data_resource = { | |
95 | .name = "Kernel data", | |
96 | .flags = IORESOURCE_BUSY | IORESOURCE_MEM, | |
97 | }; | |
98 | ||
99 | /* | |
100 | * cpu_init() initializes state that is per-CPU. | |
101 | */ | |
102 | void __devinit cpu_init (void) | |
103 | { | |
104 | int addr = hard_smp_processor_id(); | |
105 | ||
106 | /* | |
107 | * Store processor id in lowcore (used e.g. in timer_interrupt) | |
108 | */ | |
94c12cc7 | 109 | asm volatile("stidp %0": "=m" (S390_lowcore.cpu_data.cpu_id)); |
1da177e4 LT |
110 | S390_lowcore.cpu_data.cpu_addr = addr; |
111 | ||
112 | /* | |
113 | * Force FPU initialization: | |
114 | */ | |
115 | clear_thread_flag(TIF_USEDFPU); | |
116 | clear_used_math(); | |
117 | ||
118 | atomic_inc(&init_mm.mm_count); | |
119 | current->active_mm = &init_mm; | |
120 | if (current->mm) | |
121 | BUG(); | |
122 | enter_lazy_tlb(&init_mm, current); | |
123 | } | |
124 | ||
125 | /* | |
126 | * VM halt and poweroff setup routines | |
127 | */ | |
128 | char vmhalt_cmd[128] = ""; | |
129 | char vmpoff_cmd[128] = ""; | |
2b67fc46 | 130 | static char vmpanic_cmd[128] = ""; |
1da177e4 LT |
131 | |
132 | static inline void strncpy_skip_quote(char *dst, char *src, int n) | |
133 | { | |
134 | int sx, dx; | |
135 | ||
136 | dx = 0; | |
137 | for (sx = 0; src[sx] != 0; sx++) { | |
138 | if (src[sx] == '"') continue; | |
139 | dst[dx++] = src[sx]; | |
140 | if (dx >= n) break; | |
141 | } | |
142 | } | |
143 | ||
144 | static int __init vmhalt_setup(char *str) | |
145 | { | |
146 | strncpy_skip_quote(vmhalt_cmd, str, 127); | |
147 | vmhalt_cmd[127] = 0; | |
148 | return 1; | |
149 | } | |
150 | ||
151 | __setup("vmhalt=", vmhalt_setup); | |
152 | ||
153 | static int __init vmpoff_setup(char *str) | |
154 | { | |
155 | strncpy_skip_quote(vmpoff_cmd, str, 127); | |
156 | vmpoff_cmd[127] = 0; | |
157 | return 1; | |
158 | } | |
159 | ||
160 | __setup("vmpoff=", vmpoff_setup); | |
161 | ||
585c3047 PO |
162 | static int vmpanic_notify(struct notifier_block *self, unsigned long event, |
163 | void *data) | |
164 | { | |
165 | if (MACHINE_IS_VM && strlen(vmpanic_cmd) > 0) | |
166 | cpcmd(vmpanic_cmd, NULL, 0, NULL); | |
167 | ||
168 | return NOTIFY_OK; | |
169 | } | |
170 | ||
171 | #define PANIC_PRI_VMPANIC 0 | |
172 | ||
173 | static struct notifier_block vmpanic_nb = { | |
174 | .notifier_call = vmpanic_notify, | |
175 | .priority = PANIC_PRI_VMPANIC | |
176 | }; | |
177 | ||
178 | static int __init vmpanic_setup(char *str) | |
179 | { | |
180 | static int register_done __initdata = 0; | |
181 | ||
182 | strncpy_skip_quote(vmpanic_cmd, str, 127); | |
183 | vmpanic_cmd[127] = 0; | |
184 | if (!register_done) { | |
185 | register_done = 1; | |
186 | atomic_notifier_chain_register(&panic_notifier_list, | |
187 | &vmpanic_nb); | |
188 | } | |
189 | return 1; | |
190 | } | |
191 | ||
192 | __setup("vmpanic=", vmpanic_setup); | |
193 | ||
1da177e4 LT |
194 | /* |
195 | * condev= and conmode= setup parameter. | |
196 | */ | |
197 | ||
198 | static int __init condev_setup(char *str) | |
199 | { | |
200 | int vdev; | |
201 | ||
202 | vdev = simple_strtoul(str, &str, 0); | |
203 | if (vdev >= 0 && vdev < 65536) { | |
204 | console_devno = vdev; | |
205 | console_irq = -1; | |
206 | } | |
207 | return 1; | |
208 | } | |
209 | ||
210 | __setup("condev=", condev_setup); | |
211 | ||
212 | static int __init conmode_setup(char *str) | |
213 | { | |
214 | #if defined(CONFIG_SCLP_CONSOLE) | |
215 | if (strncmp(str, "hwc", 4) == 0 || strncmp(str, "sclp", 5) == 0) | |
216 | SET_CONSOLE_SCLP; | |
217 | #endif | |
218 | #if defined(CONFIG_TN3215_CONSOLE) | |
219 | if (strncmp(str, "3215", 5) == 0) | |
220 | SET_CONSOLE_3215; | |
221 | #endif | |
222 | #if defined(CONFIG_TN3270_CONSOLE) | |
223 | if (strncmp(str, "3270", 5) == 0) | |
224 | SET_CONSOLE_3270; | |
225 | #endif | |
226 | return 1; | |
227 | } | |
228 | ||
229 | __setup("conmode=", conmode_setup); | |
230 | ||
231 | static void __init conmode_default(void) | |
232 | { | |
233 | char query_buffer[1024]; | |
234 | char *ptr; | |
235 | ||
236 | if (MACHINE_IS_VM) { | |
740b5706 | 237 | cpcmd("QUERY CONSOLE", query_buffer, 1024, NULL); |
1da177e4 LT |
238 | console_devno = simple_strtoul(query_buffer + 5, NULL, 16); |
239 | ptr = strstr(query_buffer, "SUBCHANNEL ="); | |
240 | console_irq = simple_strtoul(ptr + 13, NULL, 16); | |
740b5706 | 241 | cpcmd("QUERY TERM", query_buffer, 1024, NULL); |
1da177e4 LT |
242 | ptr = strstr(query_buffer, "CONMODE"); |
243 | /* | |
244 | * Set the conmode to 3215 so that the device recognition | |
245 | * will set the cu_type of the console to 3215. If the | |
246 | * conmode is 3270 and we don't set it back then both | |
247 | * 3215 and the 3270 driver will try to access the console | |
248 | * device (3215 as console and 3270 as normal tty). | |
249 | */ | |
740b5706 | 250 | cpcmd("TERM CONMODE 3215", NULL, 0, NULL); |
1da177e4 LT |
251 | if (ptr == NULL) { |
252 | #if defined(CONFIG_SCLP_CONSOLE) | |
253 | SET_CONSOLE_SCLP; | |
254 | #endif | |
255 | return; | |
256 | } | |
257 | if (strncmp(ptr + 8, "3270", 4) == 0) { | |
258 | #if defined(CONFIG_TN3270_CONSOLE) | |
259 | SET_CONSOLE_3270; | |
260 | #elif defined(CONFIG_TN3215_CONSOLE) | |
261 | SET_CONSOLE_3215; | |
262 | #elif defined(CONFIG_SCLP_CONSOLE) | |
263 | SET_CONSOLE_SCLP; | |
264 | #endif | |
265 | } else if (strncmp(ptr + 8, "3215", 4) == 0) { | |
266 | #if defined(CONFIG_TN3215_CONSOLE) | |
267 | SET_CONSOLE_3215; | |
268 | #elif defined(CONFIG_TN3270_CONSOLE) | |
269 | SET_CONSOLE_3270; | |
270 | #elif defined(CONFIG_SCLP_CONSOLE) | |
271 | SET_CONSOLE_SCLP; | |
272 | #endif | |
273 | } | |
274 | } else if (MACHINE_IS_P390) { | |
275 | #if defined(CONFIG_TN3215_CONSOLE) | |
276 | SET_CONSOLE_3215; | |
277 | #elif defined(CONFIG_TN3270_CONSOLE) | |
278 | SET_CONSOLE_3270; | |
279 | #endif | |
280 | } else { | |
281 | #if defined(CONFIG_SCLP_CONSOLE) | |
282 | SET_CONSOLE_SCLP; | |
283 | #endif | |
284 | } | |
285 | } | |
286 | ||
fe355b7f HY |
287 | /* |
288 | * Create a Kernel NSS if the SAVESYS= parameter is defined | |
289 | */ | |
290 | #define DEFSYS_CMD_SIZE 96 | |
291 | #define SAVESYS_CMD_SIZE 32 | |
292 | ||
293 | extern int _eshared; | |
294 | char kernel_nss_name[NSS_NAME_SIZE + 1]; | |
295 | ||
296 | #ifdef CONFIG_SHARED_KERNEL | |
297 | static __init void create_kernel_nss(void) | |
298 | { | |
299 | unsigned int i, stext_pfn, eshared_pfn, end_pfn, min_size; | |
300 | #ifdef CONFIG_BLK_DEV_INITRD | |
301 | unsigned int sinitrd_pfn, einitrd_pfn; | |
302 | #endif | |
303 | int response; | |
304 | char *savesys_ptr; | |
305 | char upper_command_line[COMMAND_LINE_SIZE]; | |
306 | char defsys_cmd[DEFSYS_CMD_SIZE]; | |
307 | char savesys_cmd[SAVESYS_CMD_SIZE]; | |
308 | ||
309 | /* Do nothing if we are not running under VM */ | |
310 | if (!MACHINE_IS_VM) | |
311 | return; | |
312 | ||
313 | /* Convert COMMAND_LINE to upper case */ | |
314 | for (i = 0; i < strlen(COMMAND_LINE); i++) | |
315 | upper_command_line[i] = toupper(COMMAND_LINE[i]); | |
316 | ||
317 | savesys_ptr = strstr(upper_command_line, "SAVESYS="); | |
318 | ||
319 | if (!savesys_ptr) | |
320 | return; | |
321 | ||
322 | savesys_ptr += 8; /* Point to the beginning of the NSS name */ | |
323 | for (i = 0; i < NSS_NAME_SIZE; i++) { | |
324 | if (savesys_ptr[i] == ' ' || savesys_ptr[i] == '\0') | |
325 | break; | |
326 | kernel_nss_name[i] = savesys_ptr[i]; | |
327 | } | |
328 | ||
329 | stext_pfn = PFN_DOWN(__pa(&_stext)); | |
330 | eshared_pfn = PFN_DOWN(__pa(&_eshared)); | |
331 | end_pfn = PFN_UP(__pa(&_end)); | |
332 | min_size = end_pfn << 2; | |
333 | ||
334 | sprintf(defsys_cmd, "DEFSYS %s 00000-%.5X EW %.5X-%.5X SR %.5X-%.5X", | |
335 | kernel_nss_name, stext_pfn - 1, stext_pfn, eshared_pfn - 1, | |
336 | eshared_pfn, end_pfn); | |
337 | ||
338 | #ifdef CONFIG_BLK_DEV_INITRD | |
339 | if (INITRD_START && INITRD_SIZE) { | |
340 | sinitrd_pfn = PFN_DOWN(__pa(INITRD_START)); | |
341 | einitrd_pfn = PFN_UP(__pa(INITRD_START + INITRD_SIZE)); | |
342 | min_size = einitrd_pfn << 2; | |
343 | sprintf(defsys_cmd, "%s EW %.5X-%.5X", defsys_cmd, | |
344 | sinitrd_pfn, einitrd_pfn); | |
345 | } | |
346 | #endif | |
347 | ||
348 | sprintf(defsys_cmd, "%s EW MINSIZE=%.7iK", defsys_cmd, min_size); | |
349 | sprintf(savesys_cmd, "SAVESYS %s \n IPL %s", | |
350 | kernel_nss_name, kernel_nss_name); | |
351 | ||
352 | __cpcmd(defsys_cmd, NULL, 0, &response); | |
353 | ||
354 | if (response != 0) | |
355 | return; | |
356 | ||
357 | __cpcmd(savesys_cmd, NULL, 0, &response); | |
358 | ||
359 | if (response != strlen(savesys_cmd)) | |
360 | return; | |
361 | ||
362 | ipl_flags = IPL_NSS_VALID; | |
363 | } | |
364 | ||
365 | #else /* CONFIG_SHARED_KERNEL */ | |
366 | ||
367 | static inline void create_kernel_nss(void) { } | |
368 | ||
369 | #endif /* CONFIG_SHARED_KERNEL */ | |
370 | ||
371 | /* | |
372 | * Clear bss memory | |
373 | */ | |
374 | static __init void clear_bss_section(void) | |
375 | { | |
376 | memset(__bss_start, 0, _end - __bss_start); | |
377 | } | |
378 | ||
379 | /* | |
380 | * Initialize storage key for kernel pages | |
381 | */ | |
382 | static __init void init_kernel_storage_key(void) | |
383 | { | |
384 | unsigned long end_pfn, init_pfn; | |
385 | ||
386 | end_pfn = PFN_UP(__pa(&_end)); | |
387 | ||
388 | for (init_pfn = 0 ; init_pfn < end_pfn; init_pfn++) | |
389 | page_set_storage_key(init_pfn << PAGE_SHIFT, PAGE_DEFAULT_KEY); | |
390 | } | |
391 | ||
392 | static __init void detect_machine_type(void) | |
393 | { | |
394 | struct cpuinfo_S390 *cpuinfo = &S390_lowcore.cpu_data; | |
395 | ||
396 | asm volatile("stidp %0" : "=m" (S390_lowcore.cpu_data.cpu_id)); | |
397 | ||
398 | /* Running under z/VM ? */ | |
399 | if (cpuinfo->cpu_id.version == 0xff) | |
400 | machine_flags |= 1; | |
401 | ||
402 | /* Running on a P/390 ? */ | |
403 | if (cpuinfo->cpu_id.machine == 0x7490) | |
404 | machine_flags |= 4; | |
405 | } | |
406 | ||
407 | /* | |
408 | * Save ipl parameters, clear bss memory, initialize storage keys | |
409 | * and create a kernel NSS at startup if the SAVESYS= parm is defined | |
410 | */ | |
411 | void __init startup_init(void) | |
412 | { | |
413 | ipl_save_parameters(); | |
414 | clear_bss_section(); | |
415 | init_kernel_storage_key(); | |
416 | lockdep_init(); | |
417 | detect_machine_type(); | |
418 | create_kernel_nss(); | |
419 | } | |
420 | ||
1da177e4 | 421 | #ifdef CONFIG_SMP |
1da177e4 LT |
422 | void (*_machine_restart)(char *command) = machine_restart_smp; |
423 | void (*_machine_halt)(void) = machine_halt_smp; | |
424 | void (*_machine_power_off)(void) = machine_power_off_smp; | |
425 | #else | |
426 | /* | |
427 | * Reboot, halt and power_off routines for non SMP. | |
428 | */ | |
1da177e4 LT |
429 | static void do_machine_restart_nonsmp(char * __unused) |
430 | { | |
ff6b8ea6 | 431 | do_reipl(); |
1da177e4 LT |
432 | } |
433 | ||
434 | static void do_machine_halt_nonsmp(void) | |
435 | { | |
436 | if (MACHINE_IS_VM && strlen(vmhalt_cmd) > 0) | |
740b5706 | 437 | __cpcmd(vmhalt_cmd, NULL, 0, NULL); |
1da177e4 LT |
438 | signal_processor(smp_processor_id(), sigp_stop_and_store_status); |
439 | } | |
440 | ||
441 | static void do_machine_power_off_nonsmp(void) | |
442 | { | |
443 | if (MACHINE_IS_VM && strlen(vmpoff_cmd) > 0) | |
740b5706 | 444 | __cpcmd(vmpoff_cmd, NULL, 0, NULL); |
1da177e4 LT |
445 | signal_processor(smp_processor_id(), sigp_stop_and_store_status); |
446 | } | |
447 | ||
448 | void (*_machine_restart)(char *command) = do_machine_restart_nonsmp; | |
449 | void (*_machine_halt)(void) = do_machine_halt_nonsmp; | |
450 | void (*_machine_power_off)(void) = do_machine_power_off_nonsmp; | |
451 | #endif | |
452 | ||
453 | /* | |
454 | * Reboot, halt and power_off stubs. They just call _machine_restart, | |
455 | * _machine_halt or _machine_power_off. | |
456 | */ | |
457 | ||
458 | void machine_restart(char *command) | |
459 | { | |
06fa46a2 MS |
460 | if (!in_interrupt() || oops_in_progress) |
461 | /* | |
462 | * Only unblank the console if we are called in enabled | |
463 | * context or a bust_spinlocks cleared the way for us. | |
464 | */ | |
465 | console_unblank(); | |
1da177e4 LT |
466 | _machine_restart(command); |
467 | } | |
468 | ||
1da177e4 LT |
469 | void machine_halt(void) |
470 | { | |
06fa46a2 MS |
471 | if (!in_interrupt() || oops_in_progress) |
472 | /* | |
473 | * Only unblank the console if we are called in enabled | |
474 | * context or a bust_spinlocks cleared the way for us. | |
475 | */ | |
476 | console_unblank(); | |
1da177e4 LT |
477 | _machine_halt(); |
478 | } | |
479 | ||
1da177e4 LT |
480 | void machine_power_off(void) |
481 | { | |
06fa46a2 MS |
482 | if (!in_interrupt() || oops_in_progress) |
483 | /* | |
484 | * Only unblank the console if we are called in enabled | |
485 | * context or a bust_spinlocks cleared the way for us. | |
486 | */ | |
487 | console_unblank(); | |
1da177e4 LT |
488 | _machine_power_off(); |
489 | } | |
490 | ||
53df751c MS |
491 | /* |
492 | * Dummy power off function. | |
493 | */ | |
494 | void (*pm_power_off)(void) = machine_power_off; | |
495 | ||
59685296 HC |
496 | static int __init early_parse_mem(char *p) |
497 | { | |
498 | memory_end = memparse(p, &p); | |
499 | return 0; | |
500 | } | |
501 | early_param("mem", early_parse_mem); | |
502 | ||
503 | /* | |
504 | * "ipldelay=XXX[sm]" sets ipl delay in seconds or minutes | |
505 | */ | |
506 | static int __init early_parse_ipldelay(char *p) | |
c9e37353 | 507 | { |
c9e37353 | 508 | unsigned long delay = 0; |
1da177e4 | 509 | |
59685296 | 510 | delay = simple_strtoul(p, &p, 0); |
1da177e4 | 511 | |
59685296 HC |
512 | switch (*p) { |
513 | case 's': | |
514 | case 'S': | |
515 | delay *= 1000000; | |
516 | break; | |
517 | case 'm': | |
518 | case 'M': | |
519 | delay *= 60 * 1000000; | |
c9e37353 | 520 | } |
59685296 HC |
521 | |
522 | /* now wait for the requested amount of time */ | |
523 | udelay(delay); | |
524 | ||
525 | return 0; | |
c9e37353 | 526 | } |
59685296 | 527 | early_param("ipldelay", early_parse_ipldelay); |
c9e37353 | 528 | |
c1821c2e GS |
529 | #ifdef CONFIG_S390_SWITCH_AMODE |
530 | unsigned int switch_amode = 0; | |
531 | EXPORT_SYMBOL_GPL(switch_amode); | |
532 | ||
533 | static inline void set_amode_and_uaccess(unsigned long user_amode, | |
534 | unsigned long user32_amode) | |
535 | { | |
536 | psw_user_bits = PSW_BASE_BITS | PSW_MASK_DAT | user_amode | | |
537 | PSW_MASK_IO | PSW_MASK_EXT | PSW_MASK_MCHECK | | |
538 | PSW_MASK_PSTATE | PSW_DEFAULT_KEY; | |
539 | #ifdef CONFIG_COMPAT | |
540 | psw_user32_bits = PSW_BASE32_BITS | PSW_MASK_DAT | user_amode | | |
541 | PSW_MASK_IO | PSW_MASK_EXT | PSW_MASK_MCHECK | | |
542 | PSW_MASK_PSTATE | PSW_DEFAULT_KEY; | |
543 | psw32_user_bits = PSW32_BASE_BITS | PSW32_MASK_DAT | user32_amode | | |
544 | PSW32_MASK_IO | PSW32_MASK_EXT | PSW32_MASK_MCHECK | | |
545 | PSW32_MASK_PSTATE; | |
546 | #endif | |
547 | psw_kernel_bits = PSW_BASE_BITS | PSW_MASK_DAT | PSW_ASC_HOME | | |
548 | PSW_MASK_MCHECK | PSW_DEFAULT_KEY; | |
549 | ||
550 | if (MACHINE_HAS_MVCOS) { | |
551 | printk("mvcos available.\n"); | |
552 | memcpy(&uaccess, &uaccess_mvcos_switch, sizeof(uaccess)); | |
553 | } else { | |
554 | printk("mvcos not available.\n"); | |
555 | memcpy(&uaccess, &uaccess_pt, sizeof(uaccess)); | |
556 | } | |
557 | } | |
558 | ||
559 | /* | |
560 | * Switch kernel/user addressing modes? | |
561 | */ | |
562 | static int __init early_parse_switch_amode(char *p) | |
563 | { | |
564 | switch_amode = 1; | |
565 | return 0; | |
566 | } | |
567 | early_param("switch_amode", early_parse_switch_amode); | |
568 | ||
569 | #else /* CONFIG_S390_SWITCH_AMODE */ | |
570 | static inline void set_amode_and_uaccess(unsigned long user_amode, | |
571 | unsigned long user32_amode) | |
572 | { | |
573 | } | |
574 | #endif /* CONFIG_S390_SWITCH_AMODE */ | |
575 | ||
576 | #ifdef CONFIG_S390_EXEC_PROTECT | |
577 | unsigned int s390_noexec = 0; | |
578 | EXPORT_SYMBOL_GPL(s390_noexec); | |
579 | ||
580 | /* | |
581 | * Enable execute protection? | |
582 | */ | |
583 | static int __init early_parse_noexec(char *p) | |
584 | { | |
585 | if (!strncmp(p, "off", 3)) | |
586 | return 0; | |
587 | switch_amode = 1; | |
588 | s390_noexec = 1; | |
589 | return 0; | |
590 | } | |
591 | early_param("noexec", early_parse_noexec); | |
592 | #endif /* CONFIG_S390_EXEC_PROTECT */ | |
593 | ||
594 | static void setup_addressing_mode(void) | |
595 | { | |
596 | if (s390_noexec) { | |
597 | printk("S390 execute protection active, "); | |
598 | set_amode_and_uaccess(PSW_ASC_SECONDARY, PSW32_ASC_SECONDARY); | |
599 | return; | |
600 | } | |
601 | if (switch_amode) { | |
602 | printk("S390 address spaces switched, "); | |
603 | set_amode_and_uaccess(PSW_ASC_PRIMARY, PSW32_ASC_PRIMARY); | |
604 | } | |
605 | } | |
606 | ||
c9e37353 HC |
607 | static void __init |
608 | setup_lowcore(void) | |
609 | { | |
610 | struct _lowcore *lc; | |
611 | int lc_pages; | |
612 | ||
613 | /* | |
614 | * Setup lowcore for boot cpu | |
615 | */ | |
616 | lc_pages = sizeof(void *) == 8 ? 2 : 1; | |
617 | lc = (struct _lowcore *) | |
618 | __alloc_bootmem(lc_pages * PAGE_SIZE, lc_pages * PAGE_SIZE, 0); | |
619 | memset(lc, 0, lc_pages * PAGE_SIZE); | |
0b642ede | 620 | lc->restart_psw.mask = PSW_BASE_BITS | PSW_DEFAULT_KEY; |
c9e37353 HC |
621 | lc->restart_psw.addr = |
622 | PSW_ADDR_AMODE | (unsigned long) restart_int_handler; | |
c1821c2e GS |
623 | if (switch_amode) |
624 | lc->restart_psw.mask |= PSW_ASC_HOME; | |
625 | lc->external_new_psw.mask = psw_kernel_bits; | |
c9e37353 HC |
626 | lc->external_new_psw.addr = |
627 | PSW_ADDR_AMODE | (unsigned long) ext_int_handler; | |
c1821c2e | 628 | lc->svc_new_psw.mask = psw_kernel_bits | PSW_MASK_IO | PSW_MASK_EXT; |
c9e37353 | 629 | lc->svc_new_psw.addr = PSW_ADDR_AMODE | (unsigned long) system_call; |
c1821c2e | 630 | lc->program_new_psw.mask = psw_kernel_bits; |
c9e37353 HC |
631 | lc->program_new_psw.addr = |
632 | PSW_ADDR_AMODE | (unsigned long)pgm_check_handler; | |
77fa2245 | 633 | lc->mcck_new_psw.mask = |
c1821c2e | 634 | psw_kernel_bits & ~PSW_MASK_MCHECK & ~PSW_MASK_DAT; |
c9e37353 HC |
635 | lc->mcck_new_psw.addr = |
636 | PSW_ADDR_AMODE | (unsigned long) mcck_int_handler; | |
c1821c2e | 637 | lc->io_new_psw.mask = psw_kernel_bits; |
c9e37353 HC |
638 | lc->io_new_psw.addr = PSW_ADDR_AMODE | (unsigned long) io_int_handler; |
639 | lc->ipl_device = S390_lowcore.ipl_device; | |
640 | lc->jiffy_timer = -1LL; | |
641 | lc->kernel_stack = ((unsigned long) &init_thread_union) + THREAD_SIZE; | |
642 | lc->async_stack = (unsigned long) | |
643 | __alloc_bootmem(ASYNC_SIZE, ASYNC_SIZE, 0) + ASYNC_SIZE; | |
c9e37353 HC |
644 | lc->panic_stack = (unsigned long) |
645 | __alloc_bootmem(PAGE_SIZE, PAGE_SIZE, 0) + PAGE_SIZE; | |
c9e37353 HC |
646 | lc->current_task = (unsigned long) init_thread_union.thread_info.task; |
647 | lc->thread_info = (unsigned long) &init_thread_union; | |
347a8dc3 | 648 | #ifndef CONFIG_64BIT |
77fa2245 HC |
649 | if (MACHINE_HAS_IEEE) { |
650 | lc->extended_save_area_addr = (__u32) | |
651 | __alloc_bootmem(PAGE_SIZE, PAGE_SIZE, 0); | |
652 | /* enable extended save area */ | |
c4972f33 | 653 | __ctl_set_bit(14, 29); |
77fa2245 HC |
654 | } |
655 | #endif | |
c9e37353 HC |
656 | set_prefix((u32)(unsigned long) lc); |
657 | } | |
658 | ||
659 | static void __init | |
660 | setup_resources(void) | |
661 | { | |
fe355b7f | 662 | struct resource *res, *sub_res; |
c9e37353 HC |
663 | int i; |
664 | ||
cc13ad62 HC |
665 | code_resource.start = (unsigned long) &_text; |
666 | code_resource.end = (unsigned long) &_etext - 1; | |
667 | data_resource.start = (unsigned long) &_etext; | |
668 | data_resource.end = (unsigned long) &_edata - 1; | |
669 | ||
c9e37353 HC |
670 | for (i = 0; i < MEMORY_CHUNKS && memory_chunk[i].size > 0; i++) { |
671 | res = alloc_bootmem_low(sizeof(struct resource)); | |
672 | res->flags = IORESOURCE_BUSY | IORESOURCE_MEM; | |
673 | switch (memory_chunk[i].type) { | |
674 | case CHUNK_READ_WRITE: | |
675 | res->name = "System RAM"; | |
676 | break; | |
677 | case CHUNK_READ_ONLY: | |
678 | res->name = "System ROM"; | |
679 | res->flags |= IORESOURCE_READONLY; | |
680 | break; | |
681 | default: | |
682 | res->name = "reserved"; | |
683 | } | |
684 | res->start = memory_chunk[i].addr; | |
685 | res->end = memory_chunk[i].addr + memory_chunk[i].size - 1; | |
686 | request_resource(&iomem_resource, res); | |
fe355b7f HY |
687 | |
688 | if (code_resource.start >= res->start && | |
689 | code_resource.start <= res->end && | |
690 | code_resource.end > res->end) { | |
691 | sub_res = alloc_bootmem_low(sizeof(struct resource)); | |
692 | memcpy(sub_res, &code_resource, | |
693 | sizeof(struct resource)); | |
694 | sub_res->end = res->end; | |
695 | code_resource.start = res->end + 1; | |
696 | request_resource(res, sub_res); | |
697 | } | |
698 | ||
699 | if (code_resource.start >= res->start && | |
700 | code_resource.start <= res->end && | |
701 | code_resource.end <= res->end) | |
702 | request_resource(res, &code_resource); | |
703 | ||
704 | if (data_resource.start >= res->start && | |
705 | data_resource.start <= res->end && | |
706 | data_resource.end > res->end) { | |
707 | sub_res = alloc_bootmem_low(sizeof(struct resource)); | |
708 | memcpy(sub_res, &data_resource, | |
709 | sizeof(struct resource)); | |
710 | sub_res->end = res->end; | |
711 | data_resource.start = res->end + 1; | |
712 | request_resource(res, sub_res); | |
713 | } | |
714 | ||
715 | if (data_resource.start >= res->start && | |
716 | data_resource.start <= res->end && | |
717 | data_resource.end <= res->end) | |
718 | request_resource(res, &data_resource); | |
c9e37353 HC |
719 | } |
720 | } | |
721 | ||
8b62bc96 HC |
722 | static void __init setup_memory_end(void) |
723 | { | |
724 | unsigned long real_size, memory_size; | |
725 | unsigned long max_mem, max_phys; | |
726 | int i; | |
727 | ||
728 | memory_size = real_size = 0; | |
de338a37 | 729 | max_phys = VMALLOC_END_INIT - VMALLOC_MIN_SIZE; |
8b62bc96 HC |
730 | memory_end &= PAGE_MASK; |
731 | ||
732 | max_mem = memory_end ? min(max_phys, memory_end) : max_phys; | |
733 | ||
734 | for (i = 0; i < MEMORY_CHUNKS; i++) { | |
735 | struct mem_chunk *chunk = &memory_chunk[i]; | |
736 | ||
737 | real_size = max(real_size, chunk->addr + chunk->size); | |
738 | if (chunk->addr >= max_mem) { | |
739 | memset(chunk, 0, sizeof(*chunk)); | |
740 | continue; | |
741 | } | |
742 | if (chunk->addr + chunk->size > max_mem) | |
743 | chunk->size = max_mem - chunk->addr; | |
744 | memory_size = max(memory_size, chunk->addr + chunk->size); | |
745 | } | |
746 | if (!memory_end) | |
747 | memory_end = memory_size; | |
8b62bc96 HC |
748 | } |
749 | ||
c9e37353 HC |
750 | static void __init |
751 | setup_memory(void) | |
752 | { | |
753 | unsigned long bootmap_size; | |
fe355b7f | 754 | unsigned long start_pfn, end_pfn; |
c9e37353 | 755 | int i; |
1da177e4 LT |
756 | |
757 | /* | |
758 | * partially used pages are not usable - thus | |
759 | * we are rounding upwards: | |
760 | */ | |
65912a84 HC |
761 | start_pfn = PFN_UP(__pa(&_end)); |
762 | end_pfn = max_pfn = PFN_DOWN(memory_end); | |
1da177e4 | 763 | |
65912a84 HC |
764 | #ifdef CONFIG_BLK_DEV_INITRD |
765 | /* | |
766 | * Move the initrd in case the bitmap of the bootmem allocater | |
767 | * would overwrite it. | |
768 | */ | |
769 | ||
770 | if (INITRD_START && INITRD_SIZE) { | |
771 | unsigned long bmap_size; | |
772 | unsigned long start; | |
773 | ||
774 | bmap_size = bootmem_bootmap_pages(end_pfn - start_pfn + 1); | |
775 | bmap_size = PFN_PHYS(bmap_size); | |
776 | ||
777 | if (PFN_PHYS(start_pfn) + bmap_size > INITRD_START) { | |
778 | start = PFN_PHYS(start_pfn) + bmap_size + PAGE_SIZE; | |
779 | ||
780 | if (start + INITRD_SIZE > memory_end) { | |
781 | printk("initrd extends beyond end of memory " | |
782 | "(0x%08lx > 0x%08lx)\n" | |
783 | "disabling initrd\n", | |
784 | start + INITRD_SIZE, memory_end); | |
785 | INITRD_START = INITRD_SIZE = 0; | |
786 | } else { | |
787 | printk("Moving initrd (0x%08lx -> 0x%08lx, " | |
788 | "size: %ld)\n", | |
789 | INITRD_START, start, INITRD_SIZE); | |
790 | memmove((void *) start, (void *) INITRD_START, | |
791 | INITRD_SIZE); | |
792 | INITRD_START = start; | |
793 | } | |
794 | } | |
795 | } | |
796 | #endif | |
797 | ||
1da177e4 | 798 | /* |
7676bef9 | 799 | * Initialize the boot-time allocator |
1da177e4 LT |
800 | */ |
801 | bootmap_size = init_bootmem(start_pfn, end_pfn); | |
802 | ||
803 | /* | |
804 | * Register RAM areas with the bootmem allocator. | |
805 | */ | |
c9e37353 | 806 | |
0b642ede | 807 | for (i = 0; i < MEMORY_CHUNKS && memory_chunk[i].size > 0; i++) { |
39b742f9 | 808 | unsigned long start_chunk, end_chunk, pfn; |
1da177e4 LT |
809 | |
810 | if (memory_chunk[i].type != CHUNK_READ_WRITE) | |
811 | continue; | |
39b742f9 HC |
812 | start_chunk = PFN_DOWN(memory_chunk[i].addr); |
813 | end_chunk = start_chunk + PFN_DOWN(memory_chunk[i].size) - 1; | |
814 | end_chunk = min(end_chunk, end_pfn); | |
815 | if (start_chunk >= end_chunk) | |
816 | continue; | |
817 | add_active_range(0, start_chunk, end_chunk); | |
818 | pfn = max(start_chunk, start_pfn); | |
819 | for (; pfn <= end_chunk; pfn++) | |
820 | page_set_storage_key(PFN_PHYS(pfn), PAGE_DEFAULT_KEY); | |
1da177e4 LT |
821 | } |
822 | ||
0b642ede PO |
823 | psw_set_key(PAGE_DEFAULT_KEY); |
824 | ||
39b742f9 HC |
825 | free_bootmem_with_active_regions(0, max_pfn); |
826 | reserve_bootmem(0, PFN_PHYS(start_pfn)); | |
c9e37353 HC |
827 | |
828 | /* | |
829 | * Reserve the bootmem bitmap itself as well. We do this in two | |
830 | * steps (first step was init_bootmem()) because this catches | |
831 | * the (very unlikely) case of us accidentally initializing the | |
832 | * bootmem allocator with an invalid RAM area. | |
833 | */ | |
834 | reserve_bootmem(start_pfn << PAGE_SHIFT, bootmap_size); | |
1da177e4 LT |
835 | |
836 | #ifdef CONFIG_BLK_DEV_INITRD | |
65912a84 | 837 | if (INITRD_START && INITRD_SIZE) { |
1da177e4 LT |
838 | if (INITRD_START + INITRD_SIZE <= memory_end) { |
839 | reserve_bootmem(INITRD_START, INITRD_SIZE); | |
840 | initrd_start = INITRD_START; | |
841 | initrd_end = initrd_start + INITRD_SIZE; | |
842 | } else { | |
c9e37353 HC |
843 | printk("initrd extends beyond end of memory " |
844 | "(0x%08lx > 0x%08lx)\ndisabling initrd\n", | |
845 | initrd_start + INITRD_SIZE, memory_end); | |
846 | initrd_start = initrd_end = 0; | |
1da177e4 | 847 | } |
c9e37353 | 848 | } |
1da177e4 | 849 | #endif |
c9e37353 | 850 | } |
1da177e4 | 851 | |
c9e37353 HC |
852 | /* |
853 | * Setup function called from init/main.c just after the banner | |
854 | * was printed. | |
855 | */ | |
1da177e4 | 856 | |
c9e37353 HC |
857 | void __init |
858 | setup_arch(char **cmdline_p) | |
859 | { | |
1da177e4 | 860 | /* |
c9e37353 | 861 | * print what head.S has found out about the machine |
1da177e4 | 862 | */ |
347a8dc3 | 863 | #ifndef CONFIG_64BIT |
c9e37353 HC |
864 | printk((MACHINE_IS_VM) ? |
865 | "We are running under VM (31 bit mode)\n" : | |
866 | "We are running native (31 bit mode)\n"); | |
867 | printk((MACHINE_HAS_IEEE) ? | |
868 | "This machine has an IEEE fpu\n" : | |
869 | "This machine has no IEEE fpu\n"); | |
347a8dc3 | 870 | #else /* CONFIG_64BIT */ |
c9e37353 HC |
871 | printk((MACHINE_IS_VM) ? |
872 | "We are running under VM (64 bit mode)\n" : | |
873 | "We are running native (64 bit mode)\n"); | |
347a8dc3 | 874 | #endif /* CONFIG_64BIT */ |
c9e37353 | 875 | |
59685296 HC |
876 | /* Save unparsed command line copy for /proc/cmdline */ |
877 | strlcpy(saved_command_line, COMMAND_LINE, COMMAND_LINE_SIZE); | |
878 | ||
879 | *cmdline_p = COMMAND_LINE; | |
880 | *(*cmdline_p + COMMAND_LINE_SIZE - 1) = '\0'; | |
881 | ||
c9e37353 | 882 | ROOT_DEV = Root_RAM0; |
59685296 HC |
883 | |
884 | init_mm.start_code = PAGE_OFFSET; | |
885 | init_mm.end_code = (unsigned long) &_etext; | |
886 | init_mm.end_data = (unsigned long) &_edata; | |
887 | init_mm.brk = (unsigned long) &_end; | |
888 | ||
6c2a9e6d GS |
889 | if (MACHINE_HAS_MVCOS) |
890 | memcpy(&uaccess, &uaccess_mvcos, sizeof(uaccess)); | |
891 | else | |
892 | memcpy(&uaccess, &uaccess_std, sizeof(uaccess)); | |
893 | ||
59685296 HC |
894 | parse_early_param(); |
895 | ||
8b62bc96 | 896 | setup_memory_end(); |
c1821c2e | 897 | setup_addressing_mode(); |
c9e37353 HC |
898 | setup_memory(); |
899 | setup_resources(); | |
900 | setup_lowcore(); | |
901 | ||
1da177e4 LT |
902 | cpu_init(); |
903 | __cpu_logical_map[0] = S390_lowcore.cpu_data.cpu_addr; | |
255acee7 | 904 | smp_setup_cpu_possible_map(); |
1da177e4 LT |
905 | |
906 | /* | |
907 | * Create kernel page tables and switch to virtual addressing. | |
908 | */ | |
909 | paging_init(); | |
910 | ||
911 | /* Setup default console */ | |
912 | conmode_default(); | |
913 | } | |
914 | ||
915 | void print_cpu_info(struct cpuinfo_S390 *cpuinfo) | |
916 | { | |
917 | printk("cpu %d " | |
918 | #ifdef CONFIG_SMP | |
919 | "phys_idx=%d " | |
920 | #endif | |
921 | "vers=%02X ident=%06X machine=%04X unused=%04X\n", | |
922 | cpuinfo->cpu_nr, | |
923 | #ifdef CONFIG_SMP | |
924 | cpuinfo->cpu_addr, | |
925 | #endif | |
926 | cpuinfo->cpu_id.version, | |
927 | cpuinfo->cpu_id.ident, | |
928 | cpuinfo->cpu_id.machine, | |
929 | cpuinfo->cpu_id.unused); | |
930 | } | |
931 | ||
932 | /* | |
933 | * show_cpuinfo - Get information on one CPU for use by procfs. | |
934 | */ | |
935 | ||
936 | static int show_cpuinfo(struct seq_file *m, void *v) | |
937 | { | |
938 | struct cpuinfo_S390 *cpuinfo; | |
939 | unsigned long n = (unsigned long) v - 1; | |
940 | ||
b7ae9dd8 | 941 | preempt_disable(); |
1da177e4 LT |
942 | if (!n) { |
943 | seq_printf(m, "vendor_id : IBM/S390\n" | |
944 | "# processors : %i\n" | |
945 | "bogomips per cpu: %lu.%02lu\n", | |
946 | num_online_cpus(), loops_per_jiffy/(500000/HZ), | |
947 | (loops_per_jiffy/(5000/HZ))%100); | |
948 | } | |
949 | if (cpu_online(n)) { | |
950 | #ifdef CONFIG_SMP | |
951 | if (smp_processor_id() == n) | |
952 | cpuinfo = &S390_lowcore.cpu_data; | |
953 | else | |
954 | cpuinfo = &lowcore_ptr[n]->cpu_data; | |
955 | #else | |
956 | cpuinfo = &S390_lowcore.cpu_data; | |
957 | #endif | |
958 | seq_printf(m, "processor %li: " | |
959 | "version = %02X, " | |
960 | "identification = %06X, " | |
961 | "machine = %04X\n", | |
962 | n, cpuinfo->cpu_id.version, | |
963 | cpuinfo->cpu_id.ident, | |
964 | cpuinfo->cpu_id.machine); | |
965 | } | |
b7ae9dd8 | 966 | preempt_enable(); |
1da177e4 LT |
967 | return 0; |
968 | } | |
969 | ||
970 | static void *c_start(struct seq_file *m, loff_t *pos) | |
971 | { | |
972 | return *pos < NR_CPUS ? (void *)((unsigned long) *pos + 1) : NULL; | |
973 | } | |
974 | static void *c_next(struct seq_file *m, void *v, loff_t *pos) | |
975 | { | |
976 | ++*pos; | |
977 | return c_start(m, pos); | |
978 | } | |
979 | static void c_stop(struct seq_file *m, void *v) | |
980 | { | |
981 | } | |
982 | struct seq_operations cpuinfo_op = { | |
983 | .start = c_start, | |
984 | .next = c_next, | |
985 | .stop = c_stop, | |
986 | .show = show_cpuinfo, | |
987 | }; | |
988 |