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