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
174 * @host: serial port hardware device
182 struct device *tty_port_register_device_attr_serdev(struct tty_port *port,
189 tty_port_link_device(port, driver, index);
191 dev = serdev_tty_port_register(port, host, parent, driver, index);
204 * @port: tty_port of the device
207 * @host: serial port hardware controller device
213 struct device *tty_port_register_device_serdev(struct tty_port *port,
217 return tty_port_register_device_attr_serdev(port, driver, index,
224 * @port: tty_port of the device
232 void tty_port_unregister_device(struct tty_port *port,
237 ret = serdev_tty_port_unregister(port);
245 int tty_port_alloc_xmit_buf(struct tty_port *port)
248 mutex_lock(&port->buf_mutex);
249 if (port->xmit_buf == NULL) {
250 port->xmit_buf = (u8 *)get_zeroed_page(GFP_KERNEL);
251 if (port->xmit_buf)
252 kfifo_init(&port->xmit_fifo, port->xmit_buf, PAGE_SIZE);
254 mutex_unlock(&port->buf_mutex);
255 if (port->xmit_buf == NULL)
261 void tty_port_free_xmit_buf(struct tty_port *port)
263 mutex_lock(&port->buf_mutex);
264 free_page((unsigned long)port->xmit_buf);
265 port->xmit_buf = NULL;
266 INIT_KFIFO(port->xmit_fifo);
267 mutex_unlock(&port->buf_mutex);
272 * tty_port_destroy - destroy inited port
273 * @port: tty port to be destroyed
275 * When a port was initialized using tty_port_init(), one has to destroy the
276 * port by this function. Either indirectly by using &tty_port refcounting
279 void tty_port_destroy(struct tty_port *port)
281 tty_buffer_cancel_work(port);
282 tty_buffer_free_all(port);
288 struct tty_port *port = container_of(kref, struct tty_port, kref);
290 /* check if last port ref was dropped before tty release */
291 if (WARN_ON(port->itty))
293 free_page((unsigned long)port->xmit_buf);
294 tty_port_destroy(port);
295 if (port->ops && port->ops->destruct)
296 port->ops->destruct(port);
298 kfree(port);
303 * @port: port to drop a reference of (can be NULL)
305 * The final put will destroy and free up the @port using
306 * @port->ops->destruct() hook, or using kfree() if not provided.
308 void tty_port_put(struct tty_port *port)
310 if (port)
311 kref_put(&port->kref, tty_port_destructor);
317 * @port: tty port
319 * Return a refcount protected tty instance or %NULL if the port is not
322 struct tty_struct *tty_port_tty_get(struct tty_port *port)
327 spin_lock_irqsave(&port->lock, flags);
328 tty = tty_kref_get(port->tty);
329 spin_unlock_irqrestore(&port->lock, flags);
335 * tty_port_tty_set - set the tty of a port
336 * @port: tty port
339 * Associate the port and tty pair. Manages any internal refcounts. Pass %NULL
340 * to deassociate a port.
342 void tty_port_tty_set(struct tty_port *port, struct tty_struct *tty)
346 spin_lock_irqsave(&port->lock, flags);
347 tty_kref_put(port->tty);
348 port->tty = tty_kref_get(tty);
349 spin_unlock_irqrestore(&port->lock, flags);
355 * @port: tty port to be shut down
361 * @port->ops->shutdown().
363 static void tty_port_shutdown(struct tty_port *port, struct tty_struct *tty)
365 mutex_lock(&port->mutex);
366 if (port->console)
369 if (tty_port_initialized(port)) {
370 tty_port_set_initialized(port, false);
376 tty_port_lower_dtr_rts(port);
378 if (port->ops->shutdown)
379 port->ops->shutdown(port);
382 mutex_unlock(&port->mutex);
387 * @port: tty port
389 * Perform port level tty hangup flag and count changes. Drop the tty
394 void tty_port_hangup(struct tty_port *port)
399 spin_lock_irqsave(&port->lock, flags);
400 port->count = 0;
401 tty = port->tty;
404 port->tty = NULL;
405 spin_unlock_irqrestore(&port->lock, flags);
406 tty_port_set_active(port, false);
407 tty_port_shutdown(port, tty);
409 wake_up_interruptible(&port->open_wait);
410 wake_up_interruptible(&port->delta_msr_wait);
416 * @port: tty port
419 void tty_port_tty_hangup(struct tty_port *port, bool check_clocal)
421 struct tty_struct *tty = tty_port_tty_get(port);
431 * @port: tty port
433 void tty_port_tty_wakeup(struct tty_port *port)
435 port->client_ops->write_wakeup(port);
441 * @port: tty port
445 * internal to the tty port.
447 bool tty_port_carrier_raised(struct tty_port *port)
449 if (port->ops->carrier_raised == NULL)
451 return port->ops->carrier_raised(port);
457 * @port: tty port
461 * tty port.
463 void tty_port_raise_dtr_rts(struct tty_port *port)
465 if (port->ops->dtr_rts)
466 port->ops->dtr_rts(port, true);
472 * @port: tty port
476 * tty port.
478 void tty_port_lower_dtr_rts(struct tty_port *port)
480 if (port->ops->dtr_rts)
481 port->ops->dtr_rts(port, false);
487 * @port: the tty port being opened
498 * - port flags and counts
500 * The passed @port must implement the @port->ops->carrier_raised method if it
501 * can do carrier detect and the @port->ops->dtr_rts method if it supports
507 * Note: May drop and reacquire tty lock when blocking, so @tty and @port may
510 int tty_port_block_til_ready(struct tty_port *port,
518 * the port has just hung up or is in another error state.
521 tty_port_set_active(port, true);
527 tty_port_raise_dtr_rts(port);
528 tty_port_set_active(port, true);
542 /* The port lock protects the port counts */
543 spin_lock_irqsave(&port->lock, flags);
544 port->count--;
545 port->blocked_open++;
546 spin_unlock_irqrestore(&port->lock, flags);
550 if (C_BAUD(tty) && tty_port_initialized(port))
551 tty_port_raise_dtr_rts(port);
553 prepare_to_wait(&port->open_wait, &wait, TASK_INTERRUPTIBLE);
554 /* Check for a hangup or uninitialised port.
557 if (tty_hung_up_p(filp) || !tty_port_initialized(port)) {
558 if (port->flags & ASYNC_HUP_NOTIFY)
570 if (do_clocal || tty_port_carrier_raised(port))
580 finish_wait(&port->open_wait, &wait);
585 spin_lock_irqsave(&port->lock, flags);
587 port->count++;
588 port->blocked_open--;
589 spin_unlock_irqrestore(&port->lock, flags);
591 tty_port_set_active(port, true);
596 static void tty_port_drain_delay(struct tty_port *port, struct tty_struct *tty)
602 timeout = (HZ * 10 * port->drain_delay) / bps;
612 * @port: tty_port of the device
616 * Decrements and checks open count. Flushes the port if this is the last
625 int tty_port_close_start(struct tty_port *port,
633 spin_lock_irqsave(&port->lock, flags);
634 if (tty->count == 1 && port->count != 1) {
635 tty_warn(tty, "%s: tty->count = 1 port count = %d\n", __func__,
636 port->count);
637 port->count = 1;
639 if (--port->count < 0) {
640 tty_warn(tty, "%s: bad port count (%d)\n", __func__,
641 port->count);
642 port->count = 0;
645 if (port->count) {
646 spin_unlock_irqrestore(&port->lock, flags);
649 spin_unlock_irqrestore(&port->lock, flags);
653 if (tty_port_initialized(port)) {
654 /* Don't block on a stalled port, just pull the chain */
657 if (port->closing_wait != ASYNC_CLOSING_WAIT_NONE)
658 tty_wait_until_sent(tty, port->closing_wait);
659 if (port->drain_delay)
660 tty_port_drain_delay(port, tty);
665 /* Report to caller this is the last port reference */
672 * @port: tty_port of the device
677 * line discipline and delays the close by @port->close_delay.
681 void tty_port_close_end(struct tty_port *port, struct tty_struct *tty)
688 spin_lock_irqsave(&port->lock, flags);
690 if (port->blocked_open) {
691 spin_unlock_irqrestore(&port->lock, flags);
692 if (port->close_delay)
693 msleep_interruptible(jiffies_to_msecs(port->close_delay));
694 spin_lock_irqsave(&port->lock, flags);
695 wake_up_interruptible(&port->open_wait);
697 spin_unlock_irqrestore(&port->lock, flags);
698 tty_port_set_active(port, false);
704 * @port: tty_port of the device
715 void tty_port_close(struct tty_port *port, struct tty_struct *tty,
718 if (tty_port_close_start(port, tty, filp) == 0)
720 tty_port_shutdown(port, tty);
721 if (!port->console)
723 tty_port_close_end(port, tty);
724 tty_port_tty_set(port, NULL);
730 * @port: tty_port of the device
734 * It is the same as tty_standard_install() except the provided @port is linked
738 int tty_port_install(struct tty_port *port, struct tty_driver *driver,
741 tty->port = port;
748 * @port: tty_port of the device
753 * the devices using @port->ops->activate if not active already. And waits for
757 * Note that @port->ops->shutdown is not called when @port->ops->activate
763 * @tty and @port may have changed state (eg., may be hung up now).
765 int tty_port_open(struct tty_port *port, struct tty_struct *tty,
768 spin_lock_irq(&port->lock);
769 ++port->count;
770 spin_unlock_irq(&port->lock);
771 tty_port_tty_set(port, tty);
776 * port mutex.
779 mutex_lock(&port->mutex);
781 if (!tty_port_initialized(port)) {
783 if (port->ops->activate) {
784 int retval = port->ops->activate(port, tty);
787 mutex_unlock(&port->mutex);
791 tty_port_set_initialized(port, true);
793 mutex_unlock(&port->mutex);
794 return tty_port_block_til_ready(port, tty, filp);