Lines Matching refs:port
3 * Tty port functions
23 static int tty_port_default_receive_buf(struct tty_port *port,
31 tty = READ_ONCE(port->itty);
46 static void tty_port_default_wakeup(struct tty_port *port)
48 struct tty_struct *tty = tty_port_tty_get(port);
62 void tty_port_init(struct tty_port *port)
64 memset(port, 0, sizeof(*port));
65 tty_buffer_init(port);
66 init_waitqueue_head(&port->open_wait);
67 init_waitqueue_head(&port->delta_msr_wait);
68 mutex_init(&port->mutex);
69 mutex_init(&port->buf_mutex);
70 spin_lock_init(&port->lock);
71 port->close_delay = (50 * HZ) / 100;
72 port->closing_wait = (3000 * HZ) / 100;
73 port->client_ops = &tty_port_default_client_ops;
74 kref_init(&port->kref);
80 * @port: tty_port of the device
85 * tty_port (@port). Use this only if neither tty_port_register_device nor
89 void tty_port_link_device(struct tty_port *port,
94 driver->ports[index] = port;
100 * @port: tty_port of the device
105 * It is the same as tty_register_device except the provided @port is linked to
109 struct device *tty_port_register_device(struct tty_port *port,
113 return tty_port_register_device_attr(port, driver, index, device, NULL, NULL);
119 * @port: tty_port of the device
126 * It is the same as tty_register_device_attr except the provided @port is
130 struct device *tty_port_register_device_attr(struct tty_port *port,
135 tty_port_link_device(port, driver, index);
143 * @port: tty_port of the device
153 struct device *tty_port_register_device_attr_serdev(struct tty_port *port,
160 tty_port_link_device(port, driver, index);
162 dev = serdev_tty_port_register(port, device, driver, index);
175 * @port: tty_port of the device
183 struct device *tty_port_register_device_serdev(struct tty_port *port,
187 return tty_port_register_device_attr_serdev(port, driver, index,
194 * @port: tty_port of the device
202 void tty_port_unregister_device(struct tty_port *port,
207 ret = serdev_tty_port_unregister(port);
215 int tty_port_alloc_xmit_buf(struct tty_port *port)
218 mutex_lock(&port->buf_mutex);
219 if (port->xmit_buf == NULL)
220 port->xmit_buf = (unsigned char *)get_zeroed_page(GFP_KERNEL);
221 mutex_unlock(&port->buf_mutex);
222 if (port->xmit_buf == NULL)
228 void tty_port_free_xmit_buf(struct tty_port *port)
230 mutex_lock(&port->buf_mutex);
231 if (port->xmit_buf != NULL) {
232 free_page((unsigned long)port->xmit_buf);
233 port->xmit_buf = NULL;
235 mutex_unlock(&port->buf_mutex);
240 * tty_port_destroy -- destroy inited port
241 * @port: tty port to be destroyed
243 * When a port was initialized using tty_port_init, one has to destroy the
244 * port by this function. Either indirectly by using tty_port refcounting
247 void tty_port_destroy(struct tty_port *port)
249 tty_buffer_cancel_work(port);
250 tty_buffer_free_all(port);
256 struct tty_port *port = container_of(kref, struct tty_port, kref);
258 /* check if last port ref was dropped before tty release */
259 if (WARN_ON(port->itty))
261 if (port->xmit_buf)
262 free_page((unsigned long)port->xmit_buf);
263 tty_port_destroy(port);
264 if (port->ops && port->ops->destruct)
265 port->ops->destruct(port);
267 kfree(port);
270 void tty_port_put(struct tty_port *port)
272 if (port)
273 kref_put(&port->kref, tty_port_destructor);
279 * @port: tty port
281 * Return a refcount protected tty instance or NULL if the port is not
284 struct tty_struct *tty_port_tty_get(struct tty_port *port)
289 spin_lock_irqsave(&port->lock, flags);
290 tty = tty_kref_get(port->tty);
291 spin_unlock_irqrestore(&port->lock, flags);
297 * tty_port_tty_set - set the tty of a port
298 * @port: tty port
301 * Associate the port and tty pair. Manages any internal refcounts.
302 * Pass NULL to deassociate a port
304 void tty_port_tty_set(struct tty_port *port, struct tty_struct *tty)
308 spin_lock_irqsave(&port->lock, flags);
309 tty_kref_put(port->tty);
310 port->tty = tty_kref_get(tty);
311 spin_unlock_irqrestore(&port->lock, flags);
315 static void tty_port_shutdown(struct tty_port *port, struct tty_struct *tty)
317 mutex_lock(&port->mutex);
318 if (port->console)
321 if (tty_port_initialized(port)) {
322 tty_port_set_initialized(port, 0);
328 tty_port_lower_dtr_rts(port);
330 if (port->ops->shutdown)
331 port->ops->shutdown(port);
334 mutex_unlock(&port->mutex);
339 * @port: tty port
341 * Perform port level tty hangup flag and count changes. Drop the tty
346 void tty_port_hangup(struct tty_port *port)
351 spin_lock_irqsave(&port->lock, flags);
352 port->count = 0;
353 tty = port->tty;
356 port->tty = NULL;
357 spin_unlock_irqrestore(&port->lock, flags);
358 tty_port_set_active(port, 0);
359 tty_port_shutdown(port, tty);
361 wake_up_interruptible(&port->open_wait);
362 wake_up_interruptible(&port->delta_msr_wait);
369 * @port: tty port
372 void tty_port_tty_hangup(struct tty_port *port, bool check_clocal)
374 struct tty_struct *tty = tty_port_tty_get(port);
385 * @port: tty port
387 void tty_port_tty_wakeup(struct tty_port *port)
389 port->client_ops->write_wakeup(port);
395 * @port: tty port
399 * internal to the tty port.
401 int tty_port_carrier_raised(struct tty_port *port)
403 if (port->ops->carrier_raised == NULL)
405 return port->ops->carrier_raised(port);
411 * @port: tty port
415 * internal to the tty port.
417 void tty_port_raise_dtr_rts(struct tty_port *port)
419 if (port->ops->dtr_rts)
420 port->ops->dtr_rts(port, 1);
426 * @port: tty port
430 * internal to the tty port.
432 void tty_port_lower_dtr_rts(struct tty_port *port)
434 if (port->ops->dtr_rts)
435 port->ops->dtr_rts(port, 0);
441 * @port: the tty port being opened
451 * - port flags and counts
463 int tty_port_block_til_ready(struct tty_port *port,
471 the port has just hung up or is in another error state */
473 tty_port_set_active(port, 1);
479 tty_port_raise_dtr_rts(port);
480 tty_port_set_active(port, 1);
493 /* The port lock protects the port counts */
494 spin_lock_irqsave(&port->lock, flags);
495 port->count--;
496 port->blocked_open++;
497 spin_unlock_irqrestore(&port->lock, flags);
501 if (C_BAUD(tty) && tty_port_initialized(port))
502 tty_port_raise_dtr_rts(port);
504 prepare_to_wait(&port->open_wait, &wait, TASK_INTERRUPTIBLE);
505 /* Check for a hangup or uninitialised port.
507 if (tty_hung_up_p(filp) || !tty_port_initialized(port)) {
508 if (port->flags & ASYNC_HUP_NOTIFY)
520 if (do_clocal || tty_port_carrier_raised(port))
530 finish_wait(&port->open_wait, &wait);
534 spin_lock_irqsave(&port->lock, flags);
536 port->count++;
537 port->blocked_open--;
538 spin_unlock_irqrestore(&port->lock, flags);
540 tty_port_set_active(port, 1);
545 static void tty_port_drain_delay(struct tty_port *port, struct tty_struct *tty)
551 timeout = (HZ * 10 * port->drain_delay) / bps;
560 int tty_port_close_start(struct tty_port *port,
568 spin_lock_irqsave(&port->lock, flags);
569 if (tty->count == 1 && port->count != 1) {
570 tty_warn(tty, "%s: tty->count = 1 port count = %d\n", __func__,
571 port->count);
572 port->count = 1;
574 if (--port->count < 0) {
575 tty_warn(tty, "%s: bad port count (%d)\n", __func__,
576 port->count);
577 port->count = 0;
580 if (port->count) {
581 spin_unlock_irqrestore(&port->lock, flags);
584 spin_unlock_irqrestore(&port->lock, flags);
588 if (tty_port_initialized(port)) {
589 /* Don't block on a stalled port, just pull the chain */
592 if (port->closing_wait != ASYNC_CLOSING_WAIT_NONE)
593 tty_wait_until_sent(tty, port->closing_wait);
594 if (port->drain_delay)
595 tty_port_drain_delay(port, tty);
600 /* Report to caller this is the last port reference */
606 void tty_port_close_end(struct tty_port *port, struct tty_struct *tty)
613 spin_lock_irqsave(&port->lock, flags);
615 if (port->blocked_open) {
616 spin_unlock_irqrestore(&port->lock, flags);
617 if (port->close_delay)
618 msleep_interruptible(jiffies_to_msecs(port->close_delay));
619 spin_lock_irqsave(&port->lock, flags);
620 wake_up_interruptible(&port->open_wait);
622 spin_unlock_irqrestore(&port->lock, flags);
623 tty_port_set_active(port, 0);
632 void tty_port_close(struct tty_port *port, struct tty_struct *tty,
635 if (tty_port_close_start(port, tty, filp) == 0)
637 tty_port_shutdown(port, tty);
638 if (!port->console)
640 tty_port_close_end(port, tty);
641 tty_port_tty_set(port, NULL);
647 * @port: tty_port of the device
651 * It is the same as tty_standard_install except the provided @port is linked
655 int tty_port_install(struct tty_port *port, struct tty_driver *driver,
658 tty->port = port;
671 int tty_port_open(struct tty_port *port, struct tty_struct *tty,
674 spin_lock_irq(&port->lock);
675 ++port->count;
676 spin_unlock_irq(&port->lock);
677 tty_port_tty_set(port, tty);
682 * port mutex.
685 mutex_lock(&port->mutex);
687 if (!tty_port_initialized(port)) {
689 if (port->ops->activate) {
690 int retval = port->ops->activate(port, tty);
692 mutex_unlock(&port->mutex);
696 tty_port_set_initialized(port, 1);
698 mutex_unlock(&port->mutex);
699 return tty_port_block_til_ready(port, tty, filp);