hvc_console.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /* SPDX-License-Identifier: GPL-2.0+ */
  2. /*
  3. * hvc_console.h
  4. * Copyright (C) 2005 IBM Corporation
  5. *
  6. * Author(s):
  7. * Ryan S. Arnold <rsa@us.ibm.com>
  8. *
  9. * hvc_console header information:
  10. * moved here from arch/powerpc/include/asm/hvconsole.h
  11. * and drivers/char/hvc_console.c
  12. */
  13. #ifndef HVC_CONSOLE_H
  14. #define HVC_CONSOLE_H
  15. #include <linux/kref.h>
  16. #include <linux/tty.h>
  17. #include <linux/spinlock.h>
  18. /*
  19. * This is the max number of console adapters that can/will be found as
  20. * console devices on first stage console init. Any number beyond this range
  21. * can't be used as a console device but is still a valid tty device.
  22. */
  23. #define MAX_NR_HVC_CONSOLES 16
  24. /*
  25. * The Linux TTY code does not support dynamic addition of tty derived devices
  26. * so we need to know how many tty devices we might need when space is allocated
  27. * for the tty device. Since this driver supports hotplug of vty adapters we
  28. * need to make sure we have enough allocated.
  29. */
  30. #define HVC_ALLOC_TTY_ADAPTERS 64
  31. struct hvc_struct {
  32. struct tty_port port;
  33. spinlock_t lock;
  34. int index;
  35. int do_wakeup;
  36. char *outbuf;
  37. int outbuf_size;
  38. int n_outbuf;
  39. uint32_t vtermno;
  40. const struct hv_ops *ops;
  41. int irq_requested;
  42. int data;
  43. struct winsize ws;
  44. struct work_struct tty_resize;
  45. struct list_head next;
  46. unsigned long flags;
  47. };
  48. /* implemented by a low level driver */
  49. struct hv_ops {
  50. int (*get_chars)(uint32_t vtermno, char *buf, int count);
  51. int (*put_chars)(uint32_t vtermno, const char *buf, int count);
  52. int (*flush)(uint32_t vtermno, bool wait);
  53. /* Callbacks for notification. Called in open, close and hangup */
  54. int (*notifier_add)(struct hvc_struct *hp, int irq);
  55. void (*notifier_del)(struct hvc_struct *hp, int irq);
  56. void (*notifier_hangup)(struct hvc_struct *hp, int irq);
  57. /* tiocmget/set implementation */
  58. int (*tiocmget)(struct hvc_struct *hp);
  59. int (*tiocmset)(struct hvc_struct *hp, unsigned int set, unsigned int clear);
  60. /* Callbacks to handle tty ports */
  61. void (*dtr_rts)(struct hvc_struct *hp, int raise);
  62. };
  63. /* Register a vterm and a slot index for use as a console (console_init) */
  64. extern int hvc_instantiate(uint32_t vtermno, int index,
  65. const struct hv_ops *ops);
  66. /* register a vterm for hvc tty operation (module_init or hotplug add) */
  67. extern struct hvc_struct * hvc_alloc(uint32_t vtermno, int data,
  68. const struct hv_ops *ops, int outbuf_size);
  69. /* remove a vterm from hvc tty operation (module_exit or hotplug remove) */
  70. extern int hvc_remove(struct hvc_struct *hp);
  71. /* data available */
  72. int hvc_poll(struct hvc_struct *hp);
  73. void hvc_kick(void);
  74. /* Resize hvc tty terminal window */
  75. extern void __hvc_resize(struct hvc_struct *hp, struct winsize ws);
  76. static inline void hvc_resize(struct hvc_struct *hp, struct winsize ws)
  77. {
  78. unsigned long flags;
  79. spin_lock_irqsave(&hp->lock, flags);
  80. __hvc_resize(hp, ws);
  81. spin_unlock_irqrestore(&hp->lock, flags);
  82. }
  83. /* default notifier for irq based notification */
  84. extern int notifier_add_irq(struct hvc_struct *hp, int data);
  85. extern void notifier_del_irq(struct hvc_struct *hp, int data);
  86. extern void notifier_hangup_irq(struct hvc_struct *hp, int data);
  87. #if defined(CONFIG_XMON) && defined(CONFIG_SMP)
  88. #include <asm/xmon.h>
  89. #else
  90. static inline int cpus_are_in_xmon(void)
  91. {
  92. return 0;
  93. }
  94. #endif
  95. #endif // HVC_CONSOLE_H