Lines Matching refs:port
3 * Tty port functions
23 static size_t tty_port_default_receive_buf(struct tty_port *port, const u8 *p,
29 tty = READ_ONCE(port->itty);
44 static void tty_port_default_lookahead_buf(struct tty_port *port, const u8 *p,
50 tty = READ_ONCE(port->itty);
64 static void tty_port_default_wakeup(struct tty_port *port)
66 struct tty_struct *tty = tty_port_tty_get(port);
83 * @port: tty_port to initialize
85 * Initializes the state of struct tty_port. When a port was initialized using
86 * this function, one has to destroy the port by tty_port_destroy(). Either
90 void tty_port_init(struct tty_port *port)
92 memset(port, 0, sizeof(*port));
93 tty_buffer_init(port);
94 init_waitqueue_head(&port->open_wait);
95 init_waitqueue_head(&port->delta_msr_wait);
96 mutex_init(&port->mutex);
97 mutex_init(&port->buf_mutex);
98 spin_lock_init(&port->lock);
99 port->close_delay = (50 * HZ) / 100;
100 port->closing_wait = (3000 * HZ) / 100;
101 port->client_ops = &tty_port_default_client_ops;
102 kref_init(&port->kref);
108 * @port: tty_port of the device
113 * tty_port (@port). Use this only if neither tty_port_register_device() nor
117 void tty_port_link_device(struct tty_port *port,
122 driver->ports[index] = port;
128 * @port: tty_port of the device
133 * It is the same as tty_register_device() except the provided @port is linked
137 struct device *tty_port_register_device(struct tty_port *port,
141 return tty_port_register_device_attr(port, driver, index, device, NULL, NULL);
147 * @port: tty_port of the device
154 * It is the same as tty_register_device_attr() except the provided @port is
158 struct device *tty_port_register_device_attr(struct tty_port *port,
163 tty_port_link_device(port, driver, index);
171 * @port: tty_port of the device
181 struct device *tty_port_register_device_attr_serdev(struct tty_port *port,
188 tty_port_link_device(port, driver, index);
190 dev = serdev_tty_port_register(port, device, driver, index);
203 * @port: tty_port of the device
211 struct device *tty_port_register_device_serdev(struct tty_port *port,
215 return tty_port_register_device_attr_serdev(port, driver, index,
222 * @port: tty_port of the device
230 void tty_port_unregister_device(struct tty_port *port,
235 ret = serdev_tty_port_unregister(port);
243 int tty_port_alloc_xmit_buf(struct tty_port *port)
246 mutex_lock(&port->buf_mutex);
247 if (port->xmit_buf == NULL) {
248 port->xmit_buf = (unsigned char *)get_zeroed_page(GFP_KERNEL);
249 if (port->xmit_buf)
250 kfifo_init(&port->xmit_fifo, port->xmit_buf, PAGE_SIZE);
252 mutex_unlock(&port->buf_mutex);
253 if (port->xmit_buf == NULL)
259 void tty_port_free_xmit_buf(struct tty_port *port)
261 mutex_lock(&port->buf_mutex);
262 free_page((unsigned long)port->xmit_buf);
263 port->xmit_buf = NULL;
264 INIT_KFIFO(port->xmit_fifo);
265 mutex_unlock(&port->buf_mutex);
270 * tty_port_destroy -- destroy inited port
271 * @port: tty port to be destroyed
273 * When a port was initialized using tty_port_init(), one has to destroy the
274 * port by this function. Either indirectly by using &tty_port refcounting
277 void tty_port_destroy(struct tty_port *port)
279 tty_buffer_cancel_work(port);
280 tty_buffer_free_all(port);
286 struct tty_port *port = container_of(kref, struct tty_port, kref);
288 /* check if last port ref was dropped before tty release */
289 if (WARN_ON(port->itty))
291 free_page((unsigned long)port->xmit_buf);
292 tty_port_destroy(port);
293 if (port->ops && port->ops->destruct)
294 port->ops->destruct(port);
296 kfree(port);
301 * @port: port to drop a reference of (can be NULL)
303 * The final put will destroy and free up the @port using
304 * @port->ops->destruct() hook, or using kfree() if not provided.
306 void tty_port_put(struct tty_port *port)
308 if (port)
309 kref_put(&port->kref, tty_port_destructor);
315 * @port: tty port
317 * Return a refcount protected tty instance or %NULL if the port is not
320 struct tty_struct *tty_port_tty_get(struct tty_port *port)
325 spin_lock_irqsave(&port->lock, flags);
326 tty = tty_kref_get(port->tty);
327 spin_unlock_irqrestore(&port->lock, flags);
333 * tty_port_tty_set - set the tty of a port
334 * @port: tty port
337 * Associate the port and tty pair. Manages any internal refcounts. Pass %NULL
338 * to deassociate a port.
340 void tty_port_tty_set(struct tty_port *port, struct tty_struct *tty)
344 spin_lock_irqsave(&port->lock, flags);
345 tty_kref_put(port->tty);
346 port->tty = tty_kref_get(tty);
347 spin_unlock_irqrestore(&port->lock, flags);
353 * @port: tty port to be shut down
359 * @port->ops->shutdown().
361 static void tty_port_shutdown(struct tty_port *port, struct tty_struct *tty)
363 mutex_lock(&port->mutex);
364 if (port->console)
367 if (tty_port_initialized(port)) {
368 tty_port_set_initialized(port, false);
374 tty_port_lower_dtr_rts(port);
376 if (port->ops->shutdown)
377 port->ops->shutdown(port);
380 mutex_unlock(&port->mutex);
385 * @port: tty port
387 * Perform port level tty hangup flag and count changes. Drop the tty
392 void tty_port_hangup(struct tty_port *port)
397 spin_lock_irqsave(&port->lock, flags);
398 port->count = 0;
399 tty = port->tty;
402 port->tty = NULL;
403 spin_unlock_irqrestore(&port->lock, flags);
404 tty_port_set_active(port, false);
405 tty_port_shutdown(port, tty);
407 wake_up_interruptible(&port->open_wait);
408 wake_up_interruptible(&port->delta_msr_wait);
414 * @port: tty port
417 void tty_port_tty_hangup(struct tty_port *port, bool check_clocal)
419 struct tty_struct *tty = tty_port_tty_get(port);
429 * @port: tty port
431 void tty_port_tty_wakeup(struct tty_port *port)
433 port->client_ops->write_wakeup(port);
439 * @port: tty port
443 * internal to the tty port.
445 bool tty_port_carrier_raised(struct tty_port *port)
447 if (port->ops->carrier_raised == NULL)
449 return port->ops->carrier_raised(port);
455 * @port: tty port
459 * tty port.
461 void tty_port_raise_dtr_rts(struct tty_port *port)
463 if (port->ops->dtr_rts)
464 port->ops->dtr_rts(port, true);
470 * @port: tty port
474 * tty port.
476 void tty_port_lower_dtr_rts(struct tty_port *port)
478 if (port->ops->dtr_rts)
479 port->ops->dtr_rts(port, false);
485 * @port: the tty port being opened
496 * - port flags and counts
498 * The passed @port must implement the @port->ops->carrier_raised method if it
499 * can do carrier detect and the @port->ops->dtr_rts method if it supports
505 * Note: May drop and reacquire tty lock when blocking, so @tty and @port may
508 int tty_port_block_til_ready(struct tty_port *port,
516 * the port has just hung up or is in another error state.
519 tty_port_set_active(port, true);
525 tty_port_raise_dtr_rts(port);
526 tty_port_set_active(port, true);
540 /* The port lock protects the port counts */
541 spin_lock_irqsave(&port->lock, flags);
542 port->count--;
543 port->blocked_open++;
544 spin_unlock_irqrestore(&port->lock, flags);
548 if (C_BAUD(tty) && tty_port_initialized(port))
549 tty_port_raise_dtr_rts(port);
551 prepare_to_wait(&port->open_wait, &wait, TASK_INTERRUPTIBLE);
552 /* Check for a hangup or uninitialised port.
555 if (tty_hung_up_p(filp) || !tty_port_initialized(port)) {
556 if (port->flags & ASYNC_HUP_NOTIFY)
568 if (do_clocal || tty_port_carrier_raised(port))
578 finish_wait(&port->open_wait, &wait);
583 spin_lock_irqsave(&port->lock, flags);
585 port->count++;
586 port->blocked_open--;
587 spin_unlock_irqrestore(&port->lock, flags);
589 tty_port_set_active(port, true);
594 static void tty_port_drain_delay(struct tty_port *port, struct tty_struct *tty)
600 timeout = (HZ * 10 * port->drain_delay) / bps;
610 * @port: tty_port of the device
614 * Decrements and checks open count. Flushes the port if this is the last
623 int tty_port_close_start(struct tty_port *port,
631 spin_lock_irqsave(&port->lock, flags);
632 if (tty->count == 1 && port->count != 1) {
633 tty_warn(tty, "%s: tty->count = 1 port count = %d\n", __func__,
634 port->count);
635 port->count = 1;
637 if (--port->count < 0) {
638 tty_warn(tty, "%s: bad port count (%d)\n", __func__,
639 port->count);
640 port->count = 0;
643 if (port->count) {
644 spin_unlock_irqrestore(&port->lock, flags);
647 spin_unlock_irqrestore(&port->lock, flags);
651 if (tty_port_initialized(port)) {
652 /* Don't block on a stalled port, just pull the chain */
655 if (port->closing_wait != ASYNC_CLOSING_WAIT_NONE)
656 tty_wait_until_sent(tty, port->closing_wait);
657 if (port->drain_delay)
658 tty_port_drain_delay(port, tty);
663 /* Report to caller this is the last port reference */
670 * @port: tty_port of the device
675 * line discipline and delays the close by @port->close_delay.
679 void tty_port_close_end(struct tty_port *port, struct tty_struct *tty)
686 spin_lock_irqsave(&port->lock, flags);
688 if (port->blocked_open) {
689 spin_unlock_irqrestore(&port->lock, flags);
690 if (port->close_delay)
691 msleep_interruptible(jiffies_to_msecs(port->close_delay));
692 spin_lock_irqsave(&port->lock, flags);
693 wake_up_interruptible(&port->open_wait);
695 spin_unlock_irqrestore(&port->lock, flags);
696 tty_port_set_active(port, false);
702 * @port: tty_port of the device
713 void tty_port_close(struct tty_port *port, struct tty_struct *tty,
716 if (tty_port_close_start(port, tty, filp) == 0)
718 tty_port_shutdown(port, tty);
719 if (!port->console)
721 tty_port_close_end(port, tty);
722 tty_port_tty_set(port, NULL);
728 * @port: tty_port of the device
732 * It is the same as tty_standard_install() except the provided @port is linked
736 int tty_port_install(struct tty_port *port, struct tty_driver *driver,
739 tty->port = port;
746 * @port: tty_port of the device
751 * the devices using @port->ops->activate if not active already. And waits for
755 * Note that @port->ops->shutdown is not called when @port->ops->activate
761 * @tty and @port may have changed state (eg., may be hung up now).
763 int tty_port_open(struct tty_port *port, struct tty_struct *tty,
766 spin_lock_irq(&port->lock);
767 ++port->count;
768 spin_unlock_irq(&port->lock);
769 tty_port_tty_set(port, tty);
774 * port mutex.
777 mutex_lock(&port->mutex);
779 if (!tty_port_initialized(port)) {
781 if (port->ops->activate) {
782 int retval = port->ops->activate(port, tty);
785 mutex_unlock(&port->mutex);
789 tty_port_set_initialized(port, true);
791 mutex_unlock(&port->mutex);
792 return tty_port_block_til_ready(port, tty, filp);