xref: /openbmc/linux/drivers/gpu/drm/i915/gt/gen6_ppgtt.h (revision dc6a81c3)
1 /* SPDX-License-Identifier: MIT */
2 /*
3  * Copyright © 2020 Intel Corporation
4  */
5 
6 #ifndef __GEN6_PPGTT_H__
7 #define __GEN6_PPGTT_H__
8 
9 #include "intel_gtt.h"
10 
11 struct gen6_ppgtt {
12 	struct i915_ppgtt base;
13 
14 	struct mutex flush;
15 	struct i915_vma *vma;
16 	gen6_pte_t __iomem *pd_addr;
17 
18 	atomic_t pin_count;
19 	struct mutex pin_mutex;
20 
21 	bool scan_for_unused_pt;
22 };
23 
24 static inline u32 gen6_pte_index(u32 addr)
25 {
26 	return i915_pte_index(addr, GEN6_PDE_SHIFT);
27 }
28 
29 static inline u32 gen6_pte_count(u32 addr, u32 length)
30 {
31 	return i915_pte_count(addr, length, GEN6_PDE_SHIFT);
32 }
33 
34 static inline u32 gen6_pde_index(u32 addr)
35 {
36 	return i915_pde_index(addr, GEN6_PDE_SHIFT);
37 }
38 
39 #define __to_gen6_ppgtt(base) container_of(base, struct gen6_ppgtt, base)
40 
41 static inline struct gen6_ppgtt *to_gen6_ppgtt(struct i915_ppgtt *base)
42 {
43 	BUILD_BUG_ON(offsetof(struct gen6_ppgtt, base));
44 	return __to_gen6_ppgtt(base);
45 }
46 
47 /*
48  * gen6_for_each_pde() iterates over every pde from start until start+length.
49  * If start and start+length are not perfectly divisible, the macro will round
50  * down and up as needed. Start=0 and length=2G effectively iterates over
51  * every PDE in the system. The macro modifies ALL its parameters except 'pd',
52  * so each of the other parameters should preferably be a simple variable, or
53  * at most an lvalue with no side-effects!
54  */
55 #define gen6_for_each_pde(pt, pd, start, length, iter)			\
56 	for (iter = gen6_pde_index(start);				\
57 	     length > 0 && iter < I915_PDES &&				\
58 		     (pt = i915_pt_entry(pd, iter), true);		\
59 	     ({ u32 temp = ALIGN(start+1, 1 << GEN6_PDE_SHIFT);		\
60 		    temp = min(temp - start, length);			\
61 		    start += temp, length -= temp; }), ++iter)
62 
63 #define gen6_for_all_pdes(pt, pd, iter)					\
64 	for (iter = 0;							\
65 	     iter < I915_PDES &&					\
66 		     (pt = i915_pt_entry(pd, iter), true);		\
67 	     ++iter)
68 
69 int gen6_ppgtt_pin(struct i915_ppgtt *base);
70 void gen6_ppgtt_unpin(struct i915_ppgtt *base);
71 void gen6_ppgtt_unpin_all(struct i915_ppgtt *base);
72 void gen6_ppgtt_enable(struct intel_gt *gt);
73 void gen7_ppgtt_enable(struct intel_gt *gt);
74 struct i915_ppgtt *gen6_ppgtt_create(struct intel_gt *gt);
75 
76 #endif
77