When copying RSA use io memcpy functions if the destination address
contains a GPU local memory address. Considering even the source
address can be on local memory, a bounce buffer is used to copy from io
to io.
The intention of this patch is to make i915 portable outside x86 mainly
on ARM64.

Signed-off-by: Balasubramani Vivekanandan <balasubramani.vivekanan...@intel.com>
---
 drivers/gpu/drm/i915/gt/uc/intel_uc_fw.c | 23 +++++++++++++++++++++--
 1 file changed, 21 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/i915/gt/uc/intel_uc_fw.c 
b/drivers/gpu/drm/i915/gt/uc/intel_uc_fw.c
index bb864655c495..06d30670e15c 100644
--- a/drivers/gpu/drm/i915/gt/uc/intel_uc_fw.c
+++ b/drivers/gpu/drm/i915/gt/uc/intel_uc_fw.c
@@ -589,7 +589,7 @@ static int uc_fw_rsa_data_create(struct intel_uc_fw *uc_fw)
        struct intel_gt *gt = __uc_fw_to_gt(uc_fw);
        struct i915_vma *vma;
        size_t copied;
-       void *vaddr;
+       void *vaddr, *bounce;
        int err;
 
        err = i915_inject_probe_error(gt->i915, -ENXIO);
@@ -621,7 +621,26 @@ static int uc_fw_rsa_data_create(struct intel_uc_fw *uc_fw)
                goto unpin_out;
        }
 
-       copied = intel_uc_fw_copy_rsa(uc_fw, vaddr, vma->size);
+       if (i915_gem_object_is_lmem(vma->obj)) {
+               /* When vma is allocated from the GPU local memmory, it means
+                * the destination address contains an io memory and we need to
+                * use memcpy function for io memory for copying, to ensure
+                * i915 portability outside x86. It is most likely the RSA will
+                * also be on local memory and so the source of copy will also
+                * be an io address. Since we cannot directly copy from io to
+                * io, we use a bounce buffer to copy.
+                */
+               copied = 0;
+               bounce = kmalloc(vma->size, GFP_KERNEL);
+               if (likely(bounce)) {
+                       copied = intel_uc_fw_copy_rsa(uc_fw, bounce, vma->size);
+                       memcpy_toio((void __iomem *)vaddr, bounce, copied);
+                       kfree(bounce);
+               }
+       } else {
+               copied = intel_uc_fw_copy_rsa(uc_fw, vaddr, vma->size);
+       }
+
        i915_gem_object_unpin_map(vma->obj);
 
        if (copied < uc_fw->rsa_size) {
-- 
2.25.1

Reply via email to