• Home
  • Raw
  • Download

Lines Matching +full:cell +full:- +full:count

1 // SPDX-License-Identifier: GPL-2.0
3 * IBM/3270 Driver - tty functions.
8 * -- Copyright IBM Corp. 2003
115 /* tty3270->update_flags. See tty3270_update for details. */
117 #define TTY_UPDATE_LIST 2 /* Update lines in tty3270->update. */
130 mod_timer(&tp->timer, jiffies + expires); in tty3270_set_timer()
137 tty3270_update_prompt(struct tty3270 *tp, char *input, int count) in tty3270_update_prompt() argument
142 line = tp->prompt; in tty3270_update_prompt()
143 if (count != 0) in tty3270_update_prompt()
144 line->string[5] = TF_INMDT; in tty3270_update_prompt()
146 line->string[5] = tp->inattr; in tty3270_update_prompt()
147 if (count > tp->view.cols * 2 - 11) in tty3270_update_prompt()
148 count = tp->view.cols * 2 - 11; in tty3270_update_prompt()
149 memcpy(line->string + 6, input, count); in tty3270_update_prompt()
150 line->string[6 + count] = TO_IC; in tty3270_update_prompt()
152 if (count < tp->view.cols * 2 - 11) { in tty3270_update_prompt()
153 line->string[7 + count] = TO_RA; in tty3270_update_prompt()
154 line->string[10 + count] = 0; in tty3270_update_prompt()
155 off = tp->view.cols * tp->view.rows - 9; in tty3270_update_prompt()
156 raw3270_buffer_address(tp->view.dev, line->string+count+8, off); in tty3270_update_prompt()
157 line->len = 11 + count; in tty3270_update_prompt()
159 line->len = 7 + count; in tty3270_update_prompt()
160 tp->update_flags |= TTY_UPDATE_INPUT; in tty3270_update_prompt()
173 line = alloc_string(&tp->freemem, in tty3270_create_prompt()
174 sizeof(blueprint) + tp->view.cols * 2 - 9); in tty3270_create_prompt()
175 tp->prompt = line; in tty3270_create_prompt()
176 tp->inattr = TF_INPUT; in tty3270_create_prompt()
178 memcpy(line->string, blueprint, sizeof(blueprint)); in tty3270_create_prompt()
179 line->len = sizeof(blueprint); in tty3270_create_prompt()
181 offset = tp->view.cols * (tp->view.rows - 2); in tty3270_create_prompt()
182 raw3270_buffer_address(tp->view.dev, line->string + 1, offset); in tty3270_create_prompt()
183 offset = tp->view.cols * tp->view.rows - 9; in tty3270_create_prompt()
184 raw3270_buffer_address(tp->view.dev, line->string + 8, offset); in tty3270_create_prompt()
187 tp->input = alloc_string(&tp->freemem, tp->view.cols * 2 - 9 + 6); in tty3270_create_prompt()
199 str = (tp->nr_up != 0) ? "History" : "Running"; in tty3270_update_status()
200 memcpy(tp->status->string + 8, str, 7); in tty3270_update_status()
201 codepage_convert(tp->view.ascebc, tp->status->string + 8, 7); in tty3270_update_status()
202 tp->update_flags |= TTY_UPDATE_STATUS; in tty3270_update_status()
215 line = alloc_string(&tp->freemem,sizeof(blueprint)); in tty3270_create_status()
216 tp->status = line; in tty3270_create_status()
218 memcpy(line->string, blueprint, sizeof(blueprint)); in tty3270_create_status()
220 offset = tp->view.cols * tp->view.rows - 9; in tty3270_create_status()
221 raw3270_buffer_address(tp->view.dev, line->string + 1, offset); in tty3270_create_status()
233 raw3270_buffer_address(tp->view.dev, line->string + 1, in tty3270_update_string()
234 tp->view.cols * nr); in tty3270_update_string()
235 cp = line->string + line->len - 4; in tty3270_update_string()
237 raw3270_buffer_address(tp->view.dev, cp + 1, in tty3270_update_string()
238 tp->view.cols * (nr + 1)); in tty3270_update_string()
254 list_for_each_entry_safe(s, n, &tp->update, update) in tty3270_rebuild_update()
255 list_del_init(&s->update); in tty3270_rebuild_update()
256 line = tp->view.rows - 3; in tty3270_rebuild_update()
257 nr_up = tp->nr_up; in tty3270_rebuild_update()
258 list_for_each_entry_reverse(s, &tp->lines, list) { in tty3270_rebuild_update()
260 nr_up--; in tty3270_rebuild_update()
264 list_add(&s->update, &tp->update); in tty3270_rebuild_update()
265 if (--line < 0) in tty3270_rebuild_update()
268 tp->update_flags |= TTY_UPDATE_LIST; in tty3270_rebuild_update()
280 s = alloc_string(&tp->freemem, size); in tty3270_alloc_string()
283 list_for_each_entry_safe(s, n, &tp->lines, list) { in tty3270_alloc_string()
284 BUG_ON(tp->nr_lines <= tp->view.rows - 2); in tty3270_alloc_string()
285 list_del(&s->list); in tty3270_alloc_string()
286 if (!list_empty(&s->update)) in tty3270_alloc_string()
287 list_del(&s->update); in tty3270_alloc_string()
288 tp->nr_lines--; in tty3270_alloc_string()
289 if (free_string(&tp->freemem, s) >= size) in tty3270_alloc_string()
292 s = alloc_string(&tp->freemem, size); in tty3270_alloc_string()
294 if (tp->nr_up != 0 && in tty3270_alloc_string()
295 tp->nr_up + tp->view.rows - 2 >= tp->nr_lines) { in tty3270_alloc_string()
296 tp->nr_up = tp->nr_lines - tp->view.rows + 2; in tty3270_alloc_string()
315 memcpy(s->string, blueprint, sizeof(blueprint)); in tty3270_blank_line()
316 s->len = sizeof(blueprint); in tty3270_blank_line()
317 list_add_tail(&s->list, &tp->lines); in tty3270_blank_line()
318 tp->nr_lines++; in tty3270_blank_line()
319 if (tp->nr_up != 0) in tty3270_blank_line()
320 tp->nr_up++; in tty3270_blank_line()
332 for (i = 0; i < tp->view.rows - 2; i++) in tty3270_blank_screen()
333 tp->screen[i].len = 0; in tty3270_blank_screen()
334 tp->nr_up = 0; in tty3270_blank_screen()
335 list_for_each_entry_safe(s, n, &tp->lines, list) { in tty3270_blank_screen()
336 list_del(&s->list); in tty3270_blank_screen()
337 if (!list_empty(&s->update)) in tty3270_blank_screen()
338 list_del(&s->update); in tty3270_blank_screen()
339 tp->nr_lines--; in tty3270_blank_screen()
340 free_string(&tp->freemem, s); in tty3270_blank_screen()
350 struct tty3270 *tp = container_of(rq->view, struct tty3270, view); in tty3270_write_callback()
352 if (rq->rc != 0) { in tty3270_write_callback()
354 tp->update_flags = TTY_UPDATE_ALL; in tty3270_write_callback()
358 xchg(&tp->write, rq); in tty3270_write_callback()
375 wrq = xchg(&tp->write, 0); in tty3270_update()
381 spin_lock(&tp->view.lock); in tty3270_update()
383 if (tp->update_flags & TTY_UPDATE_ALL) { in tty3270_update()
386 tp->update_flags = TTY_UPDATE_ERASE | TTY_UPDATE_LIST | in tty3270_update()
389 if (tp->update_flags & TTY_UPDATE_ERASE) { in tty3270_update()
396 raw3270_request_add_data(wrq, &tp->wcc, 1); in tty3270_update()
397 tp->wcc = TW_NONE; in tty3270_update()
402 if (tp->update_flags & TTY_UPDATE_STATUS) in tty3270_update()
403 if (raw3270_request_add_data(wrq, tp->status->string, in tty3270_update()
404 tp->status->len) == 0) in tty3270_update()
410 if (tp->update_flags & TTY_UPDATE_INPUT) in tty3270_update()
411 if (raw3270_request_add_data(wrq, tp->prompt->string, in tty3270_update()
412 tp->prompt->len) == 0) in tty3270_update()
417 if (tp->update_flags & TTY_UPDATE_LIST) { in tty3270_update()
419 list_for_each_entry_safe(s, n, &tp->update, update) { in tty3270_update()
420 str = s->string; in tty3270_update()
421 len = s->len; in tty3270_update()
427 if (s->string[1] == sba[0] && s->string[2] == sba[1]) in tty3270_update()
428 str += 3, len -= 3; in tty3270_update()
431 list_del_init(&s->update); in tty3270_update()
432 if (s->string[s->len - 4] == TO_RA) in tty3270_update()
433 sba = s->string + s->len - 3; in tty3270_update()
437 if (list_empty(&tp->update)) in tty3270_update()
440 wrq->callback = tty3270_write_callback; in tty3270_update()
441 rc = raw3270_start(&tp->view, wrq); in tty3270_update()
443 tp->update_flags &= ~updated; in tty3270_update()
444 if (tp->update_flags) in tty3270_update()
448 xchg(&tp->write, wrq); in tty3270_update()
450 spin_unlock(&tp->view.lock); in tty3270_update()
461 tp->rcl_walk = NULL; in tty3270_rcl_add()
464 if (tp->rcl_nr >= tp->rcl_max) { in tty3270_rcl_add()
465 s = list_entry(tp->rcl_lines.next, struct string, list); in tty3270_rcl_add()
466 list_del(&s->list); in tty3270_rcl_add()
467 free_string(&tp->freemem, s); in tty3270_rcl_add()
468 tp->rcl_nr--; in tty3270_rcl_add()
471 memcpy(s->string, input, len); in tty3270_rcl_add()
472 list_add_tail(&s->list, &tp->rcl_lines); in tty3270_rcl_add()
473 tp->rcl_nr++; in tty3270_rcl_add()
479 struct tty3270 *tp = container_of(kbd->port, struct tty3270, port); in tty3270_rcl_backward()
482 spin_lock_bh(&tp->view.lock); in tty3270_rcl_backward()
483 if (tp->inattr == TF_INPUT) { in tty3270_rcl_backward()
484 if (tp->rcl_walk && tp->rcl_walk->prev != &tp->rcl_lines) in tty3270_rcl_backward()
485 tp->rcl_walk = tp->rcl_walk->prev; in tty3270_rcl_backward()
486 else if (!list_empty(&tp->rcl_lines)) in tty3270_rcl_backward()
487 tp->rcl_walk = tp->rcl_lines.prev; in tty3270_rcl_backward()
488 s = tp->rcl_walk ? in tty3270_rcl_backward()
489 list_entry(tp->rcl_walk, struct string, list) : NULL; in tty3270_rcl_backward()
490 if (tp->rcl_walk) { in tty3270_rcl_backward()
491 s = list_entry(tp->rcl_walk, struct string, list); in tty3270_rcl_backward()
492 tty3270_update_prompt(tp, s->string, s->len); in tty3270_rcl_backward()
497 spin_unlock_bh(&tp->view.lock); in tty3270_rcl_backward()
506 struct tty3270 *tp = container_of(kbd->port, struct tty3270, port); in tty3270_exit_tty()
508 raw3270_deactivate_view(&tp->view); in tty3270_exit_tty()
517 struct tty3270 *tp = container_of(kbd->port, struct tty3270, port); in tty3270_scroll_forward()
520 spin_lock_bh(&tp->view.lock); in tty3270_scroll_forward()
521 nr_up = tp->nr_up - tp->view.rows + 2; in tty3270_scroll_forward()
524 if (nr_up != tp->nr_up) { in tty3270_scroll_forward()
525 tp->nr_up = nr_up; in tty3270_scroll_forward()
530 spin_unlock_bh(&tp->view.lock); in tty3270_scroll_forward()
539 struct tty3270 *tp = container_of(kbd->port, struct tty3270, port); in tty3270_scroll_backward()
542 spin_lock_bh(&tp->view.lock); in tty3270_scroll_backward()
543 nr_up = tp->nr_up + tp->view.rows - 2; in tty3270_scroll_backward()
544 if (nr_up + tp->view.rows - 2 > tp->nr_lines) in tty3270_scroll_backward()
545 nr_up = tp->nr_lines - tp->view.rows + 2; in tty3270_scroll_backward()
546 if (nr_up != tp->nr_up) { in tty3270_scroll_backward()
547 tp->nr_up = nr_up; in tty3270_scroll_backward()
552 spin_unlock_bh(&tp->view.lock); in tty3270_scroll_backward()
563 struct tty3270 *tp = container_of(rrq->view, struct tty3270, view); in tty3270_read_tasklet()
567 spin_lock_bh(&tp->view.lock); in tty3270_read_tasklet()
575 if (tp->input->string[0] == 0x7d) { in tty3270_read_tasklet()
577 input = tp->input->string + 6; in tty3270_read_tasklet()
578 len = tp->input->len - 6 - rrq->rescnt; in tty3270_read_tasklet()
579 if (tp->inattr != TF_INPUTN) in tty3270_read_tasklet()
581 if (tp->nr_up > 0) { in tty3270_read_tasklet()
582 tp->nr_up = 0; in tty3270_read_tasklet()
589 } else if (tp->input->string[0] == 0x6d) { in tty3270_read_tasklet()
591 tp->update_flags = TTY_UPDATE_ALL; in tty3270_read_tasklet()
594 spin_unlock_bh(&tp->view.lock); in tty3270_read_tasklet()
597 raw3270_request_reset(tp->kreset); in tty3270_read_tasklet()
598 raw3270_request_set_cmd(tp->kreset, TC_WRITE); in tty3270_read_tasklet()
599 raw3270_request_add_data(tp->kreset, &kreset_data, 1); in tty3270_read_tasklet()
600 raw3270_start(&tp->view, tp->kreset); in tty3270_read_tasklet()
602 while (len-- > 0) in tty3270_read_tasklet()
603 kbd_keycode(tp->kbd, *input++); in tty3270_read_tasklet()
605 kbd_keycode(tp->kbd, 256 + tp->input->string[0]); in tty3270_read_tasklet()
608 xchg(&tp->read, rrq); in tty3270_read_tasklet()
609 raw3270_put_view(&tp->view); in tty3270_read_tasklet()
618 struct tty3270 *tp = container_of(rq->view, struct tty3270, view); in tty3270_read_callback()
619 raw3270_get_view(rq->view); in tty3270_read_callback()
621 tasklet_schedule(&tp->readlet); in tty3270_read_callback()
633 rrq = xchg(&tp->read, 0); in tty3270_issue_read()
637 rrq->callback = tty3270_read_callback; in tty3270_issue_read()
638 rrq->callback_data = tp; in tty3270_issue_read()
640 raw3270_request_set_data(rrq, tp->input->string, tp->input->len); in tty3270_issue_read()
643 rc = raw3270_start(&tp->view, rrq); in tty3270_issue_read()
645 rc = raw3270_start_irq(&tp->view, rrq); in tty3270_issue_read()
648 xchg(&tp->read, rrq); in tty3270_issue_read()
659 tty_port_tty_hangup(&tp->port, true); in tty3270_hangup_tasklet()
660 raw3270_put_view(&tp->view); in tty3270_hangup_tasklet()
671 tp->update_flags = TTY_UPDATE_ALL; in tty3270_activate()
681 del_timer(&tp->timer); in tty3270_deactivate()
688 if (irb->scsw.cmd.dstat & DEV_STAT_ATTENTION) { in tty3270_irq()
689 if (!tp->throttle) in tty3270_irq()
692 tp->attn = 1; in tty3270_irq()
696 if (irb->scsw.cmd.dstat & DEV_STAT_UNIT_CHECK) { in tty3270_irq()
697 rq->rc = -EIO; in tty3270_irq()
698 raw3270_get_view(&tp->view); in tty3270_irq()
699 tasklet_schedule(&tp->hanglet); in tty3270_irq()
701 /* Normal end. Copy residual count. */ in tty3270_irq()
702 rq->rescnt = irb->scsw.cmd.count; in tty3270_irq()
704 } else if (irb->scsw.cmd.dstat & DEV_STAT_DEV_END) { in tty3270_irq()
705 /* Interrupt without an outstanding request -> update all */ in tty3270_irq()
706 tp->update_flags = TTY_UPDATE_ALL; in tty3270_irq()
723 tp->freemem_pages = in tty3270_alloc_view()
726 if (!tp->freemem_pages) in tty3270_alloc_view()
728 INIT_LIST_HEAD(&tp->freemem); in tty3270_alloc_view()
729 INIT_LIST_HEAD(&tp->lines); in tty3270_alloc_view()
730 INIT_LIST_HEAD(&tp->update); in tty3270_alloc_view()
731 INIT_LIST_HEAD(&tp->rcl_lines); in tty3270_alloc_view()
732 tp->rcl_max = 20; in tty3270_alloc_view()
735 tp->freemem_pages[pages] = (void *) in tty3270_alloc_view()
737 if (!tp->freemem_pages[pages]) in tty3270_alloc_view()
739 add_string_memory(&tp->freemem, in tty3270_alloc_view()
740 tp->freemem_pages[pages], PAGE_SIZE); in tty3270_alloc_view()
742 tp->write = raw3270_request_alloc(TTY3270_OUTPUT_BUFFER_SIZE); in tty3270_alloc_view()
743 if (IS_ERR(tp->write)) in tty3270_alloc_view()
745 tp->read = raw3270_request_alloc(0); in tty3270_alloc_view()
746 if (IS_ERR(tp->read)) in tty3270_alloc_view()
748 tp->kreset = raw3270_request_alloc(1); in tty3270_alloc_view()
749 if (IS_ERR(tp->kreset)) in tty3270_alloc_view()
751 tp->kbd = kbd_alloc(); in tty3270_alloc_view()
752 if (!tp->kbd) in tty3270_alloc_view()
755 tty_port_init(&tp->port); in tty3270_alloc_view()
756 timer_setup(&tp->timer, tty3270_update, 0); in tty3270_alloc_view()
757 tasklet_init(&tp->readlet, tty3270_read_tasklet, in tty3270_alloc_view()
758 (unsigned long) tp->read); in tty3270_alloc_view()
759 tasklet_init(&tp->hanglet, tty3270_hangup_tasklet, in tty3270_alloc_view()
761 INIT_WORK(&tp->resize_work, tty3270_resize_work); in tty3270_alloc_view()
766 raw3270_request_free(tp->kreset); in tty3270_alloc_view()
768 raw3270_request_free(tp->read); in tty3270_alloc_view()
770 raw3270_request_free(tp->write); in tty3270_alloc_view()
772 while (pages--) in tty3270_alloc_view()
773 free_pages((unsigned long) tp->freemem_pages[pages], 0); in tty3270_alloc_view()
774 kfree(tp->freemem_pages); in tty3270_alloc_view()
775 tty_port_destroy(&tp->port); in tty3270_alloc_view()
779 return ERR_PTR(-ENOMEM); in tty3270_alloc_view()
790 kbd_free(tp->kbd); in tty3270_free_view()
791 raw3270_request_free(tp->kreset); in tty3270_free_view()
792 raw3270_request_free(tp->read); in tty3270_free_view()
793 raw3270_request_free(tp->write); in tty3270_free_view()
795 free_pages((unsigned long) tp->freemem_pages[pages], 0); in tty3270_free_view()
796 kfree(tp->freemem_pages); in tty3270_free_view()
797 tty_port_destroy(&tp->port); in tty3270_free_view()
811 size = sizeof(struct tty3270_line) * (rows - 2); in tty3270_alloc_screen()
815 for (lines = 0; lines < rows - 2; lines++) { in tty3270_alloc_screen()
823 while (lines--) in tty3270_alloc_screen()
827 return ERR_PTR(-ENOMEM); in tty3270_alloc_screen()
838 for (lines = 0; lines < rows - 2; lines++) in tty3270_free_screen()
854 screen = tty3270_alloc_screen(tp->n_rows, tp->n_cols); in tty3270_resize_work()
858 spin_lock_bh(&tp->view.lock); in tty3270_resize_work()
860 oscreen = tp->screen; in tty3270_resize_work()
861 orows = tp->view.rows; in tty3270_resize_work()
862 tp->view.model = tp->n_model; in tty3270_resize_work()
863 tp->view.rows = tp->n_rows; in tty3270_resize_work()
864 tp->view.cols = tp->n_cols; in tty3270_resize_work()
865 tp->screen = screen; in tty3270_resize_work()
866 free_string(&tp->freemem, tp->prompt); in tty3270_resize_work()
867 free_string(&tp->freemem, tp->status); in tty3270_resize_work()
870 while (tp->nr_lines < tp->view.rows - 2) in tty3270_resize_work()
872 tp->update_flags = TTY_UPDATE_ALL; in tty3270_resize_work()
873 spin_unlock_bh(&tp->view.lock); in tty3270_resize_work()
877 tty = tty_port_tty_get(&tp->port); in tty3270_resize_work()
880 ws.ws_row = tp->view.rows - 2; in tty3270_resize_work()
881 ws.ws_col = tp->view.cols; in tty3270_resize_work()
891 if (tp->n_model == model && tp->n_rows == rows && tp->n_cols == cols) in tty3270_resize()
893 tp->n_model = model; in tty3270_resize()
894 tp->n_rows = rows; in tty3270_resize()
895 tp->n_cols = cols; in tty3270_resize()
896 schedule_work(&tp->resize_work); in tty3270_resize()
906 struct tty_struct *tty = tty_port_tty_get(&tp->port); in tty3270_release()
909 tty->driver_data = NULL; in tty3270_release()
910 tty_port_tty_set(&tp->port, NULL); in tty3270_release()
912 raw3270_put_view(&tp->view); in tty3270_release()
925 del_timer_sync(&tp->timer); in tty3270_free()
926 tty3270_free_screen(tp->screen, tp->view.rows); in tty3270_free()
964 view = raw3270_find_view(&tty3270_fn, tty->index + RAW3270_FIRSTMINOR); in tty3270_install()
967 tty->driver_data = tp; in tty3270_install()
968 tty->winsize.ws_row = tp->view.rows - 2; in tty3270_install()
969 tty->winsize.ws_col = tp->view.cols; in tty3270_install()
970 tp->port.low_latency = 0; in tty3270_install()
971 tp->inattr = TF_INPUT; in tty3270_install()
974 if (tty3270_max_index < tty->index + 1) in tty3270_install()
975 tty3270_max_index = tty->index + 1; in tty3270_install()
982 rc = raw3270_add_view(&tp->view, &tty3270_fn, in tty3270_install()
983 tty->index + RAW3270_FIRSTMINOR, in tty3270_install()
990 tp->screen = tty3270_alloc_screen(tp->view.rows, tp->view.cols); in tty3270_install()
991 if (IS_ERR(tp->screen)) { in tty3270_install()
992 rc = PTR_ERR(tp->screen); in tty3270_install()
993 raw3270_put_view(&tp->view); in tty3270_install()
994 raw3270_del_view(&tp->view); in tty3270_install()
999 tp->port.low_latency = 0; in tty3270_install()
1000 tty->winsize.ws_row = tp->view.rows - 2; in tty3270_install()
1001 tty->winsize.ws_col = tp->view.cols; in tty3270_install()
1008 for (i = 0; i < tp->view.rows - 2; i++) in tty3270_install()
1011 tp->kbd->port = &tp->port; in tty3270_install()
1012 tp->kbd->fn_handler[KVAL(K_INCRCONSOLE)] = tty3270_exit_tty; in tty3270_install()
1013 tp->kbd->fn_handler[KVAL(K_SCROLLBACK)] = tty3270_scroll_backward; in tty3270_install()
1014 tp->kbd->fn_handler[KVAL(K_SCROLLFORW)] = tty3270_scroll_forward; in tty3270_install()
1015 tp->kbd->fn_handler[KVAL(K_CONS)] = tty3270_rcl_backward; in tty3270_install()
1016 kbd_ascebc(tp->kbd, tp->view.ascebc); in tty3270_install()
1018 raw3270_activate_view(&tp->view); in tty3270_install()
1021 rc = tty_port_install(&tp->port, driver, tty); in tty3270_install()
1023 raw3270_put_view(&tp->view); in tty3270_install()
1027 tty->driver_data = tp; in tty3270_install()
1038 struct tty3270 *tp = tty->driver_data; in tty3270_open()
1039 struct tty_port *port = &tp->port; in tty3270_open()
1041 port->count++; in tty3270_open()
1053 struct tty3270 *tp = tty->driver_data; in tty3270_close()
1055 if (tty->count > 1) in tty3270_close()
1058 tty_port_tty_set(&tp->port, NULL); in tty3270_close()
1063 struct tty3270 *tp = tty->driver_data; in tty3270_cleanup()
1066 tty->driver_data = NULL; in tty3270_cleanup()
1067 raw3270_put_view(&tp->view); in tty3270_cleanup()
1087 struct tty3270_cell *cell; in tty3270_put_character() local
1089 line = tp->screen + tp->cy; in tty3270_put_character()
1090 if (line->len <= tp->cx) { in tty3270_put_character()
1091 while (line->len < tp->cx) { in tty3270_put_character()
1092 cell = line->cells + line->len; in tty3270_put_character()
1093 cell->character = tp->view.ascebc[' ']; in tty3270_put_character()
1094 cell->highlight = tp->highlight; in tty3270_put_character()
1095 cell->f_color = tp->f_color; in tty3270_put_character()
1096 line->len++; in tty3270_put_character()
1098 line->len++; in tty3270_put_character()
1100 cell = line->cells + tp->cx; in tty3270_put_character()
1101 cell->character = tp->view.ascebc[(unsigned int) ch]; in tty3270_put_character()
1102 cell->highlight = tp->highlight; in tty3270_put_character()
1103 cell->f_color = tp->f_color; in tty3270_put_character()
1113 struct tty3270_cell *cell; in tty3270_convert_line() local
1122 line = tp->screen + line_nr; in tty3270_convert_line()
1123 flen += line->len; in tty3270_convert_line()
1126 for (i = 0, cell = line->cells; i < line->len; i++, cell++) { in tty3270_convert_line()
1127 if (cell->highlight != highlight) { in tty3270_convert_line()
1129 highlight = cell->highlight; in tty3270_convert_line()
1131 if (cell->f_color != f_color) { in tty3270_convert_line()
1133 f_color = cell->f_color; in tty3270_convert_line()
1140 if (line->len < tp->view.cols) in tty3270_convert_line()
1144 i = tp->view.rows - 2 - line_nr; in tty3270_convert_line()
1145 list_for_each_entry_reverse(s, &tp->lines, list) in tty3270_convert_line()
1146 if (--i <= 0) in tty3270_convert_line()
1151 if (s->len != flen) { in tty3270_convert_line()
1154 list_add(&n->list, &s->list); in tty3270_convert_line()
1155 list_del_init(&s->list); in tty3270_convert_line()
1156 if (!list_empty(&s->update)) in tty3270_convert_line()
1157 list_del_init(&s->update); in tty3270_convert_line()
1158 free_string(&tp->freemem, s); in tty3270_convert_line()
1163 cp = s->string; in tty3270_convert_line()
1170 for (i = 0, cell = line->cells; i < line->len; i++, cell++) { in tty3270_convert_line()
1171 if (cell->highlight != highlight) { in tty3270_convert_line()
1174 *cp++ = cell->highlight; in tty3270_convert_line()
1175 highlight = cell->highlight; in tty3270_convert_line()
1177 if (cell->f_color != f_color) { in tty3270_convert_line()
1180 *cp++ = cell->f_color; in tty3270_convert_line()
1181 f_color = cell->f_color; in tty3270_convert_line()
1183 *cp++ = cell->character; in tty3270_convert_line()
1195 if (line->len < tp->view.cols) { in tty3270_convert_line()
1202 if (tp->nr_up + line_nr < tp->view.rows - 2) { in tty3270_convert_line()
1206 if (list_empty(&s->update)) { in tty3270_convert_line()
1207 list_add_tail(&s->update, &tp->update); in tty3270_convert_line()
1208 tp->update_flags |= TTY_UPDATE_LIST; in tty3270_convert_line()
1219 tp->cx = 0; in tty3270_cr()
1231 tty3270_convert_line(tp, tp->cy); in tty3270_lf()
1232 if (tp->cy < tp->view.rows - 3) { in tty3270_lf()
1233 tp->cy++; in tty3270_lf()
1238 temp = tp->screen[0]; in tty3270_lf()
1240 for (i = 0; i < tp->view.rows - 3; i++) in tty3270_lf()
1241 tp->screen[i] = tp->screen[i+1]; in tty3270_lf()
1242 tp->screen[tp->view.rows - 3] = temp; in tty3270_lf()
1249 if (tp->cy > 0) { in tty3270_ri()
1250 tty3270_convert_line(tp, tp->cy); in tty3270_ri()
1251 tp->cy--; in tty3270_ri()
1264 line = tp->screen + tp->cy; in tty3270_insert_characters()
1265 while (line->len < tp->cx) { in tty3270_insert_characters()
1266 line->cells[line->len].character = tp->view.ascebc[' ']; in tty3270_insert_characters()
1267 line->cells[line->len].highlight = TAX_RESET; in tty3270_insert_characters()
1268 line->cells[line->len].f_color = TAC_RESET; in tty3270_insert_characters()
1269 line->len++; in tty3270_insert_characters()
1271 if (n > tp->view.cols - tp->cx) in tty3270_insert_characters()
1272 n = tp->view.cols - tp->cx; in tty3270_insert_characters()
1273 k = min_t(int, line->len - tp->cx, tp->view.cols - tp->cx - n); in tty3270_insert_characters()
1274 while (k--) in tty3270_insert_characters()
1275 line->cells[tp->cx + n + k] = line->cells[tp->cx + k]; in tty3270_insert_characters()
1276 line->len += n; in tty3270_insert_characters()
1277 if (line->len > tp->view.cols) in tty3270_insert_characters()
1278 line->len = tp->view.cols; in tty3270_insert_characters()
1279 while (n-- > 0) { in tty3270_insert_characters()
1280 line->cells[tp->cx + n].character = tp->view.ascebc[' ']; in tty3270_insert_characters()
1281 line->cells[tp->cx + n].highlight = tp->highlight; in tty3270_insert_characters()
1282 line->cells[tp->cx + n].f_color = tp->f_color; in tty3270_insert_characters()
1295 line = tp->screen + tp->cy; in tty3270_delete_characters()
1296 if (line->len <= tp->cx) in tty3270_delete_characters()
1298 if (line->len - tp->cx <= n) { in tty3270_delete_characters()
1299 line->len = tp->cx; in tty3270_delete_characters()
1302 for (i = tp->cx; i + n < line->len; i++) in tty3270_delete_characters()
1303 line->cells[i] = line->cells[i + n]; in tty3270_delete_characters()
1304 line->len -= n; in tty3270_delete_characters()
1314 struct tty3270_cell *cell; in tty3270_erase_characters() local
1316 line = tp->screen + tp->cy; in tty3270_erase_characters()
1317 while (line->len > tp->cx && n-- > 0) { in tty3270_erase_characters()
1318 cell = line->cells + tp->cx++; in tty3270_erase_characters()
1319 cell->character = ' '; in tty3270_erase_characters()
1320 cell->highlight = TAX_RESET; in tty3270_erase_characters()
1321 cell->f_color = TAC_RESET; in tty3270_erase_characters()
1323 tp->cx += n; in tty3270_erase_characters()
1324 tp->cx = min_t(int, tp->cx, tp->view.cols - 1); in tty3270_erase_characters()
1337 struct tty3270_cell *cell; in tty3270_erase_line() local
1340 line = tp->screen + tp->cy; in tty3270_erase_line()
1342 line->len = tp->cx; in tty3270_erase_line()
1344 for (i = 0; i < tp->cx; i++) { in tty3270_erase_line()
1345 cell = line->cells + i; in tty3270_erase_line()
1346 cell->character = ' '; in tty3270_erase_line()
1347 cell->highlight = TAX_RESET; in tty3270_erase_line()
1348 cell->f_color = TAC_RESET; in tty3270_erase_line()
1350 if (line->len <= tp->cx) in tty3270_erase_line()
1351 line->len = tp->cx + 1; in tty3270_erase_line()
1353 line->len = 0; in tty3270_erase_line()
1354 tty3270_convert_line(tp, tp->cy); in tty3270_erase_line()
1370 for (i = tp->cy + 1; i < tp->view.rows - 2; i++) { in tty3270_erase_display()
1371 tp->screen[i].len = 0; in tty3270_erase_display()
1375 for (i = 0; i < tp->cy; i++) { in tty3270_erase_display()
1376 tp->screen[i].len = 0; in tty3270_erase_display()
1381 for (i = 0; i < tp->view.rows - 2; i++) { in tty3270_erase_display()
1382 tp->screen[i].len = 0; in tty3270_erase_display()
1402 for (i = 0; i <= tp->esc_npar; i++) { in tty3270_set_attributes()
1403 attr = tp->esc_par[i]; in tty3270_set_attributes()
1406 tp->highlight = TAX_RESET; in tty3270_set_attributes()
1407 tp->f_color = TAC_RESET; in tty3270_set_attributes()
1411 tp->highlight = TAX_UNDER; in tty3270_set_attributes()
1414 tp->highlight = TAX_BLINK; in tty3270_set_attributes()
1417 tp->highlight = TAX_REVER; in tty3270_set_attributes()
1420 if (tp->highlight == TAX_UNDER) in tty3270_set_attributes()
1421 tp->highlight = TAX_RESET; in tty3270_set_attributes()
1424 if (tp->highlight == TAX_BLINK) in tty3270_set_attributes()
1425 tp->highlight = TAX_RESET; in tty3270_set_attributes()
1428 if (tp->highlight == TAX_REVER) in tty3270_set_attributes()
1429 tp->highlight = TAX_RESET; in tty3270_set_attributes()
1441 tp->f_color = f_colors[attr - 30]; in tty3270_set_attributes()
1450 return (tp->esc_par[ix] > 0) ? tp->esc_par[ix] : 1; in tty3270_getpar()
1459 tp->cx = min_t(int, tp->view.cols - 1, max_cx); in tty3270_goto_xy()
1460 cy = min_t(int, tp->view.rows - 3, max_cy); in tty3270_goto_xy()
1461 if (cy != tp->cy) { in tty3270_goto_xy()
1462 tty3270_convert_line(tp, tp->cy); in tty3270_goto_xy()
1463 tp->cy = cy; in tty3270_goto_xy()
1492 if (tp->esc_state == ESnormal) { in tty3270_escape_sequence()
1495 tp->esc_state = ESesc; in tty3270_escape_sequence()
1498 if (tp->esc_state == ESesc) { in tty3270_escape_sequence()
1499 tp->esc_state = ESnormal; in tty3270_escape_sequence()
1502 tp->esc_state = ESsquare; in tty3270_escape_sequence()
1515 kbd_puts_queue(&tp->port, "\033[?6c"); in tty3270_escape_sequence()
1518 tp->saved_cx = tp->cx; in tty3270_escape_sequence()
1519 tp->saved_cy = tp->cy; in tty3270_escape_sequence()
1520 tp->saved_highlight = tp->highlight; in tty3270_escape_sequence()
1521 tp->saved_f_color = tp->f_color; in tty3270_escape_sequence()
1524 tty3270_convert_line(tp, tp->cy); in tty3270_escape_sequence()
1525 tty3270_goto_xy(tp, tp->saved_cx, tp->saved_cy); in tty3270_escape_sequence()
1526 tp->highlight = tp->saved_highlight; in tty3270_escape_sequence()
1527 tp->f_color = tp->saved_f_color; in tty3270_escape_sequence()
1530 tp->cx = tp->saved_cx = 0; in tty3270_escape_sequence()
1531 tp->cy = tp->saved_cy = 0; in tty3270_escape_sequence()
1532 tp->highlight = tp->saved_highlight = TAX_RESET; in tty3270_escape_sequence()
1533 tp->f_color = tp->saved_f_color = TAC_RESET; in tty3270_escape_sequence()
1539 if (tp->esc_state == ESsquare) { in tty3270_escape_sequence()
1540 tp->esc_state = ESgetpars; in tty3270_escape_sequence()
1541 memset(tp->esc_par, 0, sizeof(tp->esc_par)); in tty3270_escape_sequence()
1542 tp->esc_npar = 0; in tty3270_escape_sequence()
1543 tp->esc_ques = (ch == '?'); in tty3270_escape_sequence()
1544 if (tp->esc_ques) in tty3270_escape_sequence()
1547 if (tp->esc_state == ESgetpars) { in tty3270_escape_sequence()
1548 if (ch == ';' && tp->esc_npar < ESCAPE_NPAR - 1) { in tty3270_escape_sequence()
1549 tp->esc_npar++; in tty3270_escape_sequence()
1553 tp->esc_par[tp->esc_npar] *= 10; in tty3270_escape_sequence()
1554 tp->esc_par[tp->esc_npar] += ch - '0'; in tty3270_escape_sequence()
1558 tp->esc_state = ESnormal; in tty3270_escape_sequence()
1559 if (ch == 'n' && !tp->esc_ques) { in tty3270_escape_sequence()
1560 if (tp->esc_par[0] == 5) /* Status report. */ in tty3270_escape_sequence()
1561 kbd_puts_queue(&tp->port, "\033[0n"); in tty3270_escape_sequence()
1562 else if (tp->esc_par[0] == 6) { /* Cursor report. */ in tty3270_escape_sequence()
1564 sprintf(buf, "\033[%d;%dR", tp->cy + 1, tp->cx + 1); in tty3270_escape_sequence()
1565 kbd_puts_queue(&tp->port, buf); in tty3270_escape_sequence()
1569 if (tp->esc_ques) in tty3270_escape_sequence()
1577 tty3270_goto_xy(tp, tty3270_getpar(tp, 1) - 1, in tty3270_escape_sequence()
1578 tty3270_getpar(tp, 0) - 1); in tty3270_escape_sequence()
1581 tty3270_goto_xy(tp, tp->cx, tty3270_getpar(tp, 0) - 1); in tty3270_escape_sequence()
1585 tty3270_goto_xy(tp, tp->cx, tp->cy - tty3270_getpar(tp, 0)); in tty3270_escape_sequence()
1590 tty3270_goto_xy(tp, tp->cx, tp->cy + tty3270_getpar(tp, 0)); in tty3270_escape_sequence()
1594 tty3270_goto_xy(tp, tp->cx + tty3270_getpar(tp, 0), tp->cy); in tty3270_escape_sequence()
1597 tty3270_goto_xy(tp, tp->cx - tty3270_getpar(tp, 0), tp->cy); in tty3270_escape_sequence()
1601 tty3270_goto_xy(tp, tty3270_getpar(tp, 0), tp->cy); in tty3270_escape_sequence()
1607 tty3270_erase_display(tp, tp->esc_par[0]); in tty3270_escape_sequence()
1610 tty3270_erase_line(tp, tp->esc_par[0]); in tty3270_escape_sequence()
1619 tp->saved_cx = tp->cx; in tty3270_escape_sequence()
1620 tp->saved_cy = tp->cy; in tty3270_escape_sequence()
1621 tp->saved_highlight = tp->highlight; in tty3270_escape_sequence()
1622 tp->saved_f_color = tp->f_color; in tty3270_escape_sequence()
1625 tty3270_convert_line(tp, tp->cy); in tty3270_escape_sequence()
1626 tty3270_goto_xy(tp, tp->saved_cx, tp->saved_cy); in tty3270_escape_sequence()
1627 tp->highlight = tp->saved_highlight; in tty3270_escape_sequence()
1628 tp->f_color = tp->saved_f_color; in tty3270_escape_sequence()
1638 const unsigned char *buf, int count) in tty3270_do_write() argument
1642 spin_lock_bh(&tp->view.lock); in tty3270_do_write()
1643 for (i_msg = 0; !tty->stopped && i_msg < count; i_msg++) { in tty3270_do_write()
1644 if (tp->esc_state != 0) { in tty3270_do_write()
1651 case 0x07: /* '\a' -- Alarm */ in tty3270_do_write()
1652 tp->wcc |= TW_PLUSALARM; in tty3270_do_write()
1655 if (tp->cx > 0) { in tty3270_do_write()
1656 tp->cx--; in tty3270_do_write()
1660 case 0x09: /* '\t' -- Tabulate */ in tty3270_do_write()
1661 for (i = tp->cx % 8; i < 8; i++) { in tty3270_do_write()
1662 if (tp->cx >= tp->view.cols) { in tty3270_do_write()
1668 tp->cx++; in tty3270_do_write()
1671 case 0x0a: /* '\n' -- New Line */ in tty3270_do_write()
1675 case 0x0c: /* '\f' -- Form Feed */ in tty3270_do_write()
1677 tp->cx = tp->cy = 0; in tty3270_do_write()
1679 case 0x0d: /* '\r' -- Carriage Return */ in tty3270_do_write()
1680 tp->cx = 0; in tty3270_do_write()
1688 if (tp->cx >= tp->view.cols) { in tty3270_do_write()
1693 tp->cx++; in tty3270_do_write()
1698 tty3270_convert_line(tp, tp->cy); in tty3270_do_write()
1701 if (!timer_pending(&tp->timer)) in tty3270_do_write()
1704 spin_unlock_bh(&tp->view.lock); in tty3270_do_write()
1712 const unsigned char *buf, int count) in tty3270_write() argument
1716 tp = tty->driver_data; in tty3270_write()
1719 if (tp->char_count > 0) { in tty3270_write()
1720 tty3270_do_write(tp, tty, tp->char_buf, tp->char_count); in tty3270_write()
1721 tp->char_count = 0; in tty3270_write()
1723 tty3270_do_write(tp, tty, buf, count); in tty3270_write()
1724 return count; in tty3270_write()
1734 tp = tty->driver_data; in tty3270_put_char()
1735 if (!tp || tp->char_count >= TTY3270_CHAR_BUF_SIZE) in tty3270_put_char()
1737 tp->char_buf[tp->char_count++] = ch; in tty3270_put_char()
1750 tp = tty->driver_data; in tty3270_flush_chars()
1753 if (tp->char_count > 0) { in tty3270_flush_chars()
1754 tty3270_do_write(tp, tty, tp->char_buf, tp->char_count); in tty3270_flush_chars()
1755 tp->char_count = 0; in tty3270_flush_chars()
1784 tp = tty->driver_data; in tty3270_set_termios()
1787 spin_lock_bh(&tp->view.lock); in tty3270_set_termios()
1790 if (new != tp->inattr) { in tty3270_set_termios()
1791 tp->inattr = new; in tty3270_set_termios()
1796 spin_unlock_bh(&tp->view.lock); in tty3270_set_termios()
1807 tp = tty->driver_data; in tty3270_throttle()
1810 tp->throttle = 1; in tty3270_throttle()
1821 tp = tty->driver_data; in tty3270_unthrottle()
1824 tp->throttle = 0; in tty3270_unthrottle()
1825 if (tp->attn) in tty3270_unthrottle()
1837 tp = tty->driver_data; in tty3270_hangup()
1840 spin_lock_bh(&tp->view.lock); in tty3270_hangup()
1841 tp->cx = tp->saved_cx = 0; in tty3270_hangup()
1842 tp->cy = tp->saved_cy = 0; in tty3270_hangup()
1843 tp->highlight = tp->saved_highlight = TAX_RESET; in tty3270_hangup()
1844 tp->f_color = tp->saved_f_color = TAC_RESET; in tty3270_hangup()
1846 while (tp->nr_lines < tp->view.rows - 2) in tty3270_hangup()
1848 tp->update_flags = TTY_UPDATE_ALL; in tty3270_hangup()
1849 spin_unlock_bh(&tp->view.lock); in tty3270_hangup()
1863 tp = tty->driver_data; in tty3270_ioctl()
1865 return -ENODEV; in tty3270_ioctl()
1867 return -EIO; in tty3270_ioctl()
1868 return kbd_ioctl(tp->kbd, cmd, arg); in tty3270_ioctl()
1877 tp = tty->driver_data; in tty3270_compat_ioctl()
1879 return -ENODEV; in tty3270_compat_ioctl()
1881 return -EIO; in tty3270_compat_ioctl()
1882 return kbd_ioctl(tp->kbd, cmd, (unsigned long)compat_ptr(arg)); in tty3270_compat_ioctl()
1910 tty_register_device(tty3270_driver, minor - RAW3270_FIRSTMINOR, NULL); in tty3270_create_cb()
1915 tty_unregister_device(tty3270_driver, minor - RAW3270_FIRSTMINOR); in tty3270_destroy_cb()
1945 driver->driver_name = "tty3270"; in tty3270_init()
1946 driver->name = "3270/tty"; in tty3270_init()
1947 driver->major = IBM_TTY3270_MAJOR; in tty3270_init()
1948 driver->minor_start = RAW3270_FIRSTMINOR; in tty3270_init()
1949 driver->name_base = RAW3270_FIRSTMINOR; in tty3270_init()
1950 driver->type = TTY_DRIVER_TYPE_SYSTEM; in tty3270_init()
1951 driver->subtype = SYSTEM_TYPE_TTY; in tty3270_init()
1952 driver->init_termios = tty_std_termios; in tty3270_init()