From: Ben Widawsky <benjamin.widawsky@xxxxxxxxx> Start using gen8_for_each_pde macro to allocate page tables. Signed-off-by: Ben Widawsky <ben@xxxxxxxxxxxx> Signed-off-by: Michel Thierry <michel.thierry@xxxxxxxxx> --- drivers/gpu/drm/i915/i915_gem_gtt.c | 54 ++++++++++++++++++++----------------- drivers/gpu/drm/i915/i915_gem_gtt.h | 10 +++++++ 2 files changed, 39 insertions(+), 25 deletions(-) diff --git a/drivers/gpu/drm/i915/i915_gem_gtt.c b/drivers/gpu/drm/i915/i915_gem_gtt.c index 274b20f..2fb0db7 100644 --- a/drivers/gpu/drm/i915/i915_gem_gtt.c +++ b/drivers/gpu/drm/i915/i915_gem_gtt.c @@ -601,14 +601,6 @@ static void gen8_teardown_va_range(struct i915_address_space *vm, } } -/* This function will die soon */ -static void gen8_free_full_pagedir(struct i915_hw_ppgtt *ppgtt, int i) -{ - gen8_teardown_va_range(&ppgtt->base, - i << GEN8_PDPE_SHIFT, - (1 << GEN8_PDPE_SHIFT)); -} - static void gen8_ppgtt_unmap_pages(struct i915_hw_ppgtt *ppgtt) { struct pci_dev *hwdev = ppgtt->base.dev->pdev; @@ -652,22 +644,27 @@ static void gen8_ppgtt_cleanup(struct i915_address_space *vm) gen8_ppgtt_free(ppgtt); } -static int gen8_ppgtt_allocate_page_tables(struct i915_hw_ppgtt *ppgtt) +static int gen8_ppgtt_alloc_pagetabs(struct i915_pagedir *pd, + uint64_t start, + uint64_t length, + struct drm_device *dev) { - int i, ret; + struct i915_pagetab *unused; + uint64_t temp; + uint32_t pde; - for (i = 0; i < ppgtt->num_pd_pages; i++) { - ret = alloc_pt_range(ppgtt->pdp.pagedir[i], - 0, GEN8_PDES_PER_PAGE, ppgtt->base.dev); - if (ret) + gen8_for_each_pde(unused, pd, start, length, temp, pde) { + BUG_ON(unused); + pd->page_tables[pde] = alloc_pt_single(dev); + if (IS_ERR(pd->page_tables[pde])) goto unwind_out; } return 0; unwind_out: - while (i--) - gen8_free_full_pagedir(ppgtt, i); + while (pde--) + free_pt_single(pd->page_tables[pde], dev); return -ENOMEM; } @@ -710,20 +707,28 @@ unwind_out: } static int gen8_ppgtt_alloc(struct i915_hw_ppgtt *ppgtt, - const int max_pdp) + uint64_t start, + uint64_t length) { + struct i915_pagedir *pd; + uint64_t temp; + uint32_t pdpe; int ret; - ret = gen8_ppgtt_alloc_pagedirs(&ppgtt->pdp, ppgtt->base.start, - ppgtt->base.total); + ret = gen8_ppgtt_alloc_pagedirs(&ppgtt->pdp, start, length); if (ret) return ret; - ret = gen8_ppgtt_allocate_page_tables(ppgtt); - if (ret) - goto err_out; + gen8_for_each_pdpe(pd, &ppgtt->pdp, start, length, temp, pdpe) { + ret = gen8_ppgtt_alloc_pagetabs(pd, start, length, + ppgtt->base.dev); + if (ret) + goto err_out; + + ppgtt->num_pd_entries += GEN8_PDES_PER_PAGE; + } - ppgtt->num_pd_entries = max_pdp * GEN8_PDES_PER_PAGE; + BUG_ON(pdpe > ppgtt->num_pd_pages); return 0; @@ -794,10 +799,9 @@ static int gen8_ppgtt_init(struct i915_hw_ppgtt *ppgtt, uint64_t size) ppgtt->base.start = 0; ppgtt->base.total = size; - BUG_ON(ppgtt->base.total == 0); /* 1. Do all our allocations for page directories and page tables. */ - ret = gen8_ppgtt_alloc(ppgtt, max_pdp); + ret = gen8_ppgtt_alloc(ppgtt, ppgtt->base.start, ppgtt->base.total); if (ret) return ret; diff --git a/drivers/gpu/drm/i915/i915_gem_gtt.h b/drivers/gpu/drm/i915/i915_gem_gtt.h index 7797f0e..d7b71ef 100644 --- a/drivers/gpu/drm/i915/i915_gem_gtt.h +++ b/drivers/gpu/drm/i915/i915_gem_gtt.h @@ -403,6 +403,16 @@ static inline uint32_t gen6_pde_index(uint32_t addr) temp = min(temp, length), \ start += temp, length -= temp) +/* Clamp length to the next pagetab boundary */ +static inline uint64_t gen8_clamp_pt(uint64_t start, uint64_t length) +{ + uint64_t next_pt = ALIGN(start + 1, 1 << GEN8_PDE_SHIFT); + if (next_pt > (start + length)) + return length; + + return next_pt - start; +} + /* Clamp length to the next pagedir boundary */ static inline uint64_t gen8_clamp_pd(uint64_t start, uint64_t length) { -- 2.1.1 _______________________________________________ Intel-gfx mailing list Intel-gfx@xxxxxxxxxxxxxxxxxxxxx http://lists.freedesktop.org/mailman/listinfo/intel-gfx