diff mbox

[3/7] drm/radeon: implement unpin function

Message ID 1365507466-11586-3-git-send-email-maarten.lankhorst@canonical.com (mailing list archive)
State New, archived
Headers show

Commit Message

Maarten Lankhorst April 9, 2013, 11:37 a.m. UTC
Signed-off-by: Maarten Lankhorst <maarten.lankhorst@canonical.com>
---
 drivers/gpu/drm/radeon/radeon_drv.c   |  2 ++
 drivers/gpu/drm/radeon/radeon_prime.c | 18 ++++++++++++++----
 2 files changed, 16 insertions(+), 4 deletions(-)

Comments

Jerome Glisse April 9, 2013, 2:16 p.m. UTC | #1
On Tue, Apr 9, 2013 at 7:37 AM, Maarten Lankhorst
<m.b.lankhorst@gmail.com>wrote:

> Signed-off-by: Maarten Lankhorst <maarten.lankhorst@canonical.com>
>

Can userspace pin directly ? If so then that sounds as a bad idea.

Reviewed-by: Jerome Glisse <jglisse@redhat.com>


> ---
>  drivers/gpu/drm/radeon/radeon_drv.c   |  2 ++
>  drivers/gpu/drm/radeon/radeon_prime.c | 18 ++++++++++++++----
>  2 files changed, 16 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/gpu/drm/radeon/radeon_drv.c
> b/drivers/gpu/drm/radeon/radeon_drv.c
> index 66a7f0f..6800c5e 100644
> --- a/drivers/gpu/drm/radeon/radeon_drv.c
> +++ b/drivers/gpu/drm/radeon/radeon_drv.c
> @@ -124,6 +124,7 @@ struct drm_gem_object
> *radeon_gem_prime_import_sg_table(struct drm_device *dev,
>                                                         size_t size,
>                                                         struct sg_table
> *sg);
>  int radeon_gem_prime_pin(struct drm_gem_object *obj);
> +void radeon_gem_prime_unpin(struct drm_gem_object *obj);
>  void *radeon_gem_prime_vmap(struct drm_gem_object *obj);
>  void radeon_gem_prime_vunmap(struct drm_gem_object *obj, void *vaddr);
>  extern long radeon_kms_compat_ioctl(struct file *filp, unsigned int cmd,
> @@ -415,6 +416,7 @@ static struct drm_driver kms_driver = {
>         .gem_prime_export = drm_gem_prime_export,
>         .gem_prime_import = drm_gem_prime_import,
>         .gem_prime_pin = radeon_gem_prime_pin,
> +       .gem_prime_unpin = radeon_gem_prime_unpin,
>         .gem_prime_get_sg_table = radeon_gem_prime_get_sg_table,
>         .gem_prime_import_sg_table = radeon_gem_prime_import_sg_table,
>         .gem_prime_vmap = radeon_gem_prime_vmap,
> diff --git a/drivers/gpu/drm/radeon/radeon_prime.c
> b/drivers/gpu/drm/radeon/radeon_prime.c
> index 4940af7..e557da5 100644
> --- a/drivers/gpu/drm/radeon/radeon_prime.c
> +++ b/drivers/gpu/drm/radeon/radeon_prime.c
> @@ -88,10 +88,20 @@ int radeon_gem_prime_pin(struct drm_gem_object *obj)
>
>         /* pin buffer into GTT */
>         ret = radeon_bo_pin(bo, RADEON_GEM_DOMAIN_GTT, NULL);
> -       if (ret) {
> -               radeon_bo_unreserve(bo);
> -               return ret;
> -       }
> +       radeon_bo_unreserve(bo);
> +       return ret;
> +}
> +
> +void radeon_gem_prime_unpin(struct drm_gem_object *obj)
> +{
> +       struct radeon_bo *bo = gem_to_radeon_bo(obj);
> +       int ret = 0;
> +
> +       ret = radeon_bo_reserve(bo, false);
> +       if (unlikely(ret != 0))
> +               return;
> +
> +       radeon_bo_unpin(bo);
>         radeon_bo_unreserve(bo);
>
>         return 0;
> --
> 1.8.2
>
> _______________________________________________
> dri-devel mailing list
> dri-devel@lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/dri-devel
>
Maarten Lankhorst April 9, 2013, 2:26 p.m. UTC | #2
Op 09-04-13 16:16, Jerome Glisse schreef:
> On Tue, Apr 9, 2013 at 7:37 AM, Maarten Lankhorst
> <m.b.lankhorst@gmail.com>wrote:
>
>> Signed-off-by: Maarten Lankhorst <maarten.lankhorst@canonical.com>
>>
> Can userspace pin directly ? If so then that sounds as a bad idea.
>
> Reviewed-by: Jerome Glisse <jglisse@redhat.com>
>
It's slightly better than before, it used to pin as soon as you export a buffer for as long as the buffer exists, with the series the pinning will only happen when importing to another device, until the device releases their reference.

~Maarten
Daniel Vetter April 9, 2013, 2:53 p.m. UTC | #3
On Tue, Apr 9, 2013 at 4:26 PM, Maarten Lankhorst
<maarten.lankhorst@canonical.com> wrote:
> Op 09-04-13 16:16, Jerome Glisse schreef:
>> On Tue, Apr 9, 2013 at 7:37 AM, Maarten Lankhorst
>> <m.b.lankhorst@gmail.com>wrote:
>>
>>> Signed-off-by: Maarten Lankhorst <maarten.lankhorst@canonical.com>
>>>
>> Can userspace pin directly ? If so then that sounds as a bad idea.
>>
>> Reviewed-by: Jerome Glisse <jglisse@redhat.com>
>>
> It's slightly better than before, it used to pin as soon as you export a buffer for as long as the buffer exists, with the series the pinning will only happen when importing to another device, until the device releases their reference.

To make fully dynamic pinning work (and especially reclaiming) we
first need dma_buf fences, the new ww_mutexes and all that stuff since
otherwise you can trivially deadlock in buffer reservations. But I
think with Maarten's stuff we have a plan to get there, and this is
just the first tiny step of a long journey.
-Daniel
--
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch
diff mbox

Patch

diff --git a/drivers/gpu/drm/radeon/radeon_drv.c b/drivers/gpu/drm/radeon/radeon_drv.c
index 66a7f0f..6800c5e 100644
--- a/drivers/gpu/drm/radeon/radeon_drv.c
+++ b/drivers/gpu/drm/radeon/radeon_drv.c
@@ -124,6 +124,7 @@  struct drm_gem_object *radeon_gem_prime_import_sg_table(struct drm_device *dev,
 							size_t size,
 							struct sg_table *sg);
 int radeon_gem_prime_pin(struct drm_gem_object *obj);
+void radeon_gem_prime_unpin(struct drm_gem_object *obj);
 void *radeon_gem_prime_vmap(struct drm_gem_object *obj);
 void radeon_gem_prime_vunmap(struct drm_gem_object *obj, void *vaddr);
 extern long radeon_kms_compat_ioctl(struct file *filp, unsigned int cmd,
@@ -415,6 +416,7 @@  static struct drm_driver kms_driver = {
 	.gem_prime_export = drm_gem_prime_export,
 	.gem_prime_import = drm_gem_prime_import,
 	.gem_prime_pin = radeon_gem_prime_pin,
+	.gem_prime_unpin = radeon_gem_prime_unpin,
 	.gem_prime_get_sg_table = radeon_gem_prime_get_sg_table,
 	.gem_prime_import_sg_table = radeon_gem_prime_import_sg_table,
 	.gem_prime_vmap = radeon_gem_prime_vmap,
diff --git a/drivers/gpu/drm/radeon/radeon_prime.c b/drivers/gpu/drm/radeon/radeon_prime.c
index 4940af7..e557da5 100644
--- a/drivers/gpu/drm/radeon/radeon_prime.c
+++ b/drivers/gpu/drm/radeon/radeon_prime.c
@@ -88,10 +88,20 @@  int radeon_gem_prime_pin(struct drm_gem_object *obj)
 
 	/* pin buffer into GTT */
 	ret = radeon_bo_pin(bo, RADEON_GEM_DOMAIN_GTT, NULL);
-	if (ret) {
-		radeon_bo_unreserve(bo);
-		return ret;
-	}
+	radeon_bo_unreserve(bo);
+	return ret;
+}
+
+void radeon_gem_prime_unpin(struct drm_gem_object *obj)
+{
+	struct radeon_bo *bo = gem_to_radeon_bo(obj);
+	int ret = 0;
+
+	ret = radeon_bo_reserve(bo, false);
+	if (unlikely(ret != 0))
+		return;
+
+	radeon_bo_unpin(bo);
 	radeon_bo_unreserve(bo);
 
 	return 0;