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