msm_pipe.c revision baaff307
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 29baaff307Smrg#ifdef HAVE_CONFIG_H 30baaff307Smrg# include <config.h> 31baaff307Smrg#endif 32baaff307Smrg 33e88f27b3Smrg#include "msm_priv.h" 34e88f27b3Smrg 35e88f27b3Smrg 36e88f27b3Smrgstatic int msm_pipe_get_param(struct fd_pipe *pipe, 37e88f27b3Smrg enum fd_param_id param, uint64_t *value) 38e88f27b3Smrg{ 39e88f27b3Smrg struct msm_pipe *msm_pipe = to_msm_pipe(pipe); 40e88f27b3Smrg switch(param) { 41e88f27b3Smrg case FD_DEVICE_ID: // XXX probably get rid of this.. 42e88f27b3Smrg case FD_GPU_ID: 43e88f27b3Smrg *value = msm_pipe->gpu_id; 44e88f27b3Smrg return 0; 45e88f27b3Smrg case FD_GMEM_SIZE: 46e88f27b3Smrg *value = msm_pipe->gmem; 47e88f27b3Smrg return 0; 48baaff307Smrg case FD_CHIP_ID: 49baaff307Smrg *value = msm_pipe->chip_id; 50baaff307Smrg return 0; 51e88f27b3Smrg default: 52e88f27b3Smrg ERROR_MSG("invalid param id: %d", param); 53e88f27b3Smrg return -1; 54e88f27b3Smrg } 55e88f27b3Smrg} 56e88f27b3Smrg 57e88f27b3Smrgstatic int msm_pipe_wait(struct fd_pipe *pipe, uint32_t timestamp) 58e88f27b3Smrg{ 59e88f27b3Smrg struct fd_device *dev = pipe->dev; 60e88f27b3Smrg struct drm_msm_wait_fence req = { 61e88f27b3Smrg .fence = timestamp, 62e88f27b3Smrg }; 63e88f27b3Smrg int ret; 64e88f27b3Smrg 65e88f27b3Smrg get_abs_timeout(&req.timeout, 5000); 66e88f27b3Smrg 67e88f27b3Smrg ret = drmCommandWrite(dev->fd, DRM_MSM_WAIT_FENCE, &req, sizeof(req)); 68e88f27b3Smrg if (ret) { 69e88f27b3Smrg ERROR_MSG("wait-fence failed! %d (%s)", ret, strerror(errno)); 70e88f27b3Smrg return ret; 71e88f27b3Smrg } 72e88f27b3Smrg 73e88f27b3Smrg return 0; 74e88f27b3Smrg} 75e88f27b3Smrg 76e88f27b3Smrgstatic void msm_pipe_destroy(struct fd_pipe *pipe) 77e88f27b3Smrg{ 78e88f27b3Smrg struct msm_pipe *msm_pipe = to_msm_pipe(pipe); 79e88f27b3Smrg free(msm_pipe); 80e88f27b3Smrg} 81e88f27b3Smrg 82e88f27b3Smrgstatic struct fd_pipe_funcs funcs = { 83e88f27b3Smrg .ringbuffer_new = msm_ringbuffer_new, 84e88f27b3Smrg .get_param = msm_pipe_get_param, 85e88f27b3Smrg .wait = msm_pipe_wait, 86e88f27b3Smrg .destroy = msm_pipe_destroy, 87e88f27b3Smrg}; 88e88f27b3Smrg 89e88f27b3Smrgstatic uint64_t get_param(struct fd_device *dev, uint32_t pipe, uint32_t param) 90e88f27b3Smrg{ 91e88f27b3Smrg struct drm_msm_param req = { 92e88f27b3Smrg .pipe = pipe, 93e88f27b3Smrg .param = param, 94e88f27b3Smrg }; 95e88f27b3Smrg int ret; 96e88f27b3Smrg 97e88f27b3Smrg ret = drmCommandWriteRead(dev->fd, DRM_MSM_GET_PARAM, &req, sizeof(req)); 98e88f27b3Smrg if (ret) { 99e88f27b3Smrg ERROR_MSG("get-param failed! %d (%s)", ret, strerror(errno)); 100e88f27b3Smrg return 0; 101e88f27b3Smrg } 102e88f27b3Smrg 103e88f27b3Smrg return req.value; 104e88f27b3Smrg} 105e88f27b3Smrg 106e88f27b3Smrgstruct fd_pipe * msm_pipe_new(struct fd_device *dev, enum fd_pipe_id id) 107e88f27b3Smrg{ 108e88f27b3Smrg static const uint32_t pipe_id[] = { 109e88f27b3Smrg [FD_PIPE_3D] = MSM_PIPE_3D0, 110e88f27b3Smrg [FD_PIPE_2D] = MSM_PIPE_2D0, 111e88f27b3Smrg }; 112e88f27b3Smrg struct msm_pipe *msm_pipe = NULL; 113e88f27b3Smrg struct fd_pipe *pipe = NULL; 114e88f27b3Smrg 115e88f27b3Smrg msm_pipe = calloc(1, sizeof(*msm_pipe)); 116e88f27b3Smrg if (!msm_pipe) { 117e88f27b3Smrg ERROR_MSG("allocation failed"); 118e88f27b3Smrg goto fail; 119e88f27b3Smrg } 120e88f27b3Smrg 121e88f27b3Smrg pipe = &msm_pipe->base; 122e88f27b3Smrg pipe->funcs = &funcs; 123e88f27b3Smrg 124e88f27b3Smrg msm_pipe->pipe = pipe_id[id]; 125e88f27b3Smrg msm_pipe->gpu_id = get_param(dev, pipe_id[id], MSM_PARAM_GPU_ID); 126e88f27b3Smrg msm_pipe->gmem = get_param(dev, pipe_id[id], MSM_PARAM_GMEM_SIZE); 127baaff307Smrg msm_pipe->chip_id = get_param(dev, pipe_id[id], MSM_PARAM_CHIP_ID); 128e88f27b3Smrg 129e88f27b3Smrg if (! msm_pipe->gpu_id) 130e88f27b3Smrg goto fail; 131e88f27b3Smrg 132e88f27b3Smrg INFO_MSG("Pipe Info:"); 133e88f27b3Smrg INFO_MSG(" GPU-id: %d", msm_pipe->gpu_id); 134baaff307Smrg INFO_MSG(" Chip-id: 0x%08x", msm_pipe->chip_id); 135e88f27b3Smrg INFO_MSG(" GMEM size: 0x%08x", msm_pipe->gmem); 136e88f27b3Smrg 137e88f27b3Smrg return pipe; 138e88f27b3Smrgfail: 139e88f27b3Smrg if (pipe) 140e88f27b3Smrg fd_pipe_del(pipe); 141e88f27b3Smrg return NULL; 142e88f27b3Smrg} 143