]>
Commit | Line | Data |
---|---|---|
ab14de6c HC |
1 | /* |
2 | * arch/s390/kernel/early.c | |
3 | * | |
4 | * Copyright IBM Corp. 2007 | |
5 | * Author(s): Hongjie Yang <hongjie@us.ibm.com>, | |
6 | * Heiko Carstens <heiko.carstens@de.ibm.com> | |
7 | */ | |
8 | ||
92e6ecf3 | 9 | #include <linux/compiler.h> |
ab14de6c HC |
10 | #include <linux/init.h> |
11 | #include <linux/errno.h> | |
12 | #include <linux/string.h> | |
13 | #include <linux/ctype.h> | |
14 | #include <linux/lockdep.h> | |
15 | #include <linux/module.h> | |
16 | #include <linux/pfn.h> | |
17 | #include <linux/uaccess.h> | |
a0443fbb | 18 | #include <asm/ebcdic.h> |
46b05d26 | 19 | #include <asm/ipl.h> |
ab14de6c HC |
20 | #include <asm/lowcore.h> |
21 | #include <asm/processor.h> | |
22 | #include <asm/sections.h> | |
23 | #include <asm/setup.h> | |
92e6ecf3 | 24 | #include <asm/sysinfo.h> |
ab14de6c HC |
25 | #include <asm/cpcmd.h> |
26 | #include <asm/sclp.h> | |
a806170e | 27 | #include "entry.h" |
ab14de6c HC |
28 | |
29 | /* | |
30 | * Create a Kernel NSS if the SAVESYS= parameter is defined | |
31 | */ | |
a0443fbb | 32 | #define DEFSYS_CMD_SIZE 128 |
ab14de6c HC |
33 | #define SAVESYS_CMD_SIZE 32 |
34 | ||
ab14de6c HC |
35 | char kernel_nss_name[NSS_NAME_SIZE + 1]; |
36 | ||
25097bf1 CE |
37 | static unsigned long machine_flags; |
38 | ||
a0443fbb HB |
39 | static void __init setup_boot_command_line(void); |
40 | ||
41 | ||
ab14de6c | 42 | #ifdef CONFIG_SHARED_KERNEL |
a0443fbb HB |
43 | int __init savesys_ipl_nss(char *cmd, const int cmdlen); |
44 | ||
45 | asm( | |
46 | " .section .init.text,\"ax\",@progbits\n" | |
47 | " .align 4\n" | |
48 | " .type savesys_ipl_nss, @function\n" | |
49 | "savesys_ipl_nss:\n" | |
50 | #ifdef CONFIG_64BIT | |
51 | " stmg 6,15,48(15)\n" | |
52 | " lgr 14,3\n" | |
53 | " sam31\n" | |
54 | " diag 2,14,0x8\n" | |
55 | " sam64\n" | |
56 | " lgr 2,14\n" | |
57 | " lmg 6,15,48(15)\n" | |
58 | #else | |
59 | " stm 6,15,24(15)\n" | |
60 | " lr 14,3\n" | |
61 | " diag 2,14,0x8\n" | |
62 | " lr 2,14\n" | |
63 | " lm 6,15,24(15)\n" | |
64 | #endif | |
65 | " br 14\n" | |
66 | " .size savesys_ipl_nss, .-savesys_ipl_nss\n"); | |
67 | ||
ab14de6c HC |
68 | static noinline __init void create_kernel_nss(void) |
69 | { | |
70 | unsigned int i, stext_pfn, eshared_pfn, end_pfn, min_size; | |
71 | #ifdef CONFIG_BLK_DEV_INITRD | |
72 | unsigned int sinitrd_pfn, einitrd_pfn; | |
73 | #endif | |
74 | int response; | |
a0443fbb | 75 | size_t len; |
ab14de6c HC |
76 | char *savesys_ptr; |
77 | char upper_command_line[COMMAND_LINE_SIZE]; | |
78 | char defsys_cmd[DEFSYS_CMD_SIZE]; | |
79 | char savesys_cmd[SAVESYS_CMD_SIZE]; | |
80 | ||
81 | /* Do nothing if we are not running under VM */ | |
82 | if (!MACHINE_IS_VM) | |
83 | return; | |
84 | ||
85 | /* Convert COMMAND_LINE to upper case */ | |
a0443fbb HB |
86 | for (i = 0; i < strlen(boot_command_line); i++) |
87 | upper_command_line[i] = toupper(boot_command_line[i]); | |
ab14de6c HC |
88 | |
89 | savesys_ptr = strstr(upper_command_line, "SAVESYS="); | |
90 | ||
91 | if (!savesys_ptr) | |
92 | return; | |
93 | ||
94 | savesys_ptr += 8; /* Point to the beginning of the NSS name */ | |
95 | for (i = 0; i < NSS_NAME_SIZE; i++) { | |
96 | if (savesys_ptr[i] == ' ' || savesys_ptr[i] == '\0') | |
97 | break; | |
98 | kernel_nss_name[i] = savesys_ptr[i]; | |
99 | } | |
100 | ||
101 | stext_pfn = PFN_DOWN(__pa(&_stext)); | |
102 | eshared_pfn = PFN_DOWN(__pa(&_eshared)); | |
103 | end_pfn = PFN_UP(__pa(&_end)); | |
104 | min_size = end_pfn << 2; | |
105 | ||
106 | sprintf(defsys_cmd, "DEFSYS %s 00000-%.5X EW %.5X-%.5X SR %.5X-%.5X", | |
107 | kernel_nss_name, stext_pfn - 1, stext_pfn, eshared_pfn - 1, | |
108 | eshared_pfn, end_pfn); | |
109 | ||
110 | #ifdef CONFIG_BLK_DEV_INITRD | |
111 | if (INITRD_START && INITRD_SIZE) { | |
112 | sinitrd_pfn = PFN_DOWN(__pa(INITRD_START)); | |
113 | einitrd_pfn = PFN_UP(__pa(INITRD_START + INITRD_SIZE)); | |
114 | min_size = einitrd_pfn << 2; | |
115 | sprintf(defsys_cmd, "%s EW %.5X-%.5X", defsys_cmd, | |
116 | sinitrd_pfn, einitrd_pfn); | |
117 | } | |
118 | #endif | |
119 | ||
a0443fbb HB |
120 | sprintf(defsys_cmd, "%s EW MINSIZE=%.7iK PARMREGS=0-13", |
121 | defsys_cmd, min_size); | |
ab14de6c HC |
122 | sprintf(savesys_cmd, "SAVESYS %s \n IPL %s", |
123 | kernel_nss_name, kernel_nss_name); | |
124 | ||
125 | __cpcmd(defsys_cmd, NULL, 0, &response); | |
126 | ||
583b33bc HY |
127 | if (response != 0) { |
128 | kernel_nss_name[0] = '\0'; | |
ab14de6c | 129 | return; |
583b33bc | 130 | } |
ab14de6c | 131 | |
a0443fbb HB |
132 | len = strlen(savesys_cmd); |
133 | ASCEBC(savesys_cmd, len); | |
134 | response = savesys_ipl_nss(savesys_cmd, len); | |
ab14de6c | 135 | |
a0443fbb HB |
136 | /* On success: response is equal to the command size, |
137 | * max SAVESYS_CMD_SIZE | |
138 | * On error: response contains the numeric portion of cp error message. | |
139 | * for SAVESYS it will be >= 263 | |
140 | */ | |
141 | if (response > SAVESYS_CMD_SIZE) { | |
583b33bc | 142 | kernel_nss_name[0] = '\0'; |
ab14de6c | 143 | return; |
583b33bc | 144 | } |
ab14de6c | 145 | |
a0443fbb HB |
146 | /* re-setup boot command line with new ipl vm parms */ |
147 | ipl_update_parameters(); | |
148 | setup_boot_command_line(); | |
149 | ||
ab14de6c HC |
150 | ipl_flags = IPL_NSS_VALID; |
151 | } | |
152 | ||
153 | #else /* CONFIG_SHARED_KERNEL */ | |
154 | ||
155 | static inline void create_kernel_nss(void) { } | |
156 | ||
157 | #endif /* CONFIG_SHARED_KERNEL */ | |
158 | ||
159 | /* | |
160 | * Clear bss memory | |
161 | */ | |
162 | static noinline __init void clear_bss_section(void) | |
163 | { | |
229d9c6d | 164 | memset(__bss_start, 0, __bss_stop - __bss_start); |
ab14de6c HC |
165 | } |
166 | ||
167 | /* | |
168 | * Initialize storage key for kernel pages | |
169 | */ | |
170 | static noinline __init void init_kernel_storage_key(void) | |
171 | { | |
172 | unsigned long end_pfn, init_pfn; | |
173 | ||
174 | end_pfn = PFN_UP(__pa(&_end)); | |
175 | ||
176 | for (init_pfn = 0 ; init_pfn < end_pfn; init_pfn++) | |
177 | page_set_storage_key(init_pfn << PAGE_SHIFT, PAGE_DEFAULT_KEY); | |
178 | } | |
179 | ||
92e6ecf3 CB |
180 | static __initdata struct sysinfo_3_2_2 vmms __aligned(PAGE_SIZE); |
181 | ||
ab14de6c HC |
182 | static noinline __init void detect_machine_type(void) |
183 | { | |
92e6ecf3 CB |
184 | /* No VM information? Looks like LPAR */ |
185 | if (stsi(&vmms, 3, 2, 2) == -ENOSYS) | |
186 | return; | |
187 | if (!vmms.count) | |
188 | return; | |
ab14de6c | 189 | |
92e6ecf3 CB |
190 | /* Running under KVM? If not we assume z/VM */ |
191 | if (!memcmp(vmms.vm[0].cpi, "\xd2\xe5\xd4", 3)) | |
2e5061e4 | 192 | machine_flags |= MACHINE_FLAG_KVM; |
92e6ecf3 CB |
193 | else |
194 | machine_flags |= MACHINE_FLAG_VM; | |
ab14de6c HC |
195 | } |
196 | ||
ab14de6c HC |
197 | static __init void early_pgm_check_handler(void) |
198 | { | |
199 | unsigned long addr; | |
200 | const struct exception_table_entry *fixup; | |
201 | ||
202 | addr = S390_lowcore.program_old_psw.addr; | |
203 | fixup = search_exception_tables(addr & PSW_ADDR_INSN); | |
204 | if (!fixup) | |
205 | disabled_wait(0); | |
206 | S390_lowcore.program_old_psw.addr = fixup->fixup | PSW_ADDR_AMODE; | |
207 | } | |
208 | ||
209 | static noinline __init void setup_lowcore_early(void) | |
210 | { | |
211 | psw_t psw; | |
212 | ||
213 | psw.mask = PSW_BASE_BITS | PSW_DEFAULT_KEY; | |
214 | psw.addr = PSW_ADDR_AMODE | (unsigned long) s390_base_ext_handler; | |
215 | S390_lowcore.external_new_psw = psw; | |
216 | psw.addr = PSW_ADDR_AMODE | (unsigned long) s390_base_pgm_handler; | |
217 | S390_lowcore.program_new_psw = psw; | |
218 | s390_base_pgm_handler_fn = early_pgm_check_handler; | |
219 | } | |
220 | ||
53492b1d GS |
221 | static noinline __init void setup_hpage(void) |
222 | { | |
223 | #ifndef CONFIG_DEBUG_PAGEALLOC | |
224 | unsigned int facilities; | |
225 | ||
226 | facilities = stfl(); | |
227 | if (!(facilities & (1UL << 23)) || !(facilities & (1UL << 29))) | |
228 | return; | |
229 | machine_flags |= MACHINE_FLAG_HPAGE; | |
230 | __ctl_set_bit(0, 23); | |
231 | #endif | |
232 | } | |
233 | ||
2e5061e4 HC |
234 | static __init void detect_mvpg(void) |
235 | { | |
236 | #ifndef CONFIG_64BIT | |
237 | int rc; | |
238 | ||
239 | asm volatile( | |
240 | " la 0,0\n" | |
241 | " mvpg %2,%2\n" | |
242 | "0: la %0,0\n" | |
243 | "1:\n" | |
244 | EX_TABLE(0b,1b) | |
245 | : "=d" (rc) : "0" (-EOPNOTSUPP), "a" (0) : "memory", "cc", "0"); | |
246 | if (!rc) | |
247 | machine_flags |= MACHINE_FLAG_MVPG; | |
248 | #endif | |
249 | } | |
250 | ||
251 | static __init void detect_ieee(void) | |
252 | { | |
253 | #ifndef CONFIG_64BIT | |
254 | int rc, tmp; | |
255 | ||
256 | asm volatile( | |
257 | " efpc %1,0\n" | |
258 | "0: la %0,0\n" | |
259 | "1:\n" | |
260 | EX_TABLE(0b,1b) | |
261 | : "=d" (rc), "=d" (tmp): "0" (-EOPNOTSUPP) : "cc"); | |
262 | if (!rc) | |
263 | machine_flags |= MACHINE_FLAG_IEEE; | |
264 | #endif | |
265 | } | |
266 | ||
267 | static __init void detect_csp(void) | |
268 | { | |
269 | #ifndef CONFIG_64BIT | |
270 | int rc; | |
271 | ||
272 | asm volatile( | |
273 | " la 0,0\n" | |
274 | " la 1,0\n" | |
275 | " la 2,4\n" | |
276 | " csp 0,2\n" | |
277 | "0: la %0,0\n" | |
278 | "1:\n" | |
279 | EX_TABLE(0b,1b) | |
280 | : "=d" (rc) : "0" (-EOPNOTSUPP) : "cc", "0", "1", "2"); | |
281 | if (!rc) | |
282 | machine_flags |= MACHINE_FLAG_CSP; | |
283 | #endif | |
284 | } | |
285 | ||
286 | static __init void detect_diag9c(void) | |
287 | { | |
288 | unsigned int cpu_address; | |
289 | int rc; | |
290 | ||
291 | cpu_address = stap(); | |
292 | asm volatile( | |
293 | " diag %2,0,0x9c\n" | |
294 | "0: la %0,0\n" | |
295 | "1:\n" | |
296 | EX_TABLE(0b,1b) | |
297 | : "=d" (rc) : "0" (-EOPNOTSUPP), "d" (cpu_address) : "cc"); | |
298 | if (!rc) | |
299 | machine_flags |= MACHINE_FLAG_DIAG9C; | |
300 | } | |
301 | ||
302 | static __init void detect_diag44(void) | |
303 | { | |
304 | #ifdef CONFIG_64BIT | |
305 | int rc; | |
306 | ||
307 | asm volatile( | |
308 | " diag 0,0,0x44\n" | |
309 | "0: la %0,0\n" | |
310 | "1:\n" | |
311 | EX_TABLE(0b,1b) | |
312 | : "=d" (rc) : "0" (-EOPNOTSUPP) : "cc"); | |
313 | if (!rc) | |
314 | machine_flags |= MACHINE_FLAG_DIAG44; | |
315 | #endif | |
316 | } | |
317 | ||
318 | static __init void detect_machine_facilities(void) | |
319 | { | |
320 | #ifdef CONFIG_64BIT | |
321 | unsigned int facilities; | |
322 | ||
323 | facilities = stfl(); | |
324 | if (facilities & (1 << 28)) | |
325 | machine_flags |= MACHINE_FLAG_IDTE; | |
53492b1d GS |
326 | if (facilities & (1 << 23)) |
327 | machine_flags |= MACHINE_FLAG_PFMF; | |
2e5061e4 HC |
328 | if (facilities & (1 << 4)) |
329 | machine_flags |= MACHINE_FLAG_MVCOS; | |
330 | #endif | |
331 | } | |
332 | ||
761cdf6a HC |
333 | static __init void rescue_initrd(void) |
334 | { | |
335 | #ifdef CONFIG_BLK_DEV_INITRD | |
336 | /* | |
337 | * Move the initrd right behind the bss section in case it starts | |
338 | * within the bss section. So we don't overwrite it when the bss | |
339 | * section gets cleared. | |
340 | */ | |
341 | if (!INITRD_START || !INITRD_SIZE) | |
342 | return; | |
343 | if (INITRD_START >= (unsigned long) __bss_stop) | |
344 | return; | |
345 | memmove(__bss_stop, (void *) INITRD_START, INITRD_SIZE); | |
346 | INITRD_START = (unsigned long) __bss_stop; | |
347 | #endif | |
348 | } | |
349 | ||
a0443fbb HB |
350 | /* Set up boot command line */ |
351 | static void __init setup_boot_command_line(void) | |
352 | { | |
353 | char *parm = NULL; | |
354 | ||
355 | /* copy arch command line */ | |
356 | strlcpy(boot_command_line, COMMAND_LINE, ARCH_COMMAND_LINE_SIZE); | |
a0443fbb HB |
357 | |
358 | /* append IPL PARM data to the boot command line */ | |
359 | if (MACHINE_IS_VM) { | |
360 | parm = boot_command_line + strlen(boot_command_line); | |
361 | *parm++ = ' '; | |
362 | get_ipl_vmparm(parm); | |
363 | if (parm[0] == '=') | |
364 | memmove(boot_command_line, parm + 1, strlen(parm)); | |
365 | } | |
366 | } | |
367 | ||
368 | ||
ab14de6c HC |
369 | /* |
370 | * Save ipl parameters, clear bss memory, initialize storage keys | |
371 | * and create a kernel NSS at startup if the SAVESYS= parm is defined | |
372 | */ | |
373 | void __init startup_init(void) | |
374 | { | |
ab14de6c | 375 | ipl_save_parameters(); |
761cdf6a | 376 | rescue_initrd(); |
ab14de6c HC |
377 | clear_bss_section(); |
378 | init_kernel_storage_key(); | |
379 | lockdep_init(); | |
380 | lockdep_off(); | |
ab14de6c HC |
381 | sort_main_extable(); |
382 | setup_lowcore_early(); | |
a0443fbb HB |
383 | detect_machine_type(); |
384 | ipl_update_parameters(); | |
385 | setup_boot_command_line(); | |
386 | create_kernel_nss(); | |
2e5061e4 HC |
387 | detect_mvpg(); |
388 | detect_ieee(); | |
389 | detect_csp(); | |
390 | detect_diag9c(); | |
391 | detect_diag44(); | |
392 | detect_machine_facilities(); | |
53492b1d | 393 | setup_hpage(); |
83119ad4 | 394 | sclp_facilities_detect(); |
23d17421 | 395 | detect_memory_layout(memory_chunk); |
25097bf1 | 396 | S390_lowcore.machine_flags = machine_flags; |
ab14de6c HC |
397 | lockdep_on(); |
398 | } |