All of lore.kernel.org
 help / color / mirror / Atom feed
* [RFC libdrm 0/6] Add NVIDIA Tegra support
@ 2014-02-19 16:04 Thierry Reding
  2014-02-19 16:04 ` [RFC libdrm 1/6] configure: Support symbol visibility when available Thierry Reding
                   ` (6 more replies)
  0 siblings, 7 replies; 24+ messages in thread
From: Thierry Reding @ 2014-02-19 16:04 UTC (permalink / raw)
  To: dri-devel

From: Thierry Reding <treding@nvidia.com>

Hi,

This series adds libdrm-tegra with a very lightweight API on top of the
kernel interfaces. Most of the functions provided here have been in use
in various driver efforts in different incarnations. This is an attempt
to consolidate, so I'm looking for review comments especially by Erik
to ensure it can be used by grate.

I've used these to implement basic EXA support in xf86-video-opentegra,
which I've pushed to a repository here[0]. The libdrm patches are also
available in a repository[1] for convenience.

Patch 1 adds support for symbol visibility if GCC supports it. This is
used by later patches to make only the public symbols visible in the
libdrm-tegra shared object.

Patch 2 adds support for managing a Tegra DRM object (which doesn't do
a whole lot more than wrap a file descriptor) and buffer objects.

A small test program is added in patch 3 to check that a Tegra DRM
object can be created on top of a DRM device.

Patch 4 adds functions to open a channel to an engine (gr2d or gr3d),
create and manage a job as well as compose command streams in a push
buffer and wait for a fence.

To make it easier to write further tests, patch 5 introduces some DRM
helpers to setup a screen and attach framebuffers to it. A very basic
interface is also provided for the gr2d unit, which can be used to do
a solid rectangle fill.

Finally patch 6 uses the helpers introduced in patch 5 to fill a sub-
region of the screen with a solid color.

Thierry

[0]: http://cgit.freedesktop.org/~tagr/xf86-video-opentegra/
[1]: http://cgit.freedesktop.org/~tagr/drm/

Thierry Reding (6):
  configure: Support symbol visibility when available
  libdrm: Add NVIDIA Tegra support
  tegra: Add simple test for drm_tegra_open()
  tegra: Add channel, job, pushbuf and fence APIs
  tegra: Add helper library for tests
  tegra: Add gr2d-fill test

 Makefile.am                  |   6 +-
 configure.ac                 |  36 +++++-
 include/drm/Makefile.am      |   1 +
 include/drm/tegra_drm.h      | 157 ++++++++++++++++++++++++++
 tegra/Makefile.am            |  24 ++++
 tegra/channel.c              | 127 +++++++++++++++++++++
 tegra/fence.c                |  72 ++++++++++++
 tegra/job.c                  | 167 +++++++++++++++++++++++++++
 tegra/libdrm_tegra.pc.in     |  11 ++
 tegra/private.h              | 117 +++++++++++++++++++
 tegra/pushbuf.c              | 137 +++++++++++++++++++++++
 tegra/tegra.c                | 253 +++++++++++++++++++++++++++++++++++++++++
 tegra/tegra.h                |  99 ++++++++++++++++
 tests/Makefile.am            |   4 +
 tests/modetest/modetest.c    |   2 +-
 tests/tegra/Makefile.am      |  29 +++++
 tests/tegra/drm-test-tegra.c | 132 ++++++++++++++++++++++
 tests/tegra/drm-test-tegra.h |  55 +++++++++
 tests/tegra/drm-test.c       | 261 +++++++++++++++++++++++++++++++++++++++++++
 tests/tegra/drm-test.h       |  73 ++++++++++++
 tests/tegra/gr2d-fill.c      | 145 ++++++++++++++++++++++++
 tests/tegra/openclose.c      |  63 +++++++++++
 tests/vbltest/vbltest.c      |   2 +-
 23 files changed, 1969 insertions(+), 4 deletions(-)
 create mode 100644 include/drm/tegra_drm.h
 create mode 100644 tegra/Makefile.am
 create mode 100644 tegra/channel.c
 create mode 100644 tegra/fence.c
 create mode 100644 tegra/job.c
 create mode 100644 tegra/libdrm_tegra.pc.in
 create mode 100644 tegra/private.h
 create mode 100644 tegra/pushbuf.c
 create mode 100644 tegra/tegra.c
 create mode 100644 tegra/tegra.h
 create mode 100644 tests/tegra/Makefile.am
 create mode 100644 tests/tegra/drm-test-tegra.c
 create mode 100644 tests/tegra/drm-test-tegra.h
 create mode 100644 tests/tegra/drm-test.c
 create mode 100644 tests/tegra/drm-test.h
 create mode 100644 tests/tegra/gr2d-fill.c
 create mode 100644 tests/tegra/openclose.c

-- 
1.8.4.2

^ permalink raw reply	[flat|nested] 24+ messages in thread

* [RFC libdrm 1/6] configure: Support symbol visibility when available
  2014-02-19 16:04 [RFC libdrm 0/6] Add NVIDIA Tegra support Thierry Reding
@ 2014-02-19 16:04 ` Thierry Reding
  2014-02-19 21:05   ` Erik Faye-Lund
  2014-02-19 16:04 ` [RFC libdrm 2/6] libdrm: Add NVIDIA Tegra support Thierry Reding
                   ` (5 subsequent siblings)
  6 siblings, 1 reply; 24+ messages in thread
From: Thierry Reding @ 2014-02-19 16:04 UTC (permalink / raw)
  To: dri-devel

From: Thierry Reding <treding@nvidia.com>

Checks whether or not the compiler supports the -fvisibility option. If
so it sets the VISIBILITY_CFLAGS variable which can be added to the per
directory AM_CFLAGS where appropriate.

Libraries can use the HAVE_VISIBILITY preprocessor definition to check
for availability and use something like this:

	#if defined(HAVE_VISIBILITY)
	#  define drm_private __attribute__((visibility("hidden")))
	#  define drm_public __attribute__((visibility("default")))
	#else
	#  define drm_private
	#  define drm_public
	#endif

By default all symbols will be hidden via the VISIBILITY_CFLAGS. Only
symbols explicitly marked drm_public will be exported.

Signed-off-by: Thierry Reding <treding@nvidia.com>
---
 configure.ac | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/configure.ac b/configure.ac
index d2d19d66dc17..3f4164238494 100644
--- a/configure.ac
+++ b/configure.ac
@@ -365,6 +365,26 @@ AC_ARG_WITH([kernel-source],
 	    [kernel_source="$with_kernel_source"])
 AC_SUBST(kernel_source)
 
+dnl Add flags for gcc and g++
+if test "x$GCC" = xyes; then
+    # Enable -fvisibility=hidden if using a gcc that supports it
+    save_CFLAGS="$CFLAGS"
+    AC_MSG_CHECKING([whether $CC supports -fvisibility=hidden])
+    VISIBILITY_CFLAGS="-fvisibility=hidden"
+    CFLAGS="$CFLAGS $VISIBILITY_CFLAGS"
+    AC_LINK_IFELSE([AC_LANG_PROGRAM()], AC_MSG_RESULT([yes]),
+                   [VISIBILITY_CFLAGS=""; AC_MSG_RESULT([no])]);
+
+    # Restore CFLAGS; VISIBILITY_CFLAGS are added to it where needed.
+    CFLAGS=$save_CFLAGS
+
+    if test "x$VISIBILITY_CFLAGS" != x; then
+        AC_DEFINE(HAVE_VISIBILITY, 1, [Compiler has -fvisibility support])
+    fi
+
+    AC_SUBST([VISIBILITY_CFLAGS])
+fi
+
 AC_SUBST(WARN_CFLAGS)
 AC_CONFIG_FILES([
 	Makefile
-- 
1.8.4.2

^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [RFC libdrm 2/6] libdrm: Add NVIDIA Tegra support
  2014-02-19 16:04 [RFC libdrm 0/6] Add NVIDIA Tegra support Thierry Reding
  2014-02-19 16:04 ` [RFC libdrm 1/6] configure: Support symbol visibility when available Thierry Reding
@ 2014-02-19 16:04 ` Thierry Reding
  2014-02-19 19:59   ` Rémi Cardona
                     ` (2 more replies)
  2014-02-19 16:04 ` [RFC libdrm 3/6] tegra: Add simple test for drm_tegra_open() Thierry Reding
                   ` (4 subsequent siblings)
  6 siblings, 3 replies; 24+ messages in thread
From: Thierry Reding @ 2014-02-19 16:04 UTC (permalink / raw)
  To: dri-devel

From: Thierry Reding <thierry.reding@avionic-design.de>

Add the libdrm_tegra helper library to encapsulate Tegra-specific
interfaces to the DRM.

Furthermore, Tegra is added to the list of supported chips in the
modetest and vbltest programs.

Signed-off-by: Thierry Reding <thierry.reding@avionic-design.de>
Signed-off-by: Erik Faye-Lund <kusmabite@gmail.com>
Signed-off-by: Thierry Reding <treding@nvidia.com>
---
 Makefile.am               |   6 +-
 configure.ac              |  15 ++-
 include/drm/Makefile.am   |   1 +
 include/drm/tegra_drm.h   | 157 ++++++++++++++++++++++++++++
 tegra/Makefile.am         |  20 ++++
 tegra/libdrm_tegra.pc.in  |  11 ++
 tegra/private.h           |  58 +++++++++++
 tegra/tegra.c             | 253 ++++++++++++++++++++++++++++++++++++++++++++++
 tegra/tegra.h             |  47 +++++++++
 tests/modetest/modetest.c |   2 +-
 tests/vbltest/vbltest.c   |   2 +-
 11 files changed, 568 insertions(+), 4 deletions(-)
 create mode 100644 include/drm/tegra_drm.h
 create mode 100644 tegra/Makefile.am
 create mode 100644 tegra/libdrm_tegra.pc.in
 create mode 100644 tegra/private.h
 create mode 100644 tegra/tegra.c
 create mode 100644 tegra/tegra.h

diff --git a/Makefile.am b/Makefile.am
index 826c30d0c0d9..14c402dce74f 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -51,7 +51,11 @@ if HAVE_FREEDRENO
 FREEDRENO_SUBDIR = freedreno
 endif
 
-SUBDIRS = . $(LIBKMS_SUBDIR) $(INTEL_SUBDIR) $(NOUVEAU_SUBDIR) $(RADEON_SUBDIR) $(OMAP_SUBDIR) $(EXYNOS_SUBDIR) $(FREEDRENO_SUBDIR) tests include man
+if HAVE_TEGRA
+TEGRA_SUBDIR = tegra
+endif
+
+SUBDIRS = . $(LIBKMS_SUBDIR) $(INTEL_SUBDIR) $(NOUVEAU_SUBDIR) $(RADEON_SUBDIR) $(OMAP_SUBDIR) $(EXYNOS_SUBDIR) $(FREEDRENO_SUBDIR) $(TEGRA_SUBDIR) tests include man
 
 libdrm_la_LTLIBRARIES = libdrm.la
 libdrm_ladir = $(libdir)
diff --git a/configure.ac b/configure.ac
index 3f4164238494..752a70592933 100644
--- a/configure.ac
+++ b/configure.ac
@@ -98,6 +98,11 @@ AC_ARG_ENABLE(freedreno-experimental-api,
 	      [Enable support for freedreno's experimental API (default: disabled)]),
 	      [FREEDRENO=$enableval], [FREEDRENO=no])
 
+AC_ARG_ENABLE(tegra-experimental-api,
+	      AS_HELP_STRING([--enable-tegra-experimental-api],
+	      [Enable support for Tegra's experimental API (default: disabled)]),
+	      [TEGRA=$enableval], [TEGRA=no])
+
 AC_ARG_ENABLE(install-test-programs,
 		  AS_HELP_STRING([--enable-install-test-programs],
 		  [Install test programs (default: no)]),
@@ -218,6 +223,11 @@ if test "x$FREEDRENO" = xyes; then
 	AC_DEFINE(HAVE_FREEDRENO, 1, [Have freedreno support])
 fi
 
+AM_CONDITIONAL(HAVE_TEGRA, [test "x$TEGRA" = xyes])
+if test "x$TEGRA" = xyes; then
+	AC_DEFINE(HAVE_TEGRA, 1, [Have Tegra support])
+fi
+
 AM_CONDITIONAL(HAVE_INSTALL_TESTS, [test "x$INSTALL_TESTS" = xyes])
 if test "x$INSTALL_TESTS" = xyes; then
 	AC_DEFINE(HAVE_INSTALL_TESTS, 1, [Install test programs])
@@ -269,7 +279,7 @@ else
 fi
 AM_CONDITIONAL([HAVE_MANPAGES_STYLESHEET], [test "x$HAVE_MANPAGES_STYLESHEET" = "xyes"])
 
-if test "x$INTEL" != "xno" -o "x$RADEON" != "xno" -o "x$NOUVEAU" != "xno" -o "x$OMAP" != "xno" -o "x$FREEDRENO" != "xno"; then
+if test "x$INTEL" != "xno" -o "x$RADEON" != "xno" -o "x$NOUVEAU" != "xno" -o "x$OMAP" != "xno" -o "x$FREEDRENO" != "xno" -o "x$TEGRA" != "xno"; then
     # Check for atomic intrinsics
     AC_CACHE_CHECK([for native atomic primitives], drm_cv_atomic_primitives,
     [
@@ -402,6 +412,8 @@ AC_CONFIG_FILES([
 	exynos/libdrm_exynos.pc
 	freedreno/Makefile
 	freedreno/libdrm_freedreno.pc
+	tegra/Makefile
+	tegra/libdrm_tegra.pc
 	tests/Makefile
 	tests/modeprint/Makefile
 	tests/modetest/Makefile
@@ -426,4 +438,5 @@ echo "  Nouveau API    $NOUVEAU"
 echo "  OMAP API       $OMAP"
 echo "  EXYNOS API     $EXYNOS"
 echo "  Freedreno API  $FREEDRENO"
+echo "  Tegra API      $TEGRA"
 echo ""
diff --git a/include/drm/Makefile.am b/include/drm/Makefile.am
index 2bc34d2ffd9f..f591abc45152 100644
--- a/include/drm/Makefile.am
+++ b/include/drm/Makefile.am
@@ -35,6 +35,7 @@ klibdrminclude_HEADERS = \
 	radeon_drm.h \
 	savage_drm.h \
 	sis_drm.h \
+	tegra_drm.h \
 	via_drm.h \
 	mach64_drm.h \
 	qxl_drm.h
diff --git a/include/drm/tegra_drm.h b/include/drm/tegra_drm.h
new file mode 100644
index 000000000000..956ed8aa9d98
--- /dev/null
+++ b/include/drm/tegra_drm.h
@@ -0,0 +1,157 @@
+/*
+ * Copyright (c) 2012-2013, NVIDIA 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 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 _UAPI_TEGRA_DRM_H_
+#define _UAPI_TEGRA_DRM_H_
+
+#include <drm/drm.h>
+
+#define DRM_TEGRA_GEM_CREATE_TILED     (1 << 0)
+#define DRM_TEGRA_GEM_CREATE_BOTTOM_UP (1 << 1)
+
+struct drm_tegra_gem_create {
+	__u64 size;
+	__u32 flags;
+	__u32 handle;
+};
+
+struct drm_tegra_gem_mmap {
+	__u32 handle;
+	__u32 offset;
+};
+
+struct drm_tegra_syncpt_read {
+	__u32 id;
+	__u32 value;
+};
+
+struct drm_tegra_syncpt_incr {
+	__u32 id;
+	__u32 pad;
+};
+
+struct drm_tegra_syncpt_wait {
+	__u32 id;
+	__u32 thresh;
+	__u32 timeout;
+	__u32 value;
+};
+
+#define DRM_TEGRA_NO_TIMEOUT	(0xffffffff)
+
+struct drm_tegra_open_channel {
+	__u32 client;
+	__u32 pad;
+	__u64 context;
+};
+
+struct drm_tegra_close_channel {
+	__u64 context;
+};
+
+struct drm_tegra_get_syncpt {
+	__u64 context;
+	__u32 index;
+	__u32 id;
+};
+
+struct drm_tegra_get_syncpt_base {
+	__u64 context;
+	__u32 syncpt;
+	__u32 id;
+};
+
+struct drm_tegra_syncpt {
+	__u32 id;
+	__u32 incrs;
+};
+
+struct drm_tegra_cmdbuf {
+	__u32 handle;
+	__u32 offset;
+	__u32 words;
+	__u32 pad;
+};
+
+struct drm_tegra_reloc {
+	struct {
+		__u32 handle;
+		__u32 offset;
+	} cmdbuf;
+	struct {
+		__u32 handle;
+		__u32 offset;
+	} target;
+	__u32 shift;
+	__u32 pad;
+};
+
+struct drm_tegra_waitchk {
+	__u32 handle;
+	__u32 offset;
+	__u32 syncpt;
+	__u32 thresh;
+};
+
+struct drm_tegra_submit {
+	__u64 context;
+	__u32 num_syncpts;
+	__u32 num_cmdbufs;
+	__u32 num_relocs;
+	__u32 num_waitchks;
+	__u32 waitchk_mask;
+	__u32 timeout;
+	__u32 pad;
+	__u64 syncpts;
+	__u64 cmdbufs;
+	__u64 relocs;
+	__u64 waitchks;
+	__u32 fence;		/* Return value */
+
+	__u32 reserved[5];	/* future expansion */
+};
+
+#define DRM_TEGRA_GEM_CREATE		0x00
+#define DRM_TEGRA_GEM_MMAP		0x01
+#define DRM_TEGRA_SYNCPT_READ		0x02
+#define DRM_TEGRA_SYNCPT_INCR		0x03
+#define DRM_TEGRA_SYNCPT_WAIT		0x04
+#define DRM_TEGRA_OPEN_CHANNEL		0x05
+#define DRM_TEGRA_CLOSE_CHANNEL		0x06
+#define DRM_TEGRA_GET_SYNCPT		0x07
+#define DRM_TEGRA_SUBMIT		0x08
+#define DRM_TEGRA_GET_SYNCPT_BASE	0x09
+
+#define DRM_IOCTL_TEGRA_GEM_CREATE DRM_IOWR(DRM_COMMAND_BASE + DRM_TEGRA_GEM_CREATE, struct drm_tegra_gem_create)
+#define DRM_IOCTL_TEGRA_GEM_MMAP DRM_IOWR(DRM_COMMAND_BASE + DRM_TEGRA_GEM_MMAP, struct drm_tegra_gem_mmap)
+#define DRM_IOCTL_TEGRA_SYNCPT_READ DRM_IOWR(DRM_COMMAND_BASE + DRM_TEGRA_SYNCPT_READ, struct drm_tegra_syncpt_read)
+#define DRM_IOCTL_TEGRA_SYNCPT_INCR DRM_IOWR(DRM_COMMAND_BASE + DRM_TEGRA_SYNCPT_INCR, struct drm_tegra_syncpt_incr)
+#define DRM_IOCTL_TEGRA_SYNCPT_WAIT DRM_IOWR(DRM_COMMAND_BASE + DRM_TEGRA_SYNCPT_WAIT, struct drm_tegra_syncpt_wait)
+#define DRM_IOCTL_TEGRA_OPEN_CHANNEL DRM_IOWR(DRM_COMMAND_BASE + DRM_TEGRA_OPEN_CHANNEL, struct drm_tegra_open_channel)
+#define DRM_IOCTL_TEGRA_CLOSE_CHANNEL DRM_IOWR(DRM_COMMAND_BASE + DRM_TEGRA_CLOSE_CHANNEL, struct drm_tegra_open_channel)
+#define DRM_IOCTL_TEGRA_GET_SYNCPT DRM_IOWR(DRM_COMMAND_BASE + DRM_TEGRA_GET_SYNCPT, struct drm_tegra_get_syncpt)
+#define DRM_IOCTL_TEGRA_SUBMIT DRM_IOWR(DRM_COMMAND_BASE + DRM_TEGRA_SUBMIT, struct drm_tegra_submit)
+#define DRM_IOCTL_TEGRA_GET_SYNCPT_BASE DRM_IOWR(DRM_COMMAND_BASE + DRM_TEGRA_GET_SYNCPT_BASE, struct drm_tegra_get_syncpt_base)
+
+#endif
diff --git a/tegra/Makefile.am b/tegra/Makefile.am
new file mode 100644
index 000000000000..1b83145b120d
--- /dev/null
+++ b/tegra/Makefile.am
@@ -0,0 +1,20 @@
+AM_CPPFLAGS = \
+	-I$(top_srcdir) \
+	-I$(top_srcdir)/include/drm
+
+AM_CFLAGS = \
+	$(VISIBILITY_CFLAGS)
+
+libdrm_tegra_ladir = $(libdir)
+libdrm_tegra_la_LTLIBRARIES = libdrm_tegra.la
+libdrm_tegra_la_LDFLAGS = -version-number 0:0:0 -no-undefined
+libdrm_tegra_la_LIBADD = ../libdrm.la @PTHREADSTUBS_LIBS@
+
+libdrm_tegra_la_SOURCES = \
+	tegra.c
+
+libdrm_tegraincludedir = ${includedir}/libdrm
+libdrm_tegrainclude_HEADERS = tegra.h
+
+pkgconfigdir = @pkgconfigdir@
+pkgconfig_DATA = libdrm_tegra.pc
diff --git a/tegra/libdrm_tegra.pc.in b/tegra/libdrm_tegra.pc.in
new file mode 100644
index 000000000000..2e06f49c6fba
--- /dev/null
+++ b/tegra/libdrm_tegra.pc.in
@@ -0,0 +1,11 @@
+prefix=@prefix@
+exec_prefix=@exec_prefix@
+libdir=@libdir@
+includedir=@includedir@
+
+Name: libdrm_tegra
+Description: Userspace interface to Tegra kernel DRM services
+Version: @PACKAGE_VERSION@
+Libs: -L${libdir} -ldrm_tegra
+Cflags: -I${includedir} -I${includedir}/libdrm
+Requires.private: libdrm
diff --git a/tegra/private.h b/tegra/private.h
new file mode 100644
index 000000000000..ec69295c2cf8
--- /dev/null
+++ b/tegra/private.h
@@ -0,0 +1,58 @@
+/*
+ * Copyright © 2012, 2013 Thierry Reding
+ * Copyright © 2013 Erik Faye-Lund
+ * Copyright © 2014 NVIDIA Corporation
+ *
+ * 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 COPYRIGHT HOLDER(S) OR AUTHOR(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 __DRM_TEGRA_PRIVATE_H__
+#define __DRM_TEGRA_PRIVATE_H__ 1
+
+#include <stdbool.h>
+#include <stdint.h>
+
+#include <xf86atomic.h>
+
+#include "tegra.h"
+
+#if defined(HAVE_VISIBILITY)
+#  define drm_private __attribute__((visibility("hidden")))
+#  define drm_public __attribute__((visibility("default")))
+#else
+#  define drm_private
+#  define drm_public
+#endif
+
+struct drm_tegra {
+	bool close;
+	int fd;
+};
+
+struct drm_tegra_bo {
+	struct drm_tegra *drm;
+	uint32_t handle;
+	uint32_t offset;
+	uint32_t flags;
+	uint32_t size;
+	atomic_t ref;
+	void *map;
+};
+
+#endif /* __DRM_TEGRA_PRIVATE_H__ */
diff --git a/tegra/tegra.c b/tegra/tegra.c
new file mode 100644
index 000000000000..8c48ae7c30a1
--- /dev/null
+++ b/tegra/tegra.c
@@ -0,0 +1,253 @@
+/*
+ * Copyright © 2012, 2013 Thierry Reding
+ * Copyright © 2013 Erik Faye-Lund
+ * Copyright © 2014 NVIDIA Corporation
+ *
+ * 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 COPYRIGHT HOLDER(S) OR AUTHOR(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.
+ */
+
+#ifdef HAVE_CONFIG_H
+#  include "config.h"
+#endif
+
+#include <errno.h>
+#include <fcntl.h>
+#include <string.h>
+
+#include <sys/mman.h>
+
+#include <xf86drm.h>
+
+#include <tegra_drm.h>
+
+#include "private.h"
+
+static inline struct tegra_bo *tegra_bo(struct drm_tegra_bo *bo)
+{
+	return (struct tegra_bo *)bo;
+}
+
+static void drm_tegra_bo_free(struct drm_tegra_bo *bo)
+{
+	struct drm_tegra *drm = bo->drm;
+	struct drm_gem_close args;
+
+	if (bo->map)
+		munmap(bo->map, bo->size);
+
+	memset(&args, 0, sizeof(args));
+	args.handle = bo->handle;
+
+	drmIoctl(drm->fd, DRM_IOCTL_GEM_CLOSE, &args);
+
+	free(bo);
+}
+
+static int drm_tegra_wrap(struct drm_tegra **drmp, int fd, bool close)
+{
+	struct drm_tegra *drm;
+	int err;
+
+	if (fd < 0 || !drmp)
+		return -EINVAL;
+
+	drm = calloc(1, sizeof(*drm));
+	if (!drm)
+		return -ENOMEM;
+
+	drm->close = close;
+	drm->fd = fd;
+
+	*drmp = drm;
+
+	return 0;
+}
+
+drm_public
+int drm_tegra_new(struct drm_tegra **drmp, int fd)
+{
+	bool supported = false;
+	drmVersionPtr version;
+
+	version = drmGetVersion(fd);
+	if (!version)
+		return -ENOMEM;
+
+	if (!strncmp(version->name, "tegra", version->name_len))
+		supported = true;
+
+	drmFreeVersion(version);
+
+	if (!supported)
+		return -ENOTSUP;
+
+	return drm_tegra_wrap(drmp, fd, false);
+}
+
+drm_public
+void drm_tegra_close(struct drm_tegra *drm)
+{
+	if (!drm)
+		return;
+
+	if (drm->close)
+		close(drm->fd);
+
+	free(drm);
+}
+
+drm_public
+int drm_tegra_bo_new(struct drm_tegra_bo **bop, struct drm_tegra *drm,
+		     uint32_t flags, uint32_t size)
+{
+	struct drm_tegra_gem_create args;
+	struct drm_tegra_bo *bo;
+	int err;
+
+	if (!drm || size == 0 || !bop)
+		return -EINVAL;
+
+	bo = calloc(1, sizeof(*bo));
+	if (!bo)
+		return -ENOMEM;
+
+	atomic_set(&bo->ref, 1);
+	bo->flags = flags;
+	bo->size = size;
+	bo->drm = drm;
+
+	memset(&args, 0, sizeof(args));
+	args.flags = flags;
+	args.size = size;
+
+	err = drmCommandWriteRead(drm->fd, DRM_TEGRA_GEM_CREATE, &args,
+				  sizeof(args));
+	if (err < 0) {
+		err = -errno;
+		free(bo);
+		return err;
+	}
+
+	bo->handle = args.handle;
+
+	*bop = bo;
+
+	return 0;
+}
+
+drm_public
+int drm_tegra_bo_wrap(struct drm_tegra_bo **bop, struct drm_tegra *drm,
+		      uint32_t handle, uint32_t flags, size_t size)
+{
+	struct drm_tegra_bo *bo;
+
+	if (!drm || !bop)
+		return -EINVAL;
+
+	bo = calloc(1, sizeof(*bo));
+	if (!bo)
+		return -ENOMEM;
+
+	atomic_set(&bo->ref, 1);
+	bo->handle = handle;
+	bo->flags = flags;
+	bo->size = size;
+	bo->drm = drm;
+
+	*bop = bo;
+
+	return 0;
+}
+
+drm_public
+struct drm_tegra_bo *drm_tegra_bo_get(struct drm_tegra_bo *bo)
+{
+	if (bo)
+		atomic_inc(&bo->ref);
+
+	return bo;
+}
+
+drm_public
+void drm_tegra_bo_put(struct drm_tegra_bo *bo)
+{
+	if (bo && atomic_dec_and_test(&bo->ref))
+		drm_tegra_bo_free(bo);
+}
+
+drm_public
+int drm_tegra_bo_get_handle(struct drm_tegra_bo *bo, uint32_t *handle)
+{
+	if (!bo || !handle)
+		return -EINVAL;
+
+	*handle = bo->handle;
+
+	return 0;
+}
+
+drm_public
+int drm_tegra_bo_map(struct drm_tegra_bo *bo, void **ptr)
+{
+	struct drm_tegra *drm = bo->drm;
+
+	if (!bo->map) {
+		struct drm_tegra_gem_mmap args;
+		int err;
+
+		memset(&args, 0, sizeof(args));
+		args.handle = bo->handle;
+
+		err = drmCommandWriteRead(drm->fd, DRM_TEGRA_GEM_MMAP, &args,
+					  sizeof(args));
+		if (err < 0)
+			return -errno;
+
+		bo->offset = args.offset;
+
+		bo->map = mmap(0, bo->size, PROT_READ | PROT_WRITE, MAP_SHARED,
+			       drm->fd, bo->offset);
+		if (bo->map == MAP_FAILED) {
+			bo->map = NULL;
+			return -errno;
+		}
+	}
+
+	if (ptr)
+		*ptr = bo->map;
+
+	return 0;
+}
+
+drm_public
+int drm_tegra_bo_unmap(struct drm_tegra_bo *bo)
+{
+	if (!bo)
+		return -EINVAL;
+
+	if (!bo->map)
+		return 0;
+
+	if (munmap(bo->map, bo->size))
+		return -errno;
+
+	bo->map = NULL;
+
+	return 0;
+}
diff --git a/tegra/tegra.h b/tegra/tegra.h
new file mode 100644
index 000000000000..0731cb3bd4dc
--- /dev/null
+++ b/tegra/tegra.h
@@ -0,0 +1,47 @@
+/*
+ * Copyright © 2012, 2013 Thierry Reding
+ * Copyright © 2013 Erik Faye-Lund
+ * Copyright © 2014 NVIDIA Corporation
+ *
+ * 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 COPYRIGHT HOLDER(S) OR AUTHOR(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 __DRM_TEGRA_H__
+#define __DRM_TEGRA_H__ 1
+
+#include <stdint.h>
+#include <stdlib.h>
+
+struct drm_tegra_bo;
+struct drm_tegra;
+
+int drm_tegra_new(struct drm_tegra **drmp, int fd);
+void drm_tegra_close(struct drm_tegra *drm);
+
+int drm_tegra_bo_new(struct drm_tegra_bo **bop, struct drm_tegra *drm,
+		     uint32_t flags, uint32_t size);
+int drm_tegra_bo_wrap(struct drm_tegra_bo **bop, struct drm_tegra *drm,
+		      uint32_t handle, uint32_t flags, uint32_t size);
+struct drm_tegra_bo *drm_tegra_bo_get(struct drm_tegra_bo *bo);
+void drm_tegra_bo_put(struct drm_tegra_bo *bo);
+int drm_tegra_bo_get_handle(struct drm_tegra_bo *bo, uint32_t *handle);
+int drm_tegra_bo_map(struct drm_tegra_bo *bo, void **ptr);
+int drm_tegra_bo_unmap(struct drm_tegra_bo *bo);
+
+#endif /* __DRM_TEGRA_H__ */
diff --git a/tests/modetest/modetest.c b/tests/modetest/modetest.c
index bc9c9988dec7..4212963f8ff0 100644
--- a/tests/modetest/modetest.c
+++ b/tests/modetest/modetest.c
@@ -1386,7 +1386,7 @@ int main(int argc, char **argv)
 	int encoders = 0, connectors = 0, crtcs = 0, planes = 0, framebuffers = 0;
 	int drop_master = 0;
 	int test_vsync = 0;
-	const char *modules[] = { "i915", "radeon", "nouveau", "vmwgfx", "omapdrm", "exynos", "tilcdc", "msm" };
+	const char *modules[] = { "i915", "radeon", "nouveau", "vmwgfx", "omapdrm", "exynos", "tilcdc", "msm", "tegra" };
 	char *device = NULL;
 	char *module = NULL;
 	unsigned int i;
diff --git a/tests/vbltest/vbltest.c b/tests/vbltest/vbltest.c
index 2a09d28ed00a..e4b200bf0c3c 100644
--- a/tests/vbltest/vbltest.c
+++ b/tests/vbltest/vbltest.c
@@ -103,7 +103,7 @@ static void usage(char *name)
 int main(int argc, char **argv)
 {
 	int i, c, fd, ret;
-	char *modules[] = { "i915", "radeon", "nouveau", "vmwgfx", "exynos", "omapdrm", "tilcdc", "msm" };
+	char *modules[] = { "i915", "radeon", "nouveau", "vmwgfx", "exynos", "omapdrm", "tilcdc", "msm", "tegra" };
 	drmVBlank vbl;
 	drmEventContext evctx;
 	struct vbl_info handler_info;
-- 
1.8.4.2

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [RFC libdrm 3/6] tegra: Add simple test for drm_tegra_open()
  2014-02-19 16:04 [RFC libdrm 0/6] Add NVIDIA Tegra support Thierry Reding
  2014-02-19 16:04 ` [RFC libdrm 1/6] configure: Support symbol visibility when available Thierry Reding
  2014-02-19 16:04 ` [RFC libdrm 2/6] libdrm: Add NVIDIA Tegra support Thierry Reding
@ 2014-02-19 16:04 ` Thierry Reding
  2014-02-19 20:19   ` Erik Faye-Lund
  2014-02-19 21:34   ` Erik Faye-Lund
  2014-02-19 16:04 ` [RFC libdrm 4/6] tegra: Add channel, job, pushbuf and fence APIs Thierry Reding
                   ` (3 subsequent siblings)
  6 siblings, 2 replies; 24+ messages in thread
From: Thierry Reding @ 2014-02-19 16:04 UTC (permalink / raw)
  To: dri-devel

From: Thierry Reding <treding@nvidia.com>

This test opens a device, dumps the version information and checks that
a Tegra DRM context can be opened on it.

Signed-off-by: Thierry Reding <treding@nvidia.com>
---
 configure.ac            |  1 +
 tests/Makefile.am       |  4 ++++
 tests/tegra/Makefile.am | 20 ++++++++++++++++
 tests/tegra/openclose.c | 63 +++++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 88 insertions(+)
 create mode 100644 tests/tegra/Makefile.am
 create mode 100644 tests/tegra/openclose.c

diff --git a/configure.ac b/configure.ac
index 752a70592933..c4ae14e8d2e1 100644
--- a/configure.ac
+++ b/configure.ac
@@ -421,6 +421,7 @@ AC_CONFIG_FILES([
 	tests/radeon/Makefile
 	tests/vbltest/Makefile
 	tests/exynos/Makefile
+	tests/tegra/Makefile
 	include/Makefile
 	include/drm/Makefile
 	man/Makefile
diff --git a/tests/Makefile.am b/tests/Makefile.am
index cd1149130214..0a3d21f2d99f 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -24,6 +24,10 @@ if HAVE_EXYNOS
 SUBDIRS += exynos
 endif
 
+if HAVE_TEGRA
+SUBDIRS += tegra
+endif
+
 if HAVE_LIBUDEV
 
 check_LTLIBRARIES = libdrmtest.la
diff --git a/tests/tegra/Makefile.am b/tests/tegra/Makefile.am
new file mode 100644
index 000000000000..7039f09d38aa
--- /dev/null
+++ b/tests/tegra/Makefile.am
@@ -0,0 +1,20 @@
+AM_CPPFLAGS = \
+	-I$(top_srcdir)/include/drm \
+	-I$(top_srcdir)/tegra
+
+AM_CFLAGS = -Wall -Werror
+
+LDADD = \
+	../../tegra/libdrm_tegra.la
+
+TESTS = \
+	openclose \
+
+if HAVE_INSTALL_TESTS
+testdir = $(libexecdir)/libdrm/tests/tegra
+test_PROGRAMS = \
+	$(TESTS)
+else
+noinst_PROGRAMS = $(TESTS)
+check_PROGRAMS = $(TESTS)
+endif
diff --git a/tests/tegra/openclose.c b/tests/tegra/openclose.c
new file mode 100644
index 000000000000..5b4230c774f6
--- /dev/null
+++ b/tests/tegra/openclose.c
@@ -0,0 +1,63 @@
+/*
+ * Copyright © 2014 NVIDIA Corporation
+ *
+ * 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 COPYRIGHT HOLDER(S) OR AUTHOR(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.
+ */
+
+#ifdef HAVE_CONFIG_H
+#  include "config.h"
+#endif
+
+#include <fcntl.h>
+#include <stdio.h>
+#include <unistd.h>
+
+#include "xf86drm.h"
+#include "tegra.h"
+
+int main(int argc, char *argv[])
+{
+	struct drm_tegra *tegra;
+	drmVersionPtr version;
+	int err, fd;
+
+	fd = open(argv[1], O_RDWR);
+	if (fd < 0)
+		return 1;
+
+	version = drmGetVersion(fd);
+	if (version) {
+		printf("Version: %d.%d.%d\n", version->version_major,
+		       version->version_minor, version->version_patchlevel);
+		printf("  Name: %s\n", version->name);
+		printf("  Date: %s\n", version->date);
+		printf("  Description: %s\n", version->desc);
+
+		drmFreeVersion(version);
+	}
+
+	err = drm_tegra_new(&tegra, fd);
+	if (err < 0)
+		return 1;
+
+	drm_tegra_close(tegra);
+	close(fd);
+
+	return 0;
+}
-- 
1.8.4.2

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [RFC libdrm 4/6] tegra: Add channel, job, pushbuf and fence APIs
  2014-02-19 16:04 [RFC libdrm 0/6] Add NVIDIA Tegra support Thierry Reding
                   ` (2 preceding siblings ...)
  2014-02-19 16:04 ` [RFC libdrm 3/6] tegra: Add simple test for drm_tegra_open() Thierry Reding
@ 2014-02-19 16:04 ` Thierry Reding
  2014-02-19 19:57   ` Erik Faye-Lund
  2014-02-19 16:04 ` [RFC libdrm 5/6] tegra: Add helper library for tests Thierry Reding
                   ` (2 subsequent siblings)
  6 siblings, 1 reply; 24+ messages in thread
From: Thierry Reding @ 2014-02-19 16:04 UTC (permalink / raw)
  To: dri-devel

From: Thierry Reding <treding@nvidia.com>

These functions can be used to open channels to engines, manage job
submissions, create push buffers to store command streams in and wait
until jobs have been completed.

Signed-off-by: Thierry Reding <treding@nvidia.com>
---
 tegra/Makefile.am |   4 ++
 tegra/channel.c   | 127 +++++++++++++++++++++++++++++++++++++++++
 tegra/fence.c     |  72 +++++++++++++++++++++++
 tegra/job.c       | 167 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 tegra/private.h   |  59 +++++++++++++++++++
 tegra/pushbuf.c   | 137 ++++++++++++++++++++++++++++++++++++++++++++
 tegra/tegra.h     |  52 +++++++++++++++++
 7 files changed, 618 insertions(+)
 create mode 100644 tegra/channel.c
 create mode 100644 tegra/fence.c
 create mode 100644 tegra/job.c
 create mode 100644 tegra/pushbuf.c

diff --git a/tegra/Makefile.am b/tegra/Makefile.am
index 1b83145b120d..c73587e8661e 100644
--- a/tegra/Makefile.am
+++ b/tegra/Makefile.am
@@ -11,6 +11,10 @@ libdrm_tegra_la_LDFLAGS = -version-number 0:0:0 -no-undefined
 libdrm_tegra_la_LIBADD = ../libdrm.la @PTHREADSTUBS_LIBS@
 
 libdrm_tegra_la_SOURCES = \
+	channel.c \
+	fence.c \
+	job.c \
+	pushbuf.c \
 	tegra.c
 
 libdrm_tegraincludedir = ${includedir}/libdrm
diff --git a/tegra/channel.c b/tegra/channel.c
new file mode 100644
index 000000000000..03cce30e98b9
--- /dev/null
+++ b/tegra/channel.c
@@ -0,0 +1,127 @@
+/*
+ * Copyright © 2012, 2013 Thierry Reding
+ * Copyright © 2013 Erik Faye-Lund
+ * Copyright © 2014 NVIDIA Corporation
+ *
+ * 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 COPYRIGHT HOLDER(S) OR AUTHOR(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.
+ */
+
+#ifdef HAVE_CONFIG_H
+#  include "config.h"
+#endif
+
+#include <errno.h>
+#include <string.h>
+
+#include "private.h"
+
+static int drm_tegra_channel_setup(struct drm_tegra_channel *channel)
+{
+	struct drm_tegra *drm = channel->drm;
+	struct drm_tegra_get_syncpt args;
+	int err;
+
+	memset(&args, 0, sizeof(args));
+	args.context = channel->context;
+	args.index = 0;
+
+	err = ioctl(drm->fd, DRM_IOCTL_TEGRA_GET_SYNCPT, &args);
+	if (err < 0)
+		return -errno;
+
+	channel->syncpt = args.id;
+
+	return 0;
+}
+
+drm_public
+int drm_tegra_channel_open(struct drm_tegra_channel **channelp,
+			   struct drm_tegra *drm,
+			   enum drm_tegra_class client)
+{
+	struct drm_tegra_open_channel args;
+	struct drm_tegra_channel *channel;
+	enum host1x_class class;
+	int err;
+
+	switch (client) {
+	case DRM_TEGRA_GR2D:
+		class = HOST1X_CLASS_GR2D;
+		break;
+
+	case DRM_TEGRA_GR3D:
+		class = HOST1X_CLASS_GR3D;
+		break;
+
+	default:
+		return -EINVAL;
+	}
+
+	channel = calloc(1, sizeof(*channel));
+	if (!channel)
+		return -ENOMEM;
+
+	channel->drm = drm;
+
+	memset(&args, 0, sizeof(args));
+	args.client = class;
+
+	err = ioctl(drm->fd, DRM_IOCTL_TEGRA_OPEN_CHANNEL, &args);
+	if (err < 0) {
+		free(channel);
+		return -errno;
+	}
+
+	channel->context = args.context;
+	channel->class = class;
+
+	err = drm_tegra_channel_setup(channel);
+	if (err < 0) {
+		free(channel);
+		return err;
+	}
+
+	*channelp = channel;
+
+	return 0;
+}
+
+drm_public
+int drm_tegra_channel_close(struct drm_tegra_channel *channel)
+{
+	struct drm_tegra_open_channel args;
+	struct drm_tegra *drm;
+	int err;
+
+	if (!channel)
+		return -EINVAL;
+
+	drm = channel->drm;
+
+	memset(&args, 0, sizeof(args));
+	args.context = channel->context;
+
+	err = ioctl(drm->fd, DRM_IOCTL_TEGRA_CLOSE_CHANNEL, &args);
+	if (err < 0)
+		return -errno;
+
+	free(channel);
+
+	return 0;
+}
diff --git a/tegra/fence.c b/tegra/fence.c
new file mode 100644
index 000000000000..6af60500c5f1
--- /dev/null
+++ b/tegra/fence.c
@@ -0,0 +1,72 @@
+/*
+ * Copyright © 2012, 2013 Thierry Reding
+ * Copyright © 2013 Erik Faye-Lund
+ * Copyright © 2014 NVIDIA Corporation
+ *
+ * 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 COPYRIGHT HOLDER(S) OR AUTHOR(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.
+ */
+
+#ifdef HAVE_CONFIG_H
+#  include "config.h"
+#endif
+
+#include <errno.h>
+#include <string.h>
+
+#include "private.h"
+
+drm_public
+int drm_tegra_fence_wait_timeout(struct drm_tegra_fence *fence,
+				 unsigned long timeout)
+{
+	struct drm_tegra_syncpt_wait args;
+	int err;
+
+	memset(&args, 0, sizeof(args));
+	args.id = fence->syncpt;
+	args.thresh = fence->value;
+	args.timeout = timeout;
+
+	while (true) {
+		err = ioctl(fence->drm->fd, DRM_IOCTL_TEGRA_SYNCPT_WAIT, &args);
+		if (err < 0) {
+			if (errno == EINTR)
+				continue;
+
+			drmMsg("DRM_IOCTL_TEGRA_SYNCPT_WAIT: %d\n", -errno);
+			return -errno;
+		}
+
+		break;
+	}
+
+	return 0;
+}
+
+drm_public
+int drm_tegra_fence_wait(struct drm_tegra_fence *fence)
+{
+	return drm_tegra_fence_wait_timeout(fence, -1);
+}
+
+drm_public
+void drm_tegra_fence_free(struct drm_tegra_fence *fence)
+{
+	free(fence);
+}
diff --git a/tegra/job.c b/tegra/job.c
new file mode 100644
index 000000000000..506164cec95e
--- /dev/null
+++ b/tegra/job.c
@@ -0,0 +1,167 @@
+/*
+ * Copyright © 2012, 2013 Thierry Reding
+ * Copyright © 2013 Erik Faye-Lund
+ * Copyright © 2014 NVIDIA Corporation
+ *
+ * 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 COPYRIGHT HOLDER(S) OR AUTHOR(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.
+ */
+
+#ifdef HAVE_CONFIG_H
+#  include "config.h"
+#endif
+
+#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "private.h"
+
+int drm_tegra_job_add_reloc(struct drm_tegra_job *job,
+			    const struct drm_tegra_reloc *reloc)
+{
+	struct drm_tegra_reloc *relocs;
+	size_t size;
+
+	size = (job->num_relocs + 1) * sizeof(*reloc);
+
+	relocs = realloc(job->relocs, size);
+	if (!reloc)
+		return -ENOMEM;
+
+	job->relocs = relocs;
+
+	job->relocs[job->num_relocs++] = *reloc;
+
+	return 0;
+}
+
+drm_public
+int drm_tegra_job_new(struct drm_tegra_job **jobp,
+		      struct drm_tegra_channel *channel)
+{
+	struct drm_tegra_job *job;
+
+	job = calloc(1, sizeof(*job));
+	if (!job)
+		return -ENOMEM;
+
+	DRMINITLISTHEAD(&job->pushbufs);
+	job->channel = channel;
+
+	*jobp = job;
+
+	return 0;
+}
+
+drm_public
+int drm_tegra_job_free(struct drm_tegra_job *job)
+{
+	struct drm_tegra_pushbuf_private *pushbuf;
+
+	if (!job)
+		return -EINVAL;
+
+	DRMLISTFOREACHENTRY(pushbuf, &job->pushbufs, list)
+		drm_tegra_pushbuf_free(&pushbuf->base);
+
+	free(job->relocs);
+	free(job);
+
+	return 0;
+}
+
+drm_public
+int drm_tegra_job_submit(struct drm_tegra_job *job,
+			 struct drm_tegra_fence **fencep)
+{
+	struct drm_tegra *drm = job->channel->drm;
+	struct drm_tegra_pushbuf_private *pushbuf;
+	struct drm_tegra_fence *fence = NULL;
+	struct drm_tegra_cmdbuf *cmdbufs;
+	struct drm_tegra_syncpt *syncpts;
+	struct drm_tegra_submit args;
+	unsigned int i;
+	int err;
+
+	if (fencep) {
+		fence = calloc(1, sizeof(*fence));
+		if (!fence)
+			return -ENOMEM;
+	}
+
+	cmdbufs = calloc(job->num_pushbufs, sizeof(*cmdbufs));
+	if (!cmdbufs) {
+		free(fence);
+		return -ENOMEM;
+	}
+
+	DRMLISTFOREACHENTRY(pushbuf, &job->pushbufs, list) {
+		struct drm_tegra_cmdbuf *cmdbuf = &cmdbufs[i];
+
+		cmdbuf->handle = pushbuf->bo->handle;
+		cmdbuf->offset = pushbuf->offset;
+		cmdbuf->words = pushbuf->base.ptr - pushbuf->start;
+	}
+
+	syncpts = calloc(1, sizeof(*syncpts));
+	if (!syncpts) {
+		free(cmdbufs);
+		free(fence);
+		return -ENOMEM;
+	}
+
+	syncpts[0].id = job->syncpt;
+	syncpts[0].incrs = job->increments;
+
+	memset(&args, 0, sizeof(args));
+	args.context = job->channel->context;
+	args.num_syncpts = 1;
+	args.num_cmdbufs = job->num_pushbufs;
+	args.num_relocs = job->num_relocs;
+	args.num_waitchks = 0;
+	args.waitchk_mask = 0;
+	args.timeout = 1000;
+
+	args.syncpts = (uintptr_t)syncpts;
+	args.cmdbufs = (uintptr_t)cmdbufs;
+	args.relocs = (uintptr_t)job->relocs;
+	args.waitchks = 0;
+
+	err = ioctl(drm->fd, DRM_IOCTL_TEGRA_SUBMIT, &args);
+	if (err < 0) {
+		free(syncpts);
+		free(cmdbufs);
+		free(fence);
+		return -errno;
+	}
+
+	if (fence) {
+		fence->syncpt = job->syncpt;
+		fence->value = args.fence;
+		fence->drm = drm;
+	}
+
+	if (fencep)
+		*fencep = fence;
+
+	free(syncpts);
+	free(cmdbufs);
+
+	return 0;
+}
diff --git a/tegra/private.h b/tegra/private.h
index ec69295c2cf8..3a72e9962f53 100644
--- a/tegra/private.h
+++ b/tegra/private.h
@@ -26,10 +26,13 @@
 #define __DRM_TEGRA_PRIVATE_H__ 1
 
 #include <stdbool.h>
+#include <stddef.h>
 #include <stdint.h>
 
+#include <libdrm_lists.h>
 #include <xf86atomic.h>
 
+#include "tegra_drm.h"
 #include "tegra.h"
 
 #if defined(HAVE_VISIBILITY)
@@ -40,6 +43,18 @@
 #  define drm_public
 #endif
 
+#define container_of(ptr, type, member) ({				\
+		const typeof(((type *)0)->member) *__mptr = (ptr);	\
+		(type *)((char *)__mptr - offsetof(type, member));	\
+	})
+
+enum host1x_class {
+	HOST1X_CLASS_HOST1X = 0x01,
+	HOST1X_CLASS_GR2D = 0x51,
+	HOST1X_CLASS_GR2D_SB = 0x52,
+	HOST1X_CLASS_GR3D = 0x60,
+};
+
 struct drm_tegra {
 	bool close;
 	int fd;
@@ -55,4 +70,48 @@ struct drm_tegra_bo {
 	void *map;
 };
 
+struct drm_tegra_channel {
+	struct drm_tegra *drm;
+	enum host1x_class class;
+	uint64_t context;
+	uint32_t syncpt;
+};
+
+struct drm_tegra_fence {
+	struct drm_tegra *drm;
+	uint32_t syncpt;
+	uint32_t value;
+};
+
+struct drm_tegra_pushbuf_private {
+	struct drm_tegra_pushbuf base;
+	struct drm_tegra_job *job;
+	struct drm_tegra_bo *bo;
+	unsigned long offset;
+	drmMMListHead list;
+	uint32_t *start;
+};
+
+static inline struct drm_tegra_pushbuf_private *
+pushbuf_priv(struct drm_tegra_pushbuf *pb)
+{
+	return container_of(pb, struct drm_tegra_pushbuf_private, base);
+}
+
+struct drm_tegra_job {
+	struct drm_tegra_channel *channel;
+
+	unsigned int increments;
+	uint32_t syncpt;
+
+	struct drm_tegra_reloc *relocs;
+	unsigned int num_relocs;
+
+	unsigned int num_pushbufs;
+	drmMMListHead pushbufs;
+};
+
+int drm_tegra_job_add_reloc(struct drm_tegra_job *job,
+			    const struct drm_tegra_reloc *reloc);
+
 #endif /* __DRM_TEGRA_PRIVATE_H__ */
diff --git a/tegra/pushbuf.c b/tegra/pushbuf.c
new file mode 100644
index 000000000000..93f72fd40650
--- /dev/null
+++ b/tegra/pushbuf.c
@@ -0,0 +1,137 @@
+/*
+ * Copyright © 2012, 2013 Thierry Reding
+ * Copyright © 2013 Erik Faye-Lund
+ * Copyright © 2014 NVIDIA Corporation
+ *
+ * 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 COPYRIGHT HOLDER(S) OR AUTHOR(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.
+ */
+
+#ifdef HAVE_CONFIG_H
+#  include "config.h"
+#endif
+
+#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "private.h"
+
+#define HOST1X_OPCODE_NONINCR(offset, count) \
+    ((0x2 << 28) | (((offset) & 0xfff) << 16) | ((count) & 0xffff))
+
+static inline unsigned long
+drm_tegra_pushbuf_get_offset(struct drm_tegra_pushbuf *pushbuf)
+{
+	struct drm_tegra_pushbuf_private *priv = pushbuf_priv(pushbuf);
+	struct drm_tegra_bo *bo = priv->bo;
+
+	return (unsigned long)pushbuf->ptr - (unsigned long)bo->map;
+}
+
+drm_public
+int drm_tegra_pushbuf_new(struct drm_tegra_pushbuf **pushbufp,
+			  struct drm_tegra_job *job,
+			  struct drm_tegra_bo *bo,
+			  unsigned long offset)
+{
+	struct drm_tegra_pushbuf_private *pushbuf;
+	void *ptr;
+	int err;
+
+	pushbuf = calloc(1, sizeof(*pushbuf));
+	if (!pushbuf)
+		return -ENOMEM;
+
+	pushbuf->bo = drm_tegra_bo_get(bo);
+	DRMINITLISTHEAD(&pushbuf->list);
+	pushbuf->job = job;
+
+	err = drm_tegra_bo_map(bo, &ptr);
+	if (err < 0) {
+		drm_tegra_bo_put(bo);
+		free(pushbuf);
+		return err;
+	}
+
+	pushbuf->start = pushbuf->base.ptr = ptr + offset;
+	pushbuf->offset = offset;
+
+	DRMLISTADD(&pushbuf->list, &job->pushbufs);
+	job->num_pushbufs++;
+
+	*pushbufp = &pushbuf->base;
+
+	return 0;
+}
+
+drm_public
+int drm_tegra_pushbuf_free(struct drm_tegra_pushbuf *pushbuf)
+{
+	struct drm_tegra_pushbuf_private *priv = pushbuf_priv(pushbuf);
+
+	if (!pushbuf)
+		return -EINVAL;
+
+	drm_tegra_bo_unmap(priv->bo);
+	drm_tegra_bo_put(priv->bo);
+	DRMLISTDEL(&priv->list);
+	free(priv);
+
+	return 0;
+}
+
+drm_public
+int drm_tegra_pushbuf_relocate(struct drm_tegra_pushbuf *pushbuf,
+			       struct drm_tegra_bo *target,
+			       unsigned long offset,
+			       unsigned long shift)
+{
+	struct drm_tegra_pushbuf_private *priv = pushbuf_priv(pushbuf);
+	struct drm_tegra_reloc reloc;
+	int err;
+
+	memset(&reloc, 0, sizeof(reloc));
+	reloc.cmdbuf.handle = priv->bo->handle;
+	reloc.cmdbuf.offset = drm_tegra_pushbuf_get_offset(pushbuf);
+	reloc.target.handle = target->handle;
+	reloc.target.offset = offset;
+	reloc.shift = shift;
+
+	err = drm_tegra_job_add_reloc(priv->job, &reloc);
+	if (err < 0)
+		return err;
+
+	return 0;
+}
+
+drm_public
+int drm_tegra_pushbuf_sync(struct drm_tegra_pushbuf *pushbuf,
+			   enum drm_tegra_syncpt_cond cond)
+{
+	struct drm_tegra_pushbuf_private *priv = pushbuf_priv(pushbuf);
+
+	if (cond >= DRM_TEGRA_SYNCPT_COND_MAX)
+		return -EINVAL;
+
+	*pushbuf->ptr++ = HOST1X_OPCODE_NONINCR(0x0, 0x1);
+	*pushbuf->ptr++ = cond << 8 | priv->job->syncpt;
+	priv->job->increments++;
+
+	return 0;
+}
diff --git a/tegra/tegra.h b/tegra/tegra.h
index 0731cb3bd4dc..ca0ade1bddad 100644
--- a/tegra/tegra.h
+++ b/tegra/tegra.h
@@ -28,6 +28,13 @@
 #include <stdint.h>
 #include <stdlib.h>
 
+#include <tegra_drm.h>
+
+enum drm_tegra_class {
+	DRM_TEGRA_GR2D,
+	DRM_TEGRA_GR3D,
+};
+
 struct drm_tegra_bo;
 struct drm_tegra;
 
@@ -44,4 +51,49 @@ int drm_tegra_bo_get_handle(struct drm_tegra_bo *bo, uint32_t *handle);
 int drm_tegra_bo_map(struct drm_tegra_bo *bo, void **ptr);
 int drm_tegra_bo_unmap(struct drm_tegra_bo *bo);
 
+struct drm_tegra_channel;
+struct drm_tegra_job;
+
+struct drm_tegra_pushbuf {
+	uint32_t *ptr;
+};
+
+struct drm_tegra_fence;
+
+enum drm_tegra_syncpt_cond {
+	DRM_TEGRA_SYNCPT_COND_IMMEDIATE,
+	DRM_TEGRA_SYNCPT_COND_OP_DONE,
+	DRM_TEGRA_SYNCPT_COND_RD_DONE,
+	DRM_TEGRA_SYNCPT_COND_WR_SAFE,
+	DRM_TEGRA_SYNCPT_COND_MAX,
+};
+
+int drm_tegra_channel_open(struct drm_tegra_channel **channelp,
+			   struct drm_tegra *drm,
+			   enum drm_tegra_class client);
+int drm_tegra_channel_close(struct drm_tegra_channel *channel);
+
+int drm_tegra_job_new(struct drm_tegra_job **jobp,
+		      struct drm_tegra_channel *channel);
+int drm_tegra_job_free(struct drm_tegra_job *job);
+int drm_tegra_job_submit(struct drm_tegra_job *job,
+			 struct drm_tegra_fence **fencep);
+
+int drm_tegra_pushbuf_new(struct drm_tegra_pushbuf **pushbufp,
+			  struct drm_tegra_job *job,
+			  struct drm_tegra_bo *bo,
+			  unsigned long offset);
+int drm_tegra_pushbuf_free(struct drm_tegra_pushbuf *pushbuf);
+int drm_tegra_pushbuf_relocate(struct drm_tegra_pushbuf *pushbuf,
+			       struct drm_tegra_bo *target,
+			       unsigned long offset,
+			       unsigned long shift);
+int drm_tegra_pushbuf_sync(struct drm_tegra_pushbuf *pushbuf,
+			   enum drm_tegra_syncpt_cond cond);
+
+int drm_tegra_fence_wait_timeout(struct drm_tegra_fence *fence,
+				 unsigned long timeout);
+int drm_tegra_fence_wait(struct drm_tegra_fence *fence);
+void drm_tegra_fence_free(struct drm_tegra_fence *fence);
+
 #endif /* __DRM_TEGRA_H__ */
-- 
1.8.4.2

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [RFC libdrm 5/6] tegra: Add helper library for tests
  2014-02-19 16:04 [RFC libdrm 0/6] Add NVIDIA Tegra support Thierry Reding
                   ` (3 preceding siblings ...)
  2014-02-19 16:04 ` [RFC libdrm 4/6] tegra: Add channel, job, pushbuf and fence APIs Thierry Reding
@ 2014-02-19 16:04 ` Thierry Reding
  2014-02-19 20:54   ` Erik Faye-Lund
  2014-02-19 16:04 ` [RFC libdrm 6/6] tegra: Add gr2d-fill test Thierry Reding
  2014-03-20 15:23 ` [RFC libdrm 0/6] Add NVIDIA Tegra support Erik Faye-Lund
  6 siblings, 1 reply; 24+ messages in thread
From: Thierry Reding @ 2014-02-19 16:04 UTC (permalink / raw)
  To: dri-devel

From: Thierry Reding <treding@nvidia.com>

This library provides helpers for common functionality needed by test
programs.

Signed-off-by: Thierry Reding <treding@nvidia.com>
---
 tests/tegra/Makefile.am      |  10 +-
 tests/tegra/drm-test-tegra.c | 132 ++++++++++++++++++++++
 tests/tegra/drm-test-tegra.h |  55 +++++++++
 tests/tegra/drm-test.c       | 261 +++++++++++++++++++++++++++++++++++++++++++
 tests/tegra/drm-test.h       |  73 ++++++++++++
 5 files changed, 530 insertions(+), 1 deletion(-)
 create mode 100644 tests/tegra/drm-test-tegra.c
 create mode 100644 tests/tegra/drm-test-tegra.h
 create mode 100644 tests/tegra/drm-test.c
 create mode 100644 tests/tegra/drm-test.h

diff --git a/tests/tegra/Makefile.am b/tests/tegra/Makefile.am
index 7039f09d38aa..90b11b278a42 100644
--- a/tests/tegra/Makefile.am
+++ b/tests/tegra/Makefile.am
@@ -4,8 +4,16 @@ AM_CPPFLAGS = \
 
 AM_CFLAGS = -Wall -Werror
 
+noinst_LTLIBRARIES = libdrm-test.la
+libdrm_test_la_SOURCES = \
+	drm-test.c \
+	drm-test.h \
+	drm-test-tegra.c \
+	drm-test-tegra.h
+
 LDADD = \
-	../../tegra/libdrm_tegra.la
+	../../tegra/libdrm_tegra.la \
+	libdrm-test.la
 
 TESTS = \
 	openclose \
diff --git a/tests/tegra/drm-test-tegra.c b/tests/tegra/drm-test-tegra.c
new file mode 100644
index 000000000000..69605b9595b6
--- /dev/null
+++ b/tests/tegra/drm-test-tegra.c
@@ -0,0 +1,132 @@
+/*
+ * Copyright © 2014 NVIDIA Corporation
+ *
+ * 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 COPYRIGHT HOLDER(S) OR AUTHOR(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.
+ */
+
+#ifdef HAVE_CONFIG_H
+#  include "config.h"
+#endif
+
+#include <errno.h>
+#include <stdio.h>
+
+#include "drm-test-tegra.h"
+#include "tegra.h"
+
+int drm_tegra_gr2d_open(struct drm_tegra_gr2d **gr2dp, struct drm_tegra *drm)
+{
+	struct drm_tegra_gr2d *gr2d;
+	int err;
+
+	gr2d = calloc(1, sizeof(*gr2d));
+	if (!gr2d)
+		return -ENOMEM;
+
+	gr2d->drm = drm;
+
+	err = drm_tegra_channel_open(&gr2d->channel, drm, DRM_TEGRA_GR2D);
+	if (err < 0) {
+		free(gr2d);
+		return err;
+	}
+
+	*gr2dp = gr2d;
+
+	return 0;
+}
+
+int drm_tegra_gr2d_close(struct drm_tegra_gr2d *gr2d)
+{
+	if (!gr2d)
+		return -EINVAL;
+
+	drm_tegra_channel_close(gr2d->channel);
+	free(gr2d);
+
+	return 0;
+}
+
+int drm_tegra_gr2d_fill(struct drm_tegra_gr2d *gr2d, struct drm_framebuffer *fb,
+			unsigned int x, unsigned int y, unsigned int width,
+			unsigned int height, uint32_t color)
+{
+	struct drm_tegra_bo *fbo = fb->data;
+	struct drm_tegra_pushbuf *pushbuf;
+	struct drm_tegra_fence *fence;
+	struct drm_tegra_job *job;
+	struct drm_tegra_bo *bo;
+	int err;
+
+	err = drm_tegra_job_new(&job, gr2d->channel);
+	if (err < 0)
+		return err;
+
+	err = drm_tegra_bo_new(&bo, gr2d->drm, 0, 4096);
+	if (err < 0)
+		return err;
+
+	err = drm_tegra_pushbuf_new(&pushbuf, job, bo, 0);
+	if (err < 0)
+		return err;
+
+	*pushbuf->ptr++ = HOST1X_OPCODE_SETCL(0, HOST1X_CLASS_GR2D, 0);
+
+	*pushbuf->ptr++ = HOST1X_OPCODE_MASK(0x9, 0x9);
+	*pushbuf->ptr++ = 0x0000003a;
+	*pushbuf->ptr++ = 0x00000000;
+
+	*pushbuf->ptr++ = HOST1X_OPCODE_MASK(0x1e, 0x7);
+	*pushbuf->ptr++ = 0x00000000;
+	*pushbuf->ptr++ = (2 << 16) | (1 << 6) | (1 << 2);
+	*pushbuf->ptr++ = 0x000000cc;
+
+	*pushbuf->ptr++ = HOST1X_OPCODE_MASK(0x2b, 0x9);
+	drm_tegra_pushbuf_relocate(pushbuf, fbo, 0, 0);
+	*pushbuf->ptr++ = 0xdeadbeef;
+	*pushbuf->ptr++ = fb->pitch;
+
+	*pushbuf->ptr++ = HOST1X_OPCODE_NONINCR(0x35, 1);
+	*pushbuf->ptr++ = color;
+
+	*pushbuf->ptr++ = HOST1X_OPCODE_NONINCR(0x46, 1);
+	*pushbuf->ptr++ = 0x00000000;
+
+	*pushbuf->ptr++ = HOST1X_OPCODE_MASK(0x38, 0x5);
+	*pushbuf->ptr++ = height << 16 | width;
+	*pushbuf->ptr++ = y << 16 | x;
+
+	err = drm_tegra_job_submit(job, &fence);
+	if (err < 0) {
+		fprintf(stderr, "failed to submit job: %d\n", err);
+		return err;
+	}
+
+	err = drm_tegra_fence_wait(fence);
+	if (err < 0) {
+		fprintf(stderr, "failed to wait for fence: %d\n", err);
+		return err;
+	}
+
+	drm_tegra_pushbuf_free(pushbuf);
+	drm_tegra_bo_put(bo);
+	drm_tegra_job_free(job);
+
+	return 0;
+}
diff --git a/tests/tegra/drm-test-tegra.h b/tests/tegra/drm-test-tegra.h
new file mode 100644
index 000000000000..d1cb6b1ee440
--- /dev/null
+++ b/tests/tegra/drm-test-tegra.h
@@ -0,0 +1,55 @@
+/*
+ * Copyright © 2014 NVIDIA Corporation
+ *
+ * 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 COPYRIGHT HOLDER(S) OR AUTHOR(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 TEGRA_DRM_TEST_TEGRA_H
+#define TEGRA_DRM_TEST_TEGRA_H
+
+#include "drm-test.h"
+#include "tegra.h"
+
+#define HOST1X_OPCODE_SETCL(offset, classid, mask) \
+    ((0x0 << 28) | (((offset) & 0xfff) << 16) | (((classid) & 0x3ff) << 6) | ((mask) & 0x3f))
+#define HOST1X_OPCODE_INCR(offset, count) \
+    ((0x1 << 28) | (((offset) & 0xfff) << 16) | ((count) & 0xffff))
+#define HOST1X_OPCODE_NONINCR(offset, count) \
+    ((0x2 << 28) | (((offset) & 0xfff) << 16) | ((count) & 0xffff))
+#define HOST1X_OPCODE_MASK(offset, mask) \
+    ((0x3 << 28) | (((offset) & 0xfff) << 16) | ((mask) & 0xffff))
+#define HOST1X_OPCODE_IMM(offset, data) \
+    ((0x4 << 28) | (((offset) & 0xfff) << 16) | ((data) & 0xffff))
+#define HOST1X_OPCODE_EXTEND(subop, value) \
+    ((0xe << 28) | (((subop) & 0xf) << 24) | ((value) & 0xffffff))
+
+#define HOST1X_CLASS_GR2D 0x51
+
+struct drm_tegra_gr2d {
+	struct drm_tegra *drm;
+	struct drm_tegra_channel *channel;
+};
+
+int drm_tegra_gr2d_open(struct drm_tegra_gr2d **gr2dp, struct drm_tegra *drm);
+int drm_tegra_gr2d_close(struct drm_tegra_gr2d *gr2d);
+int drm_tegra_gr2d_fill(struct drm_tegra_gr2d *gr2d, struct drm_framebuffer *fb,
+			unsigned int x, unsigned int y, unsigned int width,
+			unsigned int height, uint32_t color);
+
+#endif
diff --git a/tests/tegra/drm-test.c b/tests/tegra/drm-test.c
new file mode 100644
index 000000000000..8cfacf466494
--- /dev/null
+++ b/tests/tegra/drm-test.c
@@ -0,0 +1,261 @@
+/*
+ * Copyright © 2014 NVIDIA Corporation
+ *
+ * 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 COPYRIGHT HOLDER(S) OR AUTHOR(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.
+ */
+
+#ifdef HAVE_CONFIG_H
+#  include "config.h"
+#endif
+
+#include <errno.h>
+#include <fcntl.h>
+#include <stdbool.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include <sys/ioctl.h>
+
+#include "xf86drm.h"
+#include "xf86drmMode.h"
+#include "drm_fourcc.h"
+
+#include "drm-test.h"
+
+static int drm_screen_probe_connector(struct drm_screen *screen,
+				      drmModeConnectorPtr connector)
+{
+	drmModeEncoderPtr encoder;
+	drmModeCrtcPtr crtc;
+	drmModeFBPtr fb;
+
+	encoder = drmModeGetEncoder(screen->fd, connector->encoder_id);
+	if (!encoder)
+		return -ENODEV;
+
+	crtc = drmModeGetCrtc(screen->fd, encoder->crtc_id);
+	if (!crtc) {
+		drmModeFreeEncoder(encoder);
+		return -ENODEV;
+	}
+
+	screen->old_fb = crtc->buffer_id;
+
+	fb = drmModeGetFB(screen->fd, crtc->buffer_id);
+	if (!fb) {
+		/* TODO: create new framebuffer */
+		drmModeFreeEncoder(encoder);
+		drmModeFreeCrtc(crtc);
+		return -ENOSYS;
+	}
+
+	screen->connector = connector->connector_id;
+	screen->old_fb = crtc->buffer_id;
+	screen->crtc = encoder->crtc_id;
+	/* TODO: check crtc->mode_valid */
+	screen->mode = crtc->mode;
+
+	screen->width = fb->width;
+	screen->height = fb->height;
+	screen->pitch = fb->pitch;
+	screen->depth = fb->depth;
+	screen->bpp = fb->bpp;
+
+	drmModeFreeEncoder(encoder);
+	drmModeFreeCrtc(crtc);
+	drmModeFreeFB(fb);
+
+	return 0;
+}
+
+int drm_screen_open(struct drm_screen **screenp, int fd)
+{
+	drmModeConnectorPtr connector;
+	struct drm_screen *screen;
+	bool found = false;
+	drmModeResPtr res;
+	unsigned int i;
+	int err;
+
+	if (!screenp || fd < 0)
+		return -EINVAL;
+
+	screen = calloc(1, sizeof(*screen));
+	if (!screen)
+		return -ENOMEM;
+
+	screen->format = DRM_FORMAT_XRGB8888;
+	screen->fd = fd;
+
+	res = drmModeGetResources(fd);
+	if (!res) {
+		free(screen);
+		return -ENOMEM;
+	}
+
+	for (i = 0; i < res->count_connectors; i++) {
+		connector = drmModeGetConnector(fd, res->connectors[i]);
+		if (!connector)
+			continue;
+
+		if (connector->connection != DRM_MODE_CONNECTED) {
+			drmModeFreeConnector(connector);
+			continue;
+		}
+
+		err = drm_screen_probe_connector(screen, connector);
+		if (err < 0) {
+			drmModeFreeConnector(connector);
+			continue;
+		}
+
+		found = true;
+		break;
+	}
+
+	drmModeFreeResources(res);
+
+	if (!found) {
+		free(screen);
+		return -ENODEV;
+	}
+
+	*screenp = screen;
+
+	return 0;
+}
+
+int drm_screen_close(struct drm_screen *screen)
+{
+	struct drm_gem_close args;
+	int err;
+
+	err = drmModeSetCrtc(screen->fd, screen->crtc, screen->old_fb, 0, 0,
+			     &screen->connector, 1, &screen->mode);
+	if (err < 0) {
+		fprintf(stderr, "drmModeSetCrtc() failed: %m\n");
+		return -errno;
+	}
+
+	err = drmModeRmFB(screen->fd, screen->fb);
+	if (err < 0) {
+		fprintf(stderr, "drmModeRmFB() failed: %m\n");
+		return -errno;
+	}
+
+	memset(&args, 0, sizeof(args));
+	args.handle = screen->handle;
+
+	err = ioctl(screen->fd, DRM_IOCTL_GEM_CLOSE, &args);
+	if (err < 0) {
+		fprintf(stderr, "ioctl(DRM_IOCTL_GEM_CLOSE) failed: %m\n");
+		return -errno;
+	}
+
+	return 0;
+}
+
+int drm_framebuffer_new(struct drm_framebuffer **fbp,
+			struct drm_screen *screen, uint32_t handle,
+			unsigned int width, unsigned int height,
+			unsigned int pitch, uint32_t format,
+			void *data)
+{
+	struct drm_framebuffer *fb;
+	uint32_t handles[4];
+	uint32_t pitches[4];
+	uint32_t offsets[4];
+	int err;
+
+	fb = calloc(1, sizeof(*fb));
+	if (!fb)
+		return -ENOMEM;
+
+	fb->fd = screen->fd;
+	fb->width = width;
+	fb->height = height;
+	fb->pitch = pitch;
+	fb->format = format;
+	fb->data = data;
+
+	handles[0] = handle;
+	pitches[0] = pitch;
+	offsets[0] = 0;
+
+	err = drmModeAddFB2(screen->fd, width, height, format, handles,
+			    pitches, offsets, &fb->handle, 0);
+	if (err < 0)
+		return -errno;
+
+	*fbp = fb;
+
+	return 0;
+}
+
+int drm_framebuffer_free(struct drm_framebuffer *fb)
+{
+	int err;
+
+	err = drmModeRmFB(fb->fd, fb->handle);
+	if (err < 0)
+		return -errno;
+
+	free(fb);
+
+	return 0;
+}
+
+int drm_screen_set_framebuffer(struct drm_screen *screen,
+			       struct drm_framebuffer *fb)
+{
+	int err;
+
+	err = drmModeSetCrtc(screen->fd, screen->crtc, fb->handle, 0, 0,
+			     &screen->connector, 1, &screen->mode);
+	if (err < 0)
+		return -errno;
+
+	return 0;
+}
+
+int drm_open(const char *path)
+{
+	int fd, err;
+
+	fd = open(path, O_RDWR);
+	if (fd < 0)
+		return -errno;
+
+	err = drmSetMaster(fd);
+	if (err < 0) {
+		close(fd);
+		return -errno;
+	}
+
+	return fd;
+}
+
+void drm_close(int fd)
+{
+	drmDropMaster(fd);
+	close(fd);
+}
diff --git a/tests/tegra/drm-test.h b/tests/tegra/drm-test.h
new file mode 100644
index 000000000000..ebdd255509dd
--- /dev/null
+++ b/tests/tegra/drm-test.h
@@ -0,0 +1,73 @@
+/*
+ * Copyright © 2014 NVIDIA Corporation
+ *
+ * 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 COPYRIGHT HOLDER(S) OR AUTHOR(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 TEGRA_DRM_TEST_H
+#define TEGRA_DRM_TEST_H
+
+#include <stdint.h>
+#include <stdlib.h>
+
+#include "xf86drmMode.h"
+
+struct drm_screen {
+	int fd;
+
+	unsigned int width;
+	unsigned int height;
+	unsigned int pitch;
+	unsigned int depth;
+	unsigned int bpp;
+
+	drmModeModeInfo mode;
+	uint32_t fb, old_fb;
+	uint32_t connector;
+	uint32_t format;
+	uint32_t handle;
+	uint32_t crtc;
+};
+
+struct drm_framebuffer {
+	unsigned int width;
+	unsigned int height;
+	unsigned int pitch;
+	uint32_t format;
+	uint32_t handle;
+	void *data;
+	int fd;
+};
+
+int drm_screen_open(struct drm_screen **screenp, int fd);
+int drm_screen_close(struct drm_screen *screen);
+int drm_screen_set_framebuffer(struct drm_screen *screen,
+			       struct drm_framebuffer *fb);
+
+int drm_framebuffer_new(struct drm_framebuffer **fbp,
+			struct drm_screen *screen, uint32_t handle,
+			unsigned int width, unsigned int height,
+			unsigned int pitch, uint32_t format,
+			void *data);
+int drm_framebuffer_free(struct drm_framebuffer *fb);
+
+int drm_open(const char *path);
+void drm_close(int fd);
+
+#endif
-- 
1.8.4.2

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [RFC libdrm 6/6] tegra: Add gr2d-fill test
  2014-02-19 16:04 [RFC libdrm 0/6] Add NVIDIA Tegra support Thierry Reding
                   ` (4 preceding siblings ...)
  2014-02-19 16:04 ` [RFC libdrm 5/6] tegra: Add helper library for tests Thierry Reding
@ 2014-02-19 16:04 ` Thierry Reding
  2014-02-19 21:03   ` Erik Faye-Lund
  2014-03-20 15:23 ` [RFC libdrm 0/6] Add NVIDIA Tegra support Erik Faye-Lund
  6 siblings, 1 reply; 24+ messages in thread
From: Thierry Reding @ 2014-02-19 16:04 UTC (permalink / raw)
  To: dri-devel

From: Thierry Reding <treding@nvidia.com>

This test uses the IOCTLs for job submission and fences to fill a sub-
region of the screen to a specific color using gr2d.

Signed-off-by: Thierry Reding <treding@nvidia.com>
---
 tests/tegra/Makefile.am |   1 +
 tests/tegra/gr2d-fill.c | 145 ++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 146 insertions(+)
 create mode 100644 tests/tegra/gr2d-fill.c

diff --git a/tests/tegra/Makefile.am b/tests/tegra/Makefile.am
index 90b11b278a42..9e9e75e91ad4 100644
--- a/tests/tegra/Makefile.am
+++ b/tests/tegra/Makefile.am
@@ -17,6 +17,7 @@ LDADD = \
 
 TESTS = \
 	openclose \
+	gr2d-fill
 
 if HAVE_INSTALL_TESTS
 testdir = $(libexecdir)/libdrm/tests/tegra
diff --git a/tests/tegra/gr2d-fill.c b/tests/tegra/gr2d-fill.c
new file mode 100644
index 000000000000..7ffe6f0b0848
--- /dev/null
+++ b/tests/tegra/gr2d-fill.c
@@ -0,0 +1,145 @@
+/*
+ * Copyright © 2014 NVIDIA Corporation
+ *
+ * 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 COPYRIGHT HOLDER(S) OR AUTHOR(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.
+ */
+
+#ifdef HAVE_CONFIG_H
+#  include "config.h"
+#endif
+
+#include <errno.h>
+#include <fcntl.h>
+#include <stdbool.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include <sys/ioctl.h>
+
+#include "xf86drm.h"
+#include "xf86drmMode.h"
+#include "drm_fourcc.h"
+
+#include "drm-test-tegra.h"
+#include "tegra.h"
+
+int main(int argc, char *argv[])
+{
+	uint32_t format = DRM_FORMAT_XRGB8888;
+	struct drm_tegra_gr2d *gr2d;
+	struct drm_framebuffer *fb;
+	struct drm_screen *screen;
+	unsigned int pitch, size;
+	struct drm_tegra_bo *bo;
+	struct drm_tegra *drm;
+	uint32_t handle;
+	int fd, err;
+	void *ptr;
+
+	fd = drm_open(argv[1]);
+	if (fd < 0) {
+		fprintf(stderr, "failed to open DRM device %s: %s\n", argv[1],
+			strerror(errno));
+		return 1;
+	}
+
+	err = drm_screen_open(&screen, fd);
+	if (err < 0) {
+		fprintf(stderr, "failed to open screen: %s\n", strerror(-err));
+		return 1;
+	}
+
+	err = drm_tegra_new(&drm, fd);
+	if (err < 0) {
+		fprintf(stderr, "failed to create Tegra DRM context: %s\n",
+			strerror(-err));
+		return 1;
+	}
+
+	err = drm_tegra_gr2d_open(&gr2d, drm);
+	if (err < 0) {
+		fprintf(stderr, "failed to open gr2d channel: %s\n",
+			strerror(-err));
+		return 1;
+	}
+
+	pitch = screen->width * screen->bpp / 8;
+	size = pitch * screen->height;
+
+	err = drm_tegra_bo_new(&bo, drm, 0, size);
+	if (err < 0) {
+		fprintf(stderr, "failed to create buffer object: %s\n",
+			strerror(-err));
+		return 1;
+	}
+
+	err = drm_tegra_bo_get_handle(bo, &handle);
+	if (err < 0) {
+		fprintf(stderr, "failed to get handle to buffer object: %s\n",
+			strerror(-err));
+		return 1;
+	}
+
+	err = drm_tegra_bo_map(bo, &ptr);
+	if (err < 0) {
+		fprintf(stderr, "failed to map buffer object: %s\n",
+			strerror(-err));
+		return 1;
+	}
+
+	memset(ptr, 0xff, size);
+
+	err = drm_framebuffer_new(&fb, screen, handle, screen->width,
+				  screen->height, pitch, format, bo);
+	if (err < 0) {
+		fprintf(stderr, "failed to create framebuffer: %s\n",
+			strerror(-err));
+		return 1;
+	}
+
+	err = drm_screen_set_framebuffer(screen, fb);
+	if (err < 0) {
+		fprintf(stderr, "failed to display framebuffer: %s\n",
+			strerror(-err));
+		return 1;
+	}
+
+	sleep(1);
+
+	err = drm_tegra_gr2d_fill(gr2d, fb, fb->width / 4, fb->height / 4,
+				  fb->width / 2, fb->height / 2, 0x00000000);
+	if (err < 0) {
+		fprintf(stderr, "failed to fill rectangle: %s\n",
+			strerror(-err));
+		return 1;
+	}
+
+	sleep(1);
+
+	drm_tegra_bo_put(bo);
+	drm_tegra_gr2d_close(gr2d);
+	drm_tegra_close(drm);
+	drm_screen_close(screen);
+	drm_close(fd);
+
+	return 0;
+}
-- 
1.8.4.2

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply related	[flat|nested] 24+ messages in thread

* Re: [RFC libdrm 4/6] tegra: Add channel, job, pushbuf and fence APIs
  2014-02-19 16:04 ` [RFC libdrm 4/6] tegra: Add channel, job, pushbuf and fence APIs Thierry Reding
@ 2014-02-19 19:57   ` Erik Faye-Lund
  2014-02-19 21:11     ` Thierry Reding
  0 siblings, 1 reply; 24+ messages in thread
From: Erik Faye-Lund @ 2014-02-19 19:57 UTC (permalink / raw)
  To: Thierry Reding; +Cc: dri-devel

On Wed, Feb 19, 2014 at 5:04 PM, Thierry Reding
<thierry.reding@gmail.com> wrote:
> From: Thierry Reding <treding@nvidia.com>
>
> These functions can be used to open channels to engines, manage job
> submissions, create push buffers to store command streams in and wait
> until jobs have been completed.
>
> Signed-off-by: Thierry Reding <treding@nvidia.com>

Thanks a lot for doing this! I'm going right for the juicy patch ;)

> +drm_public
> +int drm_tegra_fence_wait_timeout(struct drm_tegra_fence *fence,
> +                                unsigned long timeout)
> +{
> +       struct drm_tegra_syncpt_wait args;
> +       int err;
> +
> +       memset(&args, 0, sizeof(args));

Nit: how about

struct drm_tegra_syncpt_wait args = { 0 };

instead?

> +       args.id = fence->syncpt;
> +       args.thresh = fence->value;
> +       args.timeout = timeout;
> +
> +       while (true) {
> +               err = ioctl(fence->drm->fd, DRM_IOCTL_TEGRA_SYNCPT_WAIT, &args);
> +               if (err < 0) {
> +                       if (errno == EINTR)
> +                               continue;
> +
> +                       drmMsg("DRM_IOCTL_TEGRA_SYNCPT_WAIT: %d\n", -errno);

What's the reason for printing the errno negated? And could we do
'...%s\n" strerror(errno));' instead?

> +int drm_tegra_job_add_reloc(struct drm_tegra_job *job,
> +                           const struct drm_tegra_reloc *reloc)
> +{
> +       struct drm_tegra_reloc *relocs;
> +       size_t size;
> +
> +       size = (job->num_relocs + 1) * sizeof(*reloc);
> +
> +       relocs = realloc(job->relocs, size);

Nit: there's no point in not assigning those while declaring them, no?

size_t size = (job->num_relocs + 1) * sizeof(*reloc);
struct drm_tegra_reloc *relocs; = realloc(job->relocs, size);

> +drm_public
> +int drm_tegra_pushbuf_new(struct drm_tegra_pushbuf **pushbufp,
> +                         struct drm_tegra_job *job,
> +                         struct drm_tegra_bo *bo,
> +                         unsigned long offset)
> +{
> +       struct drm_tegra_pushbuf_private *pushbuf;
> +       void *ptr;
> +       int err;
> +
> +       pushbuf = calloc(1, sizeof(*pushbuf));
> +       if (!pushbuf)
> +               return -ENOMEM;
> +
> +       pushbuf->bo = drm_tegra_bo_get(bo);
> +       DRMINITLISTHEAD(&pushbuf->list);
> +       pushbuf->job = job;
> +
> +       err = drm_tegra_bo_map(bo, &ptr);
> +       if (err < 0) {
> +               drm_tegra_bo_put(bo);
> +               free(pushbuf);
> +               return err;
> +       }
> +
> +       pushbuf->start = pushbuf->base.ptr = ptr + offset;
> +       pushbuf->offset = offset;
> +
> +       DRMLISTADD(&pushbuf->list, &job->pushbufs);
> +       job->num_pushbufs++;
> +
> +       *pushbufp = &pushbuf->base;
> +
> +       return 0;
> +}

It feels quite wasteful to me to have to allocate a new pushbuf in
order to be able to use a new BO. I'd much rather see the pushbuf
being a persisting object that's the interface to the command-stream
(that produces jobs).

I was thinking something like:

int drm_tegra_pushbuf_new(struct drm_tegra_pushbuf **pushbufp, struct
drm_tegra_job *job)
int drm_tegra_pushbuf_room(struct drm_tegra_pushbuf *pushbuf, int num_words);

Where room guarantees that there's space for those words in the
pushbuf. A simple implementation could just allocate a bo of that
size, but a slightly more sophisticated one can allocate larger ones
and reuse them. Even more sophisticated ones could keep old cmdbufs
around and reuse them once the hardware is done reading them, do
exponential grow-factors etc.

I've implemented the "slightly more sophisticated" approach here:

https://github.com/grate-driver/libdrm/commit/f90ea2f57ca4d8c81768402900c663ce526bac11

In my implementation, I've changed the job-structure to build the list
of cmdbufs directly rather than keeping a list of the pushbufs. Sure,
that means another allocation every time we need a new cmdbuf, but
hopefully we should be able to produce much less of them this way.

> +int drm_tegra_pushbuf_relocate(struct drm_tegra_pushbuf *pushbuf,
> +                              struct drm_tegra_bo *target,
> +                              unsigned long offset,
> +                              unsigned long shift)
> +{
> +       struct drm_tegra_pushbuf_private *priv = pushbuf_priv(pushbuf);
> +       struct drm_tegra_reloc reloc;
> +       int err;
> +
> +       memset(&reloc, 0, sizeof(reloc));
> +       reloc.cmdbuf.handle = priv->bo->handle;
> +       reloc.cmdbuf.offset = drm_tegra_pushbuf_get_offset(pushbuf);
> +       reloc.target.handle = target->handle;
> +       reloc.target.offset = offset;
> +       reloc.shift = shift;
> +
> +       err = drm_tegra_job_add_reloc(priv->job, &reloc);
> +       if (err < 0)
> +               return err;
> +
> +       return 0;
> +}

Whenever we insert a reloc, we also insert a DEADBEEF in the command
stream. Why not formalize this into this function?

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [RFC libdrm 2/6] libdrm: Add NVIDIA Tegra support
  2014-02-19 16:04 ` [RFC libdrm 2/6] libdrm: Add NVIDIA Tegra support Thierry Reding
@ 2014-02-19 19:59   ` Rémi Cardona
  2014-02-19 20:03   ` Erik Faye-Lund
  2014-02-19 20:13   ` Erik Faye-Lund
  2 siblings, 0 replies; 24+ messages in thread
From: Rémi Cardona @ 2014-02-19 19:59 UTC (permalink / raw)
  To: dri-devel

Le mercredi 19 février 2014 à 17:04 +0100, Thierry Reding a écrit :
> --- /dev/null
> +++ b/include/drm/tegra_drm.h
> @@ -0,0 +1,157 @@
> +/*
> + * Copyright (c) 2012-2013, NVIDIA CORPORATION.  All rights reserved.
                               ^^^^^^
[...]
> + * 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
                        ^^^^^^^^^^^^^^^^^

So whose code is this? Wouldn't it be better to say "the above copyright
owners" instead?

Other than that, I have no valuable review to offer.

Cheers,

Rémi

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [RFC libdrm 2/6] libdrm: Add NVIDIA Tegra support
  2014-02-19 16:04 ` [RFC libdrm 2/6] libdrm: Add NVIDIA Tegra support Thierry Reding
  2014-02-19 19:59   ` Rémi Cardona
@ 2014-02-19 20:03   ` Erik Faye-Lund
  2014-02-19 21:33     ` Thierry Reding
  2014-02-19 20:13   ` Erik Faye-Lund
  2 siblings, 1 reply; 24+ messages in thread
From: Erik Faye-Lund @ 2014-02-19 20:03 UTC (permalink / raw)
  To: Thierry Reding; +Cc: dri-devel

On Wed, Feb 19, 2014 at 5:04 PM, Thierry Reding
<thierry.reding@gmail.com> wrote:
> +#ifndef __DRM_TEGRA_PRIVATE_H__
> +#define __DRM_TEGRA_PRIVATE_H__ 1
> +
> +#include <stdbool.h>
> +#include <stdint.h>
> +
> +#include <xf86atomic.h>
> +
> +#include "tegra.h"
> +
> +#if defined(HAVE_VISIBILITY)
> +#  define drm_private __attribute__((visibility("hidden")))
> +#  define drm_public __attribute__((visibility("default")))
> +#else
> +#  define drm_private
> +#  define drm_public
> +#endif
> +

Perhaps you could put this where it's visible to other drivers as
well, like xf86drm.h?

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [RFC libdrm 2/6] libdrm: Add NVIDIA Tegra support
  2014-02-19 16:04 ` [RFC libdrm 2/6] libdrm: Add NVIDIA Tegra support Thierry Reding
  2014-02-19 19:59   ` Rémi Cardona
  2014-02-19 20:03   ` Erik Faye-Lund
@ 2014-02-19 20:13   ` Erik Faye-Lund
  2014-02-19 21:32     ` Thierry Reding
  2 siblings, 1 reply; 24+ messages in thread
From: Erik Faye-Lund @ 2014-02-19 20:13 UTC (permalink / raw)
  To: Thierry Reding; +Cc: dri-devel

On Wed, Feb 19, 2014 at 5:04 PM, Thierry Reding
<thierry.reding@gmail.com> wrote:
> diff --git a/tegra/Makefile.am b/tegra/Makefile.am
> new file mode 100644
> index 000000000000..1b83145b120d
> --- /dev/null
> +++ b/tegra/Makefile.am
> @@ -0,0 +1,20 @@
> +AM_CPPFLAGS = \
> +       -I$(top_srcdir) \
> +       -I$(top_srcdir)/include/drm
> +
> +AM_CFLAGS = \
> +       $(VISIBILITY_CFLAGS)
> +
> +libdrm_tegra_ladir = $(libdir)
> +libdrm_tegra_la_LTLIBRARIES = libdrm_tegra.la
> +libdrm_tegra_la_LDFLAGS = -version-number 0:0:0 -no-undefined
> +libdrm_tegra_la_LIBADD = ../libdrm.la @PTHREADSTUBS_LIBS@
> +
> +libdrm_tegra_la_SOURCES = \
> +       tegra.c
> +
> +libdrm_tegraincludedir = ${includedir}/libdrm
> +libdrm_tegrainclude_HEADERS = tegra.h
> +
> +pkgconfigdir = @pkgconfigdir@
> +pkgconfig_DATA = libdrm_tegra.pc

You should probably also add libdrm_tegra.pc to .gitignore also.

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [RFC libdrm 3/6] tegra: Add simple test for drm_tegra_open()
  2014-02-19 16:04 ` [RFC libdrm 3/6] tegra: Add simple test for drm_tegra_open() Thierry Reding
@ 2014-02-19 20:19   ` Erik Faye-Lund
  2014-02-19 20:50     ` Erik Faye-Lund
  2014-02-19 21:34   ` Erik Faye-Lund
  1 sibling, 1 reply; 24+ messages in thread
From: Erik Faye-Lund @ 2014-02-19 20:19 UTC (permalink / raw)
  To: Thierry Reding; +Cc: dri-devel

On Wed, Feb 19, 2014 at 5:04 PM, Thierry Reding
<thierry.reding@gmail.com> wrote:
> diff --git a/tests/tegra/Makefile.am b/tests/tegra/Makefile.am
> new file mode 100644
> index 000000000000..7039f09d38aa
> --- /dev/null
> +++ b/tests/tegra/Makefile.am
> @@ -0,0 +1,20 @@
> +AM_CPPFLAGS = \
> +       -I$(top_srcdir)/include/drm \
> +       -I$(top_srcdir)/tegra
> +
> +AM_CFLAGS = -Wall -Werror
> +
> +LDADD = \
> +       ../../tegra/libdrm_tegra.la

You also need to add ../../libdrm.la here.

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [RFC libdrm 3/6] tegra: Add simple test for drm_tegra_open()
  2014-02-19 20:19   ` Erik Faye-Lund
@ 2014-02-19 20:50     ` Erik Faye-Lund
  0 siblings, 0 replies; 24+ messages in thread
From: Erik Faye-Lund @ 2014-02-19 20:50 UTC (permalink / raw)
  To: Thierry Reding; +Cc: dri-devel

On Wed, Feb 19, 2014 at 9:19 PM, Erik Faye-Lund <kusmabite@gmail.com> wrote:
> On Wed, Feb 19, 2014 at 5:04 PM, Thierry Reding
> <thierry.reding@gmail.com> wrote:
>> diff --git a/tests/tegra/Makefile.am b/tests/tegra/Makefile.am
>> new file mode 100644
>> index 000000000000..7039f09d38aa
>> --- /dev/null
>> +++ b/tests/tegra/Makefile.am
>> @@ -0,0 +1,20 @@
>> +AM_CPPFLAGS = \
>> +       -I$(top_srcdir)/include/drm \
>> +       -I$(top_srcdir)/tegra
>> +
>> +AM_CFLAGS = -Wall -Werror
>> +
>> +LDADD = \
>> +       ../../tegra/libdrm_tegra.la
>
> You also need to add ../../libdrm.la here.

But even so, "make check" fails without any explanation.

However, gr2d-fill also fails. But with an error: "failed to open DRM
device (null): Bad address". Judging from the source-code, it seems
they expect arguments that "make check" doesn't provide.

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [RFC libdrm 5/6] tegra: Add helper library for tests
  2014-02-19 16:04 ` [RFC libdrm 5/6] tegra: Add helper library for tests Thierry Reding
@ 2014-02-19 20:54   ` Erik Faye-Lund
  0 siblings, 0 replies; 24+ messages in thread
From: Erik Faye-Lund @ 2014-02-19 20:54 UTC (permalink / raw)
  To: Thierry Reding; +Cc: dri-devel

On Wed, Feb 19, 2014 at 5:04 PM, Thierry Reding
<thierry.reding@gmail.com> wrote:
> diff --git a/tests/tegra/drm-test-tegra.h b/tests/tegra/drm-test-tegra.h
> new file mode 100644
> index 000000000000..d1cb6b1ee440
> --- /dev/null
> +++ b/tests/tegra/drm-test-tegra.h
> +int drm_open(const char *path)
> +{
> +       int fd, err;
> +
> +       fd = open(path, O_RDWR);
> +       if (fd < 0)
> +               return -errno;
> +
> +       err = drmSetMaster(fd);

Hmmpf, do we really need modesetting for all tests? Can't tests opt-in
on that instead?

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [RFC libdrm 6/6] tegra: Add gr2d-fill test
  2014-02-19 16:04 ` [RFC libdrm 6/6] tegra: Add gr2d-fill test Thierry Reding
@ 2014-02-19 21:03   ` Erik Faye-Lund
  2014-02-19 21:49     ` Thierry Reding
  0 siblings, 1 reply; 24+ messages in thread
From: Erik Faye-Lund @ 2014-02-19 21:03 UTC (permalink / raw)
  To: Thierry Reding; +Cc: dri-devel

On Wed, Feb 19, 2014 at 5:04 PM, Thierry Reding
<thierry.reding@gmail.com> wrote:
> From: Thierry Reding <treding@nvidia.com>
>
> This test uses the IOCTLs for job submission and fences to fill a sub-
> region of the screen to a specific color using gr2d.
>
> Signed-off-by: Thierry Reding <treding@nvidia.com>
> ---
>  tests/tegra/Makefile.am |   1 +
>  tests/tegra/gr2d-fill.c | 145 ++++++++++++++++++++++++++++++++++++++++++++++++
>  2 files changed, 146 insertions(+)
>  create mode 100644 tests/tegra/gr2d-fill.c
>
> diff --git a/tests/tegra/Makefile.am b/tests/tegra/Makefile.am
> index 90b11b278a42..9e9e75e91ad4 100644
> --- a/tests/tegra/Makefile.am
> +++ b/tests/tegra/Makefile.am
> @@ -17,6 +17,7 @@ LDADD = \
>
>  TESTS = \
>         openclose \
> +       gr2d-fill
>
>  if HAVE_INSTALL_TESTS
>  testdir = $(libexecdir)/libdrm/tests/tegra
> diff --git a/tests/tegra/gr2d-fill.c b/tests/tegra/gr2d-fill.c
> new file mode 100644
> index 000000000000..7ffe6f0b0848
> --- /dev/null
> +++ b/tests/tegra/gr2d-fill.c
> @@ -0,0 +1,145 @@
> +/*
> + * Copyright © 2014 NVIDIA Corporation
> + *
> + * 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 COPYRIGHT HOLDER(S) OR AUTHOR(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.
> + */
> +
> +#ifdef HAVE_CONFIG_H
> +#  include "config.h"
> +#endif
> +
> +#include <errno.h>
> +#include <fcntl.h>
> +#include <stdbool.h>
> +#include <stdint.h>
> +#include <stdio.h>
> +#include <stdlib.h>
> +#include <string.h>
> +#include <unistd.h>
> +
> +#include <sys/ioctl.h>
> +
> +#include "xf86drm.h"
> +#include "xf86drmMode.h"
> +#include "drm_fourcc.h"
> +
> +#include "drm-test-tegra.h"
> +#include "tegra.h"
> +
> +int main(int argc, char *argv[])
> +{
> +       uint32_t format = DRM_FORMAT_XRGB8888;
> +       struct drm_tegra_gr2d *gr2d;
> +       struct drm_framebuffer *fb;
> +       struct drm_screen *screen;
> +       unsigned int pitch, size;
> +       struct drm_tegra_bo *bo;
> +       struct drm_tegra *drm;
> +       uint32_t handle;
> +       int fd, err;
> +       void *ptr;
> +
> +       fd = drm_open(argv[1]);
> +       if (fd < 0) {
> +               fprintf(stderr, "failed to open DRM device %s: %s\n", argv[1],
> +                       strerror(errno));
> +               return 1;
> +       }
> +
> +       err = drm_screen_open(&screen, fd);
> +       if (err < 0) {
> +               fprintf(stderr, "failed to open screen: %s\n", strerror(-err));
> +               return 1;
> +       }
> +
> +       err = drm_tegra_new(&drm, fd);
> +       if (err < 0) {
> +               fprintf(stderr, "failed to create Tegra DRM context: %s\n",
> +                       strerror(-err));
> +               return 1;
> +       }
> +
> +       err = drm_tegra_gr2d_open(&gr2d, drm);
> +       if (err < 0) {
> +               fprintf(stderr, "failed to open gr2d channel: %s\n",
> +                       strerror(-err));
> +               return 1;
> +       }
> +
> +       pitch = screen->width * screen->bpp / 8;
> +       size = pitch * screen->height;
> +
> +       err = drm_tegra_bo_new(&bo, drm, 0, size);
> +       if (err < 0) {
> +               fprintf(stderr, "failed to create buffer object: %s\n",
> +                       strerror(-err));
> +               return 1;
> +       }
> +
> +       err = drm_tegra_bo_get_handle(bo, &handle);
> +       if (err < 0) {
> +               fprintf(stderr, "failed to get handle to buffer object: %s\n",
> +                       strerror(-err));
> +               return 1;
> +       }
> +
> +       err = drm_tegra_bo_map(bo, &ptr);
> +       if (err < 0) {
> +               fprintf(stderr, "failed to map buffer object: %s\n",
> +                       strerror(-err));
> +               return 1;
> +       }
> +
> +       memset(ptr, 0xff, size);
> +
> +       err = drm_framebuffer_new(&fb, screen, handle, screen->width,
> +                                 screen->height, pitch, format, bo);
> +       if (err < 0) {
> +               fprintf(stderr, "failed to create framebuffer: %s\n",
> +                       strerror(-err));
> +               return 1;
> +       }
> +
> +       err = drm_screen_set_framebuffer(screen, fb);
> +       if (err < 0) {
> +               fprintf(stderr, "failed to display framebuffer: %s\n",
> +                       strerror(-err));
> +               return 1;
> +       }
> +
> +       sleep(1);
> +
> +       err = drm_tegra_gr2d_fill(gr2d, fb, fb->width / 4, fb->height / 4,
> +                                 fb->width / 2, fb->height / 2, 0x00000000);
> +       if (err < 0) {
> +               fprintf(stderr, "failed to fill rectangle: %s\n",
> +                       strerror(-err));
> +               return 1;
> +       }
> +
> +       sleep(1);

Oh, I see. You don't validate the result from the code, but visually instead?

IMO, we should allow automated test to verify the result
automatically. GR2D doesn't care about modesetting.

We could of course have a switch that lets the test-result be
inspected visually when specified. But I don't think that should be
the default, as it's more error prone, and requires master-rights.

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [RFC libdrm 1/6] configure: Support symbol visibility when available
  2014-02-19 16:04 ` [RFC libdrm 1/6] configure: Support symbol visibility when available Thierry Reding
@ 2014-02-19 21:05   ` Erik Faye-Lund
  2014-02-19 21:50     ` Thierry Reding
  0 siblings, 1 reply; 24+ messages in thread
From: Erik Faye-Lund @ 2014-02-19 21:05 UTC (permalink / raw)
  To: Thierry Reding; +Cc: dri-devel

On Wed, Feb 19, 2014 at 5:04 PM, Thierry Reding
<thierry.reding@gmail.com> wrote:
> From: Thierry Reding <treding@nvidia.com>
>
> Checks whether or not the compiler supports the -fvisibility option. If
> so it sets the VISIBILITY_CFLAGS variable which can be added to the per
> directory AM_CFLAGS where appropriate.
>
> Libraries can use the HAVE_VISIBILITY preprocessor definition to check
> for availability and use something like this:
>
>         #if defined(HAVE_VISIBILITY)
>         #  define drm_private __attribute__((visibility("hidden")))
>         #  define drm_public __attribute__((visibility("default")))
>         #else
>         #  define drm_private
>         #  define drm_public
>         #endif
>
> By default all symbols will be hidden via the VISIBILITY_CFLAGS. Only
> symbols explicitly marked drm_public will be exported.

As I said in the other patch, I think it makes more sense to define
these globally. The other drivers still need to opt-in on the feature,
but it's less work, less duplication of logic and less
points-of-failure ;)

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [RFC libdrm 4/6] tegra: Add channel, job, pushbuf and fence APIs
  2014-02-19 19:57   ` Erik Faye-Lund
@ 2014-02-19 21:11     ` Thierry Reding
  0 siblings, 0 replies; 24+ messages in thread
From: Thierry Reding @ 2014-02-19 21:11 UTC (permalink / raw)
  To: Erik Faye-Lund; +Cc: dri-devel


[-- Attachment #1.1: Type: text/plain, Size: 6333 bytes --]

On Wed, Feb 19, 2014 at 08:57:29PM +0100, Erik Faye-Lund wrote:
> On Wed, Feb 19, 2014 at 5:04 PM, Thierry Reding <thierry.reding@gmail.com> wrote:
[...]
> > +drm_public
> > +int drm_tegra_fence_wait_timeout(struct drm_tegra_fence *fence,
> > +                                unsigned long timeout)
> > +{
> > +       struct drm_tegra_syncpt_wait args;
> > +       int err;
> > +
> > +       memset(&args, 0, sizeof(args));
> 
> Nit: how about
> 
> struct drm_tegra_syncpt_wait args = { 0 };
> 
> instead?

I've compiled both variants and they seem to be generating exactly the
same code. Oddly enough, neither of them seems to be explicitly clearing
any part of the stack and indeed leaving out memset() and = { 0, } does
generate the same code again. It looks like the compiler is being pretty
clever about optimizing this part.

The reason I prefer memset() is that it's somewhat more explicit. So if
you don't have any strong objections I'd like to stick with it.

> > +       args.id = fence->syncpt;
> > +       args.thresh = fence->value;
> > +       args.timeout = timeout;
> > +
> > +       while (true) {
> > +               err = ioctl(fence->drm->fd, DRM_IOCTL_TEGRA_SYNCPT_WAIT, &args);
> > +               if (err < 0) {
> > +                       if (errno == EINTR)
> > +                               continue;
> > +
> > +                       drmMsg("DRM_IOCTL_TEGRA_SYNCPT_WAIT: %d\n", -errno);
> 
> What's the reason for printing the errno negated? And could we do
> '...%s\n" strerror(errno));' instead?

Yeah, strerror(errno) would be preferable. On second thought maybe I
should drop that message altogether since we return -errno anyway and
therefore have access to it in the caller who can then decide to print a
message or not.

> > +int drm_tegra_job_add_reloc(struct drm_tegra_job *job,
> > +                           const struct drm_tegra_reloc *reloc)
> > +{
> > +       struct drm_tegra_reloc *relocs;
> > +       size_t size;
> > +
> > +       size = (job->num_relocs + 1) * sizeof(*reloc);
> > +
> > +       relocs = realloc(job->relocs, size);
> 
> Nit: there's no point in not assigning those while declaring them, no?
> 
> size_t size = (job->num_relocs + 1) * sizeof(*reloc);
> struct drm_tegra_reloc *relocs; = realloc(job->relocs, size);

In my opinion that's a lot of clutter and very hard to read. So it's
really just a matter of preferred coding style.

> > +drm_public
> > +int drm_tegra_pushbuf_new(struct drm_tegra_pushbuf **pushbufp,
> > +                         struct drm_tegra_job *job,
> > +                         struct drm_tegra_bo *bo,
> > +                         unsigned long offset)
> > +{
> > +       struct drm_tegra_pushbuf_private *pushbuf;
> > +       void *ptr;
> > +       int err;
> > +
> > +       pushbuf = calloc(1, sizeof(*pushbuf));
> > +       if (!pushbuf)
> > +               return -ENOMEM;
> > +
> > +       pushbuf->bo = drm_tegra_bo_get(bo);
> > +       DRMINITLISTHEAD(&pushbuf->list);
> > +       pushbuf->job = job;
> > +
> > +       err = drm_tegra_bo_map(bo, &ptr);
> > +       if (err < 0) {
> > +               drm_tegra_bo_put(bo);
> > +               free(pushbuf);
> > +               return err;
> > +       }
> > +
> > +       pushbuf->start = pushbuf->base.ptr = ptr + offset;
> > +       pushbuf->offset = offset;
> > +
> > +       DRMLISTADD(&pushbuf->list, &job->pushbufs);
> > +       job->num_pushbufs++;
> > +
> > +       *pushbufp = &pushbuf->base;
> > +
> > +       return 0;
> > +}
> 
> It feels quite wasteful to me to have to allocate a new pushbuf in
> order to be able to use a new BO. I'd much rather see the pushbuf
> being a persisting object that's the interface to the command-stream
> (that produces jobs).
> 
> I was thinking something like:
> 
> int drm_tegra_pushbuf_new(struct drm_tegra_pushbuf **pushbufp, struct
> drm_tegra_job *job)
> int drm_tegra_pushbuf_room(struct drm_tegra_pushbuf *pushbuf, int num_words);
> 
> Where room guarantees that there's space for those words in the
> pushbuf. A simple implementation could just allocate a bo of that
> size, but a slightly more sophisticated one can allocate larger ones
> and reuse them. Even more sophisticated ones could keep old cmdbufs
> around and reuse them once the hardware is done reading them, do
> exponential grow-factors etc.

Okay, so you suggest that the backing buffer objects are handled
entirely by the push buffer implementation? Yeah, I think that makes a
lot of sense actually.

> I've implemented the "slightly more sophisticated" approach here:
> 
> https://github.com/grate-driver/libdrm/commit/f90ea2f57ca4d8c81768402900c663ce526bac11
> 
> In my implementation, I've changed the job-structure to build the list
> of cmdbufs directly rather than keeping a list of the pushbufs. Sure,
> that means another allocation every time we need a new cmdbuf, but
> hopefully we should be able to produce much less of them this way.

Okay, I'll try to integrate your implementation. It looks somewhat
complex but still manageable. The important part at this point is to get
the API right. That way we can still implement whatever complex scheme
we want underneath.

> > +int drm_tegra_pushbuf_relocate(struct drm_tegra_pushbuf *pushbuf,
> > +                              struct drm_tegra_bo *target,
> > +                              unsigned long offset,
> > +                              unsigned long shift)
> > +{
> > +       struct drm_tegra_pushbuf_private *priv = pushbuf_priv(pushbuf);
> > +       struct drm_tegra_reloc reloc;
> > +       int err;
> > +
> > +       memset(&reloc, 0, sizeof(reloc));
> > +       reloc.cmdbuf.handle = priv->bo->handle;
> > +       reloc.cmdbuf.offset = drm_tegra_pushbuf_get_offset(pushbuf);
> > +       reloc.target.handle = target->handle;
> > +       reloc.target.offset = offset;
> > +       reloc.shift = shift;
> > +
> > +       err = drm_tegra_job_add_reloc(priv->job, &reloc);
> > +       if (err < 0)
> > +               return err;
> > +
> > +       return 0;
> > +}
> 
> Whenever we insert a reloc, we also insert a DEADBEEF in the command
> stream. Why not formalize this into this function?

That's a good idea.

Thierry

[-- Attachment #1.2: Type: application/pgp-signature, Size: 836 bytes --]

[-- Attachment #2: Type: text/plain, Size: 159 bytes --]

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [RFC libdrm 2/6] libdrm: Add NVIDIA Tegra support
  2014-02-19 20:13   ` Erik Faye-Lund
@ 2014-02-19 21:32     ` Thierry Reding
  0 siblings, 0 replies; 24+ messages in thread
From: Thierry Reding @ 2014-02-19 21:32 UTC (permalink / raw)
  To: Erik Faye-Lund; +Cc: dri-devel


[-- Attachment #1.1: Type: text/plain, Size: 1071 bytes --]

On Wed, Feb 19, 2014 at 09:13:31PM +0100, Erik Faye-Lund wrote:
> On Wed, Feb 19, 2014 at 5:04 PM, Thierry Reding
> <thierry.reding@gmail.com> wrote:
> > diff --git a/tegra/Makefile.am b/tegra/Makefile.am
> > new file mode 100644
> > index 000000000000..1b83145b120d
> > --- /dev/null
> > +++ b/tegra/Makefile.am
> > @@ -0,0 +1,20 @@
> > +AM_CPPFLAGS = \
> > +       -I$(top_srcdir) \
> > +       -I$(top_srcdir)/include/drm
> > +
> > +AM_CFLAGS = \
> > +       $(VISIBILITY_CFLAGS)
> > +
> > +libdrm_tegra_ladir = $(libdir)
> > +libdrm_tegra_la_LTLIBRARIES = libdrm_tegra.la
> > +libdrm_tegra_la_LDFLAGS = -version-number 0:0:0 -no-undefined
> > +libdrm_tegra_la_LIBADD = ../libdrm.la @PTHREADSTUBS_LIBS@
> > +
> > +libdrm_tegra_la_SOURCES = \
> > +       tegra.c
> > +
> > +libdrm_tegraincludedir = ${includedir}/libdrm
> > +libdrm_tegrainclude_HEADERS = tegra.h
> > +
> > +pkgconfigdir = @pkgconfigdir@
> > +pkgconfig_DATA = libdrm_tegra.pc
> 
> You should probably also add libdrm_tegra.pc to .gitignore also.

Done. Thanks,
Thierry

[-- Attachment #1.2: Type: application/pgp-signature, Size: 836 bytes --]

[-- Attachment #2: Type: text/plain, Size: 159 bytes --]

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [RFC libdrm 2/6] libdrm: Add NVIDIA Tegra support
  2014-02-19 20:03   ` Erik Faye-Lund
@ 2014-02-19 21:33     ` Thierry Reding
  0 siblings, 0 replies; 24+ messages in thread
From: Thierry Reding @ 2014-02-19 21:33 UTC (permalink / raw)
  To: Erik Faye-Lund; +Cc: dri-devel


[-- Attachment #1.1: Type: text/plain, Size: 851 bytes --]

On Wed, Feb 19, 2014 at 09:03:51PM +0100, Erik Faye-Lund wrote:
> On Wed, Feb 19, 2014 at 5:04 PM, Thierry Reding
> <thierry.reding@gmail.com> wrote:
> > +#ifndef __DRM_TEGRA_PRIVATE_H__
> > +#define __DRM_TEGRA_PRIVATE_H__ 1
> > +
> > +#include <stdbool.h>
> > +#include <stdint.h>
> > +
> > +#include <xf86atomic.h>
> > +
> > +#include "tegra.h"
> > +
> > +#if defined(HAVE_VISIBILITY)
> > +#  define drm_private __attribute__((visibility("hidden")))
> > +#  define drm_public __attribute__((visibility("default")))
> > +#else
> > +#  define drm_private
> > +#  define drm_public
> > +#endif
> > +
> 
> Perhaps you could put this where it's visible to other drivers as
> well, like xf86drm.h?

I'd prefer to keep this here for now. We can move it to a more central
location when another module starts using it.

Thierry

[-- Attachment #1.2: Type: application/pgp-signature, Size: 836 bytes --]

[-- Attachment #2: Type: text/plain, Size: 159 bytes --]

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [RFC libdrm 3/6] tegra: Add simple test for drm_tegra_open()
  2014-02-19 16:04 ` [RFC libdrm 3/6] tegra: Add simple test for drm_tegra_open() Thierry Reding
  2014-02-19 20:19   ` Erik Faye-Lund
@ 2014-02-19 21:34   ` Erik Faye-Lund
  1 sibling, 0 replies; 24+ messages in thread
From: Erik Faye-Lund @ 2014-02-19 21:34 UTC (permalink / raw)
  To: Thierry Reding; +Cc: dri-devel

On Wed, Feb 19, 2014 at 5:04 PM, Thierry Reding
<thierry.reding@gmail.com> wrote:
> From: Thierry Reding <treding@nvidia.com>
>
> This test opens a device, dumps the version information and checks that
> a Tegra DRM context can be opened on it.
>
> Signed-off-by: Thierry Reding <treding@nvidia.com>
> ---
>  configure.ac            |  1 +
>  tests/Makefile.am       |  4 ++++
>  tests/tegra/Makefile.am | 20 ++++++++++++++++
>  tests/tegra/openclose.c | 63 +++++++++++++++++++++++++++++++++++++++++++++++++
>  4 files changed, 88 insertions(+)
>  create mode 100644 tests/tegra/Makefile.am
>  create mode 100644 tests/tegra/openclose.c
>
> diff --git a/configure.ac b/configure.ac
> index 752a70592933..c4ae14e8d2e1 100644
> --- a/configure.ac
> +++ b/configure.ac
> @@ -421,6 +421,7 @@ AC_CONFIG_FILES([
>         tests/radeon/Makefile
>         tests/vbltest/Makefile
>         tests/exynos/Makefile
> +       tests/tegra/Makefile
>         include/Makefile
>         include/drm/Makefile
>         man/Makefile
> diff --git a/tests/Makefile.am b/tests/Makefile.am
> index cd1149130214..0a3d21f2d99f 100644
> --- a/tests/Makefile.am
> +++ b/tests/Makefile.am
> @@ -24,6 +24,10 @@ if HAVE_EXYNOS
>  SUBDIRS += exynos
>  endif
>
> +if HAVE_TEGRA
> +SUBDIRS += tegra
> +endif
> +
>  if HAVE_LIBUDEV
>
>  check_LTLIBRARIES = libdrmtest.la
> diff --git a/tests/tegra/Makefile.am b/tests/tegra/Makefile.am
> new file mode 100644
> index 000000000000..7039f09d38aa
> --- /dev/null
> +++ b/tests/tegra/Makefile.am
> @@ -0,0 +1,20 @@
> +AM_CPPFLAGS = \
> +       -I$(top_srcdir)/include/drm \
> +       -I$(top_srcdir)/tegra
> +
> +AM_CFLAGS = -Wall -Werror
> +
> +LDADD = \
> +       ../../tegra/libdrm_tegra.la
> +
> +TESTS = \
> +       openclose \
> +
> +if HAVE_INSTALL_TESTS
> +testdir = $(libexecdir)/libdrm/tests/tegra
> +test_PROGRAMS = \
> +       $(TESTS)
> +else
> +noinst_PROGRAMS = $(TESTS)
> +check_PROGRAMS = $(TESTS)
> +endif

You should probably add openclose to .gitignore also. The same goes
for gr2d-fill in the other commit.

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [RFC libdrm 6/6] tegra: Add gr2d-fill test
  2014-02-19 21:03   ` Erik Faye-Lund
@ 2014-02-19 21:49     ` Thierry Reding
  0 siblings, 0 replies; 24+ messages in thread
From: Thierry Reding @ 2014-02-19 21:49 UTC (permalink / raw)
  To: Erik Faye-Lund; +Cc: dri-devel


[-- Attachment #1.1: Type: text/plain, Size: 7049 bytes --]

On Wed, Feb 19, 2014 at 10:03:31PM +0100, Erik Faye-Lund wrote:
> On Wed, Feb 19, 2014 at 5:04 PM, Thierry Reding
> <thierry.reding@gmail.com> wrote:
> > From: Thierry Reding <treding@nvidia.com>
> >
> > This test uses the IOCTLs for job submission and fences to fill a sub-
> > region of the screen to a specific color using gr2d.
> >
> > Signed-off-by: Thierry Reding <treding@nvidia.com>
> > ---
> >  tests/tegra/Makefile.am |   1 +
> >  tests/tegra/gr2d-fill.c | 145 ++++++++++++++++++++++++++++++++++++++++++++++++
> >  2 files changed, 146 insertions(+)
> >  create mode 100644 tests/tegra/gr2d-fill.c
> >
> > diff --git a/tests/tegra/Makefile.am b/tests/tegra/Makefile.am
> > index 90b11b278a42..9e9e75e91ad4 100644
> > --- a/tests/tegra/Makefile.am
> > +++ b/tests/tegra/Makefile.am
> > @@ -17,6 +17,7 @@ LDADD = \
> >
> >  TESTS = \
> >         openclose \
> > +       gr2d-fill
> >
> >  if HAVE_INSTALL_TESTS
> >  testdir = $(libexecdir)/libdrm/tests/tegra
> > diff --git a/tests/tegra/gr2d-fill.c b/tests/tegra/gr2d-fill.c
> > new file mode 100644
> > index 000000000000..7ffe6f0b0848
> > --- /dev/null
> > +++ b/tests/tegra/gr2d-fill.c
> > @@ -0,0 +1,145 @@
> > +/*
> > + * Copyright © 2014 NVIDIA Corporation
> > + *
> > + * 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 COPYRIGHT HOLDER(S) OR AUTHOR(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.
> > + */
> > +
> > +#ifdef HAVE_CONFIG_H
> > +#  include "config.h"
> > +#endif
> > +
> > +#include <errno.h>
> > +#include <fcntl.h>
> > +#include <stdbool.h>
> > +#include <stdint.h>
> > +#include <stdio.h>
> > +#include <stdlib.h>
> > +#include <string.h>
> > +#include <unistd.h>
> > +
> > +#include <sys/ioctl.h>
> > +
> > +#include "xf86drm.h"
> > +#include "xf86drmMode.h"
> > +#include "drm_fourcc.h"
> > +
> > +#include "drm-test-tegra.h"
> > +#include "tegra.h"
> > +
> > +int main(int argc, char *argv[])
> > +{
> > +       uint32_t format = DRM_FORMAT_XRGB8888;
> > +       struct drm_tegra_gr2d *gr2d;
> > +       struct drm_framebuffer *fb;
> > +       struct drm_screen *screen;
> > +       unsigned int pitch, size;
> > +       struct drm_tegra_bo *bo;
> > +       struct drm_tegra *drm;
> > +       uint32_t handle;
> > +       int fd, err;
> > +       void *ptr;
> > +
> > +       fd = drm_open(argv[1]);
> > +       if (fd < 0) {
> > +               fprintf(stderr, "failed to open DRM device %s: %s\n", argv[1],
> > +                       strerror(errno));
> > +               return 1;
> > +       }
> > +
> > +       err = drm_screen_open(&screen, fd);
> > +       if (err < 0) {
> > +               fprintf(stderr, "failed to open screen: %s\n", strerror(-err));
> > +               return 1;
> > +       }
> > +
> > +       err = drm_tegra_new(&drm, fd);
> > +       if (err < 0) {
> > +               fprintf(stderr, "failed to create Tegra DRM context: %s\n",
> > +                       strerror(-err));
> > +               return 1;
> > +       }
> > +
> > +       err = drm_tegra_gr2d_open(&gr2d, drm);
> > +       if (err < 0) {
> > +               fprintf(stderr, "failed to open gr2d channel: %s\n",
> > +                       strerror(-err));
> > +               return 1;
> > +       }
> > +
> > +       pitch = screen->width * screen->bpp / 8;
> > +       size = pitch * screen->height;
> > +
> > +       err = drm_tegra_bo_new(&bo, drm, 0, size);
> > +       if (err < 0) {
> > +               fprintf(stderr, "failed to create buffer object: %s\n",
> > +                       strerror(-err));
> > +               return 1;
> > +       }
> > +
> > +       err = drm_tegra_bo_get_handle(bo, &handle);
> > +       if (err < 0) {
> > +               fprintf(stderr, "failed to get handle to buffer object: %s\n",
> > +                       strerror(-err));
> > +               return 1;
> > +       }
> > +
> > +       err = drm_tegra_bo_map(bo, &ptr);
> > +       if (err < 0) {
> > +               fprintf(stderr, "failed to map buffer object: %s\n",
> > +                       strerror(-err));
> > +               return 1;
> > +       }
> > +
> > +       memset(ptr, 0xff, size);
> > +
> > +       err = drm_framebuffer_new(&fb, screen, handle, screen->width,
> > +                                 screen->height, pitch, format, bo);
> > +       if (err < 0) {
> > +               fprintf(stderr, "failed to create framebuffer: %s\n",
> > +                       strerror(-err));
> > +               return 1;
> > +       }
> > +
> > +       err = drm_screen_set_framebuffer(screen, fb);
> > +       if (err < 0) {
> > +               fprintf(stderr, "failed to display framebuffer: %s\n",
> > +                       strerror(-err));
> > +               return 1;
> > +       }
> > +
> > +       sleep(1);
> > +
> > +       err = drm_tegra_gr2d_fill(gr2d, fb, fb->width / 4, fb->height / 4,
> > +                                 fb->width / 2, fb->height / 2, 0x00000000);
> > +       if (err < 0) {
> > +               fprintf(stderr, "failed to fill rectangle: %s\n",
> > +                       strerror(-err));
> > +               return 1;
> > +       }
> > +
> > +       sleep(1);
> 
> Oh, I see. You don't validate the result from the code, but visually instead?
> 
> IMO, we should allow automated test to verify the result
> automatically. GR2D doesn't care about modesetting.
> 
> We could of course have a switch that lets the test-result be
> inspected visually when specified. But I don't think that should be
> the default, as it's more error prone, and requires master-rights.

Yes, I think we should support both. Offscreen tests for automatic
validation and onscreen tests for me because I like looking at the
output.

One of the things also on my TODO list, and with these patches getting
ready that moves more towards the top, is render node support. It should
be relatively easy to support that.

Thierry

[-- Attachment #1.2: Type: application/pgp-signature, Size: 836 bytes --]

[-- Attachment #2: Type: text/plain, Size: 159 bytes --]

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [RFC libdrm 1/6] configure: Support symbol visibility when available
  2014-02-19 21:05   ` Erik Faye-Lund
@ 2014-02-19 21:50     ` Thierry Reding
  0 siblings, 0 replies; 24+ messages in thread
From: Thierry Reding @ 2014-02-19 21:50 UTC (permalink / raw)
  To: Erik Faye-Lund; +Cc: dri-devel


[-- Attachment #1.1: Type: text/plain, Size: 1341 bytes --]

On Wed, Feb 19, 2014 at 10:05:19PM +0100, Erik Faye-Lund wrote:
> On Wed, Feb 19, 2014 at 5:04 PM, Thierry Reding
> <thierry.reding@gmail.com> wrote:
> > From: Thierry Reding <treding@nvidia.com>
> >
> > Checks whether or not the compiler supports the -fvisibility option. If
> > so it sets the VISIBILITY_CFLAGS variable which can be added to the per
> > directory AM_CFLAGS where appropriate.
> >
> > Libraries can use the HAVE_VISIBILITY preprocessor definition to check
> > for availability and use something like this:
> >
> >         #if defined(HAVE_VISIBILITY)
> >         #  define drm_private __attribute__((visibility("hidden")))
> >         #  define drm_public __attribute__((visibility("default")))
> >         #else
> >         #  define drm_private
> >         #  define drm_public
> >         #endif
> >
> > By default all symbols will be hidden via the VISIBILITY_CFLAGS. Only
> > symbols explicitly marked drm_public will be exported.
> 
> As I said in the other patch, I think it makes more sense to define
> these globally. The other drivers still need to opt-in on the feature,
> but it's less work, less duplication of logic and less
> points-of-failure ;)

Well, if you put it that way, having it in somewhere in the core might
be a better option after all. I'll sleep on it.

Thierry

[-- Attachment #1.2: Type: application/pgp-signature, Size: 836 bytes --]

[-- Attachment #2: Type: text/plain, Size: 159 bytes --]

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [RFC libdrm 0/6] Add NVIDIA Tegra support
  2014-02-19 16:04 [RFC libdrm 0/6] Add NVIDIA Tegra support Thierry Reding
                   ` (5 preceding siblings ...)
  2014-02-19 16:04 ` [RFC libdrm 6/6] tegra: Add gr2d-fill test Thierry Reding
@ 2014-03-20 15:23 ` Erik Faye-Lund
  2014-04-08 12:58   ` Erik Faye-Lund
  6 siblings, 1 reply; 24+ messages in thread
From: Erik Faye-Lund @ 2014-03-20 15:23 UTC (permalink / raw)
  To: Thierry Reding; +Cc: dri-devel

On Wed, Feb 19, 2014 at 5:04 PM, Thierry Reding
<thierry.reding@gmail.com> wrote:
> From: Thierry Reding <treding@nvidia.com>
>
> Hi,
>
> This series adds libdrm-tegra with a very lightweight API on top of the
> kernel interfaces. Most of the functions provided here have been in use
> in various driver efforts in different incarnations. This is an attempt
> to consolidate, so I'm looking for review comments especially by Erik
> to ensure it can be used by grate.

Is there anything I can do to move this series along?

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [RFC libdrm 0/6] Add NVIDIA Tegra support
  2014-03-20 15:23 ` [RFC libdrm 0/6] Add NVIDIA Tegra support Erik Faye-Lund
@ 2014-04-08 12:58   ` Erik Faye-Lund
  0 siblings, 0 replies; 24+ messages in thread
From: Erik Faye-Lund @ 2014-04-08 12:58 UTC (permalink / raw)
  To: Thierry Reding; +Cc: dri-devel

On Thu, Mar 20, 2014 at 4:23 PM, Erik Faye-Lund <kusmabite@gmail.com> wrote:
> On Wed, Feb 19, 2014 at 5:04 PM, Thierry Reding
> <thierry.reding@gmail.com> wrote:
>> From: Thierry Reding <treding@nvidia.com>
>>
>> Hi,
>>
>> This series adds libdrm-tegra with a very lightweight API on top of the
>> kernel interfaces. Most of the functions provided here have been in use
>> in various driver efforts in different incarnations. This is an attempt
>> to consolidate, so I'm looking for review comments especially by Erik
>> to ensure it can be used by grate.
>
> Is there anything I can do to move this series along?

I'll ask again... Is there something I can do to help move this along?

^ permalink raw reply	[flat|nested] 24+ messages in thread

end of thread, other threads:[~2014-04-08 12:59 UTC | newest]

Thread overview: 24+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-02-19 16:04 [RFC libdrm 0/6] Add NVIDIA Tegra support Thierry Reding
2014-02-19 16:04 ` [RFC libdrm 1/6] configure: Support symbol visibility when available Thierry Reding
2014-02-19 21:05   ` Erik Faye-Lund
2014-02-19 21:50     ` Thierry Reding
2014-02-19 16:04 ` [RFC libdrm 2/6] libdrm: Add NVIDIA Tegra support Thierry Reding
2014-02-19 19:59   ` Rémi Cardona
2014-02-19 20:03   ` Erik Faye-Lund
2014-02-19 21:33     ` Thierry Reding
2014-02-19 20:13   ` Erik Faye-Lund
2014-02-19 21:32     ` Thierry Reding
2014-02-19 16:04 ` [RFC libdrm 3/6] tegra: Add simple test for drm_tegra_open() Thierry Reding
2014-02-19 20:19   ` Erik Faye-Lund
2014-02-19 20:50     ` Erik Faye-Lund
2014-02-19 21:34   ` Erik Faye-Lund
2014-02-19 16:04 ` [RFC libdrm 4/6] tegra: Add channel, job, pushbuf and fence APIs Thierry Reding
2014-02-19 19:57   ` Erik Faye-Lund
2014-02-19 21:11     ` Thierry Reding
2014-02-19 16:04 ` [RFC libdrm 5/6] tegra: Add helper library for tests Thierry Reding
2014-02-19 20:54   ` Erik Faye-Lund
2014-02-19 16:04 ` [RFC libdrm 6/6] tegra: Add gr2d-fill test Thierry Reding
2014-02-19 21:03   ` Erik Faye-Lund
2014-02-19 21:49     ` Thierry Reding
2014-03-20 15:23 ` [RFC libdrm 0/6] Add NVIDIA Tegra support Erik Faye-Lund
2014-04-08 12:58   ` Erik Faye-Lund

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.