i915_gem_gtt.h 20 KB

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