warning removal
[cor_2_6_31.git] / arch / s390 / kernel / early.c
blob8d15314381e04640bbf227ff045b9d9a782f22cf
1 /*
2 * arch/s390/kernel/early.c
4 * Copyright IBM Corp. 2007, 2009
5 * Author(s): Hongjie Yang <hongjie@us.ibm.com>,
6 * Heiko Carstens <heiko.carstens@de.ibm.com>
7 */
9 #include <linux/compiler.h>
10 #include <linux/init.h>
11 #include <linux/errno.h>
12 #include <linux/string.h>
13 #include <linux/ctype.h>
14 #include <linux/ftrace.h>
15 #include <linux/lockdep.h>
16 #include <linux/module.h>
17 #include <linux/pfn.h>
18 #include <linux/uaccess.h>
19 #include <asm/ebcdic.h>
20 #include <asm/ipl.h>
21 #include <asm/lowcore.h>
22 #include <asm/processor.h>
23 #include <asm/sections.h>
24 #include <asm/setup.h>
25 #include <asm/sysinfo.h>
26 #include <asm/cpcmd.h>
27 #include <asm/sclp.h>
28 #include "entry.h"
31 * Create a Kernel NSS if the SAVESYS= parameter is defined
33 #define DEFSYS_CMD_SIZE 128
34 #define SAVESYS_CMD_SIZE 32
36 char kernel_nss_name[NSS_NAME_SIZE + 1];
38 static unsigned long machine_flags;
40 static void __init setup_boot_command_line(void);
43 * Get the TOD clock running.
45 static void __init reset_tod_clock(void)
47 u64 time;
49 if (store_clock(&time) == 0)
50 return;
51 /* TOD clock not running. Set the clock to Unix Epoch. */
52 if (set_clock(TOD_UNIX_EPOCH) != 0 || store_clock(&time) != 0)
53 disabled_wait(0);
55 sched_clock_base_cc = TOD_UNIX_EPOCH;
58 #ifdef CONFIG_SHARED_KERNEL
59 int __init savesys_ipl_nss(char *cmd, const int cmdlen);
61 asm(
62 " .section .init.text,\"ax\",@progbits\n"
63 " .align 4\n"
64 " .type savesys_ipl_nss, @function\n"
65 "savesys_ipl_nss:\n"
66 #ifdef CONFIG_64BIT
67 " stmg 6,15,48(15)\n"
68 " lgr 14,3\n"
69 " sam31\n"
70 " diag 2,14,0x8\n"
71 " sam64\n"
72 " lgr 2,14\n"
73 " lmg 6,15,48(15)\n"
74 #else
75 " stm 6,15,24(15)\n"
76 " lr 14,3\n"
77 " diag 2,14,0x8\n"
78 " lr 2,14\n"
79 " lm 6,15,24(15)\n"
80 #endif
81 " br 14\n"
82 " .size savesys_ipl_nss, .-savesys_ipl_nss\n");
84 static noinline __init void create_kernel_nss(void)
86 unsigned int i, stext_pfn, eshared_pfn, end_pfn, min_size;
87 #ifdef CONFIG_BLK_DEV_INITRD
88 unsigned int sinitrd_pfn, einitrd_pfn;
89 #endif
90 int response;
91 size_t len;
92 char *savesys_ptr;
93 char upper_command_line[COMMAND_LINE_SIZE];
94 char defsys_cmd[DEFSYS_CMD_SIZE];
95 char savesys_cmd[SAVESYS_CMD_SIZE];
97 /* Do nothing if we are not running under VM */
98 if (!MACHINE_IS_VM)
99 return;
101 /* Convert COMMAND_LINE to upper case */
102 for (i = 0; i < strlen(boot_command_line); i++)
103 upper_command_line[i] = toupper(boot_command_line[i]);
105 savesys_ptr = strstr(upper_command_line, "SAVESYS=");
107 if (!savesys_ptr)
108 return;
110 savesys_ptr += 8; /* Point to the beginning of the NSS name */
111 for (i = 0; i < NSS_NAME_SIZE; i++) {
112 if (savesys_ptr[i] == ' ' || savesys_ptr[i] == '\0')
113 break;
114 kernel_nss_name[i] = savesys_ptr[i];
117 stext_pfn = PFN_DOWN(__pa(&_stext));
118 eshared_pfn = PFN_DOWN(__pa(&_eshared));
119 end_pfn = PFN_UP(__pa(&_end));
120 min_size = end_pfn << 2;
122 sprintf(defsys_cmd, "DEFSYS %s 00000-%.5X EW %.5X-%.5X SR %.5X-%.5X",
123 kernel_nss_name, stext_pfn - 1, stext_pfn, eshared_pfn - 1,
124 eshared_pfn, end_pfn);
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;
131 sprintf(defsys_cmd, "%s EW %.5X-%.5X", defsys_cmd,
132 sinitrd_pfn, einitrd_pfn);
134 #endif
136 sprintf(defsys_cmd, "%s EW MINSIZE=%.7iK PARMREGS=0-13",
137 defsys_cmd, min_size);
138 sprintf(savesys_cmd, "SAVESYS %s \n IPL %s",
139 kernel_nss_name, kernel_nss_name);
141 __cpcmd(defsys_cmd, NULL, 0, &response);
143 if (response != 0) {
144 kernel_nss_name[0] = '\0';
145 return;
148 len = strlen(savesys_cmd);
149 ASCEBC(savesys_cmd, len);
150 response = savesys_ipl_nss(savesys_cmd, len);
152 /* On success: response is equal to the command size,
153 * max SAVESYS_CMD_SIZE
154 * On error: response contains the numeric portion of cp error message.
155 * for SAVESYS it will be >= 263
157 if (response > SAVESYS_CMD_SIZE) {
158 kernel_nss_name[0] = '\0';
159 return;
162 /* re-setup boot command line with new ipl vm parms */
163 ipl_update_parameters();
164 setup_boot_command_line();
166 ipl_flags = IPL_NSS_VALID;
169 #else /* CONFIG_SHARED_KERNEL */
171 static inline void create_kernel_nss(void) { }
173 #endif /* CONFIG_SHARED_KERNEL */
176 * Clear bss memory
178 static noinline __init void clear_bss_section(void)
180 memset(__bss_start, 0, __bss_stop - __bss_start);
184 * Initialize storage key for kernel pages
186 static noinline __init void init_kernel_storage_key(void)
188 unsigned long end_pfn, init_pfn;
190 end_pfn = PFN_UP(__pa(&_end));
192 for (init_pfn = 0 ; init_pfn < end_pfn; init_pfn++)
193 page_set_storage_key(init_pfn << PAGE_SHIFT, PAGE_DEFAULT_KEY);
196 static __initdata struct sysinfo_3_2_2 vmms __aligned(PAGE_SIZE);
198 static noinline __init void detect_machine_type(void)
200 /* No VM information? Looks like LPAR */
201 if (stsi(&vmms, 3, 2, 2) == -ENOSYS)
202 return;
203 if (!vmms.count)
204 return;
206 /* Running under KVM? If not we assume z/VM */
207 if (!memcmp(vmms.vm[0].cpi, "\xd2\xe5\xd4", 3))
208 machine_flags |= MACHINE_FLAG_KVM;
209 else
210 machine_flags |= MACHINE_FLAG_VM;
213 static __init void early_pgm_check_handler(void)
215 unsigned long addr;
216 const struct exception_table_entry *fixup;
218 addr = S390_lowcore.program_old_psw.addr;
219 fixup = search_exception_tables(addr & PSW_ADDR_INSN);
220 if (!fixup)
221 disabled_wait(0);
222 S390_lowcore.program_old_psw.addr = fixup->fixup | PSW_ADDR_AMODE;
225 static noinline __init void setup_lowcore_early(void)
227 psw_t psw;
229 psw.mask = PSW_BASE_BITS | PSW_DEFAULT_KEY;
230 psw.addr = PSW_ADDR_AMODE | (unsigned long) s390_base_ext_handler;
231 S390_lowcore.external_new_psw = psw;
232 psw.addr = PSW_ADDR_AMODE | (unsigned long) s390_base_pgm_handler;
233 S390_lowcore.program_new_psw = psw;
234 s390_base_pgm_handler_fn = early_pgm_check_handler;
237 static noinline __init void setup_hpage(void)
239 #ifndef CONFIG_DEBUG_PAGEALLOC
240 unsigned int facilities;
242 facilities = stfl();
243 if (!(facilities & (1UL << 23)) || !(facilities & (1UL << 29)))
244 return;
245 machine_flags |= MACHINE_FLAG_HPAGE;
246 __ctl_set_bit(0, 23);
247 #endif
250 static __init void detect_mvpg(void)
252 #ifndef CONFIG_64BIT
253 int rc;
255 asm volatile(
256 " la 0,0\n"
257 " mvpg %2,%2\n"
258 "0: la %0,0\n"
259 "1:\n"
260 EX_TABLE(0b,1b)
261 : "=d" (rc) : "0" (-EOPNOTSUPP), "a" (0) : "memory", "cc", "0");
262 if (!rc)
263 machine_flags |= MACHINE_FLAG_MVPG;
264 #endif
267 static __init void detect_ieee(void)
269 #ifndef CONFIG_64BIT
270 int rc, tmp;
272 asm volatile(
273 " efpc %1,0\n"
274 "0: la %0,0\n"
275 "1:\n"
276 EX_TABLE(0b,1b)
277 : "=d" (rc), "=d" (tmp): "0" (-EOPNOTSUPP) : "cc");
278 if (!rc)
279 machine_flags |= MACHINE_FLAG_IEEE;
280 #endif
283 static __init void detect_csp(void)
285 #ifndef CONFIG_64BIT
286 int rc;
288 asm volatile(
289 " la 0,0\n"
290 " la 1,0\n"
291 " la 2,4\n"
292 " csp 0,2\n"
293 "0: la %0,0\n"
294 "1:\n"
295 EX_TABLE(0b,1b)
296 : "=d" (rc) : "0" (-EOPNOTSUPP) : "cc", "0", "1", "2");
297 if (!rc)
298 machine_flags |= MACHINE_FLAG_CSP;
299 #endif
302 static __init void detect_diag9c(void)
304 unsigned int cpu_address;
305 int rc;
307 cpu_address = stap();
308 asm volatile(
309 " diag %2,0,0x9c\n"
310 "0: la %0,0\n"
311 "1:\n"
312 EX_TABLE(0b,1b)
313 : "=d" (rc) : "0" (-EOPNOTSUPP), "d" (cpu_address) : "cc");
314 if (!rc)
315 machine_flags |= MACHINE_FLAG_DIAG9C;
318 static __init void detect_diag44(void)
320 #ifdef CONFIG_64BIT
321 int rc;
323 asm volatile(
324 " diag 0,0,0x44\n"
325 "0: la %0,0\n"
326 "1:\n"
327 EX_TABLE(0b,1b)
328 : "=d" (rc) : "0" (-EOPNOTSUPP) : "cc");
329 if (!rc)
330 machine_flags |= MACHINE_FLAG_DIAG44;
331 #endif
334 static __init void detect_machine_facilities(void)
336 #ifdef CONFIG_64BIT
337 unsigned int facilities;
339 facilities = stfl();
340 if (facilities & (1 << 28))
341 machine_flags |= MACHINE_FLAG_IDTE;
342 if (facilities & (1 << 23))
343 machine_flags |= MACHINE_FLAG_PFMF;
344 if (facilities & (1 << 4))
345 machine_flags |= MACHINE_FLAG_MVCOS;
346 #endif
349 static __init void rescue_initrd(void)
351 #ifdef CONFIG_BLK_DEV_INITRD
353 * Move the initrd right behind the bss section in case it starts
354 * within the bss section. So we don't overwrite it when the bss
355 * section gets cleared.
357 if (!INITRD_START || !INITRD_SIZE)
358 return;
359 if (INITRD_START >= (unsigned long) __bss_stop)
360 return;
361 memmove(__bss_stop, (void *) INITRD_START, INITRD_SIZE);
362 INITRD_START = (unsigned long) __bss_stop;
363 #endif
366 /* Set up boot command line */
367 static void __init setup_boot_command_line(void)
369 char *parm = NULL;
371 /* copy arch command line */
372 strlcpy(boot_command_line, COMMAND_LINE, ARCH_COMMAND_LINE_SIZE);
374 /* append IPL PARM data to the boot command line */
375 if (MACHINE_IS_VM) {
376 parm = boot_command_line + strlen(boot_command_line);
377 *parm++ = ' ';
378 get_ipl_vmparm(parm);
379 if (parm[0] == '=')
380 memmove(boot_command_line, parm + 1, strlen(parm));
386 * Save ipl parameters, clear bss memory, initialize storage keys
387 * and create a kernel NSS at startup if the SAVESYS= parm is defined
389 void __init startup_init(void)
391 reset_tod_clock();
392 ipl_save_parameters();
393 rescue_initrd();
394 clear_bss_section();
395 init_kernel_storage_key();
396 lockdep_init();
397 lockdep_off();
398 sort_main_extable();
399 setup_lowcore_early();
400 detect_machine_type();
401 ipl_update_parameters();
402 setup_boot_command_line();
403 create_kernel_nss();
404 detect_mvpg();
405 detect_ieee();
406 detect_csp();
407 detect_diag9c();
408 detect_diag44();
409 detect_machine_facilities();
410 setup_hpage();
411 sclp_facilities_detect();
412 detect_memory_layout(memory_chunk);
413 S390_lowcore.machine_flags = machine_flags;
414 #ifdef CONFIG_DYNAMIC_FTRACE
415 S390_lowcore.ftrace_func = (unsigned long)ftrace_caller;
416 #endif
417 lockdep_on();