1 /* -*- mode: C; c-file-style: "k&r"; tab-width 4; indent-tabs-mode: t; -*- */
4 * Copyright (C) 2013 Rob Clark <robclark@freedesktop.org>
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice (including the next
14 * paragraph) shall be included in all copies or substantial portions of the
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26 * Rob Clark <robclark@freedesktop.org>
35 static int query_param(struct fd_pipe *pipe, uint32_t param,
38 struct msm_pipe *msm_pipe = to_msm_pipe(pipe);
39 struct drm_msm_param req = {
40 .pipe = msm_pipe->pipe,
45 ret = drmCommandWriteRead(pipe->dev->fd, DRM_MSM_GET_PARAM,
55 static int msm_pipe_get_param(struct fd_pipe *pipe,
56 enum fd_param_id param, uint64_t *value)
58 struct msm_pipe *msm_pipe = to_msm_pipe(pipe);
60 case FD_DEVICE_ID: // XXX probably get rid of this..
62 *value = msm_pipe->gpu_id;
65 *value = msm_pipe->gmem;
68 *value = msm_pipe->chip_id;
71 return query_param(pipe, MSM_PARAM_MAX_FREQ, value);
73 return query_param(pipe, MSM_PARAM_TIMESTAMP, value);
75 ERROR_MSG("invalid param id: %d", param);
80 static int msm_pipe_wait(struct fd_pipe *pipe, uint32_t timestamp,
83 struct fd_device *dev = pipe->dev;
84 struct drm_msm_wait_fence req = {
89 get_abs_timeout(&req.timeout, timeout);
91 ret = drmCommandWrite(dev->fd, DRM_MSM_WAIT_FENCE, &req, sizeof(req));
93 ERROR_MSG("wait-fence failed! %d (%s)", ret, strerror(errno));
100 static void msm_pipe_destroy(struct fd_pipe *pipe)
102 struct msm_pipe *msm_pipe = to_msm_pipe(pipe);
106 static const struct fd_pipe_funcs funcs = {
107 .ringbuffer_new = msm_ringbuffer_new,
108 .get_param = msm_pipe_get_param,
109 .wait = msm_pipe_wait,
110 .destroy = msm_pipe_destroy,
113 static uint64_t get_param(struct fd_pipe *pipe, uint32_t param)
116 int ret = query_param(pipe, param, &value);
118 ERROR_MSG("get-param failed! %d (%s)", ret, strerror(errno));
124 drm_private struct fd_pipe * msm_pipe_new(struct fd_device *dev,
127 static const uint32_t pipe_id[] = {
128 [FD_PIPE_3D] = MSM_PIPE_3D0,
129 [FD_PIPE_2D] = MSM_PIPE_2D0,
131 struct msm_pipe *msm_pipe = NULL;
132 struct fd_pipe *pipe = NULL;
134 msm_pipe = calloc(1, sizeof(*msm_pipe));
136 ERROR_MSG("allocation failed");
140 pipe = &msm_pipe->base;
141 pipe->funcs = &funcs;
143 /* initialize before get_param(): */
145 msm_pipe->pipe = pipe_id[id];
147 /* these params should be supported since the first version of drm/msm: */
148 msm_pipe->gpu_id = get_param(pipe, MSM_PARAM_GPU_ID);
149 msm_pipe->gmem = get_param(pipe, MSM_PARAM_GMEM_SIZE);
150 msm_pipe->chip_id = get_param(pipe, MSM_PARAM_CHIP_ID);
152 if (! msm_pipe->gpu_id)
155 INFO_MSG("Pipe Info:");
156 INFO_MSG(" GPU-id: %d", msm_pipe->gpu_id);
157 INFO_MSG(" Chip-id: 0x%08x", msm_pipe->chip_id);
158 INFO_MSG(" GMEM size: 0x%08x", msm_pipe->gmem);