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