[RFC PATCH 32/42] drm/i915: Add fill_pages handler for dma_buf imported objects

Matthew Auld
2019-02-14T14:58:23Z

From: Abdiel Janulgue <abdiel.janulgue@linux.intel.com>

Use the plumbing from the new mmap_offset infrastructure to
implement gtt-mmaps.

Signed-off-by: Abdiel Janulgue <abdiel.janulgue@linux.intel.com>
Cc: Matthew Auld <matthew.auld@intel.com>
---
drivers/gpu/drm/i915/i915_gem.c | 8 ++++----
drivers/gpu/drm/i915/i915_gem_dmabuf.c | 14 ++++++++++++++
drivers/gpu/drm/i915/i915_gem_object.h | 5 +++++
3 files changed, 23 insertions(+), 4 deletions(-)

diff --git a/drivers/gpu/drm/i915/i915_gem.c b/drivers/gpu/drm/i915/i915_gem.c
index b426a1ee8d0f..a9e119d8d1f1 100644
--- a/drivers/gpu/drm/i915/i915_gem.c
+++ b/drivers/gpu/drm/i915/i915_gem.c
@@ -1797,9 +1797,9 @@ compute_partial_view(const struct drm_i915_gem_object *obj,
* The current feature set supported by i915_gem_fault() and thus GTT mmaps
* is exposed via I915_PARAM_MMAP_GTT_VERSION (see i915_gem_mmap_gtt_version).
*/
-static int __vmf_fill_pages_gtt(struct drm_i915_gem_object *obj,
- struct vm_fault *vmf,
- pgoff_t page_offset)
+int i915_vmf_fill_pages_gtt(struct drm_i915_gem_object *obj,
+ struct vm_fault *vmf,
+ pgoff_t page_offset)
{
#define MIN_CHUNK_PAGES (SZ_1M >> PAGE_SHIFT)
struct vm_area_struct *area = vmf->vma;
@@ -4299,7 +4299,7 @@ int i915_gem_vmf_fill_pages_cpu(struct drm_i915_gem_object *obj,

if (HAS_MAPPABLE_APERTURE(dev_priv) &&
obj->mmap_origin == I915_MMAP_ORIGIN_GTT)
- return __vmf_fill_pages_gtt(obj, vmf, page_offset);
+ return i915_vmf_fill_pages_gtt(obj, vmf, page_offset);

page = i915_gem_object_get_page(obj, pg_off);
pfn = page_to_pfn(page);
diff --git a/drivers/gpu/drm/i915/i915_gem_dmabuf.c b/drivers/gpu/drm/i915/i915_gem_dmabuf.c
index 02f7298bfe57..b5a8d01e41cc 100644
--- a/drivers/gpu/drm/i915/i915_gem_dmabuf.c
+++ b/drivers/gpu/drm/i915/i915_gem_dmabuf.c
@@ -268,9 +268,23 @@ static void i915_gem_object_put_pages_dmabuf(struct drm_i915_gem_object *obj,
DMA_BIDIRECTIONAL);
}

+static int i915_gem_vmf_fill_pages_dmabuf(struct drm_i915_gem_object *obj,
+ struct vm_fault *vmf,
+ pgoff_t page_offset)
+{
+ struct drm_device *dev = obj->base.dev;
+ struct drm_i915_private *dev_priv = to_i915(dev);
+
+ if (!HAS_MAPPABLE_APERTURE(dev_priv))
+ return -EFAULT;
+
+ return i915_vmf_fill_pages_gtt(obj, vmf, page_offset);
+}
+
static const struct drm_i915_gem_object_ops i915_gem_object_dmabuf_ops = {
.get_pages = i915_gem_object_get_pages_dmabuf,
.put_pages = i915_gem_object_put_pages_dmabuf,
+ .vmf_fill_pages = i915_gem_vmf_fill_pages_dmabuf,
};

struct drm_gem_object *i915_gem_prime_import(struct drm_device *dev,
diff --git a/drivers/gpu/drm/i915/i915_gem_object.h b/drivers/gpu/drm/i915/i915_gem_object.h
index 82f9068f8aed..078d5550a1c8 100644
--- a/drivers/gpu/drm/i915/i915_gem_object.h
+++ b/drivers/gpu/drm/i915/i915_gem_object.h
@@ -536,4 +536,9 @@ void i915_gem_object_flush_if_display(struct drm_i915_gem_object *obj);
int i915_gem_vmf_fill_pages_cpu(struct drm_i915_gem_object *obj,
struct vm_fault *vmf,
pgoff_t page_offset);
+
+int i915_vmf_fill_pages_gtt(struct drm_i915_gem_object *obj,
+ struct vm_fault *vmf,
+ pgoff_t page_offset);
+
#endif
--
2.20.1