Skip to contentSkip to conversation

Add NVIDIA Tegra support

RFC Superseded Thierry Reding 3 participants 24 messages Feb 19, 2014 – Apr 8, 2014

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover Add NVIDIA Tegra support

From: Thierry Reding <[email protected]>

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
Signature · 1 line
1.8.4.2
#1 lore raw

RFC 1/6 configure: Support symbol visibility when available

From: Thierry Reding <[email protected]>

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.

---
 configure.ac | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
configure.ac +20 -0
index d2d19d66dc17..3f4164238494 100644
@@ -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
Signature · 1 line
1.8.4.2
#2 lore raw

Re: [RFC libdrm 1/6] configure: Support symbol visibility when available

Quoted 17 lines · Thierry Reding

From: Thierry Reding <[email protected]>

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

Quoted 2 lines

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 ;)

#3 lore raw

Re: [RFC libdrm 1/6] configure: Support symbol visibility when available

Quoted 19 lines · Erik Faye-Lund
Quoted 17 lines · Thierry Reding

From: Thierry Reding <[email protected]>

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

Quoted 7 lines
Quoted 2 lines

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

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel

#4 lore raw

RFC 2/6 libdrm: Add NVIDIA Tegra support

In reply to Thierry Reding

From: Thierry Reding <[email protected]>

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.

---
 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
Makefile.am +5 -1
index 826c30d0c0d9..14c402dce74f 100644
@@ -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)
configure.ac +14 -1
index 3f4164238494..752a70592933 100644
@@ -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 ""
include/drm/Makefile.am +1 -0
index 2bc34d2ffd9f..f591abc45152 100644
@@ -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
include/drm/tegra_drm.h new file +157 -0

157 lines not on this page · raw message

tegra/Makefile.am new file +20 -0
new file mode 100644
index 000000000000..1b83145b120d
@@ -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
tegra/libdrm_tegra.pc.in new file +11 -0
new file mode 100644
index 000000000000..2e06f49c6fba
@@ -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
tegra/private.h new file +58 -0

58 lines not on this page · raw message

tegra/tegra.c new file +253 -0

253 lines not on this page · raw message

tegra/tegra.h new file +47 -0

47 lines not on this page · raw message

tests/modetest/modetest.c +1 -1
index bc9c9988dec7..4212963f8ff0 100644
@@ -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;
tests/vbltest/vbltest.c +1 -1
index 2a09d28ed00a..e4b200bf0c3c 100644
@@ -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;
Signature · 6 lines
1.8.4.2

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel
#5 lore raw

Re: [RFC libdrm 2/6] libdrm: Add NVIDIA Tegra support

include/drm/tegra_drm.h line 2

Quoted 5 lines · Thierry Reding
include/drm/tegra_drm.h new file +2 -0
@@ -0,0 +1,157 @@
+/*
+ * Copyright (c) 2012-2013, NVIDIA CORPORATION.  All rights reserved.
                               ^^^^^^

[...]

Quoted 4 lines

+ * 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
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel

#6 lore raw

Re: [RFC libdrm 2/6] libdrm: Add NVIDIA Tegra support

In reply to Thierry Reding
Quoted 8 lines · Thierry Reding
tegra/private.h new file +8 -0
+#ifndef __DRM_TEGRA_PRIVATE_H__
+#define __DRM_TEGRA_PRIVATE_H__ 1
+
+#include <stdbool.h>
+#include <stdint.h>
+
+#include <xf86atomic.h>
+

tegra/private.h line 42

Quoted 10 lines
tegra/private.h new file +10 -0
+#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?

#7 lore raw

Re: [RFC libdrm 2/6] libdrm: Add NVIDIA Tegra support

Quoted 15 lines · Erik Faye-Lund
Quoted 13 lines · Thierry Reding
tegra/private.h new file +13 -0
+#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")))
Quoted 8 lines

tegra/private.h line 42

Quoted 5 lines
tegra/private.h new file +5 -0
+#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

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel

#8 lore raw

Re: [RFC libdrm 2/6] libdrm: Add NVIDIA Tegra support

In reply to Thierry Reding
Quoted 16 lines · Thierry Reding
tegra/Makefile.am new file +10 -0
new file mode 100644
index 000000000000..1b83145b120d
@@ -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

tegra/Makefile.am line 20

Quoted 10 lines
tegra/Makefile.am new file +10 -0
+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.

#9 lore raw

Re: [RFC libdrm 2/6] libdrm: Add NVIDIA Tegra support

Quoted 22 lines · Erik Faye-Lund
Quoted 20 lines · Thierry Reding
tegra/Makefile.am new file +14 -0
new file mode 100644
index 000000000000..1b83145b120d
@@ -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
Quoted 8 lines

tegra/Makefile.am line 20

Quoted 6 lines
tegra/Makefile.am new file +6 -0
+
+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

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel

#10 lore raw

RFC 3/6 tegra: Add simple test for drm_tegra_open()

In reply to Thierry Reding

From: Thierry Reding <[email protected]>

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

---
 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
configure.ac +1 -0
index 752a70592933..c4ae14e8d2e1 100644
@@ -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
tests/Makefile.am +4 -0
index cd1149130214..0a3d21f2d99f 100644
@@ -24,6 +24,10 @@ if HAVE_EXYNOS
 SUBDIRS += exynos
 endif
 
+if HAVE_TEGRA
+SUBDIRS += tegra
+endif
+
 if HAVE_LIBUDEV
 
 check_LTLIBRARIES = libdrmtest.la
tests/tegra/Makefile.am new file +20 -0
new file mode 100644
index 000000000000..7039f09d38aa
@@ -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
tests/tegra/openclose.c new file +63 -0

63 lines not on this page · raw message

Signature · 6 lines
1.8.4.2

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel
#11 lore raw

Re: [RFC libdrm 3/6] tegra: Add simple test for drm_tegra_open()

Quoted 6 lines · Thierry Reding
tests/tegra/Makefile.am new file +0 -0
new file mode 100644
index 000000000000..7039f09d38aa

tests/tegra/Makefile.am line 8

Quoted 8 lines
tests/tegra/Makefile.am new file +8 -0
@@ -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.

#12 lore raw

Re: [RFC libdrm 3/6] tegra: Add simple test for drm_tegra_open()

Quoted 18 lines · Erik Faye-Lund
Quoted 6 lines · Thierry Reding
tests/tegra/Makefile.am new file +0 -0
new file mode 100644
index 000000000000..7039f09d38aa

tests/tegra/Makefile.am line 8

Quoted 8 lines
tests/tegra/Makefile.am new file +8 -0
@@ -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.

#13 lore raw

Re: [RFC libdrm 3/6] tegra: Add simple test for drm_tegra_open()

In reply to Thierry Reding
Quoted 58 lines · Thierry Reding

From: Thierry Reding <[email protected]>

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

---
 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
configure.ac +1 -0
index 752a70592933..c4ae14e8d2e1 100644
@@ -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
tests/Makefile.am +4 -0
index cd1149130214..0a3d21f2d99f 100644
@@ -24,6 +24,10 @@ if HAVE_EXYNOS
 SUBDIRS += exynos
 endif
 
+if HAVE_TEGRA
+SUBDIRS += tegra
+endif
+
 if HAVE_LIBUDEV
 
 check_LTLIBRARIES = libdrmtest.la
tests/tegra/Makefile.am new file +10 -0
new file mode 100644
index 000000000000..7039f09d38aa
@@ -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 = \

tests/tegra/Makefile.am line 20

Quoted 10 lines
tests/tegra/Makefile.am new file +10 -0
+       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.

#14 lore raw

RFC 4/6 tegra: Add channel, job, pushbuf and fence APIs

In reply to Thierry Reding

From: Thierry Reding <[email protected]>

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.

---
 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
tegra/Makefile.am +4 -0
index 1b83145b120d..c73587e8661e 100644
@@ -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
tegra/channel.c new file +127 -0

127 lines not on this page · raw message

tegra/fence.c new file +72 -0

72 lines not on this page · raw message

tegra/job.c new file +167 -0

167 lines not on this page · raw message

tegra/private.h +59 -0

79 lines not on this page · raw message

tegra/pushbuf.c new file +137 -0

137 lines not on this page · raw message

tegra/tegra.h +52 -0

62 lines not on this page · raw message

Signature · 6 lines
1.8.4.2

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel
#15 lore raw

Re: [RFC libdrm 4/6] tegra: Add channel, job, pushbuf and fence APIs

Quoted 7 lines · Thierry Reding

From: Thierry Reding <[email protected]>

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.

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

tegra/fence.c line 41

Quoted 8 lines
tegra/fence.c new file +8 -0
+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?

tegra/fence.c line 52

Quoted 11 lines
tegra/fence.c new file +11 -0
+       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?

tegra/job.c line 43

Quoted 9 lines
tegra/job.c new file +9 -0
+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);

Quoted 25 lines
tegra/pushbuf.c new file +25 -0
+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;
+       }
+

tegra/pushbuf.c line 81

Quoted 10 lines
tegra/pushbuf.c new file +10 -0
+       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.

Quoted 12 lines
tegra/pushbuf.c new file +12 -0
+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);

tegra/pushbuf.c line 121

Quoted 10 lines
tegra/pushbuf.c new file +10 -0
+       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?

#16 lore raw

Re: [RFC libdrm 4/6] tegra: Add channel, job, pushbuf and fence APIs

Quoted 1 line · Erik Faye-Lund

On Wed, Feb 19, 2014 at 5:04 PM, Thierry Reding <[email protected]> wrote:

[...]

Quoted 11 lines

tegra/fence.c line 41

Quoted 8 lines
tegra/fence.c new file +8 -0
+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

Quoted 3 lines

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.

Quoted 6 lines
Quoted 6 lines
tegra/fence.c new file +6 -0
+       args.id = fence->syncpt;
+       args.thresh = fence->value;
+       args.timeout = timeout;
+
+       while (true) {
+               err = ioctl(fence->drm->fd, DRM_IOCTL_TEGRA_SYNCPT_WAIT, &args);
Quoted 8 lines

tegra/fence.c line 52

Quoted 5 lines
tegra/fence.c new file +5 -0
+               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.

Quoted 12 lines

tegra/job.c line 43

Quoted 9 lines
tegra/job.c new file +9 -0
+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?

Quoted 2 lines

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.

Quoted 47 lines
Quoted 25 lines
tegra/pushbuf.c new file +25 -0
+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;
+       }
+

tegra/pushbuf.c line 81

Quoted 10 lines
tegra/pushbuf.c new file +10 -0
+       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);

Quoted 6 lines

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.

Quoted 8 lines

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.

Quoted 17 lines
Quoted 17 lines
tegra/pushbuf.c new file +17 -0
+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);
Quoted 8 lines

tegra/channel.c line 103

Quoted 5 lines
tegra/channel.c new file +5 -0
+       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

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel

#17 lore raw

RFC 5/6 tegra: Add helper library for tests

In reply to Thierry Reding

From: Thierry Reding <[email protected]>

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

---
 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
tests/tegra/Makefile.am +9 -1
index 7039f09d38aa..90b11b278a42 100644
@@ -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 \
tests/tegra/drm-test-tegra.c new file +132 -0

132 lines not on this page · raw message

tests/tegra/drm-test-tegra.h new file +55 -0

55 lines not on this page · raw message

tests/tegra/drm-test.c new file +261 -0

261 lines not on this page · raw message

tests/tegra/drm-test.h new file +73 -0

73 lines not on this page · raw message

Signature · 6 lines
1.8.4.2

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel
#18 lore raw

Re: [RFC libdrm 5/6] tegra: Add helper library for tests

Quoted 5 lines · Thierry Reding
tests/tegra/drm-test-tegra.h new file +0 -0
new file mode 100644
index 000000000000..d1cb6b1ee440

tests/tegra/drm-test-tegra.h

Quoted 9 lines
tests/tegra/drm-test-tegra.h new file +9 -0
+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?

#19 lore raw

RFC 6/6 tegra: Add gr2d-fill test

In reply to Thierry Reding

From: Thierry Reding <[email protected]>

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

---
 tests/tegra/Makefile.am |   1 +
 tests/tegra/gr2d-fill.c | 145 ++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 146 insertions(+)
 create mode 100644 tests/tegra/gr2d-fill.c
tests/tegra/Makefile.am +1 -0
index 90b11b278a42..9e9e75e91ad4 100644
@@ -17,6 +17,7 @@ LDADD = \
 
 TESTS = \
 	openclose \
+	gr2d-fill
 
 if HAVE_INSTALL_TESTS
 testdir = $(libexecdir)/libdrm/tests/tegra
tests/tegra/gr2d-fill.c new file +145 -0

145 lines not on this page · raw message

Signature · 6 lines
1.8.4.2

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel
#20 lore raw

Re: [RFC libdrm 6/6] tegra: Add gr2d-fill test

Quoted 156 lines · Thierry Reding

From: Thierry Reding <[email protected]>

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

---
 tests/tegra/Makefile.am |   1 +
 tests/tegra/gr2d-fill.c | 145 ++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 146 insertions(+)
 create mode 100644 tests/tegra/gr2d-fill.c
tests/tegra/Makefile.am +1 -0
index 90b11b278a42..9e9e75e91ad4 100644
@@ -17,6 +17,7 @@ LDADD = \
 
 TESTS = \
        openclose \
+       gr2d-fill
 
 if HAVE_INSTALL_TESTS
 testdir = $(libexecdir)/libdrm/tests/tegra
tests/tegra/gr2d-fill.c new file +126 -0
new file mode 100644
index 000000000000..7ffe6f0b0848
@@ -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);

tests/tegra/gr2d-fill.c line 136

Quoted 10 lines
tests/tegra/gr2d-fill.c new file +10 -0
+
+       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.

#21 lore raw

Re: [RFC libdrm 6/6] tegra: Add gr2d-fill test

Quoted 171 lines · Erik Faye-Lund
Quoted 156 lines · Thierry Reding

From: Thierry Reding <[email protected]>

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

---
 tests/tegra/Makefile.am |   1 +
 tests/tegra/gr2d-fill.c | 145 ++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 146 insertions(+)
 create mode 100644 tests/tegra/gr2d-fill.c
tests/tegra/Makefile.am +1 -0
index 90b11b278a42..9e9e75e91ad4 100644
@@ -17,6 +17,7 @@ LDADD = \
 
 TESTS = \
        openclose \
+       gr2d-fill
 
 if HAVE_INSTALL_TESTS
 testdir = $(libexecdir)/libdrm/tests/tegra
tests/tegra/gr2d-fill.c new file +126 -0
new file mode 100644
index 000000000000..7ffe6f0b0848
@@ -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);

tests/tegra/gr2d-fill.c line 136

Quoted 10 lines
tests/tegra/gr2d-fill.c new file +10 -0
+
+       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?

Quoted 6 lines

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

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel

#22 lore raw
In reply to Thierry Reding
Quoted 9 lines · Thierry Reding

From: Thierry Reding <[email protected]>

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?

#23 lore raw
Quoted 6 lines · Erik Faye-Lund
Quoted 4 lines · Thierry Reding

From: Thierry Reding <[email protected]>

Hi,

Quoted 7 lines
Quoted 5 lines

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?