Skip to content

Commit 255fc17

Browse files
author
Andi Shyti
committed
drm/i915/gem: Calculate object page offset for partial memory mapping
To enable partial memory mapping of GPU virtual memory, it's necessary to introduce an offset to the object's memory (obj->mm.pages) scatterlist. This adjustment compensates for instances when userspace mappings do not start from the beginning of the object. Based on a patch by Chris Wilson. Signed-off-by: Andi Shyti <[email protected]> Cc: Chris Wilson <[email protected]> Cc: Lionel Landwerlin <[email protected]> Reviewed-by: Nirmoy Das <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/[email protected]
1 parent 609d8b1 commit 255fc17

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

drivers/gpu/drm/i915/gem/i915_gem_mman.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@ static vm_fault_t vm_fault_cpu(struct vm_fault *vmf)
252252
struct vm_area_struct *area = vmf->vma;
253253
struct i915_mmap_offset *mmo = area->vm_private_data;
254254
struct drm_i915_gem_object *obj = mmo->obj;
255+
unsigned long obj_offset;
255256
resource_size_t iomap;
256257
int err;
257258

@@ -273,10 +274,11 @@ static vm_fault_t vm_fault_cpu(struct vm_fault *vmf)
273274
iomap -= obj->mm.region->region.start;
274275
}
275276

277+
obj_offset = area->vm_pgoff - drm_vma_node_start(&mmo->vma_node);
276278
/* PTEs are revoked in obj->ops->put_pages() */
277279
err = remap_io_sg(area,
278280
area->vm_start, area->vm_end - area->vm_start,
279-
obj->mm.pages->sgl, iomap);
281+
obj->mm.pages->sgl, obj_offset, iomap);
280282

281283
if (area->vm_flags & VM_WRITE) {
282284
GEM_BUG_ON(!i915_gem_object_has_pinned_pages(obj));

drivers/gpu/drm/i915/i915_mm.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,13 +122,15 @@ int remap_io_mapping(struct vm_area_struct *vma,
122122
* @addr: target user address to start at
123123
* @size: size of map area
124124
* @sgl: Start sg entry
125+
* @offset: offset from the start of the page
125126
* @iobase: Use stored dma address offset by this address or pfn if -1
126127
*
127128
* Note: this is only safe if the mm semaphore is held when called.
128129
*/
129130
int remap_io_sg(struct vm_area_struct *vma,
130131
unsigned long addr, unsigned long size,
131-
struct scatterlist *sgl, resource_size_t iobase)
132+
struct scatterlist *sgl, unsigned long offset,
133+
resource_size_t iobase)
132134
{
133135
struct remap_pfn r = {
134136
.mm = vma->vm_mm,
@@ -141,6 +143,14 @@ int remap_io_sg(struct vm_area_struct *vma,
141143
/* We rely on prevalidation of the io-mapping to skip track_pfn(). */
142144
GEM_BUG_ON((vma->vm_flags & EXPECTED_FLAGS) != EXPECTED_FLAGS);
143145

146+
while (offset >= sg_dma_len(r.sgt.sgp) >> PAGE_SHIFT) {
147+
offset -= sg_dma_len(r.sgt.sgp) >> PAGE_SHIFT;
148+
r.sgt = __sgt_iter(__sg_next(r.sgt.sgp), use_dma(iobase));
149+
if (!r.sgt.sgp)
150+
return -EINVAL;
151+
}
152+
r.sgt.curr = offset << PAGE_SHIFT;
153+
144154
if (!use_dma(iobase))
145155
flush_cache_range(vma, addr, size);
146156

drivers/gpu/drm/i915/i915_mm.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ int remap_io_mapping(struct vm_area_struct *vma,
3030

3131
int remap_io_sg(struct vm_area_struct *vma,
3232
unsigned long addr, unsigned long size,
33-
struct scatterlist *sgl, resource_size_t iobase);
33+
struct scatterlist *sgl, unsigned long offset,
34+
resource_size_t iobase);
3435

3536
#endif /* __I915_MM_H__ */

0 commit comments

Comments
 (0)