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 <sys/ioctl.h>
42 #include "radeon_drm.h"
54 radeon_get_prop(struct kms_driver *kms, unsigned key, unsigned *out)
58 *out = KMS_BO_TYPE_SCANOUT_X8R8G8B8 | KMS_BO_TYPE_CURSOR_64X64_A8R8G8B8;
67 radeon_destroy(struct kms_driver *kms)
74 radeon_bo_create(struct kms_driver *kms,
75 const unsigned width, const unsigned height,
76 const enum kms_bo_type type, const unsigned *attr,
79 struct drm_radeon_gem_create arg;
84 for (i = 0; attr[i]; i += 2) {
96 case KMS_BO_TYPE_CURSOR_64X64_A8R8G8B8:
100 case KMS_BO_TYPE_SCANOUT_X8R8G8B8:
102 pitch = (pitch + ALIGNMENT - 1) & ~(ALIGNMENT - 1);
103 size = pitch * height;
109 bo = calloc(1, sizeof(*bo));
113 memset(&arg, 0, sizeof(arg));
115 arg.alignment = ALIGNMENT;
116 arg.initial_domain = RADEON_GEM_DOMAIN_CPU;
120 ret = drmCommandWriteRead(kms->fd, DRM_RADEON_GEM_CREATE,
126 bo->base.handle = arg.handle;
127 bo->base.size = size;
128 bo->base.pitch = pitch;
142 radeon_bo_get_prop(struct kms_bo *bo, unsigned key, unsigned *out)
151 radeon_bo_map(struct kms_bo *_bo, void **out)
153 struct radeon_bo *bo = (struct radeon_bo *)_bo;
154 struct drm_radeon_gem_mmap arg;
164 memset(&arg, 0, sizeof(arg));
165 arg.handle = bo->base.handle;
166 arg.offset = bo->base.offset;
167 arg.size = (uint64_t)bo->base.size;
169 ret = drmCommandWriteRead(bo->base.kms->fd, DRM_RADEON_GEM_MMAP,
174 map = mmap(0, arg.size, PROT_READ | PROT_WRITE, MAP_SHARED,
175 bo->base.kms->fd, arg.addr_ptr);
176 if (map == MAP_FAILED)
187 radeon_bo_unmap(struct kms_bo *_bo)
189 struct radeon_bo *bo = (struct radeon_bo *)_bo;
190 if (--bo->map_count == 0) {
191 munmap(bo->base.ptr, bo->base.size);
198 radeon_bo_destroy(struct kms_bo *_bo)
200 struct radeon_bo *bo = (struct radeon_bo *)_bo;
201 struct drm_gem_close arg;
205 /* XXX Sanity check map_count */
206 munmap(bo->base.ptr, bo->base.size);
210 memset(&arg, 0, sizeof(arg));
211 arg.handle = bo->base.handle;
213 ret = drmIoctl(bo->base.kms->fd, DRM_IOCTL_GEM_CLOSE, &arg);
222 radeon_create(int fd, struct kms_driver **out)
224 struct kms_driver *kms;
226 kms = calloc(1, sizeof(*kms));
232 kms->bo_create = radeon_bo_create;
233 kms->bo_map = radeon_bo_map;
234 kms->bo_unmap = radeon_bo_unmap;
235 kms->bo_get_prop = radeon_bo_get_prop;
236 kms->bo_destroy = radeon_bo_destroy;
237 kms->get_prop = radeon_get_prop;
238 kms->destroy = radeon_destroy;