1 // SPDX-License-Identifier: GPL-2.0
2 #include <linux/kernel.h>
3 #include <linux/init.h>
4 #include <linux/ctype.h>
5 #include <linux/pgtable.h>
6 #include <asm/ebcdic.h>
8 #include <asm/sections.h>
9 #include <asm/boot_data.h>
10 #include <asm/facility.h>
11 #include <asm/setup.h>
15 struct parmarea parmarea __section(".parmarea") = {
16 .kernel_version = (unsigned long)kernel_version,
17 .max_command_line_size = COMMAND_LINE_SIZE,
18 .command_line = "root=/dev/ram0 ro",
21 char __bootdata(early_command_line)[COMMAND_LINE_SIZE];
22 int __bootdata(noexec_disabled);
24 unsigned int __bootdata_preserved(zlib_dfltcc_support) = ZLIB_DFLTCC_FULL;
25 struct ipl_parameter_block __bootdata_preserved(ipl_block);
26 int __bootdata_preserved(ipl_block_valid);
28 unsigned long vmalloc_size = VMALLOC_DEFAULT_SIZE;
29 unsigned long memory_limit;
33 static inline int __diag308(unsigned long subcode, void *addr)
35 unsigned long reg1, reg2;
36 union register_pair r1;
39 r1.even = (unsigned long) addr;
42 " mvc 0(16,%[psw_old]),0(%[psw_pgm])\n"
43 " epsw %[reg1],%[reg2]\n"
44 " st %[reg1],0(%[psw_pgm])\n"
45 " st %[reg2],4(%[psw_pgm])\n"
47 " stg %[reg1],8(%[psw_pgm])\n"
48 " diag %[r1],%[subcode],0x308\n"
49 "1: mvc 0(16,%[psw_pgm]),0(%[psw_old])\n"
50 : [r1] "+&d" (r1.pair),
53 "+Q" (S390_lowcore.program_new_psw),
55 : [subcode] "d" (subcode),
57 [psw_pgm] "a" (&S390_lowcore.program_new_psw)
62 void store_ipl_parmblock(void)
66 rc = __diag308(DIAG308_STORE, &ipl_block);
67 if (rc == DIAG308_RC_OK &&
68 ipl_block.hdr.version <= IPL_MAX_SUPPORTED_VERSION)
72 bool is_ipl_block_dump(void)
74 if (ipl_block.pb0_hdr.pbt == IPL_PBT_FCP &&
75 ipl_block.fcp.opt == IPL_PB0_FCP_OPT_DUMP)
77 if (ipl_block.pb0_hdr.pbt == IPL_PBT_NVME &&
78 ipl_block.nvme.opt == IPL_PB0_NVME_OPT_DUMP)
83 static size_t scpdata_length(const u8 *buf, size_t count)
86 if (buf[count - 1] != '\0' && buf[count - 1] != ' ')
93 static size_t ipl_block_get_ascii_scpdata(char *dest, size_t size,
94 const struct ipl_parameter_block *ipb)
102 switch (ipb->pb0_hdr.pbt) {
104 scp_data_len = ipb->fcp.scp_data_len;
105 scp_data = ipb->fcp.scp_data;
108 scp_data_len = ipb->nvme.scp_data_len;
109 scp_data = ipb->nvme.scp_data;
115 count = min(size - 1, scpdata_length(scp_data, scp_data_len));
120 for (i = 0; i < count; i++) {
121 if (!isascii(scp_data[i])) {
125 if (!has_lowercase && islower(scp_data[i]))
130 memcpy(dest, scp_data, count);
132 for (i = 0; i < count; i++)
133 dest[i] = tolower(scp_data[i]);
139 static void append_ipl_block_parm(void)
144 len = strlen(early_command_line);
146 delim = early_command_line + len; /* '\0' character position */
147 parm = early_command_line + len + 1; /* append right after '\0' */
149 switch (ipl_block.pb0_hdr.pbt) {
151 rc = ipl_block_get_ascii_vmparm(
152 parm, COMMAND_LINE_SIZE - len - 1, &ipl_block);
156 rc = ipl_block_get_ascii_scpdata(
157 parm, COMMAND_LINE_SIZE - len - 1, &ipl_block);
162 memmove(early_command_line, parm + 1, rc);
164 *delim = ' '; /* replace '\0' with space */
168 static inline int has_ebcdic_char(const char *str)
172 for (i = 0; str[i]; i++)
178 void setup_boot_command_line(void)
180 parmarea.command_line[COMMAND_LINE_SIZE - 1] = 0;
181 /* convert arch command line to ascii if necessary */
182 if (has_ebcdic_char(parmarea.command_line))
183 EBCASC(parmarea.command_line, COMMAND_LINE_SIZE);
184 /* copy arch command line */
185 strcpy(early_command_line, strim(parmarea.command_line));
187 /* append IPL PARM data to the boot command line */
188 if (!is_prot_virt_guest() && ipl_block_valid)
189 append_ipl_block_parm();
192 static void modify_facility(unsigned long nr, bool clear)
195 __clear_facility(nr, stfle_fac_list);
197 __set_facility(nr, stfle_fac_list);
200 static void check_cleared_facilities(void)
202 unsigned long als[] = { FACILITIES_ALS };
205 for (i = 0; i < ARRAY_SIZE(als); i++) {
206 if ((stfle_fac_list[i] & als[i]) != als[i]) {
207 sclp_early_printk("Warning: The Linux kernel requires facilities cleared via command line option\n");
208 print_missing_facilities();
214 static void modify_fac_list(char *str)
216 unsigned long val, endval;
226 val = simple_strtoull(str, &endp, 0);
232 endval = simple_strtoull(str, &endp, 0);
236 while (val <= endval) {
237 modify_facility(val, clear);
241 modify_facility(val, clear);
247 check_cleared_facilities();
250 static char command_line_buf[COMMAND_LINE_SIZE];
251 void parse_boot_command_line(void)
258 kaslr_enabled = IS_ENABLED(CONFIG_RANDOMIZE_BASE);
259 args = strcpy(command_line_buf, early_command_line);
261 args = next_arg(args, ¶m, &val);
263 if (!strcmp(param, "mem") && val)
264 memory_limit = round_down(memparse(val, NULL), PAGE_SIZE);
266 if (!strcmp(param, "vmalloc") && val) {
267 vmalloc_size = round_up(memparse(val, NULL), PAGE_SIZE);
268 vmalloc_size_set = 1;
271 if (!strcmp(param, "dfltcc") && val) {
272 if (!strcmp(val, "off"))
273 zlib_dfltcc_support = ZLIB_DFLTCC_DISABLED;
274 else if (!strcmp(val, "on"))
275 zlib_dfltcc_support = ZLIB_DFLTCC_FULL;
276 else if (!strcmp(val, "def_only"))
277 zlib_dfltcc_support = ZLIB_DFLTCC_DEFLATE_ONLY;
278 else if (!strcmp(val, "inf_only"))
279 zlib_dfltcc_support = ZLIB_DFLTCC_INFLATE_ONLY;
280 else if (!strcmp(val, "always"))
281 zlib_dfltcc_support = ZLIB_DFLTCC_FULL_DEBUG;
284 if (!strcmp(param, "noexec")) {
285 rc = kstrtobool(val, &enabled);
290 if (!strcmp(param, "facilities") && val)
291 modify_fac_list(val);
293 if (!strcmp(param, "nokaslr"))
296 #if IS_ENABLED(CONFIG_KVM)
297 if (!strcmp(param, "prot_virt")) {
298 rc = kstrtobool(val, &enabled);