10 #include <linux/module.h>
12 #include <linux/tty.h>
19 #include <asm/uaccess.h>
30 #define SCLP_TTY_BUF_SIZE 512
42 static struct list_head sclp_tty_outqueue;
44 static int sclp_tty_buffer_count;
52 static unsigned short int sclp_tty_chars_count;
56 static int sclp_tty_tolower;
57 static int sclp_tty_columns = 80;
59 #define SPACES_PER_TAB 8
60 #define CASE_DELIMITER 0x6c
99 if (sclp_ttybuf !=
NULL)
103 spin_unlock_irqrestore(&sclp_tty_lock, flags);
119 sclp_tty_buffer_count--;
123 if (!list_empty(&sclp_tty_outqueue))
126 spin_unlock_irqrestore(&sclp_tty_lock, flags);
145 count = sclp_tty_buffer_count++;
146 spin_unlock_irqrestore(&sclp_tty_lock, flags);
151 sclp_ttybuf_callback(buffer, rc);
159 sclp_tty_timeout(
unsigned long data)
167 spin_unlock_irqrestore(&sclp_tty_lock, flags);
170 __sclp_ttybuf_emit(buf);
177 static int sclp_tty_write_string(
const unsigned char *
str,
int count,
int may_fail)
191 if (sclp_ttybuf ==
NULL) {
192 while (list_empty(&sclp_tty_pages)) {
193 spin_unlock_irqrestore(&sclp_tty_lock, flags);
200 page = sclp_tty_pages.next;
206 written =
sclp_write(sclp_ttybuf, str, count);
207 overall_written += written;
208 if (written == count)
217 spin_unlock_irqrestore(&sclp_tty_lock, flags);
218 __sclp_ttybuf_emit(buf);
225 !timer_pending(&sclp_tty_timer)) {
227 sclp_tty_timer.function = sclp_tty_timeout;
228 sclp_tty_timer.data = 0
UL;
229 sclp_tty_timer.expires =
jiffies +
HZ/10;
232 spin_unlock_irqrestore(&sclp_tty_lock, flags);
234 return overall_written;
243 sclp_tty_write(
struct tty_struct *tty,
const unsigned char *buf,
int count)
245 if (sclp_tty_chars_count > 0) {
246 sclp_tty_write_string(sclp_tty_chars, sclp_tty_chars_count, 0);
247 sclp_tty_chars_count = 0;
249 return sclp_tty_write_string(buf, count, 1);
263 sclp_tty_put_char(
struct tty_struct *tty,
unsigned char ch)
265 sclp_tty_chars[sclp_tty_chars_count++] = ch;
267 sclp_tty_write_string(sclp_tty_chars, sclp_tty_chars_count, 0);
268 sclp_tty_chars_count = 0;
280 if (sclp_tty_chars_count > 0) {
281 sclp_tty_write_string(sclp_tty_chars, sclp_tty_chars_count, 0);
282 sclp_tty_chars_count = 0;
294 sclp_tty_chars_in_buffer(
struct tty_struct *tty)
303 if (sclp_ttybuf !=
NULL)
309 spin_unlock_irqrestore(&sclp_tty_lock, flags);
319 if (sclp_tty_chars_count > 0) {
320 sclp_tty_write_string(sclp_tty_chars, sclp_tty_chars_count, 0);
321 sclp_tty_chars_count = 0;
329 sclp_tty_input(
unsigned char* buf,
unsigned int count)
351 (
strncmp((
const char *) buf + count - 2,
"^n", 2) &&
352 strncmp((
const char *) buf + count - 2,
"\252n", 2))) {
354 tty_insert_flip_string(tty, buf, count);
357 tty_insert_flip_string(tty, buf, count - 2);
370 static int sclp_switch_cases(
unsigned char *buf,
int count)
372 unsigned char *
ip, *
op;
378 while (count-- > 0) {
401 if (sclp_tty_tolower)
420 str = (
unsigned char *) (sv + 1);
421 count = sv->
length -
sizeof(*sv);
422 if (sclp_tty_tolower)
424 count = sclp_switch_cases(str, count);
426 sclp_ebcasc_str(str, count);
429 sclp_tty_input(str, count);
432 static inline void sclp_eval_selfdeftextmsg(
struct gds_subvector *sv)
436 end = (
void *) sv + sv->
length;
437 for (sv = sv + 1; (
void *) sv < end; sv = (
void *) sv + sv->
length)
442 static inline void sclp_eval_textcmd(
struct gds_vector *
v)
447 end = (
void *) v + v->
length;
449 (
void *) sv < end; sv = (
void *) sv + sv->
length)
451 sclp_eval_selfdeftextmsg(sv);
455 static inline void sclp_eval_cpmsu(
struct gds_vector *v)
459 end = (
void *) v + v->
length;
460 for (v = v + 1; (
void *) v < end; v = (
void *) v + v->
length)
462 sclp_eval_textcmd(v);
466 static inline void sclp_eval_mdsmu(
struct gds_vector *v)
477 v = sclp_find_gds_vector(evbuf + 1, (
void *) evbuf + evbuf->
length,
491 .state_change_fn = sclp_tty_state_change,
492 .receiver_fn = sclp_tty_receiver
496 .open = sclp_tty_open,
497 .close = sclp_tty_close,
498 .write = sclp_tty_write,
499 .put_char = sclp_tty_put_char,
500 .flush_chars = sclp_tty_flush_chars,
501 .write_room = sclp_tty_write_room,
502 .chars_in_buffer = sclp_tty_chars_in_buffer,
503 .flush_buffer = sclp_tty_flush_buffer,
516 driver = alloc_tty_driver(1);
526 INIT_LIST_HEAD(&sclp_tty_pages);
535 INIT_LIST_HEAD(&sclp_tty_outqueue);
539 sclp_tty_buffer_count = 0;
545 sclp_tty_columns = 76;
547 sclp_tty_tolower = 1;
549 sclp_tty_chars_count = 0;
559 driver->
name =
"sclp_line";