summaryrefslogtreecommitdiffstats
path: root/meta-oe/recipes-graphics/drm/libdrm-2.4.24/glamo.patch
diff options
context:
space:
mode:
Diffstat (limited to 'meta-oe/recipes-graphics/drm/libdrm-2.4.24/glamo.patch')
-rw-r--r--meta-oe/recipes-graphics/drm/libdrm-2.4.24/glamo.patch1095
1 files changed, 1095 insertions, 0 deletions
diff --git a/meta-oe/recipes-graphics/drm/libdrm-2.4.24/glamo.patch b/meta-oe/recipes-graphics/drm/libdrm-2.4.24/glamo.patch
new file mode 100644
index 000000000..b397ded58
--- /dev/null
+++ b/meta-oe/recipes-graphics/drm/libdrm-2.4.24/glamo.patch
@@ -0,0 +1,1095 @@
1diff --git a/Makefile.am b/Makefile.am
2index 25d1747..f384228 100644
3--- a/Makefile.am
4+++ b/Makefile.am
5@@ -41,7 +41,11 @@ if HAVE_RADEON
6 RADEON_SUBDIR = radeon
7 endif
8
9-SUBDIRS = . $(LIBKMS_SUBDIR) $(INTEL_SUBDIR) $(NOUVEAU_SUBDIR) $(RADEON_SUBDIR) tests include
10+if HAVE_GLAMO
11+GLAMO_SUBDIR = glamo
12+endif
13+
14+SUBDIRS = . $(LIBKMS_SUBDIR) $(INTEL_SUBDIR) $(NOUVEAU_SUBDIR) $(RADEON_SUBDIR) $(GLAMO_SUBDIR) tests include
15
16 libdrm_la_LTLIBRARIES = libdrm.la
17 libdrm_ladir = $(libdir)
18diff --git a/configure.ac b/configure.ac
19index 62db817..0b2a33e 100644
20--- a/configure.ac
21+++ b/configure.ac
22@@ -73,6 +73,11 @@ AC_ARG_ENABLE(nouveau-experimental-api,
23 [NOUVEAU=$enableval], [NOUVEAU=no])
24
25
26+AC_ARG_ENABLE(glamo-experimental-api,
27+ AS_HELP_STRING([--enable-glamo-experimental-api],
28+ [Enable support for Glamo's KMS API (default: disabled)]),
29+ [GLAMO=$enableval], [GLAMO=no])
30+
31 dnl ===========================================================================
32 dnl check compiler flags
33 AC_DEFUN([LIBDRM_CC_TRY_FLAG], [
34@@ -169,6 +174,11 @@ if test "x$NOUVEAU" = xyes; then
35 AC_DEFINE(HAVE_NOUVEAU, 1, [Have nouveau (nvidia) support])
36 fi
37
38+AM_CONDITIONAL(HAVE_GLAMO, [test "x$GLAMO" = xyes])
39+if test "x$GLAMO" = xyes; then
40+ AC_DEFINE(HAVE_GLAMO, 1, [Have glamo support])
41+fi
42+
43 PKG_CHECK_MODULES(CAIRO, cairo, [HAVE_CAIRO=yes], [HAVE_CAIRO=no])
44 if test "x$HAVE_CAIRO" = xyes; then
45 AC_DEFINE(HAVE_CAIRO, 1, [Have cairo support])
46@@ -262,6 +272,8 @@ AC_OUTPUT([
47 radeon/libdrm_radeon.pc
48 nouveau/Makefile
49 nouveau/libdrm_nouveau.pc
50+ glamo/Makefile
51+ glamo/libdrm_glamo.pc
52 tests/Makefile
53 tests/modeprint/Makefile
54 tests/modetest/Makefile
55diff --git a/glamo/Makefile.am b/glamo/Makefile.am
56new file mode 100644
57index 0000000..1f17aa3
58--- /dev/null
59+++ b/glamo/Makefile.am
60@@ -0,0 +1,52 @@
61+# Copyright (c) 2009 Thomas Whtie <taw@bitwiz.org.uk>
62+# Based on libdrm-glamo Copyright © 2008 Jérôme Glisse
63+#
64+# Permission is hereby granted, free of charge, to any person obtaining a
65+# copy of this software and associated documentation files (the "Software"),
66+# to deal in the Software without restriction, including without limitation
67+# the rights to use, copy, modify, merge, publish, distribute, sublicense,
68+# and/or sell copies of the Software, and to permit persons to whom the
69+# Software is furnished to do so, subject to the following conditions:
70+#
71+# The above copyright notice and this permission notice (including the next
72+# paragraph) shall be included in all copies or substantial portions of the
73+# Software.
74+#
75+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
76+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
77+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
78+# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
79+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
80+# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
81+# IN THE SOFTWARE.
82+#
83+# Authors:
84+# Jérôme Glisse <glisse@freedesktop.org>
85+# Thomas White <taw@bitwiz.org.uk>
86+
87+AM_CFLAGS = \
88+ $(WARN_CFLAGS) \
89+ -I$(top_srcdir) \
90+ -I$(top_srcdir)/glamo \
91+ $(PTHREADSTUBS_CFLAGS) \
92+ -I$(top_srcdir)/include/drm
93+
94+libdrm_glamo_la_LTLIBRARIES = libdrm_glamo.la
95+libdrm_glamo_ladir = $(libdir)
96+libdrm_glamo_la_LDFLAGS = -version-number 1:0:0 -no-undefined
97+libdrm_glamo_la_LIBADD = ../libdrm.la @PTHREADSTUBS_LIBS@
98+
99+libdrm_glamo_la_SOURCES = \
100+ glamo_bo_gem.c \
101+ glamo_track.c
102+
103+libdrm_glamoincludedir = ${includedir}/libdrm
104+libdrm_glamoinclude_HEADERS = \
105+ glamo_bo.h \
106+ glamo_bo_gem.h \
107+ glamo_track.h
108+
109+pkgconfigdir = @pkgconfigdir@
110+pkgconfig_DATA = libdrm_glamo.pc
111+
112+EXTRA_DIST = libdrm_glamo.pc.in
113diff --git a/glamo/glamo_bo.h b/glamo/glamo_bo.h
114new file mode 100644
115index 0000000..8ef2a18
116--- /dev/null
117+++ b/glamo/glamo_bo.h
118@@ -0,0 +1,183 @@
119+/*
120+ * Copyright (c) 2009 Thomas White
121+ *
122+ * Heavily based on radeon_bo.h
123+ * Copyright © 2008 Jérôme Glisse
124+ * All Rights Reserved.
125+ *
126+ * Permission is hereby granted, free of charge, to any person obtaining
127+ * a copy of this software and associated documentation files (the
128+ * "Software"), to deal in the Software without restriction, including
129+ * without limitation the rights to use, copy, modify, merge, publish,
130+ * distribute, sub license, and/or sell copies of the Software, and to
131+ * permit persons to whom the Software is furnished to do so, subject to
132+ * the following conditions:
133+ *
134+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
135+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
136+ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
137+ * NON-INFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDERS, AUTHORS
138+ * AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
139+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
140+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
141+ * USE OR OTHER DEALINGS IN THE SOFTWARE.
142+ *
143+ * The above copyright notice and this permission notice (including the
144+ * next paragraph) shall be included in all copies or substantial portions
145+ * of the Software.
146+ */
147+/*
148+ * Authors:
149+ * Jérôme Glisse <glisse@freedesktop.org>
150+ * Thomas White <taw@bitwiz.org.uk>
151+ */
152+#ifndef GLAMO_BO_H
153+#define GLAMO_BO_H
154+
155+#include <stdio.h>
156+#include <stdint.h>
157+#include "glamo_track.h"
158+
159+/* bo object */
160+#define GLAMO_BO_FLAGS_MACRO_TILE 1
161+#define GLAMO_BO_FLAGS_MICRO_TILE 2
162+
163+struct glamo_bo_manager;
164+
165+struct glamo_bo {
166+ uint32_t alignment;
167+ uint32_t handle;
168+ uint32_t size;
169+ uint32_t domains;
170+ uint32_t flags;
171+ unsigned cref;
172+#ifdef GLAMO_BO_TRACK
173+ struct glamo_track *track;
174+#endif
175+ struct glamo_bo_manager *bom;
176+ void *virtual;
177+ uint32_t space_accounted;
178+};
179+
180+/* bo functions */
181+struct glamo_bo_funcs {
182+ struct glamo_bo *(*bo_open)(struct glamo_bo_manager *bom,
183+ uint32_t handle,
184+ uint32_t size,
185+ uint32_t alignment,
186+ uint32_t domains,
187+ uint32_t flags);
188+ void (*bo_ref)(struct glamo_bo *bo);
189+ struct glamo_bo *(*bo_unref)(struct glamo_bo *bo);
190+ int (*bo_map)(struct glamo_bo *bo, int write);
191+ int (*bo_unmap)(struct glamo_bo *bo);
192+ int (*bo_wait)(struct glamo_bo *bo);
193+};
194+
195+struct glamo_bo_manager {
196+ struct glamo_bo_funcs *funcs;
197+ int fd;
198+ struct glamo_tracker tracker;
199+};
200+
201+static inline void _glamo_bo_debug(struct glamo_bo *bo,
202+ const char *op,
203+ const char *file,
204+ const char *func,
205+ int line)
206+{
207+ fprintf(stderr, "%s %p 0x%08X 0x%08X 0x%08X [%s %s %d]\n",
208+ op, (void *)bo, bo->handle, bo->size, bo->cref, file, func, line);
209+}
210+
211+static inline struct glamo_bo *_glamo_bo_open(struct glamo_bo_manager *bom,
212+ uint32_t handle,
213+ uint32_t size,
214+ uint32_t alignment,
215+ uint32_t domains,
216+ uint32_t flags,
217+ const char *file,
218+ const char *func,
219+ int line)
220+{
221+ struct glamo_bo *bo;
222+
223+ bo = bom->funcs->bo_open(bom, handle, size, alignment, domains, flags);
224+#ifdef GLAMO_BO_TRACK
225+ if (bo) {
226+ bo->track = glamo_tracker_add_track(&bom->tracker, bo->handle);
227+ glamo_track_add_event(bo->track, file, func, "open", line);
228+ }
229+#endif
230+ return bo;
231+}
232+
233+static inline void _glamo_bo_ref(struct glamo_bo *bo,
234+ const char *file,
235+ const char *func,
236+ int line)
237+{
238+ bo->cref++;
239+#ifdef GLAMO_BO_TRACK
240+ glamo_track_add_event(bo->track, file, func, "ref", line);
241+#endif
242+ bo->bom->funcs->bo_ref(bo);
243+}
244+
245+static inline struct glamo_bo *_glamo_bo_unref(struct glamo_bo *bo,
246+ const char *file,
247+ const char *func,
248+ int line)
249+{
250+ bo->cref--;
251+#ifdef GLAMO_BO_TRACK
252+ glamo_track_add_event(bo->track, file, func, "unref", line);
253+ if (bo->cref <= 0) {
254+ glamo_tracker_remove_track(&bo->bom->tracker, bo->track);
255+ bo->track = NULL;
256+ }
257+#endif
258+ return bo->bom->funcs->bo_unref(bo);
259+}
260+
261+static inline int _glamo_bo_map(struct glamo_bo *bo,
262+ int write,
263+ const char *file,
264+ const char *func,
265+ int line)
266+{
267+ return bo->bom->funcs->bo_map(bo, write);
268+}
269+
270+static inline int _glamo_bo_unmap(struct glamo_bo *bo,
271+ const char *file,
272+ const char *func,
273+ int line)
274+{
275+ return bo->bom->funcs->bo_unmap(bo);
276+}
277+
278+static inline int _glamo_bo_wait(struct glamo_bo *bo,
279+ const char *file,
280+ const char *func,
281+ int line)
282+{
283+ return bo->bom->funcs->bo_wait(bo);
284+}
285+
286+#define glamo_bo_open(bom, h, s, a, d, f)\
287+ _glamo_bo_open(bom, h, s, a, d, f, __FILE__, __FUNCTION__, __LINE__)
288+#define glamo_bo_ref(bo)\
289+ _glamo_bo_ref(bo, __FILE__, __FUNCTION__, __LINE__)
290+#define glamo_bo_unref(bo)\
291+ _glamo_bo_unref(bo, __FILE__, __FUNCTION__, __LINE__)
292+#define glamo_bo_map(bo, w)\
293+ _glamo_bo_map(bo, w, __FILE__, __FUNCTION__, __LINE__)
294+#define glamo_bo_unmap(bo)\
295+ _glamo_bo_unmap(bo, __FILE__, __FUNCTION__, __LINE__)
296+#define glamo_bo_debug(bo, opcode)\
297+ _glamo_bo_debug(bo, opcode, __FILE__, __FUNCTION__, __LINE__)
298+#define glamo_bo_wait(bo) \
299+ _glamo_bo_wait(bo, __FILE__, __func__, __LINE__)
300+
301+#endif
302diff --git a/glamo/glamo_bo_gem.c b/glamo/glamo_bo_gem.c
303new file mode 100644
304index 0000000..38a4436
305--- /dev/null
306+++ b/glamo/glamo_bo_gem.c
307@@ -0,0 +1,336 @@
308+/*
309+ * Copyright © 2009 Thomas White
310+ *
311+ * Based on radeon_bo_gem.c, to which the following notice applies:
312+ *
313+ * Copyright © 2008 Dave Airlie
314+ * Copyright © 2008 Jérôme Glisse
315+ * All Rights Reserved.
316+ *
317+ * Permission is hereby granted, free of charge, to any person obtaining
318+ * a copy of this software and associated documentation files (the
319+ * "Software"), to deal in the Software without restriction, including
320+ * without limitation the rights to use, copy, modify, merge, publish,
321+ * distribute, sub license, and/or sell copies of the Software, and to
322+ * permit persons to whom the Software is furnished to do so, subject to
323+ * the following conditions:
324+ *
325+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
326+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
327+ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
328+ * NON-INFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDERS, AUTHORS
329+ * AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
330+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
331+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
332+ * USE OR OTHER DEALINGS IN THE SOFTWARE.
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+/*
339+ * Authors:
340+ * Dave Airlie
341+ * Jérôme Glisse <glisse@freedesktop.org>
342+ *
343+ *
344+ * Memory mapping functions are based on intel_bufmgr_gem.c, to which the
345+ * following notice applies:
346+ *
347+ * Copyright © 2007 Red Hat Inc.
348+ * Copyright © 2007 Intel Corporation
349+ * Copyright 2006 Tungsten Graphics, Inc., Bismarck, ND., USA
350+ * All Rights Reserved.
351+ *
352+ * Permission is hereby granted, free of charge, to any person obtaining a
353+ * copy of this software and associated documentation files (the
354+ * "Software"), to deal in the Software without restriction, including
355+ * without limitation the rights to use, copy, modify, merge, publish,
356+ * distribute, sub license, and/or sell copies of the Software, and to
357+ * permit persons to whom the Software is furnished to do so, subject to
358+ * the following conditions:
359+ *
360+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
361+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
362+ * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
363+ * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
364+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
365+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
366+ * USE OR OTHER DEALINGS IN THE SOFTWARE.
367+ *
368+ * The above copyright notice and this permission notice (including the
369+ * next paragraph) shall be included in all copies or substantial portions
370+ * of the Software.
371+ *
372+ *
373+ **************************************************************************/
374+/*
375+ * Authors: Thomas Hellström <thomas-at-tungstengraphics-dot-com>
376+ * Keith Whitwell <keithw-at-tungstengraphics-dot-com>
377+ * Eric Anholt <eric@anholt.net>
378+ * Dave Airlie <airlied@linux.ie>
379+ */
380+
381+#ifdef HAVE_CONFIG_H
382+#include "config.h"
383+#endif
384+
385+#include <stdio.h>
386+#include <stdint.h>
387+#include <stdlib.h>
388+#include <string.h>
389+#include <sys/mman.h>
390+#include <sys/ioctl.h>
391+#include <errno.h>
392+
393+#include "xf86drm.h"
394+#include "drm.h"
395+#include "glamo_drm.h"
396+#include "glamo_bo.h"
397+#include "glamo_bo_gem.h"
398+
399+struct glamo_bo_gem {
400+ struct glamo_bo base;
401+ uint32_t name;
402+ int map_count;
403+};
404+
405+struct bo_manager_gem {
406+ struct glamo_bo_manager base;
407+};
408+
409+static struct glamo_bo *bo_open(struct glamo_bo_manager *bom,
410+ uint32_t handle,
411+ uint32_t size,
412+ uint32_t alignment,
413+ uint32_t domains,
414+ uint32_t flags)
415+{
416+ struct glamo_bo_gem *bo;
417+ int r;
418+
419+ bo = (struct glamo_bo_gem*)calloc(1, sizeof(struct glamo_bo_gem));
420+ if (bo == NULL) {
421+ return NULL;
422+ }
423+
424+ bo->base.bom = bom;
425+ bo->base.handle = 0;
426+ bo->base.size = size;
427+ bo->base.alignment = alignment;
428+ bo->base.domains = domains;
429+ bo->base.flags = flags;
430+ bo->base.cref = 0;
431+ bo->map_count = 0;
432+ bo->base.virtual = NULL;
433+ if (handle) {
434+ struct drm_gem_open open_arg;
435+
436+ memset(&open_arg, 0, sizeof(open_arg));
437+ open_arg.name = handle;
438+ r = ioctl(bom->fd, DRM_IOCTL_GEM_OPEN, &open_arg);
439+ if (r != 0) {
440+ free(bo);
441+ return NULL;
442+ }
443+ bo->base.handle = open_arg.handle;
444+ bo->base.size = open_arg.size;
445+ bo->name = handle;
446+ } else {
447+ struct drm_glamo_gem_create args;
448+
449+ args.size = size;
450+ args.alignment = alignment;
451+ args.initial_domain = bo->base.domains;
452+ args.no_backing_store = 0;
453+ args.handle = 0;
454+ r = drmCommandWriteRead(bom->fd, DRM_GLAMO_GEM_CREATE,
455+ &args, sizeof(args));
456+ bo->base.handle = args.handle;
457+ if (r) {
458+ fprintf(stderr, "Failed to allocate :\n");
459+ fprintf(stderr, " size : %d bytes\n", size);
460+ fprintf(stderr, " alignment : %d bytes\n", alignment);
461+ free(bo);
462+ return NULL;
463+ }
464+ }
465+ glamo_bo_ref((struct glamo_bo*)bo);
466+ return (struct glamo_bo*)bo;
467+}
468+
469+static void bo_ref(struct glamo_bo *bo)
470+{
471+}
472+
473+static struct glamo_bo *bo_unref(struct glamo_bo *bo)
474+{
475+ struct glamo_bo_gem *bo_gem = (struct glamo_bo_gem*)bo;
476+ struct drm_gem_close args;
477+
478+ if (bo == NULL) {
479+ return NULL;
480+ }
481+ if (bo->cref) {
482+ return bo;
483+ }
484+ if (bo_gem->map_count) {
485+ munmap(bo->virtual, bo->size);
486+ }
487+
488+ /* close object */
489+ args.handle = bo->handle;
490+ ioctl(bo->bom->fd, DRM_IOCTL_GEM_CLOSE, &args);
491+ memset(bo_gem, 0, sizeof(struct glamo_bo_gem));
492+ free(bo_gem);
493+ return NULL;
494+}
495+
496+static int bo_map(struct glamo_bo *bo, int write)
497+{
498+ struct glamo_bo_gem *bo_gem;
499+ struct glamo_bo_manager *bufmgr;
500+ int ret;
501+
502+ bo_gem = (struct glamo_bo_gem *)bo;
503+ bufmgr = (struct glamo_bo_manager*)bo->bom;
504+
505+ /* Get a mapping of the buffer if we haven't before. */
506+ if (bo->virtual == NULL) {
507+
508+ struct drm_glamo_gem_mmap mmap_arg;
509+
510+ memset(&mmap_arg, 0, sizeof(mmap_arg));
511+ mmap_arg.handle = bo->handle;
512+
513+ /* Get the fake offset back... */
514+ ret = ioctl(bufmgr->fd, DRM_IOCTL_GLAMO_GEM_MMAP, &mmap_arg);
515+ if (ret != 0) {
516+ fprintf(stderr,
517+ "%s:%d: Error preparing BO map %d (%d): %s .\n",
518+ __FILE__, __LINE__,
519+ bo->handle, bo_gem->name,
520+ strerror(errno));
521+ return ret;
522+ }
523+ /* and mmap it */
524+ bo->virtual = mmap(0, bo->size, PROT_READ | PROT_WRITE,
525+ MAP_SHARED, bufmgr->fd,
526+ mmap_arg.offset);
527+ if (bo->virtual == MAP_FAILED) {
528+ fprintf(stderr,
529+ "%s:%d: Error mapping buffer %d (%d): %s .\n",
530+ __FILE__, __LINE__,
531+ bo->handle, bo_gem->name,
532+ strerror(errno));
533+ return errno;
534+ }
535+ }
536+ bo_gem->map_count++;
537+
538+ return 0;
539+}
540+
541+static int bo_unmap(struct glamo_bo *bo)
542+{
543+ struct glamo_bo_gem *bo_gem = (struct glamo_bo_gem*)bo;
544+
545+ if ( bo_gem->map_count == 0 ) {
546+ fprintf(stderr, "Not unmapping %p, because its map count"
547+ " is already zero.\n", bo_gem);
548+ return 0;
549+ }
550+
551+ if (--bo_gem->map_count > 0) {
552+ return 0;
553+ }
554+ munmap(bo->virtual, bo->size);
555+ bo->virtual = NULL;
556+ return 0;
557+}
558+
559+static int bo_wait(struct glamo_bo *bo)
560+{
561+ struct drm_glamo_gem_wait_rendering args;
562+ int ret;
563+
564+ args.handle = bo->handle;
565+ args.have_handle = 1;
566+ do {
567+ ret = drmCommandWriteRead(bo->bom->fd,
568+ DRM_GLAMO_GEM_WAIT_RENDERING,
569+ &args, sizeof(args));
570+ } while (ret == -EAGAIN);
571+ return ret;
572+}
573+
574+static struct glamo_bo_funcs bo_gem_funcs = {
575+ bo_open,
576+ bo_ref,
577+ bo_unref,
578+ bo_map,
579+ bo_unmap,
580+ bo_wait
581+};
582+
583+struct glamo_bo_manager *glamo_bo_manager_gem_ctor(int fd)
584+{
585+ struct bo_manager_gem *bomg;
586+
587+ bomg = (struct bo_manager_gem*)calloc(1, sizeof(struct bo_manager_gem));
588+ if (bomg == NULL) return NULL;
589+
590+ bomg->base.funcs = &bo_gem_funcs;
591+ bomg->base.fd = fd;
592+ return (struct glamo_bo_manager*)bomg;
593+}
594+
595+void glamo_bo_manager_gem_dtor(struct glamo_bo_manager *bom)
596+{
597+ struct bo_manager_gem *bomg = (struct bo_manager_gem*)bom;
598+
599+ if (bom == NULL) return;
600+ free(bomg);
601+}
602+
603+uint32_t glamo_gem_get_name(struct glamo_bo *bo)
604+{
605+ struct glamo_bo_gem *bo_gem = (struct glamo_bo_gem*)bo;
606+ return bo_gem->name;
607+}
608+
609+int glamo_gem_name_buffer(struct glamo_bo *bo, uint32_t *name)
610+{
611+ struct drm_gem_flink flink;
612+ int r;
613+
614+ if ( !bo ) {
615+ fprintf(stderr, "No buffer object!\n");
616+ return -1;
617+ }
618+
619+ flink.handle = bo->handle;
620+ r = ioctl(bo->bom->fd, DRM_IOCTL_GEM_FLINK, &flink);
621+ if (r) return r;
622+
623+ *name = flink.name;
624+ return 0;
625+}
626+
627+int glamo_bo_subdata(struct glamo_bo *bo, unsigned long offset,
628+ unsigned long size, const void *data)
629+{
630+ int ret;
631+
632+ if (size == 0 || data == NULL)
633+ return 0;
634+
635+ ret = bo_map(bo, 1);
636+ if ( ret ) return ret;
637+
638+ memcpy((unsigned char *)bo->virtual + offset, data, size);
639+
640+ bo_unmap(bo);
641+
642+ return 0;
643+}
644diff --git a/glamo/glamo_bo_gem.h b/glamo/glamo_bo_gem.h
645new file mode 100644
646index 0000000..05b5fb9
647--- /dev/null
648+++ b/glamo/glamo_bo_gem.h
649@@ -0,0 +1,43 @@
650+/*
651+ * Copyright © 2008 Dave Airlie
652+ * Copyright © 2008 Jérôme Glisse
653+ * All Rights Reserved.
654+ *
655+ * Permission is hereby granted, free of charge, to any person obtaining
656+ * a copy of this software and associated documentation files (the
657+ * "Software"), to deal in the Software without restriction, including
658+ * without limitation the rights to use, copy, modify, merge, publish,
659+ * distribute, sub license, and/or sell copies of the Software, and to
660+ * permit persons to whom the Software is furnished to do so, subject to
661+ * the following conditions:
662+ *
663+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
664+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
665+ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
666+ * NON-INFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDERS, AUTHORS
667+ * AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
668+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
669+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
670+ * USE OR OTHER DEALINGS IN THE SOFTWARE.
671+ *
672+ * The above copyright notice and this permission notice (including the
673+ * next paragraph) shall be included in all copies or substantial portions
674+ * of the Software.
675+ */
676+/*
677+ * Authors:
678+ * Dave Airlie
679+ * Jérôme Glisse <glisse@freedesktop.org>
680+ */
681+#ifndef GLAMO_BO_GEM_H
682+#define GLAMO_BO_GEM_H
683+
684+#include "glamo_bo.h"
685+
686+struct glamo_bo_manager *glamo_bo_manager_gem_ctor(int fd);
687+void glamo_bo_manager_gem_dtor(struct glamo_bo_manager *bom);
688+int glamo_gem_name_buffer(struct glamo_bo *bo, uint32_t *name);
689+uint32_t glamo_gem_get_name(struct glamo_bo *bo);
690+extern int glamo_bo_subdata(struct glamo_bo *bo, unsigned long offset,
691+ unsigned long size, const void *data);
692+#endif
693diff --git a/glamo/glamo_track.c b/glamo/glamo_track.c
694new file mode 100644
695index 0000000..27ffe41
696--- /dev/null
697+++ b/glamo/glamo_track.c
698@@ -0,0 +1,140 @@
699+/*
700+ * Copyright © 2008 Jérôme Glisse
701+ * All Rights Reserved.
702+ *
703+ * Permission is hereby granted, free of charge, to any person obtaining
704+ * a copy of this software and associated documentation files (the
705+ * "Software"), to deal in the Software without restriction, including
706+ * without limitation the rights to use, copy, modify, merge, publish,
707+ * distribute, sub license, and/or sell copies of the Software, and to
708+ * permit persons to whom the Software is furnished to do so, subject to
709+ * the following conditions:
710+ *
711+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
712+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
713+ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
714+ * NON-INFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDERS, AUTHORS
715+ * AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
716+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
717+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
718+ * USE OR OTHER DEALINGS IN THE SOFTWARE.
719+ *
720+ * The above copyright notice and this permission notice (including the
721+ * next paragraph) shall be included in all copies or substantial portions
722+ * of the Software.
723+ */
724+/*
725+ * Authors:
726+ * Jérôme Glisse <glisse@freedesktop.org>
727+ */
728+#include <stdio.h>
729+#include <stdlib.h>
730+#include <string.h>
731+#include "glamo_track.h"
732+
733+void glamo_track_add_event(struct glamo_track *track,
734+ const char *file,
735+ const char *func,
736+ const char *op,
737+ unsigned line)
738+{
739+ struct glamo_track_event *event;
740+
741+ if (track == NULL) {
742+ return;
743+ }
744+ event = (void*)calloc(1,sizeof(struct glamo_track_event));
745+ if (event == NULL) {
746+ return;
747+ }
748+ event->line = line;
749+ event->file = strdup(file);
750+ event->func = strdup(func);
751+ event->op = strdup(op);
752+ if (event->file == NULL || event->func == NULL || event->op == NULL) {
753+ free(event->file);
754+ free(event->func);
755+ free(event->op);
756+ free(event);
757+ return;
758+ }
759+ event->next = track->events;
760+ track->events = event;
761+}
762+
763+struct glamo_track *glamo_tracker_add_track(struct glamo_tracker *tracker,
764+ unsigned key)
765+{
766+ struct glamo_track *track;
767+
768+ track = (struct glamo_track*)calloc(1, sizeof(struct glamo_track));
769+ if (track) {
770+ track->next = tracker->tracks.next;
771+ track->prev = &tracker->tracks;
772+ tracker->tracks.next = track;
773+ if (track->next) {
774+ track->next->prev = track;
775+ }
776+ track->key = key;
777+ track->events = NULL;
778+ }
779+ return track;
780+}
781+
782+void glamo_tracker_remove_track(struct glamo_tracker *tracker,
783+ struct glamo_track *track)
784+{
785+ struct glamo_track_event *event;
786+ void *tmp;
787+
788+ if (track == NULL) {
789+ return;
790+ }
791+ track->prev->next = track->next;
792+ if (track->next) {
793+ track->next->prev = track->prev;
794+ }
795+ track->next = track->prev = NULL;
796+ event = track->events;
797+ while (event) {
798+ tmp = event;
799+ free(event->file);
800+ free(event->func);
801+ free(event->op);
802+ event = event->next;
803+ free(tmp);
804+ }
805+ track->events = NULL;
806+ free(track);
807+}
808+
809+void glamo_tracker_print(struct glamo_tracker *tracker, FILE *file)
810+{
811+ struct glamo_track *track;
812+ struct glamo_track_event *event;
813+ void *tmp;
814+
815+ track = tracker->tracks.next;
816+ while (track) {
817+ event = track->events;
818+ fprintf(file, "[0x%08X] :\n", track->key);
819+ while (event) {
820+ tmp = event;
821+ fprintf(file, " [0x%08X:%s](%s:%s:%d)\n",
822+ track->key, event->op, event->file,
823+ event->func, event->line);
824+ free(event->file);
825+ free(event->func);
826+ free(event->op);
827+ event->file = NULL;
828+ event->func = NULL;
829+ event->op = NULL;
830+ event = event->next;
831+ free(tmp);
832+ }
833+ track->events = NULL;
834+ tmp = track;
835+ track = track->next;
836+ free(tmp);
837+ }
838+}
839diff --git a/glamo/glamo_track.h b/glamo/glamo_track.h
840new file mode 100644
841index 0000000..fedead7
842--- /dev/null
843+++ b/glamo/glamo_track.h
844@@ -0,0 +1,64 @@
845+/*
846+ * Copyright © 2008 Jérôme Glisse
847+ * All Rights Reserved.
848+ *
849+ * Permission is hereby granted, free of charge, to any person obtaining
850+ * a copy of this software and associated documentation files (the
851+ * "Software"), to deal in the Software without restriction, including
852+ * without limitation the rights to use, copy, modify, merge, publish,
853+ * distribute, sub license, and/or sell copies of the Software, and to
854+ * permit persons to whom the Software is furnished to do so, subject to
855+ * the following conditions:
856+ *
857+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
858+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
859+ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
860+ * NON-INFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDERS, AUTHORS
861+ * AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
862+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
863+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
864+ * USE OR OTHER DEALINGS IN THE SOFTWARE.
865+ *
866+ * The above copyright notice and this permission notice (including the
867+ * next paragraph) shall be included in all copies or substantial portions
868+ * of the Software.
869+ */
870+/*
871+ * Authors:
872+ * Jérôme Glisse <glisse@freedesktop.org>
873+ */
874+#ifndef GLAMO_TRACK_H
875+#define GLAMO_TRACK_H
876+
877+struct glamo_track_event {
878+ struct glamo_track_event *next;
879+ char *file;
880+ char *func;
881+ char *op;
882+ unsigned line;
883+};
884+
885+struct glamo_track {
886+ struct glamo_track *next;
887+ struct glamo_track *prev;
888+ unsigned key;
889+ struct glamo_track_event *events;
890+};
891+
892+struct glamo_tracker {
893+ struct glamo_track tracks;
894+};
895+
896+void glamo_track_add_event(struct glamo_track *track,
897+ const char *file,
898+ const char *func,
899+ const char *op,
900+ unsigned line);
901+struct glamo_track *glamo_tracker_add_track(struct glamo_tracker *tracker,
902+ unsigned key);
903+void glamo_tracker_remove_track(struct glamo_tracker *tracker,
904+ struct glamo_track *track);
905+void glamo_tracker_print(struct glamo_tracker *tracker,
906+ FILE *file);
907+
908+#endif
909diff --git a/glamo/libdrm_glamo.pc.in b/glamo/libdrm_glamo.pc.in
910new file mode 100644
911index 0000000..d4d8e70
912--- /dev/null
913+++ b/glamo/libdrm_glamo.pc.in
914@@ -0,0 +1,10 @@
915+prefix=@prefix@
916+exec_prefix=@exec_prefix@
917+libdir=@libdir@
918+includedir=@includedir@
919+
920+Name: libdrm_glamo
921+Description: Userspace interface to kernel DRM services for Glamo
922+Version: 1.0.1
923+Libs: -L${libdir} -ldrm_glamo
924+Cflags: -I${includedir} -I${includedir}/libdrm
925diff --git a/include/drm/Makefile.am b/include/drm/Makefile.am
926index 43695bd..f3f7edf 100644
927--- a/include/drm/Makefile.am
928+++ b/include/drm/Makefile.am
929@@ -35,6 +35,7 @@ klibdrminclude_HEADERS = \
930 savage_drm.h \
931 sis_drm.h \
932 via_drm.h \
933+ glamo_drm.h \
934 mach64_drm.h
935
936
937diff --git a/include/drm/glamo_drm.h b/include/drm/glamo_drm.h
938new file mode 100644
939index 0000000..7629ebc
940--- /dev/null
941+++ b/include/drm/glamo_drm.h
942@@ -0,0 +1,153 @@
943+/* glamo_drm.h -- Public header for the Glamo driver
944+ *
945+ * Copyright 2009 Thomas White
946+ * Copyright 2000 Precision Insight, Inc., Cedar Park, Texas.
947+ * Copyright 2000 VA Linux Systems, Inc., Fremont, California.
948+ * Copyright 2002 Tungsten Graphics, Inc., Cedar Park, Texas.
949+ * All rights reserved.
950+ *
951+ * Permission is hereby granted, free of charge, to any person obtaining a
952+ * copy of this software and associated documentation files (the "Software"),
953+ * to deal in the Software without restriction, including without limitation
954+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
955+ * and/or sell copies of the Software, and to permit persons to whom the
956+ * Software is furnished to do so, subject to the following conditions:
957+ *
958+ * The above copyright notice and this permission notice (including the next
959+ * paragraph) shall be included in all copies or substantial portions of the
960+ * Software.
961+ *
962+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
963+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
964+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
965+ * PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
966+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
967+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
968+ * DEALINGS IN THE SOFTWARE.
969+ *
970+ * Authors:
971+ * Thomas White <taw@bitwiz.org.uk>
972+ * Kevin E. Martin <martin@valinux.com>
973+ * Gareth Hughes <gareth@valinux.com>
974+ * Keith Whitwell <keith@tungstengraphics.com>
975+ */
976+
977+#ifndef __GLAMO_DRM_H__
978+#define __GLAMO_DRM_H__
979+
980+#include "drm.h"
981+
982+#define GLAMO_GEM_DOMAIN_VRAM (0x1)
983+
984+/* Glamo specific ioctls */
985+#define DRM_GLAMO_CMDBUF 0x01
986+#define DRM_GLAMO_SWAP 0x02
987+#define DRM_GLAMO_CMDBURST 0x03
988+
989+#define DRM_GLAMO_GEM_INFO 0x1c
990+#define DRM_GLAMO_GEM_CREATE 0x1d
991+#define DRM_GLAMO_GEM_MMAP 0x1e
992+#define DRM_GLAMO_GEM_PIN 0x1f
993+#define DRM_GLAMO_GEM_UNPIN 0x20
994+#define DRM_GLAMO_GEM_PREAD 0x21
995+#define DRM_GLAMO_GEM_PWRITE 0x22
996+#define DRM_GLAMO_GEM_WAIT_RENDERING 0x24
997+
998+#define DRM_IOCTL_GLAMO_CMDBUF DRM_IOW(DRM_COMMAND_BASE + DRM_GLAMO_CMDBUF, drm_glamo_cmd_buffer_t)
999+#define DRM_IOCTL_GLAMO_SWAP DRM_IO(DRM_COMMAND_BASE + DRM_GLAMO_SWAP)
1000+#define DRM_IOCTL_GLAMO_CMDBURST DRM_IOW(DRM_COMMAND_BASE + DRM_GLAMO_CMDBURST, drm_glamo_cmd_burst_t)
1001+
1002+#define DRM_IOCTL_GLAMO_GEM_INFO DRM_IOWR(DRM_COMMAND_BASE + DRM_GLAMO_GEM_INFO, struct drm_glamo_gem_info)
1003+#define DRM_IOCTL_GLAMO_GEM_CREATE DRM_IOWR(DRM_COMMAND_BASE + DRM_GLAMO_GEM_CREATE, struct drm_glamo_gem_create)
1004+#define DRM_IOCTL_GLAMO_GEM_MMAP DRM_IOWR(DRM_COMMAND_BASE + DRM_GLAMO_GEM_MMAP, struct drm_glamo_gem_mmap)
1005+#define DRM_IOCTL_GLAMO_GEM_PIN DRM_IOWR(DRM_COMMAND_BASE + DRM_GLAMO_GEM_PIN, struct drm_glamo_gem_pin)
1006+#define DRM_IOCTL_GLAMO_GEM_UNPIN DRM_IOWR(DRM_COMMAND_BASE + DRM_GLAMO_GEM_UNPIN, struct drm_glamo_gem_unpin)
1007+#define DRM_IOCTL_GLAMO_GEM_PREAD DRM_IOWR(DRM_COMMAND_BASE + DRM_GLAMO_GEM_PREAD, struct drm_glamo_gem_pread)
1008+#define DRM_IOCTL_GLAMO_GEM_PWRITE DRM_IOWR(DRM_COMMAND_BASE + DRM_GLAMO_GEM_PWRITE, struct drm_glamo_gem_pwrite)
1009+#define DRM_IOCTL_GLAMO_GEM_WAIT_RENDERING DRM_IOW(DRM_COMMAND_BASE + DRM_GLAMO_GEM_WAIT_RENDERING, struct drm_glamo_gem_wait_rendering)
1010+
1011+
1012+/* Simple command submission - a list of 16-bit address-data pairs */
1013+typedef struct drm_glamo_cmd_buffer {
1014+ unsigned int bufsz; /* Size of buffer, in bytes */
1015+ char *buf; /* Buffer of stuff to go onto the ring buffer */
1016+ unsigned int *obj_pos; /* Offsets (in bytes) at which to put objs */
1017+ uint32_t *objs; /* List of buffer object (handles) to use */
1018+ unsigned int nobjs; /* Number of objects referenced */
1019+ int nbox;
1020+ struct drm_clip_rect *boxes;
1021+} drm_glamo_cmd_buffer_t;
1022+
1023+
1024+/* Burst command submission - base address and data:
1025+ * - Data can be 32-bit (more easily)
1026+ * - Easier for the kernel to validate */
1027+typedef struct drm_glamo_cmd_burst {
1028+ uint16_t base; /* Base address (command) */
1029+ int bufsz; /* Size of data, in bytes */
1030+ uint16_t *data; /* Pointer to data */
1031+ unsigned int *obj_pos; /* Offsets (in bytes) at which to put objs */
1032+ uint32_t *objs; /* List of buffer object (handles) to use */
1033+ unsigned int nobjs; /* Number of objects referenced */
1034+} drm_glamo_cmd_burst_t;
1035+
1036+struct drm_glamo_gem_info {
1037+ uint64_t vram_start;
1038+ uint64_t vram_size;
1039+};
1040+
1041+struct drm_glamo_gem_create {
1042+ uint64_t size;
1043+ uint64_t alignment;
1044+ uint32_t handle;
1045+ uint32_t initial_domain; // to allow VRAM to be created
1046+ uint32_t no_backing_store;
1047+};
1048+
1049+struct drm_glamo_gem_mmap {
1050+ uint32_t handle; /* Handle goes in... */
1051+ uint64_t offset; /* ...offset comes out */
1052+};
1053+
1054+struct drm_glamo_gem_wait_rendering {
1055+ uint32_t handle;
1056+ int have_handle;
1057+};
1058+
1059+struct drm_glamo_gem_pin {
1060+ uint32_t handle;
1061+ uint32_t pin_domain;
1062+ uint64_t alignment;
1063+ uint64_t offset;
1064+};
1065+
1066+struct drm_glamo_gem_unpin {
1067+ uint32_t handle;
1068+ uint32_t pad;
1069+};
1070+
1071+struct drm_glamo_gem_pread {
1072+ /** Handle for the object being read. */
1073+ uint32_t handle;
1074+ uint32_t pad;
1075+ /** Offset into the object to read from */
1076+ uint64_t offset;
1077+ /** Length of data to read */
1078+ uint64_t size;
1079+ /** Pointer to write the data into. */
1080+ uint64_t data_ptr; /* void *, but pointers are not 32/64 compatible */
1081+};
1082+
1083+struct drm_glamo_gem_pwrite {
1084+ /** Handle for the object being written to. */
1085+ uint32_t handle;
1086+ uint32_t pad;
1087+ /** Offset into the object to write to */
1088+ uint64_t offset;
1089+ /** Length of data to write */
1090+ uint64_t size;
1091+ /** Pointer to read the data from. */
1092+ uint64_t data_ptr; /* void *, but pointers are not 32/64 compatible */
1093+};
1094+
1095+#endif