blob: e4e5b32c52f2b99884881a363f7da9d02a2ce150 [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
Michael Holzheuacf6a002013-11-13 10:38:27 +010010#include <asm/ctl_reg.h>
Michael Holzheue657d8f2013-11-13 10:38:27 +010011#include <asm/sclp.h>
12#include <asm/ipl.h>
13#include "sclp_sdias.h"
14#include "sclp.h"
15
Michael Holzheuacf6a002013-11-13 10:38:27 +010016#define SCLP_CMDW_READ_SCP_INFO 0x00020001
17#define SCLP_CMDW_READ_SCP_INFO_FORCED 0x00120001
18
19struct read_info_sccb {
20 struct sccb_header header; /* 0-7 */
21 u16 rnmax; /* 8-9 */
22 u8 rnsize; /* 10 */
23 u8 _reserved0[24 - 11]; /* 11-15 */
24 u8 loadparm[8]; /* 24-31 */
25 u8 _reserved1[48 - 32]; /* 32-47 */
26 u64 facilities; /* 48-55 */
27 u8 _reserved2[84 - 56]; /* 56-83 */
28 u8 fac84; /* 84 */
29 u8 fac85; /* 85 */
30 u8 _reserved3[91 - 86]; /* 86-90 */
31 u8 flags; /* 91 */
32 u8 _reserved4[100 - 92]; /* 92-99 */
33 u32 rnsize2; /* 100-103 */
34 u64 rnmax2; /* 104-111 */
35 u8 _reserved5[4096 - 112]; /* 112-4095 */
36} __packed __aligned(PAGE_SIZE);
37
Michael Holzheuacf6a002013-11-13 10:38:27 +010038static __initdata struct read_info_sccb early_read_info_sccb;
Michael Holzheue657d8f2013-11-13 10:38:27 +010039static __initdata char sccb_early[PAGE_SIZE] __aligned(PAGE_SIZE);
40static unsigned long sclp_hsa_size;
Hendrik Brueckner333cce92013-12-05 18:46:51 +010041static struct sclp_ipl_info sclp_ipl_info;
Michael Holzheue657d8f2013-11-13 10:38:27 +010042
Michael Holzheuacf6a002013-11-13 10:38:27 +010043u64 sclp_facilities;
44u8 sclp_fac84;
45unsigned long long sclp_rzm;
46unsigned long long sclp_rnmax;
47
48static int __init sclp_cmd_sync_early(sclp_cmdw_t cmd, void *sccb)
49{
50 int rc;
51
52 __ctl_set_bit(0, 9);
53 rc = sclp_service_call(cmd, sccb);
54 if (rc)
55 goto out;
56 __load_psw_mask(PSW_DEFAULT_KEY | PSW_MASK_BASE | PSW_MASK_EA |
57 PSW_MASK_BA | PSW_MASK_EXT | PSW_MASK_WAIT);
58 local_irq_disable();
59out:
60 /* Contents of the sccb might have changed. */
61 barrier();
62 __ctl_clear_bit(0, 9);
63 return rc;
64}
65
Hendrik Brueckner333cce92013-12-05 18:46:51 +010066static int __init sclp_read_info_early(void)
Michael Holzheuacf6a002013-11-13 10:38:27 +010067{
Hendrik Brueckner333cce92013-12-05 18:46:51 +010068 int rc, i;
Michael Holzheuacf6a002013-11-13 10:38:27 +010069 struct read_info_sccb *sccb;
70 sclp_cmdw_t commands[] = {SCLP_CMDW_READ_SCP_INFO_FORCED,
71 SCLP_CMDW_READ_SCP_INFO};
72
73 sccb = &early_read_info_sccb;
74 for (i = 0; i < ARRAY_SIZE(commands); i++) {
75 do {
76 memset(sccb, 0, sizeof(*sccb));
77 sccb->header.length = sizeof(*sccb);
78 sccb->header.function_code = 0x80;
79 sccb->header.control_mask[2] = 0x80;
80 rc = sclp_cmd_sync_early(commands[i], sccb);
81 } while (rc == -EBUSY);
82
83 if (rc)
84 break;
Hendrik Brueckner333cce92013-12-05 18:46:51 +010085 if (sccb->header.response_code == 0x10)
86 return 0;
Michael Holzheuacf6a002013-11-13 10:38:27 +010087 if (sccb->header.response_code != 0x1f0)
88 break;
89 }
Hendrik Brueckner333cce92013-12-05 18:46:51 +010090 return -EIO;
Michael Holzheuacf6a002013-11-13 10:38:27 +010091}
92
Michael Holzheu7b50da52013-11-13 10:38:27 +010093static void __init sclp_facilities_detect(void)
Michael Holzheuacf6a002013-11-13 10:38:27 +010094{
95 struct read_info_sccb *sccb;
96
Hendrik Brueckner333cce92013-12-05 18:46:51 +010097 if (sclp_read_info_early())
Michael Holzheuacf6a002013-11-13 10:38:27 +010098 return;
99
100 sccb = &early_read_info_sccb;
101 sclp_facilities = sccb->facilities;
102 sclp_fac84 = sccb->fac84;
103 if (sccb->fac85 & 0x02)
104 S390_lowcore.machine_flags |= MACHINE_FLAG_ESOP;
105 sclp_rnmax = sccb->rnmax ? sccb->rnmax : sccb->rnmax2;
106 sclp_rzm = sccb->rnsize ? sccb->rnsize : sccb->rnsize2;
107 sclp_rzm <<= 20;
Hendrik Brueckner333cce92013-12-05 18:46:51 +0100108
109 /* Save IPL information */
110 sclp_ipl_info.is_valid = 1;
111 if (sccb->flags & 0x2)
112 sclp_ipl_info.has_dump = 1;
113 memcpy(&sclp_ipl_info.loadparm, &sccb->loadparm, LOADPARM_LEN);
Michael Holzheuacf6a002013-11-13 10:38:27 +0100114}
115
116bool __init sclp_has_linemode(void)
117{
Hendrik Brueckner9e3ea192013-11-29 17:29:20 +0100118 struct init_sccb *sccb = (void *) &sccb_early;
Michael Holzheuacf6a002013-11-13 10:38:27 +0100119
120 if (sccb->header.response_code != 0x20)
121 return 0;
122 if (!(sccb->sclp_send_mask & (EVTYP_OPCMD_MASK | EVTYP_PMSGCMD_MASK)))
123 return 0;
124 if (!(sccb->sclp_receive_mask & (EVTYP_MSG_MASK | EVTYP_PMSGCMD_MASK)))
125 return 0;
126 return 1;
127}
128
129bool __init sclp_has_vt220(void)
130{
Hendrik Brueckner9e3ea192013-11-29 17:29:20 +0100131 struct init_sccb *sccb = (void *) &sccb_early;
Michael Holzheuacf6a002013-11-13 10:38:27 +0100132
133 if (sccb->header.response_code != 0x20)
134 return 0;
135 if (sccb->sclp_send_mask & EVTYP_VT220MSG_MASK)
136 return 1;
137 return 0;
138}
139
140unsigned long long sclp_get_rnmax(void)
141{
142 return sclp_rnmax;
143}
144
145unsigned long long sclp_get_rzm(void)
146{
147 return sclp_rzm;
148}
149
150/*
151 * This function will be called after sclp_facilities_detect(), which gets
Hendrik Brueckner333cce92013-12-05 18:46:51 +0100152 * called from early.c code. The sclp_facilities_detect() function retrieves
153 * and saves the IPL information.
Michael Holzheuacf6a002013-11-13 10:38:27 +0100154 */
155void __init sclp_get_ipl_info(struct sclp_ipl_info *info)
156{
Hendrik Brueckner333cce92013-12-05 18:46:51 +0100157 *info = sclp_ipl_info;
Michael Holzheuacf6a002013-11-13 10:38:27 +0100158}
159
Michael Holzheue657d8f2013-11-13 10:38:27 +0100160static int __init sclp_cmd_early(sclp_cmdw_t cmd, void *sccb)
161{
162 int rc;
163
164 do {
165 rc = sclp_cmd_sync_early(cmd, sccb);
166 } while (rc == -EBUSY);
167
168 if (rc)
169 return -EIO;
170 if (((struct sccb_header *) sccb)->response_code != 0x0020)
171 return -EIO;
172 return 0;
173}
174
175static void __init sccb_init_eq_size(struct sdias_sccb *sccb)
176{
177 memset(sccb, 0, sizeof(*sccb));
178
179 sccb->hdr.length = sizeof(*sccb);
180 sccb->evbuf.hdr.length = sizeof(struct sdias_evbuf);
181 sccb->evbuf.hdr.type = EVTYP_SDIAS;
182 sccb->evbuf.event_qual = SDIAS_EQ_SIZE;
183 sccb->evbuf.data_id = SDIAS_DI_FCP_DUMP;
184 sccb->evbuf.event_id = 4712;
185 sccb->evbuf.dbs = 1;
186}
187
188static int __init sclp_set_event_mask(unsigned long receive_mask,
189 unsigned long send_mask)
190{
191 struct init_sccb *sccb = (void *) &sccb_early;
192
193 memset(sccb, 0, sizeof(*sccb));
194 sccb->header.length = sizeof(*sccb);
195 sccb->mask_length = sizeof(sccb_mask_t);
196 sccb->receive_mask = receive_mask;
197 sccb->send_mask = send_mask;
198 return sclp_cmd_early(SCLP_CMDW_WRITE_EVENT_MASK, sccb);
199}
200
201static long __init sclp_hsa_size_init(void)
202{
203 struct sdias_sccb *sccb = (void *) &sccb_early;
204
205 sccb_init_eq_size(sccb);
206 if (sclp_cmd_early(SCLP_CMDW_WRITE_EVENT_DATA, sccb))
207 return -EIO;
208 if (sccb->evbuf.blk_cnt != 0)
209 return (sccb->evbuf.blk_cnt - 1) * PAGE_SIZE;
210 return 0;
211}
212
213static long __init sclp_hsa_copy_wait(void)
214{
215 struct sccb_header *sccb = (void *) &sccb_early;
216
217 memset(sccb, 0, PAGE_SIZE);
218 sccb->length = PAGE_SIZE;
219 if (sclp_cmd_early(SCLP_CMDW_READ_EVENT_DATA, sccb))
220 return -EIO;
221 return (((struct sdias_sccb *) sccb)->evbuf.blk_cnt - 1) * PAGE_SIZE;
222}
223
224unsigned long sclp_get_hsa_size(void)
225{
226 return sclp_hsa_size;
227}
228
Michael Holzheu7b50da52013-11-13 10:38:27 +0100229static void __init sclp_hsa_size_detect(void)
Michael Holzheue657d8f2013-11-13 10:38:27 +0100230{
231 long size;
232
233 /* First try synchronous interface (LPAR) */
234 if (sclp_set_event_mask(0, 0x40000010))
235 return;
236 size = sclp_hsa_size_init();
237 if (size < 0)
238 return;
239 if (size != 0)
240 goto out;
241 /* Then try asynchronous interface (z/VM) */
242 if (sclp_set_event_mask(0x00000010, 0x40000010))
243 return;
244 size = sclp_hsa_size_init();
245 if (size < 0)
246 return;
247 size = sclp_hsa_copy_wait();
248 if (size < 0)
249 return;
250out:
Michael Holzheue657d8f2013-11-13 10:38:27 +0100251 sclp_hsa_size = size;
252}
Michael Holzheu7b50da52013-11-13 10:38:27 +0100253
254void __init sclp_early_detect(void)
255{
256 sclp_facilities_detect();
257 sclp_hsa_size_detect();
258 sclp_set_event_mask(0, 0);
259}