Lines Matching refs:port
114 static int vcc_table_add(struct vcc_port *port) in vcc_table_add() argument
122 vcc_table[i] = port; in vcc_table_add()
160 struct vcc_port *port; in vcc_get() local
166 port = vcc_table[index]; in vcc_get()
167 if (!port) { in vcc_get()
173 if (port->excl_locked) { in vcc_get()
178 port->refcnt++; in vcc_get()
180 return port; in vcc_get()
183 if (port->refcnt) { in vcc_get()
193 port->refcnt++; in vcc_get()
194 port->excl_locked = true; in vcc_get()
197 return port; in vcc_get()
208 static void vcc_put(struct vcc_port *port, bool excl) in vcc_put() argument
212 if (!port) in vcc_put()
218 if (WARN_ON((excl && !port->excl_locked) || in vcc_put()
219 (!excl && port->excl_locked))) in vcc_put()
222 port->refcnt--; in vcc_put()
225 port->excl_locked = false; in vcc_put()
242 struct vcc_port *port; in vcc_get_ne() local
244 port = vcc_get(index, false); in vcc_get_ne()
246 if (port && port->removed) { in vcc_get_ne()
247 vcc_put(port, false); in vcc_get_ne()
251 return port; in vcc_get_ne()
254 static void vcc_kick_rx(struct vcc_port *port) in vcc_kick_rx() argument
256 struct vio_driver_state *vio = &port->vio; in vcc_kick_rx()
258 assert_spin_locked(&port->lock); in vcc_kick_rx()
260 if (!timer_pending(&port->rx_timer) && !port->removed) { in vcc_kick_rx()
262 port->rx_timer.expires = (jiffies + 1); in vcc_kick_rx()
263 add_timer(&port->rx_timer); in vcc_kick_rx()
267 static void vcc_kick_tx(struct vcc_port *port) in vcc_kick_tx() argument
269 assert_spin_locked(&port->lock); in vcc_kick_tx()
271 if (!timer_pending(&port->tx_timer) && !port->removed) { in vcc_kick_tx()
272 port->tx_timer.expires = (jiffies + 1); in vcc_kick_tx()
273 add_timer(&port->tx_timer); in vcc_kick_tx()
279 if (WARN_ON(!tty || !tty->port)) in vcc_rx_check()
286 (tty_buffer_request_room(tty->port, VCC_BUFF_LEN) < VCC_BUFF_LEN)) in vcc_rx_check()
296 if (WARN_ON(!tty || !tty->port)) in vcc_rx()
299 len = tty_insert_flip_string(tty->port, buf, size); in vcc_rx()
301 tty_flip_buffer_push(tty->port); in vcc_rx()
306 static int vcc_ldc_read(struct vcc_port *port) in vcc_ldc_read() argument
308 struct vio_driver_state *vio = &port->vio; in vcc_ldc_read()
313 tty = port->tty; in vcc_ldc_read()
323 vcc_kick_rx(port); in vcc_ldc_read()
359 struct vcc_port *port = from_timer(port, t, rx_timer); in vcc_rx_timer() local
364 spin_lock_irqsave(&port->lock, flags); in vcc_rx_timer()
365 port->rx_timer.expires = 0; in vcc_rx_timer()
367 vio = &port->vio; in vcc_rx_timer()
371 if (!port->tty || port->removed) in vcc_rx_timer()
374 rv = vcc_ldc_read(port); in vcc_rx_timer()
379 spin_unlock_irqrestore(&port->lock, flags); in vcc_rx_timer()
380 vcc_put(port, false); in vcc_rx_timer()
385 struct vcc_port *port = from_timer(port, t, tx_timer); in vcc_tx_timer() local
391 spin_lock_irqsave(&port->lock, flags); in vcc_tx_timer()
392 port->tx_timer.expires = 0; in vcc_tx_timer()
394 if (!port->tty || port->removed) in vcc_tx_timer()
397 tosend = min(VCC_BUFF_LEN, port->chars_in_buffer); in vcc_tx_timer()
401 pkt = &port->buffer; in vcc_tx_timer()
404 vccdbgl(port->vio.lp); in vcc_tx_timer()
406 rv = ldc_write(port->vio.lp, pkt, (VIO_TAG_SIZE + tosend)); in vcc_tx_timer()
411 vcc_kick_tx(port); in vcc_tx_timer()
413 struct tty_struct *tty = port->tty; in vcc_tx_timer()
415 port->chars_in_buffer = 0; in vcc_tx_timer()
421 spin_unlock_irqrestore(&port->lock, flags); in vcc_tx_timer()
422 vcc_put(port, false); in vcc_tx_timer()
435 struct vcc_port *port; in vcc_event() local
439 port = arg; in vcc_event()
440 vio = &port->vio; in vcc_event()
442 spin_lock_irqsave(&port->lock, flags); in vcc_event()
451 rv = vcc_ldc_read(port); in vcc_event()
460 spin_unlock_irqrestore(&port->lock, flags); in vcc_event()
481 struct vcc_port *port; in domain_show() local
484 port = dev_get_drvdata(dev); in domain_show()
485 if (!port) in domain_show()
488 rv = scnprintf(buf, PAGE_SIZE, "%s\n", port->domain); in domain_show()
493 static int vcc_send_ctl(struct vcc_port *port, int ctl) in vcc_send_ctl() argument
502 rv = ldc_write(port->vio.lp, &pkt, sizeof(pkt.tag)); in vcc_send_ctl()
513 struct vcc_port *port; in break_store() local
518 port = dev_get_drvdata(dev); in break_store()
519 if (!port) in break_store()
522 spin_lock_irqsave(&port->lock, flags); in break_store()
526 else if (vcc_send_ctl(port, VCC_CTL_BREAK) < 0) in break_store()
527 vcc_kick_tx(port); in break_store()
529 spin_unlock_irqrestore(&port->lock, flags); in break_store()
563 struct vcc_port *port; in vcc_probe() local
577 port = kzalloc(sizeof(struct vcc_port), GFP_KERNEL); in vcc_probe()
578 if (!port) in vcc_probe()
587 rv = vio_driver_init(&port->vio, vdev, VDEV_CONSOLE_CON, vcc_versions, in vcc_probe()
592 port->vio.debug = vcc_dbg_vio; in vcc_probe()
595 rv = vio_ldc_alloc(&port->vio, &vcc_ldc_cfg, port); in vcc_probe()
599 spin_lock_init(&port->lock); in vcc_probe()
601 port->index = vcc_table_add(port); in vcc_probe()
602 if (port->index == -1) { in vcc_probe()
609 dev = tty_register_device(vcc_tty_driver, port->index, &vdev->dev); in vcc_probe()
630 port->domain = kstrdup(domain, GFP_KERNEL); in vcc_probe()
631 if (!port->domain) { in vcc_probe()
643 timer_setup(&port->rx_timer, vcc_rx_timer, 0); in vcc_probe()
644 timer_setup(&port->tx_timer, vcc_tx_timer, 0); in vcc_probe()
646 dev_set_drvdata(&vdev->dev, port); in vcc_probe()
652 vio_port_up(&port->vio); in vcc_probe()
658 kfree(port->domain); in vcc_probe()
660 tty_unregister_device(vcc_tty_driver, port->index); in vcc_probe()
662 vcc_table_remove(port->index); in vcc_probe()
664 vio_ldc_free(&port->vio); in vcc_probe()
668 kfree(port); in vcc_probe()
684 struct vcc_port *port = dev_get_drvdata(&vdev->dev); in vcc_remove() local
686 del_timer_sync(&port->rx_timer); in vcc_remove()
687 del_timer_sync(&port->tx_timer); in vcc_remove()
693 if (port->tty) in vcc_remove()
694 tty_vhangup(port->tty); in vcc_remove()
699 vcc_get(port->index, true); in vcc_remove()
701 tty_unregister_device(vcc_tty_driver, port->index); in vcc_remove()
703 del_timer_sync(&port->vio.timer); in vcc_remove()
704 vio_ldc_free(&port->vio); in vcc_remove()
707 if (port->tty) { in vcc_remove()
708 port->removed = true; in vcc_remove()
709 vcc_put(port, true); in vcc_remove()
711 vcc_table_remove(port->index); in vcc_remove()
713 kfree(port->vio.name); in vcc_remove()
714 kfree(port->domain); in vcc_remove()
715 kfree(port); in vcc_remove()
736 struct vcc_port *port; in vcc_open() local
741 port = vcc_get_ne(tty->index); in vcc_open()
742 if (unlikely(!port)) { in vcc_open()
747 if (unlikely(!port->vio.lp)) { in vcc_open()
749 vcc_put(port, false); in vcc_open()
752 vccdbgl(port->vio.lp); in vcc_open()
754 vcc_put(port, false); in vcc_open()
756 if (unlikely(!tty->port)) { in vcc_open()
761 if (unlikely(!tty->port->ops)) { in vcc_open()
766 return tty_port_open(tty->port, tty, vcc_file); in vcc_open()
774 if (unlikely(!tty->port)) { in vcc_close()
779 tty_port_close(tty->port, tty, vcc_file); in vcc_close()
782 static void vcc_ldc_hup(struct vcc_port *port) in vcc_ldc_hup() argument
786 spin_lock_irqsave(&port->lock, flags); in vcc_ldc_hup()
788 if (vcc_send_ctl(port, VCC_CTL_HUP) < 0) in vcc_ldc_hup()
789 vcc_kick_tx(port); in vcc_ldc_hup()
791 spin_unlock_irqrestore(&port->lock, flags); in vcc_ldc_hup()
796 struct vcc_port *port; in vcc_hangup() local
798 port = vcc_get_ne(tty->index); in vcc_hangup()
799 if (unlikely(!port)) { in vcc_hangup()
804 if (unlikely(!tty->port)) { in vcc_hangup()
806 vcc_put(port, false); in vcc_hangup()
810 vcc_ldc_hup(port); in vcc_hangup()
812 vcc_put(port, false); in vcc_hangup()
814 tty_port_hangup(tty->port); in vcc_hangup()
819 struct vcc_port *port; in vcc_write() local
826 port = vcc_get_ne(tty->index); in vcc_write()
827 if (unlikely(!port)) { in vcc_write()
832 spin_lock_irqsave(&port->lock, flags); in vcc_write()
834 pkt = &port->buffer; in vcc_write()
840 (VCC_BUFF_LEN - port->chars_in_buffer)); in vcc_write()
845 memcpy(&pkt->data[port->chars_in_buffer], &buf[total_sent], in vcc_write()
847 port->chars_in_buffer += tosend; in vcc_write()
853 vccdbgl(port->vio.lp); in vcc_write()
859 rv = ldc_write(port->vio.lp, pkt, (VIO_TAG_SIZE + tosend)); in vcc_write()
866 vcc_kick_tx(port); in vcc_write()
870 port->chars_in_buffer = 0; in vcc_write()
873 spin_unlock_irqrestore(&port->lock, flags); in vcc_write()
875 vcc_put(port, false); in vcc_write()
884 struct vcc_port *port; in vcc_write_room() local
887 port = vcc_get_ne(tty->index); in vcc_write_room()
888 if (unlikely(!port)) { in vcc_write_room()
893 num = VCC_BUFF_LEN - port->chars_in_buffer; in vcc_write_room()
895 vcc_put(port, false); in vcc_write_room()
902 struct vcc_port *port; in vcc_chars_in_buffer() local
905 port = vcc_get_ne(tty->index); in vcc_chars_in_buffer()
906 if (unlikely(!port)) { in vcc_chars_in_buffer()
911 num = port->chars_in_buffer; in vcc_chars_in_buffer()
913 vcc_put(port, false); in vcc_chars_in_buffer()
920 struct vcc_port *port; in vcc_break_ctl() local
923 port = vcc_get_ne(tty->index); in vcc_break_ctl()
924 if (unlikely(!port)) { in vcc_break_ctl()
931 vcc_put(port, false); in vcc_break_ctl()
935 spin_lock_irqsave(&port->lock, flags); in vcc_break_ctl()
937 if (vcc_send_ctl(port, VCC_CTL_BREAK) < 0) in vcc_break_ctl()
938 vcc_kick_tx(port); in vcc_break_ctl()
940 spin_unlock_irqrestore(&port->lock, flags); in vcc_break_ctl()
942 vcc_put(port, false); in vcc_break_ctl()
967 tty->port = NULL; in vcc_install()
974 tty->port = port_tty; in vcc_install()
985 struct vcc_port *port; in vcc_cleanup() local
987 port = vcc_get(tty->index, true); in vcc_cleanup()
988 if (port) { in vcc_cleanup()
989 port->tty = NULL; in vcc_cleanup()
991 if (port->removed) { in vcc_cleanup()
993 kfree(port->vio.name); in vcc_cleanup()
994 kfree(port->domain); in vcc_cleanup()
995 kfree(port); in vcc_cleanup()
997 vcc_put(port, true); in vcc_cleanup()
1001 tty_port_destroy(tty->port); in vcc_cleanup()
1002 kfree(tty->port); in vcc_cleanup()
1003 tty->port = NULL; in vcc_cleanup()