xref: /linux/arch/s390/kernel/early.c (revision b5510d9b68c33964abd938148f407ad3789e369f)
1ab14de6cSHeiko Carstens /*
2155af2f9SHans-Joachim Picht  *    Copyright IBM Corp. 2007, 2009
3ab14de6cSHeiko Carstens  *    Author(s): Hongjie Yang <hongjie@us.ibm.com>,
4ab14de6cSHeiko Carstens  *		 Heiko Carstens <heiko.carstens@de.ibm.com>
5ab14de6cSHeiko Carstens  */
6ab14de6cSHeiko Carstens 
711af97e1SHendrik Brueckner #define KMSG_COMPONENT "setup"
811af97e1SHendrik Brueckner #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
911af97e1SHendrik Brueckner 
1092e6ecf3SChristian Borntraeger #include <linux/compiler.h>
11ab14de6cSHeiko Carstens #include <linux/init.h>
12ab14de6cSHeiko Carstens #include <linux/errno.h>
13ab14de6cSHeiko Carstens #include <linux/string.h>
14ab14de6cSHeiko Carstens #include <linux/ctype.h>
15ab14de6cSHeiko Carstens #include <linux/lockdep.h>
16ab14de6cSHeiko Carstens #include <linux/module.h>
17ab14de6cSHeiko Carstens #include <linux/pfn.h>
18ab14de6cSHeiko Carstens #include <linux/uaccess.h>
1911af97e1SHendrik Brueckner #include <linux/kernel.h>
201ec2772eSMartin Schwidefsky #include <asm/diag.h>
21a0443fbbSHendrik Brueckner #include <asm/ebcdic.h>
2246b05d26SMichael Holzheu #include <asm/ipl.h>
23ab14de6cSHeiko Carstens #include <asm/lowcore.h>
24ab14de6cSHeiko Carstens #include <asm/processor.h>
25ab14de6cSHeiko Carstens #include <asm/sections.h>
26ab14de6cSHeiko Carstens #include <asm/setup.h>
2792e6ecf3SChristian Borntraeger #include <asm/sysinfo.h>
28ab14de6cSHeiko Carstens #include <asm/cpcmd.h>
29ab14de6cSHeiko Carstens #include <asm/sclp.h>
30a0616cdeSDavid Howells #include <asm/facility.h>
31a806170eSHeiko Carstens #include "entry.h"
32ab14de6cSHeiko Carstens 
33ab14de6cSHeiko Carstens /*
34ab14de6cSHeiko Carstens  * Create a Kernel NSS if the SAVESYS= parameter is defined
35ab14de6cSHeiko Carstens  */
36a0443fbbSHendrik Brueckner #define DEFSYS_CMD_SIZE		128
37ab14de6cSHeiko Carstens #define SAVESYS_CMD_SIZE	32
38ab14de6cSHeiko Carstens 
39ab14de6cSHeiko Carstens char kernel_nss_name[NSS_NAME_SIZE + 1];
40ab14de6cSHeiko Carstens 
41a0443fbbSHendrik Brueckner static void __init setup_boot_command_line(void);
42a0443fbbSHendrik Brueckner 
43b6112ccbSMartin Schwidefsky /*
44b6112ccbSMartin Schwidefsky  * Get the TOD clock running.
45b6112ccbSMartin Schwidefsky  */
46b6112ccbSMartin Schwidefsky static void __init reset_tod_clock(void)
47b6112ccbSMartin Schwidefsky {
48b6112ccbSMartin Schwidefsky 	u64 time;
49b6112ccbSMartin Schwidefsky 
501aae0560SHeiko Carstens 	if (store_tod_clock(&time) == 0)
51b6112ccbSMartin Schwidefsky 		return;
52b6112ccbSMartin Schwidefsky 	/* TOD clock not running. Set the clock to Unix Epoch. */
531aae0560SHeiko Carstens 	if (set_tod_clock(TOD_UNIX_EPOCH) != 0 || store_tod_clock(&time) != 0)
54b6112ccbSMartin Schwidefsky 		disabled_wait(0);
55b6112ccbSMartin Schwidefsky 
56b6112ccbSMartin Schwidefsky 	sched_clock_base_cc = TOD_UNIX_EPOCH;
57b89031e0SMartin Schwidefsky 	S390_lowcore.last_update_clock = sched_clock_base_cc;
58b6112ccbSMartin Schwidefsky }
59a0443fbbSHendrik Brueckner 
60ab14de6cSHeiko Carstens #ifdef CONFIG_SHARED_KERNEL
61a0443fbbSHendrik Brueckner int __init savesys_ipl_nss(char *cmd, const int cmdlen);
62a0443fbbSHendrik Brueckner 
63a0443fbbSHendrik Brueckner asm(
64a0443fbbSHendrik Brueckner 	"	.section .init.text,\"ax\",@progbits\n"
65a0443fbbSHendrik Brueckner 	"	.align	4\n"
66a0443fbbSHendrik Brueckner 	"	.type	savesys_ipl_nss, @function\n"
67a0443fbbSHendrik Brueckner 	"savesys_ipl_nss:\n"
68a0443fbbSHendrik Brueckner 	"	stmg	6,15,48(15)\n"
69a0443fbbSHendrik Brueckner 	"	lgr	14,3\n"
70a0443fbbSHendrik Brueckner 	"	sam31\n"
71a0443fbbSHendrik Brueckner 	"	diag	2,14,0x8\n"
72a0443fbbSHendrik Brueckner 	"	sam64\n"
73a0443fbbSHendrik Brueckner 	"	lgr	2,14\n"
74a0443fbbSHendrik Brueckner 	"	lmg	6,15,48(15)\n"
75a0443fbbSHendrik Brueckner 	"	br	14\n"
7618764463SHeiko Carstens 	"	.size	savesys_ipl_nss, .-savesys_ipl_nss\n"
7718764463SHeiko Carstens 	"	.previous\n");
78a0443fbbSHendrik Brueckner 
79684d2fd4SHendrik Brueckner static __initdata char upper_command_line[COMMAND_LINE_SIZE];
80684d2fd4SHendrik Brueckner 
81ab14de6cSHeiko Carstens static noinline __init void create_kernel_nss(void)
82ab14de6cSHeiko Carstens {
83ab14de6cSHeiko Carstens 	unsigned int i, stext_pfn, eshared_pfn, end_pfn, min_size;
84ab14de6cSHeiko Carstens #ifdef CONFIG_BLK_DEV_INITRD
85ab14de6cSHeiko Carstens 	unsigned int sinitrd_pfn, einitrd_pfn;
86ab14de6cSHeiko Carstens #endif
87ab14de6cSHeiko Carstens 	int response;
8869ac43b0SChen Liu 	int hlen;
89a0443fbbSHendrik Brueckner 	size_t len;
90ab14de6cSHeiko Carstens 	char *savesys_ptr;
91ab14de6cSHeiko Carstens 	char defsys_cmd[DEFSYS_CMD_SIZE];
92ab14de6cSHeiko Carstens 	char savesys_cmd[SAVESYS_CMD_SIZE];
93ab14de6cSHeiko Carstens 
94ab14de6cSHeiko Carstens 	/* Do nothing if we are not running under VM */
95ab14de6cSHeiko Carstens 	if (!MACHINE_IS_VM)
96ab14de6cSHeiko Carstens 		return;
97ab14de6cSHeiko Carstens 
98ab14de6cSHeiko Carstens 	/* Convert COMMAND_LINE to upper case */
99a0443fbbSHendrik Brueckner 	for (i = 0; i < strlen(boot_command_line); i++)
100a0443fbbSHendrik Brueckner 		upper_command_line[i] = toupper(boot_command_line[i]);
101ab14de6cSHeiko Carstens 
102ab14de6cSHeiko Carstens 	savesys_ptr = strstr(upper_command_line, "SAVESYS=");
103ab14de6cSHeiko Carstens 
104ab14de6cSHeiko Carstens 	if (!savesys_ptr)
105ab14de6cSHeiko Carstens 		return;
106ab14de6cSHeiko Carstens 
107ab14de6cSHeiko Carstens 	savesys_ptr += 8;    /* Point to the beginning of the NSS name */
108ab14de6cSHeiko Carstens 	for (i = 0; i < NSS_NAME_SIZE; i++) {
109ab14de6cSHeiko Carstens 		if (savesys_ptr[i] == ' ' || savesys_ptr[i] == '\0')
110ab14de6cSHeiko Carstens 			break;
111ab14de6cSHeiko Carstens 		kernel_nss_name[i] = savesys_ptr[i];
112ab14de6cSHeiko Carstens 	}
113ab14de6cSHeiko Carstens 
114ab14de6cSHeiko Carstens 	stext_pfn = PFN_DOWN(__pa(&_stext));
115ab14de6cSHeiko Carstens 	eshared_pfn = PFN_DOWN(__pa(&_eshared));
116ab14de6cSHeiko Carstens 	end_pfn = PFN_UP(__pa(&_end));
117ab14de6cSHeiko Carstens 	min_size = end_pfn << 2;
118ab14de6cSHeiko Carstens 
11969ac43b0SChen Liu 	hlen = snprintf(defsys_cmd, DEFSYS_CMD_SIZE,
12069ac43b0SChen Liu 			"DEFSYS %s 00000-%.5X EW %.5X-%.5X SR %.5X-%.5X",
12169ac43b0SChen Liu 			kernel_nss_name, stext_pfn - 1, stext_pfn,
12269ac43b0SChen Liu 			eshared_pfn - 1, eshared_pfn, end_pfn);
123ab14de6cSHeiko Carstens 
124ab14de6cSHeiko Carstens #ifdef CONFIG_BLK_DEV_INITRD
125ab14de6cSHeiko Carstens 	if (INITRD_START && INITRD_SIZE) {
126ab14de6cSHeiko Carstens 		sinitrd_pfn = PFN_DOWN(__pa(INITRD_START));
127ab14de6cSHeiko Carstens 		einitrd_pfn = PFN_UP(__pa(INITRD_START + INITRD_SIZE));
128ab14de6cSHeiko Carstens 		min_size = einitrd_pfn << 2;
12969ac43b0SChen Liu 		hlen += snprintf(defsys_cmd + hlen, DEFSYS_CMD_SIZE - hlen,
13069ac43b0SChen Liu 				 " EW %.5X-%.5X", sinitrd_pfn, einitrd_pfn);
131ab14de6cSHeiko Carstens 	}
132ab14de6cSHeiko Carstens #endif
133ab14de6cSHeiko Carstens 
13469ac43b0SChen Liu 	snprintf(defsys_cmd + hlen, DEFSYS_CMD_SIZE - hlen,
13569ac43b0SChen Liu 		 " EW MINSIZE=%.7iK PARMREGS=0-13", min_size);
13669ac43b0SChen Liu 	defsys_cmd[DEFSYS_CMD_SIZE - 1] = '\0';
137894e491eSHeiko Carstens 	snprintf(savesys_cmd, SAVESYS_CMD_SIZE, "SAVESYS %s \n IPL %s",
138ab14de6cSHeiko Carstens 		 kernel_nss_name, kernel_nss_name);
139894e491eSHeiko Carstens 	savesys_cmd[SAVESYS_CMD_SIZE - 1] = '\0';
140ab14de6cSHeiko Carstens 
141ab14de6cSHeiko Carstens 	__cpcmd(defsys_cmd, NULL, 0, &response);
142ab14de6cSHeiko Carstens 
143583b33bcSHongjie Yang 	if (response != 0) {
14411af97e1SHendrik Brueckner 		pr_err("Defining the Linux kernel NSS failed with rc=%d\n",
14511af97e1SHendrik Brueckner 			response);
146583b33bcSHongjie Yang 		kernel_nss_name[0] = '\0';
147ab14de6cSHeiko Carstens 		return;
148583b33bcSHongjie Yang 	}
149ab14de6cSHeiko Carstens 
150a0443fbbSHendrik Brueckner 	len = strlen(savesys_cmd);
151a0443fbbSHendrik Brueckner 	ASCEBC(savesys_cmd, len);
152a0443fbbSHendrik Brueckner 	response = savesys_ipl_nss(savesys_cmd, len);
153ab14de6cSHeiko Carstens 
154a0443fbbSHendrik Brueckner 	/* On success: response is equal to the command size,
155a0443fbbSHendrik Brueckner 	 *	       max SAVESYS_CMD_SIZE
156a0443fbbSHendrik Brueckner 	 * On error: response contains the numeric portion of cp error message.
157a0443fbbSHendrik Brueckner 	 *	     for SAVESYS it will be >= 263
15811af97e1SHendrik Brueckner 	 *	     for missing privilege class, it will be 1
159a0443fbbSHendrik Brueckner 	 */
16011af97e1SHendrik Brueckner 	if (response > SAVESYS_CMD_SIZE || response == 1) {
16111af97e1SHendrik Brueckner 		pr_err("Saving the Linux kernel NSS failed with rc=%d\n",
16211af97e1SHendrik Brueckner 			response);
163583b33bcSHongjie Yang 		kernel_nss_name[0] = '\0';
164ab14de6cSHeiko Carstens 		return;
165583b33bcSHongjie Yang 	}
166ab14de6cSHeiko Carstens 
167b89031e0SMartin Schwidefsky 	/* re-initialize cputime accounting. */
1681aae0560SHeiko Carstens 	sched_clock_base_cc = get_tod_clock();
169b89031e0SMartin Schwidefsky 	S390_lowcore.last_update_clock = sched_clock_base_cc;
170b89031e0SMartin Schwidefsky 	S390_lowcore.last_update_timer = 0x7fffffffffffffffULL;
171b89031e0SMartin Schwidefsky 	S390_lowcore.user_timer = 0;
172b89031e0SMartin Schwidefsky 	S390_lowcore.system_timer = 0;
173b89031e0SMartin Schwidefsky 	asm volatile("SPT 0(%0)" : : "a" (&S390_lowcore.last_update_timer));
174b89031e0SMartin Schwidefsky 
175a0443fbbSHendrik Brueckner 	/* re-setup boot command line with new ipl vm parms */
176a0443fbbSHendrik Brueckner 	ipl_update_parameters();
177a0443fbbSHendrik Brueckner 	setup_boot_command_line();
178a0443fbbSHendrik Brueckner 
179ab14de6cSHeiko Carstens 	ipl_flags = IPL_NSS_VALID;
180ab14de6cSHeiko Carstens }
181ab14de6cSHeiko Carstens 
182ab14de6cSHeiko Carstens #else /* CONFIG_SHARED_KERNEL */
183ab14de6cSHeiko Carstens 
184ab14de6cSHeiko Carstens static inline void create_kernel_nss(void) { }
185ab14de6cSHeiko Carstens 
186ab14de6cSHeiko Carstens #endif /* CONFIG_SHARED_KERNEL */
187ab14de6cSHeiko Carstens 
188ab14de6cSHeiko Carstens /*
189ab14de6cSHeiko Carstens  * Clear bss memory
190ab14de6cSHeiko Carstens  */
191ab14de6cSHeiko Carstens static noinline __init void clear_bss_section(void)
192ab14de6cSHeiko Carstens {
193229d9c6dSHeiko Carstens 	memset(__bss_start, 0, __bss_stop - __bss_start);
194ab14de6cSHeiko Carstens }
195ab14de6cSHeiko Carstens 
196ab14de6cSHeiko Carstens /*
197ab14de6cSHeiko Carstens  * Initialize storage key for kernel pages
198ab14de6cSHeiko Carstens  */
199ab14de6cSHeiko Carstens static noinline __init void init_kernel_storage_key(void)
200ab14de6cSHeiko Carstens {
201127c1fefSMartin Schwidefsky #if PAGE_DEFAULT_KEY
202ab14de6cSHeiko Carstens 	unsigned long end_pfn, init_pfn;
203ab14de6cSHeiko Carstens 
204ab14de6cSHeiko Carstens 	end_pfn = PFN_UP(__pa(&_end));
205ab14de6cSHeiko Carstens 
206ab14de6cSHeiko Carstens 	for (init_pfn = 0 ; init_pfn < end_pfn; init_pfn++)
207e2b8d7afSMartin Schwidefsky 		page_set_storage_key(init_pfn << PAGE_SHIFT,
208e2b8d7afSMartin Schwidefsky 				     PAGE_DEFAULT_KEY, 0);
209127c1fefSMartin Schwidefsky #endif
210ab14de6cSHeiko Carstens }
211ab14de6cSHeiko Carstens 
212fade4dc4SHeiko Carstens static __initdata char sysinfo_page[PAGE_SIZE] __aligned(PAGE_SIZE);
21392e6ecf3SChristian Borntraeger 
214ab14de6cSHeiko Carstens static noinline __init void detect_machine_type(void)
215ab14de6cSHeiko Carstens {
216fade4dc4SHeiko Carstens 	struct sysinfo_3_2_2 *vmms = (struct sysinfo_3_2_2 *)&sysinfo_page;
217fade4dc4SHeiko Carstens 
21827d71602SMartin Schwidefsky 	/* Check current-configuration-level */
219caf757c6SHeiko Carstens 	if (stsi(NULL, 0, 0, 0) <= 2) {
22027d71602SMartin Schwidefsky 		S390_lowcore.machine_flags |= MACHINE_FLAG_LPAR;
22192e6ecf3SChristian Borntraeger 		return;
22227d71602SMartin Schwidefsky 	}
22327d71602SMartin Schwidefsky 	/* Get virtual-machine cpu information. */
224caf757c6SHeiko Carstens 	if (stsi(vmms, 3, 2, 2) || !vmms->count)
22592e6ecf3SChristian Borntraeger 		return;
226ab14de6cSHeiko Carstens 
22792e6ecf3SChristian Borntraeger 	/* Running under KVM? If not we assume z/VM */
228fade4dc4SHeiko Carstens 	if (!memcmp(vmms->vm[0].cpi, "\xd2\xe5\xd4", 3))
229d3135e0cSHeiko Carstens 		S390_lowcore.machine_flags |= MACHINE_FLAG_KVM;
23092e6ecf3SChristian Borntraeger 	else
231d3135e0cSHeiko Carstens 		S390_lowcore.machine_flags |= MACHINE_FLAG_VM;
232ab14de6cSHeiko Carstens }
233ab14de6cSHeiko Carstens 
234fade4dc4SHeiko Carstens static __init void setup_topology(void)
235fade4dc4SHeiko Carstens {
236fade4dc4SHeiko Carstens 	int max_mnest;
237fade4dc4SHeiko Carstens 
238fade4dc4SHeiko Carstens 	if (!test_facility(11))
239fade4dc4SHeiko Carstens 		return;
240fade4dc4SHeiko Carstens 	S390_lowcore.machine_flags |= MACHINE_FLAG_TOPOLOGY;
241fade4dc4SHeiko Carstens 	for (max_mnest = 6; max_mnest > 1; max_mnest--) {
242caf757c6SHeiko Carstens 		if (stsi(&sysinfo_page, 15, 1, max_mnest) == 0)
243fade4dc4SHeiko Carstens 			break;
244fade4dc4SHeiko Carstens 	}
245fade4dc4SHeiko Carstens 	topology_max_mnest = max_mnest;
246fade4dc4SHeiko Carstens }
247fade4dc4SHeiko Carstens 
248a3415703SMichael Holzheu static void early_pgm_check_handler(void)
249ab14de6cSHeiko Carstens {
250ab14de6cSHeiko Carstens 	const struct exception_table_entry *fixup;
25150be6345SPhilipp Hachtmann 	unsigned long cr0, cr0_new;
252eb608fb3SHeiko Carstens 	unsigned long addr;
253ab14de6cSHeiko Carstens 
254ab14de6cSHeiko Carstens 	addr = S390_lowcore.program_old_psw.addr;
255ab14de6cSHeiko Carstens 	fixup = search_exception_tables(addr & PSW_ADDR_INSN);
256ab14de6cSHeiko Carstens 	if (!fixup)
257ab14de6cSHeiko Carstens 		disabled_wait(0);
25850be6345SPhilipp Hachtmann 	/* Disable low address protection before storing into lowcore. */
25950be6345SPhilipp Hachtmann 	__ctl_store(cr0, 0, 0);
26050be6345SPhilipp Hachtmann 	cr0_new = cr0 & ~(1UL << 28);
26150be6345SPhilipp Hachtmann 	__ctl_load(cr0_new, 0, 0);
262eb608fb3SHeiko Carstens 	S390_lowcore.program_old_psw.addr = extable_fixup(fixup)|PSW_ADDR_AMODE;
26350be6345SPhilipp Hachtmann 	__ctl_load(cr0, 0, 0);
264ab14de6cSHeiko Carstens }
265ab14de6cSHeiko Carstens 
2665f954c34SHeiko Carstens static noinline __init void setup_lowcore_early(void)
267ab14de6cSHeiko Carstens {
268ab14de6cSHeiko Carstens 	psw_t psw;
269ab14de6cSHeiko Carstens 
270b50511e4SMartin Schwidefsky 	psw.mask = PSW_MASK_BASE | PSW_DEFAULT_KEY | PSW_MASK_EA | PSW_MASK_BA;
271ab14de6cSHeiko Carstens 	psw.addr = PSW_ADDR_AMODE | (unsigned long) s390_base_ext_handler;
272ab14de6cSHeiko Carstens 	S390_lowcore.external_new_psw = psw;
273ab14de6cSHeiko Carstens 	psw.addr = PSW_ADDR_AMODE | (unsigned long) s390_base_pgm_handler;
274ab14de6cSHeiko Carstens 	S390_lowcore.program_new_psw = psw;
275ab14de6cSHeiko Carstens 	s390_base_pgm_handler_fn = early_pgm_check_handler;
276ab14de6cSHeiko Carstens }
277ab14de6cSHeiko Carstens 
27814375bc4SMartin Schwidefsky static noinline __init void setup_facility_list(void)
27914375bc4SMartin Schwidefsky {
2803ab121abSMichael Holzheu 	stfle(S390_lowcore.stfle_fac_list,
2813ab121abSMichael Holzheu 	      ARRAY_SIZE(S390_lowcore.stfle_fac_list));
28214375bc4SMartin Schwidefsky }
28314375bc4SMartin Schwidefsky 
2842e5061e4SHeiko Carstens static __init void detect_diag9c(void)
2852e5061e4SHeiko Carstens {
2862e5061e4SHeiko Carstens 	unsigned int cpu_address;
2872e5061e4SHeiko Carstens 	int rc;
2882e5061e4SHeiko Carstens 
2892e5061e4SHeiko Carstens 	cpu_address = stap();
2901ec2772eSMartin Schwidefsky 	diag_stat_inc(DIAG_STAT_X09C);
2912e5061e4SHeiko Carstens 	asm volatile(
2922e5061e4SHeiko Carstens 		"	diag	%2,0,0x9c\n"
2932e5061e4SHeiko Carstens 		"0:	la	%0,0\n"
2942e5061e4SHeiko Carstens 		"1:\n"
2952e5061e4SHeiko Carstens 		EX_TABLE(0b,1b)
2962e5061e4SHeiko Carstens 		: "=d" (rc) : "0" (-EOPNOTSUPP), "d" (cpu_address) : "cc");
2972e5061e4SHeiko Carstens 	if (!rc)
298d3135e0cSHeiko Carstens 		S390_lowcore.machine_flags |= MACHINE_FLAG_DIAG9C;
2992e5061e4SHeiko Carstens }
3002e5061e4SHeiko Carstens 
3012e5061e4SHeiko Carstens static __init void detect_diag44(void)
3022e5061e4SHeiko Carstens {
3032e5061e4SHeiko Carstens 	int rc;
3042e5061e4SHeiko Carstens 
3051ec2772eSMartin Schwidefsky 	diag_stat_inc(DIAG_STAT_X044);
3062e5061e4SHeiko Carstens 	asm volatile(
3072e5061e4SHeiko Carstens 		"	diag	0,0,0x44\n"
3082e5061e4SHeiko Carstens 		"0:	la	%0,0\n"
3092e5061e4SHeiko Carstens 		"1:\n"
3102e5061e4SHeiko Carstens 		EX_TABLE(0b,1b)
3112e5061e4SHeiko Carstens 		: "=d" (rc) : "0" (-EOPNOTSUPP) : "cc");
3122e5061e4SHeiko Carstens 	if (!rc)
313d3135e0cSHeiko Carstens 		S390_lowcore.machine_flags |= MACHINE_FLAG_DIAG44;
3142e5061e4SHeiko Carstens }
3152e5061e4SHeiko Carstens 
3162e5061e4SHeiko Carstens static __init void detect_machine_facilities(void)
3172e5061e4SHeiko Carstens {
3183c7ef08bSHeiko Carstens 	if (test_facility(8)) {
3193c7ef08bSHeiko Carstens 		S390_lowcore.machine_flags |= MACHINE_FLAG_EDAT1;
3203c7ef08bSHeiko Carstens 		__ctl_set_bit(0, 23);
3213c7ef08bSHeiko Carstens 	}
32285e9d0e5SHeiko Carstens 	if (test_facility(78))
32385e9d0e5SHeiko Carstens 		S390_lowcore.machine_flags |= MACHINE_FLAG_EDAT2;
32414375bc4SMartin Schwidefsky 	if (test_facility(3))
325d3135e0cSHeiko Carstens 		S390_lowcore.machine_flags |= MACHINE_FLAG_IDTE;
32614375bc4SMartin Schwidefsky 	if (test_facility(40))
32723d18e8dSHendrik Brueckner 		S390_lowcore.machine_flags |= MACHINE_FLAG_LPP;
328d35339a4SMartin Schwidefsky 	if (test_facility(50) && test_facility(73))
329d35339a4SMartin Schwidefsky 		S390_lowcore.machine_flags |= MACHINE_FLAG_TE;
3301b948d6cSMartin Schwidefsky 	if (test_facility(51))
3311b948d6cSMartin Schwidefsky 		S390_lowcore.machine_flags |= MACHINE_FLAG_TLB_LC;
332*b5510d9bSHendrik Brueckner 	if (test_facility(129)) {
33380703617SMartin Schwidefsky 		S390_lowcore.machine_flags |= MACHINE_FLAG_VX;
334*b5510d9bSHendrik Brueckner 		__ctl_set_bit(0, 17);
3352e5061e4SHeiko Carstens 	}
336*b5510d9bSHendrik Brueckner }
337*b5510d9bSHendrik Brueckner 
338*b5510d9bSHendrik Brueckner static int __init disable_vector_extension(char *str)
339*b5510d9bSHendrik Brueckner {
340*b5510d9bSHendrik Brueckner 	S390_lowcore.machine_flags &= ~MACHINE_FLAG_VX;
341*b5510d9bSHendrik Brueckner 	__ctl_clear_bit(0, 17);
342*b5510d9bSHendrik Brueckner 	return 1;
343*b5510d9bSHendrik Brueckner }
344*b5510d9bSHendrik Brueckner early_param("novx", disable_vector_extension);
3452e5061e4SHeiko Carstens 
34661b0b016SMartin Schwidefsky static int __init cad_setup(char *str)
3472c72a44eSMartin Schwidefsky {
34861b0b016SMartin Schwidefsky 	int val;
34961b0b016SMartin Schwidefsky 
35061b0b016SMartin Schwidefsky 	get_option(&str, &val);
35161b0b016SMartin Schwidefsky 	if (val && test_facility(128))
35261b0b016SMartin Schwidefsky 		S390_lowcore.machine_flags |= MACHINE_FLAG_CAD;
3532c72a44eSMartin Schwidefsky 	return 0;
3542c72a44eSMartin Schwidefsky }
35561b0b016SMartin Schwidefsky early_param("cad", cad_setup);
3562c72a44eSMartin Schwidefsky 
3572c72a44eSMartin Schwidefsky static int __init cad_init(void)
3582c72a44eSMartin Schwidefsky {
3592c72a44eSMartin Schwidefsky 	if (MACHINE_HAS_CAD)
3602c72a44eSMartin Schwidefsky 		/* Enable problem state CAD. */
3612c72a44eSMartin Schwidefsky 		__ctl_set_bit(2, 3);
3622c72a44eSMartin Schwidefsky 	return 0;
3632c72a44eSMartin Schwidefsky }
3642c72a44eSMartin Schwidefsky early_initcall(cad_init);
3652c72a44eSMartin Schwidefsky 
366761cdf6aSHeiko Carstens static __init void rescue_initrd(void)
367761cdf6aSHeiko Carstens {
368761cdf6aSHeiko Carstens #ifdef CONFIG_BLK_DEV_INITRD
36927e7318cSHeiko Carstens 	unsigned long min_initrd_addr = (unsigned long) _end + (4UL << 20);
370761cdf6aSHeiko Carstens 	/*
37127e7318cSHeiko Carstens 	 * Just like in case of IPL from VM reader we make sure there is a
37227e7318cSHeiko Carstens 	 * gap of 4MB between end of kernel and start of initrd.
37327e7318cSHeiko Carstens 	 * That way we can also be sure that saving an NSS will succeed,
37427e7318cSHeiko Carstens 	 * which however only requires different segments.
375761cdf6aSHeiko Carstens 	 */
376761cdf6aSHeiko Carstens 	if (!INITRD_START || !INITRD_SIZE)
377761cdf6aSHeiko Carstens 		return;
37827e7318cSHeiko Carstens 	if (INITRD_START >= min_initrd_addr)
379761cdf6aSHeiko Carstens 		return;
38027e7318cSHeiko Carstens 	memmove((void *) min_initrd_addr, (void *) INITRD_START, INITRD_SIZE);
38127e7318cSHeiko Carstens 	INITRD_START = min_initrd_addr;
382761cdf6aSHeiko Carstens #endif
383761cdf6aSHeiko Carstens }
384761cdf6aSHeiko Carstens 
385a0443fbbSHendrik Brueckner /* Set up boot command line */
386684d2fd4SHendrik Brueckner static void __init append_to_cmdline(size_t (*ipl_data)(char *, size_t))
387684d2fd4SHendrik Brueckner {
388684d2fd4SHendrik Brueckner 	char *parm, *delim;
389684d2fd4SHendrik Brueckner 	size_t rc, len;
390684d2fd4SHendrik Brueckner 
391684d2fd4SHendrik Brueckner 	len = strlen(boot_command_line);
392684d2fd4SHendrik Brueckner 
393684d2fd4SHendrik Brueckner 	delim = boot_command_line + len;	/* '\0' character position */
394684d2fd4SHendrik Brueckner 	parm  = boot_command_line + len + 1;	/* append right after '\0' */
395684d2fd4SHendrik Brueckner 
396684d2fd4SHendrik Brueckner 	rc = ipl_data(parm, COMMAND_LINE_SIZE - len - 1);
397684d2fd4SHendrik Brueckner 	if (rc) {
398684d2fd4SHendrik Brueckner 		if (*parm == '=')
399684d2fd4SHendrik Brueckner 			memmove(boot_command_line, parm + 1, rc);
400684d2fd4SHendrik Brueckner 		else
401684d2fd4SHendrik Brueckner 			*delim = ' ';		/* replace '\0' with space */
402684d2fd4SHendrik Brueckner 	}
403684d2fd4SHendrik Brueckner }
404684d2fd4SHendrik Brueckner 
4051fb81057SMichael Holzheu static inline int has_ebcdic_char(const char *str)
406a0443fbbSHendrik Brueckner {
40761fd330dSMartin Schwidefsky 	int i;
40861fd330dSMartin Schwidefsky 
4091fb81057SMichael Holzheu 	for (i = 0; str[i]; i++)
4101fb81057SMichael Holzheu 		if (str[i] & 0x80)
4111fb81057SMichael Holzheu 			return 1;
4121fb81057SMichael Holzheu 	return 0;
4131fb81057SMichael Holzheu }
41461fd330dSMartin Schwidefsky 
4151fb81057SMichael Holzheu static void __init setup_boot_command_line(void)
4161fb81057SMichael Holzheu {
4171fb81057SMichael Holzheu 	COMMAND_LINE[ARCH_COMMAND_LINE_SIZE - 1] = 0;
4181fb81057SMichael Holzheu 	/* convert arch command line to ascii if necessary */
4191fb81057SMichael Holzheu 	if (has_ebcdic_char(COMMAND_LINE))
4201fb81057SMichael Holzheu 		EBCASC(COMMAND_LINE, ARCH_COMMAND_LINE_SIZE);
421a0443fbbSHendrik Brueckner 	/* copy arch command line */
42261fd330dSMartin Schwidefsky 	strlcpy(boot_command_line, strstrip(COMMAND_LINE),
42361fd330dSMartin Schwidefsky 		ARCH_COMMAND_LINE_SIZE);
424a0443fbbSHendrik Brueckner 
425a0443fbbSHendrik Brueckner 	/* append IPL PARM data to the boot command line */
426684d2fd4SHendrik Brueckner 	if (MACHINE_IS_VM)
427684d2fd4SHendrik Brueckner 		append_to_cmdline(append_ipl_vmparm);
428684d2fd4SHendrik Brueckner 
429684d2fd4SHendrik Brueckner 	append_to_cmdline(append_ipl_scpdata);
430a0443fbbSHendrik Brueckner }
431a0443fbbSHendrik Brueckner 
432ab14de6cSHeiko Carstens /*
433ab14de6cSHeiko Carstens  * Save ipl parameters, clear bss memory, initialize storage keys
434ab14de6cSHeiko Carstens  * and create a kernel NSS at startup if the SAVESYS= parm is defined
435ab14de6cSHeiko Carstens  */
436ab14de6cSHeiko Carstens void __init startup_init(void)
437ab14de6cSHeiko Carstens {
438b6112ccbSMartin Schwidefsky 	reset_tod_clock();
439ab14de6cSHeiko Carstens 	ipl_save_parameters();
440761cdf6aSHeiko Carstens 	rescue_initrd();
441ab14de6cSHeiko Carstens 	clear_bss_section();
442ab14de6cSHeiko Carstens 	init_kernel_storage_key();
443ab14de6cSHeiko Carstens 	lockdep_init();
444ab14de6cSHeiko Carstens 	lockdep_off();
445ab14de6cSHeiko Carstens 	setup_lowcore_early();
44614375bc4SMartin Schwidefsky 	setup_facility_list();
447a0443fbbSHendrik Brueckner 	detect_machine_type();
448a0443fbbSHendrik Brueckner 	ipl_update_parameters();
449a0443fbbSHendrik Brueckner 	setup_boot_command_line();
450a0443fbbSHendrik Brueckner 	create_kernel_nss();
4512e5061e4SHeiko Carstens 	detect_diag9c();
4522e5061e4SHeiko Carstens 	detect_diag44();
4532e5061e4SHeiko Carstens 	detect_machine_facilities();
454fade4dc4SHeiko Carstens 	setup_topology();
4557b50da53SMichael Holzheu 	sclp_early_detect();
456ab14de6cSHeiko Carstens 	lockdep_on();
457ab14de6cSHeiko Carstens }
458