^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 VT220 terminal driver.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright IBM Corp. 2003, 2009
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * Author(s): Peter Oberparleiter <Peter.Oberparleiter@de.ibm.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/spinlock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/list.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/wait.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/timer.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/sysrq.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/tty.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/tty_driver.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <linux/tty_flip.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <linux/mm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include <linux/major.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include <linux/console.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #include <linux/kdev_t.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #include <linux/interrupt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #include <linux/reboot.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) #include <linux/uaccess.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) #include "sclp.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) #include "ctrlchar.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) #define SCLP_VT220_MAJOR TTY_MAJOR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) #define SCLP_VT220_MINOR 65
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) #define SCLP_VT220_DRIVER_NAME "sclp_vt220"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) #define SCLP_VT220_DEVICE_NAME "ttysclp"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) #define SCLP_VT220_CONSOLE_NAME "ttysclp"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) #define SCLP_VT220_CONSOLE_INDEX 0 /* console=ttysclp0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) /* Representation of a single write request */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) struct sclp_vt220_request {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) struct list_head list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) struct sclp_req sclp_req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) int retry_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) /* VT220 SCCB */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) struct sclp_vt220_sccb {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) struct sccb_header header;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) struct evbuf_header evbuf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) #define SCLP_VT220_MAX_CHARS_PER_BUFFER (PAGE_SIZE - \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) sizeof(struct sclp_vt220_request) - \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) sizeof(struct sclp_vt220_sccb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) /* Structures and data needed to register tty driver */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) static struct tty_driver *sclp_vt220_driver;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) static struct tty_port sclp_vt220_port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) /* Lock to protect internal data from concurrent access */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) static spinlock_t sclp_vt220_lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) /* List of empty pages to be used as write request buffers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) static struct list_head sclp_vt220_empty;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) /* List of pending requests */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) static struct list_head sclp_vt220_outqueue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) /* Suspend mode flag */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) static int sclp_vt220_suspended;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) /* Flag that output queue is currently running */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) static int sclp_vt220_queue_running;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) /* Timer used for delaying write requests to merge subsequent messages into
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) * a single buffer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) static struct timer_list sclp_vt220_timer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) /* Pointer to current request buffer which has been partially filled but not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) * yet sent */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) static struct sclp_vt220_request *sclp_vt220_current_request;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) /* Number of characters in current request buffer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) static int sclp_vt220_buffered_chars;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) /* Counter controlling core driver initialization. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) static int __initdata sclp_vt220_init_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) /* Flag indicating that sclp_vt220_current_request should really
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) * have been already queued but wasn't because the SCLP was processing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) * another buffer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) static int sclp_vt220_flush_later;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) static void sclp_vt220_receiver_fn(struct evbuf_header *evbuf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) static void sclp_vt220_pm_event_fn(struct sclp_register *reg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) enum sclp_pm_event sclp_pm_event);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) static int __sclp_vt220_emit(struct sclp_vt220_request *request);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) static void sclp_vt220_emit_current(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) /* Registration structure for SCLP output event buffers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) static struct sclp_register sclp_vt220_register = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) .send_mask = EVTYP_VT220MSG_MASK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) .pm_event_fn = sclp_vt220_pm_event_fn,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) /* Registration structure for SCLP input event buffers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) static struct sclp_register sclp_vt220_register_input = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) .receive_mask = EVTYP_VT220MSG_MASK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) .receiver_fn = sclp_vt220_receiver_fn,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) * Put provided request buffer back into queue and check emit pending
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) * buffers if necessary.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) sclp_vt220_process_queue(struct sclp_vt220_request *request)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) void *page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) /* Put buffer back to list of empty buffers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) page = request->sclp_req.sccb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) spin_lock_irqsave(&sclp_vt220_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) /* Move request from outqueue to empty queue */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) list_del(&request->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) list_add_tail((struct list_head *) page, &sclp_vt220_empty);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) /* Check if there is a pending buffer on the out queue. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) request = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) if (!list_empty(&sclp_vt220_outqueue))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) request = list_entry(sclp_vt220_outqueue.next,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) struct sclp_vt220_request, list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) if (!request || sclp_vt220_suspended) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) sclp_vt220_queue_running = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) spin_unlock_irqrestore(&sclp_vt220_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) spin_unlock_irqrestore(&sclp_vt220_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) } while (__sclp_vt220_emit(request));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) if (request == NULL && sclp_vt220_flush_later)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) sclp_vt220_emit_current();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) tty_port_tty_wakeup(&sclp_vt220_port);
^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) #define SCLP_BUFFER_MAX_RETRY 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) * Callback through which the result of a write request is reported by the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) * SCLP.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) sclp_vt220_callback(struct sclp_req *request, void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) struct sclp_vt220_request *vt220_request;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) struct sclp_vt220_sccb *sccb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) vt220_request = (struct sclp_vt220_request *) data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) if (request->status == SCLP_REQ_FAILED) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) sclp_vt220_process_queue(vt220_request);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) sccb = (struct sclp_vt220_sccb *) vt220_request->sclp_req.sccb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) /* Check SCLP response code and choose suitable action */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) switch (sccb->header.response_code) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) case 0x0020 :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) case 0x05f0: /* Target resource in improper state */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) case 0x0340: /* Contained SCLP equipment check */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) if (++vt220_request->retry_count > SCLP_BUFFER_MAX_RETRY)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) /* Remove processed buffers and requeue rest */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) if (sclp_remove_processed((struct sccb_header *) sccb) > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) /* Not all buffers were processed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) sccb->header.response_code = 0x0000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) vt220_request->sclp_req.status = SCLP_REQ_FILLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) if (sclp_add_request(request) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) case 0x0040: /* SCLP equipment check */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) if (++vt220_request->retry_count > SCLP_BUFFER_MAX_RETRY)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) sccb->header.response_code = 0x0000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) vt220_request->sclp_req.status = SCLP_REQ_FILLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) if (sclp_add_request(request) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) sclp_vt220_process_queue(vt220_request);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) * Emit vt220 request buffer to SCLP. Return zero on success, non-zero
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) * otherwise.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) __sclp_vt220_emit(struct sclp_vt220_request *request)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) request->sclp_req.command = SCLP_CMDW_WRITE_EVENT_DATA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) request->sclp_req.status = SCLP_REQ_FILLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) request->sclp_req.callback = sclp_vt220_callback;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) request->sclp_req.callback_data = (void *) request;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) return sclp_add_request(&request->sclp_req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) * Queue and emit current request.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) sclp_vt220_emit_current(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) struct sclp_vt220_request *request;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) struct sclp_vt220_sccb *sccb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) spin_lock_irqsave(&sclp_vt220_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) if (sclp_vt220_current_request) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) sccb = (struct sclp_vt220_sccb *)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) sclp_vt220_current_request->sclp_req.sccb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) /* Only emit buffers with content */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) if (sccb->header.length != sizeof(struct sclp_vt220_sccb)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) list_add_tail(&sclp_vt220_current_request->list,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) &sclp_vt220_outqueue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) sclp_vt220_current_request = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) if (timer_pending(&sclp_vt220_timer))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) del_timer(&sclp_vt220_timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) sclp_vt220_flush_later = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) if (sclp_vt220_queue_running || sclp_vt220_suspended)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) goto out_unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) if (list_empty(&sclp_vt220_outqueue))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) goto out_unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) request = list_first_entry(&sclp_vt220_outqueue,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) struct sclp_vt220_request, list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) sclp_vt220_queue_running = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) spin_unlock_irqrestore(&sclp_vt220_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) if (__sclp_vt220_emit(request))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) sclp_vt220_process_queue(request);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) out_unlock:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) spin_unlock_irqrestore(&sclp_vt220_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) #define SCLP_NORMAL_WRITE 0x00
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) * Helper function to initialize a page with the sclp request structure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) static struct sclp_vt220_request *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) sclp_vt220_initialize_page(void *page)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) struct sclp_vt220_request *request;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) struct sclp_vt220_sccb *sccb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) /* Place request structure at end of page */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) request = ((struct sclp_vt220_request *)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) ((addr_t) page + PAGE_SIZE)) - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) request->retry_count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) request->sclp_req.sccb = page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) /* SCCB goes at start of page */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) sccb = (struct sclp_vt220_sccb *) page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) memset((void *) sccb, 0, sizeof(struct sclp_vt220_sccb));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) sccb->header.length = sizeof(struct sclp_vt220_sccb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) sccb->header.function_code = SCLP_NORMAL_WRITE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) sccb->header.response_code = 0x0000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) sccb->evbuf.type = EVTYP_VT220MSG;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) sccb->evbuf.length = sizeof(struct evbuf_header);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) return request;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) static inline unsigned int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) sclp_vt220_space_left(struct sclp_vt220_request *request)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) struct sclp_vt220_sccb *sccb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) sccb = (struct sclp_vt220_sccb *) request->sclp_req.sccb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) return PAGE_SIZE - sizeof(struct sclp_vt220_request) -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) sccb->header.length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) static inline unsigned int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) sclp_vt220_chars_stored(struct sclp_vt220_request *request)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) struct sclp_vt220_sccb *sccb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) sccb = (struct sclp_vt220_sccb *) request->sclp_req.sccb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) return sccb->evbuf.length - sizeof(struct evbuf_header);
^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) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) * Add msg to buffer associated with request. Return the number of characters
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) * added.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) sclp_vt220_add_msg(struct sclp_vt220_request *request,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) const unsigned char *msg, int count, int convertlf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) struct sclp_vt220_sccb *sccb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) void *buffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) unsigned char c;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) int from;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) int to;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) if (count > sclp_vt220_space_left(request))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) count = sclp_vt220_space_left(request);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) if (count <= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) sccb = (struct sclp_vt220_sccb *) request->sclp_req.sccb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) buffer = (void *) ((addr_t) sccb + sccb->header.length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) if (convertlf) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) /* Perform Linefeed conversion (0x0a -> 0x0a 0x0d)*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) for (from=0, to=0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) (from < count) && (to < sclp_vt220_space_left(request));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) from++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) /* Retrieve character */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) c = msg[from];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) /* Perform conversion */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) if (c == 0x0a) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) if (to + 1 < sclp_vt220_space_left(request)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) ((unsigned char *) buffer)[to++] = c;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) ((unsigned char *) buffer)[to++] = 0x0d;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) ((unsigned char *) buffer)[to++] = c;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) sccb->header.length += to;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) sccb->evbuf.length += to;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) return from;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) memcpy(buffer, (const void *) msg, count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) sccb->header.length += count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) sccb->evbuf.length += count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) return count;
^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) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) * Emit buffer after having waited long enough for more data to arrive.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) sclp_vt220_timeout(struct timer_list *unused)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) sclp_vt220_emit_current();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) #define BUFFER_MAX_DELAY HZ/20
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) * Drop oldest console buffer if sclp_con_drop is set
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) sclp_vt220_drop_buffer(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) struct list_head *list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) struct sclp_vt220_request *request;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) void *page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) if (!sclp_console_drop)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) list = sclp_vt220_outqueue.next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) if (sclp_vt220_queue_running)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) /* The first element is in I/O */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) list = list->next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) if (list == &sclp_vt220_outqueue)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) list_del(list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) request = list_entry(list, struct sclp_vt220_request, list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) page = request->sclp_req.sccb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) list_add_tail((struct list_head *) page, &sclp_vt220_empty);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) * Internal implementation of the write function. Write COUNT bytes of data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) * from memory at BUF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) * to the SCLP interface. In case that the data does not fit into the current
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) * write buffer, emit the current one and allocate a new one. If there are no
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) * more empty buffers available, wait until one gets emptied. If DO_SCHEDULE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) * is non-zero, the buffer will be scheduled for emitting after a timeout -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) * otherwise the user has to explicitly call the flush function.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) * A non-zero CONVERTLF parameter indicates that 0x0a characters in the message
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) * buffer should be converted to 0x0a 0x0d. After completion, return the number
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) * of bytes written.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) __sclp_vt220_write(const unsigned char *buf, int count, int do_schedule,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) int convertlf, int may_fail)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) void *page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) int written;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) int overall_written;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) if (count <= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) overall_written = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) spin_lock_irqsave(&sclp_vt220_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) /* Create an sclp output buffer if none exists yet */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) if (sclp_vt220_current_request == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) if (list_empty(&sclp_vt220_empty))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) sclp_console_full++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) while (list_empty(&sclp_vt220_empty)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) if (may_fail || sclp_vt220_suspended)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) if (sclp_vt220_drop_buffer())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) spin_unlock_irqrestore(&sclp_vt220_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) sclp_sync_wait();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) spin_lock_irqsave(&sclp_vt220_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) page = (void *) sclp_vt220_empty.next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) list_del((struct list_head *) page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) sclp_vt220_current_request =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) sclp_vt220_initialize_page(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) /* Try to write the string to the current request buffer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) written = sclp_vt220_add_msg(sclp_vt220_current_request,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) buf, count, convertlf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) overall_written += written;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) if (written == count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) * Not all characters could be written to the current
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) * output buffer. Emit the buffer, create a new buffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) * and then output the rest of the string.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) spin_unlock_irqrestore(&sclp_vt220_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) sclp_vt220_emit_current();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) spin_lock_irqsave(&sclp_vt220_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) buf += written;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) count -= written;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) } while (count > 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) /* Setup timer to output current console buffer after some time */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) if (sclp_vt220_current_request != NULL &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) !timer_pending(&sclp_vt220_timer) && do_schedule) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) sclp_vt220_timer.expires = jiffies + BUFFER_MAX_DELAY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) add_timer(&sclp_vt220_timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) spin_unlock_irqrestore(&sclp_vt220_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) return overall_written;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) * This routine is called by the kernel to write a series of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) * characters to the tty device. The characters may come from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) * user space or kernel space. This routine will return the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) * number of characters actually accepted for writing.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) sclp_vt220_write(struct tty_struct *tty, const unsigned char *buf, int count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) return __sclp_vt220_write(buf, count, 1, 0, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) #define SCLP_VT220_SESSION_ENDED 0x01
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) #define SCLP_VT220_SESSION_STARTED 0x80
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) #define SCLP_VT220_SESSION_DATA 0x00
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) #ifdef CONFIG_MAGIC_SYSRQ
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) static int sysrq_pressed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) static struct sysrq_work sysrq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) static void sclp_vt220_reset_session(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) sysrq_pressed = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) static void sclp_vt220_handle_input(const char *buffer, unsigned int count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) for (i = 0; i < count; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) /* Handle magic sys request */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) if (buffer[i] == ('O' ^ 0100)) { /* CTRL-O */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) * If pressed again, reset sysrq_pressed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) * and flip CTRL-O character
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) sysrq_pressed = !sysrq_pressed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) if (sysrq_pressed)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) } else if (sysrq_pressed) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) sysrq.key = buffer[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) schedule_sysrq_work(&sysrq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) sysrq_pressed = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) tty_insert_flip_char(&sclp_vt220_port, buffer[i], 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) static void sclp_vt220_reset_session(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) static void sclp_vt220_handle_input(const char *buffer, unsigned int count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) tty_insert_flip_string(&sclp_vt220_port, buffer, count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) * Called by the SCLP to report incoming event buffers.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) sclp_vt220_receiver_fn(struct evbuf_header *evbuf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) char *buffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) unsigned int count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) buffer = (char *) ((addr_t) evbuf + sizeof(struct evbuf_header));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) count = evbuf->length - sizeof(struct evbuf_header);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) switch (*buffer) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) case SCLP_VT220_SESSION_ENDED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) case SCLP_VT220_SESSION_STARTED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) sclp_vt220_reset_session();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) case SCLP_VT220_SESSION_DATA:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) /* Send input to line discipline */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) buffer++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) count--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) sclp_vt220_handle_input(buffer, count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) tty_flip_buffer_push(&sclp_vt220_port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) * This routine is called when a particular tty device is opened.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) sclp_vt220_open(struct tty_struct *tty, struct file *filp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) if (tty->count == 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) tty_port_tty_set(&sclp_vt220_port, tty);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) sclp_vt220_port.low_latency = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) if (!tty->winsize.ws_row && !tty->winsize.ws_col) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) tty->winsize.ws_row = 24;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) tty->winsize.ws_col = 80;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) * This routine is called when a particular tty device is closed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) sclp_vt220_close(struct tty_struct *tty, struct file *filp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) if (tty->count == 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) tty_port_tty_set(&sclp_vt220_port, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) * This routine is called by the kernel to write a single
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) * character to the tty device. If the kernel uses this routine,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) * it must call the flush_chars() routine (if defined) when it is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) * done stuffing characters into the driver.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) sclp_vt220_put_char(struct tty_struct *tty, unsigned char ch)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) return __sclp_vt220_write(&ch, 1, 0, 0, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) * This routine is called by the kernel after it has written a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) * series of characters to the tty device using put_char().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) sclp_vt220_flush_chars(struct tty_struct *tty)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) if (!sclp_vt220_queue_running)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) sclp_vt220_emit_current();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) sclp_vt220_flush_later = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) * This routine returns the numbers of characters the tty driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) * will accept for queuing to be written. This number is subject
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) * to change as output buffers get emptied, or if the output flow
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) * control is acted.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) sclp_vt220_write_room(struct tty_struct *tty)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) struct list_head *l;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) int count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) spin_lock_irqsave(&sclp_vt220_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) if (sclp_vt220_current_request != NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) count = sclp_vt220_space_left(sclp_vt220_current_request);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) list_for_each(l, &sclp_vt220_empty)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) count += SCLP_VT220_MAX_CHARS_PER_BUFFER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) spin_unlock_irqrestore(&sclp_vt220_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) * Return number of buffered chars.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) sclp_vt220_chars_in_buffer(struct tty_struct *tty)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) struct list_head *l;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) struct sclp_vt220_request *r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) int count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) spin_lock_irqsave(&sclp_vt220_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) if (sclp_vt220_current_request != NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) count = sclp_vt220_chars_stored(sclp_vt220_current_request);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) list_for_each(l, &sclp_vt220_outqueue) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) r = list_entry(l, struct sclp_vt220_request, list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) count += sclp_vt220_chars_stored(r);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) spin_unlock_irqrestore(&sclp_vt220_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) * Pass on all buffers to the hardware. Return only when there are no more
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) * buffers pending.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) sclp_vt220_flush_buffer(struct tty_struct *tty)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) sclp_vt220_emit_current();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) /* Release allocated pages. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) static void __init __sclp_vt220_free_pages(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) struct list_head *page, *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) list_for_each_safe(page, p, &sclp_vt220_empty) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) list_del(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) free_page((unsigned long) page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) /* Release memory and unregister from sclp core. Controlled by init counting -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) * only the last invoker will actually perform these actions. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) static void __init __sclp_vt220_cleanup(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) sclp_vt220_init_count--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) if (sclp_vt220_init_count != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) sclp_unregister(&sclp_vt220_register);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) __sclp_vt220_free_pages();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) tty_port_destroy(&sclp_vt220_port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) /* Allocate buffer pages and register with sclp core. Controlled by init
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) * counting - only the first invoker will actually perform these actions. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) static int __init __sclp_vt220_init(int num_pages)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) void *page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) sclp_vt220_init_count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) if (sclp_vt220_init_count != 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) spin_lock_init(&sclp_vt220_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) INIT_LIST_HEAD(&sclp_vt220_empty);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) INIT_LIST_HEAD(&sclp_vt220_outqueue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) timer_setup(&sclp_vt220_timer, sclp_vt220_timeout, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) tty_port_init(&sclp_vt220_port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) sclp_vt220_current_request = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) sclp_vt220_buffered_chars = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) sclp_vt220_flush_later = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) /* Allocate pages for output buffering */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) rc = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) for (i = 0; i < num_pages; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) page = (void *) get_zeroed_page(GFP_KERNEL | GFP_DMA);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) if (!page)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) list_add_tail(page, &sclp_vt220_empty);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) rc = sclp_register(&sclp_vt220_register);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) __sclp_vt220_free_pages();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) sclp_vt220_init_count--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) tty_port_destroy(&sclp_vt220_port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) static const struct tty_operations sclp_vt220_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) .open = sclp_vt220_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) .close = sclp_vt220_close,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) .write = sclp_vt220_write,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) .put_char = sclp_vt220_put_char,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) .flush_chars = sclp_vt220_flush_chars,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) .write_room = sclp_vt220_write_room,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) .chars_in_buffer = sclp_vt220_chars_in_buffer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) .flush_buffer = sclp_vt220_flush_buffer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) * Register driver with SCLP and Linux and initialize internal tty structures.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738) static int __init sclp_vt220_tty_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740) struct tty_driver *driver;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743) /* Note: we're not testing for CONSOLE_IS_SCLP here to preserve
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) * symmetry between VM and LPAR systems regarding ttyS1. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) driver = alloc_tty_driver(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) if (!driver)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748) rc = __sclp_vt220_init(MAX_KMEM_PAGES);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) goto out_driver;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752) driver->driver_name = SCLP_VT220_DRIVER_NAME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753) driver->name = SCLP_VT220_DEVICE_NAME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754) driver->major = SCLP_VT220_MAJOR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) driver->minor_start = SCLP_VT220_MINOR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) driver->type = TTY_DRIVER_TYPE_SYSTEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757) driver->subtype = SYSTEM_TYPE_TTY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758) driver->init_termios = tty_std_termios;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759) driver->flags = TTY_DRIVER_REAL_RAW;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760) tty_set_operations(driver, &sclp_vt220_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761) tty_port_link_device(&sclp_vt220_port, driver, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763) rc = tty_register_driver(driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765) goto out_init;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766) rc = sclp_register(&sclp_vt220_register_input);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768) goto out_reg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769) sclp_vt220_driver = driver;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772) out_reg:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773) tty_unregister_driver(driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774) out_init:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775) __sclp_vt220_cleanup();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776) out_driver:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777) put_tty_driver(driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780) __initcall(sclp_vt220_tty_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782) static void __sclp_vt220_flush_buffer(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786) sclp_vt220_emit_current();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787) spin_lock_irqsave(&sclp_vt220_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788) if (timer_pending(&sclp_vt220_timer))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789) del_timer(&sclp_vt220_timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790) while (sclp_vt220_queue_running) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791) spin_unlock_irqrestore(&sclp_vt220_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792) sclp_sync_wait();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793) spin_lock_irqsave(&sclp_vt220_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795) spin_unlock_irqrestore(&sclp_vt220_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799) * Resume console: If there are cached messages, emit them.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801) static void sclp_vt220_resume(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805) spin_lock_irqsave(&sclp_vt220_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 806) sclp_vt220_suspended = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 807) spin_unlock_irqrestore(&sclp_vt220_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 808) sclp_vt220_emit_current();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 809) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 810)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 811) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 812) * Suspend console: Set suspend flag and flush console
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 813) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 814) static void sclp_vt220_suspend(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 815) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 816) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 817)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 818) spin_lock_irqsave(&sclp_vt220_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 819) sclp_vt220_suspended = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 820) spin_unlock_irqrestore(&sclp_vt220_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 821) __sclp_vt220_flush_buffer();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 822) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 823)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 824) static void sclp_vt220_pm_event_fn(struct sclp_register *reg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 825) enum sclp_pm_event sclp_pm_event)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 826) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 827) switch (sclp_pm_event) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 828) case SCLP_PM_EVENT_FREEZE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 829) sclp_vt220_suspend();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 830) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 831) case SCLP_PM_EVENT_RESTORE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 832) case SCLP_PM_EVENT_THAW:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 833) sclp_vt220_resume();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 834) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 835) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 836) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 837)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 838) #ifdef CONFIG_SCLP_VT220_CONSOLE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 839)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 840) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 841) sclp_vt220_con_write(struct console *con, const char *buf, unsigned int count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 842) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 843) __sclp_vt220_write((const unsigned char *) buf, count, 1, 1, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 844) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 845)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 846) static struct tty_driver *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 847) sclp_vt220_con_device(struct console *c, int *index)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 848) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 849) *index = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 850) return sclp_vt220_driver;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 851) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 852)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 853) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 854) sclp_vt220_notify(struct notifier_block *self,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 855) unsigned long event, void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 856) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 857) __sclp_vt220_flush_buffer();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 858) return NOTIFY_OK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 859) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 860)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 861) static struct notifier_block on_panic_nb = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 862) .notifier_call = sclp_vt220_notify,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 863) .priority = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 864) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 865)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 866) static struct notifier_block on_reboot_nb = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 867) .notifier_call = sclp_vt220_notify,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 868) .priority = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 869) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 870)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 871) /* Structure needed to register with printk */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 872) static struct console sclp_vt220_console =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 873) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 874) .name = SCLP_VT220_CONSOLE_NAME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 875) .write = sclp_vt220_con_write,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 876) .device = sclp_vt220_con_device,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 877) .flags = CON_PRINTBUFFER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 878) .index = SCLP_VT220_CONSOLE_INDEX
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 879) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 880)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 881) static int __init
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 882) sclp_vt220_con_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 883) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 884) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 885)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 886) rc = __sclp_vt220_init(sclp_console_pages);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 887) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 888) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 889) /* Attach linux console */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 890) atomic_notifier_chain_register(&panic_notifier_list, &on_panic_nb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 891) register_reboot_notifier(&on_reboot_nb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 892) register_console(&sclp_vt220_console);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 893) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 894) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 895)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 896) console_initcall(sclp_vt220_con_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 897) #endif /* CONFIG_SCLP_VT220_CONSOLE */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 898)