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"
31 #include <sys/ioctl.h>
34 * Return gem handle on success. Return 0 on failure.
37 tu_gem_new(struct tu_device
*dev
, uint64_t size
, uint32_t flags
)
39 struct drm_msm_gem_new req
= {
44 int ret
= drmCommandWriteRead(dev
->physical_device
->local_fd
,
45 DRM_MSM_GEM_NEW
, &req
, sizeof(req
));
53 tu_gem_close(struct tu_device
*dev
, uint32_t gem_handle
)
55 struct drm_gem_close req
= {
59 drmIoctl(dev
->physical_device
->local_fd
, DRM_IOCTL_GEM_CLOSE
, &req
);
62 /** Return UINT64_MAX on error. */
64 tu_gem_info(struct tu_device
*dev
, uint32_t gem_handle
, uint32_t flags
)
66 struct drm_msm_gem_info req
= {
71 int ret
= drmCommandWriteRead(dev
->physical_device
->local_fd
,
72 DRM_MSM_GEM_INFO
, &req
, sizeof(req
));
79 /** Return UINT64_MAX on error. */
81 tu_gem_info_offset(struct tu_device
*dev
, uint32_t gem_handle
)
83 return tu_gem_info(dev
, gem_handle
, 0);
86 /** Return UINT64_MAX on error. */
88 tu_gem_info_iova(struct tu_device
*dev
, uint32_t gem_handle
)
90 return tu_gem_info(dev
, gem_handle
, MSM_INFO_IOVA
);
94 tu_drm_query_param(struct tu_physical_device
*dev
,
98 /* Technically this requires a pipe, but the kernel only supports one pipe
99 * anyway at the time of writing and most of these are clearly pipe
101 struct drm_msm_param req
= {
102 .pipe
= MSM_PIPE_3D0
,
106 int ret
= drmCommandWriteRead(dev
->local_fd
, DRM_MSM_GET_PARAM
, &req
,