]> Git Repo - linux.git/blob - drivers/s390/char/sclp_early.c
Linux 6.14-rc3
[linux.git] / drivers / s390 / char / sclp_early.c
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/ctlreg.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_wti = !!(sccb->fac119 & 0x40);
48         sclp.has_kss = !!(sccb->fac98 & 0x01);
49         sclp.has_aisii = !!(sccb->fac118 & 0x40);
50         sclp.has_aeni = !!(sccb->fac118 & 0x20);
51         sclp.has_aisi = !!(sccb->fac118 & 0x10);
52         sclp.has_zpci_lsi = !!(sccb->fac118 & 0x01);
53         if (sccb->fac85 & 0x02)
54                 get_lowcore()->machine_flags |= MACHINE_FLAG_ESOP;
55         if (sccb->fac91 & 0x40)
56                 get_lowcore()->machine_flags |= MACHINE_FLAG_TLB_GUEST;
57         sclp.has_diag204_bif = !!(sccb->fac98 & 0x80);
58         sclp.has_diag310 = !!(sccb->fac91 & 0x80);
59         if (sccb->cpuoff > 134) {
60                 sclp.has_diag318 = !!(sccb->byte_134 & 0x80);
61                 sclp.has_diag320 = !!(sccb->byte_134 & 0x04);
62                 sclp.has_iplcc = !!(sccb->byte_134 & 0x02);
63         }
64         if (sccb->cpuoff > 137) {
65                 sclp.has_sipl = !!(sccb->cbl & 0x4000);
66                 sclp.has_sipl_eckd = !!(sccb->cbl & 0x2000);
67         }
68         if (sccb->cpuoff > 139)
69                 sclp.has_diag324 = !!(sccb->byte_139 & 0x80);
70         sclp.rnmax = sccb->rnmax ? sccb->rnmax : sccb->rnmax2;
71         sclp.rzm = sccb->rnsize ? sccb->rnsize : sccb->rnsize2;
72         sclp.rzm <<= 20;
73         sclp.ibc = sccb->ibc;
74
75         if (sccb->hamaxpow && sccb->hamaxpow < 64)
76                 sclp.hamax = (1UL << sccb->hamaxpow) - 1;
77         else
78                 sclp.hamax = U64_MAX;
79
80         if (!sccb->hcpua) {
81                 if (MACHINE_IS_VM)
82                         sclp.max_cores = 64;
83                 else
84                         sclp.max_cores = sccb->ncpurl;
85         } else {
86                 sclp.max_cores = sccb->hcpua + 1;
87         }
88
89         boot_cpu_address = stap();
90         cpue = (void *)sccb + sccb->cpuoff;
91         for (cpu = 0; cpu < sccb->ncpurl; cpue++, cpu++) {
92                 if (boot_cpu_address != cpue->core_id)
93                         continue;
94                 sclp.has_siif = cpue->siif;
95                 sclp.has_sigpif = cpue->sigpif;
96                 sclp.has_sief2 = cpue->sief2;
97                 sclp.has_gpere = cpue->gpere;
98                 sclp.has_ib = cpue->ib;
99                 sclp.has_cei = cpue->cei;
100                 sclp.has_skey = cpue->skey;
101                 break;
102         }
103
104         /* Save IPL information */
105         sclp_ipl_info.is_valid = 1;
106         if (sccb->fac91 & 0x2)
107                 sclp_ipl_info.has_dump = 1;
108         memcpy(&sclp_ipl_info.loadparm, &sccb->loadparm, LOADPARM_LEN);
109
110         if (sccb->hsa_size)
111                 sclp.hsa_size = (sccb->hsa_size - 1) * PAGE_SIZE;
112         sclp.mtid = (sccb->fac42 & 0x80) ? (sccb->fac42 & 31) : 0;
113         sclp.mtid_cp = (sccb->fac42 & 0x80) ? (sccb->fac43 & 31) : 0;
114         sclp.mtid_prev = (sccb->fac42 & 0x80) ? (sccb->fac66 & 31) : 0;
115
116         sclp.hmfai = sccb->hmfai;
117         sclp.has_dirq = !!(sccb->cpudirq & 0x80);
118 }
119
120 /*
121  * This function will be called after sclp_early_facilities_detect(), which gets
122  * called from early.c code. The sclp_early_facilities_detect() function retrieves
123  * and saves the IPL information.
124  */
125 void __init sclp_early_get_ipl_info(struct sclp_ipl_info *info)
126 {
127         *info = sclp_ipl_info;
128 }
129
130 int __init sclp_early_get_core_info(struct sclp_core_info *info)
131 {
132         struct read_cpu_info_sccb *sccb;
133         int length = test_facility(140) ? EXT_SCCB_READ_CPU : PAGE_SIZE;
134         int rc = 0;
135
136         if (!SCLP_HAS_CPU_INFO)
137                 return -EOPNOTSUPP;
138
139         sccb = memblock_alloc_low(length, PAGE_SIZE);
140         if (!sccb)
141                 return -ENOMEM;
142
143         memset(sccb, 0, length);
144         sccb->header.length = length;
145         sccb->header.control_mask[2] = 0x80;
146         if (sclp_early_cmd(SCLP_CMDW_READ_CPU_INFO, sccb)) {
147                 rc = -EIO;
148                 goto out;
149         }
150         if (sccb->header.response_code != 0x0010) {
151                 rc = -EIO;
152                 goto out;
153         }
154         sclp_fill_core_info(info, sccb);
155 out:
156         memblock_free(sccb, length);
157         return rc;
158 }
159
160 static void __init sclp_early_console_detect(struct init_sccb *sccb)
161 {
162         if (sccb->header.response_code != 0x20)
163                 return;
164
165         if (sclp_early_con_check_vt220(sccb))
166                 sclp.has_vt220 = 1;
167
168         if (sclp_early_con_check_linemode(sccb))
169                 sclp.has_linemode = 1;
170 }
171
172 void __init __no_sanitize_address sclp_early_adjust_va(void)
173 {
174         sclp_early_sccb = __va((unsigned long)sclp_early_sccb);
175 }
176
177 void __init sclp_early_detect(void)
178 {
179         void *sccb = sclp_early_sccb;
180
181         sclp_early_facilities_detect();
182
183         /*
184          * Turn off SCLP event notifications.  Also save remote masks in the
185          * sccb.  These are sufficient to detect sclp console capabilities.
186          */
187         sclp_early_set_event_mask(sccb, 0, 0);
188         sclp_early_console_detect(sccb);
189 }
This page took 0.045427 seconds and 4 git commands to generate.