xref: /openbmc/linux/drivers/tty/hvc/hvc_console.h (revision bbc3dfe8805de86874b1a1b1429a002e8670043e)
1728674a7SGreg Kroah-Hartman /*
2728674a7SGreg Kroah-Hartman  * hvc_console.h
3728674a7SGreg Kroah-Hartman  * Copyright (C) 2005 IBM Corporation
4728674a7SGreg Kroah-Hartman  *
5728674a7SGreg Kroah-Hartman  * Author(s):
6728674a7SGreg Kroah-Hartman  * 	Ryan S. Arnold <rsa@us.ibm.com>
7728674a7SGreg Kroah-Hartman  *
8728674a7SGreg Kroah-Hartman  * hvc_console header information:
9728674a7SGreg Kroah-Hartman  *      moved here from arch/powerpc/include/asm/hvconsole.h
10728674a7SGreg Kroah-Hartman  *      and drivers/char/hvc_console.c
11728674a7SGreg Kroah-Hartman  *
12728674a7SGreg Kroah-Hartman  * This program is free software; you can redistribute it and/or modify
13728674a7SGreg Kroah-Hartman  * it under the terms of the GNU General Public License as published by
14728674a7SGreg Kroah-Hartman  * the Free Software Foundation; either version 2 of the License, or
15728674a7SGreg Kroah-Hartman  * (at your option) any later version.
16728674a7SGreg Kroah-Hartman  *
17728674a7SGreg Kroah-Hartman  * This program is distributed in the hope that it will be useful,
18728674a7SGreg Kroah-Hartman  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19728674a7SGreg Kroah-Hartman  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20728674a7SGreg Kroah-Hartman  * GNU General Public License for more details.
21728674a7SGreg Kroah-Hartman  *
22728674a7SGreg Kroah-Hartman  * You should have received a copy of the GNU General Public License
23728674a7SGreg Kroah-Hartman  * along with this program; if not, write to the Free Software
24728674a7SGreg Kroah-Hartman  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
25728674a7SGreg Kroah-Hartman  */
26728674a7SGreg Kroah-Hartman 
27728674a7SGreg Kroah-Hartman #ifndef HVC_CONSOLE_H
28728674a7SGreg Kroah-Hartman #define HVC_CONSOLE_H
29728674a7SGreg Kroah-Hartman #include <linux/kref.h>
30728674a7SGreg Kroah-Hartman #include <linux/tty.h>
31728674a7SGreg Kroah-Hartman #include <linux/spinlock.h>
32728674a7SGreg Kroah-Hartman 
33728674a7SGreg Kroah-Hartman /*
34728674a7SGreg Kroah-Hartman  * This is the max number of console adapters that can/will be found as
35728674a7SGreg Kroah-Hartman  * console devices on first stage console init.  Any number beyond this range
36728674a7SGreg Kroah-Hartman  * can't be used as a console device but is still a valid tty device.
37728674a7SGreg Kroah-Hartman  */
38728674a7SGreg Kroah-Hartman #define MAX_NR_HVC_CONSOLES	16
39728674a7SGreg Kroah-Hartman 
40728674a7SGreg Kroah-Hartman /*
41728674a7SGreg Kroah-Hartman  * The Linux TTY code does not support dynamic addition of tty derived devices
42728674a7SGreg Kroah-Hartman  * so we need to know how many tty devices we might need when space is allocated
43728674a7SGreg Kroah-Hartman  * for the tty device.  Since this driver supports hotplug of vty adapters we
44728674a7SGreg Kroah-Hartman  * need to make sure we have enough allocated.
45728674a7SGreg Kroah-Hartman  */
46728674a7SGreg Kroah-Hartman #define HVC_ALLOC_TTY_ADAPTERS	8
47728674a7SGreg Kroah-Hartman 
48728674a7SGreg Kroah-Hartman struct hvc_struct {
49f3d9f250SJiri Slaby 	struct tty_port port;
50728674a7SGreg Kroah-Hartman 	spinlock_t lock;
51728674a7SGreg Kroah-Hartman 	int index;
52728674a7SGreg Kroah-Hartman 	int do_wakeup;
53728674a7SGreg Kroah-Hartman 	char *outbuf;
54728674a7SGreg Kroah-Hartman 	int outbuf_size;
55728674a7SGreg Kroah-Hartman 	int n_outbuf;
56728674a7SGreg Kroah-Hartman 	uint32_t vtermno;
57728674a7SGreg Kroah-Hartman 	const struct hv_ops *ops;
58728674a7SGreg Kroah-Hartman 	int irq_requested;
59728674a7SGreg Kroah-Hartman 	int data;
60728674a7SGreg Kroah-Hartman 	struct winsize ws;
61728674a7SGreg Kroah-Hartman 	struct work_struct tty_resize;
62728674a7SGreg Kroah-Hartman 	struct list_head next;
63*bbc3dfe8SSam Mendoza-Jonas 	unsigned long flags;
64728674a7SGreg Kroah-Hartman };
65728674a7SGreg Kroah-Hartman 
66728674a7SGreg Kroah-Hartman /* implemented by a low level driver */
67728674a7SGreg Kroah-Hartman struct hv_ops {
68728674a7SGreg Kroah-Hartman 	int (*get_chars)(uint32_t vtermno, char *buf, int count);
69728674a7SGreg Kroah-Hartman 	int (*put_chars)(uint32_t vtermno, const char *buf, int count);
70728674a7SGreg Kroah-Hartman 
71728674a7SGreg Kroah-Hartman 	/* Callbacks for notification. Called in open, close and hangup */
72728674a7SGreg Kroah-Hartman 	int (*notifier_add)(struct hvc_struct *hp, int irq);
73728674a7SGreg Kroah-Hartman 	void (*notifier_del)(struct hvc_struct *hp, int irq);
74728674a7SGreg Kroah-Hartman 	void (*notifier_hangup)(struct hvc_struct *hp, int irq);
754d2bb3f5SBenjamin Herrenschmidt 
764d2bb3f5SBenjamin Herrenschmidt 	/* tiocmget/set implementation */
774d2bb3f5SBenjamin Herrenschmidt 	int (*tiocmget)(struct hvc_struct *hp);
784d2bb3f5SBenjamin Herrenschmidt 	int (*tiocmset)(struct hvc_struct *hp, unsigned int set, unsigned int clear);
7933e745a1SHendrik Brueckner 
8033e745a1SHendrik Brueckner 	/* Callbacks to handle tty ports */
8133e745a1SHendrik Brueckner 	void (*dtr_rts)(struct hvc_struct *hp, int raise);
82728674a7SGreg Kroah-Hartman };
83728674a7SGreg Kroah-Hartman 
84728674a7SGreg Kroah-Hartman /* Register a vterm and a slot index for use as a console (console_init) */
85728674a7SGreg Kroah-Hartman extern int hvc_instantiate(uint32_t vtermno, int index,
86728674a7SGreg Kroah-Hartman 			   const struct hv_ops *ops);
87728674a7SGreg Kroah-Hartman 
88728674a7SGreg Kroah-Hartman /* register a vterm for hvc tty operation (module_init or hotplug add) */
89728674a7SGreg Kroah-Hartman extern struct hvc_struct * hvc_alloc(uint32_t vtermno, int data,
90728674a7SGreg Kroah-Hartman 				     const struct hv_ops *ops, int outbuf_size);
91728674a7SGreg Kroah-Hartman /* remove a vterm from hvc tty operation (module_exit or hotplug remove) */
92728674a7SGreg Kroah-Hartman extern int hvc_remove(struct hvc_struct *hp);
93728674a7SGreg Kroah-Hartman 
94728674a7SGreg Kroah-Hartman /* data available */
95728674a7SGreg Kroah-Hartman int hvc_poll(struct hvc_struct *hp);
96728674a7SGreg Kroah-Hartman void hvc_kick(void);
97728674a7SGreg Kroah-Hartman 
98728674a7SGreg Kroah-Hartman /* Resize hvc tty terminal window */
99728674a7SGreg Kroah-Hartman extern void __hvc_resize(struct hvc_struct *hp, struct winsize ws);
100728674a7SGreg Kroah-Hartman 
101728674a7SGreg Kroah-Hartman static inline void hvc_resize(struct hvc_struct *hp, struct winsize ws)
102728674a7SGreg Kroah-Hartman {
103728674a7SGreg Kroah-Hartman 	unsigned long flags;
104728674a7SGreg Kroah-Hartman 
105728674a7SGreg Kroah-Hartman 	spin_lock_irqsave(&hp->lock, flags);
106728674a7SGreg Kroah-Hartman 	__hvc_resize(hp, ws);
107728674a7SGreg Kroah-Hartman 	spin_unlock_irqrestore(&hp->lock, flags);
108728674a7SGreg Kroah-Hartman }
109728674a7SGreg Kroah-Hartman 
110728674a7SGreg Kroah-Hartman /* default notifier for irq based notification */
111728674a7SGreg Kroah-Hartman extern int notifier_add_irq(struct hvc_struct *hp, int data);
112728674a7SGreg Kroah-Hartman extern void notifier_del_irq(struct hvc_struct *hp, int data);
113728674a7SGreg Kroah-Hartman extern void notifier_hangup_irq(struct hvc_struct *hp, int data);
114728674a7SGreg Kroah-Hartman 
115728674a7SGreg Kroah-Hartman 
116728674a7SGreg Kroah-Hartman #if defined(CONFIG_XMON) && defined(CONFIG_SMP)
117728674a7SGreg Kroah-Hartman #include <asm/xmon.h>
118728674a7SGreg Kroah-Hartman #else
119728674a7SGreg Kroah-Hartman static inline int cpus_are_in_xmon(void)
120728674a7SGreg Kroah-Hartman {
121728674a7SGreg Kroah-Hartman 	return 0;
122728674a7SGreg Kroah-Hartman }
123728674a7SGreg Kroah-Hartman #endif
124728674a7SGreg Kroah-Hartman 
125728674a7SGreg Kroah-Hartman #endif // HVC_CONSOLE_H
126