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/module.h>
15 #include <linux/types.h>
16 #include <linux/kdev_t.h>
17 #include <linux/tty.h>
18 #include <linux/tty_flip.h>
19 #include <linux/vt_kern.h>
20 #include <linux/init.h>
21 #include <linux/console.h>
22 #include <linux/interrupt.h>
23 #include <linux/err.h>
25 #include <linux/slab.h>
26 #include <linux/bootmem.h>
28 #include <asm/ccwdev.h>
31 #include <asm/ebcdic.h>
32 #include <asm/uaccess.h>
33 #include <asm/delay.h>
34 #include <asm/cpcmd.h>
35 #include <asm/setup.h>
40 #define NR_3215_REQ (4*NR_3215)
41 #define RAW3215_BUFFER_SIZE 65536 /* output buffer size */
42 #define RAW3215_INBUF_SIZE 256 /* input buffer size */
43 #define RAW3215_MIN_SPACE 128 /* minimum free space for wakeup */
44 #define RAW3215_MIN_WRITE 1024 /* min. length for immediate output */
45 #define RAW3215_MAX_BYTES 3968 /* max. bytes to write with one ssch */
46 #define RAW3215_MAX_NEWLINE 50 /* max. lines to write with one ssch */
47 #define RAW3215_NR_CCWS 3
48 #define RAW3215_TIMEOUT HZ/10 /* time for delayed output */
50 #define RAW3215_FIXED 1 /* 3215 console device is not be freed */
51 #define RAW3215_ACTIVE 2 /* set if the device is in use */
52 #define RAW3215_WORKING 4 /* set if a request is being worked on */
53 #define RAW3215_THROTTLED 8 /* set if reading is disabled */
54 #define RAW3215_STOPPED 16 /* set if writing is disabled */
55 #define RAW3215_CLOSING 32 /* set while in close process */
56 #define RAW3215_TIMER_RUNS 64 /* set if the output delay timer is on */
57 #define RAW3215_FLUSHING 128 /* set to flush buffer (no delay) */
59 #define TAB_STOP_SIZE 8 /* tab stop size */
62 * Request types for a 3215 device
65 RAW3215_FREE
, RAW3215_READ
, RAW3215_WRITE
69 * Request structure for a 3215 device
72 enum raw3215_type type
; /* type of the request */
73 int start
, len
; /* start index & len in output buffer */
74 int delayable
; /* indication to wait for more data */
75 int residual
; /* residual count for read request */
76 struct ccw1 ccws
[RAW3215_NR_CCWS
]; /* space for the channel program */
77 struct raw3215_info
*info
; /* pointer to main structure */
78 struct raw3215_req
*next
; /* pointer to next request */
79 } __attribute__ ((aligned(8)));
82 struct ccw_device
*cdev
; /* device for tty driver */
83 spinlock_t
*lock
; /* pointer to irq lock */
84 int flags
; /* state flags */
85 char *buffer
; /* pointer to output buffer */
86 char *inbuf
; /* pointer to input buffer */
87 int head
; /* first free byte in output buffer */
88 int count
; /* number of bytes in output buffer */
89 int written
; /* number of bytes in write requests */
90 struct tty_struct
*tty
; /* pointer to tty structure if present */
91 struct tasklet_struct tasklet
;
92 struct raw3215_req
*queued_read
; /* pointer to queued read requests */
93 struct raw3215_req
*queued_write
;/* pointer to queued write requests */
94 wait_queue_head_t empty_wait
; /* wait queue for flushing */
95 struct timer_list timer
; /* timer for delayed output */
96 char *message
; /* pending message from raw3215_irq */
97 int msg_dstat
; /* dstat for pending message */
98 int msg_cstat
; /* cstat for pending message */
99 int line_pos
; /* position on the line (for tabs) */
100 char ubuffer
[80]; /* copy_from_user buffer */
103 /* array of 3215 devices structures */
104 static struct raw3215_info
*raw3215
[NR_3215
];
105 /* spinlock to protect the raw3215 array */
106 static DEFINE_SPINLOCK(raw3215_device_lock
);
107 /* list of free request structures */
108 static struct raw3215_req
*raw3215_freelist
;
109 /* spinlock to protect free list */
110 static spinlock_t raw3215_freelist_lock
;
112 static struct tty_driver
*tty3215_driver
;
115 * Get a request structure from the free list
117 static inline struct raw3215_req
*
118 raw3215_alloc_req(void) {
119 struct raw3215_req
*req
;
122 spin_lock_irqsave(&raw3215_freelist_lock
, flags
);
123 req
= raw3215_freelist
;
124 raw3215_freelist
= req
->next
;
125 spin_unlock_irqrestore(&raw3215_freelist_lock
, flags
);
130 * Put a request structure back to the free list
133 raw3215_free_req(struct raw3215_req
*req
) {
136 if (req
->type
== RAW3215_FREE
)
137 return; /* don't free a free request */
138 req
->type
= RAW3215_FREE
;
139 spin_lock_irqsave(&raw3215_freelist_lock
, flags
);
140 req
->next
= raw3215_freelist
;
141 raw3215_freelist
= req
;
142 spin_unlock_irqrestore(&raw3215_freelist_lock
, flags
);
146 * Set up a read request that reads up to 160 byte from the 3215 device.
147 * If there is a queued read request it is used, but that shouldn't happen
148 * because a 3215 terminal won't accept a new read before the old one is
152 raw3215_mk_read_req(struct raw3215_info
*raw
)
154 struct raw3215_req
*req
;
157 /* there can only be ONE read request at a time */
158 req
= raw
->queued_read
;
160 /* no queued read request, use new req structure */
161 req
= raw3215_alloc_req();
162 req
->type
= RAW3215_READ
;
164 raw
->queued_read
= req
;
168 ccw
->cmd_code
= 0x0A; /* read inquiry */
169 ccw
->flags
= 0x20; /* ignore incorrect length */
171 ccw
->cda
= (__u32
) __pa(raw
->inbuf
);
175 * Set up a write request with the information from the main structure.
176 * A ccw chain is created that writes as much as possible from the output
177 * buffer to the 3215 device. If a queued write exists it is replaced by
178 * the new, probably lengthened request.
181 raw3215_mk_write_req(struct raw3215_info
*raw
)
183 struct raw3215_req
*req
;
185 int len
, count
, ix
, lines
;
187 if (raw
->count
<= raw
->written
)
189 /* check if there is a queued write request */
190 req
= raw
->queued_write
;
192 /* no queued write request, use new req structure */
193 req
= raw3215_alloc_req();
194 req
->type
= RAW3215_WRITE
;
196 raw
->queued_write
= req
;
198 raw
->written
-= req
->len
;
202 req
->start
= (raw
->head
- raw
->count
+ raw
->written
) &
203 (RAW3215_BUFFER_SIZE
- 1);
205 * now we have to count newlines. We can at max accept
206 * RAW3215_MAX_NEWLINE newlines in a single ssch due to
207 * a restriction in VM
211 while (lines
< RAW3215_MAX_NEWLINE
&& ix
!= raw
->head
) {
212 if (raw
->buffer
[ix
] == 0x15)
214 ix
= (ix
+ 1) & (RAW3215_BUFFER_SIZE
- 1);
216 len
= ((ix
- 1 - req
->start
) & (RAW3215_BUFFER_SIZE
- 1)) + 1;
217 if (len
> RAW3215_MAX_BYTES
)
218 len
= RAW3215_MAX_BYTES
;
222 /* set the indication if we should try to enlarge this request */
223 req
->delayable
= (ix
== raw
->head
) && (len
< RAW3215_MIN_WRITE
);
228 ccw
[-1].flags
|= 0x40; /* use command chaining */
229 ccw
->cmd_code
= 0x01; /* write, auto carrier return */
230 ccw
->flags
= 0x20; /* ignore incorrect length ind. */
232 (__u32
) __pa(raw
->buffer
+ ix
);
234 if (ix
+ count
> RAW3215_BUFFER_SIZE
)
235 count
= RAW3215_BUFFER_SIZE
- ix
;
238 ix
= (ix
+ count
) & (RAW3215_BUFFER_SIZE
- 1);
242 * Add a NOP to the channel program. 3215 devices are purely
243 * emulated and its much better to avoid the channel end
244 * interrupt in this case.
247 ccw
[-1].flags
|= 0x40; /* use command chaining */
248 ccw
->cmd_code
= 0x03; /* NOP */
255 * Start a read or a write request
258 raw3215_start_io(struct raw3215_info
*raw
)
260 struct raw3215_req
*req
;
263 req
= raw
->queued_read
;
265 !(raw
->flags
& (RAW3215_WORKING
| RAW3215_THROTTLED
))) {
266 /* dequeue request */
267 raw
->queued_read
= NULL
;
268 res
= ccw_device_start(raw
->cdev
, req
->ccws
,
269 (unsigned long) req
, 0, 0);
271 /* do_IO failed, put request back to queue */
272 raw
->queued_read
= req
;
274 raw
->flags
|= RAW3215_WORKING
;
277 req
= raw
->queued_write
;
279 !(raw
->flags
& (RAW3215_WORKING
| RAW3215_STOPPED
))) {
280 /* dequeue request */
281 raw
->queued_write
= NULL
;
282 res
= ccw_device_start(raw
->cdev
, req
->ccws
,
283 (unsigned long) req
, 0, 0);
285 /* do_IO failed, put request back to queue */
286 raw
->queued_write
= req
;
288 raw
->flags
|= RAW3215_WORKING
;
294 * Function to start a delayed output after RAW3215_TIMEOUT seconds
297 raw3215_timeout(unsigned long __data
)
299 struct raw3215_info
*raw
= (struct raw3215_info
*) __data
;
302 spin_lock_irqsave(get_ccwdev_lock(raw
->cdev
), flags
);
303 if (raw
->flags
& RAW3215_TIMER_RUNS
) {
304 del_timer(&raw
->timer
);
305 raw
->flags
&= ~RAW3215_TIMER_RUNS
;
306 raw3215_mk_write_req(raw
);
307 raw3215_start_io(raw
);
309 spin_unlock_irqrestore(get_ccwdev_lock(raw
->cdev
), flags
);
313 * Function to conditionally start an IO. A read is started immediately,
314 * a write is only started immediately if the flush flag is on or the
315 * amount of data is bigger than RAW3215_MIN_WRITE. If a write is not
316 * done immediately a timer is started with a delay of RAW3215_TIMEOUT.
319 raw3215_try_io(struct raw3215_info
*raw
)
321 if (!(raw
->flags
& RAW3215_ACTIVE
))
323 if (raw
->queued_read
!= NULL
)
324 raw3215_start_io(raw
);
325 else if (raw
->queued_write
!= NULL
) {
326 if ((raw
->queued_write
->delayable
== 0) ||
327 (raw
->flags
& RAW3215_FLUSHING
)) {
328 /* execute write requests bigger than minimum size */
329 raw3215_start_io(raw
);
330 if (raw
->flags
& RAW3215_TIMER_RUNS
) {
331 del_timer(&raw
->timer
);
332 raw
->flags
&= ~RAW3215_TIMER_RUNS
;
334 } else if (!(raw
->flags
& RAW3215_TIMER_RUNS
)) {
335 /* delay small writes */
336 init_timer(&raw
->timer
);
337 raw
->timer
.expires
= RAW3215_TIMEOUT
+ jiffies
;
338 raw
->timer
.data
= (unsigned long) raw
;
339 raw
->timer
.function
= raw3215_timeout
;
340 add_timer(&raw
->timer
);
341 raw
->flags
|= RAW3215_TIMER_RUNS
;
347 * The bottom half handler routine for 3215 devices. It tries to start
348 * the next IO and wakes up processes waiting on the tty.
351 raw3215_tasklet(void *data
)
353 struct raw3215_info
*raw
;
354 struct tty_struct
*tty
;
357 raw
= (struct raw3215_info
*) data
;
358 spin_lock_irqsave(get_ccwdev_lock(raw
->cdev
), flags
);
359 raw3215_mk_write_req(raw
);
361 spin_unlock_irqrestore(get_ccwdev_lock(raw
->cdev
), flags
);
362 /* Check for pending message from raw3215_irq */
363 if (raw
->message
!= NULL
) {
364 printk(raw
->message
, raw
->msg_dstat
, raw
->msg_cstat
);
369 RAW3215_BUFFER_SIZE
- raw
->count
>= RAW3215_MIN_SPACE
) {
375 * Interrupt routine, called from common io layer
378 raw3215_irq(struct ccw_device
*cdev
, unsigned long intparm
, struct irb
*irb
)
380 struct raw3215_info
*raw
;
381 struct raw3215_req
*req
;
382 struct tty_struct
*tty
;
386 raw
= cdev
->dev
.driver_data
;
387 req
= (struct raw3215_req
*) intparm
;
388 cstat
= irb
->scsw
.cstat
;
389 dstat
= irb
->scsw
.dstat
;
391 raw
->message
= KERN_WARNING
392 "Got nonzero channel status in raw3215_irq "
393 "(dev sts 0x%2x, sch sts 0x%2x)";
394 raw
->msg_dstat
= dstat
;
395 raw
->msg_cstat
= cstat
;
396 tasklet_schedule(&raw
->tasklet
);
398 if (dstat
& 0x01) { /* we got a unit exception */
399 dstat
&= ~0x01; /* we can ignore it */
405 /* Attention interrupt, someone hit the enter key */
406 raw3215_mk_read_req(raw
);
408 memset(raw
->inbuf
, 0, RAW3215_INBUF_SIZE
);
409 tasklet_schedule(&raw
->tasklet
);
413 /* Channel end interrupt. */
414 if ((raw
= req
->info
) == NULL
)
415 return; /* That shouldn't happen ... */
416 if (req
->type
== RAW3215_READ
) {
417 /* store residual count, then wait for device end */
418 req
->residual
= irb
->scsw
.count
;
423 /* Device end interrupt. */
424 if ((raw
= req
->info
) == NULL
)
425 return; /* That shouldn't happen ... */
426 if (req
->type
== RAW3215_READ
&& raw
->tty
!= NULL
) {
430 count
= 160 - req
->residual
;
431 if (MACHINE_IS_P390
) {
432 slen
= strnlen(raw
->inbuf
, RAW3215_INBUF_SIZE
);
436 EBCASC(raw
->inbuf
, count
);
437 cchar
= ctrlchar_handle(raw
->inbuf
, count
, tty
);
438 switch (cchar
& CTRLCHAR_MASK
) {
443 tty_insert_flip_char(tty
, cchar
, TTY_NORMAL
);
444 tty_flip_buffer_push(raw
->tty
);
449 (strncmp(raw
->inbuf
+count
-2, "\252n", 2) &&
450 strncmp(raw
->inbuf
+count
-2, "^n", 2)) ) {
451 /* add the auto \n */
452 raw
->inbuf
[count
] = '\n';
456 tty_insert_flip_string(tty
, raw
->inbuf
, count
);
457 tty_flip_buffer_push(raw
->tty
);
460 } else if (req
->type
== RAW3215_WRITE
) {
461 raw
->count
-= req
->len
;
462 raw
->written
-= req
->len
;
464 raw
->flags
&= ~RAW3215_WORKING
;
465 raw3215_free_req(req
);
466 /* check for empty wait */
467 if (waitqueue_active(&raw
->empty_wait
) &&
468 raw
->queued_write
== NULL
&&
469 raw
->queued_read
== NULL
) {
470 wake_up_interruptible(&raw
->empty_wait
);
472 tasklet_schedule(&raw
->tasklet
);
475 /* Strange interrupt, I'll do my best to clean up */
476 if (req
!= NULL
&& req
->type
!= RAW3215_FREE
) {
477 if (req
->type
== RAW3215_WRITE
) {
478 raw
->count
-= req
->len
;
479 raw
->written
-= req
->len
;
481 raw
->flags
&= ~RAW3215_WORKING
;
482 raw3215_free_req(req
);
484 raw
->message
= KERN_WARNING
485 "Spurious interrupt in in raw3215_irq "
486 "(dev sts 0x%2x, sch sts 0x%2x)";
487 raw
->msg_dstat
= dstat
;
488 raw
->msg_cstat
= cstat
;
489 tasklet_schedule(&raw
->tasklet
);
495 * Wait until length bytes are available int the output buffer.
496 * Has to be called with the s390irq lock held. Can be called
500 raw3215_make_room(struct raw3215_info
*raw
, unsigned int length
)
502 while (RAW3215_BUFFER_SIZE
- raw
->count
< length
) {
503 /* there might be a request pending */
504 raw
->flags
|= RAW3215_FLUSHING
;
505 raw3215_mk_write_req(raw
);
507 raw
->flags
&= ~RAW3215_FLUSHING
;
508 #ifdef CONFIG_TN3215_CONSOLE
511 /* Enough room freed up ? */
512 if (RAW3215_BUFFER_SIZE
- raw
->count
>= length
)
514 /* there might be another cpu waiting for the lock */
515 spin_unlock(get_ccwdev_lock(raw
->cdev
));
517 spin_lock(get_ccwdev_lock(raw
->cdev
));
522 * String write routine for 3215 devices
525 raw3215_write(struct raw3215_info
*raw
, const char *str
, unsigned int length
)
531 spin_lock_irqsave(get_ccwdev_lock(raw
->cdev
), flags
);
532 count
= (length
> RAW3215_BUFFER_SIZE
) ?
533 RAW3215_BUFFER_SIZE
: length
;
536 raw3215_make_room(raw
, count
);
538 /* copy string to output buffer and convert it to EBCDIC */
540 c
= min_t(int, count
,
541 min(RAW3215_BUFFER_SIZE
- raw
->count
,
542 RAW3215_BUFFER_SIZE
- raw
->head
));
545 memcpy(raw
->buffer
+ raw
->head
, str
, c
);
546 ASCEBC(raw
->buffer
+ raw
->head
, c
);
547 raw
->head
= (raw
->head
+ c
) & (RAW3215_BUFFER_SIZE
- 1);
553 if (!(raw
->flags
& RAW3215_WORKING
)) {
554 raw3215_mk_write_req(raw
);
555 /* start or queue request */
558 spin_unlock_irqrestore(get_ccwdev_lock(raw
->cdev
), flags
);
563 * Put character routine for 3215 devices
566 raw3215_putchar(struct raw3215_info
*raw
, unsigned char ch
)
569 unsigned int length
, i
;
571 spin_lock_irqsave(get_ccwdev_lock(raw
->cdev
), flags
);
573 length
= TAB_STOP_SIZE
- (raw
->line_pos
%TAB_STOP_SIZE
);
574 raw
->line_pos
+= length
;
576 } else if (ch
== '\n') {
583 raw3215_make_room(raw
, length
);
585 for (i
= 0; i
< length
; i
++) {
586 raw
->buffer
[raw
->head
] = (char) _ascebc
[(int) ch
];
587 raw
->head
= (raw
->head
+ 1) & (RAW3215_BUFFER_SIZE
- 1);
590 if (!(raw
->flags
& RAW3215_WORKING
)) {
591 raw3215_mk_write_req(raw
);
592 /* start or queue request */
595 spin_unlock_irqrestore(get_ccwdev_lock(raw
->cdev
), flags
);
599 * Flush routine, it simply sets the flush flag and tries to start
603 raw3215_flush_buffer(struct raw3215_info
*raw
)
607 spin_lock_irqsave(get_ccwdev_lock(raw
->cdev
), flags
);
608 if (raw
->count
> 0) {
609 raw
->flags
|= RAW3215_FLUSHING
;
611 raw
->flags
&= ~RAW3215_FLUSHING
;
613 spin_unlock_irqrestore(get_ccwdev_lock(raw
->cdev
), flags
);
617 * Fire up a 3215 device.
620 raw3215_startup(struct raw3215_info
*raw
)
624 if (raw
->flags
& RAW3215_ACTIVE
)
627 raw
->flags
|= RAW3215_ACTIVE
;
628 spin_lock_irqsave(get_ccwdev_lock(raw
->cdev
), flags
);
630 spin_unlock_irqrestore(get_ccwdev_lock(raw
->cdev
), flags
);
636 * Shutdown a 3215 device.
639 raw3215_shutdown(struct raw3215_info
*raw
)
641 DECLARE_WAITQUEUE(wait
, current
);
644 if (!(raw
->flags
& RAW3215_ACTIVE
) || (raw
->flags
& RAW3215_FIXED
))
646 /* Wait for outstanding requests, then free irq */
647 spin_lock_irqsave(get_ccwdev_lock(raw
->cdev
), flags
);
648 if ((raw
->flags
& RAW3215_WORKING
) ||
649 raw
->queued_write
!= NULL
||
650 raw
->queued_read
!= NULL
) {
651 raw
->flags
|= RAW3215_CLOSING
;
652 add_wait_queue(&raw
->empty_wait
, &wait
);
653 set_current_state(TASK_INTERRUPTIBLE
);
654 spin_unlock_irqrestore(get_ccwdev_lock(raw
->cdev
), flags
);
656 spin_lock_irqsave(get_ccwdev_lock(raw
->cdev
), flags
);
657 remove_wait_queue(&raw
->empty_wait
, &wait
);
658 set_current_state(TASK_RUNNING
);
659 raw
->flags
&= ~(RAW3215_ACTIVE
| RAW3215_CLOSING
);
661 spin_unlock_irqrestore(get_ccwdev_lock(raw
->cdev
), flags
);
665 raw3215_probe (struct ccw_device
*cdev
)
667 struct raw3215_info
*raw
;
670 raw
= kmalloc(sizeof(struct raw3215_info
) +
671 RAW3215_INBUF_SIZE
, GFP_KERNEL
|GFP_DMA
);
675 spin_lock(&raw3215_device_lock
);
676 for (line
= 0; line
< NR_3215
; line
++) {
677 if (!raw3215
[line
]) {
682 spin_unlock(&raw3215_device_lock
);
683 if (line
== NR_3215
) {
689 raw
->inbuf
= (char *) raw
+ sizeof(struct raw3215_info
);
690 memset(raw
, 0, sizeof(struct raw3215_info
));
691 raw
->buffer
= kmalloc(RAW3215_BUFFER_SIZE
,
693 if (raw
->buffer
== NULL
) {
694 spin_lock(&raw3215_device_lock
);
695 raw3215
[line
] = NULL
;
696 spin_unlock(&raw3215_device_lock
);
700 tasklet_init(&raw
->tasklet
,
701 (void (*)(unsigned long)) raw3215_tasklet
,
702 (unsigned long) raw
);
703 init_waitqueue_head(&raw
->empty_wait
);
705 cdev
->dev
.driver_data
= raw
;
706 cdev
->handler
= raw3215_irq
;
712 raw3215_remove (struct ccw_device
*cdev
)
714 struct raw3215_info
*raw
;
716 ccw_device_set_offline(cdev
);
717 raw
= cdev
->dev
.driver_data
;
719 cdev
->dev
.driver_data
= NULL
;
726 raw3215_set_online (struct ccw_device
*cdev
)
728 struct raw3215_info
*raw
;
730 raw
= cdev
->dev
.driver_data
;
734 return raw3215_startup(raw
);
738 raw3215_set_offline (struct ccw_device
*cdev
)
740 struct raw3215_info
*raw
;
742 raw
= cdev
->dev
.driver_data
;
746 raw3215_shutdown(raw
);
751 static struct ccw_device_id raw3215_id
[] = {
752 { CCW_DEVICE(0x3215, 0) },
753 { /* end of list */ },
756 static struct ccw_driver raw3215_ccw_driver
= {
758 .owner
= THIS_MODULE
,
760 .probe
= &raw3215_probe
,
761 .remove
= &raw3215_remove
,
762 .set_online
= &raw3215_set_online
,
763 .set_offline
= &raw3215_set_offline
,
766 #ifdef CONFIG_TN3215_CONSOLE
768 * Write a string to the 3215 console
771 con3215_write(struct console
*co
, const char *str
, unsigned int count
)
773 struct raw3215_info
*raw
;
778 raw
= raw3215
[0]; /* console 3215 is the first one */
780 for (i
= 0; i
< count
; i
++)
781 if (str
[i
] == '\t' || str
[i
] == '\n')
783 raw3215_write(raw
, str
, i
);
787 raw3215_putchar(raw
, *str
);
794 static struct tty_driver
*con3215_device(struct console
*c
, int *index
)
797 return tty3215_driver
;
801 * panic() calls console_unblank before the system enters a
802 * disabled, endless loop.
805 con3215_unblank(void)
807 struct raw3215_info
*raw
;
810 raw
= raw3215
[0]; /* console 3215 is the first one */
811 spin_lock_irqsave(get_ccwdev_lock(raw
->cdev
), flags
);
812 raw3215_make_room(raw
, RAW3215_BUFFER_SIZE
);
813 spin_unlock_irqrestore(get_ccwdev_lock(raw
->cdev
), flags
);
817 * The console structure for the 3215 console
819 static struct console con3215
= {
821 .write
= con3215_write
,
822 .device
= con3215_device
,
823 .unblank
= con3215_unblank
,
824 .flags
= CON_PRINTBUFFER
,
828 * 3215 console initialization code called from console_init().
829 * NOTE: This is called before kmalloc is available.
834 struct ccw_device
*cdev
;
835 struct raw3215_info
*raw
;
836 struct raw3215_req
*req
;
839 /* Check if 3215 is to be the console */
840 if (!CONSOLE_IS_3215
)
843 /* Set the console mode for VM */
845 cpcmd("TERM CONMODE 3215", NULL
, 0, NULL
);
846 cpcmd("TERM AUTOCR OFF", NULL
, 0, NULL
);
849 /* allocate 3215 request structures */
850 raw3215_freelist
= NULL
;
851 spin_lock_init(&raw3215_freelist_lock
);
852 for (i
= 0; i
< NR_3215_REQ
; i
++) {
853 req
= (struct raw3215_req
*) alloc_bootmem_low(sizeof(struct raw3215_req
));
854 req
->next
= raw3215_freelist
;
855 raw3215_freelist
= req
;
858 cdev
= ccw_device_probe_console();
862 raw3215
[0] = raw
= (struct raw3215_info
*)
863 alloc_bootmem_low(sizeof(struct raw3215_info
));
864 memset(raw
, 0, sizeof(struct raw3215_info
));
865 raw
->buffer
= (char *) alloc_bootmem_low(RAW3215_BUFFER_SIZE
);
866 raw
->inbuf
= (char *) alloc_bootmem_low(RAW3215_INBUF_SIZE
);
868 cdev
->dev
.driver_data
= raw
;
869 cdev
->handler
= raw3215_irq
;
871 raw
->flags
|= RAW3215_FIXED
;
872 tasklet_init(&raw
->tasklet
,
873 (void (*)(unsigned long)) raw3215_tasklet
,
874 (unsigned long) raw
);
875 init_waitqueue_head(&raw
->empty_wait
);
877 /* Request the console irq */
878 if (raw3215_startup(raw
) != 0) {
879 free_bootmem((unsigned long) raw
->inbuf
, RAW3215_INBUF_SIZE
);
880 free_bootmem((unsigned long) raw
->buffer
, RAW3215_BUFFER_SIZE
);
881 free_bootmem((unsigned long) raw
, sizeof(struct raw3215_info
));
883 printk("Couldn't find a 3215 console device\n");
886 register_console(&con3215
);
889 console_initcall(con3215_init
);
895 * This routine is called whenever a 3215 tty is opened.
898 tty3215_open(struct tty_struct
*tty
, struct file
* filp
)
900 struct raw3215_info
*raw
;
904 if ((line
< 0) || (line
>= NR_3215
))
911 tty
->driver_data
= raw
;
914 tty
->low_latency
= 0; /* don't use bottom half for pushing chars */
916 * Start up 3215 device
918 retval
= raw3215_startup(raw
);
928 * This routine is called when the 3215 tty is closed. We wait
929 * for the remaining request to be completed. Then we clean up.
932 tty3215_close(struct tty_struct
*tty
, struct file
* filp
)
934 struct raw3215_info
*raw
;
936 raw
= (struct raw3215_info
*) tty
->driver_data
;
937 if (raw
== NULL
|| tty
->count
> 1)
940 /* Shutdown the terminal */
941 raw3215_shutdown(raw
);
947 * Returns the amount of free space in the output buffer.
950 tty3215_write_room(struct tty_struct
*tty
)
952 struct raw3215_info
*raw
;
954 raw
= (struct raw3215_info
*) tty
->driver_data
;
956 /* Subtract TAB_STOP_SIZE to allow for a tab, 8 <<< 64K */
957 if ((RAW3215_BUFFER_SIZE
- raw
->count
- TAB_STOP_SIZE
) >= 0)
958 return RAW3215_BUFFER_SIZE
- raw
->count
- TAB_STOP_SIZE
;
964 * String write routine for 3215 ttys
967 tty3215_write(struct tty_struct
* tty
,
968 const unsigned char *buf
, int count
)
970 struct raw3215_info
*raw
;
974 raw
= (struct raw3215_info
*) tty
->driver_data
;
975 raw3215_write(raw
, buf
, count
);
980 * Put character routine for 3215 ttys
983 tty3215_put_char(struct tty_struct
*tty
, unsigned char ch
)
985 struct raw3215_info
*raw
;
989 raw
= (struct raw3215_info
*) tty
->driver_data
;
990 raw3215_putchar(raw
, ch
);
994 tty3215_flush_chars(struct tty_struct
*tty
)
999 * Returns the number of characters in the output buffer
1002 tty3215_chars_in_buffer(struct tty_struct
*tty
)
1004 struct raw3215_info
*raw
;
1006 raw
= (struct raw3215_info
*) tty
->driver_data
;
1011 tty3215_flush_buffer(struct tty_struct
*tty
)
1013 struct raw3215_info
*raw
;
1015 raw
= (struct raw3215_info
*) tty
->driver_data
;
1016 raw3215_flush_buffer(raw
);
1021 * Currently we don't have any io controls for 3215 ttys
1024 tty3215_ioctl(struct tty_struct
*tty
, struct file
* file
,
1025 unsigned int cmd
, unsigned long arg
)
1027 if (tty
->flags
& (1 << TTY_IO_ERROR
))
1032 return -ENOIOCTLCMD
;
1038 * Disable reading from a 3215 tty
1041 tty3215_throttle(struct tty_struct
* tty
)
1043 struct raw3215_info
*raw
;
1045 raw
= (struct raw3215_info
*) tty
->driver_data
;
1046 raw
->flags
|= RAW3215_THROTTLED
;
1050 * Enable reading from a 3215 tty
1053 tty3215_unthrottle(struct tty_struct
* tty
)
1055 struct raw3215_info
*raw
;
1056 unsigned long flags
;
1058 raw
= (struct raw3215_info
*) tty
->driver_data
;
1059 if (raw
->flags
& RAW3215_THROTTLED
) {
1060 spin_lock_irqsave(get_ccwdev_lock(raw
->cdev
), flags
);
1061 raw
->flags
&= ~RAW3215_THROTTLED
;
1062 raw3215_try_io(raw
);
1063 spin_unlock_irqrestore(get_ccwdev_lock(raw
->cdev
), flags
);
1068 * Disable writing to a 3215 tty
1071 tty3215_stop(struct tty_struct
*tty
)
1073 struct raw3215_info
*raw
;
1075 raw
= (struct raw3215_info
*) tty
->driver_data
;
1076 raw
->flags
|= RAW3215_STOPPED
;
1080 * Enable writing to a 3215 tty
1083 tty3215_start(struct tty_struct
*tty
)
1085 struct raw3215_info
*raw
;
1086 unsigned long flags
;
1088 raw
= (struct raw3215_info
*) tty
->driver_data
;
1089 if (raw
->flags
& RAW3215_STOPPED
) {
1090 spin_lock_irqsave(get_ccwdev_lock(raw
->cdev
), flags
);
1091 raw
->flags
&= ~RAW3215_STOPPED
;
1092 raw3215_try_io(raw
);
1093 spin_unlock_irqrestore(get_ccwdev_lock(raw
->cdev
), flags
);
1097 static const struct tty_operations tty3215_ops
= {
1098 .open
= tty3215_open
,
1099 .close
= tty3215_close
,
1100 .write
= tty3215_write
,
1101 .put_char
= tty3215_put_char
,
1102 .flush_chars
= tty3215_flush_chars
,
1103 .write_room
= tty3215_write_room
,
1104 .chars_in_buffer
= tty3215_chars_in_buffer
,
1105 .flush_buffer
= tty3215_flush_buffer
,
1106 .ioctl
= tty3215_ioctl
,
1107 .throttle
= tty3215_throttle
,
1108 .unthrottle
= tty3215_unthrottle
,
1109 .stop
= tty3215_stop
,
1110 .start
= tty3215_start
,
1114 * 3215 tty registration code called from tty_init().
1115 * Most kernel services (incl. kmalloc) are available at this poimt.
1120 struct tty_driver
*driver
;
1123 if (!CONSOLE_IS_3215
)
1126 driver
= alloc_tty_driver(NR_3215
);
1130 ret
= ccw_driver_register(&raw3215_ccw_driver
);
1132 put_tty_driver(driver
);
1136 * Initialize the tty_driver structure
1137 * Entries in tty3215_driver that are NOT initialized:
1138 * proc_entry, set_termios, flush_buffer, set_ldisc, write_proc
1141 driver
->owner
= THIS_MODULE
;
1142 driver
->driver_name
= "tty3215";
1143 driver
->name
= "ttyS";
1144 driver
->major
= TTY_MAJOR
;
1145 driver
->minor_start
= 64;
1146 driver
->type
= TTY_DRIVER_TYPE_SYSTEM
;
1147 driver
->subtype
= SYSTEM_TYPE_TTY
;
1148 driver
->init_termios
= tty_std_termios
;
1149 driver
->init_termios
.c_iflag
= IGNBRK
| IGNPAR
;
1150 driver
->init_termios
.c_oflag
= ONLCR
| XTABS
;
1151 driver
->init_termios
.c_lflag
= ISIG
;
1152 driver
->flags
= TTY_DRIVER_REAL_RAW
;
1153 tty_set_operations(driver
, &tty3215_ops
);
1154 ret
= tty_register_driver(driver
);
1156 printk("Couldn't register tty3215 driver\n");
1157 put_tty_driver(driver
);
1160 tty3215_driver
= driver
;
1167 tty_unregister_driver(tty3215_driver
);
1168 put_tty_driver(tty3215_driver
);
1169 ccw_driver_unregister(&raw3215_ccw_driver
);
1172 module_init(tty3215_init
);
1173 module_exit(tty3215_exit
);