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