Re: [PATCH v2 02/17] drm: Add |struct drm_gem_vram_object| callbacks for |struct ttm_bo_driver|

2019-04-24 Thread Koenig, Christian
Am 24.04.19 um 14:05 schrieb Thomas Zimmermann:
> Hi Christian,
>
> Am 24.04.19 um 13:48 schrieb Thomas Zimmermann:
>> +
>> +/*
>> + * Helpers for struct ttm_bo_driver
>> + */
>> +
>> +static bool drm_is_gem_vram(struct ttm_buffer_object *bo)
>> +{
>> +return (bo->destroy == ttm_buffer_object_destroy);
>> +}
>> +
>> +/**
>> + * drm_gem_vram_bo_driver_evict_flags() - \
>> +Implements  ttm_bo_driver.evict_flags
>> + * @bo: TTM buffer object. Refers to  drm_gem_vram_object.bo
>> + * @pl: TTM placement information.
>> + */
>> +void drm_gem_vram_bo_driver_evict_flags(struct ttm_buffer_object *bo,
>> +struct ttm_placement *pl)
>> +{
>> +struct drm_gem_vram_object *gbo;
>> +
>> +/* TTM may pass BOs that are not GEM VRAM BOs. */
>> +if (!drm_is_gem_vram(bo))
>> +return;
>> +
>> +gbo = drm_gem_vram_of_bo(bo);
>> +drm_gem_vram_placement(gbo, TTM_PL_FLAG_SYSTEM);
>> +*pl = gbo->placement;
>> +}
> For drm_is_gem_vram(), I'm not quite sure what else to test for. So
> there are still a few things I'd like to discuss.
>
>   1) If this test is about the placement flags, then it's unrelated to
> the actual DRM driver. All buffers of type |struct drm_gem_vram_object|
> share the same placement flags.
>
>   2) I tested the code to work with ast and mgag200.
>
>   3) If this test is really about individual instances of each DRM
> driver, then the current implementations are already broken. In this
> scenario TTM should sort out BOs with a BO device different from the one
> that triggered the eviction process; or pass the original BO device to
> the evict_flags callback, so we can sort out buffers here.

Just go ahead with the current approach for now. It could be that we see 
fallout, but that is really unlikely.

Christian.

>
> Best regards
> Thomas
>

___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

Re: [PATCH v2 02/17] drm: Add |struct drm_gem_vram_object| callbacks for |struct ttm_bo_driver|

2019-04-24 Thread Thomas Zimmermann
Hi Christian,

Am 24.04.19 um 13:48 schrieb Thomas Zimmermann:
> +
> +/*
> + * Helpers for struct ttm_bo_driver
> + */
> +
> +static bool drm_is_gem_vram(struct ttm_buffer_object *bo)
> +{
> + return (bo->destroy == ttm_buffer_object_destroy);
> +}
> +
> +/**
> + * drm_gem_vram_bo_driver_evict_flags() - \
> + Implements  ttm_bo_driver.evict_flags
> + * @bo:  TTM buffer object. Refers to  drm_gem_vram_object.bo
> + * @pl:  TTM placement information.
> + */
> +void drm_gem_vram_bo_driver_evict_flags(struct ttm_buffer_object *bo,
> + struct ttm_placement *pl)
> +{
> + struct drm_gem_vram_object *gbo;
> +
> + /* TTM may pass BOs that are not GEM VRAM BOs. */
> + if (!drm_is_gem_vram(bo))
> + return;
> +
> + gbo = drm_gem_vram_of_bo(bo);
> + drm_gem_vram_placement(gbo, TTM_PL_FLAG_SYSTEM);
> + *pl = gbo->placement;
> +}

For drm_is_gem_vram(), I'm not quite sure what else to test for. So
there are still a few things I'd like to discuss.

 1) If this test is about the placement flags, then it's unrelated to
the actual DRM driver. All buffers of type |struct drm_gem_vram_object|
share the same placement flags.

 2) I tested the code to work with ast and mgag200.

 3) If this test is really about individual instances of each DRM
driver, then the current implementations are already broken. In this
scenario TTM should sort out BOs with a BO device different from the one
that triggered the eviction process; or pass the original BO device to
the evict_flags callback, so we can sort out buffers here.

Best regards
Thomas

-- 
Thomas Zimmermann
Graphics Driver Developer
SUSE Linux GmbH, Maxfeldstrasse 5, 90409 Nuernberg, Germany
GF: Felix Imendörffer, Mary Higgins, Sri Rasiah
HRB 21284 (AG Nürnberg)



signature.asc
Description: OpenPGP digital signature
___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

[PATCH v2 02/17] drm: Add |struct drm_gem_vram_object| callbacks for |struct ttm_bo_driver|

2019-04-24 Thread Thomas Zimmermann
The provided helpers can be used for the respective callback functions
in |struct ttm_bo_driver|.

v2:
* drm_is_gem_vram() is now a private function
* documentation fixes

Signed-off-by: Thomas Zimmermann 
---
 drivers/gpu/drm/drm_gem_vram_helper.c | 50 +++
 include/drm/drm_gem_vram_helper.h | 10 ++
 2 files changed, 60 insertions(+)

diff --git a/drivers/gpu/drm/drm_gem_vram_helper.c 
b/drivers/gpu/drm/drm_gem_vram_helper.c
index d39d8a5f36df..fcf6e78d92f7 100644
--- a/drivers/gpu/drm/drm_gem_vram_helper.c
+++ b/drivers/gpu/drm/drm_gem_vram_helper.c
@@ -408,3 +408,53 @@ void drm_gem_vram_kunmap(struct drm_gem_vram_object *gbo)
drm_gem_vram_kunmap_at(gbo, >kmap);
 }
 EXPORT_SYMBOL(drm_gem_vram_kunmap);
+
+/*
+ * Helpers for struct ttm_bo_driver
+ */
+
+static bool drm_is_gem_vram(struct ttm_buffer_object *bo)
+{
+   return (bo->destroy == ttm_buffer_object_destroy);
+}
+
+/**
+ * drm_gem_vram_bo_driver_evict_flags() - \
+   Implements  ttm_bo_driver.evict_flags
+ * @bo:TTM buffer object. Refers to  drm_gem_vram_object.bo
+ * @pl:TTM placement information.
+ */
+void drm_gem_vram_bo_driver_evict_flags(struct ttm_buffer_object *bo,
+   struct ttm_placement *pl)
+{
+   struct drm_gem_vram_object *gbo;
+
+   /* TTM may pass BOs that are not GEM VRAM BOs. */
+   if (!drm_is_gem_vram(bo))
+   return;
+
+   gbo = drm_gem_vram_of_bo(bo);
+   drm_gem_vram_placement(gbo, TTM_PL_FLAG_SYSTEM);
+   *pl = gbo->placement;
+}
+EXPORT_SYMBOL(drm_gem_vram_bo_driver_evict_flags);
+
+/**
+ * drm_gem_vram_bo_driver_verify_access() - \
+   Implements  ttm_bo_driver.verify_access
+ * @bo:TTM buffer object. Refers to  
drm_gem_vram_object.bo
+ * @filp:  File pointer.
+ *
+ * Returns:
+ * 0 on success, or
+ * a negative errno code otherwise.
+ */
+int drm_gem_vram_bo_driver_verify_access(struct ttm_buffer_object *bo,
+struct file *filp)
+{
+   struct drm_gem_vram_object *gbo = drm_gem_vram_of_bo(bo);
+
+   return drm_vma_node_verify_access(>gem.vma_node,
+ filp->private_data);
+}
+EXPORT_SYMBOL(drm_gem_vram_bo_driver_verify_access);
diff --git a/include/drm/drm_gem_vram_helper.h 
b/include/drm/drm_gem_vram_helper.h
index 167616f552e5..4872edb09fe9 100644
--- a/include/drm/drm_gem_vram_helper.h
+++ b/include/drm/drm_gem_vram_helper.h
@@ -89,4 +89,14 @@ void drm_gem_vram_kunmap_at(struct drm_gem_vram_object *gbo,
struct ttm_bo_kmap_obj *kmap);
 void drm_gem_vram_kunmap(struct drm_gem_vram_object *gbo);
 
+/*
+ * Helpers for struct ttm_bo_driver
+ */
+
+void drm_gem_vram_bo_driver_evict_flags(struct ttm_buffer_object *bo,
+   struct ttm_placement *pl);
+
+int drm_gem_vram_bo_driver_verify_access(struct ttm_buffer_object *bo,
+struct file *filp);
+
 #endif
-- 
2.21.0

___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel