From mboxrd@z Thu Jan 1 00:00:00 1970 From: Laurent Vivier Subject: Re: [PATCH 1/2] Virtual frame buffer: frontend Date: Fri, 28 Jul 2006 15:52:58 +0200 Message-ID: <44CA16BA.5050702@bull.net> References: <87ac80ghox.fsf@pike.pond.sub.org> <8764ioghnn.fsf@pike.pond.sub.org> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="===============0600018649==" Return-path: In-Reply-To: <8764ioghnn.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 List-Id: xen-devel@lists.xenproject.org This is an OpenPGP/MIME signed message (RFC 2440 and 3156) --===============0600018649== Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="------------enigB7E13ADA5D07CCBD8773DB5C" This is an OpenPGP/MIME signed message (RFC 2440 and 3156) --------------enigB7E13ADA5D07CCBD8773DB5C Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Hi, my domain hangs when I load xenfb module. The sequence is: dom0# sdlfb =2E.. domU# modprobe fbcon domU# modprobe xenkbd domU# modprobe xenfb =2E.. HANGS HERE .... I found that it hangs in xenfb_event_handler() because info->page->in_pro= d and info->page->in_cons are not initialized correctly. I propose following correction: Index: xen-3.0-testing.hg/linux-2.6.16.13-xen/drivers/xen/xenfb/xenfb.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- xen-3.0-testing.hg.orig/linux-2.6.16.13-xen/drivers/xen/xenfb/xenfb.c= 2006-07-28 12:58:47.000000000 +0200 +++ xen-3.0-testing.hg/linux-2.6.16.13-xen/drivers/xen/xenfb/xenfb.c 2006-07-28 15:28:23.000000000 +0200 @@ -414,6 +414,8 @@ info->page->depth =3D 32; 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; ret =3D bind_evtchn_to_irqhandler(info->evtchn, xenfb_event_handl= er, 0, "xenfb", info); Regards, Laurent Markus Armbruster wrote: > Derived from > http://www.cs.utexas.edu/users/aliguori/vfb-20060124.bundle >=20 > Converted to Xenstore and ported to current kernels. >=20 > Signed-off-by: Markus Armbruster >=20 >=20 > diff -r d8434a6fdd05 arch/i386/kernel/setup-xen.c > --- a/arch/i386/kernel/setup-xen.c Fri Jun 16 19:34:13 2006 +0200 > +++ b/arch/i386/kernel/setup-xen.c Fri Jun 23 10:07:51 2006 +0200 > @@ -1787,8 +1787,12 @@ void __init setup_arch(char **cmdline_p) > #endif > #endif > } else { > +#if defined(CONFIG_VT) && defined(CONFIG_DUMMY_CONSOLE) > + conswitchp =3D &dummy_con; > +#else > extern int console_use_vt; > console_use_vt =3D 0; > +#endif > } > } > =20 > diff -r d8434a6fdd05 drivers/xen/Kconfig > --- a/drivers/xen/Kconfig Fri Jun 16 19:34:13 2006 +0200 > +++ b/drivers/xen/Kconfig Fri Jun 23 10:07:51 2006 +0200 > @@ -173,6 +173,29 @@ config XEN_BLKDEV_TAP > to a character device, allowing device prototyping in application > space. Odds are that you want to say N 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 > + 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 d8434a6fdd05 drivers/xen/Makefile > --- a/drivers/xen/Makefile Fri Jun 16 19:34:13 2006 +0200 > +++ b/drivers/xen/Makefile Fri Jun 23 10:07:51 2006 +0200 > @@ -15,3 +15,5 @@ obj-$(CONFIG_XEN_BLKDEV_TAP) +=3D blkt > obj-$(CONFIG_XEN_BLKDEV_TAP) +=3D blktap/ > obj-$(CONFIG_XEN_PCIDEV_BACKEND) +=3D pciback/ > obj-$(CONFIG_XEN_PCIDEV_FRONTEND) +=3D pcifront/ > +obj-$(CONFIG_XEN_FRAMEBUFFER) +=3D xenfb/ > +obj-$(CONFIG_XEN_KEYBOARD) +=3D xenkbd/ > diff -r d8434a6fdd05 drivers/xen/xenfb/Makefile > --- /dev/null Thu Jan 01 00:00:00 1970 +0000 > +++ b/drivers/xen/xenfb/Makefile Fri Jun 23 10:07:51 2006 +0200 > @@ -0,0 +1,1 @@ > +obj-$(CONFIG_XEN_FRAMEBUFFER) :=3D xenfb.o > diff -r d8434a6fdd05 drivers/xen/xenfb/xenfb.c > --- /dev/null Thu Jan 01 00:00:00 1970 +0000 > +++ b/drivers/xen/xenfb/xenfb.c Fri Jun 23 10:07:51 2006 +0200 > @@ -0,0 +1,579 @@ > +/* > + * linux/drivers/video/xenfb.c -- Xen para-virtual frame buffer device= > + * > + * Copyright (C) 2005-2006 > + * > + * Anthony Liguori > + * > + * Based on linux/drivers/video/q40fb.c > + * > + * This file is subject to the terms and conditions of the GNU Genera= l Public > + * License. See the file COPYING in the main directory of this archiv= e for > + * more details. > + */ > + > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > + > +static int xenfb_fps =3D 20; > +static unsigned long xenfb_mem_len =3D 2 * 1024 * 1024; > + > +struct xenfb_mapping > +{ > + struct list_head next; > + 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_fix_screeninfo *fix; > + struct fb_var_screeninfo *var; > + struct fb_info *fb_info; > + struct timer_list refresh; > + int dirty; > + int y1, y2; > + int x1, x2; > + > + struct semaphore mm_lock; > + int nr_pages; > + struct page **pages; > + struct list_head mappings; > + > + unsigned evtchn; > + struct xenfb_page *page; > + unsigned long *mfns; > +}; > + > +static void xenfb_do_update(struct xenfb_info *info, > + int x, int y, int w, int h) > +{ > + union xenfb_out_event event; > + __u32 cons, 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; > + > + /* FIXME barriers */ > + prod =3D XENFB_MASK_RING(info->page->out_prod, info->page->out); > + cons =3D XENFB_MASK_RING(info->page->out_cons, info->page->out); > + prod =3D XENFB_MASK_RING(prod + 1, info->page->out); > + > + if (prod =3D=3D cons) > + return; > + > + memcpy(&info->page->out[prod], &event, sizeof(event)); > + info->page->out_prod =3D prod; > + > + notify_remote_via_evtchn(info->evtchn); > +} > + > +static int xenfb_queue_full(struct xenfb_info *info) > +{ > + __u32 cons, prod; > + > + prod =3D XENFB_MASK_RING(info->page->out_prod, info->page->out); > + cons =3D XENFB_MASK_RING(info->page->out_cons, info->page->out); > + prod =3D XENFB_MASK_RING(prod + 1, info->page->out); > + > + return (prod =3D=3D cons); > +} > + > +static void xenfb_update_screen(struct xenfb_info *info) > +{ > + int y1, y2, x1, x2; > + struct list_head *item; > + struct xenfb_mapping *map; > + > + if (xenfb_queue_full(info)) > + return; > + > + y1 =3D info->y1; > + y2 =3D info->y2; > + x1 =3D info->x1; > + x2 =3D info->x2; > + info->dirty =3D info->y1 =3D info->y2 =3D info->x1 =3D info->x2 =3D 0= ; > + down(&info->mm_lock); > + list_for_each(item, &info->mappings) { > + map =3D list_entry(item, struct xenfb_mapping, next); > + 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; > + } > + up(&info->mm_lock); > + > + xenfb_do_update(info, x1, y1, x2 - x1, y2 - y1); > +} > + > +static int xenfb_thread(void *data) > +{ > + struct xenfb_info *info =3D data; > + DECLARE_WAITQUEUE(wait, current); > + > + add_wait_queue(&info->wq, &wait); > + for (;;) { > + if (kthread_should_stop()) > + break; > + if (info->dirty) > + xenfb_update_screen(info); > + set_current_state(TASK_INTERRUPTIBLE); > + schedule(); > + } > + remove_wait_queue(&info->wq, &wait); > + return 0; > +} > + > +static int xenfb_setcolreg(unsigned regno, unsigned red, unsigned gree= n, > + 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); > + > + 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++; > + 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->y2 =3D=3D 0) { > + info->y1 =3D y1; > + info->y2 =3D y2; > + } > + if (info->x2 =3D=3D 0) { > + info->x1 =3D x1; > + info->x2 =3D x2; > + } > + > + 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_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 *= image) > +{ > + 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; > + > + down(&info->mm_lock); > + if (atomic_dec_and_test(&map->map_refs)) { > + list_del(&map->next); > + kfree(map); > + } > + up(&info->mm_lock); > +} > + > +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; > + struct page *page; > + int y1, y2; > + > + if (pgnr >=3D info->nr_pages) > + return NOPAGE_SIGBUS; > + > + down(&info->mm_lock); > + page =3D info->pages[pgnr]; > + get_page(page); > + map->faults++; > + > + y1 =3D pgnr * PAGE_SIZE / info->fix->line_length; > + y2 =3D (pgnr * PAGE_SIZE + PAGE_SIZE - 1) / info->fix->line_length; > + if (y2 > info->var->yres) > + y2 =3D info->var->yres; > + xenfb_refresh(info, 0, y1, info->var->xres, y2 - y1); > + up(&info->mm_lock); > + > + 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 *= vma) > +{ > + struct xenfb_info *info =3D fb_info->par; > + struct xenfb_mapping *map; > + int ret; > + int map_pages; > + > + down(&info->mm_lock); > + > + ret =3D -EINVAL; > + if (!(vma->vm_flags & VM_WRITE)) > + goto out; > + if (!(vma->vm_flags & VM_SHARED)) > + goto out; > + if (vma->vm_pgoff !=3D 0) > + goto out; > + > + map_pages =3D (vma->vm_end - vma->vm_start + PAGE_SIZE-1) >> PAGE_SHI= FT; > + if (map_pages > info->nr_pages) > + goto out; > + > + ret =3D -ENOMEM; > + map =3D kmalloc(sizeof(*map), GFP_KERNEL); > + if (map =3D=3D NULL) > + goto out; > + memset(map, 0, sizeof(*map)); > + > + map->vma =3D vma; > + map->faults =3D 0; > + map->info =3D info; > + atomic_set(&map->map_refs, 1); > + list_add(&map->next, &info->mappings); > + vma->vm_ops =3D &xenfb_vm_ops; > + vma->vm_flags |=3D (VM_DONTEXPAND | VM_RESERVED); > + vma->vm_private_data =3D map; > + ret =3D 0; > + > + out: > + up(&info->mm_lock); > + return ret; > +} > + > +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) > +{ > + struct xenfb_info *info =3D dev_id; > + __u32 cons, prod; > + > + if (!info->page || !info->page->initialized) > + return IRQ_NONE; > + > + /* FIXME barriers */ > + prod =3D XENFB_MASK_RING(info->page->in_prod, info->page->in); > + cons =3D XENFB_MASK_RING(info->page->in_cons, info->page->in); > + > + if (prod =3D=3D cons) > + return IRQ_HANDLED; > + > + for (; cons!=3Dprod; cons =3D XENFB_MASK_RING(cons+1, info->page->in)= ) { > + union xenfb_in_event *event; > + event =3D &info->page->in[cons]; > + notify_remote_via_evtchn(info->evtchn); > + } > + > + info->page->in_cons =3D cons; > + > + return IRQ_HANDLED; > +} > + > +static unsigned long vmalloc_to_mfn(void *address) > +{ > + return pfn_to_mfn(vmalloc_to_pfn(address)); > +} > + > +static struct xenfb_info *xenfb_info; > +static int xenfb_irq; > + > +static int __init xenfb_probe(void) > +{ > + struct xenfb_info *info; > + int i, ret; > + struct fb_info *fb_info; > + struct evtchn_alloc_unbound alloc_unbound; > + xenbus_transaction_t xbt; > + > + info =3D kmalloc(sizeof(*info), GFP_KERNEL); > + if (info =3D=3D NULL) > + return -ENOMEM; > + memset(info, 0, sizeof(*info)); > + > + INIT_LIST_HEAD(&info->mappings); > + > + info->fb =3D vmalloc(xenfb_mem_len); > + if (info->fb =3D=3D NULL) > + goto error; > + 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_KERN= EL); > + if (info->pages =3D=3D NULL) > + goto error_vfree; > + for (i =3D 0; i < info->nr_pages; i++) > + info->pages[i] =3D vmalloc_to_page(info->fb + i * PAGE_SIZE); > + > + fb_info =3D framebuffer_alloc(sizeof(u32) * 256, NULL); > + if (fb_info =3D=3D NULL) > + goto error_kfree; > + > + info->mfns =3D vmalloc(sizeof(unsigned long) * info->nr_pages); > + /* set up shared page */ > + info->page =3D (void *)__get_free_page(GFP_KERNEL); > + if (!info->page) > + goto error_kfree; > + /* set up event channel */ > + alloc_unbound.dom =3D DOMID_SELF; > + alloc_unbound.remote_dom =3D 0; > + ret =3D HYPERVISOR_event_channel_op(EVTCHNOP_alloc_unbound, > + &alloc_unbound); > + if (ret) > + goto error_freep; > + info->evtchn =3D alloc_unbound.port; > + > + 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->width =3D 800; > + info->page->height =3D 600; > + info->page->depth =3D 32; // FIXME was 24; > + info->page->line_length =3D (info->page->depth / 8) * info->page->wid= th; > + info->page->mem_length =3D xenfb_mem_len; > + > + ret =3D bind_evtchn_to_irqhandler(info->evtchn, xenfb_event_handler, > + 0, "xenfb", info); > + if (ret < 0) > + // FIXME need to close evtchn? > + goto error_kfree; > + > + xenfb_irq =3D ret; > + xenfb_info =3D info; > + > + fb_info->pseudo_palette =3D fb_info->par; > + fb_info->par =3D info; > + fb_info->screen_base =3D info->fb; > + > + memset(&fb_info->var, 0, sizeof(fb_info->var)); > + memset(&fb_info->fix, 0, sizeof(fb_info->fix)); > + > + 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->heigh= t; > + 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; > + > + fb_alloc_cmap(&fb_info->cmap, 256, 0); > + > + info->fb_info =3D fb_info; > + info->fix =3D &fb_info->fix; > + info->var =3D &fb_info->var; > + > + init_MUTEX(&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; > + > + info->kthread =3D kthread_run(xenfb_thread, info, "xenfb thread"); > + > + ret =3D register_framebuffer(fb_info); > + if (ret) > + goto error_unbind; > + > + ret =3D xenbus_transaction_start(&xbt); > + if (ret) > + goto error_unreg; > + ret =3D xenbus_printf(xbt, "vfb", "page-ref", "%lu", > + virt_to_mfn(info->page)); > + if (ret) > + goto error_xenbus; > + ret =3D xenbus_printf(xbt, "vfb", "event-channel", "%u", > + info->evtchn); > + if (ret) > + goto error_xenbus; > + ret =3D xenbus_transaction_end(xbt, 0); > + if (ret) > + goto error_unreg; > + > + info->page->initialized =3D 1; /* FIXME needed? move up? */ > + > + return 0; > + > + error_xenbus: > + xenbus_transaction_end(xbt, 1); > + error_unreg: > + unregister_framebuffer(fb_info); > + error_unbind: > + unbind_from_irqhandler(xenfb_irq, info); > + xenfb_irq =3D 0; > + error_freep: > + free_page((unsigned long)info->page); > + error_kfree: > + kfree(info->pages); > + error_vfree: > + vfree(info->fb); > + error: > + kfree(info); > + xenfb_info =3D NULL; > + > + return -ENODEV; > +} > + > +void xenfb_resume(void) > +{ > +#if 0 /* FIXME */ > + int i, ret; > + > +#if 0 > + xenfb_info->page =3D mfn_to_virt(xen_start_info->fbdev_mfn); > +#endif > + for (i =3D 0; i < xenfb_info->nr_pages; i++) > + xenfb_info->mfns[i] =3D vmalloc_to_mfn(xenfb_info->fb + i * PAGE_SIZ= E); > + xenfb_info->page->pd[0] =3D vmalloc_to_mfn(xenfb_info->mfns); > + > +#if 0 > + if (xenfb_irq) > + unbind_from_irqhandler(xenfb_irq, NULL); > +#endif > + > +#if 0 > + printk("xenfb: resume(%d)\n", xen_start_info->fbdev_evtchn); > + ret =3D bind_evtchn_to_irqhandler(xen_start_info->fbdev_evtchn, > + xenfb_event_handler, 0, "xenfb", xenfb_info); > +#endif > + if (ret <=3D 0) > + return; > + xenfb_irq =3D ret; > +#else > + printk(KERN_DEBUG "xenfb_resume not implemented\n"); > +#endif > +} > + > +static int __init xenfb_init(void) > +{ > + return xenfb_probe(); > +} > + > +static void __exit xenfb_cleanup(void) > +{ > + struct xenfb_info *info =3D xenfb_info; > + > + unregister_framebuffer(info->fb_info); > + unbind_from_irqhandler(xenfb_irq, info); > + xenfb_irq =3D 0; > + free_page((unsigned long)info->page); > + kfree(info->pages); > + vfree(info->fb); > + kfree(info); > + xenfb_info =3D NULL; > +} > + > +module_init(xenfb_init); > +module_exit(xenfb_cleanup); > + > +MODULE_LICENSE("GPL"); > diff -r d8434a6fdd05 drivers/xen/xenkbd/Makefile > --- /dev/null Thu Jan 01 00:00:00 1970 +0000 > +++ b/drivers/xen/xenkbd/Makefile Fri Jun 23 10:07:51 2006 +0200 > @@ -0,0 +1,1 @@ > +obj-$(CONFIG_XEN_KEYBOARD) +=3D xenkbd.o > diff -r d8434a6fdd05 drivers/xen/xenkbd/xenkbd.c > --- /dev/null Thu Jan 01 00:00:00 1970 +0000 > +++ b/drivers/xen/xenkbd/xenkbd.c Fri Jun 23 10:07:51 2006 +0200 > @@ -0,0 +1,206 @@ > +/* > + * linux/drivers/input/keyboard/xenkbd.c -- Xen para-virtual input dev= ice > + * > + * Copyright (C) 2005 > + * > + * Anthony Liguori > + * > + * Based on linux/drivers/input/mouse/sermouse.c > + * > + * This file is subject to the terms and conditions of the GNU Genera= l Public > + * License. See the file COPYING in the main directory of this archiv= e for > + * more details. > + */ > + > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > + > +struct xenkbd_device > +{ > + struct input_dev *dev; > + struct xenkbd_info *info; > + unsigned evtchn; > +}; > + > +static irqreturn_t input_handler(int rq, void *dev_id, struct pt_regs = *regs) > +{ > + struct xenkbd_device *dev =3D dev_id; > + struct xenkbd_info *info =3D dev ? dev->info : 0; > + static int button_map[3] =3D { BTN_RIGHT, BTN_MIDDLE, BTN_LEFT }; > + __u32 cons, prod; > + > + if (!info || !info->initialized) > + return IRQ_NONE; > + > + /* FIXME barriers */ > + prod =3D XENKBD_MASK_RING(info->in_prod, info->in); > + cons =3D XENKBD_MASK_RING(info->in_cons, info->in); > + > + if (prod =3D=3D cons) > + return IRQ_HANDLED; > + > + for (; cons !=3D prod; cons =3D XENKBD_MASK_RING(cons + 1, info->in))= { > + union xenkbd_in_event *event; > + > + event =3D &info->in[cons]; > + > + switch (event->type) { > + case XENKBD_TYPE_MOTION: > + input_report_rel(dev->dev, REL_X, event->motion.rel_x); > + input_report_rel(dev->dev, REL_Y, event->motion.rel_y); > + break; > + case XENKBD_TYPE_BUTTON: > + if (event->button.button < 3) > + input_report_key(dev->dev, > + button_map[event->button.button], > + event->button.pressed); > + break; > + case XENKBD_TYPE_KEY: > + input_report_key(dev->dev, event->key.keycode, event->key.pressed);= > + break; > + } > + > + notify_remote_via_evtchn(dev->evtchn); > + } > + input_sync(dev->dev); > + > + info->in_cons =3D cons; > + > + return IRQ_HANDLED; > +} > + > +static struct xenkbd_device *xenkbd_dev; > +static int xenkbd_irq; > + > +int __init xenkbd_init(void) > +{ > + int ret =3D 0; > + int i; > + struct xenkbd_device *dev; > + struct input_dev *input_dev; > + struct evtchn_alloc_unbound alloc_unbound; > + xenbus_transaction_t xbt; > + > + dev =3D kmalloc(sizeof(*dev), GFP_KERNEL); > + input_dev =3D input_allocate_device(); > + if (!dev || !input_dev) > + return -ENOMEM; > + > + dev->dev =3D input_dev; > + dev->info =3D (void *)__get_free_page(GFP_KERNEL); > + if (!dev->info) { > + ret =3D -ENOMEM; > + goto error; > + } > + dev->info->initialized =3D 0; > + > + alloc_unbound.dom =3D DOMID_SELF; > + alloc_unbound.remote_dom =3D 0; > + ret =3D HYPERVISOR_event_channel_op(EVTCHNOP_alloc_unbound, > + &alloc_unbound); > + if (ret) > + goto error_freep; > + dev->evtchn =3D alloc_unbound.port; > + ret =3D bind_evtchn_to_irqhandler(dev->evtchn, input_handler, 0, > + "xenkbd", dev); > + if (ret < 0) > + goto error_freep; > + > + xenkbd_irq =3D ret; > + > + input_dev->evbit[0] =3D BIT(EV_KEY) | BIT(EV_REL); > + input_dev->keybit[LONG(BTN_MOUSE)] =3D BIT(BTN_LEFT) | BIT(BTN_RIGHT)= ; > + input_dev->relbit[0] =3D BIT(REL_X) | BIT(REL_Y); > + > + /* FIXME */ > + for (i =3D 0; i < 256; i++) > + set_bit(i, input_dev->keybit); > + > + input_dev->name =3D "Xen Virtual Keyboard/Mouse"; > + > + input_register_device(input_dev); > + > + ret =3D xenbus_transaction_start(&xbt); > + if (ret) > + goto error_unreg; > + ret =3D xenbus_printf(xbt, "vkbd", "page-ref", "%lu", > + virt_to_mfn(dev->info)); > + if (ret) > + goto error_xenbus; > + ret =3D xenbus_printf(xbt, "vkbd", "event-channel", "%u", > + dev->evtchn); > + if (ret) > + goto error_xenbus; > + ret =3D xenbus_transaction_end(xbt, 0); > + if (ret) > + goto error_unreg; > + > + dev->info->in_cons =3D dev->info->in_prod =3D 0; > + dev->info->out_cons =3D dev->info->out_prod =3D 0; > + dev->info->initialized =3D 1; /* FIXME needed? move up? */ > + > + xenkbd_dev =3D dev; > + > + return ret; > + > +=09 > + error_xenbus: > + xenbus_transaction_end(xbt, 1); > + error_unreg: > + input_unregister_device(input_dev); > + unbind_from_irqhandler(xenkbd_irq, dev); > + xenkbd_irq =3D 0; > + error_freep: > + free_page((unsigned long)dev->info); > + error: > + kfree(dev); > + xenkbd_dev =3D NULL; > + return ret; > +} > + > +static void __exit xenkbd_cleanup(void) > +{ > + input_unregister_device(xenkbd_dev->dev); > + unbind_from_irqhandler(xenkbd_irq, xenkbd_dev); > + xenkbd_irq =3D 0; > + free_page((unsigned long)xenkbd_dev->info); > + kfree(xenkbd_dev); > + xenkbd_dev =3D NULL; > +} > + > +void xenkbd_resume(void) > +{ > +#if 0 > + int ret; > + > + if (xenkbd_dev && xen_start_info->kbd_evtchn) { > + if (xenkbd_irq) > + unbind_from_irqhandler(xenkbd_irq, NULL); > + > + ret =3D bind_evtchn_to_irqhandler(xen_start_info->kbd_evtchn, > + input_handler, > + 0, > + "xenkbd", > + xenkbd_dev); > + > + if (ret <=3D 0) > + return; > + > + xenkbd_irq =3D ret; > + xenkbd_dev->info =3D mfn_to_virt(xen_start_info->kbd_mfn); > + } > +#else > + printk(KERN_DEBUG "xenkbd_resume not implemented\n"); > +#endif > +} > + > +module_init(xenkbd_init); > +module_exit(xenkbd_cleanup); > + > +MODULE_LICENSE("GPL"); >=20 > _______________________________________________ > Xen-devel mailing list > Xen-devel@lists.xensource.com > http://lists.xensource.com/xen-devel >=20 >=20 --=20 Laurent Vivier Bull, Architect of an Open World (TM) http://www.bullopensource.org/ext4 --------------enigB7E13ADA5D07CCBD8773DB5C Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.7 (GNU/Linux) iD8DBQFEyhbA9Kffa9pFVzwRAjkBAJ9AczwFniYGZ6/a/9tfHeuWqfYmLwCeLiKs xsDrOu3P3flMDpRaL4Ku1DY= =7UHm -----END PGP SIGNATURE----- --------------enigB7E13ADA5D07CCBD8773DB5C-- --===============0600018649== 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 --===============0600018649==--