2 * Copyright (C) 2012-2018 Rob Clark <robclark@freedesktop.org>
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24 * Rob Clark <robclark@freedesktop.org>
27 #include "util/slab.h"
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 query_queue_param(struct fd_pipe
*pipe
, uint32_t param
,
54 struct msm_pipe
*msm_pipe
= to_msm_pipe(pipe
);
55 struct drm_msm_submitqueue_query req
= {
57 .id
= msm_pipe
->queue_id
,
59 .len
= sizeof(*value
),
63 ret
= drmCommandWriteRead(pipe
->dev
->fd
, DRM_MSM_SUBMITQUEUE_QUERY
,
71 static int msm_pipe_get_param(struct fd_pipe
*pipe
,
72 enum fd_param_id param
, uint64_t *value
)
74 struct msm_pipe
*msm_pipe
= to_msm_pipe(pipe
);
76 case FD_DEVICE_ID
: // XXX probably get rid of this..
78 *value
= msm_pipe
->gpu_id
;
81 *value
= msm_pipe
->gmem
;
84 *value
= msm_pipe
->chip_id
;
87 return query_param(pipe
, MSM_PARAM_MAX_FREQ
, value
);
89 return query_param(pipe
, MSM_PARAM_TIMESTAMP
, value
);
91 return query_param(pipe
, MSM_PARAM_NR_RINGS
, value
);
93 return query_param(pipe
, MSM_PARAM_PP_PGTABLE
, value
);
95 return query_queue_param(pipe
, MSM_SUBMITQUEUE_PARAM_FAULTS
, value
);
96 case FD_GLOBAL_FAULTS
:
97 return query_param(pipe
, MSM_PARAM_FAULTS
, value
);
99 ERROR_MSG("invalid param id: %d", param
);
104 static int msm_pipe_wait(struct fd_pipe
*pipe
, uint32_t timestamp
,
107 struct fd_device
*dev
= pipe
->dev
;
108 struct drm_msm_wait_fence req
= {
110 .queueid
= to_msm_pipe(pipe
)->queue_id
,
114 get_abs_timeout(&req
.timeout
, timeout
);
116 ret
= drmCommandWrite(dev
->fd
, DRM_MSM_WAIT_FENCE
, &req
, sizeof(req
));
118 ERROR_MSG("wait-fence failed! %d (%s)", ret
, strerror(errno
));
125 static int open_submitqueue(struct fd_pipe
*pipe
, uint32_t prio
)
127 struct drm_msm_submitqueue req
= {
131 uint64_t nr_rings
= 1;
134 if (fd_device_version(pipe
->dev
) < FD_VERSION_SUBMIT_QUEUES
) {
135 to_msm_pipe(pipe
)->queue_id
= 0;
139 msm_pipe_get_param(pipe
, FD_NR_RINGS
, &nr_rings
);
141 req
.prio
= MIN2(req
.prio
, MAX2(nr_rings
, 1) - 1);
143 ret
= drmCommandWriteRead(pipe
->dev
->fd
, DRM_MSM_SUBMITQUEUE_NEW
,
146 ERROR_MSG("could not create submitqueue! %d (%s)", ret
, strerror(errno
));
150 to_msm_pipe(pipe
)->queue_id
= req
.id
;
154 static void close_submitqueue(struct fd_pipe
*pipe
, uint32_t queue_id
)
156 if (fd_device_version(pipe
->dev
) < FD_VERSION_SUBMIT_QUEUES
)
159 drmCommandWrite(pipe
->dev
->fd
, DRM_MSM_SUBMITQUEUE_CLOSE
,
160 &queue_id
, sizeof(queue_id
));
163 static void msm_pipe_destroy(struct fd_pipe
*pipe
)
165 struct msm_pipe
*msm_pipe
= to_msm_pipe(pipe
);
166 close_submitqueue(pipe
, msm_pipe
->queue_id
);
170 static const struct fd_pipe_funcs sp_funcs
= {
171 .ringbuffer_new_object
= msm_ringbuffer_sp_new_object
,
172 .submit_new
= msm_submit_sp_new
,
173 .get_param
= msm_pipe_get_param
,
174 .wait
= msm_pipe_wait
,
175 .destroy
= msm_pipe_destroy
,
178 static const struct fd_pipe_funcs legacy_funcs
= {
179 .ringbuffer_new_object
= msm_ringbuffer_new_object
,
180 .submit_new
= msm_submit_new
,
181 .get_param
= msm_pipe_get_param
,
182 .wait
= msm_pipe_wait
,
183 .destroy
= msm_pipe_destroy
,
186 static uint64_t get_param(struct fd_pipe
*pipe
, uint32_t param
)
189 int ret
= query_param(pipe
, param
, &value
);
191 ERROR_MSG("get-param failed! %d (%s)", ret
, strerror(errno
));
197 struct fd_pipe
* msm_pipe_new(struct fd_device
*dev
,
198 enum fd_pipe_id id
, uint32_t prio
)
200 static const uint32_t pipe_id
[] = {
201 [FD_PIPE_3D
] = MSM_PIPE_3D0
,
202 [FD_PIPE_2D
] = MSM_PIPE_2D0
,
204 struct msm_pipe
*msm_pipe
= NULL
;
205 struct fd_pipe
*pipe
= NULL
;
207 msm_pipe
= calloc(1, sizeof(*msm_pipe
));
209 ERROR_MSG("allocation failed");
213 pipe
= &msm_pipe
->base
;
215 if (fd_device_version(dev
) >= FD_VERSION_SOFTPIN
) {
216 pipe
->funcs
= &sp_funcs
;
218 pipe
->funcs
= &legacy_funcs
;
221 /* initialize before get_param(): */
223 msm_pipe
->pipe
= pipe_id
[id
];
225 /* these params should be supported since the first version of drm/msm: */
226 msm_pipe
->gpu_id
= get_param(pipe
, MSM_PARAM_GPU_ID
);
227 msm_pipe
->gmem
= get_param(pipe
, MSM_PARAM_GMEM_SIZE
);
228 msm_pipe
->chip_id
= get_param(pipe
, MSM_PARAM_CHIP_ID
);
230 if (! msm_pipe
->gpu_id
)
233 INFO_MSG("Pipe Info:");
234 INFO_MSG(" GPU-id: %d", msm_pipe
->gpu_id
);
235 INFO_MSG(" Chip-id: 0x%08x", msm_pipe
->chip_id
);
236 INFO_MSG(" GMEM size: 0x%08x", msm_pipe
->gmem
);
238 if (open_submitqueue(pipe
, prio
))