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 { 49728674a7SGreg Kroah-Hartman spinlock_t lock; 50728674a7SGreg Kroah-Hartman int index; 51728674a7SGreg Kroah-Hartman struct tty_struct *tty; 52728674a7SGreg Kroah-Hartman int count; 53728674a7SGreg Kroah-Hartman int do_wakeup; 54728674a7SGreg Kroah-Hartman char *outbuf; 55728674a7SGreg Kroah-Hartman int outbuf_size; 56728674a7SGreg Kroah-Hartman int n_outbuf; 57728674a7SGreg Kroah-Hartman uint32_t vtermno; 58728674a7SGreg Kroah-Hartman const struct hv_ops *ops; 59728674a7SGreg Kroah-Hartman int irq_requested; 60728674a7SGreg Kroah-Hartman int data; 61728674a7SGreg Kroah-Hartman struct winsize ws; 62728674a7SGreg Kroah-Hartman struct work_struct tty_resize; 63728674a7SGreg Kroah-Hartman struct list_head next; 64728674a7SGreg Kroah-Hartman struct kref kref; /* ref count & hvc_struct lifetime */ 65728674a7SGreg Kroah-Hartman }; 66728674a7SGreg Kroah-Hartman 67728674a7SGreg Kroah-Hartman /* implemented by a low level driver */ 68728674a7SGreg Kroah-Hartman struct hv_ops { 69728674a7SGreg Kroah-Hartman int (*get_chars)(uint32_t vtermno, char *buf, int count); 70728674a7SGreg Kroah-Hartman int (*put_chars)(uint32_t vtermno, const char *buf, int count); 71728674a7SGreg Kroah-Hartman 72728674a7SGreg Kroah-Hartman /* Callbacks for notification. Called in open, close and hangup */ 73728674a7SGreg Kroah-Hartman int (*notifier_add)(struct hvc_struct *hp, int irq); 74728674a7SGreg Kroah-Hartman void (*notifier_del)(struct hvc_struct *hp, int irq); 75728674a7SGreg Kroah-Hartman void (*notifier_hangup)(struct hvc_struct *hp, int irq); 76*4d2bb3f5SBenjamin Herrenschmidt 77*4d2bb3f5SBenjamin Herrenschmidt /* tiocmget/set implementation */ 78*4d2bb3f5SBenjamin Herrenschmidt int (*tiocmget)(struct hvc_struct *hp); 79*4d2bb3f5SBenjamin Herrenschmidt int (*tiocmset)(struct hvc_struct *hp, unsigned int set, unsigned int clear); 80728674a7SGreg Kroah-Hartman }; 81728674a7SGreg Kroah-Hartman 82728674a7SGreg Kroah-Hartman /* Register a vterm and a slot index for use as a console (console_init) */ 83728674a7SGreg Kroah-Hartman extern int hvc_instantiate(uint32_t vtermno, int index, 84728674a7SGreg Kroah-Hartman const struct hv_ops *ops); 85728674a7SGreg Kroah-Hartman 86728674a7SGreg Kroah-Hartman /* register a vterm for hvc tty operation (module_init or hotplug add) */ 87728674a7SGreg Kroah-Hartman extern struct hvc_struct * hvc_alloc(uint32_t vtermno, int data, 88728674a7SGreg Kroah-Hartman const struct hv_ops *ops, int outbuf_size); 89728674a7SGreg Kroah-Hartman /* remove a vterm from hvc tty operation (module_exit or hotplug remove) */ 90728674a7SGreg Kroah-Hartman extern int hvc_remove(struct hvc_struct *hp); 91728674a7SGreg Kroah-Hartman 92728674a7SGreg Kroah-Hartman /* data available */ 93728674a7SGreg Kroah-Hartman int hvc_poll(struct hvc_struct *hp); 94728674a7SGreg Kroah-Hartman void hvc_kick(void); 95728674a7SGreg Kroah-Hartman 96728674a7SGreg Kroah-Hartman /* Resize hvc tty terminal window */ 97728674a7SGreg Kroah-Hartman extern void __hvc_resize(struct hvc_struct *hp, struct winsize ws); 98728674a7SGreg Kroah-Hartman 99728674a7SGreg Kroah-Hartman static inline void hvc_resize(struct hvc_struct *hp, struct winsize ws) 100728674a7SGreg Kroah-Hartman { 101728674a7SGreg Kroah-Hartman unsigned long flags; 102728674a7SGreg Kroah-Hartman 103728674a7SGreg Kroah-Hartman spin_lock_irqsave(&hp->lock, flags); 104728674a7SGreg Kroah-Hartman __hvc_resize(hp, ws); 105728674a7SGreg Kroah-Hartman spin_unlock_irqrestore(&hp->lock, flags); 106728674a7SGreg Kroah-Hartman } 107728674a7SGreg Kroah-Hartman 108728674a7SGreg Kroah-Hartman /* default notifier for irq based notification */ 109728674a7SGreg Kroah-Hartman extern int notifier_add_irq(struct hvc_struct *hp, int data); 110728674a7SGreg Kroah-Hartman extern void notifier_del_irq(struct hvc_struct *hp, int data); 111728674a7SGreg Kroah-Hartman extern void notifier_hangup_irq(struct hvc_struct *hp, int data); 112728674a7SGreg Kroah-Hartman 113728674a7SGreg Kroah-Hartman 114728674a7SGreg Kroah-Hartman #if defined(CONFIG_XMON) && defined(CONFIG_SMP) 115728674a7SGreg Kroah-Hartman #include <asm/xmon.h> 116728674a7SGreg Kroah-Hartman #else 117728674a7SGreg Kroah-Hartman static inline int cpus_are_in_xmon(void) 118728674a7SGreg Kroah-Hartman { 119728674a7SGreg Kroah-Hartman return 0; 120728674a7SGreg Kroah-Hartman } 121728674a7SGreg Kroah-Hartman #endif 122728674a7SGreg Kroah-Hartman 123728674a7SGreg Kroah-Hartman #endif // HVC_CONSOLE_H 124