tegra: Add syncpoint APIs

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.

Reviewed-by: Mikko Perttunen <mperttunen@nvidia.com>
Signed-off-by: Thierry Reding <treding@nvidia.com>
main
Thierry Reding 2021-07-09 20:45:20 +02:00
parent 4c18828e16
commit 55bc688f11
7 changed files with 201 additions and 1 deletions

View File

@ -162,3 +162,26 @@ drm_tegra_job_submit(struct drm_tegra_job *job, struct drm_tegra_fence *fence)
return 0; 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;
}

View File

@ -22,7 +22,7 @@ libdrm_tegra = library(
'drm_tegra', 'drm_tegra',
[ [
files( 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 config_file
], ],

View File

@ -104,4 +104,9 @@ struct drm_tegra_submit_cmd *
drm_tegra_job_add_command(struct drm_tegra_job *job, uint32_t type, drm_tegra_job_add_command(struct drm_tegra_job *job, uint32_t type,
uint32_t flags); uint32_t flags);
struct drm_tegra_syncpoint {
struct drm_tegra *drm;
uint32_t id;
};
#endif /* __DRM_TEGRA_PRIVATE_H__ */ #endif /* __DRM_TEGRA_PRIVATE_H__ */

View File

@ -101,6 +101,25 @@ drm_tegra_pushbuf_end(struct drm_tegra_pushbuf *pushbuf, uint32_t *ptr)
return 0; return 0;
} }
drm_public int
drm_tegra_pushbuf_wait(struct drm_tegra_pushbuf *pushbuf,
struct drm_tegra_syncpoint *syncpt,
uint32_t value)
{
struct drm_tegra_submit_cmd *command;
command = drm_tegra_job_add_command(pushbuf->job,
DRM_TEGRA_SUBMIT_CMD_WAIT_SYNCPT,
0);
if (!command)
return -ENOMEM;
command->wait_syncpt.id = syncpt->id;
command->wait_syncpt.value = value;
return 0;
}
drm_public int drm_public int
drm_tegra_pushbuf_relocate(struct drm_tegra_pushbuf *pushbuf, uint32_t **ptrp, drm_tegra_pushbuf_relocate(struct drm_tegra_pushbuf *pushbuf, uint32_t **ptrp,
struct drm_tegra_mapping *target, struct drm_tegra_mapping *target,
@ -134,3 +153,32 @@ drm_tegra_pushbuf_relocate(struct drm_tegra_pushbuf *pushbuf, uint32_t **ptrp,
return 0; return 0;
} }
drm_public int
drm_tegra_pushbuf_sync(struct drm_tegra_pushbuf *pushbuf,
struct drm_tegra_syncpoint *syncpt,
unsigned int count)
{
struct drm_tegra_job *job = pushbuf->job;
job->syncpt.increments += count;
job->syncpt.id = syncpt->id;
return 0;
}
drm_public 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)
{
struct drm_tegra_channel *channel = pushbuf->job->channel;
if (cond >= DRM_TEGRA_SYNC_COND_MAX)
return -EINVAL;
*(*ptrp)++ = HOST1X_OPCODE_NONINCR(0x0, 0x1);
*(*ptrp)++ = cond << channel->cond_shift | syncpt->id;
return drm_tegra_pushbuf_sync(pushbuf, syncpt, 1);
}

101
tegra/syncpt.c Normal file
View File

@ -0,0 +1,101 @@
/*
* Copyright © 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_syncpoint_new(struct drm_tegra *drm,
struct drm_tegra_syncpoint **syncptp)
{
struct drm_tegra_syncpoint_allocate args;
struct drm_tegra_syncpoint *syncpt;
int err;
syncpt = calloc(1, sizeof(*syncpt));
if (!syncpt)
return -ENOMEM;
memset(&args, 0, sizeof(args));
err = ioctl(drm->fd, DRM_IOCTL_TEGRA_SYNCPOINT_ALLOCATE, &args);
if (err < 0) {
free(syncpt);
return -errno;
}
syncpt->drm = drm;
syncpt->id = args.id;
*syncptp = syncpt;
return 0;
}
drm_public int
drm_tegra_syncpoint_free(struct drm_tegra_syncpoint *syncpt)
{
struct drm_tegra_syncpoint_free args;
struct drm_tegra *drm = syncpt->drm;
int err;
if (!syncpt)
return -EINVAL;
memset(&args, 0, sizeof(args));
args.id = syncpt->id;
err = ioctl(drm->fd, DRM_IOCTL_TEGRA_SYNCPOINT_FREE, &args);
if (err < 0)
return -errno;
free(syncpt);
return 0;
}
drm_public int
drm_tegra_fence_wait(struct drm_tegra_fence *fence, unsigned long timeout)
{
struct drm_tegra_syncpoint_wait args;
struct drm_tegra *drm = fence->drm;
int err;
memset(&args, 0, sizeof(args));
args.timeout_ns = 0;
args.id = fence->syncpt;
args.threshold = fence->value;
err = ioctl(drm->fd, DRM_IOCTL_TEGRA_SYNCPOINT_WAIT, &args);
if (err < 0)
return -errno;
return 0;
}

View File

@ -15,11 +15,18 @@ drm_tegra_channel_map
drm_tegra_channel_open drm_tegra_channel_open
drm_tegra_channel_unmap drm_tegra_channel_unmap
drm_tegra_close drm_tegra_close
drm_tegra_fence_wait
drm_tegra_job_free drm_tegra_job_free
drm_tegra_job_get_pushbuf drm_tegra_job_get_pushbuf
drm_tegra_job_new drm_tegra_job_new
drm_tegra_job_submit drm_tegra_job_submit
drm_tegra_job_wait
drm_tegra_new drm_tegra_new
drm_tegra_pushbuf_begin drm_tegra_pushbuf_begin
drm_tegra_pushbuf_end drm_tegra_pushbuf_end
drm_tegra_pushbuf_relocate 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

View File

@ -65,6 +65,7 @@ struct drm_tegra_channel;
struct drm_tegra_mapping; struct drm_tegra_mapping;
struct drm_tegra_pushbuf; struct drm_tegra_pushbuf;
struct drm_tegra_job; struct drm_tegra_job;
struct drm_tegra_syncpoint;
enum drm_tegra_sync_cond { enum drm_tegra_sync_cond {
DRM_TEGRA_SYNC_COND_IMMEDIATE, 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, int drm_tegra_pushbuf_begin(struct drm_tegra_pushbuf *pushbuf,
unsigned int words, uint32_t **ptrp); unsigned int words, uint32_t **ptrp);
int drm_tegra_pushbuf_end(struct drm_tegra_pushbuf *pushbuf, uint32_t *ptr); 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, int drm_tegra_pushbuf_relocate(struct drm_tegra_pushbuf *pushbuf,
uint32_t **ptrp, uint32_t **ptrp,
struct drm_tegra_mapping *target, struct drm_tegra_mapping *target,
unsigned long offset, unsigned int shift, unsigned long offset, unsigned int shift,
uint32_t flags); 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__ */ #endif /* __DRM_TEGRA_H__ */