2 * drivers/s390/char/tty3270.c
3 * IBM/3270 Driver - tty functions.
6 * Original 3270 Code for 2.4 written by Richard Hitt (UTS Global)
7 * Rewritten for 2.5 by Martin Schwidefsky <schwidefsky@de.ibm.com>
8 * -- Copyright (C) 2003 IBM Deutschland Entwicklung GmbH, IBM Corporation
11 #include <linux/module.h>
12 #include <linux/types.h>
13 #include <linux/kdev_t.h>
14 #include <linux/tty.h>
15 #include <linux/vt_kern.h>
16 #include <linux/init.h>
17 #include <linux/console.h>
18 #include <linux/interrupt.h>
20 #include <linux/slab.h>
21 #include <linux/bootmem.h>
22 #include <linux/compat.h>
24 #include <asm/ccwdev.h>
26 #include <asm/ebcdic.h>
27 #include <asm/uaccess.h>
33 #define TTY3270_CHAR_BUF_SIZE 256
34 #define TTY3270_OUTPUT_BUFFER_SIZE 1024
35 #define TTY3270_STRING_PAGES 5
37 struct tty_driver
*tty3270_driver
;
38 static int tty3270_max_index
;
40 static struct raw3270_fn tty3270_fn
;
43 unsigned char character
;
44 unsigned char highlight
;
45 unsigned char f_color
;
49 struct tty3270_cell
*cells
;
56 * The main tty view data structure.
58 * 1) describe line orientation & lines list concept against screen
59 * 2) describe conversion of screen to lines
60 * 3) describe line format.
63 struct raw3270_view view
;
64 struct tty_struct
*tty
; /* Pointer to tty structure */
65 void **freemem_pages
; /* Array of pages used for freemem. */
66 struct list_head freemem
; /* List of free memory for strings. */
69 struct list_head lines
; /* List of lines. */
70 struct list_head update
; /* List of lines to update. */
71 unsigned char wcc
; /* Write control character. */
72 int nr_lines
; /* # lines in list. */
73 int nr_up
; /* # lines up in history. */
74 unsigned long update_flags
; /* Update indication bits. */
75 struct string
*status
; /* Lower right of display. */
76 struct raw3270_request
*write
; /* Single write request. */
77 struct timer_list timer
; /* Output delay timer. */
79 /* Current tty screen. */
80 unsigned int cx
, cy
; /* Current output position. */
81 unsigned int highlight
; /* Blink/reverse/underscore */
82 unsigned int f_color
; /* Foreground color */
83 struct tty3270_line
*screen
;
86 struct string
*prompt
; /* Output string for input area. */
87 struct string
*input
; /* Input string for read request. */
88 struct raw3270_request
*read
; /* Single read request. */
89 struct raw3270_request
*kreset
; /* Single keyboard reset request. */
90 unsigned char inattr
; /* Visible/invisible input. */
91 int throttle
, attn
; /* tty throttle/unthrottle. */
92 struct tasklet_struct readlet
; /* Tasklet to issue read request. */
93 struct kbd_data
*kbd
; /* key_maps stuff. */
95 /* Escape sequence parsing. */
96 int esc_state
, esc_ques
, esc_npar
;
97 int esc_par
[ESCAPE_NPAR
];
98 unsigned int saved_cx
, saved_cy
;
99 unsigned int saved_highlight
, saved_f_color
;
101 /* Command recalling. */
102 struct list_head rcl_lines
; /* List of recallable lines. */
103 struct list_head
*rcl_walk
; /* Point in rcl_lines list. */
104 int rcl_nr
, rcl_max
; /* Number/max number of rcl_lines. */
106 /* Character array for put_char/flush_chars. */
107 unsigned int char_count
;
108 char char_buf
[TTY3270_CHAR_BUF_SIZE
];
111 /* tty3270->update_flags. See tty3270_update for details. */
112 #define TTY_UPDATE_ERASE 1 /* Use EWRITEA instead of WRITE. */
113 #define TTY_UPDATE_LIST 2 /* Update lines in tty3270->update. */
114 #define TTY_UPDATE_INPUT 4 /* Update input line. */
115 #define TTY_UPDATE_STATUS 8 /* Update status line. */
116 #define TTY_UPDATE_ALL 16 /* Recreate screen. */
118 static void tty3270_update(struct tty3270
*);
121 * Setup timeout for a device. On timeout trigger an update.
123 static void tty3270_set_timer(struct tty3270
*tp
, int expires
)
126 del_timer(&tp
->timer
);
128 mod_timer(&tp
->timer
, jiffies
+ expires
);
132 * The input line are the two last lines of the screen.
135 tty3270_update_prompt(struct tty3270
*tp
, char *input
, int count
)
142 line
->string
[5] = TF_INMDT
;
144 line
->string
[5] = tp
->inattr
;
145 if (count
> tp
->view
.cols
* 2 - 11)
146 count
= tp
->view
.cols
* 2 - 11;
147 memcpy(line
->string
+ 6, input
, count
);
148 line
->string
[6 + count
] = TO_IC
;
149 /* Clear to end of input line. */
150 if (count
< tp
->view
.cols
* 2 - 11) {
151 line
->string
[7 + count
] = TO_RA
;
152 line
->string
[10 + count
] = 0;
153 off
= tp
->view
.cols
* tp
->view
.rows
- 9;
154 raw3270_buffer_address(tp
->view
.dev
, line
->string
+count
+8, off
);
155 line
->len
= 11 + count
;
157 line
->len
= 7 + count
;
158 tp
->update_flags
|= TTY_UPDATE_INPUT
;
162 tty3270_create_prompt(struct tty3270
*tp
)
164 static const unsigned char blueprint
[] =
165 { TO_SBA
, 0, 0, 0x6e, TO_SF
, TF_INPUT
,
166 /* empty input string */
167 TO_IC
, TO_RA
, 0, 0, 0 };
171 line
= alloc_string(&tp
->freemem
,
172 sizeof(blueprint
) + tp
->view
.cols
* 2 - 9);
174 tp
->inattr
= TF_INPUT
;
175 /* Copy blueprint to status line */
176 memcpy(line
->string
, blueprint
, sizeof(blueprint
));
177 line
->len
= sizeof(blueprint
);
178 /* Set output offsets. */
179 offset
= tp
->view
.cols
* (tp
->view
.rows
- 2);
180 raw3270_buffer_address(tp
->view
.dev
, line
->string
+ 1, offset
);
181 offset
= tp
->view
.cols
* tp
->view
.rows
- 9;
182 raw3270_buffer_address(tp
->view
.dev
, line
->string
+ 8, offset
);
184 /* Allocate input string for reading. */
185 tp
->input
= alloc_string(&tp
->freemem
, tp
->view
.cols
* 2 - 9 + 6);
189 * The status line is the last line of the screen. It shows the string
190 * "Running"/"Holding" in the lower right corner of the screen.
193 tty3270_update_status(struct tty3270
* tp
)
197 str
= (tp
->nr_up
!= 0) ? "History" : "Running";
198 memcpy(tp
->status
->string
+ 8, str
, 7);
199 codepage_convert(tp
->view
.ascebc
, tp
->status
->string
+ 8, 7);
200 tp
->update_flags
|= TTY_UPDATE_STATUS
;
204 tty3270_create_status(struct tty3270
* tp
)
206 static const unsigned char blueprint
[] =
207 { TO_SBA
, 0, 0, TO_SF
, TF_LOG
, TO_SA
, TAT_COLOR
, TAC_GREEN
,
208 0, 0, 0, 0, 0, 0, 0, TO_SF
, TF_LOG
, TO_SA
, TAT_COLOR
,
213 line
= alloc_string(&tp
->freemem
,sizeof(blueprint
));
215 /* Copy blueprint to status line */
216 memcpy(line
->string
, blueprint
, sizeof(blueprint
));
217 /* Set address to start of status string (= last 9 characters). */
218 offset
= tp
->view
.cols
* tp
->view
.rows
- 9;
219 raw3270_buffer_address(tp
->view
.dev
, line
->string
+ 1, offset
);
223 * Set output offsets to 3270 datastream fragment of a tty string.
224 * (TO_SBA offset at the start and TO_RA offset at the end of the string)
227 tty3270_update_string(struct tty3270
*tp
, struct string
*line
, int nr
)
231 raw3270_buffer_address(tp
->view
.dev
, line
->string
+ 1,
233 cp
= line
->string
+ line
->len
- 4;
235 raw3270_buffer_address(tp
->view
.dev
, cp
+ 1,
236 tp
->view
.cols
* (nr
+ 1));
240 * Rebuild update list to print all lines.
243 tty3270_rebuild_update(struct tty3270
*tp
)
245 struct string
*s
, *n
;
249 * Throw away update list and create a new one,
250 * containing all lines that will fit on the screen.
252 list_for_each_entry_safe(s
, n
, &tp
->update
, update
)
253 list_del_init(&s
->update
);
254 line
= tp
->view
.rows
- 3;
256 list_for_each_entry_reverse(s
, &tp
->lines
, list
) {
261 tty3270_update_string(tp
, s
, line
);
262 list_add(&s
->update
, &tp
->update
);
266 tp
->update_flags
|= TTY_UPDATE_LIST
;
270 * Alloc string for size bytes. If there is not enough room in
271 * freemem, free strings until there is room.
273 static struct string
*
274 tty3270_alloc_string(struct tty3270
*tp
, size_t size
)
276 struct string
*s
, *n
;
278 s
= alloc_string(&tp
->freemem
, size
);
281 list_for_each_entry_safe(s
, n
, &tp
->lines
, list
) {
282 BUG_ON(tp
->nr_lines
<= tp
->view
.rows
- 2);
284 if (!list_empty(&s
->update
))
285 list_del(&s
->update
);
287 if (free_string(&tp
->freemem
, s
) >= size
)
290 s
= alloc_string(&tp
->freemem
, size
);
292 if (tp
->nr_up
!= 0 &&
293 tp
->nr_up
+ tp
->view
.rows
- 2 >= tp
->nr_lines
) {
294 tp
->nr_up
= tp
->nr_lines
- tp
->view
.rows
+ 2;
295 tty3270_rebuild_update(tp
);
296 tty3270_update_status(tp
);
302 * Add an empty line to the list.
305 tty3270_blank_line(struct tty3270
*tp
)
307 static const unsigned char blueprint
[] =
308 { TO_SBA
, 0, 0, TO_SA
, TAT_EXTHI
, TAX_RESET
,
309 TO_SA
, TAT_COLOR
, TAC_RESET
, TO_RA
, 0, 0, 0 };
312 s
= tty3270_alloc_string(tp
, sizeof(blueprint
));
313 memcpy(s
->string
, blueprint
, sizeof(blueprint
));
314 s
->len
= sizeof(blueprint
);
315 list_add_tail(&s
->list
, &tp
->lines
);
322 * Write request completion callback.
325 tty3270_write_callback(struct raw3270_request
*rq
, void *data
)
329 tp
= (struct tty3270
*) rq
->view
;
331 /* Write wasn't successfull. Refresh all. */
332 tp
->update_flags
= TTY_UPDATE_ALL
;
333 tty3270_set_timer(tp
, 1);
335 raw3270_request_reset(rq
);
336 xchg(&tp
->write
, rq
);
340 * Update 3270 display.
343 tty3270_update(struct tty3270
*tp
)
345 static char invalid_sba
[2] = { 0xff, 0xff };
346 struct raw3270_request
*wrq
;
347 unsigned long updated
;
348 struct string
*s
, *n
;
352 wrq
= xchg(&tp
->write
, 0);
354 tty3270_set_timer(tp
, 1);
358 spin_lock(&tp
->view
.lock
);
360 if (tp
->update_flags
& TTY_UPDATE_ALL
) {
361 tty3270_rebuild_update(tp
);
362 tty3270_update_status(tp
);
363 tp
->update_flags
= TTY_UPDATE_ERASE
| TTY_UPDATE_LIST
|
364 TTY_UPDATE_INPUT
| TTY_UPDATE_STATUS
;
366 if (tp
->update_flags
& TTY_UPDATE_ERASE
) {
367 /* Use erase write alternate to erase display. */
368 raw3270_request_set_cmd(wrq
, TC_EWRITEA
);
369 updated
|= TTY_UPDATE_ERASE
;
371 raw3270_request_set_cmd(wrq
, TC_WRITE
);
373 raw3270_request_add_data(wrq
, &tp
->wcc
, 1);
377 * Update status line.
379 if (tp
->update_flags
& TTY_UPDATE_STATUS
)
380 if (raw3270_request_add_data(wrq
, tp
->status
->string
,
381 tp
->status
->len
) == 0)
382 updated
|= TTY_UPDATE_STATUS
;
387 if (tp
->update_flags
& TTY_UPDATE_INPUT
)
388 if (raw3270_request_add_data(wrq
, tp
->prompt
->string
,
389 tp
->prompt
->len
) == 0)
390 updated
|= TTY_UPDATE_INPUT
;
394 if (tp
->update_flags
& TTY_UPDATE_LIST
) {
395 /* Write strings in the update list to the screen. */
396 list_for_each_entry_safe(s
, n
, &tp
->update
, update
) {
400 * Skip TO_SBA at the start of the string if the
401 * last output position matches the start address
404 if (s
->string
[1] == sba
[0] && s
->string
[2] == sba
[1])
406 if (raw3270_request_add_data(wrq
, str
, len
) != 0)
408 list_del_init(&s
->update
);
409 sba
= s
->string
+ s
->len
- 3;
411 if (list_empty(&tp
->update
))
412 updated
|= TTY_UPDATE_LIST
;
414 wrq
->callback
= tty3270_write_callback
;
415 rc
= raw3270_start(&tp
->view
, wrq
);
417 tp
->update_flags
&= ~updated
;
418 if (tp
->update_flags
)
419 tty3270_set_timer(tp
, 1);
421 raw3270_request_reset(wrq
);
422 xchg(&tp
->write
, wrq
);
424 spin_unlock(&tp
->view
.lock
);
431 tty3270_rcl_add(struct tty3270
*tp
, char *input
, int len
)
438 if (tp
->rcl_nr
>= tp
->rcl_max
) {
439 s
= list_entry(tp
->rcl_lines
.next
, struct string
, list
);
441 free_string(&tp
->freemem
, s
);
444 s
= tty3270_alloc_string(tp
, len
);
445 memcpy(s
->string
, input
, len
);
446 list_add_tail(&s
->list
, &tp
->rcl_lines
);
451 tty3270_rcl_backward(struct kbd_data
*kbd
)
456 tp
= kbd
->tty
->driver_data
;
457 spin_lock_bh(&tp
->view
.lock
);
458 if (tp
->inattr
== TF_INPUT
) {
459 if (tp
->rcl_walk
&& tp
->rcl_walk
->prev
!= &tp
->rcl_lines
)
460 tp
->rcl_walk
= tp
->rcl_walk
->prev
;
461 else if (!list_empty(&tp
->rcl_lines
))
462 tp
->rcl_walk
= tp
->rcl_lines
.prev
;
464 list_entry(tp
->rcl_walk
, struct string
, list
) : NULL
;
466 s
= list_entry(tp
->rcl_walk
, struct string
, list
);
467 tty3270_update_prompt(tp
, s
->string
, s
->len
);
469 tty3270_update_prompt(tp
, NULL
, 0);
470 tty3270_set_timer(tp
, 1);
472 spin_unlock_bh(&tp
->view
.lock
);
476 * Deactivate tty view.
479 tty3270_exit_tty(struct kbd_data
*kbd
)
483 tp
= kbd
->tty
->driver_data
;
484 raw3270_deactivate_view(&tp
->view
);
488 * Scroll forward in history.
491 tty3270_scroll_forward(struct kbd_data
*kbd
)
496 tp
= kbd
->tty
->driver_data
;
497 spin_lock_bh(&tp
->view
.lock
);
498 nr_up
= tp
->nr_up
- tp
->view
.rows
+ 2;
501 if (nr_up
!= tp
->nr_up
) {
503 tty3270_rebuild_update(tp
);
504 tty3270_update_status(tp
);
505 tty3270_set_timer(tp
, 1);
507 spin_unlock_bh(&tp
->view
.lock
);
511 * Scroll backward in history.
514 tty3270_scroll_backward(struct kbd_data
*kbd
)
519 tp
= kbd
->tty
->driver_data
;
520 spin_lock_bh(&tp
->view
.lock
);
521 nr_up
= tp
->nr_up
+ tp
->view
.rows
- 2;
522 if (nr_up
+ tp
->view
.rows
- 2 > tp
->nr_lines
)
523 nr_up
= tp
->nr_lines
- tp
->view
.rows
+ 2;
524 if (nr_up
!= tp
->nr_up
) {
526 tty3270_rebuild_update(tp
);
527 tty3270_update_status(tp
);
528 tty3270_set_timer(tp
, 1);
530 spin_unlock_bh(&tp
->view
.lock
);
534 * Pass input line to tty.
537 tty3270_read_tasklet(struct raw3270_request
*rrq
)
539 static char kreset_data
= TW_KR
;
544 tp
= (struct tty3270
*) rrq
->view
;
545 spin_lock_bh(&tp
->view
.lock
);
547 * Two AID keys are special: For 0x7d (enter) the input line
548 * has to be emitted to the tty and for 0x6d the screen
549 * needs to be redrawn.
553 if (tp
->input
->string
[0] == 0x7d) {
554 /* Enter: write input to tty. */
555 input
= tp
->input
->string
+ 6;
556 len
= tp
->input
->len
- 6 - rrq
->rescnt
;
557 if (tp
->inattr
!= TF_INPUTN
)
558 tty3270_rcl_add(tp
, input
, len
);
561 tty3270_rebuild_update(tp
);
562 tty3270_update_status(tp
);
564 /* Clear input area. */
565 tty3270_update_prompt(tp
, NULL
, 0);
566 tty3270_set_timer(tp
, 1);
567 } else if (tp
->input
->string
[0] == 0x6d) {
568 /* Display has been cleared. Redraw. */
569 tp
->update_flags
= TTY_UPDATE_ALL
;
570 tty3270_set_timer(tp
, 1);
572 spin_unlock_bh(&tp
->view
.lock
);
574 /* Start keyboard reset command. */
575 raw3270_request_reset(tp
->kreset
);
576 raw3270_request_set_cmd(tp
->kreset
, TC_WRITE
);
577 raw3270_request_add_data(tp
->kreset
, &kreset_data
, 1);
578 raw3270_start(&tp
->view
, tp
->kreset
);
580 /* Emit input string. */
583 kbd_keycode(tp
->kbd
, *input
++);
584 /* Emit keycode for AID byte. */
585 kbd_keycode(tp
->kbd
, 256 + tp
->input
->string
[0]);
588 raw3270_request_reset(rrq
);
589 xchg(&tp
->read
, rrq
);
590 raw3270_put_view(&tp
->view
);
594 * Read request completion callback.
597 tty3270_read_callback(struct raw3270_request
*rq
, void *data
)
599 raw3270_get_view(rq
->view
);
600 /* Schedule tasklet to pass input to tty. */
601 tasklet_schedule(&((struct tty3270
*) rq
->view
)->readlet
);
605 * Issue a read request. Call with device lock.
608 tty3270_issue_read(struct tty3270
*tp
, int lock
)
610 struct raw3270_request
*rrq
;
613 rrq
= xchg(&tp
->read
, 0);
615 /* Read already scheduled. */
617 rrq
->callback
= tty3270_read_callback
;
618 rrq
->callback_data
= tp
;
619 raw3270_request_set_cmd(rrq
, TC_READMOD
);
620 raw3270_request_set_data(rrq
, tp
->input
->string
, tp
->input
->len
);
621 /* Issue the read modified request. */
623 rc
= raw3270_start(&tp
->view
, rrq
);
625 rc
= raw3270_start_irq(&tp
->view
, rrq
);
627 raw3270_request_reset(rrq
);
628 xchg(&tp
->read
, rrq
);
633 * Switch to the tty view.
636 tty3270_activate(struct raw3270_view
*view
)
640 tp
= (struct tty3270
*) view
;
641 tp
->update_flags
= TTY_UPDATE_ALL
;
642 tty3270_set_timer(tp
, 1);
647 tty3270_deactivate(struct raw3270_view
*view
)
651 tp
= (struct tty3270
*) view
;
652 del_timer(&tp
->timer
);
656 tty3270_irq(struct tty3270
*tp
, struct raw3270_request
*rq
, struct irb
*irb
)
658 /* Handle ATTN. Schedule tasklet to read aid. */
659 if (irb
->scsw
.cmd
.dstat
& DEV_STAT_ATTENTION
) {
661 tty3270_issue_read(tp
, 0);
667 if (irb
->scsw
.cmd
.dstat
& DEV_STAT_UNIT_CHECK
)
670 /* Normal end. Copy residual count. */
671 rq
->rescnt
= irb
->scsw
.cmd
.count
;
673 return RAW3270_IO_DONE
;
677 * Allocate tty3270 structure.
679 static struct tty3270
*
680 tty3270_alloc_view(void)
685 tp
= kzalloc(sizeof(struct tty3270
), GFP_KERNEL
);
689 kmalloc(sizeof(void *) * TTY3270_STRING_PAGES
, GFP_KERNEL
);
690 if (!tp
->freemem_pages
)
692 INIT_LIST_HEAD(&tp
->freemem
);
693 for (pages
= 0; pages
< TTY3270_STRING_PAGES
; pages
++) {
694 tp
->freemem_pages
[pages
] = (void *)
695 __get_free_pages(GFP_KERNEL
|GFP_DMA
, 0);
696 if (!tp
->freemem_pages
[pages
])
698 add_string_memory(&tp
->freemem
,
699 tp
->freemem_pages
[pages
], PAGE_SIZE
);
701 tp
->write
= raw3270_request_alloc(TTY3270_OUTPUT_BUFFER_SIZE
);
702 if (IS_ERR(tp
->write
))
704 tp
->read
= raw3270_request_alloc(0);
705 if (IS_ERR(tp
->read
))
707 tp
->kreset
= raw3270_request_alloc(1);
708 if (IS_ERR(tp
->kreset
))
710 tp
->kbd
= kbd_alloc();
716 raw3270_request_free(tp
->kreset
);
718 raw3270_request_free(tp
->read
);
720 raw3270_request_free(tp
->write
);
723 free_pages((unsigned long) tp
->freemem_pages
[pages
], 0);
724 kfree(tp
->freemem_pages
);
728 return ERR_PTR(-ENOMEM
);
732 * Free tty3270 structure.
735 tty3270_free_view(struct tty3270
*tp
)
739 del_timer_sync(&tp
->timer
);
741 raw3270_request_free(tp
->kreset
);
742 raw3270_request_free(tp
->read
);
743 raw3270_request_free(tp
->write
);
744 for (pages
= 0; pages
< TTY3270_STRING_PAGES
; pages
++)
745 free_pages((unsigned long) tp
->freemem_pages
[pages
], 0);
746 kfree(tp
->freemem_pages
);
751 * Allocate tty3270 screen.
754 tty3270_alloc_screen(struct tty3270
*tp
)
759 size
= sizeof(struct tty3270_line
) * (tp
->view
.rows
- 2);
760 tp
->screen
= kzalloc(size
, GFP_KERNEL
);
763 for (lines
= 0; lines
< tp
->view
.rows
- 2; lines
++) {
764 size
= sizeof(struct tty3270_cell
) * tp
->view
.cols
;
765 tp
->screen
[lines
].cells
= kzalloc(size
, GFP_KERNEL
);
766 if (!tp
->screen
[lines
].cells
)
772 kfree(tp
->screen
[lines
].cells
);
779 * Free tty3270 screen.
782 tty3270_free_screen(struct tty3270
*tp
)
786 for (lines
= 0; lines
< tp
->view
.rows
- 2; lines
++)
787 kfree(tp
->screen
[lines
].cells
);
792 * Unlink tty3270 data structure from tty.
795 tty3270_release(struct raw3270_view
*view
)
798 struct tty_struct
*tty
;
800 tp
= (struct tty3270
*) view
;
803 tty
->driver_data
= NULL
;
804 tp
->tty
= tp
->kbd
->tty
= NULL
;
806 raw3270_put_view(&tp
->view
);
811 * Free tty3270 data structure
814 tty3270_free(struct raw3270_view
*view
)
816 tty3270_free_screen((struct tty3270
*) view
);
817 tty3270_free_view((struct tty3270
*) view
);
821 * Delayed freeing of tty3270 views.
824 tty3270_del_views(void)
829 for (i
= 0; i
< tty3270_max_index
; i
++) {
830 tp
= (struct tty3270
*)
831 raw3270_find_view(&tty3270_fn
, i
+ RAW3270_FIRSTMINOR
);
833 raw3270_del_view(&tp
->view
);
837 static struct raw3270_fn tty3270_fn
= {
838 .activate
= tty3270_activate
,
839 .deactivate
= tty3270_deactivate
,
840 .intv
= (void *) tty3270_irq
,
841 .release
= tty3270_release
,
846 * This routine is called whenever a 3270 tty is opened.
849 tty3270_open(struct tty_struct
*tty
, struct file
* filp
)
856 /* Check if the tty3270 is already there. */
857 tp
= (struct tty3270
*)
858 raw3270_find_view(&tty3270_fn
,
859 tty
->index
+ RAW3270_FIRSTMINOR
);
861 tty
->driver_data
= tp
;
862 tty
->winsize
.ws_row
= tp
->view
.rows
- 2;
863 tty
->winsize
.ws_col
= tp
->view
.cols
;
864 tty
->low_latency
= 0;
867 tp
->inattr
= TF_INPUT
;
870 if (tty3270_max_index
< tty
->index
+ 1)
871 tty3270_max_index
= tty
->index
+ 1;
873 /* Quick exit if there is no device for tty->index. */
874 if (PTR_ERR(tp
) == -ENODEV
)
877 /* Allocate tty3270 structure on first open. */
878 tp
= tty3270_alloc_view();
882 INIT_LIST_HEAD(&tp
->lines
);
883 INIT_LIST_HEAD(&tp
->update
);
884 INIT_LIST_HEAD(&tp
->rcl_lines
);
886 setup_timer(&tp
->timer
, (void (*)(unsigned long)) tty3270_update
,
888 tasklet_init(&tp
->readlet
,
889 (void (*)(unsigned long)) tty3270_read_tasklet
,
890 (unsigned long) tp
->read
);
892 rc
= raw3270_add_view(&tp
->view
, &tty3270_fn
,
893 tty
->index
+ RAW3270_FIRSTMINOR
);
895 tty3270_free_view(tp
);
899 rc
= tty3270_alloc_screen(tp
);
901 raw3270_put_view(&tp
->view
);
902 raw3270_del_view(&tp
->view
);
907 tty
->low_latency
= 0;
908 tty
->driver_data
= tp
;
909 tty
->winsize
.ws_row
= tp
->view
.rows
- 2;
910 tty
->winsize
.ws_col
= tp
->view
.cols
;
912 tty3270_create_prompt(tp
);
913 tty3270_create_status(tp
);
914 tty3270_update_status(tp
);
916 /* Create blank line for every line in the tty output area. */
917 for (i
= 0; i
< tp
->view
.rows
- 2; i
++)
918 tty3270_blank_line(tp
);
921 tp
->kbd
->fn_handler
[KVAL(K_INCRCONSOLE
)] = tty3270_exit_tty
;
922 tp
->kbd
->fn_handler
[KVAL(K_SCROLLBACK
)] = tty3270_scroll_backward
;
923 tp
->kbd
->fn_handler
[KVAL(K_SCROLLFORW
)] = tty3270_scroll_forward
;
924 tp
->kbd
->fn_handler
[KVAL(K_CONS
)] = tty3270_rcl_backward
;
925 kbd_ascebc(tp
->kbd
, tp
->view
.ascebc
);
927 raw3270_activate_view(&tp
->view
);
932 * This routine is called when the 3270 tty is closed. We wait
933 * for the remaining request to be completed. Then we clean up.
936 tty3270_close(struct tty_struct
*tty
, struct file
* filp
)
942 tp
= (struct tty3270
*) tty
->driver_data
;
944 tty
->driver_data
= NULL
;
945 tp
->tty
= tp
->kbd
->tty
= NULL
;
946 raw3270_put_view(&tp
->view
);
951 * We always have room.
954 tty3270_write_room(struct tty_struct
*tty
)
960 * Insert character into the screen at the current position with the
961 * current color and highlight. This function does NOT do cursor movement.
963 static void tty3270_put_character(struct tty3270
*tp
, char ch
)
965 struct tty3270_line
*line
;
966 struct tty3270_cell
*cell
;
968 line
= tp
->screen
+ tp
->cy
;
969 if (line
->len
<= tp
->cx
) {
970 while (line
->len
< tp
->cx
) {
971 cell
= line
->cells
+ line
->len
;
972 cell
->character
= tp
->view
.ascebc
[' '];
973 cell
->highlight
= tp
->highlight
;
974 cell
->f_color
= tp
->f_color
;
979 cell
= line
->cells
+ tp
->cx
;
980 cell
->character
= tp
->view
.ascebc
[(unsigned int) ch
];
981 cell
->highlight
= tp
->highlight
;
982 cell
->f_color
= tp
->f_color
;
986 * Convert a tty3270_line to a 3270 data fragment usable for output.
989 tty3270_convert_line(struct tty3270
*tp
, int line_nr
)
991 struct tty3270_line
*line
;
992 struct tty3270_cell
*cell
;
993 struct string
*s
, *n
;
994 unsigned char highlight
;
995 unsigned char f_color
;
999 /* Determine how long the fragment will be. */
1000 flen
= 3; /* Prefix (TO_SBA). */
1001 line
= tp
->screen
+ line_nr
;
1003 highlight
= TAX_RESET
;
1004 f_color
= TAC_RESET
;
1005 for (i
= 0, cell
= line
->cells
; i
< line
->len
; i
++, cell
++) {
1006 if (cell
->highlight
!= highlight
) {
1007 flen
+= 3; /* TO_SA to switch highlight. */
1008 highlight
= cell
->highlight
;
1010 if (cell
->f_color
!= f_color
) {
1011 flen
+= 3; /* TO_SA to switch color. */
1012 f_color
= cell
->f_color
;
1015 if (highlight
!= TAX_RESET
)
1016 flen
+= 3; /* TO_SA to reset hightlight. */
1017 if (f_color
!= TAC_RESET
)
1018 flen
+= 3; /* TO_SA to reset color. */
1019 if (line
->len
< tp
->view
.cols
)
1020 flen
+= 4; /* Postfix (TO_RA). */
1022 /* Find the line in the list. */
1023 i
= tp
->view
.rows
- 2 - line_nr
;
1024 list_for_each_entry_reverse(s
, &tp
->lines
, list
)
1028 * Check if the line needs to get reallocated.
1030 if (s
->len
!= flen
) {
1031 /* Reallocate string. */
1032 n
= tty3270_alloc_string(tp
, flen
);
1033 list_add(&n
->list
, &s
->list
);
1034 list_del_init(&s
->list
);
1035 if (!list_empty(&s
->update
))
1036 list_del_init(&s
->update
);
1037 free_string(&tp
->freemem
, s
);
1041 /* Write 3270 data fragment. */
1047 highlight
= TAX_RESET
;
1048 f_color
= TAC_RESET
;
1049 for (i
= 0, cell
= line
->cells
; i
< line
->len
; i
++, cell
++) {
1050 if (cell
->highlight
!= highlight
) {
1053 *cp
++ = cell
->highlight
;
1054 highlight
= cell
->highlight
;
1056 if (cell
->f_color
!= f_color
) {
1059 *cp
++ = cell
->f_color
;
1060 f_color
= cell
->f_color
;
1062 *cp
++ = cell
->character
;
1064 if (highlight
!= TAX_RESET
) {
1069 if (f_color
!= TAC_RESET
) {
1074 if (line
->len
< tp
->view
.cols
) {
1081 if (tp
->nr_up
+ line_nr
< tp
->view
.rows
- 2) {
1082 /* Line is currently visible on screen. */
1083 tty3270_update_string(tp
, s
, line_nr
);
1084 /* Add line to update list. */
1085 if (list_empty(&s
->update
)) {
1086 list_add_tail(&s
->update
, &tp
->update
);
1087 tp
->update_flags
|= TTY_UPDATE_LIST
;
1093 * Do carriage return.
1096 tty3270_cr(struct tty3270
*tp
)
1105 tty3270_lf(struct tty3270
*tp
)
1107 struct tty3270_line temp
;
1110 tty3270_convert_line(tp
, tp
->cy
);
1111 if (tp
->cy
< tp
->view
.rows
- 3) {
1115 /* Last line just filled up. Add new, blank line. */
1116 tty3270_blank_line(tp
);
1117 temp
= tp
->screen
[0];
1119 for (i
= 0; i
< tp
->view
.rows
- 3; i
++)
1120 tp
->screen
[i
] = tp
->screen
[i
+1];
1121 tp
->screen
[tp
->view
.rows
- 3] = temp
;
1122 tty3270_rebuild_update(tp
);
1126 tty3270_ri(struct tty3270
*tp
)
1129 tty3270_convert_line(tp
, tp
->cy
);
1135 * Insert characters at current position.
1138 tty3270_insert_characters(struct tty3270
*tp
, int n
)
1140 struct tty3270_line
*line
;
1143 line
= tp
->screen
+ tp
->cy
;
1144 while (line
->len
< tp
->cx
) {
1145 line
->cells
[line
->len
].character
= tp
->view
.ascebc
[' '];
1146 line
->cells
[line
->len
].highlight
= TAX_RESET
;
1147 line
->cells
[line
->len
].f_color
= TAC_RESET
;
1150 if (n
> tp
->view
.cols
- tp
->cx
)
1151 n
= tp
->view
.cols
- tp
->cx
;
1152 k
= min_t(int, line
->len
- tp
->cx
, tp
->view
.cols
- tp
->cx
- n
);
1154 line
->cells
[tp
->cx
+ n
+ k
] = line
->cells
[tp
->cx
+ k
];
1156 if (line
->len
> tp
->view
.cols
)
1157 line
->len
= tp
->view
.cols
;
1159 line
->cells
[tp
->cx
+ n
].character
= tp
->view
.ascebc
[' '];
1160 line
->cells
[tp
->cx
+ n
].highlight
= tp
->highlight
;
1161 line
->cells
[tp
->cx
+ n
].f_color
= tp
->f_color
;
1166 * Delete characters at current position.
1169 tty3270_delete_characters(struct tty3270
*tp
, int n
)
1171 struct tty3270_line
*line
;
1174 line
= tp
->screen
+ tp
->cy
;
1175 if (line
->len
<= tp
->cx
)
1177 if (line
->len
- tp
->cx
<= n
) {
1181 for (i
= tp
->cx
; i
+ n
< line
->len
; i
++)
1182 line
->cells
[i
] = line
->cells
[i
+ n
];
1187 * Erase characters at current position.
1190 tty3270_erase_characters(struct tty3270
*tp
, int n
)
1192 struct tty3270_line
*line
;
1193 struct tty3270_cell
*cell
;
1195 line
= tp
->screen
+ tp
->cy
;
1196 while (line
->len
> tp
->cx
&& n
-- > 0) {
1197 cell
= line
->cells
+ tp
->cx
++;
1198 cell
->character
= ' ';
1199 cell
->highlight
= TAX_RESET
;
1200 cell
->f_color
= TAC_RESET
;
1203 tp
->cx
= min_t(int, tp
->cx
, tp
->view
.cols
- 1);
1207 * Erase line, 3 different cases:
1208 * Esc [ 0 K Erase from current position to end of line inclusive
1209 * Esc [ 1 K Erase from beginning of line to current position inclusive
1210 * Esc [ 2 K Erase entire line (without moving cursor)
1213 tty3270_erase_line(struct tty3270
*tp
, int mode
)
1215 struct tty3270_line
*line
;
1216 struct tty3270_cell
*cell
;
1219 line
= tp
->screen
+ tp
->cy
;
1222 else if (mode
== 1) {
1223 for (i
= 0; i
< tp
->cx
; i
++) {
1224 cell
= line
->cells
+ i
;
1225 cell
->character
= ' ';
1226 cell
->highlight
= TAX_RESET
;
1227 cell
->f_color
= TAC_RESET
;
1229 if (line
->len
<= tp
->cx
)
1230 line
->len
= tp
->cx
+ 1;
1231 } else if (mode
== 2)
1233 tty3270_convert_line(tp
, tp
->cy
);
1237 * Erase display, 3 different cases:
1238 * Esc [ 0 J Erase from current position to bottom of screen inclusive
1239 * Esc [ 1 J Erase from top of screen to current position inclusive
1240 * Esc [ 2 J Erase entire screen (without moving the cursor)
1243 tty3270_erase_display(struct tty3270
*tp
, int mode
)
1248 tty3270_erase_line(tp
, 0);
1249 for (i
= tp
->cy
+ 1; i
< tp
->view
.rows
- 2; i
++) {
1250 tp
->screen
[i
].len
= 0;
1251 tty3270_convert_line(tp
, i
);
1253 } else if (mode
== 1) {
1254 for (i
= 0; i
< tp
->cy
; i
++) {
1255 tp
->screen
[i
].len
= 0;
1256 tty3270_convert_line(tp
, i
);
1258 tty3270_erase_line(tp
, 1);
1259 } else if (mode
== 2) {
1260 for (i
= 0; i
< tp
->view
.rows
- 2; i
++) {
1261 tp
->screen
[i
].len
= 0;
1262 tty3270_convert_line(tp
, i
);
1265 tty3270_rebuild_update(tp
);
1269 * Set attributes found in an escape sequence.
1270 * Esc [ <attr> ; <attr> ; ... m
1273 tty3270_set_attributes(struct tty3270
*tp
)
1275 static unsigned char f_colors
[] = {
1276 TAC_DEFAULT
, TAC_RED
, TAC_GREEN
, TAC_YELLOW
, TAC_BLUE
,
1277 TAC_PINK
, TAC_TURQ
, TAC_WHITE
, 0, TAC_DEFAULT
1281 for (i
= 0; i
<= tp
->esc_npar
; i
++) {
1282 attr
= tp
->esc_par
[i
];
1285 tp
->highlight
= TAX_RESET
;
1286 tp
->f_color
= TAC_RESET
;
1289 case 4: /* Start underlining. */
1290 tp
->highlight
= TAX_UNDER
;
1292 case 5: /* Start blink. */
1293 tp
->highlight
= TAX_BLINK
;
1295 case 7: /* Start reverse. */
1296 tp
->highlight
= TAX_REVER
;
1298 case 24: /* End underlining */
1299 if (tp
->highlight
== TAX_UNDER
)
1300 tp
->highlight
= TAX_RESET
;
1302 case 25: /* End blink. */
1303 if (tp
->highlight
== TAX_BLINK
)
1304 tp
->highlight
= TAX_RESET
;
1306 case 27: /* End reverse. */
1307 if (tp
->highlight
== TAX_REVER
)
1308 tp
->highlight
= TAX_RESET
;
1310 /* Foreground color. */
1311 case 30: /* Black */
1313 case 32: /* Green */
1314 case 33: /* Yellow */
1316 case 35: /* Magenta */
1318 case 37: /* White */
1319 case 39: /* Black */
1320 tp
->f_color
= f_colors
[attr
- 30];
1327 tty3270_getpar(struct tty3270
*tp
, int ix
)
1329 return (tp
->esc_par
[ix
] > 0) ? tp
->esc_par
[ix
] : 1;
1333 tty3270_goto_xy(struct tty3270
*tp
, int cx
, int cy
)
1335 int max_cx
= max(0, cx
);
1336 int max_cy
= max(0, cy
);
1338 tp
->cx
= min_t(int, tp
->view
.cols
- 1, max_cx
);
1339 cy
= min_t(int, tp
->view
.rows
- 3, max_cy
);
1341 tty3270_convert_line(tp
, tp
->cy
);
1347 * Process escape sequences. Known sequences:
1348 * Esc 7 Save Cursor Position
1349 * Esc 8 Restore Cursor Position
1350 * Esc [ Pn ; Pn ; .. m Set attributes
1351 * Esc [ Pn ; Pn H Cursor Position
1352 * Esc [ Pn ; Pn f Cursor Position
1353 * Esc [ Pn A Cursor Up
1354 * Esc [ Pn B Cursor Down
1355 * Esc [ Pn C Cursor Forward
1356 * Esc [ Pn D Cursor Backward
1357 * Esc [ Pn G Cursor Horizontal Absolute
1358 * Esc [ Pn X Erase Characters
1359 * Esc [ Ps J Erase in Display
1360 * Esc [ Ps K Erase in Line
1361 * // FIXME: add all the new ones.
1363 * Pn is a numeric parameter, a string of zero or more decimal digits.
1364 * Ps is a selective parameter.
1367 tty3270_escape_sequence(struct tty3270
*tp
, char ch
)
1369 enum { ESnormal
, ESesc
, ESsquare
, ESgetpars
};
1371 if (tp
->esc_state
== ESnormal
) {
1373 /* Starting new escape sequence. */
1374 tp
->esc_state
= ESesc
;
1377 if (tp
->esc_state
== ESesc
) {
1378 tp
->esc_state
= ESnormal
;
1381 tp
->esc_state
= ESsquare
;
1393 case 'Z': /* Respond ID. */
1394 kbd_puts_queue(tp
->tty
, "\033[?6c");
1396 case '7': /* Save cursor position. */
1397 tp
->saved_cx
= tp
->cx
;
1398 tp
->saved_cy
= tp
->cy
;
1399 tp
->saved_highlight
= tp
->highlight
;
1400 tp
->saved_f_color
= tp
->f_color
;
1402 case '8': /* Restore cursor position. */
1403 tty3270_convert_line(tp
, tp
->cy
);
1404 tty3270_goto_xy(tp
, tp
->saved_cx
, tp
->saved_cy
);
1405 tp
->highlight
= tp
->saved_highlight
;
1406 tp
->f_color
= tp
->saved_f_color
;
1408 case 'c': /* Reset terminal. */
1409 tp
->cx
= tp
->saved_cx
= 0;
1410 tp
->cy
= tp
->saved_cy
= 0;
1411 tp
->highlight
= tp
->saved_highlight
= TAX_RESET
;
1412 tp
->f_color
= tp
->saved_f_color
= TAC_RESET
;
1413 tty3270_erase_display(tp
, 2);
1418 if (tp
->esc_state
== ESsquare
) {
1419 tp
->esc_state
= ESgetpars
;
1420 memset(tp
->esc_par
, 0, sizeof(tp
->esc_par
));
1422 tp
->esc_ques
= (ch
== '?');
1426 if (tp
->esc_state
== ESgetpars
) {
1427 if (ch
== ';' && tp
->esc_npar
< ESCAPE_NPAR
- 1) {
1431 if (ch
>= '0' && ch
<= '9') {
1432 tp
->esc_par
[tp
->esc_npar
] *= 10;
1433 tp
->esc_par
[tp
->esc_npar
] += ch
- '0';
1437 tp
->esc_state
= ESnormal
;
1438 if (ch
== 'n' && !tp
->esc_ques
) {
1439 if (tp
->esc_par
[0] == 5) /* Status report. */
1440 kbd_puts_queue(tp
->tty
, "\033[0n");
1441 else if (tp
->esc_par
[0] == 6) { /* Cursor report. */
1443 sprintf(buf
, "\033[%d;%dR", tp
->cy
+ 1, tp
->cx
+ 1);
1444 kbd_puts_queue(tp
->tty
, buf
);
1452 tty3270_set_attributes(tp
);
1454 case 'H': /* Set cursor position. */
1456 tty3270_goto_xy(tp
, tty3270_getpar(tp
, 1) - 1,
1457 tty3270_getpar(tp
, 0) - 1);
1459 case 'd': /* Set y position. */
1460 tty3270_goto_xy(tp
, tp
->cx
, tty3270_getpar(tp
, 0) - 1);
1462 case 'A': /* Cursor up. */
1464 tty3270_goto_xy(tp
, tp
->cx
, tp
->cy
- tty3270_getpar(tp
, 0));
1466 case 'B': /* Cursor down. */
1469 tty3270_goto_xy(tp
, tp
->cx
, tp
->cy
+ tty3270_getpar(tp
, 0));
1471 case 'C': /* Cursor forward. */
1473 tty3270_goto_xy(tp
, tp
->cx
+ tty3270_getpar(tp
, 0), tp
->cy
);
1475 case 'D': /* Cursor backward. */
1476 tty3270_goto_xy(tp
, tp
->cx
- tty3270_getpar(tp
, 0), tp
->cy
);
1478 case 'G': /* Set x position. */
1480 tty3270_goto_xy(tp
, tty3270_getpar(tp
, 0), tp
->cy
);
1482 case 'X': /* Erase Characters. */
1483 tty3270_erase_characters(tp
, tty3270_getpar(tp
, 0));
1485 case 'J': /* Erase display. */
1486 tty3270_erase_display(tp
, tp
->esc_par
[0]);
1488 case 'K': /* Erase line. */
1489 tty3270_erase_line(tp
, tp
->esc_par
[0]);
1491 case 'P': /* Delete characters. */
1492 tty3270_delete_characters(tp
, tty3270_getpar(tp
, 0));
1494 case '@': /* Insert characters. */
1495 tty3270_insert_characters(tp
, tty3270_getpar(tp
, 0));
1497 case 's': /* Save cursor position. */
1498 tp
->saved_cx
= tp
->cx
;
1499 tp
->saved_cy
= tp
->cy
;
1500 tp
->saved_highlight
= tp
->highlight
;
1501 tp
->saved_f_color
= tp
->f_color
;
1503 case 'u': /* Restore cursor position. */
1504 tty3270_convert_line(tp
, tp
->cy
);
1505 tty3270_goto_xy(tp
, tp
->saved_cx
, tp
->saved_cy
);
1506 tp
->highlight
= tp
->saved_highlight
;
1507 tp
->f_color
= tp
->saved_f_color
;
1513 * String write routine for 3270 ttys
1516 tty3270_do_write(struct tty3270
*tp
, const unsigned char *buf
, int count
)
1520 spin_lock_bh(&tp
->view
.lock
);
1521 for (i_msg
= 0; !tp
->tty
->stopped
&& i_msg
< count
; i_msg
++) {
1522 if (tp
->esc_state
!= 0) {
1523 /* Continue escape sequence. */
1524 tty3270_escape_sequence(tp
, buf
[i_msg
]);
1528 switch (buf
[i_msg
]) {
1529 case 0x07: /* '\a' -- Alarm */
1530 tp
->wcc
|= TW_PLUSALARM
;
1532 case 0x08: /* Backspace. */
1535 tty3270_put_character(tp
, ' ');
1538 case 0x09: /* '\t' -- Tabulate */
1539 for (i
= tp
->cx
% 8; i
< 8; i
++) {
1540 if (tp
->cx
>= tp
->view
.cols
) {
1545 tty3270_put_character(tp
, ' ');
1549 case 0x0a: /* '\n' -- New Line */
1553 case 0x0c: /* '\f' -- Form Feed */
1554 tty3270_erase_display(tp
, 2);
1555 tp
->cx
= tp
->cy
= 0;
1557 case 0x0d: /* '\r' -- Carriage Return */
1560 case 0x0f: /* SuSE "exit alternate mode" */
1562 case 0x1b: /* Start escape sequence. */
1563 tty3270_escape_sequence(tp
, buf
[i_msg
]);
1565 default: /* Insert normal character. */
1566 if (tp
->cx
>= tp
->view
.cols
) {
1570 tty3270_put_character(tp
, buf
[i_msg
]);
1575 /* Convert current line to 3270 data fragment. */
1576 tty3270_convert_line(tp
, tp
->cy
);
1578 /* Setup timer to update display after 1/10 second */
1579 if (!timer_pending(&tp
->timer
))
1580 tty3270_set_timer(tp
, HZ
/10);
1582 spin_unlock_bh(&tp
->view
.lock
);
1586 * String write routine for 3270 ttys
1589 tty3270_write(struct tty_struct
* tty
,
1590 const unsigned char *buf
, int count
)
1594 tp
= tty
->driver_data
;
1597 if (tp
->char_count
> 0) {
1598 tty3270_do_write(tp
, tp
->char_buf
, tp
->char_count
);
1601 tty3270_do_write(tp
, buf
, count
);
1606 * Put single characters to the ttys character buffer
1608 static int tty3270_put_char(struct tty_struct
*tty
, unsigned char ch
)
1612 tp
= tty
->driver_data
;
1613 if (!tp
|| tp
->char_count
>= TTY3270_CHAR_BUF_SIZE
)
1615 tp
->char_buf
[tp
->char_count
++] = ch
;
1620 * Flush all characters from the ttys characeter buffer put there
1621 * by tty3270_put_char.
1624 tty3270_flush_chars(struct tty_struct
*tty
)
1628 tp
= tty
->driver_data
;
1631 if (tp
->char_count
> 0) {
1632 tty3270_do_write(tp
, tp
->char_buf
, tp
->char_count
);
1638 * Returns the number of characters in the output buffer. This is
1639 * used in tty_wait_until_sent to wait until all characters have
1640 * appeared on the screen.
1643 tty3270_chars_in_buffer(struct tty_struct
*tty
)
1649 tty3270_flush_buffer(struct tty_struct
*tty
)
1654 * Check for visible/invisible input switches
1657 tty3270_set_termios(struct tty_struct
*tty
, struct ktermios
*old
)
1662 tp
= tty
->driver_data
;
1665 spin_lock_bh(&tp
->view
.lock
);
1666 if (L_ICANON(tty
)) {
1667 new = L_ECHO(tty
) ? TF_INPUT
: TF_INPUTN
;
1668 if (new != tp
->inattr
) {
1670 tty3270_update_prompt(tp
, NULL
, 0);
1671 tty3270_set_timer(tp
, 1);
1674 spin_unlock_bh(&tp
->view
.lock
);
1678 * Disable reading from a 3270 tty
1681 tty3270_throttle(struct tty_struct
* tty
)
1685 tp
= tty
->driver_data
;
1692 * Enable reading from a 3270 tty
1695 tty3270_unthrottle(struct tty_struct
* tty
)
1699 tp
= tty
->driver_data
;
1704 tty3270_issue_read(tp
, 1);
1708 * Hang up the tty device.
1711 tty3270_hangup(struct tty_struct
*tty
)
1717 tty3270_wait_until_sent(struct tty_struct
*tty
, int timeout
)
1722 tty3270_ioctl(struct tty_struct
*tty
, struct file
*file
,
1723 unsigned int cmd
, unsigned long arg
)
1727 tp
= tty
->driver_data
;
1730 if (tty
->flags
& (1 << TTY_IO_ERROR
))
1732 return kbd_ioctl(tp
->kbd
, file
, cmd
, arg
);
1735 #ifdef CONFIG_COMPAT
1737 tty3270_compat_ioctl(struct tty_struct
*tty
, struct file
*file
,
1738 unsigned int cmd
, unsigned long arg
)
1742 tp
= tty
->driver_data
;
1745 if (tty
->flags
& (1 << TTY_IO_ERROR
))
1747 return kbd_ioctl(tp
->kbd
, file
, cmd
, (unsigned long)compat_ptr(arg
));
1751 static const struct tty_operations tty3270_ops
= {
1752 .open
= tty3270_open
,
1753 .close
= tty3270_close
,
1754 .write
= tty3270_write
,
1755 .put_char
= tty3270_put_char
,
1756 .flush_chars
= tty3270_flush_chars
,
1757 .write_room
= tty3270_write_room
,
1758 .chars_in_buffer
= tty3270_chars_in_buffer
,
1759 .flush_buffer
= tty3270_flush_buffer
,
1760 .throttle
= tty3270_throttle
,
1761 .unthrottle
= tty3270_unthrottle
,
1762 .hangup
= tty3270_hangup
,
1763 .wait_until_sent
= tty3270_wait_until_sent
,
1764 .ioctl
= tty3270_ioctl
,
1765 #ifdef CONFIG_COMPAT
1766 .compat_ioctl
= tty3270_compat_ioctl
,
1768 .set_termios
= tty3270_set_termios
1772 * 3270 tty registration code called from tty_init().
1773 * Most kernel services (incl. kmalloc) are available at this poimt.
1775 static int __init
tty3270_init(void)
1777 struct tty_driver
*driver
;
1780 driver
= alloc_tty_driver(RAW3270_MAXDEVS
);
1785 * Initialize the tty_driver structure
1786 * Entries in tty3270_driver that are NOT initialized:
1787 * proc_entry, set_termios, flush_buffer, set_ldisc, write_proc
1789 driver
->owner
= THIS_MODULE
;
1790 driver
->driver_name
= "ttyTUB";
1791 driver
->name
= "ttyTUB";
1792 driver
->major
= IBM_TTY3270_MAJOR
;
1793 driver
->minor_start
= RAW3270_FIRSTMINOR
;
1794 driver
->type
= TTY_DRIVER_TYPE_SYSTEM
;
1795 driver
->subtype
= SYSTEM_TYPE_TTY
;
1796 driver
->init_termios
= tty_std_termios
;
1797 driver
->flags
= TTY_DRIVER_RESET_TERMIOS
| TTY_DRIVER_DYNAMIC_DEV
;
1798 tty_set_operations(driver
, &tty3270_ops
);
1799 ret
= tty_register_driver(driver
);
1801 put_tty_driver(driver
);
1804 tty3270_driver
= driver
;
1811 struct tty_driver
*driver
;
1813 driver
= tty3270_driver
;
1814 tty3270_driver
= NULL
;
1815 tty_unregister_driver(driver
);
1816 tty3270_del_views();
1819 MODULE_LICENSE("GPL");
1820 MODULE_ALIAS_CHARDEV_MAJOR(IBM_TTY3270_MAJOR
);
1822 module_init(tty3270_init
);
1823 module_exit(tty3270_exit
);