Re: [PATCH hwc v1] drm_hwcomposer: Add CONTRIBUTING file

2017-09-22 Thread Zach Reizner
On Thu, Sep 21, 2017 at 5:37 PM, Robert Foss <robert.f...@collabora.com> wrote:
> Some basic guidelines for contributions could come in handy.
>
> These are copied from IGT and modified to be suitable.
>
> Signed-off-by: Robert Foss <robert.f...@collabora.com>
Reviewed-by: Zach Reizner <za...@chromium.org>
> ---
>  CONTRIBUTING | 31 +++
>  1 file changed, 31 insertions(+)
>  create mode 100644 CONTRIBUTING
>
> diff --git a/CONTRIBUTING b/CONTRIBUTING
> new file mode 100644
> index 000..f1b4775
> --- /dev/null
> +++ b/CONTRIBUTING
> @@ -0,0 +1,31 @@
> +Patches to drm_hwcomposer are very much welcome, we really want this to be 
> the
> +universal HW composer implementation for Android and similar platforms
> +So please bring on porting patches, bugfixes, improvements for documentation
> +and new features.
> +
> +A short list of contribution guidelines:
> +
> +- Please submit patches formatted with git send-email/git format-patch or
> +  equivalent to
> +
> +dri-devel <dri-devel@lists.freedesktop.org>
> +
> +  Please use --subject-prefix="PATCH hwc" so that drm_hwcomposer patches are 
> easily
> +  identified in the massive amount mails on dri-devel. To ensure this is 
> always
> +  done, run:
> +
> +git config format.subjectprefix "PATCH hwc"
> +
> +- drm_hwcomposer is Apache 2.0 Licensed and we require contributions to 
> follow the
> +  developer's certificate of origin: http://developercertificate.org/
> +
> +- When submitting new code please follow the naming conventions documented
> +  in the generated documentation. Also please make full use of all the 
> helpers and
> +  convenience macros provided by drm_hwcomposer. The below command can help 
> you
> +  with formatting of your patches:
> +  git diff | clang-format-diff-3.5 -p 1 -style=file
> +
> +- Harware specific changes should get tested on relevant platforms
> +  before committing.
> +
> +Happy hacking!
> --
> 2.11.0
>
___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel


Re: [hwc PATCH v1] drm_hwcomposer: reorder source layers according to zorder

2017-09-21 Thread Zach Reizner
On Thu, Sep 21, 2017 at 4:53 PM, Adrian Salido <sali...@google.com> wrote:
> Precomp layers may be added to the back at different points which may
> cause elements to be unsorted. Make sure that these are sorted after
> provisioning planes to ensure right composition based on zorder.
>
> Signed-off-by: Adrian Salido <sali...@google.com>
Reviewed-by: Zach Reizner <za...@chromium.org>
> ---
>  drmdisplaycomposition.cpp | 3 +++
>  1 file changed, 3 insertions(+)
>
> diff --git a/drmdisplaycomposition.cpp b/drmdisplaycomposition.cpp
> index 293160bfd012..0f8084b39706 100644
> --- a/drmdisplaycomposition.cpp
> +++ b/drmdisplaycomposition.cpp
> @@ -379,6 +379,9 @@ int DrmDisplayComposition::Plan(SquashState *squash,
>  if (!i.plane())
>continue;
>
> +// make sure that source layers are ordered based on zorder
> +std::sort(i.source_layers().begin(), i.source_layers().end());
> +
>  std::vector *container;
>  if (i.plane()->type() == DRM_PLANE_TYPE_PRIMARY)
>container = primary_planes;
> --
> 2.14.1.821.g8fa685d3b7-goog
>
> ___
> dri-devel mailing list
> dri-devel@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/dri-devel
___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel


Re: [hwc PATCH] drm_hwcomposer: Remove OWNERS

2017-09-21 Thread Zach Reizner
On Thu, Sep 21, 2017 at 2:49 PM, Robert Foss <robert.f...@collabora.com> wrote:
> Hey Sean,
>
> Wonderful!
>
> Feel free to add my r-b.
>
> Reviewed-by: Robert Foss <robert.f...@collabora.com>
>
> On Thu, 2017-09-21 at 14:46 -0700, Sean Paul wrote:
>> Where we're going, we don't need no stickin' OWNERS.
>>
>> Now that drm_hwcomposer is hosted on fdo, we're going to support the
>> de-centralised committer model.
>>
>> Cc: Marissa Wall <maris...@google.com>
>> Cc: Rob Clark <robdcl...@gmail.com>
>> Cc: Robert Foss <robert.f...@collabora.com>
>> Cc: Rob Herring <r...@kernel.org>
>> Cc: Stephane Marchesin <marc...@chromium.org>
>> Cc: Zach Reizner <za...@chromium.org>
Reviewed-by: Zach Reizner <za...@chromium.org>
>> Signed-off-by: Sean Paul <seanp...@chromium.org>
>> ---
>>  OWNERS | 4 
>>  1 file changed, 4 deletions(-)
>>  delete mode 100644 OWNERS
>>
>> diff --git a/OWNERS b/OWNERS
>> deleted file mode 100644
>> index 4e41276..000
>> --- a/OWNERS
>> +++ /dev/null
>> @@ -1,4 +0,0 @@
>> -marc...@chromium.org
>> -maris...@google.com
>> -seanp...@chromium.org
>> -za...@chromium.org
___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel


[PATCH 3/3] drm/vgem: Attach sw fences to exported vGEM dma-buf (ioctl)

2016-06-30 Thread Zach Reizner
On Thu, Jun 23, 2016 at 10:35 AM Chris Wilson 
wrote:

> vGEM buffers are useful for passing data between software clients and
> hardware renders. By allowing the user to create and attach fences to
> the exported vGEM buffers (on the dma-buf), the user can implement a
> deferred renderer and queue hardware operations like flipping and then
> signal the buffer readiness (i.e. this allows the user to schedule
> operations out-of-order, but have them complete in-order).
>
> This also makes it much easier to write tightly controlled testcases for
> dma-buf fencing and signaling between hardware drivers.
>
> Testcase: igt/vgem_basic/dmabuf-fence
> Signed-off-by: Chris Wilson 
> Cc: Sean Paul 
> Cc: Zach Reizner 
> ---
>  drivers/gpu/drm/vgem/Makefile |   2 +-
>  drivers/gpu/drm/vgem/vgem_drv.c   |  34 ++
>  drivers/gpu/drm/vgem/vgem_drv.h   |  18 
>  drivers/gpu/drm/vgem/vgem_fence.c | 217
> ++
>  include/uapi/drm/vgem_drm.h   |  62 +++
>  5 files changed, 332 insertions(+), 1 deletion(-)
>  create mode 100644 drivers/gpu/drm/vgem/vgem_fence.c
>  create mode 100644 include/uapi/drm/vgem_drm.h
>
> diff --git a/drivers/gpu/drm/vgem/Makefile b/drivers/gpu/drm/vgem/Makefile
> index 3f4c7b842028..bfcdea1330e6 100644
> --- a/drivers/gpu/drm/vgem/Makefile
> +++ b/drivers/gpu/drm/vgem/Makefile
> @@ -1,4 +1,4 @@
>  ccflags-y := -Iinclude/drm
> -vgem-y := vgem_drv.o
> +vgem-y := vgem_drv.o vgem_fence.o
>
>  obj-$(CONFIG_DRM_VGEM) += vgem.o
> diff --git a/drivers/gpu/drm/vgem/vgem_drv.c
> b/drivers/gpu/drm/vgem/vgem_drv.c
> index 69468b5f3d82..56e348701382 100644
> --- a/drivers/gpu/drm/vgem/vgem_drv.c
> +++ b/drivers/gpu/drm/vgem/vgem_drv.c
> @@ -83,6 +83,34 @@ static const struct vm_operations_struct
> vgem_gem_vm_ops = {
> .close = drm_gem_vm_close,
>  };
>
> +static int vgem_open(struct drm_device *dev, struct drm_file *file)
> +{
> +   struct vgem_file *vfile;
> +   int ret;
> +
> +   vfile = kzalloc(sizeof(*vfile), GFP_KERNEL);
> +   if (!vfile)
> +   return -ENOMEM;
> +
> +   file->driver_priv = vfile;
> +
> +   ret = vgem_fence_open(vfile);
> +   if (ret) {
> +   kfree(vfile);
> +   return ret;
> +   }
> +
> +   return 0;
> +}
> +
> +static void vgem_preclose(struct drm_device *dev, struct drm_file *file)
> +{
> +   struct vgem_file *vfile = file->driver_priv;
> +
> +   vgem_fence_close(vfile);
> +   kfree(vfile);
> +}
> +
>  /* ioctls */
>
>  static struct drm_gem_object *vgem_gem_create(struct drm_device *dev,
> @@ -164,6 +192,8 @@ unref:
>  }
>
>  static struct drm_ioctl_desc vgem_ioctls[] = {
> +   DRM_IOCTL_DEF_DRV(VGEM_FENCE_ATTACH, vgem_fence_attach_ioctl,
> DRM_AUTH|DRM_RENDER_ALLOW),
> +   DRM_IOCTL_DEF_DRV(VGEM_FENCE_SIGNAL, vgem_fence_signal_ioctl,
> DRM_AUTH|DRM_RENDER_ALLOW),
>  };
>
>  static int vgem_mmap(struct file *filp, struct vm_area_struct *vma)
> @@ -286,9 +316,12 @@ static int vgem_prime_mmap(struct drm_gem_object *obj,
>
>  static struct drm_driver vgem_driver = {
> .driver_features= DRIVER_GEM | DRIVER_PRIME,
> +   .open   = vgem_open,
> +   .preclose   = vgem_preclose,
> .gem_free_object_unlocked   = vgem_gem_free_object,
> .gem_vm_ops = _gem_vm_ops,
> .ioctls = vgem_ioctls,
> +   .num_ioctls = ARRAY_SIZE(vgem_ioctls),
> .fops   = _driver_fops,
>
> .dumb_create= vgem_gem_dumb_create,
> @@ -343,5 +376,6 @@ module_init(vgem_init);
>  module_exit(vgem_exit);
>
>  MODULE_AUTHOR("Red Hat, Inc.");
> +MODULE_AUTHOR("Intel Corporation");
>  MODULE_DESCRIPTION(DRIVER_DESC);
>  MODULE_LICENSE("GPL and additional rights");
> diff --git a/drivers/gpu/drm/vgem/vgem_drv.h
> b/drivers/gpu/drm/vgem/vgem_drv.h
> index 988cbaae7588..88ce21010e28 100644
> --- a/drivers/gpu/drm/vgem/vgem_drv.h
> +++ b/drivers/gpu/drm/vgem/vgem_drv.h
> @@ -32,9 +32,27 @@
>  #include 
>  #include 
>
> +#include 
> +
> +struct vgem_file {
> +   struct idr fence_idr;
> +   struct mutex fence_mutex;
> +   u64 fence_context;
> +   atomic_t fence_seqno;
> +};
> +
>  #define to_vgem_bo(x) container_of(x, struct drm_vgem_gem_object, base)
>  struct drm_vgem_gem_object {
> struct drm_gem_object base;
>  };
>
> +int vgem_fence_open(struct vgem_file *file);
> +int vgem_fence_attach_ioctl(struct drm_d

[PATCH v3] drm/vgem: Enable dmabuf interface for export

2016-06-27 Thread Zach Reizner
On Mon, Jun 20, 2016 at 1:07 PM Chris Wilson 
wrote:

> Enable the standard GEM dma-buf interface provided by the DRM core, but
> only for exporting the VGEM object. This allows passing around the VGEM
> objects created from the dumb interface and using them as sources
> elsewhere. Creating a VGEM object for a foriegn handle is not supported.
>
> v2: With additional completeness.
> v3: Need to clear the CPU cache upon exporting the dma-addresses.
>
> Testcase: igt/vgem_basic/dmabuf-*
> Testcase: igt/prime_vgem
> Signed-off-by: Chris Wilson 
> Cc: Sean Paul 
> Cc: Zach Reizner 
> ---
>  drivers/gpu/drm/vgem/vgem_drv.c | 112
> +++-
>  1 file changed, 111 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/vgem/vgem_drv.c
> b/drivers/gpu/drm/vgem/vgem_drv.c
> index e1a697d0662f..db48e837992d 100644
> --- a/drivers/gpu/drm/vgem/vgem_drv.c
> +++ b/drivers/gpu/drm/vgem/vgem_drv.c
> @@ -193,14 +193,124 @@ static const struct file_operations
> vgem_driver_fops = {
> .release= drm_release,
>  };
>
> +static void __put_pages(struct page **pages, long n_pages)
> +{
> +   while (n_pages--)
> +   put_page(pages[n_pages]);
> +   drm_free_large(pages);
> +}
> +
> +static int vgem_prime_pin(struct drm_gem_object *obj)
> +{
> +   long n_pages = obj->size >> PAGE_SHIFT;
> +   struct page **pages;
> +
> +   /* Flush the object from the CPU cache so that importers
> +* can rely on coherent indirect access via access the
> +* exported dma-address.
> +*/
> +   pages = drm_gem_get_pages(obj);
> +   if (IS_ERR(pages))
> +   return PTR_ERR(pages);
> +
> +   drm_clflush_pages(pages, n_pages);
> +   __put_pages(pages, n_pages);
> +
> +   return 0;
> +}
> +
> +static struct sg_table *vgem_prime_get_sg_table(struct drm_gem_object
> *obj)
> +{
> +   long n_pages = obj->size >> PAGE_SHIFT;
> +   struct sg_table *st;
> +   struct page **pages;
> +   int ret;
> +
> +   st = kmalloc(sizeof(struct sg_table), GFP_KERNEL);
> +   if (st == NULL)
> +   return ERR_PTR(-ENOMEM);
> +
> +   pages = drm_gem_get_pages(obj);
> +   if (IS_ERR(pages)) {
> +   ret = PTR_ERR(pages);
> +   goto err;
> +   }
> +
> +   ret = sg_alloc_table_from_pages(st, pages, n_pages,
> +   0, obj->size, GFP_KERNEL);
> +   __put_pages(pages, n_pages);
> +   if (ret)
> +   goto err;
> +
> +   return st;
> +
> +err:
> +   kfree(st);
> +   return ERR_PTR(ret);
> +}
> +
> +static void *vgem_prime_vmap(struct drm_gem_object *obj)
> +{
> +   long n_pages = obj->size >> PAGE_SHIFT;
> +   struct page **pages;
> +   void *addr;
> +
> +   pages = drm_gem_get_pages(obj);
> +   if (IS_ERR(pages))
> +   return NULL;
> +
> +   addr = vmap(pages, n_pages, 0,
> pgprot_writecombine(PAGE_KERNEL_IO));
> +   __put_pages(pages, n_pages);
> +
> +   return addr;
> +}
> +
> +static void vgem_prime_vunmap(struct drm_gem_object *obj, void *vaddr)
> +{
> +   vunmap(vaddr);
> +}
> +
> +static int vgem_prime_mmap(struct drm_gem_object *obj,
> +  struct vm_area_struct *vma)
> +{
> +   int ret;
> +
> +   if (obj->size < vma->vm_end - vma->vm_start)
> +   return -EINVAL;
> +
> +   if (!obj->filp)
> +   return -ENODEV;
> +
> +   ret = obj->filp->f_op->mmap(obj->filp, vma);
> +   if (ret)
> +   return ret;
> +
> +   fput(vma->vm_file);
> +   vma->vm_file = get_file(obj->filp);
> +   vma->vm_flags |= VM_DONTEXPAND | VM_DONTDUMP;
> +   vma->vm_page_prot =
> pgprot_writecombine(vm_get_page_prot(vma->vm_flags));
> +
> +   return 0;
> +}
> +
>  static struct drm_driver vgem_driver = {
> -   .driver_features= DRIVER_GEM,
> +   .driver_features= DRIVER_GEM | DRIVER_PRIME,
> .gem_free_object_unlocked   = vgem_gem_free_object,
> .gem_vm_ops = _gem_vm_ops,
> .ioctls = vgem_ioctls,
> .fops   = _driver_fops,
> +
> .dumb_create= vgem_gem_dumb_create,
> .dumb_map_offset= vgem_gem_dumb_map,
> +
> +   .prime_handle_to_fd = drm_gem_prime_handle_to_fd,
> +   .gem_prime_pin = vgem_prime_pin,

[PATCH] drm/rockchip: support prime fd import

2016-02-02 Thread Zach Reizner
The prime fd to handle ioctl was not used with rockchip before. Support
was added in order to support potential uses (e.g. zero-copy video
decode, camera).

Signed-off-by: Zach Reizner 
---
 drivers/gpu/drm/rockchip/rockchip_drm_drv.c |  1 +
 drivers/gpu/drm/rockchip/rockchip_drm_gem.c | 92 ++---
 drivers/gpu/drm/rockchip/rockchip_drm_gem.h |  7 ++-
 3 files changed, 91 insertions(+), 9 deletions(-)

diff --git a/drivers/gpu/drm/rockchip/rockchip_drm_drv.c 
b/drivers/gpu/drm/rockchip/rockchip_drm_drv.c
index dbfec29..4a01d92 100644
--- a/drivers/gpu/drm/rockchip/rockchip_drm_drv.c
+++ b/drivers/gpu/drm/rockchip/rockchip_drm_drv.c
@@ -307,6 +307,7 @@ static struct drm_driver rockchip_drm_driver = {
.gem_prime_import   = drm_gem_prime_import,
.gem_prime_export   = drm_gem_prime_export,
.gem_prime_get_sg_table = rockchip_gem_prime_get_sg_table,
+   .gem_prime_import_sg_table  = rockchip_gem_prime_import_sg_table,
.gem_prime_vmap = rockchip_gem_prime_vmap,
.gem_prime_vunmap   = rockchip_gem_prime_vunmap,
.gem_prime_mmap = rockchip_gem_mmap_buf,
diff --git a/drivers/gpu/drm/rockchip/rockchip_drm_gem.c 
b/drivers/gpu/drm/rockchip/rockchip_drm_gem.c
index a5c512e..cf6b50b 100644
--- a/drivers/gpu/drm/rockchip/rockchip_drm_gem.c
+++ b/drivers/gpu/drm/rockchip/rockchip_drm_gem.c
@@ -19,6 +19,7 @@
 #include 

 #include 
+#include 

 #include "rockchip_drm_drv.h"
 #include "rockchip_drm_gem.h"
@@ -105,13 +106,11 @@ int rockchip_gem_mmap(struct file *filp, struct 
vm_area_struct *vma)
return rockchip_drm_gem_object_mmap(obj, vma);
 }

-struct rockchip_gem_object *
-   rockchip_gem_create_object(struct drm_device *drm, unsigned int size,
-  bool alloc_kmap)
+static struct rockchip_gem_object *
+   rockchip_gem_alloc_object(struct drm_device *drm, unsigned int size)
 {
struct rockchip_gem_object *rk_obj;
struct drm_gem_object *obj;
-   int ret;

size = round_up(size, PAGE_SIZE);

@@ -123,6 +122,20 @@ struct rockchip_gem_object *

drm_gem_private_object_init(drm, obj, size);

+   return rk_obj;
+}
+
+struct rockchip_gem_object *
+   rockchip_gem_create_object(struct drm_device *drm, unsigned int size,
+  bool alloc_kmap)
+{
+   struct rockchip_gem_object *rk_obj;
+   int ret;
+
+   rk_obj = rockchip_gem_alloc_object(drm, size);
+   if (IS_ERR(rk_obj))
+   return rk_obj;
+
ret = rockchip_gem_alloc_buf(rk_obj, alloc_kmap);
if (ret)
goto err_free_rk_obj;
@@ -140,13 +153,18 @@ err_free_rk_obj:
  */
 void rockchip_gem_free_object(struct drm_gem_object *obj)
 {
-   struct rockchip_gem_object *rk_obj;
+   struct drm_device *drm = obj->dev;
+   struct rockchip_gem_object *rk_obj = to_rockchip_obj(obj);

drm_gem_free_mmap_offset(obj);

-   rk_obj = to_rockchip_obj(obj);
-
-   rockchip_gem_free_buf(rk_obj);
+   if (rk_obj->sg) {
+   dma_unmap_sg(drm->dev, rk_obj->sg->sgl, rk_obj->sg->nents,
+DMA_BIDIRECTIONAL);
+   drm_prime_gem_destroy(obj, rk_obj->sg);
+   } else {
+   rockchip_gem_free_buf(rk_obj);
+   }

kfree(rk_obj);
 }
@@ -289,6 +307,64 @@ struct sg_table *rockchip_gem_prime_get_sg_table(struct 
drm_gem_object *obj)
return sgt;
 }

+static unsigned long rockchip_sg_get_contiguous_size(struct sg_table *sgt,
+int count)
+{
+   struct scatterlist *s;
+   dma_addr_t expected = sg_dma_address(sgt->sgl);
+   unsigned int i;
+   unsigned long size = 0;
+
+   for_each_sg(sgt->sgl, s, count, i) {
+   if (sg_dma_address(s) != expected)
+   break;
+   expected = sg_dma_address(s) + sg_dma_len(s);
+   size += sg_dma_len(s);
+   }
+   return size;
+}
+
+
+struct drm_gem_object *
+rockchip_gem_prime_import_sg_table(struct drm_device *drm,
+  struct dma_buf_attachment *attach,
+  struct sg_table *sg)
+{
+   struct rockchip_gem_object *rk_obj;
+   size_t size = attach->dmabuf->size;
+   int count;
+   int ret;
+
+   rk_obj = rockchip_gem_alloc_object(drm, size);
+   if (IS_ERR(rk_obj))
+   return ERR_CAST(rk_obj);
+
+   count = dma_map_sg(drm->dev, sg->sgl, sg->nents,
+  DMA_BIDIRECTIONAL);
+
+   if (!count) {
+   ret = -EINVAL;
+   goto err_free_rk_obj;
+   }
+
+   if (rockchip_sg_get_contiguous_size(sg, count) < size) {
+   DRM_ERROR("failed to map sg_table to contiguous linear 
address.\n");
+   dma_unmap_sg(drm->dev, sg->

[PATCH v4] drm/vgem: implement virtual GEM

2015-03-04 Thread Zach Reizner
This patch implements the virtual GEM driver with PRIME sharing which
allows vgem to import a gem object from other drivers for the purpose
of mmap-ing them to userspace. The mmap is done using the mmap
operation exported by other drivers.

v2: remove platform_device and do not attach to dma bufs
v3: use drm helpers for get/put pages
v4: correct dumb create pitch

Reviewed-by: Rob Clark  (v3)
Reviewed-by: Stéphane Marchesin  (v3)
Signed-off-by: Adam Jackson 
Signed-off-by: Ben Widawsky 
Signed-off-by: Zach Reizner 
---
 drivers/gpu/drm/Kconfig |   9 +
 drivers/gpu/drm/Makefile|   1 +
 drivers/gpu/drm/vgem/Makefile   |   4 +
 drivers/gpu/drm/vgem/vgem_dma_buf.c |  94 ++
 drivers/gpu/drm/vgem/vgem_drv.c | 364 
 drivers/gpu/drm/vgem/vgem_drv.h |  57 ++
 6 files changed, 529 insertions(+)
 create mode 100644 drivers/gpu/drm/vgem/Makefile
 create mode 100644 drivers/gpu/drm/vgem/vgem_dma_buf.c
 create mode 100644 drivers/gpu/drm/vgem/vgem_drv.c
 create mode 100644 drivers/gpu/drm/vgem/vgem_drv.h

diff --git a/drivers/gpu/drm/Kconfig b/drivers/gpu/drm/Kconfig
index 151a050..47f2ce8 100644
--- a/drivers/gpu/drm/Kconfig
+++ b/drivers/gpu/drm/Kconfig
@@ -165,6 +165,15 @@ config DRM_SAVAGE
  Choose this option if you have a Savage3D/4/SuperSavage/Pro/Twister
  chipset. If M is selected the module will be called savage.

+config DRM_VGEM
+   tristate "Virtual GEM provider"
+   depends on DRM
+   help
+ Choose this option to get a virtual graphics memory manager,
+ as used by Mesa's software renderer for enhanced performance.
+ If M is selected the module will be called vgem.
+
+
 source "drivers/gpu/drm/exynos/Kconfig"

 source "drivers/gpu/drm/rockchip/Kconfig"
diff --git a/drivers/gpu/drm/Makefile b/drivers/gpu/drm/Makefile
index 2c239b9..7d4944e 100644
--- a/drivers/gpu/drm/Makefile
+++ b/drivers/gpu/drm/Makefile
@@ -48,6 +48,7 @@ obj-$(CONFIG_DRM_SIS)   += sis/
 obj-$(CONFIG_DRM_SAVAGE)+= savage/
 obj-$(CONFIG_DRM_VMWGFX)+= vmwgfx/
 obj-$(CONFIG_DRM_VIA)  +=via/
+obj-$(CONFIG_DRM_VGEM) += vgem/
 obj-$(CONFIG_DRM_NOUVEAU) +=nouveau/
 obj-$(CONFIG_DRM_EXYNOS) +=exynos/
 obj-$(CONFIG_DRM_ROCKCHIP) +=rockchip/
diff --git a/drivers/gpu/drm/vgem/Makefile b/drivers/gpu/drm/vgem/Makefile
new file mode 100644
index 000..1055cb7
--- /dev/null
+++ b/drivers/gpu/drm/vgem/Makefile
@@ -0,0 +1,4 @@
+ccflags-y := -Iinclude/drm
+vgem-y := vgem_drv.o vgem_dma_buf.o
+
+obj-$(CONFIG_DRM_VGEM) += vgem.o
diff --git a/drivers/gpu/drm/vgem/vgem_dma_buf.c 
b/drivers/gpu/drm/vgem/vgem_dma_buf.c
new file mode 100644
index 000..0254438
--- /dev/null
+++ b/drivers/gpu/drm/vgem/vgem_dma_buf.c
@@ -0,0 +1,94 @@
+/*
+ * Copyright © 2012 Intel Corporation
+ * Copyright © 2014 The Chromium OS Authors
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ *
+ * Authors:
+ *Ben Widawsky 
+ *
+ */
+
+#include 
+#include "vgem_drv.h"
+
+struct sg_table *vgem_gem_prime_get_sg_table(struct drm_gem_object *gobj)
+{
+   struct drm_vgem_gem_object *obj = to_vgem_bo(gobj);
+   BUG_ON(obj->pages == NULL);
+
+   return drm_prime_pages_to_sg(obj->pages, obj->base.size / PAGE_SIZE);
+}
+
+int vgem_gem_prime_pin(struct drm_gem_object *gobj)
+{
+   struct drm_vgem_gem_object *obj = to_vgem_bo(gobj);
+   return vgem_gem_get_pages(obj);
+}
+
+void vgem_gem_prime_unpin(struct drm_gem_object *gobj)
+{
+   struct drm_vgem_gem_object *obj = to_vgem_bo(gobj);
+   vgem_gem_put_pages(obj);
+}
+
+void *vgem_gem_prime_vmap(struct drm_gem_object *gobj)
+{
+   struct drm_vgem_gem_object *obj = to_vgem_bo(gobj);
+   BUG_ON(obj->pages == NULL);
+
+   return vmap(obj->pages, obj->base.size / PAGE_SIZE, 0, PAGE_KERNEL);
+}
+
+void vgem_gem_prime_vunmap(s

[PATCH v3] drm/vgem: implement virtual GEM

2015-02-10 Thread Zach Reizner
This patch implements the virtual GEM driver with PRIME sharing which
allows vgem to import a gem object from other drivers for the purpose
of mmap-ing them to userspace. The mmap is done using the mmap
operation exported by other drivers.

v2: remove platform_device and do not attach to dma bufs
v3: use drm helpers for get/put pages

Reviewed-by: Rob Clark 
Reviewed-by: Stéphane Marchesin 
Signed-off-by: Adam Jackson 
Signed-off-by: Ben Widawsky 
Signed-off-by: Zach Reizner 
---
 drivers/gpu/drm/Kconfig |   9 +
 drivers/gpu/drm/Makefile|   1 +
 drivers/gpu/drm/vgem/Makefile   |   4 +
 drivers/gpu/drm/vgem/vgem_dma_buf.c |  94 ++
 drivers/gpu/drm/vgem/vgem_drv.c | 363 
 drivers/gpu/drm/vgem/vgem_drv.h |  57 ++
 6 files changed, 528 insertions(+)
 create mode 100644 drivers/gpu/drm/vgem/Makefile
 create mode 100644 drivers/gpu/drm/vgem/vgem_dma_buf.c
 create mode 100644 drivers/gpu/drm/vgem/vgem_drv.c
 create mode 100644 drivers/gpu/drm/vgem/vgem_drv.h

diff --git a/drivers/gpu/drm/Kconfig b/drivers/gpu/drm/Kconfig
index 308c104..b58f667 100644
--- a/drivers/gpu/drm/Kconfig
+++ b/drivers/gpu/drm/Kconfig
@@ -164,6 +164,15 @@ config DRM_SAVAGE
  Choose this option if you have a Savage3D/4/SuperSavage/Pro/Twister
  chipset. If M is selected the module will be called savage.

+config DRM_VGEM
+   tristate "Virtual GEM provider"
+   depends on DRM
+   help
+ Choose this option to get a virtual graphics memory manager,
+ as used by Mesa's software renderer for enhanced performance.
+ If M is selected the module will be called vgem.
+
+
 source "drivers/gpu/drm/exynos/Kconfig"

 source "drivers/gpu/drm/rockchip/Kconfig"
diff --git a/drivers/gpu/drm/Makefile b/drivers/gpu/drm/Makefile
index 2c239b9..7d4944e 100644
--- a/drivers/gpu/drm/Makefile
+++ b/drivers/gpu/drm/Makefile
@@ -48,6 +48,7 @@ obj-$(CONFIG_DRM_SIS)   += sis/
 obj-$(CONFIG_DRM_SAVAGE)+= savage/
 obj-$(CONFIG_DRM_VMWGFX)+= vmwgfx/
 obj-$(CONFIG_DRM_VIA)  +=via/
+obj-$(CONFIG_DRM_VGEM) += vgem/
 obj-$(CONFIG_DRM_NOUVEAU) +=nouveau/
 obj-$(CONFIG_DRM_EXYNOS) +=exynos/
 obj-$(CONFIG_DRM_ROCKCHIP) +=rockchip/
diff --git a/drivers/gpu/drm/vgem/Makefile b/drivers/gpu/drm/vgem/Makefile
new file mode 100644
index 000..1055cb7
--- /dev/null
+++ b/drivers/gpu/drm/vgem/Makefile
@@ -0,0 +1,4 @@
+ccflags-y := -Iinclude/drm
+vgem-y := vgem_drv.o vgem_dma_buf.o
+
+obj-$(CONFIG_DRM_VGEM) += vgem.o
diff --git a/drivers/gpu/drm/vgem/vgem_dma_buf.c 
b/drivers/gpu/drm/vgem/vgem_dma_buf.c
new file mode 100644
index 000..0254438
--- /dev/null
+++ b/drivers/gpu/drm/vgem/vgem_dma_buf.c
@@ -0,0 +1,94 @@
+/*
+ * Copyright © 2012 Intel Corporation
+ * Copyright © 2014 The Chromium OS Authors
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ *
+ * Authors:
+ *Ben Widawsky 
+ *
+ */
+
+#include 
+#include "vgem_drv.h"
+
+struct sg_table *vgem_gem_prime_get_sg_table(struct drm_gem_object *gobj)
+{
+   struct drm_vgem_gem_object *obj = to_vgem_bo(gobj);
+   BUG_ON(obj->pages == NULL);
+
+   return drm_prime_pages_to_sg(obj->pages, obj->base.size / PAGE_SIZE);
+}
+
+int vgem_gem_prime_pin(struct drm_gem_object *gobj)
+{
+   struct drm_vgem_gem_object *obj = to_vgem_bo(gobj);
+   return vgem_gem_get_pages(obj);
+}
+
+void vgem_gem_prime_unpin(struct drm_gem_object *gobj)
+{
+   struct drm_vgem_gem_object *obj = to_vgem_bo(gobj);
+   vgem_gem_put_pages(obj);
+}
+
+void *vgem_gem_prime_vmap(struct drm_gem_object *gobj)
+{
+   struct drm_vgem_gem_object *obj = to_vgem_bo(gobj);
+   BUG_ON(obj->pages == NULL);
+
+   return vmap(obj->pages, obj->base.size / PAGE_SIZE, 0, PAGE_KERNEL);
+}
+
+void vgem_gem_prime_vunmap(struct drm_gem_object *obj, void *vaddr)
+{
+ 

[PATCH v2] drm/vgem: implement virtual GEM

2015-01-30 Thread Zach Reizner
This patch implements the virtual GEM driver with PRIME sharing which
allows vgem to import a gem object from other drivers for the purpose
of mmap-ing them to userspace. The mmap is done using the mmap
operation exported by other drivers.

v2: remove platform_device and do not attach to dma bufs

Reviewed-by: Stéphane Marchesin 
Signed-off-by: Adam Jackson 
Signed-off-by: Ben Widawsky 
Signed-off-by: Zach Reizner 
---
 drivers/gpu/drm/Kconfig |   9 +
 drivers/gpu/drm/Makefile|   1 +
 drivers/gpu/drm/vgem/Makefile   |   4 +
 drivers/gpu/drm/vgem/vgem_dma_buf.c |  96 +
 drivers/gpu/drm/vgem/vgem_drv.c | 390 
 drivers/gpu/drm/vgem/vgem_drv.h |  57 ++
 6 files changed, 557 insertions(+)
 create mode 100644 drivers/gpu/drm/vgem/Makefile
 create mode 100644 drivers/gpu/drm/vgem/vgem_dma_buf.c
 create mode 100644 drivers/gpu/drm/vgem/vgem_drv.c
 create mode 100644 drivers/gpu/drm/vgem/vgem_drv.h

diff --git a/drivers/gpu/drm/Kconfig b/drivers/gpu/drm/Kconfig
index 308c104..b58f667 100644
--- a/drivers/gpu/drm/Kconfig
+++ b/drivers/gpu/drm/Kconfig
@@ -164,6 +164,15 @@ config DRM_SAVAGE
  Choose this option if you have a Savage3D/4/SuperSavage/Pro/Twister
  chipset. If M is selected the module will be called savage.

+config DRM_VGEM
+   tristate "Virtual GEM provider"
+   depends on DRM
+   help
+ Choose this option to get a virtual graphics memory manager,
+ as used by Mesa's software renderer for enhanced performance.
+ If M is selected the module will be called vgem.
+
+
 source "drivers/gpu/drm/exynos/Kconfig"

 source "drivers/gpu/drm/rockchip/Kconfig"
diff --git a/drivers/gpu/drm/Makefile b/drivers/gpu/drm/Makefile
index 2c239b9..7d4944e 100644
--- a/drivers/gpu/drm/Makefile
+++ b/drivers/gpu/drm/Makefile
@@ -48,6 +48,7 @@ obj-$(CONFIG_DRM_SIS)   += sis/
 obj-$(CONFIG_DRM_SAVAGE)+= savage/
 obj-$(CONFIG_DRM_VMWGFX)+= vmwgfx/
 obj-$(CONFIG_DRM_VIA)  +=via/
+obj-$(CONFIG_DRM_VGEM) += vgem/
 obj-$(CONFIG_DRM_NOUVEAU) +=nouveau/
 obj-$(CONFIG_DRM_EXYNOS) +=exynos/
 obj-$(CONFIG_DRM_ROCKCHIP) +=rockchip/
diff --git a/drivers/gpu/drm/vgem/Makefile b/drivers/gpu/drm/vgem/Makefile
new file mode 100644
index 000..1055cb7
--- /dev/null
+++ b/drivers/gpu/drm/vgem/Makefile
@@ -0,0 +1,4 @@
+ccflags-y := -Iinclude/drm
+vgem-y := vgem_drv.o vgem_dma_buf.o
+
+obj-$(CONFIG_DRM_VGEM) += vgem.o
diff --git a/drivers/gpu/drm/vgem/vgem_dma_buf.c 
b/drivers/gpu/drm/vgem/vgem_dma_buf.c
new file mode 100644
index 000..3ea6bd2
--- /dev/null
+++ b/drivers/gpu/drm/vgem/vgem_dma_buf.c
@@ -0,0 +1,96 @@
+/*
+ * Copyright © 2012 Intel Corporation
+ * Copyright © 2014 The Chromium OS Authors
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ *
+ * Authors:
+ *Ben Widawsky 
+ *
+ */
+
+#include 
+#include "vgem_drv.h"
+
+#define VGEM_FD_PERMS 0600
+
+struct sg_table *vgem_gem_prime_get_sg_table(struct drm_gem_object *gobj)
+{
+   struct drm_vgem_gem_object *obj = to_vgem_bo(gobj);
+   BUG_ON(obj->pages == NULL);
+
+   return drm_prime_pages_to_sg(obj->pages, obj->base.size / PAGE_SIZE);
+}
+
+int vgem_gem_prime_pin(struct drm_gem_object *gobj)
+{
+   struct drm_vgem_gem_object *obj = to_vgem_bo(gobj);
+   return vgem_gem_get_pages(obj);
+}
+
+void vgem_gem_prime_unpin(struct drm_gem_object *gobj)
+{
+   struct drm_vgem_gem_object *obj = to_vgem_bo(gobj);
+   vgem_gem_put_pages(obj);
+}
+
+void *vgem_gem_prime_vmap(struct drm_gem_object *gobj)
+{
+   struct drm_vgem_gem_object *obj = to_vgem_bo(gobj);
+   BUG_ON(obj->pages == NULL);
+
+   return vmap(obj->pages, obj->base.size / PAGE_SIZE, 0, PAGE_KERNEL);
+}
+
+void vgem_gem_prime_vunmap(struct drm_gem_object *obj, void *vaddr)
+{
+   vunmap(vad

[PATCH v2] drm/cirrus: fix leaky driver load error handling

2014-12-01 Thread Zach Reizner
Before this patch, cirrus_mm_init could have failed while
cirrus_modeset_init succeeded and the driver would have reported overall
success on load. This patch causes cirrus_driver_load to return on the
first error encountered.

Reviewed-by: Stéphane Marchesin 
Signed-off-by: Zach Reizner 
---
 drivers/gpu/drm/cirrus/cirrus_main.c | 13 +
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/drivers/gpu/drm/cirrus/cirrus_main.c 
b/drivers/gpu/drm/cirrus/cirrus_main.c
index 99c1983..ab7cb54 100644
--- a/drivers/gpu/drm/cirrus/cirrus_main.c
+++ b/drivers/gpu/drm/cirrus/cirrus_main.c
@@ -179,17 +179,22 @@ int cirrus_driver_load(struct drm_device *dev, unsigned 
long flags)
}

r = cirrus_mm_init(cdev);
-   if (r)
+   if (r) {
dev_err(>pdev->dev, "fatal err on mm init\n");
+   goto out;
+   }

r = cirrus_modeset_init(cdev);
-   if (r)
+   if (r) {
dev_err(>pdev->dev, "Fatal error during modeset init: 
%d\n", r);
+   goto out;
+   }

dev->mode_config.funcs = (void *)_mode_funcs;
+
+   return 0;
 out:
-   if (r)
-   cirrus_driver_unload(dev);
+   cirrus_driver_unload(dev);
return r;
 }

-- 
2.2.0.rc0.207.ga3a616c



[PATCH] drm/vgem: implement virtual GEM

2014-11-20 Thread Zach Reizner
This patch implements the virtual GEM driver with PRIME sharing which
allows vgem to import a gem object from other drivers for the purpose
of mmap-ing them to userspace.

Reviewed-by: Stéphane Marchesin 
Signed-off-by: Adam Jackson 
Signed-off-by: Ben Widawsky 
Signed-off-by: Zach Reizner 
---
 drivers/gpu/drm/Kconfig |   9 +
 drivers/gpu/drm/Makefile|   1 +
 drivers/gpu/drm/vgem/Makefile   |   4 +
 drivers/gpu/drm/vgem/vgem_dma_buf.c | 169 +++
 drivers/gpu/drm/vgem/vgem_drv.c | 407 
 drivers/gpu/drm/vgem/vgem_drv.h |  62 ++
 6 files changed, 652 insertions(+)
 create mode 100644 drivers/gpu/drm/vgem/Makefile
 create mode 100644 drivers/gpu/drm/vgem/vgem_dma_buf.c
 create mode 100644 drivers/gpu/drm/vgem/vgem_drv.c
 create mode 100644 drivers/gpu/drm/vgem/vgem_drv.h

diff --git a/drivers/gpu/drm/Kconfig b/drivers/gpu/drm/Kconfig
index e3b4b0f..39909bc 100644
--- a/drivers/gpu/drm/Kconfig
+++ b/drivers/gpu/drm/Kconfig
@@ -165,6 +165,15 @@ config DRM_SAVAGE
  Choose this option if you have a Savage3D/4/SuperSavage/Pro/Twister
  chipset. If M is selected the module will be called savage.

+config DRM_VGEM
+   tristate "Virtual GEM provider"
+   depends on DRM
+   help
+ Choose this option to get a virtual graphics memory manager,
+ as used by Mesa's software renderer for enhanced performance.
+ If M is selected the module will be called vgem.
+
+
 source "drivers/gpu/drm/exynos/Kconfig"

 source "drivers/gpu/drm/vmwgfx/Kconfig"
diff --git a/drivers/gpu/drm/Makefile b/drivers/gpu/drm/Makefile
index c3cf64c..c1e4a0e 100644
--- a/drivers/gpu/drm/Makefile
+++ b/drivers/gpu/drm/Makefile
@@ -47,6 +47,7 @@ obj-$(CONFIG_DRM_SIS)   += sis/
 obj-$(CONFIG_DRM_SAVAGE)+= savage/
 obj-$(CONFIG_DRM_VMWGFX)+= vmwgfx/
 obj-$(CONFIG_DRM_VIA)  +=via/
+obj-$(CONFIG_DRM_VGEM) += vgem/
 obj-$(CONFIG_DRM_NOUVEAU) +=nouveau/
 obj-$(CONFIG_DRM_EXYNOS) +=exynos/
 obj-$(CONFIG_DRM_GMA500) += gma500/
diff --git a/drivers/gpu/drm/vgem/Makefile b/drivers/gpu/drm/vgem/Makefile
new file mode 100644
index 000..1055cb7
--- /dev/null
+++ b/drivers/gpu/drm/vgem/Makefile
@@ -0,0 +1,4 @@
+ccflags-y := -Iinclude/drm
+vgem-y := vgem_drv.o vgem_dma_buf.o
+
+obj-$(CONFIG_DRM_VGEM) += vgem.o
diff --git a/drivers/gpu/drm/vgem/vgem_dma_buf.c 
b/drivers/gpu/drm/vgem/vgem_dma_buf.c
new file mode 100644
index 000..8450124
--- /dev/null
+++ b/drivers/gpu/drm/vgem/vgem_dma_buf.c
@@ -0,0 +1,169 @@
+/*
+ * Copyright © 2012 Intel Corporation
+ * Copyright © 2014 The Chromium OS Authors
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ *
+ * Authors:
+ *Ben Widawsky 
+ *
+ */
+
+#include 
+#include "vgem_drv.h"
+
+#define VGEM_FD_PERMS 0600
+
+static struct sg_table *vgem_gem_map_dma_buf(struct dma_buf_attachment *attach,
+enum dma_data_direction dir)
+{
+   struct drm_vgem_gem_object *obj = attach->dmabuf->priv;
+   struct sg_table *sg;
+   int ret;
+
+   ret = vgem_gem_get_pages(obj);
+   if (ret)
+   return ERR_PTR(ret);
+
+   /* VGEM assumes cache coherent access. Normally we might have to flush
+* caches here */
+
+   BUG_ON(obj->pages == NULL);
+
+   sg = drm_prime_pages_to_sg(obj->pages, obj->base.size / PAGE_SIZE);
+   if (!sg) {
+   vgem_gem_put_pages(obj);
+   return NULL;
+   }
+
+   return sg;
+}
+
+static void vgem_gem_unmap_dma_buf(struct dma_buf_attachment *attach,
+   struct sg_table *sg,
+   enum dma_data_direction data_direction)
+{
+   sg_free_table(sg);
+   kfree(sg);
+}
+
+static void *vgem_kmap_atomic_dma_buf(struct dma_buf *dma_buf,
+   

[PATCH] drm/cirrus: fix leaky driver load error handling

2014-11-17 Thread Zach Reizner
Before this patch, cirrus_device_init could have failed while
cirrus_mm_init succeeded and the driver would have reported overall
success on load. This patch causes cirrus_device_init to return on
the first error encountered.

Reviewed-by: Stéphane Marchesin 
---
 drivers/gpu/drm/cirrus/cirrus_main.c | 13 +
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/drivers/gpu/drm/cirrus/cirrus_main.c 
b/drivers/gpu/drm/cirrus/cirrus_main.c
index 99c1983..ab7cb54 100644
--- a/drivers/gpu/drm/cirrus/cirrus_main.c
+++ b/drivers/gpu/drm/cirrus/cirrus_main.c
@@ -179,17 +179,22 @@ int cirrus_driver_load(struct drm_device *dev, unsigned 
long flags)
}

r = cirrus_mm_init(cdev);
-   if (r)
+   if (r) {
dev_err(>pdev->dev, "fatal err on mm init\n");
+   goto out;
+   }

r = cirrus_modeset_init(cdev);
-   if (r)
+   if (r) {
dev_err(>pdev->dev, "Fatal error during modeset init: 
%d\n", r);
+   goto out;
+   }

dev->mode_config.funcs = (void *)_mode_funcs;
+
+   return 0;
 out:
-   if (r)
-   cirrus_driver_unload(dev);
+   cirrus_driver_unload(dev);
return r;
 }

-- 
2.1.0.rc2.206.gedb03e5



[PATCH v2] allow 32bpp framebuffers for cirrus drm

2014-10-29 Thread Zach Reizner
This patch allows framebuffers for cirrus to be created with
32bpp pixel formats provided that they do not violate certain
restrictions of the cirrus hardware.

v2: Use pci resource length for vram size.

Signed-off-by: Zach Reizner 
---
 drivers/gpu/drm/cirrus/cirrus_drv.h   |  3 +++
 drivers/gpu/drm/cirrus/cirrus_fbdev.c |  5 -
 drivers/gpu/drm/cirrus/cirrus_main.c  | 27 +++
 3 files changed, 30 insertions(+), 5 deletions(-)

diff --git a/drivers/gpu/drm/cirrus/cirrus_drv.h 
b/drivers/gpu/drm/cirrus/cirrus_drv.h
index d44e69d..693a456 100644
--- a/drivers/gpu/drm/cirrus/cirrus_drv.h
+++ b/drivers/gpu/drm/cirrus/cirrus_drv.h
@@ -210,6 +210,9 @@ int cirrus_framebuffer_init(struct drm_device *dev,
struct drm_mode_fb_cmd2 *mode_cmd,
struct drm_gem_object *obj);

+bool cirrus_check_framebuffer(struct cirrus_device *cdev, int width, int 
height,
+ int bpp, int pitch);
+
/* cirrus_display.c */
 int cirrus_modeset_init(struct cirrus_device *cdev);
 void cirrus_modeset_fini(struct cirrus_device *cdev);
diff --git a/drivers/gpu/drm/cirrus/cirrus_fbdev.c 
b/drivers/gpu/drm/cirrus/cirrus_fbdev.c
index d231b1c..502a89e 100644
--- a/drivers/gpu/drm/cirrus/cirrus_fbdev.c
+++ b/drivers/gpu/drm/cirrus/cirrus_fbdev.c
@@ -139,6 +139,7 @@ static int cirrusfb_create_object(struct cirrus_fbdev 
*afbdev,
   struct drm_gem_object **gobj_p)
 {
struct drm_device *dev = afbdev->helper.dev;
+   struct cirrus_device *cdev = dev->dev_private;
u32 bpp, depth;
u32 size;
struct drm_gem_object *gobj;
@@ -146,8 +147,10 @@ static int cirrusfb_create_object(struct cirrus_fbdev 
*afbdev,
int ret = 0;
drm_fb_get_bpp_depth(mode_cmd->pixel_format, , );

-   if (bpp > 24)
+   if (!cirrus_check_framebuffer(cdev, mode_cmd->width, mode_cmd->height,
+ bpp, mode_cmd->pitches[0]))
return -EINVAL;
+
size = mode_cmd->pitches[0] * mode_cmd->height;
ret = cirrus_gem_create(dev, size, true, );
if (ret)
diff --git a/drivers/gpu/drm/cirrus/cirrus_main.c 
b/drivers/gpu/drm/cirrus/cirrus_main.c
index 99c1983..d9590fc 100644
--- a/drivers/gpu/drm/cirrus/cirrus_main.c
+++ b/drivers/gpu/drm/cirrus/cirrus_main.c
@@ -49,14 +49,16 @@ cirrus_user_framebuffer_create(struct drm_device *dev,
   struct drm_file *filp,
   struct drm_mode_fb_cmd2 *mode_cmd)
 {
+   struct cirrus_device *cdev = dev->dev_private;
struct drm_gem_object *obj;
struct cirrus_framebuffer *cirrus_fb;
int ret;
u32 bpp, depth;

drm_fb_get_bpp_depth(mode_cmd->pixel_format, , );
-   /* cirrus can't handle > 24bpp framebuffers at all */
-   if (bpp > 24)
+
+   if (!cirrus_check_framebuffer(cdev, mode_cmd->width, mode_cmd->height,
+ bpp, mode_cmd->pitches[0]))
return ERR_PTR(-EINVAL);

obj = drm_gem_object_lookup(dev, filp, mode_cmd->handles[0]);
@@ -96,8 +98,7 @@ static int cirrus_vram_init(struct cirrus_device *cdev)
 {
/* BAR 0 is VRAM */
cdev->mc.vram_base = pci_resource_start(cdev->dev->pdev, 0);
-   /* We have 4MB of VRAM */
-   cdev->mc.vram_size = 4 * 1024 * 1024;
+   cdev->mc.vram_size = pci_resource_len(cdev->dev->pdev, 0);

if (!request_mem_region(cdev->mc.vram_base, cdev->mc.vram_size,
"cirrusdrmfb_vram")) {
@@ -307,3 +308,21 @@ out_unlock:
return ret;

 }
+
+bool cirrus_check_framebuffer(struct cirrus_device *cdev, int width, int 
height,
+ int bpp, int pitch)
+{
+   const int max_pitch = 0x1FF << 3; /* (4096 - 1) & ~111b bytes */
+   const int max_size = cdev->mc.vram_size;
+
+   if (bpp > 32)
+   return false;
+
+   if (pitch > max_pitch)
+   return false;
+
+   if (pitch * height > max_size)
+   return false;
+
+   return true;
+}
-- 
2.1.0.rc2.206.gedb03e5



[PATCH] allow 32bpp framebuffers for cirrus drm

2014-10-07 Thread Zach Reizner
This patch allows framebuffers for cirrus to be created with
32bpp pixel formats provided that they do not violate certain
restrictions of the cirrus hardware.

Signed-off-by: Zach Reizner 
---
 drivers/gpu/drm/cirrus/cirrus_drv.h   |  2 ++
 drivers/gpu/drm/cirrus/cirrus_fbdev.c |  4 +++-
 drivers/gpu/drm/cirrus/cirrus_main.c  | 22 --
 3 files changed, 25 insertions(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/cirrus/cirrus_drv.h 
b/drivers/gpu/drm/cirrus/cirrus_drv.h
index 401c890..fac475c 100644
--- a/drivers/gpu/drm/cirrus/cirrus_drv.h
+++ b/drivers/gpu/drm/cirrus/cirrus_drv.h
@@ -208,6 +208,8 @@ int cirrus_framebuffer_init(struct drm_device *dev,
struct drm_mode_fb_cmd2 *mode_cmd,
struct drm_gem_object *obj);

+bool cirrus_check_framebuffer(int width, int height, int bpp, int pitch);
+
/* cirrus_display.c */
 int cirrus_modeset_init(struct cirrus_device *cdev);
 void cirrus_modeset_fini(struct cirrus_device *cdev);
diff --git a/drivers/gpu/drm/cirrus/cirrus_fbdev.c 
b/drivers/gpu/drm/cirrus/cirrus_fbdev.c
index 2a135f2..4a0756c 100644
--- a/drivers/gpu/drm/cirrus/cirrus_fbdev.c
+++ b/drivers/gpu/drm/cirrus/cirrus_fbdev.c
@@ -146,8 +146,10 @@ static int cirrusfb_create_object(struct cirrus_fbdev 
*afbdev,
int ret = 0;
drm_fb_get_bpp_depth(mode_cmd->pixel_format, , );

-   if (bpp > 24)
+   if (!cirrus_check_framebuffer(mode_cmd->width, mode_cmd->height, bpp,
+ mode_cmd->pitches[0]))
return -EINVAL;
+
size = mode_cmd->pitches[0] * mode_cmd->height;
ret = cirrus_gem_create(dev, size, true, );
if (ret)
diff --git a/drivers/gpu/drm/cirrus/cirrus_main.c 
b/drivers/gpu/drm/cirrus/cirrus_main.c
index 99c1983..029f9e9 100644
--- a/drivers/gpu/drm/cirrus/cirrus_main.c
+++ b/drivers/gpu/drm/cirrus/cirrus_main.c
@@ -55,8 +55,9 @@ cirrus_user_framebuffer_create(struct drm_device *dev,
u32 bpp, depth;

drm_fb_get_bpp_depth(mode_cmd->pixel_format, , );
-   /* cirrus can't handle > 24bpp framebuffers at all */
-   if (bpp > 24)
+
+   if (!cirrus_check_framebuffer(mode_cmd->width, mode_cmd->height,
+ bpp, mode_cmd->pitches[0]))
return ERR_PTR(-EINVAL);

obj = drm_gem_object_lookup(dev, filp, mode_cmd->handles[0]);
@@ -307,3 +308,20 @@ out_unlock:
return ret;

 }
+
+bool cirrus_check_framebuffer(int width, int height, int bpp, int pitch)
+{
+   const int max_pitch = 0x1FF << 3; /* (4096 - 1) & ~111b bytes */
+   const int max_size = 0x40; /* 4MB */
+
+   if (bpp > 32)
+   return false;
+
+   if (pitch > max_pitch)
+   return false;
+
+   if (pitch * height > max_size)
+   return false;
+
+   return true;
+}
-- 
2.1.0.rc2.206.gedb03e5