^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * SCLP line mode terminal driver.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * S390 version
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Copyright IBM Corp. 1999
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * Author(s): Martin Peschke <mpeschke@de.ibm.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * Martin Schwidefsky <schwidefsky@de.ibm.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/kmod.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/tty.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/tty_driver.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/tty_flip.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/err.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/interrupt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/gfp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <linux/uaccess.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include "ctrlchar.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include "sclp.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include "sclp_rw.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #include "sclp_tty.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) * size of a buffer that collects single characters coming in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) * via sclp_tty_put_char()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) #define SCLP_TTY_BUF_SIZE 512
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) * There is exactly one SCLP terminal, so we can keep things simple
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) * and allocate all variables statically.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) /* Lock to guard over changes to global variables. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) static spinlock_t sclp_tty_lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) /* List of free pages that can be used for console output buffering. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) static struct list_head sclp_tty_pages;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) /* List of full struct sclp_buffer structures ready for output. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) static struct list_head sclp_tty_outqueue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) /* Counter how many buffers are emitted. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) static int sclp_tty_buffer_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) /* Pointer to current console buffer. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) static struct sclp_buffer *sclp_ttybuf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) /* Timer for delayed output of console messages. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) static struct timer_list sclp_tty_timer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) static struct tty_port sclp_port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) static unsigned char sclp_tty_chars[SCLP_TTY_BUF_SIZE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) static unsigned short int sclp_tty_chars_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) struct tty_driver *sclp_tty_driver;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) static int sclp_tty_tolower;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) static int sclp_tty_columns = 80;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) #define SPACES_PER_TAB 8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) #define CASE_DELIMITER 0x6c /* to separate upper and lower case (% in EBCDIC) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) /* This routine is called whenever we try to open a SCLP terminal. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) sclp_tty_open(struct tty_struct *tty, struct file *filp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) tty_port_tty_set(&sclp_port, tty);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) tty->driver_data = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) sclp_port.low_latency = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) /* This routine is called when the SCLP terminal is closed. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) sclp_tty_close(struct tty_struct *tty, struct file *filp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) if (tty->count > 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) tty_port_tty_set(&sclp_port, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) * This routine returns the numbers of characters the tty driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) * will accept for queuing to be written. This number is subject
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) * to change as output buffers get emptied, or if the output flow
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) * control is acted. This is not an exact number because not every
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) * character needs the same space in the sccb. The worst case is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) * a string of newlines. Every newline creates a new message which
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) * needs 82 bytes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) sclp_tty_write_room (struct tty_struct *tty)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) struct list_head *l;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) int count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) spin_lock_irqsave(&sclp_tty_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) if (sclp_ttybuf != NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) count = sclp_buffer_space(sclp_ttybuf) / sizeof(struct msg_buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) list_for_each(l, &sclp_tty_pages)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) count += NR_EMPTY_MSG_PER_SCCB;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) spin_unlock_irqrestore(&sclp_tty_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) sclp_ttybuf_callback(struct sclp_buffer *buffer, int rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) void *page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) page = sclp_unmake_buffer(buffer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) spin_lock_irqsave(&sclp_tty_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) /* Remove buffer from outqueue */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) list_del(&buffer->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) sclp_tty_buffer_count--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) list_add_tail((struct list_head *) page, &sclp_tty_pages);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) /* Check if there is a pending buffer on the out queue. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) buffer = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) if (!list_empty(&sclp_tty_outqueue))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) buffer = list_entry(sclp_tty_outqueue.next,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) struct sclp_buffer, list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) spin_unlock_irqrestore(&sclp_tty_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) } while (buffer && sclp_emit_buffer(buffer, sclp_ttybuf_callback));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) tty_port_tty_wakeup(&sclp_port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) static inline void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) __sclp_ttybuf_emit(struct sclp_buffer *buffer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) int count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) spin_lock_irqsave(&sclp_tty_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) list_add_tail(&buffer->list, &sclp_tty_outqueue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) count = sclp_tty_buffer_count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) spin_unlock_irqrestore(&sclp_tty_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) if (count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) rc = sclp_emit_buffer(buffer, sclp_ttybuf_callback);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) sclp_ttybuf_callback(buffer, rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) * When this routine is called from the timer then we flush the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) * temporary write buffer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) sclp_tty_timeout(struct timer_list *unused)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) struct sclp_buffer *buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) spin_lock_irqsave(&sclp_tty_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) buf = sclp_ttybuf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) sclp_ttybuf = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) spin_unlock_irqrestore(&sclp_tty_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) if (buf != NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) __sclp_ttybuf_emit(buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) * Write a string to the sclp tty.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) static int sclp_tty_write_string(const unsigned char *str, int count, int may_fail)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) void *page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) int written;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) int overall_written;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) struct sclp_buffer *buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) if (count <= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) overall_written = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) spin_lock_irqsave(&sclp_tty_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) /* Create a sclp output buffer if none exists yet */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) if (sclp_ttybuf == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) while (list_empty(&sclp_tty_pages)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) spin_unlock_irqrestore(&sclp_tty_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) if (may_fail)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) sclp_sync_wait();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) spin_lock_irqsave(&sclp_tty_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) page = sclp_tty_pages.next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) list_del((struct list_head *) page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) sclp_ttybuf = sclp_make_buffer(page, sclp_tty_columns,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) SPACES_PER_TAB);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) /* try to write the string to the current output buffer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) written = sclp_write(sclp_ttybuf, str, count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) overall_written += written;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) if (written == count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) * Not all characters could be written to the current
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) * output buffer. Emit the buffer, create a new buffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) * and then output the rest of the string.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) buf = sclp_ttybuf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) sclp_ttybuf = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) spin_unlock_irqrestore(&sclp_tty_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) __sclp_ttybuf_emit(buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) spin_lock_irqsave(&sclp_tty_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) str += written;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) count -= written;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) } while (count > 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) /* Setup timer to output current console buffer after 1/10 second */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) if (sclp_ttybuf && sclp_chars_in_buffer(sclp_ttybuf) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) !timer_pending(&sclp_tty_timer)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) mod_timer(&sclp_tty_timer, jiffies + HZ / 10);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) spin_unlock_irqrestore(&sclp_tty_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) return overall_written;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) * This routine is called by the kernel to write a series of characters to the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) * tty device. The characters may come from user space or kernel space. This
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) * routine will return the number of characters actually accepted for writing.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) sclp_tty_write(struct tty_struct *tty, const unsigned char *buf, int count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) if (sclp_tty_chars_count > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) sclp_tty_write_string(sclp_tty_chars, sclp_tty_chars_count, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) sclp_tty_chars_count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) return sclp_tty_write_string(buf, count, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) * This routine is called by the kernel to write a single character to the tty
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) * device. If the kernel uses this routine, it must call the flush_chars()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) * routine (if defined) when it is done stuffing characters into the driver.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) * Characters provided to sclp_tty_put_char() are buffered by the SCLP driver.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) * If the given character is a '\n' the contents of the SCLP write buffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) * - including previous characters from sclp_tty_put_char() and strings from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) * sclp_write() without final '\n' - will be written.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) sclp_tty_put_char(struct tty_struct *tty, unsigned char ch)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) sclp_tty_chars[sclp_tty_chars_count++] = ch;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) if (ch == '\n' || sclp_tty_chars_count >= SCLP_TTY_BUF_SIZE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) sclp_tty_write_string(sclp_tty_chars, sclp_tty_chars_count, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) sclp_tty_chars_count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) * This routine is called by the kernel after it has written a series of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) * characters to the tty device using put_char().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) sclp_tty_flush_chars(struct tty_struct *tty)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) if (sclp_tty_chars_count > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) sclp_tty_write_string(sclp_tty_chars, sclp_tty_chars_count, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) sclp_tty_chars_count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) * This routine returns the number of characters in the write buffer of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) * SCLP driver. The provided number includes all characters that are stored
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) * in the SCCB (will be written next time the SCLP is not busy) as well as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) * characters in the write buffer (will not be written as long as there is a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) * final line feed missing).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) sclp_tty_chars_in_buffer(struct tty_struct *tty)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) struct list_head *l;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) struct sclp_buffer *t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) int count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) spin_lock_irqsave(&sclp_tty_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) if (sclp_ttybuf != NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) count = sclp_chars_in_buffer(sclp_ttybuf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) list_for_each(l, &sclp_tty_outqueue) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) t = list_entry(l, struct sclp_buffer, list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) count += sclp_chars_in_buffer(t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) spin_unlock_irqrestore(&sclp_tty_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) * removes all content from buffers of low level driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) sclp_tty_flush_buffer(struct tty_struct *tty)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) if (sclp_tty_chars_count > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) sclp_tty_write_string(sclp_tty_chars, sclp_tty_chars_count, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) sclp_tty_chars_count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) * push input to tty
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) sclp_tty_input(unsigned char* buf, unsigned int count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) struct tty_struct *tty = tty_port_tty_get(&sclp_port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) unsigned int cchar;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) * If this tty driver is currently closed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) * then throw the received input away.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) if (tty == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) cchar = ctrlchar_handle(buf, count, tty);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) switch (cchar & CTRLCHAR_MASK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) case CTRLCHAR_SYSRQ:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) case CTRLCHAR_CTRL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) tty_insert_flip_char(&sclp_port, cchar, TTY_NORMAL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) tty_flip_buffer_push(&sclp_port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) case CTRLCHAR_NONE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) /* send (normal) input to line discipline */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) if (count < 2 ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) (strncmp((const char *) buf + count - 2, "^n", 2) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) strncmp((const char *) buf + count - 2, "\252n", 2))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) /* add the auto \n */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) tty_insert_flip_string(&sclp_port, buf, count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) tty_insert_flip_char(&sclp_port, '\n', TTY_NORMAL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) tty_insert_flip_string(&sclp_port, buf, count - 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) tty_flip_buffer_push(&sclp_port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) tty_kref_put(tty);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) * get a EBCDIC string in upper/lower case,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) * find out characters in lower/upper case separated by a special character,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) * modifiy original string,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) * returns length of resulting string
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) static int sclp_switch_cases(unsigned char *buf, int count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) unsigned char *ip, *op;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) int toggle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) /* initially changing case is off */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) toggle = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) ip = op = buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) while (count-- > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) /* compare with special character */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) if (*ip == CASE_DELIMITER) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) /* followed by another special character? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) if (count && ip[1] == CASE_DELIMITER) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) * ... then put a single copy of the special
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) * character to the output string
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) *op++ = *ip++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) count--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) * ... special character follower by a normal
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) * character toggles the case change behaviour
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) toggle = ~toggle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) /* skip special character */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) ip++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) /* not the special character */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) if (toggle)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) /* but case switching is on */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) if (sclp_tty_tolower)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) /* switch to uppercase */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) *op++ = _ebc_toupper[(int) *ip++];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) /* switch to lowercase */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) *op++ = _ebc_tolower[(int) *ip++];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) /* no case switching, copy the character */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) *op++ = *ip++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) /* return length of reformatted string. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) return op - buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) static void sclp_get_input(struct gds_subvector *sv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) unsigned char *str;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) int count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) str = (unsigned char *) (sv + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) count = sv->length - sizeof(*sv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) if (sclp_tty_tolower)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) EBC_TOLOWER(str, count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) count = sclp_switch_cases(str, count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) /* convert EBCDIC to ASCII (modify original input in SCCB) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) sclp_ebcasc_str(str, count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) /* transfer input to high level driver */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) sclp_tty_input(str, count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) static inline void sclp_eval_selfdeftextmsg(struct gds_subvector *sv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) void *end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) end = (void *) sv + sv->length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) for (sv = sv + 1; (void *) sv < end; sv = (void *) sv + sv->length)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) if (sv->key == 0x30)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) sclp_get_input(sv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) static inline void sclp_eval_textcmd(struct gds_vector *v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) struct gds_subvector *sv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) void *end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) end = (void *) v + v->length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) for (sv = (struct gds_subvector *) (v + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) (void *) sv < end; sv = (void *) sv + sv->length)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) if (sv->key == GDS_KEY_SELFDEFTEXTMSG)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) sclp_eval_selfdeftextmsg(sv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) static inline void sclp_eval_cpmsu(struct gds_vector *v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) void *end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) end = (void *) v + v->length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) for (v = v + 1; (void *) v < end; v = (void *) v + v->length)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) if (v->gds_id == GDS_ID_TEXTCMD)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) sclp_eval_textcmd(v);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) static inline void sclp_eval_mdsmu(struct gds_vector *v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) v = sclp_find_gds_vector(v + 1, (void *) v + v->length, GDS_ID_CPMSU);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) if (v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) sclp_eval_cpmsu(v);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) static void sclp_tty_receiver(struct evbuf_header *evbuf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) struct gds_vector *v;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) v = sclp_find_gds_vector(evbuf + 1, (void *) evbuf + evbuf->length,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) GDS_ID_MDSMU);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) if (v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) sclp_eval_mdsmu(v);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) sclp_tty_state_change(struct sclp_register *reg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) static struct sclp_register sclp_input_event =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) .receive_mask = EVTYP_OPCMD_MASK | EVTYP_PMSGCMD_MASK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) .state_change_fn = sclp_tty_state_change,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) .receiver_fn = sclp_tty_receiver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) static const struct tty_operations sclp_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) .open = sclp_tty_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) .close = sclp_tty_close,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) .write = sclp_tty_write,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) .put_char = sclp_tty_put_char,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) .flush_chars = sclp_tty_flush_chars,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) .write_room = sclp_tty_write_room,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) .chars_in_buffer = sclp_tty_chars_in_buffer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) .flush_buffer = sclp_tty_flush_buffer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) static int __init
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) sclp_tty_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) struct tty_driver *driver;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) void *page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) /* z/VM multiplexes the line mode output on the 32xx screen */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) if (MACHINE_IS_VM && !CONSOLE_IS_SCLP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) if (!sclp.has_linemode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) driver = alloc_tty_driver(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) if (!driver)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) rc = sclp_rw_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) put_tty_driver(driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) /* Allocate pages for output buffering */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) INIT_LIST_HEAD(&sclp_tty_pages);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) for (i = 0; i < MAX_KMEM_PAGES; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) page = (void *) get_zeroed_page(GFP_KERNEL | GFP_DMA);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) if (page == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) put_tty_driver(driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) list_add_tail((struct list_head *) page, &sclp_tty_pages);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) INIT_LIST_HEAD(&sclp_tty_outqueue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) spin_lock_init(&sclp_tty_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) timer_setup(&sclp_tty_timer, sclp_tty_timeout, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) sclp_ttybuf = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) sclp_tty_buffer_count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) if (MACHINE_IS_VM) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) * save 4 characters for the CPU number
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) * written at start of each line by VM/CP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) sclp_tty_columns = 76;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) /* case input lines to lowercase */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) sclp_tty_tolower = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) sclp_tty_chars_count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) rc = sclp_register(&sclp_input_event);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) put_tty_driver(driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) tty_port_init(&sclp_port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) driver->driver_name = "sclp_line";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) driver->name = "sclp_line";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) driver->major = TTY_MAJOR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) driver->minor_start = 64;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) driver->type = TTY_DRIVER_TYPE_SYSTEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) driver->subtype = SYSTEM_TYPE_TTY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) driver->init_termios = tty_std_termios;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) driver->init_termios.c_iflag = IGNBRK | IGNPAR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) driver->init_termios.c_oflag = ONLCR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) driver->init_termios.c_lflag = ISIG | ECHO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) driver->flags = TTY_DRIVER_REAL_RAW;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) tty_set_operations(driver, &sclp_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) tty_port_link_device(&sclp_port, driver, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) rc = tty_register_driver(driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) put_tty_driver(driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) tty_port_destroy(&sclp_port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) sclp_tty_driver = driver;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) device_initcall(sclp_tty_init);