xref: /openbmc/linux/drivers/s390/char/sclp_early.c (revision c4a11bf4)
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * SCLP early driver
4  *
5  * Copyright IBM Corp. 2013
6  */
7 
8 #define KMSG_COMPONENT "sclp_early"
9 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
10 
11 #include <linux/errno.h>
12 #include <linux/memblock.h>
13 #include <asm/ctl_reg.h>
14 #include <asm/sclp.h>
15 #include <asm/ipl.h>
16 #include <asm/setup.h>
17 #include <asm/facility.h>
18 #include "sclp_sdias.h"
19 #include "sclp.h"
20 
21 static struct sclp_ipl_info sclp_ipl_info;
22 
23 struct sclp_info sclp;
24 EXPORT_SYMBOL(sclp);
25 
26 static void __init sclp_early_facilities_detect(void)
27 {
28 	struct sclp_core_entry *cpue;
29 	struct read_info_sccb *sccb;
30 	u16 boot_cpu_address, cpu;
31 
32 	sccb = sclp_early_get_info();
33 	if (!sccb)
34 		return;
35 
36 	sclp.facilities = sccb->facilities;
37 	sclp.has_sprp = !!(sccb->fac84 & 0x02);
38 	sclp.has_core_type = !!(sccb->fac84 & 0x01);
39 	sclp.has_gsls = !!(sccb->fac85 & 0x80);
40 	sclp.has_64bscao = !!(sccb->fac116 & 0x80);
41 	sclp.has_cmma = !!(sccb->fac116 & 0x40);
42 	sclp.has_esca = !!(sccb->fac116 & 0x08);
43 	sclp.has_pfmfi = !!(sccb->fac117 & 0x40);
44 	sclp.has_ibs = !!(sccb->fac117 & 0x20);
45 	sclp.has_gisaf = !!(sccb->fac118 & 0x08);
46 	sclp.has_hvs = !!(sccb->fac119 & 0x80);
47 	sclp.has_kss = !!(sccb->fac98 & 0x01);
48 	if (sccb->fac85 & 0x02)
49 		S390_lowcore.machine_flags |= MACHINE_FLAG_ESOP;
50 	if (sccb->fac91 & 0x40)
51 		S390_lowcore.machine_flags |= MACHINE_FLAG_TLB_GUEST;
52 	if (sccb->cpuoff > 134)
53 		sclp.has_diag318 = !!(sccb->byte_134 & 0x80);
54 	if (sccb->cpuoff > 137)
55 		sclp.has_sipl = !!(sccb->cbl & 0x4000);
56 	sclp.rnmax = sccb->rnmax ? sccb->rnmax : sccb->rnmax2;
57 	sclp.rzm = sccb->rnsize ? sccb->rnsize : sccb->rnsize2;
58 	sclp.rzm <<= 20;
59 	sclp.ibc = sccb->ibc;
60 
61 	if (sccb->hamaxpow && sccb->hamaxpow < 64)
62 		sclp.hamax = (1UL << sccb->hamaxpow) - 1;
63 	else
64 		sclp.hamax = U64_MAX;
65 
66 	if (!sccb->hcpua) {
67 		if (MACHINE_IS_VM)
68 			sclp.max_cores = 64;
69 		else
70 			sclp.max_cores = sccb->ncpurl;
71 	} else {
72 		sclp.max_cores = sccb->hcpua + 1;
73 	}
74 
75 	boot_cpu_address = stap();
76 	cpue = (void *)sccb + sccb->cpuoff;
77 	for (cpu = 0; cpu < sccb->ncpurl; cpue++, cpu++) {
78 		if (boot_cpu_address != cpue->core_id)
79 			continue;
80 		sclp.has_siif = cpue->siif;
81 		sclp.has_sigpif = cpue->sigpif;
82 		sclp.has_sief2 = cpue->sief2;
83 		sclp.has_gpere = cpue->gpere;
84 		sclp.has_ib = cpue->ib;
85 		sclp.has_cei = cpue->cei;
86 		sclp.has_skey = cpue->skey;
87 		break;
88 	}
89 
90 	/* Save IPL information */
91 	sclp_ipl_info.is_valid = 1;
92 	if (sccb->fac91 & 0x2)
93 		sclp_ipl_info.has_dump = 1;
94 	memcpy(&sclp_ipl_info.loadparm, &sccb->loadparm, LOADPARM_LEN);
95 
96 	if (sccb->hsa_size)
97 		sclp.hsa_size = (sccb->hsa_size - 1) * PAGE_SIZE;
98 	sclp.mtid = (sccb->fac42 & 0x80) ? (sccb->fac42 & 31) : 0;
99 	sclp.mtid_cp = (sccb->fac42 & 0x80) ? (sccb->fac43 & 31) : 0;
100 	sclp.mtid_prev = (sccb->fac42 & 0x80) ? (sccb->fac66 & 31) : 0;
101 
102 	sclp.hmfai = sccb->hmfai;
103 	sclp.has_dirq = !!(sccb->cpudirq & 0x80);
104 }
105 
106 /*
107  * This function will be called after sclp_early_facilities_detect(), which gets
108  * called from early.c code. The sclp_early_facilities_detect() function retrieves
109  * and saves the IPL information.
110  */
111 void __init sclp_early_get_ipl_info(struct sclp_ipl_info *info)
112 {
113 	*info = sclp_ipl_info;
114 }
115 
116 int __init sclp_early_get_core_info(struct sclp_core_info *info)
117 {
118 	struct read_cpu_info_sccb *sccb;
119 	int length = test_facility(140) ? EXT_SCCB_READ_CPU : PAGE_SIZE;
120 	int rc = 0;
121 
122 	if (!SCLP_HAS_CPU_INFO)
123 		return -EOPNOTSUPP;
124 
125 	sccb = memblock_alloc_low(length, PAGE_SIZE);
126 	if (!sccb)
127 		return -ENOMEM;
128 
129 	memset(sccb, 0, length);
130 	sccb->header.length = length;
131 	sccb->header.control_mask[2] = 0x80;
132 	if (sclp_early_cmd(SCLP_CMDW_READ_CPU_INFO, sccb)) {
133 		rc = -EIO;
134 		goto out;
135 	}
136 	if (sccb->header.response_code != 0x0010) {
137 		rc = -EIO;
138 		goto out;
139 	}
140 	sclp_fill_core_info(info, sccb);
141 out:
142 	memblock_phys_free((unsigned long)sccb, length);
143 	return rc;
144 }
145 
146 static void __init sclp_early_console_detect(struct init_sccb *sccb)
147 {
148 	if (sccb->header.response_code != 0x20)
149 		return;
150 
151 	if (sclp_early_con_check_vt220(sccb))
152 		sclp.has_vt220 = 1;
153 
154 	if (sclp_early_con_check_linemode(sccb))
155 		sclp.has_linemode = 1;
156 }
157 
158 void __init sclp_early_adjust_va(void)
159 {
160 	sclp_early_sccb = __va((unsigned long)sclp_early_sccb);
161 }
162 
163 void __init sclp_early_detect(void)
164 {
165 	void *sccb = sclp_early_sccb;
166 
167 	sclp_early_facilities_detect();
168 
169 	/*
170 	 * Turn off SCLP event notifications.  Also save remote masks in the
171 	 * sccb.  These are sufficient to detect sclp console capabilities.
172 	 */
173 	sclp_early_set_event_mask(sccb, 0, 0);
174 	sclp_early_console_detect(sccb);
175 }
176