aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTony Zlatinski2012-08-17 22:59:22 -0500
committerHemant Hariyani2014-10-14 11:45:46 -0500
commite0bf30f34202152fbe7447f262b815f7e24f1a50 (patch)
tree748cb6b08e6fec33a8c39cec7beffd91c5100411
parent3cb5405084111193cedb8796d259b56560b088f0 (diff)
downloadlibdrm-e0bf30f34202152fbe7447f262b815f7e24f1a50.tar.gz
libdrm-e0bf30f34202152fbe7447f262b815f7e24f1a50.tar.xz
libdrm-e0bf30f34202152fbe7447f262b815f7e24f1a50.zip
DRM-KMS: Android support of libdrm
-rw-r--r--Android.mk98
-rw-r--r--config.h163
-rw-r--r--libkms/dumb.c3
-rw-r--r--libkms/intel.c2
-rw-r--r--libkms/internal.h2
-rw-r--r--libkms/linux.c4
-rw-r--r--libkms/nouveau.c2
-rw-r--r--libkms/omap.c215
-rw-r--r--libkms/radeon.c2
-rw-r--r--libkms/vmwgfx.c2
-rw-r--r--omap/omap_drm.c3
-rw-r--r--tests/modetest/modetest.c10
12 files changed, 505 insertions, 1 deletions
diff --git a/Android.mk b/Android.mk
new file mode 100644
index 00000000..e043dbf8
--- /dev/null
+++ b/Android.mk
@@ -0,0 +1,98 @@
1# Copyright 2010-2012, The Android-x86 Open Source Project
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8
9ifneq ($(strip $(BOARD_GPU_DRIVERS)),)
10
11LOCAL_PATH := $(call my-dir)
12
13################ DRM Lib #######################
14
15include $(CLEAR_VARS)
16
17LOCAL_SRC_FILES := \
18 xf86drm.c \
19 xf86drmHash.c \
20 xf86drmMode.c \
21 xf86drmRandom.c \
22 xf86drmSL.c
23
24LOCAL_C_INCLUDES += \
25 $(LOCAL_PATH)/include/drm
26
27LOCAL_MODULE := libdrm
28LOCAL_MODULE_TAGS := optional
29
30include $(BUILD_SHARED_LIBRARY)
31
32################ OMAP DRM Lib #######################
33
34include $(CLEAR_VARS)
35
36LOCAL_SRC_FILES := \
37 omap/omap_drm.c \
38
39LOCAL_C_INCLUDES += \
40 $(LOCAL_PATH)/include/drm \
41 $(LOCAL_PATH)/omap
42
43LOCAL_CFLAGS += -DHAVE_LIBDRM_ATOMIC_PRIMITIVES=1
44
45LOCAL_MODULE := libdrm_omap
46LOCAL_MODULE_TAGS := optional
47
48LOCAL_SHARED_LIBRARIES := libdrm
49
50include $(BUILD_SHARED_LIBRARY)
51
52################ KMS Lib #######################
53
54include $(CLEAR_VARS)
55
56LOCAL_SRC_FILES := \
57 libkms/api.c \
58 libkms/dumb.c \
59 libkms/omap.c \
60 libkms/intel.c \
61 libkms/linux.c
62
63LOCAL_C_INCLUDES += \
64 $(LOCAL_PATH)/include/drm \
65 $(LOCAL_PATH)/omap \
66
67LOCAL_MODULE := libkms
68LOCAL_MODULE_TAGS := optional
69
70LOCAL_SHARED_LIBRARIES := libdrm
71
72include $(BUILD_SHARED_LIBRARY)
73
74################ Test Apps #######################
75
76include $(CLEAR_VARS)
77
78LOCAL_SRC_FILES := \
79 tests/modetest/modetest.c \
80 tests/modetest/buffers.c
81
82LOCAL_C_INCLUDES += \
83 $(LOCAL_PATH)/include/drm \
84 $(LOCAL_PATH)/libkms \
85 $(LOCAL_PATH)/omap \
86 $(LOCAL_PATH)/tests/modetest
87
88LOCAL_MODULE := modetest
89LOCAL_MODULE_TAGS := debug
90
91LOCAL_SHARED_LIBRARIES := \
92 libdrm \
93 libkms \
94 libdrm_omap
95
96include $(BUILD_EXECUTABLE)
97
98endif
diff --git a/config.h b/config.h
new file mode 100644
index 00000000..1d89f791
--- /dev/null
+++ b/config.h
@@ -0,0 +1,163 @@
1/* config.h. Generated from config.h.in by configure. */
2/* config.h.in. Generated from configure.ac by autoheader. */
3
4/* Define to one of `_getb67', `GETB67', `getb67' for Cray-2 and Cray-YMP
5 systems. This function is required for `alloca.c' support on those systems.
6 */
7/* #undef CRAY_STACKSEG_END */
8
9/* Define to 1 if using `alloca.c'. */
10/* #undef C_ALLOCA */
11
12/* Define to 1 if you have `alloca', as a function or macro. */
13#define HAVE_ALLOCA 1
14
15/* Define to 1 if you have <alloca.h> and it should be used (not on Ultrix).
16 */
17#define HAVE_ALLOCA_H 1
18
19/* Have cairo support */
20/* #undef HAVE_CAIRO */
21
22/* Define to 1 if you have the `clock_gettime' function. */
23/* #undef HAVE_CLOCK_GETTIME */
24
25/* Define to 1 if you have the <dlfcn.h> header file. */
26#define HAVE_DLFCN_H 1
27
28/* Define to 1 if you have the <inttypes.h> header file. */
29#define HAVE_INTTYPES_H 1
30
31/* Enable if your compiler supports the Intel __sync_* atomic primitives */
32#define HAVE_LIBDRM_ATOMIC_PRIMITIVES 1
33
34/* Have libudev support */
35/* #undef HAVE_LIBUDEV */
36
37/* Enable if you have libatomic-ops-dev installed */
38/* #undef HAVE_LIB_ATOMIC_OPS */
39
40/* Define to 1 if you have the <memory.h> header file. */
41#define HAVE_MEMORY_H 1
42
43/* Have nouveau (nvidia) support */
44/* #undef HAVE_NOUVEAU */
45
46/* Have OMAP support */
47#define HAVE_OMAP 1
48
49/* Define to 1 if you have the `open_memstream' function. */
50#define HAVE_OPEN_MEMSTREAM 1
51
52/* Have radeon support */
53/* #undef HAVE_RADEON */
54
55/* Define to 1 if you have the <stdint.h> header file. */
56#define HAVE_STDINT_H 1
57
58/* Define to 1 if you have the <stdlib.h> header file. */
59#define HAVE_STDLIB_H 1
60
61/* Define to 1 if you have the <strings.h> header file. */
62#define HAVE_STRINGS_H 1
63
64/* Define to 1 if you have the <string.h> header file. */
65#define HAVE_STRING_H 1
66
67/* Define to 1 if you have the <sys/stat.h> header file. */
68#define HAVE_SYS_STAT_H 1
69
70/* Define to 1 if you have the <sys/types.h> header file. */
71#define HAVE_SYS_TYPES_H 1
72
73/* Define to 1 if you have the <unistd.h> header file. */
74#define HAVE_UNISTD_H 1
75
76/* Use valgrind intrinsics to suppress false warnings */
77/* #undef HAVE_VALGRIND */
78
79/* Have vmwgfx kernel headers */
80/* #undef HAVE_VMWGFX */
81
82/* Define to the sub-directory in which libtool stores uninstalled libraries.
83 */
84#define LT_OBJDIR ".libs/"
85
86/* Name of package */
87#define PACKAGE "libdrm"
88
89/* Define to the address where bug reports for this package should be sent. */
90#define PACKAGE_BUGREPORT "https://bugs.freedesktop.org/enter_bug.cgi?product=DRI"
91
92/* Define to the full name of this package. */
93#define PACKAGE_NAME "libdrm"
94
95/* Define to the full name and version of this package. */
96#define PACKAGE_STRING "libdrm 2.4.33"
97
98/* Define to the one symbol short name of this package. */
99#define PACKAGE_TARNAME "libdrm"
100
101/* Define to the home page for this package. */
102#define PACKAGE_URL ""
103
104/* Define to the version of this package. */
105#define PACKAGE_VERSION "2.4.33"
106
107/* If using the C implementation of alloca, define if you know the
108 direction of stack growth for your system; otherwise it will be
109 automatically deduced at runtime.
110 STACK_DIRECTION > 0 => grows toward higher addresses
111 STACK_DIRECTION < 0 => grows toward lower addresses
112 STACK_DIRECTION = 0 => direction of growth unknown */
113/* #undef STACK_DIRECTION */
114
115/* Define to 1 if you have the ANSI C header files. */
116#define STDC_HEADERS 1
117
118/* Have UDEV support */
119/* #undef UDEV */
120
121/* Enable extensions on AIX 3, Interix. */
122#ifndef _ALL_SOURCE
123# define _ALL_SOURCE 1
124#endif
125/* Enable GNU extensions on systems that have them. */
126#ifndef _GNU_SOURCE
127# define _GNU_SOURCE 1
128#endif
129/* Enable threading extensions on Solaris. */
130#ifndef _POSIX_PTHREAD_SEMANTICS
131# define _POSIX_PTHREAD_SEMANTICS 1
132#endif
133/* Enable extensions on HP NonStop. */
134#ifndef _TANDEM_SOURCE
135# define _TANDEM_SOURCE 1
136#endif
137/* Enable general extensions on Solaris. */
138#ifndef __EXTENSIONS__
139# define __EXTENSIONS__ 1
140#endif
141
142
143/* Version number of package */
144#define VERSION "2.4.33"
145
146/* Number of bits in a file offset, on hosts where this is settable. */
147/* #undef _FILE_OFFSET_BITS */
148
149/* Define for large files, on AIX-style hosts. */
150/* #undef _LARGE_FILES */
151
152/* Define to 1 if on MINIX. */
153/* #undef _MINIX */
154
155/* Define to 2 if the system does not provide POSIX.1 features except with
156 this defined. */
157/* #undef _POSIX_1_SOURCE */
158
159/* Define to 1 if you need to in order for `stat' and other things to work. */
160/* #undef _POSIX_SOURCE */
161
162/* Define to `unsigned int' if <sys/types.h> does not define. */
163/* #undef size_t */
diff --git a/libkms/dumb.c b/libkms/dumb.c
index 440efb31..645a5b02 100644
--- a/libkms/dumb.c
+++ b/libkms/dumb.c
@@ -25,8 +25,9 @@
25 * 25 *
26 **************************************************************************/ 26 **************************************************************************/
27 27
28 28#ifndef HAVE_STDINT_H
29#define HAVE_STDINT_H 29#define HAVE_STDINT_H
30#endif
30#define _FILE_OFFSET_BITS 64 31#define _FILE_OFFSET_BITS 64
31 32
32#include <errno.h> 33#include <errno.h>
diff --git a/libkms/intel.c b/libkms/intel.c
index abae4525..7ee49fc8 100644
--- a/libkms/intel.c
+++ b/libkms/intel.c
@@ -26,7 +26,9 @@
26 **************************************************************************/ 26 **************************************************************************/
27 27
28 28
29#ifndef HAVE_STDINT_H
29#define HAVE_STDINT_H 30#define HAVE_STDINT_H
31#endif
30#define _FILE_OFFSET_BITS 64 32#define _FILE_OFFSET_BITS 64
31 33
32#include <errno.h> 34#include <errno.h>
diff --git a/libkms/internal.h b/libkms/internal.h
index 5e2501e4..3d867ea1 100644
--- a/libkms/internal.h
+++ b/libkms/internal.h
@@ -74,4 +74,6 @@ int nouveau_create(int fd, struct kms_driver **out);
74 74
75int radeon_create(int fd, struct kms_driver **out); 75int radeon_create(int fd, struct kms_driver **out);
76 76
77int omap_create(int fd, struct kms_driver **out);
78
77#endif 79#endif
diff --git a/libkms/linux.c b/libkms/linux.c
index eec01622..032d07b4 100644
--- a/libkms/linux.c
+++ b/libkms/linux.c
@@ -115,6 +115,10 @@ linux_from_sysfs(int fd, struct kms_driver **out)
115 else if (!strcmp(name, "radeon")) 115 else if (!strcmp(name, "radeon"))
116 ret = radeon_create(fd, out); 116 ret = radeon_create(fd, out);
117#endif 117#endif
118#ifdef HAVE_OMAP
119 else if (!strcmp(name, "omapdrm"))
120 ret = omap_create(fd, out);
121#endif
118 else 122 else
119 ret = -ENOSYS; 123 ret = -ENOSYS;
120 124
diff --git a/libkms/nouveau.c b/libkms/nouveau.c
index 608092f5..a9b90c7d 100644
--- a/libkms/nouveau.c
+++ b/libkms/nouveau.c
@@ -26,7 +26,9 @@
26 **************************************************************************/ 26 **************************************************************************/
27 27
28 28
29#ifndef HAVE_STDINT_H
29#define HAVE_STDINT_H 30#define HAVE_STDINT_H
31#endif
30#define _FILE_OFFSET_BITS 64 32#define _FILE_OFFSET_BITS 64
31 33
32#include <errno.h> 34#include <errno.h>
diff --git a/libkms/omap.c b/libkms/omap.c
new file mode 100644
index 00000000..0ac52671
--- /dev/null
+++ b/libkms/omap.c
@@ -0,0 +1,215 @@
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 HAVE_STDINT_H
30#define HAVE_STDINT_H
31#endif
32#define _FILE_OFFSET_BITS 64
33
34#include <errno.h>
35#include <stdio.h>
36#include <stdlib.h>
37#include <string.h>
38#include "internal.h"
39
40#include <sys/mman.h>
41#include <sys/ioctl.h>
42#include "xf86drm.h"
43
44#include "omap_drm.h"
45
46struct omap_kms_bo
47{
48 struct kms_bo base;
49 unsigned map_count;
50};
51
52static int
53omap_get_prop(struct kms_driver *kms, unsigned key, unsigned *out)
54{
55 switch (key) {
56 case KMS_BO_TYPE:
57 *out = KMS_BO_TYPE_SCANOUT_X8R8G8B8 | KMS_BO_TYPE_CURSOR_64X64_A8R8G8B8;
58 break;
59 default:
60 return -EINVAL;
61 }
62 return 0;
63}
64
65static int
66omap_bo_create(struct kms_driver *kms,
67 const unsigned width, const unsigned height,
68 const enum kms_bo_type type, const unsigned *attr,
69 struct kms_bo **out)
70{
71 unsigned size = 0, pitch = 0;
72 struct omap_kms_bo *bo = NULL;
73 struct drm_omap_gem_new arg;
74 int i, ret;
75
76 for (i = 0; attr[i]; i += 2) {
77 switch (attr[i]) {
78 case KMS_BO_TYPE:
79 case KMS_WIDTH:
80 case KMS_HEIGHT:
81 case KMS_PITCH:
82 case KMS_HANDLE:
83 break;
84 default:
85 return -EINVAL;
86 }
87 }
88
89 bo = calloc(1, sizeof(*bo));
90 if (!bo)
91 return -ENOMEM;
92
93 memset(&arg, 0, sizeof(arg));
94 arg.size.bytes = size;
95
96 ret = drmCommandWriteRead(kms->fd, DRM_OMAP_GEM_NEW, &arg, sizeof(arg));
97 if (ret)
98 goto err_free;
99
100 bo->base.kms = kms;
101 bo->base.handle = arg.handle;
102 bo->base.size = size;
103 bo->base.pitch = pitch;
104
105 *out = &bo->base;
106
107 return 0;
108
109err_free:
110 free(bo);
111 return ret;
112}
113
114static int
115omap_bo_get_prop(struct kms_bo *bo, unsigned key, unsigned *out)
116{
117 switch (key) {
118 default:
119 return -EINVAL;
120 }
121}
122
123static int
124_omap_bo_map(struct kms_bo *_bo, void **out)
125{
126 struct omap_kms_bo *bo = (struct omap_kms_bo *)_bo;
127 void *map = NULL;
128 int ret;
129
130 if (bo->base.ptr) {
131 bo->map_count++;
132 *out = bo->base.ptr;
133 return 0;
134 }
135
136 /* TODO: Map buffer */
137
138 bo->base.ptr = NULL;
139 bo->map_count++;
140 *out = bo->base.ptr;
141
142 return 0;
143}
144
145static int
146omap_bo_unmap(struct kms_bo *_bo)
147{
148 struct omap_kms_bo *bo = (struct omap_kms_bo *)_bo;
149
150 if(bo->map_count <= 0)
151 return -1;
152
153 bo->map_count--;
154
155 if(bo->map_count == 0)
156 {
157 /* TODO: UnMap buffer */
158 }
159
160 return 0;
161}
162
163static int
164omap_bo_destroy(struct kms_bo *_bo)
165{
166 struct omap_kms_bo *bo = (struct omap_kms_bo *)_bo;
167 struct drm_gem_close arg;
168 int ret;
169
170 if (bo->base.ptr) {
171 /* XXX Sanity check map_count */
172 munmap(bo->base.ptr, bo->base.size);
173 bo->base.ptr = NULL;
174 }
175
176 memset(&arg, 0, sizeof(arg));
177 arg.handle = bo->base.handle;
178
179 ret = drmIoctl(bo->base.kms->fd, DRM_IOCTL_GEM_CLOSE, &arg);
180 if (ret)
181 return -errno;
182
183 free(bo);
184 return 0;
185}
186
187static int
188omap_destroy(struct kms_driver *kms)
189{
190 free(kms);
191 return 0;
192}
193
194int
195omap_create(int fd, struct kms_driver **out)
196{
197 struct kms_driver *kms;
198
199 kms = calloc(1, sizeof(*kms));
200 if (!kms)
201 return -ENOMEM;
202
203 kms->fd = fd;
204
205 kms->bo_create = omap_bo_create;
206 kms->bo_map = _omap_bo_map;
207 kms->bo_unmap = omap_bo_unmap;
208 kms->bo_get_prop = omap_bo_get_prop;
209 kms->bo_destroy = omap_bo_destroy;
210 kms->get_prop = omap_get_prop;
211 kms->destroy = omap_destroy;
212 *out = kms;
213
214 return 0;
215}
diff --git a/libkms/radeon.c b/libkms/radeon.c
index f5e382ae..835bcd3d 100644
--- a/libkms/radeon.c
+++ b/libkms/radeon.c
@@ -26,7 +26,9 @@
26 **************************************************************************/ 26 **************************************************************************/
27 27
28 28
29#ifndef HAVE_STDINT_H
29#define HAVE_STDINT_H 30#define HAVE_STDINT_H
31#endif
30#define _FILE_OFFSET_BITS 64 32#define _FILE_OFFSET_BITS 64
31 33
32#include <errno.h> 34#include <errno.h>
diff --git a/libkms/vmwgfx.c b/libkms/vmwgfx.c
index d594b3bd..978db981 100644
--- a/libkms/vmwgfx.c
+++ b/libkms/vmwgfx.c
@@ -26,7 +26,9 @@
26 **************************************************************************/ 26 **************************************************************************/
27 27
28 28
29#ifndef HAVE_STDINT_H
29#define HAVE_STDINT_H 30#define HAVE_STDINT_H
31#endif
30#define _FILE_OFFSET_BITS 64 32#define _FILE_OFFSET_BITS 64
31 33
32#include <errno.h> 34#include <errno.h>
diff --git a/omap/omap_drm.c b/omap/omap_drm.c
index 16255f84..83c365a1 100644
--- a/omap/omap_drm.c
+++ b/omap/omap_drm.c
@@ -47,7 +47,10 @@
47 47
48#define __round_mask(x, y) ((__typeof__(x))((y)-1)) 48#define __round_mask(x, y) ((__typeof__(x))((y)-1))
49#define round_up(x, y) ((((x)-1) | __round_mask(x, y))+1) 49#define round_up(x, y) ((((x)-1) | __round_mask(x, y))+1)
50
51#ifndef PAGE_SIZE
50#define PAGE_SIZE 4096 52#define PAGE_SIZE 4096
53#endif
51 54
52static pthread_mutex_t table_lock = PTHREAD_MUTEX_INITIALIZER; 55static pthread_mutex_t table_lock = PTHREAD_MUTEX_INITIALIZER;
53static void * dev_table; 56static void * dev_table;
diff --git a/tests/modetest/modetest.c b/tests/modetest/modetest.c
index c91bb9d1..ce62163d 100644
--- a/tests/modetest/modetest.c
+++ b/tests/modetest/modetest.c
@@ -841,6 +841,16 @@ static char optstr[] = "ecpmfs:P:v";
841 841
842#define min(a, b) ((a) < (b) ? (a) : (b)) 842#define min(a, b) ((a) < (b) ? (a) : (b))
843 843
844static char *
845strchrnul (const char *s, int c_in)
846{
847 char c = c_in;
848 while (*s && (*s != c))
849 s++;
850
851 return (char *) s;
852}
853
844static int parse_connector(struct connector *c, const char *arg) 854static int parse_connector(struct connector *c, const char *arg)
845{ 855{
846 unsigned int len; 856 unsigned int len;