2 * arch/s390/kernel/early.c
4 * Copyright IBM Corp. 2007
5 * Author(s): Hongjie Yang <hongjie@us.ibm.com>,
6 * Heiko Carstens <heiko.carstens@de.ibm.com>
9 #include <linux/init.h>
10 #include <linux/errno.h>
11 #include <linux/string.h>
12 #include <linux/ctype.h>
13 #include <linux/lockdep.h>
14 #include <linux/module.h>
15 #include <linux/pfn.h>
16 #include <linux/uaccess.h>
17 #include <asm/ebcdic.h>
19 #include <asm/lowcore.h>
20 #include <asm/processor.h>
21 #include <asm/sections.h>
22 #include <asm/setup.h>
23 #include <asm/cpcmd.h>
28 * Create a Kernel NSS if the SAVESYS= parameter is defined
30 #define DEFSYS_CMD_SIZE 128
31 #define SAVESYS_CMD_SIZE 32
33 char kernel_nss_name[NSS_NAME_SIZE + 1];
35 static void __init setup_boot_command_line(void);
38 #ifdef CONFIG_SHARED_KERNEL
39 int __init savesys_ipl_nss(char *cmd, const int cmdlen);
42 " .section .init.text,\"ax\",@progbits\n"
44 " .type savesys_ipl_nss, @function\n"
62 " .size savesys_ipl_nss, .-savesys_ipl_nss\n");
64 static noinline __init void create_kernel_nss(void)
66 unsigned int i, stext_pfn, eshared_pfn, end_pfn, min_size;
67 #ifdef CONFIG_BLK_DEV_INITRD
68 unsigned int sinitrd_pfn, einitrd_pfn;
73 char upper_command_line[COMMAND_LINE_SIZE];
74 char defsys_cmd[DEFSYS_CMD_SIZE];
75 char savesys_cmd[SAVESYS_CMD_SIZE];
77 /* Do nothing if we are not running under VM */
81 /* Convert COMMAND_LINE to upper case */
82 for (i = 0; i < strlen(boot_command_line); i++)
83 upper_command_line[i] = toupper(boot_command_line[i]);
85 savesys_ptr = strstr(upper_command_line, "SAVESYS=");
90 savesys_ptr += 8; /* Point to the beginning of the NSS name */
91 for (i = 0; i < NSS_NAME_SIZE; i++) {
92 if (savesys_ptr[i] == ' ' || savesys_ptr[i] == '\0')
94 kernel_nss_name[i] = savesys_ptr[i];
97 stext_pfn = PFN_DOWN(__pa(&_stext));
98 eshared_pfn = PFN_DOWN(__pa(&_eshared));
99 end_pfn = PFN_UP(__pa(&_end));
100 min_size = end_pfn << 2;
102 sprintf(defsys_cmd, "DEFSYS %s 00000-%.5X EW %.5X-%.5X SR %.5X-%.5X",
103 kernel_nss_name, stext_pfn - 1, stext_pfn, eshared_pfn - 1,
104 eshared_pfn, end_pfn);
106 #ifdef CONFIG_BLK_DEV_INITRD
107 if (INITRD_START && INITRD_SIZE) {
108 sinitrd_pfn = PFN_DOWN(__pa(INITRD_START));
109 einitrd_pfn = PFN_UP(__pa(INITRD_START + INITRD_SIZE));
110 min_size = einitrd_pfn << 2;
111 sprintf(defsys_cmd, "%s EW %.5X-%.5X", defsys_cmd,
112 sinitrd_pfn, einitrd_pfn);
116 sprintf(defsys_cmd, "%s EW MINSIZE=%.7iK PARMREGS=0-13",
117 defsys_cmd, min_size);
118 sprintf(savesys_cmd, "SAVESYS %s \n IPL %s",
119 kernel_nss_name, kernel_nss_name);
121 __cpcmd(defsys_cmd, NULL, 0, &response);
124 kernel_nss_name[0] = '\0';
128 len = strlen(savesys_cmd);
129 ASCEBC(savesys_cmd, len);
130 response = savesys_ipl_nss(savesys_cmd, len);
132 /* On success: response is equal to the command size,
133 * max SAVESYS_CMD_SIZE
134 * On error: response contains the numeric portion of cp error message.
135 * for SAVESYS it will be >= 263
137 if (response > SAVESYS_CMD_SIZE) {
138 kernel_nss_name[0] = '\0';
142 /* re-setup boot command line with new ipl vm parms */
143 ipl_update_parameters();
144 setup_boot_command_line();
146 ipl_flags = IPL_NSS_VALID;
149 #else /* CONFIG_SHARED_KERNEL */
151 static inline void create_kernel_nss(void) { }
153 #endif /* CONFIG_SHARED_KERNEL */
158 static noinline __init void clear_bss_section(void)
160 memset(__bss_start, 0, __bss_stop - __bss_start);
164 * Initialize storage key for kernel pages
166 static noinline __init void init_kernel_storage_key(void)
168 unsigned long end_pfn, init_pfn;
170 end_pfn = PFN_UP(__pa(&_end));
172 for (init_pfn = 0 ; init_pfn < end_pfn; init_pfn++)
173 page_set_storage_key(init_pfn << PAGE_SHIFT, PAGE_DEFAULT_KEY);
176 static noinline __init void detect_machine_type(void)
178 struct cpuinfo_S390 *cpuinfo = &S390_lowcore.cpu_data;
180 get_cpu_id(&S390_lowcore.cpu_data.cpu_id);
182 /* Running under z/VM ? */
183 if (cpuinfo->cpu_id.version == 0xff)
184 machine_flags |= MACHINE_FLAG_VM;
186 /* Running on a P/390 ? */
187 if (cpuinfo->cpu_id.machine == 0x7490)
188 machine_flags |= MACHINE_FLAG_P390;
190 /* Running under KVM ? */
191 if (cpuinfo->cpu_id.version == 0xfe)
192 machine_flags |= MACHINE_FLAG_KVM;
195 static __init void early_pgm_check_handler(void)
198 const struct exception_table_entry *fixup;
200 addr = S390_lowcore.program_old_psw.addr;
201 fixup = search_exception_tables(addr & PSW_ADDR_INSN);
204 S390_lowcore.program_old_psw.addr = fixup->fixup | PSW_ADDR_AMODE;
207 static noinline __init void setup_lowcore_early(void)
211 psw.mask = PSW_BASE_BITS | PSW_DEFAULT_KEY;
212 psw.addr = PSW_ADDR_AMODE | (unsigned long) s390_base_ext_handler;
213 S390_lowcore.external_new_psw = psw;
214 psw.addr = PSW_ADDR_AMODE | (unsigned long) s390_base_pgm_handler;
215 S390_lowcore.program_new_psw = psw;
216 s390_base_pgm_handler_fn = early_pgm_check_handler;
219 static noinline __init void setup_hpage(void)
221 #ifndef CONFIG_DEBUG_PAGEALLOC
222 unsigned int facilities;
225 if (!(facilities & (1UL << 23)) || !(facilities & (1UL << 29)))
227 machine_flags |= MACHINE_FLAG_HPAGE;
228 __ctl_set_bit(0, 23);
232 static __init void detect_mvpg(void)
243 : "=d" (rc) : "0" (-EOPNOTSUPP), "a" (0) : "memory", "cc", "0");
245 machine_flags |= MACHINE_FLAG_MVPG;
249 static __init void detect_ieee(void)
259 : "=d" (rc), "=d" (tmp): "0" (-EOPNOTSUPP) : "cc");
261 machine_flags |= MACHINE_FLAG_IEEE;
265 static __init void detect_csp(void)
278 : "=d" (rc) : "0" (-EOPNOTSUPP) : "cc", "0", "1", "2");
280 machine_flags |= MACHINE_FLAG_CSP;
284 static __init void detect_diag9c(void)
286 unsigned int cpu_address;
289 cpu_address = stap();
295 : "=d" (rc) : "0" (-EOPNOTSUPP), "d" (cpu_address) : "cc");
297 machine_flags |= MACHINE_FLAG_DIAG9C;
300 static __init void detect_diag44(void)
310 : "=d" (rc) : "0" (-EOPNOTSUPP) : "cc");
312 machine_flags |= MACHINE_FLAG_DIAG44;
316 static __init void detect_machine_facilities(void)
319 unsigned int facilities;
322 if (facilities & (1 << 28))
323 machine_flags |= MACHINE_FLAG_IDTE;
324 if (facilities & (1 << 23))
325 machine_flags |= MACHINE_FLAG_PFMF;
326 if (facilities & (1 << 4))
327 machine_flags |= MACHINE_FLAG_MVCOS;
331 static __init void rescue_initrd(void)
333 #ifdef CONFIG_BLK_DEV_INITRD
335 * Move the initrd right behind the bss section in case it starts
336 * within the bss section. So we don't overwrite it when the bss
337 * section gets cleared.
339 if (!INITRD_START || !INITRD_SIZE)
341 if (INITRD_START >= (unsigned long) __bss_stop)
343 memmove(__bss_stop, (void *) INITRD_START, INITRD_SIZE);
344 INITRD_START = (unsigned long) __bss_stop;
348 /* Set up boot command line */
349 static void __init setup_boot_command_line(void)
353 /* copy arch command line */
354 strlcpy(boot_command_line, COMMAND_LINE, ARCH_COMMAND_LINE_SIZE);
355 boot_command_line[ARCH_COMMAND_LINE_SIZE - 1] = 0;
357 /* append IPL PARM data to the boot command line */
359 parm = boot_command_line + strlen(boot_command_line);
361 get_ipl_vmparm(parm);
363 memmove(boot_command_line, parm + 1, strlen(parm));
369 * Save ipl parameters, clear bss memory, initialize storage keys
370 * and create a kernel NSS at startup if the SAVESYS= parm is defined
372 void __init startup_init(void)
374 ipl_save_parameters();
377 init_kernel_storage_key();
381 setup_lowcore_early();
382 detect_machine_type();
383 ipl_update_parameters();
384 setup_boot_command_line();
391 detect_machine_facilities();
393 sclp_facilities_detect();
394 detect_memory_layout(memory_chunk);