Update Tegra support
cover Update Tegra support
From: Thierry Reding <[email protected]>
Hi all,
this is the userspace part of the kernel patches that were recently merged into drm-next:
https://patchwork.freedesktop.org/series/92378/
The goal is to provide a userspace implementation of the UAPI exposed by the kernel and show its usage in some test programs that can also be used for basic sanity testing. More complete userspace implementations are available here:
* https://github.com/cyndis/vaapi-tegra-driver
* https://github.com/grate-driver/xf86-video-opentegra
* https://github.com/grate-driver/grate
Thierry
Thierry Reding (25):
tegra: Indent according to .editorconfig
tegra: Remove unused IOCTL implementations
tegra: Extract common buffer object allocation code
tegra: Fix mmap() of GEM buffer objects
tegra: Add flink helpers
tegra: Add PRIME support helpers
tegra: Make API more consistent
tegra: Install tegra-openclose test
tegra: Update for new UABI
tegra: Include private.h in list of source files
tegra: Add channel APIs
tegra: Add job and push buffer APIs
tegra: Add syncpoint APIs
tests: tegra: Add helper library for tests
tests: tegra: Add gr2d-fill test
tests: tegra: Add syncpt-wait test
tests: tegra: Add syncpoint timeout test
tests: tegra: Add VIC support
tests: tegra: Add VIC 3.0 support
tests: tegra: Add VIC 4.0 support
tests: tegra: Add VIC 4.1 support
tests: tegra: Add VIC 4.2 support
tests: tegra: Add VIC clear test
tests: tegra: Add VIC blit test
tests: tegra: Add VIC flip test
include/drm/tegra_drm.h | 429 +++++++++++++++++++++++-- tegra/channel.c | 195 ++++++++++++ tegra/job.c | 187 +++++++++++ tegra/meson.build | 7 +- tegra/private.h | 85 ++++- tegra/pushbuf.c | 184 +++++++++++ tegra/syncpt.c | 101 ++++++ tegra/tegra-symbols.txt | 27 +- tegra/tegra.c | 392 ++++++++++++----------- tegra/tegra.h | 95 +++++- tests/tegra/.gitignore | 3 +- tests/tegra/drm-test-tegra.c | 147 +++++++++ tests/tegra/drm-test-tegra.h | 55 ++++ tests/tegra/drm-test.c | 248 +++++++++++++++ tests/tegra/drm-test.h | 72 +++++ tests/tegra/gr2d-fill.c | 146 +++++++++ tests/tegra/host1x.h | 34 ++ tests/tegra/meson.build | 88 +++++- tests/tegra/openclose.c | 52 +-- tests/tegra/syncpt-timeout.c | 163 ++++++++++ tests/tegra/syncpt-wait.c | 151 +++++++++ tests/tegra/vic-blit.c | 333 +++++++++++++++++++ tests/tegra/vic-clear.c | 173 ++++++++++ tests/tegra/vic-flip.c | 333 +++++++++++++++++++ tests/tegra/vic.c | 177 +++++++++++ tests/tegra/vic.h | 181 +++++++++++ tests/tegra/vic30.c | 509 +++++++++++++++++++++++++++++ tests/tegra/vic30.h | 439 ++++++++++++++++++++++++++ tests/tegra/vic40.c | 412 ++++++++++++++++++++++++ tests/tegra/vic40.h | 285 +++++++++++++++++ tests/tegra/vic41.c | 416 ++++++++++++++++++++++++ tests/tegra/vic41.h | 372 ++++++++++++++++++++++ tests/tegra/vic42.c | 423 +++++++++++++++++++++++++ tests/tegra/vic42.h | 597 +++++++++++++++++++++++++++++++++++ 34 files changed, 7248 insertions(+), 263 deletions(-) create mode 100644 tegra/channel.c create mode 100644 tegra/job.c create mode 100644 tegra/pushbuf.c create mode 100644 tegra/syncpt.c 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/host1x.h create mode 100644 tests/tegra/syncpt-timeout.c create mode 100644 tests/tegra/syncpt-wait.c create mode 100644 tests/tegra/vic-blit.c create mode 100644 tests/tegra/vic-clear.c create mode 100644 tests/tegra/vic-flip.c create mode 100644 tests/tegra/vic.c create mode 100644 tests/tegra/vic.h create mode 100644 tests/tegra/vic30.c create mode 100644 tests/tegra/vic30.h create mode 100644 tests/tegra/vic40.c create mode 100644 tests/tegra/vic40.h create mode 100644 tests/tegra/vic41.c create mode 100644 tests/tegra/vic41.h create mode 100644 tests/tegra/vic42.c create mode 100644 tests/tegra/vic42.h
Signature · 1 line
2.32.0
PATCH 1/25 tegra: Indent according to .editorconfig
From: Thierry Reding <[email protected]>
Reindent the sources according to the settings found in the newly added .editorconfig.
--- tegra/private.h | 18 +- tegra/tegra.c | 354 ++++++++++++++++++++-------------------- tegra/tegra.h | 12 +- tests/tegra/openclose.c | 52 +++--- 4 files changed, 220 insertions(+), 216 deletions(-)
tegra/private.h +9 -9
@@ -34,18 +34,18 @@#include "tegra.h" struct drm_tegra { -bool close; -int fd; +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; +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__ */
tegra/tegra.c +179 -175
471 lines not on this page · raw message
tegra/tegra.h +6 -6
@@ -35,9 +35,9 @@ 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); +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); +uint32_t handle,uint32_t flags,uint32_t size);struct drm_tegra_bo *drm_tegra_bo_ref (struct drm_tegra_bo *bo);void drm_tegra_bo_unref (struct drm_tegra_bo *bo);int drm_tegra_bo_get_handle (struct drm_tegra_bo *bo,uint32_t *handle);
@@ -48,13 +48,13 @@ int drm_tegra_bo_get_flags(struct drm_tegra_bo *bo, uint32_t *flags);int drm_tegra_bo_set_flags (struct drm_tegra_bo *bo,uint32_t flags);struct drm_tegra_bo_tiling { -uint32_t mode; -uint32_t value; +uint32_t mode; +uint32_t value; };int drm_tegra_bo_get_tiling (struct drm_tegra_bo *bo, -struct drm_tegra_bo_tiling *tiling); +struct drm_tegra_bo_tiling *tiling);int drm_tegra_bo_set_tiling (struct drm_tegra_bo *bo, -const struct drm_tegra_bo_tiling *tiling); +const struct drm_tegra_bo_tiling *tiling);#endif /* __DRM_TEGRA_H__ */
tests/tegra/openclose.c +26 -26
63 lines not on this page · raw message
Signature · 1 line
2.32.0
PATCH 2/25 tegra: Remove unused IOCTL implementations
In reply to Thierry RedingFrom: Thierry Reding <[email protected]>
The DRM_TEGRA_GEM_{GET,SET}_FLAGS and DRM_TEGRA_GEM_{GET,SET}_TILING IOCTLs were badly designed and have since been obsoleted by framebuffer modifiers. Remove these implementations to make it clear their usage is discouraged.
--- tegra/tegra-symbols.txt | 4 -- tegra/tegra.c | 95 ----------------------------------------- tegra/tegra.h | 12 ------ 3 files changed, 111 deletions(-)
tegra/tegra-symbols.txt +0 -4
@@ -1,11 +1,7 @@ -drm_tegra_bo_get_flags drm_tegra_bo_get_handle -drm_tegra_bo_get_tiling drm_tegra_bo_map drm_tegra_bo_new drm_tegra_bo_ref -drm_tegra_bo_set_flags -drm_tegra_bo_set_tiling drm_tegra_bo_unmap drm_tegra_bo_unref drm_tegra_bo_wrap
tegra/tegra.c +0 -95
98 lines not on this page · raw message
tegra/tegra.h +0 -12
@@ -44,17 +44,5 @@ 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); -int drm_tegra_bo_get_flags (struct drm_tegra_bo *bo,uint32_t *flags); -int drm_tegra_bo_set_flags (struct drm_tegra_bo *bo,uint32_t flags); - -struct drm_tegra_bo_tiling { -uint32_t mode; -uint32_t value; -}; - -int drm_tegra_bo_get_tiling (struct drm_tegra_bo *bo, -struct drm_tegra_bo_tiling *tiling); -int drm_tegra_bo_set_tiling (struct drm_tegra_bo *bo, -const struct drm_tegra_bo_tiling *tiling);#endif /* __DRM_TEGRA_H__ */
Signature · 1 line
2.32.0
PATCH 3/25 tegra: Extract common buffer object allocation code
In reply to Thierry RedingFrom: Thierry Reding <[email protected]>
All of the buffer object allocation functions use the same boilerplate code. Move that code into a separate function that can be reused.
--- tegra/tegra.c | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-)
tegra/tegra.c +22 -13
@@ -101,6 +101,26 @@ drm_public void drm_tegra_close(struct drm_tegra *drm)free (drm); } +static struct drm_tegra_bo *drm_tegra_bo_alloc (struct drm_tegra *drm, +uint32_t handle, +uint32_t flags, +uint32_t size) +{ +struct drm_tegra_bo *bo; + + bo =calloc (1 ,sizeof (*bo)); +if (!bo) +return NULL ; + +atomic_set (&bo->ref,1 ); + bo->handle = handle; + bo->flags = flags; + bo->size = size; + bo->drm = drm; + +return bo; +} + drm_public intdrm_tegra_bo_new (struct drm_tegra_bo **bop,struct drm_tegra *drm,uint32_t flags,uint32_t size)
@@ -112,15 +132,10 @@ drm_tegra_bo_new(struct drm_tegra_bo **bop, struct drm_tegra *drm,if (!drm || size ==0 || !bop)return -EINVAL ; - bo =calloc (1 ,sizeof (*bo)); + bo =drm_tegra_bo_alloc (drm,0 , flags, size);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;
@@ -149,16 +164,10 @@ drm_tegra_bo_wrap(struct drm_tegra_bo **bop, struct drm_tegra *drm,if (!drm || !bop)return -EINVAL ; - bo =calloc (1 ,sizeof (*bo)); + bo =drm_tegra_bo_alloc (drm, handle, flags, size);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 ;
Signature · 1 line
2.32.0
PATCH 4/25 tegra: Fix mmap() of GEM buffer objects
In reply to Thierry RedingFrom: Thierry Reding <[email protected]>
Store 64-bit offset values and use libdrm's built-in drm_mmap() function instead of mmap() to ensure the full 64-bit offset is used.
--- tegra/private.h | 2 +- tegra/tegra.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-)
tegra/private.h +1 -1
@@ -41,7 +41,7 @@ struct drm_tegra {struct drm_tegra_bo {struct drm_tegra *drm;uint32_t handle; -uint32_t offset; +uint64_t offset;uint32_t flags;uint32_t size;atomic_t ref;
tegra/tegra.c +2 -2
@@ -215,8 +215,8 @@ drm_public int drm_tegra_bo_map(struct drm_tegra_bo *bo, void **ptr) bo->offset = args.offset; - bo->map =mmap (0 , bo->size,PROT_READ |PROT_WRITE ,MAP_SHARED , - drm->fd, bo->offset); + bo->map =drm_mmap (NULL , bo->size,PROT_READ |PROT_WRITE ,MAP_SHARED , + drm->fd, bo->offset);if (bo->map ==MAP_FAILED ) { bo->map =NULL ;return -errno;
Signature · 1 line
2.32.0
PATCH 5/25 tegra: Add flink helpers
In reply to Thierry RedingFrom: Thierry Reding <[email protected]>
Add helpers to export and import buffer objects via flink names.
---
Changes in v3:
- add drm_public annotations
--- tegra/tegra-symbols.txt | 2 ++ tegra/tegra.c | 50 +++++++++++++++++++++++++++++++++++++++++ tegra/tegra.h | 3 +++ 3 files changed, 55 insertions(+)
tegra/tegra-symbols.txt +2 -0
@@ -1,6 +1,8 @@ drm_tegra_bo_get_handle +drm_tegra_bo_get_name drm_tegra_bo_map drm_tegra_bo_new +drm_tegra_bo_open drm_tegra_bo_ref drm_tegra_bo_unmap drm_tegra_bo_unref
tegra/tegra.c +50 -0
53 lines not on this page · raw message
tegra/tegra.h +3 -0
@@ -44,5 +44,8 @@ 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); +int drm_tegra_bo_get_name (struct drm_tegra_bo *bo,uint32_t *name); +int drm_tegra_bo_open (struct drm_tegra *drm,uint32_t name,uint32_t flags, +struct drm_tegra_bo **bop);#endif /* __DRM_TEGRA_H__ */
Signature · 1 line
2.32.0
PATCH 6/25 tegra: Add PRIME support helpers
In reply to Thierry RedingFrom: Thierry Reding <[email protected]>
These helpers facilitate exporting and importing buffer objects to and from PRIME file descriptors.
---
Changes in v3:
- add drm_public annotations
--- tegra/tegra-symbols.txt | 2 ++ tegra/tegra.c | 61 +++++++++++++++++++++++++++++++++++++++++ tegra/tegra.h | 4 +++ 3 files changed, 67 insertions(+)
tegra/tegra-symbols.txt +2 -0
@@ -1,5 +1,7 @@ +drm_tegra_bo_export drm_tegra_bo_get_handle drm_tegra_bo_get_name +drm_tegra_bo_import drm_tegra_bo_map drm_tegra_bo_new drm_tegra_bo_open
tegra/tegra.c +61 -0
64 lines not on this page · raw message
tegra/tegra.h +4 -0
@@ -48,4 +48,8 @@ int drm_tegra_bo_get_name(struct drm_tegra_bo *bo, uint32_t *name);int drm_tegra_bo_open (struct drm_tegra *drm,uint32_t name,uint32_t flags,struct drm_tegra_bo **bop); +int drm_tegra_bo_export (struct drm_tegra_bo *bo,uint32_t flags); +int drm_tegra_bo_import (struct drm_tegra *drm,int fd, +struct drm_tegra_bo **bop); +#endif /* __DRM_TEGRA_H__ */
Signature · 1 line
2.32.0
PATCH 7/25 tegra: Make API more consistent
In reply to Thierry RedingFrom: Thierry Reding <[email protected]>
Most functions in libdrm_tegra take as first parameter the object that they operate on. Make the device and buffer object creation functions follow the same scheme.
--- tegra/tegra.c | 13 +++++++------ tegra/tegra.h | 10 +++++----- tests/tegra/openclose.c | 2 +- 3 files changed, 13 insertions(+), 12 deletions(-)
tegra/tegra.c +7 -6
@@ -70,7 +70,7 @@ static int drm_tegra_wrap(struct drm_tegra **drmp, int fd, bool close)return 0 ; } -drm_public int drm_tegra_new(struct drm_tegra **drmp, int fd) +drm_public int drm_tegra_new(int fd, struct drm_tegra **drmp) {bool supported = false;drmVersionPtr version;
@@ -122,8 +122,8 @@ static struct drm_tegra_bo *drm_tegra_bo_alloc(struct drm_tegra *drm, } drm_public int -drm_tegra_bo_new (struct drm_tegra_bo **bop,struct drm_tegra *drm, -uint32_t flags,uint32_t size) +drm_tegra_bo_new (struct drm_tegra *drm,uint32_t flags,uint32_t size, +struct drm_tegra_bo **bop) {struct drm_tegra_gem_create args;struct drm_tegra_bo *bo;
@@ -156,8 +156,8 @@ drm_tegra_bo_new(struct drm_tegra_bo **bop, struct drm_tegra *drm, } drm_public int -drm_tegra_bo_wrap (struct drm_tegra_bo **bop,struct drm_tegra *drm, -uint32_t handle,uint32_t flags,uint32_t size) +drm_tegra_bo_wrap (struct drm_tegra *drm,uint32_t handle,uint32_t flags, +uint32_t size,struct drm_tegra_bo **bop) {struct drm_tegra_bo *bo;
@@ -187,7 +187,8 @@ drm_public void drm_tegra_bo_unref(struct drm_tegra_bo *bo)drm_tegra_bo_free (bo); } -drm_public int drm_tegra_bo_get_handle(struct drm_tegra_bo *bo, uint32_t *handle) +drm_public int +drm_tegra_bo_get_handle (struct drm_tegra_bo *bo,uint32_t *handle) {if (!bo || !handle)return -EINVAL ;
tegra/tegra.h +5 -5
@@ -31,13 +31,13 @@struct drm_tegra_bo ;struct drm_tegra ; -int drm_tegra_new (struct drm_tegra **drmp,int fd); +int drm_tegra_new (int fd,struct drm_tegra **drmp);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); +int drm_tegra_bo_new (struct drm_tegra *drm,uint32_t flags,uint32_t size, +struct drm_tegra_bo **bop); +int drm_tegra_bo_wrap (struct drm_tegra *drm,uint32_t handle,uint32_t flags, +uint32_t size,struct drm_tegra_bo **bop);struct drm_tegra_bo *drm_tegra_bo_ref (struct drm_tegra_bo *bo);void drm_tegra_bo_unref (struct drm_tegra_bo *bo);int drm_tegra_bo_get_handle (struct drm_tegra_bo *bo,uint32_t *handle);
tests/tegra/openclose.c +1 -1
@@ -56,7 +56,7 @@ int main(int argc, char *argv[])drmFreeVersion (version); } - err =drm_tegra_new (&tegra, fd); + err =drm_tegra_new (fd, &tegra);if (err <0 )return 1 ;
Signature · 1 line
2.32.0
PATCH 8/25 tegra: Install tegra-openclose test
In reply to Thierry RedingFrom: Thierry Reding <[email protected]>
Allow this simple test to be installed so that it can easily be run on a target device.
--- tests/tegra/.gitignore | 2 +- tests/tegra/meson.build | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-)
tests/tegra/.gitignore +1 -1
@@ -1 +1 @@ -openclose +tegra-openclose
tests/tegra/meson.build +5 -2
@@ -18,10 +18,13 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. +inc_tegra = include_directories('../../tegra') + openclose = executable( - 'openclose', + 'tegra-openclose', files('openclose.c'), - include_directories : [inc_root, inc_drm, include_directories('../../tegra')], + include_directories : [inc_root, inc_drm, inc_tegra], c_args : libdrm_c_args, link_with : [libdrm, libdrm_tegra], + install : with_install_tests, )
Signature · 1 line
2.32.0
PATCH 9/25 tegra: Update for new UABI
In reply to Thierry RedingFrom: Thierry Reding <[email protected]>
This new UABI is a more modern version that works better with both old and recent chips.
--- include/drm/tegra_drm.h | 429 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 404 insertions(+), 25 deletions(-)
include/drm/tegra_drm.h +404 -25
@@ -1,27 +1,8 @@ -/* -* 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, 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. -*/ +/* SPDX-License-Identifier: MIT */ +/* Copyright (c) 2012-2020 NVIDIA Corporation */ -#ifndef _TEGRA_DRM_H_ -#define _TEGRA_DRM_H_ +#ifndef _UAPI_TEGRA_DRM_H_ +#define _UAPI_TEGRA_DRM_H_#include "drm.h"
@@ -29,6 +10,8 @@extern "C" {#endif +/* Tegra DRM legacy UAPI. Only enabled with STAGING */ +#define DRM_TEGRA_GEM_CREATE_TILED (1 << 0)#define DRM_TEGRA_GEM_CREATE_BOTTOM_UP (1 << 1)
@@ -649,8 +632,8 @@ struct drm_tegra_gem_get_flags {#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_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
@@ -674,6 +657,402 @@ struct drm_tegra_gem_get_flags {#define DRM_IOCTL_TEGRA_GEM_SET_FLAGS DRM_IOWR(DRM_COMMAND_BASE + DRM_TEGRA_GEM_SET_FLAGS, struct drm_tegra_gem_set_flags)#define DRM_IOCTL_TEGRA_GEM_GET_FLAGS DRM_IOWR(DRM_COMMAND_BASE + DRM_TEGRA_GEM_GET_FLAGS, struct drm_tegra_gem_get_flags) +/* New Tegra DRM UAPI */ + +/* +* Reported by the driver in the `capabilities` field. +* +* DRM_TEGRA_CHANNEL_CAP_CACHE_COHERENT: If set, the engine is cache coherent +* with regard to the system memory. +*/ +#define DRM_TEGRA_CHANNEL_CAP_CACHE_COHERENT (1 << 0) + +struct drm_tegra_channel_open { +/** +* @host1x_class: [in] +* +* Host1x class of the engine that will be programmed using this +* channel. +*/ +__u32 host1x_class; + +/** +* @flags: [in] +* +* Flags. +*/ +__u32 flags; + +/** +* @context: [out] +* +* Opaque identifier corresponding to the opened channel. +*/ +__u32 context; + +/** +* @version: [out] +* +* Version of the engine hardware. This can be used by userspace +* to determine how the engine needs to be programmed. +*/ +__u32 version; + +/** +* @capabilities: [out] +* +* Flags describing the hardware capabilities. +*/ +__u32 capabilities; +__u32 padding; +}; + +struct drm_tegra_channel_close { +/** +* @context: [in] +* +* Identifier of the channel to close. +*/ +__u32 context; +__u32 padding; +}; + +/* +* Mapping flags that can be used to influence how the mapping is created. +* +* DRM_TEGRA_CHANNEL_MAP_READ: create mapping that allows HW read access +* DRM_TEGRA_CHANNEL_MAP_WRITE: create mapping that allows HW write access +*/ +#define DRM_TEGRA_CHANNEL_MAP_READ (1 << 0) +#define DRM_TEGRA_CHANNEL_MAP_WRITE (1 << 1) +#define DRM_TEGRA_CHANNEL_MAP_READ_WRITE (DRM_TEGRA_CHANNEL_MAP_READ | \ + DRM_TEGRA_CHANNEL_MAP_WRITE) + +struct drm_tegra_channel_map { +/** +* @context: [in] +* +* Identifier of the channel to which make memory available for. +*/ +__u32 context; + +/** +* @handle: [in] +* +* GEM handle of the memory to map. +*/ +__u32 handle; + +/** +* @flags: [in] +* +* Flags. +*/ +__u32 flags; + +/** +* @mapping: [out] +* +* Identifier corresponding to the mapping, to be used for +* relocations or unmapping later. +*/ +__u32 mapping; +}; + +struct drm_tegra_channel_unmap { +/** +* @context: [in] +* +* Channel identifier of the channel to unmap memory from. +*/ +__u32 context; + +/** +* @mapping: [in] +* +* Mapping identifier of the memory mapping to unmap. +*/ +__u32 mapping; +}; + +/* Submission */ + +/** +* Specify that bit 39 of the patched-in address should be set to switch +* swizzling between Tegra and non-Tegra sector layout on systems that store +* surfaces in system memory in non-Tegra sector layout. +*/ +#define DRM_TEGRA_SUBMIT_RELOC_SECTOR_LAYOUT (1 << 0) + +struct drm_tegra_submit_buf { +/** +* @mapping: [in] +* +* Identifier of the mapping to use in the submission. +*/ +__u32 mapping; + +/** +* @flags: [in] +* +* Flags. +*/ +__u32 flags; + +/** +* Information for relocation patching. +*/ +struct { +/** +* @target_offset: [in] +* +* Offset from the start of the mapping of the data whose +* address is to be patched into the gather. +*/ +__u64 target_offset; + +/** +* @gather_offset_words: [in] +* +* Offset in words from the start of the gather data to +* where the address should be patched into. +*/ +__u32 gather_offset_words; + +/** +* @shift: [in] +* +* Number of bits the address should be shifted right before +* patching in. +*/ +__u32 shift; + } reloc; +}; + +/** +* Execute `words` words of Host1x opcodes specified in the `gather_data_ptr` +* buffer. Each GATHER_UPTR command uses successive words from the buffer. +*/ +#define DRM_TEGRA_SUBMIT_CMD_GATHER_UPTR 0 +/** +* Wait for a syncpoint to reach a value before continuing with further +* commands. +*/ +#define DRM_TEGRA_SUBMIT_CMD_WAIT_SYNCPT 1 +/** +* Wait for a syncpoint to reach a value before continuing with further +* commands. The threshold is calculated relative to the start of the job. +*/ +#define DRM_TEGRA_SUBMIT_CMD_WAIT_SYNCPT_RELATIVE 2 + +struct drm_tegra_submit_cmd_gather_uptr { +__u32 words; +__u32 reserved[3 ]; +}; + +struct drm_tegra_submit_cmd_wait_syncpt { +__u32 id; +__u32 value; +__u32 reserved[2 ]; +}; + +struct drm_tegra_submit_cmd { +/** +* @type: [in] +* +* Command type to execute. One of the DRM_TEGRA_SUBMIT_CMD* +* defines. +*/ +__u32 type; + +/** +* @flags: [in] +* +* Flags. +*/ +__u32 flags; + +union { +struct drm_tegra_submit_cmd_gather_uptr gather_uptr; +struct drm_tegra_submit_cmd_wait_syncpt wait_syncpt; +__u32 reserved[4 ]; + }; +}; + +struct drm_tegra_submit_syncpt { +/** +* @id: [in] +* +* ID of the syncpoint that the job will increment. +*/ +__u32 id; + +/** +* @flags: [in] +* +* Flags. +*/ +__u32 flags; + +/** +* @increments: [in] +* +* Number of times the job will increment this syncpoint. +*/ +__u32 increments; + +/** +* @value: [out] +* +* Value the syncpoint will have once the job has completed all +* its specified syncpoint increments. +* +* Note that the kernel may increment the syncpoint before or after +* the job. These increments are not reflected in this field. +* +* If the job hangs or times out, not all of the increments may +* get executed. +*/ +__u32 value; +}; + +struct drm_tegra_channel_submit { +/** +* @context: [in] +* +* Identifier of the channel to submit this job to. +*/ +__u32 context; + +/** +* @num_bufs: [in] +* +* Number of elements in the `bufs_ptr` array. +*/ +__u32 num_bufs; + +/** +* @num_cmds: [in] +* +* Number of elements in the `cmds_ptr` array. +*/ +__u32 num_cmds; + +/** +* @gather_data_words: [in] +* +* Number of 32-bit words in the `gather_data_ptr` array. +*/ +__u32 gather_data_words; + +/** +* @bufs_ptr: [in] +* +* Pointer to an array of drm_tegra_submit_buf structures. +*/ +__u64 bufs_ptr; + +/** +* @cmds_ptr: [in] +* +* Pointer to an array of drm_tegra_submit_cmd structures. +*/ +__u64 cmds_ptr; + +/** +* @gather_data_ptr: [in] +* +* Pointer to an array of Host1x opcodes to be used by GATHER_UPTR +* commands. +*/ +__u64 gather_data_ptr; + +/** +* @syncobj_in: [in] +* +* Handle for DRM syncobj that will be waited before submission. +* Ignored if zero. +*/ +__u32 syncobj_in; + +/** +* @syncobj_out: [in] +* +* Handle for DRM syncobj that will have its fence replaced with +* the job's completion fence. Ignored if zero. +*/ +__u32 syncobj_out; + +/** +* @syncpt_incr: [in,out] +* +* Information about the syncpoint the job will increment. +*/ +struct drm_tegra_submit_syncpt syncpt; +}; + +struct drm_tegra_syncpoint_allocate { +/** +* @id: [out] +* +* ID of allocated syncpoint. +*/ +__u32 id; +__u32 padding; +}; + +struct drm_tegra_syncpoint_free { +/** +* @id: [in] +* +* ID of syncpoint to free. +*/ +__u32 id; +__u32 padding; +}; + +struct drm_tegra_syncpoint_wait { +/** +* @timeout: [in] +* +* Absolute timestamp at which the wait will time out. +*/ +__s64 timeout_ns; + +/** +* @id: [in] +* +* ID of syncpoint to wait on. +*/ +__u32 id; + +/** +* @threshold: [in] +* +* Threshold to wait for. +*/ +__u32 threshold; + +/** +* @value: [out] +* +* Value of the syncpoint upon wait completion. +*/ +__u32 value; + +__u32 padding; +}; + +#define DRM_IOCTL_TEGRA_CHANNEL_OPEN DRM_IOWR(DRM_COMMAND_BASE + 0x10, struct drm_tegra_channel_open) +#define DRM_IOCTL_TEGRA_CHANNEL_CLOSE DRM_IOWR(DRM_COMMAND_BASE + 0x11, struct drm_tegra_channel_close) +#define DRM_IOCTL_TEGRA_CHANNEL_MAP DRM_IOWR(DRM_COMMAND_BASE + 0x12, struct drm_tegra_channel_map) +#define DRM_IOCTL_TEGRA_CHANNEL_UNMAP DRM_IOWR(DRM_COMMAND_BASE + 0x13, struct drm_tegra_channel_unmap) +#define DRM_IOCTL_TEGRA_CHANNEL_SUBMIT DRM_IOWR(DRM_COMMAND_BASE + 0x14, struct drm_tegra_channel_submit) + +#define DRM_IOCTL_TEGRA_SYNCPOINT_ALLOCATE DRM_IOWR(DRM_COMMAND_BASE + 0x20, struct drm_tegra_syncpoint_allocate) +#define DRM_IOCTL_TEGRA_SYNCPOINT_FREE DRM_IOWR(DRM_COMMAND_BASE + 0x21, struct drm_tegra_syncpoint_free) +#define DRM_IOCTL_TEGRA_SYNCPOINT_WAIT DRM_IOWR(DRM_COMMAND_BASE + 0x22, struct drm_tegra_syncpoint_wait) +#if defined(__cplusplus) }#endif
Signature · 1 line
2.32.0
PATCH 10/25 tegra: Include private.h in list of source files
In reply to Thierry RedingFrom: Thierry Reding <[email protected]>
This makes sure that the proper dependencies are created and that the file is distributed.
--- tegra/meson.build | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
tegra/meson.build +6 -1
@@ -20,7 +20,12 @@ libdrm_tegra = library( 'drm_tegra', - [files('tegra.c'), config_file], + [ + files( + 'private.h', 'tegra.c' + ), + config_file + ], include_directories : [inc_root, inc_drm], link_with : libdrm, dependencies : [dep_pthread_stubs, dep_atomic_ops],
Signature · 1 line
2.32.0
PATCH 11/25 tegra: Add channel APIs
In reply to Thierry RedingFrom: Thierry Reding <[email protected]>
These new functions can be used to open a channel to a given engine, map and unmap buffer objects to that channel, and close the channel.
--- tegra/channel.c | 195 ++++++++++++++++++++++++++++++++++++++++ tegra/meson.build | 2 +- tegra/private.h | 24 +++++ tegra/tegra-symbols.txt | 5 ++ tegra/tegra.h | 22 +++++ 5 files changed, 247 insertions(+), 1 deletion(-) create mode 100644 tegra/channel.c
tegra/channel.c new file +195 -0
@@ -0,0 +1,195 @@ +/* +* Copyright © 2012, 2013 Thierry Reding +* Copyright © 2013 Erik Faye-Lund +* Copyright © 2014-2021 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 <sys/ioctl.h> + +#include "private.h" + +drm_public int +drm_tegra_channel_open (struct drm_tegra *drm, +enum drm_tegra_class client, +struct drm_tegra_channel **channelp) +{ +struct drm_tegra_channel_open args; +struct drm_tegra_channel *channel; +enum host1x_class class; +int err; + +switch (client) { +case DRM_TEGRA_HOST1X : + class =HOST1X_CLASS_HOST1X ; +break ; + +case DRM_TEGRA_GR2D : + class =HOST1X_CLASS_GR2D ; +break ; + +case DRM_TEGRA_GR3D : + class =HOST1X_CLASS_GR3D ; +break ; + +case DRM_TEGRA_VIC : + class =HOST1X_CLASS_VIC ; +break ; + +default : +return -EINVAL ; + } + + channel =calloc (1 ,sizeof (*channel)); +if (!channel) +return -ENOMEM ; + + channel->drm = drm; + +memset (&args,0 ,sizeof (args)); + args.host1x_class = class; + + err =ioctl (drm->fd,DRM_IOCTL_TEGRA_CHANNEL_OPEN , &args); +if (err <0 ) { +free (channel); +return -errno; + } + + channel->context = args.context; + channel->version = args.version; + channel->capabilities = args.capabilities; + channel->class = class; + +switch (channel->version) { +case 0x20 : +case 0x30 : +case 0x35 : +case 0x40 : +case 0x21 : + channel->cond_shift =8 ; +break ; + +case 0x18 : +case 0x19 : + channel->cond_shift =10 ; +break ; + +default : +return -ENOTSUP ; + } + + *channelp = channel; + +return 0 ; +} + +drm_public int drm_tegra_channel_close(struct drm_tegra_channel *channel) +{ +struct drm_tegra_channel_close 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_CHANNEL_CLOSE , &args); +if (err <0 ) +return -errno; + +free (channel); + +return 0 ; +} + +drm_public unsigned int +drm_tegra_channel_get_version (struct drm_tegra_channel *channel) +{ +return channel->version; +} + +drm_public int +drm_tegra_channel_map (struct drm_tegra_channel *channel, +struct drm_tegra_bo *bo,uint32_t flags, +struct drm_tegra_mapping **mapp) +{ +struct drm_tegra *drm = channel->drm; +struct drm_tegra_channel_map args; +struct drm_tegra_mapping *map; +int err; + +if (!drm || !bo || !mapp) +return -EINVAL ; + + map =calloc (1 ,sizeof (*map)); +if (!map) +return -ENOMEM ; + +memset (&args,0 ,sizeof (args)); + args.context = channel->context; + args.handle = bo->handle; + args.flags = flags; + + err =ioctl (drm->fd,DRM_IOCTL_TEGRA_CHANNEL_MAP , &args); +if (err <0 ) { +free (map); +return -errno; + } + + map->channel = channel; + map->id = args.mapping; + *mapp = map; + +return 0 ; +} + +drm_public int +drm_tegra_channel_unmap (struct drm_tegra_mapping *map) +{ +struct drm_tegra_channel *channel = map->channel; +struct drm_tegra *drm = channel->drm; +struct drm_tegra_channel_unmap args; +int err; + +if (!channel || !map) +return -EINVAL ; + +memset (&args,0 ,sizeof (args)); + args.context = channel->context; + args.mapping = map->id; + + err =ioctl (drm->fd,DRM_IOCTL_TEGRA_CHANNEL_UNMAP , &args); +if (err <0 ) +return -errno; + +free (map); +return 0 ; +}
tegra/meson.build +1 -1
@@ -22,7 +22,7 @@ libdrm_tegra = library( 'drm_tegra', [ files( - 'private.h', 'tegra.c' + 'channel.c', 'private.h', 'tegra.c' ), config_file ],
tegra/private.h +24 -0
@@ -31,8 +31,17 @@#include <libdrm_macros.h> #include <xf86atomic.h> +#include "tegra_drm.h" #include "tegra.h" +enum host1x_class { +HOST1X_CLASS_HOST1X =0x01 , +HOST1X_CLASS_GR2D =0x51 , +HOST1X_CLASS_GR2D_SB =0x52 , +HOST1X_CLASS_VIC =0x5d , +HOST1X_CLASS_GR3D =0x60 , +}; +struct drm_tegra {bool close;int fd;
@@ -48,4 +57,19 @@ struct drm_tegra_bo { void *map; }; +struct drm_tegra_channel { +struct drm_tegra *drm; +enum host1x_class class; +uint32_t capabilities; +unsigned int version; +uint64_t context; + +unsigned int cond_shift; +}; + +struct drm_tegra_mapping { +struct drm_tegra_channel *channel; +uint32_t id; +}; +#endif /* __DRM_TEGRA_PRIVATE_H__ */
tegra/tegra-symbols.txt +5 -0
@@ -9,5 +9,10 @@ drm_tegra_bo_ref drm_tegra_bo_unmap drm_tegra_bo_unref drm_tegra_bo_wrap +drm_tegra_channel_close +drm_tegra_channel_get_version +drm_tegra_channel_map +drm_tegra_channel_open +drm_tegra_channel_unmap drm_tegra_close drm_tegra_new
tegra/tegra.h +22 -0
@@ -28,6 +28,15 @@#include <stdint.h> #include <stdlib.h> +#include <tegra_drm.h> + +enum drm_tegra_class { +DRM_TEGRA_HOST1X , +DRM_TEGRA_GR2D , +DRM_TEGRA_GR3D , +DRM_TEGRA_VIC , +}; +struct drm_tegra_bo ;struct drm_tegra ;
@@ -52,4 +61,17 @@ int drm_tegra_bo_export(struct drm_tegra_bo *bo, uint32_t flags);int drm_tegra_bo_import (struct drm_tegra *drm,int fd,struct drm_tegra_bo **bop); +struct drm_tegra_channel ; +struct drm_tegra_mapping ; + +int drm_tegra_channel_open (struct drm_tegra *drm, +enum drm_tegra_class client, +struct drm_tegra_channel **channelp); +int drm_tegra_channel_close (struct drm_tegra_channel *channel); +unsigned int drm_tegra_channel_get_version (struct drm_tegra_channel *channel); +int drm_tegra_channel_map (struct drm_tegra_channel *channel, +struct drm_tegra_bo *bo,uint32_t flags, +struct drm_tegra_mapping **mapp); +int drm_tegra_channel_unmap (struct drm_tegra_mapping *map); +#endif /* __DRM_TEGRA_H__ */
Signature · 1 line
2.32.0
PATCH 12/25 tegra: Add job and push buffer APIs
In reply to Thierry RedingFrom: Thierry Reding <[email protected]>
These new functions can be used to create a job on a given channel, add commands to the job using its push buffer and submit the job.
--- tegra/job.c | 164 ++++++++++++++++++++++++++++++++++++++++ tegra/meson.build | 2 +- tegra/private.h | 32 ++++++++ tegra/pushbuf.c | 136 +++++++++++++++++++++++++++++++++ tegra/tegra-symbols.txt | 7 ++ tegra/tegra.h | 34 +++++++++ 6 files changed, 374 insertions(+), 1 deletion(-) create mode 100644 tegra/job.c create mode 100644 tegra/pushbuf.c
tegra/job.c new file +164 -0
@@ -0,0 +1,164 @@ +/* +* 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 <time.h> +#include <unistd.h> + +#include <sys/ioctl.h> +#include <sys/poll.h> + +#include "private.h" + +struct drm_tegra_submit_cmd * +drm_tegra_job_add_command (struct drm_tegra_job *job,uint32_t type, +uint32_t flags) +{ +struct drm_tegra_submit_cmd *commands, *command; +size_t size; + + size = (job->num_commands +1 ) *sizeof (*commands); + + commands =realloc (job->commands, size); +if (!commands) +return NULL ; + + command = &commands[job->num_commands]; +memset (command,0 ,sizeof (*command)); + command->type = type; + command->flags = flags; + + job->commands = commands; + job->num_commands++; + +return command; +} + +drm_public int +drm_tegra_job_new (struct drm_tegra_channel *channel, +struct drm_tegra_job **jobp) +{ +struct drm_tegra_job *job; + + job =calloc (1 ,sizeof (*job)); +if (!job) +return -ENOMEM ; + + job->page_size =sysconf (_SC_PAGESIZE); + job->channel = channel; + + *jobp = job; + +return 0 ; +} + +drm_public int drm_tegra_job_free(struct drm_tegra_job *job) +{ +if (!job) +return -EINVAL ; + +if (job->pushbuf) +drm_tegra_pushbuf_free (job->pushbuf); + +if (job->commands) +free (job->commands); + +if (job->buffers) +free (job->buffers); + +free (job); + +return 0 ; +} + +drm_public int +drm_tegra_job_get_pushbuf (struct drm_tegra_job *job, +struct drm_tegra_pushbuf **pushbufp) +{ +struct drm_tegra_pushbuf *pushbuf; + +if (!job->pushbuf) { + pushbuf =calloc (1 ,sizeof (*pushbuf)); +if (!pushbuf) +return -ENOMEM ; + + pushbuf->job = job; + + pushbuf->start =calloc (1 , job->page_size); +if (!pushbuf->start) { +free (pushbuf); +return -ENOMEM ; + } + + pushbuf->end = pushbuf->start + job->page_size /4 ; + pushbuf->ptr = pushbuf->start; + + job->pushbuf = pushbuf; + } + + *pushbufp = job->pushbuf; + +return 0 ; +} + +drm_public int +drm_tegra_job_submit (struct drm_tegra_job *job,struct drm_tegra_fence *fence) +{ +struct drm_tegra_channel *channel = job->channel; +struct drm_tegra *drm = channel->drm; +struct drm_tegra_channel_submit args; +int err; + +memset (&args,0 ,sizeof (args)); + args.context = channel->context; + args.num_bufs = job->num_buffers; + args.num_cmds = job->num_commands; + args.gather_data_words = job->pushbuf->ptr - job->pushbuf->start; + args.syncpt.id = job->syncpt.id; + args.syncpt.increments = job->syncpt.increments; + + args.bufs_ptr = (uintptr_t )job->buffers; + args.cmds_ptr = (uintptr_t )job->commands; + args.gather_data_ptr = (uintptr_t )job->pushbuf->start; + + err =ioctl (drm->fd,DRM_IOCTL_TEGRA_CHANNEL_SUBMIT , &args); +if (err <0 ) +return -errno; + + job->syncpt.fence = args.syncpt.value; + +if (fence) { + fence->drm = drm; + fence->syncpt = job->syncpt.id; + fence->value = job->syncpt.fence; + } + +return 0 ; +}
tegra/meson.build +1 -1
@@ -22,7 +22,7 @@ libdrm_tegra = library( 'drm_tegra', [ files( - 'channel.c', 'private.h', 'tegra.c' + 'channel.c', 'job.c', 'private.h', 'pushbuf.c', 'tegra.c' ), config_file ],
tegra/private.h +32 -0
@@ -72,4 +72,36 @@ struct drm_tegra_mapping { uint32_t id; }; +struct drm_tegra_pushbuf { +struct drm_tegra_job *job; + +uint32_t *start; +uint32_t *end; +uint32_t *ptr; +}; + +void drm_tegra_pushbuf_free (struct drm_tegra_pushbuf *pushbuf); + +struct drm_tegra_job { +struct drm_tegra_channel *channel; +struct drm_tegra_pushbuf *pushbuf; +size_t page_size; + +struct drm_tegra_submit_cmd *commands; +unsigned int num_commands; + +struct drm_tegra_submit_buf *buffers; +unsigned int num_buffers; + +struct { +uint32_t id; +uint32_t increments; +uint32_t fence; + } syncpt; +}; + +struct drm_tegra_submit_cmd * +drm_tegra_job_add_command (struct drm_tegra_job *job,uint32_t type, +uint32_t flags); +#endif /* __DRM_TEGRA_PRIVATE_H__ */
tegra/pushbuf.c new file +136 -0
136 lines not on this page · raw message
tegra/tegra-symbols.txt +7 -0
@@ -15,4 +15,11 @@ drm_tegra_channel_map drm_tegra_channel_open drm_tegra_channel_unmap drm_tegra_close +drm_tegra_job_free +drm_tegra_job_get_pushbuf +drm_tegra_job_new +drm_tegra_job_submit drm_tegra_new +drm_tegra_pushbuf_begin +drm_tegra_pushbuf_end +drm_tegra_pushbuf_relocate
tegra/tegra.h +34 -0
@@ -63,6 +63,22 @@ int drm_tegra_bo_import(struct drm_tegra *drm, int fd,struct drm_tegra_channel ;struct drm_tegra_mapping ; +struct drm_tegra_pushbuf ; +struct drm_tegra_job ; + +enum drm_tegra_sync_cond { +DRM_TEGRA_SYNC_COND_IMMEDIATE , +DRM_TEGRA_SYNC_COND_OP_DONE , +DRM_TEGRA_SYNC_COND_RD_DONE , +DRM_TEGRA_SYNC_COND_WR_SAFE , +DRM_TEGRA_SYNC_COND_MAX , + }; + +struct drm_tegra_fence { +struct drm_tegra *drm; +uint32_t syncpt; +uint32_t value; +}; int drm_tegra_channel_open(struct drm_tegra *drm, enum drm_tegra_class client,
@@ -74,4 +90,22 @@ int drm_tegra_channel_map(struct drm_tegra_channel *channel, struct drm_tegra_mapping **mapp);int drm_tegra_channel_unmap (struct drm_tegra_mapping *map); +int drm_tegra_job_new (struct drm_tegra_channel *channel, +struct drm_tegra_job **jobp); +int drm_tegra_job_free (struct drm_tegra_job *job); +int drm_tegra_job_get_pushbuf (struct drm_tegra_job *job, +struct drm_tegra_pushbuf **pushbufp); +int drm_tegra_job_submit (struct drm_tegra_job *job, +struct drm_tegra_fence *fence); +int drm_tegra_job_wait (struct drm_tegra_job *job,unsigned long timeout); + +int drm_tegra_pushbuf_begin (struct drm_tegra_pushbuf *pushbuf, +unsigned int words,uint32_t **ptrp); +int drm_tegra_pushbuf_end (struct drm_tegra_pushbuf *pushbuf,uint32_t *ptr); +int drm_tegra_pushbuf_relocate (struct drm_tegra_pushbuf *pushbuf, +uint32_t **ptrp, +struct drm_tegra_mapping *target, +unsigned long offset,unsigned int shift, +uint32_t flags); +#endif /* __DRM_TEGRA_H__ */
Signature · 1 line
2.32.0
PATCH 13/25 tegra: Add syncpoint APIs
In reply to Thierry RedingFrom: Thierry Reding <[email protected]>
These new functions can be used to allocate and free syncpoints, as well as wait for a syncpoint threshold to be reached. Jobs can also be waited on if a syncpoint was attached to them.
--- tegra/job.c | 23 +++++++++ tegra/meson.build | 2 +- tegra/private.h | 5 ++ tegra/pushbuf.c | 48 +++++++++++++++++++ tegra/syncpt.c | 101 ++++++++++++++++++++++++++++++++++++++++ tegra/tegra-symbols.txt | 7 +++ tegra/tegra.h | 16 +++++++ 7 files changed, 201 insertions(+), 1 deletion(-) create mode 100644 tegra/syncpt.c
tegra/job.c +23 -0
@@ -162,3 +162,26 @@ drm_tegra_job_submit(struct drm_tegra_job *job, struct drm_tegra_fence *fence)return 0 ; } + +drm_public int +drm_tegra_job_wait (struct drm_tegra_job *job,unsigned long timeout) +{ +struct drm_tegra_channel *channel = job->channel; +struct drm_tegra *drm = channel->drm; +struct drm_tegra_syncpoint_wait args; +struct timespec ts; +int err; + +clock_gettime (CLOCK_MONOTONIC , &ts); + +memset (&args,0 ,sizeof (args)); + args.timeout_ns = ts.tv_sec *1000000000 + ts.tv_nsec + timeout; + args.id = job->syncpt.id; + args.threshold = job->syncpt.fence; + + err =ioctl (drm->fd,DRM_IOCTL_TEGRA_SYNCPOINT_WAIT , &args); +if (err <0 ) +return -errno; + +return 0 ; +}
tegra/meson.build +1 -1
@@ -22,7 +22,7 @@ libdrm_tegra = library( 'drm_tegra', [ files( - 'channel.c', 'job.c', 'private.h', 'pushbuf.c', 'tegra.c' + 'channel.c', 'job.c', 'private.h', 'pushbuf.c', 'syncpt.c', 'tegra.c' ), config_file ],
tegra/private.h +5 -0
@@ -104,4 +104,9 @@ struct drm_tegra_submit_cmd * drm_tegra_job_add_command(struct drm_tegra_job *job, uint32_t type, uint32_t flags); +struct drm_tegra_syncpoint { +struct drm_tegra *drm; +uint32_t id; +}; +#endif /* __DRM_TEGRA_PRIVATE_H__ */
tegra/pushbuf.c +48 -0
57 lines not on this page · raw message
tegra/syncpt.c new file +101 -0
101 lines not on this page · raw message
tegra/tegra-symbols.txt +7 -0
@@ -15,11 +15,18 @@ drm_tegra_channel_map drm_tegra_channel_open drm_tegra_channel_unmap drm_tegra_close +drm_tegra_fence_wait drm_tegra_job_free drm_tegra_job_get_pushbuf drm_tegra_job_new drm_tegra_job_submit +drm_tegra_job_wait drm_tegra_new drm_tegra_pushbuf_begin drm_tegra_pushbuf_end drm_tegra_pushbuf_relocate +drm_tegra_pushbuf_sync +drm_tegra_pushbuf_sync_cond +drm_tegra_pushbuf_wait +drm_tegra_syncpoint_free +drm_tegra_syncpoint_new
tegra/tegra.h +16 -0
@@ -65,6 +65,7 @@ struct drm_tegra_channel;struct drm_tegra_mapping ;struct drm_tegra_pushbuf ;struct drm_tegra_job ; +struct drm_tegra_syncpoint ;enum drm_tegra_sync_cond {DRM_TEGRA_SYNC_COND_IMMEDIATE ,
@@ -102,10 +103,25 @@ int drm_tegra_job_wait(struct drm_tegra_job *job, unsigned long timeout);int drm_tegra_pushbuf_begin (struct drm_tegra_pushbuf *pushbuf,unsigned int words,uint32_t **ptrp);int drm_tegra_pushbuf_end (struct drm_tegra_pushbuf *pushbuf,uint32_t *ptr); +int drm_tegra_pushbuf_wait (struct drm_tegra_pushbuf *pushbuf, +struct drm_tegra_syncpoint *syncpt, +uint32_t value);int drm_tegra_pushbuf_relocate (struct drm_tegra_pushbuf *pushbuf,uint32_t **ptrp,struct drm_tegra_mapping *target,unsigned long offset,unsigned int shift,uint32_t flags); +int drm_tegra_pushbuf_sync (struct drm_tegra_pushbuf *pushbuf, +struct drm_tegra_syncpoint *syncpt, +unsigned int count); +int drm_tegra_pushbuf_sync_cond (struct drm_tegra_pushbuf *pushbuf, +uint32_t **ptrp, +struct drm_tegra_syncpoint *syncpt, +enum drm_tegra_sync_cond cond); + +int drm_tegra_syncpoint_new (struct drm_tegra *drm, +struct drm_tegra_syncpoint **syncptp); +int drm_tegra_syncpoint_free (struct drm_tegra_syncpoint *syncpt); +int drm_tegra_fence_wait (struct drm_tegra_fence *fence,unsigned long timeout);#endif /* __DRM_TEGRA_H__ */
Signature · 1 line
2.32.0
PATCH 14/25 tests: tegra: Add helper library for tests
In reply to Thierry RedingFrom: Thierry Reding <[email protected]>
This library provides helpers for common functionality needed by test programs.
--- tests/tegra/drm-test.c | 248 ++++++++++++++++++++++++++++++++++++++++ tests/tegra/drm-test.h | 72 ++++++++++++ tests/tegra/meson.build | 7 ++ 3 files changed, 327 insertions(+) create mode 100644 tests/tegra/drm-test.c create mode 100644 tests/tegra/drm-test.h
tests/tegra/drm-test.c new file +248 -0
@@ -0,0 +1,248 @@ +/* +* 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 < (unsigned int )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 ; + } + +drmModeFreeConnector (connector); + found = true; +break ; + } + +drmModeFreeResources (res); + +if (!found) { +free (screen); +return -ENODEV ; + } + + *screenp = screen; + +return 0 ; +} + +int drm_screen_close (struct drm_screen *screen) +{ +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; + } + +free (screen); + +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); +}
tests/tegra/drm-test.h new file +72 -0
72 lines not on this page · raw message
tests/tegra/meson.build +7 -0
@@ -20,6 +20,13 @@ inc_tegra = include_directories('../../tegra') +libdrm_test = static_library( + 'drm-test', + [files('drm-test.c', 'drm-test.h'), config_file ], + include_directories : [inc_root, inc_drm, inc_tegra], + link_with : libdrm, +) + openclose = executable( 'tegra-openclose', files('openclose.c'),
Signature · 1 line
2.32.0
PATCH 15/25 tests: tegra: Add gr2d-fill test
In reply to Thierry RedingFrom: 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/.gitignore | 1 + tests/tegra/drm-test-tegra.c | 147 +++++++++++++++++++++++++++++++++++ tests/tegra/drm-test-tegra.h | 55 +++++++++++++ tests/tegra/gr2d-fill.c | 146 ++++++++++++++++++++++++++++++++++ tests/tegra/meson.build | 19 +++++ 5 files changed, 368 insertions(+) create mode 100644 tests/tegra/drm-test-tegra.c create mode 100644 tests/tegra/drm-test-tegra.h create mode 100644 tests/tegra/gr2d-fill.c
tests/tegra/.gitignore +1 -0
@@ -1 +1,2 @@ +tegra-gr2d-fill tegra-openclose
tests/tegra/drm-test-tegra.c new file +147 -0
147 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/gr2d-fill.c new file +146 -0
146 lines not on this page · raw message
tests/tegra/meson.build +19 -0
@@ -27,6 +27,16 @@ libdrm_test = static_library( link_with : libdrm, ) +libdrm_test_tegra = static_library( + 'drm-test-tegra', + [files( + 'drm-test-tegra.c', + 'drm-test-tegra.h', + ), config_file ], + include_directories : [inc_root, inc_drm, inc_tegra], + link_with : libdrm, +) + openclose = executable( 'tegra-openclose', files('openclose.c'),
@@ -35,3 +45,12 @@ openclose = executable( link_with : [libdrm, libdrm_tegra], install : with_install_tests, ) + +gr2d_fill = executable( + 'tegra-gr2d-fill', + files('gr2d-fill.c'), + include_directories : [inc_root, inc_drm, inc_tegra], + c_args : warn_c_args, + link_with : [libdrm, libdrm_tegra, libdrm_test, libdrm_test_tegra], + install : with_install_tests, +)
Signature · 1 line
2.32.0
PATCH 16/25 tests: tegra: Add syncpt-wait test
In reply to Thierry RedingFrom: Thierry Reding <[email protected]>
This is a very simple sanity test to check whether or not a syncpt can be incremented by a host1x client. This uses gr2d on Tegra20 through Tegra114 and VIC on Tegra124 and later.
--- tests/tegra/meson.build | 9 +++ tests/tegra/syncpt-wait.c | 151 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 160 insertions(+) create mode 100644 tests/tegra/syncpt-wait.c
tests/tegra/meson.build +9 -0
@@ -54,3 +54,12 @@ gr2d_fill = executable( link_with : [libdrm, libdrm_tegra, libdrm_test, libdrm_test_tegra], install : with_install_tests, ) + +syncpt_wait = executable( + 'tegra-syncpt-wait', + files('syncpt-wait.c'), + include_directories : [inc_root, inc_drm, inc_tegra], + c_args : warn_c_args, + link_with : [libdrm, libdrm_tegra, libdrm_test, libdrm_test_tegra], + install : with_install_tests, +)
tests/tegra/syncpt-wait.c new file +151 -0
151 lines not on this page · raw message
Signature · 1 line
2.32.0
PATCH 17/25 tests: tegra: Add syncpoint timeout test
In reply to Thierry RedingFrom: Thierry Reding <[email protected]>
This test can be used to purposefully trigger a job timeout.
--- tests/tegra/meson.build | 9 ++ tests/tegra/syncpt-timeout.c | 163 +++++++++++++++++++++++++++++++++++ 2 files changed, 172 insertions(+) create mode 100644 tests/tegra/syncpt-timeout.c
tests/tegra/meson.build +9 -0
@@ -63,3 +63,12 @@ syncpt_wait = executable( link_with : [libdrm, libdrm_tegra, libdrm_test, libdrm_test_tegra], install : with_install_tests, ) + +syncpt_timeout = executable( + 'tegra-syncpt-timeout', + files('syncpt-timeout.c'), + include_directories : [inc_root, inc_drm, inc_tegra], + c_args : warn_c_args, + link_with : [libdrm, libdrm_tegra, libdrm_test, libdrm_test_tegra], + install : with_install_tests, +)
tests/tegra/syncpt-timeout.c new file +163 -0
163 lines not on this page · raw message
Signature · 1 line
2.32.0
PATCH 18/25 tests: tegra: Add VIC support
In reply to Thierry RedingFrom: Thierry Reding <[email protected]>
Implement a small abstraction interface to allow different versions of VIC to be used transparently. An implementation will be chosen based on the VIC version number reported by the DRM_TEGRA_IOCTL_OPEN_CHANNEL IOCTL.
--- tests/tegra/host1x.h | 34 ++++++++ tests/tegra/meson.build | 2 + tests/tegra/vic.c | 152 +++++++++++++++++++++++++++++++++ tests/tegra/vic.h | 181 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 369 insertions(+) create mode 100644 tests/tegra/host1x.h create mode 100644 tests/tegra/vic.c create mode 100644 tests/tegra/vic.h
tests/tegra/host1x.h new file +34 -0
@@ -0,0 +1,34 @@ +/* +* Copyright © 2018 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 HOST1X_H +#define HOST1X_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_CLASS_VIC 0x5d + +#endif
tests/tegra/meson.build +2 -0
@@ -32,6 +32,8 @@ libdrm_test_tegra = static_library( [files( 'drm-test-tegra.c', 'drm-test-tegra.h', + 'vic.c', + 'vic.h', ), config_file ], include_directories : [inc_root, inc_drm, inc_tegra], link_with : libdrm,
tests/tegra/vic.c new file +152 -0
152 lines not on this page · raw message
tests/tegra/vic.h new file +181 -0
181 lines not on this page · raw message
Signature · 1 line
2.32.0
PATCH 19/25 tests: tegra: Add VIC 3.0 support
In reply to Thierry RedingFrom: Thierry Reding <[email protected]>
The Video Image Composer (VIC) 3.0 can be found on NVIDIA Tegra124 SoCs.
--- tegra/private.h | 6 + tests/tegra/meson.build | 2 + tests/tegra/vic.c | 8 +- tests/tegra/vic30.c | 509 ++++++++++++++++++++++++++++++++++++++++ tests/tegra/vic30.h | 439 ++++++++++++++++++++++++++++++++++ 5 files changed, 962 insertions(+), 2 deletions(-) create mode 100644 tests/tegra/vic30.c create mode 100644 tests/tegra/vic30.h
tegra/private.h +6 -0
@@ -26,6 +26,7 @@#define __DRM_TEGRA_PRIVATE_H__ 1#include <stdbool.h> +#include <stddef.h> #include <stdint.h> #include <libdrm_macros.h>
@@ -34,6 +35,11 @@#include "tegra_drm.h" #include "tegra.h" +#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 ,
tests/tegra/meson.build +2 -0
@@ -34,6 +34,8 @@ libdrm_test_tegra = static_library( 'drm-test-tegra.h', 'vic.c', 'vic.h', + 'vic30.c', + 'vic30.h', ), config_file ], include_directories : [inc_root, inc_drm, inc_tegra], link_with : libdrm,
tests/tegra/vic.c +6 -2
@@ -130,6 +130,10 @@ void vic_image_dump(struct vic_image *image, FILE *fp)drm_tegra_bo_unmap (image->bo); } +/* from vic30.c */ +int vic30_new (struct drm_tegra *drm,struct drm_tegra_channel *channel, +struct vic **vicp); +int vic_new (struct drm_tegra *drm,struct drm_tegra_channel *channel,struct vic **vicp) {
@@ -138,8 +142,8 @@ int vic_new(struct drm_tegra *drm, struct drm_tegra_channel *channel, version =drm_tegra_channel_get_version (channel);switch (version) { -default : -break ; +case 0x40 : +return vic30_new (drm, channel, vicp); }return -ENOTSUP ;
tests/tegra/vic30.c new file +509 -0
509 lines not on this page · raw message
tests/tegra/vic30.h new file +439 -0
439 lines not on this page · raw message
Signature · 1 line
2.32.0
Re: [PATCH libdrm 19/25] tests: tegra: Add VIC 3.0 support
Quoted 3 lines · Thierry Reding
From: Thierry Reding <[email protected]>
The Video Image Composer (VIC) 3.0 can be found on NVIDIA Tegra124 SoCs.a
[...]
Quoted 39 lines
tests/tegra/vic30.c new file +39
-0+static int vic30_clear (struct vic *v,struct vic_image *output, +unsigned int alpha,unsigned int red, +unsigned int green,unsigned int blue) +{ + struct vic30 *vic = container_of(v, struct vic30, base); +ConfigStruct *c; +int err; + + err =drm_tegra_bo_map (vic->config.bo, (void **)&c); +if (err <0 ) { +fprintf (stderr,"failed to map configuration structure: %s\n" , +strerror (-err)); +return err; + } + +memset (c,0 ,sizeof (*c)); + + c->surfaceList0Struct.TargetRectLeft =0 ; + c->surfaceList0Struct.TargetRectTop =0 ; + c->surfaceList0Struct.TargetRectRight = output->width -1 ; + c->surfaceList0Struct.TargetRectBottom = output->height -1 ; + + c->blending0Struct.PixelFormat = output->format; + c->blending0Struct.BackgroundAlpha = alpha; + c->blending0Struct.BackgroundR = red; + c->blending0Struct.BackgroundG = green; + c->blending0Struct.BackgroundB = blue; + c->blending0Struct.LumaWidth = output->stride -1 ; + c->blending0Struct.LumaHeight = output->height -1 ; + c->blending0Struct.ChromaWidth =16383 ; + c->blending0Struct.ChromaHeight =16383 ; + c->blending0Struct.TargetRectLeft =0 ; + c->blending0Struct.TargetRectTop =0 ; + c->blending0Struct.TargetRectRight = output->width -1 ; + c->blending0Struct.TargetRectBottom = output->height -1 ; + c->blending0Struct.SurfaceWidth = output->width -1 ; + c->blending0Struct.SurfaceHeight = output->height -1 ; + c->blending0Struct.BlkKind = output->kind; + c->blending0Struct.BlkHeight =0 ;
tests/tegra/vic30.c line 98
Quoted 10 lines
tests/tegra/vic30.c new file +10
-0+ + c->fetchControl0Struct.TargetRectLeft =0 ; + c->fetchControl0Struct.TargetRectTop =0 ; + c->fetchControl0Struct.TargetRectRight = output->width -1 ; + c->fetchControl0Struct.TargetRectBottom = output->height -1 ; + +drm_tegra_bo_unmap (vic->config.bo); + +return 0 ; +}
[...]
It does look exactly like:
return vic30_fill(v, output, 0, 0, output->width - 1,
output->height - 1, alpha, red, green, blue);
Best Regards
Michał Mirosław
PATCH 20/25 tests: tegra: Add VIC 4.0 support
In reply to Thierry RedingFrom: Thierry Reding <[email protected]>
The Video Image Composer (VIC) 4.0 can be found on NVIDIA Tegra210 SoCs. It uses a different class (B0B6) that is slightly incompatible with the class found on earlier generations.
--- tests/tegra/meson.build | 2 + tests/tegra/vic.c | 7 + tests/tegra/vic40.c | 412 ++++++++++++++++++++++++++++++++++++++++ tests/tegra/vic40.h | 285 +++++++++++++++++++++++++++ 4 files changed, 706 insertions(+) create mode 100644 tests/tegra/vic40.c create mode 100644 tests/tegra/vic40.h
tests/tegra/meson.build +2 -0
@@ -36,6 +36,8 @@ libdrm_test_tegra = static_library( 'vic.h', 'vic30.c', 'vic30.h', + 'vic40.c', + 'vic40.h', ), config_file ], include_directories : [inc_root, inc_drm, inc_tegra], link_with : libdrm,
tests/tegra/vic.c +7 -0
@@ -134,6 +134,10 @@ void vic_image_dump(struct vic_image *image, FILE *fp)int vic30_new (struct drm_tegra *drm,struct drm_tegra_channel *channel,struct vic **vicp); +/* from vic40.c */ +int vic40_new (struct drm_tegra *drm,struct drm_tegra_channel *channel, +struct vic **vicp); +int vic_new (struct drm_tegra *drm,struct drm_tegra_channel *channel,struct vic **vicp) {
@@ -144,6 +148,9 @@ int vic_new(struct drm_tegra *drm, struct drm_tegra_channel *channel,switch (version) {case 0x40 :return vic30_new (drm, channel, vicp); + +case 0x21 : +return vic40_new (drm, channel, vicp); }return -ENOTSUP ;
tests/tegra/vic40.c new file +412 -0
412 lines not on this page · raw message
tests/tegra/vic40.h new file +285 -0
285 lines not on this page · raw message
Signature · 1 line
2.32.0
PATCH 21/25 tests: tegra: Add VIC 4.1 support
In reply to Thierry RedingFrom: Thierry Reding <[email protected]>
The Video Image Composer (VIC) 4.1 can be found on NVIDIA Tegra186 SoCs. It uses a different class (B1B6) that is slightly incompatible with the class found on earlier generations.
--- tests/tegra/meson.build | 2 + tests/tegra/vic.c | 7 + tests/tegra/vic41.c | 416 ++++++++++++++++++++++++++++++++++++++++ tests/tegra/vic41.h | 372 +++++++++++++++++++++++++++++++++++ 4 files changed, 797 insertions(+) create mode 100644 tests/tegra/vic41.c create mode 100644 tests/tegra/vic41.h
tests/tegra/meson.build +2 -0
@@ -38,6 +38,8 @@ libdrm_test_tegra = static_library( 'vic30.h', 'vic40.c', 'vic40.h', + 'vic41.c', + 'vic41.h', ), config_file ], include_directories : [inc_root, inc_drm, inc_tegra], link_with : libdrm,
tests/tegra/vic.c +7 -0
@@ -138,6 +138,10 @@ int vic30_new(struct drm_tegra *drm, struct drm_tegra_channel *channel,int vic40_new (struct drm_tegra *drm,struct drm_tegra_channel *channel,struct vic **vicp); +/* from vic41.c */ +int vic41_new (struct drm_tegra *drm,struct drm_tegra_channel *channel, +struct vic **vicp); +int vic_new (struct drm_tegra *drm,struct drm_tegra_channel *channel,struct vic **vicp) {
@@ -151,6 +155,9 @@ int vic_new(struct drm_tegra *drm, struct drm_tegra_channel *channel,case 0x21 :return vic40_new (drm, channel, vicp); + +case 0x18 : +return vic41_new (drm, channel, vicp); }return -ENOTSUP ;
tests/tegra/vic41.c new file +416 -0
416 lines not on this page · raw message
tests/tegra/vic41.h new file +372 -0
372 lines not on this page · raw message
Signature · 1 line
2.32.0
PATCH 22/25 tests: tegra: Add VIC 4.2 support
In reply to Thierry RedingFrom: Thierry Reding <[email protected]>
The Video Image Composer (VIC) 4.2 can be found on NVIDIA Tegra194 SoCs. It uses a different class (C5B6) that is slightly incompatible with the class found on earlier generations, although it is backwards compatible with the class implemented on Tegra186 (B1B6).
--- tests/tegra/meson.build | 2 + tests/tegra/vic.c | 7 + tests/tegra/vic42.c | 423 ++++++++++++++++++++++++++++ tests/tegra/vic42.h | 597 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 1029 insertions(+) create mode 100644 tests/tegra/vic42.c create mode 100644 tests/tegra/vic42.h
tests/tegra/meson.build +2 -0
@@ -40,6 +40,8 @@ libdrm_test_tegra = static_library( 'vic40.h', 'vic41.c', 'vic41.h', + 'vic42.c', + 'vic42.h', ), config_file ], include_directories : [inc_root, inc_drm, inc_tegra], link_with : libdrm,
tests/tegra/vic.c +7 -0
@@ -142,6 +142,10 @@ int vic40_new(struct drm_tegra *drm, struct drm_tegra_channel *channel,int vic41_new (struct drm_tegra *drm,struct drm_tegra_channel *channel,struct vic **vicp); +/* from vic42.c */ +int vic42_new (struct drm_tegra *drm,struct drm_tegra_channel *channel, +struct vic **vicp); +int vic_new (struct drm_tegra *drm,struct drm_tegra_channel *channel,struct vic **vicp) {
@@ -158,6 +162,9 @@ int vic_new(struct drm_tegra *drm, struct drm_tegra_channel *channel,case 0x18 :return vic41_new (drm, channel, vicp); + +case 0x19 : +return vic42_new (drm, channel, vicp); }return -ENOTSUP ;
tests/tegra/vic42.c new file +423 -0
423 lines not on this page · raw message
tests/tegra/vic42.h new file +597 -0
597 lines not on this page · raw message
Signature · 1 line
2.32.0
PATCH 23/25 tests: tegra: Add VIC clear test
In reply to Thierry RedingFrom: Thierry Reding <[email protected]>
This test will attempt to use VIC to clear a surface.
--- tests/tegra/meson.build | 9 +++ tests/tegra/vic-clear.c | 173 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 182 insertions(+) create mode 100644 tests/tegra/vic-clear.c
tests/tegra/meson.build +9 -0
@@ -82,3 +82,12 @@ syncpt_timeout = executable( link_with : [libdrm, libdrm_tegra, libdrm_test, libdrm_test_tegra], install : with_install_tests, ) + +vic_clear = executable( + 'tegra-vic-clear', + files('vic-clear.c'), + include_directories : [inc_root, inc_drm, inc_tegra], + c_args : warn_c_args, + link_with : [libdrm, libdrm_tegra, libdrm_test, libdrm_test_tegra], + install : with_install_tests, +)
tests/tegra/vic-clear.c new file +173 -0
173 lines not on this page · raw message
Signature · 1 line
2.32.0
PATCH 24/25 tests: tegra: Add VIC blit test
In reply to Thierry RedingFrom: Thierry Reding <[email protected]>
This test will attempt to use the VIC to blit from one surface to another.
--- tests/tegra/meson.build | 9 ++ tests/tegra/vic-blit.c | 333 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 342 insertions(+) create mode 100644 tests/tegra/vic-blit.c
tests/tegra/meson.build +9 -0
@@ -91,3 +91,12 @@ vic_clear = executable( link_with : [libdrm, libdrm_tegra, libdrm_test, libdrm_test_tegra], install : with_install_tests, ) + +vic_blit = executable( + 'tegra-vic-blit', + files('vic-blit.c'), + include_directories : [inc_root, inc_drm, inc_tegra], + c_args : warn_c_args, + link_with : [libdrm, libdrm_tegra, libdrm_test, libdrm_test_tegra], + install : with_install_tests, +)
tests/tegra/vic-blit.c new file +333 -0
333 lines not on this page · raw message
Signature · 1 line
2.32.0
PATCH 25/25 tests: tegra: Add VIC flip test
In reply to Thierry RedingFrom: Thierry Reding <[email protected]>
This test will attempt to use the VIC to blit one surface to another and perform a vertical flip.
--- tests/tegra/meson.build | 9 ++ tests/tegra/vic-flip.c | 333 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 342 insertions(+) create mode 100644 tests/tegra/vic-flip.c
tests/tegra/meson.build +9 -0
@@ -100,3 +100,12 @@ vic_blit = executable( link_with : [libdrm, libdrm_tegra, libdrm_test, libdrm_test_tegra], install : with_install_tests, ) + +vic_flip = executable( + 'tegra-vic-flip', + files('vic-flip.c'), + include_directories : [inc_root, inc_drm, inc_tegra], + c_args : warn_c_args, + link_with : [libdrm, libdrm_tegra, libdrm_test, libdrm_test_tegra], + install : with_install_tests, +)
tests/tegra/vic-flip.c new file +333 -0
333 lines not on this page · raw message
Signature · 1 line
2.32.0
27.08.2021 16:22, Thierry Reding пишет:
Quoted 38 lines
From: Thierry Reding <[email protected]>
Hi all,
this is the userspace part of the kernel patches that were recently merged into drm-next:
https://patchwork.freedesktop.org/series/92378/
The goal is to provide a userspace implementation of the UAPI exposed by the kernel and show its usage in some test programs that can also be used for basic sanity testing. More complete userspace implementations are available here:
* https://github.com/cyndis/vaapi-tegra-driver
* https://github.com/grate-driver/xf86-video-opentegra
* https://github.com/grate-driver/grateThierry
Thierry Reding (25):
tegra: Indent according to .editorconfig
tegra: Remove unused IOCTL implementations
tegra: Extract common buffer object allocation code
tegra: Fixmmap()of GEM buffer objects
tegra: Add flink helpers
tegra: Add PRIME support helpers
tegra: Make API more consistent
tegra: Install tegra-openclose test
tegra: Update for new UABI
tegra: Includeprivate.hin list of source files
tegra: Add channel APIs
tegra: Add job and push buffer APIs
tegra: Add syncpoint APIs
tests: tegra: Add helper library for tests
tests: tegra: Add gr2d-fill test
tests: tegra: Add syncpt-wait test
tests: tegra: Add syncpoint timeout test
Quoted 8 lines
tests: tegra: Add VIC support
tests: tegra: Add VIC 3.0 support
tests: tegra: Add VIC 4.0 support
tests: tegra: Add VIC 4.1 support
tests: tegra: Add VIC 4.2 support
tests: tegra: Add VIC clear test
tests: tegra: Add VIC blit test
tests: tegra: Add VIC flip test
Have you thought about moving tests into IGT? Wouldn't it be a more appropriate place for the tests?
Perhaps we can add/move Mikko's UAPI tests there too, for complicity. Although, I'd prefer it all to be written in a plain C or C++.