From 0a503ede77f395ac19eba8770e42c9e0665a730d Mon Sep 17 00:00:00 2001 From: jsg Date: Thu, 21 Mar 2024 05:14:35 +0000 Subject: [PATCH] add uao_read_to_iosys_map() alternative to shmem_read_to_iosys_map() --- sys/dev/pci/drm/i915/gt/shmem_utils.c | 32 +++++++++++++++++++++++++++ sys/dev/pci/drm/i915/gt/shmem_utils.h | 2 ++ 2 files changed, 34 insertions(+) diff --git a/sys/dev/pci/drm/i915/gt/shmem_utils.c b/sys/dev/pci/drm/i915/gt/shmem_utils.c index a5f2ed8f652..18f598bd42d 100644 --- a/sys/dev/pci/drm/i915/gt/shmem_utils.c +++ b/sys/dev/pci/drm/i915/gt/shmem_utils.c @@ -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); diff --git a/sys/dev/pci/drm/i915/gt/shmem_utils.h b/sys/dev/pci/drm/i915/gt/shmem_utils.h index a416139db45..dcec6346148 100644 --- a/sys/dev/pci/drm/i915/gt/shmem_utils.h +++ b/sys/dev/pci/drm/i915/gt/shmem_utils.h @@ -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); -- 2.20.1