108d7334dSsnj/*
208d7334dSsnj * Copyright © 2012, 2013 Thierry Reding
308d7334dSsnj * Copyright © 2013 Erik Faye-Lund
408d7334dSsnj * Copyright © 2014 NVIDIA Corporation
508d7334dSsnj *
608d7334dSsnj * Permission is hereby granted, free of charge, to any person obtaining a
708d7334dSsnj * copy of this software and associated documentation files (the "Software"),
808d7334dSsnj * to deal in the Software without restriction, including without limitation
908d7334dSsnj * the rights to use, copy, modify, merge, publish, distribute, sublicense,
1008d7334dSsnj * and/or sell copies of the Software, and to permit persons to whom the
1108d7334dSsnj * Software is furnished to do so, subject to the following conditions:
1208d7334dSsnj *
1308d7334dSsnj * The above copyright notice and this permission notice shall be included in
1408d7334dSsnj * all copies or substantial portions of the Software.
1508d7334dSsnj *
1608d7334dSsnj * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1708d7334dSsnj * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1808d7334dSsnj * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
1908d7334dSsnj * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
2008d7334dSsnj * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
2108d7334dSsnj * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
2208d7334dSsnj * OTHER DEALINGS IN THE SOFTWARE.
2308d7334dSsnj */
2408d7334dSsnj
2508d7334dSsnj#ifndef __DRM_TEGRA_H__
2608d7334dSsnj#define __DRM_TEGRA_H__ 1
2708d7334dSsnj
2808d7334dSsnj#include <stdint.h>
2908d7334dSsnj#include <stdlib.h>
3008d7334dSsnj
310ed5401bSmrg#include <tegra_drm.h>
320ed5401bSmrg
330ed5401bSmrgenum drm_tegra_class {
340ed5401bSmrg    DRM_TEGRA_HOST1X,
350ed5401bSmrg    DRM_TEGRA_GR2D,
360ed5401bSmrg    DRM_TEGRA_GR3D,
370ed5401bSmrg    DRM_TEGRA_VIC,
380ed5401bSmrg};
390ed5401bSmrg
4008d7334dSsnjstruct drm_tegra_bo;
4108d7334dSsnjstruct drm_tegra;
4208d7334dSsnj
430ed5401bSmrgint drm_tegra_new(int fd, struct drm_tegra **drmp);
4408d7334dSsnjvoid drm_tegra_close(struct drm_tegra *drm);
4508d7334dSsnj
460ed5401bSmrgint drm_tegra_bo_new(struct drm_tegra *drm, uint32_t flags, uint32_t size,
470ed5401bSmrg                     struct drm_tegra_bo **bop);
480ed5401bSmrgint drm_tegra_bo_wrap(struct drm_tegra *drm, uint32_t handle, uint32_t flags,
490ed5401bSmrg                      uint32_t size, struct drm_tegra_bo **bop);
5008d7334dSsnjstruct drm_tegra_bo *drm_tegra_bo_ref(struct drm_tegra_bo *bo);
5108d7334dSsnjvoid drm_tegra_bo_unref(struct drm_tegra_bo *bo);
5208d7334dSsnjint drm_tegra_bo_get_handle(struct drm_tegra_bo *bo, uint32_t *handle);
5308d7334dSsnjint drm_tegra_bo_map(struct drm_tegra_bo *bo, void **ptr);
5408d7334dSsnjint drm_tegra_bo_unmap(struct drm_tegra_bo *bo);
5508d7334dSsnj
560ed5401bSmrgint drm_tegra_bo_get_name(struct drm_tegra_bo *bo, uint32_t *name);
570ed5401bSmrgint drm_tegra_bo_open(struct drm_tegra *drm, uint32_t name, uint32_t flags,
580ed5401bSmrg                      struct drm_tegra_bo **bop);
590ed5401bSmrg
600ed5401bSmrgint drm_tegra_bo_export(struct drm_tegra_bo *bo, uint32_t flags);
610ed5401bSmrgint drm_tegra_bo_import(struct drm_tegra *drm, int fd,
620ed5401bSmrg                        struct drm_tegra_bo **bop);
630ed5401bSmrg
640ed5401bSmrgstruct drm_tegra_channel;
650ed5401bSmrgstruct drm_tegra_mapping;
660ed5401bSmrgstruct drm_tegra_pushbuf;
670ed5401bSmrgstruct drm_tegra_job;
680ed5401bSmrgstruct drm_tegra_syncpoint;
6908d7334dSsnj
700ed5401bSmrgenum drm_tegra_sync_cond {
710ed5401bSmrg    DRM_TEGRA_SYNC_COND_IMMEDIATE,
720ed5401bSmrg    DRM_TEGRA_SYNC_COND_OP_DONE,
730ed5401bSmrg    DRM_TEGRA_SYNC_COND_RD_DONE,
740ed5401bSmrg    DRM_TEGRA_SYNC_COND_WR_SAFE,
750ed5401bSmrg    DRM_TEGRA_SYNC_COND_MAX,
760ed5401bSmrg  };
770ed5401bSmrg
780ed5401bSmrgstruct drm_tegra_fence {
790ed5401bSmrg    struct drm_tegra *drm;
800ed5401bSmrg    uint32_t syncpt;
810ed5401bSmrg    uint32_t value;
8208d7334dSsnj};
8308d7334dSsnj
840ed5401bSmrgint drm_tegra_channel_open(struct drm_tegra *drm,
850ed5401bSmrg                           enum drm_tegra_class client,
860ed5401bSmrg                           struct drm_tegra_channel **channelp);
870ed5401bSmrgint drm_tegra_channel_close(struct drm_tegra_channel *channel);
880ed5401bSmrgunsigned int drm_tegra_channel_get_version(struct drm_tegra_channel *channel);
890ed5401bSmrgint drm_tegra_channel_map(struct drm_tegra_channel *channel,
900ed5401bSmrg                          struct drm_tegra_bo *bo, uint32_t flags,
910ed5401bSmrg                          struct drm_tegra_mapping **mapp);
920ed5401bSmrgint drm_tegra_channel_unmap(struct drm_tegra_mapping *map);
930ed5401bSmrg
940ed5401bSmrgint drm_tegra_job_new(struct drm_tegra_channel *channel,
950ed5401bSmrg                      struct drm_tegra_job **jobp);
960ed5401bSmrgint drm_tegra_job_free(struct drm_tegra_job *job);
970ed5401bSmrgint drm_tegra_job_get_pushbuf(struct drm_tegra_job *job,
980ed5401bSmrg                              struct drm_tegra_pushbuf **pushbufp);
990ed5401bSmrgint drm_tegra_job_submit(struct drm_tegra_job *job,
1000ed5401bSmrg                         struct drm_tegra_fence *fence);
1010ed5401bSmrgint drm_tegra_job_wait(struct drm_tegra_job *job, unsigned long timeout);
1020ed5401bSmrg
1030ed5401bSmrgint drm_tegra_pushbuf_begin(struct drm_tegra_pushbuf *pushbuf,
1040ed5401bSmrg                            unsigned int words, uint32_t **ptrp);
1050ed5401bSmrgint drm_tegra_pushbuf_end(struct drm_tegra_pushbuf *pushbuf, uint32_t *ptr);
1060ed5401bSmrgint drm_tegra_pushbuf_wait(struct drm_tegra_pushbuf *pushbuf,
1070ed5401bSmrg                           struct drm_tegra_syncpoint *syncpt,
1080ed5401bSmrg                           uint32_t value);
1090ed5401bSmrgint drm_tegra_pushbuf_relocate(struct drm_tegra_pushbuf *pushbuf,
1100ed5401bSmrg                               uint32_t **ptrp,
1110ed5401bSmrg                               struct drm_tegra_mapping *target,
1120ed5401bSmrg                               unsigned long offset, unsigned int shift,
1130ed5401bSmrg                               uint32_t flags);
1140ed5401bSmrgint drm_tegra_pushbuf_sync(struct drm_tegra_pushbuf *pushbuf,
1150ed5401bSmrg                           struct drm_tegra_syncpoint *syncpt,
1160ed5401bSmrg                           unsigned int count);
1170ed5401bSmrgint drm_tegra_pushbuf_sync_cond(struct drm_tegra_pushbuf *pushbuf,
1180ed5401bSmrg                                uint32_t **ptrp,
1190ed5401bSmrg                                struct drm_tegra_syncpoint *syncpt,
1200ed5401bSmrg                                enum drm_tegra_sync_cond cond);
1210ed5401bSmrg
1220ed5401bSmrgint drm_tegra_syncpoint_new(struct drm_tegra *drm,
1230ed5401bSmrg                            struct drm_tegra_syncpoint **syncptp);
1240ed5401bSmrgint drm_tegra_syncpoint_free(struct drm_tegra_syncpoint *syncpt);
1250ed5401bSmrgint drm_tegra_fence_wait(struct drm_tegra_fence *fence, unsigned long timeout);
12608d7334dSsnj
12708d7334dSsnj#endif /* __DRM_TEGRA_H__ */
128