1 // SPDX-License-Identifier: GPL-2.0
3 * 3215 line mode terminal driver.
5 * Copyright IBM Corp. 1999, 2009
6 * Author(s): Martin Schwidefsky <schwidefsky@de.ibm.com>
9 * Aug-2000: Added tab support
10 * Dan Morrison, IBM Corporation <dmorriso@cse.buffalo.edu>
13 #include <linux/types.h>
14 #include <linux/kdev_t.h>
15 #include <linux/tty.h>
16 #include <linux/tty_flip.h>
17 #include <linux/vt_kern.h>
18 #include <linux/init.h>
19 #include <linux/console.h>
20 #include <linux/interrupt.h>
21 #include <linux/err.h>
22 #include <linux/reboot.h>
23 #include <linux/serial.h> /* ASYNC_* flags */
24 #include <linux/slab.h>
25 #include <asm/ccwdev.h>
28 #include <asm/ebcdic.h>
29 #include <linux/uaccess.h>
30 #include <asm/delay.h>
31 #include <asm/cpcmd.h>
32 #include <asm/setup.h>
37 #define NR_3215_REQ (4*NR_3215)
38 #define RAW3215_BUFFER_SIZE 65536 /* output buffer size */
39 #define RAW3215_INBUF_SIZE 256 /* input buffer size */
40 #define RAW3215_MIN_SPACE 128 /* minimum free space for wakeup */
41 #define RAW3215_MIN_WRITE 1024 /* min. length for immediate output */
42 #define RAW3215_MAX_BYTES 3968 /* max. bytes to write with one ssch */
43 #define RAW3215_MAX_NEWLINE 50 /* max. lines to write with one ssch */
44 #define RAW3215_NR_CCWS 3
45 #define RAW3215_TIMEOUT HZ/10 /* time for delayed output */
47 #define RAW3215_FIXED 1 /* 3215 console device is not be freed */
48 #define RAW3215_WORKING 4 /* set if a request is being worked on */
49 #define RAW3215_THROTTLED 8 /* set if reading is disabled */
50 #define RAW3215_STOPPED 16 /* set if writing is disabled */
51 #define RAW3215_TIMER_RUNS 64 /* set if the output delay timer is on */
52 #define RAW3215_FLUSHING 128 /* set to flush buffer (no delay) */
54 #define TAB_STOP_SIZE 8 /* tab stop size */
57 * Request types for a 3215 device
60 RAW3215_FREE
, RAW3215_READ
, RAW3215_WRITE
64 * Request structure for a 3215 device
67 enum raw3215_type type
; /* type of the request */
68 int start
, len
; /* start index & len in output buffer */
69 int delayable
; /* indication to wait for more data */
70 int residual
; /* residual count for read request */
71 struct ccw1 ccws
[RAW3215_NR_CCWS
]; /* space for the channel program */
72 struct raw3215_info
*info
; /* pointer to main structure */
73 struct raw3215_req
*next
; /* pointer to next request */
74 } __attribute__ ((aligned(8)));
78 struct ccw_device
*cdev
; /* device for tty driver */
79 spinlock_t
*lock
; /* pointer to irq lock */
80 int flags
; /* state flags */
81 char *buffer
; /* pointer to output buffer */
82 char *inbuf
; /* pointer to input buffer */
83 int head
; /* first free byte in output buffer */
84 int count
; /* number of bytes in output buffer */
85 int written
; /* number of bytes in write requests */
86 struct raw3215_req
*queued_read
; /* pointer to queued read requests */
87 struct raw3215_req
*queued_write
;/* pointer to queued write requests */
88 struct tasklet_struct tlet
; /* tasklet to invoke tty_wakeup */
89 wait_queue_head_t empty_wait
; /* wait queue for flushing */
90 struct timer_list timer
; /* timer for delayed output */
91 int line_pos
; /* position on the line (for tabs) */
92 char ubuffer
[80]; /* copy_from_user buffer */
95 /* array of 3215 devices structures */
96 static struct raw3215_info
*raw3215
[NR_3215
];
97 /* spinlock to protect the raw3215 array */
98 static DEFINE_SPINLOCK(raw3215_device_lock
);
99 /* list of free request structures */
100 static struct raw3215_req
*raw3215_freelist
;
101 /* spinlock to protect free list */
102 static spinlock_t raw3215_freelist_lock
;
104 static struct tty_driver
*tty3215_driver
;
107 * Get a request structure from the free list
109 static inline struct raw3215_req
*raw3215_alloc_req(void)
111 struct raw3215_req
*req
;
114 spin_lock_irqsave(&raw3215_freelist_lock
, flags
);
115 req
= raw3215_freelist
;
116 raw3215_freelist
= req
->next
;
117 spin_unlock_irqrestore(&raw3215_freelist_lock
, flags
);
122 * Put a request structure back to the free list
124 static inline void raw3215_free_req(struct raw3215_req
*req
)
128 if (req
->type
== RAW3215_FREE
)
129 return; /* don't free a free request */
130 req
->type
= RAW3215_FREE
;
131 spin_lock_irqsave(&raw3215_freelist_lock
, flags
);
132 req
->next
= raw3215_freelist
;
133 raw3215_freelist
= req
;
134 spin_unlock_irqrestore(&raw3215_freelist_lock
, flags
);
138 * Set up a read request that reads up to 160 byte from the 3215 device.
139 * If there is a queued read request it is used, but that shouldn't happen
140 * because a 3215 terminal won't accept a new read before the old one is
143 static void raw3215_mk_read_req(struct raw3215_info
*raw
)
145 struct raw3215_req
*req
;
148 /* there can only be ONE read request at a time */
149 req
= raw
->queued_read
;
151 /* no queued read request, use new req structure */
152 req
= raw3215_alloc_req();
153 req
->type
= RAW3215_READ
;
155 raw
->queued_read
= req
;
159 ccw
->cmd_code
= 0x0A; /* read inquiry */
160 ccw
->flags
= 0x20; /* ignore incorrect length */
162 ccw
->cda
= (__u32
) __pa(raw
->inbuf
);
166 * Set up a write request with the information from the main structure.
167 * A ccw chain is created that writes as much as possible from the output
168 * buffer to the 3215 device. If a queued write exists it is replaced by
169 * the new, probably lengthened request.
171 static void raw3215_mk_write_req(struct raw3215_info
*raw
)
173 struct raw3215_req
*req
;
175 int len
, count
, ix
, lines
;
177 if (raw
->count
<= raw
->written
)
179 /* check if there is a queued write request */
180 req
= raw
->queued_write
;
182 /* no queued write request, use new req structure */
183 req
= raw3215_alloc_req();
184 req
->type
= RAW3215_WRITE
;
186 raw
->queued_write
= req
;
188 raw
->written
-= req
->len
;
192 req
->start
= (raw
->head
- raw
->count
+ raw
->written
) &
193 (RAW3215_BUFFER_SIZE
- 1);
195 * now we have to count newlines. We can at max accept
196 * RAW3215_MAX_NEWLINE newlines in a single ssch due to
197 * a restriction in VM
201 while (lines
< RAW3215_MAX_NEWLINE
&& ix
!= raw
->head
) {
202 if (raw
->buffer
[ix
] == 0x15)
204 ix
= (ix
+ 1) & (RAW3215_BUFFER_SIZE
- 1);
206 len
= ((ix
- 1 - req
->start
) & (RAW3215_BUFFER_SIZE
- 1)) + 1;
207 if (len
> RAW3215_MAX_BYTES
)
208 len
= RAW3215_MAX_BYTES
;
212 /* set the indication if we should try to enlarge this request */
213 req
->delayable
= (ix
== raw
->head
) && (len
< RAW3215_MIN_WRITE
);
218 ccw
[-1].flags
|= 0x40; /* use command chaining */
219 ccw
->cmd_code
= 0x01; /* write, auto carrier return */
220 ccw
->flags
= 0x20; /* ignore incorrect length ind. */
222 (__u32
) __pa(raw
->buffer
+ ix
);
224 if (ix
+ count
> RAW3215_BUFFER_SIZE
)
225 count
= RAW3215_BUFFER_SIZE
- ix
;
228 ix
= (ix
+ count
) & (RAW3215_BUFFER_SIZE
- 1);
232 * Add a NOP to the channel program. 3215 devices are purely
233 * emulated and its much better to avoid the channel end
234 * interrupt in this case.
237 ccw
[-1].flags
|= 0x40; /* use command chaining */
238 ccw
->cmd_code
= 0x03; /* NOP */
245 * Start a read or a write request
247 static void raw3215_start_io(struct raw3215_info
*raw
)
249 struct raw3215_req
*req
;
252 req
= raw
->queued_read
;
254 !(raw
->flags
& (RAW3215_WORKING
| RAW3215_THROTTLED
))) {
255 /* dequeue request */
256 raw
->queued_read
= NULL
;
257 res
= ccw_device_start(raw
->cdev
, req
->ccws
,
258 (unsigned long) req
, 0, 0);
260 /* do_IO failed, put request back to queue */
261 raw
->queued_read
= req
;
263 raw
->flags
|= RAW3215_WORKING
;
266 req
= raw
->queued_write
;
268 !(raw
->flags
& (RAW3215_WORKING
| RAW3215_STOPPED
))) {
269 /* dequeue request */
270 raw
->queued_write
= NULL
;
271 res
= ccw_device_start(raw
->cdev
, req
->ccws
,
272 (unsigned long) req
, 0, 0);
274 /* do_IO failed, put request back to queue */
275 raw
->queued_write
= req
;
277 raw
->flags
|= RAW3215_WORKING
;
283 * Function to start a delayed output after RAW3215_TIMEOUT seconds
285 static void raw3215_timeout(struct timer_list
*t
)
287 struct raw3215_info
*raw
= from_timer(raw
, t
, timer
);
290 spin_lock_irqsave(get_ccwdev_lock(raw
->cdev
), flags
);
291 raw
->flags
&= ~RAW3215_TIMER_RUNS
;
292 raw3215_mk_write_req(raw
);
293 raw3215_start_io(raw
);
294 if ((raw
->queued_read
|| raw
->queued_write
) &&
295 !(raw
->flags
& RAW3215_WORKING
) &&
296 !(raw
->flags
& RAW3215_TIMER_RUNS
)) {
297 raw
->timer
.expires
= RAW3215_TIMEOUT
+ jiffies
;
298 add_timer(&raw
->timer
);
299 raw
->flags
|= RAW3215_TIMER_RUNS
;
301 spin_unlock_irqrestore(get_ccwdev_lock(raw
->cdev
), flags
);
305 * Function to conditionally start an IO. A read is started immediately,
306 * a write is only started immediately if the flush flag is on or the
307 * amount of data is bigger than RAW3215_MIN_WRITE. If a write is not
308 * done immediately a timer is started with a delay of RAW3215_TIMEOUT.
310 static inline void raw3215_try_io(struct raw3215_info
*raw
)
312 if (!tty_port_initialized(&raw
->port
))
314 if (raw
->queued_read
!= NULL
)
315 raw3215_start_io(raw
);
316 else if (raw
->queued_write
!= NULL
) {
317 if ((raw
->queued_write
->delayable
== 0) ||
318 (raw
->flags
& RAW3215_FLUSHING
)) {
319 /* execute write requests bigger than minimum size */
320 raw3215_start_io(raw
);
323 if ((raw
->queued_read
|| raw
->queued_write
) &&
324 !(raw
->flags
& RAW3215_WORKING
) &&
325 !(raw
->flags
& RAW3215_TIMER_RUNS
)) {
326 raw
->timer
.expires
= RAW3215_TIMEOUT
+ jiffies
;
327 add_timer(&raw
->timer
);
328 raw
->flags
|= RAW3215_TIMER_RUNS
;
333 * Call tty_wakeup from tasklet context
335 static void raw3215_wakeup(unsigned long data
)
337 struct raw3215_info
*raw
= (struct raw3215_info
*) data
;
338 struct tty_struct
*tty
;
340 tty
= tty_port_tty_get(&raw
->port
);
348 * Try to start the next IO and wake up processes waiting on the tty.
350 static void raw3215_next_io(struct raw3215_info
*raw
, struct tty_struct
*tty
)
352 raw3215_mk_write_req(raw
);
354 if (tty
&& RAW3215_BUFFER_SIZE
- raw
->count
>= RAW3215_MIN_SPACE
)
355 tasklet_schedule(&raw
->tlet
);
359 * Interrupt routine, called from common io layer
361 static void raw3215_irq(struct ccw_device
*cdev
, unsigned long intparm
,
364 struct raw3215_info
*raw
;
365 struct raw3215_req
*req
;
366 struct tty_struct
*tty
;
370 raw
= dev_get_drvdata(&cdev
->dev
);
371 req
= (struct raw3215_req
*) intparm
;
372 tty
= tty_port_tty_get(&raw
->port
);
373 cstat
= irb
->scsw
.cmd
.cstat
;
374 dstat
= irb
->scsw
.cmd
.dstat
;
376 raw3215_next_io(raw
, tty
);
377 if (dstat
& 0x01) { /* we got a unit exception */
378 dstat
&= ~0x01; /* we can ignore it */
384 /* Attention interrupt, someone hit the enter key */
385 raw3215_mk_read_req(raw
);
386 raw3215_next_io(raw
, tty
);
390 /* Channel end interrupt. */
391 if ((raw
= req
->info
) == NULL
)
392 goto put_tty
; /* That shouldn't happen ... */
393 if (req
->type
== RAW3215_READ
) {
394 /* store residual count, then wait for device end */
395 req
->residual
= irb
->scsw
.cmd
.count
;
401 /* Device end interrupt. */
402 if ((raw
= req
->info
) == NULL
)
403 goto put_tty
; /* That shouldn't happen ... */
404 if (req
->type
== RAW3215_READ
&& tty
!= NULL
) {
407 count
= 160 - req
->residual
;
408 EBCASC(raw
->inbuf
, count
);
409 cchar
= ctrlchar_handle(raw
->inbuf
, count
, tty
);
410 switch (cchar
& CTRLCHAR_MASK
) {
415 tty_insert_flip_char(&raw
->port
, cchar
,
417 tty_flip_buffer_push(&raw
->port
);
422 (strncmp(raw
->inbuf
+count
-2, "\252n", 2) &&
423 strncmp(raw
->inbuf
+count
-2, "^n", 2)) ) {
424 /* add the auto \n */
425 raw
->inbuf
[count
] = '\n';
429 tty_insert_flip_string(&raw
->port
, raw
->inbuf
,
431 tty_flip_buffer_push(&raw
->port
);
434 } else if (req
->type
== RAW3215_WRITE
) {
435 raw
->count
-= req
->len
;
436 raw
->written
-= req
->len
;
438 raw
->flags
&= ~RAW3215_WORKING
;
439 raw3215_free_req(req
);
440 /* check for empty wait */
441 if (waitqueue_active(&raw
->empty_wait
) &&
442 raw
->queued_write
== NULL
&&
443 raw
->queued_read
== NULL
) {
444 wake_up_interruptible(&raw
->empty_wait
);
446 raw3215_next_io(raw
, tty
);
449 /* Strange interrupt, I'll do my best to clean up */
450 if (req
!= NULL
&& req
->type
!= RAW3215_FREE
) {
451 if (req
->type
== RAW3215_WRITE
) {
452 raw
->count
-= req
->len
;
453 raw
->written
-= req
->len
;
455 raw
->flags
&= ~RAW3215_WORKING
;
456 raw3215_free_req(req
);
458 raw3215_next_io(raw
, tty
);
465 * Wait until length bytes are available int the output buffer.
466 * Has to be called with the s390irq lock held. Can be called
469 static void raw3215_make_room(struct raw3215_info
*raw
, unsigned int length
)
471 while (RAW3215_BUFFER_SIZE
- raw
->count
< length
) {
472 /* there might be a request pending */
473 raw
->flags
|= RAW3215_FLUSHING
;
474 raw3215_mk_write_req(raw
);
476 raw
->flags
&= ~RAW3215_FLUSHING
;
477 #ifdef CONFIG_TN3215_CONSOLE
478 ccw_device_wait_idle(raw
->cdev
);
480 /* Enough room freed up ? */
481 if (RAW3215_BUFFER_SIZE
- raw
->count
>= length
)
483 /* there might be another cpu waiting for the lock */
484 spin_unlock(get_ccwdev_lock(raw
->cdev
));
486 spin_lock(get_ccwdev_lock(raw
->cdev
));
491 * String write routine for 3215 devices
493 static void raw3215_write(struct raw3215_info
*raw
, const char *str
,
500 spin_lock_irqsave(get_ccwdev_lock(raw
->cdev
), flags
);
501 count
= (length
> RAW3215_BUFFER_SIZE
) ?
502 RAW3215_BUFFER_SIZE
: length
;
505 raw3215_make_room(raw
, count
);
507 /* copy string to output buffer and convert it to EBCDIC */
509 c
= min_t(int, count
,
510 min(RAW3215_BUFFER_SIZE
- raw
->count
,
511 RAW3215_BUFFER_SIZE
- raw
->head
));
514 memcpy(raw
->buffer
+ raw
->head
, str
, c
);
515 ASCEBC(raw
->buffer
+ raw
->head
, c
);
516 raw
->head
= (raw
->head
+ c
) & (RAW3215_BUFFER_SIZE
- 1);
522 if (!(raw
->flags
& RAW3215_WORKING
)) {
523 raw3215_mk_write_req(raw
);
524 /* start or queue request */
527 spin_unlock_irqrestore(get_ccwdev_lock(raw
->cdev
), flags
);
532 * Put character routine for 3215 devices
534 static void raw3215_putchar(struct raw3215_info
*raw
, unsigned char ch
)
537 unsigned int length
, i
;
539 spin_lock_irqsave(get_ccwdev_lock(raw
->cdev
), flags
);
541 length
= TAB_STOP_SIZE
- (raw
->line_pos
%TAB_STOP_SIZE
);
542 raw
->line_pos
+= length
;
544 } else if (ch
== '\n') {
551 raw3215_make_room(raw
, length
);
553 for (i
= 0; i
< length
; i
++) {
554 raw
->buffer
[raw
->head
] = (char) _ascebc
[(int) ch
];
555 raw
->head
= (raw
->head
+ 1) & (RAW3215_BUFFER_SIZE
- 1);
558 if (!(raw
->flags
& RAW3215_WORKING
)) {
559 raw3215_mk_write_req(raw
);
560 /* start or queue request */
563 spin_unlock_irqrestore(get_ccwdev_lock(raw
->cdev
), flags
);
567 * Flush routine, it simply sets the flush flag and tries to start
570 static void raw3215_flush_buffer(struct raw3215_info
*raw
)
574 spin_lock_irqsave(get_ccwdev_lock(raw
->cdev
), flags
);
575 if (raw
->count
> 0) {
576 raw
->flags
|= RAW3215_FLUSHING
;
578 raw
->flags
&= ~RAW3215_FLUSHING
;
580 spin_unlock_irqrestore(get_ccwdev_lock(raw
->cdev
), flags
);
584 * Fire up a 3215 device.
586 static int raw3215_startup(struct raw3215_info
*raw
)
590 if (tty_port_initialized(&raw
->port
))
593 tty_port_set_initialized(&raw
->port
, 1);
594 spin_lock_irqsave(get_ccwdev_lock(raw
->cdev
), flags
);
596 spin_unlock_irqrestore(get_ccwdev_lock(raw
->cdev
), flags
);
602 * Shutdown a 3215 device.
604 static void raw3215_shutdown(struct raw3215_info
*raw
)
606 DECLARE_WAITQUEUE(wait
, current
);
609 if (!tty_port_initialized(&raw
->port
) || (raw
->flags
& RAW3215_FIXED
))
611 /* Wait for outstanding requests, then free irq */
612 spin_lock_irqsave(get_ccwdev_lock(raw
->cdev
), flags
);
613 if ((raw
->flags
& RAW3215_WORKING
) ||
614 raw
->queued_write
!= NULL
||
615 raw
->queued_read
!= NULL
) {
616 add_wait_queue(&raw
->empty_wait
, &wait
);
617 set_current_state(TASK_INTERRUPTIBLE
);
618 spin_unlock_irqrestore(get_ccwdev_lock(raw
->cdev
), flags
);
620 spin_lock_irqsave(get_ccwdev_lock(raw
->cdev
), flags
);
621 remove_wait_queue(&raw
->empty_wait
, &wait
);
622 set_current_state(TASK_RUNNING
);
623 tty_port_set_initialized(&raw
->port
, 1);
625 spin_unlock_irqrestore(get_ccwdev_lock(raw
->cdev
), flags
);
628 static struct raw3215_info
*raw3215_alloc_info(void)
630 struct raw3215_info
*info
;
632 info
= kzalloc(sizeof(struct raw3215_info
), GFP_KERNEL
| GFP_DMA
);
636 info
->buffer
= kzalloc(RAW3215_BUFFER_SIZE
, GFP_KERNEL
| GFP_DMA
);
637 info
->inbuf
= kzalloc(RAW3215_INBUF_SIZE
, GFP_KERNEL
| GFP_DMA
);
638 if (!info
->buffer
|| !info
->inbuf
) {
645 timer_setup(&info
->timer
, raw3215_timeout
, 0);
646 init_waitqueue_head(&info
->empty_wait
);
647 tasklet_init(&info
->tlet
, raw3215_wakeup
, (unsigned long)info
);
648 tty_port_init(&info
->port
);
653 static void raw3215_free_info(struct raw3215_info
*raw
)
657 tty_port_destroy(&raw
->port
);
661 static int raw3215_probe (struct ccw_device
*cdev
)
663 struct raw3215_info
*raw
;
666 /* Console is special. */
667 if (raw3215
[0] && (raw3215
[0] == dev_get_drvdata(&cdev
->dev
)))
670 raw
= raw3215_alloc_info();
675 dev_set_drvdata(&cdev
->dev
, raw
);
676 cdev
->handler
= raw3215_irq
;
678 spin_lock(&raw3215_device_lock
);
679 for (line
= 0; line
< NR_3215
; line
++) {
680 if (!raw3215
[line
]) {
685 spin_unlock(&raw3215_device_lock
);
686 if (line
== NR_3215
) {
687 raw3215_free_info(raw
);
694 static void raw3215_remove (struct ccw_device
*cdev
)
696 struct raw3215_info
*raw
;
699 ccw_device_set_offline(cdev
);
700 raw
= dev_get_drvdata(&cdev
->dev
);
702 spin_lock(&raw3215_device_lock
);
703 for (line
= 0; line
< NR_3215
; line
++)
704 if (raw3215
[line
] == raw
)
706 raw3215
[line
] = NULL
;
707 spin_unlock(&raw3215_device_lock
);
708 dev_set_drvdata(&cdev
->dev
, NULL
);
709 raw3215_free_info(raw
);
713 static int raw3215_set_online (struct ccw_device
*cdev
)
715 struct raw3215_info
*raw
;
717 raw
= dev_get_drvdata(&cdev
->dev
);
721 return raw3215_startup(raw
);
724 static int raw3215_set_offline (struct ccw_device
*cdev
)
726 struct raw3215_info
*raw
;
728 raw
= dev_get_drvdata(&cdev
->dev
);
732 raw3215_shutdown(raw
);
737 static struct ccw_device_id raw3215_id
[] = {
738 { CCW_DEVICE(0x3215, 0) },
739 { /* end of list */ },
742 static struct ccw_driver raw3215_ccw_driver
= {
745 .owner
= THIS_MODULE
,
748 .probe
= &raw3215_probe
,
749 .remove
= &raw3215_remove
,
750 .set_online
= &raw3215_set_online
,
751 .set_offline
= &raw3215_set_offline
,
752 .int_class
= IRQIO_C15
,
755 #ifdef CONFIG_TN3215_CONSOLE
757 * Write a string to the 3215 console
759 static void con3215_write(struct console
*co
, const char *str
,
762 struct raw3215_info
*raw
;
767 raw
= raw3215
[0]; /* console 3215 is the first one */
769 for (i
= 0; i
< count
; i
++)
770 if (str
[i
] == '\t' || str
[i
] == '\n')
772 raw3215_write(raw
, str
, i
);
776 raw3215_putchar(raw
, *str
);
783 static struct tty_driver
*con3215_device(struct console
*c
, int *index
)
786 return tty3215_driver
;
790 * panic() calls con3215_flush through a panic_notifier
791 * before the system enters a disabled, endless loop.
793 static void con3215_flush(void)
795 struct raw3215_info
*raw
;
798 raw
= raw3215
[0]; /* console 3215 is the first one */
799 spin_lock_irqsave(get_ccwdev_lock(raw
->cdev
), flags
);
800 raw3215_make_room(raw
, RAW3215_BUFFER_SIZE
);
801 spin_unlock_irqrestore(get_ccwdev_lock(raw
->cdev
), flags
);
804 static int con3215_notify(struct notifier_block
*self
,
805 unsigned long event
, void *data
)
811 static struct notifier_block on_panic_nb
= {
812 .notifier_call
= con3215_notify
,
816 static struct notifier_block on_reboot_nb
= {
817 .notifier_call
= con3215_notify
,
822 * The console structure for the 3215 console
824 static struct console con3215
= {
826 .write
= con3215_write
,
827 .device
= con3215_device
,
828 .flags
= CON_PRINTBUFFER
,
832 * 3215 console initialization code called from console_init().
834 static int __init
con3215_init(void)
836 struct ccw_device
*cdev
;
837 struct raw3215_info
*raw
;
838 struct raw3215_req
*req
;
841 /* Check if 3215 is to be the console */
842 if (!CONSOLE_IS_3215
)
845 /* Set the console mode for VM */
847 cpcmd("TERM CONMODE 3215", NULL
, 0, NULL
);
848 cpcmd("TERM AUTOCR OFF", NULL
, 0, NULL
);
851 /* allocate 3215 request structures */
852 raw3215_freelist
= NULL
;
853 spin_lock_init(&raw3215_freelist_lock
);
854 for (i
= 0; i
< NR_3215_REQ
; i
++) {
855 req
= kzalloc(sizeof(struct raw3215_req
), GFP_KERNEL
| GFP_DMA
);
858 req
->next
= raw3215_freelist
;
859 raw3215_freelist
= req
;
862 cdev
= ccw_device_create_console(&raw3215_ccw_driver
);
866 raw3215
[0] = raw
= raw3215_alloc_info();
868 dev_set_drvdata(&cdev
->dev
, raw
);
869 cdev
->handler
= raw3215_irq
;
871 raw
->flags
|= RAW3215_FIXED
;
872 if (ccw_device_enable_console(cdev
)) {
873 ccw_device_destroy_console(cdev
);
874 raw3215_free_info(raw
);
879 /* Request the console irq */
880 if (raw3215_startup(raw
) != 0) {
881 raw3215_free_info(raw
);
885 atomic_notifier_chain_register(&panic_notifier_list
, &on_panic_nb
);
886 register_reboot_notifier(&on_reboot_nb
);
887 register_console(&con3215
);
890 console_initcall(con3215_init
);
893 static int tty3215_install(struct tty_driver
*driver
, struct tty_struct
*tty
)
895 struct raw3215_info
*raw
;
897 raw
= raw3215
[tty
->index
];
901 tty
->driver_data
= raw
;
903 return tty_port_install(&raw
->port
, driver
, tty
);
909 * This routine is called whenever a 3215 tty is opened.
911 static int tty3215_open(struct tty_struct
*tty
, struct file
* filp
)
913 struct raw3215_info
*raw
= tty
->driver_data
;
915 tty_port_tty_set(&raw
->port
, tty
);
917 raw
->port
.low_latency
= 0; /* don't use bottom half for pushing chars */
919 * Start up 3215 device
921 return raw3215_startup(raw
);
927 * This routine is called when the 3215 tty is closed. We wait
928 * for the remaining request to be completed. Then we clean up.
930 static void tty3215_close(struct tty_struct
*tty
, struct file
* filp
)
932 struct raw3215_info
*raw
;
934 raw
= (struct raw3215_info
*) tty
->driver_data
;
935 if (raw
== NULL
|| tty
->count
> 1)
938 /* Shutdown the terminal */
939 raw3215_shutdown(raw
);
940 tasklet_kill(&raw
->tlet
);
942 tty_port_tty_set(&raw
->port
, NULL
);
946 * Returns the amount of free space in the output buffer.
948 static int tty3215_write_room(struct tty_struct
*tty
)
950 struct raw3215_info
*raw
;
952 raw
= (struct raw3215_info
*) tty
->driver_data
;
954 /* Subtract TAB_STOP_SIZE to allow for a tab, 8 <<< 64K */
955 if ((RAW3215_BUFFER_SIZE
- raw
->count
- TAB_STOP_SIZE
) >= 0)
956 return RAW3215_BUFFER_SIZE
- raw
->count
- TAB_STOP_SIZE
;
962 * String write routine for 3215 ttys
964 static int tty3215_write(struct tty_struct
* tty
,
965 const unsigned char *buf
, int count
)
967 struct raw3215_info
*raw
;
972 raw
= (struct raw3215_info
*) tty
->driver_data
;
975 for (i
= 0; i
< count
; i
++)
976 if (buf
[i
] == '\t' || buf
[i
] == '\n')
978 raw3215_write(raw
, buf
, i
);
982 raw3215_putchar(raw
, *buf
);
991 * Put character routine for 3215 ttys
993 static int tty3215_put_char(struct tty_struct
*tty
, unsigned char ch
)
995 struct raw3215_info
*raw
;
999 raw
= (struct raw3215_info
*) tty
->driver_data
;
1000 raw3215_putchar(raw
, ch
);
1004 static void tty3215_flush_chars(struct tty_struct
*tty
)
1009 * Returns the number of characters in the output buffer
1011 static int tty3215_chars_in_buffer(struct tty_struct
*tty
)
1013 struct raw3215_info
*raw
;
1015 raw
= (struct raw3215_info
*) tty
->driver_data
;
1019 static void tty3215_flush_buffer(struct tty_struct
*tty
)
1021 struct raw3215_info
*raw
;
1023 raw
= (struct raw3215_info
*) tty
->driver_data
;
1024 raw3215_flush_buffer(raw
);
1029 * Disable reading from a 3215 tty
1031 static void tty3215_throttle(struct tty_struct
* tty
)
1033 struct raw3215_info
*raw
;
1035 raw
= (struct raw3215_info
*) tty
->driver_data
;
1036 raw
->flags
|= RAW3215_THROTTLED
;
1040 * Enable reading from a 3215 tty
1042 static void tty3215_unthrottle(struct tty_struct
* tty
)
1044 struct raw3215_info
*raw
;
1045 unsigned long flags
;
1047 raw
= (struct raw3215_info
*) tty
->driver_data
;
1048 if (raw
->flags
& RAW3215_THROTTLED
) {
1049 spin_lock_irqsave(get_ccwdev_lock(raw
->cdev
), flags
);
1050 raw
->flags
&= ~RAW3215_THROTTLED
;
1051 raw3215_try_io(raw
);
1052 spin_unlock_irqrestore(get_ccwdev_lock(raw
->cdev
), flags
);
1057 * Disable writing to a 3215 tty
1059 static void tty3215_stop(struct tty_struct
*tty
)
1061 struct raw3215_info
*raw
;
1063 raw
= (struct raw3215_info
*) tty
->driver_data
;
1064 raw
->flags
|= RAW3215_STOPPED
;
1068 * Enable writing to a 3215 tty
1070 static void tty3215_start(struct tty_struct
*tty
)
1072 struct raw3215_info
*raw
;
1073 unsigned long flags
;
1075 raw
= (struct raw3215_info
*) tty
->driver_data
;
1076 if (raw
->flags
& RAW3215_STOPPED
) {
1077 spin_lock_irqsave(get_ccwdev_lock(raw
->cdev
), flags
);
1078 raw
->flags
&= ~RAW3215_STOPPED
;
1079 raw3215_try_io(raw
);
1080 spin_unlock_irqrestore(get_ccwdev_lock(raw
->cdev
), flags
);
1084 static const struct tty_operations tty3215_ops
= {
1085 .install
= tty3215_install
,
1086 .open
= tty3215_open
,
1087 .close
= tty3215_close
,
1088 .write
= tty3215_write
,
1089 .put_char
= tty3215_put_char
,
1090 .flush_chars
= tty3215_flush_chars
,
1091 .write_room
= tty3215_write_room
,
1092 .chars_in_buffer
= tty3215_chars_in_buffer
,
1093 .flush_buffer
= tty3215_flush_buffer
,
1094 .throttle
= tty3215_throttle
,
1095 .unthrottle
= tty3215_unthrottle
,
1096 .stop
= tty3215_stop
,
1097 .start
= tty3215_start
,
1101 * 3215 tty registration code called from tty_init().
1102 * Most kernel services (incl. kmalloc) are available at this poimt.
1104 static int __init
tty3215_init(void)
1106 struct tty_driver
*driver
;
1109 if (!CONSOLE_IS_3215
)
1112 driver
= alloc_tty_driver(NR_3215
);
1116 ret
= ccw_driver_register(&raw3215_ccw_driver
);
1118 put_tty_driver(driver
);
1122 * Initialize the tty_driver structure
1123 * Entries in tty3215_driver that are NOT initialized:
1124 * proc_entry, set_termios, flush_buffer, set_ldisc, write_proc
1127 driver
->driver_name
= "tty3215";
1128 driver
->name
= "ttyS";
1129 driver
->major
= TTY_MAJOR
;
1130 driver
->minor_start
= 64;
1131 driver
->type
= TTY_DRIVER_TYPE_SYSTEM
;
1132 driver
->subtype
= SYSTEM_TYPE_TTY
;
1133 driver
->init_termios
= tty_std_termios
;
1134 driver
->init_termios
.c_iflag
= IGNBRK
| IGNPAR
;
1135 driver
->init_termios
.c_oflag
= ONLCR
;
1136 driver
->init_termios
.c_lflag
= ISIG
;
1137 driver
->flags
= TTY_DRIVER_REAL_RAW
;
1138 tty_set_operations(driver
, &tty3215_ops
);
1139 ret
= tty_register_driver(driver
);
1141 put_tty_driver(driver
);
1144 tty3215_driver
= driver
;
1147 device_initcall(tty3215_init
);