2 * Copyright IBM Corp. 2015
3 * Author(s): Martin Schwidefsky <schwidefsky@de.ibm.com>
5 #include <linux/kernel.h>
6 #include <asm/ebcdic.h>
8 #include <asm/lowcore.h>
9 #include <asm/processor.h>
12 #define EVTYP_VT220MSG_MASK 0x00000040
13 #define EVTYP_MSG_MASK 0x40000000
15 static char _sclp_work_area[4096] __aligned(PAGE_SIZE) __section(data);
16 static bool have_vt220 __section(data);
17 static bool have_linemode __section(data);
19 static void _sclp_wait_int(void)
21 unsigned long psw_mask, addr, flags;
22 psw_t psw_ext_save, psw_wait;
23 union ctlreg0 cr0, cr0_new;
25 raw_local_irq_save(flags);
26 __ctl_store(cr0.val, 0, 0);
27 cr0_new.val = cr0.val & ~CR0_IRQ_SUBCLASS_MASK;
30 __ctl_load(cr0_new.val, 0, 0);
32 psw_ext_save = S390_lowcore.external_new_psw;
33 psw_mask = __extract_psw();
34 S390_lowcore.external_new_psw.mask = psw_mask;
35 psw_wait.mask = psw_mask | PSW_MASK_EXT | PSW_MASK_WAIT;
36 S390_lowcore.ext_int_code = 0;
41 " stg %[addr],%[psw_wait_addr]\n"
42 " stg %[addr],%[psw_ext_addr]\n"
43 " lpswe %[psw_wait]\n"
45 : [addr] "=&d" (addr),
46 [psw_wait_addr] "=Q" (psw_wait.addr),
47 [psw_ext_addr] "=Q" (S390_lowcore.external_new_psw.addr)
48 : [psw_wait] "Q" (psw_wait)
50 } while (S390_lowcore.ext_int_code != EXT_IRQ_SERVICE_SIG);
52 S390_lowcore.external_new_psw = psw_ext_save;
53 __ctl_load(cr0.val, 0, 0);
54 raw_local_irq_restore(flags);
57 static int _sclp_servc(unsigned int cmd, char *sccb)
63 " .insn rre,0xb2200000,%1,%2\n"
65 : "=d" (cc) : "d" (cmd), "a" (sccb)
72 return (*(unsigned short *)(sccb + 6) == 0x20) ? 0 : -EIO;
75 static int _sclp_setup(int disable)
77 static unsigned char init_sccb[] = {
79 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
81 0x80, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x40,
82 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
87 memcpy(_sclp_work_area, init_sccb, 28);
88 masks = (unsigned int *)(_sclp_work_area + 12);
92 rc = _sclp_servc(0x00780005, _sclp_work_area);
95 have_vt220 = masks[2] & EVTYP_VT220MSG_MASK;
96 have_linemode = masks[2] & EVTYP_MSG_MASK;
100 /* Output multi-line text using SCLP Message interface. */
101 static void _sclp_print_lm(const char *str, unsigned int len)
103 static unsigned char write_head[] = {
106 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 2 */
109 0x02, 0x00, 0x00, 0x00, /* 10 */
113 0xd4, 0xc4, 0xc2, 0x40, /* 18 */
114 0x00, 0x00, 0x00, 0x01, /* 22 */
118 0x00, 0x00, 0x00, 0x00, /* 30 */
119 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 34 */
120 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 42 */
121 0x00, 0x00, 0x00, 0x00, /* 50 */
123 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 56 */
124 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 64 */
125 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 72 */
128 static unsigned char write_mto[] = {
133 0x00, 0x00, 0x00, 0x00 /* 6 */
135 unsigned char *ptr, *end_ptr, ch;
136 unsigned int count, num;
139 memcpy(_sclp_work_area, write_head, sizeof(write_head));
140 ptr = _sclp_work_area + sizeof(write_head);
141 end_ptr = _sclp_work_area + sizeof(_sclp_work_area) - 1;
143 if (ptr + sizeof(write_mto) > end_ptr)
145 memcpy(ptr, write_mto, sizeof(write_mto));
146 for (count = sizeof(write_mto); num < len; count++) {
153 ptr[count] = _ascebc[ch];
155 /* Update length fields in mto, mdb, evbuf and sccb */
156 *(unsigned short *) ptr = count;
157 *(unsigned short *)(_sclp_work_area + 14) += count;
158 *(unsigned short *)(_sclp_work_area + 8) += count;
159 *(unsigned short *)(_sclp_work_area + 0) += count;
163 /* SCLP write data */
164 _sclp_servc(0x00760005, _sclp_work_area);
167 /* Output multi-line text (plus a newline) using SCLP VT220
170 static void _sclp_print_vt220(const char *str, unsigned int len)
172 static unsigned char const write_head[] = {
175 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
178 0x1a, 0x00, 0x00, 0x00,
181 if (sizeof(write_head) + len >= sizeof(_sclp_work_area))
182 len = sizeof(_sclp_work_area) - sizeof(write_head) - 1;
184 memcpy(_sclp_work_area, write_head, sizeof(write_head));
185 memcpy(_sclp_work_area + sizeof(write_head), str, len);
186 _sclp_work_area[sizeof(write_head) + len] = '\n';
188 /* Update length fields in evbuf and sccb headers */
189 *(unsigned short *)(_sclp_work_area + 8) += len + 1;
190 *(unsigned short *)(_sclp_work_area + 0) += len + 1;
192 /* SCLP write data */
193 (void)_sclp_servc(0x00760005, _sclp_work_area);
196 /* Output one or more lines of text on the SCLP console (VT220 and /
197 * or line-mode). All lines get terminated; no need for a trailing LF.
199 void __sclp_print_early(const char *str, unsigned int len)
201 if (_sclp_setup(0) != 0)
204 _sclp_print_lm(str, len);
206 _sclp_print_vt220(str, len);
210 void _sclp_print_early(const char *str)
212 __sclp_print_early(str, strlen(str));