760f6bd29bf8ddf3c821900937af5c8b17de7a0f
[adaptation/panda/libdrm.git] / 0001-Adding-slp-subpackage.patch
1 From e2189a84d0da40b46c3406860fe087b7b09420b3 Mon Sep 17 00:00:00 2001
2 From: Prajwal Mohan <prajwal.karur.mohan@intel.com>
3 Date: Wed, 10 Oct 2012 09:56:06 -0700
4 Subject: [PATCH] Adding slp subpackage
5
6 ---
7  Makefile.am          |    6 +-
8  libkms/Makefile.am   |    5 +
9  libkms/slp.c         |  222 +++++++++++++
10  slp/Makefile.am      |   22 ++
11  slp/drm_slp_bufmgr.c |  847 ++++++++++++++++++++++++++++++++++++++++++++++++++
12  slp/drm_slp_bufmgr.h |  201 ++++++++++++
13  slp/libdrm_slp.pc.in |   11 +
14  slp/list.h           |  131 ++++++++
15  8 files changed, 1444 insertions(+), 1 deletions(-)
16  create mode 100644 libkms/slp.c
17  create mode 100644 slp/Makefile.am
18  create mode 100644 slp/drm_slp_bufmgr.c
19  create mode 100644 slp/drm_slp_bufmgr.h
20  create mode 100644 slp/libdrm_slp.pc.in
21  create mode 100644 slp/list.h
22
23 diff --git a/Makefile.am b/Makefile.am
24 index 256a8cc..6e74607 100644
25 --- a/Makefile.am
26 +++ b/Makefile.am
27 @@ -49,7 +49,11 @@ if HAVE_EXYNOS
28  EXYNOS_SUBDIR = exynos
29  endif
30  
31 -SUBDIRS = . $(LIBKMS_SUBDIR) $(INTEL_SUBDIR) $(NOUVEAU_SUBDIR) $(RADEON_SUBDIR) $(OMAP_SUBDIR) $(EXYNOS_SUBDIR) tests include
32 +if HAVE_SLP
33 +SLP_SUBDIR = slp
34 +endif
35 +
36 +SUBDIRS = . $(LIBKMS_SUBDIR) $(INTEL_SUBDIR) $(NOUVEAU_SUBDIR) $(RADEON_SUBDIR) $(OMAP_SUBDIR) $(EXYNOS_SUBDIR) $(SLP_SUBDIR) tests include
37  
38  libdrm_la_LTLIBRARIES = libdrm.la
39  libdrm_ladir = $(libdir)
40 diff --git a/libkms/Makefile.am b/libkms/Makefile.am
41 index fa379a4..df74b7e 100644
42 --- a/libkms/Makefile.am
43 +++ b/libkms/Makefile.am
44 @@ -31,6 +31,11 @@ if HAVE_RADEON
45  libkms_la_SOURCES += radeon.c
46  endif
47  
48 +if HAVE_SLP
49 +libkms_la_SOURCES += slp.c
50 +AM_CFLAGS += -I$(top_srcdir)/exynos
51 +endif
52 +
53  libkmsincludedir = ${includedir}/libkms
54  libkmsinclude_HEADERS = libkms.h
55  
56 diff --git a/libkms/slp.c b/libkms/slp.c
57 new file mode 100644
58 index 0000000..263f2ab
59 --- /dev/null
60 +++ b/libkms/slp.c
61 @@ -0,0 +1,222 @@
62 +/**************************************************************************
63 + *
64 + * Copyright © 2009 VMware, Inc., Palo Alto, CA., USA
65 + * All Rights Reserved.
66 + *
67 + * Permission is hereby granted, free of charge, to any person obtaining a
68 + * copy of this software and associated documentation files (the
69 + * "Software"), to deal in the Software without restriction, including
70 + * without limitation the rights to use, copy, modify, merge, publish,
71 + * distribute, sub license, and/or sell copies of the Software, and to
72 + * permit persons to whom the Software is furnished to do so, subject to
73 + * the following conditions:
74 + *
75 + * The above copyright notice and this permission notice (including the
76 + * next paragraph) shall be included in all copies or substantial portions
77 + * of the Software.
78 + *
79 + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
80 + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
81 + * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
82 + * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
83 + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
84 + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
85 + * USE OR OTHER DEALINGS IN THE SOFTWARE.
86 + *
87 + **************************************************************************/
88 +
89 +
90 +#define HAVE_STDINT_H
91 +#define _FILE_OFFSET_BITS 64
92 +
93 +#include <errno.h>
94 +#include <stdio.h>
95 +#include <stdlib.h>
96 +#include <string.h>
97 +#include "internal.h"
98 +
99 +#include <sys/mman.h>
100 +#include <sys/ioctl.h>
101 +#include "xf86drm.h"
102 +
103 +#include "exynos_drm.h"
104 +
105 +struct slp_bo
106 +{
107 +       struct kms_bo base;
108 +       unsigned map_count;
109 +};
110 +
111 +static int
112 +slp_get_prop(struct kms_driver *kms, unsigned key, unsigned *out)
113 +{
114 +       switch (key) {
115 +       case KMS_BO_TYPE:
116 +               *out = KMS_BO_TYPE_SCANOUT_X8R8G8B8 | KMS_BO_TYPE_CURSOR_64X64_A8R8G8B8;
117 +               break;
118 +       default:
119 +               return -EINVAL;
120 +       }
121 +       return 0;
122 +}
123 +
124 +static int
125 +slp_destroy(struct kms_driver *kms)
126 +{
127 +       free(kms);
128 +       return 0;
129 +}
130 +
131 +static int
132 +slp_bo_create(struct kms_driver *kms,
133 +                const unsigned width, const unsigned height,
134 +                const enum kms_bo_type type, const unsigned *attr,
135 +                struct kms_bo **out)
136 +{
137 +       struct drm_exynos_gem_create arg;
138 +       unsigned size, pitch;
139 +       struct slp_bo *bo;
140 +       int i, ret;
141 +
142 +       for (i = 0; attr[i]; i += 2) {
143 +               switch (attr[i]) {
144 +               case KMS_WIDTH:
145 +               case KMS_HEIGHT:
146 +               case KMS_BO_TYPE:
147 +                       break;
148 +               default:
149 +                       return -EINVAL;
150 +               }
151 +       }
152 +
153 +       bo = calloc(1, sizeof(*bo));
154 +       if (!bo)
155 +               return -ENOMEM;
156 +
157 +       if (type == KMS_BO_TYPE_CURSOR_64X64_A8R8G8B8) {
158 +               pitch = 64 * 4;
159 +               size = 64 * 64 * 4;
160 +       } else if (type == KMS_BO_TYPE_SCANOUT_X8R8G8B8) {
161 +               pitch = width * 4;
162 +               pitch = (pitch + 512 - 1) & ~(512 - 1);
163 +               size = pitch * ((height + 4 - 1) & ~(4 - 1));
164 +       } else {
165 +               return -EINVAL;
166 +       }
167 +
168 +       memset(&arg, 0, sizeof(arg));
169 +       arg.size = size;
170 +
171 +       ret = drmCommandWriteRead(kms->fd, DRM_EXYNOS_GEM_CREATE, &arg, sizeof(arg));
172 +       if (ret)
173 +               goto err_free;
174 +
175 +       bo->base.kms = kms;
176 +       bo->base.handle = arg.handle;
177 +       bo->base.size = size;
178 +       bo->base.pitch = pitch;
179 +
180 +       *out = &bo->base;
181 +
182 +       return 0;
183 +
184 +err_free:
185 +       free(bo);
186 +       return ret;
187 +}
188 +
189 +static int
190 +slp_bo_get_prop(struct kms_bo *bo, unsigned key, unsigned *out)
191 +{
192 +       switch (key) {
193 +       default:
194 +               return -EINVAL;
195 +       }
196 +}
197 +
198 +static int
199 +slp_bo_map(struct kms_bo *_bo, void **out)
200 +{
201 +       struct slp_bo *bo = (struct slp_bo *)_bo;
202 +       struct drm_exynos_gem_map_off arg;
203 +       void *map = NULL;
204 +       int ret;
205 +
206 +       if (bo->base.ptr) {
207 +               bo->map_count++;
208 +               *out = bo->base.ptr;
209 +               return 0;
210 +       }
211 +
212 +       memset(&arg, 0, sizeof(arg));
213 +       arg.handle = bo->base.handle;
214 +
215 +       ret = drmCommandWriteRead(bo->base.kms->fd, DRM_EXYNOS_GEM_MAP_OFFSET, &arg, sizeof(arg));
216 +       if (ret)
217 +               return ret;
218 +
219 +       map = mmap(0, bo->base.size, PROT_READ | PROT_WRITE, MAP_SHARED, bo->base.kms->fd, arg.offset);
220 +       if (map == MAP_FAILED)
221 +               return -errno;
222 +
223 +       bo->base.ptr = map;
224 +       bo->map_count++;
225 +       *out = bo->base.ptr;
226 +
227 +       return 0;
228 +}
229 +
230 +static int
231 +slp_bo_unmap(struct kms_bo *_bo)
232 +{
233 +       struct slp_bo *bo = (struct slp_bo *)_bo;
234 +       bo->map_count--;
235 +       return 0;
236 +}
237 +
238 +static int
239 +slp_bo_destroy(struct kms_bo *_bo)
240 +{
241 +       struct slp_bo *bo = (struct slp_bo *)_bo;
242 +       struct drm_gem_close arg;
243 +       int ret;
244 +
245 +       if (bo->base.ptr) {
246 +               /* XXX Sanity check map_count */
247 +               munmap(bo->base.ptr, bo->base.size);
248 +               bo->base.ptr = NULL;
249 +       }
250 +
251 +       memset(&arg, 0, sizeof(arg));
252 +       arg.handle = bo->base.handle;
253 +
254 +       ret = drmIoctl(bo->base.kms->fd, DRM_IOCTL_GEM_CLOSE, &arg);
255 +       if (ret)
256 +               return -errno;
257 +
258 +       free(bo);
259 +       return 0;
260 +}
261 +
262 +int
263 +slp_create(int fd, struct kms_driver **out)
264 +{
265 +       struct kms_driver *kms;
266 +
267 +       kms = calloc(1, sizeof(*kms));
268 +       if (!kms)
269 +               return -ENOMEM;
270 +
271 +       kms->fd = fd;
272 +
273 +       kms->bo_create = slp_bo_create;
274 +       kms->bo_map = slp_bo_map;
275 +       kms->bo_unmap = slp_bo_unmap;
276 +       kms->bo_get_prop = slp_bo_get_prop;
277 +       kms->bo_destroy = slp_bo_destroy;
278 +       kms->get_prop = slp_get_prop;
279 +       kms->destroy = slp_destroy;
280 +       *out = kms;
281 +
282 +       return 0;
283 +}
284 diff --git a/slp/Makefile.am b/slp/Makefile.am
285 new file mode 100644
286 index 0000000..132662b
287 --- /dev/null
288 +++ b/slp/Makefile.am
289 @@ -0,0 +1,22 @@
290 +SUBDIRS = .
291 +
292 +AM_CFLAGS = \
293 +       $(WARN_CFLAGS) \
294 +       -I$(top_srcdir) \
295 +       -I$(top_srcdir)/slp \
296 +       $(PTHREADSTUBS_CFLAGS) \
297 +       -I$(top_srcdir)/include/drm
298 +
299 +libdrm_slp_la_LTLIBRARIES = libdrm_slp.la
300 +libdrm_slp_ladir = $(libdir)
301 +libdrm_slp_la_LDFLAGS = -version-number 1:0:0 -no-undefined
302 +libdrm_slp_la_LIBADD = ../libdrm.la @PTHREADSTUBS_LIBS@ @CLOCK_LIB@ -ldl
303 +
304 +libdrm_slp_la_SOURCES = \
305 +       drm_slp_bufmgr.c \
306 +       drm_slp_bufmgr.h
307 +
308 +libdrm_slpincludedir = ${includedir}/libdrm
309 +libdrm_slpinclude_HEADERS = drm_slp_bufmgr.h
310 +
311 +pkgconfig_DATA = libdrm_slp.pc
312 diff --git a/slp/drm_slp_bufmgr.c b/slp/drm_slp_bufmgr.c
313 new file mode 100644
314 index 0000000..f723ded
315 --- /dev/null
316 +++ b/slp/drm_slp_bufmgr.c
317 @@ -0,0 +1,847 @@
318 +/**************************************************************************
319 +
320 +xserver-xorg-video-sec
321 +
322 +Copyright 2011 Samsung Electronics co., Ltd. All Rights Reserved.
323 +
324 +Contact: SooChan Lim <sc1.lim@samsung.com>, Sangjin Lee <lsj119@samsung.com>
325 +
326 +Permission is hereby granted, free of charge, to any person obtaining a
327 +copy of this software and associated documentation files (the
328 +"Software"), to deal in the Software without restriction, including
329 +without limitation the rights to use, copy, modify, merge, publish,
330 +distribute, sub license, and/or sell copies of the Software, and to
331 +permit persons to whom the Software is furnished to do so, subject to
332 +the following conditions:
333 +
334 +The above copyright notice and this permission notice (including the
335 +next paragraph) shall be included in all copies or substantial portions
336 +of the Software.
337 +
338 +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
339 +OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
340 +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
341 +IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
342 +ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
343 +TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
344 +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
345 +
346 +**************************************************************************/
347 +
348 +#include "config.h"
349 +
350 +#include <unistd.h>
351 +#include <limits.h>
352 +#include <stdlib.h>
353 +#include <stdio.h>
354 +#include <sys/types.h>
355 +#include <sys/stat.h>
356 +#include <fcntl.h>
357 +#include <dlfcn.h>
358 +#include <dirent.h>
359 +#include <string.h>
360 +#include <errno.h>
361 +
362 +#include "drm_slp_bufmgr.h"
363 +#include "list.h"
364 +
365 +#define PREFIX_LIB    "libdrm_slp_"
366 +#define SUFFIX_LIB    ".so"
367 +#define DEFAULT_LIB  PREFIX_LIB"default"SUFFIX_LIB
368 +
369 +#define NUM_TRY_LOCK   10
370 +#define SEM_NAME               "pixmap_1"
371 +#define SEM_DEBUG 0
372 +
373 +#define DRM_RETURN_IF_FAIL(cond)          {if (!(cond)) { fprintf (stderr, "[%s] : '%s' failed.\n", __FUNCTION__, #cond); return; }}
374 +#define DRM_RETURN_VAL_IF_FAIL(cond, val) {if (!(cond)) { fprintf (stderr, "[%s] : '%s' failed.\n", __FUNCTION__, #cond); return val; }}
375 +
376 +#define MGR_IS_VALID(mgr) (mgr && \
377 +                                                mgr->link.next && \
378 +                                                mgr->link.next->prev == &mgr->link)
379 +#define BO_IS_VALID(bo) (bo && \
380 +                                            MGR_IS_VALID(bo->bufmgr) && \
381 +                                            bo->list.next && \
382 +                                            bo->list.next->prev == &bo->list)
383 +
384 +typedef struct{
385 +       void* data;
386 +
387 +       int is_valid;
388 +       drm_data_free free_func ;
389 +}drm_slp_user_data;
390 +
391 +static struct list_head *gBufMgrs = NULL;
392 +
393 +static int
394 +_sem_wait_wrapper(sem_t* sem)
395 +{
396 +       int res = 0;
397 +       int num_try = NUM_TRY_LOCK;
398 +
399 +       do
400 +       {
401 +               res = sem_wait(sem);
402 +               num_try--;
403 +       } while((res == -1) && (errno == EINTR) && (num_try >= 0));
404 +
405 +       if(res == -1)
406 +       {
407 +               fprintf(stderr,
408 +                               "[libdrm] error %s:%d(sem:%p, num_try:%d) PID:%04d\n",
409 +                               __FUNCTION__,
410 +                               __LINE__,
411 +                               sem,
412 +                               num_try,
413 +                               getpid());
414 +               return 0;
415 +       }
416 +#if SEM_DEBUG
417 +       else
418 +       {
419 +               fprintf(stderr,
420 +                               "[libdrm]   LOCK >> %s:%d(sem:%p, num_try:%d) PID:%04d\n",
421 +                               __FUNCTION__,
422 +                               __LINE__,
423 +                               sem,
424 +                               num_try,
425 +                               getpid());
426 +       }
427 +#endif
428 +
429 +       return 1;
430 +}
431 +
432 +static int
433 +_sem_post_wrapper(sem_t* sem)
434 +{
435 +       int res = 0;
436 +       int num_try = NUM_TRY_LOCK;
437 +
438 +       do
439 +       {
440 +               res = sem_post(sem);
441 +               num_try--;
442 +
443 +       } while((res == -1) && (errno == EINTR) && (num_try >= 0));
444 +
445 +       if(res == -1)
446 +       {
447 +               fprintf(stderr,
448 +                               "[libdrm] error %s:%d(sem:%p, num_try:%d) PID:%04d\n",
449 +                               __FUNCTION__,
450 +                               __LINE__,
451 +                               sem,
452 +                               num_try,
453 +                               getpid());
454 +               return 0;
455 +       }
456 +#if SEM_DEBUG
457 +       else
458 +       {
459 +               fprintf(stderr,
460 +                               "[libdrm] UNLOCK << %s:%d(sem:%p, num_try:%d) PID:%04d\n",
461 +                               __FUNCTION__,
462 +                               __LINE__,
463 +                               sem,
464 +                               num_try,
465 +                               getpid());
466 +       }
467 +#endif
468 +
469 +       return 1;
470 +}
471 +
472 +static int
473 +_sem_open(drm_slp_bufmgr bufmgr)
474 +{
475 +       bufmgr->semObj.handle = sem_open(SEM_NAME, O_CREAT, 0777, 1);
476 +       if(bufmgr->semObj.handle == SEM_FAILED)
477 +       {
478 +               fprintf(stderr,
479 +                               "[libdrm] error %s:%d(name:%s) PID:%04d\n",
480 +                               __FUNCTION__,
481 +                               __LINE__,
482 +                               SEM_NAME,
483 +                               getpid());
484 +               bufmgr->semObj.handle = NULL;
485 +               return 0;
486 +       }
487 +#if SEM_DEBUG
488 +       else
489 +       {
490 +               fprintf(stderr,
491 +                               "[libdrm] OPEN %s:%d(sem:%p) PID:%04d\n",
492 +                               __FUNCTION__,
493 +                               __LINE__,
494 +                               bufmgr->semObj.handle,
495 +                               getpid());
496 +       }
497 +#endif
498 +
499 +       bufmgr->semObj.status = STATUS_UNLOCK;
500 +
501 +       return 1;
502 +}
503 +
504 +static int
505 +_sem_close(drm_slp_bufmgr bufmgr)
506 +{
507 +       _sem_wait_wrapper(bufmgr->semObj.handle);
508 +       sem_unlink(SEM_NAME);
509 +       return 1;
510 +}
511 +
512 +static int
513 +_sem_lock(drm_slp_bufmgr bufmgr)
514 +{
515 +       if(bufmgr->semObj.status != STATUS_UNLOCK) return 0;
516 +
517 +       if(!_sem_wait_wrapper(bufmgr->semObj.handle)) return 0;
518 +       bufmgr->semObj.status = STATUS_LOCK;
519 +       return 1;
520 +}
521 +
522 +static int
523 +_sem_unlock(drm_slp_bufmgr bufmgr)
524 +{
525 +       if(bufmgr->semObj.status != STATUS_LOCK) return 0;
526 +
527 +       _sem_post_wrapper(bufmgr->semObj.handle);
528 +       bufmgr->semObj.status = STATUS_UNLOCK;
529 +       return 1;
530 +}
531 +
532 +static drm_slp_bufmgr
533 +_load_bufmgr(int fd, const char *file, void *arg)
534 +{
535 +       char path[PATH_MAX] = {0,};
536 +       drm_slp_bufmgr bufmgr = NULL;
537 +       int (*bufmgr_init)(drm_slp_bufmgr bufmgr, int fd, void *arg);
538 +       void *module;
539 +
540 +       snprintf(path, sizeof(path), BUFMGR_DIR "/%s", file);
541 +
542 +       module = dlopen(path, RTLD_LAZY);
543 +       if (!module) {
544 +               fprintf(stderr,
545 +                       "[libdrm] failed to load module: %s(%s)\n",
546 +                       dlerror(), file);
547 +               return NULL;
548 +       }
549 +
550 +       bufmgr_init = dlsym(module, "init_slp_bufmgr");
551 +       if (!bufmgr_init) {
552 +               fprintf(stderr,
553 +                       "[libdrm] failed to lookup init function: %s(%s)\n",
554 +                       dlerror(), file);
555 +               return NULL;
556 +       }
557 +
558 +       bufmgr = calloc(sizeof(struct _drm_slp_bufmgr), 1);
559 +       if(!bufmgr)
560 +       {
561 +               return NULL;
562 +       }
563 +
564 +       if(!bufmgr_init(bufmgr, fd, arg))
565 +       {
566 +               fprintf(stderr,"[libdrm] Fail to init module(%s)\n", file);
567 +               free(bufmgr);
568 +               bufmgr = NULL;
569 +               return NULL;
570 +       }
571 +
572 +       fprintf(stderr,"[libdrm] Success to load module(%s)\n", file);
573 +
574 +       return bufmgr;
575 +}
576 +
577 +drm_slp_bufmgr
578 +drm_slp_bufmgr_init(int fd, void *arg)
579 +{
580 +    drm_slp_bufmgr bufmgr = NULL;
581 +    const char *p = NULL;
582 +
583 +    if (fd < 0)
584 +        return NULL;
585 +
586 +    if(gBufMgrs == NULL)
587 +    {
588 +        gBufMgrs = malloc(sizeof(struct list_head));
589 +        LIST_INITHEAD(gBufMgrs);
590 +    }
591 +    else
592 +    {
593 +        LIST_FOR_EACH_ENTRY(bufmgr, gBufMgrs, link)
594 +        {
595 +            if(bufmgr->drm_fd == fd)
596 +            {
597 +                bufmgr->ref_count++;
598 +                fprintf(stderr, "[libdrm] bufmgr ref: fd=%d, ref_count:%d\n", fd, bufmgr->ref_count);
599 +                return bufmgr;
600 +            }
601 +        }
602 +        bufmgr = NULL;
603 +    }
604 +    fprintf(stderr, "[libdrm] bufmgr init: fd=%d\n", fd);
605 +
606 +    p = getenv ("SLP_BUFMGR_MODULE");
607 +    if (p)
608 +    {
609 +        char file[PATH_MAX] = {0,};
610 +        snprintf(file, sizeof(file), PREFIX_LIB"%s"SUFFIX_LIB, p);
611 +        bufmgr = _load_bufmgr (fd, file, arg);
612 +    }
613 +
614 +    if (!bufmgr)
615 +        bufmgr = _load_bufmgr (fd, DEFAULT_LIB, arg);
616 +
617 +    if (!bufmgr)
618 +    {
619 +        struct dirent **namelist;
620 +        int found = 0;
621 +        int n;
622 +
623 +        n = scandir(BUFMGR_DIR, &namelist, 0, alphasort);
624 +        if (n < 0)
625 +            fprintf(stderr,"[libdrm] no files : %s\n", BUFMGR_DIR);
626 +        else
627 +        {
628 +            while(n--)
629 +            {
630 +                if (!found && strstr (namelist[n]->d_name, PREFIX_LIB))
631 +                {
632 +                    char *p = strstr (namelist[n]->d_name, SUFFIX_LIB);
633 +                    if (!strcmp (p, SUFFIX_LIB))
634 +                    {
635 +                        bufmgr = _load_bufmgr (fd, namelist[n]->d_name, arg);
636 +                        if (bufmgr)
637 +                            found = 1;
638 +                    }
639 +                }
640 +                free(namelist[n]);
641 +            }
642 +            free(namelist);
643 +        }
644 +    }
645 +
646 +    if (!bufmgr)
647 +    {
648 +        fprintf(stderr,"[libdrm] backend is NULL.\n");
649 +        return NULL;
650 +    }
651 +
652 +    if (pthread_mutex_init(&bufmgr->lock, NULL) != 0)
653 +    {
654 +        bufmgr->bufmgr_destroy(bufmgr);
655 +        free(bufmgr);
656 +        return NULL;
657 +    }
658 +
659 +    bufmgr->ref_count = 1;
660 +    bufmgr->drm_fd = fd;
661 +
662 +    LIST_INITHEAD(&bufmgr->bos);
663 +    LIST_ADD(&bufmgr->link, gBufMgrs);
664 +
665 +    return bufmgr;
666 +}
667 +
668 +void
669 +drm_slp_bufmgr_destroy(drm_slp_bufmgr bufmgr)
670 +{
671 +    DRM_RETURN_IF_FAIL(MGR_IS_VALID(bufmgr));
672 +
673 +    fprintf(stderr, "[DRM] bufmgr destroy: bufmgr:%p, drm_fd:%d\n",
674 +                bufmgr, bufmgr->drm_fd);
675 +
676 +    /*Check and Free bos*/
677 +    if(!LIST_IS_EMPTY(&bufmgr->bos))
678 +    {
679 +        drm_slp_bo bo, tmp;
680 +
681 +        LIST_FOR_EACH_ENTRY_SAFE(bo, tmp, &bufmgr->bos,  list)
682 +        {
683 +            fprintf(stderr, "[libdrm] Un-freed bo(%p, ref:%d) \n", bo, bo->ref_cnt);
684 +            bo->ref_cnt = 1;
685 +            drm_slp_bo_unref(bo);
686 +        }
687 +    }
688 +
689 +    LIST_DEL(&bufmgr->link);
690 +    bufmgr->bufmgr_destroy(bufmgr);
691 +
692 +    if(bufmgr->semObj.isOpened)
693 +    {
694 +        _sem_close(bufmgr);
695 +    }
696 +
697 +    pthread_mutex_destroy(&bufmgr->lock);
698 +    free(bufmgr);
699 +}
700 +
701 +int
702 +drm_slp_bufmgr_lock(drm_slp_bufmgr bufmgr)
703 +{
704 +    DRM_RETURN_VAL_IF_FAIL(MGR_IS_VALID(bufmgr), 0);
705 +
706 +    pthread_mutex_lock(&bufmgr->lock);
707 +
708 +    if(bufmgr->bufmgr_lock)
709 +    {
710 +        int ret;
711 +        ret = bufmgr->bufmgr_lock(bufmgr);
712 +        pthread_mutex_unlock(&bufmgr->lock);
713 +        return ret;
714 +    }
715 +
716 +    if(!bufmgr->semObj.isOpened)
717 +    {
718 +        if(_sem_open(bufmgr) != 1)
719 +        {
720 +            pthread_mutex_unlock(&bufmgr->lock);
721 +            return 0;
722 +        }
723 +        bufmgr->semObj.isOpened = 1;
724 +    }
725 +
726 +    if(_sem_lock(bufmgr) != 1)
727 +    {
728 +        pthread_mutex_unlock(&bufmgr->lock);
729 +        return 0;
730 +    }
731 +
732 +    pthread_mutex_unlock(&bufmgr->lock);
733 +
734 +    return 1;
735 +}
736 +
737 +int
738 +drm_slp_bufmgr_unlock(drm_slp_bufmgr bufmgr)
739 +{
740 +    DRM_RETURN_VAL_IF_FAIL(MGR_IS_VALID(bufmgr), 0);
741 +
742 +    pthread_mutex_lock(&bufmgr->lock);
743 +
744 +    if(bufmgr->bufmgr_unlock)
745 +    {
746 +        int ret;
747 +        ret = bufmgr->bufmgr_unlock(bufmgr);
748 +        pthread_mutex_unlock(&bufmgr->lock);
749 +        return ret;
750 +    }
751 +
752 +    if(_sem_unlock(bufmgr) != 1)
753 +    {
754 +        pthread_mutex_unlock(&bufmgr->lock);
755 +        return 0;
756 +    }
757 +
758 +    pthread_mutex_unlock(&bufmgr->lock);
759 +
760 +    return 1;
761 +}
762 +
763 +int
764 +drm_slp_bufmgr_cache_flush(drm_slp_bufmgr bufmgr, drm_slp_bo bo, int flags)
765 +{
766 +    int ret;
767 +
768 +    DRM_RETURN_VAL_IF_FAIL(MGR_IS_VALID(bufmgr) || BO_IS_VALID(bo), 0);
769 +
770 +    if (!bo)
771 +        flags |= DRM_SLP_CACHE_ALL;
772 +
773 +    if (bo)
774 +    {
775 +        DRM_RETURN_VAL_IF_FAIL(BO_IS_VALID(bo), 0);
776 +
777 +        if(!bo->bufmgr)
778 +            return 0;
779 +
780 +        pthread_mutex_lock(&bo->bufmgr->lock);
781 +        ret = bo->bufmgr->bufmgr_cache_flush(bufmgr, bo, flags);
782 +        pthread_mutex_unlock(&bo->bufmgr->lock);
783 +    }
784 +    else
785 +    {
786 +        pthread_mutex_lock(&bufmgr->lock);
787 +        ret = bufmgr->bufmgr_cache_flush(bufmgr, NULL, flags);
788 +        pthread_mutex_unlock(&bufmgr->lock);
789 +    }
790 +
791 +    return ret;
792 +}
793 +
794 +int
795 +drm_slp_bo_size(drm_slp_bo bo)
796 +{
797 +    int size;
798 +    drm_slp_bufmgr bufmgr;
799 +
800 +    DRM_RETURN_VAL_IF_FAIL(BO_IS_VALID(bo), 0);
801 +
802 +    bufmgr = bo->bufmgr;
803 +
804 +    pthread_mutex_lock(&bufmgr->lock);
805 +    size = bo->bufmgr->bo_size(bo);
806 +    pthread_mutex_unlock(&bufmgr->lock);
807 +
808 +    return size;
809 +}
810 +
811 +drm_slp_bo
812 +drm_slp_bo_ref(drm_slp_bo bo)
813 +{
814 +    drm_slp_bufmgr bufmgr;
815 +
816 +    DRM_RETURN_VAL_IF_FAIL(BO_IS_VALID(bo), NULL);
817 +
818 +    bufmgr = bo->bufmgr;
819 +
820 +    pthread_mutex_lock(&bufmgr->lock);
821 +
822 +    bo->ref_cnt++;
823 +
824 +    pthread_mutex_unlock(&bufmgr->lock);
825 +
826 +    return bo;
827 +}
828 +
829 +void
830 +drm_slp_bo_unref(drm_slp_bo bo)
831 +{
832 +    drm_slp_bufmgr bufmgr;
833 +
834 +    DRM_RETURN_IF_FAIL(BO_IS_VALID(bo));
835 +
836 +    bufmgr = bo->bufmgr;
837 +
838 +    if(0 >= bo->ref_cnt)
839 +        return;
840 +
841 +    pthread_mutex_lock(&bufmgr->lock);
842 +
843 +    bo->ref_cnt--;
844 +    if(bo->ref_cnt == 0)
845 +    {
846 +        if(bo->user_data)
847 +        {
848 +            void* rd;
849 +            drm_slp_user_data* old_data;
850 +            unsigned long key;
851 +
852 +            while(1==drmSLFirst(bo->user_data, &key, &rd))
853 +            {
854 +                old_data = (drm_slp_user_data*)rd;
855 +
856 +                if(old_data->is_valid && old_data->free_func)
857 +                {
858 +                    if(old_data->data)
859 +                        old_data->free_func(old_data->data);
860 +                    old_data->data = NULL;
861 +                    free(old_data);
862 +                }
863 +                drmSLDelete(bo->user_data, key);
864 +            }
865 +
866 +            drmSLDestroy(bo->user_data);
867 +            bo->user_data = (void*)0;
868 +        }
869 +
870 +        LIST_DEL(&bo->list);
871 +        bufmgr->bo_free(bo);
872 +
873 +        free(bo);
874 +    }
875 +
876 +    pthread_mutex_unlock(&bufmgr->lock);
877 +}
878 +
879 +drm_slp_bo
880 +drm_slp_bo_alloc(drm_slp_bufmgr bufmgr, const char * name, int size, int flags)
881 +{
882 +    drm_slp_bo bo=NULL;
883 +
884 +    DRM_RETURN_VAL_IF_FAIL( MGR_IS_VALID(bufmgr) && (size > 0), NULL);
885 +
886 +    bo = calloc(sizeof(struct _drm_slp_bo), 1);
887 +    if(!bo)
888 +        return NULL;
889 +
890 +    bo->bufmgr = bufmgr;
891 +
892 +    pthread_mutex_lock(&bufmgr->lock);
893 +    if(!bufmgr->bo_alloc(bo, name, size, flags))
894 +    {
895 +        free(bo);
896 +        pthread_mutex_unlock(&bufmgr->lock);
897 +        return NULL;
898 +    }
899 +    bo->ref_cnt = 1;
900 +    LIST_ADD(&bo->list, &bufmgr->bos);
901 +    pthread_mutex_unlock(&bufmgr->lock);
902 +
903 +    return bo;
904 +}
905 +
906 +drm_slp_bo
907 +drm_slp_bo_attach(drm_slp_bufmgr bufmgr,
908 +                             const char*    name,
909 +                             int type,
910 +                             int size,
911 +                             unsigned int handle)
912 +{
913 +    drm_slp_bo bo;
914 +
915 +    DRM_RETURN_VAL_IF_FAIL(MGR_IS_VALID(bufmgr), NULL);
916 +
917 +    bo = calloc(sizeof(struct _drm_slp_bo), 1);
918 +    if(!bo)
919 +        return NULL;
920 +
921 +    bo->bufmgr = bufmgr;
922 +
923 +    pthread_mutex_lock(&bufmgr->lock);
924 +    if(!bufmgr->bo_attach(bo, name, type, size, handle))
925 +    {
926 +        free(bo);
927 +        pthread_mutex_unlock(&bufmgr->lock);
928 +        return NULL;
929 +    }
930 +    bo->ref_cnt = 1;
931 +    LIST_ADD(&bo->list, &bufmgr->bos);
932 +    pthread_mutex_unlock(&bufmgr->lock);
933 +
934 +    return bo;
935 +}
936 +
937 +drm_slp_bo
938 +drm_slp_bo_import(drm_slp_bufmgr bufmgr, unsigned int key)
939 +{
940 +    drm_slp_bo bo;
941 +
942 +    DRM_RETURN_VAL_IF_FAIL(MGR_IS_VALID(bufmgr), NULL);
943 +
944 +    bo = calloc(sizeof(struct _drm_slp_bo), 1);
945 +    if(!bo)
946 +        return NULL;
947 +
948 +    bo->bufmgr = bufmgr;
949 +
950 +    pthread_mutex_lock(&bufmgr->lock);
951 +    if(!bufmgr->bo_import(bo, key))
952 +    {
953 +        free(bo);
954 +        pthread_mutex_unlock(&bufmgr->lock);
955 +        return NULL;
956 +    }
957 +    bo->ref_cnt = 1;
958 +    LIST_ADD(&bo->list, &bufmgr->bos);
959 +    pthread_mutex_unlock(&bufmgr->lock);
960 +
961 +    return bo;
962 +}
963 +
964 +unsigned int
965 +drm_slp_bo_export(drm_slp_bo bo)
966 +{
967 +    int ret;
968 +
969 +    DRM_RETURN_VAL_IF_FAIL(BO_IS_VALID(bo), 0);
970 +
971 +    pthread_mutex_lock(&bo->bufmgr->lock);
972 +    ret = bo->bufmgr->bo_export(bo);
973 +    pthread_mutex_unlock(&bo->bufmgr->lock);
974 +
975 +    return ret;
976 +}
977 +
978 +unsigned int
979 +drm_slp_bo_get_handle(drm_slp_bo bo, int device)
980 +{
981 +    unsigned int ret;
982 +
983 +    DRM_RETURN_VAL_IF_FAIL(BO_IS_VALID(bo), 0);
984 +
985 +    pthread_mutex_lock(&bo->bufmgr->lock);
986 +    ret = bo->bufmgr->bo_get_handle(bo, device);
987 +    pthread_mutex_unlock(&bo->bufmgr->lock);
988 +
989 +    return ret;
990 +}
991 +
992 +unsigned int
993 +drm_slp_bo_map(drm_slp_bo bo, int device, int opt)
994 +{
995 +    unsigned int ret;
996 +
997 +    DRM_RETURN_VAL_IF_FAIL(BO_IS_VALID(bo), 0);
998 +
999 +    pthread_mutex_lock(&bo->bufmgr->lock);
1000 +    if(bo->bufmgr->bo_lock)
1001 +    {
1002 +        bo->bufmgr->bo_lock(bo, 0, (void*)0);
1003 +    }
1004 +
1005 +    ret = bo->bufmgr->bo_map(bo, device, opt);
1006 +    pthread_mutex_unlock(&bo->bufmgr->lock);
1007 +
1008 +    return ret;
1009 +}
1010 +
1011 +int
1012 +drm_slp_bo_unmap(drm_slp_bo bo, int device)
1013 +{
1014 +    int ret;
1015 +
1016 +    DRM_RETURN_VAL_IF_FAIL(BO_IS_VALID(bo), 0);
1017 +
1018 +    pthread_mutex_lock(&bo->bufmgr->lock);
1019 +    ret = bo->bufmgr->bo_unmap(bo, device);
1020 +
1021 +    if(bo->bufmgr->bo_unlock)
1022 +    {
1023 +        bo->bufmgr->bo_unlock(bo);
1024 +    }
1025 +    pthread_mutex_unlock(&bo->bufmgr->lock);
1026 +
1027 +    return 0;
1028 +}
1029 +
1030 +int
1031 +drm_slp_bo_swap(drm_slp_bo bo1, drm_slp_bo bo2)
1032 +{
1033 +    void* temp;
1034 +
1035 +    DRM_RETURN_VAL_IF_FAIL(BO_IS_VALID(bo1), 0);
1036 +    DRM_RETURN_VAL_IF_FAIL(BO_IS_VALID(bo2), 0);
1037 +
1038 +    if(bo1->bufmgr->bo_size(bo1) != bo2->bufmgr->bo_size(bo2))
1039 +        return 0;
1040 +
1041 +    pthread_mutex_lock(&bo1->bufmgr->lock);
1042 +    temp = bo1->priv;
1043 +    bo1->priv = bo2->priv;
1044 +    bo2->priv = temp;
1045 +    pthread_mutex_unlock(&bo1->bufmgr->lock);
1046 +
1047 +    return 1;
1048 +}
1049 +
1050 +int
1051 +drm_slp_bo_add_user_data(drm_slp_bo bo, unsigned long key, drm_data_free data_free_func)
1052 +{
1053 +    int ret;
1054 +    drm_slp_user_data* data;
1055 +
1056 +    DRM_RETURN_VAL_IF_FAIL(BO_IS_VALID(bo), 0);
1057 +
1058 +    if(!bo->user_data)
1059 +        bo->user_data = drmSLCreate();
1060 +
1061 +    data = calloc(1, sizeof(drm_slp_user_data));
1062 +    if(!data)
1063 +        return 0;
1064 +
1065 +    data->free_func = data_free_func;
1066 +    data->data = (void*)0;
1067 +    data->is_valid = 0;
1068 +
1069 +    ret = drmSLInsert(bo->user_data, key, data);
1070 +    if(ret == 1) /* Already in list */
1071 +    {
1072 +        free(data);
1073 +        return 0;
1074 +    }
1075 +
1076 +    return 1;
1077 +}
1078 +
1079 +int
1080 +drm_slp_bo_set_user_data(drm_slp_bo bo, unsigned long key, void* data)
1081 +{
1082 +    void *rd;
1083 +    drm_slp_user_data* old_data;
1084 +
1085 +    DRM_RETURN_VAL_IF_FAIL(BO_IS_VALID(bo), 0);
1086 +
1087 +    if(!bo->user_data)
1088 +        return 0;
1089 +
1090 +    if(drmSLLookup(bo->user_data, key, &rd))
1091 +        return 0;
1092 +
1093 +    old_data = (drm_slp_user_data*)rd;
1094 +    if (!old_data)
1095 +        return 0;
1096 +
1097 +    if(old_data->is_valid)
1098 +    {
1099 +        if(old_data->free_func)
1100 +        {
1101 +            if(old_data->data)
1102 +                old_data->free_func(old_data->data);
1103 +                old_data->data = NULL;
1104 +        }
1105 +    }
1106 +    else
1107 +        old_data->is_valid = 1;
1108 +
1109 +    old_data->data = data;
1110 +
1111 +    return 1;
1112 +}
1113 +
1114 +int
1115 +drm_slp_bo_get_user_data(drm_slp_bo bo, unsigned long key, void** data)
1116 +{
1117 +    void *rd;
1118 +    drm_slp_user_data* old_data;
1119 +
1120 +    DRM_RETURN_VAL_IF_FAIL(BO_IS_VALID(bo) && data && bo->user_data, 0);
1121 +
1122 +    if(drmSLLookup(bo->user_data, key, &rd))
1123 +    {
1124 +        *data = NULL;
1125 +        return 0;
1126 +    }
1127 +
1128 +    old_data = (drm_slp_user_data*)rd;
1129 +    if (!old_data)
1130 +    {
1131 +        *data = NULL;
1132 +        return 0;
1133 +    }
1134 +
1135 +    *data = old_data->data;
1136 +
1137 +    return 1;
1138 +}
1139 +
1140 +int
1141 +drm_slp_bo_delete_user_data(drm_slp_bo bo, unsigned long key)
1142 +{
1143 +    void *rd;
1144 +    drm_slp_user_data* old_data=(void*)0;
1145 +
1146 +    DRM_RETURN_VAL_IF_FAIL(BO_IS_VALID(bo) && bo->user_data, 0);
1147 +
1148 +    if(drmSLLookup(bo->user_data, key, &rd))
1149 +        return 0;
1150 +
1151 +    old_data = (drm_slp_user_data*)rd;
1152 +    if (!old_data)
1153 +        return 0;
1154 +
1155 +    if(old_data->is_valid && old_data->free_func)
1156 +    {
1157 +        if(old_data->data)
1158 +            old_data->free_func(old_data->data);
1159 +        free(old_data);
1160 +    }
1161 +    drmSLDelete(bo->user_data, key);
1162 +
1163 +    return 1;
1164 +}
1165 diff --git a/slp/drm_slp_bufmgr.h b/slp/drm_slp_bufmgr.h
1166 new file mode 100644
1167 index 0000000..a4adef5
1168 --- /dev/null
1169 +++ b/slp/drm_slp_bufmgr.h
1170 @@ -0,0 +1,201 @@
1171 +/**************************************************************************
1172 +
1173 +xserver-xorg-video-sec
1174 +
1175 +Copyright 2011 Samsung Electronics co., Ltd. All Rights Reserved.
1176 +
1177 +Contact: SooChan Lim <sc1.lim@samsung.com>, Sangjin Lee <lsj119@samsung.com>
1178 +
1179 +Permission is hereby granted, free of charge, to any person obtaining a
1180 +copy of this software and associated documentation files (the
1181 +"Software"), to deal in the Software without restriction, including
1182 +without limitation the rights to use, copy, modify, merge, publish,
1183 +distribute, sub license, and/or sell copies of the Software, and to
1184 +permit persons to whom the Software is furnished to do so, subject to
1185 +the following conditions:
1186 +
1187 +The above copyright notice and this permission notice (including the
1188 +next paragraph) shall be included in all copies or substantial portions
1189 +of the Software.
1190 +
1191 +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
1192 +OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
1193 +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
1194 +IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
1195 +ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
1196 +TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
1197 +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1198 +
1199 +**************************************************************************/
1200 +
1201 +#ifndef _DRM_SLP_BUFMGR_H_
1202 +#define _DRM_SLP_BUFMGR_H_
1203 +
1204 +#include <semaphore.h>
1205 +#include <pthread.h>
1206 +#include <xf86drm.h>
1207 +
1208 +typedef struct _drm_slp_bo * drm_slp_bo;
1209 +typedef struct _drm_slp_bufmgr * drm_slp_bufmgr;
1210 +
1211 +struct list_head
1212 +{
1213 +    struct list_head *prev;
1214 +    struct list_head *next;
1215 +};
1216 +
1217 +struct _drm_slp_bo
1218 +{
1219 +    struct list_head list;
1220 +    drm_slp_bufmgr bufmgr;
1221 +    int ref_cnt;               /*atomic count*/
1222 +    void *user_data;
1223 +
1224 +    /* private data */
1225 +    void *priv;
1226 +};
1227 +
1228 +typedef enum
1229 +{
1230 +    STATUS_UNLOCK,
1231 +    STATUS_READY_TO_LOCK,
1232 +    STATUS_LOCK,
1233 +} lock_status;
1234 +
1235 +struct _drm_slp_bufmgr
1236 +{
1237 +    struct list_head bos;  /*list head of bo*/
1238 +
1239 +    pthread_mutex_t lock;
1240 +    struct {
1241 +        int isOpened;
1242 +        lock_status status;
1243 +        sem_t* handle;
1244 +    } semObj;
1245 +
1246 +    void         (*bufmgr_destroy)(drm_slp_bufmgr bufmgr);
1247 +    int          (*bufmgr_cache_flush)(drm_slp_bufmgr bufmgr, drm_slp_bo bo, int flags);
1248 +
1249 +    int          (*bo_size)(drm_slp_bo bo);
1250 +
1251 +    void         (*bo_free)(drm_slp_bo bo);
1252 +    int          (*bo_alloc)(drm_slp_bo bo,
1253 +                                        const char*    name,
1254 +                                        int            size,
1255 +                                        int flags);
1256 +    int          (*bo_attach)(drm_slp_bo bo,
1257 +                                        const char*    name,
1258 +                                        int          type,
1259 +                                        int            size,
1260 +                                        unsigned int          handle);
1261 +    int          (*bo_import)(drm_slp_bo bo, unsigned int key);
1262 +    unsigned int (*bo_export)(drm_slp_bo bo);
1263 +
1264 +    unsigned int (*bo_get_handle)(drm_slp_bo bo, int device);
1265 +    unsigned int        (*bo_map)(drm_slp_bo bo, int device, int opt);
1266 +    int          (*bo_unmap)(drm_slp_bo bo, int device);
1267 +
1268 +
1269 +    /* Padding for future extension */
1270 +    int (*bufmgr_lock) (drm_slp_bufmgr bufmgr);
1271 +    int (*bufmgr_unlock) (drm_slp_bufmgr bufmgr);
1272 +    int (*bo_lock) (drm_slp_bo bo, unsigned int checkOnly, unsigned int* isLocked);
1273 +    int (*bo_unlock) (drm_slp_bo bo);
1274 +    void (*reserved5) (void);
1275 +    void (*reserved6) (void);
1276 +
1277 +    /* private data */
1278 +    void *priv;
1279 +
1280 +    struct list_head link;  /*link of bufmgr*/
1281 +
1282 +    int drm_fd;
1283 +    int ref_count;
1284 +};
1285 +
1286 +/* DRM_SLP_MEM_TYPE */
1287 +#define DRM_SLP_MEM_GEM             0
1288 +#define DRM_SLP_MEM_USERPTR     1
1289 +#define DRM_SLP_MEM_DMABUF      2
1290 +#define DRM_SLP_MEM_GPU             3
1291 +
1292 +/* DRM_SLP_DEVICE_TYPE */
1293 +#define DRM_SLP_DEVICE_DEFAULT   0  //Default handle
1294 +#define DRM_SLP_DEVICE_CPU 1
1295 +#define DRM_SLP_DEVICE_2D   2
1296 +#define DRM_SLP_DEVICE_3D   3
1297 +#define DRM_SLP_DEVICE_MM  4
1298 +
1299 +/* DRM_SLP_OPTION */
1300 +#define DRM_SLP_OPTION_READ    (1 << 0)
1301 +#define DRM_SLP_OPTION_WRITE   (1 << 1)
1302 +
1303 +/* DRM_SLP_CACHE */
1304 +#define DRM_SLP_CACHE_INV   0x01
1305 +#define DRM_SLP_CACHE_CLN   0x02
1306 +#define DRM_SLP_CACHE_ALL   0x10
1307 +#define DRM_SLP_CACHE_FLUSH     (DRM_SLP_CACHE_INV|DRM_SLP_CACHE_CLN)
1308 +#define DRM_SLP_CACHE_FLUSH_ALL (DRM_SLP_CACHE_FLUSH|DRM_SLP_CACHE_ALL)
1309 +
1310 +enum DRM_SLP_BO_FLAGS{
1311 +    DRM_SLP_BO_DEFAULT = 0,
1312 +    DRM_SLP_BO_SCANOUT = (1<<0),
1313 +    DRM_SLP_BO_NONCACHABLE = (1<<1),
1314 +    DRM_SLP_BO_WC = (1<<2),
1315 +};
1316 +
1317 +/* Functions for buffer mnager */
1318 +drm_slp_bufmgr
1319 +drm_slp_bufmgr_init(int fd, void * arg);
1320 +void
1321 +drm_slp_bufmgr_destroy(drm_slp_bufmgr bufmgr);
1322 +int
1323 +drm_slp_bufmgr_lock(drm_slp_bufmgr bufmgr);
1324 +int
1325 +drm_slp_bufmgr_unlock(drm_slp_bufmgr bufmgr);
1326 +int
1327 +drm_slp_bufmgr_cache_flush(drm_slp_bufmgr bufmgr, drm_slp_bo bo, int flags);
1328 +
1329 +
1330 +/*Functions for bo*/
1331 +int
1332 +drm_slp_bo_size (drm_slp_bo bo);
1333 +drm_slp_bo
1334 +drm_slp_bo_ref(drm_slp_bo bo);
1335 +void
1336 +drm_slp_bo_unref(drm_slp_bo bo);
1337 +drm_slp_bo
1338 +drm_slp_bo_alloc(drm_slp_bufmgr bufmgr,
1339 +                            const char* name,
1340 +                            int size,
1341 +                            int flags);
1342 +drm_slp_bo
1343 +drm_slp_bo_attach(drm_slp_bufmgr bufmgr,
1344 +                             const char*    name,
1345 +                             int type,
1346 +                             int size,
1347 +                             unsigned int handle);
1348 +drm_slp_bo
1349 +drm_slp_bo_import(drm_slp_bufmgr bufmgr, unsigned int key);
1350 +unsigned int
1351 +drm_slp_bo_export(drm_slp_bo bo);
1352 +unsigned int
1353 +drm_slp_bo_get_handle(drm_slp_bo, int device);
1354 +unsigned int
1355 +drm_slp_bo_map(drm_slp_bo bo, int device, int opt);
1356 +int
1357 +drm_slp_bo_unmap(drm_slp_bo bo, int device);
1358 +int
1359 +drm_slp_bo_swap(drm_slp_bo bo1, drm_slp_bo bo2);
1360 +
1361 +/*Functions for userdata of bo*/
1362 +typedef void   (*drm_data_free)(void *);
1363 +int
1364 +drm_slp_bo_add_user_data(drm_slp_bo bo, unsigned long key, drm_data_free data_free_func);
1365 +int
1366 +drm_slp_bo_delete_user_data(drm_slp_bo bo, unsigned long key);
1367 +int
1368 +drm_slp_bo_set_user_data(drm_slp_bo bo, unsigned long key, void* data);
1369 +int
1370 +drm_slp_bo_get_user_data(drm_slp_bo bo, unsigned long key, void** data);
1371 +#endif /* _DRM_SLP_BUFMGR_H_ */
1372 diff --git a/slp/libdrm_slp.pc.in b/slp/libdrm_slp.pc.in
1373 new file mode 100644
1374 index 0000000..220d38b
1375 --- /dev/null
1376 +++ b/slp/libdrm_slp.pc.in
1377 @@ -0,0 +1,11 @@
1378 +prefix=@prefix@
1379 +exec_prefix=@exec_prefix@
1380 +libdir=@libdir@
1381 +includedir=@includedir@
1382 +
1383 +Name: libdrm
1384 +Description: Userspace interface to kernel DRM services
1385 +Version: @PACKAGE_VERSION@
1386 +Requires: libdrm
1387 +Libs: -L${libdir} -ldrm_slp
1388 +Cflags: -I${includedir} -I${includedir}/libdrm
1389 diff --git a/slp/list.h b/slp/list.h
1390 new file mode 100644
1391 index 0000000..e967b93
1392 --- /dev/null
1393 +++ b/slp/list.h
1394 @@ -0,0 +1,131 @@
1395 +/*
1396 + *
1397 + * Copyright 2006 Tungsten Graphics, Inc., Bismarck, ND. USA.
1398 + * All Rights Reserved.
1399 + *
1400 + * Permission is hereby granted, free of charge, to any person obtaining a
1401 + * copy of this software and associated documentation files (the
1402 + * "Software"), to deal in the Software without restriction, including
1403 + * without limitation the rights to use, copy, modify, merge, publish,
1404 + * distribute, sub license, and/or sell copies of the Software, and to
1405 + * permit persons to whom the Software is furnished to do so, subject to
1406 + * the following conditions:
1407 + *
1408 + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1409 + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1410 + * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
1411 + * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
1412 + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
1413 + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
1414 + * USE OR OTHER DEALINGS IN THE SOFTWARE.
1415 + *
1416 + * The above copyright notice and this permission notice (including the
1417 + * next paragraph) shall be included in all copies or substantial portions
1418 + * of the Software.
1419 + *
1420 + */
1421 +
1422 +/**
1423 + * \file
1424 + * List macros heavily inspired by the Linux kernel
1425 + * list handling. No list looping yet.
1426 + *
1427 + * Is not threadsafe, so common operations need to
1428 + * be protected using an external mutex.
1429 + */
1430 +#ifndef _U_DOUBLE_LIST_H_
1431 +#define _U_DOUBLE_LIST_H_
1432 +
1433 +#include <stddef.h>
1434 +
1435 +static void list_inithead(struct list_head *item)
1436 +{
1437 +    item->prev = item;
1438 +    item->next = item;
1439 +}
1440 +
1441 +static inline void list_add(struct list_head *item, struct list_head *list)
1442 +{
1443 +    item->prev = list;
1444 +    item->next = list->next;
1445 +    list->next->prev = item;
1446 +    list->next = item;
1447 +}
1448 +
1449 +static inline void list_addtail(struct list_head *item, struct list_head *list)
1450 +{
1451 +    item->next = list;
1452 +    item->prev = list->prev;
1453 +    list->prev->next = item;
1454 +    list->prev = item;
1455 +}
1456 +
1457 +static inline void list_replace(struct list_head *from, struct list_head *to)
1458 +{
1459 +    to->prev = from->prev;
1460 +    to->next = from->next;
1461 +    from->next->prev = to;
1462 +    from->prev->next = to;
1463 +}
1464 +
1465 +static inline void list_del(struct list_head *item)
1466 +{
1467 +    item->prev->next = item->next;
1468 +    item->next->prev = item->prev;
1469 +}
1470 +
1471 +static inline void list_delinit(struct list_head *item)
1472 +{
1473 +    item->prev->next = item->next;
1474 +    item->next->prev = item->prev;
1475 +    item->next = item;
1476 +    item->prev = item;
1477 +}
1478 +
1479 +#define LIST_INITHEAD(__item) list_inithead(__item)
1480 +#define LIST_ADD(__item, __list) list_add(__item, __list)
1481 +#define LIST_ADDTAIL(__item, __list) list_addtail(__item, __list)
1482 +#define LIST_REPLACE(__from, __to) list_replace(__from, __to)
1483 +#define LIST_DEL(__item) list_del(__item)
1484 +#define LIST_DELINIT(__item) list_delinit(__item)
1485 +
1486 +#define LIST_ENTRY(__type, __item, __field)   \
1487 +    ((__type *)(((char *)(__item)) - offsetof(__type, __field)))
1488 +
1489 +#define LIST_IS_EMPTY(__list)                   \
1490 +    ((__list)->next == (__list))
1491 +
1492 +#ifndef container_of
1493 +#define container_of(ptr, sample, member)                              \
1494 +    (void *)((char *)(ptr)                                             \
1495 +            - ((char *)&(sample)->member - (char *)(sample)))
1496 +#endif
1497 +
1498 +#define LIST_FOR_EACH_ENTRY(pos, head, member)                         \
1499 +   for (pos = container_of((head)->next, pos, member);                 \
1500 +       &pos->member != (head);                                         \
1501 +       pos = container_of(pos->member.next, pos, member))
1502 +
1503 +#define LIST_FOR_EACH_ENTRY_SAFE(pos, storage, head, member)   \
1504 +   for (pos = container_of((head)->next, pos, member),                 \
1505 +       storage = container_of(pos->member.next, pos, member);  \
1506 +       &pos->member != (head);                                         \
1507 +       pos = storage, storage = container_of(storage->member.next, storage, member))
1508 +
1509 +#define LIST_FOR_EACH_ENTRY_SAFE_REV(pos, storage, head, member)       \
1510 +   for (pos = container_of((head)->prev, pos, member),                 \
1511 +       storage = container_of(pos->member.prev, pos, member);          \
1512 +       &pos->member != (head);                                         \
1513 +       pos = storage, storage = container_of(storage->member.prev, storage, member))
1514 +
1515 +#define LIST_FOR_EACH_ENTRY_FROM(pos, start, head, member)             \
1516 +   for (pos = container_of((start), pos, member);                      \
1517 +       &pos->member != (head);                                         \
1518 +       pos = container_of(pos->member.next, pos, member))
1519 +
1520 +#define LIST_FOR_EACH_ENTRY_FROM_REV(pos, start, head, member)         \
1521 +   for (pos = container_of((start), pos, member);                      \
1522 +       &pos->member != (head);                                         \
1523 +       pos = container_of(pos->member.prev, pos, member))
1524 +
1525 +#endif /*_U_DOUBLE_LIST_H_*/
1526 -- 
1527 1.7.3.4
1528