2 * IBM/3270 Driver - tty functions.
5 * Original 3270 Code for 2.4 written by Richard Hitt (UTS Global)
6 * Rewritten for 2.5 by Martin Schwidefsky <schwidefsky@de.ibm.com>
7 * -- Copyright IBM Corp. 2003
10 #include <linux/module.h>
11 #include <linux/types.h>
12 #include <linux/kdev_t.h>
13 #include <linux/tty.h>
14 #include <linux/vt_kern.h>
15 #include <linux/init.h>
16 #include <linux/console.h>
17 #include <linux/interrupt.h>
18 #include <linux/workqueue.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;
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;
84 unsigned int n_model, n_cols, n_rows; /* New model & size */
85 struct work_struct resize_work;
88 struct string *prompt; /* Output string for input area. */
89 struct string *input; /* Input string for read request. */
90 struct raw3270_request *read; /* Single read request. */
91 struct raw3270_request *kreset; /* Single keyboard reset request. */
92 unsigned char inattr; /* Visible/invisible input. */
93 int throttle, attn; /* tty throttle/unthrottle. */
94 struct tasklet_struct readlet; /* Tasklet to issue read request. */
95 struct kbd_data *kbd; /* key_maps stuff. */
97 /* Escape sequence parsing. */
98 int esc_state, esc_ques, esc_npar;
99 int esc_par[ESCAPE_NPAR];
100 unsigned int saved_cx, saved_cy;
101 unsigned int saved_highlight, saved_f_color;
103 /* Command recalling. */
104 struct list_head rcl_lines; /* List of recallable lines. */
105 struct list_head *rcl_walk; /* Point in rcl_lines list. */
106 int rcl_nr, rcl_max; /* Number/max number of rcl_lines. */
108 /* Character array for put_char/flush_chars. */
109 unsigned int char_count;
110 char char_buf[TTY3270_CHAR_BUF_SIZE];
113 /* tty3270->update_flags. See tty3270_update for details. */
114 #define TTY_UPDATE_ERASE 1 /* Use EWRITEA instead of WRITE. */
115 #define TTY_UPDATE_LIST 2 /* Update lines in tty3270->update. */
116 #define TTY_UPDATE_INPUT 4 /* Update input line. */
117 #define TTY_UPDATE_STATUS 8 /* Update status line. */
118 #define TTY_UPDATE_ALL 16 /* Recreate screen. */
120 static void tty3270_update(struct tty3270 *);
121 static void tty3270_resize_work(struct work_struct *work);
124 * Setup timeout for a device. On timeout trigger an update.
126 static void tty3270_set_timer(struct tty3270 *tp, int expires)
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)
327 struct tty3270 *tp = container_of(rq->view, struct tty3270, view);
330 /* Write wasn't successful. Refresh all. */
331 tp->update_flags = TTY_UPDATE_ALL;
332 tty3270_set_timer(tp, 1);
334 raw3270_request_reset(rq);
335 xchg(&tp->write, rq);
339 * Update 3270 display.
342 tty3270_update(struct tty3270 *tp)
344 static char invalid_sba[2] = { 0xff, 0xff };
345 struct raw3270_request *wrq;
346 unsigned long updated;
347 struct string *s, *n;
351 wrq = xchg(&tp->write, 0);
353 tty3270_set_timer(tp, 1);
357 spin_lock(&tp->view.lock);
359 if (tp->update_flags & TTY_UPDATE_ALL) {
360 tty3270_rebuild_update(tp);
361 tty3270_update_status(tp);
362 tp->update_flags = TTY_UPDATE_ERASE | TTY_UPDATE_LIST |
363 TTY_UPDATE_INPUT | TTY_UPDATE_STATUS;
365 if (tp->update_flags & TTY_UPDATE_ERASE) {
366 /* Use erase write alternate to erase display. */
367 raw3270_request_set_cmd(wrq, TC_EWRITEA);
368 updated |= TTY_UPDATE_ERASE;
370 raw3270_request_set_cmd(wrq, TC_WRITE);
372 raw3270_request_add_data(wrq, &tp->wcc, 1);
376 * Update status line.
378 if (tp->update_flags & TTY_UPDATE_STATUS)
379 if (raw3270_request_add_data(wrq, tp->status->string,
380 tp->status->len) == 0)
381 updated |= TTY_UPDATE_STATUS;
386 if (tp->update_flags & TTY_UPDATE_INPUT)
387 if (raw3270_request_add_data(wrq, tp->prompt->string,
388 tp->prompt->len) == 0)
389 updated |= TTY_UPDATE_INPUT;
393 if (tp->update_flags & TTY_UPDATE_LIST) {
394 /* Write strings in the update list to the screen. */
395 list_for_each_entry_safe(s, n, &tp->update, update) {
399 * Skip TO_SBA at the start of the string if the
400 * last output position matches the start address
403 if (s->string[1] == sba[0] && s->string[2] == sba[1])
405 if (raw3270_request_add_data(wrq, str, len) != 0)
407 list_del_init(&s->update);
408 sba = s->string + s->len - 3;
410 if (list_empty(&tp->update))
411 updated |= TTY_UPDATE_LIST;
413 wrq->callback = tty3270_write_callback;
414 rc = raw3270_start(&tp->view, wrq);
416 tp->update_flags &= ~updated;
417 if (tp->update_flags)
418 tty3270_set_timer(tp, 1);
420 raw3270_request_reset(wrq);
421 xchg(&tp->write, wrq);
423 spin_unlock(&tp->view.lock);
430 tty3270_rcl_add(struct tty3270 *tp, char *input, int len)
437 if (tp->rcl_nr >= tp->rcl_max) {
438 s = list_entry(tp->rcl_lines.next, struct string, list);
440 free_string(&tp->freemem, s);
443 s = tty3270_alloc_string(tp, len);
444 memcpy(s->string, input, len);
445 list_add_tail(&s->list, &tp->rcl_lines);
450 tty3270_rcl_backward(struct kbd_data *kbd)
452 struct tty3270 *tp = container_of(kbd->port, struct tty3270, port);
455 spin_lock_bh(&tp->view.lock);
456 if (tp->inattr == TF_INPUT) {
457 if (tp->rcl_walk && tp->rcl_walk->prev != &tp->rcl_lines)
458 tp->rcl_walk = tp->rcl_walk->prev;
459 else if (!list_empty(&tp->rcl_lines))
460 tp->rcl_walk = tp->rcl_lines.prev;
462 list_entry(tp->rcl_walk, struct string, list) : NULL;
464 s = list_entry(tp->rcl_walk, struct string, list);
465 tty3270_update_prompt(tp, s->string, s->len);
467 tty3270_update_prompt(tp, NULL, 0);
468 tty3270_set_timer(tp, 1);
470 spin_unlock_bh(&tp->view.lock);
474 * Deactivate tty view.
477 tty3270_exit_tty(struct kbd_data *kbd)
479 struct tty3270 *tp = container_of(kbd->port, struct tty3270, port);
481 raw3270_deactivate_view(&tp->view);
485 * Scroll forward in history.
488 tty3270_scroll_forward(struct kbd_data *kbd)
490 struct tty3270 *tp = container_of(kbd->port, struct tty3270, port);
493 spin_lock_bh(&tp->view.lock);
494 nr_up = tp->nr_up - tp->view.rows + 2;
497 if (nr_up != tp->nr_up) {
499 tty3270_rebuild_update(tp);
500 tty3270_update_status(tp);
501 tty3270_set_timer(tp, 1);
503 spin_unlock_bh(&tp->view.lock);
507 * Scroll backward in history.
510 tty3270_scroll_backward(struct kbd_data *kbd)
512 struct tty3270 *tp = container_of(kbd->port, struct tty3270, port);
515 spin_lock_bh(&tp->view.lock);
516 nr_up = tp->nr_up + tp->view.rows - 2;
517 if (nr_up + tp->view.rows - 2 > tp->nr_lines)
518 nr_up = tp->nr_lines - tp->view.rows + 2;
519 if (nr_up != tp->nr_up) {
521 tty3270_rebuild_update(tp);
522 tty3270_update_status(tp);
523 tty3270_set_timer(tp, 1);
525 spin_unlock_bh(&tp->view.lock);
529 * Pass input line to tty.
532 tty3270_read_tasklet(struct raw3270_request *rrq)
534 static char kreset_data = TW_KR;
535 struct tty3270 *tp = container_of(rrq->view, struct tty3270, view);
539 spin_lock_bh(&tp->view.lock);
541 * Two AID keys are special: For 0x7d (enter) the input line
542 * has to be emitted to the tty and for 0x6d the screen
543 * needs to be redrawn.
547 if (tp->input->string[0] == 0x7d) {
548 /* Enter: write input to tty. */
549 input = tp->input->string + 6;
550 len = tp->input->len - 6 - rrq->rescnt;
551 if (tp->inattr != TF_INPUTN)
552 tty3270_rcl_add(tp, input, len);
555 tty3270_rebuild_update(tp);
556 tty3270_update_status(tp);
558 /* Clear input area. */
559 tty3270_update_prompt(tp, NULL, 0);
560 tty3270_set_timer(tp, 1);
561 } else if (tp->input->string[0] == 0x6d) {
562 /* Display has been cleared. Redraw. */
563 tp->update_flags = TTY_UPDATE_ALL;
564 tty3270_set_timer(tp, 1);
566 spin_unlock_bh(&tp->view.lock);
568 /* Start keyboard reset command. */
569 raw3270_request_reset(tp->kreset);
570 raw3270_request_set_cmd(tp->kreset, TC_WRITE);
571 raw3270_request_add_data(tp->kreset, &kreset_data, 1);
572 raw3270_start(&tp->view, tp->kreset);
575 kbd_keycode(tp->kbd, *input++);
576 /* Emit keycode for AID byte. */
577 kbd_keycode(tp->kbd, 256 + tp->input->string[0]);
579 raw3270_request_reset(rrq);
580 xchg(&tp->read, rrq);
581 raw3270_put_view(&tp->view);
585 * Read request completion callback.
588 tty3270_read_callback(struct raw3270_request *rq, void *data)
590 struct tty3270 *tp = container_of(rq->view, struct tty3270, view);
591 raw3270_get_view(rq->view);
592 /* Schedule tasklet to pass input to tty. */
593 tasklet_schedule(&tp->readlet);
597 * Issue a read request. Call with device lock.
600 tty3270_issue_read(struct tty3270 *tp, int lock)
602 struct raw3270_request *rrq;
605 rrq = xchg(&tp->read, 0);
607 /* Read already scheduled. */
609 rrq->callback = tty3270_read_callback;
610 rrq->callback_data = tp;
611 raw3270_request_set_cmd(rrq, TC_READMOD);
612 raw3270_request_set_data(rrq, tp->input->string, tp->input->len);
613 /* Issue the read modified request. */
615 rc = raw3270_start(&tp->view, rrq);
617 rc = raw3270_start_irq(&tp->view, rrq);
619 raw3270_request_reset(rrq);
620 xchg(&tp->read, rrq);
625 * Switch to the tty view.
628 tty3270_activate(struct raw3270_view *view)
630 struct tty3270 *tp = container_of(view, struct tty3270, view);
632 tp->update_flags = TTY_UPDATE_ALL;
633 tty3270_set_timer(tp, 1);
638 tty3270_deactivate(struct raw3270_view *view)
640 struct tty3270 *tp = container_of(view, struct tty3270, view);
642 del_timer(&tp->timer);
646 tty3270_irq(struct tty3270 *tp, struct raw3270_request *rq, struct irb *irb)
648 /* Handle ATTN. Schedule tasklet to read aid. */
649 if (irb->scsw.cmd.dstat & DEV_STAT_ATTENTION) {
651 tty3270_issue_read(tp, 0);
657 if (irb->scsw.cmd.dstat & DEV_STAT_UNIT_CHECK)
660 /* Normal end. Copy residual count. */
661 rq->rescnt = irb->scsw.cmd.count;
662 } else if (irb->scsw.cmd.dstat & DEV_STAT_DEV_END) {
663 /* Interrupt without an outstanding request -> update all */
664 tp->update_flags = TTY_UPDATE_ALL;
665 tty3270_set_timer(tp, 1);
667 return RAW3270_IO_DONE;
671 * Allocate tty3270 structure.
673 static struct tty3270 *
674 tty3270_alloc_view(void)
679 tp = kzalloc(sizeof(struct tty3270), GFP_KERNEL);
683 kmalloc(sizeof(void *) * TTY3270_STRING_PAGES, GFP_KERNEL);
684 if (!tp->freemem_pages)
686 INIT_LIST_HEAD(&tp->freemem);
687 INIT_LIST_HEAD(&tp->lines);
688 INIT_LIST_HEAD(&tp->update);
689 INIT_LIST_HEAD(&tp->rcl_lines);
692 for (pages = 0; pages < TTY3270_STRING_PAGES; pages++) {
693 tp->freemem_pages[pages] = (void *)
694 __get_free_pages(GFP_KERNEL|GFP_DMA, 0);
695 if (!tp->freemem_pages[pages])
697 add_string_memory(&tp->freemem,
698 tp->freemem_pages[pages], PAGE_SIZE);
700 tp->write = raw3270_request_alloc(TTY3270_OUTPUT_BUFFER_SIZE);
701 if (IS_ERR(tp->write))
703 tp->read = raw3270_request_alloc(0);
704 if (IS_ERR(tp->read))
706 tp->kreset = raw3270_request_alloc(1);
707 if (IS_ERR(tp->kreset))
709 tp->kbd = kbd_alloc();
713 tty_port_init(&tp->port);
714 setup_timer(&tp->timer, (void (*)(unsigned long)) tty3270_update,
716 tasklet_init(&tp->readlet,
717 (void (*)(unsigned long)) tty3270_read_tasklet,
718 (unsigned long) tp->read);
719 INIT_WORK(&tp->resize_work, tty3270_resize_work);
724 raw3270_request_free(tp->kreset);
726 raw3270_request_free(tp->read);
728 raw3270_request_free(tp->write);
731 free_pages((unsigned long) tp->freemem_pages[pages], 0);
732 kfree(tp->freemem_pages);
733 tty_port_destroy(&tp->port);
737 return ERR_PTR(-ENOMEM);
741 * Free tty3270 structure.
744 tty3270_free_view(struct tty3270 *tp)
749 raw3270_request_free(tp->kreset);
750 raw3270_request_free(tp->read);
751 raw3270_request_free(tp->write);
752 for (pages = 0; pages < TTY3270_STRING_PAGES; pages++)
753 free_pages((unsigned long) tp->freemem_pages[pages], 0);
754 kfree(tp->freemem_pages);
755 tty_port_destroy(&tp->port);
760 * Allocate tty3270 screen.
762 static struct tty3270_line *
763 tty3270_alloc_screen(unsigned int rows, unsigned int cols)
765 struct tty3270_line *screen;
769 size = sizeof(struct tty3270_line) * (rows - 2);
770 screen = kzalloc(size, GFP_KERNEL);
773 for (lines = 0; lines < rows - 2; lines++) {
774 size = sizeof(struct tty3270_cell) * cols;
775 screen[lines].cells = kzalloc(size, GFP_KERNEL);
776 if (!screen[lines].cells)
782 kfree(screen[lines].cells);
785 return ERR_PTR(-ENOMEM);
789 * Free tty3270 screen.
792 tty3270_free_screen(struct tty3270_line *screen, unsigned int rows)
796 for (lines = 0; lines < rows - 2; lines++)
797 kfree(screen[lines].cells);
802 * Resize tty3270 screen
804 static void tty3270_resize_work(struct work_struct *work)
806 struct tty3270 *tp = container_of(work, struct tty3270, resize_work);
807 struct tty3270_line *screen, *oscreen;
808 struct tty_struct *tty;
812 screen = tty3270_alloc_screen(tp->n_rows, tp->n_cols);
815 /* Switch to new output size */
816 spin_lock_bh(&tp->view.lock);
817 oscreen = tp->screen;
818 orows = tp->view.rows;
819 tp->view.model = tp->n_model;
820 tp->view.rows = tp->n_rows;
821 tp->view.cols = tp->n_cols;
823 free_string(&tp->freemem, tp->prompt);
824 free_string(&tp->freemem, tp->status);
825 tty3270_create_prompt(tp);
826 tty3270_create_status(tp);
828 while (tp->nr_lines < tp->view.rows - 2)
829 tty3270_blank_line(tp);
830 tp->update_flags = TTY_UPDATE_ALL;
831 spin_unlock_bh(&tp->view.lock);
832 tty3270_free_screen(oscreen, orows);
833 tty3270_set_timer(tp, 1);
834 /* Informat tty layer about new size */
835 tty = tty_port_tty_get(&tp->port);
838 ws.ws_row = tp->view.rows - 2;
839 ws.ws_col = tp->view.cols;
840 tty_do_resize(tty, &ws);
844 tty3270_resize(struct raw3270_view *view, int model, int rows, int cols)
846 struct tty3270 *tp = container_of(view, struct tty3270, view);
851 schedule_work(&tp->resize_work);
855 * Unlink tty3270 data structure from tty.
858 tty3270_release(struct raw3270_view *view)
860 struct tty3270 *tp = container_of(view, struct tty3270, view);
861 struct tty_struct *tty = tty_port_tty_get(&tp->port);
864 tty->driver_data = NULL;
865 tty_port_tty_set(&tp->port, NULL);
867 raw3270_put_view(&tp->view);
873 * Free tty3270 data structure
876 tty3270_free(struct raw3270_view *view)
878 struct tty3270 *tp = container_of(view, struct tty3270, view);
880 del_timer_sync(&tp->timer);
881 tty3270_free_screen(tp->screen, tp->view.rows);
882 tty3270_free_view(tp);
886 * Delayed freeing of tty3270 views.
889 tty3270_del_views(void)
893 for (i = RAW3270_FIRSTMINOR; i <= tty3270_max_index; i++) {
894 struct raw3270_view *view = raw3270_find_view(&tty3270_fn, i);
896 raw3270_del_view(view);
900 static struct raw3270_fn tty3270_fn = {
901 .activate = tty3270_activate,
902 .deactivate = tty3270_deactivate,
903 .intv = (void *) tty3270_irq,
904 .release = tty3270_release,
905 .free = tty3270_free,
906 .resize = tty3270_resize
910 * This routine is called whenever a 3270 tty is opened first time.
912 static int tty3270_install(struct tty_driver *driver, struct tty_struct *tty)
914 struct raw3270_view *view;
918 /* Check if the tty3270 is already there. */
919 view = raw3270_find_view(&tty3270_fn, tty->index + RAW3270_FIRSTMINOR);
921 tp = container_of(view, struct tty3270, view);
922 tty->driver_data = tp;
923 tty->winsize.ws_row = tp->view.rows - 2;
924 tty->winsize.ws_col = tp->view.cols;
925 tp->port.low_latency = 0;
926 /* why to reassign? */
927 tty_port_tty_set(&tp->port, tty);
928 tp->inattr = TF_INPUT;
929 return tty_port_install(&tp->port, driver, tty);
931 if (tty3270_max_index < tty->index + 1)
932 tty3270_max_index = tty->index + 1;
934 /* Allocate tty3270 structure on first open. */
935 tp = tty3270_alloc_view();
939 rc = raw3270_add_view(&tp->view, &tty3270_fn,
940 tty->index + RAW3270_FIRSTMINOR);
942 tty3270_free_view(tp);
946 tp->screen = tty3270_alloc_screen(tp->view.rows, tp->view.cols);
947 if (IS_ERR(tp->screen)) {
948 rc = PTR_ERR(tp->screen);
949 raw3270_put_view(&tp->view);
950 raw3270_del_view(&tp->view);
951 tty3270_free_view(tp);
955 tty_port_tty_set(&tp->port, tty);
956 tp->port.low_latency = 0;
957 tty->winsize.ws_row = tp->view.rows - 2;
958 tty->winsize.ws_col = tp->view.cols;
960 tty3270_create_prompt(tp);
961 tty3270_create_status(tp);
962 tty3270_update_status(tp);
964 /* Create blank line for every line in the tty output area. */
965 for (i = 0; i < tp->view.rows - 2; i++)
966 tty3270_blank_line(tp);
968 tp->kbd->port = &tp->port;
969 tp->kbd->fn_handler[KVAL(K_INCRCONSOLE)] = tty3270_exit_tty;
970 tp->kbd->fn_handler[KVAL(K_SCROLLBACK)] = tty3270_scroll_backward;
971 tp->kbd->fn_handler[KVAL(K_SCROLLFORW)] = tty3270_scroll_forward;
972 tp->kbd->fn_handler[KVAL(K_CONS)] = tty3270_rcl_backward;
973 kbd_ascebc(tp->kbd, tp->view.ascebc);
975 raw3270_activate_view(&tp->view);
977 rc = tty_port_install(&tp->port, driver, tty);
979 raw3270_put_view(&tp->view);
983 tty->driver_data = tp;
989 * This routine is called whenever a 3270 tty is opened.
992 tty3270_open(struct tty_struct *tty, struct file *filp)
994 struct tty3270 *tp = tty->driver_data;
995 struct tty_port *port = &tp->port;
998 tty_port_tty_set(port, tty);
1003 * This routine is called when the 3270 tty is closed. We wait
1004 * for the remaining request to be completed. Then we clean up.
1007 tty3270_close(struct tty_struct *tty, struct file * filp)
1009 struct tty3270 *tp = tty->driver_data;
1014 tty->driver_data = NULL;
1015 tty_port_tty_set(&tp->port, NULL);
1019 static void tty3270_cleanup(struct tty_struct *tty)
1021 struct tty3270 *tp = tty->driver_data;
1024 raw3270_put_view(&tp->view);
1028 * We always have room.
1031 tty3270_write_room(struct tty_struct *tty)
1037 * Insert character into the screen at the current position with the
1038 * current color and highlight. This function does NOT do cursor movement.
1040 static void tty3270_put_character(struct tty3270 *tp, char ch)
1042 struct tty3270_line *line;
1043 struct tty3270_cell *cell;
1045 line = tp->screen + tp->cy;
1046 if (line->len <= tp->cx) {
1047 while (line->len < tp->cx) {
1048 cell = line->cells + line->len;
1049 cell->character = tp->view.ascebc[' '];
1050 cell->highlight = tp->highlight;
1051 cell->f_color = tp->f_color;
1056 cell = line->cells + tp->cx;
1057 cell->character = tp->view.ascebc[(unsigned int) ch];
1058 cell->highlight = tp->highlight;
1059 cell->f_color = tp->f_color;
1063 * Convert a tty3270_line to a 3270 data fragment usable for output.
1066 tty3270_convert_line(struct tty3270 *tp, int line_nr)
1068 struct tty3270_line *line;
1069 struct tty3270_cell *cell;
1070 struct string *s, *n;
1071 unsigned char highlight;
1072 unsigned char f_color;
1076 /* Determine how long the fragment will be. */
1077 flen = 3; /* Prefix (TO_SBA). */
1078 line = tp->screen + line_nr;
1080 highlight = TAX_RESET;
1081 f_color = TAC_RESET;
1082 for (i = 0, cell = line->cells; i < line->len; i++, cell++) {
1083 if (cell->highlight != highlight) {
1084 flen += 3; /* TO_SA to switch highlight. */
1085 highlight = cell->highlight;
1087 if (cell->f_color != f_color) {
1088 flen += 3; /* TO_SA to switch color. */
1089 f_color = cell->f_color;
1092 if (highlight != TAX_RESET)
1093 flen += 3; /* TO_SA to reset hightlight. */
1094 if (f_color != TAC_RESET)
1095 flen += 3; /* TO_SA to reset color. */
1096 if (line->len < tp->view.cols)
1097 flen += 4; /* Postfix (TO_RA). */
1099 /* Find the line in the list. */
1100 i = tp->view.rows - 2 - line_nr;
1101 list_for_each_entry_reverse(s, &tp->lines, list)
1105 * Check if the line needs to get reallocated.
1107 if (s->len != flen) {
1108 /* Reallocate string. */
1109 n = tty3270_alloc_string(tp, flen);
1110 list_add(&n->list, &s->list);
1111 list_del_init(&s->list);
1112 if (!list_empty(&s->update))
1113 list_del_init(&s->update);
1114 free_string(&tp->freemem, s);
1118 /* Write 3270 data fragment. */
1124 highlight = TAX_RESET;
1125 f_color = TAC_RESET;
1126 for (i = 0, cell = line->cells; i < line->len; i++, cell++) {
1127 if (cell->highlight != highlight) {
1130 *cp++ = cell->highlight;
1131 highlight = cell->highlight;
1133 if (cell->f_color != f_color) {
1136 *cp++ = cell->f_color;
1137 f_color = cell->f_color;
1139 *cp++ = cell->character;
1141 if (highlight != TAX_RESET) {
1146 if (f_color != TAC_RESET) {
1151 if (line->len < tp->view.cols) {
1158 if (tp->nr_up + line_nr < tp->view.rows - 2) {
1159 /* Line is currently visible on screen. */
1160 tty3270_update_string(tp, s, line_nr);
1161 /* Add line to update list. */
1162 if (list_empty(&s->update)) {
1163 list_add_tail(&s->update, &tp->update);
1164 tp->update_flags |= TTY_UPDATE_LIST;
1170 * Do carriage return.
1173 tty3270_cr(struct tty3270 *tp)
1182 tty3270_lf(struct tty3270 *tp)
1184 struct tty3270_line temp;
1187 tty3270_convert_line(tp, tp->cy);
1188 if (tp->cy < tp->view.rows - 3) {
1192 /* Last line just filled up. Add new, blank line. */
1193 tty3270_blank_line(tp);
1194 temp = tp->screen[0];
1196 for (i = 0; i < tp->view.rows - 3; i++)
1197 tp->screen[i] = tp->screen[i+1];
1198 tp->screen[tp->view.rows - 3] = temp;
1199 tty3270_rebuild_update(tp);
1203 tty3270_ri(struct tty3270 *tp)
1206 tty3270_convert_line(tp, tp->cy);
1212 * Insert characters at current position.
1215 tty3270_insert_characters(struct tty3270 *tp, int n)
1217 struct tty3270_line *line;
1220 line = tp->screen + tp->cy;
1221 while (line->len < tp->cx) {
1222 line->cells[line->len].character = tp->view.ascebc[' '];
1223 line->cells[line->len].highlight = TAX_RESET;
1224 line->cells[line->len].f_color = TAC_RESET;
1227 if (n > tp->view.cols - tp->cx)
1228 n = tp->view.cols - tp->cx;
1229 k = min_t(int, line->len - tp->cx, tp->view.cols - tp->cx - n);
1231 line->cells[tp->cx + n + k] = line->cells[tp->cx + k];
1233 if (line->len > tp->view.cols)
1234 line->len = tp->view.cols;
1236 line->cells[tp->cx + n].character = tp->view.ascebc[' '];
1237 line->cells[tp->cx + n].highlight = tp->highlight;
1238 line->cells[tp->cx + n].f_color = tp->f_color;
1243 * Delete characters at current position.
1246 tty3270_delete_characters(struct tty3270 *tp, int n)
1248 struct tty3270_line *line;
1251 line = tp->screen + tp->cy;
1252 if (line->len <= tp->cx)
1254 if (line->len - tp->cx <= n) {
1258 for (i = tp->cx; i + n < line->len; i++)
1259 line->cells[i] = line->cells[i + n];
1264 * Erase characters at current position.
1267 tty3270_erase_characters(struct tty3270 *tp, int n)
1269 struct tty3270_line *line;
1270 struct tty3270_cell *cell;
1272 line = tp->screen + tp->cy;
1273 while (line->len > tp->cx && n-- > 0) {
1274 cell = line->cells + tp->cx++;
1275 cell->character = ' ';
1276 cell->highlight = TAX_RESET;
1277 cell->f_color = TAC_RESET;
1280 tp->cx = min_t(int, tp->cx, tp->view.cols - 1);
1284 * Erase line, 3 different cases:
1285 * Esc [ 0 K Erase from current position to end of line inclusive
1286 * Esc [ 1 K Erase from beginning of line to current position inclusive
1287 * Esc [ 2 K Erase entire line (without moving cursor)
1290 tty3270_erase_line(struct tty3270 *tp, int mode)
1292 struct tty3270_line *line;
1293 struct tty3270_cell *cell;
1296 line = tp->screen + tp->cy;
1299 else if (mode == 1) {
1300 for (i = 0; i < tp->cx; i++) {
1301 cell = line->cells + i;
1302 cell->character = ' ';
1303 cell->highlight = TAX_RESET;
1304 cell->f_color = TAC_RESET;
1306 if (line->len <= tp->cx)
1307 line->len = tp->cx + 1;
1308 } else if (mode == 2)
1310 tty3270_convert_line(tp, tp->cy);
1314 * Erase display, 3 different cases:
1315 * Esc [ 0 J Erase from current position to bottom of screen inclusive
1316 * Esc [ 1 J Erase from top of screen to current position inclusive
1317 * Esc [ 2 J Erase entire screen (without moving the cursor)
1320 tty3270_erase_display(struct tty3270 *tp, int mode)
1325 tty3270_erase_line(tp, 0);
1326 for (i = tp->cy + 1; i < tp->view.rows - 2; i++) {
1327 tp->screen[i].len = 0;
1328 tty3270_convert_line(tp, i);
1330 } else if (mode == 1) {
1331 for (i = 0; i < tp->cy; i++) {
1332 tp->screen[i].len = 0;
1333 tty3270_convert_line(tp, i);
1335 tty3270_erase_line(tp, 1);
1336 } else if (mode == 2) {
1337 for (i = 0; i < tp->view.rows - 2; i++) {
1338 tp->screen[i].len = 0;
1339 tty3270_convert_line(tp, i);
1342 tty3270_rebuild_update(tp);
1346 * Set attributes found in an escape sequence.
1347 * Esc [ <attr> ; <attr> ; ... m
1350 tty3270_set_attributes(struct tty3270 *tp)
1352 static unsigned char f_colors[] = {
1353 TAC_DEFAULT, TAC_RED, TAC_GREEN, TAC_YELLOW, TAC_BLUE,
1354 TAC_PINK, TAC_TURQ, TAC_WHITE, 0, TAC_DEFAULT
1358 for (i = 0; i <= tp->esc_npar; i++) {
1359 attr = tp->esc_par[i];
1362 tp->highlight = TAX_RESET;
1363 tp->f_color = TAC_RESET;
1366 case 4: /* Start underlining. */
1367 tp->highlight = TAX_UNDER;
1369 case 5: /* Start blink. */
1370 tp->highlight = TAX_BLINK;
1372 case 7: /* Start reverse. */
1373 tp->highlight = TAX_REVER;
1375 case 24: /* End underlining */
1376 if (tp->highlight == TAX_UNDER)
1377 tp->highlight = TAX_RESET;
1379 case 25: /* End blink. */
1380 if (tp->highlight == TAX_BLINK)
1381 tp->highlight = TAX_RESET;
1383 case 27: /* End reverse. */
1384 if (tp->highlight == TAX_REVER)
1385 tp->highlight = TAX_RESET;
1387 /* Foreground color. */
1388 case 30: /* Black */
1390 case 32: /* Green */
1391 case 33: /* Yellow */
1393 case 35: /* Magenta */
1395 case 37: /* White */
1396 case 39: /* Black */
1397 tp->f_color = f_colors[attr - 30];
1404 tty3270_getpar(struct tty3270 *tp, int ix)
1406 return (tp->esc_par[ix] > 0) ? tp->esc_par[ix] : 1;
1410 tty3270_goto_xy(struct tty3270 *tp, int cx, int cy)
1412 int max_cx = max(0, cx);
1413 int max_cy = max(0, cy);
1415 tp->cx = min_t(int, tp->view.cols - 1, max_cx);
1416 cy = min_t(int, tp->view.rows - 3, max_cy);
1418 tty3270_convert_line(tp, tp->cy);
1424 * Process escape sequences. Known sequences:
1425 * Esc 7 Save Cursor Position
1426 * Esc 8 Restore Cursor Position
1427 * Esc [ Pn ; Pn ; .. m Set attributes
1428 * Esc [ Pn ; Pn H Cursor Position
1429 * Esc [ Pn ; Pn f Cursor Position
1430 * Esc [ Pn A Cursor Up
1431 * Esc [ Pn B Cursor Down
1432 * Esc [ Pn C Cursor Forward
1433 * Esc [ Pn D Cursor Backward
1434 * Esc [ Pn G Cursor Horizontal Absolute
1435 * Esc [ Pn X Erase Characters
1436 * Esc [ Ps J Erase in Display
1437 * Esc [ Ps K Erase in Line
1438 * // FIXME: add all the new ones.
1440 * Pn is a numeric parameter, a string of zero or more decimal digits.
1441 * Ps is a selective parameter.
1444 tty3270_escape_sequence(struct tty3270 *tp, char ch)
1446 enum { ESnormal, ESesc, ESsquare, ESgetpars };
1448 if (tp->esc_state == ESnormal) {
1450 /* Starting new escape sequence. */
1451 tp->esc_state = ESesc;
1454 if (tp->esc_state == ESesc) {
1455 tp->esc_state = ESnormal;
1458 tp->esc_state = ESsquare;
1470 case 'Z': /* Respond ID. */
1471 kbd_puts_queue(&tp->port, "\033[?6c");
1473 case '7': /* Save cursor position. */
1474 tp->saved_cx = tp->cx;
1475 tp->saved_cy = tp->cy;
1476 tp->saved_highlight = tp->highlight;
1477 tp->saved_f_color = tp->f_color;
1479 case '8': /* Restore cursor position. */
1480 tty3270_convert_line(tp, tp->cy);
1481 tty3270_goto_xy(tp, tp->saved_cx, tp->saved_cy);
1482 tp->highlight = tp->saved_highlight;
1483 tp->f_color = tp->saved_f_color;
1485 case 'c': /* Reset terminal. */
1486 tp->cx = tp->saved_cx = 0;
1487 tp->cy = tp->saved_cy = 0;
1488 tp->highlight = tp->saved_highlight = TAX_RESET;
1489 tp->f_color = tp->saved_f_color = TAC_RESET;
1490 tty3270_erase_display(tp, 2);
1495 if (tp->esc_state == ESsquare) {
1496 tp->esc_state = ESgetpars;
1497 memset(tp->esc_par, 0, sizeof(tp->esc_par));
1499 tp->esc_ques = (ch == '?');
1503 if (tp->esc_state == ESgetpars) {
1504 if (ch == ';' && tp->esc_npar < ESCAPE_NPAR - 1) {
1508 if (ch >= '0' && ch <= '9') {
1509 tp->esc_par[tp->esc_npar] *= 10;
1510 tp->esc_par[tp->esc_npar] += ch - '0';
1514 tp->esc_state = ESnormal;
1515 if (ch == 'n' && !tp->esc_ques) {
1516 if (tp->esc_par[0] == 5) /* Status report. */
1517 kbd_puts_queue(&tp->port, "\033[0n");
1518 else if (tp->esc_par[0] == 6) { /* Cursor report. */
1520 sprintf(buf, "\033[%d;%dR", tp->cy + 1, tp->cx + 1);
1521 kbd_puts_queue(&tp->port, buf);
1529 tty3270_set_attributes(tp);
1531 case 'H': /* Set cursor position. */
1533 tty3270_goto_xy(tp, tty3270_getpar(tp, 1) - 1,
1534 tty3270_getpar(tp, 0) - 1);
1536 case 'd': /* Set y position. */
1537 tty3270_goto_xy(tp, tp->cx, tty3270_getpar(tp, 0) - 1);
1539 case 'A': /* Cursor up. */
1541 tty3270_goto_xy(tp, tp->cx, tp->cy - tty3270_getpar(tp, 0));
1543 case 'B': /* Cursor down. */
1546 tty3270_goto_xy(tp, tp->cx, tp->cy + tty3270_getpar(tp, 0));
1548 case 'C': /* Cursor forward. */
1550 tty3270_goto_xy(tp, tp->cx + tty3270_getpar(tp, 0), tp->cy);
1552 case 'D': /* Cursor backward. */
1553 tty3270_goto_xy(tp, tp->cx - tty3270_getpar(tp, 0), tp->cy);
1555 case 'G': /* Set x position. */
1557 tty3270_goto_xy(tp, tty3270_getpar(tp, 0), tp->cy);
1559 case 'X': /* Erase Characters. */
1560 tty3270_erase_characters(tp, tty3270_getpar(tp, 0));
1562 case 'J': /* Erase display. */
1563 tty3270_erase_display(tp, tp->esc_par[0]);
1565 case 'K': /* Erase line. */
1566 tty3270_erase_line(tp, tp->esc_par[0]);
1568 case 'P': /* Delete characters. */
1569 tty3270_delete_characters(tp, tty3270_getpar(tp, 0));
1571 case '@': /* Insert characters. */
1572 tty3270_insert_characters(tp, tty3270_getpar(tp, 0));
1574 case 's': /* Save cursor position. */
1575 tp->saved_cx = tp->cx;
1576 tp->saved_cy = tp->cy;
1577 tp->saved_highlight = tp->highlight;
1578 tp->saved_f_color = tp->f_color;
1580 case 'u': /* Restore cursor position. */
1581 tty3270_convert_line(tp, tp->cy);
1582 tty3270_goto_xy(tp, tp->saved_cx, tp->saved_cy);
1583 tp->highlight = tp->saved_highlight;
1584 tp->f_color = tp->saved_f_color;
1590 * String write routine for 3270 ttys
1593 tty3270_do_write(struct tty3270 *tp, struct tty_struct *tty,
1594 const unsigned char *buf, int count)
1598 spin_lock_bh(&tp->view.lock);
1599 for (i_msg = 0; !tty->stopped && i_msg < count; i_msg++) {
1600 if (tp->esc_state != 0) {
1601 /* Continue escape sequence. */
1602 tty3270_escape_sequence(tp, buf[i_msg]);
1606 switch (buf[i_msg]) {
1607 case 0x07: /* '\a' -- Alarm */
1608 tp->wcc |= TW_PLUSALARM;
1610 case 0x08: /* Backspace. */
1613 tty3270_put_character(tp, ' ');
1616 case 0x09: /* '\t' -- Tabulate */
1617 for (i = tp->cx % 8; i < 8; i++) {
1618 if (tp->cx >= tp->view.cols) {
1623 tty3270_put_character(tp, ' ');
1627 case 0x0a: /* '\n' -- New Line */
1631 case 0x0c: /* '\f' -- Form Feed */
1632 tty3270_erase_display(tp, 2);
1633 tp->cx = tp->cy = 0;
1635 case 0x0d: /* '\r' -- Carriage Return */
1638 case 0x0f: /* SuSE "exit alternate mode" */
1640 case 0x1b: /* Start escape sequence. */
1641 tty3270_escape_sequence(tp, buf[i_msg]);
1643 default: /* Insert normal character. */
1644 if (tp->cx >= tp->view.cols) {
1648 tty3270_put_character(tp, buf[i_msg]);
1653 /* Convert current line to 3270 data fragment. */
1654 tty3270_convert_line(tp, tp->cy);
1656 /* Setup timer to update display after 1/10 second */
1657 if (!timer_pending(&tp->timer))
1658 tty3270_set_timer(tp, HZ/10);
1660 spin_unlock_bh(&tp->view.lock);
1664 * String write routine for 3270 ttys
1667 tty3270_write(struct tty_struct * tty,
1668 const unsigned char *buf, int count)
1672 tp = tty->driver_data;
1675 if (tp->char_count > 0) {
1676 tty3270_do_write(tp, tty, tp->char_buf, tp->char_count);
1679 tty3270_do_write(tp, tty, buf, count);
1684 * Put single characters to the ttys character buffer
1686 static int tty3270_put_char(struct tty_struct *tty, unsigned char ch)
1690 tp = tty->driver_data;
1691 if (!tp || tp->char_count >= TTY3270_CHAR_BUF_SIZE)
1693 tp->char_buf[tp->char_count++] = ch;
1698 * Flush all characters from the ttys characeter buffer put there
1699 * by tty3270_put_char.
1702 tty3270_flush_chars(struct tty_struct *tty)
1706 tp = tty->driver_data;
1709 if (tp->char_count > 0) {
1710 tty3270_do_write(tp, tty, tp->char_buf, tp->char_count);
1716 * Returns the number of characters in the output buffer. This is
1717 * used in tty_wait_until_sent to wait until all characters have
1718 * appeared on the screen.
1721 tty3270_chars_in_buffer(struct tty_struct *tty)
1727 tty3270_flush_buffer(struct tty_struct *tty)
1732 * Check for visible/invisible input switches
1735 tty3270_set_termios(struct tty_struct *tty, struct ktermios *old)
1740 tp = tty->driver_data;
1743 spin_lock_bh(&tp->view.lock);
1744 if (L_ICANON(tty)) {
1745 new = L_ECHO(tty) ? TF_INPUT: TF_INPUTN;
1746 if (new != tp->inattr) {
1748 tty3270_update_prompt(tp, NULL, 0);
1749 tty3270_set_timer(tp, 1);
1752 spin_unlock_bh(&tp->view.lock);
1756 * Disable reading from a 3270 tty
1759 tty3270_throttle(struct tty_struct * tty)
1763 tp = tty->driver_data;
1770 * Enable reading from a 3270 tty
1773 tty3270_unthrottle(struct tty_struct * tty)
1777 tp = tty->driver_data;
1782 tty3270_issue_read(tp, 1);
1786 * Hang up the tty device.
1789 tty3270_hangup(struct tty_struct *tty)
1795 tty3270_wait_until_sent(struct tty_struct *tty, int timeout)
1799 static int tty3270_ioctl(struct tty_struct *tty, unsigned int cmd,
1804 tp = tty->driver_data;
1807 if (tty->flags & (1 << TTY_IO_ERROR))
1809 return kbd_ioctl(tp->kbd, cmd, arg);
1812 #ifdef CONFIG_COMPAT
1813 static long tty3270_compat_ioctl(struct tty_struct *tty,
1814 unsigned int cmd, unsigned long arg)
1818 tp = tty->driver_data;
1821 if (tty->flags & (1 << TTY_IO_ERROR))
1823 return kbd_ioctl(tp->kbd, cmd, (unsigned long)compat_ptr(arg));
1827 static const struct tty_operations tty3270_ops = {
1828 .install = tty3270_install,
1829 .cleanup = tty3270_cleanup,
1830 .open = tty3270_open,
1831 .close = tty3270_close,
1832 .write = tty3270_write,
1833 .put_char = tty3270_put_char,
1834 .flush_chars = tty3270_flush_chars,
1835 .write_room = tty3270_write_room,
1836 .chars_in_buffer = tty3270_chars_in_buffer,
1837 .flush_buffer = tty3270_flush_buffer,
1838 .throttle = tty3270_throttle,
1839 .unthrottle = tty3270_unthrottle,
1840 .hangup = tty3270_hangup,
1841 .wait_until_sent = tty3270_wait_until_sent,
1842 .ioctl = tty3270_ioctl,
1843 #ifdef CONFIG_COMPAT
1844 .compat_ioctl = tty3270_compat_ioctl,
1846 .set_termios = tty3270_set_termios
1849 static void tty3270_create_cb(int minor)
1851 tty_register_device(tty3270_driver, minor - RAW3270_FIRSTMINOR, NULL);
1854 static void tty3270_destroy_cb(int minor)
1856 tty_unregister_device(tty3270_driver, minor - RAW3270_FIRSTMINOR);
1859 static struct raw3270_notifier tty3270_notifier =
1861 .create = tty3270_create_cb,
1862 .destroy = tty3270_destroy_cb,
1866 * 3270 tty registration code called from tty_init().
1867 * Most kernel services (incl. kmalloc) are available at this poimt.
1869 static int __init tty3270_init(void)
1871 struct tty_driver *driver;
1874 driver = tty_alloc_driver(RAW3270_MAXDEVS,
1875 TTY_DRIVER_REAL_RAW |
1876 TTY_DRIVER_DYNAMIC_DEV |
1877 TTY_DRIVER_RESET_TERMIOS);
1879 return PTR_ERR(driver);
1882 * Initialize the tty_driver structure
1883 * Entries in tty3270_driver that are NOT initialized:
1884 * proc_entry, set_termios, flush_buffer, set_ldisc, write_proc
1886 driver->driver_name = "tty3270";
1887 driver->name = "3270/tty";
1888 driver->major = IBM_TTY3270_MAJOR;
1889 driver->minor_start = RAW3270_FIRSTMINOR;
1890 driver->name_base = RAW3270_FIRSTMINOR;
1891 driver->type = TTY_DRIVER_TYPE_SYSTEM;
1892 driver->subtype = SYSTEM_TYPE_TTY;
1893 driver->init_termios = tty_std_termios;
1894 tty_set_operations(driver, &tty3270_ops);
1895 ret = tty_register_driver(driver);
1897 put_tty_driver(driver);
1900 tty3270_driver = driver;
1901 raw3270_register_notifier(&tty3270_notifier);
1908 struct tty_driver *driver;
1910 raw3270_unregister_notifier(&tty3270_notifier);
1911 driver = tty3270_driver;
1912 tty3270_driver = NULL;
1913 tty_unregister_driver(driver);
1914 put_tty_driver(driver);
1915 tty3270_del_views();
1918 MODULE_LICENSE("GPL");
1919 MODULE_ALIAS_CHARDEV_MAJOR(IBM_TTY3270_MAJOR);
1921 module_init(tty3270_init);
1922 module_exit(tty3270_exit);