Sync headers with drm-next
[drm/libdrm.git] / tegra / syncpt.c
blob16014186fa305dcb75cc5efebbdb3584b6fc5858
1 /*
2 * Copyright © 2021 NVIDIA Corporation
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
23 #ifdef HAVE_CONFIG_H
24 # include "config.h"
25 #endif
27 #include <errno.h>
28 #include <string.h>
30 #include <sys/ioctl.h>
32 #include "private.h"
34 drm_public int
35 drm_tegra_syncpoint_new(struct drm_tegra *drm,
36 struct drm_tegra_syncpoint **syncptp)
38 struct drm_tegra_syncpoint_allocate args;
39 struct drm_tegra_syncpoint *syncpt;
40 int err;
42 syncpt = calloc(1, sizeof(*syncpt));
43 if (!syncpt)
44 return -ENOMEM;
46 memset(&args, 0, sizeof(args));
48 err = ioctl(drm->fd, DRM_IOCTL_TEGRA_SYNCPOINT_ALLOCATE, &args);
49 if (err < 0) {
50 free(syncpt);
51 return -errno;
54 syncpt->drm = drm;
55 syncpt->id = args.id;
57 *syncptp = syncpt;
59 return 0;
62 drm_public int
63 drm_tegra_syncpoint_free(struct drm_tegra_syncpoint *syncpt)
65 struct drm_tegra_syncpoint_free args;
66 struct drm_tegra *drm = syncpt->drm;
67 int err;
69 if (!syncpt)
70 return -EINVAL;
72 memset(&args, 0, sizeof(args));
73 args.id = syncpt->id;
75 err = ioctl(drm->fd, DRM_IOCTL_TEGRA_SYNCPOINT_FREE, &args);
76 if (err < 0)
77 return -errno;
79 free(syncpt);
81 return 0;
84 drm_public int
85 drm_tegra_fence_wait(struct drm_tegra_fence *fence, unsigned long timeout)
87 struct drm_tegra_syncpoint_wait args;
88 struct drm_tegra *drm = fence->drm;
89 int err;
91 memset(&args, 0, sizeof(args));
92 args.timeout_ns = 0;
93 args.id = fence->syncpt;
94 args.threshold = fence->value;
96 err = ioctl(drm->fd, DRM_IOCTL_TEGRA_SYNCPOINT_WAIT, &args);
97 if (err < 0)
98 return -errno;
100 return 0;