1b8e80941Smrg/* 2b8e80941Smrg * Copyright (C) 2012-2018 Rob Clark <robclark@freedesktop.org> 3b8e80941Smrg * 4b8e80941Smrg * Permission is hereby granted, free of charge, to any person obtaining a 5b8e80941Smrg * copy of this software and associated documentation files (the "Software"), 6b8e80941Smrg * to deal in the Software without restriction, including without limitation 7b8e80941Smrg * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8b8e80941Smrg * and/or sell copies of the Software, and to permit persons to whom the 9b8e80941Smrg * Software is furnished to do so, subject to the following conditions: 10b8e80941Smrg * 11b8e80941Smrg * The above copyright notice and this permission notice (including the next 12b8e80941Smrg * paragraph) shall be included in all copies or substantial portions of the 13b8e80941Smrg * Software. 14b8e80941Smrg * 15b8e80941Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16b8e80941Smrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17b8e80941Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18b8e80941Smrg * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19b8e80941Smrg * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20b8e80941Smrg * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21b8e80941Smrg * SOFTWARE. 22b8e80941Smrg * 23b8e80941Smrg * Authors: 24b8e80941Smrg * Rob Clark <robclark@freedesktop.org> 25b8e80941Smrg */ 26b8e80941Smrg 27b8e80941Smrg#ifndef MSM_PRIV_H_ 28b8e80941Smrg#define MSM_PRIV_H_ 29b8e80941Smrg 30b8e80941Smrg#include "freedreno_priv.h" 31b8e80941Smrg 32b8e80941Smrg#ifndef __user 33b8e80941Smrg# define __user 34b8e80941Smrg#endif 35b8e80941Smrg 36b8e80941Smrg#include "msm_drm.h" 37b8e80941Smrg 38b8e80941Smrgstruct msm_device { 39b8e80941Smrg struct fd_device base; 40b8e80941Smrg struct fd_bo_cache ring_cache; 41b8e80941Smrg}; 42b8e80941SmrgFD_DEFINE_CAST(fd_device, msm_device); 43b8e80941Smrg 44b8e80941Smrgstruct fd_device * msm_device_new(int fd); 45b8e80941Smrg 46b8e80941Smrgstruct msm_pipe { 47b8e80941Smrg struct fd_pipe base; 48b8e80941Smrg uint32_t pipe; 49b8e80941Smrg uint32_t gpu_id; 50b8e80941Smrg uint64_t gmem_base; 51b8e80941Smrg uint32_t gmem; 52b8e80941Smrg uint32_t chip_id; 53b8e80941Smrg uint32_t queue_id; 54b8e80941Smrg}; 55b8e80941SmrgFD_DEFINE_CAST(fd_pipe, msm_pipe); 56b8e80941Smrg 57b8e80941Smrgstruct fd_pipe * msm_pipe_new(struct fd_device *dev, 58b8e80941Smrg enum fd_pipe_id id, uint32_t prio); 59b8e80941Smrg 60b8e80941Smrgstruct fd_ringbuffer * msm_ringbuffer_new_object(struct fd_pipe *pipe, uint32_t size); 61b8e80941Smrgstruct fd_ringbuffer * msm_ringbuffer_sp_new_object(struct fd_pipe *pipe, uint32_t size); 62b8e80941Smrg 63b8e80941Smrgstruct fd_submit * msm_submit_new(struct fd_pipe *pipe); 64b8e80941Smrgstruct fd_submit * msm_submit_sp_new(struct fd_pipe *pipe); 65b8e80941Smrg 66b8e80941Smrgstruct msm_bo { 67b8e80941Smrg struct fd_bo base; 68b8e80941Smrg uint64_t offset; 69b8e80941Smrg /* to avoid excess hashtable lookups, cache the ring this bo was 70b8e80941Smrg * last emitted on (since that will probably also be the next ring 71b8e80941Smrg * it is emitted on) 72b8e80941Smrg */ 73b8e80941Smrg unsigned current_submit_seqno; 74b8e80941Smrg uint32_t idx; 75b8e80941Smrg}; 76b8e80941SmrgFD_DEFINE_CAST(fd_bo, msm_bo); 77b8e80941Smrg 78b8e80941Smrgint msm_bo_new_handle(struct fd_device *dev, 79b8e80941Smrg uint32_t size, uint32_t flags, uint32_t *handle); 80b8e80941Smrgstruct fd_bo * msm_bo_from_handle(struct fd_device *dev, 81b8e80941Smrg uint32_t size, uint32_t handle); 82b8e80941Smrg 83b8e80941Smrgstatic inline void 84b8e80941Smrgmsm_dump_submit(struct drm_msm_gem_submit *req) 85b8e80941Smrg{ 86b8e80941Smrg for (unsigned i = 0; i < req->nr_bos; i++) { 87b8e80941Smrg struct drm_msm_gem_submit_bo *bos = U642VOID(req->bos); 88b8e80941Smrg struct drm_msm_gem_submit_bo *bo = &bos[i]; 89b8e80941Smrg ERROR_MSG(" bos[%d]: handle=%u, flags=%x", i, bo->handle, bo->flags); 90b8e80941Smrg } 91b8e80941Smrg for (unsigned i = 0; i < req->nr_cmds; i++) { 92b8e80941Smrg struct drm_msm_gem_submit_cmd *cmds = U642VOID(req->cmds); 93b8e80941Smrg struct drm_msm_gem_submit_cmd *cmd = &cmds[i]; 94b8e80941Smrg struct drm_msm_gem_submit_reloc *relocs = U642VOID(cmd->relocs); 95b8e80941Smrg ERROR_MSG(" cmd[%d]: type=%u, submit_idx=%u, submit_offset=%u, size=%u", 96b8e80941Smrg i, cmd->type, cmd->submit_idx, cmd->submit_offset, cmd->size); 97b8e80941Smrg for (unsigned j = 0; j < cmd->nr_relocs; j++) { 98b8e80941Smrg struct drm_msm_gem_submit_reloc *r = &relocs[j]; 99b8e80941Smrg ERROR_MSG(" reloc[%d]: submit_offset=%u, or=%08x, shift=%d, reloc_idx=%u" 100b8e80941Smrg ", reloc_offset=%"PRIu64, j, r->submit_offset, r->or, r->shift, 101b8e80941Smrg r->reloc_idx, r->reloc_offset); 102b8e80941Smrg } 103b8e80941Smrg } 104b8e80941Smrg} 105b8e80941Smrg 106b8e80941Smrgstatic inline void get_abs_timeout(struct drm_msm_timespec *tv, uint64_t ns) 107b8e80941Smrg{ 108b8e80941Smrg struct timespec t; 109b8e80941Smrg uint32_t s = ns / 1000000000; 110b8e80941Smrg clock_gettime(CLOCK_MONOTONIC, &t); 111b8e80941Smrg tv->tv_sec = t.tv_sec + s; 112b8e80941Smrg tv->tv_nsec = t.tv_nsec + ns - (s * 1000000000); 113b8e80941Smrg} 114b8e80941Smrg 115b8e80941Smrg/* 116b8e80941Smrg * Stupid/simple growable array implementation: 117b8e80941Smrg */ 118b8e80941Smrg 119b8e80941Smrgstatic inline void * 120b8e80941Smrggrow(void *ptr, uint16_t nr, uint16_t *max, uint16_t sz) 121b8e80941Smrg{ 122b8e80941Smrg if ((nr + 1) > *max) { 123b8e80941Smrg if ((*max * 2) < (nr + 1)) 124b8e80941Smrg *max = nr + 5; 125b8e80941Smrg else 126b8e80941Smrg *max = *max * 2; 127b8e80941Smrg ptr = realloc(ptr, *max * sz); 128b8e80941Smrg } 129b8e80941Smrg return ptr; 130b8e80941Smrg} 131b8e80941Smrg 132b8e80941Smrg#define DECLARE_ARRAY(type, name) \ 133b8e80941Smrg unsigned short nr_ ## name, max_ ## name; \ 134b8e80941Smrg type * name; 135b8e80941Smrg 136b8e80941Smrg#define APPEND(x, name) ({ \ 137b8e80941Smrg (x)->name = grow((x)->name, (x)->nr_ ## name, &(x)->max_ ## name, sizeof((x)->name[0])); \ 138b8e80941Smrg (x)->nr_ ## name ++; \ 139b8e80941Smrg}) 140b8e80941Smrg 141b8e80941Smrg#endif /* MSM_PRIV_H_ */ 142