blob: bc1fc00910b07f69103a11ee43d7d64db87fdb0d [file] [log] [blame]
Michael Holzheue657d8f2013-11-13 10:38:27 +01001/*
2 * SCLP early driver
3 *
4 * Copyright IBM Corp. 2013
5 */
6
7#define KMSG_COMPONENT "sclp_early"
8#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
9
Sebastian Otta313bdc2015-06-25 09:32:22 +020010#include <linux/errno.h>
Michael Holzheuacf6a002013-11-13 10:38:27 +010011#include <asm/ctl_reg.h>
Michael Holzheue657d8f2013-11-13 10:38:27 +010012#include <asm/sclp.h>
13#include <asm/ipl.h>
14#include "sclp_sdias.h"
15#include "sclp.h"
16
Michael Holzheuacf6a002013-11-13 10:38:27 +010017#define SCLP_CMDW_READ_SCP_INFO 0x00020001
18#define SCLP_CMDW_READ_SCP_INFO_FORCED 0x00120001
19
20struct read_info_sccb {
21 struct sccb_header header; /* 0-7 */
22 u16 rnmax; /* 8-9 */
23 u8 rnsize; /* 10 */
Martin Schwidefsky10ad34b2015-01-14 17:52:10 +010024 u8 _pad_11[16 - 11]; /* 11-15 */
Heiko Carstenscf813db2014-03-10 14:50:16 +010025 u16 ncpurl; /* 16-17 */
Heiko Carstens217a4402013-12-30 12:54:14 +010026 u16 cpuoff; /* 18-19 */
Martin Schwidefsky10ad34b2015-01-14 17:52:10 +010027 u8 _pad_20[24 - 20]; /* 20-23 */
Michael Holzheuacf6a002013-11-13 10:38:27 +010028 u8 loadparm[8]; /* 24-31 */
Martin Schwidefsky10ad34b2015-01-14 17:52:10 +010029 u8 _pad_32[42 - 32]; /* 32-41 */
30 u8 fac42; /* 42 */
31 u8 fac43; /* 43 */
32 u8 _pad_44[48 - 44]; /* 44-47 */
Michael Holzheuacf6a002013-11-13 10:38:27 +010033 u64 facilities; /* 48-55 */
Martin Schwidefsky10ad34b2015-01-14 17:52:10 +010034 u8 _pad_56[66 - 56]; /* 56-65 */
35 u8 fac66; /* 66 */
36 u8 _pad_67[76 - 67]; /* 67-83 */
Michael Mueller570126d2014-03-15 18:16:26 +010037 u32 ibc; /* 76-79 */
Martin Schwidefsky10ad34b2015-01-14 17:52:10 +010038 u8 _pad80[84 - 80]; /* 80-83 */
Michael Holzheuacf6a002013-11-13 10:38:27 +010039 u8 fac84; /* 84 */
40 u8 fac85; /* 85 */
Martin Schwidefsky10ad34b2015-01-14 17:52:10 +010041 u8 _pad_86[91 - 86]; /* 86-90 */
Martin Schwidefsky118bd312016-07-26 16:53:09 +020042 u8 fac91; /* 91 */
Farhan Ali71cb1bf2017-02-23 13:39:17 -050043 u8 _pad_92[98 - 92]; /* 92-97 */
44 u8 fac98; /* 98 */
Guenther Hutzl32e6b232014-12-01 17:24:42 +010045 u8 hamaxpow; /* 99 */
Michael Holzheuacf6a002013-11-13 10:38:27 +010046 u32 rnsize2; /* 100-103 */
47 u64 rnmax2; /* 104-111 */
Eugene (jno) Dvurechenskif7ba1d32014-10-09 16:04:48 +020048 u8 _pad_112[116 - 112]; /* 112-115 */
49 u8 fac116; /* 116 */
David Hildenbranda0eb55e2015-11-24 13:02:25 +010050 u8 fac117; /* 117 */
51 u8 _pad_118; /* 118 */
Eugene (jno) Dvurechenskif7ba1d32014-10-09 16:04:48 +020052 u8 fac119; /* 119 */
Heiko Carstenscf813db2014-03-10 14:50:16 +010053 u16 hcpua; /* 120-121 */
Alexander Yarygin154fa272016-04-01 15:36:51 +030054 u8 _pad_122[124 - 122]; /* 122-123 */
55 u32 hmfai; /* 124-127 */
56 u8 _pad_128[4096 - 128]; /* 128-4095 */
Michael Holzheuacf6a002013-11-13 10:38:27 +010057} __packed __aligned(PAGE_SIZE);
58
Hendrik Brueckner333cce92013-12-05 18:46:51 +010059static struct sclp_ipl_info sclp_ipl_info;
Michael Holzheue657d8f2013-11-13 10:38:27 +010060
David Hildenbrand37c5f6c2015-05-06 13:18:59 +020061struct sclp_info sclp;
62EXPORT_SYMBOL(sclp);
Michael Holzheuacf6a002013-11-13 10:38:27 +010063
Heiko Carstensd5ab7a32017-01-24 15:58:52 +010064static int __init sclp_early_read_info(struct read_info_sccb *sccb)
Michael Holzheuacf6a002013-11-13 10:38:27 +010065{
Heiko Carstensf694bb32017-02-02 12:33:03 +010066 int i;
Michael Holzheuacf6a002013-11-13 10:38:27 +010067 sclp_cmdw_t commands[] = {SCLP_CMDW_READ_SCP_INFO_FORCED,
68 SCLP_CMDW_READ_SCP_INFO};
69
Michael Holzheuacf6a002013-11-13 10:38:27 +010070 for (i = 0; i < ARRAY_SIZE(commands); i++) {
Heiko Carstensf694bb32017-02-02 12:33:03 +010071 memset(sccb, 0, sizeof(*sccb));
72 sccb->header.length = sizeof(*sccb);
73 sccb->header.function_code = 0x80;
74 sccb->header.control_mask[2] = 0x80;
75 if (sclp_early_cmd(commands[i], sccb))
Michael Holzheuacf6a002013-11-13 10:38:27 +010076 break;
Hendrik Brueckner333cce92013-12-05 18:46:51 +010077 if (sccb->header.response_code == 0x10)
78 return 0;
Michael Holzheuacf6a002013-11-13 10:38:27 +010079 if (sccb->header.response_code != 0x1f0)
80 break;
81 }
Hendrik Brueckner333cce92013-12-05 18:46:51 +010082 return -EIO;
Michael Holzheuacf6a002013-11-13 10:38:27 +010083}
84
Heiko Carstensd5ab7a32017-01-24 15:58:52 +010085static void __init sclp_early_facilities_detect(struct read_info_sccb *sccb)
Michael Holzheuacf6a002013-11-13 10:38:27 +010086{
Martin Schwidefskyd08d9432015-06-18 14:23:00 +020087 struct sclp_core_entry *cpue;
Heiko Carstens217a4402013-12-30 12:54:14 +010088 u16 boot_cpu_address, cpu;
89
Heiko Carstensd5ab7a32017-01-24 15:58:52 +010090 if (sclp_early_read_info(sccb))
Michael Holzheuacf6a002013-11-13 10:38:27 +010091 return;
92
David Hildenbrand78335a32015-05-06 09:17:51 +020093 sclp.facilities = sccb->facilities;
David Hildenbrand37c5f6c2015-05-06 13:18:59 +020094 sclp.has_sprp = !!(sccb->fac84 & 0x02);
Martin Schwidefskyd08d9432015-06-18 14:23:00 +020095 sclp.has_core_type = !!(sccb->fac84 & 0x01);
David Hildenbrand5236c752015-11-24 12:53:46 +010096 sclp.has_gsls = !!(sccb->fac85 & 0x80);
David Hildenbrand4013ade2015-11-24 12:49:43 +010097 sclp.has_64bscao = !!(sccb->fac116 & 0x80);
David Hildenbrand09be9cb2015-11-24 12:55:35 +010098 sclp.has_cmma = !!(sccb->fac116 & 0x40);
Eugene (jno) Dvurechenskif7ba1d32014-10-09 16:04:48 +020099 sclp.has_esca = !!(sccb->fac116 & 0x08);
David Hildenbranda0eb55e2015-11-24 13:02:25 +0100100 sclp.has_pfmfi = !!(sccb->fac117 & 0x40);
David Hildenbrand9c375492015-11-24 13:02:52 +0100101 sclp.has_ibs = !!(sccb->fac117 & 0x20);
Eugene (jno) Dvurechenskif7ba1d32014-10-09 16:04:48 +0200102 sclp.has_hvs = !!(sccb->fac119 & 0x80);
Farhan Ali71cb1bf2017-02-23 13:39:17 -0500103 sclp.has_kss = !!(sccb->fac98 & 0x01);
Michael Holzheuacf6a002013-11-13 10:38:27 +0100104 if (sccb->fac85 & 0x02)
105 S390_lowcore.machine_flags |= MACHINE_FLAG_ESOP;
Martin Schwidefsky118bd312016-07-26 16:53:09 +0200106 if (sccb->fac91 & 0x40)
107 S390_lowcore.machine_flags |= MACHINE_FLAG_TLB_GUEST;
David Hildenbrand37c5f6c2015-05-06 13:18:59 +0200108 sclp.rnmax = sccb->rnmax ? sccb->rnmax : sccb->rnmax2;
109 sclp.rzm = sccb->rnsize ? sccb->rnsize : sccb->rnsize2;
110 sclp.rzm <<= 20;
111 sclp.ibc = sccb->ibc;
Hendrik Brueckner333cce92013-12-05 18:46:51 +0100112
Guenther Hutzl32e6b232014-12-01 17:24:42 +0100113 if (sccb->hamaxpow && sccb->hamaxpow < 64)
114 sclp.hamax = (1UL << sccb->hamaxpow) - 1;
115 else
116 sclp.hamax = U64_MAX;
117
Heiko Carstenscf813db2014-03-10 14:50:16 +0100118 if (!sccb->hcpua) {
119 if (MACHINE_IS_VM)
Martin Schwidefskyd08d9432015-06-18 14:23:00 +0200120 sclp.max_cores = 64;
Heiko Carstenscf813db2014-03-10 14:50:16 +0100121 else
Martin Schwidefskyd08d9432015-06-18 14:23:00 +0200122 sclp.max_cores = sccb->ncpurl;
Heiko Carstenscf813db2014-03-10 14:50:16 +0100123 } else {
Martin Schwidefskyd08d9432015-06-18 14:23:00 +0200124 sclp.max_cores = sccb->hcpua + 1;
Heiko Carstenscf813db2014-03-10 14:50:16 +0100125 }
126
Heiko Carstens217a4402013-12-30 12:54:14 +0100127 boot_cpu_address = stap();
128 cpue = (void *)sccb + sccb->cpuoff;
129 for (cpu = 0; cpu < sccb->ncpurl; cpue++, cpu++) {
Martin Schwidefsky10ad34b2015-01-14 17:52:10 +0100130 if (boot_cpu_address != cpue->core_id)
Heiko Carstens217a4402013-12-30 12:54:14 +0100131 continue;
David Hildenbrand37c5f6c2015-05-06 13:18:59 +0200132 sclp.has_siif = cpue->siif;
133 sclp.has_sigpif = cpue->sigpif;
David Hildenbrand8dfd5232015-02-24 15:51:55 +0100134 sclp.has_sief2 = cpue->sief2;
David Hildenbrandb9e28892015-11-24 12:51:52 +0100135 sclp.has_gpere = cpue->gpere;
David Hildenbrand72cd82b2015-11-24 12:59:03 +0100136 sclp.has_ib = cpue->ib;
David Hildenbrand4a5c3e02015-11-24 13:00:23 +0100137 sclp.has_cei = cpue->cei;
David Hildenbrand23861452015-11-24 12:56:43 +0100138 sclp.has_skey = cpue->skey;
Heiko Carstens217a4402013-12-30 12:54:14 +0100139 break;
140 }
141
Hendrik Brueckner333cce92013-12-05 18:46:51 +0100142 /* Save IPL information */
143 sclp_ipl_info.is_valid = 1;
Martin Schwidefsky118bd312016-07-26 16:53:09 +0200144 if (sccb->fac91 & 0x2)
Hendrik Brueckner333cce92013-12-05 18:46:51 +0100145 sclp_ipl_info.has_dump = 1;
146 memcpy(&sclp_ipl_info.loadparm, &sccb->loadparm, LOADPARM_LEN);
Martin Schwidefsky10ad34b2015-01-14 17:52:10 +0100147
David Hildenbrand37c5f6c2015-05-06 13:18:59 +0200148 sclp.mtid = (sccb->fac42 & 0x80) ? (sccb->fac42 & 31) : 0;
149 sclp.mtid_cp = (sccb->fac42 & 0x80) ? (sccb->fac43 & 31) : 0;
David Hildenbrand37c5f6c2015-05-06 13:18:59 +0200150 sclp.mtid_prev = (sccb->fac42 & 0x80) ? (sccb->fac66 & 31) : 0;
Alexander Yarygin154fa272016-04-01 15:36:51 +0300151
152 sclp.hmfai = sccb->hmfai;
Michael Holzheuacf6a002013-11-13 10:38:27 +0100153}
154
Michael Holzheuacf6a002013-11-13 10:38:27 +0100155/*
Heiko Carstensd5ab7a32017-01-24 15:58:52 +0100156 * This function will be called after sclp_early_facilities_detect(), which gets
157 * called from early.c code. The sclp_early_facilities_detect() function retrieves
Hendrik Brueckner333cce92013-12-05 18:46:51 +0100158 * and saves the IPL information.
Michael Holzheuacf6a002013-11-13 10:38:27 +0100159 */
Heiko Carstensd5ab7a32017-01-24 15:58:52 +0100160void __init sclp_early_get_ipl_info(struct sclp_ipl_info *info)
Michael Holzheuacf6a002013-11-13 10:38:27 +0100161{
Hendrik Brueckner333cce92013-12-05 18:46:51 +0100162 *info = sclp_ipl_info;
Michael Holzheuacf6a002013-11-13 10:38:27 +0100163}
164
Heiko Carstensd5ab7a32017-01-24 15:58:52 +0100165static struct sclp_core_info sclp_early_core_info __initdata;
166static int sclp_early_core_info_valid __initdata;
Michael Holzheue657d8f2013-11-13 10:38:27 +0100167
Heiko Carstensd5ab7a32017-01-24 15:58:52 +0100168static void __init sclp_early_init_core_info(struct read_cpu_info_sccb *sccb)
Heiko Carstensaf511602016-12-03 09:48:01 +0100169{
Heiko Carstensaf511602016-12-03 09:48:01 +0100170 if (!SCLP_HAS_CPU_INFO)
171 return;
172 memset(sccb, 0, sizeof(*sccb));
173 sccb->header.length = sizeof(*sccb);
Heiko Carstensf694bb32017-02-02 12:33:03 +0100174 if (sclp_early_cmd(SCLP_CMDW_READ_CPU_INFO, sccb))
Heiko Carstensaf511602016-12-03 09:48:01 +0100175 return;
176 if (sccb->header.response_code != 0x0010)
177 return;
Heiko Carstensd5ab7a32017-01-24 15:58:52 +0100178 sclp_fill_core_info(&sclp_early_core_info, sccb);
179 sclp_early_core_info_valid = 1;
Heiko Carstensaf511602016-12-03 09:48:01 +0100180}
181
Heiko Carstensd5ab7a32017-01-24 15:58:52 +0100182int __init sclp_early_get_core_info(struct sclp_core_info *info)
Heiko Carstensaf511602016-12-03 09:48:01 +0100183{
Heiko Carstensd5ab7a32017-01-24 15:58:52 +0100184 if (!sclp_early_core_info_valid)
Heiko Carstensaf511602016-12-03 09:48:01 +0100185 return -EIO;
Heiko Carstensd5ab7a32017-01-24 15:58:52 +0100186 *info = sclp_early_core_info;
Heiko Carstensaf511602016-12-03 09:48:01 +0100187 return 0;
188}
189
Heiko Carstensd5ab7a32017-01-24 15:58:52 +0100190static long __init sclp_early_hsa_size_init(struct sdias_sccb *sccb)
Michael Holzheue657d8f2013-11-13 10:38:27 +0100191{
Heiko Carstensd5ab7a32017-01-24 15:58:52 +0100192 memset(sccb, 0, sizeof(*sccb));
193 sccb->hdr.length = sizeof(*sccb);
194 sccb->evbuf.hdr.length = sizeof(struct sdias_evbuf);
195 sccb->evbuf.hdr.type = EVTYP_SDIAS;
196 sccb->evbuf.event_qual = SDIAS_EQ_SIZE;
197 sccb->evbuf.data_id = SDIAS_DI_FCP_DUMP;
198 sccb->evbuf.event_id = 4712;
199 sccb->evbuf.dbs = 1;
200 if (sclp_early_cmd(SCLP_CMDW_WRITE_EVENT_DATA, sccb))
Michael Holzheue657d8f2013-11-13 10:38:27 +0100201 return -EIO;
Heiko Carstensf694bb32017-02-02 12:33:03 +0100202 if (sccb->hdr.response_code != 0x20)
203 return -EIO;
Michael Holzheu94999342014-02-24 14:30:00 +0100204 if (sccb->evbuf.blk_cnt == 0)
205 return 0;
206 return (sccb->evbuf.blk_cnt - 1) * PAGE_SIZE;
Michael Holzheue657d8f2013-11-13 10:38:27 +0100207}
208
Heiko Carstensd5ab7a32017-01-24 15:58:52 +0100209static long __init sclp_early_hsa_copy_wait(struct sdias_sccb *sccb)
Michael Holzheue657d8f2013-11-13 10:38:27 +0100210{
Michael Holzheue657d8f2013-11-13 10:38:27 +0100211 memset(sccb, 0, PAGE_SIZE);
Heiko Carstensd5ab7a32017-01-24 15:58:52 +0100212 sccb->hdr.length = PAGE_SIZE;
213 if (sclp_early_cmd(SCLP_CMDW_READ_EVENT_DATA, sccb))
Michael Holzheue657d8f2013-11-13 10:38:27 +0100214 return -EIO;
Heiko Carstensf694bb32017-02-02 12:33:03 +0100215 if ((sccb->hdr.response_code != 0x20) && (sccb->hdr.response_code != 0x220))
216 return -EIO;
Heiko Carstensd5ab7a32017-01-24 15:58:52 +0100217 if (sccb->evbuf.blk_cnt == 0)
Michael Holzheu94999342014-02-24 14:30:00 +0100218 return 0;
Heiko Carstensd5ab7a32017-01-24 15:58:52 +0100219 return (sccb->evbuf.blk_cnt - 1) * PAGE_SIZE;
Michael Holzheue657d8f2013-11-13 10:38:27 +0100220}
221
Heiko Carstensd5ab7a32017-01-24 15:58:52 +0100222static void __init sclp_early_hsa_size_detect(void *sccb)
Michael Holzheue657d8f2013-11-13 10:38:27 +0100223{
Heiko Carstensd5ab7a32017-01-24 15:58:52 +0100224 unsigned long flags;
225 long size = -EIO;
Michael Holzheue657d8f2013-11-13 10:38:27 +0100226
Heiko Carstensd5ab7a32017-01-24 15:58:52 +0100227 raw_local_irq_save(flags);
228 if (sclp_early_set_event_mask(sccb, EVTYP_SDIAS_MASK, EVTYP_SDIAS_MASK))
Michael Holzheue657d8f2013-11-13 10:38:27 +0100229 goto out;
Heiko Carstensd5ab7a32017-01-24 15:58:52 +0100230 size = sclp_early_hsa_size_init(sccb);
231 /* First check for synchronous response (LPAR) */
232 if (size)
233 goto out_mask;
234 if (!(S390_lowcore.ext_params & 1))
235 sclp_early_wait_irq();
236 size = sclp_early_hsa_copy_wait(sccb);
237out_mask:
238 sclp_early_set_event_mask(sccb, 0, 0);
Michael Holzheue657d8f2013-11-13 10:38:27 +0100239out:
Heiko Carstensd5ab7a32017-01-24 15:58:52 +0100240 raw_local_irq_restore(flags);
241 if (size > 0)
242 sclp.hsa_size = size;
Michael Holzheue657d8f2013-11-13 10:38:27 +0100243}
Michael Holzheu7b50da52013-11-13 10:38:27 +0100244
Heiko Carstensd5ab7a32017-01-24 15:58:52 +0100245static void __init sclp_early_console_detect(struct init_sccb *sccb)
Hendrik Brueckner52733e02013-12-05 19:28:39 +0100246{
247 if (sccb->header.response_code != 0x20)
248 return;
249
250 if (sccb->sclp_send_mask & EVTYP_VT220MSG_MASK)
David Hildenbrand37c5f6c2015-05-06 13:18:59 +0200251 sclp.has_vt220 = 1;
Hendrik Brueckner52733e02013-12-05 19:28:39 +0100252
Heiko Carstensd5ab7a32017-01-24 15:58:52 +0100253 if (sclp_early_con_check_linemode(sccb))
David Hildenbrand37c5f6c2015-05-06 13:18:59 +0200254 sclp.has_linemode = 1;
Hendrik Brueckner52733e02013-12-05 19:28:39 +0100255}
256
Michael Holzheu7b50da52013-11-13 10:38:27 +0100257void __init sclp_early_detect(void)
258{
Heiko Carstensd5ab7a32017-01-24 15:58:52 +0100259 void *sccb = &sclp_early_sccb;
Hendrik Brueckner5d5de1a2013-12-05 19:13:36 +0100260
Heiko Carstensd5ab7a32017-01-24 15:58:52 +0100261 sclp_early_facilities_detect(sccb);
262 sclp_early_init_core_info(sccb);
263 sclp_early_hsa_size_detect(sccb);
Hendrik Brueckner52733e02013-12-05 19:28:39 +0100264
Heiko Carstensd5ab7a32017-01-24 15:58:52 +0100265 /*
266 * Turn off SCLP event notifications. Also save remote masks in the
Hendrik Brueckner52733e02013-12-05 19:28:39 +0100267 * sccb. These are sufficient to detect sclp console capabilities.
268 */
Heiko Carstensd5ab7a32017-01-24 15:58:52 +0100269 sclp_early_set_event_mask(sccb, 0, 0);
270 sclp_early_console_detect(sccb);
Michael Holzheu7b50da52013-11-13 10:38:27 +0100271}