packages: kernel/kernel.spec, kernel/kernel-virtio-gl-accel.patch (NEW) - a...

evil evil at pld-linux.org
Thu Feb 24 17:29:20 CET 2011


Author: evil                         Date: Thu Feb 24 16:29:20 2011 GMT
Module: packages                      Tag: HEAD
---- Log message:
- added virtio-gl-accel.patch and virtio_gl bcond for building kernels supporting OpenGL acceleration under qemu-gl guest OS

---- Files affected:
packages/kernel:
   kernel.spec (1.880 -> 1.881) , kernel-virtio-gl-accel.patch (NONE -> 1.1)  (NEW)

---- Diffs:

================================================================
Index: packages/kernel/kernel.spec
diff -u packages/kernel/kernel.spec:1.880 packages/kernel/kernel.spec:1.881
--- packages/kernel/kernel.spec:1.880	Wed Feb 23 11:59:34 2011
+++ packages/kernel/kernel.spec	Thu Feb 24 17:29:13 2011
@@ -32,6 +32,7 @@
 %bcond_with	fbcondecor	# build fbcondecor (disable FB_TILEBLITTING and affected fb modules)
 %bcond_with	pae		# build PAE (HIGHMEM64G) support on uniprocessor
 %bcond_with	nfsroot		# build with root on NFS support
+%bcond_with	virtio_gl	# build with virtio_gl thats avaible under guest OS with patched qemu (qemu-gl.spec)
 
 %bcond_without	imq		# imq support
 %bcond_without	wrr		# wrr support
@@ -56,6 +57,10 @@
 %define		with_pax		1
 %endif
 
+%if %{with virtio_gl}
+%define		with_virtiogl		1
+%endif
+
 %define		have_drm	1
 %define		have_oss	1
 %define		have_sound	1
@@ -102,7 +107,7 @@
 %endif
 %else
 %if %{without rescuecd}
-%define		__alt_kernel	%{?with_pax:pax}%{!?with_grsecurity:nogrsecurity}%{?with_pae:pae}
+%define		__alt_kernel	%{?with_pax:pax}%{!?with_grsecurity:nogrsecurity}%{?with_pae:pae}%{?with_virtiogl:virtiogl}
 %if "%{__alt_kernel}" != ""
 %define		alt_kernel	%{__alt_kernel}
 %endif
@@ -305,6 +310,7 @@
 # Do not remove this line, please. It is easier for me to uncomment two lines, then patch
 # kernel.spec every time.
 #Patch50000:	kernel-usb_reset.patch
+Patch60000:	kernel-virtio-gl-accel.patch
 
 URL:		http://www.kernel.org/
 BuildRequires:	binutils >= 3:2.18
@@ -440,6 +446,7 @@
 %{?with_pax:PaX support - enabled}\
 %{?with_fbcondecor:Fbsplash/fbcondecor - enabled }\
 %{?with_nfsroot:Root on NFS - enabled}\
+%{?with_virtiogl:virtio_gl for qemu-gl guest OpenGL accel - enabled}\
 
 %define Features %(echo "%{__features}" | sed '/^$/d')
 
@@ -803,12 +810,13 @@
 %patch300 -p1
 
 # Small fixes:
-%patch2000 -p1
+#%patch2000 -p1
 %patch2001 -p1
 #%patch2003 -p1
 
 # Do not remove this, please!
 #%patch50000 -p1
+%{?with_virtiogl:%patch60000 -p1}
 
 # Fix EXTRAVERSION in main Makefile
 sed -i 's#EXTRAVERSION =.*#EXTRAVERSION = %{postver}%{?alt_kernel:_%{alt_kernel}}#g' Makefile
@@ -965,6 +973,10 @@
 		CONFIG_ROOT_NFS=y
 %endif
 
+%if %{with virtio_gl}
+		CONFIG_VIRTIOGL=m
+%endif
+
 # Temporary disabled RELOCATABLE. Needed only on x86??
 %if %{with pax} || %{with grsecurity}
 		CONFIG_RELOCATABLE=n
@@ -1532,6 +1544,9 @@
 All persons listed below can be reached at <cvs_login>@pld-linux.org
 
 $Log$
+Revision 1.881  2011/02/24 16:29:13  evil
+- added virtio-gl-accel.patch and virtio_gl bcond for building kernels supporting OpenGL acceleration under qemu-gl guest OS
+
 Revision 1.880  2011/02/23 10:59:34  arekm
 - up to 2.6.37.1
 

================================================================
Index: packages/kernel/kernel-virtio-gl-accel.patch
diff -u /dev/null packages/kernel/kernel-virtio-gl-accel.patch:1.1
--- /dev/null	Thu Feb 24 17:29:20 2011
+++ packages/kernel/kernel-virtio-gl-accel.patch	Thu Feb 24 17:29:13 2011
@@ -0,0 +1,372 @@
+diff --git a/drivers/gpu/Makefile b/drivers/gpu/Makefile
+index 30879df..35699a0 100644
+--- a/drivers/gpu/Makefile
++++ b/drivers/gpu/Makefile
+@@ -1 +1 @@
+-obj-y			+= drm/ vga/ stub/
++obj-y			+= drm/ vga/ stub/ misc/
+diff --git a/drivers/gpu/misc/Kconfig b/drivers/gpu/misc/Kconfig
+new file mode 100644
+index 0000000..50043d3
+--- /dev/null
++++ b/drivers/gpu/misc/Kconfig
+@@ -0,0 +1,8 @@
++config VIRTIOGL
++        tristate "Virtio userspace memory transport"
++        depends on VIRTIO_PCI
++        default n
++        help
++          A Driver to facilitate transferring data from userspace to a
++          hypervisor (eg. qemu)
++
+diff --git a/drivers/gpu/misc/Makefile b/drivers/gpu/misc/Makefile
+new file mode 100644
+index 0000000..d9ab333
+--- /dev/null
++++ b/drivers/gpu/misc/Makefile
+@@ -0,0 +1 @@
++obj-$(CONFIG_VIRTIOGL)          += virtio-gl.o
+diff --git a/drivers/gpu/misc/virtio-gl.c b/drivers/gpu/misc/virtio-gl.c
+new file mode 100644
+index 0000000..8882bda
+--- /dev/null
++++ b/drivers/gpu/misc/virtio-gl.c
+@@ -0,0 +1,312 @@
++/*
++ * Copyright (C) 2010 Intel Corporation
++ *
++ * Author: Ian Molton <ian.molton at collabora.co.uk>
++ *
++ * This program is free software; you can redistribute it and/or modify
++ * it under the terms of the GNU General Public License as published by
++ * the Free Software Foundation; either version 2 of the License, or
++ * (at your option) any later version.
++ *
++ * This program is distributed in the hope that it will be useful,
++ * but WITHOUT ANY WARRANTY; without even the implied warranty of
++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
++ * GNU General Public License for more details.
++ *
++ * You should have received a copy of the GNU General Public License
++ * along with this program; if not, write to the Free Software
++ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
++ */
++
++#include <linux/kernel.h>
++#include <linux/module.h>
++#include <linux/fs.h>
++#include <linux/dma-mapping.h>
++#include <linux/sched.h>
++#include <linux/slab.h>
++#include <linux/miscdevice.h>
++#include <linux/virtio.h>
++#include <linux/virtio_ids.h>
++#include <linux/virtio_config.h>
++
++#define DEVICE_NAME "glmem"
++
++/* Define to use debugging checksums on transfers */
++#undef DEBUG_GLIO
++
++struct virtio_gl_data {
++	char *buffer;
++	int pages;
++	unsigned int pid;
++};
++
++struct virtio_gl_header {
++	int pid;
++	int buf_size;
++	int r_buf_size;
++#ifdef DEBUG_GLIO
++	int sum;
++#endif
++	char buffer;
++} __packed;
++
++#define to_virtio_gl_data(a)   ((struct virtio_gl_data *)(a)->private_data)
++
++#ifdef DEBUG_GLIO
++#define SIZE_OUT_HEADER (sizeof(int)*4)
++#define SIZE_IN_HEADER (sizeof(int)*2)
++#else
++#define SIZE_OUT_HEADER (sizeof(int)*3)
++#define SIZE_IN_HEADER sizeof(int)
++#endif
++
++static struct virtqueue *vq;
++
++
++/* This is videobuf_vmalloc_to_sg() from videobuf-dma-sg.c with
++ * some modifications
++ */
++static struct scatterlist *vmalloc_to_sg(struct scatterlist *sg_list,
++				unsigned char *virt, unsigned int pages)
++{
++	struct page *pg;
++
++	/* unaligned */
++	BUG_ON((ulong)virt & ~PAGE_MASK);
++
++	/* Fill with elements for the data */
++	while (pages) {
++		pg = vmalloc_to_page(virt);
++		if (!pg)
++			goto err;
++
++		sg_set_page(sg_list, pg, PAGE_SIZE, 0);
++		virt += PAGE_SIZE;
++		sg_list++;
++		pages--;
++	}
++
++	return sg_list;
++
++err:
++	kfree(sg_list);
++	return NULL;
++}
++
++static int put_data(struct virtio_gl_data *gldata)
++{
++	struct scatterlist *sg, *sg_list;
++	unsigned int count, ret, o_page, i_page, sg_entries;
++	struct virtio_gl_header *header =
++				(struct virtio_gl_header *)gldata->buffer;
++
++	ret = header->buf_size;
++
++	o_page = (header->buf_size + PAGE_SIZE-1) >> PAGE_SHIFT;
++	i_page = (header->r_buf_size + PAGE_SIZE-1) >> PAGE_SHIFT;
++
++	header->pid = gldata->pid;
++
++	if ((o_page && i_page) &&
++		(o_page > gldata->pages || i_page > gldata->pages)) {
++		i_page = 0;
++	}
++
++	if (o_page > gldata->pages)
++		o_page = gldata->pages;
++
++	if (i_page > gldata->pages)
++		i_page = gldata->pages;
++
++	if (!o_page)
++		o_page = 1;
++
++	sg_entries = o_page + i_page;
++
++	sg_list = kcalloc(sg_entries, sizeof(struct scatterlist), GFP_KERNEL);
++
++	if (!sg_list) {
++		ret = -EIO;
++		goto out;
++	}
++
++	sg_init_table(sg_list, sg_entries);
++
++	sg = vmalloc_to_sg(sg_list, gldata->buffer, o_page);
++	sg = vmalloc_to_sg(sg, gldata->buffer, i_page);
++
++	if (!sg) {
++		ret = -EIO;
++		goto out_free;
++	}
++
++	/* Transfer data */
++	if (virtqueue_add_buf(vq, sg_list, o_page, i_page, (void *)1) >= 0) {
++		virtqueue_kick(vq);
++		/* Chill out until it's done with the buffer. */
++		while (!virtqueue_get_buf(vq, &count))
++			cpu_relax();
++	}
++
++out_free:
++	kfree(sg_list);
++out:
++	return ret;
++}
++
++static void free_buffer(struct virtio_gl_data *gldata)
++{
++	if (gldata->buffer) {
++		vfree(gldata->buffer);
++		gldata->buffer = NULL;
++	}
++}
++
++static int glmem_open(struct inode *inode, struct file *file)
++{
++	struct virtio_gl_data *gldata = kzalloc(sizeof(struct virtio_gl_data),
++						GFP_KERNEL);
++
++	if (!gldata)
++		return -ENXIO;
++
++	gldata->pid = pid_nr(task_pid(current));
++
++	file->private_data = gldata;
++
++	return 0;
++}
++
++static int glmem_mmap(struct file *filp, struct vm_area_struct *vma)
++{
++	struct virtio_gl_data *gldata = to_virtio_gl_data(filp);
++	int pages = (vma->vm_end - vma->vm_start) / PAGE_SIZE;
++
++	/* Set a reasonable limit */
++	if (pages > 16)
++		return -ENOMEM;
++
++	/* for now, just allow one buffer to be mmap()ed. */
++	if (gldata->buffer)
++		return -EIO;
++
++	gldata->buffer = vmalloc_user(pages*PAGE_SIZE);
++
++	if (!gldata->buffer)
++		return -ENOMEM;
++
++	gldata->pages = pages;
++
++	if (remap_vmalloc_range(vma, gldata->buffer, 0) < 0) {
++		vfree(gldata->buffer);
++		return -EIO;
++	}
++
++	vma->vm_flags |= VM_DONTEXPAND;
++
++	return 0;
++}
++
++static int glmem_fsync(struct file *filp, int datasync)
++{
++	struct virtio_gl_data *gldata = to_virtio_gl_data(filp);
++
++	put_data(gldata);
++
++	return 0;
++}
++
++static int glmem_release(struct inode *inode, struct file *file)
++{
++	struct virtio_gl_data *gldata = to_virtio_gl_data(file);
++
++	if (gldata && gldata->buffer) {
++		struct virtio_gl_header *header =
++				(struct virtio_gl_header *)gldata->buffer;
++
++		/* Make sure the host hears about the process ending / dying */
++		header->pid = gldata->pid;
++		header->buf_size = SIZE_OUT_HEADER + 2;
++		header->r_buf_size = SIZE_IN_HEADER;
++		*(short *)(&header->buffer) = -1;
++
++		put_data(gldata);
++		free_buffer(gldata);
++	}
++
++	kfree(gldata);
++
++	return 0;
++}
++
++static const struct file_operations glmem_fops = {
++	.owner		= THIS_MODULE,
++	.open		= glmem_open,
++	.mmap		= glmem_mmap,
++	.fsync		= glmem_fsync,
++	.release	= glmem_release,
++};
++
++static struct miscdevice glmem_dev = {
++	MISC_DYNAMIC_MINOR,
++	DEVICE_NAME,
++	&glmem_fops
++};
++
++static int glmem_probe(struct virtio_device *vdev)
++{
++	int ret;
++
++	/* We expect a single virtqueue. */
++	vq = virtio_find_single_vq(vdev, NULL, "output");
++	if (IS_ERR(vq))
++		return PTR_ERR(vq);
++
++	ret = misc_register(&glmem_dev);
++	if (ret) {
++		printk(KERN_ERR "glmem: cannot register glmem_dev as misc");
++		return -ENODEV;
++	}
++
++	return 0;
++}
++
++static void __devexit glmem_remove(struct virtio_device *vdev)
++{
++	vdev->config->reset(vdev);
++	misc_deregister(&glmem_dev);
++	vdev->config->del_vqs(vdev);
++}
++
++static struct virtio_device_id id_table[] = {
++	{ VIRTIO_ID_GL, VIRTIO_DEV_ANY_ID },
++	{ 0 },
++};
++
++static struct virtio_driver virtio_gl_driver = {
++	.driver	= {
++		.name =  KBUILD_MODNAME,
++		.owner = THIS_MODULE,
++	},
++	.id_table =     id_table,
++	.probe =        glmem_probe,
++	.remove =       __devexit_p(glmem_remove),
++};
++
++static int __init glmem_init(void)
++{
++	return register_virtio_driver(&virtio_gl_driver);
++}
++
++static void __exit glmem_exit(void)
++{
++	unregister_virtio_driver(&virtio_gl_driver);
++}
++
++module_init(glmem_init);
++module_exit(glmem_exit);
++
++MODULE_DEVICE_TABLE(virtio, id_table);
++MODULE_DESCRIPTION("Virtio gl passthrough driver");
++MODULE_LICENSE("GPL v2");
++
+diff --git a/drivers/video/Kconfig b/drivers/video/Kconfig
+index 3d94a14..9a9a6cc 100644
+--- a/drivers/video/Kconfig
++++ b/drivers/video/Kconfig
+@@ -16,6 +16,7 @@ source "drivers/char/agp/Kconfig"
+ source "drivers/gpu/vga/Kconfig"
+ 
+ source "drivers/gpu/drm/Kconfig"
++source "drivers/gpu/misc/Kconfig"
+ 
+ config VGASTATE
+        tristate
+diff --git a/include/linux/virtio_ids.h b/include/linux/virtio_ids.h
+index 06660c0..663b496 100644
+--- a/include/linux/virtio_ids.h
++++ b/include/linux/virtio_ids.h
+@@ -12,6 +12,7 @@
+ #define VIRTIO_ID_CONSOLE	3 /* virtio console */
+ #define VIRTIO_ID_RNG		4 /* virtio ring */
+ #define VIRTIO_ID_BALLOON	5 /* virtio balloon */
++#define VIRTIO_ID_GL		6 /* virtio usermem */
+ #define VIRTIO_ID_9P		9 /* 9p virtio console */
+ 
+ #endif /* _LINUX_VIRTIO_IDS_H */
+
+
================================================================

---- CVS-web:
    http://cvs.pld-linux.org/cgi-bin/cvsweb.cgi/packages/kernel/kernel.spec?r1=1.880&r2=1.881&f=u



More information about the pld-cvs-commit mailing list