tty_buffer.h 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef _LINUX_TTY_BUFFER_H
  3. #define _LINUX_TTY_BUFFER_H
  4. #include <linux/atomic.h>
  5. #include <linux/llist.h>
  6. #include <linux/mutex.h>
  7. #include <linux/workqueue.h>
  8. struct tty_buffer {
  9. union {
  10. struct tty_buffer *next;
  11. struct llist_node free;
  12. };
  13. int used;
  14. int size;
  15. int commit;
  16. int lookahead; /* Lazy update on recv, can become less than "read" */
  17. int read;
  18. int flags;
  19. /* Data points here */
  20. unsigned long data[];
  21. };
  22. /* Values for .flags field of tty_buffer */
  23. #define TTYB_NORMAL 1 /* buffer has no flags buffer */
  24. static inline unsigned char *char_buf_ptr(struct tty_buffer *b, int ofs)
  25. {
  26. return ((unsigned char *)b->data) + ofs;
  27. }
  28. static inline char *flag_buf_ptr(struct tty_buffer *b, int ofs)
  29. {
  30. return (char *)char_buf_ptr(b, ofs) + b->size;
  31. }
  32. struct tty_bufhead {
  33. struct tty_buffer *head; /* Queue head */
  34. struct work_struct work;
  35. struct mutex lock;
  36. atomic_t priority;
  37. struct tty_buffer sentinel;
  38. struct llist_head free; /* Free queue head */
  39. atomic_t mem_used; /* In-use buffers excluding free list */
  40. int mem_limit;
  41. struct tty_buffer *tail; /* Active buffer */
  42. };
  43. /*
  44. * When a break, frame error, or parity error happens, these codes are
  45. * stuffed into the flags buffer.
  46. */
  47. #define TTY_NORMAL 0
  48. #define TTY_BREAK 1
  49. #define TTY_FRAME 2
  50. #define TTY_PARITY 3
  51. #define TTY_OVERRUN 4
  52. #endif