i915_gem_gtt.h 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602
  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 <linux/pagevec.h>
  38. #include "i915_gem_timeline.h"
  39. #include "i915_gem_request.h"
  40. #include "i915_selftest.h"
  41. #define I915_GTT_PAGE_SIZE 4096UL
  42. #define I915_GTT_MIN_ALIGNMENT I915_GTT_PAGE_SIZE
  43. #define I915_FENCE_REG_NONE -1
  44. #define I915_MAX_NUM_FENCES 32
  45. /* 32 fences + sign bit for FENCE_REG_NONE */
  46. #define I915_MAX_NUM_FENCE_BITS 6
  47. struct drm_i915_file_private;
  48. struct drm_i915_fence_reg;
  49. typedef u32 gen6_pte_t;
  50. typedef u64 gen8_pte_t;
  51. typedef u64 gen8_pde_t;
  52. typedef u64 gen8_ppgtt_pdpe_t;
  53. typedef u64 gen8_ppgtt_pml4e_t;
  54. #define ggtt_total_entries(ggtt) ((ggtt)->base.total >> PAGE_SHIFT)
  55. /* gen6-hsw has bit 11-4 for physical addr bit 39-32 */
  56. #define GEN6_GTT_ADDR_ENCODE(addr) ((addr) | (((addr) >> 28) & 0xff0))
  57. #define GEN6_PTE_ADDR_ENCODE(addr) GEN6_GTT_ADDR_ENCODE(addr)
  58. #define GEN6_PDE_ADDR_ENCODE(addr) GEN6_GTT_ADDR_ENCODE(addr)
  59. #define GEN6_PTE_CACHE_LLC (2 << 1)
  60. #define GEN6_PTE_UNCACHED (1 << 1)
  61. #define GEN6_PTE_VALID (1 << 0)
  62. #define I915_PTES(pte_len) ((unsigned int)(PAGE_SIZE / (pte_len)))
  63. #define I915_PTE_MASK(pte_len) (I915_PTES(pte_len) - 1)
  64. #define I915_PDES 512
  65. #define I915_PDE_MASK (I915_PDES - 1)
  66. #define NUM_PTE(pde_shift) (1 << (pde_shift - PAGE_SHIFT))
  67. #define GEN6_PTES I915_PTES(sizeof(gen6_pte_t))
  68. #define GEN6_PD_SIZE (I915_PDES * PAGE_SIZE)
  69. #define GEN6_PD_ALIGN (PAGE_SIZE * 16)
  70. #define GEN6_PDE_SHIFT 22
  71. #define GEN6_PDE_VALID (1 << 0)
  72. #define GEN7_PTE_CACHE_L3_LLC (3 << 1)
  73. #define BYT_PTE_SNOOPED_BY_CPU_CACHES (1 << 2)
  74. #define BYT_PTE_WRITEABLE (1 << 1)
  75. /* Cacheability Control is a 4-bit value. The low three bits are stored in bits
  76. * 3:1 of the PTE, while the fourth bit is stored in bit 11 of the PTE.
  77. */
  78. #define HSW_CACHEABILITY_CONTROL(bits) ((((bits) & 0x7) << 1) | \
  79. (((bits) & 0x8) << (11 - 3)))
  80. #define HSW_WB_LLC_AGE3 HSW_CACHEABILITY_CONTROL(0x2)
  81. #define HSW_WB_LLC_AGE0 HSW_CACHEABILITY_CONTROL(0x3)
  82. #define HSW_WB_ELLC_LLC_AGE3 HSW_CACHEABILITY_CONTROL(0x8)
  83. #define HSW_WB_ELLC_LLC_AGE0 HSW_CACHEABILITY_CONTROL(0xb)
  84. #define HSW_WT_ELLC_LLC_AGE3 HSW_CACHEABILITY_CONTROL(0x7)
  85. #define HSW_WT_ELLC_LLC_AGE0 HSW_CACHEABILITY_CONTROL(0x6)
  86. #define HSW_PTE_UNCACHED (0)
  87. #define HSW_GTT_ADDR_ENCODE(addr) ((addr) | (((addr) >> 28) & 0x7f0))
  88. #define HSW_PTE_ADDR_ENCODE(addr) HSW_GTT_ADDR_ENCODE(addr)
  89. /* GEN8 32b style address is defined as a 3 level page table:
  90. * 31:30 | 29:21 | 20:12 | 11:0
  91. * PDPE | PDE | PTE | offset
  92. * The difference as compared to normal x86 3 level page table is the PDPEs are
  93. * programmed via register.
  94. */
  95. #define GEN8_3LVL_PDPES 4
  96. #define GEN8_PDE_SHIFT 21
  97. #define GEN8_PDE_MASK 0x1ff
  98. #define GEN8_PTE_SHIFT 12
  99. #define GEN8_PTE_MASK 0x1ff
  100. #define GEN8_PTES I915_PTES(sizeof(gen8_pte_t))
  101. /* GEN8 48b style address is defined as a 4 level page table:
  102. * 47:39 | 38:30 | 29:21 | 20:12 | 11:0
  103. * PML4E | PDPE | PDE | PTE | offset
  104. */
  105. #define GEN8_PML4ES_PER_PML4 512
  106. #define GEN8_PML4E_SHIFT 39
  107. #define GEN8_PML4E_MASK (GEN8_PML4ES_PER_PML4 - 1)
  108. #define GEN8_PDPE_SHIFT 30
  109. /* NB: GEN8_PDPE_MASK is untrue for 32b platforms, but it has no impact on 32b page
  110. * tables */
  111. #define GEN8_PDPE_MASK 0x1ff
  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) ((u64)(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. u32 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 int used_ptes;
  190. };
  191. struct i915_page_directory {
  192. struct i915_page_dma base;
  193. struct i915_page_table *page_table[I915_PDES]; /* PDEs */
  194. unsigned int used_pdes;
  195. };
  196. struct i915_page_directory_pointer {
  197. struct i915_page_dma base;
  198. struct i915_page_directory **page_directory;
  199. unsigned int used_pdpes;
  200. };
  201. struct i915_pml4 {
  202. struct i915_page_dma base;
  203. struct i915_page_directory_pointer *pdps[GEN8_PML4ES_PER_PML4];
  204. };
  205. struct i915_address_space {
  206. struct drm_mm mm;
  207. struct i915_gem_timeline timeline;
  208. struct drm_i915_private *i915;
  209. struct device *dma;
  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 total; /* size addr space maps (ex. 2GB for ggtt) */
  221. bool closed;
  222. struct i915_page_dma scratch_page;
  223. struct i915_page_table *scratch_pt;
  224. struct i915_page_directory *scratch_pd;
  225. struct i915_page_directory_pointer *scratch_pdp; /* GEN8+ & 48b PPGTT */
  226. /**
  227. * List of objects currently involved in rendering.
  228. *
  229. * Includes buffers having the contents of their GPU caches
  230. * flushed, not necessarily primitives. last_read_req
  231. * represents when the rendering involved will be completed.
  232. *
  233. * A reference is held on the buffer while on this list.
  234. */
  235. struct list_head active_list;
  236. /**
  237. * LRU list of objects which are not in the ringbuffer and
  238. * are ready to unbind, but are still in the GTT.
  239. *
  240. * last_read_req is NULL while an object is in this list.
  241. *
  242. * A reference is not held on the buffer while on this list,
  243. * as merely being GTT-bound shouldn't prevent its being
  244. * freed, and we'll pull it off the list in the free path.
  245. */
  246. struct list_head inactive_list;
  247. /**
  248. * List of vma that have been unbound.
  249. *
  250. * A reference is not held on the buffer while on this list.
  251. */
  252. struct list_head unbound_list;
  253. struct pagevec free_pages;
  254. bool pt_kmap_wc;
  255. /* FIXME: Need a more generic return type */
  256. gen6_pte_t (*pte_encode)(dma_addr_t addr,
  257. enum i915_cache_level level,
  258. u32 flags); /* Create a valid PTE */
  259. /* flags for pte_encode */
  260. #define PTE_READ_ONLY (1<<0)
  261. int (*allocate_va_range)(struct i915_address_space *vm,
  262. u64 start, u64 length);
  263. void (*clear_range)(struct i915_address_space *vm,
  264. u64 start, u64 length);
  265. void (*insert_page)(struct i915_address_space *vm,
  266. dma_addr_t addr,
  267. u64 offset,
  268. enum i915_cache_level cache_level,
  269. u32 flags);
  270. void (*insert_entries)(struct i915_address_space *vm,
  271. struct sg_table *st,
  272. u64 start,
  273. enum i915_cache_level cache_level,
  274. 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. I915_SELFTEST_DECLARE(struct fault_attr fault_attr);
  284. };
  285. #define i915_is_ggtt(V) (!(V)->file)
  286. static inline bool
  287. i915_vm_is_48bit(const struct i915_address_space *vm)
  288. {
  289. return (vm->total - 1) >> 32;
  290. }
  291. /* The Graphics Translation Table is the way in which GEN hardware translates a
  292. * Graphics Virtual Address into a Physical Address. In addition to the normal
  293. * collateral associated with any va->pa translations GEN hardware also has a
  294. * portion of the GTT which can be mapped by the CPU and remain both coherent
  295. * and correct (in cases like swizzling). That region is referred to as GMADR in
  296. * the spec.
  297. */
  298. struct i915_ggtt {
  299. struct i915_address_space base;
  300. struct io_mapping mappable; /* Mapping to our CPU mappable region */
  301. phys_addr_t mappable_base; /* PA of our GMADR */
  302. u64 mappable_end; /* End offset that we can CPU map */
  303. /* Stolen memory is segmented in hardware with different portions
  304. * offlimits to certain functions.
  305. *
  306. * The drm_mm is initialised to the total accessible range, as found
  307. * from the PCI config. On Broadwell+, this is further restricted to
  308. * avoid the first page! The upper end of stolen memory is reserved for
  309. * hardware functions and similarly removed from the accessible range.
  310. */
  311. u32 stolen_size; /* Total size of stolen memory */
  312. u32 stolen_usable_size; /* Total size minus reserved ranges */
  313. u32 stolen_reserved_base;
  314. u32 stolen_reserved_size;
  315. /** "Graphics Stolen Memory" holds the global PTEs */
  316. void __iomem *gsm;
  317. void (*invalidate)(struct drm_i915_private *dev_priv);
  318. bool do_idle_maps;
  319. int mtrr;
  320. struct drm_mm_node error_capture;
  321. };
  322. struct i915_hw_ppgtt {
  323. struct i915_address_space base;
  324. struct kref ref;
  325. struct drm_mm_node node;
  326. unsigned long pd_dirty_rings;
  327. union {
  328. struct i915_pml4 pml4; /* GEN8+ & 48b PPGTT */
  329. struct i915_page_directory_pointer pdp; /* GEN8+ */
  330. struct i915_page_directory pd; /* GEN6-7 */
  331. };
  332. gen6_pte_t __iomem *pd_addr;
  333. int (*switch_mm)(struct i915_hw_ppgtt *ppgtt,
  334. struct drm_i915_gem_request *req);
  335. void (*debug_dump)(struct i915_hw_ppgtt *ppgtt, struct seq_file *m);
  336. };
  337. /*
  338. * gen6_for_each_pde() iterates over every pde from start until start+length.
  339. * If start and start+length are not perfectly divisible, the macro will round
  340. * down and up as needed. Start=0 and length=2G effectively iterates over
  341. * every PDE in the system. The macro modifies ALL its parameters except 'pd',
  342. * so each of the other parameters should preferably be a simple variable, or
  343. * at most an lvalue with no side-effects!
  344. */
  345. #define gen6_for_each_pde(pt, pd, start, length, iter) \
  346. for (iter = gen6_pde_index(start); \
  347. length > 0 && iter < I915_PDES && \
  348. (pt = (pd)->page_table[iter], true); \
  349. ({ u32 temp = ALIGN(start+1, 1 << GEN6_PDE_SHIFT); \
  350. temp = min(temp - start, length); \
  351. start += temp, length -= temp; }), ++iter)
  352. #define gen6_for_all_pdes(pt, pd, iter) \
  353. for (iter = 0; \
  354. iter < I915_PDES && \
  355. (pt = (pd)->page_table[iter], true); \
  356. ++iter)
  357. static inline u32 i915_pte_index(u64 address, unsigned int pde_shift)
  358. {
  359. const u32 mask = NUM_PTE(pde_shift) - 1;
  360. return (address >> PAGE_SHIFT) & mask;
  361. }
  362. /* Helper to counts the number of PTEs within the given length. This count
  363. * does not cross a page table boundary, so the max value would be
  364. * GEN6_PTES for GEN6, and GEN8_PTES for GEN8.
  365. */
  366. static inline u32 i915_pte_count(u64 addr, u64 length, unsigned int pde_shift)
  367. {
  368. const u64 mask = ~((1ULL << pde_shift) - 1);
  369. u64 end;
  370. WARN_ON(length == 0);
  371. WARN_ON(offset_in_page(addr|length));
  372. end = addr + length;
  373. if ((addr & mask) != (end & mask))
  374. return NUM_PTE(pde_shift) - i915_pte_index(addr, pde_shift);
  375. return i915_pte_index(end, pde_shift) - i915_pte_index(addr, pde_shift);
  376. }
  377. static inline u32 i915_pde_index(u64 addr, u32 shift)
  378. {
  379. return (addr >> shift) & I915_PDE_MASK;
  380. }
  381. static inline u32 gen6_pte_index(u32 addr)
  382. {
  383. return i915_pte_index(addr, GEN6_PDE_SHIFT);
  384. }
  385. static inline u32 gen6_pte_count(u32 addr, u32 length)
  386. {
  387. return i915_pte_count(addr, length, GEN6_PDE_SHIFT);
  388. }
  389. static inline u32 gen6_pde_index(u32 addr)
  390. {
  391. return i915_pde_index(addr, GEN6_PDE_SHIFT);
  392. }
  393. static inline unsigned int
  394. i915_pdpes_per_pdp(const struct i915_address_space *vm)
  395. {
  396. if (i915_vm_is_48bit(vm))
  397. return GEN8_PML4ES_PER_PML4;
  398. return GEN8_3LVL_PDPES;
  399. }
  400. /* Equivalent to the gen6 version, For each pde iterates over every pde
  401. * between from start until start + length. On gen8+ it simply iterates
  402. * over every page directory entry in a page directory.
  403. */
  404. #define gen8_for_each_pde(pt, pd, start, length, iter) \
  405. for (iter = gen8_pde_index(start); \
  406. length > 0 && iter < I915_PDES && \
  407. (pt = (pd)->page_table[iter], true); \
  408. ({ u64 temp = ALIGN(start+1, 1 << GEN8_PDE_SHIFT); \
  409. temp = min(temp - start, length); \
  410. start += temp, length -= temp; }), ++iter)
  411. #define gen8_for_each_pdpe(pd, pdp, start, length, iter) \
  412. for (iter = gen8_pdpe_index(start); \
  413. length > 0 && iter < i915_pdpes_per_pdp(vm) && \
  414. (pd = (pdp)->page_directory[iter], true); \
  415. ({ u64 temp = ALIGN(start+1, 1 << GEN8_PDPE_SHIFT); \
  416. temp = min(temp - start, length); \
  417. start += temp, length -= temp; }), ++iter)
  418. #define gen8_for_each_pml4e(pdp, pml4, start, length, iter) \
  419. for (iter = gen8_pml4e_index(start); \
  420. length > 0 && iter < GEN8_PML4ES_PER_PML4 && \
  421. (pdp = (pml4)->pdps[iter], true); \
  422. ({ u64 temp = ALIGN(start+1, 1ULL << GEN8_PML4E_SHIFT); \
  423. temp = min(temp - start, length); \
  424. start += temp, length -= temp; }), ++iter)
  425. static inline u32 gen8_pte_index(u64 address)
  426. {
  427. return i915_pte_index(address, GEN8_PDE_SHIFT);
  428. }
  429. static inline u32 gen8_pde_index(u64 address)
  430. {
  431. return i915_pde_index(address, GEN8_PDE_SHIFT);
  432. }
  433. static inline u32 gen8_pdpe_index(u64 address)
  434. {
  435. return (address >> GEN8_PDPE_SHIFT) & GEN8_PDPE_MASK;
  436. }
  437. static inline u32 gen8_pml4e_index(u64 address)
  438. {
  439. return (address >> GEN8_PML4E_SHIFT) & GEN8_PML4E_MASK;
  440. }
  441. static inline u64 gen8_pte_count(u64 address, u64 length)
  442. {
  443. return i915_pte_count(address, length, GEN8_PDE_SHIFT);
  444. }
  445. static inline dma_addr_t
  446. i915_page_dir_dma_addr(const struct i915_hw_ppgtt *ppgtt, const unsigned n)
  447. {
  448. return px_dma(ppgtt->pdp.page_directory[n]);
  449. }
  450. static inline struct i915_ggtt *
  451. i915_vm_to_ggtt(struct i915_address_space *vm)
  452. {
  453. GEM_BUG_ON(!i915_is_ggtt(vm));
  454. return container_of(vm, struct i915_ggtt, base);
  455. }
  456. int i915_gem_init_aliasing_ppgtt(struct drm_i915_private *i915);
  457. void i915_gem_fini_aliasing_ppgtt(struct drm_i915_private *i915);
  458. int i915_ggtt_probe_hw(struct drm_i915_private *dev_priv);
  459. int i915_ggtt_init_hw(struct drm_i915_private *dev_priv);
  460. int i915_ggtt_enable_hw(struct drm_i915_private *dev_priv);
  461. void i915_ggtt_enable_guc(struct drm_i915_private *i915);
  462. void i915_ggtt_disable_guc(struct drm_i915_private *i915);
  463. int i915_gem_init_ggtt(struct drm_i915_private *dev_priv);
  464. void i915_ggtt_cleanup_hw(struct drm_i915_private *dev_priv);
  465. int i915_ppgtt_init_hw(struct drm_i915_private *dev_priv);
  466. void i915_ppgtt_release(struct kref *kref);
  467. struct i915_hw_ppgtt *i915_ppgtt_create(struct drm_i915_private *dev_priv,
  468. struct drm_i915_file_private *fpriv,
  469. const char *name);
  470. void i915_ppgtt_close(struct i915_address_space *vm);
  471. static inline void i915_ppgtt_get(struct i915_hw_ppgtt *ppgtt)
  472. {
  473. if (ppgtt)
  474. kref_get(&ppgtt->ref);
  475. }
  476. static inline void i915_ppgtt_put(struct i915_hw_ppgtt *ppgtt)
  477. {
  478. if (ppgtt)
  479. kref_put(&ppgtt->ref, i915_ppgtt_release);
  480. }
  481. void i915_check_and_clear_faults(struct drm_i915_private *dev_priv);
  482. void i915_gem_suspend_gtt_mappings(struct drm_i915_private *dev_priv);
  483. void i915_gem_restore_gtt_mappings(struct drm_i915_private *dev_priv);
  484. int __must_check i915_gem_gtt_prepare_pages(struct drm_i915_gem_object *obj,
  485. struct sg_table *pages);
  486. void i915_gem_gtt_finish_pages(struct drm_i915_gem_object *obj,
  487. struct sg_table *pages);
  488. int i915_gem_gtt_reserve(struct i915_address_space *vm,
  489. struct drm_mm_node *node,
  490. u64 size, u64 offset, unsigned long color,
  491. unsigned int flags);
  492. int i915_gem_gtt_insert(struct i915_address_space *vm,
  493. struct drm_mm_node *node,
  494. u64 size, u64 alignment, unsigned long color,
  495. u64 start, u64 end, unsigned int flags);
  496. /* Flags used by pin/bind&friends. */
  497. #define PIN_NONBLOCK BIT(0)
  498. #define PIN_MAPPABLE BIT(1)
  499. #define PIN_ZONE_4G BIT(2)
  500. #define PIN_NONFAULT BIT(3)
  501. #define PIN_MBZ BIT(5) /* I915_VMA_PIN_OVERFLOW */
  502. #define PIN_GLOBAL BIT(6) /* I915_VMA_GLOBAL_BIND */
  503. #define PIN_USER BIT(7) /* I915_VMA_LOCAL_BIND */
  504. #define PIN_UPDATE BIT(8)
  505. #define PIN_HIGH BIT(9)
  506. #define PIN_OFFSET_BIAS BIT(10)
  507. #define PIN_OFFSET_FIXED BIT(11)
  508. #define PIN_OFFSET_MASK (-I915_GTT_PAGE_SIZE)
  509. #endif