• Home
  • Raw
  • Download

Lines Matching full:port

3  * Tty port functions
22 static int tty_port_default_receive_buf(struct tty_port *port, in tty_port_default_receive_buf() argument
30 tty = READ_ONCE(port->itty); in tty_port_default_receive_buf()
45 static void tty_port_default_wakeup(struct tty_port *port) in tty_port_default_wakeup() argument
47 struct tty_struct *tty = tty_port_tty_get(port); in tty_port_default_wakeup()
61 void tty_port_init(struct tty_port *port) in tty_port_init() argument
63 memset(port, 0, sizeof(*port)); in tty_port_init()
64 tty_buffer_init(port); in tty_port_init()
65 init_waitqueue_head(&port->open_wait); in tty_port_init()
66 init_waitqueue_head(&port->delta_msr_wait); in tty_port_init()
67 mutex_init(&port->mutex); in tty_port_init()
68 mutex_init(&port->buf_mutex); in tty_port_init()
69 spin_lock_init(&port->lock); in tty_port_init()
70 port->close_delay = (50 * HZ) / 100; in tty_port_init()
71 port->closing_wait = (3000 * HZ) / 100; in tty_port_init()
72 port->client_ops = &tty_port_default_client_ops; in tty_port_init()
73 kref_init(&port->kref); in tty_port_init()
79 * @port: tty_port of the device
84 * tty_port (@port). Use this only if neither tty_port_register_device nor
88 void tty_port_link_device(struct tty_port *port, in tty_port_link_device() argument
93 driver->ports[index] = port; in tty_port_link_device()
99 * @port: tty_port of the device
104 * It is the same as tty_register_device except the provided @port is linked to
108 struct device *tty_port_register_device(struct tty_port *port, in tty_port_register_device() argument
112 return tty_port_register_device_attr(port, driver, index, device, NULL, NULL); in tty_port_register_device()
118 * @port: tty_port of the device
125 * It is the same as tty_register_device_attr except the provided @port is
129 struct device *tty_port_register_device_attr(struct tty_port *port, in tty_port_register_device_attr() argument
134 tty_port_link_device(port, driver, index); in tty_port_register_device_attr()
142 * @port: tty_port of the device
152 struct device *tty_port_register_device_attr_serdev(struct tty_port *port, in tty_port_register_device_attr_serdev() argument
159 tty_port_link_device(port, driver, index); in tty_port_register_device_attr_serdev()
161 dev = serdev_tty_port_register(port, device, driver, index); in tty_port_register_device_attr_serdev()
174 * @port: tty_port of the device
182 struct device *tty_port_register_device_serdev(struct tty_port *port, in tty_port_register_device_serdev() argument
186 return tty_port_register_device_attr_serdev(port, driver, index, in tty_port_register_device_serdev()
193 * @port: tty_port of the device
201 void tty_port_unregister_device(struct tty_port *port, in tty_port_unregister_device() argument
206 ret = serdev_tty_port_unregister(port); in tty_port_unregister_device()
214 int tty_port_alloc_xmit_buf(struct tty_port *port) in tty_port_alloc_xmit_buf() argument
217 mutex_lock(&port->buf_mutex); in tty_port_alloc_xmit_buf()
218 if (port->xmit_buf == NULL) in tty_port_alloc_xmit_buf()
219 port->xmit_buf = (unsigned char *)get_zeroed_page(GFP_KERNEL); in tty_port_alloc_xmit_buf()
220 mutex_unlock(&port->buf_mutex); in tty_port_alloc_xmit_buf()
221 if (port->xmit_buf == NULL) in tty_port_alloc_xmit_buf()
227 void tty_port_free_xmit_buf(struct tty_port *port) in tty_port_free_xmit_buf() argument
229 mutex_lock(&port->buf_mutex); in tty_port_free_xmit_buf()
230 if (port->xmit_buf != NULL) { in tty_port_free_xmit_buf()
231 free_page((unsigned long)port->xmit_buf); in tty_port_free_xmit_buf()
232 port->xmit_buf = NULL; in tty_port_free_xmit_buf()
234 mutex_unlock(&port->buf_mutex); in tty_port_free_xmit_buf()
239 * tty_port_destroy -- destroy inited port
240 * @port: tty port to be destroyed
242 * When a port was initialized using tty_port_init, one has to destroy the
243 * port by this function. Either indirectly by using tty_port refcounting
246 void tty_port_destroy(struct tty_port *port) in tty_port_destroy() argument
248 tty_buffer_cancel_work(port); in tty_port_destroy()
249 tty_buffer_free_all(port); in tty_port_destroy()
255 struct tty_port *port = container_of(kref, struct tty_port, kref); in tty_port_destructor() local
257 /* check if last port ref was dropped before tty release */ in tty_port_destructor()
258 if (WARN_ON(port->itty)) in tty_port_destructor()
260 if (port->xmit_buf) in tty_port_destructor()
261 free_page((unsigned long)port->xmit_buf); in tty_port_destructor()
262 tty_port_destroy(port); in tty_port_destructor()
263 if (port->ops && port->ops->destruct) in tty_port_destructor()
264 port->ops->destruct(port); in tty_port_destructor()
266 kfree(port); in tty_port_destructor()
269 void tty_port_put(struct tty_port *port) in tty_port_put() argument
271 if (port) in tty_port_put()
272 kref_put(&port->kref, tty_port_destructor); in tty_port_put()
278 * @port: tty port
280 * 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) in tty_port_tty_get() argument
289 spin_lock_irqsave(&port->lock, flags); in tty_port_tty_get()
290 tty = tty_kref_get(port->tty); in tty_port_tty_get()
291 spin_unlock_irqrestore(&port->lock, flags); in tty_port_tty_get()
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
305 void tty_port_tty_set(struct tty_port *port, struct tty_struct *tty) in tty_port_tty_set() argument
309 spin_lock_irqsave(&port->lock, flags); in tty_port_tty_set()
310 tty_kref_put(port->tty); in tty_port_tty_set()
311 port->tty = tty_kref_get(tty); in tty_port_tty_set()
312 spin_unlock_irqrestore(&port->lock, flags); in tty_port_tty_set()
316 static void tty_port_shutdown(struct tty_port *port, struct tty_struct *tty) in tty_port_shutdown() argument
318 mutex_lock(&port->mutex); in tty_port_shutdown()
319 if (port->console) in tty_port_shutdown()
322 if (tty_port_initialized(port)) { in tty_port_shutdown()
323 tty_port_set_initialized(port, 0); in tty_port_shutdown()
329 tty_port_lower_dtr_rts(port); in tty_port_shutdown()
331 if (port->ops->shutdown) in tty_port_shutdown()
332 port->ops->shutdown(port); in tty_port_shutdown()
335 mutex_unlock(&port->mutex); in tty_port_shutdown()
340 * @port: tty port
342 * Perform port level tty hangup flag and count changes. Drop the tty
348 void tty_port_hangup(struct tty_port *port) in tty_port_hangup() argument
353 spin_lock_irqsave(&port->lock, flags); in tty_port_hangup()
354 port->count = 0; in tty_port_hangup()
355 tty = port->tty; in tty_port_hangup()
358 port->tty = NULL; in tty_port_hangup()
359 spin_unlock_irqrestore(&port->lock, flags); in tty_port_hangup()
360 tty_port_set_active(port, 0); in tty_port_hangup()
361 tty_port_shutdown(port, tty); in tty_port_hangup()
363 wake_up_interruptible(&port->open_wait); in tty_port_hangup()
364 wake_up_interruptible(&port->delta_msr_wait); in tty_port_hangup()
371 * @port: tty port
374 void tty_port_tty_hangup(struct tty_port *port, bool check_clocal) in tty_port_tty_hangup() argument
376 struct tty_struct *tty = tty_port_tty_get(port); in tty_port_tty_hangup()
387 * @port: tty port
389 void tty_port_tty_wakeup(struct tty_port *port) in tty_port_tty_wakeup() argument
391 port->client_ops->write_wakeup(port); in tty_port_tty_wakeup()
397 * @port: tty port
401 * internal to the tty port.
404 int tty_port_carrier_raised(struct tty_port *port) in tty_port_carrier_raised() argument
406 if (port->ops->carrier_raised == NULL) in tty_port_carrier_raised()
408 return port->ops->carrier_raised(port); in tty_port_carrier_raised()
414 * @port: tty port
418 * internal to the tty port.
421 void tty_port_raise_dtr_rts(struct tty_port *port) in tty_port_raise_dtr_rts() argument
423 if (port->ops->dtr_rts) in tty_port_raise_dtr_rts()
424 port->ops->dtr_rts(port, 1); in tty_port_raise_dtr_rts()
430 * @port: tty port
434 * internal to the tty port.
437 void tty_port_lower_dtr_rts(struct tty_port *port) in tty_port_lower_dtr_rts() argument
439 if (port->ops->dtr_rts) in tty_port_lower_dtr_rts()
440 port->ops->dtr_rts(port, 0); in tty_port_lower_dtr_rts()
446 * @port: the tty port being opened
456 * - port flags and counts
469 int tty_port_block_til_ready(struct tty_port *port, in tty_port_block_til_ready() argument
477 the port has just hung up or is in another error state */ in tty_port_block_til_ready()
479 tty_port_set_active(port, 1); in tty_port_block_til_ready()
485 tty_port_raise_dtr_rts(port); in tty_port_block_til_ready()
486 tty_port_set_active(port, 1); in tty_port_block_til_ready()
499 /* The port lock protects the port counts */ in tty_port_block_til_ready()
500 spin_lock_irqsave(&port->lock, flags); in tty_port_block_til_ready()
501 port->count--; in tty_port_block_til_ready()
502 port->blocked_open++; in tty_port_block_til_ready()
503 spin_unlock_irqrestore(&port->lock, flags); in tty_port_block_til_ready()
507 if (C_BAUD(tty) && tty_port_initialized(port)) in tty_port_block_til_ready()
508 tty_port_raise_dtr_rts(port); in tty_port_block_til_ready()
510 prepare_to_wait(&port->open_wait, &wait, TASK_INTERRUPTIBLE); in tty_port_block_til_ready()
511 /* Check for a hangup or uninitialised port. in tty_port_block_til_ready()
513 if (tty_hung_up_p(filp) || !tty_port_initialized(port)) { in tty_port_block_til_ready()
514 if (port->flags & ASYNC_HUP_NOTIFY) in tty_port_block_til_ready()
526 if (do_clocal || tty_port_carrier_raised(port)) in tty_port_block_til_ready()
536 finish_wait(&port->open_wait, &wait); in tty_port_block_til_ready()
540 spin_lock_irqsave(&port->lock, flags); in tty_port_block_til_ready()
542 port->count++; in tty_port_block_til_ready()
543 port->blocked_open--; in tty_port_block_til_ready()
544 spin_unlock_irqrestore(&port->lock, flags); in tty_port_block_til_ready()
546 tty_port_set_active(port, 1); in tty_port_block_til_ready()
551 static void tty_port_drain_delay(struct tty_port *port, struct tty_struct *tty) in tty_port_drain_delay() argument
557 timeout = (HZ * 10 * port->drain_delay) / bps; in tty_port_drain_delay()
566 int tty_port_close_start(struct tty_port *port, in tty_port_close_start() argument
574 spin_lock_irqsave(&port->lock, flags); in tty_port_close_start()
575 if (tty->count == 1 && port->count != 1) { in tty_port_close_start()
576 tty_warn(tty, "%s: tty->count = 1 port count = %d\n", __func__, in tty_port_close_start()
577 port->count); in tty_port_close_start()
578 port->count = 1; in tty_port_close_start()
580 if (--port->count < 0) { in tty_port_close_start()
581 tty_warn(tty, "%s: bad port count (%d)\n", __func__, in tty_port_close_start()
582 port->count); in tty_port_close_start()
583 port->count = 0; in tty_port_close_start()
586 if (port->count) { in tty_port_close_start()
587 spin_unlock_irqrestore(&port->lock, flags); in tty_port_close_start()
590 spin_unlock_irqrestore(&port->lock, flags); in tty_port_close_start()
594 if (tty_port_initialized(port)) { in tty_port_close_start()
595 /* Don't block on a stalled port, just pull the chain */ in tty_port_close_start()
598 if (port->closing_wait != ASYNC_CLOSING_WAIT_NONE) in tty_port_close_start()
599 tty_wait_until_sent(tty, port->closing_wait); in tty_port_close_start()
600 if (port->drain_delay) in tty_port_close_start()
601 tty_port_drain_delay(port, tty); in tty_port_close_start()
606 /* Report to caller this is the last port reference */ in tty_port_close_start()
612 void tty_port_close_end(struct tty_port *port, struct tty_struct *tty) in tty_port_close_end() argument
619 spin_lock_irqsave(&port->lock, flags); in tty_port_close_end()
621 if (port->blocked_open) { in tty_port_close_end()
622 spin_unlock_irqrestore(&port->lock, flags); in tty_port_close_end()
623 if (port->close_delay) in tty_port_close_end()
624 msleep_interruptible(jiffies_to_msecs(port->close_delay)); in tty_port_close_end()
625 spin_lock_irqsave(&port->lock, flags); in tty_port_close_end()
626 wake_up_interruptible(&port->open_wait); in tty_port_close_end()
628 spin_unlock_irqrestore(&port->lock, flags); in tty_port_close_end()
629 tty_port_set_active(port, 0); in tty_port_close_end()
638 void tty_port_close(struct tty_port *port, struct tty_struct *tty, in tty_port_close() argument
641 if (tty_port_close_start(port, tty, filp) == 0) in tty_port_close()
643 tty_port_shutdown(port, tty); in tty_port_close()
644 if (!port->console) in tty_port_close()
646 tty_port_close_end(port, tty); in tty_port_close()
647 tty_port_tty_set(port, NULL); in tty_port_close()
653 * @port: tty_port of the device
657 * It is the same as tty_standard_install except the provided @port is linked
661 int tty_port_install(struct tty_port *port, struct tty_driver *driver, in tty_port_install() argument
664 tty->port = port; in tty_port_install()
677 int tty_port_open(struct tty_port *port, struct tty_struct *tty, in tty_port_open() argument
680 spin_lock_irq(&port->lock); in tty_port_open()
681 ++port->count; in tty_port_open()
682 spin_unlock_irq(&port->lock); in tty_port_open()
683 tty_port_tty_set(port, tty); in tty_port_open()
688 * port mutex. in tty_port_open()
691 mutex_lock(&port->mutex); in tty_port_open()
693 if (!tty_port_initialized(port)) { in tty_port_open()
695 if (port->ops->activate) { in tty_port_open()
696 int retval = port->ops->activate(port, tty); in tty_port_open()
698 mutex_unlock(&port->mutex); in tty_port_open()
702 tty_port_set_initialized(port, 1); in tty_port_open()
704 mutex_unlock(&port->mutex); in tty_port_open()
705 return tty_port_block_til_ready(port, tty, filp); in tty_port_open()