i915_gem_gtt.h 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644
  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_request.h"
  39. #include "i915_selftest.h"
  40. #include "i915_timeline.h"
  41. #define I915_GTT_PAGE_SIZE_4K BIT(12)
  42. #define I915_GTT_PAGE_SIZE_64K BIT(16)
  43. #define I915_GTT_PAGE_SIZE_2M BIT(21)
  44. #define I915_GTT_PAGE_SIZE I915_GTT_PAGE_SIZE_4K
  45. #define I915_GTT_MAX_PAGE_SIZE I915_GTT_PAGE_SIZE_2M
  46. #define I915_GTT_MIN_ALIGNMENT I915_GTT_PAGE_SIZE
  47. #define I915_FENCE_REG_NONE -1
  48. #define I915_MAX_NUM_FENCES 32
  49. /* 32 fences + sign bit for FENCE_REG_NONE */
  50. #define I915_MAX_NUM_FENCE_BITS 6
  51. struct drm_i915_file_private;
  52. struct drm_i915_fence_reg;
  53. typedef u32 gen6_pte_t;
  54. typedef u64 gen8_pte_t;
  55. typedef u64 gen8_pde_t;
  56. typedef u64 gen8_ppgtt_pdpe_t;
  57. typedef u64 gen8_ppgtt_pml4e_t;
  58. #define ggtt_total_entries(ggtt) ((ggtt)->base.total >> PAGE_SHIFT)
  59. /* gen6-hsw has bit 11-4 for physical addr bit 39-32 */
  60. #define GEN6_GTT_ADDR_ENCODE(addr) ((addr) | (((addr) >> 28) & 0xff0))
  61. #define GEN6_PTE_ADDR_ENCODE(addr) GEN6_GTT_ADDR_ENCODE(addr)
  62. #define GEN6_PDE_ADDR_ENCODE(addr) GEN6_GTT_ADDR_ENCODE(addr)
  63. #define GEN6_PTE_CACHE_LLC (2 << 1)
  64. #define GEN6_PTE_UNCACHED (1 << 1)
  65. #define GEN6_PTE_VALID (1 << 0)
  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. #define NUM_PTE(pde_shift) (1 << (pde_shift - PAGE_SHIFT))
  71. #define GEN6_PTES I915_PTES(sizeof(gen6_pte_t))
  72. #define GEN6_PD_SIZE (I915_PDES * PAGE_SIZE)
  73. #define GEN6_PD_ALIGN (PAGE_SIZE * 16)
  74. #define GEN6_PDE_SHIFT 22
  75. #define GEN6_PDE_VALID (1 << 0)
  76. #define GEN7_PTE_CACHE_L3_LLC (3 << 1)
  77. #define BYT_PTE_SNOOPED_BY_CPU_CACHES (1 << 2)
  78. #define BYT_PTE_WRITEABLE (1 << 1)
  79. /* Cacheability Control is a 4-bit value. The low three bits are stored in bits
  80. * 3:1 of the PTE, while the fourth bit is stored in bit 11 of the PTE.
  81. */
  82. #define HSW_CACHEABILITY_CONTROL(bits) ((((bits) & 0x7) << 1) | \
  83. (((bits) & 0x8) << (11 - 3)))
  84. #define HSW_WB_LLC_AGE3 HSW_CACHEABILITY_CONTROL(0x2)
  85. #define HSW_WB_LLC_AGE0 HSW_CACHEABILITY_CONTROL(0x3)
  86. #define HSW_WB_ELLC_LLC_AGE3 HSW_CACHEABILITY_CONTROL(0x8)
  87. #define HSW_WB_ELLC_LLC_AGE0 HSW_CACHEABILITY_CONTROL(0xb)
  88. #define HSW_WT_ELLC_LLC_AGE3 HSW_CACHEABILITY_CONTROL(0x7)
  89. #define HSW_WT_ELLC_LLC_AGE0 HSW_CACHEABILITY_CONTROL(0x6)
  90. #define HSW_PTE_UNCACHED (0)
  91. #define HSW_GTT_ADDR_ENCODE(addr) ((addr) | (((addr) >> 28) & 0x7f0))
  92. #define HSW_PTE_ADDR_ENCODE(addr) HSW_GTT_ADDR_ENCODE(addr)
  93. /* GEN8 32b style address is defined as a 3 level page table:
  94. * 31:30 | 29:21 | 20:12 | 11:0
  95. * PDPE | PDE | PTE | offset
  96. * The difference as compared to normal x86 3 level page table is the PDPEs are
  97. * programmed via register.
  98. */
  99. #define GEN8_3LVL_PDPES 4
  100. #define GEN8_PDE_SHIFT 21
  101. #define GEN8_PDE_MASK 0x1ff
  102. #define GEN8_PTE_SHIFT 12
  103. #define GEN8_PTE_MASK 0x1ff
  104. #define GEN8_PTES I915_PTES(sizeof(gen8_pte_t))
  105. /* GEN8 48b style address is defined as a 4 level page table:
  106. * 47:39 | 38:30 | 29:21 | 20:12 | 11:0
  107. * PML4E | PDPE | PDE | PTE | offset
  108. */
  109. #define GEN8_PML4ES_PER_PML4 512
  110. #define GEN8_PML4E_SHIFT 39
  111. #define GEN8_PML4E_MASK (GEN8_PML4ES_PER_PML4 - 1)
  112. #define GEN8_PDPE_SHIFT 30
  113. /* NB: GEN8_PDPE_MASK is untrue for 32b platforms, but it has no impact on 32b page
  114. * tables */
  115. #define GEN8_PDPE_MASK 0x1ff
  116. #define PPAT_UNCACHED (_PAGE_PWT | _PAGE_PCD)
  117. #define PPAT_CACHED_PDE 0 /* WB LLC */
  118. #define PPAT_CACHED _PAGE_PAT /* WB LLCeLLC */
  119. #define PPAT_DISPLAY_ELLC _PAGE_PCD /* WT eLLC */
  120. #define CHV_PPAT_SNOOP (1<<6)
  121. #define GEN8_PPAT_AGE(x) ((x)<<4)
  122. #define GEN8_PPAT_LLCeLLC (3<<2)
  123. #define GEN8_PPAT_LLCELLC (2<<2)
  124. #define GEN8_PPAT_LLC (1<<2)
  125. #define GEN8_PPAT_WB (3<<0)
  126. #define GEN8_PPAT_WT (2<<0)
  127. #define GEN8_PPAT_WC (1<<0)
  128. #define GEN8_PPAT_UC (0<<0)
  129. #define GEN8_PPAT_ELLC_OVERRIDE (0<<2)
  130. #define GEN8_PPAT(i, x) ((u64)(x) << ((i) * 8))
  131. #define GEN8_PPAT_GET_CA(x) ((x) & 3)
  132. #define GEN8_PPAT_GET_TC(x) ((x) & (3 << 2))
  133. #define GEN8_PPAT_GET_AGE(x) ((x) & (3 << 4))
  134. #define CHV_PPAT_GET_SNOOP(x) ((x) & (1 << 6))
  135. #define GEN8_PDE_IPS_64K BIT(11)
  136. #define GEN8_PDE_PS_2M BIT(7)
  137. struct sg_table;
  138. struct intel_rotation_info {
  139. struct intel_rotation_plane_info {
  140. /* tiles */
  141. unsigned int width, height, stride, offset;
  142. } plane[2];
  143. } __packed;
  144. static inline void assert_intel_rotation_info_is_packed(void)
  145. {
  146. BUILD_BUG_ON(sizeof(struct intel_rotation_info) != 8*sizeof(unsigned int));
  147. }
  148. struct intel_partial_info {
  149. u64 offset;
  150. unsigned int size;
  151. } __packed;
  152. static inline void assert_intel_partial_info_is_packed(void)
  153. {
  154. BUILD_BUG_ON(sizeof(struct intel_partial_info) != sizeof(u64) + sizeof(unsigned int));
  155. }
  156. enum i915_ggtt_view_type {
  157. I915_GGTT_VIEW_NORMAL = 0,
  158. I915_GGTT_VIEW_ROTATED = sizeof(struct intel_rotation_info),
  159. I915_GGTT_VIEW_PARTIAL = sizeof(struct intel_partial_info),
  160. };
  161. static inline void assert_i915_ggtt_view_type_is_unique(void)
  162. {
  163. /* As we encode the size of each branch inside the union into its type,
  164. * we have to be careful that each branch has a unique size.
  165. */
  166. switch ((enum i915_ggtt_view_type)0) {
  167. case I915_GGTT_VIEW_NORMAL:
  168. case I915_GGTT_VIEW_PARTIAL:
  169. case I915_GGTT_VIEW_ROTATED:
  170. /* gcc complains if these are identical cases */
  171. break;
  172. }
  173. }
  174. struct i915_ggtt_view {
  175. enum i915_ggtt_view_type type;
  176. union {
  177. /* Members need to contain no holes/padding */
  178. struct intel_partial_info partial;
  179. struct intel_rotation_info rotated;
  180. };
  181. };
  182. enum i915_cache_level;
  183. struct i915_vma;
  184. struct i915_page_dma {
  185. struct page *page;
  186. int order;
  187. union {
  188. dma_addr_t daddr;
  189. /* For gen6/gen7 only. This is the offset in the GGTT
  190. * where the page directory entries for PPGTT begin
  191. */
  192. u32 ggtt_offset;
  193. };
  194. };
  195. #define px_base(px) (&(px)->base)
  196. #define px_page(px) (px_base(px)->page)
  197. #define px_dma(px) (px_base(px)->daddr)
  198. struct i915_page_table {
  199. struct i915_page_dma base;
  200. unsigned int used_ptes;
  201. };
  202. struct i915_page_directory {
  203. struct i915_page_dma base;
  204. struct i915_page_table *page_table[I915_PDES]; /* PDEs */
  205. unsigned int used_pdes;
  206. };
  207. struct i915_page_directory_pointer {
  208. struct i915_page_dma base;
  209. struct i915_page_directory **page_directory;
  210. unsigned int used_pdpes;
  211. };
  212. struct i915_pml4 {
  213. struct i915_page_dma base;
  214. struct i915_page_directory_pointer *pdps[GEN8_PML4ES_PER_PML4];
  215. };
  216. struct i915_address_space {
  217. struct drm_mm mm;
  218. struct drm_i915_private *i915;
  219. struct device *dma;
  220. /* Every address space belongs to a struct file - except for the global
  221. * GTT that is owned by the driver (and so @file is set to NULL). In
  222. * principle, no information should leak from one context to another
  223. * (or between files/processes etc) unless explicitly shared by the
  224. * owner. Tracking the owner is important in order to free up per-file
  225. * objects along with the file, to aide resource tracking, and to
  226. * assign blame.
  227. */
  228. struct drm_i915_file_private *file;
  229. struct list_head global_link;
  230. u64 total; /* size addr space maps (ex. 2GB for ggtt) */
  231. u64 reserved; /* size addr space reserved */
  232. bool closed;
  233. struct i915_page_dma scratch_page;
  234. struct i915_page_table *scratch_pt;
  235. struct i915_page_directory *scratch_pd;
  236. struct i915_page_directory_pointer *scratch_pdp; /* GEN8+ & 48b PPGTT */
  237. /**
  238. * List of objects currently involved in rendering.
  239. *
  240. * Includes buffers having the contents of their GPU caches
  241. * flushed, not necessarily primitives. last_read_req
  242. * represents when the rendering involved will be completed.
  243. *
  244. * A reference is held on the buffer while on this list.
  245. */
  246. struct list_head active_list;
  247. /**
  248. * LRU list of objects which are not in the ringbuffer and
  249. * are ready to unbind, but are still in the GTT.
  250. *
  251. * last_read_req is NULL while an object is in this list.
  252. *
  253. * A reference is not held on the buffer while on this list,
  254. * as merely being GTT-bound shouldn't prevent its being
  255. * freed, and we'll pull it off the list in the free path.
  256. */
  257. struct list_head inactive_list;
  258. /**
  259. * List of vma that have been unbound.
  260. *
  261. * A reference is not held on the buffer while on this list.
  262. */
  263. struct list_head unbound_list;
  264. struct pagevec free_pages;
  265. bool pt_kmap_wc;
  266. /* FIXME: Need a more generic return type */
  267. gen6_pte_t (*pte_encode)(dma_addr_t addr,
  268. enum i915_cache_level level,
  269. u32 flags); /* Create a valid PTE */
  270. /* flags for pte_encode */
  271. #define PTE_READ_ONLY (1<<0)
  272. int (*allocate_va_range)(struct i915_address_space *vm,
  273. u64 start, u64 length);
  274. void (*clear_range)(struct i915_address_space *vm,
  275. u64 start, u64 length);
  276. void (*insert_page)(struct i915_address_space *vm,
  277. dma_addr_t addr,
  278. u64 offset,
  279. enum i915_cache_level cache_level,
  280. u32 flags);
  281. void (*insert_entries)(struct i915_address_space *vm,
  282. struct i915_vma *vma,
  283. enum i915_cache_level cache_level,
  284. u32 flags);
  285. void (*cleanup)(struct i915_address_space *vm);
  286. /** Unmap an object from an address space. This usually consists of
  287. * setting the valid PTE entries to a reserved scratch page. */
  288. void (*unbind_vma)(struct i915_vma *vma);
  289. /* Map an object into an address space with the given cache flags. */
  290. int (*bind_vma)(struct i915_vma *vma,
  291. enum i915_cache_level cache_level,
  292. u32 flags);
  293. int (*set_pages)(struct i915_vma *vma);
  294. void (*clear_pages)(struct i915_vma *vma);
  295. I915_SELFTEST_DECLARE(struct fault_attr fault_attr);
  296. I915_SELFTEST_DECLARE(bool scrub_64K);
  297. };
  298. #define i915_is_ggtt(V) (!(V)->file)
  299. static inline bool
  300. i915_vm_is_48bit(const struct i915_address_space *vm)
  301. {
  302. return (vm->total - 1) >> 32;
  303. }
  304. static inline bool
  305. i915_vm_has_scratch_64K(struct i915_address_space *vm)
  306. {
  307. return vm->scratch_page.order == get_order(I915_GTT_PAGE_SIZE_64K);
  308. }
  309. /* The Graphics Translation Table is the way in which GEN hardware translates a
  310. * Graphics Virtual Address into a Physical Address. In addition to the normal
  311. * collateral associated with any va->pa translations GEN hardware also has a
  312. * portion of the GTT which can be mapped by the CPU and remain both coherent
  313. * and correct (in cases like swizzling). That region is referred to as GMADR in
  314. * the spec.
  315. */
  316. struct i915_ggtt {
  317. struct i915_address_space base;
  318. struct io_mapping iomap; /* Mapping to our CPU mappable region */
  319. struct resource gmadr; /* GMADR resource */
  320. resource_size_t mappable_end; /* End offset that we can CPU map */
  321. /** "Graphics Stolen Memory" holds the global PTEs */
  322. void __iomem *gsm;
  323. void (*invalidate)(struct drm_i915_private *dev_priv);
  324. bool do_idle_maps;
  325. int mtrr;
  326. struct drm_mm_node error_capture;
  327. };
  328. struct i915_hw_ppgtt {
  329. struct i915_address_space base;
  330. struct kref ref;
  331. struct drm_mm_node node;
  332. unsigned long pd_dirty_rings;
  333. union {
  334. struct i915_pml4 pml4; /* GEN8+ & 48b PPGTT */
  335. struct i915_page_directory_pointer pdp; /* GEN8+ */
  336. struct i915_page_directory pd; /* GEN6-7 */
  337. };
  338. gen6_pte_t __iomem *pd_addr;
  339. int (*switch_mm)(struct i915_hw_ppgtt *ppgtt,
  340. struct i915_request *rq);
  341. void (*debug_dump)(struct i915_hw_ppgtt *ppgtt, struct seq_file *m);
  342. };
  343. /*
  344. * gen6_for_each_pde() iterates over every pde from start until start+length.
  345. * If start and start+length are not perfectly divisible, the macro will round
  346. * down and up as needed. Start=0 and length=2G effectively iterates over
  347. * every PDE in the system. The macro modifies ALL its parameters except 'pd',
  348. * so each of the other parameters should preferably be a simple variable, or
  349. * at most an lvalue with no side-effects!
  350. */
  351. #define gen6_for_each_pde(pt, pd, start, length, iter) \
  352. for (iter = gen6_pde_index(start); \
  353. length > 0 && iter < I915_PDES && \
  354. (pt = (pd)->page_table[iter], true); \
  355. ({ u32 temp = ALIGN(start+1, 1 << GEN6_PDE_SHIFT); \
  356. temp = min(temp - start, length); \
  357. start += temp, length -= temp; }), ++iter)
  358. #define gen6_for_all_pdes(pt, pd, iter) \
  359. for (iter = 0; \
  360. iter < I915_PDES && \
  361. (pt = (pd)->page_table[iter], true); \
  362. ++iter)
  363. static inline u32 i915_pte_index(u64 address, unsigned int pde_shift)
  364. {
  365. const u32 mask = NUM_PTE(pde_shift) - 1;
  366. return (address >> PAGE_SHIFT) & mask;
  367. }
  368. /* Helper to counts the number of PTEs within the given length. This count
  369. * does not cross a page table boundary, so the max value would be
  370. * GEN6_PTES for GEN6, and GEN8_PTES for GEN8.
  371. */
  372. static inline u32 i915_pte_count(u64 addr, u64 length, unsigned int pde_shift)
  373. {
  374. const u64 mask = ~((1ULL << pde_shift) - 1);
  375. u64 end;
  376. WARN_ON(length == 0);
  377. WARN_ON(offset_in_page(addr|length));
  378. end = addr + length;
  379. if ((addr & mask) != (end & mask))
  380. return NUM_PTE(pde_shift) - i915_pte_index(addr, pde_shift);
  381. return i915_pte_index(end, pde_shift) - i915_pte_index(addr, pde_shift);
  382. }
  383. static inline u32 i915_pde_index(u64 addr, u32 shift)
  384. {
  385. return (addr >> shift) & I915_PDE_MASK;
  386. }
  387. static inline u32 gen6_pte_index(u32 addr)
  388. {
  389. return i915_pte_index(addr, GEN6_PDE_SHIFT);
  390. }
  391. static inline u32 gen6_pte_count(u32 addr, u32 length)
  392. {
  393. return i915_pte_count(addr, length, GEN6_PDE_SHIFT);
  394. }
  395. static inline u32 gen6_pde_index(u32 addr)
  396. {
  397. return i915_pde_index(addr, GEN6_PDE_SHIFT);
  398. }
  399. static inline unsigned int
  400. i915_pdpes_per_pdp(const struct i915_address_space *vm)
  401. {
  402. if (i915_vm_is_48bit(vm))
  403. return GEN8_PML4ES_PER_PML4;
  404. return GEN8_3LVL_PDPES;
  405. }
  406. /* Equivalent to the gen6 version, For each pde iterates over every pde
  407. * between from start until start + length. On gen8+ it simply iterates
  408. * over every page directory entry in a page directory.
  409. */
  410. #define gen8_for_each_pde(pt, pd, start, length, iter) \
  411. for (iter = gen8_pde_index(start); \
  412. length > 0 && iter < I915_PDES && \
  413. (pt = (pd)->page_table[iter], true); \
  414. ({ u64 temp = ALIGN(start+1, 1 << GEN8_PDE_SHIFT); \
  415. temp = min(temp - start, length); \
  416. start += temp, length -= temp; }), ++iter)
  417. #define gen8_for_each_pdpe(pd, pdp, start, length, iter) \
  418. for (iter = gen8_pdpe_index(start); \
  419. length > 0 && iter < i915_pdpes_per_pdp(vm) && \
  420. (pd = (pdp)->page_directory[iter], true); \
  421. ({ u64 temp = ALIGN(start+1, 1 << GEN8_PDPE_SHIFT); \
  422. temp = min(temp - start, length); \
  423. start += temp, length -= temp; }), ++iter)
  424. #define gen8_for_each_pml4e(pdp, pml4, start, length, iter) \
  425. for (iter = gen8_pml4e_index(start); \
  426. length > 0 && iter < GEN8_PML4ES_PER_PML4 && \
  427. (pdp = (pml4)->pdps[iter], true); \
  428. ({ u64 temp = ALIGN(start+1, 1ULL << GEN8_PML4E_SHIFT); \
  429. temp = min(temp - start, length); \
  430. start += temp, length -= temp; }), ++iter)
  431. static inline u32 gen8_pte_index(u64 address)
  432. {
  433. return i915_pte_index(address, GEN8_PDE_SHIFT);
  434. }
  435. static inline u32 gen8_pde_index(u64 address)
  436. {
  437. return i915_pde_index(address, GEN8_PDE_SHIFT);
  438. }
  439. static inline u32 gen8_pdpe_index(u64 address)
  440. {
  441. return (address >> GEN8_PDPE_SHIFT) & GEN8_PDPE_MASK;
  442. }
  443. static inline u32 gen8_pml4e_index(u64 address)
  444. {
  445. return (address >> GEN8_PML4E_SHIFT) & GEN8_PML4E_MASK;
  446. }
  447. static inline u64 gen8_pte_count(u64 address, u64 length)
  448. {
  449. return i915_pte_count(address, length, GEN8_PDE_SHIFT);
  450. }
  451. static inline dma_addr_t
  452. i915_page_dir_dma_addr(const struct i915_hw_ppgtt *ppgtt, const unsigned n)
  453. {
  454. return px_dma(ppgtt->pdp.page_directory[n]);
  455. }
  456. static inline struct i915_ggtt *
  457. i915_vm_to_ggtt(struct i915_address_space *vm)
  458. {
  459. GEM_BUG_ON(!i915_is_ggtt(vm));
  460. return container_of(vm, struct i915_ggtt, base);
  461. }
  462. #define INTEL_MAX_PPAT_ENTRIES 8
  463. #define INTEL_PPAT_PERFECT_MATCH (~0U)
  464. struct intel_ppat;
  465. struct intel_ppat_entry {
  466. struct intel_ppat *ppat;
  467. struct kref ref;
  468. u8 value;
  469. };
  470. struct intel_ppat {
  471. struct intel_ppat_entry entries[INTEL_MAX_PPAT_ENTRIES];
  472. DECLARE_BITMAP(used, INTEL_MAX_PPAT_ENTRIES);
  473. DECLARE_BITMAP(dirty, INTEL_MAX_PPAT_ENTRIES);
  474. unsigned int max_entries;
  475. u8 clear_value;
  476. /*
  477. * Return a score to show how two PPAT values match,
  478. * a INTEL_PPAT_PERFECT_MATCH indicates a perfect match
  479. */
  480. unsigned int (*match)(u8 src, u8 dst);
  481. void (*update_hw)(struct drm_i915_private *i915);
  482. struct drm_i915_private *i915;
  483. };
  484. const struct intel_ppat_entry *
  485. intel_ppat_get(struct drm_i915_private *i915, u8 value);
  486. void intel_ppat_put(const struct intel_ppat_entry *entry);
  487. int i915_gem_init_aliasing_ppgtt(struct drm_i915_private *i915);
  488. void i915_gem_fini_aliasing_ppgtt(struct drm_i915_private *i915);
  489. int i915_ggtt_probe_hw(struct drm_i915_private *dev_priv);
  490. int i915_ggtt_init_hw(struct drm_i915_private *dev_priv);
  491. int i915_ggtt_enable_hw(struct drm_i915_private *dev_priv);
  492. void i915_ggtt_enable_guc(struct drm_i915_private *i915);
  493. void i915_ggtt_disable_guc(struct drm_i915_private *i915);
  494. int i915_gem_init_ggtt(struct drm_i915_private *dev_priv);
  495. void i915_ggtt_cleanup_hw(struct drm_i915_private *dev_priv);
  496. int i915_ppgtt_init_hw(struct drm_i915_private *dev_priv);
  497. void i915_ppgtt_release(struct kref *kref);
  498. struct i915_hw_ppgtt *i915_ppgtt_create(struct drm_i915_private *dev_priv,
  499. struct drm_i915_file_private *fpriv,
  500. const char *name);
  501. void i915_ppgtt_close(struct i915_address_space *vm);
  502. static inline void i915_ppgtt_get(struct i915_hw_ppgtt *ppgtt)
  503. {
  504. if (ppgtt)
  505. kref_get(&ppgtt->ref);
  506. }
  507. static inline void i915_ppgtt_put(struct i915_hw_ppgtt *ppgtt)
  508. {
  509. if (ppgtt)
  510. kref_put(&ppgtt->ref, i915_ppgtt_release);
  511. }
  512. void i915_check_and_clear_faults(struct drm_i915_private *dev_priv);
  513. void i915_gem_suspend_gtt_mappings(struct drm_i915_private *dev_priv);
  514. void i915_gem_restore_gtt_mappings(struct drm_i915_private *dev_priv);
  515. int __must_check i915_gem_gtt_prepare_pages(struct drm_i915_gem_object *obj,
  516. struct sg_table *pages);
  517. void i915_gem_gtt_finish_pages(struct drm_i915_gem_object *obj,
  518. struct sg_table *pages);
  519. int i915_gem_gtt_reserve(struct i915_address_space *vm,
  520. struct drm_mm_node *node,
  521. u64 size, u64 offset, unsigned long color,
  522. unsigned int flags);
  523. int i915_gem_gtt_insert(struct i915_address_space *vm,
  524. struct drm_mm_node *node,
  525. u64 size, u64 alignment, unsigned long color,
  526. u64 start, u64 end, unsigned int flags);
  527. /* Flags used by pin/bind&friends. */
  528. #define PIN_NONBLOCK BIT(0)
  529. #define PIN_MAPPABLE BIT(1)
  530. #define PIN_ZONE_4G BIT(2)
  531. #define PIN_NONFAULT BIT(3)
  532. #define PIN_NOEVICT BIT(4)
  533. #define PIN_MBZ BIT(5) /* I915_VMA_PIN_OVERFLOW */
  534. #define PIN_GLOBAL BIT(6) /* I915_VMA_GLOBAL_BIND */
  535. #define PIN_USER BIT(7) /* I915_VMA_LOCAL_BIND */
  536. #define PIN_UPDATE BIT(8)
  537. #define PIN_HIGH BIT(9)
  538. #define PIN_OFFSET_BIAS BIT(10)
  539. #define PIN_OFFSET_FIXED BIT(11)
  540. #define PIN_OFFSET_MASK (-I915_GTT_PAGE_SIZE)
  541. #endif