tty_ldisc.rst 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. .. SPDX-License-Identifier: GPL-2.0
  2. ===================
  3. TTY Line Discipline
  4. ===================
  5. .. contents:: :local:
  6. TTY line discipline process all incoming and outgoing character from/to a tty
  7. device. The default line discipline is :doc:`N_TTY <n_tty>`. It is also a
  8. fallback if establishing any other discipline for a tty fails. If even N_TTY
  9. fails, N_NULL takes over. That never fails, but also does not process any
  10. characters -- it throws them away.
  11. Registration
  12. ============
  13. Line disciplines are registered with tty_register_ldisc() passing the ldisc
  14. structure. At the point of registration the discipline must be ready to use and
  15. it is possible it will get used before the call returns success. If the call
  16. returns an error then it won’t get called. Do not re-use ldisc numbers as they
  17. are part of the userspace ABI and writing over an existing ldisc will cause
  18. demons to eat your computer. You must not re-register over the top of the line
  19. discipline even with the same data or your computer again will be eaten by
  20. demons. In order to remove a line discipline call tty_unregister_ldisc().
  21. Heed this warning: the reference count field of the registered copies of the
  22. tty_ldisc structure in the ldisc table counts the number of lines using this
  23. discipline. The reference count of the tty_ldisc structure within a tty counts
  24. the number of active users of the ldisc at this instant. In effect it counts
  25. the number of threads of execution within an ldisc method (plus those about to
  26. enter and exit although this detail matters not).
  27. .. kernel-doc:: drivers/tty/tty_ldisc.c
  28. :identifiers: tty_register_ldisc tty_unregister_ldisc
  29. Other Functions
  30. ===============
  31. .. kernel-doc:: drivers/tty/tty_ldisc.c
  32. :identifiers: tty_set_ldisc tty_ldisc_flush
  33. Line Discipline Operations Reference
  34. ====================================
  35. .. kernel-doc:: include/linux/tty_ldisc.h
  36. :identifiers: tty_ldisc_ops
  37. Driver Access
  38. =============
  39. Line discipline methods can call the methods of the underlying hardware driver.
  40. These are documented as a part of struct tty_operations.
  41. TTY Flags
  42. =========
  43. Line discipline methods have access to :c:member:`tty_struct.flags` field. See
  44. :doc:`tty_struct`.
  45. Locking
  46. =======
  47. Callers to the line discipline functions from the tty layer are required to
  48. take line discipline locks. The same is true of calls from the driver side
  49. but not yet enforced.
  50. .. kernel-doc:: drivers/tty/tty_ldisc.c
  51. :identifiers: tty_ldisc_ref_wait tty_ldisc_ref tty_ldisc_deref
  52. While these functions are slightly slower than the old code they should have
  53. minimal impact as most receive logic uses the flip buffers and they only
  54. need to take a reference when they push bits up through the driver.
  55. A caution: The :c:member:`tty_ldisc_ops.open()`,
  56. :c:member:`tty_ldisc_ops.close()` and :c:member:`tty_driver.set_ldisc()`
  57. functions are called with the ldisc unavailable. Thus tty_ldisc_ref() will fail
  58. in this situation if used within these functions. Ldisc and driver code
  59. calling its own functions must be careful in this case.
  60. Internal Functions
  61. ==================
  62. .. kernel-doc:: drivers/tty/tty_ldisc.c
  63. :internal: