Michael Holzheu | e657d8f | 2013-11-13 10:38:27 +0100 | [diff] [blame] | 1 | /* |
| 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 Holzheu | acf6a00 | 2013-11-13 10:38:27 +0100 | [diff] [blame] | 10 | #include <asm/ctl_reg.h> |
Michael Holzheu | e657d8f | 2013-11-13 10:38:27 +0100 | [diff] [blame] | 11 | #include <asm/sclp.h> |
| 12 | #include <asm/ipl.h> |
| 13 | #include "sclp_sdias.h" |
| 14 | #include "sclp.h" |
| 15 | |
Michael Holzheu | acf6a00 | 2013-11-13 10:38:27 +0100 | [diff] [blame] | 16 | #define SCLP_CMDW_READ_SCP_INFO 0x00020001 |
| 17 | #define SCLP_CMDW_READ_SCP_INFO_FORCED 0x00120001 |
| 18 | |
| 19 | struct 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 Holzheu | acf6a00 | 2013-11-13 10:38:27 +0100 | [diff] [blame] | 38 | static __initdata struct read_info_sccb early_read_info_sccb; |
Michael Holzheu | e657d8f | 2013-11-13 10:38:27 +0100 | [diff] [blame] | 39 | static __initdata char sccb_early[PAGE_SIZE] __aligned(PAGE_SIZE); |
| 40 | static unsigned long sclp_hsa_size; |
Hendrik Brueckner | 333cce9 | 2013-12-05 18:46:51 +0100 | [diff] [blame^] | 41 | static struct sclp_ipl_info sclp_ipl_info; |
Michael Holzheu | e657d8f | 2013-11-13 10:38:27 +0100 | [diff] [blame] | 42 | |
Michael Holzheu | acf6a00 | 2013-11-13 10:38:27 +0100 | [diff] [blame] | 43 | u64 sclp_facilities; |
| 44 | u8 sclp_fac84; |
| 45 | unsigned long long sclp_rzm; |
| 46 | unsigned long long sclp_rnmax; |
| 47 | |
| 48 | static 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(); |
| 59 | out: |
| 60 | /* Contents of the sccb might have changed. */ |
| 61 | barrier(); |
| 62 | __ctl_clear_bit(0, 9); |
| 63 | return rc; |
| 64 | } |
| 65 | |
Hendrik Brueckner | 333cce9 | 2013-12-05 18:46:51 +0100 | [diff] [blame^] | 66 | static int __init sclp_read_info_early(void) |
Michael Holzheu | acf6a00 | 2013-11-13 10:38:27 +0100 | [diff] [blame] | 67 | { |
Hendrik Brueckner | 333cce9 | 2013-12-05 18:46:51 +0100 | [diff] [blame^] | 68 | int rc, i; |
Michael Holzheu | acf6a00 | 2013-11-13 10:38:27 +0100 | [diff] [blame] | 69 | 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 Brueckner | 333cce9 | 2013-12-05 18:46:51 +0100 | [diff] [blame^] | 85 | if (sccb->header.response_code == 0x10) |
| 86 | return 0; |
Michael Holzheu | acf6a00 | 2013-11-13 10:38:27 +0100 | [diff] [blame] | 87 | if (sccb->header.response_code != 0x1f0) |
| 88 | break; |
| 89 | } |
Hendrik Brueckner | 333cce9 | 2013-12-05 18:46:51 +0100 | [diff] [blame^] | 90 | return -EIO; |
Michael Holzheu | acf6a00 | 2013-11-13 10:38:27 +0100 | [diff] [blame] | 91 | } |
| 92 | |
Michael Holzheu | 7b50da5 | 2013-11-13 10:38:27 +0100 | [diff] [blame] | 93 | static void __init sclp_facilities_detect(void) |
Michael Holzheu | acf6a00 | 2013-11-13 10:38:27 +0100 | [diff] [blame] | 94 | { |
| 95 | struct read_info_sccb *sccb; |
| 96 | |
Hendrik Brueckner | 333cce9 | 2013-12-05 18:46:51 +0100 | [diff] [blame^] | 97 | if (sclp_read_info_early()) |
Michael Holzheu | acf6a00 | 2013-11-13 10:38:27 +0100 | [diff] [blame] | 98 | 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 Brueckner | 333cce9 | 2013-12-05 18:46:51 +0100 | [diff] [blame^] | 108 | |
| 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 Holzheu | acf6a00 | 2013-11-13 10:38:27 +0100 | [diff] [blame] | 114 | } |
| 115 | |
| 116 | bool __init sclp_has_linemode(void) |
| 117 | { |
Hendrik Brueckner | 9e3ea19 | 2013-11-29 17:29:20 +0100 | [diff] [blame] | 118 | struct init_sccb *sccb = (void *) &sccb_early; |
Michael Holzheu | acf6a00 | 2013-11-13 10:38:27 +0100 | [diff] [blame] | 119 | |
| 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 | |
| 129 | bool __init sclp_has_vt220(void) |
| 130 | { |
Hendrik Brueckner | 9e3ea19 | 2013-11-29 17:29:20 +0100 | [diff] [blame] | 131 | struct init_sccb *sccb = (void *) &sccb_early; |
Michael Holzheu | acf6a00 | 2013-11-13 10:38:27 +0100 | [diff] [blame] | 132 | |
| 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 | |
| 140 | unsigned long long sclp_get_rnmax(void) |
| 141 | { |
| 142 | return sclp_rnmax; |
| 143 | } |
| 144 | |
| 145 | unsigned 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 Brueckner | 333cce9 | 2013-12-05 18:46:51 +0100 | [diff] [blame^] | 152 | * called from early.c code. The sclp_facilities_detect() function retrieves |
| 153 | * and saves the IPL information. |
Michael Holzheu | acf6a00 | 2013-11-13 10:38:27 +0100 | [diff] [blame] | 154 | */ |
| 155 | void __init sclp_get_ipl_info(struct sclp_ipl_info *info) |
| 156 | { |
Hendrik Brueckner | 333cce9 | 2013-12-05 18:46:51 +0100 | [diff] [blame^] | 157 | *info = sclp_ipl_info; |
Michael Holzheu | acf6a00 | 2013-11-13 10:38:27 +0100 | [diff] [blame] | 158 | } |
| 159 | |
Michael Holzheu | e657d8f | 2013-11-13 10:38:27 +0100 | [diff] [blame] | 160 | static 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 | |
| 175 | static 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 | |
| 188 | static 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 | |
| 201 | static 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 | |
| 213 | static 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 | |
| 224 | unsigned long sclp_get_hsa_size(void) |
| 225 | { |
| 226 | return sclp_hsa_size; |
| 227 | } |
| 228 | |
Michael Holzheu | 7b50da5 | 2013-11-13 10:38:27 +0100 | [diff] [blame] | 229 | static void __init sclp_hsa_size_detect(void) |
Michael Holzheu | e657d8f | 2013-11-13 10:38:27 +0100 | [diff] [blame] | 230 | { |
| 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; |
| 250 | out: |
Michael Holzheu | e657d8f | 2013-11-13 10:38:27 +0100 | [diff] [blame] | 251 | sclp_hsa_size = size; |
| 252 | } |
Michael Holzheu | 7b50da5 | 2013-11-13 10:38:27 +0100 | [diff] [blame] | 253 | |
| 254 | void __init sclp_early_detect(void) |
| 255 | { |
| 256 | sclp_facilities_detect(); |
| 257 | sclp_hsa_size_detect(); |
| 258 | sclp_set_event_mask(0, 0); |
| 259 | } |