aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJakob Bornecrantz2009-11-24 10:54:10 -0600
committerJakob Bornecrantz2009-12-04 09:11:55 -0600
commit8c0571a73399c372644c8d92a136a474f3e05d48 (patch)
tree1067f940118c64267f4a0bfe49b04e9f4971e94d
parent28eae30689610faa0fe043ab869587e7699e82bf (diff)
downloadexternal-libdrm-8c0571a73399c372644c8d92a136a474f3e05d48.tar.gz
external-libdrm-8c0571a73399c372644c8d92a136a474f3e05d48.tar.xz
external-libdrm-8c0571a73399c372644c8d92a136a474f3e05d48.zip
libkms: Add libkms
-rw-r--r--.gitignore1
-rw-r--r--Makefile.am6
-rw-r--r--configure.ac10
-rw-r--r--libkms/Makefile.am20
-rw-r--r--libkms/api.c124
-rw-r--r--libkms/internal.h67
-rw-r--r--libkms/libkms.h69
-rw-r--r--libkms/libkms.pc.in10
-rw-r--r--libkms/vmwgfx.c226
-rw-r--r--libkms/vmwgfx_drm.h441
10 files changed, 973 insertions, 1 deletions
diff --git a/.gitignore b/.gitignore
index 0864fd9d..2832fc2d 100644
--- a/.gitignore
+++ b/.gitignore
@@ -42,6 +42,7 @@ libdrm.pc
42libdrm_intel.pc 42libdrm_intel.pc
43libdrm_nouveau.pc 43libdrm_nouveau.pc
44libdrm_radeon.pc 44libdrm_radeon.pc
45libkms.pc
45libtool 46libtool
46ltmain.sh 47ltmain.sh
47mach64.kld 48mach64.kld
diff --git a/Makefile.am b/Makefile.am
index 41e5a342..ee3ccc70 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -25,6 +25,10 @@ DISTCHECK_CONFIGURE_FLAGS = --enable-nouveau-experimental-api --enable-radeon-ex
25pkgconfigdir = @pkgconfigdir@ 25pkgconfigdir = @pkgconfigdir@
26pkgconfig_DATA = libdrm.pc 26pkgconfig_DATA = libdrm.pc
27 27
28if HAVE_LIBKMS
29LIBKMS_SUBDIR = libkms
30endif
31
28if HAVE_INTEL 32if HAVE_INTEL
29INTEL_SUBDIR = intel 33INTEL_SUBDIR = intel
30endif 34endif
@@ -37,7 +41,7 @@ if HAVE_RADEON
37RADEON_SUBDIR = radeon 41RADEON_SUBDIR = radeon
38endif 42endif
39 43
40SUBDIRS = . $(INTEL_SUBDIR) $(NOUVEAU_SUBDIR) $(RADEON_SUBDIR) tests include 44SUBDIRS = . $(LIBKMS_SUBDIR) $(INTEL_SUBDIR) $(NOUVEAU_SUBDIR) $(RADEON_SUBDIR) tests include
41 45
42libdrm_la_LTLIBRARIES = libdrm.la 46libdrm_la_LTLIBRARIES = libdrm.la
43libdrm_ladir = $(libdir) 47libdrm_ladir = $(libdir)
diff --git a/configure.ac b/configure.ac
index b8842201..52c591dd 100644
--- a/configure.ac
+++ b/configure.ac
@@ -43,6 +43,11 @@ AC_ARG_ENABLE(udev, AS_HELP_STRING([--enable-udev],
43 [Enable support for using udev instead of mknod (default: disabled)]), 43 [Enable support for using udev instead of mknod (default: disabled)]),
44 [UDEV=$enableval], [UDEV=no]) 44 [UDEV=$enableval], [UDEV=no])
45 45
46AC_ARG_ENABLE(libkms,
47 AS_HELP_STRING([--disable-libkms],
48 [Enable KMS mm abstraction library (default: yes)]),
49 [LIBKMS=$enableval], [LIBKMS=yes])
50
46AC_ARG_ENABLE(intel, 51AC_ARG_ENABLE(intel,
47 AS_HELP_STRING([--disable-intel], 52 AS_HELP_STRING([--disable-intel],
48 [Enable support for intel's KMS API (default: auto)]), 53 [Enable support for intel's KMS API (default: auto)]),
@@ -134,6 +139,8 @@ if test "x$UDEV" = xyes; then
134 AC_DEFINE(UDEV, 1, [Have UDEV support]) 139 AC_DEFINE(UDEV, 1, [Have UDEV support])
135fi 140fi
136 141
142AM_CONDITIONAL(HAVE_LIBKMS, [test "x$LIBKMS" = xyes])
143
137AM_CONDITIONAL(HAVE_NOUVEAU, [test "x$NOUVEAU" = xyes]) 144AM_CONDITIONAL(HAVE_NOUVEAU, [test "x$NOUVEAU" = xyes])
138 145
139AM_CONDITIONAL(HAVE_RADEON, [test "x$RADEON" = xyes]) 146AM_CONDITIONAL(HAVE_RADEON, [test "x$RADEON" = xyes])
@@ -199,6 +206,8 @@ AC_SUBST(kernel_source)
199AC_SUBST(WARN_CFLAGS) 206AC_SUBST(WARN_CFLAGS)
200AC_OUTPUT([ 207AC_OUTPUT([
201 Makefile 208 Makefile
209 libkms/Makefile
210 libkms/libkms.pc
202 intel/Makefile 211 intel/Makefile
203 intel/libdrm_intel.pc 212 intel/libdrm_intel.pc
204 radeon/Makefile 213 radeon/Makefile
@@ -215,6 +224,7 @@ AC_OUTPUT([
215echo "" 224echo ""
216echo "$PACKAGE_STRING will be compiled with:" 225echo "$PACKAGE_STRING will be compiled with:"
217echo "" 226echo ""
227echo " libkms $LIBKMS"
218echo " Intel API $INTEL" 228echo " Intel API $INTEL"
219echo " Radeon API $RADEON" 229echo " Radeon API $RADEON"
220echo " Nouveau API $NOUVEAU" 230echo " Nouveau API $NOUVEAU"
diff --git a/libkms/Makefile.am b/libkms/Makefile.am
new file mode 100644
index 00000000..d65d6012
--- /dev/null
+++ b/libkms/Makefile.am
@@ -0,0 +1,20 @@
1AM_CFLAGS = \
2 $(WARN_CFLAGS) \
3 -I$(top_srcdir)/include/drm
4
5libkms_la_LTLIBRARIES = libkms.la
6libkms_ladir = $(libdir)
7libkms_la_LDFLAGS = -version-number 1:0:0 -no-undefined
8libkms_la_LIBADD =
9
10libkms_la_SOURCES = \
11 api.c \
12 vmwgfx.c
13
14libkmsincludedir = ${includedir}/libkms
15libkmsinclude_HEADERS = libkms.h
16
17pkgconfigdir = @pkgconfigdir@
18pkgconfig_DATA = libkms.pc
19
20EXTRA_DIST = libkms.pc.in
diff --git a/libkms/api.c b/libkms/api.c
new file mode 100644
index 00000000..f15ee70b
--- /dev/null
+++ b/libkms/api.c
@@ -0,0 +1,124 @@
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#include <errno.h>
30#include <stdlib.h>
31#include <string.h>
32#include "internal.h"
33
34int kms_create(int fd, struct kms_driver **out)
35{
36 return vmwgfx_create(fd, out);
37}
38
39int kms_get_prop(struct kms_driver *kms, unsigned key, unsigned *out)
40{
41 switch (key) {
42 case KMS_MAX_SCANOUT_WIDTH:
43 case KMS_MAX_SCANOUT_HEIGHT:
44 case KMS_MIN_SCANOUT_WIDTH:
45 case KMS_MIN_SCANOUT_HEIGHT:
46 case KMS_MAX_CURSOR_WIDTH:
47 case KMS_MAX_CURSOR_HEIGHT:
48 case KMS_MIN_CURSOR_WIDTH:
49 case KMS_MIN_CURSOR_HEIGHT:
50 break;
51 default:
52 return -EINVAL;
53 }
54 return kms->get_prop(kms, key, out);
55}
56
57int kms_destroy(struct kms_driver *kms)
58{
59 free(kms);
60 return 0;
61}
62
63int kms_bo_create(struct kms_driver *kms, const unsigned *attr, struct kms_bo **out)
64{
65 unsigned width = 0;
66 unsigned height = 0;
67 enum kms_bo_type type = KMS_BO_TYPE_SCANOUT;
68 int i;
69
70 for (i = 0; attr[i];) {
71 unsigned key = attr[i++];
72 unsigned value = attr[i++];
73
74 switch (key) {
75 case KMS_WIDTH:
76 width = value;
77 break;
78 case KMS_HEIGHT:
79 height = value;
80 break;
81 case KMS_BO_TYPE:
82 type = value;
83 break;
84 default:
85 return EINVAL;
86 }
87 }
88
89 if (width == 0 || height == 0)
90 return -EINVAL;
91
92 return kms->bo_create(kms, width, height, type, attr, out);
93}
94
95int kms_bo_get_prop(struct kms_bo *bo, unsigned key, unsigned *out)
96{
97 switch (key) {
98 case KMS_PITCH:
99 *out = bo->pitch;
100 break;
101 case KMS_HANDLE:
102 *out = bo->handle;
103 break;
104 default:
105 return -EINVAL;
106 }
107
108 return 0;
109}
110
111int kms_bo_map(struct kms_bo *bo, void **out)
112{
113 return bo->kms->bo_map(bo, out);
114}
115
116int kms_bo_unmap(struct kms_bo *bo)
117{
118 return bo->kms->bo_unmap(bo);
119}
120
121int kms_bo_destroy(struct kms_bo *bo)
122{
123 return bo->kms->bo_destroy(bo);
124}
diff --git a/libkms/internal.h b/libkms/internal.h
new file mode 100644
index 00000000..f1a2b1cf
--- /dev/null
+++ b/libkms/internal.h
@@ -0,0 +1,67 @@
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#ifndef INTERNAL_H_
30#define INTERNAL_H_
31
32#include "libkms.h"
33
34struct kms_driver
35{
36 int (*get_prop)(struct kms_driver *kms, const unsigned key,
37 unsigned *out);
38 int (*destroy)(struct kms_driver *kms);
39
40 int (*bo_create)(struct kms_driver *kms,
41 unsigned width,
42 unsigned height,
43 enum kms_bo_type type,
44 const unsigned *attr,
45 struct kms_bo **out);
46 int (*bo_get_prop)(struct kms_bo *bo, const unsigned key,
47 unsigned *out);
48 int (*bo_map)(struct kms_bo *bo, void **out);
49 int (*bo_unmap)(struct kms_bo *bo);
50 int (*bo_destroy)(struct kms_bo *bo);
51
52 int fd;
53};
54
55struct kms_bo
56{
57 struct kms_driver *kms;
58 void *ptr;
59 size_t size;
60 size_t offset;
61 size_t pitch;
62 unsigned handle;
63};
64
65int vmwgfx_create(int fd, struct kms_driver **out);
66
67#endif
diff --git a/libkms/libkms.h b/libkms/libkms.h
new file mode 100644
index 00000000..9cc8ae21
--- /dev/null
+++ b/libkms/libkms.h
@@ -0,0 +1,69 @@
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#ifndef _LIBKMS_H_
30#define _LIBKMS_H_
31
32struct kms_driver;
33struct kms_bo;
34
35enum kms_attrib
36{
37 KMS_TERMINATE_PROP_LIST,
38 KMS_BO_TYPE,
39 KMS_WIDTH,
40 KMS_HEIGHT,
41 KMS_PITCH,
42 KMS_HANDLE,
43 KMS_MAX_SCANOUT_WIDTH,
44 KMS_MAX_SCANOUT_HEIGHT,
45 KMS_MIN_SCANOUT_WIDTH,
46 KMS_MIN_SCANOUT_HEIGHT,
47 KMS_MAX_CURSOR_WIDTH,
48 KMS_MAX_CURSOR_HEIGHT,
49 KMS_MIN_CURSOR_WIDTH,
50 KMS_MIN_CURSOR_HEIGHT,
51};
52
53enum kms_bo_type
54{
55 KMS_BO_TYPE_SCANOUT = (1 << 0),
56 KMS_BO_TYPE_CURSOR = (1 << 1),
57};
58
59int kms_create(int fd, struct kms_driver **out);
60int kms_get_prop(struct kms_driver *kms, unsigned key, unsigned *out);
61int kms_destroy(struct kms_driver *kms);
62
63int kms_bo_create(struct kms_driver *kms, const unsigned *attr, struct kms_bo **out);
64int kms_bo_get_prop(struct kms_bo *bo, unsigned key, unsigned *out);
65int kms_bo_map(struct kms_bo *bo, void **out);
66int kms_bo_unmap(struct kms_bo *bo);
67int kms_bo_destroy(struct kms_bo *bo);
68
69#endif
diff --git a/libkms/libkms.pc.in b/libkms/libkms.pc.in
new file mode 100644
index 00000000..b3cbbf33
--- /dev/null
+++ b/libkms/libkms.pc.in
@@ -0,0 +1,10 @@
1prefix=@prefix@
2exec_prefix=@exec_prefix@
3libdir=@libdir@
4includedir=@includedir@
5
6Name: libkms
7Description: Library that abstract aways the different mm interface for kernel drivers
8Version: 1.0
9Libs: -L${libdir} -lkms
10Cflags: -I${includedir}/libkms
diff --git a/libkms/vmwgfx.c b/libkms/vmwgfx.c
new file mode 100644
index 00000000..5030b7e3
--- /dev/null
+++ b/libkms/vmwgfx.c
@@ -0,0 +1,226 @@
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 <stdlib.h>
34#include <string.h>
35#include "internal.h"
36
37#include <sys/mman.h>
38#include "xf86drm.h"
39#include "vmwgfx_drm.h"
40
41struct vmwgfx_bo
42{
43 struct kms_bo base;
44 uint64_t map_handle;
45 unsigned map_count;
46};
47
48static int
49vmwgfx_get_prop(struct kms_driver *kms, unsigned key, unsigned *out)
50{
51 switch (key) {
52 case KMS_MAX_SCANOUT_WIDTH:
53 *out = 2048;
54 break;
55 case KMS_MAX_SCANOUT_HEIGHT:
56 *out = 2048;
57 break;
58 case KMS_MIN_SCANOUT_WIDTH:
59 *out = 1;
60 break;
61 case KMS_MIN_SCANOUT_HEIGHT:
62 *out = 1;
63 break;
64 case KMS_MAX_CURSOR_WIDTH:
65 *out = 64;
66 break;
67 case KMS_MAX_CURSOR_HEIGHT:
68 *out = 64;
69 break;
70 case KMS_MIN_CURSOR_WIDTH:
71 *out = 64;
72 break;
73 case KMS_MIN_CURSOR_HEIGHT:
74 *out = 64;
75 break;
76 default:
77 return -EINVAL;
78 }
79 return 0;
80}
81
82static int
83vmwgfx_destroy(struct kms_driver *kms)
84{
85 free(kms);
86 return 0;
87}
88
89static int
90vmwgfx_bo_create(struct kms_driver *kms,
91 const unsigned width, const unsigned height,
92 const enum kms_bo_type type, const unsigned *attr,
93 struct kms_bo **out)
94{
95 struct vmwgfx_bo *bo;
96 int i, ret;
97
98 for (i = 0; attr[i]; i += 2) {
99 switch (attr[i]) {
100 case KMS_WIDTH:
101 case KMS_HEIGHT:
102 case KMS_BO_TYPE:
103 break;
104 default:
105 return EINVAL;
106 }
107 }
108
109 bo = calloc(1, sizeof(*bo));
110 if (!bo)
111 return -EINVAL;
112
113 {
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;
117
118 memset(&arg, 0, sizeof(arg));
119 req->size = width * height * 4;
120 bo->base.size = req->size;
121 bo->base.pitch = width * 4;
122 bo->base.kms = kms;
123
124 do {
125 ret = drmCommandWriteRead(bo->base.kms->fd,
126 DRM_VMW_ALLOC_DMABUF,
127 &arg, sizeof(arg));
128 } while (ret == -ERESTART);
129
130 if (ret)
131 goto err_free;
132
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;
137 }
138
139 *out = &bo->base;
140
141 return 0;
142
143err_free:
144 free(bo);
145 return ret;
146}
147
148static int
149vmwgfx_bo_get_prop(struct kms_bo *bo, unsigned key, unsigned *out)
150{
151 switch (key) {
152 default:
153 return -EINVAL;
154 }
155}
156
157static int
158vmwgfx_bo_map(struct kms_bo *_bo, void **out)
159{
160 struct vmwgfx_bo *bo = (struct vmwgfx_bo *)_bo;
161 void *map;
162
163 if (!bo->map_count) {
164 map = mmap(NULL, bo->base.size, PROT_READ | PROT_WRITE,
165 MAP_SHARED, bo->base.kms->fd, bo->map_handle);
166
167 if (!map)
168 return -ENOMEM;
169
170 bo->base.ptr = map;
171 }
172
173 bo->map_count++;
174 *out = bo->base.ptr;
175
176 return 0;
177}
178
179static int
180vmwgfx_bo_unmap(struct kms_bo *_bo)
181{
182 struct vmwgfx_bo *bo = (struct vmwgfx_bo *)_bo;
183 bo->map_count--;
184 return 0;
185}
186
187static int
188vmwgfx_bo_destroy(struct kms_bo *_bo)
189{
190 struct vmwgfx_bo *bo = (struct vmwgfx_bo *)_bo;
191 struct drm_vmw_unref_dmabuf_arg arg;
192
193 if (bo->map_count) {
194 munmap(bo->base.ptr, bo->base.size);
195 bo->base.ptr = NULL;
196 }
197
198 memset(&arg, 0, sizeof(arg));
199 arg.handle = bo->base.handle;
200 drmCommandWrite(bo->base.kms->fd, DRM_VMW_UNREF_DMABUF, &arg, sizeof(arg));
201
202 free(bo);
203 return 0;
204}
205
206int
207vmwgfx_create(int fd, struct kms_driver **out)
208{
209 struct kms_driver *kms;
210
211 kms = calloc(1, sizeof(*kms));
212 if (!kms)
213 return -ENOMEM;
214
215 kms->fd = fd;
216
217 kms->bo_create = vmwgfx_bo_create;
218 kms->bo_map = vmwgfx_bo_map;
219 kms->bo_unmap = vmwgfx_bo_unmap;
220 kms->bo_get_prop = vmwgfx_bo_get_prop;
221 kms->bo_destroy = vmwgfx_bo_destroy;
222 kms->get_prop = vmwgfx_get_prop;
223 kms->destroy = vmwgfx_destroy;
224 *out = kms;
225 return 0;
226}
diff --git a/libkms/vmwgfx_drm.h b/libkms/vmwgfx_drm.h
new file mode 100644
index 00000000..597ab3c9
--- /dev/null
+++ b/libkms/vmwgfx_drm.h
@@ -0,0 +1,441 @@
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#ifndef _VMWGFX_DRM_H_
29#define _VMWGFX_DRM_H_
30
31#define DRM_VMW_MAX_SURFACE_FACES 6
32#define DRM_VMW_MAX_MIP_LEVELS 24
33
34#define DRM_VMW_EXT_NAME_LEN 128
35
36#define DRM_VMW_GET_PARAM 1
37#define DRM_VMW_EXTENSION 2
38#define DRM_VMW_CREATE_CONTEXT 3
39#define DRM_VMW_UNREF_CONTEXT 4
40#define DRM_VMW_CREATE_SURFACE 5
41#define DRM_VMW_UNREF_SURFACE 6
42#define DRM_VMW_REF_SURFACE 7
43#define DRM_VMW_EXECBUF 8
44#define DRM_VMW_ALLOC_DMABUF 9
45#define DRM_VMW_UNREF_DMABUF 10
46#define DRM_VMW_FIFO_DEBUG 11
47#define DRM_VMW_FENCE_WAIT 12
48
49/*************************************************************************/
50/**
51 * DRM_VMW_GET_PARAM - get device information.
52 *
53 * Currently we support only one parameter:
54 *
55 * DRM_VMW_PARAM_FIFO_OFFSET:
56 * Offset to use to map the first page of the FIFO read-only.
57 * The fifo is mapped using the mmap() system call on the drm device.
58 */
59
60#define DRM_VMW_PARAM_FIFO_OFFSET 0
61
62/**
63 * struct drm_vmw_getparam_arg
64 *
65 * @value: Returned value. //Out
66 * @param: Parameter to query. //In.
67 *
68 * Argument to the DRM_VMW_GET_PARAM Ioctl.
69 */
70
71struct drm_vmw_getparam_arg {
72 uint64_t value;
73 uint32_t param;
74 uint32_t pad64;
75};
76
77/*************************************************************************/
78/**
79 * DRM_VMW_EXTENSION - Query device extensions.
80 */
81
82/**
83 * struct drm_vmw_extension_rep
84 *
85 * @exists: The queried extension exists.
86 * @driver_ioctl_offset: Ioctl number of the first ioctl in the extension.
87 * @driver_sarea_offset: Offset to any space in the DRI SAREA
88 * used by the extension.
89 * @major: Major version number of the extension.
90 * @minor: Minor version number of the extension.
91 * @pl: Patch level version number of the extension.
92 *
93 * Output argument to the DRM_VMW_EXTENSION Ioctl.
94 */
95
96struct drm_vmw_extension_rep {
97 int32_t exists;
98 uint32_t driver_ioctl_offset;
99 uint32_t driver_sarea_offset;
100 uint32_t major;
101 uint32_t minor;
102 uint32_t pl;
103 uint32_t pad64;
104};
105
106/**
107 * union drm_vmw_extension_arg
108 *
109 * @extension - Ascii name of the extension to be queried. //In
110 * @rep - Reply as defined above. //Out
111 *
112 * Argument to the DRM_VMW_EXTENSION Ioctl.
113 */
114
115union drm_vmw_extension_arg {
116 char extension[DRM_VMW_EXT_NAME_LEN];
117 struct drm_vmw_extension_rep rep;
118};
119
120/*************************************************************************/
121/**
122 * DRM_VMW_CREATE_CONTEXT - Create a host context.
123 *
124 * Allocates a device unique context id, and queues a create context command
125 * for the host. Does not wait for host completion.
126 */
127
128/**
129 * struct drm_vmw_context_arg
130 *
131 * @cid: Device unique context ID.
132 *
133 * Output argument to the DRM_VMW_CREATE_CONTEXT Ioctl.
134 * Input argument to the DRM_VMW_UNREF_CONTEXT Ioctl.
135 */
136
137struct drm_vmw_context_arg {
138 int32_t cid;
139 uint32_t pad64;
140};
141
142/*************************************************************************/
143/**
144 * DRM_VMW_UNREF_CONTEXT - Create a host context.
145 *
146 * Frees a global context id, and queues a destroy host command for the host.
147 * Does not wait for host completion. The context ID can be used directly
148 * in the command stream and shows up as the same context ID on the host.
149 */
150
151/*************************************************************************/
152/**
153 * DRM_VMW_CREATE_SURFACE - Create a host suface.
154 *
155 * Allocates a device unique surface id, and queues a create surface command
156 * for the host. Does not wait for host completion. The surface ID can be
157 * used directly in the command stream and shows up as the same surface
158 * ID on the host.
159 */
160
161/**
162 * struct drm_wmv_surface_create_req
163 *
164 * @flags: Surface flags as understood by the host.
165 * @format: Surface format as understood by the host.
166 * @mip_levels: Number of mip levels for each face.
167 * An unused face should have 0 encoded.
168 * @size_addr: Address of a user-space array of sruct drm_vmw_size
169 * cast to an uint64_t for 32-64 bit compatibility.
170 * The size of the array should equal the total number of mipmap levels.
171 * @shareable: Boolean whether other clients (as identified by file descriptors)
172 * may reference this surface.
173 *
174 * Input data to the DRM_VMW_CREATE_SURFACE Ioctl.
175 * Output data from the DRM_VMW_REF_SURFACE Ioctl.
176 */
177
178struct drm_vmw_surface_create_req {
179 uint32_t flags;
180 uint32_t format;
181 uint32_t mip_levels[DRM_VMW_MAX_SURFACE_FACES];
182 uint64_t size_addr;
183 int32_t shareable;
184 uint32_t pad64;
185};
186
187/**
188 * struct drm_wmv_surface_arg
189 *
190 * @sid: Surface id of created surface or surface to destroy or reference.
191 *
192 * Output data from the DRM_VMW_CREATE_SURFACE Ioctl.
193 * Input argument to the DRM_VMW_UNREF_SURFACE Ioctl.
194 * Input argument to the DRM_VMW_REF_SURFACE Ioctl.
195 */
196
197struct drm_vmw_surface_arg {
198 int32_t sid;
199 uint32_t pad64;
200};
201
202/**
203 * struct drm_vmw_size ioctl.
204 *
205 * @width - mip level width
206 * @height - mip level height
207 * @depth - mip level depth
208 *
209 * Description of a mip level.
210 * Input data to the DRM_WMW_CREATE_SURFACE Ioctl.
211 */
212
213struct drm_vmw_size {
214 uint32_t width;
215 uint32_t height;
216 uint32_t depth;
217 uint32_t pad64;
218};
219
220/**
221 * union drm_vmw_surface_create_arg
222 *
223 * @rep: Output data as described above.
224 * @req: Input data as described above.
225 *
226 * Argument to the DRM_VMW_CREATE_SURFACE Ioctl.
227 */
228
229union drm_vmw_surface_create_arg {
230 struct drm_vmw_surface_arg rep;
231 struct drm_vmw_surface_create_req req;
232};
233
234/*************************************************************************/
235/**
236 * DRM_VMW_REF_SURFACE - Reference a host surface.
237 *
238 * Puts a reference on a host surface with a give sid, as previously
239 * returned by the DRM_VMW_CREATE_SURFACE ioctl.
240 * A reference will make sure the surface isn't destroyed while we hold
241 * it and will allow the calling client to use the surface ID in the command
242 * stream.
243 *
244 * On successful return, the Ioctl returns the surface information given
245 * in the DRM_VMW_CREATE_SURFACE ioctl.
246 */
247
248/**
249 * union drm_vmw_surface_reference_arg
250 *
251 * @rep: Output data as described above.
252 * @req: Input data as described above.
253 *
254 * Argument to the DRM_VMW_REF_SURFACE Ioctl.
255 */
256
257union drm_vmw_surface_reference_arg {
258 struct drm_vmw_surface_create_req rep;
259 struct drm_vmw_surface_arg req;
260};
261
262/*************************************************************************/
263/**
264 * DRM_VMW_UNREF_SURFACE - Unreference a host surface.
265 *
266 * Clear a reference previously put on a host surface.
267 * When all references are gone, including the one implicitly placed
268 * on creation,
269 * a destroy surface command will be queued for the host.
270 * Does not wait for completion.
271 */
272
273/*************************************************************************/
274/**
275 * DRM_VMW_EXECBUF
276 *
277 * Submit a command buffer for execution on the host, and return a
278 * fence sequence that when signaled, indicates that the command buffer has
279 * executed.
280 */
281
282/**
283 * struct drm_vmw_execbuf_arg
284 *
285 * @commands: User-space address of a command buffer cast to an uint64_t.
286 * @command-size: Size in bytes of the command buffer.
287 * @fence_rep: User-space address of a struct drm_vmw_fence_rep cast to an
288 * uint64_t.
289 *
290 * Argument to the DRM_VMW_EXECBUF Ioctl.
291 */
292
293struct drm_vmw_execbuf_arg {
294 uint64_t commands;
295 uint32_t command_size;
296 uint32_t pad64;
297 uint64_t fence_rep;
298};
299
300/**
301 * struct drm_vmw_fence_rep
302 *
303 * @fence_seq: Fence sequence associated with a command submission.
304 * @error: This member should've been set to -EFAULT on submission.
305 * The following actions should be take on completion:
306 * error == -EFAULT: Fence communication failed. The host is synchronized.
307 * Use the last fence id read from the FIFO fence register.
308 * error != 0 && error != -EFAULT:
309 * Fence submission failed. The host is synchronized. Use the fence_seq member.
310 * error == 0: All is OK, The host may not be synchronized.
311 * Use the fence_seq member.
312 *
313 * Input / Output data to the DRM_VMW_EXECBUF Ioctl.
314 */
315
316struct drm_vmw_fence_rep {
317 uint64_t fence_seq;
318 int32_t error;
319 uint32_t pad64;
320};
321
322/*************************************************************************/
323/**
324 * DRM_VMW_ALLOC_DMABUF
325 *
326 * Allocate a DMA buffer that is visible also to the host.
327 * NOTE: The buffer is
328 * identified by a handle and an offset, which are private to the guest, but
329 * useable in the command stream. The guest kernel may translate these
330 * and patch up the command stream accordingly. In the future, the offset may
331 * be zero at all times, or it may disappear from the interface before it is
332 * fixed.
333 *
334 * The DMA buffer may stay user-space mapped in the guest at all times,
335 * and is thus suitable for sub-allocation.
336 *
337 * DMA buffers are mapped using the mmap() syscall on the drm device.
338 */
339
340/**
341 * struct drm_vmw_alloc_dmabuf_req
342 *
343 * @size: Required minimum size of the buffer.
344 *
345 * Input data to the DRM_VMW_ALLOC_DMABUF Ioctl.
346 */
347
348struct drm_vmw_alloc_dmabuf_req {
349 uint32_t size;
350 uint32_t pad64;
351};
352
353/**
354 * struct drm_vmw_dmabuf_rep
355 *
356 * @map_handle: Offset to use in the mmap() call used to map the buffer.
357 * @handle: Handle unique to this buffer. Used for unreferencing.
358 * @cur_gmr_id: GMR id to use in the command stream when this buffer is
359 * referenced. See not above.
360 * @cur_gmr_offset: Offset to use in the command stream when this buffer is
361 * referenced. See note above.
362 *
363 * Output data from the DRM_VMW_ALLOC_DMABUF Ioctl.
364 */
365
366struct drm_vmw_dmabuf_rep {
367 uint64_t map_handle;
368 uint32_t handle;
369 uint32_t cur_gmr_id;
370 uint32_t cur_gmr_offset;
371 uint32_t pad64;
372};
373
374/**
375 * union drm_vmw_dmabuf_arg
376 *
377 * @req: Input data as described above.
378 * @rep: Output data as described above.
379 *
380 * Argument to the DRM_VMW_ALLOC_DMABUF Ioctl.
381 */
382
383union drm_vmw_alloc_dmabuf_arg {
384 struct drm_vmw_alloc_dmabuf_req req;
385 struct drm_vmw_dmabuf_rep rep;
386};
387
388/*************************************************************************/
389/**
390 * DRM_VMW_UNREF_DMABUF - Free a DMA buffer.
391 *
392 */
393
394/**
395 * struct drm_vmw_unref_dmabuf_arg
396 *
397 * @handle: Handle indicating what buffer to free. Obtained from the
398 * DRM_VMW_ALLOC_DMABUF Ioctl.
399 *
400 * Argument to the DRM_VMW_UNREF_DMABUF Ioctl.
401 */
402
403struct drm_vmw_unref_dmabuf_arg {
404 uint32_t handle;
405 uint32_t pad64;
406};
407
408/*************************************************************************/
409/**
410 * DRM_VMW_FIFO_DEBUG - Get last FIFO submission.
411 *
412 * This IOCTL copies the last FIFO submission directly out of the FIFO buffer.
413 */
414
415/**
416 * struct drm_vmw_fifo_debug_arg
417 *
418 * @debug_buffer: User space address of a debug_buffer cast to an uint64_t //In
419 * @debug_buffer_size: Size in bytes of debug buffer //In
420 * @used_size: Number of bytes copied to the buffer // Out
421 * @did_not_fit: Boolean indicating that the fifo contents did not fit. //Out
422 *
423 * Argument to the DRM_VMW_FIFO_DEBUG Ioctl.
424 */
425
426struct drm_vmw_fifo_debug_arg {
427 uint64_t debug_buffer;
428 uint32_t debug_buffer_size;
429 uint32_t used_size;
430 int32_t did_not_fit;
431 uint32_t pad64;
432};
433
434struct drm_vmw_fence_wait_arg {
435 uint64_t sequence;
436 uint64_t kernel_cookie;
437 int32_t cookie_valid;
438 int32_t pad64;
439};
440
441#endif