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