i915_gem_gtt.h 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588
  1. /*
  2. * Copyright © 2014 Intel Corporation
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a
  5. * copy of this software and associated documentation files (the "Software"),
  6. * to deal in the Software without restriction, including without limitation
  7. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8. * and/or sell copies of the Software, and to permit persons to whom the
  9. * Software is furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice (including the next
  12. * paragraph) shall be included in all copies or substantial portions of the
  13. * Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  18. * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  20. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  21. * IN THE SOFTWARE.
  22. *
  23. * Please try to maintain the following order within this file unless it makes
  24. * sense to do otherwise. From top to bottom:
  25. * 1. typedefs
  26. * 2. #defines, and macros
  27. * 3. structure definitions
  28. * 4. function prototypes
  29. *
  30. * Within each section, please try to order by generation in ascending order,
  31. * from top to bottom (ie. gen6 on the top, gen8 on the bottom).
  32. */
  33. #ifndef __I915_GEM_GTT_H__
  34. #define __I915_GEM_GTT_H__
  35. #include <linux/io-mapping.h>
  36. #include <linux/mm.h>
  37. #include "i915_gem_timeline.h"
  38. #include "i915_gem_request.h"
  39. #define I915_GTT_PAGE_SIZE 4096UL
  40. #define I915_GTT_MIN_ALIGNMENT I915_GTT_PAGE_SIZE
  41. #define I915_FENCE_REG_NONE -1
  42. #define I915_MAX_NUM_FENCES 32
  43. /* 32 fences + sign bit for FENCE_REG_NONE */
  44. #define I915_MAX_NUM_FENCE_BITS 6
  45. struct drm_i915_file_private;
  46. struct drm_i915_fence_reg;
  47. typedef uint32_t gen6_pte_t;
  48. typedef uint64_t gen8_pte_t;
  49. typedef uint64_t gen8_pde_t;
  50. typedef uint64_t gen8_ppgtt_pdpe_t;
  51. typedef uint64_t gen8_ppgtt_pml4e_t;
  52. #define ggtt_total_entries(ggtt) ((ggtt)->base.total >> PAGE_SHIFT)
  53. /* gen6-hsw has bit 11-4 for physical addr bit 39-32 */
  54. #define GEN6_GTT_ADDR_ENCODE(addr) ((addr) | (((addr) >> 28) & 0xff0))
  55. #define GEN6_PTE_ADDR_ENCODE(addr) GEN6_GTT_ADDR_ENCODE(addr)
  56. #define GEN6_PDE_ADDR_ENCODE(addr) GEN6_GTT_ADDR_ENCODE(addr)
  57. #define GEN6_PTE_CACHE_LLC (2 << 1)
  58. #define GEN6_PTE_UNCACHED (1 << 1)
  59. #define GEN6_PTE_VALID (1 << 0)
  60. #define I915_PTES(pte_len) (PAGE_SIZE / (pte_len))
  61. #define I915_PTE_MASK(pte_len) (I915_PTES(pte_len) - 1)
  62. #define I915_PDES 512
  63. #define I915_PDE_MASK (I915_PDES - 1)
  64. #define NUM_PTE(pde_shift) (1 << (pde_shift - PAGE_SHIFT))
  65. #define GEN6_PTES I915_PTES(sizeof(gen6_pte_t))
  66. #define GEN6_PD_SIZE (I915_PDES * PAGE_SIZE)
  67. #define GEN6_PD_ALIGN (PAGE_SIZE * 16)
  68. #define GEN6_PDE_SHIFT 22
  69. #define GEN6_PDE_VALID (1 << 0)
  70. #define GEN7_PTE_CACHE_L3_LLC (3 << 1)
  71. #define BYT_PTE_SNOOPED_BY_CPU_CACHES (1 << 2)
  72. #define BYT_PTE_WRITEABLE (1 << 1)
  73. /* Cacheability Control is a 4-bit value. The low three bits are stored in bits
  74. * 3:1 of the PTE, while the fourth bit is stored in bit 11 of the PTE.
  75. */
  76. #define HSW_CACHEABILITY_CONTROL(bits) ((((bits) & 0x7) << 1) | \
  77. (((bits) & 0x8) << (11 - 3)))
  78. #define HSW_WB_LLC_AGE3 HSW_CACHEABILITY_CONTROL(0x2)
  79. #define HSW_WB_LLC_AGE0 HSW_CACHEABILITY_CONTROL(0x3)
  80. #define HSW_WB_ELLC_LLC_AGE3 HSW_CACHEABILITY_CONTROL(0x8)
  81. #define HSW_WB_ELLC_LLC_AGE0 HSW_CACHEABILITY_CONTROL(0xb)
  82. #define HSW_WT_ELLC_LLC_AGE3 HSW_CACHEABILITY_CONTROL(0x7)
  83. #define HSW_WT_ELLC_LLC_AGE0 HSW_CACHEABILITY_CONTROL(0x6)
  84. #define HSW_PTE_UNCACHED (0)
  85. #define HSW_GTT_ADDR_ENCODE(addr) ((addr) | (((addr) >> 28) & 0x7f0))
  86. #define HSW_PTE_ADDR_ENCODE(addr) HSW_GTT_ADDR_ENCODE(addr)
  87. /* GEN8 legacy style address is defined as a 3 level page table:
  88. * 31:30 | 29:21 | 20:12 | 11:0
  89. * PDPE | PDE | PTE | offset
  90. * The difference as compared to normal x86 3 level page table is the PDPEs are
  91. * programmed via register.
  92. *
  93. * GEN8 48b legacy style address is defined as a 4 level page table:
  94. * 47:39 | 38:30 | 29:21 | 20:12 | 11:0
  95. * PML4E | PDPE | PDE | PTE | offset
  96. */
  97. #define GEN8_PML4ES_PER_PML4 512
  98. #define GEN8_PML4E_SHIFT 39
  99. #define GEN8_PML4E_MASK (GEN8_PML4ES_PER_PML4 - 1)
  100. #define GEN8_PDPE_SHIFT 30
  101. /* NB: GEN8_PDPE_MASK is untrue for 32b platforms, but it has no impact on 32b page
  102. * tables */
  103. #define GEN8_PDPE_MASK 0x1ff
  104. #define GEN8_PDE_SHIFT 21
  105. #define GEN8_PDE_MASK 0x1ff
  106. #define GEN8_PTE_SHIFT 12
  107. #define GEN8_PTE_MASK 0x1ff
  108. #define GEN8_LEGACY_PDPES 4
  109. #define GEN8_PTES I915_PTES(sizeof(gen8_pte_t))
  110. #define I915_PDPES_PER_PDP(dev_priv) (USES_FULL_48BIT_PPGTT(dev_priv) ?\
  111. GEN8_PML4ES_PER_PML4 : GEN8_LEGACY_PDPES)
  112. #define PPAT_UNCACHED_INDEX (_PAGE_PWT | _PAGE_PCD)
  113. #define PPAT_CACHED_PDE_INDEX 0 /* WB LLC */
  114. #define PPAT_CACHED_INDEX _PAGE_PAT /* WB LLCeLLC */
  115. #define PPAT_DISPLAY_ELLC_INDEX _PAGE_PCD /* WT eLLC */
  116. #define CHV_PPAT_SNOOP (1<<6)
  117. #define GEN8_PPAT_AGE(x) (x<<4)
  118. #define GEN8_PPAT_LLCeLLC (3<<2)
  119. #define GEN8_PPAT_LLCELLC (2<<2)
  120. #define GEN8_PPAT_LLC (1<<2)
  121. #define GEN8_PPAT_WB (3<<0)
  122. #define GEN8_PPAT_WT (2<<0)
  123. #define GEN8_PPAT_WC (1<<0)
  124. #define GEN8_PPAT_UC (0<<0)
  125. #define GEN8_PPAT_ELLC_OVERRIDE (0<<2)
  126. #define GEN8_PPAT(i, x) ((uint64_t) (x) << ((i) * 8))
  127. struct sg_table;
  128. struct intel_rotation_info {
  129. struct intel_rotation_plane_info {
  130. /* tiles */
  131. unsigned int width, height, stride, offset;
  132. } plane[2];
  133. } __packed;
  134. static inline void assert_intel_rotation_info_is_packed(void)
  135. {
  136. BUILD_BUG_ON(sizeof(struct intel_rotation_info) != 8*sizeof(unsigned int));
  137. }
  138. struct intel_partial_info {
  139. u64 offset;
  140. unsigned int size;
  141. } __packed;
  142. static inline void assert_intel_partial_info_is_packed(void)
  143. {
  144. BUILD_BUG_ON(sizeof(struct intel_partial_info) != sizeof(u64) + sizeof(unsigned int));
  145. }
  146. enum i915_ggtt_view_type {
  147. I915_GGTT_VIEW_NORMAL = 0,
  148. I915_GGTT_VIEW_ROTATED = sizeof(struct intel_rotation_info),
  149. I915_GGTT_VIEW_PARTIAL = sizeof(struct intel_partial_info),
  150. };
  151. static inline void assert_i915_ggtt_view_type_is_unique(void)
  152. {
  153. /* As we encode the size of each branch inside the union into its type,
  154. * we have to be careful that each branch has a unique size.
  155. */
  156. switch ((enum i915_ggtt_view_type)0) {
  157. case I915_GGTT_VIEW_NORMAL:
  158. case I915_GGTT_VIEW_PARTIAL:
  159. case I915_GGTT_VIEW_ROTATED:
  160. /* gcc complains if these are identical cases */
  161. break;
  162. }
  163. }
  164. struct i915_ggtt_view {
  165. enum i915_ggtt_view_type type;
  166. union {
  167. /* Members need to contain no holes/padding */
  168. struct intel_partial_info partial;
  169. struct intel_rotation_info rotated;
  170. };
  171. };
  172. enum i915_cache_level;
  173. struct i915_vma;
  174. struct i915_page_dma {
  175. struct page *page;
  176. union {
  177. dma_addr_t daddr;
  178. /* For gen6/gen7 only. This is the offset in the GGTT
  179. * where the page directory entries for PPGTT begin
  180. */
  181. uint32_t ggtt_offset;
  182. };
  183. };
  184. #define px_base(px) (&(px)->base)
  185. #define px_page(px) (px_base(px)->page)
  186. #define px_dma(px) (px_base(px)->daddr)
  187. struct i915_page_table {
  188. struct i915_page_dma base;
  189. unsigned long *used_ptes;
  190. };
  191. struct i915_page_directory {
  192. struct i915_page_dma base;
  193. unsigned long *used_pdes;
  194. struct i915_page_table *page_table[I915_PDES]; /* PDEs */
  195. };
  196. struct i915_page_directory_pointer {
  197. struct i915_page_dma base;
  198. unsigned long *used_pdpes;
  199. struct i915_page_directory **page_directory;
  200. };
  201. struct i915_pml4 {
  202. struct i915_page_dma base;
  203. DECLARE_BITMAP(used_pml4es, GEN8_PML4ES_PER_PML4);
  204. struct i915_page_directory_pointer *pdps[GEN8_PML4ES_PER_PML4];
  205. };
  206. struct i915_address_space {
  207. struct drm_mm mm;
  208. struct i915_gem_timeline timeline;
  209. struct drm_i915_private *i915;
  210. /* Every address space belongs to a struct file - except for the global
  211. * GTT that is owned by the driver (and so @file is set to NULL). In
  212. * principle, no information should leak from one context to another
  213. * (or between files/processes etc) unless explicitly shared by the
  214. * owner. Tracking the owner is important in order to free up per-file
  215. * objects along with the file, to aide resource tracking, and to
  216. * assign blame.
  217. */
  218. struct drm_i915_file_private *file;
  219. struct list_head global_link;
  220. u64 start; /* Start offset always 0 for dri2 */
  221. u64 total; /* size addr space maps (ex. 2GB for ggtt) */
  222. bool closed;
  223. struct i915_page_dma scratch_page;
  224. struct i915_page_table *scratch_pt;
  225. struct i915_page_directory *scratch_pd;
  226. struct i915_page_directory_pointer *scratch_pdp; /* GEN8+ & 48b PPGTT */
  227. /**
  228. * List of objects currently involved in rendering.
  229. *
  230. * Includes buffers having the contents of their GPU caches
  231. * flushed, not necessarily primitives. last_read_req
  232. * represents when the rendering involved will be completed.
  233. *
  234. * A reference is held on the buffer while on this list.
  235. */
  236. struct list_head active_list;
  237. /**
  238. * LRU list of objects which are not in the ringbuffer and
  239. * are ready to unbind, but are still in the GTT.
  240. *
  241. * last_read_req is NULL while an object is in this list.
  242. *
  243. * A reference is not held on the buffer while on this list,
  244. * as merely being GTT-bound shouldn't prevent its being
  245. * freed, and we'll pull it off the list in the free path.
  246. */
  247. struct list_head inactive_list;
  248. /**
  249. * List of vma that have been unbound.
  250. *
  251. * A reference is not held on the buffer while on this list.
  252. */
  253. struct list_head unbound_list;
  254. /* FIXME: Need a more generic return type */
  255. gen6_pte_t (*pte_encode)(dma_addr_t addr,
  256. enum i915_cache_level level,
  257. u32 flags); /* Create a valid PTE */
  258. /* flags for pte_encode */
  259. #define PTE_READ_ONLY (1<<0)
  260. int (*allocate_va_range)(struct i915_address_space *vm,
  261. uint64_t start,
  262. uint64_t length);
  263. void (*clear_range)(struct i915_address_space *vm,
  264. uint64_t start,
  265. uint64_t length);
  266. void (*insert_page)(struct i915_address_space *vm,
  267. dma_addr_t addr,
  268. uint64_t offset,
  269. enum i915_cache_level cache_level,
  270. u32 flags);
  271. void (*insert_entries)(struct i915_address_space *vm,
  272. struct sg_table *st,
  273. uint64_t start,
  274. enum i915_cache_level cache_level, u32 flags);
  275. void (*cleanup)(struct i915_address_space *vm);
  276. /** Unmap an object from an address space. This usually consists of
  277. * setting the valid PTE entries to a reserved scratch page. */
  278. void (*unbind_vma)(struct i915_vma *vma);
  279. /* Map an object into an address space with the given cache flags. */
  280. int (*bind_vma)(struct i915_vma *vma,
  281. enum i915_cache_level cache_level,
  282. u32 flags);
  283. };
  284. #define i915_is_ggtt(V) (!(V)->file)
  285. /* The Graphics Translation Table is the way in which GEN hardware translates a
  286. * Graphics Virtual Address into a Physical Address. In addition to the normal
  287. * collateral associated with any va->pa translations GEN hardware also has a
  288. * portion of the GTT which can be mapped by the CPU and remain both coherent
  289. * and correct (in cases like swizzling). That region is referred to as GMADR in
  290. * the spec.
  291. */
  292. struct i915_ggtt {
  293. struct i915_address_space base;
  294. struct io_mapping mappable; /* Mapping to our CPU mappable region */
  295. phys_addr_t mappable_base; /* PA of our GMADR */
  296. u64 mappable_end; /* End offset that we can CPU map */
  297. /* Stolen memory is segmented in hardware with different portions
  298. * offlimits to certain functions.
  299. *
  300. * The drm_mm is initialised to the total accessible range, as found
  301. * from the PCI config. On Broadwell+, this is further restricted to
  302. * avoid the first page! The upper end of stolen memory is reserved for
  303. * hardware functions and similarly removed from the accessible range.
  304. */
  305. u32 stolen_size; /* Total size of stolen memory */
  306. u32 stolen_usable_size; /* Total size minus reserved ranges */
  307. u32 stolen_reserved_base;
  308. u32 stolen_reserved_size;
  309. /** "Graphics Stolen Memory" holds the global PTEs */
  310. void __iomem *gsm;
  311. void (*invalidate)(struct drm_i915_private *dev_priv);
  312. bool do_idle_maps;
  313. int mtrr;
  314. struct drm_mm_node error_capture;
  315. };
  316. struct i915_hw_ppgtt {
  317. struct i915_address_space base;
  318. struct kref ref;
  319. struct drm_mm_node node;
  320. unsigned long pd_dirty_rings;
  321. union {
  322. struct i915_pml4 pml4; /* GEN8+ & 48b PPGTT */
  323. struct i915_page_directory_pointer pdp; /* GEN8+ */
  324. struct i915_page_directory pd; /* GEN6-7 */
  325. };
  326. gen6_pte_t __iomem *pd_addr;
  327. int (*enable)(struct i915_hw_ppgtt *ppgtt);
  328. int (*switch_mm)(struct i915_hw_ppgtt *ppgtt,
  329. struct drm_i915_gem_request *req);
  330. void (*debug_dump)(struct i915_hw_ppgtt *ppgtt, struct seq_file *m);
  331. };
  332. /*
  333. * gen6_for_each_pde() iterates over every pde from start until start+length.
  334. * If start and start+length are not perfectly divisible, the macro will round
  335. * down and up as needed. Start=0 and length=2G effectively iterates over
  336. * every PDE in the system. The macro modifies ALL its parameters except 'pd',
  337. * so each of the other parameters should preferably be a simple variable, or
  338. * at most an lvalue with no side-effects!
  339. */
  340. #define gen6_for_each_pde(pt, pd, start, length, iter) \
  341. for (iter = gen6_pde_index(start); \
  342. length > 0 && iter < I915_PDES && \
  343. (pt = (pd)->page_table[iter], true); \
  344. ({ u32 temp = ALIGN(start+1, 1 << GEN6_PDE_SHIFT); \
  345. temp = min(temp - start, length); \
  346. start += temp, length -= temp; }), ++iter)
  347. #define gen6_for_all_pdes(pt, pd, iter) \
  348. for (iter = 0; \
  349. iter < I915_PDES && \
  350. (pt = (pd)->page_table[iter], true); \
  351. ++iter)
  352. static inline uint32_t i915_pte_index(uint64_t address, uint32_t pde_shift)
  353. {
  354. const uint32_t mask = NUM_PTE(pde_shift) - 1;
  355. return (address >> PAGE_SHIFT) & mask;
  356. }
  357. /* Helper to counts the number of PTEs within the given length. This count
  358. * does not cross a page table boundary, so the max value would be
  359. * GEN6_PTES for GEN6, and GEN8_PTES for GEN8.
  360. */
  361. static inline uint32_t i915_pte_count(uint64_t addr, size_t length,
  362. uint32_t pde_shift)
  363. {
  364. const uint64_t mask = ~((1ULL << pde_shift) - 1);
  365. uint64_t end;
  366. WARN_ON(length == 0);
  367. WARN_ON(offset_in_page(addr|length));
  368. end = addr + length;
  369. if ((addr & mask) != (end & mask))
  370. return NUM_PTE(pde_shift) - i915_pte_index(addr, pde_shift);
  371. return i915_pte_index(end, pde_shift) - i915_pte_index(addr, pde_shift);
  372. }
  373. static inline uint32_t i915_pde_index(uint64_t addr, uint32_t shift)
  374. {
  375. return (addr >> shift) & I915_PDE_MASK;
  376. }
  377. static inline uint32_t gen6_pte_index(uint32_t addr)
  378. {
  379. return i915_pte_index(addr, GEN6_PDE_SHIFT);
  380. }
  381. static inline size_t gen6_pte_count(uint32_t addr, uint32_t length)
  382. {
  383. return i915_pte_count(addr, length, GEN6_PDE_SHIFT);
  384. }
  385. static inline uint32_t gen6_pde_index(uint32_t addr)
  386. {
  387. return i915_pde_index(addr, GEN6_PDE_SHIFT);
  388. }
  389. /* Equivalent to the gen6 version, For each pde iterates over every pde
  390. * between from start until start + length. On gen8+ it simply iterates
  391. * over every page directory entry in a page directory.
  392. */
  393. #define gen8_for_each_pde(pt, pd, start, length, iter) \
  394. for (iter = gen8_pde_index(start); \
  395. length > 0 && iter < I915_PDES && \
  396. (pt = (pd)->page_table[iter], true); \
  397. ({ u64 temp = ALIGN(start+1, 1 << GEN8_PDE_SHIFT); \
  398. temp = min(temp - start, length); \
  399. start += temp, length -= temp; }), ++iter)
  400. #define gen8_for_each_pdpe(pd, pdp, start, length, iter) \
  401. for (iter = gen8_pdpe_index(start); \
  402. length > 0 && iter < I915_PDPES_PER_PDP(dev) && \
  403. (pd = (pdp)->page_directory[iter], true); \
  404. ({ u64 temp = ALIGN(start+1, 1 << GEN8_PDPE_SHIFT); \
  405. temp = min(temp - start, length); \
  406. start += temp, length -= temp; }), ++iter)
  407. #define gen8_for_each_pml4e(pdp, pml4, start, length, iter) \
  408. for (iter = gen8_pml4e_index(start); \
  409. length > 0 && iter < GEN8_PML4ES_PER_PML4 && \
  410. (pdp = (pml4)->pdps[iter], true); \
  411. ({ u64 temp = ALIGN(start+1, 1ULL << GEN8_PML4E_SHIFT); \
  412. temp = min(temp - start, length); \
  413. start += temp, length -= temp; }), ++iter)
  414. static inline uint32_t gen8_pte_index(uint64_t address)
  415. {
  416. return i915_pte_index(address, GEN8_PDE_SHIFT);
  417. }
  418. static inline uint32_t gen8_pde_index(uint64_t address)
  419. {
  420. return i915_pde_index(address, GEN8_PDE_SHIFT);
  421. }
  422. static inline uint32_t gen8_pdpe_index(uint64_t address)
  423. {
  424. return (address >> GEN8_PDPE_SHIFT) & GEN8_PDPE_MASK;
  425. }
  426. static inline uint32_t gen8_pml4e_index(uint64_t address)
  427. {
  428. return (address >> GEN8_PML4E_SHIFT) & GEN8_PML4E_MASK;
  429. }
  430. static inline size_t gen8_pte_count(uint64_t address, uint64_t length)
  431. {
  432. return i915_pte_count(address, length, GEN8_PDE_SHIFT);
  433. }
  434. static inline dma_addr_t
  435. i915_page_dir_dma_addr(const struct i915_hw_ppgtt *ppgtt, const unsigned n)
  436. {
  437. return test_bit(n, ppgtt->pdp.used_pdpes) ?
  438. px_dma(ppgtt->pdp.page_directory[n]) :
  439. px_dma(ppgtt->base.scratch_pd);
  440. }
  441. static inline struct i915_ggtt *
  442. i915_vm_to_ggtt(struct i915_address_space *vm)
  443. {
  444. GEM_BUG_ON(!i915_is_ggtt(vm));
  445. return container_of(vm, struct i915_ggtt, base);
  446. }
  447. int i915_ggtt_probe_hw(struct drm_i915_private *dev_priv);
  448. int i915_ggtt_init_hw(struct drm_i915_private *dev_priv);
  449. int i915_ggtt_enable_hw(struct drm_i915_private *dev_priv);
  450. void i915_ggtt_enable_guc(struct drm_i915_private *i915);
  451. void i915_ggtt_disable_guc(struct drm_i915_private *i915);
  452. int i915_gem_init_ggtt(struct drm_i915_private *dev_priv);
  453. void i915_ggtt_cleanup_hw(struct drm_i915_private *dev_priv);
  454. int i915_ppgtt_init_hw(struct drm_i915_private *dev_priv);
  455. void i915_ppgtt_release(struct kref *kref);
  456. struct i915_hw_ppgtt *i915_ppgtt_create(struct drm_i915_private *dev_priv,
  457. struct drm_i915_file_private *fpriv,
  458. const char *name);
  459. void i915_ppgtt_close(struct i915_address_space *vm);
  460. static inline void i915_ppgtt_get(struct i915_hw_ppgtt *ppgtt)
  461. {
  462. if (ppgtt)
  463. kref_get(&ppgtt->ref);
  464. }
  465. static inline void i915_ppgtt_put(struct i915_hw_ppgtt *ppgtt)
  466. {
  467. if (ppgtt)
  468. kref_put(&ppgtt->ref, i915_ppgtt_release);
  469. }
  470. void i915_check_and_clear_faults(struct drm_i915_private *dev_priv);
  471. void i915_gem_suspend_gtt_mappings(struct drm_i915_private *dev_priv);
  472. void i915_gem_restore_gtt_mappings(struct drm_i915_private *dev_priv);
  473. int __must_check i915_gem_gtt_prepare_pages(struct drm_i915_gem_object *obj,
  474. struct sg_table *pages);
  475. void i915_gem_gtt_finish_pages(struct drm_i915_gem_object *obj,
  476. struct sg_table *pages);
  477. int i915_gem_gtt_reserve(struct i915_address_space *vm,
  478. struct drm_mm_node *node,
  479. u64 size, u64 offset, unsigned long color,
  480. unsigned int flags);
  481. int i915_gem_gtt_insert(struct i915_address_space *vm,
  482. struct drm_mm_node *node,
  483. u64 size, u64 alignment, unsigned long color,
  484. u64 start, u64 end, unsigned int flags);
  485. /* Flags used by pin/bind&friends. */
  486. #define PIN_NONBLOCK BIT(0)
  487. #define PIN_MAPPABLE BIT(1)
  488. #define PIN_ZONE_4G BIT(2)
  489. #define PIN_NONFAULT BIT(3)
  490. #define PIN_MBZ BIT(5) /* I915_VMA_PIN_OVERFLOW */
  491. #define PIN_GLOBAL BIT(6) /* I915_VMA_GLOBAL_BIND */
  492. #define PIN_USER BIT(7) /* I915_VMA_LOCAL_BIND */
  493. #define PIN_UPDATE BIT(8)
  494. #define PIN_HIGH BIT(9)
  495. #define PIN_OFFSET_BIAS BIT(10)
  496. #define PIN_OFFSET_FIXED BIT(11)
  497. #define PIN_OFFSET_MASK (-I915_GTT_PAGE_SIZE)
  498. #endif