From ef1498d2e2402b2b62a98e3c98eaedc3b57a4fdb Mon Sep 17 00:00:00 2001 From: Martin Jansa Date: Tue, 16 Feb 2010 11:38:35 +0100 Subject: Initial libdrm_glamo bits --- Makefile.am | 6 +- configure.ac | 9 ++ glamo/Makefile.am | 52 +++++++++++ glamo/glamo_bo.h | 179 +++++++++++++++++++++++++++++++++++ glamo/glamo_bo_gem.c | 236 +++++++++++++++++++++++++++++++++++++++++++++++ glamo/glamo_bo_gem.h | 41 ++++++++ glamo/glamo_track.c | 140 ++++++++++++++++++++++++++++ glamo/glamo_track.h | 64 +++++++++++++ glamo/libdrm_glamo.pc.in | 10 ++ include/drm/glamo_drm.h | 138 +++++++++++++++++++++++++++ 10 files changed, 874 insertions(+), 1 deletion(-) create mode 100644 glamo/Makefile.am create mode 100644 glamo/glamo_bo.h create mode 100644 glamo/glamo_bo_gem.c create mode 100644 glamo/glamo_bo_gem.h create mode 100644 glamo/glamo_track.c create mode 100644 glamo/glamo_track.h create mode 100644 glamo/libdrm_glamo.pc.in create mode 100644 include/drm/glamo_drm.h diff --git a/Makefile.am b/Makefile.am index 25d17470..f384228a 100644 --- a/Makefile.am +++ b/Makefile.am @@ -41,7 +41,11 @@ if HAVE_RADEON RADEON_SUBDIR = radeon endif -SUBDIRS = . $(LIBKMS_SUBDIR) $(INTEL_SUBDIR) $(NOUVEAU_SUBDIR) $(RADEON_SUBDIR) tests include +if HAVE_GLAMO +GLAMO_SUBDIR = glamo +endif + +SUBDIRS = . $(LIBKMS_SUBDIR) $(INTEL_SUBDIR) $(NOUVEAU_SUBDIR) $(RADEON_SUBDIR) $(GLAMO_SUBDIR) tests include libdrm_la_LTLIBRARIES = libdrm.la libdrm_ladir = $(libdir) diff --git a/configure.ac b/configure.ac index bc76603c..a9322ed1 100644 --- a/configure.ac +++ b/configure.ac @@ -70,6 +70,11 @@ AC_ARG_ENABLE(nouveau-experimental-api, [NOUVEAU=$enableval], [NOUVEAU=no]) +AC_ARG_ENABLE(glamo-experimental-api, + AS_HELP_STRING([--enable-glamo-experimental-api], + [Enable support for Glamo's KMS API (default: disabled)]), + [GLAMO=$enableval], [GLAMO=no]) + dnl =========================================================================== dnl check compiler flags AC_DEFUN([LIBDRM_CC_TRY_FLAG], [ @@ -166,6 +171,8 @@ if test "x$NOUVEAU" = xyes; then AC_DEFINE(HAVE_NOUVEAU, 1, [Have nouveau (nvidia) support]) fi +AM_CONDITIONAL(HAVE_GLAMO, [test "x$GLAMO" = xyes]) + PKG_CHECK_MODULES(CAIRO, cairo, [HAVE_CAIRO=yes], [HAVE_CAIRO=no]) if test "x$HAVE_CAIRO" = xyes; then AC_DEFINE(HAVE_CAIRO, 1, [Have cairo support]) @@ -259,6 +266,8 @@ AC_OUTPUT([ radeon/libdrm_radeon.pc nouveau/Makefile nouveau/libdrm_nouveau.pc + glamo/Makefile + glamo/libdrm_glamo.pc tests/Makefile tests/modeprint/Makefile tests/modetest/Makefile diff --git a/glamo/Makefile.am b/glamo/Makefile.am new file mode 100644 index 00000000..6373a3ac --- /dev/null +++ b/glamo/Makefile.am @@ -0,0 +1,52 @@ +# Copyright (c) 2009 Thomas Whtie +# Based on libdrm-glamo Copyright © 2008 Jérôme Glisse +# +# Permission is hereby granted, free of charge, to any person obtaining a +# copy of this software and associated documentation files (the "Software"), +# to deal in the Software without restriction, including without limitation +# the rights to use, copy, modify, merge, publish, distribute, sublicense, +# and/or sell copies of the Software, and to permit persons to whom the +# Software is furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice (including the next +# paragraph) shall be included in all copies or substantial portions of the +# Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +# IN THE SOFTWARE. +# +# Authors: +# Jérôme Glisse +# Thomas White + +AM_CFLAGS = \ + $(WARN_CFLAGS) \ + -I$(top_srcdir) \ + -I$(top_srcdir)/glamo \ + $(PTHREADSTUBS_CFLAGS) \ + -I$(top_srcdir)/include/drm + +libdrm_glamo_la_LTLIBRARIES = libdrm_glamo.la +libdrm_glamo_ladir = $(libdir) +libdrm_glamo_la_LDFLAGS = -version-number 1:0:0 -no-undefined +libdrm_glamo_la_LIBADD = ../libdrm.la @PTHREADSTUBS_LIBS@ + +libdrm_glamo_la_SOURCES = \ + glamo_bo_gem.c \ + glamo_track.c + +libdrm_glamoincludedir = ${includedir}/drm +libdrm_glamoinclude_HEADERS = \ + glamo_bo.h \ + glamo_bo_gem.h \ + glamo_track.h + +pkgconfigdir = @pkgconfigdir@ +pkgconfig_DATA = libdrm_glamo.pc + +EXTRA_DIST = libdrm_glamo.pc.in diff --git a/glamo/glamo_bo.h b/glamo/glamo_bo.h new file mode 100644 index 00000000..5c605c35 --- /dev/null +++ b/glamo/glamo_bo.h @@ -0,0 +1,179 @@ +/* + * Copyright © 2008 Jérôme Glisse + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES + * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NON-INFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDERS, AUTHORS + * AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE + * USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + */ +/* + * Authors: + * Jérôme Glisse + */ +#ifndef GLAMO_BO_H +#define GLAMO_BO_H + +#include +#include +#include "glamo_track.h" + +/* bo object */ +#define GLAMO_BO_FLAGS_MACRO_TILE 1 +#define GLAMO_BO_FLAGS_MICRO_TILE 2 + +struct glamo_bo_manager; + +struct glamo_bo { + uint32_t alignment; + uint32_t handle; + uint32_t size; + uint32_t domains; + uint32_t flags; + unsigned cref; +#ifdef GLAMO_BO_TRACK + struct glamo_track *track; +#endif + void *ptr; + struct glamo_bo_manager *bom; + uint32_t space_accounted; +}; + +/* bo functions */ +struct glamo_bo_funcs { + struct glamo_bo *(*bo_open)(struct glamo_bo_manager *bom, + uint32_t handle, + uint32_t size, + uint32_t alignment, + uint32_t domains, + uint32_t flags); + void (*bo_ref)(struct glamo_bo *bo); + struct glamo_bo *(*bo_unref)(struct glamo_bo *bo); + int (*bo_map)(struct glamo_bo *bo, int write); + int (*bo_unmap)(struct glamo_bo *bo); + int (*bo_wait)(struct glamo_bo *bo); +}; + +struct glamo_bo_manager { + struct glamo_bo_funcs *funcs; + int fd; + struct glamo_tracker tracker; +}; + +static inline void _glamo_bo_debug(struct glamo_bo *bo, + const char *op, + const char *file, + const char *func, + int line) +{ + fprintf(stderr, "%s %p 0x%08X 0x%08X 0x%08X [%s %s %d]\n", + op, bo, bo->handle, bo->size, bo->cref, file, func, line); +} + +static inline struct glamo_bo *_glamo_bo_open(struct glamo_bo_manager *bom, + uint32_t handle, + uint32_t size, + uint32_t alignment, + uint32_t domains, + uint32_t flags, + const char *file, + const char *func, + int line) +{ + struct glamo_bo *bo; + + bo = bom->funcs->bo_open(bom, handle, size, alignment, domains, flags); +#ifdef GLAMO_BO_TRACK + if (bo) { + bo->track = glamo_tracker_add_track(&bom->tracker, bo->handle); + glamo_track_add_event(bo->track, file, func, "open", line); + } +#endif + return bo; +} + +static inline void _glamo_bo_ref(struct glamo_bo *bo, + const char *file, + const char *func, + int line) +{ + bo->cref++; +#ifdef GLAMO_BO_TRACK + glamo_track_add_event(bo->track, file, func, "ref", line); +#endif + bo->bom->funcs->bo_ref(bo); +} + +static inline struct glamo_bo *_glamo_bo_unref(struct glamo_bo *bo, + const char *file, + const char *func, + int line) +{ + bo->cref--; +#ifdef GLAMO_BO_TRACK + glamo_track_add_event(bo->track, file, func, "unref", line); + if (bo->cref <= 0) { + glamo_tracker_remove_track(&bo->bom->tracker, bo->track); + bo->track = NULL; + } +#endif + return bo->bom->funcs->bo_unref(bo); +} + +static inline int _glamo_bo_map(struct glamo_bo *bo, + int write, + const char *file, + const char *func, + int line) +{ + return bo->bom->funcs->bo_map(bo, write); +} + +static inline int _glamo_bo_unmap(struct glamo_bo *bo, + const char *file, + const char *func, + int line) +{ + return bo->bom->funcs->bo_unmap(bo); +} + +static inline int _glamo_bo_wait(struct glamo_bo *bo, + const char *file, + const char *func, + int line) +{ + return bo->bom->funcs->bo_wait(bo); +} + +#define glamo_bo_open(bom, h, s, a, d, f)\ + _glamo_bo_open(bom, h, s, a, d, f, __FILE__, __FUNCTION__, __LINE__) +#define glamo_bo_ref(bo)\ + _glamo_bo_ref(bo, __FILE__, __FUNCTION__, __LINE__) +#define glamo_bo_unref(bo)\ + _glamo_bo_unref(bo, __FILE__, __FUNCTION__, __LINE__) +#define glamo_bo_map(bo, w)\ + _glamo_bo_map(bo, w, __FILE__, __FUNCTION__, __LINE__) +#define glamo_bo_unmap(bo)\ + _glamo_bo_unmap(bo, __FILE__, __FUNCTION__, __LINE__) +#define glamo_bo_debug(bo, opcode)\ + _glamo_bo_debug(bo, opcode, __FILE__, __FUNCTION__, __LINE__) +#define glamo_bo_wait(bo) \ + _glamo_bo_wait(bo, __FILE__, __func__, __LINE__) + +#endif diff --git a/glamo/glamo_bo_gem.c b/glamo/glamo_bo_gem.c new file mode 100644 index 00000000..6dc5a148 --- /dev/null +++ b/glamo/glamo_bo_gem.c @@ -0,0 +1,236 @@ +/* + * Copyright © 2009 Thomas White + * Copyright © 2008 Dave Airlie + * Copyright © 2008 Jérôme Glisse + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES + * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NON-INFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDERS, AUTHORS + * AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE + * USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + */ +/* + * Authors: + * Dave Airlie + * Jérôme Glisse + * Thomas White + */ +#include +#include +#include +#include +#include +#include +#include + +#include "xf86drm.h" +#include "drm.h" +#include "glamo_drm.h" +#include "glamo_bo.h" +#include "glamo_bo_gem.h" + +struct glamo_bo_gem { + struct glamo_bo base; + uint32_t name; + int map_count; +}; + +struct bo_manager_gem { + struct glamo_bo_manager base; +}; + +static struct glamo_bo *bo_open(struct glamo_bo_manager *bom, + uint32_t handle, + uint32_t size, + uint32_t alignment, + uint32_t domains, + uint32_t flags) +{ + struct glamo_bo_gem *bo; + int r; + + printf("bo_open, size=%i\n", size);fflush(stdout); + + bo = (struct glamo_bo_gem*)calloc(1, sizeof(struct glamo_bo_gem)); + if (bo == NULL) { + return NULL; + } + + bo->base.bom = bom; + bo->base.handle = 0; + bo->base.size = size; + bo->base.alignment = alignment; + bo->base.domains = domains; + bo->base.flags = flags; + bo->base.ptr = NULL; + bo->map_count = 0; + if (handle) { + struct drm_gem_open open_arg; + + memset(&open_arg, 0, sizeof(open_arg)); + open_arg.name = handle; + r = ioctl(bom->fd, DRM_IOCTL_GEM_OPEN, &open_arg); + if (r != 0) { + free(bo); + return NULL; + } + bo->base.handle = open_arg.handle; + bo->base.size = open_arg.size; + bo->name = handle; + } else { + struct drm_glamo_gem_create args; + + args.size = size; + args.alignment = alignment; + args.initial_domain = bo->base.domains; + args.no_backing_store = 0; + args.handle = 0; + r = drmCommandWriteRead(bom->fd, DRM_GLAMO_GEM_CREATE, + &args, sizeof(args)); + bo->base.handle = args.handle; + if (r) { + fprintf(stderr, "Failed to allocate :\n"); + fprintf(stderr, " size : %d bytes\n", size); + fprintf(stderr, " alignment : %d bytes\n", alignment); + fprintf(stderr, " domains : %d\n", bo->base.domains); + free(bo); + return NULL; + } + } + glamo_bo_ref((struct glamo_bo*)bo); + return (struct glamo_bo*)bo; +} + +static void bo_ref(struct glamo_bo *bo) +{ +} + +static struct glamo_bo *bo_unref(struct glamo_bo *bo) +{ + struct glamo_bo_gem *bo_gem = (struct glamo_bo_gem*)bo; + struct drm_gem_close args; + + if (bo == NULL) { + return NULL; + } + if (bo->cref) { + return bo; + } + if (bo_gem->map_count) { + munmap(bo->ptr, bo->size); + } + + /* close object */ + args.handle = bo->handle; + ioctl(bo->bom->fd, DRM_IOCTL_GEM_CLOSE, &args); + memset(bo_gem, 0, sizeof(struct glamo_bo_gem)); + free(bo_gem); + return NULL; +} + +static int bo_map(struct glamo_bo *bo, int write) +{ + struct glamo_bo_gem *bo_gem = (struct glamo_bo_gem*)bo; + struct drm_glamo_gem_mmap args; + int r; + + if (bo_gem->map_count++ != 0) { + return 0; + } + bo->ptr = NULL; + args.handle = bo->handle; + args.offset = 0; + args.size = (uint64_t)bo->size; + r = drmCommandWriteRead(bo->bom->fd, + DRM_GLAMO_GEM_MMAP, + &args, + sizeof(args)); + if (!r) { + bo->ptr = (void *)(unsigned long)args.addr_ptr; + } else { + fprintf(stderr, "error mapping %p 0x%08X (error = %d)\n", + bo, bo->handle, r); + } + return r; +} + +static int bo_unmap(struct glamo_bo *bo) +{ + struct glamo_bo_gem *bo_gem = (struct glamo_bo_gem*)bo; + + if (--bo_gem->map_count > 0) { + return 0; + } + munmap(bo->ptr, bo->size); + bo->ptr = NULL; + return 0; +} + +static int bo_wait(struct glamo_bo *bo) +{ + struct drm_glamo_gem_wait_rendering args; + int ret; + + args.handle = bo->handle; + do { + ret = drmCommandWriteRead(bo->bom->fd, DRM_GLAMO_GEM_WAIT_RENDERING, + &args, sizeof(args)); + } while (ret == -EAGAIN); + return ret; +} + +static struct glamo_bo_funcs bo_gem_funcs = { + bo_open, + bo_ref, + bo_unref, + bo_map, + bo_unmap, + bo_wait +}; + +struct glamo_bo_manager *glamo_bo_manager_gem_ctor(int fd) +{ + struct bo_manager_gem *bomg; + + printf("Creating a new glamo_bo_manager\n");fflush(stdout); + + bomg = (struct bo_manager_gem*)calloc(1, sizeof(struct bo_manager_gem)); + if (bomg == NULL) { + return NULL; + } + bomg->base.funcs = &bo_gem_funcs; + bomg->base.fd = fd; + return (struct glamo_bo_manager*)bomg; +} + +void glamo_bo_manager_gem_dtor(struct glamo_bo_manager *bom) +{ + struct bo_manager_gem *bomg = (struct bo_manager_gem*)bom; + + if (bom == NULL) { + return; + } + free(bomg); +} + +uint32_t glamo_gem_name_bo(struct glamo_bo *bo) +{ + struct glamo_bo_gem *bo_gem = (struct glamo_bo_gem*)bo; + return bo_gem->name; +} diff --git a/glamo/glamo_bo_gem.h b/glamo/glamo_bo_gem.h new file mode 100644 index 00000000..7230176e --- /dev/null +++ b/glamo/glamo_bo_gem.h @@ -0,0 +1,41 @@ +/* + * Copyright © 2008 Dave Airlie + * Copyright © 2008 Jérôme Glisse + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES + * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NON-INFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDERS, AUTHORS + * AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE + * USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + */ +/* + * Authors: + * Dave Airlie + * Jérôme Glisse + */ +#ifndef GLAMO_BO_GEM_H +#define GLAMO_BO_GEM_H + +#include "glamo_bo.h" + +struct glamo_bo_manager *glamo_bo_manager_gem_ctor(int fd); +void glamo_bo_manager_gem_dtor(struct glamo_bo_manager *bom); + +uint32_t glamo_gem_name_bo(struct glamo_bo *bo); +#endif diff --git a/glamo/glamo_track.c b/glamo/glamo_track.c new file mode 100644 index 00000000..27ffe416 --- /dev/null +++ b/glamo/glamo_track.c @@ -0,0 +1,140 @@ +/* + * Copyright © 2008 Jérôme Glisse + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES + * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NON-INFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDERS, AUTHORS + * AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE + * USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + */ +/* + * Authors: + * Jérôme Glisse + */ +#include +#include +#include +#include "glamo_track.h" + +void glamo_track_add_event(struct glamo_track *track, + const char *file, + const char *func, + const char *op, + unsigned line) +{ + struct glamo_track_event *event; + + if (track == NULL) { + return; + } + event = (void*)calloc(1,sizeof(struct glamo_track_event)); + if (event == NULL) { + return; + } + event->line = line; + event->file = strdup(file); + event->func = strdup(func); + event->op = strdup(op); + if (event->file == NULL || event->func == NULL || event->op == NULL) { + free(event->file); + free(event->func); + free(event->op); + free(event); + return; + } + event->next = track->events; + track->events = event; +} + +struct glamo_track *glamo_tracker_add_track(struct glamo_tracker *tracker, + unsigned key) +{ + struct glamo_track *track; + + track = (struct glamo_track*)calloc(1, sizeof(struct glamo_track)); + if (track) { + track->next = tracker->tracks.next; + track->prev = &tracker->tracks; + tracker->tracks.next = track; + if (track->next) { + track->next->prev = track; + } + track->key = key; + track->events = NULL; + } + return track; +} + +void glamo_tracker_remove_track(struct glamo_tracker *tracker, + struct glamo_track *track) +{ + struct glamo_track_event *event; + void *tmp; + + if (track == NULL) { + return; + } + track->prev->next = track->next; + if (track->next) { + track->next->prev = track->prev; + } + track->next = track->prev = NULL; + event = track->events; + while (event) { + tmp = event; + free(event->file); + free(event->func); + free(event->op); + event = event->next; + free(tmp); + } + track->events = NULL; + free(track); +} + +void glamo_tracker_print(struct glamo_tracker *tracker, FILE *file) +{ + struct glamo_track *track; + struct glamo_track_event *event; + void *tmp; + + track = tracker->tracks.next; + while (track) { + event = track->events; + fprintf(file, "[0x%08X] :\n", track->key); + while (event) { + tmp = event; + fprintf(file, " [0x%08X:%s](%s:%s:%d)\n", + track->key, event->op, event->file, + event->func, event->line); + free(event->file); + free(event->func); + free(event->op); + event->file = NULL; + event->func = NULL; + event->op = NULL; + event = event->next; + free(tmp); + } + track->events = NULL; + tmp = track; + track = track->next; + free(tmp); + } +} diff --git a/glamo/glamo_track.h b/glamo/glamo_track.h new file mode 100644 index 00000000..fedead76 --- /dev/null +++ b/glamo/glamo_track.h @@ -0,0 +1,64 @@ +/* + * Copyright © 2008 Jérôme Glisse + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES + * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NON-INFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDERS, AUTHORS + * AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE + * USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + */ +/* + * Authors: + * Jérôme Glisse + */ +#ifndef GLAMO_TRACK_H +#define GLAMO_TRACK_H + +struct glamo_track_event { + struct glamo_track_event *next; + char *file; + char *func; + char *op; + unsigned line; +}; + +struct glamo_track { + struct glamo_track *next; + struct glamo_track *prev; + unsigned key; + struct glamo_track_event *events; +}; + +struct glamo_tracker { + struct glamo_track tracks; +}; + +void glamo_track_add_event(struct glamo_track *track, + const char *file, + const char *func, + const char *op, + unsigned line); +struct glamo_track *glamo_tracker_add_track(struct glamo_tracker *tracker, + unsigned key); +void glamo_tracker_remove_track(struct glamo_tracker *tracker, + struct glamo_track *track); +void glamo_tracker_print(struct glamo_tracker *tracker, + FILE *file); + +#endif diff --git a/glamo/libdrm_glamo.pc.in b/glamo/libdrm_glamo.pc.in new file mode 100644 index 00000000..269b7a5d --- /dev/null +++ b/glamo/libdrm_glamo.pc.in @@ -0,0 +1,10 @@ +prefix=@prefix@ +exec_prefix=@exec_prefix@ +libdir=@libdir@ +includedir=@includedir@ + +Name: libdrm_glamo +Description: Userspace interface to kernel DRM services for Glamo +Version: 1.0.1 +Libs: -L${libdir} -ldrm_glamo +Cflags: -I${includedir} -I${includedir}/drm diff --git a/include/drm/glamo_drm.h b/include/drm/glamo_drm.h new file mode 100644 index 00000000..68b65471 --- /dev/null +++ b/include/drm/glamo_drm.h @@ -0,0 +1,138 @@ +/* glamo_drm.h -- Public header for the Glamo driver + * + * Copyright 2009 Thomas White + * Copyright 2000 Precision Insight, Inc., Cedar Park, Texas. + * Copyright 2000 VA Linux Systems, Inc., Fremont, California. + * Copyright 2002 Tungsten Graphics, Inc., Cedar Park, Texas. + * All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + * Authors: + * Thomas White + * Kevin E. Martin + * Gareth Hughes + * Keith Whitwell + */ + +#ifndef __GLAMO_DRM_H__ +#define __GLAMO_DRM_H__ + +#include "drm.h" + +/* Glamo specific ioctls */ +#define DRM_GLAMO_CMDBUF 0x01 +#define DRM_GLAMO_SWAP 0x02 + +#define DRM_GLAMO_GEM_INFO 0x1c +#define DRM_GLAMO_GEM_CREATE 0x1d +#define DRM_GLAMO_GEM_MMAP 0x1e +#define DRM_GLAMO_GEM_PIN 0x1f +#define DRM_GLAMO_GEM_UNPIN 0x20 +#define DRM_GLAMO_GEM_PREAD 0x21 +#define DRM_GLAMO_GEM_PWRITE 0x22 +#define DRM_GLAMO_GEM_WAIT_RENDERING 0x24 + +#define DRM_IOCTL_GLAMO_CMDBUF DRM_IOW( DRM_COMMAND_BASE + DRM_GLAMO_CMDBUF, drm_glamo_cmd_buffer_t) +#define DRM_IOCTL_GLAMO_SWAP DRM_IO( DRM_COMMAND_BASE + DRM_GLAMO_SWAP) + +#define DRM_IOCTL_GLAMO_GEM_INFO DRM_IOWR(DRM_COMMAND_BASE + DRM_GLAMO_GEM_INFO, struct drm_glamo_gem_info) +#define DRM_IOCTL_GLAMO_GEM_CREATE DRM_IOWR(DRM_COMMAND_BASE + DRM_GLAMO_GEM_CREATE, struct drm_glamo_gem_create) +#define DRM_IOCTL_GLAMO_GEM_MMAP DRM_IOWR(DRM_COMMAND_BASE + DRM_GLAMO_GEM_MMAP, struct drm_glamo_gem_mmap) +#define DRM_IOCTL_GLAMO_GEM_PIN DRM_IOWR(DRM_COMMAND_BASE + DRM_GLAMO_GEM_PIN, struct drm_glamo_gem_pin) +#define DRM_IOCTL_GLAMO_GEM_UNPIN DRM_IOWR(DRM_COMMAND_BASE + DRM_GLAMO_GEM_UNPIN, struct drm_glamo_gem_unpin) +#define DRM_IOCTL_GLAMO_GEM_PREAD DRM_IOWR(DRM_COMMAND_BASE + DRM_GLAMO_GEM_PREAD, struct drm_glamo_gem_pread) +#define DRM_IOCTL_GLAMO_GEM_PWRITE DRM_IOWR(DRM_COMMAND_BASE + DRM_GLAMO_GEM_PWRITE, struct drm_glamo_gem_pwrite) +#define DRM_IOCTL_GLAMO_GEM_WAIT_RENDERING DRM_IOW(DRM_COMMAND_BASE + DRM_GLAMO_GEM_WAIT_RENDERING, struct drm_glamo_gem_wait_rendering) + +typedef struct drm_glamo_cmd_buffer { + int bufsz; + char __user *buf; + int nbox; + struct drm_clip_rect __user *boxes; +} drm_glamo_cmd_buffer_t; + +/* return to userspace start/size of gtt and vram apertures */ +struct drm_glamo_gem_info { + uint64_t gart_start; + uint64_t gart_size; + uint64_t vram_start; + uint64_t vram_size; + uint64_t vram_visible; +}; + +struct drm_glamo_gem_create { + uint64_t size; + uint64_t alignment; + uint32_t handle; + uint32_t initial_domain; // to allow VRAM to be created + uint32_t no_backing_store; // for VRAM objects - select whether they need backing store + // pretty much front/back/depth don't need it - other things do +}; + +struct drm_glamo_gem_mmap { + uint32_t handle; + uint32_t pad; + uint64_t offset; + uint64_t size; + uint64_t addr_ptr; +}; + +struct drm_glamo_gem_wait_rendering { + uint32_t handle; +}; + +struct drm_glamo_gem_pin { + uint32_t handle; + uint32_t pin_domain; + uint64_t alignment; + uint64_t offset; +}; + +struct drm_glamo_gem_unpin { + uint32_t handle; + uint32_t pad; +}; + +struct drm_glamo_gem_pread { + /** Handle for the object being read. */ + uint32_t handle; + uint32_t pad; + /** Offset into the object to read from */ + uint64_t offset; + /** Length of data to read */ + uint64_t size; + /** Pointer to write the data into. */ + uint64_t data_ptr; /* void *, but pointers are not 32/64 compatible */ +}; + +struct drm_glamo_gem_pwrite { + /** Handle for the object being written to. */ + uint32_t handle; + uint32_t pad; + /** Offset into the object to write to */ + uint64_t offset; + /** Length of data to write */ + uint64_t size; + /** Pointer to read the data from. */ + uint64_t data_ptr; /* void *, but pointers are not 32/64 compatible */ +}; + +#endif -- cgit v1.2.3