Linux Audio

Check our new training course

Loading...
v6.13.7
  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/abs_lowcore.h>
  7#include <asm/page-states.h>
  8#include <asm/ebcdic.h>
  9#include <asm/sclp.h>
 10#include <asm/sections.h>
 11#include <asm/boot_data.h>
 12#include <asm/facility.h>
 13#include <asm/setup.h>
 14#include <asm/uv.h>
 15#include "boot.h"
 16
 17struct parmarea parmarea __section(".parmarea") = {
 18	.kernel_version		= (unsigned long)kernel_version,
 19	.max_command_line_size	= COMMAND_LINE_SIZE,
 20	.command_line		= "root=/dev/ram0 ro",
 21};
 22
 23char __bootdata(early_command_line)[COMMAND_LINE_SIZE];
 24
 25unsigned int __bootdata_preserved(zlib_dfltcc_support) = ZLIB_DFLTCC_FULL;
 26struct ipl_parameter_block __bootdata_preserved(ipl_block);
 27int __bootdata_preserved(ipl_block_valid);
 28int __bootdata_preserved(__kaslr_enabled);
 29int __bootdata_preserved(cmma_flag) = 1;
 30
 31unsigned long vmalloc_size = VMALLOC_DEFAULT_SIZE;
 32unsigned long memory_limit;
 33int vmalloc_size_set;
 34
 35static inline int __diag308(unsigned long subcode, void *addr)
 36{
 37	unsigned long reg1, reg2;
 38	union register_pair r1;
 39	psw_t old;
 40
 41	r1.even = (unsigned long) addr;
 42	r1.odd	= 0;
 43	asm volatile(
 44		"	mvc	0(16,%[psw_old]),0(%[psw_pgm])\n"
 45		"	epsw	%[reg1],%[reg2]\n"
 46		"	st	%[reg1],0(%[psw_pgm])\n"
 47		"	st	%[reg2],4(%[psw_pgm])\n"
 48		"	larl	%[reg1],1f\n"
 49		"	stg	%[reg1],8(%[psw_pgm])\n"
 50		"	diag	%[r1],%[subcode],0x308\n"
 51		"1:	mvc	0(16,%[psw_pgm]),0(%[psw_old])\n"
 52		: [r1] "+&d" (r1.pair),
 53		  [reg1] "=&d" (reg1),
 54		  [reg2] "=&a" (reg2),
 55		  "+Q" (get_lowcore()->program_new_psw),
 56		  "=Q" (old)
 57		: [subcode] "d" (subcode),
 58		  [psw_old] "a" (&old),
 59		  [psw_pgm] "a" (&get_lowcore()->program_new_psw)
 60		: "cc", "memory");
 61	return r1.odd;
 62}
 63
 64void store_ipl_parmblock(void)
 65{
 66	int rc;
 67
 68	rc = __diag308(DIAG308_STORE, &ipl_block);
 69	if (rc == DIAG308_RC_OK &&
 70	    ipl_block.hdr.version <= IPL_MAX_SUPPORTED_VERSION)
 71		ipl_block_valid = 1;
 72}
 73
 74bool is_ipl_block_dump(void)
 75{
 76	if (ipl_block.pb0_hdr.pbt == IPL_PBT_FCP &&
 77	    ipl_block.fcp.opt == IPL_PB0_FCP_OPT_DUMP)
 78		return true;
 79	if (ipl_block.pb0_hdr.pbt == IPL_PBT_NVME &&
 80	    ipl_block.nvme.opt == IPL_PB0_NVME_OPT_DUMP)
 81		return true;
 82	if (ipl_block.pb0_hdr.pbt == IPL_PBT_ECKD &&
 83	    ipl_block.eckd.opt == IPL_PB0_ECKD_OPT_DUMP)
 84		return true;
 85	return false;
 86}
 87
 88static size_t scpdata_length(const u8 *buf, size_t count)
 89{
 90	while (count) {
 91		if (buf[count - 1] != '\0' && buf[count - 1] != ' ')
 92			break;
 93		count--;
 94	}
 95	return count;
 96}
 97
 98static size_t ipl_block_get_ascii_scpdata(char *dest, size_t size,
 99					  const struct ipl_parameter_block *ipb)
100{
101	const __u8 *scp_data;
102	__u32 scp_data_len;
103	int has_lowercase;
104	size_t count = 0;
105	size_t i;
106
107	switch (ipb->pb0_hdr.pbt) {
108	case IPL_PBT_FCP:
109		scp_data_len = ipb->fcp.scp_data_len;
110		scp_data = ipb->fcp.scp_data;
111		break;
112	case IPL_PBT_NVME:
113		scp_data_len = ipb->nvme.scp_data_len;
114		scp_data = ipb->nvme.scp_data;
115		break;
116	case IPL_PBT_ECKD:
117		scp_data_len = ipb->eckd.scp_data_len;
118		scp_data = ipb->eckd.scp_data;
119		break;
120
121	default:
122		goto out;
123	}
124
125	count = min(size - 1, scpdata_length(scp_data, scp_data_len));
126	if (!count)
127		goto out;
128
129	has_lowercase = 0;
130	for (i = 0; i < count; i++) {
131		if (!isascii(scp_data[i])) {
132			count = 0;
133			goto out;
134		}
135		if (!has_lowercase && islower(scp_data[i]))
136			has_lowercase = 1;
137	}
138
139	if (has_lowercase)
140		memcpy(dest, scp_data, count);
141	else
142		for (i = 0; i < count; i++)
143			dest[i] = tolower(scp_data[i]);
144out:
145	dest[count] = '\0';
146	return count;
147}
148
149static void append_ipl_block_parm(void)
150{
151	char *parm, *delim;
152	size_t len, rc = 0;
153
154	len = strlen(early_command_line);
155
156	delim = early_command_line + len;    /* '\0' character position */
157	parm = early_command_line + len + 1; /* append right after '\0' */
158
159	switch (ipl_block.pb0_hdr.pbt) {
160	case IPL_PBT_CCW:
161		rc = ipl_block_get_ascii_vmparm(
162			parm, COMMAND_LINE_SIZE - len - 1, &ipl_block);
163		break;
164	case IPL_PBT_FCP:
165	case IPL_PBT_NVME:
166	case IPL_PBT_ECKD:
167		rc = ipl_block_get_ascii_scpdata(
168			parm, COMMAND_LINE_SIZE - len - 1, &ipl_block);
169		break;
170	}
171	if (rc) {
172		if (*parm == '=')
173			memmove(early_command_line, parm + 1, rc);
174		else
175			*delim = ' '; /* replace '\0' with space */
176	}
177}
178
179static inline int has_ebcdic_char(const char *str)
180{
181	int i;
182
183	for (i = 0; str[i]; i++)
184		if (str[i] & 0x80)
185			return 1;
186	return 0;
187}
188
189void setup_boot_command_line(void)
190{
191	parmarea.command_line[COMMAND_LINE_SIZE - 1] = 0;
192	/* convert arch command line to ascii if necessary */
193	if (has_ebcdic_char(parmarea.command_line))
194		EBCASC(parmarea.command_line, COMMAND_LINE_SIZE);
195	/* copy arch command line */
196	strcpy(early_command_line, strim(parmarea.command_line));
197
198	/* append IPL PARM data to the boot command line */
199	if (!is_prot_virt_guest() && ipl_block_valid)
200		append_ipl_block_parm();
201}
202
203static void modify_facility(unsigned long nr, bool clear)
204{
205	if (clear)
206		__clear_facility(nr, stfle_fac_list);
207	else
208		__set_facility(nr, stfle_fac_list);
209}
210
211static void check_cleared_facilities(void)
212{
213	unsigned long als[] = { FACILITIES_ALS };
214	int i;
215
216	for (i = 0; i < ARRAY_SIZE(als); i++) {
217		if ((stfle_fac_list[i] & als[i]) != als[i]) {
218			boot_printk("Warning: The Linux kernel requires facilities cleared via command line option\n");
219			print_missing_facilities();
220			break;
221		}
222	}
223}
224
225static void modify_fac_list(char *str)
226{
227	unsigned long val, endval;
228	char *endp;
229	bool clear;
230
231	while (*str) {
232		clear = false;
233		if (*str == '!') {
234			clear = true;
235			str++;
236		}
237		val = simple_strtoull(str, &endp, 0);
238		if (str == endp)
239			break;
240		str = endp;
241		if (*str == '-') {
242			str++;
243			endval = simple_strtoull(str, &endp, 0);
244			if (str == endp)
245				break;
246			str = endp;
247			while (val <= endval) {
248				modify_facility(val, clear);
249				val++;
250			}
251		} else {
252			modify_facility(val, clear);
253		}
254		if (*str != ',')
255			break;
256		str++;
257	}
258	check_cleared_facilities();
259}
260
261static char command_line_buf[COMMAND_LINE_SIZE];
262void parse_boot_command_line(void)
263{
264	char *param, *val;
265	bool enabled;
266	char *args;
267	int rc;
268
269	__kaslr_enabled = IS_ENABLED(CONFIG_RANDOMIZE_BASE);
270	args = strcpy(command_line_buf, early_command_line);
271	while (*args) {
272		args = next_arg(args, &param, &val);
273
274		if (!strcmp(param, "mem") && val)
275			memory_limit = round_down(memparse(val, NULL), PAGE_SIZE);
276
277		if (!strcmp(param, "vmalloc") && val) {
278			vmalloc_size = round_up(memparse(val, NULL), _SEGMENT_SIZE);
279			vmalloc_size_set = 1;
280		}
281
282		if (!strcmp(param, "dfltcc") && val) {
283			if (!strcmp(val, "off"))
284				zlib_dfltcc_support = ZLIB_DFLTCC_DISABLED;
285			else if (!strcmp(val, "on"))
286				zlib_dfltcc_support = ZLIB_DFLTCC_FULL;
287			else if (!strcmp(val, "def_only"))
288				zlib_dfltcc_support = ZLIB_DFLTCC_DEFLATE_ONLY;
289			else if (!strcmp(val, "inf_only"))
290				zlib_dfltcc_support = ZLIB_DFLTCC_INFLATE_ONLY;
291			else if (!strcmp(val, "always"))
292				zlib_dfltcc_support = ZLIB_DFLTCC_FULL_DEBUG;
293		}
294
295		if (!strcmp(param, "facilities") && val)
296			modify_fac_list(val);
297
298		if (!strcmp(param, "nokaslr"))
299			__kaslr_enabled = 0;
300
301		if (!strcmp(param, "cmma")) {
302			rc = kstrtobool(val, &enabled);
303			if (!rc && !enabled)
304				cmma_flag = 0;
305		}
306
307#if IS_ENABLED(CONFIG_KVM)
308		if (!strcmp(param, "prot_virt")) {
309			rc = kstrtobool(val, &enabled);
310			if (!rc && enabled)
311				prot_virt_host = 1;
312		}
313#endif
314		if (!strcmp(param, "relocate_lowcore") && test_facility(193))
315			relocate_lowcore = 1;
316	}
317}
v6.9.4
  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/page-states.h>
  7#include <asm/ebcdic.h>
  8#include <asm/sclp.h>
  9#include <asm/sections.h>
 10#include <asm/boot_data.h>
 11#include <asm/facility.h>
 12#include <asm/setup.h>
 13#include <asm/uv.h>
 14#include "boot.h"
 15
 16struct parmarea parmarea __section(".parmarea") = {
 17	.kernel_version		= (unsigned long)kernel_version,
 18	.max_command_line_size	= COMMAND_LINE_SIZE,
 19	.command_line		= "root=/dev/ram0 ro",
 20};
 21
 22char __bootdata(early_command_line)[COMMAND_LINE_SIZE];
 23
 24unsigned int __bootdata_preserved(zlib_dfltcc_support) = ZLIB_DFLTCC_FULL;
 25struct ipl_parameter_block __bootdata_preserved(ipl_block);
 26int __bootdata_preserved(ipl_block_valid);
 27int __bootdata_preserved(__kaslr_enabled);
 28int __bootdata_preserved(cmma_flag) = 1;
 29
 30unsigned long vmalloc_size = VMALLOC_DEFAULT_SIZE;
 31unsigned long memory_limit;
 32int vmalloc_size_set;
 33
 34static inline int __diag308(unsigned long subcode, void *addr)
 35{
 36	unsigned long reg1, reg2;
 37	union register_pair r1;
 38	psw_t old;
 39
 40	r1.even = (unsigned long) addr;
 41	r1.odd	= 0;
 42	asm volatile(
 43		"	mvc	0(16,%[psw_old]),0(%[psw_pgm])\n"
 44		"	epsw	%[reg1],%[reg2]\n"
 45		"	st	%[reg1],0(%[psw_pgm])\n"
 46		"	st	%[reg2],4(%[psw_pgm])\n"
 47		"	larl	%[reg1],1f\n"
 48		"	stg	%[reg1],8(%[psw_pgm])\n"
 49		"	diag	%[r1],%[subcode],0x308\n"
 50		"1:	mvc	0(16,%[psw_pgm]),0(%[psw_old])\n"
 51		: [r1] "+&d" (r1.pair),
 52		  [reg1] "=&d" (reg1),
 53		  [reg2] "=&a" (reg2),
 54		  "+Q" (S390_lowcore.program_new_psw),
 55		  "=Q" (old)
 56		: [subcode] "d" (subcode),
 57		  [psw_old] "a" (&old),
 58		  [psw_pgm] "a" (&S390_lowcore.program_new_psw)
 59		: "cc", "memory");
 60	return r1.odd;
 61}
 62
 63void store_ipl_parmblock(void)
 64{
 65	int rc;
 66
 67	rc = __diag308(DIAG308_STORE, &ipl_block);
 68	if (rc == DIAG308_RC_OK &&
 69	    ipl_block.hdr.version <= IPL_MAX_SUPPORTED_VERSION)
 70		ipl_block_valid = 1;
 71}
 72
 73bool is_ipl_block_dump(void)
 74{
 75	if (ipl_block.pb0_hdr.pbt == IPL_PBT_FCP &&
 76	    ipl_block.fcp.opt == IPL_PB0_FCP_OPT_DUMP)
 77		return true;
 78	if (ipl_block.pb0_hdr.pbt == IPL_PBT_NVME &&
 79	    ipl_block.nvme.opt == IPL_PB0_NVME_OPT_DUMP)
 80		return true;
 81	if (ipl_block.pb0_hdr.pbt == IPL_PBT_ECKD &&
 82	    ipl_block.eckd.opt == IPL_PB0_ECKD_OPT_DUMP)
 83		return true;
 84	return false;
 85}
 86
 87static size_t scpdata_length(const u8 *buf, size_t count)
 88{
 89	while (count) {
 90		if (buf[count - 1] != '\0' && buf[count - 1] != ' ')
 91			break;
 92		count--;
 93	}
 94	return count;
 95}
 96
 97static size_t ipl_block_get_ascii_scpdata(char *dest, size_t size,
 98					  const struct ipl_parameter_block *ipb)
 99{
100	const __u8 *scp_data;
101	__u32 scp_data_len;
102	int has_lowercase;
103	size_t count = 0;
104	size_t i;
105
106	switch (ipb->pb0_hdr.pbt) {
107	case IPL_PBT_FCP:
108		scp_data_len = ipb->fcp.scp_data_len;
109		scp_data = ipb->fcp.scp_data;
110		break;
111	case IPL_PBT_NVME:
112		scp_data_len = ipb->nvme.scp_data_len;
113		scp_data = ipb->nvme.scp_data;
114		break;
115	case IPL_PBT_ECKD:
116		scp_data_len = ipb->eckd.scp_data_len;
117		scp_data = ipb->eckd.scp_data;
118		break;
119
120	default:
121		goto out;
122	}
123
124	count = min(size - 1, scpdata_length(scp_data, scp_data_len));
125	if (!count)
126		goto out;
127
128	has_lowercase = 0;
129	for (i = 0; i < count; i++) {
130		if (!isascii(scp_data[i])) {
131			count = 0;
132			goto out;
133		}
134		if (!has_lowercase && islower(scp_data[i]))
135			has_lowercase = 1;
136	}
137
138	if (has_lowercase)
139		memcpy(dest, scp_data, count);
140	else
141		for (i = 0; i < count; i++)
142			dest[i] = tolower(scp_data[i]);
143out:
144	dest[count] = '\0';
145	return count;
146}
147
148static void append_ipl_block_parm(void)
149{
150	char *parm, *delim;
151	size_t len, rc = 0;
152
153	len = strlen(early_command_line);
154
155	delim = early_command_line + len;    /* '\0' character position */
156	parm = early_command_line + len + 1; /* append right after '\0' */
157
158	switch (ipl_block.pb0_hdr.pbt) {
159	case IPL_PBT_CCW:
160		rc = ipl_block_get_ascii_vmparm(
161			parm, COMMAND_LINE_SIZE - len - 1, &ipl_block);
162		break;
163	case IPL_PBT_FCP:
164	case IPL_PBT_NVME:
165	case IPL_PBT_ECKD:
166		rc = ipl_block_get_ascii_scpdata(
167			parm, COMMAND_LINE_SIZE - len - 1, &ipl_block);
168		break;
169	}
170	if (rc) {
171		if (*parm == '=')
172			memmove(early_command_line, parm + 1, rc);
173		else
174			*delim = ' '; /* replace '\0' with space */
175	}
176}
177
178static inline int has_ebcdic_char(const char *str)
179{
180	int i;
181
182	for (i = 0; str[i]; i++)
183		if (str[i] & 0x80)
184			return 1;
185	return 0;
186}
187
188void setup_boot_command_line(void)
189{
190	parmarea.command_line[COMMAND_LINE_SIZE - 1] = 0;
191	/* convert arch command line to ascii if necessary */
192	if (has_ebcdic_char(parmarea.command_line))
193		EBCASC(parmarea.command_line, COMMAND_LINE_SIZE);
194	/* copy arch command line */
195	strcpy(early_command_line, strim(parmarea.command_line));
196
197	/* append IPL PARM data to the boot command line */
198	if (!is_prot_virt_guest() && ipl_block_valid)
199		append_ipl_block_parm();
200}
201
202static void modify_facility(unsigned long nr, bool clear)
203{
204	if (clear)
205		__clear_facility(nr, stfle_fac_list);
206	else
207		__set_facility(nr, stfle_fac_list);
208}
209
210static void check_cleared_facilities(void)
211{
212	unsigned long als[] = { FACILITIES_ALS };
213	int i;
214
215	for (i = 0; i < ARRAY_SIZE(als); i++) {
216		if ((stfle_fac_list[i] & als[i]) != als[i]) {
217			sclp_early_printk("Warning: The Linux kernel requires facilities cleared via command line option\n");
218			print_missing_facilities();
219			break;
220		}
221	}
222}
223
224static void modify_fac_list(char *str)
225{
226	unsigned long val, endval;
227	char *endp;
228	bool clear;
229
230	while (*str) {
231		clear = false;
232		if (*str == '!') {
233			clear = true;
234			str++;
235		}
236		val = simple_strtoull(str, &endp, 0);
237		if (str == endp)
238			break;
239		str = endp;
240		if (*str == '-') {
241			str++;
242			endval = simple_strtoull(str, &endp, 0);
243			if (str == endp)
244				break;
245			str = endp;
246			while (val <= endval) {
247				modify_facility(val, clear);
248				val++;
249			}
250		} else {
251			modify_facility(val, clear);
252		}
253		if (*str != ',')
254			break;
255		str++;
256	}
257	check_cleared_facilities();
258}
259
260static char command_line_buf[COMMAND_LINE_SIZE];
261void parse_boot_command_line(void)
262{
263	char *param, *val;
264	bool enabled;
265	char *args;
266	int rc;
267
268	__kaslr_enabled = IS_ENABLED(CONFIG_RANDOMIZE_BASE);
269	args = strcpy(command_line_buf, early_command_line);
270	while (*args) {
271		args = next_arg(args, &param, &val);
272
273		if (!strcmp(param, "mem") && val)
274			memory_limit = round_down(memparse(val, NULL), PAGE_SIZE);
275
276		if (!strcmp(param, "vmalloc") && val) {
277			vmalloc_size = round_up(memparse(val, NULL), _SEGMENT_SIZE);
278			vmalloc_size_set = 1;
279		}
280
281		if (!strcmp(param, "dfltcc") && val) {
282			if (!strcmp(val, "off"))
283				zlib_dfltcc_support = ZLIB_DFLTCC_DISABLED;
284			else if (!strcmp(val, "on"))
285				zlib_dfltcc_support = ZLIB_DFLTCC_FULL;
286			else if (!strcmp(val, "def_only"))
287				zlib_dfltcc_support = ZLIB_DFLTCC_DEFLATE_ONLY;
288			else if (!strcmp(val, "inf_only"))
289				zlib_dfltcc_support = ZLIB_DFLTCC_INFLATE_ONLY;
290			else if (!strcmp(val, "always"))
291				zlib_dfltcc_support = ZLIB_DFLTCC_FULL_DEBUG;
292		}
293
294		if (!strcmp(param, "facilities") && val)
295			modify_fac_list(val);
296
297		if (!strcmp(param, "nokaslr"))
298			__kaslr_enabled = 0;
299
300		if (!strcmp(param, "cmma")) {
301			rc = kstrtobool(val, &enabled);
302			if (!rc && !enabled)
303				cmma_flag = 0;
304		}
305
306#if IS_ENABLED(CONFIG_KVM)
307		if (!strcmp(param, "prot_virt")) {
308			rc = kstrtobool(val, &enabled);
309			if (!rc && enabled)
310				prot_virt_host = 1;
311		}
312#endif
 
 
313	}
314}