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()
583 rv = vio_driver_init(&port->vio, vdev, VDEV_CONSOLE_CON, vcc_versions, in vcc_probe()
588 port->vio.debug = vcc_dbg_vio; in vcc_probe()
591 rv = vio_ldc_alloc(&port->vio, &vcc_ldc_cfg, port); in vcc_probe()
595 spin_lock_init(&port->lock); in vcc_probe()
597 port->index = vcc_table_add(port); in vcc_probe()
598 if (port->index == -1) { in vcc_probe()
605 dev = tty_register_device(vcc_tty_driver, port->index, &vdev->dev); in vcc_probe()
626 port->domain = kstrdup(domain, GFP_KERNEL); in vcc_probe()
634 timer_setup(&port->rx_timer, vcc_rx_timer, 0); in vcc_probe()
635 timer_setup(&port->tx_timer, vcc_tx_timer, 0); in vcc_probe()
637 dev_set_drvdata(&vdev->dev, port); in vcc_probe()
643 vio_port_up(&port->vio); in vcc_probe()
649 kfree(port->domain); in vcc_probe()
651 tty_unregister_device(vcc_tty_driver, port->index); in vcc_probe()
653 vcc_table_remove(port->index); in vcc_probe()
655 vio_ldc_free(&port->vio); in vcc_probe()
658 kfree(port); in vcc_probe()
674 struct vcc_port *port = dev_get_drvdata(&vdev->dev); in vcc_remove() local
676 del_timer_sync(&port->rx_timer); in vcc_remove()
677 del_timer_sync(&port->tx_timer); in vcc_remove()
683 if (port->tty) in vcc_remove()
684 tty_vhangup(port->tty); in vcc_remove()
689 vcc_get(port->index, true); in vcc_remove()
691 tty_unregister_device(vcc_tty_driver, port->index); in vcc_remove()
693 del_timer_sync(&port->vio.timer); in vcc_remove()
694 vio_ldc_free(&port->vio); in vcc_remove()
697 if (port->tty) { in vcc_remove()
698 port->removed = true; in vcc_remove()
699 vcc_put(port, true); in vcc_remove()
701 vcc_table_remove(port->index); in vcc_remove()
703 kfree(port->vio.name); in vcc_remove()
704 kfree(port->domain); in vcc_remove()
705 kfree(port); in vcc_remove()
726 struct vcc_port *port; in vcc_open() local
731 port = vcc_get_ne(tty->index); in vcc_open()
732 if (unlikely(!port)) { in vcc_open()
737 if (unlikely(!port->vio.lp)) { in vcc_open()
739 vcc_put(port, false); in vcc_open()
742 vccdbgl(port->vio.lp); in vcc_open()
744 vcc_put(port, false); in vcc_open()
746 if (unlikely(!tty->port)) { in vcc_open()
751 if (unlikely(!tty->port->ops)) { in vcc_open()
756 return tty_port_open(tty->port, tty, vcc_file); in vcc_open()
764 if (unlikely(!tty->port)) { in vcc_close()
769 tty_port_close(tty->port, tty, vcc_file); in vcc_close()
772 static void vcc_ldc_hup(struct vcc_port *port) in vcc_ldc_hup() argument
776 spin_lock_irqsave(&port->lock, flags); in vcc_ldc_hup()
778 if (vcc_send_ctl(port, VCC_CTL_HUP) < 0) in vcc_ldc_hup()
779 vcc_kick_tx(port); in vcc_ldc_hup()
781 spin_unlock_irqrestore(&port->lock, flags); in vcc_ldc_hup()
786 struct vcc_port *port; in vcc_hangup() local
788 port = vcc_get_ne(tty->index); in vcc_hangup()
789 if (unlikely(!port)) { in vcc_hangup()
794 if (unlikely(!tty->port)) { in vcc_hangup()
796 vcc_put(port, false); in vcc_hangup()
800 vcc_ldc_hup(port); in vcc_hangup()
802 vcc_put(port, false); in vcc_hangup()
804 tty_port_hangup(tty->port); in vcc_hangup()
810 struct vcc_port *port; in vcc_write() local
817 port = vcc_get_ne(tty->index); in vcc_write()
818 if (unlikely(!port)) { in vcc_write()
823 spin_lock_irqsave(&port->lock, flags); in vcc_write()
825 pkt = &port->buffer; in vcc_write()
830 tosend = min(count, (VCC_BUFF_LEN - port->chars_in_buffer)); in vcc_write()
835 memcpy(&pkt->data[port->chars_in_buffer], &buf[total_sent], in vcc_write()
837 port->chars_in_buffer += tosend; in vcc_write()
843 vccdbgl(port->vio.lp); in vcc_write()
849 rv = ldc_write(port->vio.lp, pkt, (VIO_TAG_SIZE + tosend)); in vcc_write()
856 vcc_kick_tx(port); in vcc_write()
860 port->chars_in_buffer = 0; in vcc_write()
863 spin_unlock_irqrestore(&port->lock, flags); in vcc_write()
865 vcc_put(port, false); in vcc_write()
874 struct vcc_port *port; in vcc_write_room() local
877 port = vcc_get_ne(tty->index); in vcc_write_room()
878 if (unlikely(!port)) { in vcc_write_room()
883 num = VCC_BUFF_LEN - port->chars_in_buffer; in vcc_write_room()
885 vcc_put(port, false); in vcc_write_room()
892 struct vcc_port *port; in vcc_chars_in_buffer() local
895 port = vcc_get_ne(tty->index); in vcc_chars_in_buffer()
896 if (unlikely(!port)) { in vcc_chars_in_buffer()
901 num = port->chars_in_buffer; in vcc_chars_in_buffer()
903 vcc_put(port, false); in vcc_chars_in_buffer()
910 struct vcc_port *port; in vcc_break_ctl() local
913 port = vcc_get_ne(tty->index); in vcc_break_ctl()
914 if (unlikely(!port)) { in vcc_break_ctl()
921 vcc_put(port, false); in vcc_break_ctl()
925 spin_lock_irqsave(&port->lock, flags); in vcc_break_ctl()
927 if (vcc_send_ctl(port, VCC_CTL_BREAK) < 0) in vcc_break_ctl()
928 vcc_kick_tx(port); in vcc_break_ctl()
930 spin_unlock_irqrestore(&port->lock, flags); in vcc_break_ctl()
932 vcc_put(port, false); in vcc_break_ctl()
957 tty->port = NULL; in vcc_install()
964 tty->port = port_tty; in vcc_install()
975 struct vcc_port *port; in vcc_cleanup() local
977 port = vcc_get(tty->index, true); in vcc_cleanup()
978 if (port) { in vcc_cleanup()
979 port->tty = NULL; in vcc_cleanup()
981 if (port->removed) { in vcc_cleanup()
983 kfree(port->vio.name); in vcc_cleanup()
984 kfree(port->domain); in vcc_cleanup()
985 kfree(port); in vcc_cleanup()
987 vcc_put(port, true); in vcc_cleanup()
991 tty_port_destroy(tty->port); in vcc_cleanup()
992 kfree(tty->port); in vcc_cleanup()
993 tty->port = NULL; in vcc_cleanup()