]>
Commit | Line | Data |
---|---|---|
b2441318 | 1 | // SPDX-License-Identifier: GPL-2.0 |
ab14de6c | 2 | /* |
155af2f9 | 3 | * Copyright IBM Corp. 2007, 2009 |
ab14de6c HC |
4 | * Author(s): Hongjie Yang <hongjie@us.ibm.com>, |
5 | * Heiko Carstens <heiko.carstens@de.ibm.com> | |
6 | */ | |
7 | ||
11af97e1 HB |
8 | #define KMSG_COMPONENT "setup" |
9 | #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt | |
10 | ||
92e6ecf3 | 11 | #include <linux/compiler.h> |
ab14de6c HC |
12 | #include <linux/init.h> |
13 | #include <linux/errno.h> | |
14 | #include <linux/string.h> | |
15 | #include <linux/ctype.h> | |
16 | #include <linux/lockdep.h> | |
dcc096c5 | 17 | #include <linux/extable.h> |
ab14de6c HC |
18 | #include <linux/pfn.h> |
19 | #include <linux/uaccess.h> | |
11af97e1 | 20 | #include <linux/kernel.h> |
1ec2772e | 21 | #include <asm/diag.h> |
a0443fbb | 22 | #include <asm/ebcdic.h> |
46b05d26 | 23 | #include <asm/ipl.h> |
ab14de6c HC |
24 | #include <asm/lowcore.h> |
25 | #include <asm/processor.h> | |
26 | #include <asm/sections.h> | |
27 | #include <asm/setup.h> | |
92e6ecf3 | 28 | #include <asm/sysinfo.h> |
ab14de6c HC |
29 | #include <asm/cpcmd.h> |
30 | #include <asm/sclp.h> | |
a0616cde | 31 | #include <asm/facility.h> |
a806170e | 32 | #include "entry.h" |
ab14de6c HC |
33 | |
34 | /* | |
35 | * Create a Kernel NSS if the SAVESYS= parameter is defined | |
36 | */ | |
a0443fbb | 37 | #define DEFSYS_CMD_SIZE 128 |
ab14de6c HC |
38 | #define SAVESYS_CMD_SIZE 32 |
39 | ||
ab14de6c HC |
40 | char kernel_nss_name[NSS_NAME_SIZE + 1]; |
41 | ||
a0443fbb HB |
42 | static void __init setup_boot_command_line(void); |
43 | ||
b6112ccb MS |
44 | /* |
45 | * Get the TOD clock running. | |
46 | */ | |
47 | static void __init reset_tod_clock(void) | |
48 | { | |
49 | u64 time; | |
50 | ||
1aae0560 | 51 | if (store_tod_clock(&time) == 0) |
b6112ccb MS |
52 | return; |
53 | /* TOD clock not running. Set the clock to Unix Epoch. */ | |
1aae0560 | 54 | if (set_tod_clock(TOD_UNIX_EPOCH) != 0 || store_tod_clock(&time) != 0) |
b6112ccb MS |
55 | disabled_wait(0); |
56 | ||
6e2ef5e4 MS |
57 | memset(tod_clock_base, 0, 16); |
58 | *(__u64 *) &tod_clock_base[1] = TOD_UNIX_EPOCH; | |
59 | S390_lowcore.last_update_clock = TOD_UNIX_EPOCH; | |
b6112ccb | 60 | } |
a0443fbb | 61 | |
ab14de6c | 62 | #ifdef CONFIG_SHARED_KERNEL |
a0443fbb HB |
63 | int __init savesys_ipl_nss(char *cmd, const int cmdlen); |
64 | ||
65 | asm( | |
66 | " .section .init.text,\"ax\",@progbits\n" | |
67 | " .align 4\n" | |
68 | " .type savesys_ipl_nss, @function\n" | |
69 | "savesys_ipl_nss:\n" | |
a0443fbb HB |
70 | " stmg 6,15,48(15)\n" |
71 | " lgr 14,3\n" | |
72 | " sam31\n" | |
73 | " diag 2,14,0x8\n" | |
74 | " sam64\n" | |
75 | " lgr 2,14\n" | |
76 | " lmg 6,15,48(15)\n" | |
a0443fbb | 77 | " br 14\n" |
18764463 HC |
78 | " .size savesys_ipl_nss, .-savesys_ipl_nss\n" |
79 | " .previous\n"); | |
a0443fbb | 80 | |
684d2fd4 HB |
81 | static __initdata char upper_command_line[COMMAND_LINE_SIZE]; |
82 | ||
ab14de6c HC |
83 | static noinline __init void create_kernel_nss(void) |
84 | { | |
85 | unsigned int i, stext_pfn, eshared_pfn, end_pfn, min_size; | |
86 | #ifdef CONFIG_BLK_DEV_INITRD | |
87 | unsigned int sinitrd_pfn, einitrd_pfn; | |
88 | #endif | |
89 | int response; | |
69ac43b0 | 90 | int hlen; |
a0443fbb | 91 | size_t len; |
ab14de6c | 92 | char *savesys_ptr; |
ab14de6c HC |
93 | char defsys_cmd[DEFSYS_CMD_SIZE]; |
94 | char savesys_cmd[SAVESYS_CMD_SIZE]; | |
95 | ||
96 | /* Do nothing if we are not running under VM */ | |
97 | if (!MACHINE_IS_VM) | |
98 | return; | |
99 | ||
100 | /* Convert COMMAND_LINE to upper case */ | |
a0443fbb HB |
101 | for (i = 0; i < strlen(boot_command_line); i++) |
102 | upper_command_line[i] = toupper(boot_command_line[i]); | |
ab14de6c HC |
103 | |
104 | savesys_ptr = strstr(upper_command_line, "SAVESYS="); | |
105 | ||
106 | if (!savesys_ptr) | |
107 | return; | |
108 | ||
109 | savesys_ptr += 8; /* Point to the beginning of the NSS name */ | |
110 | for (i = 0; i < NSS_NAME_SIZE; i++) { | |
111 | if (savesys_ptr[i] == ' ' || savesys_ptr[i] == '\0') | |
112 | break; | |
113 | kernel_nss_name[i] = savesys_ptr[i]; | |
114 | } | |
115 | ||
116 | stext_pfn = PFN_DOWN(__pa(&_stext)); | |
117 | eshared_pfn = PFN_DOWN(__pa(&_eshared)); | |
118 | end_pfn = PFN_UP(__pa(&_end)); | |
119 | min_size = end_pfn << 2; | |
120 | ||
69ac43b0 CL |
121 | hlen = snprintf(defsys_cmd, DEFSYS_CMD_SIZE, |
122 | "DEFSYS %s 00000-%.5X EW %.5X-%.5X SR %.5X-%.5X", | |
123 | kernel_nss_name, stext_pfn - 1, stext_pfn, | |
124 | eshared_pfn - 1, eshared_pfn, end_pfn); | |
ab14de6c HC |
125 | |
126 | #ifdef CONFIG_BLK_DEV_INITRD | |
127 | if (INITRD_START && INITRD_SIZE) { | |
128 | sinitrd_pfn = PFN_DOWN(__pa(INITRD_START)); | |
129 | einitrd_pfn = PFN_UP(__pa(INITRD_START + INITRD_SIZE)); | |
130 | min_size = einitrd_pfn << 2; | |
69ac43b0 CL |
131 | hlen += snprintf(defsys_cmd + hlen, DEFSYS_CMD_SIZE - hlen, |
132 | " EW %.5X-%.5X", sinitrd_pfn, einitrd_pfn); | |
ab14de6c HC |
133 | } |
134 | #endif | |
135 | ||
69ac43b0 CL |
136 | snprintf(defsys_cmd + hlen, DEFSYS_CMD_SIZE - hlen, |
137 | " EW MINSIZE=%.7iK PARMREGS=0-13", min_size); | |
138 | defsys_cmd[DEFSYS_CMD_SIZE - 1] = '\0'; | |
894e491e HC |
139 | snprintf(savesys_cmd, SAVESYS_CMD_SIZE, "SAVESYS %s \n IPL %s", |
140 | kernel_nss_name, kernel_nss_name); | |
141 | savesys_cmd[SAVESYS_CMD_SIZE - 1] = '\0'; | |
ab14de6c HC |
142 | |
143 | __cpcmd(defsys_cmd, NULL, 0, &response); | |
144 | ||
583b33bc | 145 | if (response != 0) { |
11af97e1 HB |
146 | pr_err("Defining the Linux kernel NSS failed with rc=%d\n", |
147 | response); | |
583b33bc | 148 | kernel_nss_name[0] = '\0'; |
ab14de6c | 149 | return; |
583b33bc | 150 | } |
ab14de6c | 151 | |
a0443fbb HB |
152 | len = strlen(savesys_cmd); |
153 | ASCEBC(savesys_cmd, len); | |
154 | response = savesys_ipl_nss(savesys_cmd, len); | |
ab14de6c | 155 | |
a0443fbb HB |
156 | /* On success: response is equal to the command size, |
157 | * max SAVESYS_CMD_SIZE | |
158 | * On error: response contains the numeric portion of cp error message. | |
159 | * for SAVESYS it will be >= 263 | |
11af97e1 | 160 | * for missing privilege class, it will be 1 |
a0443fbb | 161 | */ |
11af97e1 HB |
162 | if (response > SAVESYS_CMD_SIZE || response == 1) { |
163 | pr_err("Saving the Linux kernel NSS failed with rc=%d\n", | |
164 | response); | |
583b33bc | 165 | kernel_nss_name[0] = '\0'; |
ab14de6c | 166 | return; |
583b33bc | 167 | } |
ab14de6c | 168 | |
b89031e0 | 169 | /* re-initialize cputime accounting. */ |
6e2ef5e4 MS |
170 | get_tod_clock_ext(tod_clock_base); |
171 | S390_lowcore.last_update_clock = *(__u64 *) &tod_clock_base[1]; | |
b89031e0 MS |
172 | S390_lowcore.last_update_timer = 0x7fffffffffffffffULL; |
173 | S390_lowcore.user_timer = 0; | |
174 | S390_lowcore.system_timer = 0; | |
175 | asm volatile("SPT 0(%0)" : : "a" (&S390_lowcore.last_update_timer)); | |
176 | ||
a0443fbb HB |
177 | /* re-setup boot command line with new ipl vm parms */ |
178 | ipl_update_parameters(); | |
179 | setup_boot_command_line(); | |
180 | ||
ab14de6c HC |
181 | ipl_flags = IPL_NSS_VALID; |
182 | } | |
183 | ||
184 | #else /* CONFIG_SHARED_KERNEL */ | |
185 | ||
186 | static inline void create_kernel_nss(void) { } | |
187 | ||
188 | #endif /* CONFIG_SHARED_KERNEL */ | |
189 | ||
190 | /* | |
191 | * Clear bss memory | |
192 | */ | |
193 | static noinline __init void clear_bss_section(void) | |
194 | { | |
229d9c6d | 195 | memset(__bss_start, 0, __bss_stop - __bss_start); |
ab14de6c HC |
196 | } |
197 | ||
198 | /* | |
199 | * Initialize storage key for kernel pages | |
200 | */ | |
201 | static noinline __init void init_kernel_storage_key(void) | |
202 | { | |
127c1fef | 203 | #if PAGE_DEFAULT_KEY |
ab14de6c HC |
204 | unsigned long end_pfn, init_pfn; |
205 | ||
206 | end_pfn = PFN_UP(__pa(&_end)); | |
207 | ||
208 | for (init_pfn = 0 ; init_pfn < end_pfn; init_pfn++) | |
e2b8d7af MS |
209 | page_set_storage_key(init_pfn << PAGE_SHIFT, |
210 | PAGE_DEFAULT_KEY, 0); | |
127c1fef | 211 | #endif |
ab14de6c HC |
212 | } |
213 | ||
fade4dc4 | 214 | static __initdata char sysinfo_page[PAGE_SIZE] __aligned(PAGE_SIZE); |
92e6ecf3 | 215 | |
ab14de6c HC |
216 | static noinline __init void detect_machine_type(void) |
217 | { | |
fade4dc4 HC |
218 | struct sysinfo_3_2_2 *vmms = (struct sysinfo_3_2_2 *)&sysinfo_page; |
219 | ||
27d71602 | 220 | /* Check current-configuration-level */ |
caf757c6 | 221 | if (stsi(NULL, 0, 0, 0) <= 2) { |
27d71602 | 222 | S390_lowcore.machine_flags |= MACHINE_FLAG_LPAR; |
92e6ecf3 | 223 | return; |
27d71602 MS |
224 | } |
225 | /* Get virtual-machine cpu information. */ | |
caf757c6 | 226 | if (stsi(vmms, 3, 2, 2) || !vmms->count) |
92e6ecf3 | 227 | return; |
ab14de6c | 228 | |
92e6ecf3 | 229 | /* Running under KVM? If not we assume z/VM */ |
fade4dc4 | 230 | if (!memcmp(vmms->vm[0].cpi, "\xd2\xe5\xd4", 3)) |
d3135e0c | 231 | S390_lowcore.machine_flags |= MACHINE_FLAG_KVM; |
92e6ecf3 | 232 | else |
d3135e0c | 233 | S390_lowcore.machine_flags |= MACHINE_FLAG_VM; |
ab14de6c HC |
234 | } |
235 | ||
d2f03974 HC |
236 | /* Remove leading, trailing and double whitespace. */ |
237 | static inline void strim_all(char *str) | |
238 | { | |
239 | char *s; | |
240 | ||
241 | s = strim(str); | |
242 | if (s != str) | |
243 | memmove(str, s, strlen(s)); | |
244 | while (*str) { | |
245 | if (!isspace(*str++)) | |
246 | continue; | |
247 | if (isspace(*str)) { | |
248 | s = skip_spaces(str); | |
249 | memmove(str, s, strlen(s) + 1); | |
250 | } | |
251 | } | |
252 | } | |
253 | ||
4b8fe77a CB |
254 | static noinline __init void setup_arch_string(void) |
255 | { | |
256 | struct sysinfo_1_1_1 *mach = (struct sysinfo_1_1_1 *)&sysinfo_page; | |
2f8876f9 HC |
257 | struct sysinfo_3_2_2 *vm = (struct sysinfo_3_2_2 *)&sysinfo_page; |
258 | char mstr[80], hvstr[17]; | |
4b8fe77a CB |
259 | |
260 | if (stsi(mach, 1, 1, 1)) | |
261 | return; | |
262 | EBCASC(mach->manufacturer, sizeof(mach->manufacturer)); | |
263 | EBCASC(mach->type, sizeof(mach->type)); | |
264 | EBCASC(mach->model, sizeof(mach->model)); | |
265 | EBCASC(mach->model_capacity, sizeof(mach->model_capacity)); | |
d2f03974 HC |
266 | sprintf(mstr, "%-16.16s %-4.4s %-16.16s %-16.16s", |
267 | mach->manufacturer, mach->type, | |
268 | mach->model, mach->model_capacity); | |
269 | strim_all(mstr); | |
2f8876f9 HC |
270 | if (stsi(vm, 3, 2, 2) == 0 && vm->count) { |
271 | EBCASC(vm->vm[0].cpi, sizeof(vm->vm[0].cpi)); | |
272 | sprintf(hvstr, "%-16.16s", vm->vm[0].cpi); | |
273 | strim_all(hvstr); | |
274 | } else { | |
275 | sprintf(hvstr, "%s", | |
276 | MACHINE_IS_LPAR ? "LPAR" : | |
277 | MACHINE_IS_VM ? "z/VM" : | |
278 | MACHINE_IS_KVM ? "KVM" : "unknown"); | |
279 | } | |
280 | dump_stack_set_arch_desc("%s (%s)", mstr, hvstr); | |
4b8fe77a CB |
281 | } |
282 | ||
fade4dc4 HC |
283 | static __init void setup_topology(void) |
284 | { | |
fade4dc4 HC |
285 | int max_mnest; |
286 | ||
287 | if (!test_facility(11)) | |
288 | return; | |
289 | S390_lowcore.machine_flags |= MACHINE_FLAG_TOPOLOGY; | |
290 | for (max_mnest = 6; max_mnest > 1; max_mnest--) { | |
caf757c6 | 291 | if (stsi(&sysinfo_page, 15, 1, max_mnest) == 0) |
fade4dc4 HC |
292 | break; |
293 | } | |
294 | topology_max_mnest = max_mnest; | |
fade4dc4 HC |
295 | } |
296 | ||
a3415703 | 297 | static void early_pgm_check_handler(void) |
ab14de6c | 298 | { |
ab14de6c | 299 | const struct exception_table_entry *fixup; |
50be6345 | 300 | unsigned long cr0, cr0_new; |
eb608fb3 | 301 | unsigned long addr; |
ab14de6c HC |
302 | |
303 | addr = S390_lowcore.program_old_psw.addr; | |
9cb1ccec | 304 | fixup = search_exception_tables(addr); |
ab14de6c HC |
305 | if (!fixup) |
306 | disabled_wait(0); | |
50be6345 PH |
307 | /* Disable low address protection before storing into lowcore. */ |
308 | __ctl_store(cr0, 0, 0); | |
309 | cr0_new = cr0 & ~(1UL << 28); | |
310 | __ctl_load(cr0_new, 0, 0); | |
fecc868a | 311 | S390_lowcore.program_old_psw.addr = extable_fixup(fixup); |
50be6345 | 312 | __ctl_load(cr0, 0, 0); |
ab14de6c HC |
313 | } |
314 | ||
5f954c34 | 315 | static noinline __init void setup_lowcore_early(void) |
ab14de6c HC |
316 | { |
317 | psw_t psw; | |
318 | ||
b50511e4 | 319 | psw.mask = PSW_MASK_BASE | PSW_DEFAULT_KEY | PSW_MASK_EA | PSW_MASK_BA; |
fecc868a | 320 | psw.addr = (unsigned long) s390_base_ext_handler; |
ab14de6c | 321 | S390_lowcore.external_new_psw = psw; |
fecc868a | 322 | psw.addr = (unsigned long) s390_base_pgm_handler; |
ab14de6c HC |
323 | S390_lowcore.program_new_psw = psw; |
324 | s390_base_pgm_handler_fn = early_pgm_check_handler; | |
c360192b | 325 | S390_lowcore.preempt_count = INIT_PREEMPT_COUNT; |
ab14de6c HC |
326 | } |
327 | ||
14375bc4 MS |
328 | static noinline __init void setup_facility_list(void) |
329 | { | |
3ab121ab MH |
330 | stfle(S390_lowcore.stfle_fac_list, |
331 | ARRAY_SIZE(S390_lowcore.stfle_fac_list)); | |
14375bc4 MS |
332 | } |
333 | ||
2e5061e4 HC |
334 | static __init void detect_diag9c(void) |
335 | { | |
336 | unsigned int cpu_address; | |
337 | int rc; | |
338 | ||
339 | cpu_address = stap(); | |
1ec2772e | 340 | diag_stat_inc(DIAG_STAT_X09C); |
2e5061e4 HC |
341 | asm volatile( |
342 | " diag %2,0,0x9c\n" | |
343 | "0: la %0,0\n" | |
344 | "1:\n" | |
345 | EX_TABLE(0b,1b) | |
346 | : "=d" (rc) : "0" (-EOPNOTSUPP), "d" (cpu_address) : "cc"); | |
347 | if (!rc) | |
d3135e0c | 348 | S390_lowcore.machine_flags |= MACHINE_FLAG_DIAG9C; |
2e5061e4 HC |
349 | } |
350 | ||
351 | static __init void detect_diag44(void) | |
352 | { | |
2e5061e4 HC |
353 | int rc; |
354 | ||
1ec2772e | 355 | diag_stat_inc(DIAG_STAT_X044); |
2e5061e4 HC |
356 | asm volatile( |
357 | " diag 0,0,0x44\n" | |
358 | "0: la %0,0\n" | |
359 | "1:\n" | |
360 | EX_TABLE(0b,1b) | |
361 | : "=d" (rc) : "0" (-EOPNOTSUPP) : "cc"); | |
362 | if (!rc) | |
d3135e0c | 363 | S390_lowcore.machine_flags |= MACHINE_FLAG_DIAG44; |
2e5061e4 HC |
364 | } |
365 | ||
366 | static __init void detect_machine_facilities(void) | |
367 | { | |
3c7ef08b HC |
368 | if (test_facility(8)) { |
369 | S390_lowcore.machine_flags |= MACHINE_FLAG_EDAT1; | |
370 | __ctl_set_bit(0, 23); | |
371 | } | |
85e9d0e5 HC |
372 | if (test_facility(78)) |
373 | S390_lowcore.machine_flags |= MACHINE_FLAG_EDAT2; | |
14375bc4 | 374 | if (test_facility(3)) |
d3135e0c | 375 | S390_lowcore.machine_flags |= MACHINE_FLAG_IDTE; |
14375bc4 | 376 | if (test_facility(40)) |
23d18e8d | 377 | S390_lowcore.machine_flags |= MACHINE_FLAG_LPP; |
d35339a4 MS |
378 | if (test_facility(50) && test_facility(73)) |
379 | S390_lowcore.machine_flags |= MACHINE_FLAG_TE; | |
1b948d6c MS |
380 | if (test_facility(51)) |
381 | S390_lowcore.machine_flags |= MACHINE_FLAG_TLB_LC; | |
b5510d9b | 382 | if (test_facility(129)) { |
80703617 | 383 | S390_lowcore.machine_flags |= MACHINE_FLAG_VX; |
b5510d9b HB |
384 | __ctl_set_bit(0, 17); |
385 | } | |
57d7f939 MS |
386 | if (test_facility(130)) { |
387 | S390_lowcore.machine_flags |= MACHINE_FLAG_NX; | |
388 | __ctl_set_bit(0, 20); | |
389 | } | |
916cda1a MS |
390 | if (test_facility(133)) |
391 | S390_lowcore.machine_flags |= MACHINE_FLAG_GS; | |
6e2ef5e4 MS |
392 | if (test_facility(139) && (tod_clock_base[1] & 0x80)) { |
393 | /* Enabled signed clock comparator comparisons */ | |
394 | S390_lowcore.machine_flags |= MACHINE_FLAG_SCC; | |
395 | clock_comparator_max = -1ULL >> 1; | |
396 | __ctl_set_bit(0, 53); | |
397 | } | |
b5510d9b HB |
398 | } |
399 | ||
1a36a39e MS |
400 | static inline void save_vector_registers(void) |
401 | { | |
402 | #ifdef CONFIG_CRASH_DUMP | |
403 | if (test_facility(129)) | |
404 | save_vx_regs(boot_cpu_vector_save_area); | |
405 | #endif | |
406 | } | |
407 | ||
b5510d9b HB |
408 | static int __init disable_vector_extension(char *str) |
409 | { | |
410 | S390_lowcore.machine_flags &= ~MACHINE_FLAG_VX; | |
411 | __ctl_clear_bit(0, 17); | |
673cfddf | 412 | return 0; |
2e5061e4 | 413 | } |
b5510d9b | 414 | early_param("novx", disable_vector_extension); |
2e5061e4 | 415 | |
57d7f939 MS |
416 | static int __init noexec_setup(char *str) |
417 | { | |
418 | bool enabled; | |
419 | int rc; | |
420 | ||
421 | rc = kstrtobool(str, &enabled); | |
422 | if (!rc && !enabled) { | |
423 | /* Disable no-execute support */ | |
424 | S390_lowcore.machine_flags &= ~MACHINE_FLAG_NX; | |
425 | __ctl_clear_bit(0, 20); | |
426 | } | |
427 | return rc; | |
428 | } | |
429 | early_param("noexec", noexec_setup); | |
430 | ||
61b0b016 | 431 | static int __init cad_setup(char *str) |
2c72a44e | 432 | { |
b13de4b7 MS |
433 | bool enabled; |
434 | int rc; | |
2c72a44e | 435 | |
b13de4b7 MS |
436 | rc = kstrtobool(str, &enabled); |
437 | if (!rc && enabled && test_facility(128)) | |
2c72a44e MS |
438 | /* Enable problem state CAD. */ |
439 | __ctl_set_bit(2, 3); | |
b13de4b7 | 440 | return rc; |
2c72a44e | 441 | } |
b13de4b7 | 442 | early_param("cad", cad_setup); |
2c72a44e | 443 | |
d543a106 HC |
444 | static __init void memmove_early(void *dst, const void *src, size_t n) |
445 | { | |
446 | unsigned long addr; | |
447 | long incr; | |
448 | psw_t old; | |
449 | ||
450 | if (!n) | |
451 | return; | |
452 | incr = 1; | |
453 | if (dst > src) { | |
454 | incr = -incr; | |
455 | dst += n - 1; | |
456 | src += n - 1; | |
457 | } | |
458 | old = S390_lowcore.program_new_psw; | |
459 | S390_lowcore.program_new_psw.mask = __extract_psw(); | |
460 | asm volatile( | |
461 | " larl %[addr],1f\n" | |
462 | " stg %[addr],%[psw_pgm_addr]\n" | |
463 | "0: mvc 0(1,%[dst]),0(%[src])\n" | |
464 | " agr %[dst],%[incr]\n" | |
465 | " agr %[src],%[incr]\n" | |
466 | " brctg %[n],0b\n" | |
467 | "1:\n" | |
468 | : [addr] "=&d" (addr), | |
75a35734 | 469 | [psw_pgm_addr] "=Q" (S390_lowcore.program_new_psw.addr), |
d543a106 HC |
470 | [dst] "+&a" (dst), [src] "+&a" (src), [n] "+d" (n) |
471 | : [incr] "d" (incr) | |
472 | : "cc", "memory"); | |
473 | S390_lowcore.program_new_psw = old; | |
474 | } | |
475 | ||
476 | static __init noinline void ipl_save_parameters(void) | |
477 | { | |
478 | void *src, *dst; | |
479 | ||
480 | src = (void *)(unsigned long) S390_lowcore.ipl_parmblock_ptr; | |
481 | dst = (void *) IPL_PARMBLOCK_ORIGIN; | |
482 | memmove_early(dst, src, PAGE_SIZE); | |
483 | S390_lowcore.ipl_parmblock_ptr = IPL_PARMBLOCK_ORIGIN; | |
484 | } | |
485 | ||
486 | static __init noinline void rescue_initrd(void) | |
761cdf6a HC |
487 | { |
488 | #ifdef CONFIG_BLK_DEV_INITRD | |
27e7318c | 489 | unsigned long min_initrd_addr = (unsigned long) _end + (4UL << 20); |
761cdf6a | 490 | /* |
27e7318c HC |
491 | * Just like in case of IPL from VM reader we make sure there is a |
492 | * gap of 4MB between end of kernel and start of initrd. | |
493 | * That way we can also be sure that saving an NSS will succeed, | |
494 | * which however only requires different segments. | |
761cdf6a HC |
495 | */ |
496 | if (!INITRD_START || !INITRD_SIZE) | |
497 | return; | |
27e7318c | 498 | if (INITRD_START >= min_initrd_addr) |
761cdf6a | 499 | return; |
d543a106 | 500 | memmove_early((void *) min_initrd_addr, (void *) INITRD_START, INITRD_SIZE); |
27e7318c | 501 | INITRD_START = min_initrd_addr; |
761cdf6a HC |
502 | #endif |
503 | } | |
504 | ||
a0443fbb | 505 | /* Set up boot command line */ |
684d2fd4 | 506 | static void __init append_to_cmdline(size_t (*ipl_data)(char *, size_t)) |
a0443fbb | 507 | { |
684d2fd4 HB |
508 | char *parm, *delim; |
509 | size_t rc, len; | |
510 | ||
511 | len = strlen(boot_command_line); | |
a0443fbb | 512 | |
684d2fd4 HB |
513 | delim = boot_command_line + len; /* '\0' character position */ |
514 | parm = boot_command_line + len + 1; /* append right after '\0' */ | |
515 | ||
516 | rc = ipl_data(parm, COMMAND_LINE_SIZE - len - 1); | |
517 | if (rc) { | |
518 | if (*parm == '=') | |
519 | memmove(boot_command_line, parm + 1, rc); | |
520 | else | |
521 | *delim = ' '; /* replace '\0' with space */ | |
522 | } | |
523 | } | |
524 | ||
1fb81057 | 525 | static inline int has_ebcdic_char(const char *str) |
684d2fd4 | 526 | { |
61fd330d MS |
527 | int i; |
528 | ||
1fb81057 MH |
529 | for (i = 0; str[i]; i++) |
530 | if (str[i] & 0x80) | |
531 | return 1; | |
532 | return 0; | |
533 | } | |
61fd330d | 534 | |
1fb81057 MH |
535 | static void __init setup_boot_command_line(void) |
536 | { | |
537 | COMMAND_LINE[ARCH_COMMAND_LINE_SIZE - 1] = 0; | |
538 | /* convert arch command line to ascii if necessary */ | |
539 | if (has_ebcdic_char(COMMAND_LINE)) | |
540 | EBCASC(COMMAND_LINE, ARCH_COMMAND_LINE_SIZE); | |
a0443fbb | 541 | /* copy arch command line */ |
61fd330d MS |
542 | strlcpy(boot_command_line, strstrip(COMMAND_LINE), |
543 | ARCH_COMMAND_LINE_SIZE); | |
a0443fbb HB |
544 | |
545 | /* append IPL PARM data to the boot command line */ | |
684d2fd4 HB |
546 | if (MACHINE_IS_VM) |
547 | append_to_cmdline(append_ipl_vmparm); | |
548 | ||
549 | append_to_cmdline(append_ipl_scpdata); | |
a0443fbb HB |
550 | } |
551 | ||
ab14de6c HC |
552 | /* |
553 | * Save ipl parameters, clear bss memory, initialize storage keys | |
554 | * and create a kernel NSS at startup if the SAVESYS= parm is defined | |
555 | */ | |
556 | void __init startup_init(void) | |
557 | { | |
b6112ccb | 558 | reset_tod_clock(); |
ab14de6c | 559 | ipl_save_parameters(); |
761cdf6a | 560 | rescue_initrd(); |
ab14de6c | 561 | clear_bss_section(); |
d543a106 | 562 | ipl_verify_parameters(); |
b1c0854d | 563 | time_early_init(); |
ab14de6c | 564 | init_kernel_storage_key(); |
ab14de6c | 565 | lockdep_off(); |
ab14de6c | 566 | setup_lowcore_early(); |
14375bc4 | 567 | setup_facility_list(); |
a0443fbb | 568 | detect_machine_type(); |
4b8fe77a | 569 | setup_arch_string(); |
a0443fbb HB |
570 | ipl_update_parameters(); |
571 | setup_boot_command_line(); | |
572 | create_kernel_nss(); | |
2e5061e4 HC |
573 | detect_diag9c(); |
574 | detect_diag44(); | |
575 | detect_machine_facilities(); | |
1a36a39e | 576 | save_vector_registers(); |
fade4dc4 | 577 | setup_topology(); |
7b50da53 | 578 | sclp_early_detect(); |
ab14de6c HC |
579 | lockdep_on(); |
580 | } |