Skip to contentSkip to conversation

Add NVIDIA Tegra support

RFC In review Thierry Reding 3 participants 6 messages Dec 4, 2012 – Dec 5, 2012 4 messages not in the archive

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

Hi,

I mentioned in a reply to Terje's patch series for 2D acceleration that I had prototyped some libdrm support a few weeks back. I've spent a bit of time cleaning it up and decided to post it for early review.

There's really not much interesting code here. A basic API is provided along with two IOCTLs that can be used to create Tegra-specific GEM, as opposed to dumb buffer objects. Given the various comments on Terje's proposed IOCTLs I wanted to make sure that these will be safe. I've seen that other chips use 64-bit fields for the size and offset of buffer objects and I wonder if those are really necessary.

Linux kernel patches for the IOCTLs are also in the works and I hope to get around to posting them this week. Obviously there will be some overlap between this and what Terje posted in his series, but it should be easy to synchronize.

Thierry

Thierry Reding (1):
libdrm: Add NVIDIA Tegra support

 Makefile.am               |   6 +-
 configure.ac              |  15 ++-
 include/drm/Makefile.am   |   1 +
 include/drm/tegra_drm.h   |  48 ++++++++++
 tegra/Makefile.am         |  17 ++++
 tegra/libdrm_tegra.pc.in  |  11 +++
 tegra/tegra.c             | 227 ++++++++++++++++++++++++++++++++++++++++++++++
 tegra/tegra.h             |  51 +++++++++++
 tests/modetest/modetest.c |   2 +-
 tests/vbltest/vbltest.c   |   2 +-
 10 files changed, 376 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/tegra.c
 create mode 100644 tegra/tegra.h
Signature · 1 line
1.8.0.1
#2 lore raw

RFC 1/1 Add NVIDIA Tegra support

In reply to a message not in the archive

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   |  48 ++++++++++
 tegra/Makefile.am         |  17 ++++
 tegra/libdrm_tegra.pc.in  |  11 +++
 tegra/tegra.c             | 227 ++++++++++++++++++++++++++++++++++++++++++++++
 tegra/tegra.h             |  51 +++++++++++
 tests/modetest/modetest.c |   2 +-
 tests/vbltest/vbltest.c   |   2 +-
 10 files changed, 376 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/tegra.c
 create mode 100644 tegra/tegra.h
Makefile.am +5 -1
index 8ecd9d9..e90ae43 100644
@@ -49,7 +49,11 @@ if HAVE_EXYNOS
 EXYNOS_SUBDIR = exynos
 endif
 
-SUBDIRS = . $(LIBKMS_SUBDIR) $(INTEL_SUBDIR) $(NOUVEAU_SUBDIR) $(RADEON_SUBDIR) $(OMAP_SUBDIR) $(EXYNOS_SUBDIR) tests include man
+if HAVE_TEGRA
+TEGRA_SUBDIR = tegra
+endif
+
+SUBDIRS = . $(LIBKMS_SUBDIR) $(INTEL_SUBDIR) $(NOUVEAU_SUBDIR) $(RADEON_SUBDIR) $(OMAP_SUBDIR) $(EXYNOS_SUBDIR) $(TEGRA_SUBDIR) tests include man
 
 libdrm_la_LTLIBRARIES = libdrm.la
 libdrm_ladir = $(libdir)
configure.ac +14 -1
index 0c19929..72d6dfa 100644
@@ -114,6 +114,11 @@ AC_ARG_ENABLE(exynos-experimental-api,
 	      [Enable support for EXYNOS's experimental API (default: disabled)]),
 	      [EXYNOS=$enableval], [EXYNOS=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])
+
 dnl ===========================================================================
 dnl check compiler flags
 AC_DEFUN([LIBDRM_CC_TRY_FLAG], [
@@ -222,6 +227,11 @@ if test "x$EXYNOS" = xyes; then
 	AC_DEFINE(HAVE_EXYNOS, 1, [Have EXYNOS 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
+
 AC_ARG_ENABLE([cairo-tests],
               [AS_HELP_STRING([--enable-cairo-tests],
                               [Enable support for Cairo rendering in tests (default: auto)])],
@@ -247,7 +257,7 @@ if test "x$HAVE_LIBUDEV" = xyes; then
 fi
 AM_CONDITIONAL(HAVE_LIBUDEV, [test "x$HAVE_LIBUDEV" = xyes])
 
-if test "x$INTEL" != "xno" -o "x$RADEON" != "xno" -o "x$NOUVEAU" != "xno" -o "x$OMAP" != "xno"; then
+if test "x$INTEL" != "xno" -o "x$RADEON" != "xno" -o "x$NOUVEAU" != "xno" -o "x$OMAP" != "xno" -o "x$TEGRA" != "xno"; then
     # Check for atomic intrinsics
     AC_CACHE_CHECK([for native atomic primitives], drm_cv_atomic_primitives,
     [
@@ -358,6 +368,8 @@ AC_CONFIG_FILES([
 	omap/libdrm_omap.pc
 	exynos/Makefile
 	exynos/libdrm_exynos.pc
+	tegra/Makefile
+	tegra/libdrm_tegra.pc
 	tests/Makefile
 	tests/modeprint/Makefile
 	tests/modetest/Makefile
@@ -380,4 +392,5 @@ echo "  Radeon API     $RADEON"
 echo "  Nouveau API    $NOUVEAU"
 echo "  OMAP API       $OMAP"
 echo "  EXYNOS API     $EXYNOS"
+echo "  Tegra API      $TEGRA"
 echo ""
include/drm/Makefile.am +1 -0
index 2923ab4..3e33ed0 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
 
include/drm/tegra_drm.h new file +48 -0

48 lines not on this page · raw message

tegra/Makefile.am new file +17 -0
new file mode 100644
index 0000000..65cd628
@@ -0,0 +1,17 @@
+AM_CPPFLAGS = \
+	-I$(top_srcdir) \
+	-I$(top_srcdir)/include/drm
+
+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 0000000..f83c74c
@@ -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: 2.4.40
+Libs: -L${libdir} -ldrm_tegra
+Cflags: -I${includedir} -I${includedir}/libdrm
+Requires.private: libdrm
tegra/tegra.c new file +227 -0

227 lines not on this page · raw message

tegra/tegra.h new file +51 -0

51 lines not on this page · raw message

tests/modetest/modetest.c +1 -1
index c91bb9d..913ede8 100644
@@ -939,7 +939,7 @@ int main(int argc, char **argv)
 	int c;
 	int encoders = 0, connectors = 0, crtcs = 0, planes = 0, framebuffers = 0;
 	int test_vsync = 0;
-	char *modules[] = { "i915", "radeon", "nouveau", "vmwgfx", "omapdrm", "exynos" };
+	char *modules[] = { "i915", "radeon", "nouveau", "vmwgfx", "omapdrm", "exynos", "tegra" };
 	unsigned int i;
 	int count = 0, plane_count = 0;
 	struct connector con_args[2];
tests/vbltest/vbltest.c +1 -1
index 4fccd59..22a5339 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" };
+	char *modules[] = { "i915", "radeon", "nouveau", "vmwgfx", "exynos", "tegra" };
 	drmVBlank vbl;
 	drmEventContext evctx;
 	struct vbl_info handler_info;
Signature · 1 line
1.8.0.1
#3 lore raw
Quoted 28 lines · Thierry Reding
tegra/tegra.c new file +28 -0
+int drm_tegra_bo_new(struct drm_tegra *device, uint32_t flags, uint32_t size,
+                    struct drm_tegra_bo **bop)
+{
+       struct drm_tegra_gem_create args;
+       struct drm_tegra_bo *bo;
+       struct tegra_bo *priv;
+       int err;
+
+       if (!device || size == 0 || !bop)
+               return -EINVAL;
+
+       bo = calloc(1, sizeof(*bo));
+       if (!bo)
+               return -ENOMEM;
+
+       priv = tegra_bo(bo);
+
+       DRMLISTINITHEAD(&priv->list);
+       atomic_set(&priv->ref, 1);
+       bo->device = device;
+       bo->flags = flags;
+       bo->size = size;
+
+       memset(&args, 0, sizeof(args));
+       args.flags = flags;
+       args.size = size;
+
+       err = drmCommandWriteRead(device->fd, DRM_TEGRA_GEM_CREATE, &args,

tegra/tegra.c line 145

Quoted 10 lines
tegra/tegra.c new file +10 -0
+                                 sizeof(args));
+       if (err < 0) {
+               err = -errno;
+               free(bo);
+               return err;
+       }
+
+       DRMLISTADD(&priv->list, &device->bo_list);
+       bo->handle = args.handle;
+       bo->offset = args.offset;

btw, x11 can rapidly create/destroy temporary pixmaps.. which don't necessarily need userspace access. You might prefer to avoid creating mmap offset on GEM bo creation, and instead do this only if userspace needs to mmap the bo

BR,
-R

Quoted 5 lines
tegra/tegra.c new file +5 -0
+
+       *bop = bo;
+
+       return 0;
+}
#5 lore raw
In reply to a message not in the archive
Quoted 37 lines · Rob Clark
Quoted 35 lines · Thierry Reding
tegra/tegra.c new file +35 -0
+int drm_tegra_bo_new(struct drm_tegra *device, uint32_t flags, uint32_t size,
+                    struct drm_tegra_bo **bop)
+{
+       struct drm_tegra_gem_create args;
+       struct drm_tegra_bo *bo;
+       struct tegra_bo *priv;
+       int err;
+
+       if (!device || size == 0 || !bop)
+               return -EINVAL;
+
+       bo = calloc(1, sizeof(*bo));
+       if (!bo)
+               return -ENOMEM;
+
+       priv = tegra_bo(bo);
+
+       DRMLISTINITHEAD(&priv->list);
+       atomic_set(&priv->ref, 1);
+       bo->device = device;
+       bo->flags = flags;
+       bo->size = size;
+
+       memset(&args, 0, sizeof(args));
+       args.flags = flags;
+       args.size = size;
+
+       err = drmCommandWriteRead(device->fd, DRM_TEGRA_GEM_CREATE, &args,
+                                 sizeof(args));
+       if (err < 0) {
+               err = -errno;
+               free(bo);
+               return err;
+       }
+
Quoted 8 lines

tegra/tegra.c line 145

Quoted 3 lines
tegra/tegra.c new file +3 -0
+       DRMLISTADD(&priv->list, &device->bo_list);
+       bo->handle = args.handle;
+       bo->offset = args.offset;

btw, x11 can rapidly create/destroy temporary pixmaps.. which don't necessarily need userspace access. You might prefer to avoid creating mmap offset on GEM bo creation, and instead do this only if userspace needs to mmap the bo

Ah, so that's the reason for the MMAP IOCTL provided by other DRMs. Yes, that might be better in the long run. For now I don't think it makes much of a difference since the GEM objects are backed by CMA, and therefore the offset will be created along with the GEM anyway.

With Terje's upcoming rework that handles all the allocations in host1x this should become more important, especially when the mapping is done through the Tegra30's IOMMU.

I'll rework that. Thanks for the quick reply.

Thierry

#7 lore raw
In reply to a message not in the archive
Quoted 15 lines · Thierry Reding
tegra/tegra.c new file +15 -0
+int drm_tegra_open(const char *path, struct drm_tegra **devicep)
+{
+       struct drm_tegra *device;
+       int err;
+
+       if (!path || !devicep)
+               return -EINVAL;
+
+       device = calloc(1, sizeof(*device));
+       if (!device)
+               return -ENOMEM;
+
+       DRMINITLISTHEAD(&device->bo_list);
+
+       device->fd = open(path, O_RDWR);

tegra/tegra.c line 98

Quoted 10 lines
tegra/tegra.c new file +10 -0
+       if (device->fd < 0) {
+               err = -errno;
+               free(device);
+               return err;
+       }
+
+       *devicep = device;
+
+       return 0;
+}

I think you shouldn't ask the path from the application (=DDX) here, but use drmOpen() that automatically finds the correct device for you.

I'd also prefer letting the application open and close the device and modify drm_tegra_open() to take the fd as a parameter. That way the DDX could easily access also all generic libdrm functions.

- Arto

#9 lore raw
In reply to a message not in the archive
Quoted 31 lines · Arto Merilainen
Quoted 15 lines · Thierry Reding
tegra/tegra.c new file +15 -0
+int drm_tegra_open(const char *path, struct drm_tegra **devicep)
+{
+       struct drm_tegra *device;
+       int err;
+
+       if (!path || !devicep)
+               return -EINVAL;
+
+       device = calloc(1, sizeof(*device));
+       if (!device)
+               return -ENOMEM;
+
+       DRMINITLISTHEAD(&device->bo_list);
+
+       device->fd = open(path, O_RDWR);

tegra/tegra.c line 98

Quoted 10 lines
tegra/tegra.c new file +10 -0
+       if (device->fd < 0) {
+               err = -errno;
+               free(device);
+               return err;
+       }
+
+       *devicep = device;
+
+       return 0;
+}

I think you shouldn't ask the path from the application (=DDX) here, but use drmOpen() that automatically finds the correct device for you.

Quoted 3 lines

I'd also prefer letting the application open and close the device and modify drm_tegra_open() to take the fd as a parameter. That way the DDX could easily access also all generic libdrm functions.

Good points, I'll take those into account.

Thanks,
Thierry