rpms/libdrm/devel libdrm-radeon.patch, 1.3, 1.4 libdrm.spec, 1.57, 1.58 libdrm-radeon-update.patch, 1.1, NONE

Dave Airlie airlied at fedoraproject.org
Thu Feb 5 00:52:57 UTC 2009


Author: airlied

Update of /cvs/pkgs/rpms/libdrm/devel
In directory cvs1.fedora.phx.redhat.com:/tmp/cvs-serv16764

Modified Files:
	libdrm-radeon.patch libdrm.spec 
Removed Files:
	libdrm-radeon-update.patch 
Log Message:
* Thu Feb 05 2009 Dave Airlie <airlied at redhat.com> 2.4.4-3
- update with more libdrm/radeon upstream fixes


libdrm-radeon.patch:

Index: libdrm-radeon.patch
===================================================================
RCS file: /cvs/pkgs/rpms/libdrm/devel/libdrm-radeon.patch,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- libdrm-radeon.patch	22 Dec 2008 02:28:48 -0000	1.3
+++ libdrm-radeon.patch	5 Feb 2009 00:52:26 -0000	1.4
@@ -21,9 +21,193 @@
  
  libdrm_la_LTLIBRARIES = libdrm.la
  libdrm_ladir = $(libdir)
-diff -up /dev/null libdrm-2.4.3/libdrm/radeon/Makefile.am
---- /dev/null	2008-12-18 14:22:13.823022429 +1000
-+++ libdrm-2.4.3/libdrm/radeon/Makefile.am	2008-12-22 12:05:48.000000000 +1000
+diff -up libdrm-2.4.3/shared-core/radeon_drm.h.dave libdrm-2.4.3/shared-core/radeon_drm.h
+--- libdrm-2.4.3/shared-core/radeon_drm.h.dave	2008-12-19 14:33:38.000000000 +1000
++++ libdrm-2.4.3/shared-core/radeon_drm.h	2008-12-22 12:05:48.000000000 +1000
+@@ -453,8 +453,18 @@ typedef struct {
+ 	int pfCurrentPage;	/* which buffer is being displayed? */
+ 	int crtc2_base;		/* CRTC2 frame offset */
+ 	int tiling_enabled;	/* set by drm, read by 2d + 3d clients */
++
++	unsigned int last_fence;
++
++	uint32_t front_handle;
++	uint32_t back_handle;
++	uint32_t depth_handle;
++	uint32_t front_pitch;
++	uint32_t back_pitch;
++	uint32_t depth_pitch;
+ } drm_radeon_sarea_t;
+ 
++
+ /* WARNING: If you change any of these defines, make sure to change the
+  * defines in the Xserver file (xf86drmRadeon.h)
+  *
+@@ -493,6 +503,18 @@ typedef struct {
+ #define DRM_RADEON_SURF_ALLOC 0x1a
+ #define DRM_RADEON_SURF_FREE  0x1b
+ 
++#define DRM_RADEON_GEM_INFO   0x1c
++#define DRM_RADEON_GEM_CREATE 0x1d
++#define DRM_RADEON_GEM_MMAP   0x1e
++#define DRM_RADEON_GEM_PIN    0x1f
++#define DRM_RADEON_GEM_UNPIN  0x20
++#define DRM_RADEON_GEM_PREAD  0x21
++#define DRM_RADEON_GEM_PWRITE 0x22
++#define DRM_RADEON_GEM_SET_DOMAIN 0x23
++#define DRM_RADEON_GEM_WAIT_RENDERING 0x24
++
++#define DRM_RADEON_CS       0x26
++
+ #define DRM_IOCTL_RADEON_CP_INIT    DRM_IOW( DRM_COMMAND_BASE + DRM_RADEON_CP_INIT, drm_radeon_init_t)
+ #define DRM_IOCTL_RADEON_CP_START   DRM_IO(  DRM_COMMAND_BASE + DRM_RADEON_CP_START)
+ #define DRM_IOCTL_RADEON_CP_STOP    DRM_IOW( DRM_COMMAND_BASE + DRM_RADEON_CP_STOP, drm_radeon_cp_stop_t)
+@@ -521,6 +543,17 @@ typedef struct {
+ #define DRM_IOCTL_RADEON_SURF_ALLOC DRM_IOW( DRM_COMMAND_BASE + DRM_RADEON_SURF_ALLOC, drm_radeon_surface_alloc_t)
+ #define DRM_IOCTL_RADEON_SURF_FREE  DRM_IOW( DRM_COMMAND_BASE + DRM_RADEON_SURF_FREE, drm_radeon_surface_free_t)
+ 
++#define DRM_IOCTL_RADEON_GEM_INFO   DRM_IOWR(DRM_COMMAND_BASE + DRM_RADEON_GEM_INFO, struct drm_radeon_gem_info)
++#define DRM_IOCTL_RADEON_GEM_CREATE   DRM_IOWR(DRM_COMMAND_BASE + DRM_RADEON_GEM_CREATE, struct drm_radeon_gem_create)
++#define DRM_IOCTL_RADEON_GEM_MMAP   DRM_IOWR(DRM_COMMAND_BASE + DRM_RADEON_GEM_MMAP, struct drm_radeon_gem_mmap)
++#define DRM_IOCTL_RADEON_GEM_PIN   DRM_IOWR(DRM_COMMAND_BASE + DRM_RADEON_GEM_PIN, struct drm_radeon_gem_pin)
++#define DRM_IOCTL_RADEON_GEM_UNPIN   DRM_IOWR(DRM_COMMAND_BASE + DRM_RADEON_GEM_UNPIN, struct drm_radeon_gem_unpin)
++#define DRM_IOCTL_RADEON_GEM_PREAD   DRM_IOWR(DRM_COMMAND_BASE + DRM_RADEON_GEM_PREAD, struct drm_radeon_gem_pread)
++#define DRM_IOCTL_RADEON_GEM_PWRITE   DRM_IOWR(DRM_COMMAND_BASE + DRM_RADEON_GEM_PWRITE, struct drm_radeon_gem_pwrite)
++#define DRM_IOCTL_RADEON_GEM_SET_DOMAIN  DRM_IOWR(DRM_COMMAND_BASE + DRM_RADEON_GEM_SET_DOMAIN, struct drm_radeon_gem_set_domain)
++#define DRM_IOCTL_RADEON_GEM_WAIT_RENDERING DRM_IOW(DRM_COMMAND_BASE + DRM_RADEON_GEM_WAIT_RENDERING, struct drm_radeon_gem_wait_rendering) 
++#define DRM_IOCTL_RADEON_CS DRM_IOWR(DRM_COMMAND_BASE + DRM_RADEON_CS, struct drm_radeon_cs)
++
+ typedef struct drm_radeon_init {
+ 	enum {
+ 		RADEON_INIT_CP = 0x01,
+@@ -677,6 +710,7 @@ typedef struct drm_radeon_indirect {
+ #define RADEON_PARAM_VBLANK_CRTC           13   /* VBLANK CRTC */
+ #define RADEON_PARAM_FB_LOCATION           14   /* FB location */
+ #define RADEON_PARAM_NUM_GB_PIPES          15   /* num GB pipes */
++#define RADEON_PARAM_KERNEL_MM             16
+ 
+ typedef struct drm_radeon_getparam {
+ 	int param;
+@@ -732,6 +766,7 @@ typedef struct drm_radeon_setparam {
+ #define RADEON_SETPARAM_NEW_MEMMAP 4		/* Use new memory map */
+ #define RADEON_SETPARAM_PCIGART_TABLE_SIZE 5    /* PCI GART Table Size */
+ #define RADEON_SETPARAM_VBLANK_CRTC 6           /* VBLANK CRTC */
++#define RADEON_SETPARAM_MM_INIT 7		/* Initialise the mm */
+ /* 1.14: Clients can allocate/free a surface
+  */
+ typedef struct drm_radeon_surface_alloc {
+@@ -747,4 +782,106 @@ typedef struct drm_radeon_surface_free {
+ #define	DRM_RADEON_VBLANK_CRTC1		1
+ #define	DRM_RADEON_VBLANK_CRTC2		2
+ 
++#define RADEON_GEM_DOMAIN_CPU 0x1   // Cached CPU domain
++#define RADEON_GEM_DOMAIN_GTT 0x2   // GTT or cache flushed
++#define RADEON_GEM_DOMAIN_VRAM 0x4  // VRAM domain
++
++/* return to userspace start/size of gtt and vram apertures */
++struct drm_radeon_gem_info {
++	uint64_t gart_start;
++	uint64_t gart_size;
++	uint64_t vram_start;
++	uint64_t vram_size;
++	uint64_t vram_visible;
++};
++
++struct drm_radeon_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_radeon_gem_mmap {
++	uint32_t handle;
++	uint32_t pad;
++	uint64_t offset;
++	uint64_t size;
++	uint64_t addr_ptr;
++};
++
++struct drm_radeon_gem_set_domain {
++	uint32_t handle;
++	uint32_t read_domains;
++	uint32_t write_domain;
++};
++
++struct drm_radeon_gem_wait_rendering {
++	uint32_t handle;
++};
++
++struct drm_radeon_gem_pin {
++	uint32_t handle;
++	uint32_t pin_domain;
++	uint64_t alignment;
++	uint64_t offset;
++};
++
++struct drm_radeon_gem_unpin {
++	uint32_t handle;
++	uint32_t pad;
++};
++
++struct drm_radeon_gem_busy {
++	uint32_t handle;
++	uint32_t busy;
++};
++
++struct drm_radeon_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_radeon_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 */
++};
++
++
++/* New interface which obsolete all previous interface.
++ */
++
++#define RADEON_CHUNK_ID_RELOCS 0x01
++#define RADEON_CHUNK_ID_IB     0x02
++
++struct drm_radeon_cs_chunk {
++	uint32_t chunk_id;
++	uint32_t length_dw;
++	uint64_t chunk_data;
++};
++
++struct drm_radeon_cs {
++	uint32_t	num_chunks;
++	uint32_t        cs_id;
++	uint64_t	chunks; /* this points to uint64_t * which point to
++				   cs chunks */
++};
++
++
+ #endif
+diff --git a/libdrm/radeon/Makefile.am b/libdrm/radeon/Makefile.am
+new file mode 100644
+index 0000000..32ca559
+--- /dev/null
++++ b/libdrm/radeon/Makefile.am
 @@ -0,0 +1,48 @@
 +# Copyright © 2008 Jérôme Glisse
 +#
@@ -56,27 +240,214 @@
 +	$(PTHREADSTUBS_CFLAGS) \
 +	-I$(top_srcdir)/shared-core
 +
-+libdrm_radeon_la_LTLIBRARIES = libdrm_radeon.la
-+libdrm_radeon_ladir = $(libdir)
-+libdrm_radeon_la_LDFLAGS = -version-number 1:0:0 -no-undefined
-+libdrm_radeon_la_LIBADD = ../libdrm.la @PTHREADSTUBS_LIBS@
++libdrm_radeon_la_LTLIBRARIES = libdrm_radeon.la
++libdrm_radeon_ladir = $(libdir)
++libdrm_radeon_la_LDFLAGS = -version-number 1:0:0 -no-undefined
++libdrm_radeon_la_LIBADD = ../libdrm.la @PTHREADSTUBS_LIBS@
++
++libdrm_radeon_la_SOURCES = \
++	radeon_bo_gem.c \
++	radeon_cs_gem.c \
++	radeon_track.c
++
++libdrm_radeonincludedir = ${includedir}/drm
++libdrm_radeoninclude_HEADERS = \
++	radeon_bo.h \
++	radeon_cs.h \
++	radeon_bo_gem.h \
++	radeon_cs_gem.h \
++	radeon_track.h
+diff --git a/libdrm/radeon/radeon_bo.h b/libdrm/radeon/radeon_bo.h
+new file mode 100644
+index 0000000..3cabdfc
+--- /dev/null
++++ b/libdrm/radeon/radeon_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 <glisse at freedesktop.org>
++ */
++#ifndef RADEON_BO_H
++#define RADEON_BO_H
++
++#include <stdio.h>
++#include <stdint.h>
++#include "radeon_track.h"
++
++/* bo object */
++#define RADEON_BO_FLAGS_MACRO_TILE  1
++#define RADEON_BO_FLAGS_MICRO_TILE  2
++
++struct radeon_bo_manager;
++
++struct radeon_bo {
++    uint32_t                    alignment;
++    uint32_t                    handle;
++    uint32_t                    size;
++    uint32_t                    domains;
++    uint32_t                    flags;
++    unsigned                    cref;
++#ifdef RADEON_BO_TRACK
++    struct radeon_track         *track;
++#endif
++    void                        *ptr;
++    struct radeon_bo_manager    *bom;
++    uint32_t                    space_accounted;
++};
++
++/* bo functions */
++struct radeon_bo_funcs {
++    struct radeon_bo *(*bo_open)(struct radeon_bo_manager *bom,
++                                 uint32_t handle,
++                                 uint32_t size,
++                                 uint32_t alignment,
++                                 uint32_t domains,
++                                 uint32_t flags);
++    void (*bo_ref)(struct radeon_bo *bo);
++    struct radeon_bo *(*bo_unref)(struct radeon_bo *bo);
++    int (*bo_map)(struct radeon_bo *bo, int write);
++    int (*bo_unmap)(struct radeon_bo *bo);
++    int (*bo_wait)(struct radeon_bo *bo);
++};
++
++struct radeon_bo_manager {
++    struct radeon_bo_funcs  *funcs;
++    int                     fd;
++    struct radeon_tracker   tracker;
++};
++    
++static inline void _radeon_bo_debug(struct radeon_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 radeon_bo *_radeon_bo_open(struct radeon_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 radeon_bo *bo;
++
++    bo = bom->funcs->bo_open(bom, handle, size, alignment, domains, flags);
++#ifdef RADEON_BO_TRACK
++    if (bo) {
++        bo->track = radeon_tracker_add_track(&bom->tracker, bo->handle);
++        radeon_track_add_event(bo->track, file, func, "open", line);
++    }
++#endif
++    return bo;
++}
++
++static inline void _radeon_bo_ref(struct radeon_bo *bo,
++                                  const char *file,
++                                  const char *func,
++                                  int line)
++{
++    bo->cref++;
++#ifdef RADEON_BO_TRACK
++    radeon_track_add_event(bo->track, file, func, "ref", line); 
++#endif
++    bo->bom->funcs->bo_ref(bo);
++}
++
++static inline struct radeon_bo *_radeon_bo_unref(struct radeon_bo *bo,
++                                                 const char *file,
++                                                 const char *func,
++                                                 int line)
++{
++    bo->cref--;
++#ifdef RADEON_BO_TRACK
++    radeon_track_add_event(bo->track, file, func, "unref", line);
++    if (bo->cref <= 0) {
++        radeon_tracker_remove_track(&bo->bom->tracker, bo->track);
++        bo->track = NULL;
++    }
++#endif
++    return bo->bom->funcs->bo_unref(bo);
++}
++
++static inline int _radeon_bo_map(struct radeon_bo *bo,
++                                 int write,
++                                 const char *file,
++                                 const char *func,
++                                 int line)
++{
++    return bo->bom->funcs->bo_map(bo, write);
++}
++
++static inline int _radeon_bo_unmap(struct radeon_bo *bo,
++                                   const char *file,
++                                   const char *func,
++                                   int line)
++{
++    return bo->bom->funcs->bo_unmap(bo);
++}
++
++static inline int _radeon_bo_wait(struct radeon_bo *bo,
++                                  const char *file,
++                                  const char *func,
++                                  int line)
++{
++    return bo->bom->funcs->bo_wait(bo);
++}
 +
-+libdrm_radeon_la_SOURCES = \
-+	radeon_bo_gem.c \
-+	radeon_cs_gem.c \
-+	radeon_track.c
++#define radeon_bo_open(bom, h, s, a, d, f)\
++    _radeon_bo_open(bom, h, s, a, d, f, __FILE__, __FUNCTION__, __LINE__)
++#define radeon_bo_ref(bo)\
++    _radeon_bo_ref(bo, __FILE__, __FUNCTION__, __LINE__)
++#define radeon_bo_unref(bo)\
++    _radeon_bo_unref(bo, __FILE__, __FUNCTION__, __LINE__)
++#define radeon_bo_map(bo, w)\
++    _radeon_bo_map(bo, w, __FILE__, __FUNCTION__, __LINE__)
++#define radeon_bo_unmap(bo)\
++    _radeon_bo_unmap(bo, __FILE__, __FUNCTION__, __LINE__)
++#define radeon_bo_debug(bo, opcode)\
++    _radeon_bo_debug(bo, opcode, __FILE__, __FUNCTION__, __LINE__)
++#define radeon_bo_wait(bo) \
++    _radeon_bo_wait(bo, __FILE__, __func__, __LINE__)
 +
-+libdrm_radeonincludedir = ${includedir}/drm
-+libdrm_radeoninclude_HEADERS = \
-+	radeon_bo.h \
-+	radeon_cs.h \
-+	radeon_bo_gem.h \
-+	radeon_cs_gem.h \
-+	radeon_track.h
-diff -up /dev/null libdrm-2.4.3/libdrm/radeon/radeon_bo_gem.c
---- /dev/null	2008-12-18 14:22:13.823022429 +1000
-+++ libdrm-2.4.3/libdrm/radeon/radeon_bo_gem.c	2008-12-22 12:05:48.000000000 +1000
-@@ -0,0 +1,208 @@
++#endif
+diff --git a/libdrm/radeon/radeon_bo_gem.c b/libdrm/radeon/radeon_bo_gem.c
+new file mode 100644
+index 0000000..932afeb
+--- /dev/null
++++ b/libdrm/radeon/radeon_bo_gem.c
+@@ -0,0 +1,223 @@
 +/* 
 + * Copyright © 2008 Dave Airlie
 + * Copyright © 2008 Jérôme Glisse
@@ -114,6 +485,7 @@
 +#include <string.h>
 +#include <sys/mman.h>
 +#include <sys/ioctl.h>
++#include <errno.h>
 +#include "xf86drm.h"
 +#include "drm.h"
 +#include "radeon_drm.h"
@@ -255,12 +627,26 @@
 +    return 0;
 +}
 +
++static int bo_wait(struct radeon_bo *bo)
++{
++    struct drm_radeon_gem_wait_rendering args;
++    int ret;
++
++    args.handle = bo->handle;
++    do {
++        ret = drmCommandWriteRead(bo->bom->fd, DRM_RADEON_GEM_WAIT_RENDERING,
++                                  &args, sizeof(args));
++    } while (ret == -EAGAIN);
++    return ret;
++}
++
 +static struct radeon_bo_funcs bo_gem_funcs = {
 +    bo_open,
 +    bo_ref,
 +    bo_unref,
 +    bo_map,
-+    bo_unmap
++    bo_unmap,
++    bo_wait
 +};
 +
 +struct radeon_bo_manager *radeon_bo_manager_gem_ctor(int fd)
@@ -285,9 +671,11 @@
 +    }
 +    free(bomg);
 +}
-diff -up /dev/null libdrm-2.4.3/libdrm/radeon/radeon_bo_gem.h
---- /dev/null	2008-12-18 14:22:13.823022429 +1000
-+++ libdrm-2.4.3/libdrm/radeon/radeon_bo_gem.h	2008-12-22 12:05:48.000000000 +1000
+diff --git a/libdrm/radeon/radeon_bo_gem.h b/libdrm/radeon/radeon_bo_gem.h
+new file mode 100644
+index 0000000..c0f68e6
+--- /dev/null
++++ b/libdrm/radeon/radeon_bo_gem.h
 @@ -0,0 +1,40 @@
 +/* 
 + * Copyright © 2008 Dave Airlie
@@ -329,29 +717,31 @@
 +void radeon_bo_manager_gem_dtor(struct radeon_bo_manager *bom);
 +
 +#endif
-diff -up /dev/null libdrm-2.4.3/libdrm/radeon/radeon_bo.h
---- /dev/null	2008-12-18 14:22:13.823022429 +1000
-+++ libdrm-2.4.3/libdrm/radeon/radeon_bo.h	2008-12-22 12:05:48.000000000 +1000
-@@ -0,0 +1,167 @@
+diff --git a/libdrm/radeon/radeon_cs.h b/libdrm/radeon/radeon_cs.h
+new file mode 100644
+index 0000000..7cc75d4
+--- /dev/null
++++ b/libdrm/radeon/radeon_cs.h
+@@ -0,0 +1,198 @@
 +/* 
++ * Copyright © 2008 Nicolai Haehnle
 + * 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
++ * 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 
++ * 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
@@ -360,150 +750,183 @@
 + */
 +/*
 + * Authors:
++ *      Aapo Tahkola <aet at rasterburn.org>
++ *      Nicolai Haehnle <prefect_ at gmx.net>
 + *      Jérôme Glisse <glisse at freedesktop.org>
 + */
-+#ifndef RADEON_BO_H
-+#define RADEON_BO_H
++#ifndef RADEON_CS_H
++#define RADEON_CS_H
 +
-+#include <stdio.h>
 +#include <stdint.h>
-+#include "radeon_track.h"
++#include "drm.h"
++#include "radeon_drm.h"
++#include "radeon_bo.h"
 +
-+/* bo object */
-+#define RADEON_BO_FLAGS_MACRO_TILE  1
-+#define RADEON_BO_FLAGS_MICRO_TILE  2
++struct radeon_cs_reloc {
++    struct radeon_bo    *bo;
++    uint32_t            read_domain;
++    uint32_t            write_domain;
++    uint32_t            flags;
++};
 +
-+struct radeon_bo_manager;
 +
-+struct radeon_bo {
-+    uint32_t                    alignment;
-+    uint32_t                    handle;
-+    uint32_t                    size;
-+    uint32_t                    domains;
-+    uint32_t                    flags;
-+    unsigned                    cref;
-+#ifdef RADEON_BO_TRACK
-+    struct radeon_track         *track;
-+#endif
-+    void                        *ptr;
-+    struct radeon_bo_manager    *bom;
++#define RADEON_CS_SPACE_OK 0
++#define RADEON_CS_SPACE_OP_TO_BIG 1
++#define RADEON_CS_SPACE_FLUSH 2
++
++struct radeon_cs_space_check {
++    struct radeon_bo *bo;
++    uint32_t read_domains;
++    uint32_t write_domain;
++    uint32_t new_accounted;
 +};
 +
-+/* bo functions */
-+struct radeon_bo_funcs {
-+    struct radeon_bo *(*bo_open)(struct radeon_bo_manager *bom,
-+                                 uint32_t handle,
-+                                 uint32_t size,
-+                                 uint32_t alignment,
-+                                 uint32_t domains,
-+                                 uint32_t flags);
-+    void (*bo_ref)(struct radeon_bo *bo);
-+    struct radeon_bo *(*bo_unref)(struct radeon_bo *bo);
-+    int (*bo_map)(struct radeon_bo *bo, int write);
-+    int (*bo_unmap)(struct radeon_bo *bo);
++struct radeon_cs_manager;
++
++struct radeon_cs {
++    struct radeon_cs_manager    *csm;
++    void                        *relocs;
++    uint32_t                    *packets;
++    unsigned                    crelocs;
++    unsigned                    relocs_total_size;
++    unsigned                    cdw;
++    unsigned                    ndw;
++    int                         section;
++    unsigned                    section_ndw;
++    unsigned                    section_cdw;
++    const char                  *section_file;
++    const char                  *section_func;
++    int                         section_line;
++
 +};
 +
-+struct radeon_bo_manager {
-+    struct radeon_bo_funcs  *funcs;
++/* cs functions */
++struct radeon_cs_funcs {
++    struct radeon_cs *(*cs_create)(struct radeon_cs_manager *csm,
++                                   uint32_t ndw);
++    int (*cs_write_reloc)(struct radeon_cs *cs,
++                          struct radeon_bo *bo,
++                          uint32_t read_domain,
++                          uint32_t write_domain,
++                          uint32_t flags);
++    int (*cs_begin)(struct radeon_cs *cs,
++                    uint32_t ndw,
++                    const char *file,
++                    const char *func,
++                    int line);
++    int (*cs_end)(struct radeon_cs *cs,
++                  const char *file,
++                  const char *func,
++                  int line);
++    int (*cs_emit)(struct radeon_cs *cs);
++    int (*cs_destroy)(struct radeon_cs *cs);
++    int (*cs_erase)(struct radeon_cs *cs);
++    int (*cs_need_flush)(struct radeon_cs *cs);
++    void (*cs_print)(struct radeon_cs *cs, FILE *file);
++    int (*cs_space_check)(struct radeon_cs *cs, struct radeon_cs_space_check *bos,
++			  int num_bo);
++};
++
++struct radeon_cs_manager {
++    struct radeon_cs_funcs  *funcs;
 +    int                     fd;
-+    struct radeon_tracker   tracker;
++    uint32_t vram_limit, gart_limit;
++    uint32_t vram_write_used, gart_write_used;
++    uint32_t read_used;
 +};
-+    
-+static inline void _radeon_bo_debug(struct radeon_bo *bo,
-+                                    const char *op,
-+                                    const char *file,
-+                                    const char *func,
-+                                    int line)
++
++static inline struct radeon_cs *radeon_cs_create(struct radeon_cs_manager *csm,
++                                                 uint32_t ndw)
 +{
-+    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);
++    return csm->funcs->cs_create(csm, ndw);
 +}
 +
-+static inline struct radeon_bo *_radeon_bo_open(struct radeon_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)
++static inline int radeon_cs_write_reloc(struct radeon_cs *cs,
++                                        struct radeon_bo *bo,
++                                        uint32_t read_domain,
++                                        uint32_t write_domain,
++                                        uint32_t flags)
 +{
-+    struct radeon_bo *bo;
-+
-+    bo = bom->funcs->bo_open(bom, handle, size, alignment, domains, flags);
-+#ifdef RADEON_BO_TRACK
-+    if (bo) {
-+        bo->track = radeon_tracker_add_track(&bom->tracker, bo->handle);
-+        radeon_track_add_event(bo->track, file, func, "open", line);
-+    }
-+#endif
-+    return bo;
++    return cs->csm->funcs->cs_write_reloc(cs,
++                                          bo,
++                                          read_domain,
++                                          write_domain,
++                                          flags);
 +}
 +
-+static inline void _radeon_bo_ref(struct radeon_bo *bo,
++static inline int radeon_cs_begin(struct radeon_cs *cs,
++                                  uint32_t ndw,
 +                                  const char *file,
 +                                  const char *func,
 +                                  int line)
 +{
-+    bo->cref++;
-+#ifdef RADEON_BO_TRACK
-+    radeon_track_add_event(bo->track, file, func, "ref", line); 
-+#endif
-+    bo->bom->funcs->bo_ref(bo);
++    return cs->csm->funcs->cs_begin(cs, ndw, file, func, line);
 +}
 +
-+static inline struct radeon_bo *_radeon_bo_unref(struct radeon_bo *bo,
-+                                                 const char *file,
-+                                                 const char *func,
-+                                                 int line)
++static inline int radeon_cs_end(struct radeon_cs *cs,
++                                const char *file,
++                                const char *func,
++                                int line)
 +{
-+    bo->cref--;
-+#ifdef RADEON_BO_TRACK
-+    radeon_track_add_event(bo->track, file, func, "unref", line);
-+    if (bo->cref <= 0) {
-+        radeon_tracker_remove_track(&bo->bom->tracker, bo->track);
-+        bo->track = NULL;
-+    }
-+#endif
-+    return bo->bom->funcs->bo_unref(bo);
++    return cs->csm->funcs->cs_end(cs, file, func, line);
 +}
 +
-+static inline int _radeon_bo_map(struct radeon_bo *bo,
-+                                 int write,
-+                                 const char *file,
-+                                 const char *func,
-+                                 int line)
++static inline int radeon_cs_emit(struct radeon_cs *cs)
 +{
-+    return bo->bom->funcs->bo_map(bo, write);
++    return cs->csm->funcs->cs_emit(cs);
++}
++
++static inline int radeon_cs_destroy(struct radeon_cs *cs)
++{
++    return cs->csm->funcs->cs_destroy(cs);
++}
++
++static inline int radeon_cs_erase(struct radeon_cs *cs)
++{
++    return cs->csm->funcs->cs_erase(cs);
++}
++
++static inline int radeon_cs_need_flush(struct radeon_cs *cs)
++{
++    return cs->csm->funcs->cs_need_flush(cs);
++}
++
++static inline void radeon_cs_print(struct radeon_cs *cs, FILE *file)
++{
++    cs->csm->funcs->cs_print(cs, file);
++}
++
++static inline int radeon_cs_space_check(struct radeon_cs *cs,
++					    struct radeon_cs_space_check *bos,
++					    int num_bo)
++{
++    return cs->csm->funcs->cs_space_check(cs, bos, num_bo);
 +}
 +
-+static inline int _radeon_bo_unmap(struct radeon_bo *bo,
-+                                   const char *file,
-+                                   const char *func,
-+                                   int line)
++static inline void radeon_cs_set_limit(struct radeon_cs *cs, uint32_t domain, uint32_t limit)
 +{
-+    return bo->bom->funcs->bo_unmap(bo);
++    
++    if (domain == RADEON_GEM_DOMAIN_VRAM)
++	cs->csm->vram_limit = limit;
++    else
++	cs->csm->gart_limit = limit;
 +}
 +
-+#define radeon_bo_open(bom, h, s, a, d, f)\
-+    _radeon_bo_open(bom, h, s, a, d, f, __FILE__, __FUNCTION__, __LINE__)
-+#define radeon_bo_ref(bo)\
-+    _radeon_bo_ref(bo, __FILE__, __FUNCTION__, __LINE__)
-+#define radeon_bo_unref(bo)\
-+    _radeon_bo_unref(bo, __FILE__, __FUNCTION__, __LINE__)
-+#define radeon_bo_map(bo, w)\
-+    _radeon_bo_map(bo, w, __FILE__, __FUNCTION__, __LINE__)
-+#define radeon_bo_unmap(bo)\
-+    _radeon_bo_unmap(bo, __FILE__, __FUNCTION__, __LINE__)
-+#define radeon_bo_debug(bo, opcode)\
-+    _radeon_bo_debug(bo, opcode, __FILE__, __FUNCTION__, __LINE__)
++static inline void radeon_cs_write_dword(struct radeon_cs *cs, uint32_t dword)
++{
++    cs->packets[cs->cdw++] = dword;
++    if (cs->section) {
++        cs->section_cdw++;
++    }
++}
 +
 +#endif
-diff -up /dev/null libdrm-2.4.3/libdrm/radeon/radeon_cs_gem.c
---- /dev/null	2008-12-18 14:22:13.823022429 +1000
-+++ libdrm-2.4.3/libdrm/radeon/radeon_cs_gem.c	2008-12-22 12:05:48.000000000 +1000
-@@ -0,0 +1,420 @@
+diff --git a/libdrm/radeon/radeon_cs_gem.c b/libdrm/radeon/radeon_cs_gem.c
+new file mode 100644
+index 0000000..dc14a8a
+--- /dev/null
++++ b/libdrm/radeon/radeon_cs_gem.c
+@@ -0,0 +1,537 @@
 +/* 
 + * Copyright © 2008 Jérôme Glisse
 + * All Rights Reserved.
@@ -612,25 +1035,6 @@
 +    return (struct radeon_cs*)csg;
 +}
 +
-+static int cs_gem_write_dword(struct radeon_cs *cs, uint32_t dword)
-+{
-+    struct cs_gem *csg = (struct cs_gem*)cs;
-+    if (cs->cdw >= cs->ndw) {
-+        uint32_t tmp, *ptr;
-+        tmp = (cs->cdw + 1 + 0x3FF) & (~0x3FF);
-+        ptr = (uint32_t*)realloc(cs->packets, 4 * tmp);
-+        if (ptr == NULL) {
-+            return -ENOMEM;
-+        }
-+        cs->packets = ptr;
-+        cs->ndw = tmp;
-+        csg->chunks[0].chunk_data = (uint64_t)(intptr_t)csg->base.packets;
-+    }
-+    cs->packets[cs->cdw++] = dword;
-+    csg->chunks[0].length_dw += 1;
-+    return 0;
-+}
-+
 +static int cs_gem_write_reloc(struct radeon_cs *cs,
 +                              struct radeon_bo *bo,
 +                              uint32_t read_domain,
@@ -677,8 +1081,8 @@
 +            /* update flags */
 +            reloc->flags |= (flags & reloc->flags);
 +            /* write relocation packet */
-+            cs_gem_write_dword(cs, 0xc0001000);
-+            cs_gem_write_dword(cs, idx);
++            radeon_cs_write_dword(cs, 0xc0001000);
++            radeon_cs_write_dword(cs, idx);
 +            return 0;
 +        }
 +    }
@@ -711,8 +1115,8 @@
 +    csg->chunks[1].length_dw += RELOC_SIZE;
 +    radeon_bo_ref(bo);
 +    cs->relocs_total_size += bo->size;
-+    cs_gem_write_dword(cs, 0xc0001000);
-+    cs_gem_write_dword(cs, idx);
++    radeon_cs_write_dword(cs, 0xc0001000);
++    radeon_cs_write_dword(cs, idx);
 +    return 0;
 +}
 +
@@ -722,6 +1126,35 @@
 +                        const char *func,
 +                        int line)
 +{
++
++    if (cs->section) {
++        fprintf(stderr, "CS already in a section(%s,%s,%d)\n",
++                cs->section_file, cs->section_func, cs->section_line);
++        fprintf(stderr, "CS can't start section(%s,%s,%d)\n",
++                file, func, line);
++        return -EPIPE;
++    }
++    cs->section = 1;
++    cs->section_ndw = ndw;
++    cs->section_cdw = 0;
++    cs->section_file = file;
++    cs->section_func = func;
++    cs->section_line = line;
++
++
++    if (cs->cdw + ndw > cs->ndw) {
++        uint32_t tmp, *ptr;
++	int num = (ndw > 0x3FF) ? ndw : 0x3FF;
++
++        tmp = (cs->cdw + 1 + num) & (~num);
++        ptr = (uint32_t*)realloc(cs->packets, 4 * tmp);
++        if (ptr == NULL) {
++            return -ENOMEM;
++        }
++        cs->packets = ptr;
++        cs->ndw = tmp;
++    }
++
 +    return 0;
 +}
 +
@@ -731,7 +1164,19 @@
 +                      int line)
 +
 +{
++    if (!cs->section) {
++        fprintf(stderr, "CS no section to end at (%s,%s,%d)\n",
++                file, func, line);
++        return -EPIPE;
++    }
 +    cs->section = 0;
++    if (cs->section_ndw != cs->section_cdw) {
++        fprintf(stderr, "CS section size missmatch start at (%s,%s,%d) %d vs %d\n",
++                cs->section_file, cs->section_func, cs->section_line, cs->section_ndw, cs->section_cdw);
++        fprintf(stderr, "CS section end at (%s,%s,%d)\n",
++                file, func, line);
++        return -EPIPE;
++    }
 +    return 0;
 +}
 +
@@ -756,6 +1201,10 @@
 +        radeon_bo_unref(csg->relocs_bo[i]);
 +        csg->relocs_bo[i] = NULL;
 +    }
++
++    cs->csm->read_used = 0;
++    cs->csm->vram_write_used = 0;
++    cs->csm->gart_write_used = 0;
 +    return r;
 +}
 +
@@ -893,249 +1342,180 @@
 +    }
 +}
 +
-+static struct radeon_cs_funcs radeon_cs_gem_funcs = {
-+    cs_gem_create,
-+    cs_gem_write_dword,
-+    cs_gem_write_reloc,
-+    cs_gem_begin,
-+    cs_gem_end,
-+    cs_gem_emit,
-+    cs_gem_destroy,
-+    cs_gem_erase,
-+    cs_gem_need_flush,
-+    cs_gem_print
-+};
-+
-+struct radeon_cs_manager *radeon_cs_manager_gem_ctor(int fd)
-+{
-+    struct radeon_cs_manager *csm;
-+
-+    csm = (struct radeon_cs_manager*)calloc(1,
-+                                            sizeof(struct radeon_cs_manager));
-+    if (csm == NULL) {
-+        return NULL;
-+    }
-+    csm->funcs = &radeon_cs_gem_funcs;
-+    csm->fd = fd;
-+    return csm;
-+}
-+
-+void radeon_cs_manager_gem_dtor(struct radeon_cs_manager *csm)
-+{
-+    free(csm);
-+}
-diff -up /dev/null libdrm-2.4.3/libdrm/radeon/radeon_cs_gem.h
---- /dev/null	2008-12-18 14:22:13.823022429 +1000
-+++ libdrm-2.4.3/libdrm/radeon/radeon_cs_gem.h	2008-12-22 12:05:48.000000000 +1000
-@@ -0,0 +1,41 @@
-+/* 
-+ * Copyright © 2008 Nicolai Haehnle
-+ * 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:
-+ *      Aapo Tahkola <aet at rasterburn.org>
-+ *      Nicolai Haehnle <prefect_ at gmx.net>
-+ *      Jérôme Glisse <glisse at freedesktop.org>
-+ */
-+#ifndef RADEON_CS_GEM_H
-+#define RADEON_CS_GEM_H
-+
-+#include "radeon_cs.h"
-+
-+struct radeon_cs_manager *radeon_cs_manager_gem_ctor(int fd);
-+void radeon_cs_manager_gem_dtor(struct radeon_cs_manager *csm);
-+
-+#endif
-diff -up /dev/null libdrm-2.4.3/libdrm/radeon/radeon_cs.h
---- /dev/null	2008-12-18 14:22:13.823022429 +1000
-+++ libdrm-2.4.3/libdrm/radeon/radeon_cs.h	2008-12-22 12:05:48.000000000 +1000
-@@ -0,0 +1,160 @@
-+/* 
-+ * Copyright © 2008 Nicolai Haehnle
-+ * 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:
-+ *      Aapo Tahkola <aet at rasterburn.org>
-+ *      Nicolai Haehnle <prefect_ at gmx.net>
-+ *      Jérôme Glisse <glisse at freedesktop.org>
-+ */
-+#ifndef RADEON_CS_H
-+#define RADEON_CS_H
-+
-+#include <stdint.h>
-+#include "radeon_bo.h"
-+
-+struct radeon_cs_reloc {
-+    struct radeon_bo    *bo;
-+    uint32_t            read_domain;
-+    uint32_t            write_domain;
-+    uint32_t            flags;
-+};
-+
-+struct radeon_cs_manager;
-+
-+struct radeon_cs {
-+    struct radeon_cs_manager    *csm;
-+    void                        *relocs;
-+    uint32_t                    *packets;
-+    unsigned                    crelocs;
-+    unsigned                    relocs_total_size;
-+    unsigned                    cdw;
-+    unsigned                    ndw;
-+    int                         section;
-+    unsigned                    section_ndw;
-+    unsigned                    section_cdw;
-+    const char                  *section_file;
-+    const char                  *section_func;
-+    int                         section_line;
-+};
-+
-+/* cs functions */
-+struct radeon_cs_funcs {
-+    struct radeon_cs *(*cs_create)(struct radeon_cs_manager *csm,
-+                                   uint32_t ndw);
-+    int (*cs_write_dword)(struct radeon_cs *cs, uint32_t dword);
-+    int (*cs_write_reloc)(struct radeon_cs *cs,
-+                          struct radeon_bo *bo,
-+                          uint32_t read_domain,
-+                          uint32_t write_domain,
-+                          uint32_t flags);
-+    int (*cs_begin)(struct radeon_cs *cs,
-+                    uint32_t ndw,
-+                    const char *file,
-+                    const char *func,
-+                    int line);
-+    int (*cs_end)(struct radeon_cs *cs,
-+                  const char *file,
-+                  const char *func,
-+                  int line);
-+    int (*cs_emit)(struct radeon_cs *cs);
-+    int (*cs_destroy)(struct radeon_cs *cs);
-+    int (*cs_erase)(struct radeon_cs *cs);
-+    int (*cs_need_flush)(struct radeon_cs *cs);
-+    void (*cs_print)(struct radeon_cs *cs, FILE *file);
-+};
-+
-+struct radeon_cs_manager {
-+    struct radeon_cs_funcs  *funcs;
-+    int                     fd;
-+};
-+
-+static inline struct radeon_cs *radeon_cs_create(struct radeon_cs_manager *csm,
-+                                                 uint32_t ndw)
-+{
-+    return csm->funcs->cs_create(csm, ndw);
-+}
-+
-+static inline int radeon_cs_write_dword(struct radeon_cs *cs, uint32_t dword)
-+{
-+    return cs->csm->funcs->cs_write_dword(cs, dword);
-+}
-+
-+static inline int radeon_cs_write_reloc(struct radeon_cs *cs,
-+                                        struct radeon_bo *bo,
-+                                        uint32_t read_domain,
-+                                        uint32_t write_domain,
-+                                        uint32_t flags)
++static int cs_gem_check_space(struct radeon_cs *cs, struct radeon_cs_space_check *bos, int num_bo)
 +{
-+    return cs->csm->funcs->cs_write_reloc(cs,
-+                                          bo,
-+                                          read_domain,
-+                                          write_domain,
-+                                          flags);
-+}
++    struct radeon_cs_manager *csm = cs->csm;
++    int this_op_read = 0, this_op_gart_write = 0, this_op_vram_write = 0;
++    uint32_t read_domains, write_domain;
++    int i;
++    struct radeon_bo *bo;
 +
-+static inline int radeon_cs_begin(struct radeon_cs *cs,
-+                                  uint32_t ndw,
-+                                  const char *file,
-+                                  const char *func,
-+                                  int line)
-+{
-+    return cs->csm->funcs->cs_begin(cs, ndw, file, func, line);
-+}
++    /* check the totals for this operation */
 +
-+static inline int radeon_cs_end(struct radeon_cs *cs,
-+                                const char *file,
-+                                const char *func,
-+                                int line)
-+{
-+    return cs->csm->funcs->cs_end(cs, file, func, line);
-+}
++    if (num_bo == 0)
++        return 0;
 +
-+static inline int radeon_cs_emit(struct radeon_cs *cs)
-+{
-+    return cs->csm->funcs->cs_emit(cs);
-+}
++    /* prepare */
++    for (i = 0; i < num_bo; i++) {
++      bo = bos[i].bo;
++
++      bos[i].new_accounted = 0;
++      read_domains = bos[i].read_domains;
++      write_domain = bos[i].write_domain;
++		
++      /* already accounted this bo */
++      if (write_domain && (write_domain == bo->space_accounted))
++	  continue;
++
++      if (read_domains && ((read_domains << 16) == bo->space_accounted))
++	  continue;
++      
++      if (bo->space_accounted == 0) {
++	  if (write_domain == RADEON_GEM_DOMAIN_VRAM)
++	      this_op_vram_write += bo->size;
++	  else if (write_domain == RADEON_GEM_DOMAIN_GTT)
++	      this_op_gart_write += bo->size;
++	  else
++	      this_op_read += bo->size;
++	  bos[i].new_accounted = (read_domains << 16) | write_domain;
++      } else {
++	  uint16_t old_read, old_write;
++	  
++	  old_read = bo->space_accounted >> 16;
++	  old_write = bo->space_accounted & 0xffff;
++
++	  if (write_domain && (old_read & write_domain)) {
++	      bos[i].new_accounted = write_domain;
++	      /* moving from read to a write domain */
++	      if (write_domain == RADEON_GEM_DOMAIN_VRAM) {
++		  this_op_read -= bo->size;
++		  this_op_vram_write += bo->size;
++	      } else if (write_domain == RADEON_GEM_DOMAIN_VRAM) {
++		  this_op_read -= bo->size;
++		  this_op_gart_write += bo->size;
++	      }
++	  } else if (read_domains & old_write) {
++	      bos[i].new_accounted = bo->space_accounted & 0xffff;
++	  } else {
++	      /* rewrite the domains */
++	      if (write_domain != old_write)
++		  fprintf(stderr,"WRITE DOMAIN RELOC FAILURE 0x%x %d %d\n", bo->handle, write_domain, old_write);
++	      if (read_domains != old_read)
++		  fprintf(stderr,"READ DOMAIN RELOC FAILURE 0x%x %d %d\n", bo->handle, read_domains, old_read);
++	      return RADEON_CS_SPACE_FLUSH;
++	  }
++      }
++	}
++	
++	if (this_op_read < 0)
++		this_op_read = 0;
++
++	/* check sizes - operation first */
++	if ((this_op_read + this_op_gart_write > csm->gart_limit) ||
++	    (this_op_vram_write > csm->vram_limit)) {
++	    return RADEON_CS_SPACE_OP_TO_BIG;
++	}
++
++	if (((csm->vram_write_used + this_op_vram_write) > csm->vram_limit) ||
++	    ((csm->read_used + csm->gart_write_used + this_op_gart_write + this_op_read) > csm->gart_limit)) {
++		return RADEON_CS_SPACE_FLUSH;
++	}
++
++	csm->gart_write_used += this_op_gart_write;
++	csm->vram_write_used += this_op_vram_write;
++	csm->read_used += this_op_read;
++	/* commit */
++	for (i = 0; i < num_bo; i++) {
++		bo = bos[i].bo;
++		bo->space_accounted = bos[i].new_accounted;
++	}
 +
-+static inline int radeon_cs_destroy(struct radeon_cs *cs)
-+{
-+    return cs->csm->funcs->cs_destroy(cs);
++	return RADEON_CS_SPACE_OK;
 +}
 +
-+static inline int radeon_cs_erase(struct radeon_cs *cs)
-+{
-+    return cs->csm->funcs->cs_erase(cs);
-+}
++static struct radeon_cs_funcs radeon_cs_gem_funcs = {
++    cs_gem_create,
++    cs_gem_write_reloc,
++    cs_gem_begin,
++    cs_gem_end,
++    cs_gem_emit,
++    cs_gem_destroy,
++    cs_gem_erase,
++    cs_gem_need_flush,
++    cs_gem_print,
++    cs_gem_check_space,
++};
 +
-+static inline int radeon_cs_need_flush(struct radeon_cs *cs)
++struct radeon_cs_manager *radeon_cs_manager_gem_ctor(int fd)
 +{
-+    return cs->csm->funcs->cs_need_flush(cs);
++    struct radeon_cs_manager *csm;
++
++    csm = (struct radeon_cs_manager*)calloc(1,
++                                            sizeof(struct radeon_cs_manager));
++    if (csm == NULL) {
++        return NULL;
++    }
++    csm->funcs = &radeon_cs_gem_funcs;
++    csm->fd = fd;
++    return csm;
 +}
 +
-+static inline void radeon_cs_print(struct radeon_cs *cs, FILE *file)
++void radeon_cs_manager_gem_dtor(struct radeon_cs_manager *csm)
 +{
-+    cs->csm->funcs->cs_print(cs, file);
++    free(csm);
 +}
+diff --git a/libdrm/radeon/radeon_cs_gem.h b/libdrm/radeon/radeon_cs_gem.h
+new file mode 100644
+index 0000000..5efd146
+--- /dev/null
++++ b/libdrm/radeon/radeon_cs_gem.h
+@@ -0,0 +1,41 @@
++/* 
++ * Copyright © 2008 Nicolai Haehnle
++ * 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:
++ *      Aapo Tahkola <aet at rasterburn.org>
++ *      Nicolai Haehnle <prefect_ at gmx.net>
++ *      Jérôme Glisse <glisse at freedesktop.org>
++ */
++#ifndef RADEON_CS_GEM_H
++#define RADEON_CS_GEM_H
++
++#include "radeon_cs.h"
++
++struct radeon_cs_manager *radeon_cs_manager_gem_ctor(int fd);
++void radeon_cs_manager_gem_dtor(struct radeon_cs_manager *csm);
 +
 +#endif
-diff -up /dev/null libdrm-2.4.3/libdrm/radeon/radeon_track.c
---- /dev/null	2008-12-18 14:22:13.823022429 +1000
-+++ libdrm-2.4.3/libdrm/radeon/radeon_track.c	2008-12-22 12:05:48.000000000 +1000
+diff --git a/libdrm/radeon/radeon_track.c b/libdrm/radeon/radeon_track.c
+new file mode 100644
+index 0000000..1623906
+--- /dev/null
++++ b/libdrm/radeon/radeon_track.c
 @@ -0,0 +1,140 @@
 +/* 
 + * Copyright © 2008 Jérôme Glisse
@@ -1277,9 +1657,11 @@
 +        free(tmp);
 +    }
 +}
-diff -up /dev/null libdrm-2.4.3/libdrm/radeon/radeon_track.h
---- /dev/null	2008-12-18 14:22:13.823022429 +1000
-+++ libdrm-2.4.3/libdrm/radeon/radeon_track.h	2008-12-22 12:05:48.000000000 +1000
+diff --git a/libdrm/radeon/radeon_track.h b/libdrm/radeon/radeon_track.h
+new file mode 100644
+index 0000000..838d1f3
+--- /dev/null
++++ b/libdrm/radeon/radeon_track.h
 @@ -0,0 +1,64 @@
 +/* 
 + * Copyright © 2008 Jérôme Glisse
@@ -1345,185 +1727,3 @@
 +                          FILE *file);
 +
 +#endif
-diff -up libdrm-2.4.3/shared-core/radeon_drm.h.dave libdrm-2.4.3/shared-core/radeon_drm.h
---- libdrm-2.4.3/shared-core/radeon_drm.h.dave	2008-12-19 14:33:38.000000000 +1000
-+++ libdrm-2.4.3/shared-core/radeon_drm.h	2008-12-22 12:05:48.000000000 +1000
-@@ -453,8 +453,18 @@ typedef struct {
- 	int pfCurrentPage;	/* which buffer is being displayed? */
- 	int crtc2_base;		/* CRTC2 frame offset */
- 	int tiling_enabled;	/* set by drm, read by 2d + 3d clients */
-+
-+	unsigned int last_fence;
-+
-+	uint32_t front_handle;
-+	uint32_t back_handle;
-+	uint32_t depth_handle;
-+	uint32_t front_pitch;
-+	uint32_t back_pitch;
-+	uint32_t depth_pitch;
- } drm_radeon_sarea_t;
- 
-+
- /* WARNING: If you change any of these defines, make sure to change the
-  * defines in the Xserver file (xf86drmRadeon.h)
-  *
-@@ -493,6 +503,18 @@ typedef struct {
- #define DRM_RADEON_SURF_ALLOC 0x1a
- #define DRM_RADEON_SURF_FREE  0x1b
- 
-+#define DRM_RADEON_GEM_INFO   0x1c
-+#define DRM_RADEON_GEM_CREATE 0x1d
-+#define DRM_RADEON_GEM_MMAP   0x1e
-+#define DRM_RADEON_GEM_PIN    0x1f
-+#define DRM_RADEON_GEM_UNPIN  0x20
-+#define DRM_RADEON_GEM_PREAD  0x21
-+#define DRM_RADEON_GEM_PWRITE 0x22
-+#define DRM_RADEON_GEM_SET_DOMAIN 0x23
-+#define DRM_RADEON_GEM_WAIT_RENDERING 0x24
-+
-+#define DRM_RADEON_CS       0x26
-+
- #define DRM_IOCTL_RADEON_CP_INIT    DRM_IOW( DRM_COMMAND_BASE + DRM_RADEON_CP_INIT, drm_radeon_init_t)
- #define DRM_IOCTL_RADEON_CP_START   DRM_IO(  DRM_COMMAND_BASE + DRM_RADEON_CP_START)
- #define DRM_IOCTL_RADEON_CP_STOP    DRM_IOW( DRM_COMMAND_BASE + DRM_RADEON_CP_STOP, drm_radeon_cp_stop_t)
-@@ -521,6 +543,17 @@ typedef struct {
- #define DRM_IOCTL_RADEON_SURF_ALLOC DRM_IOW( DRM_COMMAND_BASE + DRM_RADEON_SURF_ALLOC, drm_radeon_surface_alloc_t)
- #define DRM_IOCTL_RADEON_SURF_FREE  DRM_IOW( DRM_COMMAND_BASE + DRM_RADEON_SURF_FREE, drm_radeon_surface_free_t)
- 
-+#define DRM_IOCTL_RADEON_GEM_INFO   DRM_IOWR(DRM_COMMAND_BASE + DRM_RADEON_GEM_INFO, struct drm_radeon_gem_info)
-+#define DRM_IOCTL_RADEON_GEM_CREATE   DRM_IOWR(DRM_COMMAND_BASE + DRM_RADEON_GEM_CREATE, struct drm_radeon_gem_create)
-+#define DRM_IOCTL_RADEON_GEM_MMAP   DRM_IOWR(DRM_COMMAND_BASE + DRM_RADEON_GEM_MMAP, struct drm_radeon_gem_mmap)
-+#define DRM_IOCTL_RADEON_GEM_PIN   DRM_IOWR(DRM_COMMAND_BASE + DRM_RADEON_GEM_PIN, struct drm_radeon_gem_pin)
-+#define DRM_IOCTL_RADEON_GEM_UNPIN   DRM_IOWR(DRM_COMMAND_BASE + DRM_RADEON_GEM_UNPIN, struct drm_radeon_gem_unpin)
-+#define DRM_IOCTL_RADEON_GEM_PREAD   DRM_IOWR(DRM_COMMAND_BASE + DRM_RADEON_GEM_PREAD, struct drm_radeon_gem_pread)
-+#define DRM_IOCTL_RADEON_GEM_PWRITE   DRM_IOWR(DRM_COMMAND_BASE + DRM_RADEON_GEM_PWRITE, struct drm_radeon_gem_pwrite)
-+#define DRM_IOCTL_RADEON_GEM_SET_DOMAIN  DRM_IOWR(DRM_COMMAND_BASE + DRM_RADEON_GEM_SET_DOMAIN, struct drm_radeon_gem_set_domain)
-+#define DRM_IOCTL_RADEON_GEM_WAIT_RENDERING DRM_IOW(DRM_COMMAND_BASE + DRM_RADEON_GEM_WAIT_RENDERING, struct drm_radeon_gem_wait_rendering) 
-+#define DRM_IOCTL_RADEON_CS DRM_IOWR(DRM_COMMAND_BASE + DRM_RADEON_CS, struct drm_radeon_cs)
-+
- typedef struct drm_radeon_init {
- 	enum {
- 		RADEON_INIT_CP = 0x01,
-@@ -677,6 +710,7 @@ typedef struct drm_radeon_indirect {
- #define RADEON_PARAM_VBLANK_CRTC           13   /* VBLANK CRTC */
- #define RADEON_PARAM_FB_LOCATION           14   /* FB location */
- #define RADEON_PARAM_NUM_GB_PIPES          15   /* num GB pipes */
-+#define RADEON_PARAM_KERNEL_MM             16
- 
- typedef struct drm_radeon_getparam {
- 	int param;
-@@ -732,6 +766,7 @@ typedef struct drm_radeon_setparam {
- #define RADEON_SETPARAM_NEW_MEMMAP 4		/* Use new memory map */
- #define RADEON_SETPARAM_PCIGART_TABLE_SIZE 5    /* PCI GART Table Size */
- #define RADEON_SETPARAM_VBLANK_CRTC 6           /* VBLANK CRTC */
-+#define RADEON_SETPARAM_MM_INIT 7		/* Initialise the mm */
- /* 1.14: Clients can allocate/free a surface
-  */
- typedef struct drm_radeon_surface_alloc {
-@@ -747,4 +782,106 @@ typedef struct drm_radeon_surface_free {
- #define	DRM_RADEON_VBLANK_CRTC1		1
- #define	DRM_RADEON_VBLANK_CRTC2		2
- 
-+#define RADEON_GEM_DOMAIN_CPU 0x1   // Cached CPU domain
-+#define RADEON_GEM_DOMAIN_GTT 0x2   // GTT or cache flushed
-+#define RADEON_GEM_DOMAIN_VRAM 0x4  // VRAM domain
-+
-+/* return to userspace start/size of gtt and vram apertures */
-+struct drm_radeon_gem_info {
-+	uint64_t gart_start;
-+	uint64_t gart_size;
-+	uint64_t vram_start;
-+	uint64_t vram_size;
-+	uint64_t vram_visible;
-+};
-+
-+struct drm_radeon_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_radeon_gem_mmap {
-+	uint32_t handle;
-+	uint32_t pad;
-+	uint64_t offset;
-+	uint64_t size;
-+	uint64_t addr_ptr;
-+};
-+
-+struct drm_radeon_gem_set_domain {
-+	uint32_t handle;
-+	uint32_t read_domains;
-+	uint32_t write_domain;
-+};
-+
-+struct drm_radeon_gem_wait_rendering {
-+	uint32_t handle;
-+};
-+
-+struct drm_radeon_gem_pin {
-+	uint32_t handle;
-+	uint32_t pin_domain;
-+	uint64_t alignment;
-+	uint64_t offset;
-+};
-+
-+struct drm_radeon_gem_unpin {
-+	uint32_t handle;
-+	uint32_t pad;
-+};
-+
-+struct drm_radeon_gem_busy {
-+	uint32_t handle;
-+	uint32_t busy;
-+};
-+
-+struct drm_radeon_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_radeon_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 */
-+};
-+
-+
-+/* New interface which obsolete all previous interface.
-+ */
-+
-+#define RADEON_CHUNK_ID_RELOCS 0x01
-+#define RADEON_CHUNK_ID_IB     0x02
-+
-+struct drm_radeon_cs_chunk {
-+	uint32_t chunk_id;
-+	uint32_t length_dw;
-+	uint64_t chunk_data;
-+};
-+
-+struct drm_radeon_cs {
-+	uint32_t	num_chunks;
-+	uint32_t        cs_id;
-+	uint64_t	chunks; /* this points to uint64_t * which point to
-+				   cs chunks */
-+};
-+
-+
- #endif


Index: libdrm.spec
===================================================================
RCS file: /cvs/pkgs/rpms/libdrm/devel/libdrm.spec,v
retrieving revision 1.57
retrieving revision 1.58
diff -u -r1.57 -r1.58
--- libdrm.spec	1 Feb 2009 07:08:35 -0000	1.57
+++ libdrm.spec	5 Feb 2009 00:52:26 -0000	1.58
@@ -3,7 +3,7 @@
 Summary: Direct Rendering Manager runtime library
 Name: libdrm
 Version: 2.4.4
-Release: 2%{?dist}
+Release: 3%{?dist}
 License: MIT
 Group: System Environment/Libraries
 URL: http://dri.sourceforge.net
@@ -28,7 +28,6 @@
 Patch4: libdrm-2.4.0-no-bc.patch
 # radeon libdrm patches from modesetting-gem branch of upstream
 Patch8: libdrm-radeon.patch
-Patch9: libdrm-radeon-update.patch
 
 %description
 Direct Rendering Manager runtime library
@@ -48,7 +47,6 @@
 %patch3 -p1 -b .forceperms
 %patch4 -p1 -b .no-bc
 %patch8 -p1 -b .radeon
-%patch9 -p1 -b .radeon2
 
 %build
 autoreconf -v --install || exit 1
@@ -100,6 +98,9 @@
 %{_libdir}/pkgconfig/libdrm.pc
 
 %changelog
+* Thu Feb 05 2009 Dave Airlie <airlied at redhat.com> 2.4.4-3
+- update with more libdrm/radeon upstream fixes
+
 * Sun Feb 01 2009 Dave Airlie <airlied at redhat.com> 2.4.4-2
 - update specfile with review changes
 


--- libdrm-radeon-update.patch DELETED ---




More information about the scm-commits mailing list