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