[Intel-gfx] [PATCH 05/11] drm/i915/gtt: Compute the radix for gen8 page table levels

Mika Kuoppala mika.kuoppala at linux.intel.com
Wed Jul 10 09:24:48 UTC 2019


Chris Wilson <chris at chris-wilson.co.uk> writes:

> The radix levels of each page directory are easily determined so replace
> the numerous hardcoded constants with precomputed derived constants.
>
> Signed-off-by: Chris Wilson <chris at chris-wilson.co.uk>
> ---
>  drivers/gpu/drm/i915/i915_gem_gtt.c | 39 +++++++++++++++++++++++++++++
>  1 file changed, 39 insertions(+)
>
> diff --git a/drivers/gpu/drm/i915/i915_gem_gtt.c b/drivers/gpu/drm/i915/i915_gem_gtt.c
> index 2fc60e8acd9a..271305705c1c 100644
> --- a/drivers/gpu/drm/i915/i915_gem_gtt.c
> +++ b/drivers/gpu/drm/i915/i915_gem_gtt.c
> @@ -868,6 +868,45 @@ static int gen8_ppgtt_notify_vgt(struct i915_ppgtt *ppgtt, bool create)
>  	return 0;
>  }
>  
> +/* Index shifts into the pagetable are offset by GEN8_PTE_SHIFT [12] */
> +#define gen8_pd_shift(lvl) ((lvl) * ilog2(I915_PDES))
> +#define gen8_pd_index(i, lvl) i915_pde_index((i), gen8_pd_shift(lvl))
> +#define __gen8_pte_shift(lvl) (GEN8_PTE_SHIFT + gen8_pd_shift(lvl))
> +#define __gen8_pte_index(a, lvl) i915_pde_index((a), __gen8_pte_shift(lvl))
> +
> +static inline unsigned int
> +gen8_pd_range(u64 addr, u64 end, int lvl, unsigned int *idx)
> +{
> +	const int shift = gen8_pd_shift(lvl);
> +	const u64 mask = ~0ull << gen8_pd_shift(lvl + 1);
> +
> +	GEM_BUG_ON(addr >= end);

GEM_BUG_ON(!lvl) ?

> +	end += ~mask >> gen8_pd_shift(1);
> +
> +	*idx = i915_pde_index(addr, shift);

As I see no usage of this macro yet, this looks
wrong as the shift doesn't include the pte shift?

For example for address for first page, we could get index of
7.

-Mika

> +	if ((addr ^ end) & mask)
> +		return I915_PDES - *idx;
> +	else
> +		return i915_pde_index(end, shift) - *idx;
> +}
> +
> +static inline bool gen8_pd_subsumes(u64 addr, u64 end, int lvl)
> +{
> +	const u64 mask = ~0ull << gen8_pd_shift(lvl + 1);
> +
> +	GEM_BUG_ON(addr >= end);
> +	return (addr ^ end) & mask && (addr & ~mask) == 0;
> +}
> +
> +static inline unsigned int gen8_pt_count(u64 addr, u64 end)
> +{
> +	GEM_BUG_ON(addr >= end);
> +	if ((addr ^ end) & ~I915_PDE_MASK)
> +		return I915_PDES - (addr & I915_PDE_MASK);
> +	else
> +		return end - addr;
> +}
> +
>  static void gen8_free_page_tables(struct i915_address_space *vm,
>  				  struct i915_page_directory *pd)
>  {
> -- 
> 2.20.1


More information about the Intel-gfx mailing list