1e88f27b3Smrg/* -*- mode: C; c-file-style: "k&r"; tab-width 4; indent-tabs-mode: t; -*- */ 2e88f27b3Smrg 3e88f27b3Smrg/* 4e88f27b3Smrg * Copyright (C) 2013 Rob Clark <robclark@freedesktop.org> 5e88f27b3Smrg * 6e88f27b3Smrg * Permission is hereby granted, free of charge, to any person obtaining a 7e88f27b3Smrg * copy of this software and associated documentation files (the "Software"), 8e88f27b3Smrg * to deal in the Software without restriction, including without limitation 9e88f27b3Smrg * the rights to use, copy, modify, merge, publish, distribute, sublicense, 10e88f27b3Smrg * and/or sell copies of the Software, and to permit persons to whom the 11e88f27b3Smrg * Software is furnished to do so, subject to the following conditions: 12e88f27b3Smrg * 13e88f27b3Smrg * The above copyright notice and this permission notice (including the next 14e88f27b3Smrg * paragraph) shall be included in all copies or substantial portions of the 15e88f27b3Smrg * Software. 16e88f27b3Smrg * 17e88f27b3Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18e88f27b3Smrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19e88f27b3Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 20e88f27b3Smrg * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21e88f27b3Smrg * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22e88f27b3Smrg * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23e88f27b3Smrg * SOFTWARE. 24e88f27b3Smrg * 25e88f27b3Smrg * Authors: 26e88f27b3Smrg * Rob Clark <robclark@freedesktop.org> 27e88f27b3Smrg */ 28e88f27b3Smrg 29e88f27b3Smrg#ifndef MSM_PRIV_H_ 30e88f27b3Smrg#define MSM_PRIV_H_ 31e88f27b3Smrg 32e88f27b3Smrg#include "freedreno_priv.h" 33e88f27b3Smrg 34e88f27b3Smrg#ifndef __user 35e88f27b3Smrg# define __user 36e88f27b3Smrg#endif 37e88f27b3Smrg 38e88f27b3Smrg#include "msm_drm.h" 39e88f27b3Smrg 40e88f27b3Smrgstruct msm_device { 41e88f27b3Smrg struct fd_device base; 423f012e29Smrg struct fd_bo_cache ring_cache; 433f012e29Smrg unsigned ring_cnt; 44e88f27b3Smrg}; 45e88f27b3Smrg 46e88f27b3Smrgstatic inline struct msm_device * to_msm_device(struct fd_device *x) 47e88f27b3Smrg{ 48e88f27b3Smrg return (struct msm_device *)x; 49e88f27b3Smrg} 50e88f27b3Smrg 51e6188e58Smrgdrm_private struct fd_device * msm_device_new(int fd); 52e88f27b3Smrg 53e88f27b3Smrgstruct msm_pipe { 54e88f27b3Smrg struct fd_pipe base; 55e88f27b3Smrg uint32_t pipe; 56e88f27b3Smrg uint32_t gpu_id; 57e88f27b3Smrg uint32_t gmem; 58baaff307Smrg uint32_t chip_id; 5900a23bdaSmrg uint32_t queue_id; 607cdc0497Smrg 617cdc0497Smrg /* Allow for sub-allocation of stateobj ring buffers (ie. sharing 627cdc0497Smrg * the same underlying bo).. 637cdc0497Smrg * 647cdc0497Smrg * This takes advantage of each context having it's own fd_pipe, 657cdc0497Smrg * so we don't have to worry about access from multiple threads. 667cdc0497Smrg * 677cdc0497Smrg * We also rely on previous stateobj having been fully constructed 687cdc0497Smrg * so we can reclaim extra space at it's end. 697cdc0497Smrg */ 707cdc0497Smrg struct fd_ringbuffer *suballoc_ring; 71e88f27b3Smrg}; 72e88f27b3Smrg 73e88f27b3Smrgstatic inline struct msm_pipe * to_msm_pipe(struct fd_pipe *x) 74e88f27b3Smrg{ 75e88f27b3Smrg return (struct msm_pipe *)x; 76e88f27b3Smrg} 77e88f27b3Smrg 78e6188e58Smrgdrm_private struct fd_pipe * msm_pipe_new(struct fd_device *dev, 7900a23bdaSmrg enum fd_pipe_id id, uint32_t prio); 80e88f27b3Smrg 81e6188e58Smrgdrm_private struct fd_ringbuffer * msm_ringbuffer_new(struct fd_pipe *pipe, 827cdc0497Smrg uint32_t size, enum fd_ringbuffer_flags flags); 83e88f27b3Smrg 84e88f27b3Smrgstruct msm_bo { 85e88f27b3Smrg struct fd_bo base; 86e88f27b3Smrg uint64_t offset; 87e88f27b3Smrg uint64_t presumed; 883f012e29Smrg /* to avoid excess hashtable lookups, cache the ring this bo was 893f012e29Smrg * last emitted on (since that will probably also be the next ring 903f012e29Smrg * it is emitted on) 913f012e29Smrg */ 923f012e29Smrg unsigned current_ring_seqno; 933f012e29Smrg uint32_t idx; 94e88f27b3Smrg}; 95e88f27b3Smrg 96e88f27b3Smrgstatic inline struct msm_bo * to_msm_bo(struct fd_bo *x) 97e88f27b3Smrg{ 98e88f27b3Smrg return (struct msm_bo *)x; 99e88f27b3Smrg} 100e88f27b3Smrg 101e6188e58Smrgdrm_private int msm_bo_new_handle(struct fd_device *dev, 102e88f27b3Smrg uint32_t size, uint32_t flags, uint32_t *handle); 103e6188e58Smrgdrm_private struct fd_bo * msm_bo_from_handle(struct fd_device *dev, 104e88f27b3Smrg uint32_t size, uint32_t handle); 105e88f27b3Smrg 1063f012e29Smrgstatic inline void get_abs_timeout(struct drm_msm_timespec *tv, uint64_t ns) 107e88f27b3Smrg{ 108e88f27b3Smrg struct timespec t; 1093f012e29Smrg uint32_t s = ns / 1000000000; 110e88f27b3Smrg clock_gettime(CLOCK_MONOTONIC, &t); 111e88f27b3Smrg tv->tv_sec = t.tv_sec + s; 1123f012e29Smrg tv->tv_nsec = t.tv_nsec + ns - (s * 1000000000); 113e88f27b3Smrg} 114e88f27b3Smrg 1157cdc0497Smrg/* 1167cdc0497Smrg * Stupid/simple growable array implementation: 1177cdc0497Smrg */ 1187cdc0497Smrg 1197cdc0497Smrgstatic inline void * 1207cdc0497Smrggrow(void *ptr, uint32_t nr, uint32_t *max, uint32_t sz) 1217cdc0497Smrg{ 1227cdc0497Smrg if ((nr + 1) > *max) { 1237cdc0497Smrg if ((*max * 2) < (nr + 1)) 1247cdc0497Smrg *max = nr + 5; 1257cdc0497Smrg else 1267cdc0497Smrg *max = *max * 2; 1277cdc0497Smrg ptr = realloc(ptr, *max * sz); 1287cdc0497Smrg } 1297cdc0497Smrg return ptr; 1307cdc0497Smrg} 1317cdc0497Smrg 1327cdc0497Smrg#define DECLARE_ARRAY(type, name) \ 1337cdc0497Smrg unsigned nr_ ## name, max_ ## name; \ 1347cdc0497Smrg type * name; 1357cdc0497Smrg 1367cdc0497Smrg#define APPEND(x, name) ({ \ 1377cdc0497Smrg (x)->name = grow((x)->name, (x)->nr_ ## name, &(x)->max_ ## name, sizeof((x)->name[0])); \ 1387cdc0497Smrg (x)->nr_ ## name ++; \ 1397cdc0497Smrg}) 1407cdc0497Smrg 141e88f27b3Smrg#endif /* MSM_PRIV_H_ */ 142