1 /**********************************************************
2 * Copyright 2009 VMware, Inc. All rights reserved.
4 * Permission is hereby granted, free of charge, to any person
5 * obtaining a copy of this software and associated documentation
6 * files (the "Software"), to deal in the Software without
7 * restriction, including without limitation the rights to use, copy,
8 * modify, merge, publish, distribute, sublicense, and/or sell copies
9 * of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice shall be
13 * included in all copies or substantial portions of the Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24 **********************************************************/
28 * Contains the functions for creating dma buffers by calling
29 * the kernel via driver specific ioctls.
31 * @author Jakob Bornecrantz <jakob@vmware.com>
35 #define HAVE_STDINT_H 1
37 #define _FILE_OFFSET_BITS 64
45 #include "../../winsys/svga/drm/vmwgfx_drm.h"
47 #include "vmw_driver.h"
48 #include "util/u_debug.h"
60 vmw_ioctl_get_param(struct vmw_customizer
*vmw
, uint32_t param
, uint64_t *out
)
62 struct drm_vmw_getparam_arg gp_arg
;
65 memset(&gp_arg
, 0, sizeof(gp_arg
));
67 ret
= drmCommandWriteRead(vmw
->fd
, DRM_VMW_GET_PARAM
,
68 &gp_arg
, sizeof(gp_arg
));
78 vmw_ioctl_supports_streams(struct vmw_customizer
*vmw
)
83 ret
= vmw_ioctl_get_param(vmw
, DRM_VMW_PARAM_NUM_STREAMS
, &value
);
87 return value
? 0 : -ENOSYS
;
91 vmw_ioctl_num_streams(struct vmw_customizer
*vmw
,
92 uint32_t *ntot
, uint32_t *nfree
)
97 ret
= vmw_ioctl_get_param(vmw
, DRM_VMW_PARAM_NUM_STREAMS
, &v1
);
101 ret
= vmw_ioctl_get_param(vmw
, DRM_VMW_PARAM_NUM_FREE_STREAMS
, &v2
);
105 *ntot
= (uint32_t)v1
;
106 *nfree
= (uint32_t)v2
;
112 vmw_ioctl_claim_stream(struct vmw_customizer
*vmw
, uint32_t *out
)
114 struct drm_vmw_stream_arg s_arg
;
117 ret
= drmCommandRead(vmw
->fd
, DRM_VMW_CLAIM_STREAM
,
118 &s_arg
, sizeof(s_arg
));
123 *out
= s_arg
.stream_id
;
128 vmw_ioctl_unref_stream(struct vmw_customizer
*vmw
, uint32_t stream_id
)
130 struct drm_vmw_stream_arg s_arg
;
133 memset(&s_arg
, 0, sizeof(s_arg
));
134 s_arg
.stream_id
= stream_id
;
136 ret
= drmCommandRead(vmw
->fd
, DRM_VMW_CLAIM_STREAM
,
137 &s_arg
, sizeof(s_arg
));
143 vmw_ioctl_cursor_bypass(struct vmw_customizer
*vmw
, int xhot
, int yhot
)
145 struct drm_vmw_cursor_bypass_arg arg
;
148 memset(&arg
, 0, sizeof(arg
));
149 arg
.flags
= DRM_VMW_CURSOR_BYPASS_ALL
;
153 ret
= drmCommandWrite(vmw
->fd
, DRM_VMW_CURSOR_BYPASS
,
159 struct vmw_dma_buffer
*
160 vmw_ioctl_buffer_create(struct vmw_customizer
*vmw
, uint32_t size
, unsigned *handle
)
162 struct vmw_dma_buffer
*buf
;
163 union drm_vmw_alloc_dmabuf_arg arg
;
164 struct drm_vmw_alloc_dmabuf_req
*req
= &arg
.req
;
165 struct drm_vmw_dmabuf_rep
*rep
= &arg
.rep
;
168 buf
= xcalloc(1, sizeof(*buf
));
172 memset(&arg
, 0, sizeof(arg
));
175 ret
= drmCommandWriteRead(vmw
->fd
, DRM_VMW_ALLOC_DMABUF
, &arg
, sizeof(arg
));
176 } while (ret
== -ERESTART
);
179 debug_printf("IOCTL failed %d: %s\n", ret
, strerror(-ret
));
185 buf
->handle
= rep
->handle
;
186 buf
->map_handle
= rep
->map_handle
;
190 *handle
= rep
->handle
;
201 vmw_ioctl_buffer_destroy(struct vmw_customizer
*vmw
, struct vmw_dma_buffer
*buf
)
203 struct drm_vmw_unref_dmabuf_arg arg
;
206 munmap(buf
->data
, buf
->size
);
210 memset(&arg
, 0, sizeof(arg
));
211 arg
.handle
= buf
->handle
;
212 drmCommandWrite(vmw
->fd
, DRM_VMW_UNREF_DMABUF
, &arg
, sizeof(arg
));
218 vmw_ioctl_buffer_map(struct vmw_customizer
*vmw
, struct vmw_dma_buffer
*buf
)
222 if (buf
->data
== NULL
) {
223 map
= mmap(NULL
, buf
->size
, PROT_READ
| PROT_WRITE
, MAP_SHARED
,
224 vmw
->fd
, buf
->map_handle
);
225 if (map
== MAP_FAILED
) {
226 debug_printf("%s: Map failed.\n", __FUNCTION__
);
239 vmw_ioctl_buffer_unmap(struct vmw_customizer
*vmw
, struct vmw_dma_buffer
*buf
)
245 vmw_ioctl_update_layout(struct vmw_customizer
*vmw
, uint32_t num
, struct vmw_rect
*rects
)
247 struct drm_vmw_update_layout_arg ul_arg
;
250 assert(sizeof(struct vmw_rect
) == sizeof(struct drm_vmw_rect
));
252 memset(&ul_arg
, 0, sizeof(ul_arg
));
253 ul_arg
.num_outputs
= num
;
254 ul_arg
.rects
= (uint64_t)(uintptr_t)rects
;
256 ret
= drmCommandWriteRead(vmw
->fd
, DRM_VMW_UPDATE_LAYOUT
,
257 &ul_arg
, sizeof(ul_arg
));