xref: /openbmc/linux/drivers/tty/hvc/hvc_console.h (revision 9a87ffc99ec8eb8d35eed7c4f816d75f5cc9662e)
1bdc3070eSNishad Kamdar /* SPDX-License-Identifier: GPL-2.0+ */
2728674a7SGreg Kroah-Hartman /*
3728674a7SGreg Kroah-Hartman  * hvc_console.h
4728674a7SGreg Kroah-Hartman  * Copyright (C) 2005 IBM Corporation
5728674a7SGreg Kroah-Hartman  *
6728674a7SGreg Kroah-Hartman  * Author(s):
7728674a7SGreg Kroah-Hartman  * 	Ryan S. Arnold <rsa@us.ibm.com>
8728674a7SGreg Kroah-Hartman  *
9728674a7SGreg Kroah-Hartman  * hvc_console header information:
10728674a7SGreg Kroah-Hartman  *      moved here from arch/powerpc/include/asm/hvconsole.h
11728674a7SGreg Kroah-Hartman  *      and drivers/char/hvc_console.c
12728674a7SGreg Kroah-Hartman  */
13728674a7SGreg Kroah-Hartman 
14728674a7SGreg Kroah-Hartman #ifndef HVC_CONSOLE_H
15728674a7SGreg Kroah-Hartman #define HVC_CONSOLE_H
16728674a7SGreg Kroah-Hartman #include <linux/kref.h>
17728674a7SGreg Kroah-Hartman #include <linux/tty.h>
18728674a7SGreg Kroah-Hartman #include <linux/spinlock.h>
19728674a7SGreg Kroah-Hartman 
20728674a7SGreg Kroah-Hartman /*
21728674a7SGreg Kroah-Hartman  * This is the max number of console adapters that can/will be found as
22728674a7SGreg Kroah-Hartman  * console devices on first stage console init.  Any number beyond this range
23728674a7SGreg Kroah-Hartman  * can't be used as a console device but is still a valid tty device.
24728674a7SGreg Kroah-Hartman  */
25728674a7SGreg Kroah-Hartman #define MAX_NR_HVC_CONSOLES	16
26728674a7SGreg Kroah-Hartman 
27728674a7SGreg Kroah-Hartman /*
28728674a7SGreg Kroah-Hartman  * The Linux TTY code does not support dynamic addition of tty derived devices
29728674a7SGreg Kroah-Hartman  * so we need to know how many tty devices we might need when space is allocated
30728674a7SGreg Kroah-Hartman  * for the tty device.  Since this driver supports hotplug of vty adapters we
31728674a7SGreg Kroah-Hartman  * need to make sure we have enough allocated.
32728674a7SGreg Kroah-Hartman  */
33728674a7SGreg Kroah-Hartman #define HVC_ALLOC_TTY_ADAPTERS	8
34728674a7SGreg Kroah-Hartman 
35728674a7SGreg Kroah-Hartman struct hvc_struct {
36f3d9f250SJiri Slaby 	struct tty_port port;
37728674a7SGreg Kroah-Hartman 	spinlock_t lock;
38728674a7SGreg Kroah-Hartman 	int index;
39728674a7SGreg Kroah-Hartman 	int do_wakeup;
40728674a7SGreg Kroah-Hartman 	char *outbuf;
41728674a7SGreg Kroah-Hartman 	int outbuf_size;
42728674a7SGreg Kroah-Hartman 	int n_outbuf;
43728674a7SGreg Kroah-Hartman 	uint32_t vtermno;
44728674a7SGreg Kroah-Hartman 	const struct hv_ops *ops;
45728674a7SGreg Kroah-Hartman 	int irq_requested;
46728674a7SGreg Kroah-Hartman 	int data;
47728674a7SGreg Kroah-Hartman 	struct winsize ws;
48728674a7SGreg Kroah-Hartman 	struct work_struct tty_resize;
49728674a7SGreg Kroah-Hartman 	struct list_head next;
50bbc3dfe8SSam Mendoza-Jonas 	unsigned long flags;
51728674a7SGreg Kroah-Hartman };
52728674a7SGreg Kroah-Hartman 
53728674a7SGreg Kroah-Hartman /* implemented by a low level driver */
54728674a7SGreg Kroah-Hartman struct hv_ops {
55728674a7SGreg Kroah-Hartman 	int (*get_chars)(uint32_t vtermno, char *buf, int count);
56728674a7SGreg Kroah-Hartman 	int (*put_chars)(uint32_t vtermno, const char *buf, int count);
579f65b81fSNicholas Piggin 	int (*flush)(uint32_t vtermno, bool wait);
58728674a7SGreg Kroah-Hartman 
59728674a7SGreg Kroah-Hartman 	/* Callbacks for notification. Called in open, close and hangup */
60728674a7SGreg Kroah-Hartman 	int (*notifier_add)(struct hvc_struct *hp, int irq);
61728674a7SGreg Kroah-Hartman 	void (*notifier_del)(struct hvc_struct *hp, int irq);
62728674a7SGreg Kroah-Hartman 	void (*notifier_hangup)(struct hvc_struct *hp, int irq);
634d2bb3f5SBenjamin Herrenschmidt 
644d2bb3f5SBenjamin Herrenschmidt 	/* tiocmget/set implementation */
654d2bb3f5SBenjamin Herrenschmidt 	int (*tiocmget)(struct hvc_struct *hp);
664d2bb3f5SBenjamin Herrenschmidt 	int (*tiocmset)(struct hvc_struct *hp, unsigned int set, unsigned int clear);
6733e745a1SHendrik Brueckner 
6833e745a1SHendrik Brueckner 	/* Callbacks to handle tty ports */
69*5701cb8bSIlpo Järvinen 	void (*dtr_rts)(struct hvc_struct *hp, bool active);
70728674a7SGreg Kroah-Hartman };
71728674a7SGreg Kroah-Hartman 
72728674a7SGreg Kroah-Hartman /* Register a vterm and a slot index for use as a console (console_init) */
73728674a7SGreg Kroah-Hartman extern int hvc_instantiate(uint32_t vtermno, int index,
74728674a7SGreg Kroah-Hartman 			   const struct hv_ops *ops);
75728674a7SGreg Kroah-Hartman 
76728674a7SGreg Kroah-Hartman /* register a vterm for hvc tty operation (module_init or hotplug add) */
77728674a7SGreg Kroah-Hartman extern struct hvc_struct * hvc_alloc(uint32_t vtermno, int data,
78728674a7SGreg Kroah-Hartman 				     const struct hv_ops *ops, int outbuf_size);
79728674a7SGreg Kroah-Hartman /* remove a vterm from hvc tty operation (module_exit or hotplug remove) */
80728674a7SGreg Kroah-Hartman extern int hvc_remove(struct hvc_struct *hp);
81728674a7SGreg Kroah-Hartman 
82728674a7SGreg Kroah-Hartman /* data available */
83728674a7SGreg Kroah-Hartman int hvc_poll(struct hvc_struct *hp);
84728674a7SGreg Kroah-Hartman void hvc_kick(void);
85728674a7SGreg Kroah-Hartman 
86728674a7SGreg Kroah-Hartman /* Resize hvc tty terminal window */
87728674a7SGreg Kroah-Hartman extern void __hvc_resize(struct hvc_struct *hp, struct winsize ws);
88728674a7SGreg Kroah-Hartman 
hvc_resize(struct hvc_struct * hp,struct winsize ws)89728674a7SGreg Kroah-Hartman static inline void hvc_resize(struct hvc_struct *hp, struct winsize ws)
90728674a7SGreg Kroah-Hartman {
91728674a7SGreg Kroah-Hartman 	unsigned long flags;
92728674a7SGreg Kroah-Hartman 
93728674a7SGreg Kroah-Hartman 	spin_lock_irqsave(&hp->lock, flags);
94728674a7SGreg Kroah-Hartman 	__hvc_resize(hp, ws);
95728674a7SGreg Kroah-Hartman 	spin_unlock_irqrestore(&hp->lock, flags);
96728674a7SGreg Kroah-Hartman }
97728674a7SGreg Kroah-Hartman 
98728674a7SGreg Kroah-Hartman /* default notifier for irq based notification */
99728674a7SGreg Kroah-Hartman extern int notifier_add_irq(struct hvc_struct *hp, int data);
100728674a7SGreg Kroah-Hartman extern void notifier_del_irq(struct hvc_struct *hp, int data);
101728674a7SGreg Kroah-Hartman extern void notifier_hangup_irq(struct hvc_struct *hp, int data);
102728674a7SGreg Kroah-Hartman 
103728674a7SGreg Kroah-Hartman 
104728674a7SGreg Kroah-Hartman #if defined(CONFIG_XMON) && defined(CONFIG_SMP)
105728674a7SGreg Kroah-Hartman #include <asm/xmon.h>
106728674a7SGreg Kroah-Hartman #else
cpus_are_in_xmon(void)107728674a7SGreg Kroah-Hartman static inline int cpus_are_in_xmon(void)
108728674a7SGreg Kroah-Hartman {
109728674a7SGreg Kroah-Hartman 	return 0;
110728674a7SGreg Kroah-Hartman }
111728674a7SGreg Kroah-Hartman #endif
112728674a7SGreg Kroah-Hartman 
113728674a7SGreg Kroah-Hartman #endif // HVC_CONSOLE_H
114