1*728674a7SGreg Kroah-Hartman /* 2*728674a7SGreg Kroah-Hartman * hvc_console.h 3*728674a7SGreg Kroah-Hartman * Copyright (C) 2005 IBM Corporation 4*728674a7SGreg Kroah-Hartman * 5*728674a7SGreg Kroah-Hartman * Author(s): 6*728674a7SGreg Kroah-Hartman * Ryan S. Arnold <rsa@us.ibm.com> 7*728674a7SGreg Kroah-Hartman * 8*728674a7SGreg Kroah-Hartman * hvc_console header information: 9*728674a7SGreg Kroah-Hartman * moved here from arch/powerpc/include/asm/hvconsole.h 10*728674a7SGreg Kroah-Hartman * and drivers/char/hvc_console.c 11*728674a7SGreg Kroah-Hartman * 12*728674a7SGreg Kroah-Hartman * This program is free software; you can redistribute it and/or modify 13*728674a7SGreg Kroah-Hartman * it under the terms of the GNU General Public License as published by 14*728674a7SGreg Kroah-Hartman * the Free Software Foundation; either version 2 of the License, or 15*728674a7SGreg Kroah-Hartman * (at your option) any later version. 16*728674a7SGreg Kroah-Hartman * 17*728674a7SGreg Kroah-Hartman * This program is distributed in the hope that it will be useful, 18*728674a7SGreg Kroah-Hartman * but WITHOUT ANY WARRANTY; without even the implied warranty of 19*728674a7SGreg Kroah-Hartman * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20*728674a7SGreg Kroah-Hartman * GNU General Public License for more details. 21*728674a7SGreg Kroah-Hartman * 22*728674a7SGreg Kroah-Hartman * You should have received a copy of the GNU General Public License 23*728674a7SGreg Kroah-Hartman * along with this program; if not, write to the Free Software 24*728674a7SGreg Kroah-Hartman * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 25*728674a7SGreg Kroah-Hartman */ 26*728674a7SGreg Kroah-Hartman 27*728674a7SGreg Kroah-Hartman #ifndef HVC_CONSOLE_H 28*728674a7SGreg Kroah-Hartman #define HVC_CONSOLE_H 29*728674a7SGreg Kroah-Hartman #include <linux/kref.h> 30*728674a7SGreg Kroah-Hartman #include <linux/tty.h> 31*728674a7SGreg Kroah-Hartman #include <linux/spinlock.h> 32*728674a7SGreg Kroah-Hartman 33*728674a7SGreg Kroah-Hartman /* 34*728674a7SGreg Kroah-Hartman * This is the max number of console adapters that can/will be found as 35*728674a7SGreg Kroah-Hartman * console devices on first stage console init. Any number beyond this range 36*728674a7SGreg Kroah-Hartman * can't be used as a console device but is still a valid tty device. 37*728674a7SGreg Kroah-Hartman */ 38*728674a7SGreg Kroah-Hartman #define MAX_NR_HVC_CONSOLES 16 39*728674a7SGreg Kroah-Hartman 40*728674a7SGreg Kroah-Hartman /* 41*728674a7SGreg Kroah-Hartman * The Linux TTY code does not support dynamic addition of tty derived devices 42*728674a7SGreg Kroah-Hartman * so we need to know how many tty devices we might need when space is allocated 43*728674a7SGreg Kroah-Hartman * for the tty device. Since this driver supports hotplug of vty adapters we 44*728674a7SGreg Kroah-Hartman * need to make sure we have enough allocated. 45*728674a7SGreg Kroah-Hartman */ 46*728674a7SGreg Kroah-Hartman #define HVC_ALLOC_TTY_ADAPTERS 8 47*728674a7SGreg Kroah-Hartman 48*728674a7SGreg Kroah-Hartman struct hvc_struct { 49*728674a7SGreg Kroah-Hartman spinlock_t lock; 50*728674a7SGreg Kroah-Hartman int index; 51*728674a7SGreg Kroah-Hartman struct tty_struct *tty; 52*728674a7SGreg Kroah-Hartman int count; 53*728674a7SGreg Kroah-Hartman int do_wakeup; 54*728674a7SGreg Kroah-Hartman char *outbuf; 55*728674a7SGreg Kroah-Hartman int outbuf_size; 56*728674a7SGreg Kroah-Hartman int n_outbuf; 57*728674a7SGreg Kroah-Hartman uint32_t vtermno; 58*728674a7SGreg Kroah-Hartman const struct hv_ops *ops; 59*728674a7SGreg Kroah-Hartman int irq_requested; 60*728674a7SGreg Kroah-Hartman int data; 61*728674a7SGreg Kroah-Hartman struct winsize ws; 62*728674a7SGreg Kroah-Hartman struct work_struct tty_resize; 63*728674a7SGreg Kroah-Hartman struct list_head next; 64*728674a7SGreg Kroah-Hartman struct kref kref; /* ref count & hvc_struct lifetime */ 65*728674a7SGreg Kroah-Hartman }; 66*728674a7SGreg Kroah-Hartman 67*728674a7SGreg Kroah-Hartman /* implemented by a low level driver */ 68*728674a7SGreg Kroah-Hartman struct hv_ops { 69*728674a7SGreg Kroah-Hartman int (*get_chars)(uint32_t vtermno, char *buf, int count); 70*728674a7SGreg Kroah-Hartman int (*put_chars)(uint32_t vtermno, const char *buf, int count); 71*728674a7SGreg Kroah-Hartman 72*728674a7SGreg Kroah-Hartman /* Callbacks for notification. Called in open, close and hangup */ 73*728674a7SGreg Kroah-Hartman int (*notifier_add)(struct hvc_struct *hp, int irq); 74*728674a7SGreg Kroah-Hartman void (*notifier_del)(struct hvc_struct *hp, int irq); 75*728674a7SGreg Kroah-Hartman void (*notifier_hangup)(struct hvc_struct *hp, int irq); 76*728674a7SGreg Kroah-Hartman }; 77*728674a7SGreg Kroah-Hartman 78*728674a7SGreg Kroah-Hartman /* Register a vterm and a slot index for use as a console (console_init) */ 79*728674a7SGreg Kroah-Hartman extern int hvc_instantiate(uint32_t vtermno, int index, 80*728674a7SGreg Kroah-Hartman const struct hv_ops *ops); 81*728674a7SGreg Kroah-Hartman 82*728674a7SGreg Kroah-Hartman /* register a vterm for hvc tty operation (module_init or hotplug add) */ 83*728674a7SGreg Kroah-Hartman extern struct hvc_struct * hvc_alloc(uint32_t vtermno, int data, 84*728674a7SGreg Kroah-Hartman const struct hv_ops *ops, int outbuf_size); 85*728674a7SGreg Kroah-Hartman /* remove a vterm from hvc tty operation (module_exit or hotplug remove) */ 86*728674a7SGreg Kroah-Hartman extern int hvc_remove(struct hvc_struct *hp); 87*728674a7SGreg Kroah-Hartman 88*728674a7SGreg Kroah-Hartman /* data available */ 89*728674a7SGreg Kroah-Hartman int hvc_poll(struct hvc_struct *hp); 90*728674a7SGreg Kroah-Hartman void hvc_kick(void); 91*728674a7SGreg Kroah-Hartman 92*728674a7SGreg Kroah-Hartman /* Resize hvc tty terminal window */ 93*728674a7SGreg Kroah-Hartman extern void __hvc_resize(struct hvc_struct *hp, struct winsize ws); 94*728674a7SGreg Kroah-Hartman 95*728674a7SGreg Kroah-Hartman static inline void hvc_resize(struct hvc_struct *hp, struct winsize ws) 96*728674a7SGreg Kroah-Hartman { 97*728674a7SGreg Kroah-Hartman unsigned long flags; 98*728674a7SGreg Kroah-Hartman 99*728674a7SGreg Kroah-Hartman spin_lock_irqsave(&hp->lock, flags); 100*728674a7SGreg Kroah-Hartman __hvc_resize(hp, ws); 101*728674a7SGreg Kroah-Hartman spin_unlock_irqrestore(&hp->lock, flags); 102*728674a7SGreg Kroah-Hartman } 103*728674a7SGreg Kroah-Hartman 104*728674a7SGreg Kroah-Hartman /* default notifier for irq based notification */ 105*728674a7SGreg Kroah-Hartman extern int notifier_add_irq(struct hvc_struct *hp, int data); 106*728674a7SGreg Kroah-Hartman extern void notifier_del_irq(struct hvc_struct *hp, int data); 107*728674a7SGreg Kroah-Hartman extern void notifier_hangup_irq(struct hvc_struct *hp, int data); 108*728674a7SGreg Kroah-Hartman 109*728674a7SGreg Kroah-Hartman 110*728674a7SGreg Kroah-Hartman #if defined(CONFIG_XMON) && defined(CONFIG_SMP) 111*728674a7SGreg Kroah-Hartman #include <asm/xmon.h> 112*728674a7SGreg Kroah-Hartman #else 113*728674a7SGreg Kroah-Hartman static inline int cpus_are_in_xmon(void) 114*728674a7SGreg Kroah-Hartman { 115*728674a7SGreg Kroah-Hartman return 0; 116*728674a7SGreg Kroah-Hartman } 117*728674a7SGreg Kroah-Hartman #endif 118*728674a7SGreg Kroah-Hartman 119*728674a7SGreg Kroah-Hartman #endif // HVC_CONSOLE_H 120