[PATCH 0/2] Make the vmwgfx driver reasonably DMA-API compliant

2013-11-04 Thread Thomas Hellstrom
These patches makes the vmwgfx driver use the DMA API to obtain valid
device addresses rather than blindly using physical addresses.

The main motivation is to be able to use a virtual IOMMU in the future.

Other TTM drivers typically map pages one by one rather than using a
scatter-gather list, but since we can benefit from having a single dma
address region set up by the IOMMU, we use a scatter-gather list instead.

Finally to be able to handle all the dma mapping modes, we locally extend the
scatter-gather list page iterator to handle also the direct physical- and
coherent cases.

Finally, the TTM DMA page pool is enabled also when the Intel IOMMU is active

--
Android is increasing in popularity, but the open development platform that
developers love is also attractive to malware creators. Download this white
paper to learn more about secure code signing practices that can help keep
Android apps secure.
http://pubads.g.doubleclick.net/gampad/clk?id=65839951iu=/4140/ostg.clktrk
--
___
Dri-devel mailing list
Dri-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/dri-devel


[PATCH 2/2] drm/vmwgfx: Use the linux DMA api to get valid device addresses of pages

2013-11-04 Thread Thomas Hellstrom
The code handles three different cases:
1) physical page addresses. The ttm page array is used.
2) DMA subsystem addresses. A scatter-gather list is used.
3) Coherent pages. The ttm dma pool is used, together with the dma_ttm
array os dma_addr_t

Signed-off-by: Thomas Hellstrom thellst...@vmware.com
Reviewed-by: Jakob Bornecrantz ja...@vmware.com
---
 drivers/gpu/drm/vmwgfx/vmwgfx_buffer.c |  379 ++--
 drivers/gpu/drm/vmwgfx/vmwgfx_drv.c|   87 +++-
 drivers/gpu/drm/vmwgfx/vmwgfx_drv.h|   98 -
 drivers/gpu/drm/vmwgfx/vmwgfx_gmr.c|  150 ++---
 4 files changed, 620 insertions(+), 94 deletions(-)

diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_buffer.c 
b/drivers/gpu/drm/vmwgfx/vmwgfx_buffer.c
index 96dc84d..7776e6f 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_buffer.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_buffer.c
@@ -141,37 +141,374 @@ struct ttm_placement vmw_srf_placement = {
 };
 
 struct vmw_ttm_tt {
-   struct ttm_tt ttm;
+   struct ttm_dma_tt dma_ttm;
struct vmw_private *dev_priv;
int gmr_id;
+   struct sg_table sgt;
+   struct vmw_sg_table vsgt;
+   uint64_t sg_alloc_size;
+   bool mapped;
 };
 
+/**
+ * Helper functions to advance a struct vmw_piter iterator.
+ *
+ * @viter: Pointer to the iterator.
+ *
+ * These functions return false if past the end of the list,
+ * true otherwise. Functions are selected depending on the current
+ * DMA mapping mode.
+ */
+static bool __vmw_piter_non_sg_next(struct vmw_piter *viter)
+{
+   return ++(viter-i)  viter-num_pages;
+}
+
+static bool __vmw_piter_sg_next(struct vmw_piter *viter)
+{
+   return __sg_page_iter_next(viter-iter);
+}
+
+
+/**
+ * Helper functions to return a pointer to the current page.
+ *
+ * @viter: Pointer to the iterator
+ *
+ * These functions return a pointer to the page currently
+ * pointed to by @viter. Functions are selected depending on the
+ * current mapping mode.
+ */
+static struct page *__vmw_piter_non_sg_page(struct vmw_piter *viter)
+{
+   return viter-pages[viter-i];
+}
+
+static struct page *__vmw_piter_sg_page(struct vmw_piter *viter)
+{
+   return sg_page_iter_page(viter-iter);
+}
+
+
+/**
+ * Helper functions to return the DMA address of the current page.
+ *
+ * @viter: Pointer to the iterator
+ *
+ * These functions return the DMA address of the page currently
+ * pointed to by @viter. Functions are selected depending on the
+ * current mapping mode.
+ */
+static dma_addr_t __vmw_piter_phys_addr(struct vmw_piter *viter)
+{
+   return page_to_phys(viter-pages[viter-i]);
+}
+
+static dma_addr_t __vmw_piter_dma_addr(struct vmw_piter *viter)
+{
+   return viter-addrs[viter-i];
+}
+
+static dma_addr_t __vmw_piter_sg_addr(struct vmw_piter *viter)
+{
+   return sg_page_iter_dma_address(viter-iter);
+}
+
+
+/**
+ * vmw_piter_start - Initialize a struct vmw_piter.
+ *
+ * @viter: Pointer to the iterator to initialize
+ * @vsgt: Pointer to a struct vmw_sg_table to initialize from
+ *
+ * Note that we're following the convention of __sg_page_iter_start, so that
+ * the iterator doesn't point to a valid page after initialization; it has
+ * to be advanced one step first.
+ */
+void vmw_piter_start(struct vmw_piter *viter, const struct vmw_sg_table *vsgt,
+unsigned long p_offset)
+{
+   viter-i = p_offset - 1;
+   viter-num_pages = vsgt-num_pages;
+   switch (vsgt-mode) {
+   case vmw_dma_phys:
+   viter-next = __vmw_piter_non_sg_next;
+   viter-dma_address = __vmw_piter_phys_addr;
+   viter-page = __vmw_piter_non_sg_page;
+   viter-pages = vsgt-pages;
+   break;
+   case vmw_dma_alloc_coherent:
+   viter-next = __vmw_piter_non_sg_next;
+   viter-dma_address = __vmw_piter_dma_addr;
+   viter-page = __vmw_piter_non_sg_page;
+   viter-addrs = vsgt-addrs;
+   break;
+   case vmw_dma_map_populate:
+   case vmw_dma_map_bind:
+   viter-next = __vmw_piter_sg_next;
+   viter-dma_address = __vmw_piter_sg_addr;
+   viter-page = __vmw_piter_sg_page;
+   __sg_page_iter_start(viter-iter, vsgt-sgt-sgl,
+vsgt-sgt-orig_nents, p_offset);
+   break;
+   default:
+   BUG();
+   }
+}
+
+/**
+ * vmw_ttm_unmap_from_dma - unmap  device addresses previsouly mapped for
+ * TTM pages
+ *
+ * @vmw_tt: Pointer to a struct vmw_ttm_backend
+ *
+ * Used to free dma mappings previously mapped by vmw_ttm_map_for_dma.
+ */
+static void vmw_ttm_unmap_from_dma(struct vmw_ttm_tt *vmw_tt)
+{
+   struct device *dev = vmw_tt-dev_priv-dev-dev;
+
+   dma_unmap_sg(dev, vmw_tt-sgt.sgl, vmw_tt-sgt.nents,
+   DMA_BIDIRECTIONAL);
+   vmw_tt-sgt.nents = vmw_tt-sgt.orig_nents;
+}
+
+/**
+ * vmw_ttm_map_for_dma - map TTM pages to get device addresses
+ *
+ * 

[PATCH 1/2] drm/ttm: Enable the dma page pool also for intel IOMMUs

2013-11-04 Thread Thomas Hellstrom
Used by the vmwgfx driver

Signed-off-by: Thomas Hellstrom thellst...@vmware.com
Reviewed-by: Jakob Bornecrantz ja...@vmware.com
---
 drivers/gpu/drm/ttm/Makefile |6 +-
 drivers/gpu/drm/ttm/ttm_page_alloc_dma.c |3 +++
 include/drm/ttm/ttm_page_alloc.h |   11 ++-
 3 files changed, 14 insertions(+), 6 deletions(-)

diff --git a/drivers/gpu/drm/ttm/Makefile b/drivers/gpu/drm/ttm/Makefile
index b2b33dd..b433b9f 100644
--- a/drivers/gpu/drm/ttm/Makefile
+++ b/drivers/gpu/drm/ttm/Makefile
@@ -5,10 +5,6 @@ ccflags-y := -Iinclude/drm
 ttm-y := ttm_agp_backend.o ttm_memory.o ttm_tt.o ttm_bo.o \
ttm_bo_util.o ttm_bo_vm.o ttm_module.o \
ttm_object.o ttm_lock.o ttm_execbuf_util.o ttm_page_alloc.o \
-   ttm_bo_manager.o
-
-ifeq ($(CONFIG_SWIOTLB),y)
-ttm-y += ttm_page_alloc_dma.o
-endif
+   ttm_bo_manager.o ttm_page_alloc_dma.o
 
 obj-$(CONFIG_DRM_TTM) += ttm.o
diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc_dma.c 
b/drivers/gpu/drm/ttm/ttm_page_alloc_dma.c
index 7957bee..fb8259f 100644
--- a/drivers/gpu/drm/ttm/ttm_page_alloc_dma.c
+++ b/drivers/gpu/drm/ttm/ttm_page_alloc_dma.c
@@ -33,6 +33,7 @@
  *   when freed).
  */
 
+#if defined(CONFIG_SWIOTLB) || defined(CONFIG_INTEL_IOMMU)
 #define pr_fmt(fmt) [TTM]  fmt
 
 #include linux/dma-mapping.h
@@ -1142,3 +1143,5 @@ int ttm_dma_page_alloc_debugfs(struct seq_file *m, void 
*data)
return 0;
 }
 EXPORT_SYMBOL_GPL(ttm_dma_page_alloc_debugfs);
+
+#endif
diff --git a/include/drm/ttm/ttm_page_alloc.h b/include/drm/ttm/ttm_page_alloc.h
index 706b962..d1f61bf 100644
--- a/include/drm/ttm/ttm_page_alloc.h
+++ b/include/drm/ttm/ttm_page_alloc.h
@@ -62,7 +62,7 @@ extern void ttm_pool_unpopulate(struct ttm_tt *ttm);
 extern int ttm_page_alloc_debugfs(struct seq_file *m, void *data);
 
 
-#ifdef CONFIG_SWIOTLB
+#if defined(CONFIG_SWIOTLB) || defined(CONFIG_INTEL_IOMMU)
 /**
  * Initialize pool allocator.
  */
@@ -94,6 +94,15 @@ static inline int ttm_dma_page_alloc_debugfs(struct seq_file 
*m, void *data)
 {
return 0;
 }
+static inline int ttm_dma_populate(struct ttm_dma_tt *ttm_dma,
+  struct device *dev)
+{
+   return -ENOMEM;
+}
+static inline void ttm_dma_unpopulate(struct ttm_dma_tt *ttm_dma,
+ struct device *dev)
+{
+}
 #endif
 
 #endif
-- 
1.7.10.4

--
Android is increasing in popularity, but the open development platform that
developers love is also attractive to malware creators. Download this white
paper to learn more about secure code signing practices that can help keep
Android apps secure.
http://pubads.g.doubleclick.net/gampad/clk?id=65839951iu=/4140/ostg.clktrk
--
___
Dri-devel mailing list
Dri-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/dri-devel


Re: [PATCH 2/2] drm/vmwgfx: Use the linux DMA api to get valid device addresses of pages

2013-11-04 Thread Daniel Vetter
On Mon, Nov 04, 2013 at 05:57:39AM -0800, Thomas Hellstrom wrote:
 The code handles three different cases:
 1) physical page addresses. The ttm page array is used.
 2) DMA subsystem addresses. A scatter-gather list is used.
 3) Coherent pages. The ttm dma pool is used, together with the dma_ttm
 array os dma_addr_t
 
 Signed-off-by: Thomas Hellstrom thellst...@vmware.com
 Reviewed-by: Jakob Bornecrantz ja...@vmware.com

For i915.ko use we've added page iterators which should walk the physical
backing storage.

commit a321e91b6d73ed011ffceed384c40d2785cf723b
Author: Imre Deak imre.d...@intel.com
Date:   Wed Feb 27 17:02:56 2013 -0800

lib/scatterlist: add simple page iterator

Now we've unified all our backing storage handling around sg tables (even
for stolen memory), so maybe that's not useful for you guys. Just figured
I'll drop this here, it imo made our code look fairly tidy.

Cheers, Daniel

 ---
  drivers/gpu/drm/vmwgfx/vmwgfx_buffer.c |  379 
 ++--
  drivers/gpu/drm/vmwgfx/vmwgfx_drv.c|   87 +++-
  drivers/gpu/drm/vmwgfx/vmwgfx_drv.h|   98 -
  drivers/gpu/drm/vmwgfx/vmwgfx_gmr.c|  150 ++---
  4 files changed, 620 insertions(+), 94 deletions(-)
 
 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_buffer.c 
 b/drivers/gpu/drm/vmwgfx/vmwgfx_buffer.c
 index 96dc84d..7776e6f 100644
 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_buffer.c
 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_buffer.c
 @@ -141,37 +141,374 @@ struct ttm_placement vmw_srf_placement = {
  };
  
  struct vmw_ttm_tt {
 - struct ttm_tt ttm;
 + struct ttm_dma_tt dma_ttm;
   struct vmw_private *dev_priv;
   int gmr_id;
 + struct sg_table sgt;
 + struct vmw_sg_table vsgt;
 + uint64_t sg_alloc_size;
 + bool mapped;
  };
  
 +/**
 + * Helper functions to advance a struct vmw_piter iterator.
 + *
 + * @viter: Pointer to the iterator.
 + *
 + * These functions return false if past the end of the list,
 + * true otherwise. Functions are selected depending on the current
 + * DMA mapping mode.
 + */
 +static bool __vmw_piter_non_sg_next(struct vmw_piter *viter)
 +{
 + return ++(viter-i)  viter-num_pages;
 +}
 +
 +static bool __vmw_piter_sg_next(struct vmw_piter *viter)
 +{
 + return __sg_page_iter_next(viter-iter);
 +}
 +
 +
 +/**
 + * Helper functions to return a pointer to the current page.
 + *
 + * @viter: Pointer to the iterator
 + *
 + * These functions return a pointer to the page currently
 + * pointed to by @viter. Functions are selected depending on the
 + * current mapping mode.
 + */
 +static struct page *__vmw_piter_non_sg_page(struct vmw_piter *viter)
 +{
 + return viter-pages[viter-i];
 +}
 +
 +static struct page *__vmw_piter_sg_page(struct vmw_piter *viter)
 +{
 + return sg_page_iter_page(viter-iter);
 +}
 +
 +
 +/**
 + * Helper functions to return the DMA address of the current page.
 + *
 + * @viter: Pointer to the iterator
 + *
 + * These functions return the DMA address of the page currently
 + * pointed to by @viter. Functions are selected depending on the
 + * current mapping mode.
 + */
 +static dma_addr_t __vmw_piter_phys_addr(struct vmw_piter *viter)
 +{
 + return page_to_phys(viter-pages[viter-i]);
 +}
 +
 +static dma_addr_t __vmw_piter_dma_addr(struct vmw_piter *viter)
 +{
 + return viter-addrs[viter-i];
 +}
 +
 +static dma_addr_t __vmw_piter_sg_addr(struct vmw_piter *viter)
 +{
 + return sg_page_iter_dma_address(viter-iter);
 +}
 +
 +
 +/**
 + * vmw_piter_start - Initialize a struct vmw_piter.
 + *
 + * @viter: Pointer to the iterator to initialize
 + * @vsgt: Pointer to a struct vmw_sg_table to initialize from
 + *
 + * Note that we're following the convention of __sg_page_iter_start, so that
 + * the iterator doesn't point to a valid page after initialization; it has
 + * to be advanced one step first.
 + */
 +void vmw_piter_start(struct vmw_piter *viter, const struct vmw_sg_table 
 *vsgt,
 +  unsigned long p_offset)
 +{
 + viter-i = p_offset - 1;
 + viter-num_pages = vsgt-num_pages;
 + switch (vsgt-mode) {
 + case vmw_dma_phys:
 + viter-next = __vmw_piter_non_sg_next;
 + viter-dma_address = __vmw_piter_phys_addr;
 + viter-page = __vmw_piter_non_sg_page;
 + viter-pages = vsgt-pages;
 + break;
 + case vmw_dma_alloc_coherent:
 + viter-next = __vmw_piter_non_sg_next;
 + viter-dma_address = __vmw_piter_dma_addr;
 + viter-page = __vmw_piter_non_sg_page;
 + viter-addrs = vsgt-addrs;
 + break;
 + case vmw_dma_map_populate:
 + case vmw_dma_map_bind:
 + viter-next = __vmw_piter_sg_next;
 + viter-dma_address = __vmw_piter_sg_addr;
 + viter-page = __vmw_piter_sg_page;
 + __sg_page_iter_start(viter-iter, vsgt-sgt-sgl,
 +  vsgt-sgt-orig_nents, p_offset);
 + break;
 + default:
 

Re: [PATCH 2/2] drm/vmwgfx: Use the linux DMA api to get valid device addresses of pages

2013-11-04 Thread Thomas Hellstrom
On 11/04/2013 05:27 PM, Daniel Vetter wrote:
 On Mon, Nov 04, 2013 at 05:57:39AM -0800, Thomas Hellstrom wrote:
 The code handles three different cases:
 1) physical page addresses. The ttm page array is used.
 2) DMA subsystem addresses. A scatter-gather list is used.
 3) Coherent pages. The ttm dma pool is used, together with the dma_ttm
 array os dma_addr_t

 Signed-off-by: Thomas Hellstrom thellst...@vmware.com
 Reviewed-by: Jakob Bornecrantz ja...@vmware.com
 For i915.ko use we've added page iterators which should walk the physical
 backing storage.

 commit a321e91b6d73ed011ffceed384c40d2785cf723b
 Author: Imre Deak imre.d...@intel.com
 Date:   Wed Feb 27 17:02:56 2013 -0800

  lib/scatterlist: add simple page iterator



Yes, I saw those iterators, (nice stuff!) and my patch are using them as 
a base class, handling also
TTM page - and dma address arrays basically with the same interface. In 
the long run we might
want to move ttm over to sg_tables as well.

One problem, though, the page iterators break in the mapped case where
sg_dma_len(sg) != sg_len(sg).
An iommu implementation is allowed to reduce the sg list to a single 
segment, in which case those page
iterators will fall apart. I was planning to see if I could fix that up, 
but unfortunately there is no generic
dma_to_phys.
It all works now because intel_iommu, amd_iommu and swiotlb all keep the 
number of entries in an
sg list across mapping

/Thomas

--
Android is increasing in popularity, but the open development platform that
developers love is also attractive to malware creators. Download this white
paper to learn more about secure code signing practices that can help keep
Android apps secure.
http://pubads.g.doubleclick.net/gampad/clk?id=65839951iu=/4140/ostg.clktrk
--
___
Dri-devel mailing list
Dri-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/dri-devel


Re: [PATCH 0/2] Make the vmwgfx driver reasonably DMA-API compliant

2013-11-04 Thread Thomas Hellstrom
On 11/04/2013 05:30 PM, Konrad Rzeszutek Wilk wrote:
 On Mon, Nov 04, 2013 at 05:57:37AM -0800, Thomas Hellstrom wrote:
 These patches makes the vmwgfx driver use the DMA API to obtain valid
 device addresses rather than blindly using physical addresses.

 The main motivation is to be able to use a virtual IOMMU in the future.
 Ooooh. Neat! Are there any RFC patches available?

Nope, not yet.

Thanks,
Thomas

--
Android is increasing in popularity, but the open development platform that
developers love is also attractive to malware creators. Download this white
paper to learn more about secure code signing practices that can help keep
Android apps secure.
http://pubads.g.doubleclick.net/gampad/clk?id=65839951iu=/4140/ostg.clktrk
--
___
Dri-devel mailing list
Dri-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/dri-devel


Re: [PATCH 1/2] drm/ttm: Enable the dma page pool also for intel IOMMUs

2013-11-04 Thread Thomas Hellstrom
On 11/04/2013 05:34 PM, Konrad Rzeszutek Wilk wrote:
 On Mon, Nov 04, 2013 at 05:57:38AM -0800, Thomas Hellstrom wrote:
 Used by the vmwgfx driver
 That looks OK to me. And baremetal should not be
 affected as the Intel VT-d driver turns of the SWIOTLB
 driver - so it will still use the classic ttm pool code.

 Reviewed-by: Konrad Rzeszutek Wilk konrad.w...@oracle.com


Thanks for reviewing, Konrad.

/Thomas

--
Android is increasing in popularity, but the open development platform that
developers love is also attractive to malware creators. Download this white
paper to learn more about secure code signing practices that can help keep
Android apps secure.
http://pubads.g.doubleclick.net/gampad/clk?id=65839951iu=/4140/ostg.clktrk
--
___
Dri-devel mailing list
Dri-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/dri-devel


Re: [PATCH 2/2] drm/vmwgfx: Use the linux DMA api to get valid device addresses of pages

2013-11-04 Thread Thomas Hellstrom
On 11/04/2013 05:40 PM, Konrad Rzeszutek Wilk wrote:
 On Mon, Nov 04, 2013 at 05:57:39AM -0800, Thomas Hellstrom wrote:
 The code handles three different cases:
 1) physical page addresses. The ttm page array is used.
 2) DMA subsystem addresses. A scatter-gather list is used.
 3) Coherent pages. The ttm dma pool is used, together with the dma_ttm
 array os dma_addr_t

 Signed-off-by: Thomas Hellstrom thellst...@vmware.com
 Reviewed-by: Jakob Bornecrantz ja...@vmware.com
 I looked at it from the TTM DMA perspective and it looks OK for me.

Great. Thanks,

Thomas

--
Android is increasing in popularity, but the open development platform that
developers love is also attractive to malware creators. Download this white
paper to learn more about secure code signing practices that can help keep
Android apps secure.
http://pubads.g.doubleclick.net/gampad/clk?id=65839951iu=/4140/ostg.clktrk
--
___
Dri-devel mailing list
Dri-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/dri-devel


Re: [Mesa3d-dev] [PATCH 3/6] dri/intel: Add explicit size parameter to intel_region_alloc_for_fd

2013-11-04 Thread Ian Romanick
On 10/31/2013 04:13 PM, Keith Packard wrote:
 Instead of assuming that the size will be height * pitch, have the caller pass
 in the size explicitly.
 
 Signed-off-by: Keith Packard kei...@keithp.com

One nit below.  With that changed,

Reviewed-by: Ian Romanick ian.d.roman...@intel.com

 ---
  src/mesa/drivers/dri/i915/intel_regions.c | 4 ++--
  src/mesa/drivers/dri/i915/intel_regions.h | 2 +-
  src/mesa/drivers/dri/i915/intel_screen.c  | 2 +-
  src/mesa/drivers/dri/i965/intel_regions.c | 4 ++--
  src/mesa/drivers/dri/i965/intel_regions.h | 1 +
  src/mesa/drivers/dri/i965/intel_screen.c  | 2 +-
  6 files changed, 8 insertions(+), 7 deletions(-)
 
 diff --git a/src/mesa/drivers/dri/i915/intel_regions.c 
 b/src/mesa/drivers/dri/i915/intel_regions.c
 index 44f7030..9f5b89e 100644
 --- a/src/mesa/drivers/dri/i915/intel_regions.c
 +++ b/src/mesa/drivers/dri/i915/intel_regions.c
 @@ -209,6 +209,7 @@ struct intel_region *
  intel_region_alloc_for_fd(struct intel_screen *screen,
GLuint cpp,
GLuint width, GLuint height, GLuint pitch,
 +  GLuint size,
int fd, const char *name)
  {
 struct intel_region *region;
 @@ -216,8 +217,7 @@ intel_region_alloc_for_fd(struct intel_screen *screen,
 int ret;
 uint32_t bit_6_swizzle, tiling;
  
 -   buffer = drm_intel_bo_gem_create_from_prime(screen-bufmgr,
 -   fd, height * pitch);
 +   buffer = drm_intel_bo_gem_create_from_prime(screen-bufmgr, fd, size);
 if (buffer == NULL)
return NULL;
 ret = drm_intel_bo_get_tiling(buffer, tiling, bit_6_swizzle);
 diff --git a/src/mesa/drivers/dri/i915/intel_regions.h 
 b/src/mesa/drivers/dri/i915/intel_regions.h
 index 5c612a9..6bc4a42 100644
 --- a/src/mesa/drivers/dri/i915/intel_regions.h
 +++ b/src/mesa/drivers/dri/i915/intel_regions.h
 @@ -91,7 +91,7 @@ struct intel_region *
  intel_region_alloc_for_fd(struct intel_screen *screen,
GLuint cpp,
GLuint width, GLuint height, GLuint pitch,
 -  int fd, const char *name);
 +  GLuint size, int fd, const char *name);
  
  bool
  intel_region_flink(struct intel_region *region, uint32_t *name);
 diff --git a/src/mesa/drivers/dri/i915/intel_screen.c 
 b/src/mesa/drivers/dri/i915/intel_screen.c
 index 3f54752..085e894 100644
 --- a/src/mesa/drivers/dri/i915/intel_screen.c
 +++ b/src/mesa/drivers/dri/i915/intel_screen.c
 @@ -653,7 +653,7 @@ intel_create_image_from_fds(__DRIscreen *screen,
return NULL;
  
 image-region = intel_region_alloc_for_fd(intelScreen,
 - 1, width, height,
 + 1, width, height, height * 
 strides[0],
   strides[0], fds[0], image);
 if (image-region == NULL) {
free(image);
 diff --git a/src/mesa/drivers/dri/i965/intel_regions.c 
 b/src/mesa/drivers/dri/i965/intel_regions.c
 index a6b80fd..3920f4f 100644
 --- a/src/mesa/drivers/dri/i965/intel_regions.c
 +++ b/src/mesa/drivers/dri/i965/intel_regions.c
 @@ -209,6 +209,7 @@ struct intel_region *
  intel_region_alloc_for_fd(struct intel_screen *screen,
GLuint cpp,
GLuint width, GLuint height, GLuint pitch,
 +  GLuint size,
int fd, const char *name)
  {
 struct intel_region *region;
 @@ -216,8 +217,7 @@ intel_region_alloc_for_fd(struct intel_screen *screen,
 int ret;
 uint32_t bit_6_swizzle, tiling;
  
 -   buffer = drm_intel_bo_gem_create_from_prime(screen-bufmgr,
 -   fd, height * pitch);
 +   buffer = drm_intel_bo_gem_create_from_prime(screen-bufmgr, fd, size);
 if (buffer == NULL)
return NULL;
 ret = drm_intel_bo_get_tiling(buffer, tiling, bit_6_swizzle);
 diff --git a/src/mesa/drivers/dri/i965/intel_regions.h 
 b/src/mesa/drivers/dri/i965/intel_regions.h
 index f08a113..05dfef3 100644
 --- a/src/mesa/drivers/dri/i965/intel_regions.h
 +++ b/src/mesa/drivers/dri/i965/intel_regions.h
 @@ -92,6 +92,7 @@ struct intel_region *
  intel_region_alloc_for_fd(struct intel_screen *screen,
GLuint cpp,
GLuint width, GLuint height, GLuint pitch,
 +  GLuint size,

Since this isn't exposed to the GL API, use either unsigned or size_t.

int fd, const char *name);
  
  bool
 diff --git a/src/mesa/drivers/dri/i965/intel_screen.c 
 b/src/mesa/drivers/dri/i965/intel_screen.c
 index eafafa2..0bd0789 100644
 --- a/src/mesa/drivers/dri/i965/intel_screen.c
 +++ b/src/mesa/drivers/dri/i965/intel_screen.c
 @@ -712,7 +712,7 @@ intel_create_image_from_fds(__DRIscreen *screen,
return NULL;
  
 image-region =