Commit 1e6437b0 authored by Mika Kuoppala's avatar Mika Kuoppala Committed by Mika Kuoppala

drm/i915/gtt: Prefer i915_vm_is_48bit() over macro

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: default avatarMika Kuoppala <mika.kuoppala@intel.com>
Reviewed-by: default avatarChris Wilson <chris@chris-wilson.co.uk>
Link: http://patchwork.freedesktop.org/patch/msgid/1488295691-9404-3-git-send-email-mika.kuoppala@intel.com
parent 54af56db
...@@ -548,13 +548,18 @@ static void __pdp_fini(struct i915_page_directory_pointer *pdp) ...@@ -548,13 +548,18 @@ static void __pdp_fini(struct i915_page_directory_pointer *pdp)
pdp->page_directory = NULL; 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 * static struct i915_page_directory_pointer *
alloc_pdp(struct i915_address_space *vm) alloc_pdp(struct i915_address_space *vm)
{ {
struct i915_page_directory_pointer *pdp; struct i915_page_directory_pointer *pdp;
int ret = -ENOMEM; int ret = -ENOMEM;
WARN_ON(!USES_FULL_48BIT_PPGTT(vm->i915)); WARN_ON(!use_4lvl(vm));
pdp = kzalloc(sizeof(*pdp), GFP_KERNEL); pdp = kzalloc(sizeof(*pdp), GFP_KERNEL);
if (!pdp) if (!pdp)
...@@ -582,10 +587,12 @@ static void free_pdp(struct i915_address_space *vm, ...@@ -582,10 +587,12 @@ static void free_pdp(struct i915_address_space *vm,
struct i915_page_directory_pointer *pdp) struct i915_page_directory_pointer *pdp)
{ {
__pdp_fini(pdp); __pdp_fini(pdp);
if (USES_FULL_48BIT_PPGTT(vm->i915)) {
cleanup_px(vm, pdp); if (!use_4lvl(vm))
kfree(pdp); return;
}
cleanup_px(vm, pdp);
kfree(pdp);
} }
static void gen8_initialize_pdp(struct i915_address_space *vm, 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, ...@@ -739,7 +746,7 @@ static void gen8_ppgtt_set_pdpe(struct i915_address_space *vm,
gen8_ppgtt_pdpe_t *vaddr; gen8_ppgtt_pdpe_t *vaddr;
pdp->page_directory[pdpe] = pd; pdp->page_directory[pdpe] = pd;
if (!USES_FULL_48BIT_PPGTT(vm->i915)) if (!use_4lvl(vm))
return; return;
vaddr = kmap_atomic_px(pdp); vaddr = kmap_atomic_px(pdp);
...@@ -804,7 +811,7 @@ static void gen8_ppgtt_clear_4lvl(struct i915_address_space *vm, ...@@ -804,7 +811,7 @@ static void gen8_ppgtt_clear_4lvl(struct i915_address_space *vm,
struct i915_page_directory_pointer *pdp; struct i915_page_directory_pointer *pdp;
unsigned int pml4e; 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) { gen8_for_each_pml4e(pdp, pml4, start, length, pml4e) {
GEM_BUG_ON(pdp == vm->scratch_pdp); GEM_BUG_ON(pdp == vm->scratch_pdp);
...@@ -968,7 +975,7 @@ static int gen8_init_scratch(struct i915_address_space *vm) ...@@ -968,7 +975,7 @@ static int gen8_init_scratch(struct i915_address_space *vm)
goto free_pt; goto free_pt;
} }
if (USES_FULL_48BIT_PPGTT(dev)) { if (use_4lvl(vm)) {
vm->scratch_pdp = alloc_pdp(vm); vm->scratch_pdp = alloc_pdp(vm);
if (IS_ERR(vm->scratch_pdp)) { if (IS_ERR(vm->scratch_pdp)) {
ret = PTR_ERR(vm->scratch_pdp); ret = PTR_ERR(vm->scratch_pdp);
...@@ -978,7 +985,7 @@ static int gen8_init_scratch(struct i915_address_space *vm) ...@@ -978,7 +985,7 @@ static int gen8_init_scratch(struct i915_address_space *vm)
gen8_initialize_pt(vm, vm->scratch_pt); gen8_initialize_pt(vm, vm->scratch_pt);
gen8_initialize_pd(vm, vm->scratch_pd); 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); gen8_initialize_pdp(vm, vm->scratch_pdp);
return 0; return 0;
...@@ -995,12 +1002,13 @@ static int gen8_init_scratch(struct i915_address_space *vm) ...@@ -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) static int gen8_ppgtt_notify_vgt(struct i915_hw_ppgtt *ppgtt, bool create)
{ {
struct i915_address_space *vm = &ppgtt->base;
struct drm_i915_private *dev_priv = vm->i915;
enum vgt_g2v_type msg; enum vgt_g2v_type msg;
struct drm_i915_private *dev_priv = ppgtt->base.i915;
int i; int i;
if (USES_FULL_48BIT_PPGTT(dev_priv)) { if (use_4lvl(vm)) {
u64 daddr = px_dma(&ppgtt->pml4); const u64 daddr = px_dma(&ppgtt->pml4);
I915_WRITE(vgtif_reg(pdp[0].lo), lower_32_bits(daddr)); I915_WRITE(vgtif_reg(pdp[0].lo), lower_32_bits(daddr));
I915_WRITE(vgtif_reg(pdp[0].hi), upper_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) ...@@ -1009,7 +1017,7 @@ static int gen8_ppgtt_notify_vgt(struct i915_hw_ppgtt *ppgtt, bool create)
VGT_G2V_PPGTT_L4_PAGE_TABLE_DESTROY); VGT_G2V_PPGTT_L4_PAGE_TABLE_DESTROY);
} else { } else {
for (i = 0; i < GEN8_LEGACY_PDPES; i++) { 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].lo), lower_32_bits(daddr));
I915_WRITE(vgtif_reg(pdp[i].hi), upper_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) ...@@ -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) 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_pdp(vm, vm->scratch_pdp);
free_pd(vm, vm->scratch_pd); free_pd(vm, vm->scratch_pd);
free_pt(vm, vm->scratch_pt); free_pt(vm, vm->scratch_pt);
...@@ -1072,10 +1080,10 @@ static void gen8_ppgtt_cleanup(struct i915_address_space *vm) ...@@ -1072,10 +1080,10 @@ static void gen8_ppgtt_cleanup(struct i915_address_space *vm)
if (intel_vgpu_active(dev_priv)) if (intel_vgpu_active(dev_priv))
gen8_ppgtt_notify_vgt(ppgtt, false); gen8_ppgtt_notify_vgt(ppgtt, false);
if (!USES_FULL_48BIT_PPGTT(vm->i915)) if (use_4lvl(vm))
gen8_ppgtt_cleanup_3lvl(&ppgtt->base, &ppgtt->pdp);
else
gen8_ppgtt_cleanup_4lvl(ppgtt); gen8_ppgtt_cleanup_4lvl(ppgtt);
else
gen8_ppgtt_cleanup_3lvl(&ppgtt->base, &ppgtt->pdp);
gen8_free_scratch(vm); gen8_free_scratch(vm);
} }
...@@ -1258,9 +1266,7 @@ static void gen8_dump_ppgtt(struct i915_hw_ppgtt *ppgtt, struct seq_file *m) ...@@ -1258,9 +1266,7 @@ static void gen8_dump_ppgtt(struct i915_hw_ppgtt *ppgtt, struct seq_file *m)
gen8_pte_encode(vm->scratch_page.daddr, I915_CACHE_LLC); gen8_pte_encode(vm->scratch_page.daddr, I915_CACHE_LLC);
u64 start = 0, length = ppgtt->base.total; u64 start = 0, length = ppgtt->base.total;
if (!USES_FULL_48BIT_PPGTT(vm->i915)) { if (use_4lvl(vm)) {
gen8_dump_pdp(ppgtt, &ppgtt->pdp, start, length, scratch_pte, m);
} else {
u64 pml4e; u64 pml4e;
struct i915_pml4 *pml4 = &ppgtt->pml4; struct i915_pml4 *pml4 = &ppgtt->pml4;
struct i915_page_directory_pointer *pdp; struct i915_page_directory_pointer *pdp;
...@@ -1272,6 +1278,8 @@ static void gen8_dump_ppgtt(struct i915_hw_ppgtt *ppgtt, struct seq_file *m) ...@@ -1272,6 +1278,8 @@ static void gen8_dump_ppgtt(struct i915_hw_ppgtt *ppgtt, struct seq_file *m)
seq_printf(m, " PML4E #%llu\n", pml4e); seq_printf(m, " PML4E #%llu\n", pml4e);
gen8_dump_pdp(ppgtt, pdp, start, length, scratch_pte, m); gen8_dump_pdp(ppgtt, pdp, start, length, scratch_pte, m);
} }
} else {
gen8_dump_pdp(ppgtt, &ppgtt->pdp, start, length, scratch_pte, m);
} }
} }
...@@ -1316,12 +1324,19 @@ static int gen8_preallocate_top_level_pdp(struct i915_hw_ppgtt *ppgtt) ...@@ -1316,12 +1324,19 @@ static int gen8_preallocate_top_level_pdp(struct i915_hw_ppgtt *ppgtt)
*/ */
static int gen8_ppgtt_init(struct i915_hw_ppgtt *ppgtt) static int gen8_ppgtt_init(struct i915_hw_ppgtt *ppgtt)
{ {
struct drm_i915_private *dev_priv = ppgtt->base.i915; struct i915_address_space *vm = &ppgtt->base;
struct drm_i915_private *dev_priv = vm->i915;
int ret; int ret;
ppgtt->base.total = USES_FULL_48BIT_PPGTT(dev_priv) ?
1ULL << 48 :
1ULL << 32;
ret = gen8_init_scratch(&ppgtt->base); ret = gen8_init_scratch(&ppgtt->base);
if (ret) if (ret) {
ppgtt->base.total = 0;
return ret; return ret;
}
ppgtt->base.cleanup = gen8_ppgtt_cleanup; ppgtt->base.cleanup = gen8_ppgtt_cleanup;
ppgtt->base.unbind_vma = ppgtt_unbind_vma; ppgtt->base.unbind_vma = ppgtt_unbind_vma;
...@@ -1334,14 +1349,13 @@ static int gen8_ppgtt_init(struct i915_hw_ppgtt *ppgtt) ...@@ -1334,14 +1349,13 @@ static int gen8_ppgtt_init(struct i915_hw_ppgtt *ppgtt)
if (IS_CHERRYVIEW(dev_priv) || IS_BROXTON(dev_priv)) if (IS_CHERRYVIEW(dev_priv) || IS_BROXTON(dev_priv))
ppgtt->base.pt_kmap_wc = true; ppgtt->base.pt_kmap_wc = true;
if (USES_FULL_48BIT_PPGTT(dev_priv)) { if (use_4lvl(vm)) {
ret = setup_px(&ppgtt->base, &ppgtt->pml4); ret = setup_px(&ppgtt->base, &ppgtt->pml4);
if (ret) if (ret)
goto free_scratch; goto free_scratch;
gen8_initialize_pml4(&ppgtt->base, &ppgtt->pml4); gen8_initialize_pml4(&ppgtt->base, &ppgtt->pml4);
ppgtt->base.total = 1ULL << 48;
ppgtt->switch_mm = gen8_48b_mm_switch; ppgtt->switch_mm = gen8_48b_mm_switch;
ppgtt->base.allocate_va_range = gen8_ppgtt_alloc_4lvl; ppgtt->base.allocate_va_range = gen8_ppgtt_alloc_4lvl;
...@@ -1352,7 +1366,6 @@ static int gen8_ppgtt_init(struct i915_hw_ppgtt *ppgtt) ...@@ -1352,7 +1366,6 @@ static int gen8_ppgtt_init(struct i915_hw_ppgtt *ppgtt)
if (ret) if (ret)
goto free_scratch; goto free_scratch;
ppgtt->base.total = 1ULL << 32;
ppgtt->switch_mm = gen8_legacy_mm_switch; ppgtt->switch_mm = gen8_legacy_mm_switch;
if (intel_vgpu_active(dev_priv)) { if (intel_vgpu_active(dev_priv)) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment