From mboxrd@z Thu Jan 1 00:00:00 1970 From: Steven Smith Subject: Re: [PATCH] PV framebuffer Date: Fri, 1 Dec 2006 13:25:42 +0000 Message-ID: <20061201132541.GA3249@cam.ac.uk> References: <8764cwzt2f.fsf@pike.pond.sub.org> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="===============0729841930==" Return-path: In-Reply-To: <8764cwzt2f.fsf@pike.pond.sub.org> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Mime-version: 1.0 Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: Markus Armbruster Cc: xen-devel@lists.xensource.com, sos22@srcf.ucam.org List-Id: xen-devel@lists.xenproject.org --===============0729841930== Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="7AUc2qLy4jB3hD7Z" Content-Disposition: inline --7AUc2qLy4jB3hD7Z Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Applied. Thanks, Steven. > This is Anthony Liguori's virtual framebuffer forward ported and > extensively hacked based on feedback from xen-devel. >=20 > Its architecture is comparable to the common split device driver > architecture: xenfb and xenkbd modules serve as frontend in domU, and > the user space vncfb or sdlfb process serves as backend in dom0. >=20 > Signed-off-by: Markus Armbruster > Signed-off-by: Anthony Liguori > --- > Summary of changes since last submission: >=20 > * Update to hg tip 12621:d1b0a5adaeab >=20 > * Rename/move files to better match existing code: xenfb/ and xenkbd/ > to fbfront/, xenfb.h to fbif.h, xenkbd.h to kbdif.h. >=20 > * Patched tty_io.c is identical to non-xen version; remove it from the > sparse tree instead. >=20 > linux-2.6-xen-sparse/arch/i386/kernel/setup-xen.c | 5=20 > linux-2.6-xen-sparse/arch/ia64/kernel/setup.c | 4=20 > linux-2.6-xen-sparse/arch/x86_64/kernel/setup-xen.c | 7=20 > linux-2.6-xen-sparse/drivers/char/tty_io.c | 3264 -------------= ------- > linux-2.6-xen-sparse/drivers/xen/Kconfig | 23=20 > linux-2.6-xen-sparse/drivers/xen/Makefile | 2=20 > linux-2.6-xen-sparse/drivers/xen/console/console.c | 10=20 > linux-2.6-xen-sparse/drivers/xen/fbfront/Makefile | 2=20 > linux-2.6-xen-sparse/drivers/xen/fbfront/xenfb.c | 682 ++++ > linux-2.6-xen-sparse/drivers/xen/fbfront/xenkbd.c | 300 + > linux-2.6-xen-sparse/mm/memory.c | 1=20 > tools/Makefile | 1=20 > tools/python/xen/xend/XendDevices.py | 4=20 > tools/python/xen/xend/XendDomainInfo.py | 19=20 > tools/python/xen/xend/image.py | 74=20 > tools/python/xen/xend/server/vfbif.py | 29=20 > tools/python/xen/xm/create.py | 34=20 > tools/xenfb/Makefile | 35=20 > tools/xenfb/sdlfb.c | 334 ++ > tools/xenfb/vncfb.c | 393 ++ > tools/xenfb/xenfb.c | 691 ++++ > tools/xenfb/xenfb.h | 34=20 > xen/include/public/io/fbif.h | 116=20 > xen/include/public/io/kbdif.h | 108=20 > 24 files changed, 2895 insertions(+), 3277 deletions(-) >=20 > diff -r 2773c39df9a6 linux-2.6-xen-sparse/arch/i386/kernel/setup-xen.c > --- a/linux-2.6-xen-sparse/arch/i386/kernel/setup-xen.c Wed Nov 29 12:16:= 19 2006 +0000 > +++ b/linux-2.6-xen-sparse/arch/i386/kernel/setup-xen.c Thu Nov 30 15:13:= 53 2006 +0100 > @@ -1850,8 +1850,9 @@ void __init setup_arch(char **cmdline_p) > #endif > #endif > } else { > - extern int console_use_vt; > - console_use_vt =3D 0; > +#if defined(CONFIG_VT) && defined(CONFIG_DUMMY_CONSOLE) > + conswitchp =3D &dummy_con; > +#endif > } > } > =20 > diff -r 2773c39df9a6 linux-2.6-xen-sparse/arch/ia64/kernel/setup.c > --- a/linux-2.6-xen-sparse/arch/ia64/kernel/setup.c Wed Nov 29 12:16:19 2= 006 +0000 > +++ b/linux-2.6-xen-sparse/arch/ia64/kernel/setup.c Thu Nov 30 15:13:53 2= 006 +0100 > @@ -550,9 +550,9 @@ setup_arch (char **cmdline_p) > xen_start_info->nr_pages, xen_start_info->flags); > =20 > if (!is_initial_xendomain()) { > - extern int console_use_vt; > +#if !defined(CONFIG_VT) || !defined(CONFIG_DUMMY_CONSOLE) > conswitchp =3D NULL; > - console_use_vt =3D 0; > +#endif > } > } > #endif > diff -r 2773c39df9a6 linux-2.6-xen-sparse/arch/x86_64/kernel/setup-xen.c > --- a/linux-2.6-xen-sparse/arch/x86_64/kernel/setup-xen.c Wed Nov 29 12:1= 6:19 2006 +0000 > +++ b/linux-2.6-xen-sparse/arch/x86_64/kernel/setup-xen.c Thu Nov 30 15:1= 3:53 2006 +0100 > @@ -970,9 +970,10 @@ void __init setup_arch(char **cmdline_p) > #endif > #endif > } else { > - extern int console_use_vt; > - console_use_vt =3D 0; > - } > +#if defined(CONFIG_VT) && defined(CONFIG_DUMMY_CONSOLE) > + conswitchp =3D &dummy_con; > +#endif > + } > } > #else /* CONFIG_XEN */ > =20 > diff -r 2773c39df9a6 linux-2.6-xen-sparse/drivers/xen/Kconfig > --- a/linux-2.6-xen-sparse/drivers/xen/Kconfig Wed Nov 29 12:16:19 2006 += 0000 > +++ b/linux-2.6-xen-sparse/drivers/xen/Kconfig Thu Nov 30 15:13:53 2006 += 0100 > @@ -172,6 +172,29 @@ config XEN_NETDEV_FRONTEND > dedicated device-driver domain, or your master control domain > (domain 0), then you almost certainly want to say Y here. > =20 > +config XEN_FRAMEBUFFER > + tristate "Framebuffer-device frontend driver" > + depends on XEN && FB > + select FB_CFB_FILLRECT > + select FB_CFB_COPYAREA > + select FB_CFB_IMAGEBLIT > + default y > + help > + The framebuffer-device frontend drivers allows the kernel to create a > + virtual framebuffer. This framebuffer can be viewed in another > + domain. Unless this domain has access to a real video card, you > + probably want to say Y here. > + > +config XEN_KEYBOARD > + tristate "Keyboard-device frontend driver" > + depends on XEN && XEN_FRAMEBUFFER && INPUT > + default y > + help > + The keyboard-device frontend driver allows the kernel to create a > + virtual keyboard. This keyboard can then be driven by another > + domain. If you've said Y to CONFIG_XEN_FRAMEBUFFER, you probably > + want to say Y here. > + > config XEN_SCRUB_PAGES > bool "Scrub memory before freeing it to Xen" > default y > diff -r 2773c39df9a6 linux-2.6-xen-sparse/drivers/xen/Makefile > --- a/linux-2.6-xen-sparse/drivers/xen/Makefile Wed Nov 29 12:16:19 2006 = +0000 > +++ b/linux-2.6-xen-sparse/drivers/xen/Makefile Thu Nov 30 15:13:53 2006 = +0100 > @@ -15,3 +15,5 @@ obj-$(CONFIG_XEN_NETDEV_FRONTEND) +=3D net > obj-$(CONFIG_XEN_NETDEV_FRONTEND) +=3D netfront/ > obj-$(CONFIG_XEN_PCIDEV_BACKEND) +=3D pciback/ > obj-$(CONFIG_XEN_PCIDEV_FRONTEND) +=3D pcifront/ > +obj-$(CONFIG_XEN_FRAMEBUFFER) +=3D fbfront/ > +obj-$(CONFIG_XEN_KEYBOARD) +=3D fbfront/ > diff -r 2773c39df9a6 linux-2.6-xen-sparse/drivers/xen/console/console.c > --- a/linux-2.6-xen-sparse/drivers/xen/console/console.c Wed Nov 29 12:16= :19 2006 +0000 > +++ b/linux-2.6-xen-sparse/drivers/xen/console/console.c Thu Nov 30 15:13= :53 2006 +0100 > @@ -57,6 +57,7 @@ > #include > #include > #include > +#include > #include > =20 > /* > @@ -698,6 +699,15 @@ static int __init xencons_init(void) > printk("Xen virtual console successfully installed as %s%d\n", > DRV(xencons_driver)->name, xc_num); > =20 > + /* Check about framebuffer messing up the console */ > + if (!is_initial_xendomain() && > + !xenbus_exists(XBT_NIL, "device", "vfb")) { > + /* FIXME: this is ugly */ > + unregister_console(&kcons_info); > + kcons_info.flags |=3D CON_CONSDEV; > + register_console(&kcons_info); > + } > + > return 0; > } > =20 > diff -r 2773c39df9a6 linux-2.6-xen-sparse/mm/memory.c > --- a/linux-2.6-xen-sparse/mm/memory.c Wed Nov 29 12:16:19 2006 +0000 > +++ b/linux-2.6-xen-sparse/mm/memory.c Thu Nov 30 15:13:53 2006 +0100 > @@ -882,6 +882,7 @@ unsigned long zap_page_range(struct vm_a > tlb_finish_mmu(tlb, address, end); > return end; > } > +EXPORT_SYMBOL(zap_page_range); > =20 > /* > * Do a quick page-table lookup for a single page. > diff -r 2773c39df9a6 tools/Makefile > --- a/tools/Makefile Wed Nov 29 12:16:19 2006 +0000 > +++ b/tools/Makefile Wed Nov 29 13:56:23 2006 +0100 > @@ -19,6 +19,7 @@ SUBDIRS-y +=3D libaio > SUBDIRS-y +=3D libaio > SUBDIRS-y +=3D blktap > SUBDIRS-y +=3D libfsimage > +SUBDIRS-y +=3D xenfb > SUBDIRS-$(LIBXENAPI_BINDINGS) +=3D libxen > =20 > # These don't cross-compile > diff -r 2773c39df9a6 tools/python/xen/xend/XendDevices.py > --- a/tools/python/xen/xend/XendDevices.py Wed Nov 29 12:16:19 2006 +0000 > +++ b/tools/python/xen/xend/XendDevices.py Thu Nov 23 18:54:35 2006 +0100 > @@ -19,7 +19,7 @@ > # A collection of DevControllers=20 > # > =20 > -from xen.xend.server import blkif, netif, tpmif, pciif, iopif, irqif, us= bif > +from xen.xend.server import blkif, netif, tpmif, pciif, iopif, irqif, us= bif, vfbif > from xen.xend.server.BlktapController import BlktapController > =20 > class XendDevices: > @@ -41,6 +41,8 @@ class XendDevices: > 'irq': irqif.IRQController, > 'usb': usbif.UsbifController, > 'tap': BlktapController, > + 'vfb': vfbif.VfbifController, > + 'vkbd': vfbif.VkbdifController, > } > =20 > #@classmethod > diff -r 2773c39df9a6 tools/python/xen/xend/XendDomainInfo.py > --- a/tools/python/xen/xend/XendDomainInfo.py Wed Nov 29 12:16:19 2006 +0= 000 > +++ b/tools/python/xen/xend/XendDomainInfo.py Wed Nov 29 13:56:25 2006 +0= 100 > @@ -458,7 +458,7 @@ class XendDomainInfo: > try: > self._constructDomain() > self._storeVmDetails() > - self._createDevices() > + self._restoreDomain() > self._createChannels() > self._storeDomDetails() > self._endRestore() > @@ -1330,6 +1330,23 @@ class XendDomainInfo: > self.image.cleanupBootloading() > raise VmError(str(exn)) > =20 > + > + def _restoreDomain(self): > + log.debug('XendDomainInfo.restoreDomain: %s %s', > + self.domid, > + self.info['cpu_weight']) > + > + if not self.infoIsSet('image'): > + raise VmError('Missing image in configuration') > + > + try: > + self.image =3D image.create(self, > + self.info['image'], > + self.info['device']) > + > + self._createDevices() > + except RuntimeError, exn: > + raise VmError(str(exn)) > =20 > def cleanupDomain(self): > """Cleanup domain resources; release devices. Idempotent. Noth= row > diff -r 2773c39df9a6 tools/python/xen/xend/image.py > --- a/tools/python/xen/xend/image.py Wed Nov 29 12:16:19 2006 +0000 > +++ b/tools/python/xen/xend/image.py Wed Nov 29 13:56:25 2006 +0100 > @@ -23,6 +23,7 @@ import signal > import signal > =20 > import xen.lowlevel.xc > +import xen.util.auxbin > from xen.xend import sxp > from xen.xend.XendError import VmError, XendError > from xen.xend.XendLogging import log > @@ -209,6 +210,79 @@ class LinuxImageHandler(ImageHandler): > cmdline =3D self.cmdline, > ramdisk =3D self.ramdisk, > features =3D self.vm.getFeatures()) > + > + def configure(self, imageConfig, deviceConfig): > + ImageHandler.configure(self, imageConfig, deviceConfig) > + > + self.pid =3D 0 > + log.info("configuring linux guest") > + > + # set up the graphics bits. > + # FIXME: this is much like what we do for HVM, should it be=20 > + # for all image types now? > + self.display =3D sxp.child_value(imageConfig, 'display') > + self.xauthority =3D sxp.child_value(imageConfig, 'xauthority') > + self.vncconsole =3D sxp.child_value(imageConfig, 'vncconsole') > + vncpasswd =3D sxp.child_value(imageConfig, 'vncpasswd') > + self.vncpasswd =3D vncpasswd > + > + self.vnc =3D sxp.child_value(imageConfig, 'vnc') > + self.sdl =3D sxp.child_value(imageConfig, 'sdl') > + if self.vnc: > + self.vncdisplay =3D int(sxp.child_value(imageConfig, 'vncdis= play', > + self.vm.getDomid())) > + self.vncunused =3D sxp.child_value(imageConfig, 'vncunused') > + self.vnclisten =3D sxp.child_value(imageConfig, 'vnclisten') > + if not(self.vnclisten): > + self.vnclisten =3D xen.xend.XendRoot.instance().get_vncl= isten_address() > + > + def createDeviceModel(self): > + if self.pid: > + return > + # Execute device model (for us, it's just the fb frontend) > + if not self.vnc and not self.sdl: > + return > + > + if self.vnc: > + args =3D [xen.util.auxbin.pathTo("xen-vncfb")] > + if self.vncunused: > + args +=3D ['--unused'] > + elif self.vncdisplay: > + args +=3D [ "--vncport", "%d" %(5900 + self.vncdisplay,)= ] > + if self.vnclisten: > + args +=3D [ "--listen", self.vnclisten ] > + > + # password check > + if self.vncpasswd is None: > + # get password from xend-config(if password omitted, Non= e) > + self.vncpasswd =3D xen.xend.XendRoot.instance().get_vncp= asswd_default() > + > + if self.vncpasswd is None: > + raise VmError('vncpasswd is not setup in the guest c= onfig or xend-config.') > + if self.vncpasswd !=3D '': > + self.vm.storeVm("vncpasswd", self.vncpasswd) > + log.info("vncpassword set to '%s'", self.vncpasswd) > + > + elif self.sdl: > + args =3D [xen.util.auxbin.pathTo("xen-sdlfb")] > + args =3D args + [ "--domid", "%d" % self.vm.getDomid(), > + "--title", self.vm.info['name'] ] > + > + env =3D dict(os.environ) > + if self.display: > + env['DISPLAY'] =3D self.display > + if self.xauthority: > + env['XAUTHORITY'] =3D self.xauthority > + log.info("spawning video: %s", args) > + self.pid =3D os.spawnve(os.P_NOWAIT, args[0], args, env) > + log.info("device model pid: %d", self.pid) > + > + def destroy(self): > + if not self.pid: > + return > + os.kill(self.pid, signal.SIGKILL) > + os.waitpid(self.pid, 0) > + self.pid =3D 0 > =20 > class PPC_LinuxImageHandler(LinuxImageHandler): > =20 > diff -r 2773c39df9a6 tools/python/xen/xm/create.py > --- a/tools/python/xen/xm/create.py Wed Nov 29 12:16:19 2006 +0000 > +++ b/tools/python/xen/xm/create.py Wed Nov 29 13:57:17 2006 +0100 > @@ -284,6 +284,14 @@ gopts.var('usbport', val=3D'PATH', > use=3D"""Add a physical USB port to a domain, as specified by = the path > to that port. This option may be repeated to add more than on= e port.""") > =20 > +gopts.var('vfb', val=3D"no|yes'", > + fn=3Dset_bool, default=3D0, > + use=3D"Make the domain a framebuffer backend.") > + > +gopts.var('vkbd', val=3D"no|yes'", > + fn=3Dset_bool, default=3D0, > + use=3D"Make the domain a keyboard backend.") > + > gopts.var('vif', val=3D"type=3DTYPE,mac=3DMAC,bridge=3DBRIDGE,ip=3DIPADD= R,script=3DSCRIPT,backend=3DDOM,vifname=3DNAME", > fn=3Dappend_value, default=3D[], > use=3D"""Add a network interface with the given MAC address an= d bridge. > @@ -512,8 +520,10 @@ def configure_image(vals): > config_image.append(['args', vals.extra]) > =20 > if vals.builder =3D=3D 'hvm': > - configure_hvm(config_image, vals) > - =20 > + configure_hvm(config_image, vals)=20 > + > + configure_graphics(config_image, vals) =20 > + =20 > return config_image > =20 > def configure_disks(config_devs, vals): > @@ -564,6 +574,13 @@ def configure_usb(config_devs, vals): > config_usb =3D ['usbport', ['path', path]] > config_devs.append(['device', config_usb]) > =20 > +def configure_vfbs(config_devs, vals): > + if vals.vfb: > + config_devs.append(['device', ['vfb', []]]) > + > +def configure_vkbds(config_devs, vals): > + if vals.vkbd: > + config_devs.append(['device', ['vkbd', []]]) > =20 > def configure_security(config, vals): > """Create the config for ACM security labels. > @@ -661,13 +678,20 @@ def configure_vifs(config_devs, vals): > config_devs.append(['device', config_vif]) > =20 > =20 > +def configure_graphics(config_image, vals): > + """Create the config for graphic consoles. > + """ > + args =3D [ 'vnc', 'vncdisplay', 'vncconsole', 'vncunused', > + 'sdl', 'display', 'xauthority', 'vnclisten', 'vncpasswd'] > + for a in args: > + if (vals.__dict__[a]): > + config_image.append([a, vals.__dict__[a]]) > + > def configure_hvm(config_image, vals): > """Create the config for HVM devices. > """ > args =3D [ 'device_model', 'pae', 'vcpus', 'boot', 'fda', 'fdb', > 'localtime', 'serial', 'stdvga', 'isa', 'nographic', 'sound= hw', > - 'vnc', 'vncdisplay', 'vncunused', 'vncconsole', 'vnclisten', > - 'sdl', 'display', 'xauthority', > 'acpi', 'apic', 'usb', 'usbdevice', 'keymap' ] > for a in args: > if a in vals.__dict__ and vals.__dict__[a] is not None: > @@ -742,6 +766,8 @@ def make_config(vals): > configure_vifs(config_devs, vals) > configure_usb(config_devs, vals) > configure_vtpm(config_devs, vals) > + configure_vfbs(config_devs, vals) > + configure_vkbds(config_devs, vals) > configure_security(config, vals) > config +=3D config_devs > =20 > diff -r 2773c39df9a6 linux-2.6-xen-sparse/drivers/xen/fbfront/Makefile > --- /dev/null Thu Jan 01 00:00:00 1970 +0000 > +++ b/linux-2.6-xen-sparse/drivers/xen/fbfront/Makefile Thu Nov 30 15:13:= 53 2006 +0100 > @@ -0,0 +1,2 @@ > +obj-$(CONFIG_XEN_FRAMEBUFFER) :=3D xenfb.o > +obj-$(CONFIG_XEN_KEYBOARD) +=3D xenkbd.o > diff -r 2773c39df9a6 linux-2.6-xen-sparse/drivers/xen/fbfront/xenfb.c > --- /dev/null Thu Jan 01 00:00:00 1970 +0000 > +++ b/linux-2.6-xen-sparse/drivers/xen/fbfront/xenfb.c Thu Nov 30 15:13:5= 3 2006 +0100 > @@ -0,0 +1,682 @@ > +/* > + * linux/drivers/video/xenfb.c -- Xen para-virtual frame buffer device > + * > + * Copyright (C) 2005-2006 Anthony Liguori > + * Copyright (C) 2006 Red Hat, Inc., Markus Armbruster > + * > + * Based on linux/drivers/video/q40fb.c > + * > + * This file is subject to the terms and conditions of the GNU General = Public > + * License. See the file COPYING in the main directory of this archive = for > + * more details. > + */ > + > +/* > + * TODO: > + * > + * Switch to grant tables when they become capable of dealing with the > + * frame buffer. > + */ > + > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > + > +struct xenfb_mapping > +{ > + struct list_head link; > + struct vm_area_struct *vma; > + atomic_t map_refs; > + int faults; > + struct xenfb_info *info; > +}; > + > +struct xenfb_info > +{ > + struct task_struct *kthread; > + wait_queue_head_t wq; > + > + unsigned char *fb; > + struct fb_info *fb_info; > + struct timer_list refresh; > + int dirty; > + int x1, y1, x2, y2; /* dirty rectangle, > + protected by mm_lock */ > + spinlock_t mm_lock; > + int nr_pages; > + struct page **pages; > + struct list_head mappings; /* protected by mm_lock */ > + > + unsigned evtchn; > + int irq; > + struct xenfb_page *page; > + unsigned long *mfns; > + int update_wanted; /* XENFB_TYPE_UPDATE wanted */ > + > + struct xenbus_device *xbdev; > +}; > + > +static int xenfb_fps =3D 20; > +static unsigned long xenfb_mem_len =3D XENFB_WIDTH * XENFB_HEIGHT * XENF= B_DEPTH / 8; > + > +static int xenfb_remove(struct xenbus_device *); > +static void xenfb_init_shared_page(struct xenfb_info *); > +static int xenfb_connect_backend(struct xenbus_device *, struct xenfb_in= fo *); > +static void xenfb_disconnect_backend(struct xenfb_info *); > + > +static void xenfb_do_update(struct xenfb_info *info, > + int x, int y, int w, int h) > +{ > + union xenfb_out_event event; > + __u32 prod; > + > + event.type =3D XENFB_TYPE_UPDATE; > + event.update.x =3D x; > + event.update.y =3D y; > + event.update.width =3D w; > + event.update.height =3D h; > + > + prod =3D info->page->out_prod; > + /* caller ensures !xenfb_queue_full() */ > + mb(); /* ensure ring space available */ > + XENFB_OUT_RING_REF(info->page, prod) =3D event; > + wmb(); /* ensure ring contents visible */ > + info->page->out_prod =3D prod + 1; > + > + notify_remote_via_evtchn(info->evtchn); > +} > + > +static int xenfb_queue_full(struct xenfb_info *info) > +{ > + __u32 cons, prod; > + > + prod =3D info->page->out_prod; > + cons =3D info->page->out_cons; > + return prod - cons =3D=3D XENFB_OUT_RING_LEN; > +} > + > +static void xenfb_update_screen(struct xenfb_info *info) > +{ > + unsigned long flags; > + int y1, y2, x1, x2; > + struct xenfb_mapping *map; > + > + if (!info->update_wanted) > + return; > + if (xenfb_queue_full(info)) > + return; > + > + spin_lock_irqsave(&info->mm_lock, flags); > + > + y1 =3D info->y1; > + y2 =3D info->y2; > + x1 =3D info->x1; > + x2 =3D info->x2; > + info->x1 =3D info->y1 =3D INT_MAX; > + info->x2 =3D info->y2 =3D 0; > + > + list_for_each_entry(map, &info->mappings, link) { > + if (!map->faults) > + continue; > + zap_page_range(map->vma, map->vma->vm_start, > + map->vma->vm_end - map->vma->vm_start, NULL); > + map->faults =3D 0; > + } > + > + spin_unlock_irqrestore(&info->mm_lock, flags); > + > + xenfb_do_update(info, x1, y1, x2 - x1, y2 - y1); > +} > + > +static int xenfb_thread(void *data) > +{ > + struct xenfb_info *info =3D data; > + > + while (!kthread_should_stop()) { > + if (info->dirty) { > + info->dirty =3D 0; > + xenfb_update_screen(info); > + } > + wait_event_interruptible(info->wq, > + kthread_should_stop() || info->dirty); > + try_to_freeze(); > + } > + return 0; > +} > + > +static int xenfb_setcolreg(unsigned regno, unsigned red, unsigned green, > + unsigned blue, unsigned transp, > + struct fb_info *info) > +{ > + u32 v; > + > + if (regno > info->cmap.len) > + return 1; > + > + red >>=3D (16 - info->var.red.length); > + green >>=3D (16 - info->var.green.length); > + blue >>=3D (16 - info->var.blue.length); > + > + v =3D (red << info->var.red.offset) | > + (green << info->var.green.offset) | > + (blue << info->var.blue.offset); > + > + /* FIXME is this sane? check against xxxfb_setcolreg()! */ > + switch (info->var.bits_per_pixel) { > + case 16: > + case 24: > + case 32: > + ((u32 *)info->pseudo_palette)[regno] =3D v; > + break; > + } > +=09 > + return 0; > +} > + > +static void xenfb_timer(unsigned long data) > +{ > + struct xenfb_info *info =3D (struct xenfb_info *)data; > + info->dirty =3D 1; > + wake_up(&info->wq); > +} > + > +static void __xenfb_refresh(struct xenfb_info *info, > + int x1, int y1, int w, int h) > +{ > + int y2, x2; > + > + y2 =3D y1 + h; > + x2 =3D x1 + w; > + > + if (info->y1 > y1) > + info->y1 =3D y1; > + if (info->y2 < y2) > + info->y2 =3D y2; > + if (info->x1 > x1) > + info->x1 =3D x1; > + if (info->x2 < x2) > + info->x2 =3D x2; > + > + if (timer_pending(&info->refresh)) > + return; > + > + mod_timer(&info->refresh, jiffies + HZ/xenfb_fps); > +} > + > +static void xenfb_refresh(struct xenfb_info *info, > + int x1, int y1, int w, int h) > +{ > + unsigned long flags; > + > + spin_lock_irqsave(&info->mm_lock, flags); > + __xenfb_refresh(info, x1, y1, w, h); > + spin_unlock_irqrestore(&info->mm_lock, flags); > +} > + > +static void xenfb_fillrect(struct fb_info *p, const struct fb_fillrect *= rect) > +{ > + struct xenfb_info *info =3D p->par; > + > + cfb_fillrect(p, rect); > + xenfb_refresh(info, rect->dx, rect->dy, rect->width, rect->height); > +} > + > +static void xenfb_imageblit(struct fb_info *p, const struct fb_image *im= age) > +{ > + struct xenfb_info *info =3D p->par; > + > + cfb_imageblit(p, image); > + xenfb_refresh(info, image->dx, image->dy, image->width, image->height); > +} > + > +static void xenfb_copyarea(struct fb_info *p, const struct fb_copyarea *= area) > +{ > + struct xenfb_info *info =3D p->par; > + > + cfb_copyarea(p, area); > + xenfb_refresh(info, area->dx, area->dy, area->width, area->height); > +} > + > +static void xenfb_vm_open(struct vm_area_struct *vma) > +{ > + struct xenfb_mapping *map =3D vma->vm_private_data; > + atomic_inc(&map->map_refs); > +} > + > +static void xenfb_vm_close(struct vm_area_struct *vma) > +{ > + struct xenfb_mapping *map =3D vma->vm_private_data; > + struct xenfb_info *info =3D map->info; > + unsigned long flags; > + > + spin_lock_irqsave(&info->mm_lock, flags); > + if (atomic_dec_and_test(&map->map_refs)) { > + list_del(&map->link); > + kfree(map); > + } > + spin_unlock_irqrestore(&info->mm_lock, flags); > +} > + > +static struct page *xenfb_vm_nopage(struct vm_area_struct *vma, > + unsigned long vaddr, int *type) > +{ > + struct xenfb_mapping *map =3D vma->vm_private_data; > + struct xenfb_info *info =3D map->info; > + int pgnr =3D (vaddr - vma->vm_start) >> PAGE_SHIFT; > + unsigned long flags; > + struct page *page; > + int y1, y2; > + > + if (pgnr >=3D info->nr_pages) > + return NOPAGE_SIGBUS; > + > + spin_lock_irqsave(&info->mm_lock, flags); > + page =3D info->pages[pgnr]; > + get_page(page); > + map->faults++; > + > + y1 =3D pgnr * PAGE_SIZE / info->fb_info->fix.line_length; > + y2 =3D (pgnr * PAGE_SIZE + PAGE_SIZE - 1) / info->fb_info->fix.line_len= gth; > + if (y2 > info->fb_info->var.yres) > + y2 =3D info->fb_info->var.yres; > + __xenfb_refresh(info, 0, y1, info->fb_info->var.xres, y2 - y1); > + spin_unlock_irqrestore(&info->mm_lock, flags); > + > + if (type) > + *type =3D VM_FAULT_MINOR; > + > + return page; > +} > + > +static struct vm_operations_struct xenfb_vm_ops =3D { > + .open =3D xenfb_vm_open, > + .close =3D xenfb_vm_close, > + .nopage =3D xenfb_vm_nopage, > +}; > + > +static int xenfb_mmap(struct fb_info *fb_info, struct vm_area_struct *vm= a) > +{ > + struct xenfb_info *info =3D fb_info->par; > + unsigned long flags; > + struct xenfb_mapping *map; > + int map_pages; > + > + if (!(vma->vm_flags & VM_WRITE)) > + return -EINVAL; > + if (!(vma->vm_flags & VM_SHARED)) > + return -EINVAL; > + if (vma->vm_pgoff !=3D 0) > + return -EINVAL; > + > + map_pages =3D (vma->vm_end - vma->vm_start + PAGE_SIZE-1) >> PAGE_SHIFT; > + if (map_pages > info->nr_pages) > + return -EINVAL; > + > + map =3D kzalloc(sizeof(*map), GFP_KERNEL); > + if (map =3D=3D NULL) > + return -ENOMEM; > + > + map->vma =3D vma; > + map->faults =3D 0; > + map->info =3D info; > + atomic_set(&map->map_refs, 1); > + > + spin_lock_irqsave(&info->mm_lock, flags); > + list_add(&map->link, &info->mappings); > + spin_unlock_irqrestore(&info->mm_lock, flags); > + > + vma->vm_ops =3D &xenfb_vm_ops; > + vma->vm_flags |=3D (VM_DONTEXPAND | VM_RESERVED); > + vma->vm_private_data =3D map; > + > + return 0; > +} > + > +static struct fb_ops xenfb_fb_ops =3D { > + .owner =3D THIS_MODULE, > + .fb_setcolreg =3D xenfb_setcolreg, > + .fb_fillrect =3D xenfb_fillrect, > + .fb_copyarea =3D xenfb_copyarea, > + .fb_imageblit =3D xenfb_imageblit, > + .fb_mmap =3D xenfb_mmap, > +}; > + > +static irqreturn_t xenfb_event_handler(int rq, void *dev_id, > + struct pt_regs *regs) > +{ > + /* > + * No in events recognized, simply ignore them all. > + * If you need to recognize some, see xenbkd's input_handler() > + * for how to do that. > + */ > + struct xenfb_info *info =3D dev_id; > + struct xenfb_page *page =3D info->page; > + > + if (page->in_cons !=3D page->in_prod) { > + info->page->in_cons =3D info->page->in_prod; > + notify_remote_via_evtchn(info->evtchn); > + } > + return IRQ_HANDLED; > +} > + > +static unsigned long vmalloc_to_mfn(void *address) > +{ > + return pfn_to_mfn(vmalloc_to_pfn(address)); > +} > + > +static int __devinit xenfb_probe(struct xenbus_device *dev, > + const struct xenbus_device_id *id) > +{ > + struct xenfb_info *info; > + struct fb_info *fb_info; > + int ret; > + > + info =3D kzalloc(sizeof(*info), GFP_KERNEL); > + if (info =3D=3D NULL) { > + xenbus_dev_fatal(dev, -ENOMEM, "allocating info structure"); > + return -ENOMEM; > + } > + dev->dev.driver_data =3D info; > + info->xbdev =3D dev; > + info->irq =3D -1; > + info->x1 =3D info->y1 =3D INT_MAX; > + spin_lock_init(&info->mm_lock); > + init_waitqueue_head(&info->wq); > + init_timer(&info->refresh); > + info->refresh.function =3D xenfb_timer; > + info->refresh.data =3D (unsigned long)info; > + INIT_LIST_HEAD(&info->mappings); > + > + info->fb =3D vmalloc(xenfb_mem_len); > + if (info->fb =3D=3D NULL) > + goto error_nomem; > + memset(info->fb, 0, xenfb_mem_len); > + > + info->nr_pages =3D (xenfb_mem_len + PAGE_SIZE - 1) >> PAGE_SHIFT; > + > + info->pages =3D kmalloc(sizeof(struct page *) * info->nr_pages, > + GFP_KERNEL); > + if (info->pages =3D=3D NULL) > + goto error_nomem; > + > + info->mfns =3D vmalloc(sizeof(unsigned long) * info->nr_pages); > + if (!info->mfns) > + goto error_nomem; > + > + /* set up shared page */ > + info->page =3D (void *)__get_free_page(GFP_KERNEL); > + if (!info->page) > + goto error_nomem; > + > + xenfb_init_shared_page(info); > + > + fb_info =3D framebuffer_alloc(sizeof(u32) * 256, NULL); > + /* see fishy hackery below */ > + if (fb_info =3D=3D NULL) > + goto error_nomem; > + > + /* FIXME fishy hackery */ > + fb_info->pseudo_palette =3D fb_info->par; > + fb_info->par =3D info; > + /* /FIXME */ > + fb_info->screen_base =3D info->fb; > + > + fb_info->fbops =3D &xenfb_fb_ops; > + fb_info->var.xres_virtual =3D fb_info->var.xres =3D info->page->width; > + fb_info->var.yres_virtual =3D fb_info->var.yres =3D info->page->height; > + fb_info->var.bits_per_pixel =3D info->page->depth; > + > + fb_info->var.red =3D (struct fb_bitfield){16, 8, 0}; > + fb_info->var.green =3D (struct fb_bitfield){8, 8, 0}; > + fb_info->var.blue =3D (struct fb_bitfield){0, 8, 0}; > + > + fb_info->var.activate =3D FB_ACTIVATE_NOW; > + fb_info->var.height =3D -1; > + fb_info->var.width =3D -1; > + fb_info->var.vmode =3D FB_VMODE_NONINTERLACED; > + > + fb_info->fix.visual =3D FB_VISUAL_TRUECOLOR; > + fb_info->fix.line_length =3D info->page->line_length; > + fb_info->fix.smem_start =3D 0; > + fb_info->fix.smem_len =3D xenfb_mem_len; > + strcpy(fb_info->fix.id, "xen"); > + fb_info->fix.type =3D FB_TYPE_PACKED_PIXELS; > + fb_info->fix.accel =3D FB_ACCEL_NONE; > + > + fb_info->flags =3D FBINFO_FLAG_DEFAULT; > + > + ret =3D fb_alloc_cmap(&fb_info->cmap, 256, 0); > + if (ret < 0) { > + framebuffer_release(fb_info); > + xenbus_dev_fatal(dev, ret, "fb_alloc_cmap"); > + goto error; > + } > + > + ret =3D register_framebuffer(fb_info); > + if (ret) { > + fb_dealloc_cmap(&info->fb_info->cmap); > + framebuffer_release(fb_info); > + xenbus_dev_fatal(dev, ret, "register_framebuffer"); > + goto error; > + } > + info->fb_info =3D fb_info; > + > + /* FIXME should this be delayed until backend XenbusStateConnected? */ > + info->kthread =3D kthread_run(xenfb_thread, info, "xenfb thread"); > + if (IS_ERR(info->kthread)) { > + ret =3D PTR_ERR(info->kthread); > + info->kthread =3D NULL; > + xenbus_dev_fatal(dev, ret, "register_framebuffer"); > + goto error; > + } > + > + ret =3D xenfb_connect_backend(dev, info); > + if (ret < 0) > + goto error; > + > + return 0; > + > + error_nomem: > + ret =3D -ENOMEM; > + xenbus_dev_fatal(dev, ret, "allocating device memory"); > + error: > + xenfb_remove(dev); > + return ret; > +} > + > +static int xenfb_resume(struct xenbus_device *dev) > +{ > + struct xenfb_info *info =3D dev->dev.driver_data; > + > + xenfb_disconnect_backend(info); > + xenfb_init_shared_page(info); > + return xenfb_connect_backend(dev, info); > +} > + > +static int xenfb_remove(struct xenbus_device *dev) > +{ > + struct xenfb_info *info =3D dev->dev.driver_data; > + > + del_timer(&info->refresh); > + if (info->kthread) > + kthread_stop(info->kthread); > + xenfb_disconnect_backend(info); > + if (info->fb_info) { > + unregister_framebuffer(info->fb_info); > + fb_dealloc_cmap(&info->fb_info->cmap); > + framebuffer_release(info->fb_info); > + } > + free_page((unsigned long)info->page); > + vfree(info->mfns); > + kfree(info->pages); > + vfree(info->fb); > + kfree(info); > + > + return 0; > +} > + > +static void xenfb_init_shared_page(struct xenfb_info *info) > +{ > + int i; > + > + for (i =3D 0; i < info->nr_pages; i++) > + info->pages[i] =3D vmalloc_to_page(info->fb + i * PAGE_SIZE); > + > + for (i =3D 0; i < info->nr_pages; i++) > + info->mfns[i] =3D vmalloc_to_mfn(info->fb + i * PAGE_SIZE); > + > + info->page->pd[0] =3D vmalloc_to_mfn(info->mfns); > + info->page->pd[1] =3D 0; > + info->page->width =3D XENFB_WIDTH; > + info->page->height =3D XENFB_HEIGHT; > + info->page->depth =3D XENFB_DEPTH; > + info->page->line_length =3D (info->page->depth / 8) * info->page->width; > + info->page->mem_length =3D xenfb_mem_len; > + info->page->in_cons =3D info->page->in_prod =3D 0; > + info->page->out_cons =3D info->page->out_prod =3D 0; > +} > + > +static int xenfb_connect_backend(struct xenbus_device *dev, > + struct xenfb_info *info) > +{ > + int ret; > + struct xenbus_transaction xbt; > + > + ret =3D xenbus_alloc_evtchn(dev, &info->evtchn); > + if (ret) > + return ret; > + ret =3D bind_evtchn_to_irqhandler(info->evtchn, xenfb_event_handler, > + 0, "xenfb", info); > + if (ret < 0) { > + xenbus_free_evtchn(dev, info->evtchn); > + xenbus_dev_fatal(dev, ret, "bind_evtchn_to_irqhandler"); > + return ret; > + } > + info->irq =3D ret; > + > + again: > + ret =3D xenbus_transaction_start(&xbt); > + if (ret) { > + xenbus_dev_fatal(dev, ret, "starting transaction"); > + return ret; > + } > + ret =3D xenbus_printf(xbt, dev->nodename, "page-ref", "%lu", > + virt_to_mfn(info->page)); > + if (ret) > + goto error_xenbus; > + ret =3D xenbus_printf(xbt, dev->nodename, "event-channel", "%u", > + info->evtchn); > + if (ret) > + goto error_xenbus; > + ret =3D xenbus_printf(xbt, dev->nodename, "feature-update", "1"); > + if (ret) > + goto error_xenbus; > + ret =3D xenbus_transaction_end(xbt, 0); > + if (ret) { > + if (ret =3D=3D -EAGAIN) > + goto again; > + xenbus_dev_fatal(dev, ret, "completing transaction"); > + return ret; > + } > + > + xenbus_switch_state(dev, XenbusStateInitialised); > + return 0; > + > + error_xenbus: > + xenbus_transaction_end(xbt, 1); > + xenbus_dev_fatal(dev, ret, "writing xenstore"); > + return ret; > +} > + > +static void xenfb_disconnect_backend(struct xenfb_info *info) > +{ > + if (info->irq >=3D 0) > + unbind_from_irqhandler(info->irq, info); > + info->irq =3D -1; > +} > + > +static void xenfb_backend_changed(struct xenbus_device *dev, > + enum xenbus_state backend_state) > +{ > + struct xenfb_info *info =3D dev->dev.driver_data; > + int val; > + > + switch (backend_state) { > + case XenbusStateInitialising: > + case XenbusStateInitialised: > + case XenbusStateUnknown: > + case XenbusStateClosed: > + break; > + > + case XenbusStateInitWait: > + InitWait: > + xenbus_switch_state(dev, XenbusStateConnected); > + break; > + > + case XenbusStateConnected: > + /* > + * Work around xenbus race condition: If backend goes > + * through InitWait to Connected fast enough, we can > + * get Connected twice here. > + */ > + if (dev->state !=3D XenbusStateConnected) > + goto InitWait; /* no InitWait seen yet, fudge it */ > + > + if (xenbus_scanf(XBT_NIL, info->xbdev->otherend, > + "request-update", "%d", &val) < 0) > + val =3D 0; > + if (val) > + info->update_wanted =3D 1; > + break; > + > + case XenbusStateClosing: > + // FIXME is this safe in any dev->state? > + xenbus_frontend_closed(dev); > + break; > + } > +} > + > +static struct xenbus_device_id xenfb_ids[] =3D { > + { "vfb" }, > + { "" } > +}; > + > +static struct xenbus_driver xenfb =3D { > + .name =3D "vfb", > + .owner =3D THIS_MODULE, > + .ids =3D xenfb_ids, > + .probe =3D xenfb_probe, > + .remove =3D xenfb_remove, > + .resume =3D xenfb_resume, > + .otherend_changed =3D xenfb_backend_changed, > +}; > + > +static int __init xenfb_init(void) > +{ > + if (!is_running_on_xen()) > + return -ENODEV; > + > + /* Nothing to do if running in dom0. */ > + if (is_initial_xendomain()) > + return -ENODEV; > + > + return xenbus_register_frontend(&xenfb); > +} > + > +static void __exit xenfb_cleanup(void) > +{ > + return xenbus_unregister_driver(&xenfb); > +} > + > +module_init(xenfb_init); > +module_exit(xenfb_cleanup); > + > +MODULE_LICENSE("GPL"); > diff -r 2773c39df9a6 linux-2.6-xen-sparse/drivers/xen/fbfront/xenkbd.c > --- /dev/null Thu Jan 01 00:00:00 1970 +0000 > +++ b/linux-2.6-xen-sparse/drivers/xen/fbfront/xenkbd.c Thu Nov 30 15:13:= 53 2006 +0100 > @@ -0,0 +1,300 @@ > +/* > + * linux/drivers/input/keyboard/xenkbd.c -- Xen para-virtual input device > + * > + * Copyright (C) 2005 Anthony Liguori > + * Copyright (C) 2006 Red Hat, Inc., Markus Armbruster > + * > + * Based on linux/drivers/input/mouse/sermouse.c > + * > + * This file is subject to the terms and conditions of the GNU General = Public > + * License. See the file COPYING in the main directory of this archive = for > + * more details. > + */ > + > +/* > + * TODO: > + * > + * Switch to grant tables together with xenfb.c. > + */ > + > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > + > +struct xenkbd_info > +{ > + struct input_dev *dev; > + struct xenkbd_page *page; > + unsigned evtchn; > + int irq; > + struct xenbus_device *xbdev; > +}; > + > +static int xenkbd_remove(struct xenbus_device *); > +static int xenkbd_connect_backend(struct xenbus_device *, struct xenkbd_= info *); > +static void xenkbd_disconnect_backend(struct xenkbd_info *); > + > +/* > + * Note: if you need to send out events, see xenfb_do_update() for how > + * to do that. > + */ > + > +static irqreturn_t input_handler(int rq, void *dev_id, struct pt_regs *r= egs) > +{ > + struct xenkbd_info *info =3D dev_id; > + struct xenkbd_page *page =3D info->page; > + __u32 cons, prod; > + > + prod =3D page->in_prod; > + if (prod =3D=3D page->out_cons) > + return IRQ_HANDLED; > + rmb(); /* ensure we see ring contents up to prod */ > + for (cons =3D page->in_cons; cons !=3D prod; cons++) { > + union xenkbd_in_event *event; > + event =3D &XENKBD_IN_RING_REF(page, cons); > + > + switch (event->type) { > + case XENKBD_TYPE_MOTION: > + input_report_rel(info->dev, REL_X, event->motion.rel_x); > + input_report_rel(info->dev, REL_Y, event->motion.rel_y); > + break; > + case XENKBD_TYPE_KEY: > + input_report_key(info->dev, event->key.keycode, event->key.pressed); > + break; > + case XENKBD_TYPE_POS: > + input_report_abs(info->dev, ABS_X, event->pos.abs_x); > + input_report_abs(info->dev, ABS_Y, event->pos.abs_y); > + break; > + } > + } > + input_sync(info->dev); > + mb(); /* ensure we got ring contents */ > + page->in_cons =3D cons; > + notify_remote_via_evtchn(info->evtchn); > + > + return IRQ_HANDLED; > +} > + > +int __devinit xenkbd_probe(struct xenbus_device *dev, > + const struct xenbus_device_id *id) > +{ > + int ret, i; > + struct xenkbd_info *info; > + struct input_dev *input_dev; > + > + info =3D kzalloc(sizeof(*info), GFP_KERNEL); > + if (!info) { > + xenbus_dev_fatal(dev, -ENOMEM, "allocating info structure"); > + return -ENOMEM; > + } > + dev->dev.driver_data =3D info; > + info->xbdev =3D dev; > + > + info->page =3D (void *)__get_free_page(GFP_KERNEL); > + if (!info->page) > + goto error_nomem; > + info->page->in_cons =3D info->page->in_prod =3D 0; > + info->page->out_cons =3D info->page->out_prod =3D 0; > + > + input_dev =3D input_allocate_device(); > + if (!input_dev) > + goto error_nomem; > + > + input_dev->evbit[0] =3D BIT(EV_KEY) | BIT(EV_REL) | BIT(EV_ABS); > + input_dev->keybit[LONG(BTN_MOUSE)] > + =3D BIT(BTN_LEFT) | BIT(BTN_MIDDLE) | BIT(BTN_RIGHT); > + /* TODO additional buttons */ > + input_dev->relbit[0] =3D BIT(REL_X) | BIT(REL_Y); > + > + /* FIXME not sure this is quite right */ > + for (i =3D 0; i < 256; i++) > + set_bit(i, input_dev->keybit); > + > + input_dev->name =3D "Xen Virtual Keyboard/Mouse"; > + > + input_set_abs_params(input_dev, ABS_X, 0, XENFB_WIDTH, 0, 0); > + input_set_abs_params(input_dev, ABS_Y, 0, XENFB_HEIGHT, 0, 0); > + > + ret =3D input_register_device(input_dev); > + if (ret) { > + input_free_device(input_dev); > + xenbus_dev_fatal(dev, ret, "input_register_device"); > + goto error; > + } > + info->dev =3D input_dev; > + > + ret =3D xenkbd_connect_backend(dev, info); > + if (ret < 0) > + goto error; > + > + return 0; > + > + error_nomem: > + ret =3D -ENOMEM; > + xenbus_dev_fatal(dev, ret, "allocating device memory"); > + error: > + xenkbd_remove(dev); > + return ret; > +} > + > +static int xenkbd_resume(struct xenbus_device *dev) > +{ > + struct xenkbd_info *info =3D dev->dev.driver_data; > + > + xenkbd_disconnect_backend(info); > + return xenkbd_connect_backend(dev, info); > +} > + > +static int xenkbd_remove(struct xenbus_device *dev) > +{ > + struct xenkbd_info *info =3D dev->dev.driver_data; > + > + xenkbd_disconnect_backend(info); > + input_unregister_device(info->dev); > + free_page((unsigned long)info->page); > + kfree(info); > + return 0; > +} > + > +static int xenkbd_connect_backend(struct xenbus_device *dev, > + struct xenkbd_info *info) > +{ > + int ret; > + struct xenbus_transaction xbt; > + > + ret =3D xenbus_alloc_evtchn(dev, &info->evtchn); > + if (ret) > + return ret; > + ret =3D bind_evtchn_to_irqhandler(info->evtchn, input_handler, 0, > + "xenkbd", info); > + if (ret < 0) { > + xenbus_free_evtchn(dev, info->evtchn); > + xenbus_dev_fatal(dev, ret, "bind_evtchn_to_irqhandler"); > + return ret; > + } > + info->irq =3D ret; > + > + again: > + ret =3D xenbus_transaction_start(&xbt); > + if (ret) { > + xenbus_dev_fatal(dev, ret, "starting transaction"); > + return ret; > + } > + ret =3D xenbus_printf(xbt, dev->nodename, "page-ref", "%lu", > + virt_to_mfn(info->page)); > + if (ret) > + goto error_xenbus; > + ret =3D xenbus_printf(xbt, dev->nodename, "event-channel", "%u", > + info->evtchn); > + if (ret) > + goto error_xenbus; > + ret =3D xenbus_transaction_end(xbt, 0); > + if (ret) { > + if (ret =3D=3D -EAGAIN) > + goto again; > + xenbus_dev_fatal(dev, ret, "completing transaction"); > + return ret; > + } > + > + xenbus_switch_state(dev, XenbusStateInitialised); > + return 0; > + > + error_xenbus: > + xenbus_transaction_end(xbt, 1); > + xenbus_dev_fatal(dev, ret, "writing xenstore"); > + return ret; > +} > + > +static void xenkbd_disconnect_backend(struct xenkbd_info *info) > +{ > + if (info->irq >=3D 0) > + unbind_from_irqhandler(info->irq, info); > + info->irq =3D -1; > +} > + > +static void xenkbd_backend_changed(struct xenbus_device *dev, > + enum xenbus_state backend_state) > +{ > + struct xenkbd_info *info =3D dev->dev.driver_data; > + int ret, val; > + > + switch (backend_state) { > + case XenbusStateInitialising: > + case XenbusStateInitialised: > + case XenbusStateUnknown: > + case XenbusStateClosed: > + break; > + > + case XenbusStateInitWait: > + InitWait: > + ret =3D xenbus_scanf(XBT_NIL, info->xbdev->otherend, > + "feature-abs-pointer", "%d", &val); > + if (ret < 0) > + val =3D 0; > + if (val) { > + ret =3D xenbus_printf(XBT_NIL, info->xbdev->nodename, > + "request-abs-pointer", "1"); > + if (ret) > + ; /* FIXME */ > + } > + xenbus_switch_state(dev, XenbusStateConnected); > + break; > + > + case XenbusStateConnected: > + /* > + * Work around xenbus race condition: If backend goes > + * through InitWait to Connected fast enough, we can > + * get Connected twice here. > + */ > + if (dev->state !=3D XenbusStateConnected) > + goto InitWait; /* no InitWait seen yet, fudge it */ > + break; > + > + case XenbusStateClosing: > + xenbus_frontend_closed(dev); > + break; > + } > +} > + > +static struct xenbus_device_id xenkbd_ids[] =3D { > + { "vkbd" }, > + { "" } > +}; > + > +static struct xenbus_driver xenkbd =3D { > + .name =3D "vkbd", > + .owner =3D THIS_MODULE, > + .ids =3D xenkbd_ids, > + .probe =3D xenkbd_probe, > + .remove =3D xenkbd_remove, > + .resume =3D xenkbd_resume, > + .otherend_changed =3D xenkbd_backend_changed, > +}; > + > +static int __init xenkbd_init(void) > +{ > + if (!is_running_on_xen()) > + return -ENODEV; > + > + /* Nothing to do if running in dom0. */ > + if (is_initial_xendomain()) > + return -ENODEV; > + > + return xenbus_register_frontend(&xenkbd); > +} > + > +static void __exit xenkbd_cleanup(void) > +{ > + return xenbus_unregister_driver(&xenkbd); > +} > + > +module_init(xenkbd_init); > +module_exit(xenkbd_cleanup); > + > +MODULE_LICENSE("GPL"); > diff -r 2773c39df9a6 tools/python/xen/xend/server/vfbif.py > --- /dev/null Thu Jan 01 00:00:00 1970 +0000 > +++ b/tools/python/xen/xend/server/vfbif.py Thu Nov 23 09:18:03 2006 +0100 > @@ -0,0 +1,29 @@ > +from xen.xend.server.DevController import DevController > + > +class VfbifController(DevController): > + """Virtual frame buffer controller. Handles all vfb devices for a do= main. > + """ > + > + def __init__(self, vm): > + DevController.__init__(self, vm) > + > + def getDeviceDetails(self, config): > + """@see DevController.getDeviceDetails""" > + devid =3D 0 > + back =3D {} > + front =3D {} > + return (devid, back, front) > + > +class VkbdifController(DevController): > + """Virtual keyboard controller. Handles all vkbd devices for a domai= n. > + """ > + > + def __init__(self, vm): > + DevController.__init__(self, vm) > + > + def getDeviceDetails(self, config): > + """@see DevController.getDeviceDetails""" > + devid =3D 0 > + back =3D {} > + front =3D {} > + return (devid, back, front) > diff -r 2773c39df9a6 tools/xenfb/Makefile > --- /dev/null Thu Jan 01 00:00:00 1970 +0000 > +++ b/tools/xenfb/Makefile Thu Nov 23 11:29:49 2006 +0100 > @@ -0,0 +1,35 @@ > +XEN_ROOT=3D../.. > +include $(XEN_ROOT)/tools/Rules.mk > + > +CFLAGS +=3D -I$(XEN_LIBXC) -I$(XEN_XENSTORE) -I$(XEN_ROOT)/linux-2.6-xen= -sparse/include > +LDFLAGS +=3D -L$(XEN_LIBXC) -L$(XEN_XENSTORE) > + > +INSTALL =3D install > +INSTALL_PROG =3D $(INSTALL) -m0755 > +INSTALL_DIR =3D $(INSTALL) -d -m0755 > + > +.PHONY: all > +all: build > + > +.PHONY: build > +build: mk-symlinks > + $(MAKE) vncfb sdlfb > + > +install: all > + $(INSTALL_DIR) -p $(DESTDIR)/usr/$(LIBDIR)/xen/bin > + $(INSTALL_PROG) vncfb $(DESTDIR)/usr/$(LIBDIR)/xen/bin/xen-vncfb > + $(INSTALL_PROG) sdlfb $(DESTDIR)/usr/$(LIBDIR)/xen/bin/xen-sdlfb > + > +sdlfb: sdlfb.o xenfb.o > + > +sdlfb.o: CFLAGS +=3D $(shell sdl-config --cflags) > +sdlfb: LDLIBS +=3D $(shell sdl-config --libs) -lxenctrl -lxenstore > + > +clean: > + $(RM) *.o *~ vncfb sdlfb > + > +vncfb: vncfb.o xenfb.o > +vncfb.o: CFLAGS +=3D $(shell libvncserver-config --cflags) > +vncfb: LDLIBS +=3D $(shell libvncserver-config --libs) -lxenctrl -lxenst= ore > + > +sdlfb.o xenfb.o vncfb.o: xenfb.h > diff -r 2773c39df9a6 tools/xenfb/sdlfb.c > --- /dev/null Thu Jan 01 00:00:00 1970 +0000 > +++ b/tools/xenfb/sdlfb.c Thu Nov 23 11:09:50 2006 +0100 > @@ -0,0 +1,334 @@ > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include "xenfb.h" > + > +struct SDLFBData > +{ > + SDL_Surface *dst; > + SDL_Surface *src; > +}; > + > +/* > + * Map from scancode to Linux input layer keycode. Scancodes are > + * hardware-specific. This map assumes a standard AT or PS/2 > + * keyboard. > + * > + * Why use scancodes? We can't use key symbols, because they don't > + * identify keys --- they're what keys are mapped to. The standard > + * German keymap, for instance, maps both KEY_COMMA and KEY_102ND to > + * SDLK_LESS. > + */ > +static int keymap[256] =3D { > + [9] =3D KEY_ESC, > + [10] =3D KEY_1, > + [11] =3D KEY_2, > + [12] =3D KEY_3, > + [13] =3D KEY_4, > + [14] =3D KEY_5, > + [15] =3D KEY_6, > + [16] =3D KEY_7, > + [17] =3D KEY_8, > + [18] =3D KEY_9, > + [19] =3D KEY_0, > + [20] =3D KEY_MINUS, > + [21] =3D KEY_EQUAL, > + [22] =3D KEY_BACKSPACE, > + [23] =3D KEY_TAB, > + [24] =3D KEY_Q, > + [25] =3D KEY_W, > + [26] =3D KEY_E, > + [27] =3D KEY_R, > + [28] =3D KEY_T, > + [29] =3D KEY_Y, > + [30] =3D KEY_U, > + [31] =3D KEY_I, > + [32] =3D KEY_O, > + [33] =3D KEY_P, > + [34] =3D KEY_LEFTBRACE, > + [35] =3D KEY_RIGHTBRACE, > + [36] =3D KEY_ENTER, > + [37] =3D KEY_LEFTCTRL, > + [38] =3D KEY_A, > + [39] =3D KEY_S, > + [40] =3D KEY_D, > + [41] =3D KEY_F, > + [42] =3D KEY_G, > + [43] =3D KEY_H, > + [44] =3D KEY_J, > + [45] =3D KEY_K, > + [46] =3D KEY_L, > + [47] =3D KEY_SEMICOLON, > + [48] =3D KEY_APOSTROPHE, > + [49] =3D KEY_GRAVE, > + [50] =3D KEY_LEFTSHIFT, > + [51] =3D KEY_BACKSLASH, > + [52] =3D KEY_Z, > + [53] =3D KEY_X, > + [54] =3D KEY_C, > + [55] =3D KEY_V, > + [56] =3D KEY_B, > + [57] =3D KEY_N, > + [58] =3D KEY_M, > + [59] =3D KEY_COMMA, > + [60] =3D KEY_DOT, > + [61] =3D KEY_SLASH, > + [62] =3D KEY_RIGHTSHIFT, > + [63] =3D KEY_KPASTERISK, > + [64] =3D KEY_LEFTALT, > + [65] =3D KEY_SPACE, > + [66] =3D KEY_CAPSLOCK, > + [67] =3D KEY_F1, > + [68] =3D KEY_F2, > + [69] =3D KEY_F3, > + [70] =3D KEY_F4, > + [71] =3D KEY_F5, > + [72] =3D KEY_F6, > + [73] =3D KEY_F7, > + [74] =3D KEY_F8, > + [75] =3D KEY_F9, > + [76] =3D KEY_F10, > + [77] =3D KEY_NUMLOCK, > + [78] =3D KEY_SCROLLLOCK, > + [79] =3D KEY_KP7, > + [80] =3D KEY_KP8, > + [81] =3D KEY_KP9, > + [82] =3D KEY_KPMINUS, > + [83] =3D KEY_KP4, > + [84] =3D KEY_KP5, > + [85] =3D KEY_KP6, > + [86] =3D KEY_KPPLUS, > + [87] =3D KEY_KP1, > + [88] =3D KEY_KP2, > + [89] =3D KEY_KP3, > + [90] =3D KEY_KP0, > + [91] =3D KEY_KPDOT, > + [94] =3D KEY_102ND, /* FIXME is this correct? */ > + [95] =3D KEY_F11, > + [96] =3D KEY_F12, > + [108] =3D KEY_KPENTER, > + [109] =3D KEY_RIGHTCTRL, > + [112] =3D KEY_KPSLASH, > + [111] =3D KEY_SYSRQ, > + [113] =3D KEY_RIGHTALT, > + [97] =3D KEY_HOME, > + [98] =3D KEY_UP, > + [99] =3D KEY_PAGEUP, > + [100] =3D KEY_LEFT, > + [102] =3D KEY_RIGHT, > + [103] =3D KEY_END, > + [104] =3D KEY_DOWN, > + [105] =3D KEY_PAGEDOWN, > + [106] =3D KEY_INSERT, > + [107] =3D KEY_DELETE, > + [110] =3D KEY_PAUSE, > + [115] =3D KEY_LEFTMETA, > + [116] =3D KEY_RIGHTMETA, > + [117] =3D KEY_MENU, > +}; > + > +static int btnmap[] =3D { > + [SDL_BUTTON_LEFT] =3D BTN_LEFT, > + [SDL_BUTTON_MIDDLE] =3D BTN_MIDDLE, > + [SDL_BUTTON_RIGHT] =3D BTN_RIGHT, > + /* FIXME not 100% sure about these: */ > + [SDL_BUTTON_WHEELUP] =3D BTN_FORWARD, > + [SDL_BUTTON_WHEELDOWN] BTN_BACK > +}; > + > +static void sdl_update(struct xenfb *xenfb, int x, int y, int width, int= height) > +{ > + struct SDLFBData *data =3D xenfb->user_data; > + SDL_Rect r =3D { x, y, width, height }; > + SDL_BlitSurface(data->src, &r, data->dst, &r); > + SDL_UpdateRect(data->dst, x, y, width, height); > +} > + > +static int sdl_on_event(struct xenfb *xenfb, SDL_Event *event) > +{ > + int x, y, ret; > + > + switch (event->type) { > + case SDL_KEYDOWN: > + case SDL_KEYUP: > + if (keymap[event->key.keysym.scancode] =3D=3D 0) > + break; > + ret =3D xenfb_send_key(xenfb, > + event->type =3D=3D SDL_KEYDOWN, > + keymap[event->key.keysym.scancode]); > + if (ret < 0) > + fprintf(stderr, "Key %d %s lost (%s)\n", > + keymap[event->key.keysym.scancode], > + event->type =3D=3D SDL_KEYDOWN ? "down" : "up", > + strerror(errno)); > + break; > + case SDL_MOUSEMOTION: > + if (xenfb->abs_pointer_wanted) { > + SDL_GetMouseState(&x, &y); > + ret =3D xenfb_send_position(xenfb, x, y); > + } else { > + SDL_GetRelativeMouseState(&x, &y); > + ret =3D xenfb_send_motion(xenfb, x, y); > + } > + if (ret < 0) > + fprintf(stderr, "Pointer to %d,%d lost (%s)\n", > + x, y, strerror(errno)); > + break; > + case SDL_MOUSEBUTTONDOWN: > + case SDL_MOUSEBUTTONUP: > + if (event->button.button >=3D sizeof(btnmap) / sizeof(*btnmap)) > + break; > + if (btnmap[event->button.button] =3D=3D 0) > + break; > + ret =3D xenfb_send_key(xenfb, > + event->type =3D=3D SDL_MOUSEBUTTONDOWN, > + btnmap[event->button.button]); > + if (ret < 0) > + fprintf(stderr, "Button %d %s lost (%s)\n", > + btnmap[event->button.button] - BTN_MOUSE, > + event->type =3D=3D SDL_MOUSEBUTTONDOWN ? "down" : "up", > + strerror(errno)); > + break; > + case SDL_QUIT: > + return 0; > + } > + > + return 1; > +} > + > +static struct option options[] =3D { > + { "domid", 1, NULL, 'd' }, > + { "title", 1, NULL, 't' }, > +}; > + > +int main(int argc, char **argv) > +{ > + struct xenfb *xenfb; > + int domid =3D -1; > + char * title =3D NULL; > + fd_set readfds; > + int nfds; > + struct SDLFBData data; > + SDL_Rect r; > + struct timeval tv; > + SDL_Event event; > + int do_quit =3D 0; > + int opt; > + char *endp; > + > + while ((opt =3D getopt_long(argc, argv, "d:t:", options, > + NULL)) !=3D -1) { > + switch (opt) { > + case 'd': > + domid =3D strtol(optarg, &endp, 10); > + if (endp =3D=3D optarg || *endp) { > + fprintf(stderr, "Invalid domain id specified\n"); > + exit(1); > + } > + break; > + case 't': > + title =3D strdup(optarg); > + break; > + } > + } > + if (optind !=3D argc) { > + fprintf(stderr, "Invalid options!\n"); > + exit(1); > + } > + if (domid <=3D 0) { > + fprintf(stderr, "Domain ID must be specified!\n"); > + exit(1); > + } > + > + xenfb =3D xenfb_new(); > + if (xenfb =3D=3D NULL) { > + fprintf(stderr, "Could not create framebuffer (%s)\n", > + strerror(errno)); > + exit(1); > + } > + > + if (xenfb_attach_dom(xenfb, domid) < 0) { > + fprintf(stderr, "Could not connect to domain (%s)\n", > + strerror(errno)); > + exit(1); > + } > + > + if (SDL_Init(SDL_INIT_VIDEO) < 0) { > + fprintf(stderr, "Could not initialize SDL\n"); > + exit(1); > + } > + > + data.dst =3D SDL_SetVideoMode(xenfb->width, xenfb->height, xenfb->depth, > + SDL_SWSURFACE); > + if (!data.dst) { > + fprintf(stderr, "SDL_SetVideoMode failed\n"); > + exit(1); > + } > + > + data.src =3D SDL_CreateRGBSurfaceFrom(xenfb->pixels, > + xenfb->width, xenfb->height, > + xenfb->depth, xenfb->row_stride, > + 0xFF0000, 0xFF00, 0xFF, 0); > + > + if (!data.src) { > + fprintf(stderr, "SDL_CreateRGBSurfaceFrom failed\n"); > + exit(1); > + } > + > + if (title =3D=3D NULL) > + title =3D strdup("xen-sdlfb"); > + SDL_WM_SetCaption(title, title); > + > + r.x =3D r.y =3D 0; > + r.w =3D xenfb->width; > + r.h =3D xenfb->height; > + SDL_BlitSurface(data.src, &r, data.dst, &r); > + SDL_UpdateRect(data.dst, 0, 0, xenfb->width, xenfb->height); > + > + xenfb->update =3D sdl_update; > + xenfb->user_data =3D &data; > + > + SDL_ShowCursor(0); > + > + /* > + * We need to wait for fds becoming ready or SDL events to > + * arrive. We time out the select after 10ms to poll for SDL > + * events. Clunky, but works. Could avoid the clunkiness > + * with a separate thread. > + */ > + for (;;) { > + FD_ZERO(&readfds); > + nfds =3D xenfb_select_fds(xenfb, &readfds); > + tv =3D (struct timeval){0, 10000}; > + > + if (select(nfds, &readfds, NULL, NULL, &tv) < 0) { > + if (errno =3D=3D EINTR) > + continue; > + fprintf(stderr, > + "Can't select() on event channel (%s)\n", > + strerror(errno)); > + break; > + } > + > + while (SDL_PollEvent(&event)) { > + if (!sdl_on_event(xenfb, &event)) > + do_quit =3D 1; > + } > + > + if (do_quit) > + break; > + > + xenfb_poll(xenfb, &readfds); > + } > + > + xenfb_delete(xenfb); > + > + SDL_Quit(); > + > + return 0; > +} > diff -r 2773c39df9a6 tools/xenfb/vncfb.c > --- /dev/null Thu Jan 01 00:00:00 1970 +0000 > +++ b/tools/xenfb/vncfb.c Thu Nov 23 11:32:35 2006 +0100 > @@ -0,0 +1,393 @@ > +#define _GNU_SOURCE > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include "xenfb.h" > + > +static int xk2linux[0x10000] =3D { > + [XK_a] =3D KEY_A, > + [XK_b] =3D KEY_B, > + [XK_c] =3D KEY_C, > + [XK_d] =3D KEY_D, > + [XK_e] =3D KEY_E, > + [XK_f] =3D KEY_F, > + [XK_g] =3D KEY_G, > + [XK_h] =3D KEY_H, > + [XK_i] =3D KEY_I, > + [XK_j] =3D KEY_J, > + [XK_k] =3D KEY_K, > + [XK_l] =3D KEY_L, > + [XK_m] =3D KEY_M, > + [XK_n] =3D KEY_N, > + [XK_o] =3D KEY_O, > + [XK_p] =3D KEY_P, > + [XK_q] =3D KEY_Q, > + [XK_r] =3D KEY_R, > + [XK_s] =3D KEY_S, > + [XK_t] =3D KEY_T, > + [XK_u] =3D KEY_U, > + [XK_v] =3D KEY_V, > + [XK_w] =3D KEY_W, > + [XK_x] =3D KEY_X, > + [XK_y] =3D KEY_Y, > + [XK_z] =3D KEY_Z, > + [XK_A] =3D KEY_A, > + [XK_B] =3D KEY_B, > + [XK_C] =3D KEY_C, > + [XK_D] =3D KEY_D, > + [XK_E] =3D KEY_E, > + [XK_F] =3D KEY_F, > + [XK_G] =3D KEY_G, > + [XK_H] =3D KEY_H, > + [XK_I] =3D KEY_I, > + [XK_J] =3D KEY_J, > + [XK_K] =3D KEY_K, > + [XK_L] =3D KEY_L, > + [XK_M] =3D KEY_M, > + [XK_N] =3D KEY_N, > + [XK_O] =3D KEY_O, > + [XK_P] =3D KEY_P, > + [XK_Q] =3D KEY_Q, > + [XK_R] =3D KEY_R, > + [XK_S] =3D KEY_S, > + [XK_T] =3D KEY_T, > + [XK_U] =3D KEY_U, > + [XK_V] =3D KEY_V, > + [XK_W] =3D KEY_W, > + [XK_X] =3D KEY_X, > + [XK_Y] =3D KEY_Y, > + [XK_Z] =3D KEY_Z, > + [XK_0] =3D KEY_0, > + [XK_1] =3D KEY_1, > + [XK_2] =3D KEY_2, > + [XK_3] =3D KEY_3, > + [XK_4] =3D KEY_4, > + [XK_5] =3D KEY_5, > + [XK_6] =3D KEY_6, > + [XK_7] =3D KEY_7, > + [XK_8] =3D KEY_8, > + [XK_9] =3D KEY_9, > + [XK_Return] =3D KEY_ENTER, > + [XK_BackSpace] =3D KEY_BACKSPACE, > + [XK_Tab] =3D KEY_TAB, > + [XK_Pause] =3D KEY_PAUSE, > + [XK_Delete] =3D KEY_DELETE, > + [XK_slash] =3D KEY_SLASH, > + [XK_minus] =3D KEY_MINUS, > + [XK_equal] =3D KEY_EQUAL, > + [XK_Escape] =3D KEY_ESC, > + [XK_braceleft] =3D KEY_LEFTBRACE, > + [XK_braceright] =3D KEY_RIGHTBRACE, > + [XK_bracketleft] =3D KEY_LEFTMETA, > + [XK_bracketright] =3D KEY_RIGHTMETA, > + [XK_Control_L] =3D KEY_LEFTCTRL, > + [XK_Control_R] =3D KEY_RIGHTCTRL, > + [XK_Shift_L] =3D KEY_LEFTSHIFT, > + [XK_Shift_R] =3D KEY_RIGHTSHIFT, > + [XK_Alt_L] =3D KEY_LEFTALT, > + [XK_Alt_R] =3D KEY_RIGHTALT, > + [XK_semicolon] =3D KEY_SEMICOLON,=20 > + [XK_apostrophe] =3D KEY_APOSTROPHE, > + [XK_grave] =3D KEY_GRAVE, > + [XK_backslash] =3D KEY_BACKSLASH, > + [XK_comma] =3D KEY_COMMA, > + [XK_period] =3D KEY_DOT, > + [XK_space] =3D KEY_SPACE, > + [XK_Caps_Lock] =3D KEY_CAPSLOCK, > + [XK_Num_Lock] =3D KEY_NUMLOCK, > + [XK_Scroll_Lock] =3D KEY_SCROLLLOCK, > + [XK_Sys_Req] =3D KEY_SYSRQ, > + [XK_Linefeed] =3D KEY_LINEFEED, > + [XK_Home] =3D KEY_HOME, > + [XK_Pause] =3D KEY_PAUSE, > + [XK_F1] =3D KEY_F1, > + [XK_F2] =3D KEY_F2, > + [XK_F3] =3D KEY_F3, > + [XK_F4] =3D KEY_F4, > + [XK_F5] =3D KEY_F5, > + [XK_F6] =3D KEY_F6, > + [XK_F7] =3D KEY_F7, > + [XK_F8] =3D KEY_F8, > + [XK_F9] =3D KEY_F9, > + [XK_F10] =3D KEY_F10, > + [XK_F11] =3D KEY_F11, > + [XK_F12] =3D KEY_F12, > + [XK_Up] =3D KEY_UP, > + [XK_Page_Up] =3D KEY_PAGEUP, > + [XK_Left] =3D KEY_LEFT, > + [XK_Right] =3D KEY_RIGHT, > + [XK_End] =3D KEY_END, > + [XK_Down] =3D KEY_DOWN, > + [XK_Page_Down] =3D KEY_PAGEDOWN, > + [XK_Insert] =3D KEY_INSERT,=20 > + [XK_colon] =3D KEY_SEMICOLON, > + [XK_quotedbl] =3D KEY_APOSTROPHE, > + [XK_less] =3D KEY_COMMA, > + [XK_greater] =3D KEY_DOT, > + [XK_question] =3D KEY_SLASH, > + [XK_bar] =3D KEY_BACKSLASH, > + [XK_asciitilde] =3D KEY_GRAVE, > + [XK_exclam] =3D KEY_1, > + [XK_at] =3D KEY_2, > + [XK_numbersign] =3D KEY_3, > + [XK_dollar] =3D KEY_4, > + [XK_percent] =3D KEY_5, > + [XK_asciicircum] =3D KEY_6, > + [XK_ampersand] =3D KEY_7, > + [XK_asterisk] =3D KEY_8, > + [XK_parenleft] =3D KEY_9, > + [XK_parenright] =3D KEY_0, > + [XK_underscore] =3D KEY_MINUS, > + [XK_plus] =3D KEY_EQUAL, > +}; > + > +static void on_kbd_event(rfbBool down, rfbKeySym keycode, rfbClientPtr c= l) > +{ > + /* > + * We need to map to the key's Linux input layer keycode. > + * Unfortunately, we don't get the key here, only the > + * rfbKeySym, which is what the key is mapped to. Mapping > + * back to the key is impossible in general, even when you > + * know the keymap. For instance, the standard German keymap > + * maps both KEY_COMMA and KEY_102ND to XK_less. We simply > + * assume standard US layout. This sucks. > + */ > + rfbScreenInfoPtr server =3D cl->screen; > + struct xenfb *xenfb =3D server->screenData; > + if (keycode >=3D sizeof(xk2linux) / sizeof(*xk2linux)) > + return; > + if (xk2linux[keycode] =3D=3D 0) > + return; > + if (xenfb_send_key(xenfb, down, xk2linux[keycode]) < 0) > + fprintf(stderr, "Key %d %s lost (%s)\n", > + xk2linux[keycode], down ? "down" : "up", > + strerror(errno)); > +} > + > +static void on_ptr_event(int buttonMask, int x, int y, rfbClientPtr cl) > +{ > + /* initial pointer state: at (0,0), buttons up */ > + static int last_x, last_y, last_button; > + rfbScreenInfoPtr server =3D cl->screen; > + struct xenfb *xenfb =3D server->screenData; > + int i, last_down, down, ret; > + > + for (i =3D 0; i < 8; i++) { > + last_down =3D last_button & (1 << i); > + down =3D buttonMask & (1 << i); > + if (down =3D=3D last_down) > + continue; > + /* FIXME this assumes buttons are numbered the same; verify they are */ > + if (xenfb_send_key(xenfb, down !=3D 0, BTN_MOUSE + i) < 0) > + fprintf(stderr, "Button %d %s lost (%s)\n", > + i, down ? "down" : "up", strerror(errno)); > + } > + > + if (x !=3D last_x || y !=3D last_y) { > + if (xenfb->abs_pointer_wanted)=20 > + ret =3D xenfb_send_position(xenfb, x, y); > + else > + ret =3D xenfb_send_motion(xenfb, x - last_x, y - last_y); > + if (ret < 0) > + fprintf(stderr, "Pointer to %d,%d lost (%s)\n", > + x, y, strerror(errno)); > + } > + > + last_button =3D buttonMask; > + last_x =3D x; > + last_y =3D y; > +} > + > +static void xenstore_write_vncport(int port, int domid) > +{ > + char *buf =3D NULL, *path; > + char portstr[10]; > + struct xs_handle *xsh =3D NULL; > + > + xsh =3D xs_daemon_open(); > + if (xsh =3D=3D NULL) > + return; > + > + path =3D xs_get_domain_path(xsh, domid); > + if (path =3D=3D NULL) { > + fprintf(stderr, "Can't get domain path (%s)\n", > + strerror(errno)); > + goto out; > + } > + > + if (asprintf(&buf, "%s/console/vnc-port", path) =3D=3D -1) { > + fprintf(stderr, "Can't make vncport path\n"); > + goto out; > + } > + > + if (snprintf(portstr, sizeof(portstr), "%d", port) =3D=3D -1) { > + fprintf(stderr, "Can't make vncport value\n"); > + goto out; > + } > + > + if (!xs_write(xsh, XBT_NULL, buf, portstr, strlen(portstr))) > + fprintf(stderr, "Can't set vncport (%s)\n", > + strerror(errno)); > + > + out: > + free(buf); > +} > + > + > +static void vnc_update(struct xenfb *xenfb, int x, int y, int w, int h) > +{ > + rfbScreenInfoPtr server =3D xenfb->user_data; > + rfbMarkRectAsModified(server, x, y, x + w, y + h); > +} > + > +static struct option options[] =3D { > + { "domid", 1, NULL, 'd' }, > + { "vncport", 1, NULL, 'p' }, > + { "title", 1, NULL, 't' }, > + { "unused", 0, NULL, 'u' }, > + { "listen", 1, NULL, 'l' }, > +}; > + > +int main(int argc, char **argv) > +{ > + rfbScreenInfoPtr server; > + char *fake_argv[7] =3D { "vncfb", "-rfbport", "5901",=20 > + "-desktop", "xen-vncfb",=20 > + "-listen", "127.0.0.1" }; > + int fake_argc =3D sizeof(fake_argv) / sizeof(fake_argv[0]); > + int domid =3D -1, port =3D -1; > + char *title =3D NULL; > + char *listen =3D NULL; > + bool unused =3D false; > + int opt; > + struct xenfb *xenfb; > + fd_set readfds; > + int nfds; > + char portstr[10]; > + char *endp; > + > + while ((opt =3D getopt_long(argc, argv, "d:p:t:u", options, > + NULL)) !=3D -1) { > + switch (opt) { > + case 'd': > + errno =3D 0; > + domid =3D strtol(optarg, &endp, 10); > + if (endp =3D=3D optarg || *endp || errno) { > + fprintf(stderr, "Invalid domain id specified\n"); > + exit(1); > + } > + break; > + case 'p': > + errno =3D 0; > + port =3D strtol(optarg, &endp, 10); > + if (endp =3D=3D optarg || *endp || errno) { > + fprintf(stderr, "Invalid port specified\n"); > + exit(1); > + } > + break; > + case 't': > + title =3D strdup(optarg); > + break; > + case 'u': > + unused =3D true; > + break; > + case 'l': > + listen =3D strdup(optarg); > + break; > + } > + } > + if (optind !=3D argc) { > + fprintf(stderr, "Invalid options!\n"); > + exit(1); > + } > + if (domid <=3D 0) { > + fprintf(stderr, "Domain ID must be specified!\n"); > + exit(1); > + } > + =20 > + if (port <=3D 0) > + port =3D 5900 + domid; > + if (snprintf(portstr, sizeof(portstr), "%d", port) =3D=3D -1) { > + fprintf(stderr, "Invalid port specified\n"); > + exit(1); > + } > + =20 > + fake_argv[2] =3D portstr; > + > + if (title !=3D NULL) > + fake_argv[4] =3D title; > + > + if (listen !=3D NULL) > + fake_argv[6] =3D listen; > + > + signal(SIGPIPE, SIG_IGN); > + > + xenfb =3D xenfb_new(); > + if (xenfb =3D=3D NULL) { > + fprintf(stderr, "Could not create framebuffer (%s)\n", > + strerror(errno)); > + exit(1); > + } > + > + if (xenfb_attach_dom(xenfb, domid) < 0) { > + fprintf(stderr, "Could not connect to domain (%s)\n", > + strerror(errno)); > + exit(1); > + } > + > + server =3D rfbGetScreen(&fake_argc, fake_argv,=20 > + xenfb->width, xenfb->height, > + 8, 3, xenfb->depth / 8); > + if (server =3D=3D NULL) { > + fprintf(stderr, "Could not create VNC server\n"); > + exit(1); > + } > + > + xenfb->user_data =3D server; > + xenfb->update =3D vnc_update; > + > + if (unused) > + server->autoPort =3D true; > + > + server->serverFormat.redShift =3D 16; > + server->serverFormat.greenShift =3D 8; > + server->serverFormat.blueShift =3D 0; > + server->kbdAddEvent =3D on_kbd_event; > + server->ptrAddEvent =3D on_ptr_event; > + server->frameBuffer =3D xenfb->pixels; > + server->screenData =3D xenfb; > + server->cursor =3D NULL; > + rfbInitServer(server); > + > + rfbRunEventLoop(server, -1, true); > + > + xenstore_write_vncport(server->port, domid); > + > + for (;;) { > + FD_ZERO(&readfds); > + nfds =3D xenfb_select_fds(xenfb, &readfds); > + > + if (select(nfds, &readfds, NULL, NULL, NULL) < 0) { > + if (errno =3D=3D EINTR) > + continue; > + fprintf(stderr, > + "Can't select() on event channel (%s)\n", > + strerror(errno)); > + break; > + } > + > + xenfb_poll(xenfb, &readfds); > + } > + > + rfbScreenCleanup(server); > + xenfb_delete(xenfb); > + > + return 0; > +} > diff -r 2773c39df9a6 tools/xenfb/xenfb.c > --- /dev/null Thu Jan 01 00:00:00 1970 +0000 > +++ b/tools/xenfb/xenfb.c Thu Nov 30 09:48:37 2006 +0100 > @@ -0,0 +1,691 @@ > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > + > +#include "xenfb.h" > + > +// FIXME defend against malicious frontend? > + > +struct xenfb_device { > + const char *devicetype; > + char nodename[64]; /* backend xenstore dir */ > + char otherend[64]; /* frontend xenstore dir */ > + int otherend_id; /* frontend domid */ > + enum xenbus_state state; /* backend state */ > + void *page; /* shared page */ > + evtchn_port_t port; > + struct xenfb_private *xenfb; > +}; > + > +struct xenfb_private { > + struct xenfb pub; > + int evt_xch; /* event channel driver handle */ > + int xc; /* hypervisor interface handle */ > + struct xs_handle *xsh; /* xs daemon handle */ > + struct xenfb_device fb, kbd; > + size_t fb_len; /* size of framebuffer */ > +}; > + > +static void xenfb_detach_dom(struct xenfb_private *); > + > +static char *xenfb_path_in_dom(struct xs_handle *xsh, > + char *buf, size_t size, > + unsigned domid, const char *fmt, ...) > +{ > + va_list ap; > + char *domp =3D xs_get_domain_path(xsh, domid); > + int n; > + > + if (domp =3D=3D NULL) > + return NULL; > + > + n =3D snprintf(buf, size, "%s/", domp); > + free(domp); > + if (n >=3D size) > + return NULL; > + > + va_start(ap, fmt); > + n +=3D vsnprintf(buf + n, size - n, fmt, ap); > + va_end(ap); > + if (n >=3D size) > + return NULL; > + > + return buf; > +} > + > +static int xenfb_xs_scanf1(struct xs_handle *xsh, > + const char *dir, const char *node, > + const char *fmt, void *dest) > +{ > + char buf[1024]; > + char *p; > + int ret; > + > + if (snprintf(buf, sizeof(buf), "%s/%s", dir, node) >=3D sizeof(buf)) { > + errno =3D ENOENT; > + return -1; > + } > + p =3D xs_read(xsh, XBT_NULL, buf, NULL); > + if (!p) { > + errno =3D ENOENT; > + return -1; > + } > + ret =3D sscanf(p, fmt, dest); > + free(p); > + if (ret !=3D 1) { > + errno =3D EDOM; > + return -1; > + } > + return ret; > +} > + > +static int xenfb_xs_printf(struct xs_handle *xsh, > + const char *dir, const char *node, char *fmt, ...) > +{ > + va_list ap; > + char key[1024]; > + char val[1024]; > + int n; > + > + if (snprintf(key, sizeof(key), "%s/%s", dir, node) >=3D sizeof(key)) { > + errno =3D ENOENT; > + return -1; > + } > + > + va_start(ap, fmt); > + n =3D vsnprintf(val, sizeof(val), fmt, ap); > + va_end(ap); > + if (n >=3D sizeof(val)) { > + errno =3D ENOSPC; /* close enough */ > + return -1; > + } > + > + if (!xs_write(xsh, XBT_NULL, key, val, n)) > + return -1; > + return 0; > +} > + > +static void xenfb_device_init(struct xenfb_device *dev, > + const char *type, > + struct xenfb_private *xenfb) > +{ > + dev->devicetype =3D type; > + dev->otherend_id =3D -1; > + dev->port =3D -1; > + dev->xenfb =3D xenfb; > +} > + > +int xenfb_device_set_domain(struct xenfb_device *dev, int domid) > +{ > + struct xenfb_private *xenfb =3D dev->xenfb; > + > + dev->otherend_id =3D domid; > + > + if (!xenfb_path_in_dom(xenfb->xsh, > + dev->otherend, sizeof(dev->otherend), > + domid, "device/%s/0", dev->devicetype)) { > + errno =3D ENOENT; > + return -1; > + } > + if (!xenfb_path_in_dom(xenfb->xsh, > + dev->nodename, sizeof(dev->nodename), > + 0, "backend/%s/%d/0", dev->devicetype, domid)) { > + errno =3D ENOENT; > + return -1; > + } > + > + return 0; > +} > + > +struct xenfb *xenfb_new(void) > +{ > + struct xenfb_private *xenfb =3D malloc(sizeof(*xenfb)); > + int serrno; > + > + if (xenfb =3D=3D NULL) > + return NULL; > + > + memset(xenfb, 0, sizeof(*xenfb)); > + xenfb->evt_xch =3D xenfb->xc =3D -1; > + xenfb_device_init(&xenfb->fb, "vfb", xenfb); > + xenfb_device_init(&xenfb->kbd, "vkbd", xenfb); > + > + xenfb->evt_xch =3D xc_evtchn_open(); > + if (xenfb->evt_xch =3D=3D -1) > + goto fail; > + > + xenfb->xc =3D xc_interface_open(); > + if (xenfb->xc =3D=3D -1) > + goto fail; > + > + xenfb->xsh =3D xs_daemon_open(); > + if (!xenfb->xsh) > + goto fail; > + > + return &xenfb->pub; > + > + fail: > + serrno =3D errno; > + xenfb_delete(&xenfb->pub); > + errno =3D serrno; > + return NULL; > +} > + > +void xenfb_delete(struct xenfb *xenfb_pub) > +{ > + struct xenfb_private *xenfb =3D (struct xenfb_private *)xenfb_pub; > + > + xenfb_detach_dom(xenfb); > + if (xenfb->xc >=3D 0) > + xc_interface_close(xenfb->xc); > + if (xenfb->evt_xch >=3D 0) > + xc_evtchn_close(xenfb->evt_xch); > + if (xenfb->xsh) > + xs_daemon_close(xenfb->xsh); > + free(xenfb); > +} > + > +static enum xenbus_state xenfb_read_state(struct xs_handle *xsh, > + const char *dir) > +{ > + int ret, state; > + > + ret =3D xenfb_xs_scanf1(xsh, dir, "state", "%d", &state); > + if (ret < 0) > + return XenbusStateUnknown; > + > + if ((unsigned)state > XenbusStateClosed) > + state =3D XenbusStateUnknown; > + return state; > +} > + > +static int xenfb_switch_state(struct xenfb_device *dev, > + enum xenbus_state state) > +{ > + struct xs_handle *xsh =3D dev->xenfb->xsh; > + > + if (xenfb_xs_printf(xsh, dev->nodename, "state", "%d", state) < 0) > + return -1; > + dev->state =3D state; > + return 0; > +} > + > +static int xenfb_wait_for_state(struct xs_handle *xsh, const char *dir, > + unsigned awaited) > +{ > + unsigned state, dummy; > + char **vec; > + > + for (;;) { > + state =3D xenfb_read_state(xsh, dir); > + if (state < 0) > + return -1; > + > + if ((1 << state) & awaited) > + return state; > + > + vec =3D xs_read_watch(xsh, &dummy); > + if (!vec) > + return -1; > + free(vec); > + } > +} > + > +static int xenfb_wait_for_backend_creation(struct xenfb_device *dev) > +{ > + struct xs_handle *xsh =3D dev->xenfb->xsh; > + int state; > + > + if (!xs_watch(xsh, dev->nodename, "")) > + return -1; > + state =3D xenfb_wait_for_state(xsh, dev->nodename, > + (1 << XenbusStateInitialising) > + | (1 << XenbusStateClosed) > +#if 1 /* TODO fudging state to permit restarting; to be removed */ > + | (1 << XenbusStateInitWait) > + | (1 << XenbusStateConnected) > + | (1 << XenbusStateClosing) > +#endif > + ); > + xs_unwatch(xsh, dev->nodename, ""); > + > + switch (state) { > +#if 1 > + case XenbusStateInitWait: > + case XenbusStateConnected: > + printf("Fudging state to %d\n", XenbusStateInitialising); /* FIXME */ > +#endif > + case XenbusStateInitialising: > + case XenbusStateClosing: > + case XenbusStateClosed: > + break; > + default: > + return -1; > + } > + > + return 0; > +} > + > +static int xenfb_hotplug(struct xenfb_device *dev) > +{ > + if (xenfb_xs_printf(dev->xenfb->xsh, dev->nodename, > + "hotplug-status", "connected")) > + return -1; > + return 0; > +} > + > +static int xenfb_wait_for_frontend_initialised(struct xenfb_device *dev) > +{ > + switch (xenfb_wait_for_state(dev->xenfb->xsh, dev->otherend, > +#if 1 /* TODO fudging state to permit restarting; to be removed */ > + (1 << XenbusStateInitialised) > + | (1 << XenbusStateConnected) > +#else > + 1 << XenbusStateInitialised, > +#endif > + )) { > +#if 1 > + case XenbusStateConnected: > + printf("Fudging state to %d\n", XenbusStateInitialised); /* FIXME */ > +#endif > + case XenbusStateInitialised: > + break; > + default: > + return -1; > + } > + > + return 0; > +} > + > +static int xenfb_map_fb(struct xenfb_private *xenfb, int domid) > +{ > + struct xenfb_page *page =3D xenfb->fb.page; > + int n_fbmfns; > + int n_fbdirs; > + unsigned long *fbmfns; > + > + n_fbmfns =3D (xenfb->fb_len + (XC_PAGE_SIZE - 1)) / XC_PAGE_SIZE; > + n_fbdirs =3D n_fbmfns * sizeof(unsigned long); > + n_fbdirs =3D (n_fbdirs + (XC_PAGE_SIZE - 1)) / XC_PAGE_SIZE; > + > + /* > + * Bug alert: xc_map_foreign_batch() can fail partly and > + * return a non-null value. This is a design flaw. When it > + * happens, we happily continue here, and later crash on > + * access. > + */ > + fbmfns =3D xc_map_foreign_batch(xenfb->xc, domid, > + PROT_READ, page->pd, n_fbdirs); > + if (fbmfns =3D=3D NULL) > + return -1; > + > + xenfb->pub.pixels =3D xc_map_foreign_batch(xenfb->xc, domid, > + PROT_READ | PROT_WRITE, fbmfns, n_fbmfns); > + if (xenfb->pub.pixels =3D=3D NULL) { > + munmap(fbmfns, n_fbdirs * XC_PAGE_SIZE); > + return -1; > + } > + > + return munmap(fbmfns, n_fbdirs * XC_PAGE_SIZE); > +} > + > +static int xenfb_bind(struct xenfb_device *dev) > +{ > + struct xenfb_private *xenfb =3D dev->xenfb; > + unsigned long mfn; > + evtchn_port_t evtchn; > + > + if (xenfb_xs_scanf1(xenfb->xsh, dev->otherend, "page-ref", "%lu", > + &mfn) < 0) > + return -1; > + if (xenfb_xs_scanf1(xenfb->xsh, dev->otherend, "event-channel", "%u", > + &evtchn) < 0) > + return -1; > + > + dev->port =3D xc_evtchn_bind_interdomain(xenfb->evt_xch, > + dev->otherend_id, evtchn); > + if (dev->port =3D=3D -1) > + return -1; > + > + dev->page =3D xc_map_foreign_range(xenfb->xc, dev->otherend_id, > + XC_PAGE_SIZE, PROT_READ | PROT_WRITE, mfn); > + if (dev->page =3D=3D NULL) > + return -1; > + > + return 0; > +} > + > +static void xenfb_unbind(struct xenfb_device *dev) > +{ > + if (dev->page) { > + munmap(dev->page, XC_PAGE_SIZE); > + dev->page =3D NULL; > + } > + if (dev->port >=3D 0) { > + xc_evtchn_unbind(dev->xenfb->evt_xch, dev->port); > + dev->port =3D -1; > + } > +} > + > +static int xenfb_wait_for_frontend_connected(struct xenfb_device *dev) > +{ > + switch (xenfb_wait_for_state(dev->xenfb->xsh, dev->otherend, > + 1 << XenbusStateConnected)) { > + case XenbusStateConnected: > + break; > + default: > + return -1; > + } > + > + return 0; > +} > + > +static void xenfb_dev_fatal(struct xenfb_device *dev, int err, > + const char *fmt, ...) > +{ > + struct xs_handle *xsh =3D dev->xenfb->xsh; > + va_list ap; > + char errdir[80]; > + char buf[1024]; > + int n; > + > + fprintf(stderr, "%s ", dev->nodename); /* somewhat crude */ > + va_start(ap, fmt); > + vfprintf(stderr, fmt, ap); > + va_end(ap); > + if (err) > + fprintf(stderr, " (%s)", strerror(err)); > + putc('\n', stderr); > + > + if (!xenfb_path_in_dom(xsh, errdir, sizeof(errdir), 0, > + "error/%s", dev->nodename)) > + goto out; /* FIXME complain */ > + > + va_start(ap, fmt); > + n =3D snprintf(buf, sizeof(buf), "%d ", err); > + snprintf(buf + n, sizeof(buf) - n, fmt, ap); > + va_end(ap); > + > + if (xenfb_xs_printf(xsh, buf, "error", "%s", buf) < 0) > + goto out; /* FIXME complain */ > + > + out: > + xenfb_switch_state(dev, XenbusStateClosing); > +} > + > +int xenfb_attach_dom(struct xenfb *xenfb_pub, int domid) > +{ > + struct xenfb_private *xenfb =3D (struct xenfb_private *)xenfb_pub; > + struct xs_handle *xsh =3D xenfb->xsh; > + int val, serrno; > + struct xenfb_page *fb_page; > + > + xenfb_detach_dom(xenfb); > + > + xenfb_device_set_domain(&xenfb->fb, domid); > + xenfb_device_set_domain(&xenfb->kbd, domid); > + > + if (xenfb_wait_for_backend_creation(&xenfb->fb) < 0) > + goto error; > + if (xenfb_wait_for_backend_creation(&xenfb->kbd) < 0) > + goto error; > + > + if (xenfb_xs_printf(xsh, xenfb->kbd.nodename, "feature-abs-pointer", "1= ")) > + goto error; > + if (xenfb_switch_state(&xenfb->fb, XenbusStateInitWait)) > + goto error; > + if (xenfb_switch_state(&xenfb->kbd, XenbusStateInitWait)) > + goto error; > + > + if (xenfb_hotplug(&xenfb->fb) < 0) > + goto error; > + if (xenfb_hotplug(&xenfb->kbd) < 0) > + goto error; > + > + if (!xs_watch(xsh, xenfb->fb.otherend, "")) > + goto error; > + if (!xs_watch(xsh, xenfb->kbd.otherend, "")) > + goto error; > + > + if (xenfb_wait_for_frontend_initialised(&xenfb->fb) < 0) > + goto error; > + if (xenfb_wait_for_frontend_initialised(&xenfb->kbd) < 0) > + goto error; > + > + if (xenfb_bind(&xenfb->fb) < 0) > + goto error; > + if (xenfb_bind(&xenfb->kbd) < 0) > + goto error; > + > + if (xenfb_xs_scanf1(xsh, xenfb->fb.otherend, "feature-update", > + "%d", &val) < 0) > + val =3D 0; > + if (!val) { > + errno =3D ENOTSUP; > + goto error; > + } > + xenfb_xs_printf(xsh, xenfb->fb.nodename, "request-update", "1"); > + > + /* TODO check for permitted ranges */ > + fb_page =3D xenfb->fb.page; > + xenfb->pub.depth =3D fb_page->depth; > + xenfb->pub.width =3D fb_page->width; > + xenfb->pub.height =3D fb_page->height; > + /* TODO check for consistency with the above */ > + xenfb->fb_len =3D fb_page->mem_length; > + xenfb->pub.row_stride =3D fb_page->line_length; > + > + if (xenfb_map_fb(xenfb, domid) < 0) > + goto error; > + > + if (xenfb_switch_state(&xenfb->fb, XenbusStateConnected)) > + goto error; > + if (xenfb_switch_state(&xenfb->kbd, XenbusStateConnected)) > + goto error; > + > + if (xenfb_wait_for_frontend_connected(&xenfb->kbd) < 0) > + goto error; > + if (xenfb_xs_scanf1(xsh, xenfb->kbd.otherend, "request-abs-pointer", > + "%d", &val) < 0) > + val =3D 0; > + xenfb->pub.abs_pointer_wanted =3D val; > + > + return 0; > + > + error: > + serrno =3D errno; > + xenfb_detach_dom(xenfb); > + xenfb_dev_fatal(&xenfb->fb, serrno, "on fire"); > + xenfb_dev_fatal(&xenfb->kbd, serrno, "on fire"); > + errno =3D serrno; > + return -1; > +} > + > +static void xenfb_detach_dom(struct xenfb_private *xenfb) > +{ > + xenfb_unbind(&xenfb->fb); > + xenfb_unbind(&xenfb->kbd); > + if (xenfb->pub.pixels) { > + munmap(xenfb->pub.pixels, xenfb->fb_len); > + xenfb->pub.pixels =3D NULL; > + } > +} > + > +static void xenfb_on_fb_event(struct xenfb_private *xenfb) > +{ > + uint32_t prod, cons; > + struct xenfb_page *page =3D xenfb->fb.page; > + > + prod =3D page->out_prod; > + if (prod =3D=3D page->out_cons) > + return; > + rmb(); /* ensure we see ring contents up to prod */ > + for (cons =3D page->out_cons; cons !=3D prod; cons++) { > + union xenfb_out_event *event =3D &XENFB_OUT_RING_REF(page, cons); > + > + switch (event->type) { > + case XENFB_TYPE_UPDATE: > + if (xenfb->pub.update) > + xenfb->pub.update(&xenfb->pub, > + event->update.x, event->update.y, > + event->update.width, event->update.height); > + break; > + } > + } > + mb(); /* ensure we're done with ring contents */ > + page->out_cons =3D cons; > + xc_evtchn_notify(xenfb->evt_xch, xenfb->fb.port); > +} > + > +static void xenfb_on_kbd_event(struct xenfb_private *xenfb) > +{ > + struct xenkbd_page *page =3D xenfb->kbd.page; > + > + /* We don't understand any keyboard events, so just ignore them. */ > + if (page->out_prod =3D=3D page->out_cons) > + return; > + page->out_cons =3D page->out_prod; > + xc_evtchn_notify(xenfb->evt_xch, xenfb->kbd.port); > +} > + > +static void xenfb_on_state_change(struct xenfb_device *dev) > +{ > + enum xenbus_state state; > + > + state =3D xenfb_read_state(dev->xenfb->xsh, dev->otherend); > + > + switch (state) { > + case XenbusStateUnknown: > + case XenbusStateInitialising: > + case XenbusStateInitWait: > + case XenbusStateInitialised: > + case XenbusStateConnected: > + break; > + case XenbusStateClosing: > + xenfb_unbind(dev); > + xenfb_switch_state(dev, state); > + break; > + case XenbusStateClosed: > + xs_unwatch(dev->xenfb->xsh, dev->otherend, ""); > + xenfb_switch_state(dev, state); > + } > +} > + > +int xenfb_poll(struct xenfb *xenfb_pub, fd_set *readfds) > +{ > + struct xenfb_private *xenfb =3D (struct xenfb_private *)xenfb_pub; > + evtchn_port_t port; > + unsigned dummy; > + char **vec; > + > + if (FD_ISSET(xc_evtchn_fd(xenfb->evt_xch), readfds)) { > + port =3D xc_evtchn_pending(xenfb->evt_xch); > + if (port =3D=3D -1) > + return -1; > + > + if (port =3D=3D xenfb->fb.port) > + xenfb_on_fb_event(xenfb); > + else if (port =3D=3D xenfb->kbd.port) > + xenfb_on_kbd_event(xenfb); > + > + if (xc_evtchn_unmask(xenfb->evt_xch, port) =3D=3D -1) > + return -1; > + } > + > + if (FD_ISSET(xs_fileno(xenfb->xsh), readfds)) { > + vec =3D xs_read_watch(xenfb->xsh, &dummy); > + free(vec); > + xenfb_on_state_change(&xenfb->fb); > + xenfb_on_state_change(&xenfb->kbd); > + } > + > + return 0; > +} > + > +int xenfb_select_fds(struct xenfb *xenfb_pub, fd_set *readfds) > +{ > + struct xenfb_private *xenfb =3D (struct xenfb_private *)xenfb_pub; > + int fd1 =3D xc_evtchn_fd(xenfb->evt_xch); > + int fd2 =3D xs_fileno(xenfb->xsh); > + > + FD_SET(fd1, readfds); > + FD_SET(fd2, readfds); > + return fd1 > fd2 ? fd1 + 1 : fd2 + 1; > +} > + > +static int xenfb_kbd_event(struct xenfb_private *xenfb, > + union xenkbd_in_event *event) > +{ > + uint32_t prod; > + struct xenkbd_page *page =3D xenfb->kbd.page; > + > + if (xenfb->kbd.state !=3D XenbusStateConnected) > + return 0; > + > + prod =3D page->in_prod; > + if (prod - page->in_cons =3D=3D XENKBD_IN_RING_LEN) { > + errno =3D EAGAIN; > + return -1; > + } > + > + mb(); /* ensure ring space available */ > + XENKBD_IN_RING_REF(page, prod) =3D *event; > + wmb(); /* ensure ring contents visible */ > + page->in_prod =3D prod + 1; > + return xc_evtchn_notify(xenfb->evt_xch, xenfb->kbd.port); > +} > + > +int xenfb_send_key(struct xenfb *xenfb_pub, bool down, int keycode) > +{ > + struct xenfb_private *xenfb =3D (struct xenfb_private *)xenfb_pub; > + union xenkbd_in_event event; > + > + memset(&event, 0, XENKBD_IN_EVENT_SIZE); > + event.type =3D XENKBD_TYPE_KEY; > + event.key.pressed =3D down ? 1 : 0; > + event.key.keycode =3D keycode; > + > + return xenfb_kbd_event(xenfb, &event); > +} > + > +int xenfb_send_motion(struct xenfb *xenfb_pub, int rel_x, int rel_y) > +{ > + struct xenfb_private *xenfb =3D (struct xenfb_private *)xenfb_pub; > + union xenkbd_in_event event; > + > + memset(&event, 0, XENKBD_IN_EVENT_SIZE); > + event.type =3D XENKBD_TYPE_MOTION; > + event.motion.rel_x =3D rel_x; > + event.motion.rel_y =3D rel_y; > + > + return xenfb_kbd_event(xenfb, &event); > +} > + > +int xenfb_send_position(struct xenfb *xenfb_pub, int abs_x, int abs_y) > +{ > + struct xenfb_private *xenfb =3D (struct xenfb_private *)xenfb_pub; > + union xenkbd_in_event event; > + > + memset(&event, 0, XENKBD_IN_EVENT_SIZE); > + event.type =3D XENKBD_TYPE_POS; > + event.pos.abs_x =3D abs_x; > + event.pos.abs_y =3D abs_y; > + > + return xenfb_kbd_event(xenfb, &event); > +} > diff -r 2773c39df9a6 tools/xenfb/xenfb.h > --- /dev/null Thu Jan 01 00:00:00 1970 +0000 > +++ b/tools/xenfb/xenfb.h Thu Nov 23 11:32:28 2006 +0100 > @@ -0,0 +1,34 @@ > +#ifndef _XENFB_H_ > +#define _XENFB_H_ > + > +#include > +#include > + > +struct xenfb > +{ > + void *pixels; > + > + int row_stride; > + int depth; > + int width; > + int height; > + int abs_pointer_wanted; > + > + void *user_data; > + > + void (*update)(struct xenfb *xenfb, int x, int y, int width, int height= ); > +}; > + > +struct xenfb *xenfb_new(void); > +void xenfb_delete(struct xenfb *xenfb); > + > +int xenfb_attach_dom(struct xenfb *xenfb, int domid); > + > +int xenfb_select_fds(struct xenfb *xenfb, fd_set *readfds); > +int xenfb_poll(struct xenfb *xenfb, fd_set *readfds); > + > +int xenfb_send_key(struct xenfb *xenfb, bool down, int keycode); > +int xenfb_send_motion(struct xenfb *xenfb, int rel_x, int rel_y); > +int xenfb_send_position(struct xenfb *xenfb, int abs_x, int abs_y); > + > +#endif > diff -r 2773c39df9a6 xen/include/public/io/fbif.h > --- /dev/null Thu Jan 01 00:00:00 1970 +0000 > +++ b/xen/include/public/io/fbif.h Wed Nov 29 17:34:09 2006 +0100 > @@ -0,0 +1,116 @@ > +/* > + * fbif.h -- Xen virtual frame buffer device > + * > + * Copyright (C) 2005 Anthony Liguori > + * Copyright (C) 2006 Red Hat, Inc., Markus Armbruster > + * > + * This file is subject to the terms and conditions of the GNU General = Public > + * License. See the file COPYING in the main directory of this archive = for > + * more details. > + */ > + > +#ifndef __XEN_PUBLIC_IO_FBIF_H__ > +#define __XEN_PUBLIC_IO_FBIF_H__ > + > +#include > + > +/* Out events (frontend -> backend) */ > + > +/* > + * Out events may be sent only when requested by backend, and receipt > + * of an unknown out event is an error. > + */ > + > +/* Event type 1 currently not used */ > +/* > + * Framebuffer update notification event > + * Capable frontend sets feature-update in xenstore. > + * Backend requests it by setting request-update in xenstore. > + */ > +#define XENFB_TYPE_UPDATE 2 > + > +struct xenfb_update > +{ > + __u8 type; /* XENFB_TYPE_UPDATE */ > + __s32 x; /* source x */ > + __s32 y; /* source y */ > + __s32 width; /* rect width */ > + __s32 height; /* rect height */ > +}; > + > +#define XENFB_OUT_EVENT_SIZE 40 > + > +union xenfb_out_event > +{ > + __u8 type; > + struct xenfb_update update; > + char pad[XENFB_OUT_EVENT_SIZE]; > +}; > + > +/* In events (backend -> frontend) */ > + > +/* > + * Frontends should ignore unknown in events. > + * No in events currently defined. > + */ > + > +#define XENFB_IN_EVENT_SIZE 40 > + > +union xenfb_in_event > +{ > + __u8 type; > + char pad[XENFB_IN_EVENT_SIZE]; > +}; > + > +/* shared page */ > + > +#define XENFB_IN_RING_SIZE 1024 > +#define XENFB_IN_RING_LEN (XENFB_IN_RING_SIZE / XENFB_IN_EVENT_SIZE) > +#define XENFB_IN_RING_OFFS 1024 > +#define XENFB_IN_RING(page) \ > + ((union xenfb_in_event *)((char *)(page) + XENFB_IN_RING_OFFS)) > +#define XENFB_IN_RING_REF(page, idx) \ > + (XENFB_IN_RING((page))[(idx) % XENFB_IN_RING_LEN]) > + > +#define XENFB_OUT_RING_SIZE 2048 > +#define XENFB_OUT_RING_LEN (XENFB_OUT_RING_SIZE / XENFB_OUT_EVENT_SIZE) > +#define XENFB_OUT_RING_OFFS (XENFB_IN_RING_OFFS + XENFB_IN_RING_SIZE) > +#define XENFB_OUT_RING(page) \ > + ((union xenfb_out_event *)((char *)(page) + XENFB_OUT_RING_OFFS)) > +#define XENFB_OUT_RING_REF(page, idx) \ > + (XENFB_OUT_RING((page))[(idx) % XENFB_OUT_RING_LEN]) > + > +struct xenfb_page > +{ > + __u32 in_cons, in_prod; > + __u32 out_cons, out_prod; > + > + __s32 width; /* the width of the framebuffer (in pixels) */ > + __s32 height; /* the height of the framebuffer (in pixels) */ > + __u32 line_length; /* the length of a row of pixels (in bytes) */ > + __u32 mem_length; /* the length of the framebuffer (in bytes) */ > + __u8 depth; /* the depth of a pixel (in bits) */ > + > + /* > + * Framebuffer page directory > + * > + * Each directory page holds PAGE_SIZE / sizeof(*pd) > + * framebuffer pages, and can thus map up to PAGE_SIZE * > + * PAGE_SIZE / sizeof(*pd) bytes. With PAGE_SIZE =3D=3D 4096 and > + * sizeof(unsigned long) =3D=3D 4, that's 4 Megs. Two directory > + * pages should be enough for a while. > + */ > + unsigned long pd[2]; > +}; > + > +/* > + * Wart: xenkbd needs to know resolution. Put it here until a better > + * solution is found, but don't leak it to the backend. > + */ > +#ifdef __KERNEL__ > +#define XENFB_WIDTH 800 > +#define XENFB_HEIGHT 600 > +#define XENFB_DEPTH 32 > +#endif > + > +#endif > diff -r 2773c39df9a6 xen/include/public/io/kbdif.h > --- /dev/null Thu Jan 01 00:00:00 1970 +0000 > +++ b/xen/include/public/io/kbdif.h Wed Nov 29 17:35:42 2006 +0100 > @@ -0,0 +1,108 @@ > +/* > + * kbdif.h -- Xen virtual keyboard/mouse > + * > + * Copyright (C) 2005 Anthony Liguori > + * Copyright (C) 2006 Red Hat, Inc., Markus Armbruster > + * > + * This file is subject to the terms and conditions of the GNU General = Public > + * License. See the file COPYING in the main directory of this archive = for > + * more details. > + */ > + > +#ifndef __XEN_PUBLIC_IO_KBDIF_H__ > +#define __XEN_PUBLIC_IO_KBDIF_H__ > + > +#include > + > +/* In events (backend -> frontend) */ > + > +/* > + * Frontends should ignore unknown in events. > + */ > + > +/* Pointer movement event */ > +#define XENKBD_TYPE_MOTION 1 > +/* Event type 2 currently not used */ > +/* Key event (includes pointer buttons) */ > +#define XENKBD_TYPE_KEY 3 > +/* > + * Pointer position event > + * Capable backend sets feature-abs-pointer in xenstore. > + * Frontend requests ot instead of XENKBD_TYPE_MOTION by setting > + * request-abs-update in xenstore. > + */ > +#define XENKBD_TYPE_POS 4 > + > +struct xenkbd_motion > +{ > + __u8 type; /* XENKBD_TYPE_MOTION */ > + __s32 rel_x; /* relative X motion */ > + __s32 rel_y; /* relative Y motion */ > +}; > + > +struct xenkbd_key > +{ > + __u8 type; /* XENKBD_TYPE_KEY */ > + __u8 pressed; /* 1 if pressed; 0 otherwise */ > + __u32 keycode; /* KEY_* from linux/input.h */ > +}; > + > +struct xenkbd_position > +{ > + __u8 type; /* XENKBD_TYPE_POS */ > + __s32 abs_x; /* absolute X position (in FB pixels) */ > + __s32 abs_y; /* absolute Y position (in FB pixels) */ > +}; > + > +#define XENKBD_IN_EVENT_SIZE 40 > + > +union xenkbd_in_event > +{ > + __u8 type; > + struct xenkbd_motion motion; > + struct xenkbd_key key; > + struct xenkbd_position pos; > + char pad[XENKBD_IN_EVENT_SIZE]; > +}; > + > +/* Out events (frontend -> backend) */ > + > +/* > + * Out events may be sent only when requested by backend, and receipt > + * of an unknown out event is an error. > + * No out events currently defined. > + */ > + > +#define XENKBD_OUT_EVENT_SIZE 40 > + > +union xenkbd_out_event > +{ > + __u8 type; > + char pad[XENKBD_OUT_EVENT_SIZE]; > +}; > + > +/* shared page */ > + > +#define XENKBD_IN_RING_SIZE 2048 > +#define XENKBD_IN_RING_LEN (XENKBD_IN_RING_SIZE / XENKBD_IN_EVENT_SIZE) > +#define XENKBD_IN_RING_OFFS 1024 > +#define XENKBD_IN_RING(page) \ > + ((union xenkbd_in_event *)((char *)(page) + XENKBD_IN_RING_OFFS)) > +#define XENKBD_IN_RING_REF(page, idx) \ > + (XENKBD_IN_RING((page))[(idx) % XENKBD_IN_RING_LEN]) > + > +#define XENKBD_OUT_RING_SIZE 1024 > +#define XENKBD_OUT_RING_LEN (XENKBD_OUT_RING_SIZE / XENKBD_OUT_EVENT_SIZ= E) > +#define XENKBD_OUT_RING_OFFS (XENKBD_IN_RING_OFFS + XENKBD_IN_RING_SIZE) > +#define XENKBD_OUT_RING(page) \ > + ((union xenkbd_out_event *)((char *)(page) + XENKBD_OUT_RING_OFFS)) > +#define XENKBD_OUT_RING_REF(page, idx) \ > + (XENKBD_OUT_RING((page))[(idx) % XENKBD_OUT_RING_LEN]) > + > +struct xenkbd_page > +{ > + __u32 in_cons, in_prod; > + __u32 out_cons, out_prod; > +}; > + > +#endif > diff -r 2773c39df9a6 linux-2.6-xen-sparse/drivers/char/tty_io.c > --- a/linux-2.6-xen-sparse/drivers/char/tty_io.c Wed Nov 29 12:16:19 2006= +0000 > +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 > @@ -1,3264 +0,0 @@ > -/* > - * linux/drivers/char/tty_io.c > - * > - * Copyright (C) 1991, 1992 Linus Torvalds > - */ > - > -/* > - * 'tty_io.c' gives an orthogonal feeling to tty's, be they consoles > - * or rs-channels. It also implements echoing, cooked mode etc. > - * > - * Kill-line thanks to John T Kohl, who also corrected VMIN =3D VTIME = =3D 0. > - * > - * Modified by Theodore Ts'o, 9/14/92, to dynamically allocate the > - * tty_struct and tty_queue structures. Previously there was an array > - * of 256 tty_struct's which was statically allocated, and the > - * tty_queue structures were allocated at boot time. Both are now > - * dynamically allocated only when the tty is open. > - * > - * Also restructured routines so that there is more of a separation > - * between the high-level tty routines (tty_io.c and tty_ioctl.c) and > - * the low-level tty routines (serial.c, pty.c, console.c). This > - * makes for cleaner and more compact code. -TYT, 9/17/92=20 > - * > - * Modified by Fred N. van Kempen, 01/29/93, to add line disciplines > - * which can be dynamically activated and de-activated by the line > - * discipline handling modules (like SLIP). > - * > - * NOTE: pay no attention to the line discipline code (yet); its > - * interface is still subject to change in this version... > - * -- TYT, 1/31/92 > - * > - * Added functionality to the OPOST tty handling. No delays, but all > - * other bits should be there. > - * -- Nick Holloway , 27th May 1993. > - * > - * Rewrote canonical mode and added more termios flags. > - * -- julian@uhunix.uhcc.hawaii.edu (J. Cowley), 13Jan94 > - * > - * Reorganized FASYNC support so mouse code can share it. > - * -- ctm@ardi.com, 9Sep95 > - * > - * New TIOCLINUX variants added. > - * -- mj@k332.feld.cvut.cz, 19-Nov-95 > - *=20 > - * Restrict vt switching via ioctl() > - * -- grif@cs.ucr.edu, 5-Dec-95 > - * > - * Move console and virtual terminal code to more appropriate files, > - * implement CONFIG_VT and generalize console device interface. > - * -- Marko Kohtala , March 97 > - * > - * Rewrote init_dev and release_dev to eliminate races. > - * -- Bill Hawes , June 97 > - * > - * Added devfs support. > - * -- C. Scott Ananian , 13-Jan-1998 > - * > - * Added support for a Unix98-style ptmx device. > - * -- C. Scott Ananian , 14-Jan-1998 > - * > - * Reduced memory usage for older ARM systems > - * -- Russell King > - * > - * Move do_SAK() into process context. Less stack use in devfs function= s. > - * alloc_tty_struct() always uses kmalloc() -- Andrew Morton 17Mar01 > - */ > - > -#include > -#include > -#include > -#include > -#include > -#include > -#include > -#include > -#include > -#include > -#include > -#include > -#include > -#include > -#include > -#include > -#include > -#include > -#include > -#include > -#include > -#include > -#include > -#include > -#include > -#include > -#include > -#include > -#include > -#include > - > -#include > -#include > - > -#include > -#include > -#include > -#include > - > -#include > - > -#undef TTY_DEBUG_HANGUP > - > -#define TTY_PARANOIA_CHECK 1 > -#define CHECK_TTY_COUNT 1 > - > -struct termios tty_std_termios =3D { /* for the benefit of tty drivers = */ > - .c_iflag =3D ICRNL | IXON, > - .c_oflag =3D OPOST | ONLCR, > - .c_cflag =3D B38400 | CS8 | CREAD | HUPCL, > - .c_lflag =3D ISIG | ICANON | ECHO | ECHOE | ECHOK | > - ECHOCTL | ECHOKE | IEXTEN, > - .c_cc =3D INIT_C_CC > -}; > - > -EXPORT_SYMBOL(tty_std_termios); > - > -/* This list gets poked at by procfs and various bits of boot up code. T= his > - could do with some rationalisation such as pulling the tty proc funct= ion > - into this file */ > - =20 > -LIST_HEAD(tty_drivers); /* linked list of tty drivers */ > - > -/* Semaphore to protect creating and releasing a tty. This is shared with > - vt.c for deeply disgusting hack reasons */ > -DECLARE_MUTEX(tty_sem); > - > -int console_use_vt =3D 1; > - > -#ifdef CONFIG_UNIX98_PTYS > -extern struct tty_driver *ptm_driver; /* Unix98 pty masters; for /dev/pt= mx */ > -extern int pty_limit; /* Config limit on Unix98 ptys */ > -static DEFINE_IDR(allocated_ptys); > -static DECLARE_MUTEX(allocated_ptys_lock); > -static int ptmx_open(struct inode *, struct file *); > -#endif > - > -extern void disable_early_printk(void); > - > -static void initialize_tty_struct(struct tty_struct *tty); > - > -static ssize_t tty_read(struct file *, char __user *, size_t, loff_t *); > -static ssize_t tty_write(struct file *, const char __user *, size_t, lof= f_t *); > -ssize_t redirected_tty_write(struct file *, const char __user *, size_t,= loff_t *); > -static unsigned int tty_poll(struct file *, poll_table *); > -static int tty_open(struct inode *, struct file *); > -static int tty_release(struct inode *, struct file *); > -int tty_ioctl(struct inode * inode, struct file * file, > - unsigned int cmd, unsigned long arg); > -static int tty_fasync(int fd, struct file * filp, int on); > -static void release_mem(struct tty_struct *tty, int idx); > - > - > -static struct tty_struct *alloc_tty_struct(void) > -{ > - struct tty_struct *tty; > - > - tty =3D kmalloc(sizeof(struct tty_struct), GFP_KERNEL); > - if (tty) > - memset(tty, 0, sizeof(struct tty_struct)); > - return tty; > -} > - > -static void tty_buffer_free_all(struct tty_struct *); > - > -static inline void free_tty_struct(struct tty_struct *tty) > -{ > - kfree(tty->write_buf); > - tty_buffer_free_all(tty); > - kfree(tty); > -} > - > -#define TTY_NUMBER(tty) ((tty)->index + (tty)->driver->name_base) > - > -char *tty_name(struct tty_struct *tty, char *buf) > -{ > - if (!tty) /* Hmm. NULL pointer. That's fun. */ > - strcpy(buf, "NULL tty"); > - else > - strcpy(buf, tty->name); > - return buf; > -} > - > -EXPORT_SYMBOL(tty_name); > - > -int tty_paranoia_check(struct tty_struct *tty, struct inode *inode, > - const char *routine) > -{ > -#ifdef TTY_PARANOIA_CHECK > - if (!tty) { > - printk(KERN_WARNING > - "null TTY for (%d:%d) in %s\n", > - imajor(inode), iminor(inode), routine); > - return 1; > - } > - if (tty->magic !=3D TTY_MAGIC) { > - printk(KERN_WARNING > - "bad magic number for tty struct (%d:%d) in %s\n", > - imajor(inode), iminor(inode), routine); > - return 1; > - } > -#endif > - return 0; > -} > - > -static int check_tty_count(struct tty_struct *tty, const char *routine) > -{ > -#ifdef CHECK_TTY_COUNT > - struct list_head *p; > - int count =3D 0; > -=09 > - file_list_lock(); > - list_for_each(p, &tty->tty_files) { > - count++; > - } > - file_list_unlock(); > - if (tty->driver->type =3D=3D TTY_DRIVER_TYPE_PTY && > - tty->driver->subtype =3D=3D PTY_TYPE_SLAVE && > - tty->link && tty->link->count) > - count++; > - if (tty->count !=3D count) { > - printk(KERN_WARNING "Warning: dev (%s) tty->count(%d) " > - "!=3D #fd's(%d) in %s\n", > - tty->name, tty->count, count, routine); > - return count; > - }=09 > -#endif > - return 0; > -} > - > -/* > - * Tty buffer allocation management > - */ > - > -static void tty_buffer_free_all(struct tty_struct *tty) > -{ > - struct tty_buffer *thead; > - while((thead =3D tty->buf.head) !=3D NULL) { > - tty->buf.head =3D thead->next; > - kfree(thead); > - } > - while((thead =3D tty->buf.free) !=3D NULL) { > - tty->buf.free =3D thead->next; > - kfree(thead); > - } > - tty->buf.tail =3D NULL; > -} > - > -static void tty_buffer_init(struct tty_struct *tty) > -{ > - spin_lock_init(&tty->buf.lock); > - tty->buf.head =3D NULL; > - tty->buf.tail =3D NULL; > - tty->buf.free =3D NULL; > -} > - > -static struct tty_buffer *tty_buffer_alloc(size_t size) > -{ > - struct tty_buffer *p =3D kmalloc(sizeof(struct tty_buffer) + 2 * size, = GFP_ATOMIC); > - if(p =3D=3D NULL) > - return NULL; > - p->used =3D 0; > - p->size =3D size; > - p->next =3D NULL; > - p->active =3D 0; > - p->commit =3D 0; > - p->read =3D 0; > - p->char_buf_ptr =3D (char *)(p->data); > - p->flag_buf_ptr =3D (unsigned char *)p->char_buf_ptr + size; > -/* printk("Flip create %p\n", p); */ > - return p; > -} > - > -/* Must be called with the tty_read lock held. This needs to acquire str= ategy > - code to decide if we should kfree or relink a given expired buffer */ > - > -static void tty_buffer_free(struct tty_struct *tty, struct tty_buffer *b) > -{ > - /* Dumb strategy for now - should keep some stats */ > -/* printk("Flip dispose %p\n", b); */ > - if(b->size >=3D 512) > - kfree(b); > - else { > - b->next =3D tty->buf.free; > - tty->buf.free =3D b; > - } > -} > - > -static struct tty_buffer *tty_buffer_find(struct tty_struct *tty, size_t= size) > -{ > - struct tty_buffer **tbh =3D &tty->buf.free; > - while((*tbh) !=3D NULL) { > - struct tty_buffer *t =3D *tbh; > - if(t->size >=3D size) { > - *tbh =3D t->next; > - t->next =3D NULL; > - t->used =3D 0; > - t->commit =3D 0; > - t->read =3D 0; > - /* DEBUG ONLY */ > -/* memset(t->data, '*', size); */ > -/* printk("Flip recycle %p\n", t); */ > - return t; > - } > - tbh =3D &((*tbh)->next); > - } > - /* Round the buffer size out */ > - size =3D (size + 0xFF) & ~ 0xFF; > - return tty_buffer_alloc(size); > - /* Should possibly check if this fails for the largest buffer we > - have queued and recycle that ? */ > -} > - > -int tty_buffer_request_room(struct tty_struct *tty, size_t size) > -{ > - struct tty_buffer *b, *n; > - int left; > - unsigned long flags; > - > - spin_lock_irqsave(&tty->buf.lock, flags); > - > - /* OPTIMISATION: We could keep a per tty "zero" sized buffer to > - remove this conditional if its worth it. This would be invisible > - to the callers */ > - if ((b =3D tty->buf.tail) !=3D NULL) { > - left =3D b->size - b->used; > - b->active =3D 1; > - } else > - left =3D 0; > - > - if (left < size) { > - /* This is the slow path - looking for new buffers to use */ > - if ((n =3D tty_buffer_find(tty, size)) !=3D NULL) { > - if (b !=3D NULL) { > - b->next =3D n; > - b->active =3D 0; > - b->commit =3D b->used; > - } else > - tty->buf.head =3D n; > - tty->buf.tail =3D n; > - n->active =3D 1; > - } else > - size =3D left; > - } > - > - spin_unlock_irqrestore(&tty->buf.lock, flags); > - return size; > -} > - > -EXPORT_SYMBOL_GPL(tty_buffer_request_room); > - > -int tty_insert_flip_string(struct tty_struct *tty, unsigned char *chars,= size_t size) > -{ > - int copied =3D 0; > - do { > - int space =3D tty_buffer_request_room(tty, size - copied); > - struct tty_buffer *tb =3D tty->buf.tail; > - /* If there is no space then tb may be NULL */ > - if(unlikely(space =3D=3D 0)) > - break; > - memcpy(tb->char_buf_ptr + tb->used, chars, space); > - memset(tb->flag_buf_ptr + tb->used, TTY_NORMAL, space); > - tb->used +=3D space; > - copied +=3D space; > - chars +=3D space; > -/* printk("Flip insert %d.\n", space); */ > - } > - /* There is a small chance that we need to split the data over > - several buffers. If this is the case we must loop */ > - while (unlikely(size > copied)); > - return copied; > -} > - > -EXPORT_SYMBOL_GPL(tty_insert_flip_string); > - > -int tty_insert_flip_string_flags(struct tty_struct *tty, unsigned char *= chars, char *flags, size_t size) > -{ > - int copied =3D 0; > - do { > - int space =3D tty_buffer_request_room(tty, size - copied); > - struct tty_buffer *tb =3D tty->buf.tail; > - /* If there is no space then tb may be NULL */ > - if(unlikely(space =3D=3D 0)) > - break; > - memcpy(tb->char_buf_ptr + tb->used, chars, space); > - memcpy(tb->flag_buf_ptr + tb->used, flags, space); > - tb->used +=3D space; > - copied +=3D space; > - chars +=3D space; > - flags +=3D space; > - } > - /* There is a small chance that we need to split the data over > - several buffers. If this is the case we must loop */ > - while (unlikely(size > copied)); > - return copied; > -} > - > -EXPORT_SYMBOL_GPL(tty_insert_flip_string_flags); > - > - > -/* > - * Prepare a block of space in the buffer for data. Returns the length > - * available and buffer pointer to the space which is now allocated and > - * accounted for as ready for normal characters. This is used for drivers > - * that need their own block copy routines into the buffer. There is no > - * guarantee the buffer is a DMA target! > - */ > - > -int tty_prepare_flip_string(struct tty_struct *tty, unsigned char **char= s, size_t size) > -{ > - int space =3D tty_buffer_request_room(tty, size); > - if (likely(space)) { > - struct tty_buffer *tb =3D tty->buf.tail; > - *chars =3D tb->char_buf_ptr + tb->used; > - memset(tb->flag_buf_ptr + tb->used, TTY_NORMAL, space); > - tb->used +=3D space; > - } > - return space; > -} > - > -EXPORT_SYMBOL_GPL(tty_prepare_flip_string); > - > -/* > - * Prepare a block of space in the buffer for data. Returns the length > - * available and buffer pointer to the space which is now allocated and > - * accounted for as ready for characters. This is used for drivers > - * that need their own block copy routines into the buffer. There is no > - * guarantee the buffer is a DMA target! > - */ > - > -int tty_prepare_flip_string_flags(struct tty_struct *tty, unsigned char = **chars, char **flags, size_t size) > -{ > - int space =3D tty_buffer_request_room(tty, size); > - if (likely(space)) { > - struct tty_buffer *tb =3D tty->buf.tail; > - *chars =3D tb->char_buf_ptr + tb->used; > - *flags =3D tb->flag_buf_ptr + tb->used; > - tb->used +=3D space; > - } > - return space; > -} > - > -EXPORT_SYMBOL_GPL(tty_prepare_flip_string_flags); > - > - > - > -/* > - * This is probably overkill for real world processors but > - * they are not on hot paths so a little discipline won't do=20 > - * any harm. > - */ > -=20 > -static void tty_set_termios_ldisc(struct tty_struct *tty, int num) > -{ > - down(&tty->termios_sem); > - tty->termios->c_line =3D num; > - up(&tty->termios_sem); > -} > - > -/* > - * This guards the refcounted line discipline lists. The lock > - * must be taken with irqs off because there are hangup path > - * callers who will do ldisc lookups and cannot sleep. > - */ > -=20 > -static DEFINE_SPINLOCK(tty_ldisc_lock); > -static DECLARE_WAIT_QUEUE_HEAD(tty_ldisc_wait); > -static struct tty_ldisc tty_ldiscs[NR_LDISCS]; /* line disc dispatch tab= le */ > - > -int tty_register_ldisc(int disc, struct tty_ldisc *new_ldisc) > -{ > - unsigned long flags; > - int ret =3D 0; > -=09 > - if (disc < N_TTY || disc >=3D NR_LDISCS) > - return -EINVAL; > -=09 > - spin_lock_irqsave(&tty_ldisc_lock, flags); > - tty_ldiscs[disc] =3D *new_ldisc; > - tty_ldiscs[disc].num =3D disc; > - tty_ldiscs[disc].flags |=3D LDISC_FLAG_DEFINED; > - tty_ldiscs[disc].refcount =3D 0; > - spin_unlock_irqrestore(&tty_ldisc_lock, flags); > -=09 > - return ret; > -} > -EXPORT_SYMBOL(tty_register_ldisc); > - > -int tty_unregister_ldisc(int disc) > -{ > - unsigned long flags; > - int ret =3D 0; > - > - if (disc < N_TTY || disc >=3D NR_LDISCS) > - return -EINVAL; > - > - spin_lock_irqsave(&tty_ldisc_lock, flags); > - if (tty_ldiscs[disc].refcount) > - ret =3D -EBUSY; > - else > - tty_ldiscs[disc].flags &=3D ~LDISC_FLAG_DEFINED; > - spin_unlock_irqrestore(&tty_ldisc_lock, flags); > - > - return ret; > -} > -EXPORT_SYMBOL(tty_unregister_ldisc); > - > -struct tty_ldisc *tty_ldisc_get(int disc) > -{ > - unsigned long flags; > - struct tty_ldisc *ld; > - > - if (disc < N_TTY || disc >=3D NR_LDISCS) > - return NULL; > -=09 > - spin_lock_irqsave(&tty_ldisc_lock, flags); > - > - ld =3D &tty_ldiscs[disc]; > - /* Check the entry is defined */ > - if(ld->flags & LDISC_FLAG_DEFINED) > - { > - /* If the module is being unloaded we can't use it */ > - if (!try_module_get(ld->owner)) > - ld =3D NULL; > - else /* lock it */ > - ld->refcount++; > - } > - else > - ld =3D NULL; > - spin_unlock_irqrestore(&tty_ldisc_lock, flags); > - return ld; > -} > - > -EXPORT_SYMBOL_GPL(tty_ldisc_get); > - > -void tty_ldisc_put(int disc) > -{ > - struct tty_ldisc *ld; > - unsigned long flags; > -=09 > - if (disc < N_TTY || disc >=3D NR_LDISCS) > - BUG(); > - =09 > - spin_lock_irqsave(&tty_ldisc_lock, flags); > - ld =3D &tty_ldiscs[disc]; > - if(ld->refcount =3D=3D 0) > - BUG(); > - ld->refcount --; > - module_put(ld->owner); > - spin_unlock_irqrestore(&tty_ldisc_lock, flags); > -} > -=09 > -EXPORT_SYMBOL_GPL(tty_ldisc_put); > - > -static void tty_ldisc_assign(struct tty_struct *tty, struct tty_ldisc *l= d) > -{ > - tty->ldisc =3D *ld; > - tty->ldisc.refcount =3D 0; > -} > - > -/** > - * tty_ldisc_try - internal helper > - * @tty: the tty > - * > - * Make a single attempt to grab and bump the refcount on > - * the tty ldisc. Return 0 on failure or 1 on success. This is > - * used to implement both the waiting and non waiting versions > - * of tty_ldisc_ref > - */ > - > -static int tty_ldisc_try(struct tty_struct *tty) > -{ > - unsigned long flags; > - struct tty_ldisc *ld; > - int ret =3D 0; > -=09 > - spin_lock_irqsave(&tty_ldisc_lock, flags); > - ld =3D &tty->ldisc; > - if(test_bit(TTY_LDISC, &tty->flags)) > - { > - ld->refcount++; > - ret =3D 1; > - } > - spin_unlock_irqrestore(&tty_ldisc_lock, flags); > - return ret; > -} > - > -/** > - * tty_ldisc_ref_wait - wait for the tty ldisc > - * @tty: tty device > - * > - * Dereference the line discipline for the terminal and take a=20 > - * reference to it. If the line discipline is in flux then=20 > - * wait patiently until it changes. > - * > - * Note: Must not be called from an IRQ/timer context. The caller > - * must also be careful not to hold other locks that will deadlock > - * against a discipline change, such as an existing ldisc reference > - * (which we check for) > - */ > -=20 > -struct tty_ldisc *tty_ldisc_ref_wait(struct tty_struct *tty) > -{ > - /* wait_event is a macro */ > - wait_event(tty_ldisc_wait, tty_ldisc_try(tty)); > - if(tty->ldisc.refcount =3D=3D 0) > - printk(KERN_ERR "tty_ldisc_ref_wait\n"); > - return &tty->ldisc; > -} > - > -EXPORT_SYMBOL_GPL(tty_ldisc_ref_wait); > - > -/** > - * tty_ldisc_ref - get the tty ldisc > - * @tty: tty device > - * > - * Dereference the line discipline for the terminal and take a=20 > - * reference to it. If the line discipline is in flux then=20 > - * return NULL. Can be called from IRQ and timer functions. > - */ > -=20 > -struct tty_ldisc *tty_ldisc_ref(struct tty_struct *tty) > -{ > - if(tty_ldisc_try(tty)) > - return &tty->ldisc; > - return NULL; > -} > - > -EXPORT_SYMBOL_GPL(tty_ldisc_ref); > - > -/** > - * tty_ldisc_deref - free a tty ldisc reference > - * @ld: reference to free up > - * > - * Undoes the effect of tty_ldisc_ref or tty_ldisc_ref_wait. May > - * be called in IRQ context. > - */ > -=20 > -void tty_ldisc_deref(struct tty_ldisc *ld) > -{ > - unsigned long flags; > - > - if(ld =3D=3D NULL) > - BUG(); > - =09 > - spin_lock_irqsave(&tty_ldisc_lock, flags); > - if(ld->refcount =3D=3D 0) > - printk(KERN_ERR "tty_ldisc_deref: no references.\n"); > - else > - ld->refcount--; > - if(ld->refcount =3D=3D 0) > - wake_up(&tty_ldisc_wait); > - spin_unlock_irqrestore(&tty_ldisc_lock, flags); > -} > - > -EXPORT_SYMBOL_GPL(tty_ldisc_deref); > - > -/** > - * tty_ldisc_enable - allow ldisc use > - * @tty: terminal to activate ldisc on > - * > - * Set the TTY_LDISC flag when the line discipline can be called > - * again. Do neccessary wakeups for existing sleepers. > - * > - * Note: nobody should set this bit except via this function. Clearing > - * directly is allowed. > - */ > - > -static void tty_ldisc_enable(struct tty_struct *tty) > -{ > - set_bit(TTY_LDISC, &tty->flags); > - wake_up(&tty_ldisc_wait); > -} > -=09 > -/** > - * tty_set_ldisc - set line discipline > - * @tty: the terminal to set > - * @ldisc: the line discipline > - * > - * Set the discipline of a tty line. Must be called from a process > - * context. > - */ > -=20 > -static int tty_set_ldisc(struct tty_struct *tty, int ldisc) > -{ > - int retval =3D 0; > - struct tty_ldisc o_ldisc; > - char buf[64]; > - int work; > - unsigned long flags; > - struct tty_ldisc *ld; > - struct tty_struct *o_tty; > - > - if ((ldisc < N_TTY) || (ldisc >=3D NR_LDISCS)) > - return -EINVAL; > - > -restart: > - > - ld =3D tty_ldisc_get(ldisc); > - /* Eduardo Blanco */ > - /* Cyrus Durgin */ > - if (ld =3D=3D NULL) { > - request_module("tty-ldisc-%d", ldisc); > - ld =3D tty_ldisc_get(ldisc); > - } > - if (ld =3D=3D NULL) > - return -EINVAL; > - > - /* > - * No more input please, we are switching. The new ldisc > - * will update this value in the ldisc open function > - */ > - > - tty->receive_room =3D 0; > - > - /* > - * Problem: What do we do if this blocks ? > - */ > - > - tty_wait_until_sent(tty, 0); > - > - if (tty->ldisc.num =3D=3D ldisc) { > - tty_ldisc_put(ldisc); > - return 0; > - } > - > - o_ldisc =3D tty->ldisc; > - o_tty =3D tty->link; > - > - /* > - * Make sure we don't change while someone holds a > - * reference to the line discipline. The TTY_LDISC bit > - * prevents anyone taking a reference once it is clear. > - * We need the lock to avoid racing reference takers. > - */ > - > - spin_lock_irqsave(&tty_ldisc_lock, flags); > - if (tty->ldisc.refcount || (o_tty && o_tty->ldisc.refcount)) { > - if(tty->ldisc.refcount) { > - /* Free the new ldisc we grabbed. Must drop the lock > - first. */ > - spin_unlock_irqrestore(&tty_ldisc_lock, flags); > - tty_ldisc_put(ldisc); > - /* > - * There are several reasons we may be busy, including > - * random momentary I/O traffic. We must therefore > - * retry. We could distinguish between blocking ops > - * and retries if we made tty_ldisc_wait() smarter. That > - * is up for discussion. > - */ > - if (wait_event_interruptible(tty_ldisc_wait, tty->ldisc.refcount =3D= =3D 0) < 0) > - return -ERESTARTSYS; > - goto restart; > - } > - if(o_tty && o_tty->ldisc.refcount) { > - spin_unlock_irqrestore(&tty_ldisc_lock, flags); > - tty_ldisc_put(ldisc); > - if (wait_event_interruptible(tty_ldisc_wait, o_tty->ldisc.refcount = =3D=3D 0) < 0) > - return -ERESTARTSYS; > - goto restart; > - } > - } > - > - /* if the TTY_LDISC bit is set, then we are racing against another ldis= c change */ > - > - if (!test_bit(TTY_LDISC, &tty->flags)) { > - spin_unlock_irqrestore(&tty_ldisc_lock, flags); > - tty_ldisc_put(ldisc); > - ld =3D tty_ldisc_ref_wait(tty); > - tty_ldisc_deref(ld); > - goto restart; > - } > - > - clear_bit(TTY_LDISC, &tty->flags); > - clear_bit(TTY_DONT_FLIP, &tty->flags); > - if (o_tty) { > - clear_bit(TTY_LDISC, &o_tty->flags); > - clear_bit(TTY_DONT_FLIP, &o_tty->flags); > - } > - spin_unlock_irqrestore(&tty_ldisc_lock, flags); > - > - /* > - * From this point on we know nobody has an ldisc > - * usage reference, nor can they obtain one until > - * we say so later on. > - */ > - > - work =3D cancel_delayed_work(&tty->buf.work); > - /* > - * Wait for ->hangup_work and ->buf.work handlers to terminate > - */ > - =20 > - flush_scheduled_work(); > - /* Shutdown the current discipline. */ > - if (tty->ldisc.close) > - (tty->ldisc.close)(tty); > - > - /* Now set up the new line discipline. */ > - tty_ldisc_assign(tty, ld); > - tty_set_termios_ldisc(tty, ldisc); > - if (tty->ldisc.open) > - retval =3D (tty->ldisc.open)(tty); > - if (retval < 0) { > - tty_ldisc_put(ldisc); > - /* There is an outstanding reference here so this is safe */ > - tty_ldisc_assign(tty, tty_ldisc_get(o_ldisc.num)); > - tty_set_termios_ldisc(tty, tty->ldisc.num); > - if (tty->ldisc.open && (tty->ldisc.open(tty) < 0)) { > - tty_ldisc_put(o_ldisc.num); > - /* This driver is always present */ > - tty_ldisc_assign(tty, tty_ldisc_get(N_TTY)); > - tty_set_termios_ldisc(tty, N_TTY); > - if (tty->ldisc.open) { > - int r =3D tty->ldisc.open(tty); > - > - if (r < 0) > - panic("Couldn't open N_TTY ldisc for " > - "%s --- error %d.", > - tty_name(tty, buf), r); > - } > - } > - } > - /* At this point we hold a reference to the new ldisc and a > - a reference to the old ldisc. If we ended up flipping back > - to the existing ldisc we have two references to it */ > -=09 > - if (tty->ldisc.num !=3D o_ldisc.num && tty->driver->set_ldisc) > - tty->driver->set_ldisc(tty); > - =09 > - tty_ldisc_put(o_ldisc.num); > -=09 > - /* > - * Allow ldisc referencing to occur as soon as the driver > - * ldisc callback completes. > - */ > - =20 > - tty_ldisc_enable(tty); > - if (o_tty) > - tty_ldisc_enable(o_tty); > -=09 > - /* Restart it in case no characters kick it off. Safe if > - already running */ > - if (work) > - schedule_delayed_work(&tty->buf.work, 1); > - return retval; > -} > - > -/* > - * This routine returns a tty driver structure, given a device number > - */ > -static struct tty_driver *get_tty_driver(dev_t device, int *index) > -{ > - struct tty_driver *p; > - > - list_for_each_entry(p, &tty_drivers, tty_drivers) { > - dev_t base =3D MKDEV(p->major, p->minor_start); > - if (device < base || device >=3D base + p->num) > - continue; > - *index =3D device - base; > - return p; > - } > - return NULL; > -} > - > -/* > - * If we try to write to, or set the state of, a terminal and we're > - * not in the foreground, send a SIGTTOU. If the signal is blocked or > - * ignored, go ahead and perform the operation. (POSIX 7.2) > - */ > -int tty_check_change(struct tty_struct * tty) > -{ > - if (current->signal->tty !=3D tty) > - return 0; > - if (tty->pgrp <=3D 0) { > - printk(KERN_WARNING "tty_check_change: tty->pgrp <=3D 0!\n"); > - return 0; > - } > - if (process_group(current) =3D=3D tty->pgrp) > - return 0; > - if (is_ignored(SIGTTOU)) > - return 0; > - if (is_orphaned_pgrp(process_group(current))) > - return -EIO; > - (void) kill_pg(process_group(current), SIGTTOU, 1); > - return -ERESTARTSYS; > -} > - > -EXPORT_SYMBOL(tty_check_change); > - > -static ssize_t hung_up_tty_read(struct file * file, char __user * buf, > - size_t count, loff_t *ppos) > -{ > - return 0; > -} > - > -static ssize_t hung_up_tty_write(struct file * file, const char __user *= buf, > - size_t count, loff_t *ppos) > -{ > - return -EIO; > -} > - > -/* No kernel lock held - none needed ;) */ > -static unsigned int hung_up_tty_poll(struct file * filp, poll_table * wa= it) > -{ > - return POLLIN | POLLOUT | POLLERR | POLLHUP | POLLRDNORM | POLLWRNORM; > -} > - > -static int hung_up_tty_ioctl(struct inode * inode, struct file * file, > - unsigned int cmd, unsigned long arg) > -{ > - return cmd =3D=3D TIOCSPGRP ? -ENOTTY : -EIO; > -} > - > -static struct file_operations tty_fops =3D { > - .llseek =3D no_llseek, > - .read =3D tty_read, > - .write =3D tty_write, > - .poll =3D tty_poll, > - .ioctl =3D tty_ioctl, > - .open =3D tty_open, > - .release =3D tty_release, > - .fasync =3D tty_fasync, > -}; > - > -#ifdef CONFIG_UNIX98_PTYS > -static struct file_operations ptmx_fops =3D { > - .llseek =3D no_llseek, > - .read =3D tty_read, > - .write =3D tty_write, > - .poll =3D tty_poll, > - .ioctl =3D tty_ioctl, > - .open =3D ptmx_open, > - .release =3D tty_release, > - .fasync =3D tty_fasync, > -}; > -#endif > - > -static struct file_operations console_fops =3D { > - .llseek =3D no_llseek, > - .read =3D tty_read, > - .write =3D redirected_tty_write, > - .poll =3D tty_poll, > - .ioctl =3D tty_ioctl, > - .open =3D tty_open, > - .release =3D tty_release, > - .fasync =3D tty_fasync, > -}; > - > -static struct file_operations hung_up_tty_fops =3D { > - .llseek =3D no_llseek, > - .read =3D hung_up_tty_read, > - .write =3D hung_up_tty_write, > - .poll =3D hung_up_tty_poll, > - .ioctl =3D hung_up_tty_ioctl, > - .release =3D tty_release, > -}; > - > -static DEFINE_SPINLOCK(redirect_lock); > -static struct file *redirect; > - > -/** > - * tty_wakeup - request more data > - * @tty: terminal > - * > - * Internal and external helper for wakeups of tty. This function > - * informs the line discipline if present that the driver is ready > - * to receive more output data. > - */ > -=20 > -void tty_wakeup(struct tty_struct *tty) > -{ > - struct tty_ldisc *ld; > -=09 > - if (test_bit(TTY_DO_WRITE_WAKEUP, &tty->flags)) { > - ld =3D tty_ldisc_ref(tty); > - if(ld) { > - if(ld->write_wakeup) > - ld->write_wakeup(tty); > - tty_ldisc_deref(ld); > - } > - } > - wake_up_interruptible(&tty->write_wait); > -} > - > -EXPORT_SYMBOL_GPL(tty_wakeup); > - > -/** > - * tty_ldisc_flush - flush line discipline queue > - * @tty: tty > - * > - * Flush the line discipline queue (if any) for this tty. If there > - * is no line discipline active this is a no-op. > - */ > -=20 > -void tty_ldisc_flush(struct tty_struct *tty) > -{ > - struct tty_ldisc *ld =3D tty_ldisc_ref(tty); > - if(ld) { > - if(ld->flush_buffer) > - ld->flush_buffer(tty); > - tty_ldisc_deref(ld); > - } > -} > - > -EXPORT_SYMBOL_GPL(tty_ldisc_flush); > -=09 > -/* > - * This can be called by the "eventd" kernel thread. That is process sy= nchronous, > - * but doesn't hold any locks, so we need to make sure we have the appro= priate > - * locks for what we're doing.. > - */ > -static void do_tty_hangup(void *data) > -{ > - struct tty_struct *tty =3D (struct tty_struct *) data; > - struct file * cons_filp =3D NULL; > - struct file *filp, *f =3D NULL; > - struct task_struct *p; > - struct tty_ldisc *ld; > - int closecount =3D 0, n; > - > - if (!tty) > - return; > - > - /* inuse_filps is protected by the single kernel lock */ > - lock_kernel(); > - > - spin_lock(&redirect_lock); > - if (redirect && redirect->private_data =3D=3D tty) { > - f =3D redirect; > - redirect =3D NULL; > - } > - spin_unlock(&redirect_lock); > -=09 > - check_tty_count(tty, "do_tty_hangup"); > - file_list_lock(); > - /* This breaks for file handles being sent over AF_UNIX sockets ? */ > - list_for_each_entry(filp, &tty->tty_files, f_u.fu_list) { > - if (filp->f_op->write =3D=3D redirected_tty_write) > - cons_filp =3D filp; > - if (filp->f_op->write !=3D tty_write) > - continue; > - closecount++; > - tty_fasync(-1, filp, 0); /* can't block */ > - filp->f_op =3D &hung_up_tty_fops; > - } > - file_list_unlock(); > -=09 > - /* FIXME! What are the locking issues here? This may me overdoing thing= s.. > - * this question is especially important now that we've removed the irq= lock. */ > - > - ld =3D tty_ldisc_ref(tty); > - if(ld !=3D NULL) /* We may have no line discipline at this point */ > - { > - if (ld->flush_buffer) > - ld->flush_buffer(tty); > - if (tty->driver->flush_buffer) > - tty->driver->flush_buffer(tty); > - if ((test_bit(TTY_DO_WRITE_WAKEUP, &tty->flags)) && > - ld->write_wakeup) > - ld->write_wakeup(tty); > - if (ld->hangup) > - ld->hangup(tty); > - } > - > - /* FIXME: Once we trust the LDISC code better we can wait here for > - ldisc completion and fix the driver call race */ > - =20 > - wake_up_interruptible(&tty->write_wait); > - wake_up_interruptible(&tty->read_wait); > - > - /* > - * Shutdown the current line discipline, and reset it to > - * N_TTY. > - */ > - if (tty->driver->flags & TTY_DRIVER_RESET_TERMIOS) > - { > - down(&tty->termios_sem); > - *tty->termios =3D tty->driver->init_termios; > - up(&tty->termios_sem); > - } > -=09 > - /* Defer ldisc switch */ > - /* tty_deferred_ldisc_switch(N_TTY); > -=09 > - This should get done automatically when the port closes and > - tty_release is called */ > -=09 > - read_lock(&tasklist_lock); > - if (tty->session > 0) { > - do_each_task_pid(tty->session, PIDTYPE_SID, p) { > - if (p->signal->tty =3D=3D tty) > - p->signal->tty =3D NULL; > - if (!p->signal->leader) > - continue; > - send_group_sig_info(SIGHUP, SEND_SIG_PRIV, p); > - send_group_sig_info(SIGCONT, SEND_SIG_PRIV, p); > - if (tty->pgrp > 0) > - p->signal->tty_old_pgrp =3D tty->pgrp; > - } while_each_task_pid(tty->session, PIDTYPE_SID, p); > - } > - read_unlock(&tasklist_lock); > - > - tty->flags =3D 0; > - tty->session =3D 0; > - tty->pgrp =3D -1; > - tty->ctrl_status =3D 0; > - /* > - * If one of the devices matches a console pointer, we > - * cannot just call hangup() because that will cause > - * tty->count and state->count to go out of sync. > - * So we just call close() the right number of times. > - */ > - if (cons_filp) { > - if (tty->driver->close) > - for (n =3D 0; n < closecount; n++) > - tty->driver->close(tty, cons_filp); > - } else if (tty->driver->hangup) > - (tty->driver->hangup)(tty); > - =09 > - /* We don't want to have driver/ldisc interactions beyond > - the ones we did here. The driver layer expects no > - calls after ->hangup() from the ldisc side. However we > - can't yet guarantee all that */ > - > - set_bit(TTY_HUPPED, &tty->flags); > - if (ld) { > - tty_ldisc_enable(tty); > - tty_ldisc_deref(ld); > - } > - unlock_kernel(); > - if (f) > - fput(f); > -} > - > -void tty_hangup(struct tty_struct * tty) > -{ > -#ifdef TTY_DEBUG_HANGUP > - char buf[64]; > -=09 > - printk(KERN_DEBUG "%s hangup...\n", tty_name(tty, buf)); > -#endif > - schedule_work(&tty->hangup_work); > -} > - > -EXPORT_SYMBOL(tty_hangup); > - > -void tty_vhangup(struct tty_struct * tty) > -{ > -#ifdef TTY_DEBUG_HANGUP > - char buf[64]; > - > - printk(KERN_DEBUG "%s vhangup...\n", tty_name(tty, buf)); > -#endif > - do_tty_hangup((void *) tty); > -} > -EXPORT_SYMBOL(tty_vhangup); > - > -int tty_hung_up_p(struct file * filp) > -{ > - return (filp->f_op =3D=3D &hung_up_tty_fops); > -} > - > -EXPORT_SYMBOL(tty_hung_up_p); > - > -/* > - * This function is typically called only by the session leader, when > - * it wants to disassociate itself from its controlling tty. > - * > - * It performs the following functions: > - * (1) Sends a SIGHUP and SIGCONT to the foreground process group > - * (2) Clears the tty from being controlling the session > - * (3) Clears the controlling tty for all processes in the > - * session group. > - * > - * The argument on_exit is set to 1 if called when a process is > - * exiting; it is 0 if called by the ioctl TIOCNOTTY. > - */ > -void disassociate_ctty(int on_exit) > -{ > - struct tty_struct *tty; > - struct task_struct *p; > - int tty_pgrp =3D -1; > - > - lock_kernel(); > - > - down(&tty_sem); > - tty =3D current->signal->tty; > - if (tty) { > - tty_pgrp =3D tty->pgrp; > - up(&tty_sem); > - if (on_exit && tty->driver->type !=3D TTY_DRIVER_TYPE_PTY) > - tty_vhangup(tty); > - } else { > - if (current->signal->tty_old_pgrp) { > - kill_pg(current->signal->tty_old_pgrp, SIGHUP, on_exit); > - kill_pg(current->signal->tty_old_pgrp, SIGCONT, on_exit); > - } > - up(&tty_sem); > - unlock_kernel();=09 > - return; > - } > - if (tty_pgrp > 0) { > - kill_pg(tty_pgrp, SIGHUP, on_exit); > - if (!on_exit) > - kill_pg(tty_pgrp, SIGCONT, on_exit); > - } > - > - /* Must lock changes to tty_old_pgrp */ > - down(&tty_sem); > - current->signal->tty_old_pgrp =3D 0; > - tty->session =3D 0; > - tty->pgrp =3D -1; > - > - /* Now clear signal->tty under the lock */ > - read_lock(&tasklist_lock); > - do_each_task_pid(current->signal->session, PIDTYPE_SID, p) { > - p->signal->tty =3D NULL; > - } while_each_task_pid(current->signal->session, PIDTYPE_SID, p); > - read_unlock(&tasklist_lock); > - up(&tty_sem); > - unlock_kernel(); > -} > - > -void stop_tty(struct tty_struct *tty) > -{ > - if (tty->stopped) > - return; > - tty->stopped =3D 1; > - if (tty->link && tty->link->packet) { > - tty->ctrl_status &=3D ~TIOCPKT_START; > - tty->ctrl_status |=3D TIOCPKT_STOP; > - wake_up_interruptible(&tty->link->read_wait); > - } > - if (tty->driver->stop) > - (tty->driver->stop)(tty); > -} > - > -EXPORT_SYMBOL(stop_tty); > - > -void start_tty(struct tty_struct *tty) > -{ > - if (!tty->stopped || tty->flow_stopped) > - return; > - tty->stopped =3D 0; > - if (tty->link && tty->link->packet) { > - tty->ctrl_status &=3D ~TIOCPKT_STOP; > - tty->ctrl_status |=3D TIOCPKT_START; > - wake_up_interruptible(&tty->link->read_wait); > - } > - if (tty->driver->start) > - (tty->driver->start)(tty); > - > - /* If we have a running line discipline it may need kicking */ > - tty_wakeup(tty); > - wake_up_interruptible(&tty->write_wait); > -} > - > -EXPORT_SYMBOL(start_tty); > - > -static ssize_t tty_read(struct file * file, char __user * buf, size_t co= unt,=20 > - loff_t *ppos) > -{ > - int i; > - struct tty_struct * tty; > - struct inode *inode; > - struct tty_ldisc *ld; > - > - tty =3D (struct tty_struct *)file->private_data; > - inode =3D file->f_dentry->d_inode; > - if (tty_paranoia_check(tty, inode, "tty_read")) > - return -EIO; > - if (!tty || (test_bit(TTY_IO_ERROR, &tty->flags))) > - return -EIO; > - > - /* We want to wait for the line discipline to sort out in this > - situation */ > - ld =3D tty_ldisc_ref_wait(tty); > - lock_kernel(); > - if (ld->read) > - i =3D (ld->read)(tty,file,buf,count); > - else > - i =3D -EIO; > - tty_ldisc_deref(ld); > - unlock_kernel(); > - if (i > 0) > - inode->i_atime =3D current_fs_time(inode->i_sb); > - return i; > -} > - > -/* > - * Split writes up in sane blocksizes to avoid > - * denial-of-service type attacks > - */ > -static inline ssize_t do_tty_write( > - ssize_t (*write)(struct tty_struct *, struct file *, const unsigned cha= r *, size_t), > - struct tty_struct *tty, > - struct file *file, > - const char __user *buf, > - size_t count) > -{ > - ssize_t ret =3D 0, written =3D 0; > - unsigned int chunk; > -=09 > - if (down_interruptible(&tty->atomic_write)) { > - return -ERESTARTSYS; > - } > - > - /* > - * We chunk up writes into a temporary buffer. This > - * simplifies low-level drivers immensely, since they > - * don't have locking issues and user mode accesses. > - * > - * But if TTY_NO_WRITE_SPLIT is set, we should use a > - * big chunk-size.. > - * > - * The default chunk-size is 2kB, because the NTTY > - * layer has problems with bigger chunks. It will > - * claim to be able to handle more characters than > - * it actually does. > - */ > - chunk =3D 2048; > - if (test_bit(TTY_NO_WRITE_SPLIT, &tty->flags)) > - chunk =3D 65536; > - if (count < chunk) > - chunk =3D count; > - > - /* write_buf/write_cnt is protected by the atomic_write semaphore */ > - if (tty->write_cnt < chunk) { > - unsigned char *buf; > - > - if (chunk < 1024) > - chunk =3D 1024; > - > - buf =3D kmalloc(chunk, GFP_KERNEL); > - if (!buf) { > - up(&tty->atomic_write); > - return -ENOMEM; > - } > - kfree(tty->write_buf); > - tty->write_cnt =3D chunk; > - tty->write_buf =3D buf; > - } > - > - /* Do the write .. */ > - for (;;) { > - size_t size =3D count; > - if (size > chunk) > - size =3D chunk; > - ret =3D -EFAULT; > - if (copy_from_user(tty->write_buf, buf, size)) > - break; > - lock_kernel(); > - ret =3D write(tty, file, tty->write_buf, size); > - unlock_kernel(); > - if (ret <=3D 0) > - break; > - written +=3D ret; > - buf +=3D ret; > - count -=3D ret; > - if (!count) > - break; > - ret =3D -ERESTARTSYS; > - if (signal_pending(current)) > - break; > - cond_resched(); > - } > - if (written) { > - struct inode *inode =3D file->f_dentry->d_inode; > - inode->i_mtime =3D current_fs_time(inode->i_sb); > - ret =3D written; > - } > - up(&tty->atomic_write); > - return ret; > -} > - > - > -static ssize_t tty_write(struct file * file, const char __user * buf, si= ze_t count, > - loff_t *ppos) > -{ > - struct tty_struct * tty; > - struct inode *inode =3D file->f_dentry->d_inode; > - ssize_t ret; > - struct tty_ldisc *ld; > -=09 > - tty =3D (struct tty_struct *)file->private_data; > - if (tty_paranoia_check(tty, inode, "tty_write")) > - return -EIO; > - if (!tty || !tty->driver->write || (test_bit(TTY_IO_ERROR, &tty->flags)= )) > - return -EIO; > - > - ld =3D tty_ldisc_ref_wait(tty); =09 > - if (!ld->write) > - ret =3D -EIO; > - else > - ret =3D do_tty_write(ld->write, tty, file, buf, count); > - tty_ldisc_deref(ld); > - return ret; > -} > - > -ssize_t redirected_tty_write(struct file * file, const char __user * buf= , size_t count, > - loff_t *ppos) > -{ > - struct file *p =3D NULL; > - > - spin_lock(&redirect_lock); > - if (redirect) { > - get_file(redirect); > - p =3D redirect; > - } > - spin_unlock(&redirect_lock); > - > - if (p) { > - ssize_t res; > - res =3D vfs_write(p, buf, count, &p->f_pos); > - fput(p); > - return res; > - } > - > - return tty_write(file, buf, count, ppos); > -} > - > -static char ptychar[] =3D "pqrstuvwxyzabcde"; > - > -static inline void pty_line_name(struct tty_driver *driver, int index, c= har *p) > -{ > - int i =3D index + driver->name_base; > - /* ->name is initialized to "ttyp", but "tty" is expected */ > - sprintf(p, "%s%c%x", > - driver->subtype =3D=3D PTY_TYPE_SLAVE ? "tty" : driver->name, > - ptychar[i >> 4 & 0xf], i & 0xf); > -} > - > -static inline void tty_line_name(struct tty_driver *driver, int index, c= har *p) > -{ > - sprintf(p, "%s%d", driver->name, index + driver->name_base); > -} > - > -/* > - * WSH 06/09/97: Rewritten to remove races and properly clean up after a > - * failed open. The new code protects the open with a semaphore, so it's > - * really quite straightforward. The semaphore locking can probably be > - * relaxed for the (most common) case of reopening a tty. > - */ > -static int init_dev(struct tty_driver *driver, int idx, > - struct tty_struct **ret_tty) > -{ > - struct tty_struct *tty, *o_tty; > - struct termios *tp, **tp_loc, *o_tp, **o_tp_loc; > - struct termios *ltp, **ltp_loc, *o_ltp, **o_ltp_loc; > - int retval=3D0; > - > - /* check whether we're reopening an existing tty */ > - if (driver->flags & TTY_DRIVER_DEVPTS_MEM) { > - tty =3D devpts_get_tty(idx); > - if (tty && driver->subtype =3D=3D PTY_TYPE_MASTER) > - tty =3D tty->link; > - } else { > - tty =3D driver->ttys[idx]; > - } > - if (tty) goto fast_track; > - > - /* > - * First time open is complex, especially for PTY devices. > - * This code guarantees that either everything succeeds and the > - * TTY is ready for operation, or else the table slots are vacated > - * and the allocated memory released. (Except that the termios=20 > - * and locked termios may be retained.) > - */ > - > - if (!try_module_get(driver->owner)) { > - retval =3D -ENODEV; > - goto end_init; > - } > - > - o_tty =3D NULL; > - tp =3D o_tp =3D NULL; > - ltp =3D o_ltp =3D NULL; > - > - tty =3D alloc_tty_struct(); > - if(!tty) > - goto fail_no_mem; > - initialize_tty_struct(tty); > - tty->driver =3D driver; > - tty->index =3D idx; > - tty_line_name(driver, idx, tty->name); > - > - if (driver->flags & TTY_DRIVER_DEVPTS_MEM) { > - tp_loc =3D &tty->termios; > - ltp_loc =3D &tty->termios_locked; > - } else { > - tp_loc =3D &driver->termios[idx]; > - ltp_loc =3D &driver->termios_locked[idx]; > - } > - > - if (!*tp_loc) { > - tp =3D (struct termios *) kmalloc(sizeof(struct termios), > - GFP_KERNEL); > - if (!tp) > - goto free_mem_out; > - *tp =3D driver->init_termios; > - } > - > - if (!*ltp_loc) { > - ltp =3D (struct termios *) kmalloc(sizeof(struct termios), > - GFP_KERNEL); > - if (!ltp) > - goto free_mem_out; > - memset(ltp, 0, sizeof(struct termios)); > - } > - > - if (driver->type =3D=3D TTY_DRIVER_TYPE_PTY) { > - o_tty =3D alloc_tty_struct(); > - if (!o_tty) > - goto free_mem_out; > - initialize_tty_struct(o_tty); > - o_tty->driver =3D driver->other; > - o_tty->index =3D idx; > - tty_line_name(driver->other, idx, o_tty->name); > - > - if (driver->flags & TTY_DRIVER_DEVPTS_MEM) { > - o_tp_loc =3D &o_tty->termios; > - o_ltp_loc =3D &o_tty->termios_locked; > - } else { > - o_tp_loc =3D &driver->other->termios[idx]; > - o_ltp_loc =3D &driver->other->termios_locked[idx]; > - } > - > - if (!*o_tp_loc) { > - o_tp =3D (struct termios *) > - kmalloc(sizeof(struct termios), GFP_KERNEL); > - if (!o_tp) > - goto free_mem_out; > - *o_tp =3D driver->other->init_termios; > - } > - > - if (!*o_ltp_loc) { > - o_ltp =3D (struct termios *) > - kmalloc(sizeof(struct termios), GFP_KERNEL); > - if (!o_ltp) > - goto free_mem_out; > - memset(o_ltp, 0, sizeof(struct termios)); > - } > - > - /* > - * Everything allocated ... set up the o_tty structure. > - */ > - if (!(driver->other->flags & TTY_DRIVER_DEVPTS_MEM)) { > - driver->other->ttys[idx] =3D o_tty; > - } > - if (!*o_tp_loc) > - *o_tp_loc =3D o_tp; > - if (!*o_ltp_loc) > - *o_ltp_loc =3D o_ltp; > - o_tty->termios =3D *o_tp_loc; > - o_tty->termios_locked =3D *o_ltp_loc; > - driver->other->refcount++; > - if (driver->subtype =3D=3D PTY_TYPE_MASTER) > - o_tty->count++; > - > - /* Establish the links in both directions */ > - tty->link =3D o_tty; > - o_tty->link =3D tty; > - } > - > - /*=20 > - * All structures have been allocated, so now we install them. > - * Failures after this point use release_mem to clean up, so=20 > - * there's no need to null out the local pointers. > - */ > - if (!(driver->flags & TTY_DRIVER_DEVPTS_MEM)) { > - driver->ttys[idx] =3D tty; > - } > -=09 > - if (!*tp_loc) > - *tp_loc =3D tp; > - if (!*ltp_loc) > - *ltp_loc =3D ltp; > - tty->termios =3D *tp_loc; > - tty->termios_locked =3D *ltp_loc; > - driver->refcount++; > - tty->count++; > - > - /*=20 > - * Structures all installed ... call the ldisc open routines. > - * If we fail here just call release_mem to clean up. No need > - * to decrement the use counts, as release_mem doesn't care. > - */ > - > - if (tty->ldisc.open) { > - retval =3D (tty->ldisc.open)(tty); > - if (retval) > - goto release_mem_out; > - } > - if (o_tty && o_tty->ldisc.open) { > - retval =3D (o_tty->ldisc.open)(o_tty); > - if (retval) { > - if (tty->ldisc.close) > - (tty->ldisc.close)(tty); > - goto release_mem_out; > - } > - tty_ldisc_enable(o_tty); > - } > - tty_ldisc_enable(tty); > - goto success; > - > - /* > - * This fast open can be used if the tty is already open. > - * No memory is allocated, and the only failures are from > - * attempting to open a closing tty or attempting multiple > - * opens on a pty master. > - */ > -fast_track: > - if (test_bit(TTY_CLOSING, &tty->flags)) { > - retval =3D -EIO; > - goto end_init; > - } > - if (driver->type =3D=3D TTY_DRIVER_TYPE_PTY && > - driver->subtype =3D=3D PTY_TYPE_MASTER) { > - /* > - * special case for PTY masters: only one open permitted,=20 > - * and the slave side open count is incremented as well. > - */ > - if (tty->count) { > - retval =3D -EIO; > - goto end_init; > - } > - tty->link->count++; > - } > - tty->count++; > - tty->driver =3D driver; /* N.B. why do this every time?? */ > - > - /* FIXME */ > - if(!test_bit(TTY_LDISC, &tty->flags)) > - printk(KERN_ERR "init_dev but no ldisc\n"); > -success: > - *ret_tty =3D tty; > -=09 > - /* All paths come through here to release the semaphore */ > -end_init: > - return retval; > - > - /* Release locally allocated memory ... nothing placed in slots */ > -free_mem_out: > - kfree(o_tp); > - if (o_tty) > - free_tty_struct(o_tty); > - kfree(ltp); > - kfree(tp); > - free_tty_struct(tty); > - > -fail_no_mem: > - module_put(driver->owner); > - retval =3D -ENOMEM; > - goto end_init; > - > - /* call the tty release_mem routine to clean out this slot */ > -release_mem_out: > - printk(KERN_INFO "init_dev: ldisc open failed, " > - "clearing slot %d\n", idx); > - release_mem(tty, idx); > - goto end_init; > -} > - > -/* > - * Releases memory associated with a tty structure, and clears out the > - * driver table slots. > - */ > -static void release_mem(struct tty_struct *tty, int idx) > -{ > - struct tty_struct *o_tty; > - struct termios *tp; > - int devpts =3D tty->driver->flags & TTY_DRIVER_DEVPTS_MEM; > - > - if ((o_tty =3D tty->link) !=3D NULL) { > - if (!devpts) > - o_tty->driver->ttys[idx] =3D NULL; > - if (o_tty->driver->flags & TTY_DRIVER_RESET_TERMIOS) { > - tp =3D o_tty->termios; > - if (!devpts) > - o_tty->driver->termios[idx] =3D NULL; > - kfree(tp); > - > - tp =3D o_tty->termios_locked; > - if (!devpts) > - o_tty->driver->termios_locked[idx] =3D NULL; > - kfree(tp); > - } > - o_tty->magic =3D 0; > - o_tty->driver->refcount--; > - file_list_lock(); > - list_del_init(&o_tty->tty_files); > - file_list_unlock(); > - free_tty_struct(o_tty); > - } > - > - if (!devpts) > - tty->driver->ttys[idx] =3D NULL; > - if (tty->driver->flags & TTY_DRIVER_RESET_TERMIOS) { > - tp =3D tty->termios; > - if (!devpts) > - tty->driver->termios[idx] =3D NULL; > - kfree(tp); > - > - tp =3D tty->termios_locked; > - if (!devpts) > - tty->driver->termios_locked[idx] =3D NULL; > - kfree(tp); > - } > - > - tty->magic =3D 0; > - tty->driver->refcount--; > - file_list_lock(); > - list_del_init(&tty->tty_files); > - file_list_unlock(); > - module_put(tty->driver->owner); > - free_tty_struct(tty); > -} > - > -/* > - * Even releasing the tty structures is a tricky business.. We have > - * to be very careful that the structures are all released at the > - * same time, as interrupts might otherwise get the wrong pointers. > - * > - * WSH 09/09/97: rewritten to avoid some nasty race conditions that could > - * lead to double frees or releasing memory still in use. > - */ > -static void release_dev(struct file * filp) > -{ > - struct tty_struct *tty, *o_tty; > - int pty_master, tty_closing, o_tty_closing, do_sleep; > - int devpts_master, devpts; > - int idx; > - char buf[64]; > - unsigned long flags; > -=09 > - tty =3D (struct tty_struct *)filp->private_data; > - if (tty_paranoia_check(tty, filp->f_dentry->d_inode, "release_dev")) > - return; > - > - check_tty_count(tty, "release_dev"); > - > - tty_fasync(-1, filp, 0); > - > - idx =3D tty->index; > - pty_master =3D (tty->driver->type =3D=3D TTY_DRIVER_TYPE_PTY && > - tty->driver->subtype =3D=3D PTY_TYPE_MASTER); > - devpts =3D (tty->driver->flags & TTY_DRIVER_DEVPTS_MEM) !=3D 0; > - devpts_master =3D pty_master && devpts; > - o_tty =3D tty->link; > - > -#ifdef TTY_PARANOIA_CHECK > - if (idx < 0 || idx >=3D tty->driver->num) { > - printk(KERN_DEBUG "release_dev: bad idx when trying to " > - "free (%s)\n", tty->name); > - return; > - } > - if (!(tty->driver->flags & TTY_DRIVER_DEVPTS_MEM)) { > - if (tty !=3D tty->driver->ttys[idx]) { > - printk(KERN_DEBUG "release_dev: driver.table[%d] not tty " > - "for (%s)\n", idx, tty->name); > - return; > - } > - if (tty->termios !=3D tty->driver->termios[idx]) { > - printk(KERN_DEBUG "release_dev: driver.termios[%d] not termios " > - "for (%s)\n", > - idx, tty->name); > - return; > - } > - if (tty->termios_locked !=3D tty->driver->termios_locked[idx]) { > - printk(KERN_DEBUG "release_dev: driver.termios_locked[%d] not " > - "termios_locked for (%s)\n", > - idx, tty->name); > - return; > - } > - } > -#endif > - > -#ifdef TTY_DEBUG_HANGUP > - printk(KERN_DEBUG "release_dev of %s (tty count=3D%d)...", > - tty_name(tty, buf), tty->count); > -#endif > - > -#ifdef TTY_PARANOIA_CHECK > - if (tty->driver->other && > - !(tty->driver->flags & TTY_DRIVER_DEVPTS_MEM)) { > - if (o_tty !=3D tty->driver->other->ttys[idx]) { > - printk(KERN_DEBUG "release_dev: other->table[%d] " > - "not o_tty for (%s)\n", > - idx, tty->name); > - return; > - } > - if (o_tty->termios !=3D tty->driver->other->termios[idx]) { > - printk(KERN_DEBUG "release_dev: other->termios[%d] " > - "not o_termios for (%s)\n", > - idx, tty->name); > - return; > - } > - if (o_tty->termios_locked !=3D=20 > - tty->driver->other->termios_locked[idx]) { > - printk(KERN_DEBUG "release_dev: other->termios_locked[" > - "%d] not o_termios_locked for (%s)\n", > - idx, tty->name); > - return; > - } > - if (o_tty->link !=3D tty) { > - printk(KERN_DEBUG "release_dev: bad pty pointers\n"); > - return; > - } > - } > -#endif > - if (tty->driver->close) > - tty->driver->close(tty, filp); > - > - /* > - * Sanity check: if tty->count is going to zero, there shouldn't be > - * any waiters on tty->read_wait or tty->write_wait. We test the > - * wait queues and kick everyone out _before_ actually starting to > - * close. This ensures that we won't block while releasing the tty > - * structure. > - * > - * The test for the o_tty closing is necessary, since the master and > - * slave sides may close in any order. If the slave side closes out > - * first, its count will be one, since the master side holds an open. > - * Thus this test wouldn't be triggered at the time the slave closes, > - * so we do it now. > - * > - * Note that it's possible for the tty to be opened again while we're > - * flushing out waiters. By recalculating the closing flags before > - * each iteration we avoid any problems. > - */ > - while (1) { > - /* Guard against races with tty->count changes elsewhere and > - opens on /dev/tty */ > - =20 > - down(&tty_sem); > - tty_closing =3D tty->count <=3D 1; > - o_tty_closing =3D o_tty && > - (o_tty->count <=3D (pty_master ? 1 : 0)); > - do_sleep =3D 0; > - > - if (tty_closing) { > - if (waitqueue_active(&tty->read_wait)) { > - wake_up(&tty->read_wait); > - do_sleep++; > - } > - if (waitqueue_active(&tty->write_wait)) { > - wake_up(&tty->write_wait); > - do_sleep++; > - } > - } > - if (o_tty_closing) { > - if (waitqueue_active(&o_tty->read_wait)) { > - wake_up(&o_tty->read_wait); > - do_sleep++; > - } > - if (waitqueue_active(&o_tty->write_wait)) { > - wake_up(&o_tty->write_wait); > - do_sleep++; > - } > - } > - if (!do_sleep) > - break; > - > - printk(KERN_WARNING "release_dev: %s: read/write wait queue " > - "active!\n", tty_name(tty, buf)); > - up(&tty_sem); > - schedule(); > - }=09 > - > - /* > - * The closing flags are now consistent with the open counts on=20 > - * both sides, and we've completed the last operation that could=20 > - * block, so it's safe to proceed with closing. > - */ > - if (pty_master) { > - if (--o_tty->count < 0) { > - printk(KERN_WARNING "release_dev: bad pty slave count " > - "(%d) for %s\n", > - o_tty->count, tty_name(o_tty, buf)); > - o_tty->count =3D 0; > - } > - } > - if (--tty->count < 0) { > - printk(KERN_WARNING "release_dev: bad tty->count (%d) for %s\n", > - tty->count, tty_name(tty, buf)); > - tty->count =3D 0; > - } > -=09 > - /* > - * We've decremented tty->count, so we need to remove this file > - * descriptor off the tty->tty_files list; this serves two > - * purposes: > - * - check_tty_count sees the correct number of file descriptors > - * associated with this tty. > - * - do_tty_hangup no longer sees this file descriptor as > - * something that needs to be handled for hangups. > - */ > - file_kill(filp); > - filp->private_data =3D NULL; > - > - /* > - * Perform some housekeeping before deciding whether to return. > - * > - * Set the TTY_CLOSING flag if this was the last open. In the > - * case of a pty we may have to wait around for the other side > - * to close, and TTY_CLOSING makes sure we can't be reopened. > - */ > - if(tty_closing) > - set_bit(TTY_CLOSING, &tty->flags); > - if(o_tty_closing) > - set_bit(TTY_CLOSING, &o_tty->flags); > - > - /* > - * If _either_ side is closing, make sure there aren't any > - * processes that still think tty or o_tty is their controlling > - * tty. > - */ > - if (tty_closing || o_tty_closing) { > - struct task_struct *p; > - > - read_lock(&tasklist_lock); > - do_each_task_pid(tty->session, PIDTYPE_SID, p) { > - p->signal->tty =3D NULL; > - } while_each_task_pid(tty->session, PIDTYPE_SID, p); > - if (o_tty) > - do_each_task_pid(o_tty->session, PIDTYPE_SID, p) { > - p->signal->tty =3D NULL; > - } while_each_task_pid(o_tty->session, PIDTYPE_SID, p); > - read_unlock(&tasklist_lock); > - } > - > - up(&tty_sem); > - > - /* check whether both sides are closing ... */ > - if (!tty_closing || (o_tty && !o_tty_closing)) > - return; > -=09 > -#ifdef TTY_DEBUG_HANGUP > - printk(KERN_DEBUG "freeing tty structure..."); > -#endif > - /* > - * Prevent flush_to_ldisc() from rescheduling the work for later. Then > - * kill any delayed work. As this is the final close it does not > - * race with the set_ldisc code path. > - */ > - clear_bit(TTY_LDISC, &tty->flags); > - clear_bit(TTY_DONT_FLIP, &tty->flags); > - cancel_delayed_work(&tty->buf.work); > - > - /* > - * Wait for ->hangup_work and ->buf.work handlers to terminate > - */ > - =20 > - flush_scheduled_work(); > -=09 > - /* > - * Wait for any short term users (we know they are just driver > - * side waiters as the file is closing so user count on the file > - * side is zero. > - */ > - spin_lock_irqsave(&tty_ldisc_lock, flags); > - while(tty->ldisc.refcount) > - { > - spin_unlock_irqrestore(&tty_ldisc_lock, flags); > - wait_event(tty_ldisc_wait, tty->ldisc.refcount =3D=3D 0); > - spin_lock_irqsave(&tty_ldisc_lock, flags); > - } > - spin_unlock_irqrestore(&tty_ldisc_lock, flags); > - /* > - * Shutdown the current line discipline, and reset it to N_TTY. > - * N.B. why reset ldisc when we're releasing the memory?? > - * > - * FIXME: this MUST get fixed for the new reflocking > - */ > - if (tty->ldisc.close) > - (tty->ldisc.close)(tty); > - tty_ldisc_put(tty->ldisc.num); > -=09 > - /* > - * Switch the line discipline back > - */ > - tty_ldisc_assign(tty, tty_ldisc_get(N_TTY)); > - tty_set_termios_ldisc(tty,N_TTY);=20 > - if (o_tty) { > - /* FIXME: could o_tty be in setldisc here ? */ > - clear_bit(TTY_LDISC, &o_tty->flags); > - if (o_tty->ldisc.close) > - (o_tty->ldisc.close)(o_tty); > - tty_ldisc_put(o_tty->ldisc.num); > - tty_ldisc_assign(o_tty, tty_ldisc_get(N_TTY)); > - tty_set_termios_ldisc(o_tty,N_TTY);=20 > - } > - /* > - * The release_mem function takes care of the details of clearing > - * the slots and preserving the termios structure. > - */ > - release_mem(tty, idx); > - > -#ifdef CONFIG_UNIX98_PTYS > - /* Make this pty number available for reallocation */ > - if (devpts) { > - down(&allocated_ptys_lock); > - idr_remove(&allocated_ptys, idx); > - up(&allocated_ptys_lock); > - } > -#endif > - > -} > - > -/* > - * tty_open and tty_release keep up the tty count that contains the > - * number of opens done on a tty. We cannot use the inode-count, as > - * different inodes might point to the same tty. > - * > - * Open-counting is needed for pty masters, as well as for keeping > - * track of serial lines: DTR is dropped when the last close happens. > - * (This is not done solely through tty->count, now. - Ted 1/27/92) > - * > - * The termios state of a pty is reset on first open so that > - * settings don't persist across reuse. > - */ > -static int tty_open(struct inode * inode, struct file * filp) > -{ > - struct tty_struct *tty; > - int noctty, retval; > - struct tty_driver *driver; > - int index; > - dev_t device =3D inode->i_rdev; > - unsigned short saved_flags =3D filp->f_flags; > - > - nonseekable_open(inode, filp); > -=09 > -retry_open: > - noctty =3D filp->f_flags & O_NOCTTY; > - index =3D -1; > - retval =3D 0; > -=09 > - down(&tty_sem); > - > - if (device =3D=3D MKDEV(TTYAUX_MAJOR,0)) { > - if (!current->signal->tty) { > - up(&tty_sem); > - return -ENXIO; > - } > - driver =3D current->signal->tty->driver; > - index =3D current->signal->tty->index; > - filp->f_flags |=3D O_NONBLOCK; /* Don't let /dev/tty block */ > - /* noctty =3D 1; */ > - goto got_driver; > - } > -#ifdef CONFIG_VT > - if (console_use_vt && (device =3D=3D MKDEV(TTY_MAJOR,0))) { > - extern struct tty_driver *console_driver; > - driver =3D console_driver; > - index =3D fg_console; > - noctty =3D 1; > - goto got_driver; > - } > -#endif > - if (device =3D=3D MKDEV(TTYAUX_MAJOR,1)) { > - driver =3D console_device(&index); > - if (driver) { > - /* Don't let /dev/console block */ > - filp->f_flags |=3D O_NONBLOCK; > - noctty =3D 1; > - goto got_driver; > - } > - up(&tty_sem); > - return -ENODEV; > - } > - > - driver =3D get_tty_driver(device, &index); > - if (!driver) { > - up(&tty_sem); > - return -ENODEV; > - } > -got_driver: > - retval =3D init_dev(driver, index, &tty); > - up(&tty_sem); > - if (retval) > - return retval; > - > - filp->private_data =3D tty; > - file_move(filp, &tty->tty_files); > - check_tty_count(tty, "tty_open"); > - if (tty->driver->type =3D=3D TTY_DRIVER_TYPE_PTY && > - tty->driver->subtype =3D=3D PTY_TYPE_MASTER) > - noctty =3D 1; > -#ifdef TTY_DEBUG_HANGUP > - printk(KERN_DEBUG "opening %s...", tty->name); > -#endif > - if (!retval) { > - if (tty->driver->open) > - retval =3D tty->driver->open(tty, filp); > - else > - retval =3D -ENODEV; > - } > - filp->f_flags =3D saved_flags; > - > - if (!retval && test_bit(TTY_EXCLUSIVE, &tty->flags) && !capable(CAP_SYS= _ADMIN)) > - retval =3D -EBUSY; > - > - if (retval) { > -#ifdef TTY_DEBUG_HANGUP > - printk(KERN_DEBUG "error %d in opening %s...", retval, > - tty->name); > -#endif > - release_dev(filp); > - if (retval !=3D -ERESTARTSYS) > - return retval; > - if (signal_pending(current)) > - return retval; > - schedule(); > - /* > - * Need to reset f_op in case a hangup happened. > - */ > - if (filp->f_op =3D=3D &hung_up_tty_fops) > - filp->f_op =3D &tty_fops; > - goto retry_open; > - } > - if (!noctty && > - current->signal->leader && > - !current->signal->tty && > - tty->session =3D=3D 0) { > - task_lock(current); > - current->signal->tty =3D tty; > - task_unlock(current); > - current->signal->tty_old_pgrp =3D 0; > - tty->session =3D current->signal->session; > - tty->pgrp =3D process_group(current); > - } > - return 0; > -} > - > -#ifdef CONFIG_UNIX98_PTYS > -static int ptmx_open(struct inode * inode, struct file * filp) > -{ > - struct tty_struct *tty; > - int retval; > - int index; > - int idr_ret; > - > - nonseekable_open(inode, filp); > - > - /* find a device that is not in use. */ > - down(&allocated_ptys_lock); > - if (!idr_pre_get(&allocated_ptys, GFP_KERNEL)) { > - up(&allocated_ptys_lock); > - return -ENOMEM; > - } > - idr_ret =3D idr_get_new(&allocated_ptys, NULL, &index); > - if (idr_ret < 0) { > - up(&allocated_ptys_lock); > - if (idr_ret =3D=3D -EAGAIN) > - return -ENOMEM; > - return -EIO; > - } > - if (index >=3D pty_limit) { > - idr_remove(&allocated_ptys, index); > - up(&allocated_ptys_lock); > - return -EIO; > - } > - up(&allocated_ptys_lock); > - > - down(&tty_sem); > - retval =3D init_dev(ptm_driver, index, &tty); > - up(&tty_sem); > -=09 > - if (retval) > - goto out; > - > - set_bit(TTY_PTY_LOCK, &tty->flags); /* LOCK THE SLAVE */ > - filp->private_data =3D tty; > - file_move(filp, &tty->tty_files); > - > - retval =3D -ENOMEM; > - if (devpts_pty_new(tty->link)) > - goto out1; > - > - check_tty_count(tty, "tty_open"); > - retval =3D ptm_driver->open(tty, filp); > - if (!retval) > - return 0; > -out1: > - release_dev(filp); > -out: > - down(&allocated_ptys_lock); > - idr_remove(&allocated_ptys, index); > - up(&allocated_ptys_lock); > - return retval; > -} > -#endif > - > -static int tty_release(struct inode * inode, struct file * filp) > -{ > - lock_kernel(); > - release_dev(filp); > - unlock_kernel(); > - return 0; > -} > - > -/* No kernel lock held - fine */ > -static unsigned int tty_poll(struct file * filp, poll_table * wait) > -{ > - struct tty_struct * tty; > - struct tty_ldisc *ld; > - int ret =3D 0; > - > - tty =3D (struct tty_struct *)filp->private_data; > - if (tty_paranoia_check(tty, filp->f_dentry->d_inode, "tty_poll")) > - return 0; > - =09 > - ld =3D tty_ldisc_ref_wait(tty); > - if (ld->poll) > - ret =3D (ld->poll)(tty, filp, wait); > - tty_ldisc_deref(ld); > - return ret; > -} > - > -static int tty_fasync(int fd, struct file * filp, int on) > -{ > - struct tty_struct * tty; > - int retval; > - > - tty =3D (struct tty_struct *)filp->private_data; > - if (tty_paranoia_check(tty, filp->f_dentry->d_inode, "tty_fasync")) > - return 0; > -=09 > - retval =3D fasync_helper(fd, filp, on, &tty->fasync); > - if (retval <=3D 0) > - return retval; > - > - if (on) { > - if (!waitqueue_active(&tty->read_wait)) > - tty->minimum_to_wake =3D 1; > - retval =3D f_setown(filp, (-tty->pgrp) ? : current->pid, 0); > - if (retval) > - return retval; > - } else { > - if (!tty->fasync && !waitqueue_active(&tty->read_wait)) > - tty->minimum_to_wake =3D N_TTY_BUF_SIZE; > - } > - return 0; > -} > - > -static int tiocsti(struct tty_struct *tty, char __user *p) > -{ > - char ch, mbz =3D 0; > - struct tty_ldisc *ld; > -=09 > - if ((current->signal->tty !=3D tty) && !capable(CAP_SYS_ADMIN)) > - return -EPERM; > - if (get_user(ch, p)) > - return -EFAULT; > - ld =3D tty_ldisc_ref_wait(tty); > - ld->receive_buf(tty, &ch, &mbz, 1); > - tty_ldisc_deref(ld); > - return 0; > -} > - > -static int tiocgwinsz(struct tty_struct *tty, struct winsize __user * ar= g) > -{ > - if (copy_to_user(arg, &tty->winsize, sizeof(*arg))) > - return -EFAULT; > - return 0; > -} > - > -static int tiocswinsz(struct tty_struct *tty, struct tty_struct *real_tt= y, > - struct winsize __user * arg) > -{ > - struct winsize tmp_ws; > - > - if (copy_from_user(&tmp_ws, arg, sizeof(*arg))) > - return -EFAULT; > - if (!memcmp(&tmp_ws, &tty->winsize, sizeof(*arg))) > - return 0; > -#ifdef CONFIG_VT > - if (tty->driver->type =3D=3D TTY_DRIVER_TYPE_CONSOLE) { > - int rc; > - > - acquire_console_sem(); > - rc =3D vc_resize(tty->driver_data, tmp_ws.ws_col, tmp_ws.ws_row); > - release_console_sem(); > - if (rc) > - return -ENXIO; > - } > -#endif > - if (tty->pgrp > 0) > - kill_pg(tty->pgrp, SIGWINCH, 1); > - if ((real_tty->pgrp !=3D tty->pgrp) && (real_tty->pgrp > 0)) > - kill_pg(real_tty->pgrp, SIGWINCH, 1); > - tty->winsize =3D tmp_ws; > - real_tty->winsize =3D tmp_ws; > - return 0; > -} > - > -static int tioccons(struct file *file) > -{ > - if (!capable(CAP_SYS_ADMIN)) > - return -EPERM; > - if (file->f_op->write =3D=3D redirected_tty_write) { > - struct file *f; > - spin_lock(&redirect_lock); > - f =3D redirect; > - redirect =3D NULL; > - spin_unlock(&redirect_lock); > - if (f) > - fput(f); > - return 0; > - } > - spin_lock(&redirect_lock); > - if (redirect) { > - spin_unlock(&redirect_lock); > - return -EBUSY; > - } > - get_file(file); > - redirect =3D file; > - spin_unlock(&redirect_lock); > - return 0; > -} > - > - > -static int fionbio(struct file *file, int __user *p) > -{ > - int nonblock; > - > - if (get_user(nonblock, p)) > - return -EFAULT; > - > - if (nonblock) > - file->f_flags |=3D O_NONBLOCK; > - else > - file->f_flags &=3D ~O_NONBLOCK; > - return 0; > -} > - > -static int tiocsctty(struct tty_struct *tty, int arg) > -{ > - task_t *p; > - > - if (current->signal->leader && > - (current->signal->session =3D=3D tty->session)) > - return 0; > - /* > - * The process must be a session leader and > - * not have a controlling tty already. > - */ > - if (!current->signal->leader || current->signal->tty) > - return -EPERM; > - if (tty->session > 0) { > - /* > - * This tty is already the controlling > - * tty for another session group! > - */ > - if ((arg =3D=3D 1) && capable(CAP_SYS_ADMIN)) { > - /* > - * Steal it away > - */ > - > - read_lock(&tasklist_lock); > - do_each_task_pid(tty->session, PIDTYPE_SID, p) { > - p->signal->tty =3D NULL; > - } while_each_task_pid(tty->session, PIDTYPE_SID, p); > - read_unlock(&tasklist_lock); > - } else > - return -EPERM; > - } > - task_lock(current); > - current->signal->tty =3D tty; > - task_unlock(current); > - current->signal->tty_old_pgrp =3D 0; > - tty->session =3D current->signal->session; > - tty->pgrp =3D process_group(current); > - return 0; > -} > - > -static int tiocgpgrp(struct tty_struct *tty, struct tty_struct *real_tty= , pid_t __user *p) > -{ > - /* > - * (tty =3D=3D real_tty) is a cheap way of > - * testing if the tty is NOT a master pty. > - */ > - if (tty =3D=3D real_tty && current->signal->tty !=3D real_tty) > - return -ENOTTY; > - return put_user(real_tty->pgrp, p); > -} > - > -static int tiocspgrp(struct tty_struct *tty, struct tty_struct *real_tty= , pid_t __user *p) > -{ > - pid_t pgrp; > - int retval =3D tty_check_change(real_tty); > - > - if (retval =3D=3D -EIO) > - return -ENOTTY; > - if (retval) > - return retval; > - if (!current->signal->tty || > - (current->signal->tty !=3D real_tty) || > - (real_tty->session !=3D current->signal->session)) > - return -ENOTTY; > - if (get_user(pgrp, p)) > - return -EFAULT; > - if (pgrp < 0) > - return -EINVAL; > - if (session_of_pgrp(pgrp) !=3D current->signal->session) > - return -EPERM; > - real_tty->pgrp =3D pgrp; > - return 0; > -} > - > -static int tiocgsid(struct tty_struct *tty, struct tty_struct *real_tty,= pid_t __user *p) > -{ > - /* > - * (tty =3D=3D real_tty) is a cheap way of > - * testing if the tty is NOT a master pty. > - */ > - if (tty =3D=3D real_tty && current->signal->tty !=3D real_tty) > - return -ENOTTY; > - if (real_tty->session <=3D 0) > - return -ENOTTY; > - return put_user(real_tty->session, p); > -} > - > -static int tiocsetd(struct tty_struct *tty, int __user *p) > -{ > - int ldisc; > - > - if (get_user(ldisc, p)) > - return -EFAULT; > - return tty_set_ldisc(tty, ldisc); > -} > - > -static int send_break(struct tty_struct *tty, unsigned int duration) > -{ > - tty->driver->break_ctl(tty, -1); > - if (!signal_pending(current)) { > - msleep_interruptible(duration); > - } > - tty->driver->break_ctl(tty, 0); > - if (signal_pending(current)) > - return -EINTR; > - return 0; > -} > - > -static int > -tty_tiocmget(struct tty_struct *tty, struct file *file, int __user *p) > -{ > - int retval =3D -EINVAL; > - > - if (tty->driver->tiocmget) { > - retval =3D tty->driver->tiocmget(tty, file); > - > - if (retval >=3D 0) > - retval =3D put_user(retval, p); > - } > - return retval; > -} > - > -static int > -tty_tiocmset(struct tty_struct *tty, struct file *file, unsigned int cmd, > - unsigned __user *p) > -{ > - int retval =3D -EINVAL; > - > - if (tty->driver->tiocmset) { > - unsigned int set, clear, val; > - > - retval =3D get_user(val, p); > - if (retval) > - return retval; > - > - set =3D clear =3D 0; > - switch (cmd) { > - case TIOCMBIS: > - set =3D val; > - break; > - case TIOCMBIC: > - clear =3D val; > - break; > - case TIOCMSET: > - set =3D val; > - clear =3D ~val; > - break; > - } > - > - set &=3D TIOCM_DTR|TIOCM_RTS|TIOCM_OUT1|TIOCM_OUT2|TIOCM_LOOP; > - clear &=3D TIOCM_DTR|TIOCM_RTS|TIOCM_OUT1|TIOCM_OUT2|TIOCM_LOOP; > - > - retval =3D tty->driver->tiocmset(tty, file, set, clear); > - } > - return retval; > -} > - > -/* > - * Split this up, as gcc can choke on it otherwise.. > - */ > -int tty_ioctl(struct inode * inode, struct file * file, > - unsigned int cmd, unsigned long arg) > -{ > - struct tty_struct *tty, *real_tty; > - void __user *p =3D (void __user *)arg; > - int retval; > - struct tty_ldisc *ld; > -=09 > - tty =3D (struct tty_struct *)file->private_data; > - if (tty_paranoia_check(tty, inode, "tty_ioctl")) > - return -EINVAL; > - > - real_tty =3D tty; > - if (tty->driver->type =3D=3D TTY_DRIVER_TYPE_PTY && > - tty->driver->subtype =3D=3D PTY_TYPE_MASTER) > - real_tty =3D tty->link; > - > - /* > - * Break handling by driver > - */ > - if (!tty->driver->break_ctl) { > - switch(cmd) { > - case TIOCSBRK: > - case TIOCCBRK: > - if (tty->driver->ioctl) > - return tty->driver->ioctl(tty, file, cmd, arg); > - return -EINVAL; > - =09 > - /* These two ioctl's always return success; even if */ > - /* the driver doesn't support them. */ > - case TCSBRK: > - case TCSBRKP: > - if (!tty->driver->ioctl) > - return 0; > - retval =3D tty->driver->ioctl(tty, file, cmd, arg); > - if (retval =3D=3D -ENOIOCTLCMD) > - retval =3D 0; > - return retval; > - } > - } > - > - /* > - * Factor out some common prep work > - */ > - switch (cmd) { > - case TIOCSETD: > - case TIOCSBRK: > - case TIOCCBRK: > - case TCSBRK: > - case TCSBRKP: =09 > - retval =3D tty_check_change(tty); > - if (retval) > - return retval; > - if (cmd !=3D TIOCCBRK) { > - tty_wait_until_sent(tty, 0); > - if (signal_pending(current)) > - return -EINTR; > - } > - break; > - } > - > - switch (cmd) { > - case TIOCSTI: > - return tiocsti(tty, p); > - case TIOCGWINSZ: > - return tiocgwinsz(tty, p); > - case TIOCSWINSZ: > - return tiocswinsz(tty, real_tty, p); > - case TIOCCONS: > - return real_tty!=3Dtty ? -EINVAL : tioccons(file); > - case FIONBIO: > - return fionbio(file, p); > - case TIOCEXCL: > - set_bit(TTY_EXCLUSIVE, &tty->flags); > - return 0; > - case TIOCNXCL: > - clear_bit(TTY_EXCLUSIVE, &tty->flags); > - return 0; > - case TIOCNOTTY: > - if (current->signal->tty !=3D tty) > - return -ENOTTY; > - if (current->signal->leader) > - disassociate_ctty(0); > - task_lock(current); > - current->signal->tty =3D NULL; > - task_unlock(current); > - return 0; > - case TIOCSCTTY: > - return tiocsctty(tty, arg); > - case TIOCGPGRP: > - return tiocgpgrp(tty, real_tty, p); > - case TIOCSPGRP: > - return tiocspgrp(tty, real_tty, p); > - case TIOCGSID: > - return tiocgsid(tty, real_tty, p); > - case TIOCGETD: > - /* FIXME: check this is ok */ > - return put_user(tty->ldisc.num, (int __user *)p); > - case TIOCSETD: > - return tiocsetd(tty, p); > -#ifdef CONFIG_VT > - case TIOCLINUX: > - return tioclinux(tty, arg); > -#endif > - /* > - * Break handling > - */ > - case TIOCSBRK: /* Turn break on, unconditionally */ > - tty->driver->break_ctl(tty, -1); > - return 0; > - =09 > - case TIOCCBRK: /* Turn break off, unconditionally */ > - tty->driver->break_ctl(tty, 0); > - return 0; > - case TCSBRK: /* SVID version: non-zero arg --> no break */ > - /* > - * XXX is the above comment correct, or the > - * code below correct? Is this ioctl used at > - * all by anyone? > - */ > - if (!arg) > - return send_break(tty, 250); > - return 0; > - case TCSBRKP: /* support for POSIX tcsendbreak() */=09 > - return send_break(tty, arg ? arg*100 : 250); > - > - case TIOCMGET: > - return tty_tiocmget(tty, file, p); > - > - case TIOCMSET: > - case TIOCMBIC: > - case TIOCMBIS: > - return tty_tiocmset(tty, file, cmd, p); > - } > - if (tty->driver->ioctl) { > - retval =3D (tty->driver->ioctl)(tty, file, cmd, arg); > - if (retval !=3D -ENOIOCTLCMD) > - return retval; > - } > - ld =3D tty_ldisc_ref_wait(tty); > - retval =3D -EINVAL; > - if (ld->ioctl) { > - retval =3D ld->ioctl(tty, file, cmd, arg); > - if (retval =3D=3D -ENOIOCTLCMD) > - retval =3D -EINVAL; > - } > - tty_ldisc_deref(ld); > - return retval; > -} > - > - > -/* > - * This implements the "Secure Attention Key" --- the idea is to > - * prevent trojan horses by killing all processes associated with this > - * tty when the user hits the "Secure Attention Key". Required for > - * super-paranoid applications --- see the Orange Book for more details. > - *=20 > - * This code could be nicer; ideally it should send a HUP, wait a few > - * seconds, then send a INT, and then a KILL signal. But you then > - * have to coordinate with the init process, since all processes associa= ted > - * with the current tty must be dead before the new getty is allowed > - * to spawn. > - * > - * Now, if it would be correct ;-/ The current code has a nasty hole - > - * it doesn't catch files in flight. We may send the descriptor to ourse= lves > - * via AF_UNIX socket, close it and later fetch from socket. FIXME. > - * > - * Nasty bug: do_SAK is being called in interrupt context. This can > - * deadlock. We punt it up to process context. AKPM - 16Mar2001 > - */ > -static void __do_SAK(void *arg) > -{ > -#ifdef TTY_SOFT_SAK > - tty_hangup(tty); > -#else > - struct tty_struct *tty =3D arg; > - struct task_struct *p; > - int session; > - int i; > - struct file *filp; > - struct tty_ldisc *disc; > - struct fdtable *fdt; > -=09 > - if (!tty) > - return; > - session =3D tty->session; > -=09 > - /* We don't want an ldisc switch during this */ > - disc =3D tty_ldisc_ref(tty); > - if (disc && disc->flush_buffer) > - disc->flush_buffer(tty); > - tty_ldisc_deref(disc); > - > - if (tty->driver->flush_buffer) > - tty->driver->flush_buffer(tty); > -=09 > - read_lock(&tasklist_lock); > - do_each_task_pid(session, PIDTYPE_SID, p) { > - if (p->signal->tty =3D=3D tty || session > 0) { > - printk(KERN_NOTICE "SAK: killed process %d" > - " (%s): p->signal->session=3D=3Dtty->session\n", > - p->pid, p->comm); > - send_sig(SIGKILL, p, 1); > - continue; > - } > - task_lock(p); > - if (p->files) { > - /* > - * We don't take a ref to the file, so we must > - * hold ->file_lock instead. > - */ > - spin_lock(&p->files->file_lock); > - fdt =3D files_fdtable(p->files); > - for (i=3D0; i < fdt->max_fds; i++) { > - filp =3D fcheck_files(p->files, i); > - if (!filp) > - continue; > - if (filp->f_op->read =3D=3D tty_read && > - filp->private_data =3D=3D tty) { > - printk(KERN_NOTICE "SAK: killed process %d" > - " (%s): fd#%d opened to the tty\n", > - p->pid, p->comm, i); > - send_sig(SIGKILL, p, 1); > - break; > - } > - } > - spin_unlock(&p->files->file_lock); > - } > - task_unlock(p); > - } while_each_task_pid(session, PIDTYPE_SID, p); > - read_unlock(&tasklist_lock); > -#endif > -} > - > -/* > - * The tq handling here is a little racy - tty->SAK_work may already be = queued. > - * Fortunately we don't need to worry, because if ->SAK_work is already = queued, > - * the values which we write to it will be identical to the values which= it > - * already has. --akpm > - */ > -void do_SAK(struct tty_struct *tty) > -{ > - if (!tty) > - return; > - PREPARE_WORK(&tty->SAK_work, __do_SAK, tty); > - schedule_work(&tty->SAK_work); > -} > - > -EXPORT_SYMBOL(do_SAK); > - > -/* > - * This routine is called out of the software interrupt to flush data > - * from the buffer chain to the line discipline. > - */ > -=20 > -static void flush_to_ldisc(void *private_) > -{ > - struct tty_struct *tty =3D (struct tty_struct *) private_; > - unsigned long flags; > - struct tty_ldisc *disc; > - struct tty_buffer *tbuf, *head; > - int count; > - char *char_buf; > - unsigned char *flag_buf; > - > - disc =3D tty_ldisc_ref(tty); > - if (disc =3D=3D NULL) /* !TTY_LDISC */ > - return; > - > - if (test_bit(TTY_DONT_FLIP, &tty->flags)) { > - /* > - * Do it after the next timer tick: > - */ > - schedule_delayed_work(&tty->buf.work, 1); > - goto out; > - } > - spin_lock_irqsave(&tty->buf.lock, flags); > - head =3D tty->buf.head; > - tty->buf.head =3D NULL; > - while((tbuf =3D head) !=3D NULL) { > - while ((count =3D tbuf->commit - tbuf->read) !=3D 0) { > - char_buf =3D tbuf->char_buf_ptr + tbuf->read; > - flag_buf =3D tbuf->flag_buf_ptr + tbuf->read; > - tbuf->read +=3D count; > - spin_unlock_irqrestore(&tty->buf.lock, flags); > - disc->receive_buf(tty, char_buf, flag_buf, count); > - spin_lock_irqsave(&tty->buf.lock, flags); > - } > - if (tbuf->active) { > - tty->buf.head =3D head; > - break; > - } > - head =3D tbuf->next; > - if (head =3D=3D NULL) > - tty->buf.tail =3D NULL; > - tty_buffer_free(tty, tbuf); > - } > - spin_unlock_irqrestore(&tty->buf.lock, flags); > -out: > - tty_ldisc_deref(disc); > -} > - > -/* > - * Routine which returns the baud rate of the tty > - * > - * Note that the baud_table needs to be kept in sync with the > - * include/asm/termbits.h file. > - */ > -static int baud_table[] =3D { > - 0, 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800, > - 9600, 19200, 38400, 57600, 115200, 230400, 460800, > -#ifdef __sparc__ > - 76800, 153600, 307200, 614400, 921600 > -#else > - 500000, 576000, 921600, 1000000, 1152000, 1500000, 2000000, > - 2500000, 3000000, 3500000, 4000000 > -#endif > -}; > - > -static int n_baud_table =3D ARRAY_SIZE(baud_table); > - > -/** > - * tty_termios_baud_rate > - * @termios: termios structure > - * > - * Convert termios baud rate data into a speed. This should be called > - * with the termios lock held if this termios is a terminal termios > - * structure. May change the termios data. > - */ > -=20 > -int tty_termios_baud_rate(struct termios *termios) > -{ > - unsigned int cbaud; > -=09 > - cbaud =3D termios->c_cflag & CBAUD; > - > - if (cbaud & CBAUDEX) { > - cbaud &=3D ~CBAUDEX; > - > - if (cbaud < 1 || cbaud + 15 > n_baud_table) > - termios->c_cflag &=3D ~CBAUDEX; > - else > - cbaud +=3D 15; > - } > - return baud_table[cbaud]; > -} > - > -EXPORT_SYMBOL(tty_termios_baud_rate); > - > -/** > - * tty_get_baud_rate - get tty bit rates > - * @tty: tty to query > - * > - * Returns the baud rate as an integer for this terminal. The > - * termios lock must be held by the caller and the terminal bit > - * flags may be updated. > - */ > -=20 > -int tty_get_baud_rate(struct tty_struct *tty) > -{ > - int baud =3D tty_termios_baud_rate(tty->termios); > - > - if (baud =3D=3D 38400 && tty->alt_speed) { > - if (!tty->warned) { > - printk(KERN_WARNING "Use of setserial/setrocket to " > - "set SPD_* flags is deprecated\n"); > - tty->warned =3D 1; > - } > - baud =3D tty->alt_speed; > - } > -=09 > - return baud; > -} > - > -EXPORT_SYMBOL(tty_get_baud_rate); > - > -/** > - * tty_flip_buffer_push - terminal > - * @tty: tty to push > - * > - * Queue a push of the terminal flip buffers to the line discipline. This > - * function must not be called from IRQ context if tty->low_latency is s= et. > - * > - * In the event of the queue being busy for flipping the work will be > - * held off and retried later. > - */ > - > -void tty_flip_buffer_push(struct tty_struct *tty) > -{ > - unsigned long flags; > - spin_lock_irqsave(&tty->buf.lock, flags); > - if (tty->buf.tail !=3D NULL) { > - tty->buf.tail->active =3D 0; > - tty->buf.tail->commit =3D tty->buf.tail->used; > - } > - spin_unlock_irqrestore(&tty->buf.lock, flags); > - > - if (tty->low_latency) > - flush_to_ldisc((void *) tty); > - else > - schedule_delayed_work(&tty->buf.work, 1); > -} > - > -EXPORT_SYMBOL(tty_flip_buffer_push); > - > - > -/* > - * This subroutine initializes a tty structure. > - */ > -static void initialize_tty_struct(struct tty_struct *tty) > -{ > - memset(tty, 0, sizeof(struct tty_struct)); > - tty->magic =3D TTY_MAGIC; > - tty_ldisc_assign(tty, tty_ldisc_get(N_TTY)); > - tty->pgrp =3D -1; > - tty->overrun_time =3D jiffies; > - tty->buf.head =3D tty->buf.tail =3D NULL; > - tty_buffer_init(tty); > - INIT_WORK(&tty->buf.work, flush_to_ldisc, tty); > - init_MUTEX(&tty->buf.pty_sem); > - init_MUTEX(&tty->termios_sem); > - init_waitqueue_head(&tty->write_wait); > - init_waitqueue_head(&tty->read_wait); > - INIT_WORK(&tty->hangup_work, do_tty_hangup, tty); > - sema_init(&tty->atomic_read, 1); > - sema_init(&tty->atomic_write, 1); > - spin_lock_init(&tty->read_lock); > - INIT_LIST_HEAD(&tty->tty_files); > - INIT_WORK(&tty->SAK_work, NULL, NULL); > -} > - > -/* > - * The default put_char routine if the driver did not define one. > - */ > -static void tty_default_put_char(struct tty_struct *tty, unsigned char c= h) > -{ > - tty->driver->write(tty, &ch, 1); > -} > - > -static struct class *tty_class; > - > -/** > - * tty_register_device - register a tty device > - * @driver: the tty driver that describes the tty device > - * @index: the index in the tty driver for this tty device > - * @device: a struct device that is associated with this tty device. > - * This field is optional, if there is no known struct device for this > - * tty device it can be set to NULL safely. > - * > - * This call is required to be made to register an individual tty device= if > - * the tty driver's flags have the TTY_DRIVER_NO_DEVFS bit set. If that > - * bit is not set, this function should not be called. > - */ > -void tty_register_device(struct tty_driver *driver, unsigned index, > - struct device *device) > -{ > - char name[64]; > - dev_t dev =3D MKDEV(driver->major, driver->minor_start) + index; > - > - if (index >=3D driver->num) { > - printk(KERN_ERR "Attempt to register invalid tty line number " > - " (%d).\n", index); > - return; > - } > - > - devfs_mk_cdev(dev, S_IFCHR | S_IRUSR | S_IWUSR, > - "%s%d", driver->devfs_name, index + driver->name_base); > - > - if (driver->type =3D=3D TTY_DRIVER_TYPE_PTY) > - pty_line_name(driver, index, name); > - else > - tty_line_name(driver, index, name); > - class_device_create(tty_class, NULL, dev, device, "%s", name); > -} > - > -/** > - * tty_unregister_device - unregister a tty device > - * @driver: the tty driver that describes the tty device > - * @index: the index in the tty driver for this tty device > - * > - * If a tty device is registered with a call to tty_register_device() th= en > - * this function must be made when the tty device is gone. > - */ > -void tty_unregister_device(struct tty_driver *driver, unsigned index) > -{ > - devfs_remove("%s%d", driver->devfs_name, index + driver->name_base); > - class_device_destroy(tty_class, MKDEV(driver->major, driver->minor_star= t) + index); > -} > - > -EXPORT_SYMBOL(tty_register_device); > -EXPORT_SYMBOL(tty_unregister_device); > - > -struct tty_driver *alloc_tty_driver(int lines) > -{ > - struct tty_driver *driver; > - > - driver =3D kmalloc(sizeof(struct tty_driver), GFP_KERNEL); > - if (driver) { > - memset(driver, 0, sizeof(struct tty_driver)); > - driver->magic =3D TTY_DRIVER_MAGIC; > - driver->num =3D lines; > - /* later we'll move allocation of tables here */ > - } > - return driver; > -} > - > -void put_tty_driver(struct tty_driver *driver) > -{ > - kfree(driver); > -} > - > -void tty_set_operations(struct tty_driver *driver, struct tty_operations= *op) > -{ > - driver->open =3D op->open; > - driver->close =3D op->close; > - driver->write =3D op->write; > - driver->put_char =3D op->put_char; > - driver->flush_chars =3D op->flush_chars; > - driver->write_room =3D op->write_room; > - driver->chars_in_buffer =3D op->chars_in_buffer; > - driver->ioctl =3D op->ioctl; > - driver->set_termios =3D op->set_termios; > - driver->throttle =3D op->throttle; > - driver->unthrottle =3D op->unthrottle; > - driver->stop =3D op->stop; > - driver->start =3D op->start; > - driver->hangup =3D op->hangup; > - driver->break_ctl =3D op->break_ctl; > - driver->flush_buffer =3D op->flush_buffer; > - driver->set_ldisc =3D op->set_ldisc; > - driver->wait_until_sent =3D op->wait_until_sent; > - driver->send_xchar =3D op->send_xchar; > - driver->read_proc =3D op->read_proc; > - driver->write_proc =3D op->write_proc; > - driver->tiocmget =3D op->tiocmget; > - driver->tiocmset =3D op->tiocmset; > -} > - > - > -EXPORT_SYMBOL(alloc_tty_driver); > -EXPORT_SYMBOL(put_tty_driver); > -EXPORT_SYMBOL(tty_set_operations); > - > -/* > - * Called by a tty driver to register itself. > - */ > -int tty_register_driver(struct tty_driver *driver) > -{ > - int error; > - int i; > - dev_t dev; > - void **p =3D NULL; > - > - if (driver->flags & TTY_DRIVER_INSTALLED) > - return 0; > - > - if (!(driver->flags & TTY_DRIVER_DEVPTS_MEM)) { > - p =3D kmalloc(driver->num * 3 * sizeof(void *), GFP_KERNEL); > - if (!p) > - return -ENOMEM; > - memset(p, 0, driver->num * 3 * sizeof(void *)); > - } > - > - if (!driver->major) { > - error =3D alloc_chrdev_region(&dev, driver->minor_start, driver->num, > - (char*)driver->name); > - if (!error) { > - driver->major =3D MAJOR(dev); > - driver->minor_start =3D MINOR(dev); > - } > - } else { > - dev =3D MKDEV(driver->major, driver->minor_start); > - error =3D register_chrdev_region(dev, driver->num, > - (char*)driver->name); > - } > - if (error < 0) { > - kfree(p); > - return error; > - } > - > - if (p) { > - driver->ttys =3D (struct tty_struct **)p; > - driver->termios =3D (struct termios **)(p + driver->num); > - driver->termios_locked =3D (struct termios **)(p + driver->num * 2); > - } else { > - driver->ttys =3D NULL; > - driver->termios =3D NULL; > - driver->termios_locked =3D NULL; > - } > - > - cdev_init(&driver->cdev, &tty_fops); > - driver->cdev.owner =3D driver->owner; > - error =3D cdev_add(&driver->cdev, dev, driver->num); > - if (error) { > - cdev_del(&driver->cdev); > - unregister_chrdev_region(dev, driver->num); > - driver->ttys =3D NULL; > - driver->termios =3D driver->termios_locked =3D NULL; > - kfree(p); > - return error; > - } > - > - if (!driver->put_char) > - driver->put_char =3D tty_default_put_char; > -=09 > - list_add(&driver->tty_drivers, &tty_drivers); > -=09 > - if ( !(driver->flags & TTY_DRIVER_NO_DEVFS) ) { > - for(i =3D 0; i < driver->num; i++) > - tty_register_device(driver, i, NULL); > - } > - proc_tty_register_driver(driver); > - return 0; > -} > - > -EXPORT_SYMBOL(tty_register_driver); > - > -/* > - * Called by a tty driver to unregister itself. > - */ > -int tty_unregister_driver(struct tty_driver *driver) > -{ > - int i; > - struct termios *tp; > - void *p; > - > - if (driver->refcount) > - return -EBUSY; > - > - unregister_chrdev_region(MKDEV(driver->major, driver->minor_start), > - driver->num); > - > - list_del(&driver->tty_drivers); > - > - /* > - * Free the termios and termios_locked structures because > - * we don't want to get memory leaks when modular tty > - * drivers are removed from the kernel. > - */ > - for (i =3D 0; i < driver->num; i++) { > - tp =3D driver->termios[i]; > - if (tp) { > - driver->termios[i] =3D NULL; > - kfree(tp); > - } > - tp =3D driver->termios_locked[i]; > - if (tp) { > - driver->termios_locked[i] =3D NULL; > - kfree(tp); > - } > - if (!(driver->flags & TTY_DRIVER_NO_DEVFS)) > - tty_unregister_device(driver, i); > - } > - p =3D driver->ttys; > - proc_tty_unregister_driver(driver); > - driver->ttys =3D NULL; > - driver->termios =3D driver->termios_locked =3D NULL; > - kfree(p); > - cdev_del(&driver->cdev); > - return 0; > -} > - > -EXPORT_SYMBOL(tty_unregister_driver); > - > - > -/* > - * Initialize the console device. This is called *early*, so > - * we can't necessarily depend on lots of kernel help here. > - * Just do some early initializations, and do the complex setup > - * later. > - */ > -void __init console_init(void) > -{ > - initcall_t *call; > - > - /* Setup the default TTY line discipline. */ > - (void) tty_register_ldisc(N_TTY, &tty_ldisc_N_TTY); > - > - /* > - * set up the console device so that later boot sequences can=20 > - * inform about problems etc.. > - */ > -#ifdef CONFIG_EARLY_PRINTK > - disable_early_printk(); > -#endif > - call =3D __con_initcall_start; > - while (call < __con_initcall_end) { > - (*call)(); > - call++; > - } > -} > - > -#ifdef CONFIG_VT > -extern int vty_init(void); > -#endif > - > -static int __init tty_class_init(void) > -{ > - tty_class =3D class_create(THIS_MODULE, "tty"); > - if (IS_ERR(tty_class)) > - return PTR_ERR(tty_class); > - return 0; > -} > - > -postcore_initcall(tty_class_init); > - > -/* 3/2004 jmc: why do these devices exist? */ > - > -static struct cdev tty_cdev, console_cdev; > -#ifdef CONFIG_UNIX98_PTYS > -static struct cdev ptmx_cdev; > -#endif > -#ifdef CONFIG_VT > -static struct cdev vc0_cdev; > -#endif > - > -/* > - * Ok, now we can initialize the rest of the tty devices and can count > - * on memory allocations, interrupts etc.. > - */ > -static int __init tty_init(void) > -{ > - cdev_init(&tty_cdev, &tty_fops); > - if (cdev_add(&tty_cdev, MKDEV(TTYAUX_MAJOR, 0), 1) || > - register_chrdev_region(MKDEV(TTYAUX_MAJOR, 0), 1, "/dev/tty") < 0) > - panic("Couldn't register /dev/tty driver\n"); > - devfs_mk_cdev(MKDEV(TTYAUX_MAJOR, 0), S_IFCHR|S_IRUGO|S_IWUGO, "tty"); > - class_device_create(tty_class, NULL, MKDEV(TTYAUX_MAJOR, 0), NULL, "tty= "); > - > - cdev_init(&console_cdev, &console_fops); > - if (cdev_add(&console_cdev, MKDEV(TTYAUX_MAJOR, 1), 1) || > - register_chrdev_region(MKDEV(TTYAUX_MAJOR, 1), 1, "/dev/console") <= 0) > - panic("Couldn't register /dev/console driver\n"); > - devfs_mk_cdev(MKDEV(TTYAUX_MAJOR, 1), S_IFCHR|S_IRUSR|S_IWUSR, "console= "); > - class_device_create(tty_class, NULL, MKDEV(TTYAUX_MAJOR, 1), NULL, "con= sole"); > - > -#ifdef CONFIG_UNIX98_PTYS > - cdev_init(&ptmx_cdev, &ptmx_fops); > - if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) || > - register_chrdev_region(MKDEV(TTYAUX_MAJOR, 2), 1, "/dev/ptmx") < 0) > - panic("Couldn't register /dev/ptmx driver\n"); > - devfs_mk_cdev(MKDEV(TTYAUX_MAJOR, 2), S_IFCHR|S_IRUGO|S_IWUGO, "ptmx"); > - class_device_create(tty_class, NULL, MKDEV(TTYAUX_MAJOR, 2), NULL, "ptm= x"); > -#endif > - > -#ifdef CONFIG_VT > - if (!console_use_vt) > - goto out_vt; > - cdev_init(&vc0_cdev, &console_fops); > - if (cdev_add(&vc0_cdev, MKDEV(TTY_MAJOR, 0), 1) || > - register_chrdev_region(MKDEV(TTY_MAJOR, 0), 1, "/dev/vc/0") < 0) > - panic("Couldn't register /dev/tty0 driver\n"); > - devfs_mk_cdev(MKDEV(TTY_MAJOR, 0), S_IFCHR|S_IRUSR|S_IWUSR, "vc/0"); > - class_device_create(tty_class, NULL, MKDEV(TTY_MAJOR, 0), NULL, "tty0"); > - > - vty_init(); > - out_vt: > -#endif > - return 0; > -} > -module_init(tty_init); >=20 > _______________________________________________ > Xen-devel mailing list > Xen-devel@lists.xensource.com > http://lists.xensource.com/xen-devel --7AUc2qLy4jB3hD7Z Content-Type: application/pgp-signature; name="signature.asc" Content-Description: Digital signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.5 (GNU/Linux) iD8DBQFFcC1VO4S8/gLNrjcRAoXXAKDaf9HophN1wtnXCSHq6xXKg3i27QCfZW/F Pj7VDMNLFuF3hgnuSETKmw0= =r6+r -----END PGP SIGNATURE----- --7AUc2qLy4jB3hD7Z-- --===============0729841930== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel --===============0729841930==--