Skip to content

Commit cecab0b

Browse files
author
Andi Shyti
committed
drm/i915/gem: Improve pfn calculation readability in vm_fault_gtt()
By moving the pfn calculation to the set_address_limits() function we improve code readability. This way, set_address_limits() is responsible for calculating all memory mapping paramenters: "start", "end" and "pfn". This suggestion from Jonathan was made during the review of commit 8bdd9ef ("drm/i915/gem: Fix Virtual Memory mapping boundaries calculation"), which I liked, but it got lost on the way. Suggested-by: Jonathan Cavitt <[email protected]> Signed-off-by: Andi Shyti <[email protected]> Reviewed-by: Krzysztof Niemiec <[email protected]> Reviewed-by: Jonathan Cavitt <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/[email protected]
1 parent 0829b5b commit cecab0b

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

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

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -293,8 +293,10 @@ static vm_fault_t vm_fault_cpu(struct vm_fault *vmf)
293293
static void set_address_limits(struct vm_area_struct *area,
294294
struct i915_vma *vma,
295295
unsigned long obj_offset,
296+
resource_size_t gmadr_start,
296297
unsigned long *start_vaddr,
297-
unsigned long *end_vaddr)
298+
unsigned long *end_vaddr,
299+
unsigned long *pfn)
298300
{
299301
unsigned long vm_start, vm_end, vma_size; /* user's memory parameters */
300302
long start, end; /* memory boundaries */
@@ -323,6 +325,10 @@ static void set_address_limits(struct vm_area_struct *area,
323325
/* Let's move back into the "<< PAGE_SHIFT" domain */
324326
*start_vaddr = (unsigned long)start << PAGE_SHIFT;
325327
*end_vaddr = (unsigned long)end << PAGE_SHIFT;
328+
329+
*pfn = (gmadr_start + i915_ggtt_offset(vma)) >> PAGE_SHIFT;
330+
*pfn += (*start_vaddr - area->vm_start) >> PAGE_SHIFT;
331+
*pfn += obj_offset - vma->gtt_view.partial.offset;
326332
}
327333

328334
static vm_fault_t vm_fault_gtt(struct vm_fault *vmf)
@@ -441,11 +447,13 @@ static vm_fault_t vm_fault_gtt(struct vm_fault *vmf)
441447
if (ret)
442448
goto err_unpin;
443449

444-
set_address_limits(area, vma, obj_offset, &start, &end);
445-
446-
pfn = (ggtt->gmadr.start + i915_ggtt_offset(vma)) >> PAGE_SHIFT;
447-
pfn += (start - area->vm_start) >> PAGE_SHIFT;
448-
pfn += obj_offset - vma->gtt_view.partial.offset;
450+
/*
451+
* Dump all the necessary parameters in this function to perform the
452+
* arithmetic calculation for the virtual address start and end and
453+
* the PFN (Page Frame Number).
454+
*/
455+
set_address_limits(area, vma, obj_offset, ggtt->gmadr.start,
456+
&start, &end, &pfn);
449457

450458
/* Finally, remap it using the new GTT offset */
451459
ret = remap_io_mapping(area, start, pfn, end - start, &ggtt->iomap);

0 commit comments

Comments
 (0)