msm_pipe.c revision 3f012e29
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 353f012e29Smrgstatic int query_param(struct fd_pipe *pipe, uint32_t param, 363f012e29Smrg uint64_t *value) 373f012e29Smrg{ 383f012e29Smrg struct msm_pipe *msm_pipe = to_msm_pipe(pipe); 393f012e29Smrg struct drm_msm_param req = { 403f012e29Smrg .pipe = msm_pipe->pipe, 413f012e29Smrg .param = param, 423f012e29Smrg }; 433f012e29Smrg int ret; 443f012e29Smrg 453f012e29Smrg ret = drmCommandWriteRead(pipe->dev->fd, DRM_MSM_GET_PARAM, 463f012e29Smrg &req, sizeof(req)); 473f012e29Smrg if (ret) 483f012e29Smrg return ret; 493f012e29Smrg 503f012e29Smrg *value = req.value; 513f012e29Smrg 523f012e29Smrg return 0; 533f012e29Smrg} 54e88f27b3Smrg 55e88f27b3Smrgstatic int msm_pipe_get_param(struct fd_pipe *pipe, 56e88f27b3Smrg enum fd_param_id param, uint64_t *value) 57e88f27b3Smrg{ 58e88f27b3Smrg struct msm_pipe *msm_pipe = to_msm_pipe(pipe); 59e88f27b3Smrg switch(param) { 60e88f27b3Smrg case FD_DEVICE_ID: // XXX probably get rid of this.. 61e88f27b3Smrg case FD_GPU_ID: 62e88f27b3Smrg *value = msm_pipe->gpu_id; 63e88f27b3Smrg return 0; 64e88f27b3Smrg case FD_GMEM_SIZE: 65e88f27b3Smrg *value = msm_pipe->gmem; 66e88f27b3Smrg return 0; 67baaff307Smrg case FD_CHIP_ID: 68baaff307Smrg *value = msm_pipe->chip_id; 69baaff307Smrg return 0; 703f012e29Smrg case FD_MAX_FREQ: 713f012e29Smrg return query_param(pipe, MSM_PARAM_MAX_FREQ, value); 723f012e29Smrg case FD_TIMESTAMP: 733f012e29Smrg return query_param(pipe, MSM_PARAM_TIMESTAMP, value); 74e88f27b3Smrg default: 75e88f27b3Smrg ERROR_MSG("invalid param id: %d", param); 76e88f27b3Smrg return -1; 77e88f27b3Smrg } 78e88f27b3Smrg} 79e88f27b3Smrg 803f012e29Smrgstatic int msm_pipe_wait(struct fd_pipe *pipe, uint32_t timestamp, 813f012e29Smrg uint64_t timeout) 82e88f27b3Smrg{ 83e88f27b3Smrg struct fd_device *dev = pipe->dev; 84e88f27b3Smrg struct drm_msm_wait_fence req = { 85e88f27b3Smrg .fence = timestamp, 86e88f27b3Smrg }; 87e88f27b3Smrg int ret; 88e88f27b3Smrg 893f012e29Smrg get_abs_timeout(&req.timeout, timeout); 90e88f27b3Smrg 91e88f27b3Smrg ret = drmCommandWrite(dev->fd, DRM_MSM_WAIT_FENCE, &req, sizeof(req)); 92e88f27b3Smrg if (ret) { 93e88f27b3Smrg ERROR_MSG("wait-fence failed! %d (%s)", ret, strerror(errno)); 94e88f27b3Smrg return ret; 95e88f27b3Smrg } 96e88f27b3Smrg 97e88f27b3Smrg return 0; 98e88f27b3Smrg} 99e88f27b3Smrg 100e88f27b3Smrgstatic void msm_pipe_destroy(struct fd_pipe *pipe) 101e88f27b3Smrg{ 102e88f27b3Smrg struct msm_pipe *msm_pipe = to_msm_pipe(pipe); 103e88f27b3Smrg free(msm_pipe); 104e88f27b3Smrg} 105e88f27b3Smrg 1063f012e29Smrgstatic const struct fd_pipe_funcs funcs = { 107e88f27b3Smrg .ringbuffer_new = msm_ringbuffer_new, 108e88f27b3Smrg .get_param = msm_pipe_get_param, 109e88f27b3Smrg .wait = msm_pipe_wait, 110e88f27b3Smrg .destroy = msm_pipe_destroy, 111e88f27b3Smrg}; 112e88f27b3Smrg 1133f012e29Smrgstatic uint64_t get_param(struct fd_pipe *pipe, uint32_t param) 114e88f27b3Smrg{ 1153f012e29Smrg uint64_t value; 1163f012e29Smrg int ret = query_param(pipe, param, &value); 117e88f27b3Smrg if (ret) { 118e88f27b3Smrg ERROR_MSG("get-param failed! %d (%s)", ret, strerror(errno)); 119e88f27b3Smrg return 0; 120e88f27b3Smrg } 1213f012e29Smrg return value; 122e88f27b3Smrg} 123e88f27b3Smrg 124e6188e58Smrgdrm_private struct fd_pipe * msm_pipe_new(struct fd_device *dev, 125e6188e58Smrg enum fd_pipe_id id) 126e88f27b3Smrg{ 127e88f27b3Smrg static const uint32_t pipe_id[] = { 128e88f27b3Smrg [FD_PIPE_3D] = MSM_PIPE_3D0, 129e88f27b3Smrg [FD_PIPE_2D] = MSM_PIPE_2D0, 130e88f27b3Smrg }; 131e88f27b3Smrg struct msm_pipe *msm_pipe = NULL; 132e88f27b3Smrg struct fd_pipe *pipe = NULL; 133e88f27b3Smrg 134e88f27b3Smrg msm_pipe = calloc(1, sizeof(*msm_pipe)); 135e88f27b3Smrg if (!msm_pipe) { 136e88f27b3Smrg ERROR_MSG("allocation failed"); 137e88f27b3Smrg goto fail; 138e88f27b3Smrg } 139e88f27b3Smrg 140e88f27b3Smrg pipe = &msm_pipe->base; 141e88f27b3Smrg pipe->funcs = &funcs; 142e88f27b3Smrg 1433f012e29Smrg /* initialize before get_param(): */ 1443f012e29Smrg pipe->dev = dev; 145e88f27b3Smrg msm_pipe->pipe = pipe_id[id]; 1463f012e29Smrg 1473f012e29Smrg /* these params should be supported since the first version of drm/msm: */ 1483f012e29Smrg msm_pipe->gpu_id = get_param(pipe, MSM_PARAM_GPU_ID); 1493f012e29Smrg msm_pipe->gmem = get_param(pipe, MSM_PARAM_GMEM_SIZE); 1503f012e29Smrg msm_pipe->chip_id = get_param(pipe, MSM_PARAM_CHIP_ID); 151e88f27b3Smrg 152e88f27b3Smrg if (! msm_pipe->gpu_id) 153e88f27b3Smrg goto fail; 154e88f27b3Smrg 155e88f27b3Smrg INFO_MSG("Pipe Info:"); 156e88f27b3Smrg INFO_MSG(" GPU-id: %d", msm_pipe->gpu_id); 157baaff307Smrg INFO_MSG(" Chip-id: 0x%08x", msm_pipe->chip_id); 158e88f27b3Smrg INFO_MSG(" GMEM size: 0x%08x", msm_pipe->gmem); 159e88f27b3Smrg 160e88f27b3Smrg return pipe; 161e88f27b3Smrgfail: 162e88f27b3Smrg if (pipe) 163e88f27b3Smrg fd_pipe_del(pipe); 164e88f27b3Smrg return NULL; 165e88f27b3Smrg} 166