1 /* SPDX-License-Identifier: GPL-2.0 */
3 * Copyright IBM Corp. 1999,2012
5 * Author(s): Martin Peschke <mpeschke@de.ibm.com>
6 * Martin Schwidefsky <schwidefsky@de.ibm.com>
12 #include <linux/types.h>
13 #include <linux/list.h>
15 #include <asm/ebcdic.h>
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
21 #define SCLP_EVTYP_MASK(T) (1U << (32 - (T)))
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
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)
51 #define GNRLMSGFLGS_DOM 0x8000
52 #define GNRLMSGFLGS_SNDALRM 0x4000
53 #define GNRLMSGFLGS_HOLDMSG 0x2000
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
61 typedef unsigned int sclp_cmdw_t
;
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
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
77 #define GDS_KEY_SELFDEFTEXTMSG 0x31
82 SCLP_PM_EVENT_RESTORE
,
85 #define SCLP_PANIC_PRIO 1
86 #define SCLP_PANIC_PRIO_CLIENT 0
88 typedef u32 sccb_mask_t
; /* ATTENTION: assumes 32bit mask !!! */
95 } __attribute__((packed
));
98 struct sccb_header header
;
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
));
107 struct read_cpu_info_sccb
{
108 struct sccb_header header
;
110 u16 offset_configured
;
113 u8 reserved
[4096 - 16];
114 } __attribute__((packed
, aligned(PAGE_SIZE
)));
116 static inline void sclp_fill_core_info(struct sclp_core_info
*info
,
117 struct read_cpu_info_sccb
*sccb
)
119 char *page
= (char *) sccb
;
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
));
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)
136 struct gds_subvector
{
139 } __attribute__((packed
));
144 } __attribute__((packed
));
146 struct evbuf_header
{
151 } __attribute__((packed
));
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
);
162 int queue_timeout
; /* request queue timeout (sec), set by
163 caller of sclp_add_request(), if
165 /* Internal fields */
166 unsigned long queue_expires
; /* request queue timeout (jiffies) */
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 */
176 #define SCLP_QUEUE_INTERVAL 5 /* timeout interval for request queue */
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
;
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 */
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
);
211 int sclp_sdias_init(void);
212 void sclp_sdias_exit(void);
215 sclp_init_state_uninitialized
,
216 sclp_init_state_initializing
,
217 sclp_init_state_initialized
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
;
225 extern char sclp_early_sccb
[PAGE_SIZE
];
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
);
236 /* Perform service call. Return 0 on success, non-zero otherwise. */
237 static inline int sclp_service_call(sclp_cmdw_t command
, void *sccb
)
239 int cc
= 4; /* Initialize for program check handling */
242 "0: .insn rre,0xb2200000,%1,%2\n" /* servc %1,%2 */
248 : "+&d" (cc
) : "d" (command
), "a" ((unsigned long)sccb
)
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
)
264 return (MACHINE_IS_VM
) ? _ascebc
[ch
] : _ascebc_500
[ch
];
267 /* translate string from EBCDIC to ASCII */
269 sclp_ebcasc_str(unsigned char *str
, int nr
)
271 (MACHINE_IS_VM
) ? EBCASC(str
, nr
) : EBCASC_500(str
, nr
);
274 /* translate string from ASCII to EBCDIC */
276 sclp_ascebc_str(unsigned char *str
, int nr
)
278 (MACHINE_IS_VM
) ? ASCEBC(str
, nr
) : ASCEBC_500(str
, nr
);
281 static inline struct gds_vector
*
282 sclp_find_gds_vector(void *start
, void *end
, u16 id
)
284 struct gds_vector
*v
;
286 for (v
= start
; (void *) v
< end
; v
= (void *) v
+ v
->length
)
292 static inline struct gds_subvector
*
293 sclp_find_gds_subvector(void *start
, void *end
, u8 key
)
295 struct gds_subvector
*sv
;
297 for (sv
= start
; (void *) sv
< end
; sv
= (void *) sv
+ sv
->length
)
303 #endif /* __SCLP_H__ */