1 /* SPDX-License-Identifier: GPL-2.0 */ 2 /* 3 * Copyright IBM Corp. 1999,2012 4 * 5 * Author(s): Martin Peschke <mpeschke@de.ibm.com> 6 * Martin Schwidefsky <schwidefsky@de.ibm.com> 7 */ 8 9 #ifndef __SCLP_H__ 10 #define __SCLP_H__ 11 12 #include <linux/types.h> 13 #include <linux/list.h> 14 #include <asm/sclp.h> 15 #include <asm/ebcdic.h> 16 17 /* maximum number of pages concerning our own memory management */ 18 #define MAX_KMEM_PAGES (sizeof(unsigned long) << 3) 19 #define SCLP_CONSOLE_PAGES 6 20 21 #define SCLP_EVTYP_MASK(T) (1U << (32 - (T))) 22 23 #define EVTYP_OPCMD 0x01 24 #define EVTYP_MSG 0x02 25 #define EVTYP_CONFMGMDATA 0x04 26 #define EVTYP_DIAG_TEST 0x07 27 #define EVTYP_STATECHANGE 0x08 28 #define EVTYP_PMSGCMD 0x09 29 #define EVTYP_ASYNC 0x0A 30 #define EVTYP_CTLPROGIDENT 0x0B 31 #define EVTYP_ERRNOTIFY 0x18 32 #define EVTYP_VT220MSG 0x1A 33 #define EVTYP_SDIAS 0x1C 34 #define EVTYP_SIGQUIESCE 0x1D 35 #define EVTYP_OCF 0x1E 36 37 #define EVTYP_OPCMD_MASK SCLP_EVTYP_MASK(EVTYP_OPCMD) 38 #define EVTYP_MSG_MASK SCLP_EVTYP_MASK(EVTYP_MSG) 39 #define EVTYP_CONFMGMDATA_MASK SCLP_EVTYP_MASK(EVTYP_CONFMGMDATA) 40 #define EVTYP_DIAG_TEST_MASK SCLP_EVTYP_MASK(EVTYP_DIAG_TEST) 41 #define EVTYP_STATECHANGE_MASK SCLP_EVTYP_MASK(EVTYP_STATECHANGE) 42 #define EVTYP_PMSGCMD_MASK SCLP_EVTYP_MASK(EVTYP_PMSGCMD) 43 #define EVTYP_ASYNC_MASK SCLP_EVTYP_MASK(EVTYP_ASYNC) 44 #define EVTYP_CTLPROGIDENT_MASK SCLP_EVTYP_MASK(EVTYP_CTLPROGIDENT) 45 #define EVTYP_ERRNOTIFY_MASK SCLP_EVTYP_MASK(EVTYP_ERRNOTIFY) 46 #define EVTYP_VT220MSG_MASK SCLP_EVTYP_MASK(EVTYP_VT220MSG) 47 #define EVTYP_SDIAS_MASK SCLP_EVTYP_MASK(EVTYP_SDIAS) 48 #define EVTYP_SIGQUIESCE_MASK SCLP_EVTYP_MASK(EVTYP_SIGQUIESCE) 49 #define EVTYP_OCF_MASK SCLP_EVTYP_MASK(EVTYP_OCF) 50 51 #define GNRLMSGFLGS_DOM 0x8000 52 #define GNRLMSGFLGS_SNDALRM 0x4000 53 #define GNRLMSGFLGS_HOLDMSG 0x2000 54 55 #define LNTPFLGS_CNTLTEXT 0x8000 56 #define LNTPFLGS_LABELTEXT 0x4000 57 #define LNTPFLGS_DATATEXT 0x2000 58 #define LNTPFLGS_ENDTEXT 0x1000 59 #define LNTPFLGS_PROMPTTEXT 0x0800 60 61 typedef unsigned int sclp_cmdw_t; 62 63 #define SCLP_CMDW_READ_CPU_INFO 0x00010001 64 #define SCLP_CMDW_READ_EVENT_DATA 0x00770005 65 #define SCLP_CMDW_WRITE_EVENT_DATA 0x00760005 66 #define SCLP_CMDW_WRITE_EVENT_MASK 0x00780005 67 68 #define GDS_ID_MDSMU 0x1310 69 #define GDS_ID_MDSROUTEINFO 0x1311 70 #define GDS_ID_AGUNWRKCORR 0x1549 71 #define GDS_ID_SNACONDREPORT 0x1532 72 #define GDS_ID_CPMSU 0x1212 73 #define GDS_ID_ROUTTARGINSTR 0x154D 74 #define GDS_ID_OPREQ 0x8070 75 #define GDS_ID_TEXTCMD 0x1320 76 77 #define GDS_KEY_SELFDEFTEXTMSG 0x31 78 79 enum sclp_pm_event { 80 SCLP_PM_EVENT_FREEZE, 81 SCLP_PM_EVENT_THAW, 82 SCLP_PM_EVENT_RESTORE, 83 }; 84 85 #define SCLP_PANIC_PRIO 1 86 #define SCLP_PANIC_PRIO_CLIENT 0 87 88 typedef u32 sccb_mask_t; /* ATTENTION: assumes 32bit mask !!! */ 89 90 struct sccb_header { 91 u16 length; 92 u8 function_code; 93 u8 control_mask[3]; 94 u16 response_code; 95 } __attribute__((packed)); 96 97 struct init_sccb { 98 struct sccb_header header; 99 u16 _reserved; 100 u16 mask_length; 101 sccb_mask_t receive_mask; 102 sccb_mask_t send_mask; 103 sccb_mask_t sclp_receive_mask; 104 sccb_mask_t sclp_send_mask; 105 } __attribute__((packed)); 106 107 struct read_cpu_info_sccb { 108 struct sccb_header header; 109 u16 nr_configured; 110 u16 offset_configured; 111 u16 nr_standby; 112 u16 offset_standby; 113 u8 reserved[4096 - 16]; 114 } __attribute__((packed, aligned(PAGE_SIZE))); 115 116 static inline void sclp_fill_core_info(struct sclp_core_info *info, 117 struct read_cpu_info_sccb *sccb) 118 { 119 char *page = (char *) sccb; 120 121 memset(info, 0, sizeof(*info)); 122 info->configured = sccb->nr_configured; 123 info->standby = sccb->nr_standby; 124 info->combined = sccb->nr_configured + sccb->nr_standby; 125 memcpy(&info->core, page + sccb->offset_configured, 126 info->combined * sizeof(struct sclp_core_entry)); 127 } 128 129 #define SCLP_HAS_CHP_INFO (sclp.facilities & 0x8000000000000000ULL) 130 #define SCLP_HAS_CHP_RECONFIG (sclp.facilities & 0x2000000000000000ULL) 131 #define SCLP_HAS_CPU_INFO (sclp.facilities & 0x0800000000000000ULL) 132 #define SCLP_HAS_CPU_RECONFIG (sclp.facilities & 0x0400000000000000ULL) 133 #define SCLP_HAS_PCI_RECONFIG (sclp.facilities & 0x0000000040000000ULL) 134 135 136 struct gds_subvector { 137 u8 length; 138 u8 key; 139 } __attribute__((packed)); 140 141 struct gds_vector { 142 u16 length; 143 u16 gds_id; 144 } __attribute__((packed)); 145 146 struct evbuf_header { 147 u16 length; 148 u8 type; 149 u8 flags; 150 u16 _reserved; 151 } __attribute__((packed)); 152 153 struct sclp_req { 154 struct list_head list; /* list_head for request queueing. */ 155 sclp_cmdw_t command; /* sclp command to execute */ 156 void *sccb; /* pointer to the sccb to execute */ 157 char status; /* status of this request */ 158 int start_count; /* number of SVCs done for this req */ 159 /* Callback that is called after reaching final status. */ 160 void (*callback)(struct sclp_req *, void *data); 161 void *callback_data; 162 int queue_timeout; /* request queue timeout (sec), set by 163 caller of sclp_add_request(), if 164 needed */ 165 /* Internal fields */ 166 unsigned long queue_expires; /* request queue timeout (jiffies) */ 167 }; 168 169 #define SCLP_REQ_FILLED 0x00 /* request is ready to be processed */ 170 #define SCLP_REQ_QUEUED 0x01 /* request is queued to be processed */ 171 #define SCLP_REQ_RUNNING 0x02 /* request is currently running */ 172 #define SCLP_REQ_DONE 0x03 /* request is completed successfully */ 173 #define SCLP_REQ_FAILED 0x05 /* request is finally failed */ 174 #define SCLP_REQ_QUEUED_TIMEOUT 0x06 /* request on queue timed out */ 175 176 #define SCLP_QUEUE_INTERVAL 5 /* timeout interval for request queue */ 177 178 /* function pointers that a high level driver has to use for registration */ 179 /* of some routines it wants to be called from the low level driver */ 180 struct sclp_register { 181 struct list_head list; 182 /* User wants to receive: */ 183 sccb_mask_t receive_mask; 184 /* User wants to send: */ 185 sccb_mask_t send_mask; 186 /* H/W can receive: */ 187 sccb_mask_t sclp_receive_mask; 188 /* H/W can send: */ 189 sccb_mask_t sclp_send_mask; 190 /* called if event type availability changes */ 191 void (*state_change_fn)(struct sclp_register *); 192 /* called for events in cp_receive_mask/sclp_receive_mask */ 193 void (*receiver_fn)(struct evbuf_header *); 194 /* called for power management events */ 195 void (*pm_event_fn)(struct sclp_register *, enum sclp_pm_event); 196 /* pm event posted flag */ 197 int pm_event_posted; 198 }; 199 200 /* externals from sclp.c */ 201 int sclp_add_request(struct sclp_req *req); 202 void sclp_sync_wait(void); 203 int sclp_register(struct sclp_register *reg); 204 void sclp_unregister(struct sclp_register *reg); 205 int sclp_remove_processed(struct sccb_header *sccb); 206 int sclp_deactivate(void); 207 int sclp_reactivate(void); 208 int sclp_sync_request(sclp_cmdw_t command, void *sccb); 209 int sclp_sync_request_timeout(sclp_cmdw_t command, void *sccb, int timeout); 210 211 int sclp_sdias_init(void); 212 void sclp_sdias_exit(void); 213 214 enum { 215 sclp_init_state_uninitialized, 216 sclp_init_state_initializing, 217 sclp_init_state_initialized 218 }; 219 220 extern int sclp_init_state; 221 extern int sclp_console_pages; 222 extern int sclp_console_drop; 223 extern unsigned long sclp_console_full; 224 225 extern char sclp_early_sccb[PAGE_SIZE]; 226 227 void sclp_early_wait_irq(void); 228 int sclp_early_cmd(sclp_cmdw_t cmd, void *sccb); 229 unsigned int sclp_early_con_check_linemode(struct init_sccb *sccb); 230 int sclp_early_set_event_mask(struct init_sccb *sccb, 231 unsigned long receive_mask, 232 unsigned long send_mask); 233 234 /* useful inlines */ 235 236 /* Perform service call. Return 0 on success, non-zero otherwise. */ 237 static inline int sclp_service_call(sclp_cmdw_t command, void *sccb) 238 { 239 int cc = 4; /* Initialize for program check handling */ 240 241 asm volatile( 242 "0: .insn rre,0xb2200000,%1,%2\n" /* servc %1,%2 */ 243 "1: ipm %0\n" 244 " srl %0,28\n" 245 "2:\n" 246 EX_TABLE(0b, 2b) 247 EX_TABLE(1b, 2b) 248 : "+&d" (cc) : "d" (command), "a" ((unsigned long)sccb) 249 : "cc", "memory"); 250 if (cc == 4) 251 return -EINVAL; 252 if (cc == 3) 253 return -EIO; 254 if (cc == 2) 255 return -EBUSY; 256 return 0; 257 } 258 259 /* VM uses EBCDIC 037, LPAR+native(SE+HMC) use EBCDIC 500 */ 260 /* translate single character from ASCII to EBCDIC */ 261 static inline unsigned char 262 sclp_ascebc(unsigned char ch) 263 { 264 return (MACHINE_IS_VM) ? _ascebc[ch] : _ascebc_500[ch]; 265 } 266 267 /* translate string from EBCDIC to ASCII */ 268 static inline void 269 sclp_ebcasc_str(unsigned char *str, int nr) 270 { 271 (MACHINE_IS_VM) ? EBCASC(str, nr) : EBCASC_500(str, nr); 272 } 273 274 /* translate string from ASCII to EBCDIC */ 275 static inline void 276 sclp_ascebc_str(unsigned char *str, int nr) 277 { 278 (MACHINE_IS_VM) ? ASCEBC(str, nr) : ASCEBC_500(str, nr); 279 } 280 281 static inline struct gds_vector * 282 sclp_find_gds_vector(void *start, void *end, u16 id) 283 { 284 struct gds_vector *v; 285 286 for (v = start; (void *) v < end; v = (void *) v + v->length) 287 if (v->gds_id == id) 288 return v; 289 return NULL; 290 } 291 292 static inline struct gds_subvector * 293 sclp_find_gds_subvector(void *start, void *end, u8 key) 294 { 295 struct gds_subvector *sv; 296 297 for (sv = start; (void *) sv < end; sv = (void *) sv + sv->length) 298 if (sv->key == key) 299 return sv; 300 return NULL; 301 } 302 303 #endif /* __SCLP_H__ */ 304