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 under KVM ? */
187 if (cpuinfo->cpu_id.version == 0xfe)
188 machine_flags |= MACHINE_FLAG_KVM;
191 static __init void early_pgm_check_handler(void)
194 const struct exception_table_entry *fixup;
196 addr = S390_lowcore.program_old_psw.addr;
197 fixup = search_exception_tables(addr & PSW_ADDR_INSN);
200 S390_lowcore.program_old_psw.addr = fixup->fixup | PSW_ADDR_AMODE;
203 static noinline __init void setup_lowcore_early(void)
207 psw.mask = PSW_BASE_BITS | PSW_DEFAULT_KEY;
208 psw.addr = PSW_ADDR_AMODE | (unsigned long) s390_base_ext_handler;
209 S390_lowcore.external_new_psw = psw;
210 psw.addr = PSW_ADDR_AMODE | (unsigned long) s390_base_pgm_handler;
211 S390_lowcore.program_new_psw = psw;
212 s390_base_pgm_handler_fn = early_pgm_check_handler;
215 static noinline __init void setup_hpage(void)
217 #ifndef CONFIG_DEBUG_PAGEALLOC
218 unsigned int facilities;
221 if (!(facilities & (1UL << 23)) || !(facilities & (1UL << 29)))
223 machine_flags |= MACHINE_FLAG_HPAGE;
224 __ctl_set_bit(0, 23);
228 static __init void detect_mvpg(void)
239 : "=d" (rc) : "0" (-EOPNOTSUPP), "a" (0) : "memory", "cc", "0");
241 machine_flags |= MACHINE_FLAG_MVPG;
245 static __init void detect_ieee(void)
255 : "=d" (rc), "=d" (tmp): "0" (-EOPNOTSUPP) : "cc");
257 machine_flags |= MACHINE_FLAG_IEEE;
261 static __init void detect_csp(void)
274 : "=d" (rc) : "0" (-EOPNOTSUPP) : "cc", "0", "1", "2");
276 machine_flags |= MACHINE_FLAG_CSP;
280 static __init void detect_diag9c(void)
282 unsigned int cpu_address;
285 cpu_address = stap();
291 : "=d" (rc) : "0" (-EOPNOTSUPP), "d" (cpu_address) : "cc");
293 machine_flags |= MACHINE_FLAG_DIAG9C;
296 static __init void detect_diag44(void)
306 : "=d" (rc) : "0" (-EOPNOTSUPP) : "cc");
308 machine_flags |= MACHINE_FLAG_DIAG44;
312 static __init void detect_machine_facilities(void)
315 unsigned int facilities;
318 if (facilities & (1 << 28))
319 machine_flags |= MACHINE_FLAG_IDTE;
320 if (facilities & (1 << 23))
321 machine_flags |= MACHINE_FLAG_PFMF;
322 if (facilities & (1 << 4))
323 machine_flags |= MACHINE_FLAG_MVCOS;
327 static __init void rescue_initrd(void)
329 #ifdef CONFIG_BLK_DEV_INITRD
331 * Move the initrd right behind the bss section in case it starts
332 * within the bss section. So we don't overwrite it when the bss
333 * section gets cleared.
335 if (!INITRD_START || !INITRD_SIZE)
337 if (INITRD_START >= (unsigned long) __bss_stop)
339 memmove(__bss_stop, (void *) INITRD_START, INITRD_SIZE);
340 INITRD_START = (unsigned long) __bss_stop;
344 /* Set up boot command line */
345 static void __init setup_boot_command_line(void)
349 /* copy arch command line */
350 strlcpy(boot_command_line, COMMAND_LINE, ARCH_COMMAND_LINE_SIZE);
351 boot_command_line[ARCH_COMMAND_LINE_SIZE - 1] = 0;
353 /* append IPL PARM data to the boot command line */
355 parm = boot_command_line + strlen(boot_command_line);
357 get_ipl_vmparm(parm);
359 memmove(boot_command_line, parm + 1, strlen(parm));
365 * Save ipl parameters, clear bss memory, initialize storage keys
366 * and create a kernel NSS at startup if the SAVESYS= parm is defined
368 void __init startup_init(void)
370 ipl_save_parameters();
373 init_kernel_storage_key();
377 setup_lowcore_early();
378 detect_machine_type();
379 ipl_update_parameters();
380 setup_boot_command_line();
387 detect_machine_facilities();
389 sclp_facilities_detect();
390 detect_memory_layout(memory_chunk);