blob: 9a74abb9224d02fc47041e98a6600265a3bac881 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001// SPDX-License-Identifier: GPL-2.0
Michael Holzheue657d8f2013-11-13 10:38:27 +01002/*
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
Sebastian Otta313bdc2015-06-25 09:32:22 +020011#include <linux/errno.h>
Michael Holzheuacf6a002013-11-13 10:38:27 +010012#include <asm/ctl_reg.h>
Michael Holzheue657d8f2013-11-13 10:38:27 +010013#include <asm/sclp.h>
14#include <asm/ipl.h>
15#include "sclp_sdias.h"
16#include "sclp.h"
17
Michael Holzheuacf6a002013-11-13 10:38:27 +010018#define SCLP_CMDW_READ_SCP_INFO 0x00020001
19#define SCLP_CMDW_READ_SCP_INFO_FORCED 0x00120001
20
21struct read_info_sccb {
22 struct sccb_header header; /* 0-7 */
23 u16 rnmax; /* 8-9 */
24 u8 rnsize; /* 10 */
Martin Schwidefsky10ad34b2015-01-14 17:52:10 +010025 u8 _pad_11[16 - 11]; /* 11-15 */
Heiko Carstenscf813db2014-03-10 14:50:16 +010026 u16 ncpurl; /* 16-17 */
Heiko Carstens217a4402013-12-30 12:54:14 +010027 u16 cpuoff; /* 18-19 */
Martin Schwidefsky10ad34b2015-01-14 17:52:10 +010028 u8 _pad_20[24 - 20]; /* 20-23 */
Michael Holzheuacf6a002013-11-13 10:38:27 +010029 u8 loadparm[8]; /* 24-31 */
Martin Schwidefsky10ad34b2015-01-14 17:52:10 +010030 u8 _pad_32[42 - 32]; /* 32-41 */
31 u8 fac42; /* 42 */
32 u8 fac43; /* 43 */
33 u8 _pad_44[48 - 44]; /* 44-47 */
Michael Holzheuacf6a002013-11-13 10:38:27 +010034 u64 facilities; /* 48-55 */
Martin Schwidefsky10ad34b2015-01-14 17:52:10 +010035 u8 _pad_56[66 - 56]; /* 56-65 */
36 u8 fac66; /* 66 */
37 u8 _pad_67[76 - 67]; /* 67-83 */
Michael Mueller570126d2014-03-15 18:16:26 +010038 u32 ibc; /* 76-79 */
Martin Schwidefsky10ad34b2015-01-14 17:52:10 +010039 u8 _pad80[84 - 80]; /* 80-83 */
Michael Holzheuacf6a002013-11-13 10:38:27 +010040 u8 fac84; /* 84 */
41 u8 fac85; /* 85 */
Martin Schwidefsky10ad34b2015-01-14 17:52:10 +010042 u8 _pad_86[91 - 86]; /* 86-90 */
Martin Schwidefsky118bd312016-07-26 16:53:09 +020043 u8 fac91; /* 91 */
Farhan Ali71cb1bf2017-02-23 13:39:17 -050044 u8 _pad_92[98 - 92]; /* 92-97 */
45 u8 fac98; /* 98 */
Guenther Hutzl32e6b232014-12-01 17:24:42 +010046 u8 hamaxpow; /* 99 */
Michael Holzheuacf6a002013-11-13 10:38:27 +010047 u32 rnsize2; /* 100-103 */
48 u64 rnmax2; /* 104-111 */
Eugene (jno) Dvurechenskif7ba1d32014-10-09 16:04:48 +020049 u8 _pad_112[116 - 112]; /* 112-115 */
50 u8 fac116; /* 116 */
David Hildenbranda0eb55e62015-11-24 13:02:25 +010051 u8 fac117; /* 117 */
Michael Mueller9e73ea72017-06-12 13:49:28 +020052 u8 fac118; /* 118 */
Eugene (jno) Dvurechenskif7ba1d32014-10-09 16:04:48 +020053 u8 fac119; /* 119 */
Heiko Carstenscf813db2014-03-10 14:50:16 +010054 u16 hcpua; /* 120-121 */
Alexander Yarygin154fa272016-04-01 15:36:51 +030055 u8 _pad_122[124 - 122]; /* 122-123 */
56 u32 hmfai; /* 124-127 */
57 u8 _pad_128[4096 - 128]; /* 128-4095 */
Michael Holzheuacf6a002013-11-13 10:38:27 +010058} __packed __aligned(PAGE_SIZE);
59
Hendrik Brueckner333cce92013-12-05 18:46:51 +010060static struct sclp_ipl_info sclp_ipl_info;
Michael Holzheue657d8f2013-11-13 10:38:27 +010061
David Hildenbrand37c5f6c2015-05-06 13:18:59 +020062struct sclp_info sclp;
63EXPORT_SYMBOL(sclp);
Michael Holzheuacf6a002013-11-13 10:38:27 +010064
Heiko Carstensd5ab7a32017-01-24 15:58:52 +010065static int __init sclp_early_read_info(struct read_info_sccb *sccb)
Michael Holzheuacf6a002013-11-13 10:38:27 +010066{
Heiko Carstensf694bb32017-02-02 12:33:03 +010067 int i;
Michael Holzheuacf6a002013-11-13 10:38:27 +010068 sclp_cmdw_t commands[] = {SCLP_CMDW_READ_SCP_INFO_FORCED,
69 SCLP_CMDW_READ_SCP_INFO};
70
Michael Holzheuacf6a002013-11-13 10:38:27 +010071 for (i = 0; i < ARRAY_SIZE(commands); i++) {
Heiko Carstensf694bb32017-02-02 12:33:03 +010072 memset(sccb, 0, sizeof(*sccb));
73 sccb->header.length = sizeof(*sccb);
74 sccb->header.function_code = 0x80;
75 sccb->header.control_mask[2] = 0x80;
76 if (sclp_early_cmd(commands[i], sccb))
Michael Holzheuacf6a002013-11-13 10:38:27 +010077 break;
Hendrik Brueckner333cce92013-12-05 18:46:51 +010078 if (sccb->header.response_code == 0x10)
79 return 0;
Michael Holzheuacf6a002013-11-13 10:38:27 +010080 if (sccb->header.response_code != 0x1f0)
81 break;
82 }
Hendrik Brueckner333cce92013-12-05 18:46:51 +010083 return -EIO;
Michael Holzheuacf6a002013-11-13 10:38:27 +010084}
85
Heiko Carstensd5ab7a32017-01-24 15:58:52 +010086static void __init sclp_early_facilities_detect(struct read_info_sccb *sccb)
Michael Holzheuacf6a002013-11-13 10:38:27 +010087{
Martin Schwidefskyd08d9432015-06-18 14:23:00 +020088 struct sclp_core_entry *cpue;
Heiko Carstens217a4402013-12-30 12:54:14 +010089 u16 boot_cpu_address, cpu;
90
Heiko Carstensd5ab7a32017-01-24 15:58:52 +010091 if (sclp_early_read_info(sccb))
Michael Holzheuacf6a002013-11-13 10:38:27 +010092 return;
93
David Hildenbrand78335a32015-05-06 09:17:51 +020094 sclp.facilities = sccb->facilities;
David Hildenbrand37c5f6c2015-05-06 13:18:59 +020095 sclp.has_sprp = !!(sccb->fac84 & 0x02);
Martin Schwidefskyd08d9432015-06-18 14:23:00 +020096 sclp.has_core_type = !!(sccb->fac84 & 0x01);
David Hildenbrand5236c752015-11-24 12:53:46 +010097 sclp.has_gsls = !!(sccb->fac85 & 0x80);
David Hildenbrand4013ade2015-11-24 12:49:43 +010098 sclp.has_64bscao = !!(sccb->fac116 & 0x80);
David Hildenbrand09be9cb2015-11-24 12:55:35 +010099 sclp.has_cmma = !!(sccb->fac116 & 0x40);
Eugene (jno) Dvurechenskif7ba1d32014-10-09 16:04:48 +0200100 sclp.has_esca = !!(sccb->fac116 & 0x08);
David Hildenbranda0eb55e62015-11-24 13:02:25 +0100101 sclp.has_pfmfi = !!(sccb->fac117 & 0x40);
David Hildenbrand9c375492015-11-24 13:02:52 +0100102 sclp.has_ibs = !!(sccb->fac117 & 0x20);
Michael Mueller9e73ea72017-06-12 13:49:28 +0200103 sclp.has_gisaf = !!(sccb->fac118 & 0x08);
Eugene (jno) Dvurechenskif7ba1d32014-10-09 16:04:48 +0200104 sclp.has_hvs = !!(sccb->fac119 & 0x80);
Farhan Ali71cb1bf2017-02-23 13:39:17 -0500105 sclp.has_kss = !!(sccb->fac98 & 0x01);
Michael Holzheuacf6a002013-11-13 10:38:27 +0100106 if (sccb->fac85 & 0x02)
107 S390_lowcore.machine_flags |= MACHINE_FLAG_ESOP;
Martin Schwidefsky118bd312016-07-26 16:53:09 +0200108 if (sccb->fac91 & 0x40)
109 S390_lowcore.machine_flags |= MACHINE_FLAG_TLB_GUEST;
David Hildenbrand37c5f6c2015-05-06 13:18:59 +0200110 sclp.rnmax = sccb->rnmax ? sccb->rnmax : sccb->rnmax2;
111 sclp.rzm = sccb->rnsize ? sccb->rnsize : sccb->rnsize2;
112 sclp.rzm <<= 20;
113 sclp.ibc = sccb->ibc;
Hendrik Brueckner333cce92013-12-05 18:46:51 +0100114
Guenther Hutzl32e6b232014-12-01 17:24:42 +0100115 if (sccb->hamaxpow && sccb->hamaxpow < 64)
116 sclp.hamax = (1UL << sccb->hamaxpow) - 1;
117 else
118 sclp.hamax = U64_MAX;
119
Heiko Carstenscf813db2014-03-10 14:50:16 +0100120 if (!sccb->hcpua) {
121 if (MACHINE_IS_VM)
Martin Schwidefskyd08d9432015-06-18 14:23:00 +0200122 sclp.max_cores = 64;
Heiko Carstenscf813db2014-03-10 14:50:16 +0100123 else
Martin Schwidefskyd08d9432015-06-18 14:23:00 +0200124 sclp.max_cores = sccb->ncpurl;
Heiko Carstenscf813db2014-03-10 14:50:16 +0100125 } else {
Martin Schwidefskyd08d9432015-06-18 14:23:00 +0200126 sclp.max_cores = sccb->hcpua + 1;
Heiko Carstenscf813db2014-03-10 14:50:16 +0100127 }
128
Heiko Carstens217a4402013-12-30 12:54:14 +0100129 boot_cpu_address = stap();
130 cpue = (void *)sccb + sccb->cpuoff;
131 for (cpu = 0; cpu < sccb->ncpurl; cpue++, cpu++) {
Martin Schwidefsky10ad34b2015-01-14 17:52:10 +0100132 if (boot_cpu_address != cpue->core_id)
Heiko Carstens217a4402013-12-30 12:54:14 +0100133 continue;
David Hildenbrand37c5f6c2015-05-06 13:18:59 +0200134 sclp.has_siif = cpue->siif;
135 sclp.has_sigpif = cpue->sigpif;
David Hildenbrand8dfd5232015-02-24 15:51:55 +0100136 sclp.has_sief2 = cpue->sief2;
David Hildenbrandb9e28892015-11-24 12:51:52 +0100137 sclp.has_gpere = cpue->gpere;
David Hildenbrand72cd82b2015-11-24 12:59:03 +0100138 sclp.has_ib = cpue->ib;
David Hildenbrand4a5c3e02015-11-24 13:00:23 +0100139 sclp.has_cei = cpue->cei;
David Hildenbrand23861452015-11-24 12:56:43 +0100140 sclp.has_skey = cpue->skey;
Heiko Carstens217a4402013-12-30 12:54:14 +0100141 break;
142 }
143
Hendrik Brueckner333cce92013-12-05 18:46:51 +0100144 /* Save IPL information */
145 sclp_ipl_info.is_valid = 1;
Martin Schwidefsky118bd312016-07-26 16:53:09 +0200146 if (sccb->fac91 & 0x2)
Hendrik Brueckner333cce92013-12-05 18:46:51 +0100147 sclp_ipl_info.has_dump = 1;
148 memcpy(&sclp_ipl_info.loadparm, &sccb->loadparm, LOADPARM_LEN);
Martin Schwidefsky10ad34b2015-01-14 17:52:10 +0100149
David Hildenbrand37c5f6c2015-05-06 13:18:59 +0200150 sclp.mtid = (sccb->fac42 & 0x80) ? (sccb->fac42 & 31) : 0;
151 sclp.mtid_cp = (sccb->fac42 & 0x80) ? (sccb->fac43 & 31) : 0;
David Hildenbrand37c5f6c2015-05-06 13:18:59 +0200152 sclp.mtid_prev = (sccb->fac42 & 0x80) ? (sccb->fac66 & 31) : 0;
Alexander Yarygin154fa272016-04-01 15:36:51 +0300153
154 sclp.hmfai = sccb->hmfai;
Michael Holzheuacf6a002013-11-13 10:38:27 +0100155}
156
Michael Holzheuacf6a002013-11-13 10:38:27 +0100157/*
Heiko Carstensd5ab7a32017-01-24 15:58:52 +0100158 * This function will be called after sclp_early_facilities_detect(), which gets
159 * called from early.c code. The sclp_early_facilities_detect() function retrieves
Hendrik Brueckner333cce92013-12-05 18:46:51 +0100160 * and saves the IPL information.
Michael Holzheuacf6a002013-11-13 10:38:27 +0100161 */
Heiko Carstensd5ab7a32017-01-24 15:58:52 +0100162void __init sclp_early_get_ipl_info(struct sclp_ipl_info *info)
Michael Holzheuacf6a002013-11-13 10:38:27 +0100163{
Hendrik Brueckner333cce92013-12-05 18:46:51 +0100164 *info = sclp_ipl_info;
Michael Holzheuacf6a002013-11-13 10:38:27 +0100165}
166
Heiko Carstensd5ab7a32017-01-24 15:58:52 +0100167static struct sclp_core_info sclp_early_core_info __initdata;
168static int sclp_early_core_info_valid __initdata;
Michael Holzheue657d8f2013-11-13 10:38:27 +0100169
Heiko Carstensd5ab7a32017-01-24 15:58:52 +0100170static void __init sclp_early_init_core_info(struct read_cpu_info_sccb *sccb)
Heiko Carstensaf51160e2016-12-03 09:48:01 +0100171{
Heiko Carstensaf51160e2016-12-03 09:48:01 +0100172 if (!SCLP_HAS_CPU_INFO)
173 return;
174 memset(sccb, 0, sizeof(*sccb));
175 sccb->header.length = sizeof(*sccb);
Heiko Carstensf694bb32017-02-02 12:33:03 +0100176 if (sclp_early_cmd(SCLP_CMDW_READ_CPU_INFO, sccb))
Heiko Carstensaf51160e2016-12-03 09:48:01 +0100177 return;
178 if (sccb->header.response_code != 0x0010)
179 return;
Heiko Carstensd5ab7a32017-01-24 15:58:52 +0100180 sclp_fill_core_info(&sclp_early_core_info, sccb);
181 sclp_early_core_info_valid = 1;
Heiko Carstensaf51160e2016-12-03 09:48:01 +0100182}
183
Heiko Carstensd5ab7a32017-01-24 15:58:52 +0100184int __init sclp_early_get_core_info(struct sclp_core_info *info)
Heiko Carstensaf51160e2016-12-03 09:48:01 +0100185{
Heiko Carstensd5ab7a32017-01-24 15:58:52 +0100186 if (!sclp_early_core_info_valid)
Heiko Carstensaf51160e2016-12-03 09:48:01 +0100187 return -EIO;
Heiko Carstensd5ab7a32017-01-24 15:58:52 +0100188 *info = sclp_early_core_info;
Heiko Carstensaf51160e2016-12-03 09:48:01 +0100189 return 0;
190}
191
Heiko Carstensd5ab7a32017-01-24 15:58:52 +0100192static long __init sclp_early_hsa_size_init(struct sdias_sccb *sccb)
Michael Holzheue657d8f2013-11-13 10:38:27 +0100193{
Heiko Carstensd5ab7a32017-01-24 15:58:52 +0100194 memset(sccb, 0, sizeof(*sccb));
195 sccb->hdr.length = sizeof(*sccb);
196 sccb->evbuf.hdr.length = sizeof(struct sdias_evbuf);
197 sccb->evbuf.hdr.type = EVTYP_SDIAS;
198 sccb->evbuf.event_qual = SDIAS_EQ_SIZE;
199 sccb->evbuf.data_id = SDIAS_DI_FCP_DUMP;
200 sccb->evbuf.event_id = 4712;
201 sccb->evbuf.dbs = 1;
202 if (sclp_early_cmd(SCLP_CMDW_WRITE_EVENT_DATA, sccb))
Michael Holzheue657d8f2013-11-13 10:38:27 +0100203 return -EIO;
Heiko Carstensf694bb32017-02-02 12:33:03 +0100204 if (sccb->hdr.response_code != 0x20)
205 return -EIO;
Michael Holzheu94999342014-02-24 14:30:00 +0100206 if (sccb->evbuf.blk_cnt == 0)
207 return 0;
208 return (sccb->evbuf.blk_cnt - 1) * PAGE_SIZE;
Michael Holzheue657d8f2013-11-13 10:38:27 +0100209}
210
Heiko Carstensd5ab7a32017-01-24 15:58:52 +0100211static long __init sclp_early_hsa_copy_wait(struct sdias_sccb *sccb)
Michael Holzheue657d8f2013-11-13 10:38:27 +0100212{
Michael Holzheue657d8f2013-11-13 10:38:27 +0100213 memset(sccb, 0, PAGE_SIZE);
Heiko Carstensd5ab7a32017-01-24 15:58:52 +0100214 sccb->hdr.length = PAGE_SIZE;
215 if (sclp_early_cmd(SCLP_CMDW_READ_EVENT_DATA, sccb))
Michael Holzheue657d8f2013-11-13 10:38:27 +0100216 return -EIO;
Heiko Carstensf694bb32017-02-02 12:33:03 +0100217 if ((sccb->hdr.response_code != 0x20) && (sccb->hdr.response_code != 0x220))
218 return -EIO;
Heiko Carstensd5ab7a32017-01-24 15:58:52 +0100219 if (sccb->evbuf.blk_cnt == 0)
Michael Holzheu94999342014-02-24 14:30:00 +0100220 return 0;
Heiko Carstensd5ab7a32017-01-24 15:58:52 +0100221 return (sccb->evbuf.blk_cnt - 1) * PAGE_SIZE;
Michael Holzheue657d8f2013-11-13 10:38:27 +0100222}
223
Heiko Carstensd5ab7a32017-01-24 15:58:52 +0100224static void __init sclp_early_hsa_size_detect(void *sccb)
Michael Holzheue657d8f2013-11-13 10:38:27 +0100225{
Heiko Carstensd5ab7a32017-01-24 15:58:52 +0100226 unsigned long flags;
227 long size = -EIO;
Michael Holzheue657d8f2013-11-13 10:38:27 +0100228
Heiko Carstensd5ab7a32017-01-24 15:58:52 +0100229 raw_local_irq_save(flags);
230 if (sclp_early_set_event_mask(sccb, EVTYP_SDIAS_MASK, EVTYP_SDIAS_MASK))
Michael Holzheue657d8f2013-11-13 10:38:27 +0100231 goto out;
Heiko Carstensd5ab7a32017-01-24 15:58:52 +0100232 size = sclp_early_hsa_size_init(sccb);
233 /* First check for synchronous response (LPAR) */
234 if (size)
235 goto out_mask;
236 if (!(S390_lowcore.ext_params & 1))
237 sclp_early_wait_irq();
238 size = sclp_early_hsa_copy_wait(sccb);
239out_mask:
240 sclp_early_set_event_mask(sccb, 0, 0);
Michael Holzheue657d8f2013-11-13 10:38:27 +0100241out:
Heiko Carstensd5ab7a32017-01-24 15:58:52 +0100242 raw_local_irq_restore(flags);
243 if (size > 0)
244 sclp.hsa_size = size;
Michael Holzheue657d8f2013-11-13 10:38:27 +0100245}
Michael Holzheu7b50da52013-11-13 10:38:27 +0100246
Heiko Carstensd5ab7a32017-01-24 15:58:52 +0100247static void __init sclp_early_console_detect(struct init_sccb *sccb)
Hendrik Brueckner52733e02013-12-05 19:28:39 +0100248{
249 if (sccb->header.response_code != 0x20)
250 return;
251
Claudio Imbrendab8435632018-01-23 16:41:38 +0100252 if (sclp_early_con_check_vt220(sccb))
David Hildenbrand37c5f6c2015-05-06 13:18:59 +0200253 sclp.has_vt220 = 1;
Hendrik Brueckner52733e02013-12-05 19:28:39 +0100254
Heiko Carstensd5ab7a32017-01-24 15:58:52 +0100255 if (sclp_early_con_check_linemode(sccb))
David Hildenbrand37c5f6c2015-05-06 13:18:59 +0200256 sclp.has_linemode = 1;
Hendrik Brueckner52733e02013-12-05 19:28:39 +0100257}
258
Michael Holzheu7b50da52013-11-13 10:38:27 +0100259void __init sclp_early_detect(void)
260{
Heiko Carstensd5ab7a32017-01-24 15:58:52 +0100261 void *sccb = &sclp_early_sccb;
Hendrik Brueckner5d5de1a2013-12-05 19:13:36 +0100262
Heiko Carstensd5ab7a32017-01-24 15:58:52 +0100263 sclp_early_facilities_detect(sccb);
264 sclp_early_init_core_info(sccb);
265 sclp_early_hsa_size_detect(sccb);
Hendrik Brueckner52733e02013-12-05 19:28:39 +0100266
Heiko Carstensd5ab7a32017-01-24 15:58:52 +0100267 /*
268 * Turn off SCLP event notifications. Also save remote masks in the
Hendrik Brueckner52733e02013-12-05 19:28:39 +0100269 * sccb. These are sufficient to detect sclp console capabilities.
270 */
Heiko Carstensd5ab7a32017-01-24 15:58:52 +0100271 sclp_early_set_event_mask(sccb, 0, 0);
272 sclp_early_console_detect(sccb);
Michael Holzheu7b50da52013-11-13 10:38:27 +0100273}