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 **************************************************************************/
35 #include <sys/ioctl.h>
37 #include "libdrm_macros.h"
46 dumb_get_prop(struct kms_driver
*kms
, unsigned key
, unsigned *out
)
50 *out
= KMS_BO_TYPE_SCANOUT_X8R8G8B8
| KMS_BO_TYPE_CURSOR_64X64_A8R8G8B8
;
59 dumb_destroy(struct kms_driver
*kms
)
66 dumb_bo_create(struct kms_driver
*kms
,
67 const unsigned width
, const unsigned height
,
68 const enum kms_bo_type type
, const unsigned *attr
,
71 struct drm_mode_create_dumb arg
;
75 for (i
= 0; attr
[i
]; i
+= 2) {
87 bo
= calloc(1, sizeof(*bo
));
91 memset(&arg
, 0, sizeof(arg
));
93 /* All BO_TYPE currently are 32bpp formats */
98 ret
= drmIoctl(kms
->fd
, DRM_IOCTL_MODE_CREATE_DUMB
, &arg
);
103 bo
->base
.handle
= arg
.handle
;
104 bo
->base
.size
= arg
.size
;
105 bo
->base
.pitch
= arg
.pitch
;
117 dumb_bo_get_prop(struct kms_bo
*bo
, unsigned key
, unsigned *out
)
126 dumb_bo_map(struct kms_bo
*_bo
, void **out
)
128 struct dumb_bo
*bo
= (struct dumb_bo
*)_bo
;
129 struct drm_mode_map_dumb arg
;
139 memset(&arg
, 0, sizeof(arg
));
140 arg
.handle
= bo
->base
.handle
;
142 ret
= drmIoctl(bo
->base
.kms
->fd
, DRM_IOCTL_MODE_MAP_DUMB
, &arg
);
146 map
= drm_mmap(0, bo
->base
.size
, PROT_READ
| PROT_WRITE
, MAP_SHARED
, bo
->base
.kms
->fd
, arg
.offset
);
147 if (map
== MAP_FAILED
)
158 dumb_bo_unmap(struct kms_bo
*_bo
)
160 struct dumb_bo
*bo
= (struct dumb_bo
*)_bo
;
166 dumb_bo_destroy(struct kms_bo
*_bo
)
168 struct dumb_bo
*bo
= (struct dumb_bo
*)_bo
;
169 struct drm_mode_destroy_dumb arg
;
173 /* XXX Sanity check map_count */
174 drm_munmap(bo
->base
.ptr
, bo
->base
.size
);
178 memset(&arg
, 0, sizeof(arg
));
179 arg
.handle
= bo
->base
.handle
;
181 ret
= drmIoctl(bo
->base
.kms
->fd
, DRM_IOCTL_MODE_DESTROY_DUMB
, &arg
);
190 dumb_create(int fd
, struct kms_driver
**out
)
192 struct kms_driver
*kms
;
196 ret
= drmGetCap(fd
, DRM_CAP_DUMB_BUFFER
, &cap
);
200 kms
= calloc(1, sizeof(*kms
));
206 kms
->bo_create
= dumb_bo_create
;
207 kms
->bo_map
= dumb_bo_map
;
208 kms
->bo_unmap
= dumb_bo_unmap
;
209 kms
->bo_get_prop
= dumb_bo_get_prop
;
210 kms
->bo_destroy
= dumb_bo_destroy
;
211 kms
->get_prop
= dumb_get_prop
;
212 kms
->destroy
= dumb_destroy
;