1 /**************************************************************************
3 * Copyright © 2009 VMware, Inc., Palo Alto, CA., USA
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
21 * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
22 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
23 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
24 * USE OR OTHER DEALINGS IN THE SOFTWARE.
26 **************************************************************************/
30 #define _FILE_OFFSET_BITS 64
39 #include "vmwgfx_drm.h"
49 vmwgfx_get_prop(struct kms_driver *kms, unsigned key, unsigned *out)
52 case KMS_MAX_SCANOUT_WIDTH:
55 case KMS_MAX_SCANOUT_HEIGHT:
58 case KMS_MIN_SCANOUT_WIDTH:
61 case KMS_MIN_SCANOUT_HEIGHT:
64 case KMS_MAX_CURSOR_WIDTH:
67 case KMS_MAX_CURSOR_HEIGHT:
70 case KMS_MIN_CURSOR_WIDTH:
73 case KMS_MIN_CURSOR_HEIGHT:
83 vmwgfx_destroy(struct kms_driver *kms)
90 vmwgfx_bo_create(struct kms_driver *kms,
91 const unsigned width, const unsigned height,
92 const enum kms_bo_type type, const unsigned *attr,
98 for (i = 0; attr[i]; i += 2) {
109 bo = calloc(1, sizeof(*bo));
114 union drm_vmw_alloc_dmabuf_arg arg;
115 struct drm_vmw_alloc_dmabuf_req *req = &arg.req;
116 struct drm_vmw_dmabuf_rep *rep = &arg.rep;
118 memset(&arg, 0, sizeof(arg));
119 req->size = width * height * 4;
120 bo->base.size = req->size;
121 bo->base.pitch = width * 4;
125 ret = drmCommandWriteRead(bo->base.kms->fd,
126 DRM_VMW_ALLOC_DMABUF,
128 } while (ret == -ERESTART);
133 bo->base.handle = rep->handle;
134 bo->map_handle = rep->map_handle;
135 bo->base.handle = rep->cur_gmr_id;
136 bo->base.offset = rep->cur_gmr_offset;
149 vmwgfx_bo_get_prop(struct kms_bo *bo, unsigned key, unsigned *out)
158 vmwgfx_bo_map(struct kms_bo *_bo, void **out)
160 struct vmwgfx_bo *bo = (struct vmwgfx_bo *)_bo;
169 map = mmap(NULL, bo->base.size, PROT_READ | PROT_WRITE, MAP_SHARED, bo->base.kms->fd, bo->map_handle);
170 if (map == MAP_FAILED)
181 vmwgfx_bo_unmap(struct kms_bo *_bo)
183 struct vmwgfx_bo *bo = (struct vmwgfx_bo *)_bo;
189 vmwgfx_bo_destroy(struct kms_bo *_bo)
191 struct vmwgfx_bo *bo = (struct vmwgfx_bo *)_bo;
192 struct drm_vmw_unref_dmabuf_arg arg;
195 /* XXX Sanity check map_count */
196 munmap(bo->base.ptr, bo->base.size);
200 memset(&arg, 0, sizeof(arg));
201 arg.handle = bo->base.handle;
202 drmCommandWrite(bo->base.kms->fd, DRM_VMW_UNREF_DMABUF, &arg, sizeof(arg));
209 vmwgfx_create(int fd, struct kms_driver **out)
211 struct kms_driver *kms;
213 kms = calloc(1, sizeof(*kms));
219 kms->bo_create = vmwgfx_bo_create;
220 kms->bo_map = vmwgfx_bo_map;
221 kms->bo_unmap = vmwgfx_bo_unmap;
222 kms->bo_get_prop = vmwgfx_bo_get_prop;
223 kms->bo_destroy = vmwgfx_bo_destroy;
224 kms->get_prop = vmwgfx_get_prop;
225 kms->destroy = vmwgfx_destroy;