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