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>
31 static int query_param(struct fd_pipe *pipe, uint32_t param,
34 struct msm_pipe *msm_pipe = to_msm_pipe(pipe);
35 struct drm_msm_param req = {
36 .pipe = msm_pipe->pipe,
41 ret = drmCommandWriteRead(pipe->dev->fd, DRM_MSM_GET_PARAM,
51 static int msm_pipe_get_param(struct fd_pipe *pipe,
52 enum fd_param_id param, uint64_t *value)
54 struct msm_pipe *msm_pipe = to_msm_pipe(pipe);
56 case FD_DEVICE_ID: // XXX probably get rid of this..
58 *value = msm_pipe->gpu_id;
61 *value = msm_pipe->gmem;
64 *value = msm_pipe->chip_id;
67 return query_param(pipe, MSM_PARAM_MAX_FREQ, value);
69 return query_param(pipe, MSM_PARAM_TIMESTAMP, value);
71 return query_param(pipe, MSM_PARAM_NR_RINGS, value);
73 ERROR_MSG("invalid param id: %d", param);
78 static int msm_pipe_wait(struct fd_pipe *pipe, uint32_t timestamp,
81 struct fd_device *dev = pipe->dev;
82 struct drm_msm_wait_fence req = {
84 .queueid = to_msm_pipe(pipe)->queue_id,
88 get_abs_timeout(&req.timeout, timeout);
90 ret = drmCommandWrite(dev->fd, DRM_MSM_WAIT_FENCE, &req, sizeof(req));
92 ERROR_MSG("wait-fence failed! %d (%s)", ret, strerror(errno));
99 static int open_submitqueue(struct fd_pipe *pipe, uint32_t prio)
101 struct drm_msm_submitqueue req = {
105 uint64_t nr_rings = 1;
108 if (fd_device_version(pipe->dev) < FD_VERSION_SUBMIT_QUEUES) {
109 to_msm_pipe(pipe)->queue_id = 0;
113 msm_pipe_get_param(pipe, FD_NR_RINGS, &nr_rings);
115 req.prio = MIN2(req.prio, MAX2(nr_rings, 1) - 1);
117 ret = drmCommandWriteRead(pipe->dev->fd, DRM_MSM_SUBMITQUEUE_NEW,
120 ERROR_MSG("could not create submitqueue! %d (%s)", ret, strerror(errno));
124 to_msm_pipe(pipe)->queue_id = req.id;
128 static void close_submitqueue(struct fd_pipe *pipe, uint32_t queue_id)
130 if (fd_device_version(pipe->dev) < FD_VERSION_SUBMIT_QUEUES)
133 drmCommandWrite(pipe->dev->fd, DRM_MSM_SUBMITQUEUE_CLOSE,
134 &queue_id, sizeof(queue_id));
137 static void msm_pipe_destroy(struct fd_pipe *pipe)
139 struct msm_pipe *msm_pipe = to_msm_pipe(pipe);
140 close_submitqueue(pipe, msm_pipe->queue_id);
142 if (msm_pipe->suballoc_ring) {
143 fd_ringbuffer_del(msm_pipe->suballoc_ring);
144 msm_pipe->suballoc_ring = NULL;
150 static const struct fd_pipe_funcs funcs = {
151 .ringbuffer_new = msm_ringbuffer_new,
152 .get_param = msm_pipe_get_param,
153 .wait = msm_pipe_wait,
154 .destroy = msm_pipe_destroy,
157 static uint64_t get_param(struct fd_pipe *pipe, uint32_t param)
160 int ret = query_param(pipe, param, &value);
162 ERROR_MSG("get-param failed! %d (%s)", ret, strerror(errno));
168 drm_private struct fd_pipe * msm_pipe_new(struct fd_device *dev,
169 enum fd_pipe_id id, uint32_t prio)
171 static const uint32_t pipe_id[] = {
172 [FD_PIPE_3D] = MSM_PIPE_3D0,
173 [FD_PIPE_2D] = MSM_PIPE_2D0,
175 struct msm_pipe *msm_pipe = NULL;
176 struct fd_pipe *pipe = NULL;
178 msm_pipe = calloc(1, sizeof(*msm_pipe));
180 ERROR_MSG("allocation failed");
184 pipe = &msm_pipe->base;
185 pipe->funcs = &funcs;
187 /* initialize before get_param(): */
189 msm_pipe->pipe = pipe_id[id];
191 /* these params should be supported since the first version of drm/msm: */
192 msm_pipe->gpu_id = get_param(pipe, MSM_PARAM_GPU_ID);
193 msm_pipe->gmem = get_param(pipe, MSM_PARAM_GMEM_SIZE);
194 msm_pipe->chip_id = get_param(pipe, MSM_PARAM_CHIP_ID);
196 if (! msm_pipe->gpu_id)
199 INFO_MSG("Pipe Info:");
200 INFO_MSG(" GPU-id: %d", msm_pipe->gpu_id);
201 INFO_MSG(" Chip-id: 0x%08x", msm_pipe->chip_id);
202 INFO_MSG(" GMEM size: 0x%08x", msm_pipe->gmem);
204 if (open_submitqueue(pipe, prio))