Home | History | Annotate | Line # | Download | only in gt
intel_gtt.h revision 1.8
      1 /*	$NetBSD: intel_gtt.h,v 1.8 2021/12/19 11:15:33 riastradh Exp $	*/
      2 
      3 /* SPDX-License-Identifier: MIT */
      4 /*
      5  * Copyright  2020 Intel Corporation
      6  *
      7  * Please try to maintain the following order within this file unless it makes
      8  * sense to do otherwise. From top to bottom:
      9  * 1. typedefs
     10  * 2. #defines, and macros
     11  * 3. structure definitions
     12  * 4. function prototypes
     13  *
     14  * Within each section, please try to order by generation in ascending order,
     15  * from top to bottom (ie. gen6 on the top, gen8 on the bottom).
     16  */
     17 
     18 #ifndef __INTEL_GTT_H__
     19 #define __INTEL_GTT_H__
     20 
     21 #include <linux/io-mapping.h>
     22 #include <linux/highmem.h>
     23 #include <linux/kref.h>
     24 #include <linux/mm.h>
     25 #include <linux/pagevec.h>
     26 #include <linux/scatterlist.h>
     27 #include <linux/workqueue.h>
     28 
     29 #include <drm/drm_mm.h>
     30 
     31 #include "gt/intel_reset.h"
     32 #include "i915_gem_fence_reg.h"
     33 #include "i915_selftest.h"
     34 #include "i915_vma_types.h"
     35 
     36 #define I915_GFP_ALLOW_FAIL (GFP_KERNEL | __GFP_RETRY_MAYFAIL | __GFP_NOWARN)
     37 
     38 #if IS_ENABLED(CONFIG_DRM_I915_TRACE_GTT)
     39 #define DBG(...) trace_printk(__VA_ARGS__)
     40 #else
     41 #define DBG(...)
     42 #endif
     43 
     44 #define NALLOC 3 /* 1 normal, 1 for concurrent threads, 1 for preallocation */
     45 
     46 #define I915_GTT_PAGE_SIZE_4K	BIT_ULL(12)
     47 #define I915_GTT_PAGE_SIZE_64K	BIT_ULL(16)
     48 #define I915_GTT_PAGE_SIZE_2M	BIT_ULL(21)
     49 
     50 #define I915_GTT_PAGE_SIZE I915_GTT_PAGE_SIZE_4K
     51 #define I915_GTT_MAX_PAGE_SIZE I915_GTT_PAGE_SIZE_2M
     52 
     53 #define I915_GTT_PAGE_MASK -I915_GTT_PAGE_SIZE
     54 
     55 #define I915_GTT_MIN_ALIGNMENT I915_GTT_PAGE_SIZE
     56 
     57 #define I915_FENCE_REG_NONE -1
     58 #define I915_MAX_NUM_FENCES 32
     59 /* 32 fences + sign bit for FENCE_REG_NONE */
     60 #define I915_MAX_NUM_FENCE_BITS 6
     61 
     62 typedef u32 gen6_pte_t;
     63 typedef u64 gen8_pte_t;
     64 
     65 #define ggtt_total_entries(ggtt) ((ggtt)->vm.total >> PAGE_SHIFT)
     66 
     67 #define I915_PTES(pte_len)		((unsigned int)(PAGE_SIZE / (pte_len)))
     68 #define I915_PTE_MASK(pte_len)		(I915_PTES(pte_len) - 1)
     69 #define I915_PDES			512
     70 #define I915_PDE_MASK			(I915_PDES - 1)
     71 
     72 /* gen6-hsw has bit 11-4 for physical addr bit 39-32 */
     73 #define GEN6_GTT_ADDR_ENCODE(addr)	((addr) | (((addr) >> 28) & 0xff0))
     74 #define GEN6_PTE_ADDR_ENCODE(addr)	GEN6_GTT_ADDR_ENCODE(addr)
     75 #define GEN6_PDE_ADDR_ENCODE(addr)	GEN6_GTT_ADDR_ENCODE(addr)
     76 #define GEN6_PTE_CACHE_LLC		(2 << 1)
     77 #define GEN6_PTE_UNCACHED		(1 << 1)
     78 #define GEN6_PTE_VALID			REG_BIT(0)
     79 
     80 #define GEN6_PTES			I915_PTES(sizeof(gen6_pte_t))
     81 #define GEN6_PD_SIZE		        (I915_PDES * PAGE_SIZE)
     82 #define GEN6_PD_ALIGN			(PAGE_SIZE * 16)
     83 #define GEN6_PDE_SHIFT			22
     84 #define GEN6_PDE_VALID			REG_BIT(0)
     85 #define NUM_PTE(pde_shift)     (1 << (pde_shift - PAGE_SHIFT))
     86 
     87 #define GEN7_PTE_CACHE_L3_LLC		(3 << 1)
     88 
     89 #define BYT_PTE_SNOOPED_BY_CPU_CACHES	REG_BIT(2)
     90 #define BYT_PTE_WRITEABLE		REG_BIT(1)
     91 
     92 /*
     93  * Cacheability Control is a 4-bit value. The low three bits are stored in bits
     94  * 3:1 of the PTE, while the fourth bit is stored in bit 11 of the PTE.
     95  */
     96 #define HSW_CACHEABILITY_CONTROL(bits)	((((bits) & 0x7) << 1) | \
     97 					 (((bits) & 0x8) << (11 - 3)))
     98 #define HSW_WB_LLC_AGE3			HSW_CACHEABILITY_CONTROL(0x2)
     99 #define HSW_WB_LLC_AGE0			HSW_CACHEABILITY_CONTROL(0x3)
    100 #define HSW_WB_ELLC_LLC_AGE3		HSW_CACHEABILITY_CONTROL(0x8)
    101 #define HSW_WB_ELLC_LLC_AGE0		HSW_CACHEABILITY_CONTROL(0xb)
    102 #define HSW_WT_ELLC_LLC_AGE3		HSW_CACHEABILITY_CONTROL(0x7)
    103 #define HSW_WT_ELLC_LLC_AGE0		HSW_CACHEABILITY_CONTROL(0x6)
    104 #define HSW_PTE_UNCACHED		(0)
    105 #define HSW_GTT_ADDR_ENCODE(addr)	((addr) | (((addr) >> 28) & 0x7f0))
    106 #define HSW_PTE_ADDR_ENCODE(addr)	HSW_GTT_ADDR_ENCODE(addr)
    107 
    108 /*
    109  * GEN8 32b style address is defined as a 3 level page table:
    110  * 31:30 | 29:21 | 20:12 |  11:0
    111  * PDPE  |  PDE  |  PTE  | offset
    112  * The difference as compared to normal x86 3 level page table is the PDPEs are
    113  * programmed via register.
    114  *
    115  * GEN8 48b style address is defined as a 4 level page table:
    116  * 47:39 | 38:30 | 29:21 | 20:12 |  11:0
    117  * PML4E | PDPE  |  PDE  |  PTE  | offset
    118  */
    119 #define GEN8_3LVL_PDPES			4
    120 
    121 #define PPAT_UNCACHED			(_PAGE_PWT | _PAGE_PCD)
    122 #define PPAT_CACHED_PDE			0 /* WB LLC */
    123 #define PPAT_CACHED			_PAGE_PAT /* WB LLCeLLC */
    124 #define PPAT_DISPLAY_ELLC		_PAGE_PCD /* WT eLLC */
    125 
    126 #define CHV_PPAT_SNOOP			REG_BIT(6)
    127 #define GEN8_PPAT_AGE(x)		((x)<<4)
    128 #define GEN8_PPAT_LLCeLLC		(3<<2)
    129 #define GEN8_PPAT_LLCELLC		(2<<2)
    130 #define GEN8_PPAT_LLC			(1<<2)
    131 #define GEN8_PPAT_WB			(3<<0)
    132 #define GEN8_PPAT_WT			(2<<0)
    133 #define GEN8_PPAT_WC			(1<<0)
    134 #define GEN8_PPAT_UC			(0<<0)
    135 #define GEN8_PPAT_ELLC_OVERRIDE		(0<<2)
    136 #define GEN8_PPAT(i, x)			((u64)(x) << ((i) * 8))
    137 
    138 #define GEN8_PDE_IPS_64K BIT(11)
    139 #define GEN8_PDE_PS_2M   BIT(7)
    140 
    141 #define for_each_sgt_daddr(__dp, __iter, __sgt) \
    142 	__for_each_sgt_daddr(__dp, __iter, __sgt, I915_GTT_PAGE_SIZE)
    143 
    144 struct i915_page_dma {
    145 	struct page *page;
    146 #ifdef __NetBSD__
    147 	union {
    148 		bus_dma_segment_t seg;
    149 		uint32_t ggtt_offset;
    150 	};
    151 	bus_dmamap_t map;
    152 #else
    153 	union {
    154 		dma_addr_t daddr;
    155 
    156 		/*
    157 		 * For gen6/gen7 only. This is the offset in the GGTT
    158 		 * where the page directory entries for PPGTT begin
    159 		 */
    160 		u32 ggtt_offset;
    161 	};
    162 #endif
    163 };
    164 
    165 struct i915_page_scratch {
    166 	struct i915_page_dma base;
    167 	u64 encode;
    168 };
    169 
    170 struct i915_page_table {
    171 	struct i915_page_dma base;
    172 	atomic_t used;
    173 };
    174 
    175 struct i915_page_directory {
    176 	struct i915_page_table pt;
    177 	spinlock_t lock;
    178 	void *entry[512];
    179 };
    180 
    181 #define __px_choose_expr(x, type, expr, other) \
    182 	__builtin_choose_expr( \
    183 	__builtin_types_compatible_p(typeof(x), type) || \
    184 	__builtin_types_compatible_p(typeof(x), const type), \
    185 	({ type __x = (type)__UNCONST(x); expr; }), \
    186 	other)
    187 
    188 #define px_base(px) \
    189 	__px_choose_expr(px, struct i915_page_dma *, __x, \
    190 	__px_choose_expr(px, struct i915_page_scratch *, &__x->base, \
    191 	__px_choose_expr(px, struct i915_page_table *, &__x->base, \
    192 	__px_choose_expr(px, struct i915_page_directory *, &__x->pt.base, \
    193 	(void)0))))
    194 #ifdef __NetBSD__
    195 #define px_dma(px) (px_base(px)->map->dm_segs[0].ds_addr)
    196 #else
    197 #define px_dma(px) (px_base(px)->daddr)
    198 #endif
    199 
    200 #define px_pt(px) \
    201 	__px_choose_expr(px, struct i915_page_table *, __x, \
    202 	__px_choose_expr(px, struct i915_page_directory *, &__x->pt, \
    203 	(void)0))
    204 #define px_used(px) (&px_pt(px)->used)
    205 
    206 enum i915_cache_level;
    207 
    208 struct drm_i915_file_private;
    209 struct drm_i915_gem_object;
    210 struct i915_vma;
    211 struct intel_gt;
    212 
    213 struct i915_vma_ops {
    214 	/* Map an object into an address space with the given cache flags. */
    215 	int (*bind_vma)(struct i915_vma *vma,
    216 			enum i915_cache_level cache_level,
    217 			u32 flags);
    218 	/*
    219 	 * Unmap an object from an address space. This usually consists of
    220 	 * setting the valid PTE entries to a reserved scratch page.
    221 	 */
    222 	void (*unbind_vma)(struct i915_vma *vma);
    223 
    224 	int (*set_pages)(struct i915_vma *vma);
    225 	void (*clear_pages)(struct i915_vma *vma);
    226 };
    227 
    228 struct pagestash {
    229 #ifndef __NetBSD__
    230 	spinlock_t lock;
    231 	struct pagevec pvec;
    232 #endif
    233 };
    234 
    235 void stash_init(struct pagestash *stash);
    236 
    237 struct i915_address_space {
    238 	struct kref ref;
    239 	struct rcu_work rcu;
    240 
    241 	struct drm_mm mm;
    242 	struct intel_gt *gt;
    243 	struct drm_i915_private *i915;
    244 #ifdef __NetBSD__
    245 	bus_dma_tag_t dmat;
    246 #else
    247 	struct device *dma;
    248 #endif
    249 
    250 	/*
    251 	 * Every address space belongs to a struct file - except for the global
    252 	 * GTT that is owned by the driver (and so @file is set to NULL). In
    253 	 * principle, no information should leak from one context to another
    254 	 * (or between files/processes etc) unless explicitly shared by the
    255 	 * owner. Tracking the owner is important in order to free up per-file
    256 	 * objects along with the file, to aide resource tracking, and to
    257 	 * assign blame.
    258 	 */
    259 	struct drm_i915_file_private *file;
    260 	u64 total;		/* size addr space maps (ex. 2GB for ggtt) */
    261 	u64 reserved;		/* size addr space reserved */
    262 
    263 	unsigned int bind_async_flags;
    264 
    265 	/*
    266 	 * Each active user context has its own address space (in full-ppgtt).
    267 	 * Since the vm may be shared between multiple contexts, we count how
    268 	 * many contexts keep us "open". Once open hits zero, we are closed
    269 	 * and do not allow any new attachments, and proceed to shutdown our
    270 	 * vma and page directories.
    271 	 */
    272 	atomic_t open;
    273 
    274 	struct mutex mutex; /* protects vma and our lists */
    275 #define VM_CLASS_GGTT 0
    276 #define VM_CLASS_PPGTT 1
    277 
    278 	struct i915_page_scratch scratch[4];
    279 	unsigned int scratch_order;
    280 	unsigned int top;
    281 
    282 	/**
    283 	 * List of vma currently bound.
    284 	 */
    285 	struct list_head bound_list;
    286 
    287 #ifndef __NetBSD__
    288 	struct pagestash free_pages;
    289 #endif
    290 
    291 	/* Global GTT */
    292 	bool is_ggtt:1;
    293 
    294 	/* Some systems require uncached updates of the page directories */
    295 	bool pt_kmap_wc:1;
    296 
    297 	/* Some systems support read-only mappings for GGTT and/or PPGTT */
    298 	bool has_read_only:1;
    299 
    300 	u64 (*pte_encode)(dma_addr_t addr,
    301 			  enum i915_cache_level level,
    302 			  u32 flags); /* Create a valid PTE */
    303 #define PTE_READ_ONLY	BIT(0)
    304 
    305 	int (*allocate_va_range)(struct i915_address_space *vm,
    306 				 u64 start, u64 length);
    307 	void (*clear_range)(struct i915_address_space *vm,
    308 			    u64 start, u64 length);
    309 	void (*insert_page)(struct i915_address_space *vm,
    310 			    dma_addr_t addr,
    311 			    u64 offset,
    312 			    enum i915_cache_level cache_level,
    313 			    u32 flags);
    314 	void (*insert_entries)(struct i915_address_space *vm,
    315 			       struct i915_vma *vma,
    316 			       enum i915_cache_level cache_level,
    317 			       u32 flags);
    318 	void (*cleanup)(struct i915_address_space *vm);
    319 
    320 	struct i915_vma_ops vma_ops;
    321 
    322 	I915_SELFTEST_DECLARE(struct fault_attr fault_attr);
    323 	I915_SELFTEST_DECLARE(bool scrub_64K);
    324 };
    325 
    326 /*
    327  * The Graphics Translation Table is the way in which GEN hardware translates a
    328  * Graphics Virtual Address into a Physical Address. In addition to the normal
    329  * collateral associated with any va->pa translations GEN hardware also has a
    330  * portion of the GTT which can be mapped by the CPU and remain both coherent
    331  * and correct (in cases like swizzling). That region is referred to as GMADR in
    332  * the spec.
    333  */
    334 struct i915_ggtt {
    335 	struct i915_address_space vm;
    336 
    337 	struct io_mapping iomap;	/* Mapping to our CPU mappable region */
    338 #ifdef __NetBSD__
    339 	struct {
    340 		bus_addr_t start;
    341 	} gmadr;
    342 #else
    343 	struct resource gmadr;          /* GMADR resource */
    344 #endif
    345 	resource_size_t mappable_end;	/* End offset that we can CPU map */
    346 
    347 	/** "Graphics Stolen Memory" holds the global PTEs */
    348 #ifdef __NetBSD__
    349 	/*
    350 	 * This is not actually the `Graphics Stolen Memory'; it is the
    351 	 * graphics translation table, which we write to through the
    352 	 * GTTADR/GTTMMADR PCI BAR, and which is backed by `Graphics
    353 	 * GTT Stolen Memory'.  That isn't the `Graphics Stolen Memory'
    354 	 * either, although it is stolen from main memory.
    355 	 */
    356 	bus_space_tag_t		gsmt;
    357 	bus_space_handle_t	gsmh;
    358 	bus_size_t		gsmsz;
    359 
    360 	/* Maximum physical address that can be wired into a GTT entry.  */
    361 	uint64_t		max_paddr;
    362 
    363 	/* Page freelist for pages limited to the above maximum address.  */
    364 	int			pgfl;
    365 #else
    366 	void __iomem *gsm;
    367 #endif
    368 	void (*invalidate)(struct i915_ggtt *ggtt);
    369 
    370 	/** PPGTT used for aliasing the PPGTT with the GTT */
    371 	struct i915_ppgtt *alias;
    372 
    373 	bool do_idle_maps;
    374 
    375 	int mtrr;
    376 
    377 	/** Bit 6 swizzling required for X tiling */
    378 	u32 bit_6_swizzle_x;
    379 	/** Bit 6 swizzling required for Y tiling */
    380 	u32 bit_6_swizzle_y;
    381 
    382 	u32 pin_bias;
    383 
    384 	unsigned int num_fences;
    385 	struct i915_fence_reg fence_regs[I915_MAX_NUM_FENCES];
    386 	struct list_head fence_list;
    387 
    388 	/**
    389 	 * List of all objects in gtt_space, currently mmaped by userspace.
    390 	 * All objects within this list must also be on bound_list.
    391 	 */
    392 	struct list_head userfault_list;
    393 
    394 	/* Manual runtime pm autosuspend delay for user GGTT mmaps */
    395 	struct intel_wakeref_auto userfault_wakeref;
    396 
    397 	struct mutex error_mutex;
    398 	struct drm_mm_node error_capture;
    399 	struct drm_mm_node uc_fw;
    400 };
    401 
    402 struct i915_ppgtt {
    403 	struct i915_address_space vm;
    404 
    405 	struct i915_page_directory *pd;
    406 };
    407 
    408 #define i915_is_ggtt(vm) ((vm)->is_ggtt)
    409 
    410 static inline bool
    411 i915_vm_is_4lvl(const struct i915_address_space *vm)
    412 {
    413 	return (vm->total - 1) >> 32;
    414 }
    415 
    416 static inline bool
    417 i915_vm_has_scratch_64K(struct i915_address_space *vm)
    418 {
    419 	return vm->scratch_order == get_order(I915_GTT_PAGE_SIZE_64K);
    420 }
    421 
    422 static inline bool
    423 i915_vm_has_cache_coloring(struct i915_address_space *vm)
    424 {
    425 	return i915_is_ggtt(vm) && vm->mm.color_adjust;
    426 }
    427 
    428 static inline struct i915_ggtt *
    429 i915_vm_to_ggtt(struct i915_address_space *vm)
    430 {
    431 	BUILD_BUG_ON(offsetof(struct i915_ggtt, vm));
    432 	GEM_BUG_ON(!i915_is_ggtt(vm));
    433 	return container_of(vm, struct i915_ggtt, vm);
    434 }
    435 
    436 static inline struct i915_ppgtt *
    437 i915_vm_to_ppgtt(struct i915_address_space *vm)
    438 {
    439 	BUILD_BUG_ON(offsetof(struct i915_ppgtt, vm));
    440 	GEM_BUG_ON(i915_is_ggtt(vm));
    441 	return container_of(vm, struct i915_ppgtt, vm);
    442 }
    443 
    444 static inline struct i915_address_space *
    445 i915_vm_get(struct i915_address_space *vm)
    446 {
    447 	kref_get(&vm->ref);
    448 	return vm;
    449 }
    450 
    451 void i915_vm_release(struct kref *kref);
    452 
    453 static inline void i915_vm_put(struct i915_address_space *vm)
    454 {
    455 	kref_put(&vm->ref, i915_vm_release);
    456 }
    457 
    458 static inline struct i915_address_space *
    459 i915_vm_open(struct i915_address_space *vm)
    460 {
    461 	GEM_BUG_ON(!atomic_read(&vm->open));
    462 	atomic_inc(&vm->open);
    463 	return i915_vm_get(vm);
    464 }
    465 
    466 static inline bool
    467 i915_vm_tryopen(struct i915_address_space *vm)
    468 {
    469 	if (atomic_add_unless(&vm->open, 1, 0))
    470 		return i915_vm_get(vm);
    471 
    472 	return false;
    473 }
    474 
    475 void __i915_vm_close(struct i915_address_space *vm);
    476 
    477 static inline void
    478 i915_vm_close(struct i915_address_space *vm)
    479 {
    480 	GEM_BUG_ON(!atomic_read(&vm->open));
    481 	if (atomic_dec_and_test(&vm->open))
    482 		__i915_vm_close(vm);
    483 
    484 	i915_vm_put(vm);
    485 }
    486 
    487 void i915_address_space_init(struct i915_address_space *vm, int subclass);
    488 void i915_address_space_fini(struct i915_address_space *vm);
    489 
    490 static inline u32 i915_pte_index(u64 address, unsigned int pde_shift)
    491 {
    492 	const u32 mask = NUM_PTE(pde_shift) - 1;
    493 
    494 	return (address >> PAGE_SHIFT) & mask;
    495 }
    496 
    497 /*
    498  * Helper to counts the number of PTEs within the given length. This count
    499  * does not cross a page table boundary, so the max value would be
    500  * GEN6_PTES for GEN6, and GEN8_PTES for GEN8.
    501  */
    502 static inline u32 i915_pte_count(u64 addr, u64 length, unsigned int pde_shift)
    503 {
    504 	const u64 mask = ~((1ULL << pde_shift) - 1);
    505 	u64 end;
    506 
    507 	GEM_BUG_ON(length == 0);
    508 	GEM_BUG_ON(offset_in_page(addr | length));
    509 
    510 	end = addr + length;
    511 
    512 	if ((addr & mask) != (end & mask))
    513 		return NUM_PTE(pde_shift) - i915_pte_index(addr, pde_shift);
    514 
    515 	return i915_pte_index(end, pde_shift) - i915_pte_index(addr, pde_shift);
    516 }
    517 
    518 static inline u32 i915_pde_index(u64 addr, u32 shift)
    519 {
    520 	return (addr >> shift) & I915_PDE_MASK;
    521 }
    522 
    523 static inline struct i915_page_table *
    524 i915_pt_entry(const struct i915_page_directory * const pd,
    525 	      const unsigned short n)
    526 {
    527 	return pd->entry[n];
    528 }
    529 
    530 static inline struct i915_page_directory *
    531 i915_pd_entry(const struct i915_page_directory * const pdp,
    532 	      const unsigned short n)
    533 {
    534 	return pdp->entry[n];
    535 }
    536 
    537 static inline dma_addr_t
    538 i915_page_dir_dma_addr(const struct i915_ppgtt *ppgtt, const unsigned int n)
    539 {
    540 	struct i915_page_dma *pt = ppgtt->pd->entry[n];
    541 
    542 	return px_dma(pt ?: px_base(&ppgtt->vm.scratch[ppgtt->vm.top]));
    543 }
    544 
    545 void ppgtt_init(struct i915_ppgtt *ppgtt, struct intel_gt *gt);
    546 
    547 int i915_ggtt_probe_hw(struct drm_i915_private *i915);
    548 int i915_ggtt_init_hw(struct drm_i915_private *i915);
    549 int i915_ggtt_enable_hw(struct drm_i915_private *i915);
    550 void i915_ggtt_enable_guc(struct i915_ggtt *ggtt);
    551 void i915_ggtt_disable_guc(struct i915_ggtt *ggtt);
    552 int i915_init_ggtt(struct drm_i915_private *i915);
    553 void i915_ggtt_driver_release(struct drm_i915_private *i915);
    554 
    555 static inline bool i915_ggtt_has_aperture(const struct i915_ggtt *ggtt)
    556 {
    557 	return ggtt->mappable_end > 0;
    558 }
    559 
    560 int i915_ppgtt_init_hw(struct intel_gt *gt);
    561 
    562 struct i915_ppgtt *i915_ppgtt_create(struct intel_gt *gt);
    563 
    564 void i915_gem_suspend_gtt_mappings(struct drm_i915_private *i915);
    565 void i915_gem_restore_gtt_mappings(struct drm_i915_private *i915);
    566 
    567 u64 gen8_pte_encode(dma_addr_t addr,
    568 		    enum i915_cache_level level,
    569 		    u32 flags);
    570 
    571 int setup_page_dma(struct i915_address_space *vm, struct i915_page_dma *p);
    572 void cleanup_page_dma(struct i915_address_space *vm, struct i915_page_dma *p);
    573 
    574 #define kmap_atomic_px(px) kmap_atomic(px_base(px)->page)
    575 
    576 void
    577 fill_page_dma(const struct i915_page_dma *p, const u64 val, unsigned int count);
    578 
    579 #define fill_px(px, v) fill_page_dma(px_base(px), (v), PAGE_SIZE / sizeof(u64))
    580 #define fill32_px(px, v) do {						\
    581 	u64 v__ = lower_32_bits(v);					\
    582 	fill_px((px), v__ << 32 | v__);					\
    583 } while (0)
    584 
    585 int setup_scratch_page(struct i915_address_space *vm, gfp_t gfp);
    586 void cleanup_scratch_page(struct i915_address_space *vm);
    587 void free_scratch(struct i915_address_space *vm);
    588 
    589 struct i915_page_table *alloc_pt(struct i915_address_space *vm);
    590 struct i915_page_directory *alloc_pd(struct i915_address_space *vm);
    591 struct i915_page_directory *__alloc_pd(size_t sz);
    592 
    593 void free_pd(struct i915_address_space *vm, struct i915_page_dma *pd);
    594 
    595 #define free_px(vm, px) free_pd(vm, px_base(px))
    596 
    597 void
    598 __set_pd_entry(struct i915_page_directory * const pd,
    599 	       const unsigned short idx,
    600 	       struct i915_page_dma * const to,
    601 	       u64 (*encode)(const dma_addr_t, const enum i915_cache_level));
    602 
    603 #define set_pd_entry(pd, idx, to) \
    604 	__set_pd_entry((pd), (idx), px_base(to), gen8_pde_encode)
    605 
    606 void
    607 clear_pd_entry(struct i915_page_directory * const pd,
    608 	       const unsigned short idx,
    609 	       const struct i915_page_scratch * const scratch);
    610 
    611 bool
    612 release_pd_entry(struct i915_page_directory * const pd,
    613 		 const unsigned short idx,
    614 		 struct i915_page_table * const pt,
    615 		 const struct i915_page_scratch * const scratch);
    616 void gen6_ggtt_invalidate(struct i915_ggtt *ggtt);
    617 
    618 int ggtt_set_pages(struct i915_vma *vma);
    619 int ppgtt_set_pages(struct i915_vma *vma);
    620 void clear_pages(struct i915_vma *vma);
    621 
    622 void gtt_write_workarounds(struct intel_gt *gt);
    623 
    624 void setup_private_pat(struct intel_uncore *uncore);
    625 
    626 #ifdef __NetBSD__
    627 struct sgt_dma {
    628 	bus_dmamap_t map;
    629 	unsigned seg;
    630 	bus_size_t off;
    631 };
    632 static inline struct sgt_dma
    633 sgt_dma(struct i915_vma *vma)
    634 {
    635 	return (struct sgt_dma) { vma->pages, 0, 0 };
    636 }
    637 #else
    638 static inline struct sgt_dma {
    639 	struct scatterlist *sg;
    640 	dma_addr_t dma, max;
    641 } sgt_dma(struct i915_vma *vma) {
    642 	struct scatterlist *sg = vma->pages->sgl;
    643 	dma_addr_t addr = sg_dma_address(sg);
    644 
    645 	return (struct sgt_dma){ sg, addr, addr + sg->length };
    646 }
    647 #endif
    648 
    649 #endif
    650