1/*
2 * Copyright © 2012, 2013 Thierry Reding
3 * Copyright © 2013 Erik Faye-Lund
4 * Copyright © 2014 NVIDIA Corporation
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
19 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
20 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22 * OTHER DEALINGS IN THE SOFTWARE.
23 */
24
25#ifndef __DRM_TEGRA_H__
26#define __DRM_TEGRA_H__ 1
27
28#include <stdint.h>
29#include <stdlib.h>
30
31#include <tegra_drm.h>
32
33enum drm_tegra_class {
34    DRM_TEGRA_HOST1X,
35    DRM_TEGRA_GR2D,
36    DRM_TEGRA_GR3D,
37    DRM_TEGRA_VIC,
38};
39
40struct drm_tegra_bo;
41struct drm_tegra;
42
43int drm_tegra_new(int fd, struct drm_tegra **drmp);
44void drm_tegra_close(struct drm_tegra *drm);
45
46int drm_tegra_bo_new(struct drm_tegra *drm, uint32_t flags, uint32_t size,
47                     struct drm_tegra_bo **bop);
48int drm_tegra_bo_wrap(struct drm_tegra *drm, uint32_t handle, uint32_t flags,
49                      uint32_t size, struct drm_tegra_bo **bop);
50struct drm_tegra_bo *drm_tegra_bo_ref(struct drm_tegra_bo *bo);
51void drm_tegra_bo_unref(struct drm_tegra_bo *bo);
52int drm_tegra_bo_get_handle(struct drm_tegra_bo *bo, uint32_t *handle);
53int drm_tegra_bo_map(struct drm_tegra_bo *bo, void **ptr);
54int drm_tegra_bo_unmap(struct drm_tegra_bo *bo);
55
56int drm_tegra_bo_get_name(struct drm_tegra_bo *bo, uint32_t *name);
57int drm_tegra_bo_open(struct drm_tegra *drm, uint32_t name, uint32_t flags,
58                      struct drm_tegra_bo **bop);
59
60int drm_tegra_bo_export(struct drm_tegra_bo *bo, uint32_t flags);
61int drm_tegra_bo_import(struct drm_tegra *drm, int fd,
62                        struct drm_tegra_bo **bop);
63
64struct drm_tegra_channel;
65struct drm_tegra_mapping;
66struct drm_tegra_pushbuf;
67struct drm_tegra_job;
68struct drm_tegra_syncpoint;
69
70enum drm_tegra_sync_cond {
71    DRM_TEGRA_SYNC_COND_IMMEDIATE,
72    DRM_TEGRA_SYNC_COND_OP_DONE,
73    DRM_TEGRA_SYNC_COND_RD_DONE,
74    DRM_TEGRA_SYNC_COND_WR_SAFE,
75    DRM_TEGRA_SYNC_COND_MAX,
76  };
77
78struct drm_tegra_fence {
79    struct drm_tegra *drm;
80    uint32_t syncpt;
81    uint32_t value;
82};
83
84int drm_tegra_channel_open(struct drm_tegra *drm,
85                           enum drm_tegra_class client,
86                           struct drm_tegra_channel **channelp);
87int drm_tegra_channel_close(struct drm_tegra_channel *channel);
88unsigned int drm_tegra_channel_get_version(struct drm_tegra_channel *channel);
89int drm_tegra_channel_map(struct drm_tegra_channel *channel,
90                          struct drm_tegra_bo *bo, uint32_t flags,
91                          struct drm_tegra_mapping **mapp);
92int drm_tegra_channel_unmap(struct drm_tegra_mapping *map);
93
94int drm_tegra_job_new(struct drm_tegra_channel *channel,
95                      struct drm_tegra_job **jobp);
96int drm_tegra_job_free(struct drm_tegra_job *job);
97int drm_tegra_job_get_pushbuf(struct drm_tegra_job *job,
98                              struct drm_tegra_pushbuf **pushbufp);
99int drm_tegra_job_submit(struct drm_tegra_job *job,
100                         struct drm_tegra_fence *fence);
101int drm_tegra_job_wait(struct drm_tegra_job *job, unsigned long timeout);
102
103int drm_tegra_pushbuf_begin(struct drm_tegra_pushbuf *pushbuf,
104                            unsigned int words, uint32_t **ptrp);
105int drm_tegra_pushbuf_end(struct drm_tegra_pushbuf *pushbuf, uint32_t *ptr);
106int drm_tegra_pushbuf_wait(struct drm_tegra_pushbuf *pushbuf,
107                           struct drm_tegra_syncpoint *syncpt,
108                           uint32_t value);
109int drm_tegra_pushbuf_relocate(struct drm_tegra_pushbuf *pushbuf,
110                               uint32_t **ptrp,
111                               struct drm_tegra_mapping *target,
112                               unsigned long offset, unsigned int shift,
113                               uint32_t flags);
114int drm_tegra_pushbuf_sync(struct drm_tegra_pushbuf *pushbuf,
115                           struct drm_tegra_syncpoint *syncpt,
116                           unsigned int count);
117int drm_tegra_pushbuf_sync_cond(struct drm_tegra_pushbuf *pushbuf,
118                                uint32_t **ptrp,
119                                struct drm_tegra_syncpoint *syncpt,
120                                enum drm_tegra_sync_cond cond);
121
122int drm_tegra_syncpoint_new(struct drm_tegra *drm,
123                            struct drm_tegra_syncpoint **syncptp);
124int drm_tegra_syncpoint_free(struct drm_tegra_syncpoint *syncpt);
125int drm_tegra_fence_wait(struct drm_tegra_fence *fence, unsigned long timeout);
126
127#endif /* __DRM_TEGRA_H__ */
128