Path: blob/21.2-virgl/src/freedreno/drm/msm_priv.h
4564 views
/*1* Copyright (C) 2012-2018 Rob Clark <[email protected]>2*3* Permission is hereby granted, free of charge, to any person obtaining a4* copy of this software and associated documentation files (the "Software"),5* to deal in the Software without restriction, including without limitation6* the rights to use, copy, modify, merge, publish, distribute, sublicense,7* and/or sell copies of the Software, and to permit persons to whom the8* Software is furnished to do so, subject to the following conditions:9*10* The above copyright notice and this permission notice (including the next11* paragraph) shall be included in all copies or substantial portions of the12* Software.13*14* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR15* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,16* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL17* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER18* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,19* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE20* SOFTWARE.21*22* Authors:23* Rob Clark <[email protected]>24*/2526#ifndef MSM_PRIV_H_27#define MSM_PRIV_H_2829#include "freedreno_priv.h"3031#include "util/slab.h"3233#ifndef __user34#define __user35#endif3637#include "drm-uapi/msm_drm.h"3839struct msm_device {40struct fd_device base;41struct fd_bo_cache ring_cache;42struct util_queue submit_queue;43};44FD_DEFINE_CAST(fd_device, msm_device);4546struct fd_device *msm_device_new(int fd, drmVersionPtr version);4748struct msm_pipe {49struct fd_pipe base;50uint32_t pipe;51uint32_t gpu_id;52uint64_t gmem_base;53uint32_t gmem;54uint32_t chip_id;55uint32_t queue_id;56struct slab_parent_pool ring_pool;5758/* BO for suballocating long-lived objects on the pipe. */59struct fd_bo *suballoc_bo;60uint32_t suballoc_offset;6162/**63* The last fence seqno that was flushed to kernel (doesn't mean that it64* is complete, just that the kernel knows about it)65*/66uint32_t last_submit_fence;6768uint32_t last_enqueue_fence; /* just for debugging */6970/**71* If we *ever* see an in-fence-fd, assume that userspace is72* not relying on implicit fences.73*/74bool no_implicit_sync;75};76FD_DEFINE_CAST(fd_pipe, msm_pipe);7778struct fd_pipe *msm_pipe_new(struct fd_device *dev, enum fd_pipe_id id,79uint32_t prio);8081struct fd_ringbuffer *msm_ringbuffer_new_object(struct fd_pipe *pipe,82uint32_t size);83struct fd_ringbuffer *msm_ringbuffer_sp_new_object(struct fd_pipe *pipe,84uint32_t size);8586struct fd_submit *msm_submit_new(struct fd_pipe *pipe);87struct fd_submit *msm_submit_sp_new(struct fd_pipe *pipe);88void msm_pipe_sp_flush(struct fd_pipe *pipe, uint32_t fence);8990void msm_pipe_sp_ringpool_init(struct msm_pipe *msm_pipe);91void msm_pipe_sp_ringpool_fini(struct msm_pipe *msm_pipe);9293struct msm_bo {94struct fd_bo base;95uint64_t offset;96uint32_t idx;97};98FD_DEFINE_CAST(fd_bo, msm_bo);99100int msm_bo_new_handle(struct fd_device *dev, uint32_t size, uint32_t flags,101uint32_t *handle);102struct fd_bo *msm_bo_from_handle(struct fd_device *dev, uint32_t size,103uint32_t handle);104105static inline void106msm_dump_submit(struct drm_msm_gem_submit *req)107{108for (unsigned i = 0; i < req->nr_bos; i++) {109struct drm_msm_gem_submit_bo *bos = U642VOID(req->bos);110struct drm_msm_gem_submit_bo *bo = &bos[i];111ERROR_MSG(" bos[%d]: handle=%u, flags=%x", i, bo->handle, bo->flags);112}113for (unsigned i = 0; i < req->nr_cmds; i++) {114struct drm_msm_gem_submit_cmd *cmds = U642VOID(req->cmds);115struct drm_msm_gem_submit_cmd *cmd = &cmds[i];116struct drm_msm_gem_submit_reloc *relocs = U642VOID(cmd->relocs);117ERROR_MSG(" cmd[%d]: type=%u, submit_idx=%u, submit_offset=%u, size=%u",118i, cmd->type, cmd->submit_idx, cmd->submit_offset, cmd->size);119for (unsigned j = 0; j < cmd->nr_relocs; j++) {120struct drm_msm_gem_submit_reloc *r = &relocs[j];121ERROR_MSG(122" reloc[%d]: submit_offset=%u, or=%08x, shift=%d, reloc_idx=%u"123", reloc_offset=%" PRIu64,124j, r->submit_offset, r->or, r->shift, r->reloc_idx,125(uint64_t)r->reloc_offset);126}127}128}129130static inline void131get_abs_timeout(struct drm_msm_timespec *tv, uint64_t ns)132{133struct timespec t;134clock_gettime(CLOCK_MONOTONIC, &t);135tv->tv_sec = t.tv_sec + ns / 1000000000;136tv->tv_nsec = t.tv_nsec + ns % 1000000000;137}138139#endif /* MSM_PRIV_H_ */140141142