145d607ed92695d7543f5e1fc5b133cd69834e3e4Ryan S. Arnold/* 245d607ed92695d7543f5e1fc5b133cd69834e3e4Ryan S. Arnold * hvc_console.h 345d607ed92695d7543f5e1fc5b133cd69834e3e4Ryan S. Arnold * Copyright (C) 2005 IBM Corporation 445d607ed92695d7543f5e1fc5b133cd69834e3e4Ryan S. Arnold * 545d607ed92695d7543f5e1fc5b133cd69834e3e4Ryan S. Arnold * Author(s): 645d607ed92695d7543f5e1fc5b133cd69834e3e4Ryan S. Arnold * Ryan S. Arnold <rsa@us.ibm.com> 745d607ed92695d7543f5e1fc5b133cd69834e3e4Ryan S. Arnold * 845d607ed92695d7543f5e1fc5b133cd69834e3e4Ryan S. Arnold * hvc_console header information: 9b8b572e1015f81b4e748417be2629dfe51ab99f9Stephen Rothwell * moved here from arch/powerpc/include/asm/hvconsole.h 1045d607ed92695d7543f5e1fc5b133cd69834e3e4Ryan S. Arnold * and drivers/char/hvc_console.c 1145d607ed92695d7543f5e1fc5b133cd69834e3e4Ryan S. Arnold * 1245d607ed92695d7543f5e1fc5b133cd69834e3e4Ryan S. Arnold * This program is free software; you can redistribute it and/or modify 1345d607ed92695d7543f5e1fc5b133cd69834e3e4Ryan S. Arnold * it under the terms of the GNU General Public License as published by 1445d607ed92695d7543f5e1fc5b133cd69834e3e4Ryan S. Arnold * the Free Software Foundation; either version 2 of the License, or 1545d607ed92695d7543f5e1fc5b133cd69834e3e4Ryan S. Arnold * (at your option) any later version. 1645d607ed92695d7543f5e1fc5b133cd69834e3e4Ryan S. Arnold * 1745d607ed92695d7543f5e1fc5b133cd69834e3e4Ryan S. Arnold * This program is distributed in the hope that it will be useful, 1845d607ed92695d7543f5e1fc5b133cd69834e3e4Ryan S. Arnold * but WITHOUT ANY WARRANTY; without even the implied warranty of 1945d607ed92695d7543f5e1fc5b133cd69834e3e4Ryan S. Arnold * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 2045d607ed92695d7543f5e1fc5b133cd69834e3e4Ryan S. Arnold * GNU General Public License for more details. 2145d607ed92695d7543f5e1fc5b133cd69834e3e4Ryan S. Arnold * 2245d607ed92695d7543f5e1fc5b133cd69834e3e4Ryan S. Arnold * You should have received a copy of the GNU General Public License 2345d607ed92695d7543f5e1fc5b133cd69834e3e4Ryan S. Arnold * along with this program; if not, write to the Free Software 2445d607ed92695d7543f5e1fc5b133cd69834e3e4Ryan S. Arnold * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 2545d607ed92695d7543f5e1fc5b133cd69834e3e4Ryan S. Arnold */ 2645d607ed92695d7543f5e1fc5b133cd69834e3e4Ryan S. Arnold 2745d607ed92695d7543f5e1fc5b133cd69834e3e4Ryan S. Arnold#ifndef HVC_CONSOLE_H 2845d607ed92695d7543f5e1fc5b133cd69834e3e4Ryan S. Arnold#define HVC_CONSOLE_H 29611e097d7707741a336a0677d9d69bec40f29f3dChristian Borntraeger#include <linux/kref.h> 30febde3711992a64ea83a47a719f68a90c4b0927aHendrik Brueckner#include <linux/tty.h> 31254be490f257fc3f76ca5f869ac8d107b3827025Hendrik Brueckner#include <linux/spinlock.h> 3245d607ed92695d7543f5e1fc5b133cd69834e3e4Ryan S. Arnold 3345d607ed92695d7543f5e1fc5b133cd69834e3e4Ryan S. Arnold/* 3445d607ed92695d7543f5e1fc5b133cd69834e3e4Ryan S. Arnold * This is the max number of console adapters that can/will be found as 3545d607ed92695d7543f5e1fc5b133cd69834e3e4Ryan S. Arnold * console devices on first stage console init. Any number beyond this range 3645d607ed92695d7543f5e1fc5b133cd69834e3e4Ryan S. Arnold * can't be used as a console device but is still a valid tty device. 3745d607ed92695d7543f5e1fc5b133cd69834e3e4Ryan S. Arnold */ 3845d607ed92695d7543f5e1fc5b133cd69834e3e4Ryan S. Arnold#define MAX_NR_HVC_CONSOLES 16 3945d607ed92695d7543f5e1fc5b133cd69834e3e4Ryan S. Arnold 4045d607ed92695d7543f5e1fc5b133cd69834e3e4Ryan S. Arnold/* 4145d607ed92695d7543f5e1fc5b133cd69834e3e4Ryan S. Arnold * The Linux TTY code does not support dynamic addition of tty derived devices 4245d607ed92695d7543f5e1fc5b133cd69834e3e4Ryan S. Arnold * so we need to know how many tty devices we might need when space is allocated 4345d607ed92695d7543f5e1fc5b133cd69834e3e4Ryan S. Arnold * for the tty device. Since this driver supports hotplug of vty adapters we 4445d607ed92695d7543f5e1fc5b133cd69834e3e4Ryan S. Arnold * need to make sure we have enough allocated. 4545d607ed92695d7543f5e1fc5b133cd69834e3e4Ryan S. Arnold */ 4645d607ed92695d7543f5e1fc5b133cd69834e3e4Ryan S. Arnold#define HVC_ALLOC_TTY_ADAPTERS 8 4745d607ed92695d7543f5e1fc5b133cd69834e3e4Ryan S. Arnold 48611e097d7707741a336a0677d9d69bec40f29f3dChristian Borntraegerstruct hvc_struct { 49611e097d7707741a336a0677d9d69bec40f29f3dChristian Borntraeger spinlock_t lock; 50611e097d7707741a336a0677d9d69bec40f29f3dChristian Borntraeger int index; 51611e097d7707741a336a0677d9d69bec40f29f3dChristian Borntraeger struct tty_struct *tty; 523d26825ec03f623f20ba860e6e6113ab2d0bb0f1roel kluin int count; 53611e097d7707741a336a0677d9d69bec40f29f3dChristian Borntraeger int do_wakeup; 54611e097d7707741a336a0677d9d69bec40f29f3dChristian Borntraeger char *outbuf; 55611e097d7707741a336a0677d9d69bec40f29f3dChristian Borntraeger int outbuf_size; 56611e097d7707741a336a0677d9d69bec40f29f3dChristian Borntraeger int n_outbuf; 57611e097d7707741a336a0677d9d69bec40f29f3dChristian Borntraeger uint32_t vtermno; 58b51130685817d8c1b56386f9957405b5be2cdfe0Rusty Russell const struct hv_ops *ops; 59611e097d7707741a336a0677d9d69bec40f29f3dChristian Borntraeger int irq_requested; 60611e097d7707741a336a0677d9d69bec40f29f3dChristian Borntraeger int data; 61febde3711992a64ea83a47a719f68a90c4b0927aHendrik Brueckner struct winsize ws; 62febde3711992a64ea83a47a719f68a90c4b0927aHendrik Brueckner struct work_struct tty_resize; 63611e097d7707741a336a0677d9d69bec40f29f3dChristian Borntraeger struct list_head next; 64611e097d7707741a336a0677d9d69bec40f29f3dChristian Borntraeger struct kref kref; /* ref count & hvc_struct lifetime */ 65611e097d7707741a336a0677d9d69bec40f29f3dChristian Borntraeger}; 6645d607ed92695d7543f5e1fc5b133cd69834e3e4Ryan S. Arnold 6745d607ed92695d7543f5e1fc5b133cd69834e3e4Ryan S. Arnold/* implemented by a low level driver */ 6845d607ed92695d7543f5e1fc5b133cd69834e3e4Ryan S. Arnoldstruct hv_ops { 6945d607ed92695d7543f5e1fc5b133cd69834e3e4Ryan S. Arnold int (*get_chars)(uint32_t vtermno, char *buf, int count); 7045d607ed92695d7543f5e1fc5b133cd69834e3e4Ryan S. Arnold int (*put_chars)(uint32_t vtermno, const char *buf, int count); 7145d607ed92695d7543f5e1fc5b133cd69834e3e4Ryan S. Arnold 72fc362e2e0efd8b652ebfb409a4e43e6189c04f6fHendrik Brueckner /* Callbacks for notification. Called in open, close and hangup */ 73611e097d7707741a336a0677d9d69bec40f29f3dChristian Borntraeger int (*notifier_add)(struct hvc_struct *hp, int irq); 74611e097d7707741a336a0677d9d69bec40f29f3dChristian Borntraeger void (*notifier_del)(struct hvc_struct *hp, int irq); 75fc362e2e0efd8b652ebfb409a4e43e6189c04f6fHendrik Brueckner void (*notifier_hangup)(struct hvc_struct *hp, int irq); 764d2bb3f5003617cb42b89faefd0009c505c3abd5Benjamin Herrenschmidt 774d2bb3f5003617cb42b89faefd0009c505c3abd5Benjamin Herrenschmidt /* tiocmget/set implementation */ 784d2bb3f5003617cb42b89faefd0009c505c3abd5Benjamin Herrenschmidt int (*tiocmget)(struct hvc_struct *hp); 794d2bb3f5003617cb42b89faefd0009c505c3abd5Benjamin Herrenschmidt int (*tiocmset)(struct hvc_struct *hp, unsigned int set, unsigned int clear); 80611e097d7707741a336a0677d9d69bec40f29f3dChristian Borntraeger}; 8145d607ed92695d7543f5e1fc5b133cd69834e3e4Ryan S. Arnold 8245d607ed92695d7543f5e1fc5b133cd69834e3e4Ryan S. Arnold/* Register a vterm and a slot index for use as a console (console_init) */ 83b51130685817d8c1b56386f9957405b5be2cdfe0Rusty Russellextern int hvc_instantiate(uint32_t vtermno, int index, 84b51130685817d8c1b56386f9957405b5be2cdfe0Rusty Russell const struct hv_ops *ops); 8545d607ed92695d7543f5e1fc5b133cd69834e3e4Ryan S. Arnold 8645d607ed92695d7543f5e1fc5b133cd69834e3e4Ryan S. Arnold/* register a vterm for hvc tty operation (module_init or hotplug add) */ 87119ea10947cc1402abbf9d6200815b0606536906Amit Shahextern struct hvc_struct * hvc_alloc(uint32_t vtermno, int data, 88119ea10947cc1402abbf9d6200815b0606536906Amit Shah const struct hv_ops *ops, int outbuf_size); 89611e097d7707741a336a0677d9d69bec40f29f3dChristian Borntraeger/* remove a vterm from hvc tty operation (module_exit or hotplug remove) */ 90934752d8a4aaae4bee7a1b46944f30a55178ec91Hendrik Bruecknerextern int hvc_remove(struct hvc_struct *hp); 9145d607ed92695d7543f5e1fc5b133cd69834e3e4Ryan S. Arnold 92611e097d7707741a336a0677d9d69bec40f29f3dChristian Borntraeger/* data available */ 93611e097d7707741a336a0677d9d69bec40f29f3dChristian Borntraegerint hvc_poll(struct hvc_struct *hp); 94611e097d7707741a336a0677d9d69bec40f29f3dChristian Borntraegervoid hvc_kick(void); 95611e097d7707741a336a0677d9d69bec40f29f3dChristian Borntraeger 96febde3711992a64ea83a47a719f68a90c4b0927aHendrik Brueckner/* Resize hvc tty terminal window */ 97254be490f257fc3f76ca5f869ac8d107b3827025Hendrik Bruecknerextern void __hvc_resize(struct hvc_struct *hp, struct winsize ws); 98254be490f257fc3f76ca5f869ac8d107b3827025Hendrik Brueckner 99254be490f257fc3f76ca5f869ac8d107b3827025Hendrik Bruecknerstatic inline void hvc_resize(struct hvc_struct *hp, struct winsize ws) 100254be490f257fc3f76ca5f869ac8d107b3827025Hendrik Brueckner{ 101254be490f257fc3f76ca5f869ac8d107b3827025Hendrik Brueckner unsigned long flags; 102254be490f257fc3f76ca5f869ac8d107b3827025Hendrik Brueckner 103254be490f257fc3f76ca5f869ac8d107b3827025Hendrik Brueckner spin_lock_irqsave(&hp->lock, flags); 104254be490f257fc3f76ca5f869ac8d107b3827025Hendrik Brueckner __hvc_resize(hp, ws); 105254be490f257fc3f76ca5f869ac8d107b3827025Hendrik Brueckner spin_unlock_irqrestore(&hp->lock, flags); 106254be490f257fc3f76ca5f869ac8d107b3827025Hendrik Brueckner} 107febde3711992a64ea83a47a719f68a90c4b0927aHendrik Brueckner 108611e097d7707741a336a0677d9d69bec40f29f3dChristian Borntraeger/* default notifier for irq based notification */ 109611e097d7707741a336a0677d9d69bec40f29f3dChristian Borntraegerextern int notifier_add_irq(struct hvc_struct *hp, int data); 110611e097d7707741a336a0677d9d69bec40f29f3dChristian Borntraegerextern void notifier_del_irq(struct hvc_struct *hp, int data); 111fc362e2e0efd8b652ebfb409a4e43e6189c04f6fHendrik Bruecknerextern void notifier_hangup_irq(struct hvc_struct *hp, int data); 112611e097d7707741a336a0677d9d69bec40f29f3dChristian Borntraeger 1131c8950ff87de950a3b6ccfb26650fc0a56278836Michael Ellerman 1141c8950ff87de950a3b6ccfb26650fc0a56278836Michael Ellerman#if defined(CONFIG_XMON) && defined(CONFIG_SMP) 1151c8950ff87de950a3b6ccfb26650fc0a56278836Michael Ellerman#include <asm/xmon.h> 1161c8950ff87de950a3b6ccfb26650fc0a56278836Michael Ellerman#else 1171c8950ff87de950a3b6ccfb26650fc0a56278836Michael Ellermanstatic inline int cpus_are_in_xmon(void) 1181c8950ff87de950a3b6ccfb26650fc0a56278836Michael Ellerman{ 1191c8950ff87de950a3b6ccfb26650fc0a56278836Michael Ellerman return 0; 1201c8950ff87de950a3b6ccfb26650fc0a56278836Michael Ellerman} 1211c8950ff87de950a3b6ccfb26650fc0a56278836Michael Ellerman#endif 1221c8950ff87de950a3b6ccfb26650fc0a56278836Michael Ellerman 12345d607ed92695d7543f5e1fc5b133cd69834e3e4Ryan S. Arnold#endif // HVC_CONSOLE_H 124