4 * Copyright IBM Corp. 2013
7 #define KMSG_COMPONENT "sclp_early"
8 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
10 #include <asm/ctl_reg.h>
13 #include "sclp_sdias.h"
16 #define SCLP_CMDW_READ_SCP_INFO 0x00020001
17 #define SCLP_CMDW_READ_SCP_INFO_FORCED 0x00120001
19 struct read_info_sccb {
20 struct sccb_header header; /* 0-7 */
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 */
30 u8 _reserved3[91 - 86]; /* 86-90 */
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);
38 static __initdata struct init_sccb early_event_mask_sccb __aligned(PAGE_SIZE);
39 static __initdata struct read_info_sccb early_read_info_sccb;
40 static __initdata char sccb_early[PAGE_SIZE] __aligned(PAGE_SIZE);
41 static unsigned long sclp_hsa_size;
43 __initdata int sclp_early_read_info_sccb_valid;
46 unsigned long long sclp_rzm;
47 unsigned long long sclp_rnmax;
49 static int __init sclp_cmd_sync_early(sclp_cmdw_t cmd, void *sccb)
54 rc = sclp_service_call(cmd, sccb);
57 __load_psw_mask(PSW_DEFAULT_KEY | PSW_MASK_BASE | PSW_MASK_EA |
58 PSW_MASK_BA | PSW_MASK_EXT | PSW_MASK_WAIT);
61 /* Contents of the sccb might have changed. */
63 __ctl_clear_bit(0, 9);
67 static void __init sclp_read_info_early(void)
71 struct read_info_sccb *sccb;
72 sclp_cmdw_t commands[] = {SCLP_CMDW_READ_SCP_INFO_FORCED,
73 SCLP_CMDW_READ_SCP_INFO};
75 sccb = &early_read_info_sccb;
76 for (i = 0; i < ARRAY_SIZE(commands); i++) {
78 memset(sccb, 0, sizeof(*sccb));
79 sccb->header.length = sizeof(*sccb);
80 sccb->header.function_code = 0x80;
81 sccb->header.control_mask[2] = 0x80;
82 rc = sclp_cmd_sync_early(commands[i], sccb);
83 } while (rc == -EBUSY);
87 if (sccb->header.response_code == 0x10) {
88 sclp_early_read_info_sccb_valid = 1;
91 if (sccb->header.response_code != 0x1f0)
96 static void __init sclp_facilities_detect(void)
98 struct read_info_sccb *sccb;
100 sclp_read_info_early();
101 if (!sclp_early_read_info_sccb_valid)
104 sccb = &early_read_info_sccb;
105 sclp_facilities = sccb->facilities;
106 sclp_fac84 = sccb->fac84;
107 if (sccb->fac85 & 0x02)
108 S390_lowcore.machine_flags |= MACHINE_FLAG_ESOP;
109 sclp_rnmax = sccb->rnmax ? sccb->rnmax : sccb->rnmax2;
110 sclp_rzm = sccb->rnsize ? sccb->rnsize : sccb->rnsize2;
114 bool __init sclp_has_linemode(void)
116 struct init_sccb *sccb = &early_event_mask_sccb;
118 if (sccb->header.response_code != 0x20)
120 if (!(sccb->sclp_send_mask & (EVTYP_OPCMD_MASK | EVTYP_PMSGCMD_MASK)))
122 if (!(sccb->sclp_receive_mask & (EVTYP_MSG_MASK | EVTYP_PMSGCMD_MASK)))
127 bool __init sclp_has_vt220(void)
129 struct init_sccb *sccb = &early_event_mask_sccb;
131 if (sccb->header.response_code != 0x20)
133 if (sccb->sclp_send_mask & EVTYP_VT220MSG_MASK)
138 unsigned long long sclp_get_rnmax(void)
143 unsigned long long sclp_get_rzm(void)
149 * This function will be called after sclp_facilities_detect(), which gets
150 * called from early.c code. Therefore the sccb should have valid contents.
152 void __init sclp_get_ipl_info(struct sclp_ipl_info *info)
154 struct read_info_sccb *sccb;
156 if (!sclp_early_read_info_sccb_valid)
158 sccb = &early_read_info_sccb;
160 if (sccb->flags & 0x2)
162 memcpy(&info->loadparm, &sccb->loadparm, LOADPARM_LEN);
165 static int __init sclp_cmd_early(sclp_cmdw_t cmd, void *sccb)
170 rc = sclp_cmd_sync_early(cmd, sccb);
171 } while (rc == -EBUSY);
175 if (((struct sccb_header *) sccb)->response_code != 0x0020)
180 static void __init sccb_init_eq_size(struct sdias_sccb *sccb)
182 memset(sccb, 0, sizeof(*sccb));
184 sccb->hdr.length = sizeof(*sccb);
185 sccb->evbuf.hdr.length = sizeof(struct sdias_evbuf);
186 sccb->evbuf.hdr.type = EVTYP_SDIAS;
187 sccb->evbuf.event_qual = SDIAS_EQ_SIZE;
188 sccb->evbuf.data_id = SDIAS_DI_FCP_DUMP;
189 sccb->evbuf.event_id = 4712;
193 static int __init sclp_set_event_mask(unsigned long receive_mask,
194 unsigned long send_mask)
196 struct init_sccb *sccb = (void *) &sccb_early;
198 memset(sccb, 0, sizeof(*sccb));
199 sccb->header.length = sizeof(*sccb);
200 sccb->mask_length = sizeof(sccb_mask_t);
201 sccb->receive_mask = receive_mask;
202 sccb->send_mask = send_mask;
203 return sclp_cmd_early(SCLP_CMDW_WRITE_EVENT_MASK, sccb);
206 static long __init sclp_hsa_size_init(void)
208 struct sdias_sccb *sccb = (void *) &sccb_early;
210 sccb_init_eq_size(sccb);
211 if (sclp_cmd_early(SCLP_CMDW_WRITE_EVENT_DATA, sccb))
213 if (sccb->evbuf.blk_cnt != 0)
214 return (sccb->evbuf.blk_cnt - 1) * PAGE_SIZE;
218 static long __init sclp_hsa_copy_wait(void)
220 struct sccb_header *sccb = (void *) &sccb_early;
222 memset(sccb, 0, PAGE_SIZE);
223 sccb->length = PAGE_SIZE;
224 if (sclp_cmd_early(SCLP_CMDW_READ_EVENT_DATA, sccb))
226 return (((struct sdias_sccb *) sccb)->evbuf.blk_cnt - 1) * PAGE_SIZE;
229 unsigned long sclp_get_hsa_size(void)
231 return sclp_hsa_size;
234 static void __init sclp_hsa_size_detect(void)
238 /* First try synchronous interface (LPAR) */
239 if (sclp_set_event_mask(0, 0x40000010))
241 size = sclp_hsa_size_init();
246 /* Then try asynchronous interface (z/VM) */
247 if (sclp_set_event_mask(0x00000010, 0x40000010))
249 size = sclp_hsa_size_init();
252 size = sclp_hsa_copy_wait();
256 sclp_hsa_size = size;
259 void __init sclp_early_detect(void)
261 sclp_facilities_detect();
262 sclp_hsa_size_detect();
263 sclp_set_event_mask(0, 0);