2 * Copyright © 2018 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.
31 #define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
33 static int channel_open(struct drm_tegra
*drm
,
34 struct drm_tegra_channel
**channel
)
37 enum drm_tegra_class
class;
40 { DRM_TEGRA_VIC
, "VIC" },
41 { DRM_TEGRA_GR2D
, "GR2D" },
46 for (i
= 0; i
< ARRAY_SIZE(classes
); i
++) {
47 err
= drm_tegra_channel_open(drm
, classes
[i
].class, channel
);
49 fprintf(stderr
, "failed to open channel to %s: %s\n",
50 classes
[i
].name
, strerror(-err
));
60 int main(int argc
, char *argv
[])
62 const char *device
= "/dev/dri/renderD128";
63 struct drm_tegra_syncpoint
*syncpt
;
64 struct drm_tegra_channel
*channel
;
65 struct drm_tegra_pushbuf
*pushbuf
;
66 struct drm_tegra_job
*job
;
67 struct drm_tegra
*drm
;
74 fd
= open(device
, O_RDWR
);
76 fprintf(stderr
, "open() failed: %s\n", strerror(errno
));
80 err
= drm_tegra_new(fd
, &drm
);
82 fprintf(stderr
, "failed to open Tegra device: %s\n", strerror(-err
));
87 err
= drm_tegra_syncpoint_new(drm
, &syncpt
);
89 fprintf(stderr
, "failed to allocate syncpoint: %s\n", strerror(-err
));
95 err
= channel_open(drm
, &channel
);
97 fprintf(stderr
, "failed to open channel: %s\n", strerror(-err
));
101 err
= drm_tegra_job_new(channel
, &job
);
103 fprintf(stderr
, "failed to create job: %s\n", strerror(-err
));
107 err
= drm_tegra_job_get_pushbuf(job
, &pushbuf
);
109 fprintf(stderr
, "failed to create push buffer: %s\n", strerror(-err
));
113 err
= drm_tegra_pushbuf_begin(pushbuf
, 4, &ptr
);
115 fprintf(stderr
, "failed to prepare push buffer: %s\n", strerror(-err
));
119 err
= drm_tegra_pushbuf_sync_cond(pushbuf
, &ptr
, syncpt
,
120 DRM_TEGRA_SYNC_COND_IMMEDIATE
);
122 fprintf(stderr
, "failed to push syncpoint: %s\n", strerror(-err
));
126 err
= drm_tegra_pushbuf_end(pushbuf
, ptr
);
128 fprintf(stderr
, "failed to update push buffer: %s\n", strerror(-err
));
132 err
= drm_tegra_job_submit(job
, NULL
);
134 fprintf(stderr
, "failed to submit job: %s\n", strerror(-err
));
138 err
= drm_tegra_job_wait(job
, 250000000);
140 fprintf(stderr
, "failed to wait for job: %s\n", strerror(-err
));
144 drm_tegra_job_free(job
);
145 drm_tegra_channel_close(channel
);
146 drm_tegra_syncpoint_free(syncpt
);
147 drm_tegra_close(drm
);