[Openchrome-devel] drm-openchrome: configure.ac src/gallium/Android.mk src/gallium/drivers src/gallium/Makefile.am src/gallium/targets src/gallium/winsys

James Simmons jsimmons at kemper.freedesktop.org
Tue Jan 6 19:02:08 PST 2015


 configure.ac                                              |   11 
 src/gallium/Android.mk                                    |    5 
 src/gallium/Makefile.am                                   |    5 
 src/gallium/drivers/openchrome/Android.mk                 |   35 +
 src/gallium/drivers/openchrome/Automake.inc               |   10 
 src/gallium/drivers/openchrome/Makefile.am                |   30 +
 src/gallium/drivers/openchrome/Makefile.sources           |    3 
 src/gallium/drivers/openchrome/openchrome_resource.c      |  127 +++++
 src/gallium/drivers/openchrome/openchrome_resource.h      |   31 +
 src/gallium/drivers/openchrome/openchrome_screen.c        |  186 +++++++
 src/gallium/drivers/openchrome/openchrome_screen.h        |   69 ++
 src/gallium/targets/d3dadapter9/Makefile.am               |    2 
 src/gallium/targets/dri/Makefile.am                       |    2 
 src/gallium/targets/egl-static/Android.mk                 |    3 
 src/gallium/targets/egl-static/Makefile.am                |    2 
 src/gallium/targets/gbm/Makefile.am                       |    2 
 src/gallium/targets/pipe-loader/Makefile.am               |   13 
 src/gallium/targets/pipe-loader/pipe_openchrome.c         |   17 
 src/gallium/targets/xa/Makefile.am                        |    2 
 src/gallium/winsys/openchrome/drm/Android.mk              |   38 +
 src/gallium/winsys/openchrome/drm/Makefile.am             |   33 +
 src/gallium/winsys/openchrome/drm/Makefile.sources        |    7 
 src/gallium/winsys/openchrome/drm/openchrome_drm_bufmgr.c |  192 +++++++
 src/gallium/winsys/openchrome/drm/openchrome_drm_bufmgr.h |   62 ++
 src/gallium/winsys/openchrome/drm/openchrome_drm_winsys.c |   70 ++
 src/gallium/winsys/openchrome/drm/openchrome_drm_winsys.h |   41 +
 src/gallium/winsys/openchrome/drm/via_drm.h               |  354 ++++++++++++++
 27 files changed, 1351 insertions(+), 1 deletion(-)

New commits:
commit 716c57efe8e28867baf25d791c5fb7cfd130a105
Author: James Simmons <jsimmons at infradead.org>
Date:   Tue Jan 6 19:44:57 2015 -0700

    openchrome: gallium driver for VIA hardware
    
    Start of Gallium driver for VIA hardware. Currently it is a little
    skeleton driver but the plan it to expand it to suport glamour with
    our xorg driver. This way we don't need to make a specific libdrm
    sub library but instead just work on one code base. The plan is make
    the driver core code be platform independent and winsys contain the
    libdrm type code.
    
    Signed-off-by: James Simmons <jsimmons at infradead.org>

diff --git a/configure.ac b/configure.ac
index c8723ef..84294f1 100644
--- a/configure.ac
+++ b/configure.ac
@@ -742,7 +742,7 @@ GALLIUM_DRIVERS_DEFAULT="r300,r600,svga,swrast"
 AC_ARG_WITH([gallium-drivers],
     [AS_HELP_STRING([--with-gallium-drivers@<:@=DIRS...@:>@],
         [comma delimited Gallium drivers list, e.g.
-        "i915,ilo,nouveau,r300,r600,radeonsi,freedreno,svga,swrast,vc4"
+        "i915,ilo,nouveau,r300,r600,radeonsi,freedreno,openchrome,svga,swrast,vc4"
         @<:@default=r300,r600,svga,swrast@:>@])],
     [with_gallium_drivers="$withval"],
     [with_gallium_drivers="$GALLIUM_DRIVERS_DEFAULT"])
@@ -1946,6 +1946,12 @@ if test -n "$with_gallium_drivers"; then
             gallium_require_drm "freedreno"
             gallium_require_drm_loader
             ;;
+        xopenchrome)
+            HAVE_GALLIUM_OPENCHROME=yes
+            gallium_require_drm "openchrome"
+            gallium_require_drm_loader
+            require_egl_drm "openchrome"
+            ;;
         xswrast)
             HAVE_GALLIUM_SOFTPIPE=yes
             if test "x$MESA_LLVM" = x1; then
@@ -2029,6 +2035,7 @@ AM_CONDITIONAL(HAVE_GALLIUM_NOUVEAU, test "x$HAVE_GALLIUM_NOUVEAU" = xyes)
 AM_CONDITIONAL(HAVE_GALLIUM_FREEDRENO, test "x$HAVE_GALLIUM_FREEDRENO" = xyes)
 AM_CONDITIONAL(HAVE_GALLIUM_SOFTPIPE, test "x$HAVE_GALLIUM_SOFTPIPE" = xyes)
 AM_CONDITIONAL(HAVE_GALLIUM_LLVMPIPE, test "x$HAVE_GALLIUM_LLVMPIPE" = xyes)
+AM_CONDITIONAL(HAVE_GALLIUM_OPENCHROME, test "x$HAVE_GALLIUM_OPENCHROME" = xyes)
 AM_CONDITIONAL(HAVE_GALLIUM_VC4, test "x$HAVE_GALLIUM_VC4" = xyes)
 
 AM_CONDITIONAL(HAVE_GALLIUM_STATIC_TARGETS, test "x$enable_shared_pipe_drivers" = xno)
@@ -2160,6 +2167,7 @@ AC_CONFIG_FILES([Makefile
 		src/gallium/drivers/llvmpipe/Makefile
 		src/gallium/drivers/noop/Makefile
 		src/gallium/drivers/nouveau/Makefile
+		src/gallium/drivers/openchrome/Makefile
 		src/gallium/drivers/r300/Makefile
 		src/gallium/drivers/r600/Makefile
 		src/gallium/drivers/radeon/Makefile
@@ -2198,6 +2206,7 @@ AC_CONFIG_FILES([Makefile
 		src/gallium/tests/trivial/Makefile
 		src/gallium/tests/unit/Makefile
 		src/gallium/winsys/freedreno/drm/Makefile
+		src/gallium/winsys/openchrome/drm/Makefile
 		src/gallium/winsys/i915/drm/Makefile
 		src/gallium/winsys/intel/drm/Makefile
 		src/gallium/winsys/nouveau/drm/Makefile
diff --git a/src/gallium/Android.mk b/src/gallium/Android.mk
index bf99e4f..d036235 100644
--- a/src/gallium/Android.mk
+++ b/src/gallium/Android.mk
@@ -74,6 +74,11 @@ endif
 endif
 endif
 
+# openchrome
+ifneq ($(filter openchrome, $(MESA_GPU_DRIVERS)),)
+SUBDIRS += winsys/openchrome/drm drivers/openchrome
+endif
+
 # vmwgfx
 ifneq ($(filter vmwgfx, $(MESA_GPU_DRIVERS)),)
 SUBDIRS += winsys/svga/drm drivers/svga
diff --git a/src/gallium/Makefile.am b/src/gallium/Makefile.am
index 6a2a866..e875b76 100644
--- a/src/gallium/Makefile.am
+++ b/src/gallium/Makefile.am
@@ -67,6 +67,11 @@ if NEED_RADEON_DRM_WINSYS
 SUBDIRS += winsys/radeon/drm
 endif
 
+## openchrome
+if HAVE_GALLIUM_OPENCHROME
+SUBDIRS += drivers/openchrome
+endif
+
 ## swrast/softpipe
 if HAVE_GALLIUM_SOFTPIPE
 SUBDIRS += drivers/softpipe
diff --git a/src/gallium/drivers/openchrome/Android.mk b/src/gallium/drivers/openchrome/Android.mk
new file mode 100644
index 0000000..177b1e1
--- /dev/null
+++ b/src/gallium/drivers/openchrome/Android.mk
@@ -0,0 +1,35 @@
+# Mesa 3-D graphics library
+#
+# Copyright (C) 2015 James Simmons <jsimmons at infradead.org>
+#
+# Permission is hereby granted, free of charge, to any person obtaining a
+# copy of this software and associated documentation files (the "Software"),
+# to deal in the Software without restriction, including without limitation
+# the rights to use, copy, modify, merge, publish, distribute, sublicense,
+# and/or sell copies of the Software, and to permit persons to whom the
+# Software is furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+# DEALINGS IN THE SOFTWARE.
+
+LOCAL_PATH := $(call my-dir)
+
+# get C_SOURCES
+include $(LOCAL_PATH)/Makefile.sources
+
+include $(CLEAR_VARS)
+
+LOCAL_SRC_FILES := $(C_SOURCES)
+
+LOCAL_MODULE := libmesa_pipe_openchrome
+
+include $(GALLIUM_COMMON_MK)
+include $(BUILD_STATIC_LIBRARY)
diff --git a/src/gallium/drivers/openchrome/Automake.inc b/src/gallium/drivers/openchrome/Automake.inc
new file mode 100644
index 0000000..59c02ce
--- /dev/null
+++ b/src/gallium/drivers/openchrome/Automake.inc
@@ -0,0 +1,10 @@
+if HAVE_GALLIUM_OPENCHROME
+
+TARGET_DRIVERS += openchrome
+TARGET_CPPFLAGS += -DGALLIUM_OPENCHROME
+TARGET_LIB_DEPS += \
+	$(top_builddir)/src/gallium/winsys/openchrome/drm/libopenchromedrm.la \
+	$(top_builddir)/src/gallium/drivers/openchrome/libopenchrome.la \
+	$(LIBDRM_LIBS)
+
+endif
diff --git a/src/gallium/drivers/openchrome/Makefile.am b/src/gallium/drivers/openchrome/Makefile.am
new file mode 100644
index 0000000..e825614
--- /dev/null
+++ b/src/gallium/drivers/openchrome/Makefile.am
@@ -0,0 +1,30 @@
+# Copyright © 2015 James Simmons <jsimmons at infradead.org>
+#
+# Permission is hereby granted, free of charge, to any person obtaining a
+# copy of this software and associated documentation files (the "Software"),
+# to deal in the Software without restriction, including without limitation
+# the rights to use, copy, modify, merge, publish, distribute, sublicense,
+# and/or sell copies of the Software, and to permit persons to whom the
+# Software is furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice (including the next
+# paragraph) shall be included in all copies or substantial portions of the
+# Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT.  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+# DEALINGS IN THE SOFTWARE.
+
+include Makefile.sources
+include $(top_srcdir)/src/gallium/Automake.inc
+
+AM_CFLAGS = $(GALLIUM_DRIVER_CFLAGS)
+
+noinst_LTLIBRARIES = libopenchrome.la
+
+libopenchrome_la_SOURCES = $(C_SOURCES)
diff --git a/src/gallium/drivers/openchrome/Makefile.sources b/src/gallium/drivers/openchrome/Makefile.sources
new file mode 100644
index 0000000..9e39066
--- /dev/null
+++ b/src/gallium/drivers/openchrome/Makefile.sources
@@ -0,0 +1,3 @@
+C_SOURCES := \
+	openchrome_screen.c \
+	openchrome_resource.c
diff --git a/src/gallium/drivers/openchrome/openchrome_resource.c b/src/gallium/drivers/openchrome/openchrome_resource.c
new file mode 100644
index 0000000..29de675
--- /dev/null
+++ b/src/gallium/drivers/openchrome/openchrome_resource.c
@@ -0,0 +1,127 @@
+/**************************************************************************
+ *
+ * Copyright 2013 The Openchrome Project [openchrome.org]
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+ * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
+ * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ **************************************************************************/
+
+#include "pipebuffer/pb_bufmgr.h"
+#include "util/u_transfer.h"
+#include "util/u_memory.h"
+#include "util/u_format.h"
+
+#include "openchrome_screen.h"
+#include "openchrome_resource.h"
+
+static void
+openchrome_buffer_destroy(struct pipe_screen *screen,
+							struct pipe_resource *resource)
+{
+	struct openchrome_resource *res = MALLOC_STRUCT(openchrome_resource);
+
+	FREE(res);
+}
+
+static void *
+openchrome_buffer_transfer_map(struct pipe_context *ctx,
+								struct pipe_resource *resource, unsigned level,
+								unsigned usage, const struct pipe_box *box,
+								struct pipe_transfer **ptransfer)
+{
+	return NULL;
+}
+
+struct u_resource_vtbl openchrome_buffer_vtbl =
+{
+	u_default_resource_get_handle,		/* get_handle */
+	openchrome_buffer_destroy,			/* resource_destroy */
+	openchrome_buffer_transfer_map,		/* transfer_map */
+	u_default_transfer_flush_region,	/* transfer_flush_region */
+	u_default_transfer_unmap,			/* transfer_unmap */
+	u_default_transfer_inline_write		/* transfer_inline_write */
+};
+
+static struct pipe_resource *
+openchrome_buffer_create(struct pipe_screen *screen,
+							const struct pipe_resource *templ)
+{
+	struct openchrome_resource *res = MALLOC_STRUCT(openchrome_resource);
+	struct openchrome_screen *pscreen = openchrome_screen(screen);
+	struct pb_desc desc;
+	unsigned int stride;
+	pb_size size;
+
+	if (!res)
+		goto err;
+
+	stride = util_format_get_stride(templ->format, templ->width0);
+	size = align(stride * templ->height0 * templ->depth0, 16);
+
+	memset(&desc, 0, sizeof(desc));
+	desc.alignment = 16;
+	desc.usage = PB_USAGE_GPU_READ | PB_USAGE_GPU_WRITE;
+
+	res->buf = pscreen->mgr->create_buffer(pscreen->mgr, size, &desc);
+	if (!res->buf) {
+		FREE(res);
+		res = NULL;
+		goto err;
+	}
+
+	res->base.b = *templ;
+	res->base.vtbl = &openchrome_buffer_vtbl;
+	pipe_reference_init(&res->base.b.reference, 1);
+	res->base.b.screen = screen;
+
+err:
+	return &res->base.b;
+}
+
+static struct pipe_resource *
+openchrome_resource_create(struct pipe_screen *screen,
+							const struct pipe_resource *template)
+{
+	if (template->target == PIPE_BUFFER)
+		return openchrome_buffer_create(screen, template);
+	else
+		return NULL; //openchrome_texture_create(screen, template, FALSE);
+}
+
+static struct pipe_resource *
+openchrome_resource_from_handle(struct pipe_screen * screen,
+								const struct pipe_resource *template,
+								struct winsys_handle *whandle)
+{
+	if (template->target == PIPE_BUFFER)
+		return NULL;
+	else
+		return NULL; //openchrome_texture_from_handle(screen, template, whandle);
+}
+
+void openchrome_screen_resource_init(struct pipe_screen *screen)
+{
+	screen->resource_create = openchrome_resource_create;
+	screen->resource_from_handle = openchrome_resource_from_handle;
+	screen->resource_get_handle = u_resource_get_handle_vtbl;
+	screen->resource_destroy = u_resource_destroy_vtbl;
+}
diff --git a/src/gallium/drivers/openchrome/openchrome_resource.h b/src/gallium/drivers/openchrome/openchrome_resource.h
new file mode 100644
index 0000000..2d0e016
--- /dev/null
+++ b/src/gallium/drivers/openchrome/openchrome_resource.h
@@ -0,0 +1,31 @@
+/**************************************************************************
+ *
+ * Copyright 2013 The Openchrome Project [openchrome.org]
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+ * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
+ * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ **************************************************************************/
+
+struct openchrome_resource {
+	struct u_resource base;
+	struct pb_buffer *buf;
+};
diff --git a/src/gallium/drivers/openchrome/openchrome_screen.c b/src/gallium/drivers/openchrome/openchrome_screen.c
new file mode 100644
index 0000000..696e602
--- /dev/null
+++ b/src/gallium/drivers/openchrome/openchrome_screen.c
@@ -0,0 +1,186 @@
+/**************************************************************************
+ *
+ * Copyright 2013 The Openchrome Project [openchrome.org]
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+ * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
+ * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ **************************************************************************/
+
+#include "util/u_string.h"
+#include "util/u_memory.h"
+
+#include "openchrome_screen.h"
+
+static const char *
+openchrome_get_vendor(struct pipe_screen *screen)
+{
+	return "VIA Technologies, Inc.";
+}
+
+static const char *
+openchrome_get_name(struct pipe_screen *screen)
+{
+	struct openchrome_screen *pscreen = openchrome_screen(screen);
+	static char buffer[128];
+	const char *chipset;
+
+	switch (pscreen->chipset_id) {
+	case PCI_CHIP_CLE3122:
+		chipset = "CLE266";
+		break;
+
+	case PCI_CHIP_VT3205:
+		chipset = "KM400";
+		break;
+
+	case PCI_CHIP_VT3204:
+		chipset = "K8M800";
+		break;
+
+	case PCI_CHIP_VT3259:
+		chipset = "PM800";
+		break;
+
+	case PCI_CHIP_VT3314:
+		chipset = "VM800";
+		break;
+
+	case PCI_CHIP_VT3324:
+		chipset = "CX700";
+		break;
+
+	case PCI_CHIP_VT3336:
+		chipset = "K8M890";
+		break;
+
+	case PCI_CHIP_VT3327:
+		chipset = "P4M890";
+		break;
+
+	case PCI_CHIP_VT3364:
+		chipset = "P4M900";
+		break;
+
+	case PCI_CHIP_VT3353:
+		chipset = "VX800";
+		break;
+
+	case PCI_CHIP_VT3409:
+		chipset = "VX855/VX875";
+		break;
+
+	case PCI_CHIP_VT3410:
+		chipset = "VX900";
+		break;
+
+	case PCI_CHIP_VT3293:
+		chipset = "CN750";
+		break;
+
+	default:
+		chipset = "unknown";
+		break;
+	}
+
+    util_snprintf(buffer, sizeof(buffer), "via (chipset: %s)", chipset);
+    return buffer;
+}
+
+static int
+openchrome_get_param(struct pipe_screen *screen, enum pipe_cap param)
+{
+	return 0;
+}
+
+static float
+openchrome_get_paramf(struct pipe_screen *screen, enum pipe_capf param)
+{
+	return 0.0f;
+}
+
+static int
+openchrome_get_shader_param(struct pipe_screen *screen, unsigned shader,
+                            enum pipe_shader_cap param)
+{
+	return 0;
+}
+
+static int
+openchrome_get_video_param(struct pipe_screen *screen,
+                            enum pipe_video_profile profile,
+                            enum pipe_video_cap param)
+{
+	return 0;
+}
+
+static int
+openchrome_get_compute_param(struct pipe_screen *screen,
+                            enum pipe_compute_cap param, void *ret)
+{
+	return 0;
+}
+
+static uint64_t
+openchrome_get_timestamp(struct pipe_screen *screen)
+{
+	return 0;
+}
+
+static void
+openchrome_destroy_screen(struct pipe_screen *screen)
+{
+	struct openchrome_screen *pscreen = openchrome_screen(screen);
+
+	/*if (pscreen->ws)
+		pscreen->ws->destroy(pscreen->ws);*/
+
+	FREE(pscreen);
+}
+
+struct pipe_screen *
+openchrome_screen_create(struct pb_manager *mgr, int chipset_id)
+{
+	struct openchrome_screen *screen = CALLOC_STRUCT(openchrome_screen);
+	struct pipe_screen *pscreen;
+
+	if (!screen)
+		return NULL;
+
+	pscreen = &screen->base;
+
+	screen->base.get_name = openchrome_get_name;
+	screen->base.get_vendor = openchrome_get_vendor;
+	screen->base.destroy = openchrome_destroy_screen;
+	screen->base.get_param = openchrome_get_param;
+	screen->base.get_paramf = openchrome_get_paramf;
+	screen->base.get_shader_param = openchrome_get_shader_param;
+	screen->base.get_video_param = openchrome_get_video_param;
+	screen->base.get_compute_param = openchrome_get_compute_param;
+	screen->base.get_timestamp = openchrome_get_timestamp;
+
+	screen->chipset_id = chipset_id;
+	screen->mgr = mgr;
+
+	openchrome_screen_resource_init(pscreen);
+
+	return pscreen;
+}
diff --git a/src/gallium/drivers/openchrome/openchrome_screen.h b/src/gallium/drivers/openchrome/openchrome_screen.h
new file mode 100644
index 0000000..df8d913
--- /dev/null
+++ b/src/gallium/drivers/openchrome/openchrome_screen.h
@@ -0,0 +1,69 @@
+/**************************************************************************
+ *
+ * Copyright 2013 The Openchrome Project [openchrome.org]
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+ * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
+ * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ **************************************************************************/
+
+#ifndef OPENCHROME_SCREEN_H
+#define OPENCHROME_SCREEN_H
+
+#include "pipe/p_state.h"
+#include "pipe/p_screen.h"
+
+#define PCI_CHIP_CLE3122	0x3122	/* CLE266 */
+#define PCI_CHIP_VT3205		0x7205	/* KM400 */
+#define PCI_CHIP_VT3204		0x3108	/* K8M800 */
+#define PCI_CHIP_VT3259		0x3118	/* PM800 */
+#define PCI_CHIP_VT3314		0x3344	/* VM800 */
+#define PCI_CHIP_VT3324		0x3157	/* CX700 */
+#define PCI_CHIP_VT3336		0x3230	/* K8M890 */
+#define PCI_CHIP_VT3327		0x3343	/* P4M890 */
+#define PCI_CHIP_VT3364		0x3371	/* P4M900 */
+#define PCI_CHIP_VT3353		0x1122	/* VX800 */
+#define PCI_CHIP_VT3409		0x5122	/* VX855/VX875 */
+#define PCI_CHIP_VT3410		0x7122	/* VX900 */
+#define PCI_CHIP_VT3293		0x3225	/* CN750 */
+
+/**
+ * Subclass of pipe_screen
+ */
+struct openchrome_screen
+{
+    struct pipe_screen base;
+	struct pb_manager *mgr;
+
+    struct openchrome_drm_winsys *ws;
+	int chipset_id;
+};
+
+static INLINE struct openchrome_screen *
+openchrome_screen(struct pipe_screen *pscreen)
+{
+    return (struct openchrome_screen *) pscreen;
+}
+
+struct pipe_screen *openchrome_screen_create(struct pb_manager *mgr, int chipset_id);
+void openchrome_screen_resource_init(struct pipe_screen *screen);
+
+#endif	/* OPENCHROME_SCREEN_H */
diff --git a/src/gallium/targets/d3dadapter9/Makefile.am b/src/gallium/targets/d3dadapter9/Makefile.am
index 1dc55f5..21b5d0e 100644
--- a/src/gallium/targets/d3dadapter9/Makefile.am
+++ b/src/gallium/targets/d3dadapter9/Makefile.am
@@ -101,6 +101,8 @@ include $(top_srcdir)/src/gallium/drivers/svga/Automake.inc
 
 include $(top_srcdir)/src/gallium/drivers/freedreno/Automake.inc
 
+include $(top_srcdir)/src/gallium/drivers/openchrome/Automake.inc
+
 include $(top_srcdir)/src/gallium/drivers/vc4/Automake.inc
 
 include $(top_srcdir)/src/gallium/drivers/softpipe/Automake.inc
diff --git a/src/gallium/targets/dri/Makefile.am b/src/gallium/targets/dri/Makefile.am
index 5df3a20..8767c12 100644
--- a/src/gallium/targets/dri/Makefile.am
+++ b/src/gallium/targets/dri/Makefile.am
@@ -86,6 +86,8 @@ include $(top_srcdir)/src/gallium/drivers/svga/Automake.inc
 
 include $(top_srcdir)/src/gallium/drivers/freedreno/Automake.inc
 
+include $(top_srcdir)/src/gallium/drivers/openchrome/Automake.inc
+
 include $(top_srcdir)/src/gallium/drivers/vc4/Automake.inc
 
 include $(top_srcdir)/src/gallium/drivers/softpipe/Automake.inc
diff --git a/src/gallium/targets/egl-static/Android.mk b/src/gallium/targets/egl-static/Android.mk
index adaf582..7dd7d43 100644
--- a/src/gallium/targets/egl-static/Android.mk
+++ b/src/gallium/targets/egl-static/Android.mk
@@ -71,6 +71,9 @@ endif
 ifneq ($(filter radeonsi, $(MESA_GPU_DRIVERS)),)
 LOCAL_CFLAGS += -DGALLIUM_RADEONSI
 endif
+ifneq ($(filter openchrome, $(MESA_GPU_DRIVERS)),)
+LOCAL_CFLAGS += -DGALLIUM_OPENCHROME
+endif
 ifneq ($(filter vmwgfx, $(MESA_GPU_DRIVERS)),)
 LOCAL_CFLAGS += -DGALLIUM_VMWGFX
 endif
diff --git a/src/gallium/targets/egl-static/Makefile.am b/src/gallium/targets/egl-static/Makefile.am
index 85f2ac1..42576a9 100644
--- a/src/gallium/targets/egl-static/Makefile.am
+++ b/src/gallium/targets/egl-static/Makefile.am
@@ -177,6 +177,8 @@ include $(top_srcdir)/src/gallium/drivers/svga/Automake.inc
 
 include $(top_srcdir)/src/gallium/drivers/freedreno/Automake.inc
 
+include $(top_srcdir)/src/gallium/drivers/openchrome/Automake.inc
+
 include $(top_srcdir)/src/gallium/drivers/softpipe/Automake.inc
 include $(top_srcdir)/src/gallium/drivers/llvmpipe/Automake.inc
 
diff --git a/src/gallium/targets/gbm/Makefile.am b/src/gallium/targets/gbm/Makefile.am
index aaf7580..72c094d 100644
--- a/src/gallium/targets/gbm/Makefile.am
+++ b/src/gallium/targets/gbm/Makefile.am
@@ -74,6 +74,8 @@ include $(top_srcdir)/src/gallium/drivers/svga/Automake.inc
 
 include $(top_srcdir)/src/gallium/drivers/freedreno/Automake.inc
 
+include $(top_srcdir)/src/gallium/drivers/openchrome/Automake.inc
+
 gbm_gallium_drm_la_SOURCES += target.c
 gbm_gallium_drm_la_CPPFLAGS = $(TARGET_CPPFLAGS)
 gbm_gallium_drm_la_LIBADD += $(TARGET_LIB_DEPS) \
diff --git a/src/gallium/targets/pipe-loader/Makefile.am b/src/gallium/targets/pipe-loader/Makefile.am
index 3d73a51..2b44f34 100644
--- a/src/gallium/targets/pipe-loader/Makefile.am
+++ b/src/gallium/targets/pipe-loader/Makefile.am
@@ -171,6 +171,19 @@ pipe_msm_la_LIBADD = \
 
 endif
 
+if HAVE_GALLIUM_OPENCHROME
+pipe_LTLIBRARIES += pipe_openchrome.la
+
+pipe_msm_la_SOURCES = pipe_openchrome.c
+nodist_EXTRA_pipe_openchrome_la_SOURCES = dummy.cpp
+pipe_openchrome_la_LIBADD = \
+	$(PIPE_LIBS) \
+	$(top_builddir)/src/gallium/winsys/openchrome/drm/libopenchromedrm.la \
+	$(top_builddir)/src/gallium/drivers/openchrome/libopenchrome.la \
+	$(LIBDRM_LIBS)
+
+endif
+
 if HAVE_GALLIUM_SVGA
 pipe_LTLIBRARIES += pipe_vmwgfx.la
 
diff --git a/src/gallium/targets/pipe-loader/pipe_openchrome.c b/src/gallium/targets/pipe-loader/pipe_openchrome.c
new file mode 100644
index 0000000..dd3bc21
--- /dev/null
+++ b/src/gallium/targets/pipe-loader/pipe_openchrome.c
@@ -0,0 +1,17 @@
+#include "state_tracker/drm_driver.h"
+#include "target-helpers/inline_debug_helper.h"
+#include "openchrome/drm/openchrome_drm_public.h"
+#include "openchrome/drm/openchrome_winsys.h"
+
+static struct pipe_screen *
+create_screen(int fd)
+{
+/*   struct radeon_winsys *rw;
+
+	rw = radeon_drm_winsys_create(fd, radeonsi_screen_create);
+	return rw ? debug_screen_wrap(rw->screen) : NULL;*/
+	return NULL;
+}
+
+PUBLIC
+DRM_DRIVER_DESCRIPTOR("openchrome", "openchrome", create_screen, NULL)
diff --git a/src/gallium/targets/xa/Makefile.am b/src/gallium/targets/xa/Makefile.am
index a1eae2a..a38fa2c 100644
--- a/src/gallium/targets/xa/Makefile.am
+++ b/src/gallium/targets/xa/Makefile.am
@@ -71,6 +71,8 @@ include $(top_srcdir)/src/gallium/drivers/svga/Automake.inc
 
 include $(top_srcdir)/src/gallium/drivers/freedreno/Automake.inc
 
+include $(top_srcdir)/src/gallium/drivers/openchrome/Automake.inc
+
 libxatracker_la_SOURCES += target.c
 libxatracker_la_CPPFLAGS = $(TARGET_CPPFLAGS)
 libxatracker_la_LIBADD += $(TARGET_LIB_DEPS)
diff --git a/src/gallium/winsys/openchrome/drm/Android.mk b/src/gallium/winsys/openchrome/drm/Android.mk
new file mode 100644
index 0000000..4e16f09
--- /dev/null
+++ b/src/gallium/winsys/openchrome/drm/Android.mk
@@ -0,0 +1,38 @@
+# Mesa 3-D graphics library
+#
+# Copyright (C) 2011 Chia-I Wu <olvaffe at gmail.com>
+# Copyright (C) 2011 LunarG Inc.
+#
+# Permission is hereby granted, free of charge, to any person obtaining a
+# copy of this software and associated documentation files (the "Software"),
+# to deal in the Software without restriction, including without limitation
+# the rights to use, copy, modify, merge, publish, distribute, sublicense,
+# and/or sell copies of the Software, and to permit persons to whom the
+# Software is furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+# DEALINGS IN THE SOFTWARE.
+
+LOCAL_PATH := $(call my-dir)
+
+# get C_SOURCES
+include $(LOCAL_PATH)/Makefile.sources
+
+include $(CLEAR_VARS)
+
+LOCAL_SRC_FILES := $(C_SOURCES)
+
+LOCAL_C_INCLUDES := $(TARGET_OUT_HEADERS)/libdrm
+
+LOCAL_MODULE := libmesa_winsys_openchrome
+
+include $(GALLIUM_COMMON_MK)
+include $(BUILD_STATIC_LIBRARY)
diff --git a/src/gallium/winsys/openchrome/drm/Makefile.am b/src/gallium/winsys/openchrome/drm/Makefile.am
new file mode 100644
index 0000000..903b1a8
--- /dev/null
+++ b/src/gallium/winsys/openchrome/drm/Makefile.am
@@ -0,0 +1,33 @@
+# Copyright 2015 The Openchrome Project [openchrome.org]
+#
+# Permission is hereby granted, free of charge, to any person obtaining a
+# copy of this software and associated documentation files (the "Software"),
+# to deal in the Software without restriction, including without limitation
+# the rights to use, copy, modify, merge, publish, distribute, sublicense,
+# and/or sell copies of the Software, and to permit persons to whom the
+# Software is furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice (including the next
+# paragraph) shall be included in all copies or substantial portions of the
+# Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT.  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+# DEALINGS IN THE SOFTWARE.
+
+include Makefile.sources
+include $(top_srcdir)/src/gallium/Automake.inc
+
+AM_CFLAGS = \
+	-I$(top_srcdir)/src/gallium/drivers \
+	$(LIBDRM_CFLAGS) \
+	$(GALLIUM_WINSYS_CFLAGS)
+
+noinst_LTLIBRARIES = libopenchromedrm.la
+
+libopenchromedrm_la_SOURCES = $(C_SOURCES)
diff --git a/src/gallium/winsys/openchrome/drm/Makefile.sources b/src/gallium/winsys/openchrome/drm/Makefile.sources
new file mode 100644
index 0000000..07fcbc9
--- /dev/null
+++ b/src/gallium/winsys/openchrome/drm/Makefile.sources
@@ -0,0 +1,7 @@
+C_SOURCES := \
+	openchrome_drm_bufmgr.c	\
+	openchrome_drm_bufmgr.h	\
+	openchrome_drm_winsys.c \
+	openchrome_drm_winsys.h \
+	openchrome_drm_winsys.c \
+	via_drm.h
diff --git a/src/gallium/winsys/openchrome/drm/openchrome_drm_bufmgr.c b/src/gallium/winsys/openchrome/drm/openchrome_drm_bufmgr.c
new file mode 100644
index 0000000..179e2d8
--- /dev/null
+++ b/src/gallium/winsys/openchrome/drm/openchrome_drm_bufmgr.c
@@ -0,0 +1,192 @@
+/**************************************************************************
+ *
+ * Copyright 2013 The Openchrome Project [openchrome.org]
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+ * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
+ * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ **************************************************************************/
+
+#define _FILE_OFFSET_BITS 64
+
+#include "pipebuffer/pb_buffer.h"
+#include "util/u_memory.h"
+#include "os/os_mman.h"
+
+#include <stdio.h>
+#include <errno.h>
+#include "via_drm.h"
+#include <xf86drm.h>
+
+#include "openchrome_drm_bufmgr.h"
+#include "openchrome_drm_winsys.h"
+
+static void *
+openchrome_bo_map(struct pb_buffer *buf, unsigned flags, void *flush_ctx)
+{
+	struct openchrome_bo *bo = (struct openchrome_bo *) buf;
+	void *ptr = NULL;
+
+	if (bo->ptr)
+		return bo->ptr;
+
+	ptr = os_mmap(0, bo->base.size, PROT_READ | PROT_WRITE,
+				  MAP_SHARED, bo->mgr->ws->fd, bo->map_offset);
+	if (ptr == MAP_FAILED) {
+		debug_printf("mmap for 0x%08X failed with error %d\n",
+				bo->handle, -errno);
+		ptr = NULL;
+	}
+	bo->ptr = ptr;
+
+	return ptr;
+}
+
+static void
+openchrome_bo_unmap(struct pb_buffer *buf)
+{
+	struct openchrome_bo *bo = (struct openchrome_bo *) buf;
+
+	if (bo->ptr)
+		os_munmap(bo->ptr, bo->base.size);
+}
+
+static enum pipe_error
+openchrome_bo_validate(struct pb_buffer *buf, struct pb_validate *vl,
+					   unsigned flags)
+{
+	return PIPE_OK;
+}
+
+static void
+openchrome_bo_fence(struct pb_buffer *buf, struct pipe_fence_handle *fence)
+{
+}
+
+static void
+openchrome_bo_get_base_buffer(struct pb_buffer *buf, struct pb_buffer **base_buf,
+							  pb_size *offset)
+{
+	*base_buf = buf;
+	*offset = 0;
+}
+
+static void
+openchrome_bo_destroy(struct pb_buffer *buf)
+{
+	struct openchrome_bo *bo = (struct openchrome_bo *) buf;
+	struct drm_gem_close args;
+
+	openchrome_bo_unmap(buf);
+
+	memset(&args, 0, sizeof(args));
+	args.handle = bo->handle;
+	drmIoctl(bo->mgr->ws->fd, DRM_IOCTL_GEM_CLOSE, &args);
+	FREE(bo);
+}
+
+const struct pb_vtbl openchrome_vtbl = {
+	openchrome_bo_destroy,
+	openchrome_bo_map,
+	openchrome_bo_unmap,
+	openchrome_bo_validate,
+	openchrome_bo_fence,
+	openchrome_bo_get_base_buffer,
+};
+
+static void openchrome_bufmgr_destroy(struct pb_manager *mgr)
+{
+	FREE(mgr);
+}
+
+static struct pb_buffer *
+openchrome_bufmgr_create_bo(struct pb_manager *mgr, pb_size size,
+							const struct pb_desc *desc)
+{
+	struct openchrome_bufmgr *bomgr = openchrome_bomgr(mgr);
+	struct openchrome_bo *buf = NULL;
+	struct drm_via_gem_create args;
+
+	buf = CALLOC_STRUCT(openchrome_bo);
+	if (!buf)
+		return NULL;
+
+	memset(&args, 0, sizeof(args));
+
+	switch (desc->usage) {
+	case PB_USAGE_CPU_READ:
+	case PB_USAGE_CPU_WRITE:
+		args.domains = TTM_PL_FLAG_TT;
+		break;
+
+	case PB_USAGE_GPU_READ:
+	case PB_USAGE_GPU_WRITE:
+		args.domains = TTM_PL_FLAG_VRAM;
+		break;
+	}
+	args.alignment = desc->alignment;
+	args.size = size;
+	if (drmIoctl(bomgr->ws->fd, DRM_VIA_GEM_CREATE, &args)) {
+		FREE(buf);
+		return NULL;
+	}
+	buf->map_offset = args.map_handle;
+	buf->handle = args.handle;
+	buf->mgr = bomgr;
+
+	buf->base.alignment = args.alignment;
+	buf->base.usage = desc->usage;
+	buf->base.size = args.size;
+	buf->base.vtbl = &openchrome_vtbl;
+
+	return &buf->base;
+}
+
+static void
+openchrome_bufmgr_flush(struct pb_manager *mgr)
+{
+}
+
+static boolean
+openchrome_bufmgr_is_buffer_busy(struct pb_manager *mgr,
+								struct pb_buffer *buf)
+{
+	return FALSE;
+}
+
+struct pb_manager *
+openchrome_create_bufmgr(struct openchrome_drm_winsys *ws)
+{
+	struct openchrome_bufmgr *mgr;
+
+	mgr = CALLOC_STRUCT(openchrome_bufmgr);
+	if (!mgr)
+		return NULL;
+
+	mgr->base.destroy = openchrome_bufmgr_destroy;
+	mgr->base.create_buffer = openchrome_bufmgr_create_bo;
+	mgr->base.flush = openchrome_bufmgr_flush;
+	mgr->base.is_buffer_busy = openchrome_bufmgr_is_buffer_busy;
+
+	mgr->ws = ws;
+
+	return &mgr->base;
+}
diff --git a/src/gallium/winsys/openchrome/drm/openchrome_drm_bufmgr.h b/src/gallium/winsys/openchrome/drm/openchrome_drm_bufmgr.h
new file mode 100644
index 0000000..bc7a0f1
--- /dev/null
+++ b/src/gallium/winsys/openchrome/drm/openchrome_drm_bufmgr.h
@@ -0,0 +1,62 @@
+/**************************************************************************
+ *
+ * Copyright 2013 The Openchrome Project [openchrome.org]
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+ * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
+ * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ **************************************************************************/
+
+#ifndef VIA_DRM_BO_H
+#define VIA_DRM_BO_H
+
+#include "pipebuffer/pb_bufmgr.h"
+
+#define TTM_PL_FLAG_SYSTEM      1
+#define TTM_PL_FLAG_TT          2
+#define TTM_PL_FLAG_VRAM        4
+
+struct openchrome_bufmgr {
+	/* Base class. */
+	struct pb_manager base;
+
+	struct openchrome_drm_winsys *ws;
+};
+
+static INLINE struct openchrome_bufmgr *
+openchrome_bomgr(struct pb_manager *mgr)
+{
+    return (struct openchrome_bufmgr *) mgr;
+}
+
+struct pb_manager *
+openchrome_create_bufmgr(struct openchrome_drm_winsys *ws);
+
+struct openchrome_bo {
+	struct pb_buffer base;
+
+	struct openchrome_bufmgr *mgr;
+	off_t map_offset;
+	int handle;
+	void *ptr;
+};
+
+#endif
diff --git a/src/gallium/winsys/openchrome/drm/openchrome_drm_winsys.c b/src/gallium/winsys/openchrome/drm/openchrome_drm_winsys.c
new file mode 100644
index 0000000..401e928
--- /dev/null
+++ b/src/gallium/winsys/openchrome/drm/openchrome_drm_winsys.c
@@ -0,0 +1,70 @@
+/**************************************************************************
+ *
+ * Copyright 2013 The Openchrome Project [openchrome.org]
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+ * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
+ * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ **************************************************************************/
+
+#include "util/u_memory.h"
+
+#include <stdio.h>
+#include <xf86drm.h>
+#include "via_drm.h"
+
+#include "openchrome_drm_winsys.h"
+#include "openchrome_drm_bufmgr.h"
+#include "openchrome/openchrome_screen.h"
+
+struct pipe_screen *
+openchrome_drm_winsys_create(int fd)
+{
+	struct openchrome_drm_winsys *ws = CALLOC_STRUCT(openchrome_drm_winsys);
+	struct drm_via_param params;
+	struct pb_manager *mgr;
+	drmVersionPtr version;
+
+	if (!ws)
+		return NULL;
+
+	ws->fd = fd;
+
+	version = drmGetVersion(fd);
+	if (version->version_major < 3) {
+        debug_printf("%s: DRM version is %d.%d.%d but this driver requires "
+		             "3.0 or above\n",  __FUNCTION__, version->version_major,
+		             version->version_minor, version->version_patchlevel);
+		drmFreeVersion(version);
+		return NULL;
+	}
+	drmFreeVersion(version);
+
+	params.param = VIA_PARAM_CHIPSET_ID;
+	if (drmCommandWriteRead(fd, DRM_VIA_GETPARAM, &params,
+							sizeof(params)) != 0) {
+		debug_printf("%s: Failed to get PCI id\n", __FUNCTION__);
+		return NULL;
+	}
+	mgr = openchrome_create_bufmgr(ws);
+
+	return openchrome_screen_create(mgr, params.value);
+}
diff --git a/src/gallium/winsys/openchrome/drm/openchrome_drm_winsys.h b/src/gallium/winsys/openchrome/drm/openchrome_drm_winsys.h
new file mode 100644
index 0000000..ed6058c
--- /dev/null
+++ b/src/gallium/winsys/openchrome/drm/openchrome_drm_winsys.h
@@ -0,0 +1,41 @@
+/**************************************************************************
+ *
+ * Copyright 2013 The Openchrome Project [openchrome.org]
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+ * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
+ * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ **************************************************************************/
+
+#ifndef __OPENCHROME_DRM_PUBLIC_H__
+#define __OPENCHROME_DRM_PUBLIC_H__
+
+#include "pipebuffer/pb_bufmgr.h"
+
+struct openchrome_drm_winsys {
+	int fd;
+};
+
+struct pipe_screen;
+
+struct pipe_screen *openchrome_drm_winsys_create(int drmFD);
+
+#endif
diff --git a/src/gallium/winsys/openchrome/drm/via_drm.h b/src/gallium/winsys/openchrome/drm/via_drm.h
new file mode 100644
index 0000000..f9b3cc3
--- /dev/null
+++ b/src/gallium/winsys/openchrome/drm/via_drm.h
@@ -0,0 +1,354 @@
+/*
+ * Copyright 1998-2003 VIA Technologies, Inc. All Rights Reserved.
+ * Copyright 2001-2003 S3 Graphics, Inc. All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sub license,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHOR(S) OR COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+#ifndef _VIA_DRM_H_
+#define _VIA_DRM_H_
+
+#include <drm.h>
+
+/* WARNING: These defines must be the same as what the Xserver uses.
+ * if you change them, you must change the defines in the Xserver.
+ */
+
+#ifndef _VIA_DEFINES_
+#define _VIA_DEFINES_
+
+#define VIA_NR_SAREA_CLIPRECTS		8
+#define VIA_NR_XVMC_PORTS		10
+#define VIA_NR_XVMC_LOCKS		5
+#define VIA_MAX_CACHELINE_SIZE		64
+#define XVMCLOCKPTR(saPriv,lockNo)					\
+	((volatile struct drm_hw_lock *)(((((unsigned long) (saPriv)->XvMCLockArea) + \
+				      (VIA_MAX_CACHELINE_SIZE - 1)) &	\
+				     ~(VIA_MAX_CACHELINE_SIZE - 1)) +	\
+				    VIA_MAX_CACHELINE_SIZE*(lockNo)))
+
+/* Each region is a minimum of 64k, and there are at most 64 of them.
+ */
+#define VIA_NR_TEX_REGIONS 64
+#define VIA_LOG_MIN_TEX_REGION_SIZE 16
+#endif
+
+#define VIA_UPLOAD_TEX0IMAGE  0x1	/* handled clientside */
+#define VIA_UPLOAD_TEX1IMAGE  0x2	/* handled clientside */
+#define VIA_UPLOAD_CTX        0x4
+#define VIA_UPLOAD_BUFFERS    0x8
+#define VIA_UPLOAD_TEX0       0x10
+#define VIA_UPLOAD_TEX1       0x20
+#define VIA_UPLOAD_CLIPRECTS  0x40
+#define VIA_UPLOAD_ALL        0xff
+
+/* VIA specific ioctls */
+#define DRM_VIA_ALLOCMEM	0x00
+#define DRM_VIA_FREEMEM		0x01
+#define DRM_VIA_AGP_INIT	0x02
+#define DRM_VIA_FB_INIT		0x03
+#define DRM_VIA_MAP_INIT	0x04
+#define DRM_VIA_DEC_FUTEX	0x05
+#define DRM_VIA_OLD_GEM_CREATE	0x06
+#define DRM_VIA_DMA_INIT	0x07
+#define DRM_VIA_CMDBUFFER	0x08
+#define DRM_VIA_FLUSH		0x09
+#define DRM_VIA_PCICMD		0x0a
+#define DRM_VIA_CMDBUF_SIZE	0x0b
+#define NOT_USED
+#define DRM_VIA_WAIT_IRQ	0x0d
+#define DRM_VIA_DMA_BLIT	0x0e
+#define DRM_VIA_BLIT_SYNC	0x0f
+
+/* KMS ioctls */
+#define DRM_VIA_GETPARAM	0x10
+#define DRM_VIA_SETPARAM	0x11
+#define DRM_VIA_GEM_CREATE	0x12
+#define DRM_VIA_GEM_WAIT	0x13
+#define DRM_VIA_GEM_STATE	0x14
+
+#define DRM_IOCTL_VIA_ALLOCMEM	  DRM_IOWR(DRM_COMMAND_BASE + DRM_VIA_ALLOCMEM, drm_via_mem_t)
+#define DRM_IOCTL_VIA_FREEMEM	  DRM_IOW( DRM_COMMAND_BASE + DRM_VIA_FREEMEM, drm_via_mem_t)
+#define DRM_IOCTL_VIA_AGP_INIT	  DRM_IOWR(DRM_COMMAND_BASE + DRM_VIA_AGP_INIT, drm_via_agp_t)
+#define DRM_IOCTL_VIA_FB_INIT	  DRM_IOWR(DRM_COMMAND_BASE + DRM_VIA_FB_INIT, drm_via_fb_t)
+#define DRM_IOCTL_VIA_MAP_INIT	  DRM_IOWR(DRM_COMMAND_BASE + DRM_VIA_MAP_INIT, drm_via_init_t)
+#define DRM_IOCTL_VIA_DEC_FUTEX   DRM_IOW( DRM_COMMAND_BASE + DRM_VIA_DEC_FUTEX, drm_via_futex_t)
+#define DRM_IOCTL_VIA_OLD_GEM_CREATE  DRM_IOWR(DRM_COMMAND_BASE + DRM_VIA_OLD_GEM_CREATE, struct drm_via_gem_create)
+#define DRM_IOCTL_VIA_DMA_INIT	  DRM_IOWR(DRM_COMMAND_BASE + DRM_VIA_DMA_INIT, drm_via_dma_init_t)
+#define DRM_IOCTL_VIA_CMDBUFFER	  DRM_IOW( DRM_COMMAND_BASE + DRM_VIA_CMDBUFFER, drm_via_cmdbuffer_t)
+#define DRM_IOCTL_VIA_FLUSH	  DRM_IO(  DRM_COMMAND_BASE + DRM_VIA_FLUSH)
+#define DRM_IOCTL_VIA_PCICMD	  DRM_IOW( DRM_COMMAND_BASE + DRM_VIA_PCICMD, drm_via_cmdbuffer_t)
+#define DRM_IOCTL_VIA_CMDBUF_SIZE DRM_IOWR( DRM_COMMAND_BASE + DRM_VIA_CMDBUF_SIZE, \
+					    drm_via_cmdbuf_size_t)
+#define DRM_IOCTL_VIA_WAIT_IRQ    DRM_IOWR( DRM_COMMAND_BASE + DRM_VIA_WAIT_IRQ, drm_via_irqwait_t)
+#define DRM_IOCTL_VIA_DMA_BLIT    DRM_IOW(DRM_COMMAND_BASE + DRM_VIA_DMA_BLIT, drm_via_dmablit_t)
+#define DRM_IOCTL_VIA_BLIT_SYNC   DRM_IOW(DRM_COMMAND_BASE + DRM_VIA_BLIT_SYNC, drm_via_blitsync_t)
+
+/* KMS ioctls */
+#define DRM_IOCTL_VIA_GETPARAM    DRM_IOR(DRM_COMMAND_BASE + DRM_VIA_GETPARAM, struct drm_via_param)
+#define DRM_IOCTL_VIA_SETPARAM    DRM_IOW(DRM_COMMAND_BASE + DRM_VIA_SETPARAM, struct drm_via_param)
+#define DRM_IOCTL_VIA_GEM_CREATE  DRM_IOWR(DRM_COMMAND_BASE + DRM_VIA_GEM_CREATE, struct drm_via_gem_create)
+#define DRM_IOCTL_VIA_GEM_WAIT    DRM_IOW(DRM_COMMAND_BASE + DRM_VIA_GEM_WAIT, struct drm_via_gem_wait)
+#define DRM_IOCTL_VIA_GEM_STATE   DRM_IOWR(DRM_COMMAND_BASE + DRM_VIA_GEM_STATE, struct drm_via_gem_create)
+
+/* Indices into buf.Setup where various bits of state are mirrored per
+ * context and per buffer.  These can be fired at the card as a unit,
+ * or in a piecewise fashion as required.
+ */
+
+#define VIA_TEX_SETUP_SIZE 8
+
+/* Flags for clear ioctl
+ */
+#define VIA_FRONT   0x1
+#define VIA_BACK    0x2
+#define VIA_DEPTH   0x4
+#define VIA_STENCIL 0x8
+
+#define VIA_MEM_VIDEO   0	/* matches drm constant */
+#define VIA_MEM_AGP     1	/* matches drm constant */
+#define VIA_MEM_SYSTEM  2
+#define VIA_MEM_MIXED   3
+#define VIA_MEM_UNKNOWN 4
+
+typedef struct {
+	__u32 offset;
+	__u32 size;
+} drm_via_agp_t;
+
+typedef struct {
+	__u32 offset;
+	__u32 size;
+} drm_via_fb_t;
+
+typedef struct {
+	__u32 context;
+	__u32 type;
+	__u32 size;
+	unsigned long index;
+	unsigned long offset;
+} drm_via_mem_t;
+
+typedef struct _drm_via_init {
+	enum {
+		VIA_INIT_MAP = 0x01,
+		VIA_CLEANUP_MAP = 0x02
+	} func;
+
+	unsigned long sarea_priv_offset;
+	unsigned long fb_offset;
+	unsigned long mmio_offset;
+	unsigned long agpAddr;
+} drm_via_init_t;
+
+typedef struct _drm_via_futex {
+	enum {
+		VIA_FUTEX_WAIT = 0x00,
+		VIA_FUTEX_WAKE = 0X01
+	} func;
+	__u32 ms;
+	__u32 lock;
+	__u32 val;
+} drm_via_futex_t;
+
+typedef struct _drm_via_dma_init {
+	enum {
+		VIA_INIT_DMA = 0x01,
+		VIA_CLEANUP_DMA = 0x02,
+		VIA_DMA_INITIALIZED = 0x03
+	} func;
+
+	unsigned long offset;
+	unsigned long size;
+	unsigned long reg_pause_addr;
+} drm_via_dma_init_t;
+
+/* Warning: If you change the SAREA structure you must change the Xserver
+ * structure as well */
+
+typedef struct _drm_via_tex_region {
+	unsigned char next, prev;	/* indices to form a circular LRU  */
+	unsigned char inUse;	/* owned by a client, or free? */
+	int age;		/* tracked by clients to update local LRU's */
+} drm_via_tex_region_t;
+
+typedef struct _drm_via_sarea {
+	unsigned int dirty;
+	unsigned int nbox;
+	struct drm_clip_rect boxes[VIA_NR_SAREA_CLIPRECTS];
+	drm_via_tex_region_t texList[VIA_NR_TEX_REGIONS + 1];
+	int texAge;		/* last time texture was uploaded */
+	int ctxOwner;		/* last context to upload state */
+	int vertexPrim;
+
+	/*
+	 * Below is for XvMC.
+	 * We want the lock integers alone on, and aligned to, a cache line.
+	 * Therefore this somewhat strange construct.
+	 */
+
+	char XvMCLockArea[VIA_MAX_CACHELINE_SIZE * (VIA_NR_XVMC_LOCKS + 1)];
+
+	unsigned int XvMCDisplaying[VIA_NR_XVMC_PORTS];
+	unsigned int XvMCSubPicOn[VIA_NR_XVMC_PORTS];
+	unsigned int XvMCCtxNoGrabbed;	/* Last context to hold decoder */
+
+	/* Used by the 3d driver only at this point, for pageflipping:
+	 */
+	unsigned int pfCurrentOffset;
+} drm_via_sarea_t;
+
+typedef struct _drm_via_cmdbuf_size {
+	enum {
+		VIA_CMDBUF_SPACE = 0x01,
+		VIA_CMDBUF_LAG = 0x02
+	} func;
+	int wait;
+	__u32 size;
+} drm_via_cmdbuf_size_t;
+
+typedef enum {
+	VIA_IRQ_ABSOLUTE = 0x0,
+	VIA_IRQ_RELATIVE = 0x1,
+	VIA_IRQ_SIGNAL = 0x10000000,
+	VIA_IRQ_FORCE_SEQUENCE = 0x20000000
+} via_irq_seq_type_t;
+
+#define VIA_IRQ_FLAGS_MASK 0xF0000000
+
+enum drm_via_irqs {
+	drm_via_irq_hqv0 = 0,
+	drm_via_irq_hqv1,
+	drm_via_irq_dma0_dd,
+	drm_via_irq_dma0_td,
+	drm_via_irq_dma1_dd,
+	drm_via_irq_dma1_td,
+	drm_via_irq_num
+};
+
+struct drm_via_wait_irq_request {
+	unsigned irq;
+	via_irq_seq_type_t type;
+	__u32 sequence;
+	__u32 signal;
+};
+
+typedef union drm_via_irqwait {
+	struct drm_via_wait_irq_request request;
+	struct drm_wait_vblank_reply reply;
+} drm_via_irqwait_t;
+
+typedef struct drm_via_blitsync {
+	__u32 sync_handle;
+	unsigned engine;
+} drm_via_blitsync_t;
+
+/* - * Below,"flags" is currently unused but will be used for possible future
+ * extensions like kernel space bounce buffers for bad alignments and
+ * blit engine busy-wait polling for better latency in the absence of
+ * interrupts.
+ */
+
+typedef struct drm_via_dmablit {
+	__u32 num_lines;
+	__u32 line_length;
+
+	__u32 fb_addr;
+	__u32 fb_stride;
+
+	unsigned char *mem_addr;
+	__u32 mem_stride;
+
+	__u32 flags;
+	int to_fb;
+
+	drm_via_blitsync_t sync;
+} drm_via_dmablit_t;
+
+/* Ioctl to query kernel params:
+ */
+#define VIA_PARAM_CHIPSET_ID		0
+#define VIA_PARAM_REVISION_ID		1
+
+struct drm_via_param {
+	uint64_t param;
+	uint64_t value;
+};
+
+struct drm_via_gem_create {
+	/**
+	 * Requested size for the object.
+	 *
+	 * The (page-aligned) allocated size for the object will be returned.
+	 */
+	uint64_t size;
+
+	/*
+	 * Place the memory at the proper byte alignment.
+	 */
+	uint32_t alignment;
+
+	/**
+	 * Format of data i.e tile pitch, for linear it is zero
+	 */
+	uint32_t pitch;
+
+	/**
+	 * Give hints where to allocate this object.
+	 */
+	uint32_t domains;
+
+	/**
+	 * chmod values applied to a buffer.
+	 */
+	uint32_t mode_t;
+
+	/**
+	 * Offset to start of memory region.
+	 */
+	uint64_t offset;
+
+	/**
+	 * Returned handle need to mmap the buffer.
+	 */
+	uint64_t map_handle;
+
+	/**
+	 * Returned handle for the object.
+	 *
+	 * Object handles are nonzero.
+	 */
+	uint32_t handle;
+
+	/**
+	 * Padding for future expansion.
+	 */
+	uint32_t pad1;
+	uint64_t pad2;
+	uint64_t pad3;
+	uint64_t pad4;
+};
+
+struct drm_via_gem_wait {
+	/* the buffer object handle */
+	uint32_t handle;
+	uint32_t no_wait;
+};
+
+#endif				/* _VIA_DRM_H_ */


More information about the Openchrome-devel mailing list