xref: /linux/arch/s390/kernel/early.c (revision 127c1feffff8078400f01372712c600d0f9eef51)
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>
15dfd9f7abSHeiko Carstens #include <linux/ftrace.h>
16ab14de6cSHeiko Carstens #include <linux/lockdep.h>
17ab14de6cSHeiko Carstens #include <linux/module.h>
18ab14de6cSHeiko Carstens #include <linux/pfn.h>
19ab14de6cSHeiko Carstens #include <linux/uaccess.h>
2011af97e1SHendrik Brueckner #include <linux/kernel.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 #ifdef CONFIG_64BIT
69a0443fbbSHendrik Brueckner 	"	stmg	6,15,48(15)\n"
70a0443fbbSHendrik Brueckner 	"	lgr	14,3\n"
71a0443fbbSHendrik Brueckner 	"	sam31\n"
72a0443fbbSHendrik Brueckner 	"	diag	2,14,0x8\n"
73a0443fbbSHendrik Brueckner 	"	sam64\n"
74a0443fbbSHendrik Brueckner 	"	lgr	2,14\n"
75a0443fbbSHendrik Brueckner 	"	lmg	6,15,48(15)\n"
76a0443fbbSHendrik Brueckner #else
77a0443fbbSHendrik Brueckner 	"	stm	6,15,24(15)\n"
78a0443fbbSHendrik Brueckner 	"	lr	14,3\n"
79a0443fbbSHendrik Brueckner 	"	diag	2,14,0x8\n"
80a0443fbbSHendrik Brueckner 	"	lr	2,14\n"
81a0443fbbSHendrik Brueckner 	"	lm	6,15,24(15)\n"
82a0443fbbSHendrik Brueckner #endif
83a0443fbbSHendrik Brueckner 	"	br	14\n"
8418764463SHeiko Carstens 	"	.size	savesys_ipl_nss, .-savesys_ipl_nss\n"
8518764463SHeiko Carstens 	"	.previous\n");
86a0443fbbSHendrik Brueckner 
87684d2fd4SHendrik Brueckner static __initdata char upper_command_line[COMMAND_LINE_SIZE];
88684d2fd4SHendrik Brueckner 
89ab14de6cSHeiko Carstens static noinline __init void create_kernel_nss(void)
90ab14de6cSHeiko Carstens {
91ab14de6cSHeiko Carstens 	unsigned int i, stext_pfn, eshared_pfn, end_pfn, min_size;
92ab14de6cSHeiko Carstens #ifdef CONFIG_BLK_DEV_INITRD
93ab14de6cSHeiko Carstens 	unsigned int sinitrd_pfn, einitrd_pfn;
94ab14de6cSHeiko Carstens #endif
95ab14de6cSHeiko Carstens 	int response;
9669ac43b0SChen Liu 	int hlen;
97a0443fbbSHendrik Brueckner 	size_t len;
98ab14de6cSHeiko Carstens 	char *savesys_ptr;
99ab14de6cSHeiko Carstens 	char defsys_cmd[DEFSYS_CMD_SIZE];
100ab14de6cSHeiko Carstens 	char savesys_cmd[SAVESYS_CMD_SIZE];
101ab14de6cSHeiko Carstens 
102ab14de6cSHeiko Carstens 	/* Do nothing if we are not running under VM */
103ab14de6cSHeiko Carstens 	if (!MACHINE_IS_VM)
104ab14de6cSHeiko Carstens 		return;
105ab14de6cSHeiko Carstens 
106ab14de6cSHeiko Carstens 	/* Convert COMMAND_LINE to upper case */
107a0443fbbSHendrik Brueckner 	for (i = 0; i < strlen(boot_command_line); i++)
108a0443fbbSHendrik Brueckner 		upper_command_line[i] = toupper(boot_command_line[i]);
109ab14de6cSHeiko Carstens 
110ab14de6cSHeiko Carstens 	savesys_ptr = strstr(upper_command_line, "SAVESYS=");
111ab14de6cSHeiko Carstens 
112ab14de6cSHeiko Carstens 	if (!savesys_ptr)
113ab14de6cSHeiko Carstens 		return;
114ab14de6cSHeiko Carstens 
115ab14de6cSHeiko Carstens 	savesys_ptr += 8;    /* Point to the beginning of the NSS name */
116ab14de6cSHeiko Carstens 	for (i = 0; i < NSS_NAME_SIZE; i++) {
117ab14de6cSHeiko Carstens 		if (savesys_ptr[i] == ' ' || savesys_ptr[i] == '\0')
118ab14de6cSHeiko Carstens 			break;
119ab14de6cSHeiko Carstens 		kernel_nss_name[i] = savesys_ptr[i];
120ab14de6cSHeiko Carstens 	}
121ab14de6cSHeiko Carstens 
122ab14de6cSHeiko Carstens 	stext_pfn = PFN_DOWN(__pa(&_stext));
123ab14de6cSHeiko Carstens 	eshared_pfn = PFN_DOWN(__pa(&_eshared));
124ab14de6cSHeiko Carstens 	end_pfn = PFN_UP(__pa(&_end));
125ab14de6cSHeiko Carstens 	min_size = end_pfn << 2;
126ab14de6cSHeiko Carstens 
12769ac43b0SChen Liu 	hlen = snprintf(defsys_cmd, DEFSYS_CMD_SIZE,
12869ac43b0SChen Liu 			"DEFSYS %s 00000-%.5X EW %.5X-%.5X SR %.5X-%.5X",
12969ac43b0SChen Liu 			kernel_nss_name, stext_pfn - 1, stext_pfn,
13069ac43b0SChen Liu 			eshared_pfn - 1, eshared_pfn, end_pfn);
131ab14de6cSHeiko Carstens 
132ab14de6cSHeiko Carstens #ifdef CONFIG_BLK_DEV_INITRD
133ab14de6cSHeiko Carstens 	if (INITRD_START && INITRD_SIZE) {
134ab14de6cSHeiko Carstens 		sinitrd_pfn = PFN_DOWN(__pa(INITRD_START));
135ab14de6cSHeiko Carstens 		einitrd_pfn = PFN_UP(__pa(INITRD_START + INITRD_SIZE));
136ab14de6cSHeiko Carstens 		min_size = einitrd_pfn << 2;
13769ac43b0SChen Liu 		hlen += snprintf(defsys_cmd + hlen, DEFSYS_CMD_SIZE - hlen,
13869ac43b0SChen Liu 				 " EW %.5X-%.5X", sinitrd_pfn, einitrd_pfn);
139ab14de6cSHeiko Carstens 	}
140ab14de6cSHeiko Carstens #endif
141ab14de6cSHeiko Carstens 
14269ac43b0SChen Liu 	snprintf(defsys_cmd + hlen, DEFSYS_CMD_SIZE - hlen,
14369ac43b0SChen Liu 		 " EW MINSIZE=%.7iK PARMREGS=0-13", min_size);
14469ac43b0SChen Liu 	defsys_cmd[DEFSYS_CMD_SIZE - 1] = '\0';
145894e491eSHeiko Carstens 	snprintf(savesys_cmd, SAVESYS_CMD_SIZE, "SAVESYS %s \n IPL %s",
146ab14de6cSHeiko Carstens 		 kernel_nss_name, kernel_nss_name);
147894e491eSHeiko Carstens 	savesys_cmd[SAVESYS_CMD_SIZE - 1] = '\0';
148ab14de6cSHeiko Carstens 
149ab14de6cSHeiko Carstens 	__cpcmd(defsys_cmd, NULL, 0, &response);
150ab14de6cSHeiko Carstens 
151583b33bcSHongjie Yang 	if (response != 0) {
15211af97e1SHendrik Brueckner 		pr_err("Defining the Linux kernel NSS failed with rc=%d\n",
15311af97e1SHendrik Brueckner 			response);
154583b33bcSHongjie Yang 		kernel_nss_name[0] = '\0';
155ab14de6cSHeiko Carstens 		return;
156583b33bcSHongjie Yang 	}
157ab14de6cSHeiko Carstens 
158a0443fbbSHendrik Brueckner 	len = strlen(savesys_cmd);
159a0443fbbSHendrik Brueckner 	ASCEBC(savesys_cmd, len);
160a0443fbbSHendrik Brueckner 	response = savesys_ipl_nss(savesys_cmd, len);
161ab14de6cSHeiko Carstens 
162a0443fbbSHendrik Brueckner 	/* On success: response is equal to the command size,
163a0443fbbSHendrik Brueckner 	 *	       max SAVESYS_CMD_SIZE
164a0443fbbSHendrik Brueckner 	 * On error: response contains the numeric portion of cp error message.
165a0443fbbSHendrik Brueckner 	 *	     for SAVESYS it will be >= 263
16611af97e1SHendrik Brueckner 	 *	     for missing privilege class, it will be 1
167a0443fbbSHendrik Brueckner 	 */
16811af97e1SHendrik Brueckner 	if (response > SAVESYS_CMD_SIZE || response == 1) {
16911af97e1SHendrik Brueckner 		pr_err("Saving the Linux kernel NSS failed with rc=%d\n",
17011af97e1SHendrik Brueckner 			response);
171583b33bcSHongjie Yang 		kernel_nss_name[0] = '\0';
172ab14de6cSHeiko Carstens 		return;
173583b33bcSHongjie Yang 	}
174ab14de6cSHeiko Carstens 
175b89031e0SMartin Schwidefsky 	/* re-initialize cputime accounting. */
1761aae0560SHeiko Carstens 	sched_clock_base_cc = get_tod_clock();
177b89031e0SMartin Schwidefsky 	S390_lowcore.last_update_clock = sched_clock_base_cc;
178b89031e0SMartin Schwidefsky 	S390_lowcore.last_update_timer = 0x7fffffffffffffffULL;
179b89031e0SMartin Schwidefsky 	S390_lowcore.user_timer = 0;
180b89031e0SMartin Schwidefsky 	S390_lowcore.system_timer = 0;
181b89031e0SMartin Schwidefsky 	asm volatile("SPT 0(%0)" : : "a" (&S390_lowcore.last_update_timer));
182b89031e0SMartin Schwidefsky 
183a0443fbbSHendrik Brueckner 	/* re-setup boot command line with new ipl vm parms */
184a0443fbbSHendrik Brueckner 	ipl_update_parameters();
185a0443fbbSHendrik Brueckner 	setup_boot_command_line();
186a0443fbbSHendrik Brueckner 
187ab14de6cSHeiko Carstens 	ipl_flags = IPL_NSS_VALID;
188ab14de6cSHeiko Carstens }
189ab14de6cSHeiko Carstens 
190ab14de6cSHeiko Carstens #else /* CONFIG_SHARED_KERNEL */
191ab14de6cSHeiko Carstens 
192ab14de6cSHeiko Carstens static inline void create_kernel_nss(void) { }
193ab14de6cSHeiko Carstens 
194ab14de6cSHeiko Carstens #endif /* CONFIG_SHARED_KERNEL */
195ab14de6cSHeiko Carstens 
196ab14de6cSHeiko Carstens /*
197ab14de6cSHeiko Carstens  * Clear bss memory
198ab14de6cSHeiko Carstens  */
199ab14de6cSHeiko Carstens static noinline __init void clear_bss_section(void)
200ab14de6cSHeiko Carstens {
201229d9c6dSHeiko Carstens 	memset(__bss_start, 0, __bss_stop - __bss_start);
202ab14de6cSHeiko Carstens }
203ab14de6cSHeiko Carstens 
204ab14de6cSHeiko Carstens /*
205ab14de6cSHeiko Carstens  * Initialize storage key for kernel pages
206ab14de6cSHeiko Carstens  */
207ab14de6cSHeiko Carstens static noinline __init void init_kernel_storage_key(void)
208ab14de6cSHeiko Carstens {
209*127c1fefSMartin Schwidefsky #if PAGE_DEFAULT_KEY
210ab14de6cSHeiko Carstens 	unsigned long end_pfn, init_pfn;
211ab14de6cSHeiko Carstens 
212ab14de6cSHeiko Carstens 	end_pfn = PFN_UP(__pa(&_end));
213ab14de6cSHeiko Carstens 
214ab14de6cSHeiko Carstens 	for (init_pfn = 0 ; init_pfn < end_pfn; init_pfn++)
215e2b8d7afSMartin Schwidefsky 		page_set_storage_key(init_pfn << PAGE_SHIFT,
216e2b8d7afSMartin Schwidefsky 				     PAGE_DEFAULT_KEY, 0);
217*127c1fefSMartin Schwidefsky #endif
218ab14de6cSHeiko Carstens }
219ab14de6cSHeiko Carstens 
220fade4dc4SHeiko Carstens static __initdata char sysinfo_page[PAGE_SIZE] __aligned(PAGE_SIZE);
22192e6ecf3SChristian Borntraeger 
222ab14de6cSHeiko Carstens static noinline __init void detect_machine_type(void)
223ab14de6cSHeiko Carstens {
224fade4dc4SHeiko Carstens 	struct sysinfo_3_2_2 *vmms = (struct sysinfo_3_2_2 *)&sysinfo_page;
225fade4dc4SHeiko Carstens 
22627d71602SMartin Schwidefsky 	/* Check current-configuration-level */
227caf757c6SHeiko Carstens 	if (stsi(NULL, 0, 0, 0) <= 2) {
22827d71602SMartin Schwidefsky 		S390_lowcore.machine_flags |= MACHINE_FLAG_LPAR;
22992e6ecf3SChristian Borntraeger 		return;
23027d71602SMartin Schwidefsky 	}
23127d71602SMartin Schwidefsky 	/* Get virtual-machine cpu information. */
232caf757c6SHeiko Carstens 	if (stsi(vmms, 3, 2, 2) || !vmms->count)
23392e6ecf3SChristian Borntraeger 		return;
234ab14de6cSHeiko Carstens 
23592e6ecf3SChristian Borntraeger 	/* Running under KVM? If not we assume z/VM */
236fade4dc4SHeiko Carstens 	if (!memcmp(vmms->vm[0].cpi, "\xd2\xe5\xd4", 3))
237d3135e0cSHeiko Carstens 		S390_lowcore.machine_flags |= MACHINE_FLAG_KVM;
23892e6ecf3SChristian Borntraeger 	else
239d3135e0cSHeiko Carstens 		S390_lowcore.machine_flags |= MACHINE_FLAG_VM;
240ab14de6cSHeiko Carstens }
241ab14de6cSHeiko Carstens 
242fade4dc4SHeiko Carstens static __init void setup_topology(void)
243fade4dc4SHeiko Carstens {
244fade4dc4SHeiko Carstens #ifdef CONFIG_64BIT
245fade4dc4SHeiko Carstens 	int max_mnest;
246fade4dc4SHeiko Carstens 
247fade4dc4SHeiko Carstens 	if (!test_facility(11))
248fade4dc4SHeiko Carstens 		return;
249fade4dc4SHeiko Carstens 	S390_lowcore.machine_flags |= MACHINE_FLAG_TOPOLOGY;
250fade4dc4SHeiko Carstens 	for (max_mnest = 6; max_mnest > 1; max_mnest--) {
251caf757c6SHeiko Carstens 		if (stsi(&sysinfo_page, 15, 1, max_mnest) == 0)
252fade4dc4SHeiko Carstens 			break;
253fade4dc4SHeiko Carstens 	}
254fade4dc4SHeiko Carstens 	topology_max_mnest = max_mnest;
255fade4dc4SHeiko Carstens #endif
256fade4dc4SHeiko Carstens }
257fade4dc4SHeiko Carstens 
258a3415703SMichael Holzheu static void early_pgm_check_handler(void)
259ab14de6cSHeiko Carstens {
260ab14de6cSHeiko Carstens 	const struct exception_table_entry *fixup;
261eb608fb3SHeiko Carstens 	unsigned long addr;
262ab14de6cSHeiko Carstens 
263ab14de6cSHeiko Carstens 	addr = S390_lowcore.program_old_psw.addr;
264ab14de6cSHeiko Carstens 	fixup = search_exception_tables(addr & PSW_ADDR_INSN);
265ab14de6cSHeiko Carstens 	if (!fixup)
266ab14de6cSHeiko Carstens 		disabled_wait(0);
267eb608fb3SHeiko Carstens 	S390_lowcore.program_old_psw.addr = extable_fixup(fixup)|PSW_ADDR_AMODE;
268ab14de6cSHeiko Carstens }
269ab14de6cSHeiko Carstens 
2705f954c34SHeiko Carstens static noinline __init void setup_lowcore_early(void)
271ab14de6cSHeiko Carstens {
272ab14de6cSHeiko Carstens 	psw_t psw;
273ab14de6cSHeiko Carstens 
274b50511e4SMartin Schwidefsky 	psw.mask = PSW_MASK_BASE | PSW_DEFAULT_KEY | PSW_MASK_EA | PSW_MASK_BA;
275ab14de6cSHeiko Carstens 	psw.addr = PSW_ADDR_AMODE | (unsigned long) s390_base_ext_handler;
276ab14de6cSHeiko Carstens 	S390_lowcore.external_new_psw = psw;
277ab14de6cSHeiko Carstens 	psw.addr = PSW_ADDR_AMODE | (unsigned long) s390_base_pgm_handler;
278ab14de6cSHeiko Carstens 	S390_lowcore.program_new_psw = psw;
279ab14de6cSHeiko Carstens 	s390_base_pgm_handler_fn = early_pgm_check_handler;
280ab14de6cSHeiko Carstens }
281ab14de6cSHeiko Carstens 
28214375bc4SMartin Schwidefsky static noinline __init void setup_facility_list(void)
28314375bc4SMartin Schwidefsky {
2843ab121abSMichael Holzheu 	stfle(S390_lowcore.stfle_fac_list,
2853ab121abSMichael Holzheu 	      ARRAY_SIZE(S390_lowcore.stfle_fac_list));
28614375bc4SMartin Schwidefsky }
28714375bc4SMartin Schwidefsky 
2882e5061e4SHeiko Carstens static __init void detect_mvpg(void)
2892e5061e4SHeiko Carstens {
2902e5061e4SHeiko Carstens #ifndef CONFIG_64BIT
2912e5061e4SHeiko Carstens 	int rc;
2922e5061e4SHeiko Carstens 
2932e5061e4SHeiko Carstens 	asm volatile(
2942e5061e4SHeiko Carstens 		"	la	0,0\n"
2952e5061e4SHeiko Carstens 		"	mvpg	%2,%2\n"
2962e5061e4SHeiko Carstens 		"0:	la	%0,0\n"
2972e5061e4SHeiko Carstens 		"1:\n"
2982e5061e4SHeiko Carstens 		EX_TABLE(0b,1b)
2992e5061e4SHeiko Carstens 		: "=d" (rc) : "0" (-EOPNOTSUPP), "a" (0) : "memory", "cc", "0");
3002e5061e4SHeiko Carstens 	if (!rc)
301d3135e0cSHeiko Carstens 		S390_lowcore.machine_flags |= MACHINE_FLAG_MVPG;
3022e5061e4SHeiko Carstens #endif
3032e5061e4SHeiko Carstens }
3042e5061e4SHeiko Carstens 
3052e5061e4SHeiko Carstens static __init void detect_ieee(void)
3062e5061e4SHeiko Carstens {
3072e5061e4SHeiko Carstens #ifndef CONFIG_64BIT
3082e5061e4SHeiko Carstens 	int rc, tmp;
3092e5061e4SHeiko Carstens 
3102e5061e4SHeiko Carstens 	asm volatile(
3112e5061e4SHeiko Carstens 		"	efpc	%1,0\n"
3122e5061e4SHeiko Carstens 		"0:	la	%0,0\n"
3132e5061e4SHeiko Carstens 		"1:\n"
3142e5061e4SHeiko Carstens 		EX_TABLE(0b,1b)
3152e5061e4SHeiko Carstens 		: "=d" (rc), "=d" (tmp): "0" (-EOPNOTSUPP) : "cc");
3162e5061e4SHeiko Carstens 	if (!rc)
317d3135e0cSHeiko Carstens 		S390_lowcore.machine_flags |= MACHINE_FLAG_IEEE;
3182e5061e4SHeiko Carstens #endif
3192e5061e4SHeiko Carstens }
3202e5061e4SHeiko Carstens 
3212e5061e4SHeiko Carstens static __init void detect_csp(void)
3222e5061e4SHeiko Carstens {
3232e5061e4SHeiko Carstens #ifndef CONFIG_64BIT
3242e5061e4SHeiko Carstens 	int rc;
3252e5061e4SHeiko Carstens 
3262e5061e4SHeiko Carstens 	asm volatile(
3272e5061e4SHeiko Carstens 		"	la	0,0\n"
3282e5061e4SHeiko Carstens 		"	la	1,0\n"
3292e5061e4SHeiko Carstens 		"	la	2,4\n"
3302e5061e4SHeiko Carstens 		"	csp	0,2\n"
3312e5061e4SHeiko Carstens 		"0:	la	%0,0\n"
3322e5061e4SHeiko Carstens 		"1:\n"
3332e5061e4SHeiko Carstens 		EX_TABLE(0b,1b)
3342e5061e4SHeiko Carstens 		: "=d" (rc) : "0" (-EOPNOTSUPP) : "cc", "0", "1", "2");
3352e5061e4SHeiko Carstens 	if (!rc)
336d3135e0cSHeiko Carstens 		S390_lowcore.machine_flags |= MACHINE_FLAG_CSP;
3372e5061e4SHeiko Carstens #endif
3382e5061e4SHeiko Carstens }
3392e5061e4SHeiko Carstens 
3402e5061e4SHeiko Carstens static __init void detect_diag9c(void)
3412e5061e4SHeiko Carstens {
3422e5061e4SHeiko Carstens 	unsigned int cpu_address;
3432e5061e4SHeiko Carstens 	int rc;
3442e5061e4SHeiko Carstens 
3452e5061e4SHeiko Carstens 	cpu_address = stap();
3462e5061e4SHeiko Carstens 	asm volatile(
3472e5061e4SHeiko Carstens 		"	diag	%2,0,0x9c\n"
3482e5061e4SHeiko Carstens 		"0:	la	%0,0\n"
3492e5061e4SHeiko Carstens 		"1:\n"
3502e5061e4SHeiko Carstens 		EX_TABLE(0b,1b)
3512e5061e4SHeiko Carstens 		: "=d" (rc) : "0" (-EOPNOTSUPP), "d" (cpu_address) : "cc");
3522e5061e4SHeiko Carstens 	if (!rc)
353d3135e0cSHeiko Carstens 		S390_lowcore.machine_flags |= MACHINE_FLAG_DIAG9C;
3542e5061e4SHeiko Carstens }
3552e5061e4SHeiko Carstens 
3562e5061e4SHeiko Carstens static __init void detect_diag44(void)
3572e5061e4SHeiko Carstens {
3582e5061e4SHeiko Carstens #ifdef CONFIG_64BIT
3592e5061e4SHeiko Carstens 	int rc;
3602e5061e4SHeiko Carstens 
3612e5061e4SHeiko Carstens 	asm volatile(
3622e5061e4SHeiko Carstens 		"	diag	0,0,0x44\n"
3632e5061e4SHeiko Carstens 		"0:	la	%0,0\n"
3642e5061e4SHeiko Carstens 		"1:\n"
3652e5061e4SHeiko Carstens 		EX_TABLE(0b,1b)
3662e5061e4SHeiko Carstens 		: "=d" (rc) : "0" (-EOPNOTSUPP) : "cc");
3672e5061e4SHeiko Carstens 	if (!rc)
368d3135e0cSHeiko Carstens 		S390_lowcore.machine_flags |= MACHINE_FLAG_DIAG44;
3692e5061e4SHeiko Carstens #endif
3702e5061e4SHeiko Carstens }
3712e5061e4SHeiko Carstens 
3722e5061e4SHeiko Carstens static __init void detect_machine_facilities(void)
3732e5061e4SHeiko Carstens {
3742e5061e4SHeiko Carstens #ifdef CONFIG_64BIT
3753c7ef08bSHeiko Carstens 	if (test_facility(8)) {
3763c7ef08bSHeiko Carstens 		S390_lowcore.machine_flags |= MACHINE_FLAG_EDAT1;
3773c7ef08bSHeiko Carstens 		__ctl_set_bit(0, 23);
3783c7ef08bSHeiko Carstens 	}
37985e9d0e5SHeiko Carstens 	if (test_facility(78))
38085e9d0e5SHeiko Carstens 		S390_lowcore.machine_flags |= MACHINE_FLAG_EDAT2;
38114375bc4SMartin Schwidefsky 	if (test_facility(3))
382d3135e0cSHeiko Carstens 		S390_lowcore.machine_flags |= MACHINE_FLAG_IDTE;
38314375bc4SMartin Schwidefsky 	if (test_facility(27))
384d3135e0cSHeiko Carstens 		S390_lowcore.machine_flags |= MACHINE_FLAG_MVCOS;
38514375bc4SMartin Schwidefsky 	if (test_facility(40))
38623d18e8dSHendrik Brueckner 		S390_lowcore.machine_flags |= MACHINE_FLAG_LPP;
387d35339a4SMartin Schwidefsky 	if (test_facility(50) && test_facility(73))
388d35339a4SMartin Schwidefsky 		S390_lowcore.machine_flags |= MACHINE_FLAG_TE;
3891ae1c1d0SGerald Schaefer 	if (test_facility(66))
3901ae1c1d0SGerald Schaefer 		S390_lowcore.machine_flags |= MACHINE_FLAG_RRBM;
3912e5061e4SHeiko Carstens #endif
3922e5061e4SHeiko Carstens }
3932e5061e4SHeiko Carstens 
394761cdf6aSHeiko Carstens static __init void rescue_initrd(void)
395761cdf6aSHeiko Carstens {
396761cdf6aSHeiko Carstens #ifdef CONFIG_BLK_DEV_INITRD
39727e7318cSHeiko Carstens 	unsigned long min_initrd_addr = (unsigned long) _end + (4UL << 20);
398761cdf6aSHeiko Carstens 	/*
39927e7318cSHeiko Carstens 	 * Just like in case of IPL from VM reader we make sure there is a
40027e7318cSHeiko Carstens 	 * gap of 4MB between end of kernel and start of initrd.
40127e7318cSHeiko Carstens 	 * That way we can also be sure that saving an NSS will succeed,
40227e7318cSHeiko Carstens 	 * which however only requires different segments.
403761cdf6aSHeiko Carstens 	 */
404761cdf6aSHeiko Carstens 	if (!INITRD_START || !INITRD_SIZE)
405761cdf6aSHeiko Carstens 		return;
40627e7318cSHeiko Carstens 	if (INITRD_START >= min_initrd_addr)
407761cdf6aSHeiko Carstens 		return;
40827e7318cSHeiko Carstens 	memmove((void *) min_initrd_addr, (void *) INITRD_START, INITRD_SIZE);
40927e7318cSHeiko Carstens 	INITRD_START = min_initrd_addr;
410761cdf6aSHeiko Carstens #endif
411761cdf6aSHeiko Carstens }
412761cdf6aSHeiko Carstens 
413a0443fbbSHendrik Brueckner /* Set up boot command line */
414684d2fd4SHendrik Brueckner static void __init append_to_cmdline(size_t (*ipl_data)(char *, size_t))
415684d2fd4SHendrik Brueckner {
416684d2fd4SHendrik Brueckner 	char *parm, *delim;
417684d2fd4SHendrik Brueckner 	size_t rc, len;
418684d2fd4SHendrik Brueckner 
419684d2fd4SHendrik Brueckner 	len = strlen(boot_command_line);
420684d2fd4SHendrik Brueckner 
421684d2fd4SHendrik Brueckner 	delim = boot_command_line + len;	/* '\0' character position */
422684d2fd4SHendrik Brueckner 	parm  = boot_command_line + len + 1;	/* append right after '\0' */
423684d2fd4SHendrik Brueckner 
424684d2fd4SHendrik Brueckner 	rc = ipl_data(parm, COMMAND_LINE_SIZE - len - 1);
425684d2fd4SHendrik Brueckner 	if (rc) {
426684d2fd4SHendrik Brueckner 		if (*parm == '=')
427684d2fd4SHendrik Brueckner 			memmove(boot_command_line, parm + 1, rc);
428684d2fd4SHendrik Brueckner 		else
429684d2fd4SHendrik Brueckner 			*delim = ' ';		/* replace '\0' with space */
430684d2fd4SHendrik Brueckner 	}
431684d2fd4SHendrik Brueckner }
432684d2fd4SHendrik Brueckner 
4331fb81057SMichael Holzheu static inline int has_ebcdic_char(const char *str)
434a0443fbbSHendrik Brueckner {
43561fd330dSMartin Schwidefsky 	int i;
43661fd330dSMartin Schwidefsky 
4371fb81057SMichael Holzheu 	for (i = 0; str[i]; i++)
4381fb81057SMichael Holzheu 		if (str[i] & 0x80)
4391fb81057SMichael Holzheu 			return 1;
4401fb81057SMichael Holzheu 	return 0;
4411fb81057SMichael Holzheu }
44261fd330dSMartin Schwidefsky 
4431fb81057SMichael Holzheu static void __init setup_boot_command_line(void)
4441fb81057SMichael Holzheu {
4451fb81057SMichael Holzheu 	COMMAND_LINE[ARCH_COMMAND_LINE_SIZE - 1] = 0;
4461fb81057SMichael Holzheu 	/* convert arch command line to ascii if necessary */
4471fb81057SMichael Holzheu 	if (has_ebcdic_char(COMMAND_LINE))
4481fb81057SMichael Holzheu 		EBCASC(COMMAND_LINE, ARCH_COMMAND_LINE_SIZE);
449a0443fbbSHendrik Brueckner 	/* copy arch command line */
45061fd330dSMartin Schwidefsky 	strlcpy(boot_command_line, strstrip(COMMAND_LINE),
45161fd330dSMartin Schwidefsky 		ARCH_COMMAND_LINE_SIZE);
452a0443fbbSHendrik Brueckner 
453a0443fbbSHendrik Brueckner 	/* append IPL PARM data to the boot command line */
454684d2fd4SHendrik Brueckner 	if (MACHINE_IS_VM)
455684d2fd4SHendrik Brueckner 		append_to_cmdline(append_ipl_vmparm);
456684d2fd4SHendrik Brueckner 
457684d2fd4SHendrik Brueckner 	append_to_cmdline(append_ipl_scpdata);
458a0443fbbSHendrik Brueckner }
459a0443fbbSHendrik Brueckner 
460ab14de6cSHeiko Carstens /*
461ab14de6cSHeiko Carstens  * Save ipl parameters, clear bss memory, initialize storage keys
462ab14de6cSHeiko Carstens  * and create a kernel NSS at startup if the SAVESYS= parm is defined
463ab14de6cSHeiko Carstens  */
464ab14de6cSHeiko Carstens void __init startup_init(void)
465ab14de6cSHeiko Carstens {
466b6112ccbSMartin Schwidefsky 	reset_tod_clock();
467ab14de6cSHeiko Carstens 	ipl_save_parameters();
468761cdf6aSHeiko Carstens 	rescue_initrd();
469ab14de6cSHeiko Carstens 	clear_bss_section();
470ab14de6cSHeiko Carstens 	init_kernel_storage_key();
471ab14de6cSHeiko Carstens 	lockdep_init();
472ab14de6cSHeiko Carstens 	lockdep_off();
473ab14de6cSHeiko Carstens 	setup_lowcore_early();
47414375bc4SMartin Schwidefsky 	setup_facility_list();
475a0443fbbSHendrik Brueckner 	detect_machine_type();
476a0443fbbSHendrik Brueckner 	ipl_update_parameters();
477a0443fbbSHendrik Brueckner 	setup_boot_command_line();
478a0443fbbSHendrik Brueckner 	create_kernel_nss();
4792e5061e4SHeiko Carstens 	detect_mvpg();
4802e5061e4SHeiko Carstens 	detect_ieee();
4812e5061e4SHeiko Carstens 	detect_csp();
4822e5061e4SHeiko Carstens 	detect_diag9c();
4832e5061e4SHeiko Carstens 	detect_diag44();
4842e5061e4SHeiko Carstens 	detect_machine_facilities();
485fade4dc4SHeiko Carstens 	setup_topology();
48683119ad4SHeiko Carstens 	sclp_facilities_detect();
487dfd9f7abSHeiko Carstens #ifdef CONFIG_DYNAMIC_FTRACE
488dfd9f7abSHeiko Carstens 	S390_lowcore.ftrace_func = (unsigned long)ftrace_caller;
489dfd9f7abSHeiko Carstens #endif
490ab14de6cSHeiko Carstens 	lockdep_on();
491ab14de6cSHeiko Carstens }
492