aboutsummaryrefslogtreecommitdiffstats
path: root/libkms
diff options
context:
space:
mode:
authorDave Airlie2011-02-08 21:41:49 -0600
committerDave Airlie2011-03-03 23:25:51 -0600
commitbb994653667986757b4c906b8f144737667f7374 (patch)
tree0f7be1d571a71e37db10ecadfac5c2d6f1dfbab1 /libkms
parent5c6c6913d1260024e5d156db7973c9e46fe1ff03 (diff)
downloadexternal-libdrm-bb994653667986757b4c906b8f144737667f7374.tar.gz
external-libdrm-bb994653667986757b4c906b8f144737667f7374.tar.xz
external-libdrm-bb994653667986757b4c906b8f144737667f7374.zip
libkms: add dumb support
this uses the drm cap interface to check if the dumb ioctl is supported.
Diffstat (limited to 'libkms')
-rw-r--r--libkms/Makefile.am1
-rw-r--r--libkms/dumb.c220
-rw-r--r--libkms/internal.h2
-rw-r--r--libkms/linux.c3
4 files changed, 226 insertions, 0 deletions
diff --git a/libkms/Makefile.am b/libkms/Makefile.am
index 5c2e63fc..fa379a4b 100644
--- a/libkms/Makefile.am
+++ b/libkms/Makefile.am
@@ -16,6 +16,7 @@ libkms_la_SOURCES = \
16 internal.h \ 16 internal.h \
17 linux.c \ 17 linux.c \
18 intel.c \ 18 intel.c \
19 dumb.c \
19 api.c 20 api.c
20 21
21if HAVE_VMWGFX 22if HAVE_VMWGFX
diff --git a/libkms/dumb.c b/libkms/dumb.c
new file mode 100644
index 00000000..3be5f7a2
--- /dev/null
+++ b/libkms/dumb.c
@@ -0,0 +1,220 @@
1/**************************************************************************
2 *
3 * Copyright © 2009 VMware, Inc., Palo Alto, CA., USA
4 * All Rights Reserved.
5 *
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:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
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.
25 *
26 **************************************************************************/
27
28
29#define HAVE_STDINT_H
30#define _FILE_OFFSET_BITS 64
31
32#include <errno.h>
33#include <stdio.h>
34#include <stdlib.h>
35#include <string.h>
36#include "internal.h"
37
38#include <sys/mman.h>
39#include <sys/ioctl.h>
40#include "xf86drm.h"
41
42#include "i915_drm.h"
43
44struct dumb_bo
45{
46 struct kms_bo base;
47 unsigned map_count;
48};
49
50static int
51dumb_get_prop(struct kms_driver *kms, unsigned key, unsigned *out)
52{
53 switch (key) {
54 case KMS_BO_TYPE:
55 *out = KMS_BO_TYPE_SCANOUT_X8R8G8B8 | KMS_BO_TYPE_CURSOR_64X64_A8R8G8B8;
56 break;
57 default:
58 return -EINVAL;
59 }
60 return 0;
61}
62
63static int
64dumb_destroy(struct kms_driver *kms)
65{
66 free(kms);
67 return 0;
68}
69
70static int
71dumb_bo_create(struct kms_driver *kms,
72 const unsigned width, const unsigned height,
73 const enum kms_bo_type type, const unsigned *attr,
74 struct kms_bo **out)
75{
76 struct drm_mode_create_dumb arg;
77 struct dumb_bo *bo;
78 int i, ret;
79
80 for (i = 0; attr[i]; i += 2) {
81 switch (attr[i]) {
82 case KMS_WIDTH:
83 case KMS_HEIGHT:
84 break;
85 case KMS_BO_TYPE:
86 break;
87 default:
88 return -EINVAL;
89 }
90 }
91
92 bo = calloc(1, sizeof(*bo));
93 if (!bo)
94 return -ENOMEM;
95
96 memset(&arg, 0, sizeof(arg));
97
98 arg.bpp = 16;
99 arg.width = width;
100 arg.height = height;
101
102 ret = drmIoctl(kms->fd, DRM_IOCTL_MODE_CREATE_DUMB, &arg);
103 if (ret)
104 goto err_free;
105
106 bo->base.kms = kms;
107 bo->base.handle = arg.handle;
108 bo->base.size = arg.size;
109 bo->base.pitch = arg.pitch;
110
111 *out = &bo->base;
112
113 return 0;
114
115err_free:
116 free(bo);
117 return ret;
118}
119
120static int
121dumb_bo_get_prop(struct kms_bo *bo, unsigned key, unsigned *out)
122{
123 switch (key) {
124 default:
125 return -EINVAL;
126 }
127}
128
129static int
130dumb_bo_map(struct kms_bo *_bo, void **out)
131{
132 struct dumb_bo *bo = (struct dumb_bo *)_bo;
133 struct drm_mode_map_dumb arg;
134 void *map = NULL;
135 int ret;
136
137 if (bo->base.ptr) {
138 bo->map_count++;
139 *out = bo->base.ptr;
140 return 0;
141 }
142
143 memset(&arg, 0, sizeof(arg));
144 arg.handle = bo->base.handle;
145
146 ret = drmIoctl(bo->base.kms->fd, DRM_IOCTL_MODE_MAP_DUMB, &arg);
147 if (ret)
148 return ret;
149
150 map = mmap(0, bo->base.size, PROT_READ | PROT_WRITE, MAP_SHARED, bo->base.kms->fd, arg.offset);
151 if (map == MAP_FAILED)
152 return -errno;
153
154 bo->base.ptr = map;
155 bo->map_count++;
156 *out = bo->base.ptr;
157
158 return 0;
159}
160
161static int
162dumb_bo_unmap(struct kms_bo *_bo)
163{
164 struct dumb_bo *bo = (struct dumb_bo *)_bo;
165 bo->map_count--;
166 return 0;
167}
168
169static int
170dumb_bo_destroy(struct kms_bo *_bo)
171{
172 struct dumb_bo *bo = (struct dumb_bo *)_bo;
173 struct drm_mode_destroy_dumb arg;
174 int ret;
175
176 if (bo->base.ptr) {
177 /* XXX Sanity check map_count */
178 munmap(bo->base.ptr, bo->base.size);
179 bo->base.ptr = NULL;
180 }
181
182 memset(&arg, 0, sizeof(arg));
183 arg.handle = bo->base.handle;
184
185 ret = drmIoctl(bo->base.kms->fd, DRM_IOCTL_MODE_DESTROY_DUMB, &arg);
186 if (ret)
187 return -errno;
188
189 free(bo);
190 return 0;
191}
192
193int
194dumb_create(int fd, struct kms_driver **out)
195{
196 struct kms_driver *kms;
197 int ret;
198 uint64_t cap = 0;
199
200 ret = drmGetCap(fd, DRM_CAP_DUMB_BUFFER, &cap);
201 if (ret || cap == 0)
202 return -EINVAL;
203
204 kms = calloc(1, sizeof(*kms));
205 if (!kms)
206 return -ENOMEM;
207
208 kms->fd = fd;
209
210 kms->bo_create = dumb_bo_create;
211 kms->bo_map = dumb_bo_map;
212 kms->bo_unmap = dumb_bo_unmap;
213 kms->bo_get_prop = dumb_bo_get_prop;
214 kms->bo_destroy = dumb_bo_destroy;
215 kms->get_prop = dumb_get_prop;
216 kms->destroy = dumb_destroy;
217 *out = kms;
218
219 return 0;
220}
diff --git a/libkms/internal.h b/libkms/internal.h
index 51f5e65c..5e2501e4 100644
--- a/libkms/internal.h
+++ b/libkms/internal.h
@@ -68,6 +68,8 @@ int vmwgfx_create(int fd, struct kms_driver **out);
68 68
69int intel_create(int fd, struct kms_driver **out); 69int intel_create(int fd, struct kms_driver **out);
70 70
71int dumb_create(int fd, struct kms_driver **out);
72
71int nouveau_create(int fd, struct kms_driver **out); 73int nouveau_create(int fd, struct kms_driver **out);
72 74
73int radeon_create(int fd, struct kms_driver **out); 75int radeon_create(int fd, struct kms_driver **out);
diff --git a/libkms/linux.c b/libkms/linux.c
index 7449abc1..fc4f205c 100644
--- a/libkms/linux.c
+++ b/libkms/linux.c
@@ -216,6 +216,9 @@ linux_from_udev(int fd, struct kms_driver **out)
216int 216int
217linux_create(int fd, struct kms_driver **out) 217linux_create(int fd, struct kms_driver **out)
218{ 218{
219 if (!dumb_create(fd, out))
220 return 0;
221
219 if (!linux_from_udev(fd, out)) 222 if (!linux_from_udev(fd, out))
220 return 0; 223 return 0;
221 224