2 * Copyright © 2018 Google, Inc.
3 * Copyright © 2015 Intel Corporation
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
25 #include "tu_private.h"
29 #include <sys/ioctl.h>
32 #include "drm/msm_drm.h"
35 tu_drm_get_param(const struct tu_physical_device
*dev
,
39 /* Technically this requires a pipe, but the kernel only supports one pipe
40 * anyway at the time of writing and most of these are clearly pipe
42 struct drm_msm_param req
= {
47 int ret
= drmCommandWriteRead(dev
->local_fd
, DRM_MSM_GET_PARAM
, &req
,
58 tu_drm_get_gpu_id(const struct tu_physical_device
*dev
, uint32_t *id
)
61 int ret
= tu_drm_get_param(dev
, MSM_PARAM_GPU_ID
, &value
);
70 tu_drm_get_gmem_size(const struct tu_physical_device
*dev
, uint32_t *size
)
73 int ret
= tu_drm_get_param(dev
, MSM_PARAM_GMEM_SIZE
, &value
);
82 tu_drm_submitqueue_new(const struct tu_device
*dev
,
86 struct drm_msm_submitqueue req
= {
91 int ret
= drmCommandWriteRead(dev
->physical_device
->local_fd
,
92 DRM_MSM_SUBMITQUEUE_NEW
, &req
, sizeof(req
));
101 tu_drm_submitqueue_close(const struct tu_device
*dev
, uint32_t queue_id
)
103 drmCommandWrite(dev
->physical_device
->local_fd
, DRM_MSM_SUBMITQUEUE_CLOSE
,
104 &queue_id
, sizeof(uint32_t));
108 * Return gem handle on success. Return 0 on failure.
111 tu_gem_new(struct tu_device
*dev
, uint64_t size
, uint32_t flags
)
113 struct drm_msm_gem_new req
= {
118 int ret
= drmCommandWriteRead(dev
->physical_device
->local_fd
,
119 DRM_MSM_GEM_NEW
, &req
, sizeof(req
));
127 tu_gem_close(struct tu_device
*dev
, uint32_t gem_handle
)
129 struct drm_gem_close req
= {
130 .handle
= gem_handle
,
133 drmIoctl(dev
->physical_device
->local_fd
, DRM_IOCTL_GEM_CLOSE
, &req
);
136 /** Return UINT64_MAX on error. */
138 tu_gem_info(struct tu_device
*dev
, uint32_t gem_handle
, uint32_t info
)
140 struct drm_msm_gem_info req
= {
141 .handle
= gem_handle
,
145 int ret
= drmCommandWriteRead(dev
->physical_device
->local_fd
,
146 DRM_MSM_GEM_INFO
, &req
, sizeof(req
));
153 /** Return UINT64_MAX on error. */
155 tu_gem_info_offset(struct tu_device
*dev
, uint32_t gem_handle
)
157 return tu_gem_info(dev
, gem_handle
, MSM_INFO_GET_OFFSET
);
160 /** Return UINT64_MAX on error. */
162 tu_gem_info_iova(struct tu_device
*dev
, uint32_t gem_handle
)
164 return tu_gem_info(dev
, gem_handle
, MSM_INFO_GET_IOVA
);