2 * drivers/s390/char/con3215.c
3 * 3215 line mode terminal driver.
6 * Copyright (C) 1999,2000 IBM Deutschland Entwicklung GmbH, IBM Corporation
7 * Author(s): Martin Schwidefsky (schwidefsky@de.ibm.com),
10 * Aug-2000: Added tab support
11 * Dan Morrison, IBM Corporation (dmorriso@cse.buffalo.edu)
14 #include <linux/config.h>
15 #include <linux/types.h>
16 #include <linux/kdev_t.h>
17 #include <linux/tty.h>
18 #include <linux/vt_kern.h>
19 #include <linux/init.h>
20 #include <linux/console.h>
21 #include <linux/interrupt.h>
23 #include <linux/slab.h>
24 #include <linux/bootmem.h>
25 #include <linux/devfs_fs_kernel.h>
28 #include <asm/ebcdic.h>
29 #include <asm/uaccess.h>
30 #include <asm/delay.h>
31 #include <asm/cpcmd.h>
33 #include <asm/setup.h>
38 #define NR_3215_REQ (4*NR_3215)
39 #define RAW3215_BUFFER_SIZE 65536 /* output buffer size */
40 #define RAW3215_INBUF_SIZE 256 /* input buffer size */
41 #define RAW3215_MIN_SPACE 128 /* minimum free space for wakeup */
42 #define RAW3215_MIN_WRITE 1024 /* min. length for immediate output */
43 #define RAW3215_MAX_BYTES 3968 /* max. bytes to write with one ssch */
44 #define RAW3215_MAX_NEWLINE 50 /* max. lines to write with one ssch */
45 #define RAW3215_NR_CCWS 3
46 #define RAW3215_TIMEOUT HZ/10 /* time for delayed output */
48 #define RAW3215_FIXED 1 /* 3215 console device is not be freed */
49 #define RAW3215_ACTIVE 2 /* set if the device is in use */
50 #define RAW3215_WORKING 4 /* set if a request is being worked on */
51 #define RAW3215_THROTTLED 8 /* set if reading is disabled */
52 #define RAW3215_STOPPED 16 /* set if writing is disabled */
53 #define RAW3215_CLOSING 32 /* set while in close process */
54 #define RAW3215_TIMER_RUNS 64 /* set if the output delay timer is on */
55 #define RAW3215_FLUSHING 128 /* set to flush buffer (no delay) */
56 #define RAW3215_BH_PENDING 256 /* indication for bh scheduling */
58 #define TAB_STOP_SIZE 8 /* tab stop size */
60 struct _raw3215_info; /* forward declaration ... */
62 int raw3215_condevice = -1; /* preset console device */
65 * Request types for a 3215 device
68 RAW3215_FREE, RAW3215_READ, RAW3215_WRITE
72 * Request structure for a 3215 device
74 typedef struct _raw3215_req {
75 raw3215_type type; /* type of the request */
76 int start, len; /* start index & len in output buffer */
77 int delayable; /* indication to wait for more data */
78 int residual; /* residual count for read request */
79 ccw1_t ccws[RAW3215_NR_CCWS]; /* space for the channel program */
80 struct _raw3215_info *info; /* pointer to main structure */
81 struct _raw3215_req *next; /* pointer to next request */
82 } raw3215_req __attribute__ ((aligned(8)));
84 typedef struct _raw3215_info {
85 int flags; /* state flags */
86 int irq; /* interrupt number to do_IO */
87 char *buffer; /* pointer to output buffer */
88 char *inbuf; /* pointer to input buffer */
89 int head; /* first free byte in output buffer */
90 int count; /* number of bytes in output buffer */
91 int written; /* number of bytes in write requests */
92 devstat_t devstat; /* device status structure for do_IO */
93 struct tty_struct *tty; /* pointer to tty structure if present */
94 struct tq_struct tqueue; /* task queue to bottom half */
95 raw3215_req *queued_read; /* pointer to queued read requests */
96 raw3215_req *queued_write; /* pointer to queued write requests */
97 wait_queue_head_t empty_wait; /* wait queue for flushing */
98 struct timer_list timer; /* timer for delayed output */
99 char *message; /* pending message from raw3215_irq */
100 int msg_dstat; /* dstat for pending message */
101 int msg_cstat; /* cstat for pending message */
102 int line_pos; /* position on the line (for tabs) */
105 static raw3215_info *raw3215[NR_3215]; /* array of 3215 devices structures */
106 static raw3215_req *raw3215_freelist; /* list of free request structures */
107 static spinlock_t raw3215_freelist_lock;/* spinlock to protect free list */
109 static struct tty_driver tty3215_driver;
110 static struct tty_struct *tty3215_table[NR_3215];
111 static struct termios *tty3215_termios[NR_3215];
112 static struct termios *tty3215_termios_locked[NR_3215];
113 static int tty3215_refcount;
116 #define MIN(a,b) ((a) < (b) ? (a) : (b))
120 * Get a request structure from the free list
122 static inline raw3215_req *raw3215_alloc_req(void) {
126 spin_lock_irqsave(&raw3215_freelist_lock, flags);
127 req = raw3215_freelist;
128 raw3215_freelist = req->next;
129 spin_unlock_irqrestore(&raw3215_freelist_lock, flags);
134 * Put a request structure back to the free list
136 static inline void raw3215_free_req(raw3215_req *req) {
139 if (req->type == RAW3215_FREE)
140 return; /* don't free a free request */
141 req->type = RAW3215_FREE;
142 spin_lock_irqsave(&raw3215_freelist_lock, flags);
143 req->next = raw3215_freelist;
144 raw3215_freelist = req;
145 spin_unlock_irqrestore(&raw3215_freelist_lock, flags);
149 * Set up a read request that reads up to 160 byte from the 3215 device.
150 * If there is a queued read request it is used, but that shouldn't happen
151 * because a 3215 terminal won't accept a new read before the old one is
154 static void raw3215_mk_read_req(raw3215_info *raw)
159 /* there can only be ONE read request at a time */
160 req = raw->queued_read;
162 /* no queued read request, use new req structure */
163 req = raw3215_alloc_req();
164 req->type = RAW3215_READ;
166 raw->queued_read = req;
170 ccw->cmd_code = 0x0A; /* read inquiry */
171 ccw->flags = 0x20; /* ignore incorrect length */
173 ccw->cda = (__u32) __pa(raw->inbuf);
177 * Set up a write request with the information from the main structure.
178 * A ccw chain is created that writes as much as possible from the output
179 * buffer to the 3215 device. If a queued write exists it is replaced by
180 * the new, probably lengthened request.
182 static void raw3215_mk_write_req(raw3215_info *raw)
186 int len, count, ix, lines;
188 if (raw->count <= raw->written)
190 /* check if there is a queued write request */
191 req = raw->queued_write;
193 /* no queued write request, use new req structure */
194 req = raw3215_alloc_req();
195 req->type = RAW3215_WRITE;
197 raw->queued_write = req;
199 raw->written -= req->len;
203 req->start = (raw->head - raw->count + raw->written) &
204 (RAW3215_BUFFER_SIZE - 1);
206 * now we have to count newlines. We can at max accept
207 * RAW3215_MAX_NEWLINE newlines in a single ssch due to
208 * a restriction in VM
212 while (lines < RAW3215_MAX_NEWLINE && ix != raw->head) {
213 if (raw->buffer[ix] == 0x15)
215 ix = (ix + 1) & (RAW3215_BUFFER_SIZE - 1);
217 len = ((ix - 1 - req->start) & (RAW3215_BUFFER_SIZE - 1)) + 1;
218 if (len > RAW3215_MAX_BYTES)
219 len = RAW3215_MAX_BYTES;
223 /* set the indication if we should try to enlarge this request */
224 req->delayable = (ix == raw->head) && (len < RAW3215_MIN_WRITE);
229 ccw[-1].flags |= 0x40; /* use command chaining */
230 ccw->cmd_code = 0x01; /* write, auto carrier return */
231 ccw->flags = 0x20; /* ignore incorrect length ind. */
233 (__u32) __pa(raw->buffer + ix);
235 if (ix + count > RAW3215_BUFFER_SIZE)
236 count = RAW3215_BUFFER_SIZE - ix;
239 ix = (ix + count) & (RAW3215_BUFFER_SIZE - 1);
243 * Add a NOP to the channel program. 3215 devices are purely
244 * emulated and its much better to avoid the channel end
245 * interrupt in this case.
248 ccw[-1].flags |= 0x40; /* use command chaining */
249 ccw->cmd_code = 0x03; /* NOP */
256 * Start a read or a write request
258 static void raw3215_start_io(raw3215_info *raw)
263 req = raw->queued_read;
265 !(raw->flags & (RAW3215_WORKING | RAW3215_THROTTLED))) {
266 /* dequeue request */
267 raw->queued_read = NULL;
268 res = do_IO(raw->irq, req->ccws, (unsigned long) req, 0, 0);
270 /* do_IO failed, put request back to queue */
271 raw->queued_read = req;
273 raw->flags |= RAW3215_WORKING;
276 req = raw->queued_write;
278 !(raw->flags & (RAW3215_WORKING | RAW3215_STOPPED))) {
279 /* dequeue request */
280 raw->queued_write = NULL;
281 res = do_IO(raw->irq, req->ccws, (unsigned long) req, 0, 0);
283 /* do_IO failed, put request back to queue */
284 raw->queued_write = req;
286 raw->flags |= RAW3215_WORKING;
292 * Function to start a delayed output after RAW3215_TIMEOUT seconds
294 static void raw3215_timeout(unsigned long __data)
296 raw3215_info *raw = (raw3215_info *) __data;
299 s390irq_spin_lock_irqsave(raw->irq, flags);
300 if (raw->flags & RAW3215_TIMER_RUNS) {
301 del_timer(&raw->timer);
302 raw->flags &= ~RAW3215_TIMER_RUNS;
303 raw3215_mk_write_req(raw);
304 raw3215_start_io(raw);
306 s390irq_spin_unlock_irqrestore(raw->irq, flags);
310 * Function to conditionally start an IO. A read is started immediatly,
311 * a write is only started immediatly if the flush flag is on or the
312 * amount of data is bigger than RAW3215_MIN_WRITE. If a write is not
313 * done immediatly a timer is started with a delay of RAW3215_TIMEOUT.
315 static inline void raw3215_try_io(raw3215_info *raw)
317 if (!(raw->flags & RAW3215_ACTIVE))
319 if (raw->queued_read != NULL)
320 raw3215_start_io(raw);
321 else if (raw->queued_write != NULL) {
322 if ((raw->queued_write->delayable == 0) ||
323 (raw->flags & RAW3215_FLUSHING)) {
324 /* execute write requests bigger than minimum size */
325 raw3215_start_io(raw);
326 if (raw->flags & RAW3215_TIMER_RUNS) {
327 del_timer(&raw->timer);
328 raw->flags &= ~RAW3215_TIMER_RUNS;
330 } else if (!(raw->flags & RAW3215_TIMER_RUNS)) {
331 /* delay small writes */
332 init_timer(&raw->timer);
333 raw->timer.expires = RAW3215_TIMEOUT + jiffies;
334 raw->timer.data = (unsigned long) raw;
335 raw->timer.function = raw3215_timeout;
336 add_timer(&raw->timer);
337 raw->flags |= RAW3215_TIMER_RUNS;
343 * The bottom half handler routine for 3215 devices. It tries to start
344 * the next IO and wakes up processes waiting on the tty.
346 static void raw3215_softint(void *data)
349 struct tty_struct *tty;
352 raw = (raw3215_info *) data;
353 s390irq_spin_lock_irqsave(raw->irq, flags);
354 raw3215_mk_write_req(raw);
356 raw->flags &= ~RAW3215_BH_PENDING;
357 s390irq_spin_unlock_irqrestore(raw->irq, flags);
358 /* Check for pending message from raw3215_irq */
359 if (raw->message != NULL) {
360 printk(raw->message, raw->irq, raw->msg_dstat, raw->msg_cstat);
365 RAW3215_BUFFER_SIZE - raw->count >= RAW3215_MIN_SPACE) {
371 * Function to safely add raw3215_softint to tq_immediate.
372 * The s390irq spinlock must be held.
374 static inline void raw3215_sched_bh(raw3215_info *raw)
376 if (raw->flags & RAW3215_BH_PENDING)
377 return; /* already pending */
378 raw->flags |= RAW3215_BH_PENDING;
379 INIT_LIST_HEAD(&raw->tqueue.list);
380 raw->tqueue.sync = 0;
381 raw->tqueue.routine = raw3215_softint;
382 raw->tqueue.data = raw;
383 queue_task(&raw->tqueue, &tq_immediate);
384 mark_bh(IMMEDIATE_BH);
388 * Find the raw3215_info structure associated with irq
390 static inline raw3215_info *raw3215_find_info(int irq) {
394 for (i = 0; i < NR_3215; i++) {
396 if (raw != NULL && raw->irq == irq &&
397 (raw->flags & RAW3215_ACTIVE))
400 return (i >= NR_3215) ? NULL : raw;
404 * Interrupt routine, called from Ingo's I/O layer
406 static void raw3215_irq(int irq, void *int_parm, struct pt_regs *regs)
410 struct tty_struct *tty;
415 stat = (devstat_t *) int_parm;
416 req = (raw3215_req *) stat->intparm;
420 raw = raw3215_find_info(irq);
422 raw->message = KERN_WARNING
423 "Got nonzero channel status in raw3215_irq "
424 "(dev %i, dev sts 0x%2x, sch sts 0x%2x)";
425 raw->msg_dstat = dstat;
426 raw->msg_cstat = cstat;
427 raw3215_sched_bh(raw);
430 if (dstat & 0x01) { /* we got a unit exception */
431 dstat &= ~0x01; /* we can ignore it */
437 /* Attention interrupt, someone hit the enter key */
438 if ((raw = raw3215_find_info(irq)) == NULL)
439 return; /* That shouldn't happen ... */
440 /* Setup a read request */
441 raw3215_mk_read_req(raw);
443 memset(raw->inbuf, 0, RAW3215_INBUF_SIZE);
444 raw3215_sched_bh(raw);
448 /* Channel end interrupt. */
449 if ((raw = req->info) == NULL)
450 return; /* That shouldn't happen ... */
451 if (req->type == RAW3215_READ) {
452 /* store residual count, then wait for device end */
453 req->residual = stat->rescnt;
458 /* Device end interrupt. */
459 if ((raw = req->info) == NULL)
460 return; /* That shouldn't happen ... */
461 if (req->type == RAW3215_READ && raw->tty != NULL) {
465 count = 160 - req->residual;
466 if (MACHINE_IS_P390) {
467 slen = strnlen(raw->inbuf, RAW3215_INBUF_SIZE);
471 if (count >= TTY_FLIPBUF_SIZE - tty->flip.count)
472 count = TTY_FLIPBUF_SIZE - tty->flip.count - 1;
473 EBCASC(raw->inbuf, count);
474 cchar = ctrlchar_handle(raw->inbuf, count, tty);
475 switch (cchar & CTRLCHAR_MASK) {
481 *tty->flip.flag_buf_ptr++ = TTY_NORMAL;
482 *tty->flip.char_buf_ptr++ = cchar;
483 tty_flip_buffer_push(raw->tty);
487 memcpy(tty->flip.char_buf_ptr,
490 (strncmp(raw->inbuf+count-2, "^n", 2) &&
491 strncmp(raw->inbuf+count-2, "\252n", 2)) ) {
492 /* don't add the auto \n */
493 tty->flip.char_buf_ptr[count] = '\n';
494 memset(tty->flip.flag_buf_ptr,
495 TTY_NORMAL, count + 1);
499 tty->flip.char_buf_ptr += count;
500 tty->flip.flag_buf_ptr += count;
501 tty->flip.count += count;
502 tty_flip_buffer_push(raw->tty);
505 } else if (req->type == RAW3215_WRITE) {
506 raw->count -= req->len;
507 raw->written -= req->len;
509 raw->flags &= ~RAW3215_WORKING;
510 raw3215_free_req(req);
511 /* check for empty wait */
512 if (waitqueue_active(&raw->empty_wait) &&
513 raw->queued_write == NULL &&
514 raw->queued_read == NULL) {
515 wake_up_interruptible(&raw->empty_wait);
517 raw3215_sched_bh(raw);
520 /* Strange interrupt, I'll do my best to clean up */
521 if ((raw = raw3215_find_info(irq)) == NULL)
522 return; /* That shouldn't happen ... */
523 if (raw == NULL) break;
524 if (req != NULL && req->type != RAW3215_FREE) {
525 if (req->type == RAW3215_WRITE) {
526 raw->count -= req->len;
527 raw->written -= req->len;
529 raw->flags &= ~RAW3215_WORKING;
530 raw3215_free_req(req);
532 raw->message = KERN_WARNING
533 "Spurious interrupt in in raw3215_irq "
534 "(dev %i, dev sts 0x%2x, sch sts 0x%2x)";
535 raw->msg_dstat = dstat;
536 raw->msg_cstat = cstat;
537 raw3215_sched_bh(raw);
543 * Wait until length bytes are available int the output buffer.
544 * Has to be called with the s390irq lock held. Can be called
547 void raw3215_make_room(raw3215_info *raw, unsigned int length)
549 while (RAW3215_BUFFER_SIZE - raw->count < length) {
550 /* there might be a request pending */
551 raw->flags |= RAW3215_FLUSHING;
552 raw3215_mk_write_req(raw);
554 raw->flags &= ~RAW3215_FLUSHING;
555 if (wait_cons_dev(raw->irq) != 0) {
556 /* that shouldn't happen */
560 /* Enough room freed up ? */
561 if (RAW3215_BUFFER_SIZE - raw->count >= length)
563 /* there might be another cpu waiting for the lock */
564 s390irq_spin_unlock(raw->irq);
566 s390irq_spin_lock(raw->irq);
571 * String write routine for 3215 devices
574 raw3215_write(raw3215_info *raw, const char *str,
575 int from_user, unsigned int length)
583 s390irq_spin_lock_irqsave(raw->irq, flags);
584 count = (length > RAW3215_BUFFER_SIZE) ?
585 RAW3215_BUFFER_SIZE : length;
588 raw3215_make_room(raw, count);
590 /* copy string to output buffer and convert it to EBCDIC */
594 MIN(RAW3215_BUFFER_SIZE - raw->count,
595 RAW3215_BUFFER_SIZE - raw->head));
598 c -= copy_from_user(raw->buffer + raw->head,
605 ASCEBC(raw->buffer + raw->head, c);
606 raw->head = (raw->head + c) &
607 (RAW3215_BUFFER_SIZE - 1);
617 MIN(RAW3215_BUFFER_SIZE - raw->count,
618 RAW3215_BUFFER_SIZE - raw->head));
621 memcpy(raw->buffer + raw->head, str, c);
622 ASCEBC(raw->buffer + raw->head, c);
623 raw->head = (raw->head + c) &
624 (RAW3215_BUFFER_SIZE - 1);
632 if (!(raw->flags & RAW3215_WORKING)) {
633 raw3215_mk_write_req(raw);
634 /* start or queue request */
637 s390irq_spin_unlock_irqrestore(raw->irq, flags);
644 * Put character routine for 3215 devices
647 static void raw3215_putchar(raw3215_info *raw, unsigned char ch)
650 unsigned int length, i;
652 s390irq_spin_lock_irqsave(raw->irq, flags);
654 length = TAB_STOP_SIZE - (raw->line_pos%TAB_STOP_SIZE);
655 raw->line_pos += length;
657 } else if (ch == '\n') {
664 raw3215_make_room(raw, length);
666 for (i = 0; i < length; i++) {
667 raw->buffer[raw->head] = (char) _ascebc[(int) ch];
668 raw->head = (raw->head + 1) & (RAW3215_BUFFER_SIZE - 1);
671 if (!(raw->flags & RAW3215_WORKING)) {
672 raw3215_mk_write_req(raw);
673 /* start or queue request */
676 s390irq_spin_unlock_irqrestore(raw->irq, flags);
680 * Flush routine, it simply sets the flush flag and tries to start
683 static void raw3215_flush_buffer(raw3215_info *raw)
687 s390irq_spin_lock_irqsave(raw->irq, flags);
688 if (raw->count > 0) {
689 raw->flags |= RAW3215_FLUSHING;
691 raw->flags &= ~RAW3215_FLUSHING;
693 s390irq_spin_unlock_irqrestore(raw->irq, flags);
697 * Fire up a 3215 device.
699 static int raw3215_startup(raw3215_info *raw)
703 if (raw->flags & RAW3215_ACTIVE)
705 if (request_irq(raw->irq, raw3215_irq, SA_INTERRUPT,
706 "3215 terminal driver", &raw->devstat) != 0)
709 raw->flags |= RAW3215_ACTIVE;
710 s390irq_spin_lock_irqsave(raw->irq, flags);
711 set_cons_dev(raw->irq);
713 s390irq_spin_unlock_irqrestore(raw->irq, flags);
719 * Shutdown a 3215 device.
721 static void raw3215_shutdown(raw3215_info *raw)
723 DECLARE_WAITQUEUE(wait, current);
726 if (!(raw->flags & RAW3215_ACTIVE) || (raw->flags & RAW3215_FIXED))
728 /* Wait for outstanding requests, then free irq */
729 s390irq_spin_lock_irqsave(raw->irq, flags);
730 if ((raw->flags & RAW3215_WORKING) ||
731 raw->queued_write != NULL ||
732 raw->queued_read != NULL) {
733 raw->flags |= RAW3215_CLOSING;
734 add_wait_queue(&raw->empty_wait, &wait);
735 current->state = TASK_INTERRUPTIBLE;
736 s390irq_spin_unlock_irqrestore(raw->irq, flags);
738 s390irq_spin_lock_irqsave(raw->irq, flags);
739 remove_wait_queue(&raw->empty_wait, &wait);
740 current->state = TASK_RUNNING;
741 raw->flags &= ~(RAW3215_ACTIVE | RAW3215_CLOSING);
743 free_irq(raw->irq, NULL);
744 s390irq_spin_unlock_irqrestore(raw->irq, flags);
748 raw3215_find_dev(int number)
750 s390_dev_info_t dinfo;
754 irq = get_irq_first();
756 while (count <= number && irq != -ENODEV) {
757 if (get_dev_info(irq, &dinfo) == -ENODEV)
759 if (dinfo.devno == console_device ||
760 dinfo.sid_data.cu_type == 0x3215) {
765 irq = get_irq_next(irq);
767 return -1; /* console not found */
770 #ifdef CONFIG_TN3215_CONSOLE
773 * Write a string to the 3215 console
776 con3215_write(struct console *co, const char *str, unsigned int count)
783 raw = raw3215[0]; /* console 3215 is the first one */
785 for (i = 0; i < count; i++)
786 if (str[i] == '\t' || str[i] == '\n')
788 raw3215_write(raw, str, 0, i);
792 raw3215_putchar(raw, *str);
799 kdev_t con3215_device(struct console *c)
801 return MKDEV(TTY_MAJOR, c->index + 64 );
805 * panic() calls console_unblank before the system enters a
806 * disabled, endless loop.
808 void con3215_unblank(void)
813 raw = raw3215[0]; /* console 3215 is the first one */
814 s390irq_spin_lock_irqsave(raw->irq, flags);
815 raw3215_make_room(raw, RAW3215_BUFFER_SIZE);
816 s390irq_spin_unlock_irqrestore(raw->irq, flags);
819 static int __init con3215_consetup(struct console *co, char *options)
825 * The console structure for the 3215 console
827 static struct console con3215 = {
830 write: con3215_write,
831 device: con3215_device,
832 unblank: con3215_unblank,
833 setup: con3215_consetup,
834 flags: CON_PRINTBUFFER,
842 * This routine is called whenever a 3215 tty is opened.
844 static int tty3215_open(struct tty_struct *tty, struct file * filp)
849 line = MINOR(tty->device) - tty->driver.minor_start;
850 if ((line < 0) || (line >= NR_3215))
855 raw = kmalloc(sizeof(raw3215_info) +
856 RAW3215_INBUF_SIZE, GFP_KERNEL|GFP_DMA);
859 raw->irq = raw3215_find_dev(line);
860 if (raw->irq == -1) {
864 raw->inbuf = (char *) raw + sizeof(raw3215_info);
865 memset(raw, 0, sizeof(raw3215_info));
866 raw->buffer = (char *) kmalloc(RAW3215_BUFFER_SIZE,
868 if (raw->buffer == NULL) {
872 raw->tqueue.routine = raw3215_softint;
873 raw->tqueue.data = raw;
874 init_waitqueue_head(&raw->empty_wait);
878 tty->driver_data = raw;
881 tty->low_latency = 0; /* don't use bottom half for pushing chars */
883 * Start up 3215 device
885 retval = raw3215_startup(raw);
895 * This routine is called when the 3215 tty is closed. We wait
896 * for the remaining request to be completed. Then we clean up.
898 static void tty3215_close(struct tty_struct *tty, struct file * filp)
902 raw = (raw3215_info *) tty->driver_data;
903 if (raw == NULL || tty->count > 1)
906 /* Shutdown the terminal */
907 raw3215_shutdown(raw);
913 * Returns the amount of free space in the output buffer.
915 static int tty3215_write_room(struct tty_struct *tty)
919 raw = (raw3215_info *) tty->driver_data;
921 /* Subtract TAB_STOP_SIZE to allow for a tab, 8 <<< 64K */
922 if ((RAW3215_BUFFER_SIZE - raw->count - TAB_STOP_SIZE) >= 0)
923 return RAW3215_BUFFER_SIZE - raw->count - TAB_STOP_SIZE;
929 * String write routine for 3215 ttys
931 static int tty3215_write(struct tty_struct * tty, int from_user,
932 const unsigned char *buf, int count)
939 raw = (raw3215_info *) tty->driver_data;
940 ret = raw3215_write(raw, buf, from_user, count);
945 * Put character routine for 3215 ttys
947 static void tty3215_put_char(struct tty_struct *tty, unsigned char ch)
953 raw = (raw3215_info *) tty->driver_data;
954 raw3215_putchar(raw, ch);
957 static void tty3215_flush_chars(struct tty_struct *tty)
962 * Returns the number of characters in the output buffer
964 static int tty3215_chars_in_buffer(struct tty_struct *tty)
968 raw = (raw3215_info *) tty->driver_data;
972 static void tty3215_flush_buffer(struct tty_struct *tty)
976 raw = (raw3215_info *) tty->driver_data;
977 raw3215_flush_buffer(raw);
982 * Currently we don't have any io controls for 3215 ttys
984 static int tty3215_ioctl(struct tty_struct *tty, struct file * file,
985 unsigned int cmd, unsigned long arg)
987 if (tty->flags & (1 << TTY_IO_ERROR))
998 * Disable reading from a 3215 tty
1000 static void tty3215_throttle(struct tty_struct * tty)
1004 raw = (raw3215_info *) tty->driver_data;
1005 raw->flags |= RAW3215_THROTTLED;
1009 * Enable reading from a 3215 tty
1011 static void tty3215_unthrottle(struct tty_struct * tty)
1014 unsigned long flags;
1016 raw = (raw3215_info *) tty->driver_data;
1017 if (raw->flags & RAW3215_THROTTLED) {
1018 s390irq_spin_lock_irqsave(raw->irq, flags);
1019 raw->flags &= ~RAW3215_THROTTLED;
1020 raw3215_try_io(raw);
1021 s390irq_spin_unlock_irqrestore(raw->irq, flags);
1026 * Disable writing to a 3215 tty
1028 static void tty3215_stop(struct tty_struct *tty)
1032 raw = (raw3215_info *) tty->driver_data;
1033 raw->flags |= RAW3215_STOPPED;
1037 * Enable writing to a 3215 tty
1039 static void tty3215_start(struct tty_struct *tty)
1042 unsigned long flags;
1044 raw = (raw3215_info *) tty->driver_data;
1045 if (raw->flags & RAW3215_STOPPED) {
1046 s390irq_spin_lock_irqsave(raw->irq, flags);
1047 raw->flags &= ~RAW3215_STOPPED;
1048 raw3215_try_io(raw);
1049 s390irq_spin_unlock_irqrestore(raw->irq, flags);
1055 * 3215 console initialization code called from console_init().
1056 * NOTE: This is called before kmalloc is available.
1058 void __init con3215_init(void)
1065 /* Check if 3215 is to be the console */
1066 if (!CONSOLE_IS_3215)
1068 irq = raw3215_find_dev(0);
1070 /* Set the console mode for VM */
1071 if (MACHINE_IS_VM) {
1072 cpcmd("TERM CONMODE 3215", NULL, 0);
1073 cpcmd("TERM AUTOCR OFF", NULL, 0);
1076 /* allocate 3215 request structures */
1077 raw3215_freelist = NULL;
1078 spin_lock_init(&raw3215_freelist_lock);
1079 for (i = 0; i < NR_3215_REQ; i++) {
1080 req = (raw3215_req *) alloc_bootmem_low(sizeof(raw3215_req));
1081 req->next = raw3215_freelist;
1082 raw3215_freelist = req;
1087 #ifdef CONFIG_TN3215_CONSOLE
1088 raw3215[0] = raw = (raw3215_info *)
1089 alloc_bootmem_low(sizeof(raw3215_info));
1090 memset(raw, 0, sizeof(raw3215_info));
1091 raw->buffer = (char *) alloc_bootmem_low(RAW3215_BUFFER_SIZE);
1092 raw->inbuf = (char *) alloc_bootmem_low(RAW3215_INBUF_SIZE);
1094 /* Find the first console */
1095 raw->irq = raw3215_find_dev(0);
1096 raw->flags |= RAW3215_FIXED;
1097 raw->tqueue.routine = raw3215_softint;
1098 raw->tqueue.data = raw;
1099 init_waitqueue_head(&raw->empty_wait);
1101 /* Request the console irq */
1102 if ( raw3215_startup(raw) != 0 )
1105 if (raw->irq != -1) {
1106 register_console(&con3215);
1108 free_bootmem((unsigned long) raw->inbuf, RAW3215_INBUF_SIZE);
1109 free_bootmem((unsigned long) raw->buffer, RAW3215_BUFFER_SIZE);
1110 free_bootmem((unsigned long) raw, sizeof(raw3215_info));
1112 printk("Couldn't find a 3215 console device\n");
1118 * 3215 tty registration code called from tty_init().
1119 * Most kernel services (incl. kmalloc) are available at this poimt.
1121 void __init tty3215_init(void)
1123 /* Don't bother registering the tty if we already skipped the console */
1124 if (!CONSOLE_IS_3215)
1127 * Initialize the tty_driver structure
1128 * Entries in tty3215_driver that are NOT initialized:
1129 * proc_entry, set_termios, flush_buffer, set_ldisc, write_proc
1132 memset(&tty3215_driver, 0, sizeof(struct tty_driver));
1133 tty3215_driver.magic = TTY_DRIVER_MAGIC;
1134 tty3215_driver.driver_name = "tty3215";
1135 tty3215_driver.name = "ttyS";
1136 tty3215_driver.name_base = 0;
1137 tty3215_driver.major = TTY_MAJOR;
1138 tty3215_driver.minor_start = 64;
1139 tty3215_driver.num = NR_3215;
1140 tty3215_driver.type = TTY_DRIVER_TYPE_SYSTEM;
1141 tty3215_driver.subtype = SYSTEM_TYPE_TTY;
1142 tty3215_driver.init_termios = tty_std_termios;
1143 tty3215_driver.init_termios.c_iflag = IGNBRK | IGNPAR;
1144 tty3215_driver.init_termios.c_oflag = ONLCR | XTABS;
1145 tty3215_driver.init_termios.c_lflag = ISIG;
1146 tty3215_driver.flags = TTY_DRIVER_REAL_RAW;
1147 tty3215_driver.refcount = &tty3215_refcount;
1148 tty3215_driver.table = tty3215_table;
1149 tty3215_driver.termios = tty3215_termios;
1150 tty3215_driver.termios_locked = tty3215_termios_locked;
1152 tty3215_driver.open = tty3215_open;
1153 tty3215_driver.close = tty3215_close;
1154 tty3215_driver.write = tty3215_write;
1155 tty3215_driver.put_char = tty3215_put_char;
1156 tty3215_driver.flush_chars = tty3215_flush_chars;
1157 tty3215_driver.write_room = tty3215_write_room;
1158 tty3215_driver.chars_in_buffer = tty3215_chars_in_buffer;
1159 tty3215_driver.flush_buffer = tty3215_flush_buffer;
1160 tty3215_driver.ioctl = tty3215_ioctl;
1161 tty3215_driver.throttle = tty3215_throttle;
1162 tty3215_driver.unthrottle = tty3215_unthrottle;
1163 tty3215_driver.send_xchar = NULL;
1164 tty3215_driver.set_termios = NULL;
1165 tty3215_driver.stop = tty3215_stop;
1166 tty3215_driver.start = tty3215_start;
1167 tty3215_driver.hangup = NULL;
1168 tty3215_driver.break_ctl = NULL;
1169 tty3215_driver.wait_until_sent = NULL;
1170 tty3215_driver.read_proc = NULL;
1172 if (tty_register_driver(&tty3215_driver))
1173 panic("Couldn't register tty3215 driver\n");