gallium: Simplify winsys buffer interface.

The properties of a buffer represented by struct pipe_buffer_handle are now
basically constant over its lifetime. The state tracker gets to deal with any
more complex buffer semantics it may need to provide.
diff --git a/src/mesa/pipe/i915simple/i915_context.c b/src/mesa/pipe/i915simple/i915_context.c
index 1c6b8cb..c2b96d2 100644
--- a/src/mesa/pipe/i915simple/i915_context.c
+++ b/src/mesa/pipe/i915simple/i915_context.c
@@ -185,7 +185,7 @@
          void *buf
             = pipe->winsys->buffer_map(pipe->winsys,
                                        i915->vertex_buffer[i].buffer,
-                                       PIPE_BUFFER_FLAG_READ);
+                                       PIPE_BUFFER_USAGE_CPU_READ);
          draw_set_mapped_vertex_buffer(draw, i, buf);
       }
    }
@@ -193,7 +193,7 @@
    if (indexBuffer) {
       void *mapped_indexes
          = pipe->winsys->buffer_map(pipe->winsys, indexBuffer,
-                                    PIPE_BUFFER_FLAG_READ);
+                                    PIPE_BUFFER_USAGE_CPU_READ);
       draw_set_mapped_element_buffer(draw, indexSize, mapped_indexes);
    }
    else {
diff --git a/src/mesa/pipe/i915simple/i915_prim_vbuf.c b/src/mesa/pipe/i915simple/i915_prim_vbuf.c
index edc62e2..0887f9a 100644
--- a/src/mesa/pipe/i915simple/i915_prim_vbuf.c
+++ b/src/mesa/pipe/i915simple/i915_prim_vbuf.c
@@ -99,16 +99,14 @@
 
    /* FIXME: handle failure */
    assert(!i915->vbo);
-   i915->vbo = winsys->buffer_create(winsys, 64, 0, 0);
-   winsys->buffer_data( winsys, i915->vbo, 
-                        size, NULL, 
-                        I915_BUFFER_USAGE_LIT_VERTEX );
+   i915->vbo = winsys->buffer_create(winsys, 64, I915_BUFFER_USAGE_LIT_VERTEX,
+                                     size);
    
    i915->dirty |= I915_NEW_VBO;
    
    return winsys->buffer_map(winsys, 
                              i915->vbo, 
-                             PIPE_BUFFER_FLAG_WRITE );
+                             PIPE_BUFFER_USAGE_CPU_WRITE);
 }
 
 
diff --git a/src/mesa/pipe/i915simple/i915_state.c b/src/mesa/pipe/i915simple/i915_state.c
index 1190e05..950ea52 100644
--- a/src/mesa/pipe/i915simple/i915_state.c
+++ b/src/mesa/pipe/i915simple/i915_state.c
@@ -476,7 +476,8 @@
    {
       void *mapped;
       if (buf->size &&
-          (mapped = ws->buffer_map(ws, buf->buffer, PIPE_BUFFER_FLAG_READ))) {
+          (mapped = ws->buffer_map(ws, buf->buffer,
+                                   PIPE_BUFFER_USAGE_CPU_READ))) {
          memcpy(i915->current.constants[shader], mapped, buf->size);
          ws->buffer_unmap(ws, buf->buffer);
          i915->current.num_user_constants[shader]
diff --git a/src/mesa/pipe/i915simple/i915_texture.c b/src/mesa/pipe/i915simple/i915_texture.c
index 6b0a4a9..bf80e18 100644
--- a/src/mesa/pipe/i915simple/i915_texture.c
+++ b/src/mesa/pipe/i915simple/i915_texture.c
@@ -490,15 +490,11 @@
 	     sizeof(struct i915_texture) - sizeof(struct pipe_texture));
 
       if (i915->flags.is_i945 ? i945_miptree_layout(pipe, tex) :
-	  i915_miptree_layout(pipe, tex)) {
-	 tex->buffer = pipe->winsys->buffer_create(pipe->winsys, 64, 0, 0);
-
-	 if (tex->buffer)
-	    pipe->winsys->buffer_data(pipe->winsys, tex->buffer,
-				      tex->pitch * tex->base.cpp *
-				      tex->total_height, NULL,
-				      PIPE_BUFFER_USAGE_PIXEL);
-      }
+	  i915_miptree_layout(pipe, tex))
+	 tex->buffer = pipe->winsys->buffer_create(pipe->winsys, 64,
+                                                   PIPE_BUFFER_USAGE_PIXEL,
+                                                   tex->pitch * tex->base.cpp *
+                                                   tex->total_height);
 
       if (!tex->buffer) {
 	 FREE(tex);
diff --git a/src/mesa/pipe/i965simple/brw_curbe.c b/src/mesa/pipe/i965simple/brw_curbe.c
index 4d79a7a..2733eb4 100644
--- a/src/mesa/pipe/i965simple/brw_curbe.c
+++ b/src/mesa/pipe/i965simple/brw_curbe.c
@@ -255,15 +255,12 @@
       /* FIXME: buffer size is num_consts + num_immediates */
       if (brw->vs.prog_data->num_consts) {
          /* map the vertex constant buffer and copy to curbe: */
-         ws->buffer_map(ws, cbuffer->buffer, 0);
+         void *data = ws->buffer_map(ws, cbuffer->buffer, 0);
          /* FIXME: this is wrong. the cbuffer->size currently
           * represents size of consts + immediates. so if we'll
           * have both we'll copy over the end of the buffer
           * with the subsequent memcpy */
-         ws->buffer_get_subdata(ws, cbuffer->buffer,
-                                0,
-                                cbuffer->size,
-                                &buf[offset]);
+         memcpy(&buf[offset], data, cbuffer->size);
          ws->buffer_unmap(ws, cbuffer->buffer);
          offset += cbuffer->size;
       }
diff --git a/src/mesa/pipe/i965simple/brw_draw_upload.c b/src/mesa/pipe/i965simple/brw_draw_upload.c
index 88d6c9d..43e5391 100644
--- a/src/mesa/pipe/i965simple/brw_draw_upload.c
+++ b/src/mesa/pipe/i965simple/brw_draw_upload.c
@@ -240,7 +240,7 @@
 
    for (i = 0; i < nr_enabled; i++) {
       OUT_BATCH( vbp.vb[i].vb0.dword );
-      OUT_RELOC( vbp.vb[i].buffer,  PIPE_BUFFER_FLAG_READ,
+      OUT_RELOC( vbp.vb[i].buffer,  PIPE_BUFFER_USAGE_GPU_READ,
 		 vbp.vb[i].offset);
       OUT_BATCH( vbp.vb[i].max_index );
       OUT_BATCH( vbp.vb[i].instance_data_step_rate );
@@ -290,8 +290,8 @@
 
       BEGIN_BATCH(4, 0);
       OUT_BATCH( ib.header.dword );
-      OUT_RELOC( index_buffer, PIPE_BUFFER_FLAG_READ, start);
-      OUT_RELOC( index_buffer, PIPE_BUFFER_FLAG_READ, start + count);
+      OUT_RELOC( index_buffer, PIPE_BUFFER_USAGE_GPU_READ, start);
+      OUT_RELOC( index_buffer, PIPE_BUFFER_USAGE_GPU_READ, start + count);
       OUT_BATCH( 0 );
       ADVANCE_BATCH();
    }
diff --git a/src/mesa/pipe/i965simple/brw_misc_state.c b/src/mesa/pipe/i965simple/brw_misc_state.c
index 3b7f36d..925049e 100644
--- a/src/mesa/pipe/i965simple/brw_misc_state.c
+++ b/src/mesa/pipe/i965simple/brw_misc_state.c
@@ -245,7 +245,7 @@
 //		(depth_surface->region->tiled << 27) |
 		(BRW_SURFACE_2D << 29));
       OUT_RELOC(depth_surface->buffer,
-		PIPE_BUFFER_FLAG_READ | PIPE_BUFFER_FLAG_WRITE, 0);
+		PIPE_BUFFER_USAGE_GPU_READ | PIPE_BUFFER_USAGE_GPU_WRITE, 0);
       OUT_BATCH((BRW_SURFACE_MIPMAPLAYOUT_BELOW << 1) |
 		((depth_surface->pitch - 1) << 6) |
 		((depth_surface->height - 1) << 19));
@@ -465,10 +465,10 @@
    BEGIN_BATCH(6, INTEL_BATCH_NO_CLIPRECTS);
    OUT_BATCH(CMD_STATE_BASE_ADDRESS << 16 | (6 - 2));
    OUT_RELOC(brw->pool[BRW_GS_POOL].buffer,
-	     PIPE_BUFFER_FLAG_READ,
+	     PIPE_BUFFER_USAGE_GPU_READ,
 	     1); /* General state base address */
    OUT_RELOC(brw->pool[BRW_SS_POOL].buffer,
-	     PIPE_BUFFER_FLAG_READ,
+	     PIPE_BUFFER_USAGE_GPU_READ,
 	     1); /* Surface state base address */
    OUT_BATCH(1); /* Indirect object base address */
    OUT_BATCH(1); /* General state upper bound */
diff --git a/src/mesa/pipe/i965simple/brw_state_pool.c b/src/mesa/pipe/i965simple/brw_state_pool.c
index 78268ed..2f930be 100644
--- a/src/mesa/pipe/i965simple/brw_state_pool.c
+++ b/src/mesa/pipe/i965simple/brw_state_pool.c
@@ -91,13 +91,9 @@
    pool->brw = brw;
 
    pool->buffer = brw->pipe.winsys->buffer_create(brw->pipe.winsys,
-						  4096, 0, 0);
-
-   brw->pipe.winsys->buffer_data(brw->pipe.winsys,
-				 pool->buffer,
-				 size,
-				 NULL,
-				 0 /*  DRM_BO_FLAG_MEM_TT */);
+						  4096,
+                                                  0 /*  DRM_BO_FLAG_MEM_TT */,
+                                                  size);
 }
 
 static void brw_destroy_pool( struct brw_context *brw,
diff --git a/src/mesa/pipe/i965simple/brw_tex_layout.c b/src/mesa/pipe/i965simple/brw_tex_layout.c
index 2b2bf16..eadacbf 100644
--- a/src/mesa/pipe/i965simple/brw_tex_layout.c
+++ b/src/mesa/pipe/i965simple/brw_tex_layout.c
@@ -308,15 +308,11 @@
       memset(&tex->base + 1, 0,
 	     sizeof(struct brw_texture) - sizeof(struct pipe_texture));
 
-      if (brw_miptree_layout(pipe, tex)) {
-	 tex->buffer = pipe->winsys->buffer_create(pipe->winsys, 64, 0, 0);
-
-         if (tex->buffer)
-            pipe->winsys->buffer_data(pipe->winsys, tex->buffer,
-                                      tex->pitch * tex->base.cpp *
-                                      tex->total_height, NULL,
-                                      PIPE_BUFFER_USAGE_PIXEL);
-      }
+      if (brw_miptree_layout(pipe, tex))
+	 tex->buffer = pipe->winsys->buffer_create(pipe->winsys, 64,
+                                                   PIPE_BUFFER_USAGE_PIXEL,
+                                                   tex->pitch * tex->base.cpp *
+                                                   tex->total_height);
 
       if (!tex->buffer) {
 	 FREE(tex);
diff --git a/src/mesa/pipe/p_defines.h b/src/mesa/pipe/p_defines.h
index 50bea69..90eebd5 100644
--- a/src/mesa/pipe/p_defines.h
+++ b/src/mesa/pipe/p_defines.h
@@ -178,25 +178,19 @@
 
 
 /**
- * Buffer access flags
- */
-#define PIPE_BUFFER_FLAG_READ         0x1
-#define PIPE_BUFFER_FLAG_WRITE        0x2
-#define PIPE_BUFFER_FLAG_MEM_LOCAL    0x4
-#define PIPE_BUFFER_FLAG_CACHED       0x8
-#define PIPE_BUFFER_FLAG_CUSTOM       (1<<16)
-
-
-
-/**
  * Buffer usage flags
  */
-#define PIPE_BUFFER_USAGE_PIXEL    (1 << 0)
-#define PIPE_BUFFER_USAGE_VERTEX   (1 << 1)
-#define PIPE_BUFFER_USAGE_INDEX    (1 << 2)
-#define PIPE_BUFFER_USAGE_CONSTANT (1 << 3)
+#define PIPE_BUFFER_USAGE_CPU_READ  (1 << 0)
+#define PIPE_BUFFER_USAGE_CPU_WRITE (1 << 1)
+#define PIPE_BUFFER_USAGE_GPU_READ  (1 << 2)
+#define PIPE_BUFFER_USAGE_GPU_WRITE (1 << 3)
+#define PIPE_BUFFER_USAGE_PIXEL     (1 << 4)
+#define PIPE_BUFFER_USAGE_VERTEX    (1 << 5)
+#define PIPE_BUFFER_USAGE_INDEX     (1 << 6)
+#define PIPE_BUFFER_USAGE_CONSTANT  (1 << 7)
 /** Pipe driver custam usage flags should be greater or equal to this value */
-#define PIPE_BUFFER_USAGE_CUSTOM   (1 << 16)
+#define PIPE_BUFFER_USAGE_CUSTOM    (1 << 16)
+
 
 /** 
  * Flush types:
diff --git a/src/mesa/pipe/p_inlines.h b/src/mesa/pipe/p_inlines.h
index 6976d08..8ee0820 100644
--- a/src/mesa/pipe/p_inlines.h
+++ b/src/mesa/pipe/p_inlines.h
@@ -37,8 +37,8 @@
 pipe_surface_map(struct pipe_surface *surface)
 {
    return (char *)surface->winsys->buffer_map( surface->winsys, surface->buffer,
-					       PIPE_BUFFER_FLAG_WRITE |
-					       PIPE_BUFFER_FLAG_READ )
+					       PIPE_BUFFER_USAGE_CPU_WRITE |
+					       PIPE_BUFFER_USAGE_CPU_READ )
       + surface->offset;
 }
 
diff --git a/src/mesa/pipe/p_winsys.h b/src/mesa/pipe/p_winsys.h
index 75c6dc7..9742f59 100644
--- a/src/mesa/pipe/p_winsys.h
+++ b/src/mesa/pipe/p_winsys.h
@@ -1,4 +1,4 @@
-/**************************************************************************
+ /**************************************************************************
  * 
  * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
  * All Rights Reserved.
@@ -93,17 +93,20 @@
 
    
    /**
-    * The buffer manager is modeled after the dri_bufmgr interface, which 
-    * in turn is modeled after the ARB_vertex_buffer_object extension,  
-    * but this is the subset that gallium cares about.  Remember that
-    * gallium gets to choose the interface it needs, and the window
-    * systems must then implement that interface (rather than the
+    * Buffer management. Buffer attributes are mostly fixed over its lifetime.
+    *
+    * Remember that gallium gets to choose the interface it needs, and the
+    * window systems must then implement that interface (rather than the
     * other way around...).
+    *
+    * usage is a bitmask of PIPE_BUFFER_USAGE_PIXEL/VERTEX/INDEX/CONSTANT. This
+    * usage argument is only an optimization hint, not a guarantee, therefore 
+    * proper behavior must be observed in all circumstances.
     */
    struct pipe_buffer_handle *(*buffer_create)( struct pipe_winsys *sws, 
 					        unsigned alignment,
-                                                unsigned flags,
-                                                unsigned hint );
+                                                unsigned usage,
+                                                unsigned size );
 
    /** Create a buffer that wraps user-space data */
    struct pipe_buffer_handle *(*user_buffer_create)(struct pipe_winsys *sws, 
@@ -116,7 +119,7 @@
     */
    void *(*buffer_map)( struct pipe_winsys *sws, 
 			struct pipe_buffer_handle *buf,
-			unsigned flags );
+			unsigned usage );
    
    void (*buffer_unmap)( struct pipe_winsys *sws, 
 			 struct pipe_buffer_handle *buf );
@@ -126,44 +129,8 @@
                              struct pipe_buffer_handle **ptr,
                              struct pipe_buffer_handle *buf );
 
-   /** 
-    * Create the data store of a buffer and optionally initialize it.
-    * 
-    * usage is a bitmask of PIPE_BUFFER_USAGE_PIXEL/VERTEX/INDEX/CONSTANT. This
-    * usage argument is only an optimization hint, not a guarantee, therefore 
-    * proper behavior must be observed in all circumstances.
-    * 
-    * Returns zero on success.
-    */
-   int (*buffer_data)(struct pipe_winsys *sws, 
-		       struct pipe_buffer_handle *buf,
-		       unsigned size, const void *data,
-		       unsigned usage);
 
-   /** 
-    * Modify some or all of the data contained in a buffer's data store.
-    * 
-    * Returns zero on success.
-    */
-   int (*buffer_subdata)(struct pipe_winsys *sws, 
-                         struct pipe_buffer_handle *buf,
-                         unsigned long offset, 
-                         unsigned long size, 
-                         const void *data);
-
-   /** 
-    * Query some or all of the data contained in a buffer's data store.
-    * 
-    * Returns zero on success.
-    */
-   int (*buffer_get_subdata)(struct pipe_winsys *sws, 
-                             struct pipe_buffer_handle *buf,
-                             unsigned long offset, 
-                             unsigned long size, 
-                             void *data);
-
-
-   /** Set ptr = buf, with reference counting */
+   /** Set ptr = fence, with reference counting */
    void (*fence_reference)( struct pipe_winsys *sws,
                             struct pipe_fence_handle **ptr,
                             struct pipe_fence_handle *fence );
diff --git a/src/mesa/pipe/pipebuffer/pb_buffer_handle.c b/src/mesa/pipe/pipebuffer/pb_buffer_handle.c
index 5a5eaee..9aeff97 100644
--- a/src/mesa/pipe/pipebuffer/pb_buffer_handle.c
+++ b/src/mesa/pipe/pipebuffer/pb_buffer_handle.c
@@ -46,8 +46,8 @@
 static struct pipe_buffer_handle *
 buffer_handle_create(struct pipe_winsys *winsys,
                      unsigned alignment,
-                     unsigned flags,
-                     unsigned hint)
+                     unsigned usage,
+                     unsigned size)
 {
    struct pipe_buffer_handle *handle;
   
@@ -57,8 +57,8 @@
    
    handle->refcount = 1;
    handle->alignment = alignment;
-   handle->flags = flags;
-   handle->hint = hint;
+   handle->usage = usage;
+   handle->size = size;
    
    handle->buf = &null_buffer;
    
@@ -73,7 +73,7 @@
    struct pipe_buffer_handle *handle;
    struct pipe_buffer *buf;
    
-   handle = buffer_handle_create(winsys, 1, 0, 0);
+   handle = buffer_handle_create(winsys, 1, 0, size);
    if(!handle)
       return NULL;
    
@@ -129,46 +129,6 @@
 }
 
 
-static int 
-buffer_handle_subdata(struct pipe_winsys *winsys, 
-                      struct pipe_buffer_handle *handle,
-                      unsigned long offset, 
-                      unsigned long size, 
-                      const void *data)
-{
-   void *map;
-   assert(handle);
-   assert(data);
-   map = buffer_handle_map(winsys, handle, PIPE_BUFFER_FLAG_WRITE);
-   if(map) {
-      memcpy((char *)map + offset, data, size);
-      buffer_handle_unmap(winsys, handle);
-      return 0;
-   }
-   return -1; 
-}
-
-
-static int  
-buffer_handle_get_subdata(struct pipe_winsys *winsys,
-                          struct pipe_buffer_handle *handle,
-                          unsigned long offset, 
-                          unsigned long size, 
-                          void *data)
-{
-   void *map;
-   assert(handle);
-   assert(data);
-   map = buffer_handle_map(winsys, handle, PIPE_BUFFER_FLAG_READ);
-   if(map) {
-      memcpy(data, (char *)map + offset, size);
-      buffer_handle_unmap(winsys, handle);
-      return 0;
-   }
-   return -1; 
-}
-
-
 void 
 buffer_handle_init_winsys(struct pipe_winsys *winsys)
 {
@@ -177,6 +137,4 @@
    winsys->buffer_map = buffer_handle_map;
    winsys->buffer_unmap = buffer_handle_unmap;
    winsys->buffer_reference = buffer_handle_reference;
-   winsys->buffer_subdata = buffer_handle_subdata;
-   winsys->buffer_get_subdata = buffer_handle_get_subdata;
 }
diff --git a/src/mesa/pipe/pipebuffer/pb_buffer_handle.h b/src/mesa/pipe/pipebuffer/pb_buffer_handle.h
index 076eec2..34133c9 100644
--- a/src/mesa/pipe/pipebuffer/pb_buffer_handle.h
+++ b/src/mesa/pipe/pipebuffer/pb_buffer_handle.h
@@ -55,8 +55,8 @@
 
    /** Allocation characteristics */
    unsigned alignment;
-   unsigned flags;
-   unsigned hint;
+   unsigned usage;
+   unsigned size;
    
    /** 
     * The actual buffer.
diff --git a/src/mesa/pipe/pipebuffer/pb_bufmgr_mm.c b/src/mesa/pipe/pipebuffer/pb_bufmgr_mm.c
index e9bc34b..d174f24 100644
--- a/src/mesa/pipe/pipebuffer/pb_bufmgr_mm.c
+++ b/src/mesa/pipe/pipebuffer/pb_bufmgr_mm.c
@@ -241,7 +241,8 @@
    mm->buffer = buffer; 
 
    mm->map = buffer_map(mm->buffer, 
-                        PIPE_BUFFER_FLAG_READ | PIPE_BUFFER_FLAG_WRITE );
+                        PIPE_BUFFER_USAGE_CPU_READ |
+                        PIPE_BUFFER_USAGE_CPU_WRITE);
    if(!mm->map)
       goto failure;
 
diff --git a/src/mesa/pipe/pipebuffer/pb_bufmgr_pool.c b/src/mesa/pipe/pipebuffer/pb_bufmgr_pool.c
index ee6fa62..e6a8c78 100644
--- a/src/mesa/pipe/pipebuffer/pb_bufmgr_pool.c
+++ b/src/mesa/pipe/pipebuffer/pb_bufmgr_pool.c
@@ -246,8 +246,8 @@
       goto failure;
 
    pool->map = buffer_map(pool->buffer,
-                          PIPE_BUFFER_FLAG_READ |
-                          PIPE_BUFFER_FLAG_WRITE );
+                          PIPE_BUFFER_USAGE_CPU_READ |
+                          PIPE_BUFFER_USAGE_CPU_WRITE);
    if(!pool->map)
       goto failure;
 
diff --git a/src/mesa/pipe/softpipe/sp_draw_arrays.c b/src/mesa/pipe/softpipe/sp_draw_arrays.c
index b7626f8..8ee9177 100644
--- a/src/mesa/pipe/softpipe/sp_draw_arrays.c
+++ b/src/mesa/pipe/softpipe/sp_draw_arrays.c
@@ -50,7 +50,7 @@
    for (i = 0; i < 2; i++) {
       if (sp->constants[i].size)
          sp->mapped_constants[i] = ws->buffer_map(ws, sp->constants[i].buffer,
-                                                  PIPE_BUFFER_FLAG_READ);
+                                                  PIPE_BUFFER_USAGE_CPU_READ);
    }
 
    draw_set_mapped_constant_buffer(sp->draw,
@@ -122,7 +122,7 @@
          void *buf
             = pipe->winsys->buffer_map(pipe->winsys,
                                        sp->vertex_buffer[i].buffer,
-                                       PIPE_BUFFER_FLAG_READ);
+                                       PIPE_BUFFER_USAGE_CPU_READ);
          draw_set_mapped_vertex_buffer(draw, i, buf);
       }
    }
@@ -130,7 +130,7 @@
    if (indexBuffer) {
       void *mapped_indexes
          = pipe->winsys->buffer_map(pipe->winsys, indexBuffer,
-                                    PIPE_BUFFER_FLAG_READ);
+                                    PIPE_BUFFER_USAGE_CPU_READ);
       draw_set_mapped_element_buffer(draw, indexSize, mapped_indexes);
    }
    else {
diff --git a/src/mesa/pipe/softpipe/sp_texture.c b/src/mesa/pipe/softpipe/sp_texture.c
index d43a699..23e9c1b 100644
--- a/src/mesa/pipe/softpipe/sp_texture.c
+++ b/src/mesa/pipe/softpipe/sp_texture.c
@@ -91,12 +91,9 @@
 
       softpipe_texture_layout(spt);
 
-      spt->buffer = pipe->winsys->buffer_create(pipe->winsys, 32, 0, 0);
-
-      if (spt->buffer) {
-	 pipe->winsys->buffer_data(pipe->winsys, spt->buffer, spt->buffer_size,
-				   NULL, PIPE_BUFFER_USAGE_PIXEL);
-      }
+      spt->buffer = pipe->winsys->buffer_create(pipe->winsys, 32,
+                                                PIPE_BUFFER_USAGE_PIXEL,
+                                                spt->buffer_size);
 
       if (!spt->buffer) {
 	 FREE(spt);
diff --git a/src/mesa/pipe/xlib/xm_winsys.c b/src/mesa/pipe/xlib/xm_winsys.c
index 432431a..cb043ef 100644
--- a/src/mesa/pipe/xlib/xm_winsys.c
+++ b/src/mesa/pipe/xlib/xm_winsys.c
@@ -165,48 +165,6 @@
    }
 }
 
-static int
-xm_buffer_data(struct pipe_winsys *pws, struct pipe_buffer_handle *buf,
-               unsigned size, const void *data, unsigned usage )
-{
-   struct xm_buffer *xm_buf = xm_bo(buf);
-   assert(!xm_buf->userBuffer);
-   if (xm_buf->size != size) {
-      if (xm_buf->data)
-         align_free(xm_buf->data);
-      /* align to 16-byte multiple for Cell */
-      xm_buf->data = align_malloc(size, 16);
-      xm_buf->size = size;
-   }
-   if (data)
-      memcpy(xm_buf->data, data, size);
-   return 0;
-}
-
-static int
-xm_buffer_subdata(struct pipe_winsys *pws, struct pipe_buffer_handle *buf,
-                  unsigned long offset, unsigned long size, const void *data)
-{
-   struct xm_buffer *xm_buf = xm_bo(buf);
-   GLubyte *b = (GLubyte *) xm_buf->data;
-   assert(!xm_buf->userBuffer);
-   assert(b);
-   memcpy(b + offset, data, size);
-   return 0;
-}
-
-static int
-xm_buffer_get_subdata(struct pipe_winsys *pws, struct pipe_buffer_handle *buf,
-                      unsigned long offset, unsigned long size, void *data)
-{
-   const struct xm_buffer *xm_buf = xm_bo(buf);
-   const GLubyte *b = (GLubyte *) xm_buf->data;
-   assert(!xm_buf->userBuffer);
-   assert(b);
-   memcpy(data, b + offset, size);
-   return 0;
-}
-
 
 /**
  * Display a surface that's in a tiled configuration.  That is, all the
@@ -317,11 +275,16 @@
 static struct pipe_buffer_handle *
 xm_buffer_create(struct pipe_winsys *pws, 
                  unsigned alignment, 
-                 unsigned flags,
-                 unsigned hints)
+                 unsigned usage,
+                 unsigned size)
 {
    struct xm_buffer *buffer = CALLOC_STRUCT(xm_buffer);
    buffer->refcount = 1;
+
+   /* align to 16-byte multiple for Cell */
+   buffer->data = align_malloc(size, max(alignment, 16));
+   buffer->size = size;
+
    return pipe_bo(buffer);
 }
 
@@ -359,7 +322,6 @@
                          unsigned flags)
 {
    const unsigned alignment = 64;
-   int ret;
 
    surf->width = width;
    surf->height = height;
@@ -372,19 +334,11 @@
 #endif
 
    assert(!surf->buffer);
-   surf->buffer = winsys->buffer_create(winsys, alignment, 0, 0);
+   surf->buffer = winsys->buffer_create(winsys, alignment,
+                                        PIPE_BUFFER_USAGE_PIXEL,
+                                        surf->pitch * surf->cpp * height);
    if(!surf->buffer)
       return -1;
-
-   ret = winsys->buffer_data(winsys, 
-                             surf->buffer,
-                             surf->pitch * surf->cpp * height,
-                             NULL,
-                             0);
-   if(ret) {
-      winsys->buffer_reference(winsys, &surf->buffer, NULL);
-      return ret;
-   }
    
    return 0;
 }
@@ -454,9 +408,6 @@
       ws->buffer_map = xm_buffer_map;
       ws->buffer_unmap = xm_buffer_unmap;
       ws->buffer_reference = xm_buffer_reference;
-      ws->buffer_data = xm_buffer_data;
-      ws->buffer_subdata = xm_buffer_subdata;
-      ws->buffer_get_subdata = xm_buffer_get_subdata;
 
       ws->surface_alloc = xm_surface_alloc;
       ws->surface_alloc_storage = xm_surface_alloc_storage;
diff --git a/src/mesa/pipe/xlib/xm_winsys_aub.c b/src/mesa/pipe/xlib/xm_winsys_aub.c
index 980c0be..28dd07b 100644
--- a/src/mesa/pipe/xlib/xm_winsys_aub.c
+++ b/src/mesa/pipe/xlib/xm_winsys_aub.c
@@ -101,7 +101,7 @@
 
    assert(sbo->data);
 
-   if (flags & PIPE_BUFFER_FLAG_WRITE)
+   if (flags & PIPE_BUFFER_USAGE_CPU_WRITE)
       sbo->dump_on_unmap = 1;
 
    sbo->map_count++;
@@ -150,61 +150,6 @@
 }
 
 
-static int aub_buffer_data(struct pipe_winsys *winsys, 
-			      struct pipe_buffer_handle *buf,
-			      unsigned size, const void *data,
-			      unsigned usage )
-{
-   struct aub_pipe_winsys *iws = aub_pipe_winsys(winsys);
-   struct aub_buffer *sbo = aub_bo(buf);
-
-   /* Could reuse buffers that are not referenced in current
-    * batchbuffer.  Can't do that atm, so always reallocate:
-    */
-   if (1 || sbo->size < size) {
-      assert(iws->used + size < iws->size);
-      sbo->data = iws->pool + iws->used;
-      sbo->offset = AUB_BUF_START + iws->used;
-      iws->used += align(size, 4096);
-   }
-
-   sbo->size = size;
-
-   if (data != NULL) {
-      memcpy(sbo->data, data, size);
-
-      brw_aub_gtt_data( iws->aubfile, 
-			sbo->offset,
-			sbo->data,
-			sbo->size,
-			0,
-			0 );
-   }
-   return 0;
-}
-
-static int aub_buffer_subdata(struct pipe_winsys *winsys, 
-				 struct pipe_buffer_handle *buf,
-				 unsigned long offset, 
-				 unsigned long size, 
-				 const void *data)
-{
-   struct aub_pipe_winsys *iws = aub_pipe_winsys(winsys);
-   struct aub_buffer *sbo = aub_bo(buf);
-
-   assert(sbo->size > offset + size);
-   memcpy(sbo->data + offset, data, size);
-
-   brw_aub_gtt_data( iws->aubfile, 
-		     sbo->offset + offset,
-		     sbo->data + offset,
-		     size,
-		     0,
-		     0 );
-   return 0;
-}
-
-
 void xmesa_buffer_subdata_aub(struct pipe_winsys *winsys, 
 			      struct pipe_buffer_handle *buf,
 			      unsigned long offset, 
@@ -258,29 +203,30 @@
 
 
 
-static int aub_buffer_get_subdata(struct pipe_winsys *winsys, 
-				     struct pipe_buffer_handle *buf,
-				     unsigned long offset, 
-				     unsigned long size, 
-				     void *data)
-{
-   struct aub_buffer *sbo = aub_bo(buf);
-   assert(sbo->size >= offset + size);
-   memcpy(data, sbo->data + offset, size);
-   return 0;
-}
-
 /* Pipe has no concept of pools.  We choose the tex/region pool
  * for all buffers.
  */
 static struct pipe_buffer_handle *
 aub_buffer_create(struct pipe_winsys *winsys,
-                     unsigned alignment,
-                     unsigned flags,
-                     unsigned hint)
+                  unsigned alignment,
+                  unsigned usage,
+                  unsigned size)
 {
+   struct aub_pipe_winsys *iws = aub_pipe_winsys(winsys);
    struct aub_buffer *sbo = CALLOC_STRUCT(aub_buffer);
+
    sbo->refcount = 1;
+
+   /* Could reuse buffers that are not referenced in current
+    * batchbuffer.  Can't do that atm, so always reallocate:
+    */
+   assert(iws->used + size < iws->size);
+   sbo->data = iws->pool + iws->used;
+   sbo->offset = AUB_BUF_START + iws->used;
+   iws->used += align(size, 4096);
+
+   sbo->size = size;
+
    return pipe_bo(sbo);
 }
 
@@ -288,17 +234,14 @@
 static struct pipe_buffer_handle *
 aub_user_buffer_create(struct pipe_winsys *winsys, void *ptr, unsigned bytes)
 {
-   struct aub_buffer *sbo = CALLOC_STRUCT(aub_buffer);
-
-   sbo->refcount = 1;
+   struct aub_buffer *sbo;
 
    /* Lets hope this is meant for upload, not as a result!  
     */
-   aub_buffer_data( winsys, 
-		    pipe_bo(sbo),
-		    bytes, 
-		    ptr,
-		    0 );
+   sbo = aub_bo(aub_buffer_create( winsys, 0, 0, 0 ));
+
+   sbo->data = ptr;
+   sbo->size = bytes;
 
    return pipe_bo(sbo);
 }
@@ -345,7 +288,6 @@
                                unsigned flags)
 {
     const unsigned alignment = 64;
-    int ret;
 
     surf->width = width;
     surf->height = height;
@@ -354,20 +296,12 @@
     surf->pitch = round_up(width, alignment / surf->cpp);
 
     assert(!surf->buffer);
-    surf->buffer = winsys->buffer_create(winsys, alignment, 0, 0);
+    surf->buffer = winsys->buffer_create(winsys, alignment,
+                                         PIPE_BUFFER_USAGE_PIXEL,
+                                         surf->pitch * surf->cpp * height);
     if(!surf->buffer)
         return -1;
 
-    ret = winsys->buffer_data(winsys,
-                              surf->buffer,
-                              surf->pitch * surf->cpp * height,
-                              NULL,
-                              0);
-    if(ret) {
-        winsys->buffer_reference(winsys, &surf->buffer, NULL);
-        return ret;
-    }
-
     return 0;
 }
 
@@ -418,9 +352,6 @@
    iws->winsys.buffer_map = aub_buffer_map;
    iws->winsys.buffer_unmap = aub_buffer_unmap;
    iws->winsys.buffer_reference = aub_buffer_reference;
-   iws->winsys.buffer_data = aub_buffer_data;
-   iws->winsys.buffer_subdata = aub_buffer_subdata;
-   iws->winsys.buffer_get_subdata = aub_buffer_get_subdata;
    iws->winsys.flush_frontbuffer = aub_flush_frontbuffer;
    iws->winsys.printf = aub_printf;
    iws->winsys.get_name = aub_get_name;