aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTony Zlatinski2012-09-19 00:26:29 -0500
committerHemant Hariyani2014-10-14 11:45:54 -0500
commitb1da92efe6d989224c86b0e0e688a793059a54d7 (patch)
tree6377e43a10e31e56d3685581456b499deb1137e0
parent9061a8f14d6f63991a1ca11e845d13b60c780474 (diff)
downloadlibdrm-b1da92efe6d989224c86b0e0e688a793059a54d7.tar.gz
libdrm-b1da92efe6d989224c86b0e0e688a793059a54d7.tar.xz
libdrm-b1da92efe6d989224c86b0e0e688a793059a54d7.zip
OMAPKMSLIB: Fixed the KMS Lib alloc/free/map
-rw-r--r--Android.mk2
-rw-r--r--libkms/omap.c159
-rw-r--r--tests/modetest/modetest.c2
3 files changed, 112 insertions, 51 deletions
diff --git a/Android.mk b/Android.mk
index e0833941..b09e693e 100644
--- a/Android.mk
+++ b/Android.mk
@@ -70,7 +70,7 @@ LOCAL_C_INCLUDES += \
70LOCAL_MODULE := libkms 70LOCAL_MODULE := libkms
71LOCAL_MODULE_TAGS := optional 71LOCAL_MODULE_TAGS := optional
72 72
73LOCAL_SHARED_LIBRARIES := libdrm 73LOCAL_SHARED_LIBRARIES := libdrm libdrm_omap
74 74
75include $(BUILD_SHARED_LIBRARY) 75include $(BUILD_SHARED_LIBRARY)
76 76
diff --git a/libkms/omap.c b/libkms/omap.c
index 0ac52671..32d248c4 100644
--- a/libkms/omap.c
+++ b/libkms/omap.c
@@ -41,16 +41,45 @@
41#include <sys/ioctl.h> 41#include <sys/ioctl.h>
42#include "xf86drm.h" 42#include "xf86drm.h"
43 43
44#include <xf86drmMode.h>
45
44#include "omap_drm.h" 46#include "omap_drm.h"
47#include "omap_drmif.h"
48
49#ifndef PAGE_SHIFT
50# define PAGE_SHIFT 12
51#endif
52
53/* align x to next highest multiple of 2^n */
54#define ALIGN2(x,n) (((x) + ((1 << (n)) - 1)) & ~((1 << (n)) - 1))
55
56#ifndef container_of
57#define container_of(ptr, type, member) \
58 (type *)((char *)(ptr) - (char *) &((type *)0)->member)
59#endif
60
61#define MSG(fmt, ...) \
62 do { fprintf(stderr, fmt "\n", ##__VA_ARGS__); } while (0)
63#define ERROR(fmt, ...) \
64 do { fprintf(stderr, "ERROR:%s:%d: " fmt "\n", __func__, __LINE__, ##__VA_ARGS__); } while (0)
65
66#define to_display_kms(x) container_of(x, struct display_kms, kms)
67struct display_kms {
68 struct kms_driver kms;
69 struct omap_device *dev;
70 uint32_t width, height;
71 uint32_t bo_flags;
72};
45 73
46struct omap_kms_bo 74struct omap_kms_bo
47{ 75{
48 struct kms_bo base; 76 struct kms_bo base;
77 struct omap_bo * omap_bo;
49 unsigned map_count; 78 unsigned map_count;
50}; 79};
51 80
52static int 81static int
53omap_get_prop(struct kms_driver *kms, unsigned key, unsigned *out) 82omapkms_get_prop(struct kms_driver *kms, unsigned key, unsigned *out)
54{ 83{
55 switch (key) { 84 switch (key) {
56 case KMS_BO_TYPE: 85 case KMS_BO_TYPE:
@@ -63,7 +92,7 @@ omap_get_prop(struct kms_driver *kms, unsigned key, unsigned *out)
63} 92}
64 93
65static int 94static int
66omap_bo_create(struct kms_driver *kms, 95omapkms_bo_create(struct kms_driver *kms,
67 const unsigned width, const unsigned height, 96 const unsigned width, const unsigned height,
68 const enum kms_bo_type type, const unsigned *attr, 97 const enum kms_bo_type type, const unsigned *attr,
69 struct kms_bo **out) 98 struct kms_bo **out)
@@ -72,6 +101,9 @@ omap_bo_create(struct kms_driver *kms,
72 struct omap_kms_bo *bo = NULL; 101 struct omap_kms_bo *bo = NULL;
73 struct drm_omap_gem_new arg; 102 struct drm_omap_gem_new arg;
74 int i, ret; 103 int i, ret;
104 uint32_t bpp;
105 struct display_kms *disp = to_display_kms(kms);
106 uint32_t bo_flags = disp->bo_flags;
75 107
76 for (i = 0; attr[i]; i += 2) { 108 for (i = 0; attr[i]; i += 2) {
77 switch (attr[i]) { 109 switch (attr[i]) {
@@ -90,17 +122,36 @@ omap_bo_create(struct kms_driver *kms,
90 if (!bo) 122 if (!bo)
91 return -ENOMEM; 123 return -ENOMEM;
92 124
93 memset(&arg, 0, sizeof(arg)); 125 bpp = 32;
94 arg.size.bytes = size; 126
127 if ((bo_flags & OMAP_BO_TILED) == OMAP_BO_TILED) {
128 bo_flags &= ~OMAP_BO_TILED;
129 if (bpp == 8) {
130 bo_flags |= OMAP_BO_TILED_8;
131 } else if (bpp == 16) {
132 bo_flags |= OMAP_BO_TILED_16;
133 } else if (bpp == 32) {
134 bo_flags |= OMAP_BO_TILED_32;
135 }
136 }
95 137
96 ret = drmCommandWriteRead(kms->fd, DRM_OMAP_GEM_NEW, &arg, sizeof(arg)); 138 bo_flags |= OMAP_BO_WC;
97 if (ret) 139
98 goto err_free; 140 if (bo_flags & OMAP_BO_TILED) {
141 bo->omap_bo = omap_bo_new_tiled(disp->dev, width, height, bo_flags);
142 } else {
143 bo->omap_bo = omap_bo_new(disp->dev, width * height * bpp / 8, bo_flags);
144 }
145
146 if (bo->omap_bo) {
147 bo->base.handle = omap_bo_handle(bo->omap_bo);
148 bo->base.pitch = width * bpp / 8;
149 if (bo_flags & OMAP_BO_TILED)
150 bo->base.pitch = ALIGN2(bo->base.pitch, PAGE_SHIFT);
151 }
99 152
100 bo->base.kms = kms; 153 bo->base.kms = kms;
101 bo->base.handle = arg.handle; 154 bo->base.size = bo->base.pitch * height;
102 bo->base.size = size;
103 bo->base.pitch = pitch;
104 155
105 *out = &bo->base; 156 *out = &bo->base;
106 157
@@ -112,7 +163,7 @@ err_free:
112} 163}
113 164
114static int 165static int
115omap_bo_get_prop(struct kms_bo *bo, unsigned key, unsigned *out) 166omapkms_bo_get_prop(struct kms_bo *bo, unsigned key, unsigned *out)
116{ 167{
117 switch (key) { 168 switch (key) {
118 default: 169 default:
@@ -121,29 +172,26 @@ omap_bo_get_prop(struct kms_bo *bo, unsigned key, unsigned *out)
121} 172}
122 173
123static int 174static int
124_omap_bo_map(struct kms_bo *_bo, void **out) 175omapkms_bo_map(struct kms_bo *_bo, void **out)
125{ 176{
126 struct omap_kms_bo *bo = (struct omap_kms_bo *)_bo; 177 struct omap_kms_bo *bo = (struct omap_kms_bo *)_bo;
127 void *map = NULL; 178
128 int ret; 179 if(bo->base.ptr == NULL) {
180 omap_bo_cpu_prep(bo->omap_bo, OMAP_GEM_WRITE /* | OMAP_GEM_READ */);
181 bo->base.ptr = omap_bo_map(bo->omap_bo);
182 }
129 183
130 if (bo->base.ptr) { 184 if (bo->base.ptr) {
131 bo->map_count++; 185 bo->map_count++;
132 *out = bo->base.ptr;
133 return 0;
134 } 186 }
135 187
136 /* TODO: Map buffer */
137
138 bo->base.ptr = NULL;
139 bo->map_count++;
140 *out = bo->base.ptr; 188 *out = bo->base.ptr;
141 189
142 return 0; 190 return (bo->base.ptr) ? 0 : -1;
143} 191}
144 192
145static int 193static int
146omap_bo_unmap(struct kms_bo *_bo) 194omapkms_bo_unmap(struct kms_bo *_bo)
147{ 195{
148 struct omap_kms_bo *bo = (struct omap_kms_bo *)_bo; 196 struct omap_kms_bo *bo = (struct omap_kms_bo *)_bo;
149 197
@@ -154,62 +202,75 @@ omap_bo_unmap(struct kms_bo *_bo)
154 202
155 if(bo->map_count == 0) 203 if(bo->map_count == 0)
156 { 204 {
157 /* TODO: UnMap buffer */ 205 omap_bo_cpu_fini(bo->omap_bo, OMAP_GEM_WRITE /* | OMAP_GEM_READ */);
206 bo->base.ptr = NULL;
158 } 207 }
159 208
160 return 0; 209 return 0;
161} 210}
162 211
163static int 212static int
164omap_bo_destroy(struct kms_bo *_bo) 213omapkms_bo_destroy(struct kms_bo *_bo)
165{ 214{
166 struct omap_kms_bo *bo = (struct omap_kms_bo *)_bo; 215 struct omap_kms_bo *bo = (struct omap_kms_bo *)_bo;
167 struct drm_gem_close arg;
168 int ret;
169 216
170 if (bo->base.ptr) { 217 omap_bo_del(bo->omap_bo);
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 218
183 free(bo); 219 free(bo);
220
184 return 0; 221 return 0;
185} 222}
186 223
187static int 224static int
188omap_destroy(struct kms_driver *kms) 225omapkms_destroy(struct kms_driver *kms)
189{ 226{
190 free(kms); 227 struct display_kms *disp = to_display_kms(kms);
228
229 if(disp->dev)
230 {
231 omap_device_del(disp->dev);
232 disp->dev = NULL;
233 }
234
235 free(disp);
236
191 return 0; 237 return 0;
192} 238}
193 239
194int 240int
195omap_create(int fd, struct kms_driver **out) 241omap_create(int fd, struct kms_driver **out)
196{ 242{
243 struct display_kms *disp = NULL;
197 struct kms_driver *kms; 244 struct kms_driver *kms;
198 245
199 kms = calloc(1, sizeof(*kms)); 246 disp = calloc(1, sizeof(*disp));
200 if (!kms) 247 if (!disp)
201 return -ENOMEM; 248 return -ENOMEM;
202 249
250 kms = &disp->kms;
251
203 kms->fd = fd; 252 kms->fd = fd;
204 253
205 kms->bo_create = omap_bo_create; 254 kms->bo_create = omapkms_bo_create;
206 kms->bo_map = _omap_bo_map; 255 kms->bo_map = omapkms_bo_map;
207 kms->bo_unmap = omap_bo_unmap; 256 kms->bo_unmap = omapkms_bo_unmap;
208 kms->bo_get_prop = omap_bo_get_prop; 257 kms->bo_get_prop = omapkms_bo_get_prop;
209 kms->bo_destroy = omap_bo_destroy; 258 kms->bo_destroy = omapkms_bo_destroy;
210 kms->get_prop = omap_get_prop; 259 kms->get_prop = omapkms_get_prop;
211 kms->destroy = omap_destroy; 260 kms->destroy = omapkms_destroy;
212 *out = kms; 261 *out = kms;
213 262
263 disp->dev = omap_device_new(fd);
264 if (!disp->dev) {
265 ERROR("couldn't create device");
266 goto fail;
267 }
268
269 disp->bo_flags = OMAP_BO_SCANOUT;
270
214 return 0; 271 return 0;
272
273fail:
274 free(disp);
275 return -ENOMEM;
215} 276}
diff --git a/tests/modetest/modetest.c b/tests/modetest/modetest.c
index ce62163d..ff45dc9a 100644
--- a/tests/modetest/modetest.c
+++ b/tests/modetest/modetest.c
@@ -949,7 +949,7 @@ int main(int argc, char **argv)
949 int c; 949 int c;
950 int encoders = 0, connectors = 0, crtcs = 0, planes = 0, framebuffers = 0; 950 int encoders = 0, connectors = 0, crtcs = 0, planes = 0, framebuffers = 0;
951 int test_vsync = 0; 951 int test_vsync = 0;
952 char *modules[] = { "i915", "radeon", "nouveau", "vmwgfx", "omapdrm", "exynos" }; 952 char *modules[] = { /* "i915", "radeon", "nouveau", "vmwgfx", */ "omapdrm" /*, "exynos" */};
953 unsigned int i; 953 unsigned int i;
954 int count = 0, plane_count = 0; 954 int count = 0, plane_count = 0;
955 struct connector con_args[2]; 955 struct connector con_args[2];