Skip to content

Commit d976521

Browse files
changqin-tangmatt-auld
authored andcommitted
drm/i915: extend i915_vma_pin_iomap()
In the future display might try call this with a normal smem object, which doesn't require PIN_MAPPABLE underneath in order to CPU map the pages (unlike stolen). Extend i915_vma_pin_iomap() to directly use i915_gem_object_pin_map() for such cases. This change was suggested by Chris P Wilson, that we pin the smem with i915_gem_object_pin_map_unlocked(). v2 (jheikkil): Change i915_gem_object_pin_map_unlocked to i915_gem_object_pin_map Signed-off-by: CQ Tang <[email protected]> Signed-off-by: Juha-Pekka Heikkila <[email protected]> Cc: Chris Wilson <[email protected]> Cc: Jari Tahvanainen <[email protected]> Reviewed-by: Matthew Auld <[email protected]> Signed-off-by: Matthew Auld <[email protected]> [mauld: tweak commit message, plus minor checkpatch fix] Link: https://patchwork.freedesktop.org/patch/msgid/[email protected]
1 parent afd5cb3 commit d976521

File tree

1 file changed

+23
-12
lines changed

1 file changed

+23
-12
lines changed

drivers/gpu/drm/i915/i915_vma.c

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -551,13 +551,6 @@ void __iomem *i915_vma_pin_iomap(struct i915_vma *vma)
551551
if (WARN_ON_ONCE(vma->obj->flags & I915_BO_ALLOC_GPU_ONLY))
552552
return IOMEM_ERR_PTR(-EINVAL);
553553

554-
if (!i915_gem_object_is_lmem(vma->obj)) {
555-
if (GEM_WARN_ON(!i915_vma_is_map_and_fenceable(vma))) {
556-
err = -ENODEV;
557-
goto err;
558-
}
559-
}
560-
561554
GEM_BUG_ON(!i915_vma_is_ggtt(vma));
562555
GEM_BUG_ON(!i915_vma_is_bound(vma, I915_VMA_GLOBAL_BIND));
563556
GEM_BUG_ON(i915_vma_verify_bind_complete(vma));
@@ -570,20 +563,33 @@ void __iomem *i915_vma_pin_iomap(struct i915_vma *vma)
570563
* of pages, that way we can also drop the
571564
* I915_BO_ALLOC_CONTIGUOUS when allocating the object.
572565
*/
573-
if (i915_gem_object_is_lmem(vma->obj))
566+
if (i915_gem_object_is_lmem(vma->obj)) {
574567
ptr = i915_gem_object_lmem_io_map(vma->obj, 0,
575568
vma->obj->base.size);
576-
else
569+
} else if (i915_vma_is_map_and_fenceable(vma)) {
577570
ptr = io_mapping_map_wc(&i915_vm_to_ggtt(vma->vm)->iomap,
578571
vma->node.start,
579572
vma->node.size);
573+
} else {
574+
ptr = (void __iomem *)
575+
i915_gem_object_pin_map(vma->obj, I915_MAP_WC);
576+
if (IS_ERR(ptr)) {
577+
err = PTR_ERR(ptr);
578+
goto err;
579+
}
580+
ptr = page_pack_bits(ptr, 1);
581+
}
582+
580583
if (ptr == NULL) {
581584
err = -ENOMEM;
582585
goto err;
583586
}
584587

585588
if (unlikely(cmpxchg(&vma->iomap, NULL, ptr))) {
586-
io_mapping_unmap(ptr);
589+
if (page_unmask_bits(ptr))
590+
__i915_gem_object_release_map(vma->obj);
591+
else
592+
io_mapping_unmap(ptr);
587593
ptr = vma->iomap;
588594
}
589595
}
@@ -597,7 +603,7 @@ void __iomem *i915_vma_pin_iomap(struct i915_vma *vma)
597603
i915_vma_set_ggtt_write(vma);
598604

599605
/* NB Access through the GTT requires the device to be awake. */
600-
return ptr;
606+
return page_mask_bits(ptr);
601607

602608
err_unpin:
603609
__i915_vma_unpin(vma);
@@ -615,6 +621,8 @@ void i915_vma_unpin_iomap(struct i915_vma *vma)
615621
{
616622
GEM_BUG_ON(vma->iomap == NULL);
617623

624+
/* XXX We keep the mapping until __i915_vma_unbind()/evict() */
625+
618626
i915_vma_flush_writes(vma);
619627

620628
i915_vma_unpin_fence(vma);
@@ -1763,7 +1771,10 @@ static void __i915_vma_iounmap(struct i915_vma *vma)
17631771
if (vma->iomap == NULL)
17641772
return;
17651773

1766-
io_mapping_unmap(vma->iomap);
1774+
if (page_unmask_bits(vma->iomap))
1775+
__i915_gem_object_release_map(vma->obj);
1776+
else
1777+
io_mapping_unmap(vma->iomap);
17671778
vma->iomap = NULL;
17681779
}
17691780

0 commit comments

Comments
 (0)