1 // SPDX-License-Identifier: GPL-2.0
2 #include <linux/kernel.h>
3 #include <linux/init.h>
4 #include <linux/ctype.h>
5 #include <asm/ebcdic.h>
7 #include <asm/sections.h>
8 #include <asm/boot_data.h>
9 #include <asm/facility.h>
13 char __bootdata(early_command_line)[COMMAND_LINE_SIZE];
14 struct ipl_parameter_block __bootdata_preserved(ipl_block);
15 int __bootdata_preserved(ipl_block_valid);
17 unsigned long __bootdata(memory_end);
18 int __bootdata(memory_end_set);
19 int __bootdata(noexec_disabled);
21 int kaslr_enabled __section(.data);
23 static inline int __diag308(unsigned long subcode, void *addr)
25 register unsigned long _addr asm("0") = (unsigned long)addr;
26 register unsigned long _rc asm("1") = 0;
27 unsigned long reg1, reg2;
28 psw_t old = S390_lowcore.program_new_psw;
33 " st %1,%[psw_pgm]+4\n"
35 " stg %0,%[psw_pgm]+8\n"
36 " diag %[addr],%[subcode],0x308\n"
38 : "=&d" (reg1), "=&a" (reg2),
39 [psw_pgm] "=Q" (S390_lowcore.program_new_psw),
40 [addr] "+d" (_addr), "+d" (_rc)
41 : [subcode] "d" (subcode)
43 S390_lowcore.program_new_psw = old;
47 void store_ipl_parmblock(void)
51 rc = __diag308(DIAG308_STORE, &ipl_block);
52 if (rc == DIAG308_RC_OK &&
53 ipl_block.hdr.version <= IPL_MAX_SUPPORTED_VERSION)
57 static size_t scpdata_length(const u8 *buf, size_t count)
60 if (buf[count - 1] != '\0' && buf[count - 1] != ' ')
67 static size_t ipl_block_get_ascii_scpdata(char *dest, size_t size,
68 const struct ipl_parameter_block *ipb)
74 count = min(size - 1, scpdata_length(ipb->fcp.scp_data,
75 ipb->fcp.scp_data_len));
80 for (i = 0; i < count; i++) {
81 if (!isascii(ipb->fcp.scp_data[i])) {
85 if (!has_lowercase && islower(ipb->fcp.scp_data[i]))
90 memcpy(dest, ipb->fcp.scp_data, count);
92 for (i = 0; i < count; i++)
93 dest[i] = tolower(ipb->fcp.scp_data[i]);
99 static void append_ipl_block_parm(void)
104 len = strlen(early_command_line);
106 delim = early_command_line + len; /* '\0' character position */
107 parm = early_command_line + len + 1; /* append right after '\0' */
109 switch (ipl_block.pb0_hdr.pbt) {
111 rc = ipl_block_get_ascii_vmparm(
112 parm, COMMAND_LINE_SIZE - len - 1, &ipl_block);
115 rc = ipl_block_get_ascii_scpdata(
116 parm, COMMAND_LINE_SIZE - len - 1, &ipl_block);
121 memmove(early_command_line, parm + 1, rc);
123 *delim = ' '; /* replace '\0' with space */
127 static inline int has_ebcdic_char(const char *str)
131 for (i = 0; str[i]; i++)
137 void setup_boot_command_line(void)
139 COMMAND_LINE[ARCH_COMMAND_LINE_SIZE - 1] = 0;
140 /* convert arch command line to ascii if necessary */
141 if (has_ebcdic_char(COMMAND_LINE))
142 EBCASC(COMMAND_LINE, ARCH_COMMAND_LINE_SIZE);
143 /* copy arch command line */
144 strcpy(early_command_line, strim(COMMAND_LINE));
146 /* append IPL PARM data to the boot command line */
147 if (!is_prot_virt_guest() && ipl_block_valid)
148 append_ipl_block_parm();
151 static void modify_facility(unsigned long nr, bool clear)
154 __clear_facility(nr, S390_lowcore.stfle_fac_list);
156 __set_facility(nr, S390_lowcore.stfle_fac_list);
159 static void check_cleared_facilities(void)
161 unsigned long als[] = { FACILITIES_ALS };
164 for (i = 0; i < ARRAY_SIZE(als); i++) {
165 if ((S390_lowcore.stfle_fac_list[i] & als[i]) != als[i]) {
166 sclp_early_printk("Warning: The Linux kernel requires facilities cleared via command line option\n");
167 print_missing_facilities();
173 static void modify_fac_list(char *str)
175 unsigned long val, endval;
185 val = simple_strtoull(str, &endp, 0);
191 endval = simple_strtoull(str, &endp, 0);
195 while (val <= endval) {
196 modify_facility(val, clear);
200 modify_facility(val, clear);
206 check_cleared_facilities();
209 static char command_line_buf[COMMAND_LINE_SIZE] __section(.data);
210 void parse_boot_command_line(void)
217 kaslr_enabled = IS_ENABLED(CONFIG_RANDOMIZE_BASE);
218 args = strcpy(command_line_buf, early_command_line);
220 args = next_arg(args, ¶m, &val);
222 if (!strcmp(param, "mem")) {
223 memory_end = memparse(val, NULL);
227 if (!strcmp(param, "noexec")) {
228 rc = kstrtobool(val, &enabled);
233 if (!strcmp(param, "facilities"))
234 modify_fac_list(val);
236 if (!strcmp(param, "nokaslr"))
241 void setup_memory_end(void)
243 #ifdef CONFIG_CRASH_DUMP
246 } else if (ipl_block_valid &&
247 ipl_block.pb0_hdr.pbt == IPL_PBT_FCP &&
248 ipl_block.fcp.opt == IPL_PB0_FCP_OPT_DUMP) {
250 if (!sclp_early_get_hsa_size(&memory_end) && memory_end)