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
37 #define TTY3270_SCREEN_PAGES 8 /* has to be power-of-two */
38 #define TTY3270_RECALL_SIZE 16 /* has to be power-of-two */
129 /* tty3270->update_flags. See tty3270_update for details. */
142 mod_timer(&tp->timer, jiffies + expires); in tty3270_set_timer()
147 return tp->view.rows - TTY3270_INPUT_AREA_ROWS; in tty3270_tty_rows()
153 raw3270_buffer_address(tp->view.dev, cp, x, y); in tty3270_add_ba()
188 return (line + incr) & (tp->allocated_lines - 1); in tty3270_line_increment()
193 return tp->screen + tty3270_line_increment(tp, tp->line_write_start, num); in tty3270_get_write_line()
198 return tp->screen + tty3270_line_increment(tp, tp->line_view_start, num - tp->nr_up); in tty3270_get_view_line()
203 return cols * 2 - 11; in tty3270_input_size()
208 strcpy(tp->prompt, input); in tty3270_update_prompt()
209 tp->update_flags |= TTY_UPDATE_INPUT; in tty3270_update_prompt()
218 int count = 0; in tty3270_add_prompt() local
221 cp = tp->converted_line; in tty3270_add_prompt()
222 cp = tty3270_add_ba(tp, cp, TO_SBA, 0, -2); in tty3270_add_prompt()
223 *cp++ = tp->view.ascebc['>']; in tty3270_add_prompt()
225 if (*tp->prompt) { in tty3270_add_prompt()
227 count = min_t(int, strlen(tp->prompt), in tty3270_add_prompt()
228 tp->view.cols * 2 - TTY3270_STATUS_AREA_SIZE - 2); in tty3270_add_prompt()
229 memcpy(cp, tp->prompt, count); in tty3270_add_prompt()
230 cp += count; in tty3270_add_prompt()
232 cp = tty3270_add_sf(tp, cp, tp->inattr); in tty3270_add_prompt()
236 if (count < tp->view.cols * 2 - 11) in tty3270_add_prompt()
237 cp = tty3270_add_ra(tp, cp, -TTY3270_STATUS_AREA_SIZE, -1, 0); in tty3270_add_prompt()
238 return cp - tp->converted_line; in tty3270_add_prompt()
244 *d++ = tp->view.ascebc[(int)*s++]; in tty3270_ebcdic_convert()
254 char *cp = tp->converted_line; in tty3270_add_status()
257 cp = tty3270_add_ba(tp, cp, TO_SBA, -TTY3270_STATUS_AREA_SIZE, -1); in tty3270_add_status()
273 if (tp->nr_up) { in tty3270_add_status()
274 len = sprintf(cp, "History %d", -tp->nr_up); in tty3270_add_status()
275 codepage_convert(tp->view.ascebc, cp, len); in tty3270_add_status()
282 return cp - (char *)tp->converted_line; in tty3270_add_status()
292 line->len = 0; in tty3270_blank_screen()
293 line->dirty = 1; in tty3270_blank_screen()
295 tp->nr_up = 0; in tty3270_blank_screen()
303 struct tty3270 *tp = container_of(rq->view, struct tty3270, view); in tty3270_write_callback()
305 if (rq->rc != 0) { in tty3270_write_callback()
307 tp->update_flags = TTY_UPDATE_ALL; in tty3270_write_callback()
311 xchg(&tp->write, rq); in tty3270_write_callback()
317 struct tty3270_cell *cell; in tty3270_required_length() local
320 flen += line->len; in tty3270_required_length()
325 for (i = 0, cell = line->cells; i < line->len; i++, cell++) { in tty3270_required_length()
326 if (cell->attributes.highlight != highlight) { in tty3270_required_length()
328 highlight = cell->attributes.highlight; in tty3270_required_length()
330 if (cell->attributes.f_color != f_color) { in tty3270_required_length()
332 f_color = cell->attributes.f_color; in tty3270_required_length()
334 if (cell->attributes.b_color != b_color) { in tty3270_required_length()
336 b_color = cell->attributes.b_color; in tty3270_required_length()
338 if (cell->attributes.alternate_charset) in tty3270_required_length()
347 if (line->len < tp->view.cols) in tty3270_required_length()
356 if (attr->highlight) in tty3270_add_reset_attributes()
358 if (attr->f_color != TAC_RESET) in tty3270_add_reset_attributes()
360 if (attr->b_color != TAC_RESET) in tty3270_add_reset_attributes()
362 if (line->len < tp->view.cols) in tty3270_add_reset_attributes()
370 case 'q': /* - */ in tty3270_graphics_translate()
374 case 'l': /* |- */ in tty3270_graphics_translate()
380 case 'k': /* -| */ in tty3270_graphics_translate()
418 struct tty3270_cell *cell; in tty3270_add_attributes() local
423 for (i = 0, cell = line->cells; i < line->len; i++, cell++) { in tty3270_add_attributes()
424 if (cell->attributes.highlight != attr->highlight) { in tty3270_add_attributes()
425 attr->highlight = cell->attributes.highlight; in tty3270_add_attributes()
426 cp = tty3270_add_sa(tp, cp, TAT_EXTHI, highlights[attr->highlight]); in tty3270_add_attributes()
428 if (cell->attributes.f_color != attr->f_color) { in tty3270_add_attributes()
429 attr->f_color = cell->attributes.f_color; in tty3270_add_attributes()
430 cp = tty3270_add_sa(tp, cp, TAT_FGCOLOR, colors[attr->f_color]); in tty3270_add_attributes()
432 if (cell->attributes.b_color != attr->b_color) { in tty3270_add_attributes()
433 attr->b_color = cell->attributes.b_color; in tty3270_add_attributes()
434 cp = tty3270_add_sa(tp, cp, TAT_BGCOLOR, colors[attr->b_color]); in tty3270_add_attributes()
436 c = cell->character; in tty3270_add_attributes()
437 if (cell->attributes.alternate_charset) in tty3270_add_attributes()
440 *cp++ = tp->view.ascebc[c]; in tty3270_add_attributes()
447 attr->highlight = TAX_RESET; in tty3270_reset_attributes()
448 attr->f_color = TAC_RESET; in tty3270_reset_attributes()
449 attr->b_color = TAC_RESET; in tty3270_reset_attributes()
467 cp = tty3270_add_attributes(tp, line, &attr, tp->converted_line, lineno); in tty3270_convert_line()
469 return cp - (char *)tp->converted_line; in tty3270_convert_line()
479 if (!line->dirty) in tty3270_update_lines_visible()
482 if (raw3270_request_add_data(rq, tp->converted_line, len)) in tty3270_update_lines_visible()
484 line->dirty = 0; in tty3270_update_lines_visible()
487 for (i = 0; i < tp->allocated_lines; i++) in tty3270_update_lines_visible()
488 tp->screen[i].dirty = 0; in tty3270_update_lines_visible()
489 tp->update_flags &= ~TTY_UPDATE_LINES; in tty3270_update_lines_visible()
499 for (i = 0; i < tp->allocated_lines; i++) { in tty3270_update_lines_all()
500 line = tty3270_get_write_line(tp, i + tp->cy + 1); in tty3270_update_lines_all()
501 if (!line->dirty) in tty3270_update_lines_all()
503 len = tty3270_convert_line(tp, line, tp->oops_line); in tty3270_update_lines_all()
504 if (raw3270_request_add_data(rq, tp->converted_line, len)) in tty3270_update_lines_all()
506 line->dirty = 0; in tty3270_update_lines_all()
507 if (++tp->oops_line >= tty3270_tty_rows(tp)) in tty3270_update_lines_all()
508 tp->oops_line = 0; in tty3270_update_lines_all()
511 if (i == tp->allocated_lines) { in tty3270_update_lines_all()
512 if (tp->oops_line < tty3270_tty_rows(tp)) { in tty3270_update_lines_all()
517 tp->update_flags &= ~TTY_UPDATE_LINES; in tty3270_update_lines_all()
531 wrq = xchg(&tp->write, 0); in tty3270_update()
537 spin_lock_irq(&tp->view.lock); in tty3270_update()
538 if (tp->update_flags == TTY_UPDATE_ALL) in tty3270_update()
542 raw3270_request_add_data(wrq, &tp->wcc, 1); in tty3270_update()
543 tp->wcc = TW_NONE; in tty3270_update()
548 if (tp->update_flags & TTY_UPDATE_STATUS) { in tty3270_update()
550 if (raw3270_request_add_data(wrq, tp->converted_line, len) == 0) in tty3270_update()
551 tp->update_flags &= ~TTY_UPDATE_STATUS; in tty3270_update()
557 if (tp->update_flags & TTY_UPDATE_INPUT) { in tty3270_update()
559 if (raw3270_request_add_data(wrq, tp->converted_line, len) == 0) in tty3270_update()
560 tp->update_flags &= ~TTY_UPDATE_INPUT; in tty3270_update()
563 if (tp->update_flags & TTY_UPDATE_LINES) { in tty3270_update()
570 wrq->callback = tty3270_write_callback; in tty3270_update()
571 rc = raw3270_start(&tp->view, wrq); in tty3270_update()
573 if (tp->update_flags) in tty3270_update()
577 xchg(&tp->write, wrq); in tty3270_update()
579 spin_unlock_irq(&tp->view.lock); in tty3270_update()
591 p = tp->rcl_lines[tp->rcl_write_index++]; in tty3270_rcl_add()
592 tp->rcl_write_index &= TTY3270_RECALL_SIZE - 1; in tty3270_rcl_add()
595 tp->rcl_read_index = tp->rcl_write_index; in tty3270_rcl_add()
600 struct tty3270 *tp = container_of(kbd->port, struct tty3270, port); in tty3270_rcl_backward()
603 spin_lock_irq(&tp->view.lock); in tty3270_rcl_backward()
604 if (tp->inattr == TF_INPUT) { in tty3270_rcl_backward()
606 tp->rcl_read_index--; in tty3270_rcl_backward()
607 tp->rcl_read_index &= TTY3270_RECALL_SIZE - 1; in tty3270_rcl_backward()
608 } while (!*tp->rcl_lines[tp->rcl_read_index] && in tty3270_rcl_backward()
609 i++ < TTY3270_RECALL_SIZE - 1); in tty3270_rcl_backward()
610 tty3270_update_prompt(tp, tp->rcl_lines[tp->rcl_read_index]); in tty3270_rcl_backward()
612 spin_unlock_irq(&tp->view.lock); in tty3270_rcl_backward()
620 struct tty3270 *tp = container_of(kbd->port, struct tty3270, port); in tty3270_exit_tty()
622 raw3270_deactivate_view(&tp->view); in tty3270_exit_tty()
630 tty3270_get_view_line(tp, i)->dirty = 1; in tty3270_redraw()
631 tp->update_flags = TTY_UPDATE_ALL; in tty3270_redraw()
640 struct tty3270 *tp = container_of(kbd->port, struct tty3270, port); in tty3270_scroll_forward()
642 spin_lock_irq(&tp->view.lock); in tty3270_scroll_forward()
644 if (tp->nr_up >= tty3270_tty_rows(tp)) in tty3270_scroll_forward()
645 tp->nr_up -= tty3270_tty_rows(tp) / 2; in tty3270_scroll_forward()
647 tp->nr_up = 0; in tty3270_scroll_forward()
649 spin_unlock_irq(&tp->view.lock); in tty3270_scroll_forward()
657 struct tty3270 *tp = container_of(kbd->port, struct tty3270, port); in tty3270_scroll_backward()
659 spin_lock_irq(&tp->view.lock); in tty3270_scroll_backward()
660 tp->nr_up += tty3270_tty_rows(tp) / 2; in tty3270_scroll_backward()
661 if (tp->nr_up > tp->allocated_lines - tty3270_tty_rows(tp)) in tty3270_scroll_backward()
662 tp->nr_up = tp->allocated_lines - tty3270_tty_rows(tp); in tty3270_scroll_backward()
664 spin_unlock_irq(&tp->view.lock); in tty3270_scroll_backward()
674 struct tty3270 *tp = container_of(rrq->view, struct tty3270, view); in tty3270_read_tasklet()
678 spin_lock_irq(&tp->view.lock); in tty3270_read_tasklet()
686 switch (tp->input[0]) { in tty3270_read_tasklet()
689 input = tp->input + 6; in tty3270_read_tasklet()
690 len = tty3270_input_size(tp->view.cols) - 6 - rrq->rescnt; in tty3270_read_tasklet()
691 if (tp->inattr != TF_INPUTN) in tty3270_read_tasklet()
693 if (tp->nr_up > 0) in tty3270_read_tasklet()
694 tp->nr_up = 0; in tty3270_read_tasklet()
701 tp->update_flags = TTY_UPDATE_ALL; in tty3270_read_tasklet()
703 if (!list_empty(&tp->readpartreq->list)) in tty3270_read_tasklet()
705 raw3270_start_request(&tp->view, tp->readpartreq, TC_WRITESF, in tty3270_read_tasklet()
709 raw3270_read_modified_cb(tp->readpartreq, tp->input); in tty3270_read_tasklet()
714 spin_unlock_irq(&tp->view.lock); in tty3270_read_tasklet()
717 raw3270_start_request(&tp->view, tp->kreset, TC_WRITE, &kreset_data, 1); in tty3270_read_tasklet()
719 while (len-- > 0) in tty3270_read_tasklet()
720 kbd_keycode(tp->kbd, *input++); in tty3270_read_tasklet()
722 kbd_keycode(tp->kbd, 256 + tp->input[0]); in tty3270_read_tasklet()
725 xchg(&tp->read, rrq); in tty3270_read_tasklet()
726 raw3270_put_view(&tp->view); in tty3270_read_tasklet()
734 struct tty3270 *tp = container_of(rq->view, struct tty3270, view); in tty3270_read_callback()
736 raw3270_get_view(rq->view); in tty3270_read_callback()
738 tasklet_schedule(&tp->readlet); in tty3270_read_callback()
749 rrq = xchg(&tp->read, 0); in tty3270_issue_read()
753 rrq->callback = tty3270_read_callback; in tty3270_issue_read()
754 rrq->callback_data = tp; in tty3270_issue_read()
756 raw3270_request_set_data(rrq, tp->input, tty3270_input_size(tp->view.cols)); in tty3270_issue_read()
759 rc = raw3270_start(&tp->view, rrq); in tty3270_issue_read()
761 rc = raw3270_start_irq(&tp->view, rrq); in tty3270_issue_read()
764 xchg(&tp->read, rrq); in tty3270_issue_read()
775 tty_port_tty_hangup(&tp->port, true); in tty3270_hangup_tasklet()
776 raw3270_put_view(&tp->view); in tty3270_hangup_tasklet()
786 tp->update_flags = TTY_UPDATE_ALL; in tty3270_activate()
795 del_timer(&tp->timer); in tty3270_deactivate()
801 if (irb->scsw.cmd.dstat & DEV_STAT_ATTENTION) { in tty3270_irq()
802 if (!tp->throttle) in tty3270_irq()
805 tp->attn = 1; in tty3270_irq()
809 if (irb->scsw.cmd.dstat & DEV_STAT_UNIT_CHECK) { in tty3270_irq()
810 rq->rc = -EIO; in tty3270_irq()
811 raw3270_get_view(&tp->view); in tty3270_irq()
812 tasklet_schedule(&tp->hanglet); in tty3270_irq()
814 /* Normal end. Copy residual count. */ in tty3270_irq()
815 rq->rescnt = irb->scsw.cmd.count; in tty3270_irq()
817 } else if (irb->scsw.cmd.dstat & DEV_STAT_DEV_END) { in tty3270_irq()
818 /* Interrupt without an outstanding request -> update all */ in tty3270_irq()
819 tp->update_flags = TTY_UPDATE_ALL; in tty3270_irq()
835 tp->write = raw3270_request_alloc(TTY3270_OUTPUT_BUFFER_SIZE); in tty3270_alloc_view()
836 if (IS_ERR(tp->write)) in tty3270_alloc_view()
838 tp->read = raw3270_request_alloc(0); in tty3270_alloc_view()
839 if (IS_ERR(tp->read)) in tty3270_alloc_view()
841 tp->kreset = raw3270_request_alloc(1); in tty3270_alloc_view()
842 if (IS_ERR(tp->kreset)) in tty3270_alloc_view()
844 tp->readpartreq = raw3270_request_alloc(sizeof(sfq_read_partition)); in tty3270_alloc_view()
845 if (IS_ERR(tp->readpartreq)) in tty3270_alloc_view()
847 tp->kbd = kbd_alloc(); in tty3270_alloc_view()
848 if (!tp->kbd) in tty3270_alloc_view()
851 tty_port_init(&tp->port); in tty3270_alloc_view()
852 timer_setup(&tp->timer, tty3270_update, 0); in tty3270_alloc_view()
853 tasklet_init(&tp->readlet, tty3270_read_tasklet, in tty3270_alloc_view()
854 (unsigned long)tp->read); in tty3270_alloc_view()
855 tasklet_init(&tp->hanglet, tty3270_hangup_tasklet, in tty3270_alloc_view()
860 raw3270_request_free(tp->readpartreq); in tty3270_alloc_view()
862 raw3270_request_free(tp->kreset); in tty3270_alloc_view()
864 raw3270_request_free(tp->read); in tty3270_alloc_view()
866 raw3270_request_free(tp->write); in tty3270_alloc_view()
870 return ERR_PTR(-ENOMEM); in tty3270_alloc_view()
878 kbd_free(tp->kbd); in tty3270_free_view()
879 raw3270_request_free(tp->kreset); in tty3270_free_view()
880 raw3270_request_free(tp->read); in tty3270_free_view()
881 raw3270_request_free(tp->write); in tty3270_free_view()
882 free_page((unsigned long)tp->converted_line); in tty3270_free_view()
883 tty_port_destroy(&tp->port); in tty3270_free_view()
908 while (lines--) in tty3270_alloc_screen()
912 return ERR_PTR(-ENOMEM); in tty3270_alloc_screen()
932 while (i--) in tty3270_alloc_recall()
973 int new_allocated, old_allocated = tp->allocated_lines; in tty3270_resize()
978 spin_lock_irq(&tp->view.lock); in tty3270_resize()
980 spin_unlock_irq(&tp->view.lock); in tty3270_resize()
998 spin_lock_irq(&tp->view.lock); in tty3270_resize()
1000 oscreen = tp->screen; in tty3270_resize()
1001 tp->screen = screen; in tty3270_resize()
1002 tp->allocated_lines = new_allocated; in tty3270_resize()
1003 tp->view.rows = new_rows; in tty3270_resize()
1004 tp->view.cols = new_cols; in tty3270_resize()
1005 tp->view.model = new_model; in tty3270_resize()
1006 tp->update_flags = TTY_UPDATE_ALL; in tty3270_resize()
1007 old_input = tp->input; in tty3270_resize()
1008 old_prompt = tp->prompt; in tty3270_resize()
1009 old_rcl_lines = tp->rcl_lines; in tty3270_resize()
1010 tp->input = new_input; in tty3270_resize()
1011 tp->prompt = new_prompt; in tty3270_resize()
1012 tp->rcl_lines = new_rcl_lines; in tty3270_resize()
1013 tp->rcl_read_index = 0; in tty3270_resize()
1014 tp->rcl_write_index = 0; in tty3270_resize()
1015 spin_unlock_irq(&tp->view.lock); in tty3270_resize()
1022 tty = tty_port_tty_get(&tp->port); in tty3270_resize()
1026 ws.ws_col = tp->view.cols; in tty3270_resize()
1044 struct tty_struct *tty = tty_port_tty_get(&tp->port); in tty3270_release()
1047 tty->driver_data = NULL; in tty3270_release()
1048 tty_port_tty_set(&tp->port, NULL); in tty3270_release()
1050 raw3270_put_view(&tp->view); in tty3270_release()
1062 del_timer_sync(&tp->timer); in tty3270_free()
1063 tty3270_free_screen(tp->screen, tp->allocated_lines); in tty3270_free()
1064 free_page((unsigned long)tp->converted_line); in tty3270_free()
1065 kfree(tp->input); in tty3270_free()
1066 kfree(tp->prompt); in tty3270_free()
1108 rc = raw3270_add_view(&tp->view, &tty3270_fn, in tty3270_create_view()
1114 tp->screen = tty3270_alloc_screen(tp, tp->view.rows, tp->view.cols, in tty3270_create_view()
1115 &tp->allocated_lines); in tty3270_create_view()
1116 if (IS_ERR(tp->screen)) { in tty3270_create_view()
1117 rc = PTR_ERR(tp->screen); in tty3270_create_view()
1121 tp->converted_line = (void *)__get_free_page(GFP_KERNEL); in tty3270_create_view()
1122 if (!tp->converted_line) { in tty3270_create_view()
1123 rc = -ENOMEM; in tty3270_create_view()
1127 tp->input = kzalloc(tty3270_input_size(tp->view.cols), GFP_KERNEL | GFP_DMA); in tty3270_create_view()
1128 if (!tp->input) { in tty3270_create_view()
1129 rc = -ENOMEM; in tty3270_create_view()
1133 tp->prompt = kzalloc(tty3270_input_size(tp->view.cols), GFP_KERNEL); in tty3270_create_view()
1134 if (!tp->prompt) { in tty3270_create_view()
1135 rc = -ENOMEM; in tty3270_create_view()
1139 tp->rcl_lines = tty3270_alloc_recall(tp->view.cols); in tty3270_create_view()
1140 if (!tp->rcl_lines) { in tty3270_create_view()
1141 rc = -ENOMEM; in tty3270_create_view()
1148 tp->kbd->port = &tp->port; in tty3270_create_view()
1149 tp->kbd->fn_handler[KVAL(K_INCRCONSOLE)] = tty3270_exit_tty; in tty3270_create_view()
1150 tp->kbd->fn_handler[KVAL(K_SCROLLBACK)] = tty3270_scroll_backward; in tty3270_create_view()
1151 tp->kbd->fn_handler[KVAL(K_SCROLLFORW)] = tty3270_scroll_forward; in tty3270_create_view()
1152 tp->kbd->fn_handler[KVAL(K_CONS)] = tty3270_rcl_backward; in tty3270_create_view()
1153 kbd_ascebc(tp->kbd, tp->view.ascebc); in tty3270_create_view()
1155 raw3270_activate_view(&tp->view); in tty3270_create_view()
1156 raw3270_put_view(&tp->view); in tty3270_create_view()
1161 kfree(tp->prompt); in tty3270_create_view()
1163 kfree(tp->input); in tty3270_create_view()
1165 free_page((unsigned long)tp->converted_line); in tty3270_create_view()
1167 tty3270_free_screen(tp->screen, tp->view.rows); in tty3270_create_view()
1169 raw3270_put_view(&tp->view); in tty3270_create_view()
1170 raw3270_del_view(&tp->view); in tty3270_create_view()
1187 view = raw3270_find_view(&tty3270_fn, tty->index + RAW3270_FIRSTMINOR); in tty3270_install()
1189 rc = tty3270_create_view(tty->index, &tp); in tty3270_install()
1194 tty->driver_data = tp; in tty3270_install()
1195 tp->inattr = TF_INPUT; in tty3270_install()
1198 tty->winsize.ws_row = tty3270_tty_rows(tp); in tty3270_install()
1199 tty->winsize.ws_col = tp->view.cols; in tty3270_install()
1200 rc = tty_port_install(&tp->port, driver, tty); in tty3270_install()
1202 raw3270_put_view(&tp->view); in tty3270_install()
1205 tty->driver_data = tp; in tty3270_install()
1214 struct tty3270 *tp = tty->driver_data; in tty3270_open()
1215 struct tty_port *port = &tp->port; in tty3270_open()
1217 port->count++; in tty3270_open()
1228 struct tty3270 *tp = tty->driver_data; in tty3270_close()
1230 if (tty->count > 1) in tty3270_close()
1233 tty_port_tty_set(&tp->port, NULL); in tty3270_close()
1238 struct tty3270 *tp = tty->driver_data; in tty3270_cleanup()
1241 tty->driver_data = NULL; in tty3270_cleanup()
1242 raw3270_put_view(&tp->view); in tty3270_cleanup()
1261 struct tty3270_cell *cell; in tty3270_put_character() local
1263 line = tty3270_get_write_line(tp, tp->cy); in tty3270_put_character()
1264 if (line->len <= tp->cx) { in tty3270_put_character()
1265 while (line->len < tp->cx) { in tty3270_put_character()
1266 cell = line->cells + line->len; in tty3270_put_character()
1267 cell->character = ' '; in tty3270_put_character()
1268 cell->attributes = tp->attributes; in tty3270_put_character()
1269 line->len++; in tty3270_put_character()
1271 line->len++; in tty3270_put_character()
1273 cell = line->cells + tp->cx; in tty3270_put_character()
1274 cell->character = ch; in tty3270_put_character()
1275 cell->attributes = tp->attributes; in tty3270_put_character()
1276 line->dirty = 1; in tty3270_put_character()
1284 tp->cx = 0; in tty3270_cr()
1295 if (tp->cy < tty3270_tty_rows(tp) - 1) { in tty3270_lf()
1296 tp->cy++; in tty3270_lf()
1298 tp->line_view_start = tty3270_line_increment(tp, tp->line_view_start, 1); in tty3270_lf()
1299 tp->line_write_start = tty3270_line_increment(tp, tp->line_write_start, 1); in tty3270_lf()
1301 tty3270_get_view_line(tp, i)->dirty = 1; in tty3270_lf()
1304 line = tty3270_get_write_line(tp, tp->cy); in tty3270_lf()
1305 line->len = 0; in tty3270_lf()
1306 line->dirty = 1; in tty3270_lf()
1311 if (tp->cy > 0) in tty3270_ri()
1312 tp->cy--; in tty3270_ri()
1315 static void tty3270_reset_cell(struct tty3270 *tp, struct tty3270_cell *cell) in tty3270_reset_cell() argument
1317 cell->character = ' '; in tty3270_reset_cell()
1318 tty3270_reset_attributes(&cell->attributes); in tty3270_reset_cell()
1329 line = tty3270_get_write_line(tp, tp->cy); in tty3270_insert_characters()
1330 while (line->len < tp->cx) in tty3270_insert_characters()
1331 tty3270_reset_cell(tp, &line->cells[line->len++]); in tty3270_insert_characters()
1332 if (n > tp->view.cols - tp->cx) in tty3270_insert_characters()
1333 n = tp->view.cols - tp->cx; in tty3270_insert_characters()
1334 k = min_t(int, line->len - tp->cx, tp->view.cols - tp->cx - n); in tty3270_insert_characters()
1335 while (k--) in tty3270_insert_characters()
1336 line->cells[tp->cx + n + k] = line->cells[tp->cx + k]; in tty3270_insert_characters()
1337 line->len += n; in tty3270_insert_characters()
1338 if (line->len > tp->view.cols) in tty3270_insert_characters()
1339 line->len = tp->view.cols; in tty3270_insert_characters()
1340 while (n-- > 0) { in tty3270_insert_characters()
1341 line->cells[tp->cx + n].character = ' '; in tty3270_insert_characters()
1342 line->cells[tp->cx + n].attributes = tp->attributes; in tty3270_insert_characters()
1354 line = tty3270_get_write_line(tp, tp->cy); in tty3270_delete_characters()
1355 if (line->len <= tp->cx) in tty3270_delete_characters()
1357 if (line->len - tp->cx <= n) { in tty3270_delete_characters()
1358 line->len = tp->cx; in tty3270_delete_characters()
1361 for (i = tp->cx; i + n < line->len; i++) in tty3270_delete_characters()
1362 line->cells[i] = line->cells[i + n]; in tty3270_delete_characters()
1363 line->len -= n; in tty3270_delete_characters()
1372 struct tty3270_cell *cell; in tty3270_erase_characters() local
1374 line = tty3270_get_write_line(tp, tp->cy); in tty3270_erase_characters()
1375 while (line->len > tp->cx && n-- > 0) { in tty3270_erase_characters()
1376 cell = line->cells + tp->cx++; in tty3270_erase_characters()
1377 tty3270_reset_cell(tp, cell); in tty3270_erase_characters()
1379 tp->cx += n; in tty3270_erase_characters()
1380 tp->cx = min_t(int, tp->cx, tp->view.cols - 1); in tty3270_erase_characters()
1392 struct tty3270_cell *cell; in tty3270_erase_line() local
1395 line = tty3270_get_write_line(tp, tp->cy); in tty3270_erase_line()
1399 start = tp->cx; in tty3270_erase_line()
1400 end = tp->view.cols; in tty3270_erase_line()
1404 end = tp->cx; in tty3270_erase_line()
1408 end = tp->view.cols; in tty3270_erase_line()
1415 cell = line->cells + i; in tty3270_erase_line()
1416 tty3270_reset_cell(tp, cell); in tty3270_erase_line()
1417 cell->attributes.b_color = tp->attributes.b_color; in tty3270_erase_line()
1420 if (line->len <= end) in tty3270_erase_line()
1421 line->len = end; in tty3270_erase_line()
1438 start = tp->cy + 1; in tty3270_erase_display()
1443 end = tp->cy; in tty3270_erase_display()
1455 line->len = 0; in tty3270_erase_display()
1456 line->dirty = 1; in tty3270_erase_display()
1468 for (i = 0; i <= tp->esc_npar; i++) { in tty3270_set_attributes()
1469 attr = tp->esc_par[i]; in tty3270_set_attributes()
1472 tty3270_reset_attributes(&tp->attributes); in tty3270_set_attributes()
1476 tp->attributes.highlight = TTY3270_HIGHLIGHT_UNDERSCORE; in tty3270_set_attributes()
1479 tp->attributes.highlight = TTY3270_HIGHLIGHT_BLINK; in tty3270_set_attributes()
1482 tp->attributes.highlight = TTY3270_HIGHLIGHT_REVERSE; in tty3270_set_attributes()
1485 tp->attributes.highlight &= ~TTY3270_HIGHLIGHT_UNDERSCORE; in tty3270_set_attributes()
1488 tp->attributes.highlight &= ~TTY3270_HIGHLIGHT_BLINK; in tty3270_set_attributes()
1491 tp->attributes.highlight &= ~TTY3270_HIGHLIGHT_REVERSE; in tty3270_set_attributes()
1503 tp->attributes.f_color = attr - 30; in tty3270_set_attributes()
1515 tp->attributes.b_color = attr - 40; in tty3270_set_attributes()
1523 return (tp->esc_par[ix] > 0) ? tp->esc_par[ix] : 1; in tty3270_getpar()
1529 struct tty3270_cell *cell; in tty3270_goto_xy() local
1533 tp->cx = min_t(int, tp->view.cols - 1, max_cx); in tty3270_goto_xy()
1534 line = tty3270_get_write_line(tp, tp->cy); in tty3270_goto_xy()
1535 while (line->len < tp->cx) { in tty3270_goto_xy()
1536 cell = line->cells + line->len; in tty3270_goto_xy()
1537 cell->character = ' '; in tty3270_goto_xy()
1538 cell->attributes = tp->attributes; in tty3270_goto_xy()
1539 line->len++; in tty3270_goto_xy()
1541 tp->cy = min_t(int, tty3270_tty_rows(tp) - 1, max_cy); in tty3270_goto_xy()
1568 if (tp->esc_state == ES_NORMAL) { in tty3270_escape_sequence()
1571 tp->esc_state = ES_ESC; in tty3270_escape_sequence()
1574 if (tp->esc_state == ES_ESC) { in tty3270_escape_sequence()
1575 tp->esc_state = ES_NORMAL; in tty3270_escape_sequence()
1578 tp->esc_state = ES_SQUARE; in tty3270_escape_sequence()
1581 tp->esc_state = ES_PAREN; in tty3270_escape_sequence()
1594 kbd_puts_queue(&tp->port, "\033[?6c"); in tty3270_escape_sequence()
1597 tp->saved_cx = tp->cx; in tty3270_escape_sequence()
1598 tp->saved_cy = tp->cy; in tty3270_escape_sequence()
1599 tp->saved_attributes = tp->attributes; in tty3270_escape_sequence()
1602 tty3270_goto_xy(tp, tp->saved_cx, tp->saved_cy); in tty3270_escape_sequence()
1603 tp->attributes = tp->saved_attributes; in tty3270_escape_sequence()
1606 tp->cx = 0; in tty3270_escape_sequence()
1607 tp->cy = 0; in tty3270_escape_sequence()
1608 tp->saved_cx = 0; in tty3270_escape_sequence()
1609 tp->saved_cy = 0; in tty3270_escape_sequence()
1610 tty3270_reset_attributes(&tp->attributes); in tty3270_escape_sequence()
1611 tty3270_reset_attributes(&tp->saved_attributes); in tty3270_escape_sequence()
1618 switch (tp->esc_state) { in tty3270_escape_sequence()
1620 tp->esc_state = ES_NORMAL; in tty3270_escape_sequence()
1623 tp->attributes.alternate_charset = 0; in tty3270_escape_sequence()
1626 tp->attributes.alternate_charset = 1; in tty3270_escape_sequence()
1631 tp->esc_state = ES_GETPARS; in tty3270_escape_sequence()
1632 memset(tp->esc_par, 0, sizeof(tp->esc_par)); in tty3270_escape_sequence()
1633 tp->esc_npar = 0; in tty3270_escape_sequence()
1634 tp->esc_ques = (ch == '?'); in tty3270_escape_sequence()
1635 if (tp->esc_ques) in tty3270_escape_sequence()
1639 if (ch == ';' && tp->esc_npar < ESCAPE_NPAR - 1) { in tty3270_escape_sequence()
1640 tp->esc_npar++; in tty3270_escape_sequence()
1644 tp->esc_par[tp->esc_npar] *= 10; in tty3270_escape_sequence()
1645 tp->esc_par[tp->esc_npar] += ch - '0'; in tty3270_escape_sequence()
1652 tp->esc_state = ES_NORMAL; in tty3270_escape_sequence()
1653 if (ch == 'n' && !tp->esc_ques) { in tty3270_escape_sequence()
1654 if (tp->esc_par[0] == 5) /* Status report. */ in tty3270_escape_sequence()
1655 kbd_puts_queue(&tp->port, "\033[0n"); in tty3270_escape_sequence()
1656 else if (tp->esc_par[0] == 6) { /* Cursor report. */ in tty3270_escape_sequence()
1659 sprintf(buf, "\033[%d;%dR", tp->cy + 1, tp->cx + 1); in tty3270_escape_sequence()
1660 kbd_puts_queue(&tp->port, buf); in tty3270_escape_sequence()
1664 if (tp->esc_ques) in tty3270_escape_sequence()
1672 tty3270_goto_xy(tp, tty3270_getpar(tp, 1) - 1, in tty3270_escape_sequence()
1673 tty3270_getpar(tp, 0) - 1); in tty3270_escape_sequence()
1676 tty3270_goto_xy(tp, tp->cx, tty3270_getpar(tp, 0) - 1); in tty3270_escape_sequence()
1680 tty3270_goto_xy(tp, tp->cx, tp->cy - tty3270_getpar(tp, 0)); in tty3270_escape_sequence()
1685 tty3270_goto_xy(tp, tp->cx, tp->cy + tty3270_getpar(tp, 0)); in tty3270_escape_sequence()
1689 tty3270_goto_xy(tp, tp->cx + tty3270_getpar(tp, 0), tp->cy); in tty3270_escape_sequence()
1692 tty3270_goto_xy(tp, tp->cx - tty3270_getpar(tp, 0), tp->cy); in tty3270_escape_sequence()
1696 tty3270_goto_xy(tp, tty3270_getpar(tp, 0), tp->cy); in tty3270_escape_sequence()
1702 tty3270_erase_display(tp, tp->esc_par[0]); in tty3270_escape_sequence()
1705 tty3270_erase_line(tp, tp->esc_par[0]); in tty3270_escape_sequence()
1714 tp->saved_cx = tp->cx; in tty3270_escape_sequence()
1715 tp->saved_cy = tp->cy; in tty3270_escape_sequence()
1716 tp->saved_attributes = tp->attributes; in tty3270_escape_sequence()
1719 tty3270_goto_xy(tp, tp->saved_cx, tp->saved_cy); in tty3270_escape_sequence()
1720 tp->attributes = tp->saved_attributes; in tty3270_escape_sequence()
1729 const unsigned char *buf, int count) in tty3270_do_write() argument
1733 spin_lock_irq(&tp->view.lock); in tty3270_do_write()
1734 for (i_msg = 0; !tty->flow.stopped && i_msg < count; i_msg++) { in tty3270_do_write()
1735 if (tp->esc_state != 0) { in tty3270_do_write()
1744 case 0x07: /* '\a' -- Alarm */ in tty3270_do_write()
1745 tp->wcc |= TW_PLUSALARM; in tty3270_do_write()
1748 if (tp->cx > 0) { in tty3270_do_write()
1749 tp->cx--; in tty3270_do_write()
1753 case 0x09: /* '\t' -- Tabulate */ in tty3270_do_write()
1754 for (i = tp->cx % 8; i < 8; i++) { in tty3270_do_write()
1755 if (tp->cx >= tp->view.cols) { in tty3270_do_write()
1761 tp->cx++; in tty3270_do_write()
1764 case 0x0a: /* '\n' -- New Line */ in tty3270_do_write()
1768 case 0x0c: /* '\f' -- Form Feed */ in tty3270_do_write()
1770 tp->cx = 0; in tty3270_do_write()
1771 tp->cy = 0; in tty3270_do_write()
1773 case 0x0d: /* '\r' -- Carriage Return */ in tty3270_do_write()
1774 tp->cx = 0; in tty3270_do_write()
1777 tp->attributes.alternate_charset = 1; in tty3270_do_write()
1780 tp->attributes.alternate_charset = 0; in tty3270_do_write()
1786 if (tp->cx >= tp->view.cols) { in tty3270_do_write()
1791 tp->cx++; in tty3270_do_write()
1796 tp->update_flags |= TTY_UPDATE_LINES; in tty3270_do_write()
1797 if (!timer_pending(&tp->timer)) in tty3270_do_write()
1800 spin_unlock_irq(&tp->view.lock); in tty3270_do_write()
1807 size_t count) in tty3270_write() argument
1811 tp = tty->driver_data; in tty3270_write()
1814 if (tp->char_count > 0) { in tty3270_write()
1815 tty3270_do_write(tp, tty, tp->char_buf, tp->char_count); in tty3270_write()
1816 tp->char_count = 0; in tty3270_write()
1818 tty3270_do_write(tp, tty, buf, count); in tty3270_write()
1819 return count; in tty3270_write()
1829 tp = tty->driver_data; in tty3270_put_char()
1830 if (!tp || tp->char_count >= TTY3270_CHAR_BUF_SIZE) in tty3270_put_char()
1832 tp->char_buf[tp->char_count++] = ch; in tty3270_put_char()
1844 tp = tty->driver_data; in tty3270_flush_chars()
1847 if (tp->char_count > 0) { in tty3270_flush_chars()
1848 tty3270_do_write(tp, tty, tp->char_buf, tp->char_count); in tty3270_flush_chars()
1849 tp->char_count = 0; in tty3270_flush_chars()
1861 tp = tty->driver_data; in tty3270_set_termios()
1864 spin_lock_irq(&tp->view.lock); in tty3270_set_termios()
1867 if (new != tp->inattr) { in tty3270_set_termios()
1868 tp->inattr = new; in tty3270_set_termios()
1873 spin_unlock_irq(&tp->view.lock); in tty3270_set_termios()
1883 tp = tty->driver_data; in tty3270_throttle()
1886 tp->throttle = 1; in tty3270_throttle()
1896 tp = tty->driver_data; in tty3270_unthrottle()
1899 tp->throttle = 0; in tty3270_unthrottle()
1900 if (tp->attn) in tty3270_unthrottle()
1911 tp = tty->driver_data; in tty3270_hangup()
1914 spin_lock_irq(&tp->view.lock); in tty3270_hangup()
1915 tp->cx = 0; in tty3270_hangup()
1916 tp->cy = 0; in tty3270_hangup()
1917 tp->saved_cx = 0; in tty3270_hangup()
1918 tp->saved_cy = 0; in tty3270_hangup()
1919 tty3270_reset_attributes(&tp->attributes); in tty3270_hangup()
1920 tty3270_reset_attributes(&tp->saved_attributes); in tty3270_hangup()
1922 tp->update_flags = TTY_UPDATE_ALL; in tty3270_hangup()
1923 spin_unlock_irq(&tp->view.lock); in tty3270_hangup()
1936 tp = tty->driver_data; in tty3270_ioctl()
1938 return -ENODEV; in tty3270_ioctl()
1940 return -EIO; in tty3270_ioctl()
1941 return kbd_ioctl(tp->kbd, cmd, arg); in tty3270_ioctl()
1950 tp = tty->driver_data; in tty3270_compat_ioctl()
1952 return -ENODEV; in tty3270_compat_ioctl()
1954 return -EIO; in tty3270_compat_ioctl()
1955 return kbd_ioctl(tp->kbd, cmd, (unsigned long)compat_ptr(arg)); in tty3270_compat_ioctl()
1981 tty_register_device(tty3270_driver, minor - RAW3270_FIRSTMINOR, NULL); in tty3270_create_cb()
1986 tty_unregister_device(tty3270_driver, minor - RAW3270_FIRSTMINOR); in tty3270_destroy_cb()
2015 driver->driver_name = "tty3270"; in tty3270_init()
2016 driver->name = "3270/tty"; in tty3270_init()
2017 driver->major = IBM_TTY3270_MAJOR; in tty3270_init()
2018 driver->minor_start = RAW3270_FIRSTMINOR; in tty3270_init()
2019 driver->name_base = RAW3270_FIRSTMINOR; in tty3270_init()
2020 driver->type = TTY_DRIVER_TYPE_SYSTEM; in tty3270_init()
2021 driver->subtype = SYSTEM_TYPE_TTY; in tty3270_init()
2022 driver->init_termios = tty_std_termios; in tty3270_init()
2051 con3270_write(struct console *co, const char *str, unsigned int count) in con3270_write() argument
2053 struct tty3270 *tp = co->data; in con3270_write()
2057 spin_lock_irqsave(&tp->view.lock, flags); in con3270_write()
2058 while (count--) { in con3270_write()
2064 if (tp->cx >= tp->view.cols) { in con3270_write()
2069 tp->cx++; in con3270_write()
2072 spin_unlock_irqrestore(&tp->view.lock, flags); in con3270_write()
2078 *index = c->index; in con3270_device()
2085 while (!tp->write) { in con3270_wait_write()
2086 raw3270_wait_cons_dev(tp->view.dev); in con3270_wait_write()
2107 if (!tp->view.dev) in con3270_notify()
2109 if (!raw3270_view_lock_unavailable(&tp->view)) { in con3270_notify()
2110 rc = raw3270_activate_view(&tp->view); in con3270_notify()
2114 if (!spin_trylock_irqsave(&tp->view.lock, flags)) in con3270_notify()
2117 tp->nr_up = 0; in con3270_notify()
2118 tp->update_flags = TTY_UPDATE_ALL; in con3270_notify()
2119 while (tp->update_flags != 0) { in con3270_notify()
2120 spin_unlock_irqrestore(&tp->view.lock, flags); in con3270_notify()
2121 tty3270_update(&tp->timer); in con3270_notify()
2122 spin_lock_irqsave(&tp->view.lock, flags); in con3270_notify()
2125 spin_unlock_irqrestore(&tp->view.lock, flags); in con3270_notify()
2156 return -ENODEV; in con3270_init()
2176 tp->inattr = TF_INPUT; in con3270_init()