Re: [Intel-gfx] [PATCH 3/5] drm/i915/gtt: Prefer i915_vm_is_48bit() over macro

2017-02-28 Thread Chris Wilson
On Tue, Feb 28, 2017 at 05:28:09PM +0200, Mika Kuoppala wrote:
> If we setup the vm size early, we can use the newly introduced
> i915_vm_is_48bit() in majority of callsites wanting to know the vm size.
> 
> As we operate either with 3lvl or 4lvl page table structure,
> wrap the vm size query inside a function which tells us if
> 4lvl setup is needed for particular vm, as the following
> code uses the function names where level is noted.
> 
> v2: use_4lvl (Chris)
> 
> Signed-off-by: Mika Kuoppala 
Reviewed-by: Chris Wilson 
-Chris

-- 
Chris Wilson, Intel Open Source Technology Centre
___
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx


[Intel-gfx] [PATCH 3/5] drm/i915/gtt: Prefer i915_vm_is_48bit() over macro

2017-02-28 Thread Mika Kuoppala
If we setup the vm size early, we can use the newly introduced
i915_vm_is_48bit() in majority of callsites wanting to know the vm size.

As we operate either with 3lvl or 4lvl page table structure,
wrap the vm size query inside a function which tells us if
4lvl setup is needed for particular vm, as the following
code uses the function names where level is noted.

v2: use_4lvl (Chris)

Signed-off-by: Mika Kuoppala 
---
 drivers/gpu/drm/i915/i915_gem_gtt.c | 63 ++---
 1 file changed, 38 insertions(+), 25 deletions(-)

diff --git a/drivers/gpu/drm/i915/i915_gem_gtt.c 
b/drivers/gpu/drm/i915/i915_gem_gtt.c
index 5299600..9399906 100644
--- a/drivers/gpu/drm/i915/i915_gem_gtt.c
+++ b/drivers/gpu/drm/i915/i915_gem_gtt.c
@@ -548,13 +548,18 @@ static void __pdp_fini(struct i915_page_directory_pointer 
*pdp)
pdp->page_directory = NULL;
 }
 
+static inline bool use_4lvl(const struct i915_address_space *vm)
+{
+   return i915_vm_is_48bit(vm);
+}
+
 static struct i915_page_directory_pointer *
 alloc_pdp(struct i915_address_space *vm)
 {
struct i915_page_directory_pointer *pdp;
int ret = -ENOMEM;
 
-   WARN_ON(!USES_FULL_48BIT_PPGTT(vm->i915));
+   WARN_ON(!use_4lvl(vm));
 
pdp = kzalloc(sizeof(*pdp), GFP_KERNEL);
if (!pdp)
@@ -582,10 +587,12 @@ static void free_pdp(struct i915_address_space *vm,
 struct i915_page_directory_pointer *pdp)
 {
__pdp_fini(pdp);
-   if (USES_FULL_48BIT_PPGTT(vm->i915)) {
-   cleanup_px(vm, pdp);
-   kfree(pdp);
-   }
+
+   if (!use_4lvl(vm))
+   return;
+
+   cleanup_px(vm, pdp);
+   kfree(pdp);
 }
 
 static void gen8_initialize_pdp(struct i915_address_space *vm,
@@ -739,7 +746,7 @@ static void gen8_ppgtt_set_pdpe(struct i915_address_space 
*vm,
gen8_ppgtt_pdpe_t *vaddr;
 
pdp->page_directory[pdpe] = pd;
-   if (!USES_FULL_48BIT_PPGTT(vm->i915))
+   if (!use_4lvl(vm))
return;
 
vaddr = kmap_atomic_px(pdp);
@@ -804,7 +811,7 @@ static void gen8_ppgtt_clear_4lvl(struct i915_address_space 
*vm,
struct i915_page_directory_pointer *pdp;
unsigned int pml4e;
 
-   GEM_BUG_ON(!USES_FULL_48BIT_PPGTT(vm->i915));
+   GEM_BUG_ON(!use_4lvl(vm));
 
gen8_for_each_pml4e(pdp, pml4, start, length, pml4e) {
GEM_BUG_ON(pdp == vm->scratch_pdp);
@@ -968,7 +975,7 @@ static int gen8_init_scratch(struct i915_address_space *vm)
goto free_pt;
}
 
-   if (USES_FULL_48BIT_PPGTT(dev)) {
+   if (use_4lvl(vm)) {
vm->scratch_pdp = alloc_pdp(vm);
if (IS_ERR(vm->scratch_pdp)) {
ret = PTR_ERR(vm->scratch_pdp);
@@ -978,7 +985,7 @@ static int gen8_init_scratch(struct i915_address_space *vm)
 
gen8_initialize_pt(vm, vm->scratch_pt);
gen8_initialize_pd(vm, vm->scratch_pd);
-   if (USES_FULL_48BIT_PPGTT(dev_priv))
+   if (use_4lvl(vm))
gen8_initialize_pdp(vm, vm->scratch_pdp);
 
return 0;
@@ -995,12 +1002,13 @@ static int gen8_init_scratch(struct i915_address_space 
*vm)
 
 static int gen8_ppgtt_notify_vgt(struct i915_hw_ppgtt *ppgtt, bool create)
 {
+   struct i915_address_space *vm = >base;
+   struct drm_i915_private *dev_priv = vm->i915;
enum vgt_g2v_type msg;
-   struct drm_i915_private *dev_priv = ppgtt->base.i915;
int i;
 
-   if (USES_FULL_48BIT_PPGTT(dev_priv)) {
-   u64 daddr = px_dma(>pml4);
+   if (use_4lvl(vm)) {
+   const u64 daddr = px_dma(>pml4);
 
I915_WRITE(vgtif_reg(pdp[0].lo), lower_32_bits(daddr));
I915_WRITE(vgtif_reg(pdp[0].hi), upper_32_bits(daddr));
@@ -1009,7 +1017,7 @@ static int gen8_ppgtt_notify_vgt(struct i915_hw_ppgtt 
*ppgtt, bool create)
VGT_G2V_PPGTT_L4_PAGE_TABLE_DESTROY);
} else {
for (i = 0; i < GEN8_LEGACY_PDPES; i++) {
-   u64 daddr = i915_page_dir_dma_addr(ppgtt, i);
+   const u64 daddr = i915_page_dir_dma_addr(ppgtt, i);
 
I915_WRITE(vgtif_reg(pdp[i].lo), lower_32_bits(daddr));
I915_WRITE(vgtif_reg(pdp[i].hi), upper_32_bits(daddr));
@@ -1026,7 +1034,7 @@ static int gen8_ppgtt_notify_vgt(struct i915_hw_ppgtt 
*ppgtt, bool create)
 
 static void gen8_free_scratch(struct i915_address_space *vm)
 {
-   if (USES_FULL_48BIT_PPGTT(vm->i915))
+   if (use_4lvl(vm))
free_pdp(vm, vm->scratch_pdp);
free_pd(vm, vm->scratch_pd);
free_pt(vm, vm->scratch_pt);
@@ -1072,10 +1080,10 @@ static void gen8_ppgtt_cleanup(struct 
i915_address_space *vm)
if (intel_vgpu_active(dev_priv))
gen8_ppgtt_notify_vgt(ppgtt, false);
 
-   if (!USES_FULL_48BIT_PPGTT(vm->i915))
-