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>
14 char __bootdata(early_command_line)[COMMAND_LINE_SIZE];
15 int __bootdata(noexec_disabled);
17 unsigned int __bootdata_preserved(zlib_dfltcc_support) = ZLIB_DFLTCC_FULL;
18 struct ipl_parameter_block __bootdata_preserved(ipl_block);
19 int __bootdata_preserved(ipl_block_valid);
21 unsigned long vmalloc_size = VMALLOC_DEFAULT_SIZE;
22 unsigned long memory_limit;
26 static inline int __diag308(unsigned long subcode, void *addr)
28 unsigned long reg1, reg2;
29 union register_pair r1;
32 r1.even = (unsigned long) addr;
35 " mvc 0(16,%[psw_old]),0(%[psw_pgm])\n"
36 " epsw %[reg1],%[reg2]\n"
37 " st %[reg1],0(%[psw_pgm])\n"
38 " st %[reg2],4(%[psw_pgm])\n"
40 " stg %[reg1],8(%[psw_pgm])\n"
41 " diag %[r1],%[subcode],0x308\n"
42 "1: mvc 0(16,%[psw_pgm]),0(%[psw_old])\n"
43 : [r1] "+&d" (r1.pair),
46 "+Q" (S390_lowcore.program_new_psw),
48 : [subcode] "d" (subcode),
50 [psw_pgm] "a" (&S390_lowcore.program_new_psw)
55 void store_ipl_parmblock(void)
59 rc = __diag308(DIAG308_STORE, &ipl_block);
60 if (rc == DIAG308_RC_OK &&
61 ipl_block.hdr.version <= IPL_MAX_SUPPORTED_VERSION)
65 bool is_ipl_block_dump(void)
67 if (ipl_block.pb0_hdr.pbt == IPL_PBT_FCP &&
68 ipl_block.fcp.opt == IPL_PB0_FCP_OPT_DUMP)
70 if (ipl_block.pb0_hdr.pbt == IPL_PBT_NVME &&
71 ipl_block.nvme.opt == IPL_PB0_NVME_OPT_DUMP)
76 static size_t scpdata_length(const u8 *buf, size_t count)
79 if (buf[count - 1] != '\0' && buf[count - 1] != ' ')
86 static size_t ipl_block_get_ascii_scpdata(char *dest, size_t size,
87 const struct ipl_parameter_block *ipb)
95 switch (ipb->pb0_hdr.pbt) {
97 scp_data_len = ipb->fcp.scp_data_len;
98 scp_data = ipb->fcp.scp_data;
101 scp_data_len = ipb->nvme.scp_data_len;
102 scp_data = ipb->nvme.scp_data;
108 count = min(size - 1, scpdata_length(scp_data, scp_data_len));
113 for (i = 0; i < count; i++) {
114 if (!isascii(scp_data[i])) {
118 if (!has_lowercase && islower(scp_data[i]))
123 memcpy(dest, scp_data, count);
125 for (i = 0; i < count; i++)
126 dest[i] = tolower(scp_data[i]);
132 static void append_ipl_block_parm(void)
137 len = strlen(early_command_line);
139 delim = early_command_line + len; /* '\0' character position */
140 parm = early_command_line + len + 1; /* append right after '\0' */
142 switch (ipl_block.pb0_hdr.pbt) {
144 rc = ipl_block_get_ascii_vmparm(
145 parm, COMMAND_LINE_SIZE - len - 1, &ipl_block);
149 rc = ipl_block_get_ascii_scpdata(
150 parm, COMMAND_LINE_SIZE - len - 1, &ipl_block);
155 memmove(early_command_line, parm + 1, rc);
157 *delim = ' '; /* replace '\0' with space */
161 static inline int has_ebcdic_char(const char *str)
165 for (i = 0; str[i]; i++)
171 void setup_boot_command_line(void)
173 parmarea.command_line[COMMAND_LINE_SIZE - 1] = 0;
174 /* convert arch command line to ascii if necessary */
175 if (has_ebcdic_char(parmarea.command_line))
176 EBCASC(parmarea.command_line, COMMAND_LINE_SIZE);
177 /* copy arch command line */
178 strcpy(early_command_line, strim(parmarea.command_line));
180 /* append IPL PARM data to the boot command line */
181 if (!is_prot_virt_guest() && ipl_block_valid)
182 append_ipl_block_parm();
185 static void modify_facility(unsigned long nr, bool clear)
188 __clear_facility(nr, stfle_fac_list);
190 __set_facility(nr, stfle_fac_list);
193 static void check_cleared_facilities(void)
195 unsigned long als[] = { FACILITIES_ALS };
198 for (i = 0; i < ARRAY_SIZE(als); i++) {
199 if ((stfle_fac_list[i] & als[i]) != als[i]) {
200 sclp_early_printk("Warning: The Linux kernel requires facilities cleared via command line option\n");
201 print_missing_facilities();
207 static void modify_fac_list(char *str)
209 unsigned long val, endval;
219 val = simple_strtoull(str, &endp, 0);
225 endval = simple_strtoull(str, &endp, 0);
229 while (val <= endval) {
230 modify_facility(val, clear);
234 modify_facility(val, clear);
240 check_cleared_facilities();
243 static char command_line_buf[COMMAND_LINE_SIZE];
244 void parse_boot_command_line(void)
251 kaslr_enabled = IS_ENABLED(CONFIG_RANDOMIZE_BASE);
252 args = strcpy(command_line_buf, early_command_line);
254 args = next_arg(args, ¶m, &val);
256 if (!strcmp(param, "mem") && val)
257 memory_limit = round_down(memparse(val, NULL), PAGE_SIZE);
259 if (!strcmp(param, "vmalloc") && val) {
260 vmalloc_size = round_up(memparse(val, NULL), PAGE_SIZE);
261 vmalloc_size_set = 1;
264 if (!strcmp(param, "dfltcc") && val) {
265 if (!strcmp(val, "off"))
266 zlib_dfltcc_support = ZLIB_DFLTCC_DISABLED;
267 else if (!strcmp(val, "on"))
268 zlib_dfltcc_support = ZLIB_DFLTCC_FULL;
269 else if (!strcmp(val, "def_only"))
270 zlib_dfltcc_support = ZLIB_DFLTCC_DEFLATE_ONLY;
271 else if (!strcmp(val, "inf_only"))
272 zlib_dfltcc_support = ZLIB_DFLTCC_INFLATE_ONLY;
273 else if (!strcmp(val, "always"))
274 zlib_dfltcc_support = ZLIB_DFLTCC_FULL_DEBUG;
277 if (!strcmp(param, "noexec")) {
278 rc = kstrtobool(val, &enabled);
283 if (!strcmp(param, "facilities") && val)
284 modify_fac_list(val);
286 if (!strcmp(param, "nokaslr"))
289 #if IS_ENABLED(CONFIG_KVM)
290 if (!strcmp(param, "prot_virt")) {
291 rc = kstrtobool(val, &enabled);