File linux-2.6-xen-pvfb.patch of Package kernel

diff -r ec03b24a2d83 -r 6ca424e1867e linux-2.6-xen-sparse/arch/i386/kernel/setup-xen.c
--- linux-2.6-xen-sparse/arch/i386/kernel/setup-xen.c	Tue Aug 15 19:53:55 2006 +0100
+++ linux-2.6-xen-sparse/arch/i386/kernel/setup-xen.c	Fri Aug 18 16:17:58 2006 -0400
@@ -1871,8 +1871,12 @@ void __init setup_arch(char **cmdline_p)
 #endif
 #endif
 	} else {
+#if defined(CONFIG_VT) && defined(CONFIG_DUMMY_CONSOLE)
+		conswitchp = &dummy_con;
+#else
 		extern int console_use_vt;
 		console_use_vt = 0;
+#endif
 	}
 }
 
diff -r ec03b24a2d83 -r 6ca424e1867e linux-2.6-xen-sparse/drivers/xen/Kconfig
--- linux-2.6-xen-sparse/drivers/xen/Kconfig	Tue Aug 15 19:53:55 2006 +0100
+++ linux-2.6-xen-sparse/drivers/xen/Kconfig	Fri Aug 18 16:17:58 2006 -0400
@@ -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.
 
+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 ec03b24a2d83 -r 6ca424e1867e linux-2.6-xen-sparse/drivers/xen/Makefile
--- linux-2.6-xen-sparse/drivers/xen/Makefile	Tue Aug 15 19:53:55 2006 +0100
+++ linux-2.6-xen-sparse/drivers/xen/Makefile	Fri Aug 18 16:17:58 2006 -0400
@@ -15,3 +15,5 @@ obj-$(CONFIG_XEN_NETDEV_FRONTEND)	+= net
 obj-$(CONFIG_XEN_NETDEV_FRONTEND)	+= netfront/
 obj-$(CONFIG_XEN_PCIDEV_BACKEND)	+= pciback/
 obj-$(CONFIG_XEN_PCIDEV_FRONTEND)	+= pcifront/
+obj-$(CONFIG_XEN_FRAMEBUFFER)		+= xenfb/
+obj-$(CONFIG_XEN_KEYBOARD)		+= xenkbd/
diff -r ec03b24a2d83 -r 6ca424e1867e linux-2.6-xen-sparse/mm/memory.c
--- linux-2.6-xen-sparse/mm/memory.c	Tue Aug 15 19:53:55 2006 +0100
+++ linux-2.6-xen-sparse/mm/memory.c	Fri Aug 18 16:17:58 2006 -0400
@@ -881,6 +881,7 @@ unsigned long zap_page_range(struct vm_a
 		tlb_finish_mmu(tlb, address, end);
 	return end;
 }
+EXPORT_SYMBOL(zap_page_range);
 
 /*
  * Do a quick page-table lookup for a single page.
diff -r ec03b24a2d83 -r 6ca424e1867e linux-2.6-xen-sparse/drivers/xen/xenfb/Makefile
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ linux-2.6-xen-sparse/drivers/xen/xenfb/Makefile	Fri Aug 18 16:17:58 2006 -0400
@@ -0,0 +1,1 @@
+obj-$(CONFIG_XEN_FRAMEBUFFER)	:= xenfb.o
diff -r ec03b24a2d83 -r 6ca424e1867e linux-2.6-xen-sparse/drivers/xen/xenfb/xenfb.c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ linux-2.6-xen-sparse/drivers/xen/xenfb/xenfb.c	Fri Aug 18 16:17:58 2006 -0400
@@ -0,0 +1,568 @@
+/*
+ * linux/drivers/video/xenfb.c -- Xen para-virtual frame buffer device
+ *
+ * Copyright (C) 2005-2006
+ *
+ *      Anthony Liguori <aliguori@us.ibm.com>
+ *
+ *  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.
+ */
+
+#include <linux/kernel.h>
+#include <linux/errno.h>
+#include <linux/fb.h>
+#include <linux/module.h>
+#include <linux/vmalloc.h>
+#include <linux/mm.h>
+#include <asm/hypervisor.h>
+#include <xen/evtchn.h>
+#include <xen/xenbus.h>
+#include <linux/xenfb.h>
+#include <linux/kthread.h>
+
+static int xenfb_fps = 20;
+static unsigned long xenfb_mem_len = 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 prod;
+
+	event.type = XENFB_TYPE_UPDATE;
+	event.update.x = x;
+	event.update.y = y;
+	event.update.width = w;
+	event.update.height = h;
+
+	prod = info->page->out_prod;
+	if (prod - info->page->out_cons == XENFB_RING_SIZE(info->page->out))
+		return;		/* ring buffer full, event lost */
+	XENFB_RING_REF(info->page->out, prod) = event;
+	info->page->out_prod = prod + 1;
+
+	notify_remote_via_evtchn(info->evtchn);
+}
+
+static int xenfb_queue_full(struct xenfb_info *info)
+{
+	__u32 cons, prod;
+
+	prod = info->page->out_prod;
+	cons = info->page->out_cons;
+	return prod - cons == XENFB_RING_SIZE(info->page->out);
+}
+
+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 = info->y1;
+	y2 = info->y2;
+	x1 = info->x1;
+	x2 = info->x2;
+	info->dirty = info->y1 = info->y2 = info->x1 = info->x2 = 0;
+	down(&info->mm_lock);
+	list_for_each(item, &info->mappings) {
+		map = 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 = 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 = 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 green,
+			   unsigned blue, unsigned transp,
+			   struct fb_info *info)
+{
+	u32 v;
+
+	if (regno > info->cmap.len)
+		return 1;
+
+	red   >>= (16 - info->var.red.length);
+	green >>= (16 - info->var.green.length);
+	blue  >>= (16 - info->var.blue.length);
+
+	v = (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] = v;
+		break;
+	}
+	
+	return 0;
+}
+
+static void xenfb_timer(unsigned long data)
+{
+	struct xenfb_info *info = (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 = y1 + h;
+	x2 = x1 + w;
+	if (info->y2 == 0) {
+		info->y1 = y1;
+		info->y2 = y2;
+	}
+	if (info->x2 == 0) {
+		info->x1 = x1;
+		info->x2 = x2;
+	}
+
+	if (info->y1 > y1)
+		info->y1 = y1;
+	if (info->y2 < y2)
+		info->y2 = y2;
+	if (info->x1 > x1)
+		info->x1 = x1;
+	if (info->x2 < x2)
+		info->x2 = 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 = 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 = 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 = 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 = vma->vm_private_data;
+	atomic_inc(&map->map_refs);
+}
+
+static void xenfb_vm_close(struct vm_area_struct *vma)
+{
+	struct xenfb_mapping *map = vma->vm_private_data;
+	struct xenfb_info *info = 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 = vma->vm_private_data;
+	struct xenfb_info *info = map->info;
+	int pgnr = (vaddr - vma->vm_start) >> PAGE_SHIFT;
+	struct page *page;
+	int y1, y2;
+
+	if (pgnr >= info->nr_pages)
+		return NOPAGE_SIGBUS;
+
+	down(&info->mm_lock);
+	page = info->pages[pgnr];
+	get_page(page);
+	map->faults++;
+
+	y1 = pgnr * PAGE_SIZE / info->fix->line_length;
+	y2 = (pgnr * PAGE_SIZE + PAGE_SIZE - 1) / info->fix->line_length;
+	if (y2 > info->var->yres)
+		y2 = info->var->yres;
+	xenfb_refresh(info, 0, y1, info->var->xres, y2 - y1);
+	up(&info->mm_lock);
+
+	if (type)
+		*type = VM_FAULT_MINOR;
+
+	return page;
+}
+
+static struct vm_operations_struct xenfb_vm_ops = {
+	.open	= xenfb_vm_open,
+	.close	= xenfb_vm_close,
+	.nopage	= xenfb_vm_nopage,
+};
+
+static int xenfb_mmap(struct fb_info *fb_info, struct vm_area_struct *vma)
+{
+	struct xenfb_info *info = fb_info->par;
+	struct xenfb_mapping *map;
+	int ret;
+	int map_pages;
+
+	down(&info->mm_lock);
+
+	ret = -EINVAL;
+	if (!(vma->vm_flags & VM_WRITE))
+		goto out;
+	if (!(vma->vm_flags & VM_SHARED))
+		goto out;
+	if (vma->vm_pgoff != 0)
+		goto out;
+
+	map_pages = (vma->vm_end - vma->vm_start + PAGE_SIZE-1) >> PAGE_SHIFT;
+	if (map_pages > info->nr_pages)
+		goto out;
+
+	ret = -ENOMEM;
+	map = kmalloc(sizeof(*map), GFP_KERNEL);
+	if (map == NULL)
+		goto out;
+	memset(map, 0, sizeof(*map));
+
+	map->vma = vma;
+	map->faults = 0;
+	map->info = info;
+	atomic_set(&map->map_refs, 1);
+	list_add(&map->next, &info->mappings);
+	vma->vm_ops = &xenfb_vm_ops;
+	vma->vm_flags |= (VM_DONTEXPAND | VM_RESERVED);
+	vma->vm_private_data = map;
+	ret = 0;
+
+ out:
+	up(&info->mm_lock);
+	return ret;
+}
+
+static struct fb_ops xenfb_fb_ops = {
+	.owner		= THIS_MODULE,
+	.fb_setcolreg	= xenfb_setcolreg,
+	.fb_fillrect	= xenfb_fillrect,
+	.fb_copyarea	= xenfb_copyarea,
+	.fb_imageblit	= xenfb_imageblit,
+	.fb_mmap	= xenfb_mmap,
+};
+
+static irqreturn_t xenfb_event_handler(int rq, void *dev_id,
+				       struct pt_regs *regs)
+{
+	struct xenfb_info *info = dev_id;
+	__u32 cons, prod;
+
+	if (!info->page || !info->page->initialized)
+		return IRQ_NONE;
+
+	prod = info->page->in_prod;
+	rmb();			/* ensure we see ring contents up to prod */
+	for (cons = info->page->in_cons; cons != prod; cons++) {
+		union xenfb_in_event *event;
+		event = &XENFB_RING_REF(info->page->in, cons);
+		notify_remote_via_evtchn(info->evtchn);
+	}
+	/* FIXME do I need a wmb() here? */
+	info->page->in_cons = 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;
+	struct xenbus_transaction xbt;
+
+	info = kmalloc(sizeof(*info), GFP_KERNEL);
+	if (info == NULL)
+		return -ENOMEM;
+	memset(info, 0, sizeof(*info));
+
+	INIT_LIST_HEAD(&info->mappings);
+
+	info->fb = vmalloc(xenfb_mem_len);
+	if (info->fb == NULL)
+		goto error;
+	memset(info->fb, 0, xenfb_mem_len);
+	info->nr_pages = (xenfb_mem_len + PAGE_SIZE - 1) >> PAGE_SHIFT;
+	info->pages = kmalloc(sizeof(struct page*)*info->nr_pages, GFP_KERNEL);
+	if (info->pages == NULL)
+		goto error_vfree;
+	for (i = 0; i < info->nr_pages; i++)
+		info->pages[i] = vmalloc_to_page(info->fb + i * PAGE_SIZE);
+
+	fb_info = framebuffer_alloc(sizeof(u32) * 256, NULL);
+	if (fb_info == NULL)
+		goto error_kfree;
+
+	info->mfns = vmalloc(sizeof(unsigned long) * info->nr_pages);
+	/* set up shared page */
+	info->page = (void *)__get_free_page(GFP_KERNEL);
+	if (!info->page)
+		goto error_kfree;
+	/* set up event channel */
+	alloc_unbound.dom = DOMID_SELF;
+	alloc_unbound.remote_dom = 0;
+	ret = HYPERVISOR_event_channel_op(EVTCHNOP_alloc_unbound,
+					  &alloc_unbound);
+	if (ret)
+		goto error_freep;
+	info->evtchn = alloc_unbound.port;
+
+	for (i = 0; i < info->nr_pages; i++)
+		info->mfns[i] = vmalloc_to_mfn(info->fb + i * PAGE_SIZE);
+	info->page->pd[0] = vmalloc_to_mfn(info->mfns);
+	info->page->pd[1] = 0;
+	info->page->width = 800;
+	info->page->height = 600;
+	info->page->depth = 32;
+	info->page->line_length = (info->page->depth / 8) * info->page->width;
+	info->page->mem_length = xenfb_mem_len;
+	info->page->in_cons = info->page->in_prod = 0;
+	info->page->out_cons = info->page->out_prod = 0;
+
+	ret = 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 = ret;
+	xenfb_info = info;
+
+	fb_info->pseudo_palette = fb_info->par;
+	fb_info->par = info;
+	fb_info->screen_base = info->fb;
+
+	memset(&fb_info->var, 0, sizeof(fb_info->var));
+	memset(&fb_info->fix, 0, sizeof(fb_info->fix));
+
+	fb_info->fbops = &xenfb_fb_ops;
+	fb_info->var.xres_virtual = fb_info->var.xres = info->page->width;
+	fb_info->var.yres_virtual = fb_info->var.yres = info->page->height;
+	fb_info->var.bits_per_pixel = info->page->depth;
+
+	fb_info->var.red = (struct fb_bitfield){16, 8, 0};
+	fb_info->var.green = (struct fb_bitfield){8, 8, 0};
+	fb_info->var.blue = (struct fb_bitfield){0, 8, 0};
+
+	fb_info->var.activate = FB_ACTIVATE_NOW;
+	fb_info->var.height = -1;
+	fb_info->var.width = -1;
+	fb_info->var.vmode = FB_VMODE_NONINTERLACED;
+
+	fb_info->fix.visual = FB_VISUAL_TRUECOLOR;
+	fb_info->fix.line_length = info->page->line_length;
+	fb_info->fix.smem_start = 0;
+	fb_info->fix.smem_len = xenfb_mem_len;
+	strcpy(fb_info->fix.id, "xen");
+	fb_info->fix.type = FB_TYPE_PACKED_PIXELS;
+	fb_info->fix.accel = FB_ACCEL_NONE;
+
+	fb_info->flags = FBINFO_FLAG_DEFAULT;
+
+	fb_alloc_cmap(&fb_info->cmap, 256, 0);
+
+	info->fb_info = fb_info;
+	info->fix = &fb_info->fix;
+	info->var = &fb_info->var;
+
+	init_MUTEX(&info->mm_lock);
+	init_waitqueue_head(&info->wq);
+	init_timer(&info->refresh);
+	info->refresh.function = xenfb_timer;
+	info->refresh.data = (unsigned long)info;
+
+	info->kthread = kthread_run(xenfb_thread, info, "xenfb thread");
+
+	ret = register_framebuffer(fb_info);
+	if (ret)
+		goto error_unbind;
+
+ again:
+	ret = xenbus_transaction_start(&xbt);
+	if (ret)
+		goto error_unreg;
+	ret = xenbus_printf(xbt, "vfb", "page-ref", "%lu",
+			    virt_to_mfn(info->page));
+	if (ret)
+		goto error_xenbus;
+	ret = xenbus_printf(xbt, "vfb", "event-channel", "%u",
+			    info->evtchn);
+	if (ret)
+		goto error_xenbus;
+	ret = xenbus_transaction_end(xbt, 0);
+	if (ret) {
+		if (ret == -EAGAIN)
+			goto again;
+		goto error_unreg;
+	}
+
+	info->page->initialized = 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 = 0;
+ error_freep:
+	free_page((unsigned long)info->page);
+ error_kfree:
+	kfree(info->pages);
+ error_vfree:
+	vfree(info->fb);
+ error:
+	kfree(info);
+	xenfb_info = NULL;
+
+	return -ENODEV;
+}
+
+void xenfb_resume(void)
+{
+#if 0 /* FIXME */
+	int i, ret;
+
+	xenfb_info->page = mfn_to_virt(xen_start_info->fbdev_mfn);
+	for (i = 0; i < xenfb_info->nr_pages; i++)
+		xenfb_info->mfns[i] = vmalloc_to_mfn(xenfb_info->fb + i * PAGE_SIZE);
+	xenfb_info->page->pd[0] = vmalloc_to_mfn(xenfb_info->mfns);
+
+	if (xenfb_irq)
+		unbind_from_irqhandler(xenfb_irq, NULL);
+
+	printk("xenfb: resume(%d)\n", xen_start_info->fbdev_evtchn);
+	ret = bind_evtchn_to_irqhandler(xen_start_info->fbdev_evtchn,
+					xenfb_event_handler, 0, "xenfb", xenfb_info);
+	if (ret <= 0)
+		return;
+	xenfb_irq = 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 = xenfb_info;
+
+	unregister_framebuffer(info->fb_info);
+	unbind_from_irqhandler(xenfb_irq, info);
+	xenfb_irq = 0;
+	free_page((unsigned long)info->page);
+	kfree(info->pages);
+	vfree(info->fb);
+	kfree(info);
+	xenfb_info = NULL;
+}
+
+module_init(xenfb_init);
+module_exit(xenfb_cleanup);
+
+MODULE_LICENSE("GPL");
diff -r ec03b24a2d83 -r 6ca424e1867e linux-2.6-xen-sparse/drivers/xen/xenkbd/Makefile
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ linux-2.6-xen-sparse/drivers/xen/xenkbd/Makefile	Fri Aug 18 16:17:58 2006 -0400
@@ -0,0 +1,1 @@
+obj-$(CONFIG_XEN_KEYBOARD)	+= xenkbd.o
diff -r ec03b24a2d83 -r 6ca424e1867e linux-2.6-xen-sparse/drivers/xen/xenkbd/xenkbd.c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ linux-2.6-xen-sparse/drivers/xen/xenkbd/xenkbd.c	Fri Aug 18 16:17:58 2006 -0400
@@ -0,0 +1,205 @@
+/*
+ * linux/drivers/input/keyboard/xenkbd.c -- Xen para-virtual input device
+ *
+ * Copyright (C) 2005
+ *
+ *      Anthony Liguori <aliguori@us.ibm.com>
+ *
+ *  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.
+ */
+
+#include <linux/kernel.h>
+#include <linux/errno.h>
+#include <linux/module.h>
+#include <linux/input.h>
+#include <asm/hypervisor.h>
+#include <xen/evtchn.h>
+#include <xen/xenbus.h>
+#include <linux/xenkbd.h>
+
+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 = dev_id;
+	struct xenkbd_info *info = dev ? dev->info : 0;
+	static int button_map[3] = { BTN_RIGHT, BTN_MIDDLE, BTN_LEFT };
+	__u32 cons, prod;
+
+	if (!info || !info->initialized)
+		return IRQ_NONE;
+
+	prod = info->in_prod;
+	rmb();			/* ensure we see ring contents up to prod */
+	for (cons = info->in_cons; cons != prod; cons++) {
+		union xenkbd_in_event *event;
+		event = &XENKBD_RING_REF(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);
+	/* FIXME do I need a wmb() here? */
+	info->in_cons = cons;
+
+	return IRQ_HANDLED;
+}
+
+static struct xenkbd_device *xenkbd_dev;
+static int xenkbd_irq;
+
+int __init xenkbd_init(void)
+{
+	int ret = 0;
+	int i;
+	struct xenkbd_device *dev;
+	struct input_dev *input_dev;
+	struct evtchn_alloc_unbound alloc_unbound;
+	struct xenbus_transaction xbt;
+
+	dev = kmalloc(sizeof(*dev), GFP_KERNEL);
+	input_dev = input_allocate_device();
+	if (!dev || !input_dev)
+		return -ENOMEM;
+
+	dev->dev = input_dev;
+	dev->info = (void *)__get_free_page(GFP_KERNEL);
+	if (!dev->info) {
+		ret = -ENOMEM;
+		goto error;
+	}
+	dev->info->initialized = 0;
+
+	alloc_unbound.dom = DOMID_SELF;
+	alloc_unbound.remote_dom = 0;
+	ret = HYPERVISOR_event_channel_op(EVTCHNOP_alloc_unbound,
+					  &alloc_unbound);
+	if (ret)
+		goto error_freep;
+	dev->evtchn = alloc_unbound.port;
+	ret = bind_evtchn_to_irqhandler(dev->evtchn, input_handler, 0,
+					"xenkbd", dev);
+	if (ret < 0)
+		goto error_freep;
+
+	xenkbd_irq = ret;
+
+	input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_REL);
+	input_dev->keybit[LONG(BTN_MOUSE)] = BIT(BTN_LEFT) | BIT(BTN_RIGHT);
+	input_dev->relbit[0] = BIT(REL_X) | BIT(REL_Y);
+
+	/* FIXME not sure this is quite right */
+	for (i = 0; i < 256; i++)
+		set_bit(i, input_dev->keybit);
+
+	input_dev->name = "Xen Virtual Keyboard/Mouse";
+
+	input_register_device(input_dev);
+
+ again:
+	ret = xenbus_transaction_start(&xbt);
+	if (ret)
+		goto error_unreg;
+	ret = xenbus_printf(xbt, "vkbd", "page-ref", "%lu",
+			    virt_to_mfn(dev->info));
+	if (ret)
+		goto error_xenbus;
+	ret = xenbus_printf(xbt, "vkbd", "event-channel", "%u",
+			    dev->evtchn);
+	if (ret)
+		goto error_xenbus;
+	ret = xenbus_transaction_end(xbt, 0);
+	if (ret) {
+		if (ret == -EAGAIN)
+			goto again;
+		/* FIXME really retry forever? */
+		goto error_unreg;
+	}
+
+	dev->info->in_cons = dev->info->in_prod = 0;
+	dev->info->out_cons = dev->info->out_prod = 0;
+	dev->info->initialized = 1; /* FIXME needed?  move up? */
+
+	xenkbd_dev = dev;
+
+	return ret;
+
+	
+ error_xenbus:
+	xenbus_transaction_end(xbt, 1);
+ error_unreg:
+	input_unregister_device(input_dev);
+	unbind_from_irqhandler(xenkbd_irq, dev);
+	xenkbd_irq = 0;
+ error_freep:
+	free_page((unsigned long)dev->info);
+ error:
+	kfree(dev);
+	xenkbd_dev = NULL;
+	return ret;
+}
+
+static void __exit xenkbd_cleanup(void)
+{
+	input_unregister_device(xenkbd_dev->dev);
+	unbind_from_irqhandler(xenkbd_irq, xenkbd_dev);
+	xenkbd_irq = 0;
+	free_page((unsigned long)xenkbd_dev->info);
+	kfree(xenkbd_dev);
+	xenkbd_dev = NULL;
+}
+
+void xenkbd_resume(void)
+{
+#if 0 /* FIXME */
+	int ret;
+
+	if (xenkbd_dev && xen_start_info->kbd_evtchn) {
+		if (xenkbd_irq)
+			unbind_from_irqhandler(xenkbd_irq, NULL);
+
+		ret = bind_evtchn_to_irqhandler(xen_start_info->kbd_evtchn,
+						input_handler,
+						0,
+						"xenkbd",
+						xenkbd_dev);
+
+		if (ret <= 0)
+			return;
+
+		xenkbd_irq = ret;
+		xenkbd_dev->info = 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");
diff -r ec03b24a2d83 -r 6ca424e1867e linux-2.6-xen-sparse/include/linux/xenfb.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ linux-2.6-xen-sparse/include/linux/xenfb.h	Fri Aug 18 16:17:58 2006 -0400
@@ -0,0 +1,97 @@
+/*
+ * linux/include/linux/xenfb.h -- Xen virtual frame buffer device
+ *
+ * Copyright (C) 2005
+ *
+ *      Anthony Liguori <aliguori@us.ibm.com>
+ *
+ *  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 _LINUX_XENFB_H
+#define _LINUX_XENFB_H
+
+#include <asm/types.h>
+
+/* out events */
+
+#define XENFB_TYPE_MOTION 1
+#define XENFB_TYPE_UPDATE 2
+
+struct xenfb_motion
+{
+	__u8 type;          /* XENFB_TYPE_MOTION */
+	__u16 x;            /* The new x coordinate */
+	__u16 y;            /* The new y coordinate */
+};
+
+struct xenfb_update
+{
+	__u8 type;          /* XENFB_TYPE_UPDATE */
+	__u16 x;            /* source x */
+	__u16 y;            /* source y */
+	__u16 width;        /* rect width */
+	__u16 height;       /* rect height */
+};
+
+union xenfb_out_event
+{
+	__u8 type;
+	struct xenfb_motion motion;
+	struct xenfb_update update;
+	char _[40];
+};
+
+/* in events */
+
+#define XENFB_TYPE_SET_EVENTS 1
+
+#define XENFB_FLAG_MOTION 1
+#define XENFB_FLAG_UPDATE 2
+#define XENFB_FLAG_COPY 4
+#define XENFB_FLAG_FILL 8
+
+struct xenfb_set_events
+{
+	__u8 type;          /* XENFB_TYPE_SET_EVENTS */
+	__u32 flags;        /* combination of XENFB_FLAG_* */
+};
+
+union xenfb_in_event
+{
+	__u8 type;
+	struct xenfb_set_events set_events;
+	char _[40];
+};
+
+/* shared page */
+
+#define XENFB_IN_RING_SIZE (1024 / 40)
+#define XENFB_OUT_RING_SIZE (2048 / 40)
+
+#define XENFB_RING_SIZE(ring) (sizeof((ring)) / sizeof(*(ring)))
+#define XENFB_RING_REF(ring, idx) (ring)[(idx) % XENFB_RING_SIZE((ring))]
+
+struct xenfb_page
+{
+	__u8 initialized;
+	__u16 width;         /* the width of the framebuffer (in pixels) */
+	__u16 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) */
+
+	unsigned long pd[2];
+
+	__u32 in_cons, in_prod;
+	__u32 out_cons, out_prod;
+
+	union xenfb_in_event in[XENFB_IN_RING_SIZE];
+	union xenfb_out_event out[XENFB_OUT_RING_SIZE];
+};
+
+void xenfb_resume(void);
+
+#endif
diff -r ec03b24a2d83 -r 6ca424e1867e linux-2.6-xen-sparse/include/linux/xenkbd.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ linux-2.6-xen-sparse/include/linux/xenkbd.h	Fri Aug 18 16:17:58 2006 -0400
@@ -0,0 +1,82 @@
+/*
+ * linux/include/linux/xenkbd.h -- Xen virtual keyboard/mouse
+ *
+ * Copyright (C) 2005
+ *
+ *      Anthony Liguori <aliguori@us.ibm.com>
+ *
+ *  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 _LINUX_XENKBD_H
+#define _LINUX_XENKBD_H
+
+#include <asm/types.h>
+
+/* in events */
+
+#define XENKBD_TYPE_MOTION  1     /* mouse movement event */
+#define XENKBD_TYPE_BUTTON  2     /* mouse button event */
+#define XENKBD_TYPE_KEY     3     /* keyboard event */
+
+struct xenkbd_motion
+{
+	__u8 type;         /* XENKBD_TYPE_MOTION */
+	__s16 rel_x;       /* relative X motion */
+	__s16 rel_y;       /* relative Y motion */
+};
+
+struct xenkbd_button
+{
+	__u8 type;         /* XENKBD_TYPE_BUTTON */
+	__u8 pressed;      /* 1 if pressed; 0 otherwise */
+	__u8 button;       /* the button (0, 1, 2 is right, middle, left) */
+};
+
+struct xenkbd_key
+{
+	__u8 type;         /* XENKBD_TYPE_KEY */
+	__u8 pressed;      /* 1 if pressed; 0 otherwise */
+	__u16 keycode;     /* KEY_* from linux/input.h */
+};
+
+union xenkbd_in_event
+{
+	__u8 type;
+	struct xenkbd_motion motion;
+	struct xenkbd_button button;
+	struct xenkbd_key key;
+	char _[40];
+};
+
+/* out events */
+
+union xenkbd_out_event
+{
+	__u8 type;
+	char _[40];
+};
+
+/* shared page */
+
+#define XENKBD_IN_RING_SIZE (2048 / 40)
+#define XENKBD_OUT_RING_SIZE (1024 / 40)
+
+#define XENKBD_RING_SIZE(ring) (sizeof((ring)) / sizeof(*(ring)))
+#define XENKBD_RING_REF(ring, idx) (ring)[(idx) % XENKBD_RING_SIZE((ring))]
+
+struct xenkbd_info
+{
+	__u8 initialized;
+	__u32 in_cons, in_prod;
+	__u32 out_cons, out_prod;
+
+	union xenkbd_in_event in[XENKBD_IN_RING_SIZE];
+	union xenkbd_out_event out[XENKBD_OUT_RING_SIZE];
+};
+
+void xenkbd_resume(void);
+
+#endif
diff -r 5c452351be21 -r d49bc30b6b27 linux-2.6-xen-sparse/drivers/xen/console/console.c
--- linux-2.6-xen-sparse/drivers/xen/console/console.c	Fri Aug 18 16:20:59 2006 -0400
+++ linux-2.6-xen-sparse/drivers/xen/console/console.c	Fri Aug 18 16:26:39 2006 -0400
@@ -57,19 +57,27 @@
 #include <asm/hypervisor.h>
 #include <xen/evtchn.h>
 #include <xen/xencons.h>
+#include <xen/xenbus.h>
 
 /*
  * Modes:
  *  'xencons=off'  [XC_OFF]:     Console is disabled.
  *  'xencons=tty'  [XC_TTY]:     Console attached to '/dev/tty[0-9]+'.
  *  'xencons=ttyS' [XC_SERIAL]:  Console attached to '/dev/ttyS[0-9]+'.
+ *  'xencons=xvc'  [XC_XVC]:     Console attached to '/dev/xvc[0-9]+'.
  *                 [XC_DEFAULT]: DOM0 -> XC_SERIAL ; all others -> XC_TTY.
  * 
  * NB. In mode XC_TTY, we create dummy consoles for tty2-63. This suppresses
  * warnings from standard distro startup scripts.
  */
-static enum { XC_OFF, XC_DEFAULT, XC_TTY, XC_SERIAL } xc_mode = XC_DEFAULT;
+static enum { XC_OFF, XC_DEFAULT, XC_TTY, XC_SERIAL, XC_XVC } 
+    xc_mode = XC_DEFAULT;
 static int xc_num = -1;
+
+/* If we are in XC_XVC mode (a virtual console at /dev/xvcX), we need to
+ * comply with Lanana and use a minor under the low density serial major.
+ */
+#define XEN_XVC_MINOR 187
 
 #ifdef CONFIG_MAGIC_SYSRQ
 static unsigned long sysrq_requested;
@@ -85,6 +93,8 @@ static int __init xencons_setup(char *st
 		xc_mode = XC_SERIAL;
 	else if (!strncmp(str, "tty", 3))
 		xc_mode = XC_TTY;
+	else if (!strncmp(str, "xvc", 3))
+		xc_mode = XC_XVC;
 	else if (!strncmp(str, "off", 3))
 		xc_mode = XC_OFF;
 
@@ -95,6 +105,11 @@ static int __init xencons_setup(char *st
 			xc_num = n;
 		break;
 	case XC_TTY:
+		n = simple_strtol(str+3, &q, 10);
+		if (q > (str + 3))
+			xc_num = n;
+		break;
+	case XC_XVC:
 		n = simple_strtol(str+3, &q, 10);
 		if (q > (str + 3))
 			xc_num = n;
@@ -194,11 +209,17 @@ static int __init xen_console_init(void)
 		kcons_info.write = kcons_write_dom0;
 	} else {
 		if (xc_mode == XC_DEFAULT)
-			xc_mode = XC_TTY;
+			xc_mode = XC_XVC;
 		kcons_info.write = kcons_write;
 	}
 
 	switch (xc_mode) {
+	case XC_XVC:
+		strcpy(kcons_info.name, "xvc");
+		if (xc_num == -1)
+			xc_num = 0;
+		break;
+
 	case XC_SERIAL:
 		strcpy(kcons_info.name, "ttyS");
 		if (xc_num == -1)
@@ -265,7 +286,7 @@ void xencons_force_flush(void)
 /******************** User-space console driver (/dev/console) ************/
 
 #define DRV(_d)         (_d)
-#define DUMMY_TTY(_tty) ((xc_mode != XC_SERIAL) &&		\
+#define DUMMY_TTY(_tty) ((xc_mode != XC_SERIAL) && (xc_mode != XC_XVC) && \
 			 ((_tty)->index != (xc_num - 1)))
 
 static struct termios *xencons_termios[MAX_NR_CONSOLES];
@@ -584,7 +605,8 @@ static int __init xencons_init(void)
 
 	xencons_ring_init();
 
-	xencons_driver = alloc_tty_driver((xc_mode == XC_SERIAL) ?
+	xencons_driver = alloc_tty_driver(((xc_mode == XC_SERIAL) || 
+					   (xc_mode == XC_XVC)) ?
 					  1 : MAX_NR_CONSOLES);
 	if (xencons_driver == NULL)
 		return -ENOMEM;
@@ -604,6 +626,11 @@ static int __init xencons_init(void)
 		DRV(xencons_driver)->name        = "ttyS";
 		DRV(xencons_driver)->minor_start = 64 + xc_num;
 		DRV(xencons_driver)->name_base   = 0 + xc_num;
+	} else if (xc_mode == XC_XVC) {
+		DRV(xencons_driver)->name        = "xvc";
+		DRV(xencons_driver)->major       = 250; /* FIXME: until lanana approves for 204:187 */
+		DRV(xencons_driver)->minor_start = XEN_XVC_MINOR;
+		DRV(xencons_driver)->name_base   = xc_num;
 	} else {
 		DRV(xencons_driver)->name        = "tty";
 		DRV(xencons_driver)->minor_start = 1;
diff -r d49bc30b6b27 -r e1df81251b97 linux-2.6-xen-sparse/drivers/xen/xenfb/xenfb.c
--- linux-2.6-xen-sparse/drivers/xen/xenfb/xenfb.c	Fri Aug 18 16:26:39 2006 -0400
+++ linux-2.6-xen-sparse/drivers/xen/xenfb/xenfb.c	Fri Aug 18 16:29:50 2006 -0400
@@ -369,6 +369,15 @@ static int __init xenfb_probe(void)
 	struct fb_info *fb_info;
 	struct evtchn_alloc_unbound alloc_unbound;
 	struct xenbus_transaction xbt;
+
+        /* Nothing to do if running in dom0. */
+        if (is_initial_xendomain())
+	  return -ENODEV;
+        /* if we're not set up to use graphics mode, then don't initialize */
+	if (xenbus_scanf(XBT_NIL, "console", "use_graphics", "%d", &ret) < 0)
+	  return -ENODEV;
+	if (ret == 0)
+	  return -ENODEV;
 
 	info = kmalloc(sizeof(*info), GFP_KERNEL);
 	if (info == NULL)
diff -r d49bc30b6b27 -r e1df81251b97 linux-2.6-xen-sparse/drivers/xen/xenkbd/xenkbd.c
--- linux-2.6-xen-sparse/drivers/xen/xenkbd/xenkbd.c	Fri Aug 18 16:26:39 2006 -0400
+++ linux-2.6-xen-sparse/drivers/xen/xenkbd/xenkbd.c	Fri Aug 18 16:29:50 2006 -0400
@@ -80,6 +80,15 @@ int __init xenkbd_init(void)
 	struct input_dev *input_dev;
 	struct evtchn_alloc_unbound alloc_unbound;
 	struct xenbus_transaction xbt;
+
+        /* Nothing to do if running in dom0. */
+        if (is_initial_xendomain())
+	  return -ENODEV;
+        /* if we're not set up to use graphics mode, then don't initialize */
+	if (xenbus_scanf(XBT_NIL, "console", "use_graphics", "%d", &ret) < 0)
+	  return -ENODEV;
+	if (ret == 0)
+	  return -ENODEV;
 
 	dev = kmalloc(sizeof(*dev), GFP_KERNEL);
 	input_dev = input_allocate_device();
diff -r e1df81251b97 -r fccccf63eb85 linux-2.6-xen-sparse/drivers/xen/console/console.c
--- linux-2.6-xen-sparse/drivers/xen/console/console.c	Fri Aug 18 16:29:50 2006 -0400
+++ linux-2.6-xen-sparse/drivers/xen/console/console.c	Fri Aug 18 16:31:16 2006 -0400
@@ -663,6 +663,20 @@ static int __init xencons_init(void)
 	printk("Xen virtual console successfully installed as %s%d\n",
 	       DRV(xencons_driver)->name, xc_num);
 
+        /* Don't need to check about graphical fb for domain 0 */
+        if (is_initial_xendomain())
+	  return 0;
+
+	rc = 0;
+	if (xenbus_scanf(XBT_NIL, "console", "use_graphics", "%d", &rc) < 0)
+		printk(KERN_ERR "Unable to read console/use_graphics\n");
+	if (rc == 0) {
+               /* FIXME: this is ugly */
+	       unregister_console(&kcons_info);
+	       kcons_info.flags |= CON_CONSDEV;
+	       register_console(&kcons_info);
+	}
+
 	return 0;
 }
 
diff -r fccccf63eb85 -r e1f90db3f153 linux-2.6-xen-sparse/arch/i386/kernel/setup-xen.c
--- linux-2.6-xen-sparse/arch/i386/kernel/setup-xen.c	Fri Aug 18 16:31:16 2006 -0400
+++ linux-2.6-xen-sparse/arch/i386/kernel/setup-xen.c	Fri Aug 18 16:31:31 2006 -0400
@@ -1873,9 +1873,6 @@ void __init setup_arch(char **cmdline_p)
 	} else {
 #if defined(CONFIG_VT) && defined(CONFIG_DUMMY_CONSOLE)
 		conswitchp = &dummy_con;
-#else
-		extern int console_use_vt;
-		console_use_vt = 0;
 #endif
 	}
 }
diff -r fccccf63eb85 -r e1f90db3f153 linux-2.6-xen-sparse/drivers/char/tty_io.c
--- linux-2.6-xen-sparse/drivers/char/tty_io.c	Fri Aug 18 16:31:16 2006 -0400
+++ linux-2.6-xen-sparse/drivers/char/tty_io.c	Fri Aug 18 16:31:31 2006 -0400
@@ -132,8 +132,6 @@ LIST_HEAD(tty_drivers);			/* linked list
    vt.c for deeply disgusting hack reasons */
 DECLARE_MUTEX(tty_sem);
 
-int console_use_vt = 1;
-
 #ifdef CONFIG_UNIX98_PTYS
 extern struct tty_driver *ptm_driver;	/* Unix98 pty masters; for /dev/ptmx */
 extern int pty_limit;		/* Config limit on Unix98 ptys */
@@ -2056,7 +2054,7 @@ retry_open:
 		goto got_driver;
 	}
 #ifdef CONFIG_VT
-	if (console_use_vt && (device == MKDEV(TTY_MAJOR,0))) {
+	if (device == MKDEV(TTY_MAJOR,0)) {
 		extern struct tty_driver *console_driver;
 		driver = console_driver;
 		index = fg_console;
@@ -3243,8 +3241,6 @@ static int __init tty_init(void)
 #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)
diff -r 3b373014768d -r 1aa79d3b152a linux-2.6-xen-sparse/arch/ia64/kernel/setup.c
--- linux-2.6-xen-sparse/arch/ia64/kernel/setup.c	Mon Aug 28 20:27:32 2006 -0400
+++ linux-2.6-xen-sparse/arch/ia64/kernel/setup.c	Mon Aug 28 21:18:57 2006 -0400
@@ -546,9 +546,9 @@ setup_arch (char **cmdline_p)
 		       xen_start_info->nr_pages, xen_start_info->flags);
 
 		if (!is_initial_xendomain()) {
-			extern int console_use_vt;
+#if !defined(CONFIG_VT) || !defined(CONFIG_DUMMY_CONSOLE)
 			conswitchp = NULL;
-			console_use_vt = 0;
+#endif
 		}
 	}
 #endif
diff -r 3b373014768d -r 1aa79d3b152a linux-2.6-xen-sparse/arch/x86_64/kernel/setup-xen.c
--- linux-2.6-xen-sparse/arch/x86_64/kernel/setup-xen.c	Mon Aug 28 20:27:32 2006 -0400
+++ linux-2.6-xen-sparse/arch/x86_64/kernel/setup-xen.c	Mon Aug 28 21:18:57 2006 -0400
@@ -994,9 +994,10 @@ void __init setup_arch(char **cmdline_p)
 #endif
 #endif
 		} else {
-			extern int console_use_vt;
-			console_use_vt = 0;
-		}
+#if defined(CONFIG_VT) && defined(CONFIG_DUMMY_CONSOLE)
+                    conswitchp = &dummy_con;
+#endif
+                }
 	}
 #else	/* CONFIG_XEN */
 
diff -r 158f57cd19f6 -r 74930c9686ba linux-2.6-xen-sparse/drivers/xen/xenfb/xenfb.c
--- linux-2.6-xen-sparse/drivers/xen/xenfb/xenfb.c	Sat Sep 02 11:25:27 2006 -0400
+++ linux-2.6-xen-sparse/drivers/xen/xenfb/xenfb.c	Sat Sep 02 12:12:25 2006 -0400
@@ -24,8 +24,12 @@
 #include <linux/xenfb.h>
 #include <linux/kthread.h>
 
+#define XENFB_WIDTH 800
+#define XENFB_HEIGHT 600
+#define XENFB_DEPTH 32
+
 static int xenfb_fps = 20;
-static unsigned long xenfb_mem_len = 2 * 1024 * 1024;
+static unsigned long xenfb_mem_len = XENFB_WIDTH * XENFB_HEIGHT * XENFB_DEPTH / 8;
 
 struct xenfb_mapping
 {
@@ -56,8 +60,10 @@ struct xenfb_info
 	struct list_head		mappings;
 
 	unsigned			evtchn;
+	int				irq;
 	struct xenfb_page		*page;
 	unsigned long 			*mfns;
+	u32				flags;
 };
 
 static void xenfb_do_update(struct xenfb_info *info,
@@ -73,9 +79,11 @@ static void xenfb_do_update(struct xenfb
 	event.update.height = h;
 
 	prod = info->page->out_prod;
-	if (prod - info->page->out_cons == XENFB_RING_SIZE(info->page->out))
+	if (prod - info->page->out_cons == XENFB_OUT_RING_LEN)
 		return;		/* ring buffer full, event lost */
-	XENFB_RING_REF(info->page->out, prod) = event;
+	mb();			/* ensure ring space available */
+	XENFB_OUT_RING_REF(info->page, prod) = event;
+	wmb();			/* ensure ring contents visible */
 	info->page->out_prod = prod + 1;
 
 	notify_remote_via_evtchn(info->evtchn);
@@ -87,7 +95,7 @@ static int xenfb_queue_full(struct xenfb
 
 	prod = info->page->out_prod;
 	cons = info->page->out_cons;
-	return prod - cons == XENFB_RING_SIZE(info->page->out);
+	return prod - cons == XENFB_OUT_RING_LEN;
 }
 
 static void xenfb_update_screen(struct xenfb_info *info)
@@ -96,6 +104,8 @@ static void xenfb_update_screen(struct x
 	struct list_head *item;
 	struct xenfb_mapping *map;
 
+	if (!(info->flags & XENFB_FLAG_UPDATE))
+		return;
 	if (xenfb_queue_full(info))
 		return;
 
@@ -103,7 +113,7 @@ static void xenfb_update_screen(struct x
 	y2 = info->y2;
 	x1 = info->x1;
 	x2 = info->x2;
-	info->dirty = info->y1 = info->y2 = info->x1 = info->x2 = 0;
+	info->y1 = info->y2 = info->x1 = info->x2 = 0;
 	down(&info->mm_lock);
 	list_for_each(item, &info->mappings) {
 		map = list_entry(item, struct xenfb_mapping, next);
@@ -121,18 +131,17 @@ static int xenfb_thread(void *data)
 static int xenfb_thread(void *data)
 {
 	struct xenfb_info *info = data;
-	DECLARE_WAITQUEUE(wait, current);
-
-	add_wait_queue(&info->wq, &wait);
+
 	for (;;) {
 		if (kthread_should_stop())
 			break;
-		if (info->dirty)
+		if (info->dirty) {
+			info->dirty = 0;
 			xenfb_update_screen(info);
-		set_current_state(TASK_INTERRUPTIBLE);
-		schedule();
-	}
-	remove_wait_queue(&info->wq, &wait);
+		}
+		wait_event_interruptible(info->wq,
+			kthread_should_stop() || info->dirty);
+	}
 	return 0;
 }
 
@@ -167,7 +176,7 @@ static void xenfb_timer(unsigned long da
 static void xenfb_timer(unsigned long data)
 {
 	struct xenfb_info *info = (struct xenfb_info *)data;
-	info->dirty++;
+	info->dirty = 1;
 	wake_up(&info->wq);
 }
 
@@ -338,29 +347,32 @@ static irqreturn_t xenfb_event_handler(i
 	struct xenfb_info *info = dev_id;
 	__u32 cons, prod;
 
-	if (!info->page || !info->page->initialized)
-		return IRQ_NONE;
-
 	prod = info->page->in_prod;
 	rmb();			/* ensure we see ring contents up to prod */
 	for (cons = info->page->in_cons; cons != prod; cons++) {
 		union xenfb_in_event *event;
-		event = &XENFB_RING_REF(info->page->in, cons);
-		notify_remote_via_evtchn(info->evtchn);
-	}
-	/* FIXME do I need a wmb() here? */
+		event = &XENFB_IN_RING_REF(info->page, cons);
+
+		switch (event->type) {
+		case XENFB_TYPE_SET_EVENTS:
+			info->flags = event->set_events.flags;
+			break;
+		}
+	}
+	mb();			/* ensure we're done with ring contents */
 	info->page->in_cons = cons;
+	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));
+	return pfn_to_mfn(vmalloc_to_pfn(address));
+	//return arbitrary_virt_to_machine(address) >> PAGE_SHIFT;
 }
 
 static struct xenfb_info *xenfb_info;
-static int xenfb_irq;
 
 static int __init xenfb_probe(void)
 {
@@ -368,16 +380,19 @@ static int __init xenfb_probe(void)
 	int i, ret;
 	struct fb_info *fb_info;
 	struct evtchn_alloc_unbound alloc_unbound;
+	struct evtchn_close close;
 	struct xenbus_transaction xbt;
 
         /* Nothing to do if running in dom0. */
         if (is_initial_xendomain())
-	  return -ENODEV;
+		return -ENODEV;
+#if 1
         /* if we're not set up to use graphics mode, then don't initialize */
 	if (xenbus_scanf(XBT_NIL, "console", "use_graphics", "%d", &ret) < 0)
-	  return -ENODEV;
+		return -ENODEV;
 	if (ret == 0)
-	  return -ENODEV;
+		return -ENODEV;
+#endif
 
 	info = kmalloc(sizeof(*info), GFP_KERNEL);
 	if (info == NULL)
@@ -398,6 +413,7 @@ static int __init xenfb_probe(void)
 		info->pages[i] = vmalloc_to_page(info->fb + i * PAGE_SIZE);
 
 	fb_info = framebuffer_alloc(sizeof(u32) * 256, NULL);
+	// FIXME sizeof(struct xenfb_info)
 	if (fb_info == NULL)
 		goto error_kfree;
 
@@ -419,9 +435,9 @@ static int __init xenfb_probe(void)
 		info->mfns[i] = vmalloc_to_mfn(info->fb + i * PAGE_SIZE);
 	info->page->pd[0] = vmalloc_to_mfn(info->mfns);
 	info->page->pd[1] = 0;
-	info->page->width = 800;
-	info->page->height = 600;
-	info->page->depth = 32;
+	info->page->width = XENFB_WIDTH;
+	info->page->height = XENFB_HEIGHT;
+	info->page->depth = XENFB_DEPTH;
 	info->page->line_length = (info->page->depth / 8) * info->page->width;
 	info->page->mem_length = xenfb_mem_len;
 	info->page->in_cons = info->page->in_prod = 0;
@@ -429,11 +445,13 @@ static int __init xenfb_probe(void)
 
 	ret = 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 = ret;
+	if (ret < 0) {
+		close.port = info->evtchn;
+		HYPERVISOR_event_channel_op(EVTCHNOP_close, &close);
+		goto error_freep;
+	}
+
+	info->irq = ret;
 	xenfb_info = info;
 
 	fb_info->pseudo_palette = fb_info->par;
@@ -480,6 +498,8 @@ static int __init xenfb_probe(void)
 	info->refresh.data = (unsigned long)info;
 
 	info->kthread = kthread_run(xenfb_thread, info, "xenfb thread");
+	if (IS_ERR(info->kthread))
+		goto error_unbind;
 
 	ret = register_framebuffer(fb_info);
 	if (ret)
@@ -491,6 +511,7 @@ static int __init xenfb_probe(void)
 		goto error_unreg;
 	ret = xenbus_printf(xbt, "vfb", "page-ref", "%lu",
 			    virt_to_mfn(info->page));
+	// FIXME grant tables?
 	if (ret)
 		goto error_xenbus;
 	ret = xenbus_printf(xbt, "vfb", "event-channel", "%u",
@@ -504,8 +525,6 @@ static int __init xenfb_probe(void)
 		goto error_unreg;
 	}
 
-	info->page->initialized = 1; /* FIXME needed?  move up? */
-
 	return 0;
 
  error_xenbus:
@@ -513,8 +532,8 @@ static int __init xenfb_probe(void)
  error_unreg:
 	unregister_framebuffer(fb_info);
  error_unbind:
-	unbind_from_irqhandler(xenfb_irq, info);
-	xenfb_irq = 0;
+	unbind_from_irqhandler(info->irq, info);
+	// FIXME do we have to stop info->kthread?
  error_freep:
 	free_page((unsigned long)info->page);
  error_kfree:
@@ -528,30 +547,6 @@ static int __init xenfb_probe(void)
 	return -ENODEV;
 }
 
-void xenfb_resume(void)
-{
-#if 0 /* FIXME */
-	int i, ret;
-
-	xenfb_info->page = mfn_to_virt(xen_start_info->fbdev_mfn);
-	for (i = 0; i < xenfb_info->nr_pages; i++)
-		xenfb_info->mfns[i] = vmalloc_to_mfn(xenfb_info->fb + i * PAGE_SIZE);
-	xenfb_info->page->pd[0] = vmalloc_to_mfn(xenfb_info->mfns);
-
-	if (xenfb_irq)
-		unbind_from_irqhandler(xenfb_irq, NULL);
-
-	printk("xenfb: resume(%d)\n", xen_start_info->fbdev_evtchn);
-	ret = bind_evtchn_to_irqhandler(xen_start_info->fbdev_evtchn,
-					xenfb_event_handler, 0, "xenfb", xenfb_info);
-	if (ret <= 0)
-		return;
-	xenfb_irq = ret;
-#else
-	printk(KERN_DEBUG "xenfb_resume not implemented\n");
-#endif
-}
-
 static int __init xenfb_init(void)
 {
 	return xenfb_probe();
@@ -562,8 +557,7 @@ static void __exit xenfb_cleanup(void)
 	struct xenfb_info *info = xenfb_info;
 
 	unregister_framebuffer(info->fb_info);
-	unbind_from_irqhandler(xenfb_irq, info);
-	xenfb_irq = 0;
+	unbind_from_irqhandler(info->irq, info);
 	free_page((unsigned long)info->page);
 	kfree(info->pages);
 	vfree(info->fb);
diff -r 158f57cd19f6 -r 74930c9686ba linux-2.6-xen-sparse/drivers/xen/xenkbd/xenkbd.c
--- linux-2.6-xen-sparse/drivers/xen/xenkbd/xenkbd.c	Sat Sep 02 11:25:27 2006 -0400
+++ linux-2.6-xen-sparse/drivers/xen/xenkbd/xenkbd.c	Sat Sep 02 12:12:25 2006 -0400
@@ -26,6 +26,7 @@ struct xenkbd_device
 	struct input_dev *dev;
 	struct xenkbd_info *info;
 	unsigned evtchn;
+	int irq;
 };
 
 static irqreturn_t input_handler(int rq, void *dev_id, struct pt_regs *regs)
@@ -35,14 +36,11 @@ static irqreturn_t input_handler(int rq,
 	static int button_map[3] = { BTN_RIGHT, BTN_MIDDLE, BTN_LEFT };
 	__u32 cons, prod;
 
-	if (!info || !info->initialized)
-		return IRQ_NONE;
-
 	prod = info->in_prod;
 	rmb();			/* ensure we see ring contents up to prod */
 	for (cons = info->in_cons; cons != prod; cons++) {
 		union xenkbd_in_event *event;
-		event = &XENKBD_RING_REF(info->in, cons);
+		event = &XENKBD_IN_RING_REF(info, cons);
 	
 		switch (event->type) {
 		case XENKBD_TYPE_MOTION:
@@ -59,18 +57,16 @@ static irqreturn_t input_handler(int rq,
 			input_report_key(dev->dev, event->key.keycode, event->key.pressed);
 			break;
 		}
-
-		notify_remote_via_evtchn(dev->evtchn);
 	}
 	input_sync(dev->dev);
-	/* FIXME do I need a wmb() here? */
+	mb();			/* ensure we got ring contents */
 	info->in_cons = cons;
+	notify_remote_via_evtchn(dev->evtchn);
 
 	return IRQ_HANDLED;
 }
 
 static struct xenkbd_device *xenkbd_dev;
-static int xenkbd_irq;
 
 int __init xenkbd_init(void)
 {
@@ -84,11 +80,13 @@ int __init xenkbd_init(void)
         /* Nothing to do if running in dom0. */
         if (is_initial_xendomain())
 	  return -ENODEV;
+#if 1
         /* if we're not set up to use graphics mode, then don't initialize */
 	if (xenbus_scanf(XBT_NIL, "console", "use_graphics", "%d", &ret) < 0)
 	  return -ENODEV;
 	if (ret == 0)
 	  return -ENODEV;
+#endif
 
 	dev = kmalloc(sizeof(*dev), GFP_KERNEL);
 	input_dev = input_allocate_device();
@@ -101,7 +99,6 @@ int __init xenkbd_init(void)
 		ret = -ENOMEM;
 		goto error;
 	}
-	dev->info->initialized = 0;
 
 	alloc_unbound.dom = DOMID_SELF;
 	alloc_unbound.remote_dom = 0;
@@ -114,8 +111,7 @@ int __init xenkbd_init(void)
 					"xenkbd", dev);
 	if (ret < 0)
 		goto error_freep;
-
-	xenkbd_irq = ret;
+	dev->irq = ret;
 
 	input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_REL);
 	input_dev->keybit[LONG(BTN_MOUSE)] = BIT(BTN_LEFT) | BIT(BTN_RIGHT);
@@ -145,14 +141,11 @@ int __init xenkbd_init(void)
 	if (ret) {
 		if (ret == -EAGAIN)
 			goto again;
-		/* FIXME really retry forever? */
 		goto error_unreg;
 	}
 
 	dev->info->in_cons = dev->info->in_prod = 0;
 	dev->info->out_cons = dev->info->out_prod = 0;
-	dev->info->initialized = 1; /* FIXME needed?  move up? */
-
 	xenkbd_dev = dev;
 
 	return ret;
@@ -162,50 +155,21 @@ int __init xenkbd_init(void)
 	xenbus_transaction_end(xbt, 1);
  error_unreg:
 	input_unregister_device(input_dev);
-	unbind_from_irqhandler(xenkbd_irq, dev);
-	xenkbd_irq = 0;
+	unbind_from_irqhandler(dev->irq, dev);
  error_freep:
 	free_page((unsigned long)dev->info);
  error:
 	kfree(dev);
-	xenkbd_dev = NULL;
 	return ret;
 }
 
 static void __exit xenkbd_cleanup(void)
 {
 	input_unregister_device(xenkbd_dev->dev);
-	unbind_from_irqhandler(xenkbd_irq, xenkbd_dev);
-	xenkbd_irq = 0;
+	unbind_from_irqhandler(xenkbd_dev->irq, xenkbd_dev);
 	free_page((unsigned long)xenkbd_dev->info);
 	kfree(xenkbd_dev);
 	xenkbd_dev = NULL;
-}
-
-void xenkbd_resume(void)
-{
-#if 0 /* FIXME */
-	int ret;
-
-	if (xenkbd_dev && xen_start_info->kbd_evtchn) {
-		if (xenkbd_irq)
-			unbind_from_irqhandler(xenkbd_irq, NULL);
-
-		ret = bind_evtchn_to_irqhandler(xen_start_info->kbd_evtchn,
-						input_handler,
-						0,
-						"xenkbd",
-						xenkbd_dev);
-
-		if (ret <= 0)
-			return;
-
-		xenkbd_irq = ret;
-		xenkbd_dev->info = mfn_to_virt(xen_start_info->kbd_mfn);
-	}
-#else
-	printk(KERN_DEBUG "xenkbd_resume not implemented\n");
-#endif
 }
 
 module_init(xenkbd_init);
diff -r 158f57cd19f6 -r 74930c9686ba linux-2.6-xen-sparse/include/linux/xenfb.h
--- linux-2.6-xen-sparse/include/linux/xenfb.h	Sat Sep 02 11:25:27 2006 -0400
+++ linux-2.6-xen-sparse/include/linux/xenfb.h	Sat Sep 02 12:12:25 2006 -0400
@@ -17,10 +17,12 @@
 
 /* out events */
 
+#define XENFB_OUT_EVENT_SIZE 40
+
 #define XENFB_TYPE_MOTION 1
 #define XENFB_TYPE_UPDATE 2
 
-struct xenfb_motion
+struct xenfb_motion	    /* currently unused */
 {
 	__u8 type;          /* XENFB_TYPE_MOTION */
 	__u16 x;            /* The new x coordinate */
@@ -41,10 +43,12 @@ union xenfb_out_event
 	__u8 type;
 	struct xenfb_motion motion;
 	struct xenfb_update update;
-	char _[40];
+	char _[XENFB_OUT_EVENT_SIZE];
 };
 
 /* in events */
+
+#define XENFB_IN_EVENT_SIZE 40
 
 #define XENFB_TYPE_SET_EVENTS 1
 
@@ -63,33 +67,40 @@ union xenfb_in_event
 {
 	__u8 type;
 	struct xenfb_set_events set_events;
-	char _[40];
+	char _[XENFB_OUT_EVENT_SIZE];
 };
 
 /* shared page */
 
-#define XENFB_IN_RING_SIZE (1024 / 40)
-#define XENFB_OUT_RING_SIZE (2048 / 40)
+#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_RING_SIZE(ring) (sizeof((ring)) / sizeof(*(ring)))
-#define XENFB_RING_REF(ring, idx) (ring)[(idx) % XENFB_RING_SIZE((ring))]
+#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
 {
-	__u8 initialized;
 	__u16 width;         /* the width of the framebuffer (in pixels) */
 	__u16 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) */
 
-	unsigned long pd[2];
+	unsigned long pd[2];	/* FIXME rename to pgdir? */
+	/* FIXME pd[1] unused at this time, shrink? */
 
 	__u32 in_cons, in_prod;
 	__u32 out_cons, out_prod;
-
-	union xenfb_in_event in[XENFB_IN_RING_SIZE];
-	union xenfb_out_event out[XENFB_OUT_RING_SIZE];
 };
 
 void xenfb_resume(void);
diff -r 158f57cd19f6 -r 74930c9686ba linux-2.6-xen-sparse/include/linux/xenkbd.h
--- linux-2.6-xen-sparse/include/linux/xenkbd.h	Sat Sep 02 11:25:27 2006 -0400
+++ linux-2.6-xen-sparse/include/linux/xenkbd.h	Sat Sep 02 12:12:25 2006 -0400
@@ -16,6 +16,8 @@
 #include <asm/types.h>
 
 /* in events */
+
+#define XENKBD_IN_EVENT_SIZE 40
 
 #define XENKBD_TYPE_MOTION  1     /* mouse movement event */
 #define XENKBD_TYPE_BUTTON  2     /* mouse button event */
@@ -48,33 +50,41 @@ union xenkbd_in_event
 	struct xenkbd_motion motion;
 	struct xenkbd_button button;
 	struct xenkbd_key key;
-	char _[40];
+	char _[XENKBD_IN_EVENT_SIZE];
 };
 
 /* out events */
 
+#define XENKBD_OUT_EVENT_SIZE 40
+
 union xenkbd_out_event
 {
 	__u8 type;
-	char _[40];
+	char _[XENKBD_OUT_EVENT_SIZE];
 };
 
 /* shared page */
 
-#define XENKBD_IN_RING_SIZE (2048 / 40)
-#define XENKBD_OUT_RING_SIZE (1024 / 40)
+#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_RING_SIZE(ring) (sizeof((ring)) / sizeof(*(ring)))
-#define XENKBD_RING_REF(ring, idx) (ring)[(idx) % XENKBD_RING_SIZE((ring))]
+#define XENKBD_OUT_RING_SIZE 1024
+#define XENKBD_OUT_RING_LEN (XENKBD_OUT_RING_SIZE / XENKBD_OUT_EVENT_SIZE)
+#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_info
 {
-	__u8 initialized;
 	__u32 in_cons, in_prod;
 	__u32 out_cons, out_prod;
-
-	union xenkbd_in_event in[XENKBD_IN_RING_SIZE];
-	union xenkbd_out_event out[XENKBD_OUT_RING_SIZE];
 };
 
 void xenkbd_resume(void);
openSUSE Build Service is sponsored by