add uao_read_to_iosys_map() alternative to shmem_read_to_iosys_map()
authorjsg <jsg@openbsd.org>
Thu, 21 Mar 2024 05:14:35 +0000 (05:14 +0000)
committerjsg <jsg@openbsd.org>
Thu, 21 Mar 2024 05:14:35 +0000 (05:14 +0000)
sys/dev/pci/drm/i915/gt/shmem_utils.c
sys/dev/pci/drm/i915/gt/shmem_utils.h

index a5f2ed8..18f598b 100644 (file)
@@ -249,6 +249,38 @@ static int __uao_rw(struct uvm_object *uao, loff_t off,
        return 0;
 }
 
+int uao_read_to_iosys_map(struct uvm_object *uao, loff_t off,
+                           struct iosys_map *map, size_t map_off, size_t len)
+{
+       struct pglist plist;
+       struct vm_page *page;
+       vaddr_t pgoff = trunc_page(off);
+       size_t olen = round_page(len);
+
+       TAILQ_INIT(&plist);
+       if (uvm_obj_wire(uao, pgoff, olen, &plist))
+               return -ENOMEM;
+
+       TAILQ_FOREACH(page, &plist, pageq) {
+               unsigned int this =
+                       min_t(size_t, PAGE_SIZE - offset_in_page(off), len);
+               void *vaddr;
+
+               vaddr = kmap(page);
+               iosys_map_memcpy_to(map, map_off, vaddr + offset_in_page(off),
+                                   this);
+               kunmap_va(vaddr);
+
+               len -= this;
+               map_off += this;
+               off = 0;
+       }
+
+       uvm_obj_unwire(uao, pgoff, olen);
+
+       return 0;
+}
+
 int uao_read(struct uvm_object *uao, loff_t off, void *dst, size_t len)
 {
        return __uao_rw(uao, off, dst, len, false);
index a416139..dcec634 100644 (file)
@@ -27,6 +27,8 @@ int shmem_write(struct file *file, loff_t off, void *src, size_t len);
 
 struct uvm_object *
 uao_create_from_object(struct drm_i915_gem_object *);
+int uao_read_to_iosys_map(struct uvm_object *, loff_t,
+       struct iosys_map *, size_t, size_t);
 int uao_read(struct uvm_object *, loff_t, void *, size_t);
 int uao_write(struct uvm_object *, loff_t, void *, size_t);