summaryrefslogtreecommitdiff
path: root/va/drm
diff options
context:
space:
mode:
authorDmitry Ermilov <dmitry.ermilov@intel.com>2012-06-07 19:29:14 +0400
committerGwenole Beauchesne <gwenole.beauchesne@intel.com>2012-09-26 11:47:56 +0200
commitbcc85ca5200ae83cbbf895dde46bfa2767495f7f (patch)
treef6bf21d0f59aee73f630430537809cec4d0dbd9d /va/drm
parent901bbe13c187bfcc138f5a9def3d3625a6395657 (diff)
downloadlibva-bcc85ca5200ae83cbbf895dde46bfa2767495f7f.tar.gz
API: add support for raw DRM.
This API makes it possible to use DRM-based VA drivers without an X server. Since this is a renderless API, vaPutSurface() is not available. Signed-off-by: Dmitry Ermilov <dmitry.ermilov@intel.com> Signed-off-by: Gwenole Beauchesne <gwenole.beauchesne@intel.com>
Diffstat (limited to 'va/drm')
-rw-r--r--va/drm/Makefile.am48
-rw-r--r--va/drm/va_drm.c148
-rw-r--r--va/drm/va_drm.h61
3 files changed, 257 insertions, 0 deletions
diff --git a/va/drm/Makefile.am b/va/drm/Makefile.am
new file mode 100644
index 0000000..a2770f2
--- /dev/null
+++ b/va/drm/Makefile.am
@@ -0,0 +1,48 @@
+# Copyright (C) 2012 Intel Corporation. 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 PRECISION INSIGHT 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.
+
+INCLUDES = \
+ -DLINUX \
+ -I$(top_srcdir) \
+ -I$(top_srcdir)/va \
+ $(DRM_CFLAGS) \
+ $(NULL)
+
+source_c = \
+ va_drm.c \
+ $(NULL)
+
+source_h = \
+ va_drm.h \
+ $(NULL)
+
+source_h_priv = \
+ $(NULL)
+
+noinst_LTLIBRARIES = libva_drm.la
+libva_drmincludedir = ${includedir}/va
+libva_drminclude_HEADERS = $(source_h)
+libva_drm_la_SOURCES = $(source_c)
+noinst_HEADERS = $(source_h_priv)
+
+# Extra clean files so that maintainer-clean removes *everything*
+MAINTAINERCLEANFILES = Makefile.in
diff --git a/va/drm/va_drm.c b/va/drm/va_drm.c
new file mode 100644
index 0000000..c45565f
--- /dev/null
+++ b/va/drm/va_drm.c
@@ -0,0 +1,148 @@
+/*
+ * Copyright (c) 2012 Intel Corporation. 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 PRECISION INSIGHT 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 "sysdeps.h"
+#include <xf86drm.h>
+#include "va_drm.h"
+#include "va_backend.h"
+#include "va_drmcommon.h"
+
+static int
+va_DisplayContextIsValid(VADisplayContextP pDisplayContext)
+{
+ VADriverContextP const pDriverContext = pDisplayContext->pDriverContext;
+
+ return (pDriverContext &&
+ pDriverContext->display_type == VA_DISPLAY_DRM);
+}
+
+static void
+va_DisplayContextDestroy(VADisplayContextP pDisplayContext)
+{
+ if (!pDisplayContext)
+ return;
+
+ free(pDisplayContext->pDriverContext->drm_state);
+ free(pDisplayContext->pDriverContext);
+ free(pDisplayContext);
+}
+
+struct driver_name_map {
+ const char *key;
+ int key_len;
+ const char *name;
+};
+
+static const struct driver_name_map g_driver_name_map[] = {
+ { "i915", 4, "i965" }, // Intel OTC GenX driver
+ { "pvrsrvkm", 8, "pvr" }, // Intel UMG PVR driver
+ { "emgd", 4, "emgd" }, // Intel ECG PVR driver
+ { NULL, }
+};
+
+static VAStatus
+va_DisplayContextGetDriverName(
+ VADisplayContextP pDisplayContext,
+ char **driver_name_ptr
+)
+{
+
+ VADriverContextP const ctx = pDisplayContext->pDriverContext;
+ struct drm_state * const drm_state = ctx->drm_state;
+ drmVersionPtr drm_version;
+ char *driver_name = NULL;
+ const struct driver_name_map *m;
+ drm_magic_t magic;
+
+ *driver_name_ptr = NULL;
+
+ drm_version = drmGetVersion(drm_state->fd);
+ if (!drm_version)
+ return VA_STATUS_ERROR_UNKNOWN;
+
+ for (m = g_driver_name_map; m->key != NULL; m++) {
+ if (drm_version->name_len >= m->key_len &&
+ strncmp(drm_version->name, m->key, m->key_len) == 0)
+ break;
+ }
+ drmFreeVersion(drm_version);
+
+ if (!m->name)
+ return VA_STATUS_ERROR_UNKNOWN;
+
+ driver_name = strdup(m->name);
+ if (!driver_name)
+ return VA_STATUS_ERROR_ALLOCATION_FAILED;
+
+ *driver_name_ptr = driver_name;
+
+ drmGetMagic(drm_state->fd, &magic);
+ drmAuthMagic(drm_state->fd, magic);
+
+ drm_state->auth_type = VA_DRM_AUTH_CUSTOM;
+
+ return VA_STATUS_SUCCESS;
+}
+
+VADisplay
+vaGetDisplayDRM(int fd)
+{
+ VADisplayContextP pDisplayContext = NULL;
+ VADriverContextP pDriverContext = NULL;
+ struct drm_state *drm_state = NULL;
+
+ if (fd < 0)
+ return NULL;
+
+ /* Create new entry */
+ /* XXX: handle cache? */
+ drm_state = calloc(1, sizeof(*drm_state));
+ if (!drm_state)
+ goto error;
+ drm_state->fd = fd;
+
+ pDriverContext = calloc(1, sizeof(*pDriverContext));
+ if (!pDriverContext)
+ goto error;
+ pDriverContext->native_dpy = NULL;
+ pDriverContext->display_type = VA_DISPLAY_DRM;
+ pDriverContext->drm_state = drm_state;
+
+ pDisplayContext = calloc(1, sizeof(*pDisplayContext));
+ if (!pDisplayContext)
+ goto error;
+
+ pDisplayContext->vadpy_magic = VA_DISPLAY_MAGIC;
+ pDisplayContext->pDriverContext = pDriverContext;
+ pDisplayContext->vaIsValid = va_DisplayContextIsValid;
+ pDisplayContext->vaDestroy = va_DisplayContextDestroy;
+ pDisplayContext->vaGetDriverName = va_DisplayContextGetDriverName;
+ return pDisplayContext;
+
+error:
+ free(pDisplayContext);
+ free(pDriverContext);
+ free(drm_state);
+ return NULL;
+}
diff --git a/va/drm/va_drm.h b/va/drm/va_drm.h
new file mode 100644
index 0000000..9af3cc8
--- /dev/null
+++ b/va/drm/va_drm.h
@@ -0,0 +1,61 @@
+/*
+ * va_drm.h - Raw DRM API
+ *
+ * Copyright (c) 2012 Intel Corporation. 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 INTEL 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 VA_DRM_H
+#define VA_DRM_H
+
+#include <va/va.h>
+
+/**
+ * \file va_drm.h
+ * \brief The raw DRM API
+ *
+ * This file contains the \ref api_drm "Raw DRM API".
+ */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * \brief Returns a VA display derived from the specified DRM connection.
+ *
+ * This function returns a (possibly cached) VA display from the
+ * specified DRM connection @fd.
+ *
+ * @param[in] fd the DRM connection descriptor
+ * @return the VA display
+ */
+VADisplay
+vaGetDisplayDRM(int fd);
+
+/**@}*/
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* VA_DRM_H */