[PATCH 5/9] drm/i915/gtt: Determine the radices for gen8 page directories

Chris Wilson chris at chris-wilson.co.uk
Sat Jul 6 23:43:43 UTC 2019


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 | 32 +++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)

diff --git a/drivers/gpu/drm/i915/i915_gem_gtt.c b/drivers/gpu/drm/i915/i915_gem_gtt.c
index 2fc60e8acd9a..5eb415b0fc17 100644
--- a/drivers/gpu/drm/i915/i915_gem_gtt.c
+++ b/drivers/gpu/drm/i915/i915_gem_gtt.c
@@ -868,6 +868,38 @@ static int gen8_ppgtt_notify_vgt(struct i915_ppgtt *ppgtt, bool create)
 	return 0;
 }
 
+#define pd_lvl(lvl) ((lvl) * ilog2(I915_PDES))
+#define gen8_pd_shift(lvl) (GEN8_PTE_SHIFT + pd_lvl(lvl))
+#define gen8_pd_size(lvl) BIT_ULL(gen8_pd_shift(lvl))
+#define gen8_pd_index(a, l) i915_pde_index((a), gen8_pd_shift(l))
+
+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);
+
+	end += ~mask >> pd_lvl(1);
+
+	*idx = i915_pde_index(addr, shift);
+	if ((addr & mask) != (end & mask))
+		return I915_PDES - *idx;
+	else
+		return i915_pde_index(end, shift) - *idx;
+}
+
+static inline unsigned int gen8_pd_count(u64 addr, u64 end, int lvl)
+{
+	unsigned int dummy;
+
+	return gen8_pd_range(addr, end, lvl, &dummy);
+}
+
+static inline unsigned int gen8_pt_count(u64 addr, u64 end)
+{
+	return gen8_pd_count(addr, end, 0);
+}
+
 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-trybot mailing list