intel_engine_cs.c 35 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276
  1. /*
  2. * Copyright © 2016 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. */
  24. #include "i915_drv.h"
  25. #include "intel_ringbuffer.h"
  26. #include "intel_lrc.h"
  27. /* Haswell does have the CXT_SIZE register however it does not appear to be
  28. * valid. Now, docs explain in dwords what is in the context object. The full
  29. * size is 70720 bytes, however, the power context and execlist context will
  30. * never be saved (power context is stored elsewhere, and execlists don't work
  31. * on HSW) - so the final size, including the extra state required for the
  32. * Resource Streamer, is 66944 bytes, which rounds to 17 pages.
  33. */
  34. #define HSW_CXT_TOTAL_SIZE (17 * PAGE_SIZE)
  35. /* Same as Haswell, but 72064 bytes now. */
  36. #define GEN8_CXT_TOTAL_SIZE (18 * PAGE_SIZE)
  37. #define GEN8_LR_CONTEXT_RENDER_SIZE (20 * PAGE_SIZE)
  38. #define GEN9_LR_CONTEXT_RENDER_SIZE (22 * PAGE_SIZE)
  39. #define GEN8_LR_CONTEXT_OTHER_SIZE ( 2 * PAGE_SIZE)
  40. struct engine_class_info {
  41. const char *name;
  42. int (*init_legacy)(struct intel_engine_cs *engine);
  43. int (*init_execlists)(struct intel_engine_cs *engine);
  44. };
  45. static const struct engine_class_info intel_engine_classes[] = {
  46. [RENDER_CLASS] = {
  47. .name = "rcs",
  48. .init_execlists = logical_render_ring_init,
  49. .init_legacy = intel_init_render_ring_buffer,
  50. },
  51. [COPY_ENGINE_CLASS] = {
  52. .name = "bcs",
  53. .init_execlists = logical_xcs_ring_init,
  54. .init_legacy = intel_init_blt_ring_buffer,
  55. },
  56. [VIDEO_DECODE_CLASS] = {
  57. .name = "vcs",
  58. .init_execlists = logical_xcs_ring_init,
  59. .init_legacy = intel_init_bsd_ring_buffer,
  60. },
  61. [VIDEO_ENHANCEMENT_CLASS] = {
  62. .name = "vecs",
  63. .init_execlists = logical_xcs_ring_init,
  64. .init_legacy = intel_init_vebox_ring_buffer,
  65. },
  66. };
  67. struct engine_info {
  68. unsigned int hw_id;
  69. unsigned int uabi_id;
  70. u8 class;
  71. u8 instance;
  72. u32 mmio_base;
  73. unsigned irq_shift;
  74. };
  75. static const struct engine_info intel_engines[] = {
  76. [RCS] = {
  77. .hw_id = RCS_HW,
  78. .uabi_id = I915_EXEC_RENDER,
  79. .class = RENDER_CLASS,
  80. .instance = 0,
  81. .mmio_base = RENDER_RING_BASE,
  82. .irq_shift = GEN8_RCS_IRQ_SHIFT,
  83. },
  84. [BCS] = {
  85. .hw_id = BCS_HW,
  86. .uabi_id = I915_EXEC_BLT,
  87. .class = COPY_ENGINE_CLASS,
  88. .instance = 0,
  89. .mmio_base = BLT_RING_BASE,
  90. .irq_shift = GEN8_BCS_IRQ_SHIFT,
  91. },
  92. [VCS] = {
  93. .hw_id = VCS_HW,
  94. .uabi_id = I915_EXEC_BSD,
  95. .class = VIDEO_DECODE_CLASS,
  96. .instance = 0,
  97. .mmio_base = GEN6_BSD_RING_BASE,
  98. .irq_shift = GEN8_VCS1_IRQ_SHIFT,
  99. },
  100. [VCS2] = {
  101. .hw_id = VCS2_HW,
  102. .uabi_id = I915_EXEC_BSD,
  103. .class = VIDEO_DECODE_CLASS,
  104. .instance = 1,
  105. .mmio_base = GEN8_BSD2_RING_BASE,
  106. .irq_shift = GEN8_VCS2_IRQ_SHIFT,
  107. },
  108. [VECS] = {
  109. .hw_id = VECS_HW,
  110. .uabi_id = I915_EXEC_VEBOX,
  111. .class = VIDEO_ENHANCEMENT_CLASS,
  112. .instance = 0,
  113. .mmio_base = VEBOX_RING_BASE,
  114. .irq_shift = GEN8_VECS_IRQ_SHIFT,
  115. },
  116. };
  117. /**
  118. * ___intel_engine_context_size() - return the size of the context for an engine
  119. * @dev_priv: i915 device private
  120. * @class: engine class
  121. *
  122. * Each engine class may require a different amount of space for a context
  123. * image.
  124. *
  125. * Return: size (in bytes) of an engine class specific context image
  126. *
  127. * Note: this size includes the HWSP, which is part of the context image
  128. * in LRC mode, but does not include the "shared data page" used with
  129. * GuC submission. The caller should account for this if using the GuC.
  130. */
  131. static u32
  132. __intel_engine_context_size(struct drm_i915_private *dev_priv, u8 class)
  133. {
  134. u32 cxt_size;
  135. BUILD_BUG_ON(I915_GTT_PAGE_SIZE != PAGE_SIZE);
  136. switch (class) {
  137. case RENDER_CLASS:
  138. switch (INTEL_GEN(dev_priv)) {
  139. default:
  140. MISSING_CASE(INTEL_GEN(dev_priv));
  141. case 9:
  142. return GEN9_LR_CONTEXT_RENDER_SIZE;
  143. case 8:
  144. return i915.enable_execlists ?
  145. GEN8_LR_CONTEXT_RENDER_SIZE :
  146. GEN8_CXT_TOTAL_SIZE;
  147. case 7:
  148. if (IS_HASWELL(dev_priv))
  149. return HSW_CXT_TOTAL_SIZE;
  150. cxt_size = I915_READ(GEN7_CXT_SIZE);
  151. return round_up(GEN7_CXT_TOTAL_SIZE(cxt_size) * 64,
  152. PAGE_SIZE);
  153. case 6:
  154. cxt_size = I915_READ(CXT_SIZE);
  155. return round_up(GEN6_CXT_TOTAL_SIZE(cxt_size) * 64,
  156. PAGE_SIZE);
  157. case 5:
  158. case 4:
  159. case 3:
  160. case 2:
  161. /* For the special day when i810 gets merged. */
  162. case 1:
  163. return 0;
  164. }
  165. break;
  166. default:
  167. MISSING_CASE(class);
  168. case VIDEO_DECODE_CLASS:
  169. case VIDEO_ENHANCEMENT_CLASS:
  170. case COPY_ENGINE_CLASS:
  171. if (INTEL_GEN(dev_priv) < 8)
  172. return 0;
  173. return GEN8_LR_CONTEXT_OTHER_SIZE;
  174. }
  175. }
  176. static int
  177. intel_engine_setup(struct drm_i915_private *dev_priv,
  178. enum intel_engine_id id)
  179. {
  180. const struct engine_info *info = &intel_engines[id];
  181. const struct engine_class_info *class_info;
  182. struct intel_engine_cs *engine;
  183. GEM_BUG_ON(info->class >= ARRAY_SIZE(intel_engine_classes));
  184. class_info = &intel_engine_classes[info->class];
  185. GEM_BUG_ON(dev_priv->engine[id]);
  186. engine = kzalloc(sizeof(*engine), GFP_KERNEL);
  187. if (!engine)
  188. return -ENOMEM;
  189. engine->id = id;
  190. engine->i915 = dev_priv;
  191. WARN_ON(snprintf(engine->name, sizeof(engine->name), "%s%u",
  192. class_info->name, info->instance) >=
  193. sizeof(engine->name));
  194. engine->uabi_id = info->uabi_id;
  195. engine->hw_id = engine->guc_id = info->hw_id;
  196. engine->mmio_base = info->mmio_base;
  197. engine->irq_shift = info->irq_shift;
  198. engine->class = info->class;
  199. engine->instance = info->instance;
  200. engine->context_size = __intel_engine_context_size(dev_priv,
  201. engine->class);
  202. if (WARN_ON(engine->context_size > BIT(20)))
  203. engine->context_size = 0;
  204. /* Nothing to do here, execute in order of dependencies */
  205. engine->schedule = NULL;
  206. ATOMIC_INIT_NOTIFIER_HEAD(&engine->context_status_notifier);
  207. dev_priv->engine[id] = engine;
  208. return 0;
  209. }
  210. /**
  211. * intel_engines_init_mmio() - allocate and prepare the Engine Command Streamers
  212. * @dev_priv: i915 device private
  213. *
  214. * Return: non-zero if the initialization failed.
  215. */
  216. int intel_engines_init_mmio(struct drm_i915_private *dev_priv)
  217. {
  218. struct intel_device_info *device_info = mkwrite_device_info(dev_priv);
  219. const unsigned int ring_mask = INTEL_INFO(dev_priv)->ring_mask;
  220. struct intel_engine_cs *engine;
  221. enum intel_engine_id id;
  222. unsigned int mask = 0;
  223. unsigned int i;
  224. int err;
  225. WARN_ON(ring_mask == 0);
  226. WARN_ON(ring_mask &
  227. GENMASK(sizeof(mask) * BITS_PER_BYTE - 1, I915_NUM_ENGINES));
  228. for (i = 0; i < ARRAY_SIZE(intel_engines); i++) {
  229. if (!HAS_ENGINE(dev_priv, i))
  230. continue;
  231. err = intel_engine_setup(dev_priv, i);
  232. if (err)
  233. goto cleanup;
  234. mask |= ENGINE_MASK(i);
  235. }
  236. /*
  237. * Catch failures to update intel_engines table when the new engines
  238. * are added to the driver by a warning and disabling the forgotten
  239. * engines.
  240. */
  241. if (WARN_ON(mask != ring_mask))
  242. device_info->ring_mask = mask;
  243. /* We always presume we have at least RCS available for later probing */
  244. if (WARN_ON(!HAS_ENGINE(dev_priv, RCS))) {
  245. err = -ENODEV;
  246. goto cleanup;
  247. }
  248. device_info->num_rings = hweight32(mask);
  249. return 0;
  250. cleanup:
  251. for_each_engine(engine, dev_priv, id)
  252. kfree(engine);
  253. return err;
  254. }
  255. /**
  256. * intel_engines_init() - init the Engine Command Streamers
  257. * @dev_priv: i915 device private
  258. *
  259. * Return: non-zero if the initialization failed.
  260. */
  261. int intel_engines_init(struct drm_i915_private *dev_priv)
  262. {
  263. struct intel_device_info *device_info = mkwrite_device_info(dev_priv);
  264. struct intel_engine_cs *engine;
  265. enum intel_engine_id id, err_id;
  266. unsigned int mask = 0;
  267. int err = 0;
  268. for_each_engine(engine, dev_priv, id) {
  269. const struct engine_class_info *class_info =
  270. &intel_engine_classes[engine->class];
  271. int (*init)(struct intel_engine_cs *engine);
  272. if (i915.enable_execlists)
  273. init = class_info->init_execlists;
  274. else
  275. init = class_info->init_legacy;
  276. if (!init) {
  277. kfree(engine);
  278. dev_priv->engine[id] = NULL;
  279. continue;
  280. }
  281. err = init(engine);
  282. if (err) {
  283. err_id = id;
  284. goto cleanup;
  285. }
  286. GEM_BUG_ON(!engine->submit_request);
  287. mask |= ENGINE_MASK(id);
  288. }
  289. /*
  290. * Catch failures to update intel_engines table when the new engines
  291. * are added to the driver by a warning and disabling the forgotten
  292. * engines.
  293. */
  294. if (WARN_ON(mask != INTEL_INFO(dev_priv)->ring_mask))
  295. device_info->ring_mask = mask;
  296. device_info->num_rings = hweight32(mask);
  297. return 0;
  298. cleanup:
  299. for_each_engine(engine, dev_priv, id) {
  300. if (id >= err_id)
  301. kfree(engine);
  302. else
  303. dev_priv->gt.cleanup_engine(engine);
  304. }
  305. return err;
  306. }
  307. void intel_engine_init_global_seqno(struct intel_engine_cs *engine, u32 seqno)
  308. {
  309. struct drm_i915_private *dev_priv = engine->i915;
  310. GEM_BUG_ON(!intel_engine_is_idle(engine));
  311. GEM_BUG_ON(i915_gem_active_isset(&engine->timeline->last_request));
  312. /* Our semaphore implementation is strictly monotonic (i.e. we proceed
  313. * so long as the semaphore value in the register/page is greater
  314. * than the sync value), so whenever we reset the seqno,
  315. * so long as we reset the tracking semaphore value to 0, it will
  316. * always be before the next request's seqno. If we don't reset
  317. * the semaphore value, then when the seqno moves backwards all
  318. * future waits will complete instantly (causing rendering corruption).
  319. */
  320. if (IS_GEN6(dev_priv) || IS_GEN7(dev_priv)) {
  321. I915_WRITE(RING_SYNC_0(engine->mmio_base), 0);
  322. I915_WRITE(RING_SYNC_1(engine->mmio_base), 0);
  323. if (HAS_VEBOX(dev_priv))
  324. I915_WRITE(RING_SYNC_2(engine->mmio_base), 0);
  325. }
  326. if (dev_priv->semaphore) {
  327. struct page *page = i915_vma_first_page(dev_priv->semaphore);
  328. void *semaphores;
  329. /* Semaphores are in noncoherent memory, flush to be safe */
  330. semaphores = kmap_atomic(page);
  331. memset(semaphores + GEN8_SEMAPHORE_OFFSET(engine->id, 0),
  332. 0, I915_NUM_ENGINES * gen8_semaphore_seqno_size);
  333. drm_clflush_virt_range(semaphores + GEN8_SEMAPHORE_OFFSET(engine->id, 0),
  334. I915_NUM_ENGINES * gen8_semaphore_seqno_size);
  335. kunmap_atomic(semaphores);
  336. }
  337. intel_write_status_page(engine, I915_GEM_HWS_INDEX, seqno);
  338. clear_bit(ENGINE_IRQ_BREADCRUMB, &engine->irq_posted);
  339. /* After manually advancing the seqno, fake the interrupt in case
  340. * there are any waiters for that seqno.
  341. */
  342. intel_engine_wakeup(engine);
  343. GEM_BUG_ON(intel_engine_get_seqno(engine) != seqno);
  344. }
  345. static void intel_engine_init_timeline(struct intel_engine_cs *engine)
  346. {
  347. engine->timeline = &engine->i915->gt.global_timeline.engine[engine->id];
  348. }
  349. /**
  350. * intel_engines_setup_common - setup engine state not requiring hw access
  351. * @engine: Engine to setup.
  352. *
  353. * Initializes @engine@ structure members shared between legacy and execlists
  354. * submission modes which do not require hardware access.
  355. *
  356. * Typically done early in the submission mode specific engine setup stage.
  357. */
  358. void intel_engine_setup_common(struct intel_engine_cs *engine)
  359. {
  360. engine->execlist_queue = RB_ROOT;
  361. engine->execlist_first = NULL;
  362. intel_engine_init_timeline(engine);
  363. intel_engine_init_hangcheck(engine);
  364. i915_gem_batch_pool_init(engine, &engine->batch_pool);
  365. intel_engine_init_cmd_parser(engine);
  366. }
  367. int intel_engine_create_scratch(struct intel_engine_cs *engine, int size)
  368. {
  369. struct drm_i915_gem_object *obj;
  370. struct i915_vma *vma;
  371. int ret;
  372. WARN_ON(engine->scratch);
  373. obj = i915_gem_object_create_stolen(engine->i915, size);
  374. if (!obj)
  375. obj = i915_gem_object_create_internal(engine->i915, size);
  376. if (IS_ERR(obj)) {
  377. DRM_ERROR("Failed to allocate scratch page\n");
  378. return PTR_ERR(obj);
  379. }
  380. vma = i915_vma_instance(obj, &engine->i915->ggtt.base, NULL);
  381. if (IS_ERR(vma)) {
  382. ret = PTR_ERR(vma);
  383. goto err_unref;
  384. }
  385. ret = i915_vma_pin(vma, 0, 4096, PIN_GLOBAL | PIN_HIGH);
  386. if (ret)
  387. goto err_unref;
  388. engine->scratch = vma;
  389. DRM_DEBUG_DRIVER("%s pipe control offset: 0x%08x\n",
  390. engine->name, i915_ggtt_offset(vma));
  391. return 0;
  392. err_unref:
  393. i915_gem_object_put(obj);
  394. return ret;
  395. }
  396. static void intel_engine_cleanup_scratch(struct intel_engine_cs *engine)
  397. {
  398. i915_vma_unpin_and_release(&engine->scratch);
  399. }
  400. /**
  401. * intel_engines_init_common - initialize cengine state which might require hw access
  402. * @engine: Engine to initialize.
  403. *
  404. * Initializes @engine@ structure members shared between legacy and execlists
  405. * submission modes which do require hardware access.
  406. *
  407. * Typcally done at later stages of submission mode specific engine setup.
  408. *
  409. * Returns zero on success or an error code on failure.
  410. */
  411. int intel_engine_init_common(struct intel_engine_cs *engine)
  412. {
  413. int ret;
  414. engine->set_default_submission(engine);
  415. /* We may need to do things with the shrinker which
  416. * require us to immediately switch back to the default
  417. * context. This can cause a problem as pinning the
  418. * default context also requires GTT space which may not
  419. * be available. To avoid this we always pin the default
  420. * context.
  421. */
  422. ret = engine->context_pin(engine, engine->i915->kernel_context);
  423. if (ret)
  424. return ret;
  425. ret = intel_engine_init_breadcrumbs(engine);
  426. if (ret)
  427. goto err_unpin;
  428. ret = i915_gem_render_state_init(engine);
  429. if (ret)
  430. goto err_unpin;
  431. return 0;
  432. err_unpin:
  433. engine->context_unpin(engine, engine->i915->kernel_context);
  434. return ret;
  435. }
  436. /**
  437. * intel_engines_cleanup_common - cleans up the engine state created by
  438. * the common initiailizers.
  439. * @engine: Engine to cleanup.
  440. *
  441. * This cleans up everything created by the common helpers.
  442. */
  443. void intel_engine_cleanup_common(struct intel_engine_cs *engine)
  444. {
  445. intel_engine_cleanup_scratch(engine);
  446. i915_gem_render_state_fini(engine);
  447. intel_engine_fini_breadcrumbs(engine);
  448. intel_engine_cleanup_cmd_parser(engine);
  449. i915_gem_batch_pool_fini(&engine->batch_pool);
  450. engine->context_unpin(engine, engine->i915->kernel_context);
  451. }
  452. u64 intel_engine_get_active_head(struct intel_engine_cs *engine)
  453. {
  454. struct drm_i915_private *dev_priv = engine->i915;
  455. u64 acthd;
  456. if (INTEL_GEN(dev_priv) >= 8)
  457. acthd = I915_READ64_2x32(RING_ACTHD(engine->mmio_base),
  458. RING_ACTHD_UDW(engine->mmio_base));
  459. else if (INTEL_GEN(dev_priv) >= 4)
  460. acthd = I915_READ(RING_ACTHD(engine->mmio_base));
  461. else
  462. acthd = I915_READ(ACTHD);
  463. return acthd;
  464. }
  465. u64 intel_engine_get_last_batch_head(struct intel_engine_cs *engine)
  466. {
  467. struct drm_i915_private *dev_priv = engine->i915;
  468. u64 bbaddr;
  469. if (INTEL_GEN(dev_priv) >= 8)
  470. bbaddr = I915_READ64_2x32(RING_BBADDR(engine->mmio_base),
  471. RING_BBADDR_UDW(engine->mmio_base));
  472. else
  473. bbaddr = I915_READ(RING_BBADDR(engine->mmio_base));
  474. return bbaddr;
  475. }
  476. const char *i915_cache_level_str(struct drm_i915_private *i915, int type)
  477. {
  478. switch (type) {
  479. case I915_CACHE_NONE: return " uncached";
  480. case I915_CACHE_LLC: return HAS_LLC(i915) ? " LLC" : " snooped";
  481. case I915_CACHE_L3_LLC: return " L3+LLC";
  482. case I915_CACHE_WT: return " WT";
  483. default: return "";
  484. }
  485. }
  486. static inline uint32_t
  487. read_subslice_reg(struct drm_i915_private *dev_priv, int slice,
  488. int subslice, i915_reg_t reg)
  489. {
  490. uint32_t mcr;
  491. uint32_t ret;
  492. enum forcewake_domains fw_domains;
  493. fw_domains = intel_uncore_forcewake_for_reg(dev_priv, reg,
  494. FW_REG_READ);
  495. fw_domains |= intel_uncore_forcewake_for_reg(dev_priv,
  496. GEN8_MCR_SELECTOR,
  497. FW_REG_READ | FW_REG_WRITE);
  498. spin_lock_irq(&dev_priv->uncore.lock);
  499. intel_uncore_forcewake_get__locked(dev_priv, fw_domains);
  500. mcr = I915_READ_FW(GEN8_MCR_SELECTOR);
  501. /*
  502. * The HW expects the slice and sublice selectors to be reset to 0
  503. * after reading out the registers.
  504. */
  505. WARN_ON_ONCE(mcr & (GEN8_MCR_SLICE_MASK | GEN8_MCR_SUBSLICE_MASK));
  506. mcr &= ~(GEN8_MCR_SLICE_MASK | GEN8_MCR_SUBSLICE_MASK);
  507. mcr |= GEN8_MCR_SLICE(slice) | GEN8_MCR_SUBSLICE(subslice);
  508. I915_WRITE_FW(GEN8_MCR_SELECTOR, mcr);
  509. ret = I915_READ_FW(reg);
  510. mcr &= ~(GEN8_MCR_SLICE_MASK | GEN8_MCR_SUBSLICE_MASK);
  511. I915_WRITE_FW(GEN8_MCR_SELECTOR, mcr);
  512. intel_uncore_forcewake_put__locked(dev_priv, fw_domains);
  513. spin_unlock_irq(&dev_priv->uncore.lock);
  514. return ret;
  515. }
  516. /* NB: please notice the memset */
  517. void intel_engine_get_instdone(struct intel_engine_cs *engine,
  518. struct intel_instdone *instdone)
  519. {
  520. struct drm_i915_private *dev_priv = engine->i915;
  521. u32 mmio_base = engine->mmio_base;
  522. int slice;
  523. int subslice;
  524. memset(instdone, 0, sizeof(*instdone));
  525. switch (INTEL_GEN(dev_priv)) {
  526. default:
  527. instdone->instdone = I915_READ(RING_INSTDONE(mmio_base));
  528. if (engine->id != RCS)
  529. break;
  530. instdone->slice_common = I915_READ(GEN7_SC_INSTDONE);
  531. for_each_instdone_slice_subslice(dev_priv, slice, subslice) {
  532. instdone->sampler[slice][subslice] =
  533. read_subslice_reg(dev_priv, slice, subslice,
  534. GEN7_SAMPLER_INSTDONE);
  535. instdone->row[slice][subslice] =
  536. read_subslice_reg(dev_priv, slice, subslice,
  537. GEN7_ROW_INSTDONE);
  538. }
  539. break;
  540. case 7:
  541. instdone->instdone = I915_READ(RING_INSTDONE(mmio_base));
  542. if (engine->id != RCS)
  543. break;
  544. instdone->slice_common = I915_READ(GEN7_SC_INSTDONE);
  545. instdone->sampler[0][0] = I915_READ(GEN7_SAMPLER_INSTDONE);
  546. instdone->row[0][0] = I915_READ(GEN7_ROW_INSTDONE);
  547. break;
  548. case 6:
  549. case 5:
  550. case 4:
  551. instdone->instdone = I915_READ(RING_INSTDONE(mmio_base));
  552. if (engine->id == RCS)
  553. /* HACK: Using the wrong struct member */
  554. instdone->slice_common = I915_READ(GEN4_INSTDONE1);
  555. break;
  556. case 3:
  557. case 2:
  558. instdone->instdone = I915_READ(GEN2_INSTDONE);
  559. break;
  560. }
  561. }
  562. static int wa_add(struct drm_i915_private *dev_priv,
  563. i915_reg_t addr,
  564. const u32 mask, const u32 val)
  565. {
  566. const u32 idx = dev_priv->workarounds.count;
  567. if (WARN_ON(idx >= I915_MAX_WA_REGS))
  568. return -ENOSPC;
  569. dev_priv->workarounds.reg[idx].addr = addr;
  570. dev_priv->workarounds.reg[idx].value = val;
  571. dev_priv->workarounds.reg[idx].mask = mask;
  572. dev_priv->workarounds.count++;
  573. return 0;
  574. }
  575. #define WA_REG(addr, mask, val) do { \
  576. const int r = wa_add(dev_priv, (addr), (mask), (val)); \
  577. if (r) \
  578. return r; \
  579. } while (0)
  580. #define WA_SET_BIT_MASKED(addr, mask) \
  581. WA_REG(addr, (mask), _MASKED_BIT_ENABLE(mask))
  582. #define WA_CLR_BIT_MASKED(addr, mask) \
  583. WA_REG(addr, (mask), _MASKED_BIT_DISABLE(mask))
  584. #define WA_SET_FIELD_MASKED(addr, mask, value) \
  585. WA_REG(addr, mask, _MASKED_FIELD(mask, value))
  586. #define WA_SET_BIT(addr, mask) WA_REG(addr, mask, I915_READ(addr) | (mask))
  587. #define WA_CLR_BIT(addr, mask) WA_REG(addr, mask, I915_READ(addr) & ~(mask))
  588. #define WA_WRITE(addr, val) WA_REG(addr, 0xffffffff, val)
  589. static int wa_ring_whitelist_reg(struct intel_engine_cs *engine,
  590. i915_reg_t reg)
  591. {
  592. struct drm_i915_private *dev_priv = engine->i915;
  593. struct i915_workarounds *wa = &dev_priv->workarounds;
  594. const uint32_t index = wa->hw_whitelist_count[engine->id];
  595. if (WARN_ON(index >= RING_MAX_NONPRIV_SLOTS))
  596. return -EINVAL;
  597. WA_WRITE(RING_FORCE_TO_NONPRIV(engine->mmio_base, index),
  598. i915_mmio_reg_offset(reg));
  599. wa->hw_whitelist_count[engine->id]++;
  600. return 0;
  601. }
  602. static int gen8_init_workarounds(struct intel_engine_cs *engine)
  603. {
  604. struct drm_i915_private *dev_priv = engine->i915;
  605. WA_SET_BIT_MASKED(INSTPM, INSTPM_FORCE_ORDERING);
  606. /* WaDisableAsyncFlipPerfMode:bdw,chv */
  607. WA_SET_BIT_MASKED(MI_MODE, ASYNC_FLIP_PERF_DISABLE);
  608. /* WaDisablePartialInstShootdown:bdw,chv */
  609. WA_SET_BIT_MASKED(GEN8_ROW_CHICKEN,
  610. PARTIAL_INSTRUCTION_SHOOTDOWN_DISABLE);
  611. /* Use Force Non-Coherent whenever executing a 3D context. This is a
  612. * workaround for for a possible hang in the unlikely event a TLB
  613. * invalidation occurs during a PSD flush.
  614. */
  615. /* WaForceEnableNonCoherent:bdw,chv */
  616. /* WaHdcDisableFetchWhenMasked:bdw,chv */
  617. WA_SET_BIT_MASKED(HDC_CHICKEN0,
  618. HDC_DONOT_FETCH_MEM_WHEN_MASKED |
  619. HDC_FORCE_NON_COHERENT);
  620. /* From the Haswell PRM, Command Reference: Registers, CACHE_MODE_0:
  621. * "The Hierarchical Z RAW Stall Optimization allows non-overlapping
  622. * polygons in the same 8x4 pixel/sample area to be processed without
  623. * stalling waiting for the earlier ones to write to Hierarchical Z
  624. * buffer."
  625. *
  626. * This optimization is off by default for BDW and CHV; turn it on.
  627. */
  628. WA_CLR_BIT_MASKED(CACHE_MODE_0_GEN7, HIZ_RAW_STALL_OPT_DISABLE);
  629. /* Wa4x4STCOptimizationDisable:bdw,chv */
  630. WA_SET_BIT_MASKED(CACHE_MODE_1, GEN8_4x4_STC_OPTIMIZATION_DISABLE);
  631. /*
  632. * BSpec recommends 8x4 when MSAA is used,
  633. * however in practice 16x4 seems fastest.
  634. *
  635. * Note that PS/WM thread counts depend on the WIZ hashing
  636. * disable bit, which we don't touch here, but it's good
  637. * to keep in mind (see 3DSTATE_PS and 3DSTATE_WM).
  638. */
  639. WA_SET_FIELD_MASKED(GEN7_GT_MODE,
  640. GEN6_WIZ_HASHING_MASK,
  641. GEN6_WIZ_HASHING_16x4);
  642. return 0;
  643. }
  644. static int bdw_init_workarounds(struct intel_engine_cs *engine)
  645. {
  646. struct drm_i915_private *dev_priv = engine->i915;
  647. int ret;
  648. ret = gen8_init_workarounds(engine);
  649. if (ret)
  650. return ret;
  651. /* WaDisableThreadStallDopClockGating:bdw (pre-production) */
  652. WA_SET_BIT_MASKED(GEN8_ROW_CHICKEN, STALL_DOP_GATING_DISABLE);
  653. /* WaDisableDopClockGating:bdw
  654. *
  655. * Also see the related UCGTCL1 write in broadwell_init_clock_gating()
  656. * to disable EUTC clock gating.
  657. */
  658. WA_SET_BIT_MASKED(GEN7_ROW_CHICKEN2,
  659. DOP_CLOCK_GATING_DISABLE);
  660. WA_SET_BIT_MASKED(HALF_SLICE_CHICKEN3,
  661. GEN8_SAMPLER_POWER_BYPASS_DIS);
  662. WA_SET_BIT_MASKED(HDC_CHICKEN0,
  663. /* WaForceContextSaveRestoreNonCoherent:bdw */
  664. HDC_FORCE_CONTEXT_SAVE_RESTORE_NON_COHERENT |
  665. /* WaDisableFenceDestinationToSLM:bdw (pre-prod) */
  666. (IS_BDW_GT3(dev_priv) ? HDC_FENCE_DEST_SLM_DISABLE : 0));
  667. return 0;
  668. }
  669. static int chv_init_workarounds(struct intel_engine_cs *engine)
  670. {
  671. struct drm_i915_private *dev_priv = engine->i915;
  672. int ret;
  673. ret = gen8_init_workarounds(engine);
  674. if (ret)
  675. return ret;
  676. /* WaDisableThreadStallDopClockGating:chv */
  677. WA_SET_BIT_MASKED(GEN8_ROW_CHICKEN, STALL_DOP_GATING_DISABLE);
  678. /* Improve HiZ throughput on CHV. */
  679. WA_SET_BIT_MASKED(HIZ_CHICKEN, CHV_HZ_8X8_MODE_IN_1X);
  680. return 0;
  681. }
  682. static int gen9_init_workarounds(struct intel_engine_cs *engine)
  683. {
  684. struct drm_i915_private *dev_priv = engine->i915;
  685. int ret;
  686. /* WaConextSwitchWithConcurrentTLBInvalidate:skl,bxt,kbl,glk */
  687. I915_WRITE(GEN9_CSFE_CHICKEN1_RCS, _MASKED_BIT_ENABLE(GEN9_PREEMPT_GPGPU_SYNC_SWITCH_DISABLE));
  688. /* WaEnableLbsSlaRetryTimerDecrement:skl,bxt,kbl,glk */
  689. I915_WRITE(BDW_SCRATCH1, I915_READ(BDW_SCRATCH1) |
  690. GEN9_LBS_SLA_RETRY_TIMER_DECREMENT_ENABLE);
  691. /* WaDisableKillLogic:bxt,skl,kbl */
  692. I915_WRITE(GAM_ECOCHK, I915_READ(GAM_ECOCHK) |
  693. ECOCHK_DIS_TLB);
  694. /* WaClearFlowControlGpgpuContextSave:skl,bxt,kbl,glk */
  695. /* WaDisablePartialInstShootdown:skl,bxt,kbl,glk */
  696. WA_SET_BIT_MASKED(GEN8_ROW_CHICKEN,
  697. FLOW_CONTROL_ENABLE |
  698. PARTIAL_INSTRUCTION_SHOOTDOWN_DISABLE);
  699. /* Syncing dependencies between camera and graphics:skl,bxt,kbl */
  700. WA_SET_BIT_MASKED(HALF_SLICE_CHICKEN3,
  701. GEN9_DISABLE_OCL_OOB_SUPPRESS_LOGIC);
  702. /* WaDisableDgMirrorFixInHalfSliceChicken5:bxt */
  703. if (IS_BXT_REVID(dev_priv, 0, BXT_REVID_A1))
  704. WA_CLR_BIT_MASKED(GEN9_HALF_SLICE_CHICKEN5,
  705. GEN9_DG_MIRROR_FIX_ENABLE);
  706. /* WaSetDisablePixMaskCammingAndRhwoInCommonSliceChicken:bxt */
  707. if (IS_BXT_REVID(dev_priv, 0, BXT_REVID_A1)) {
  708. WA_SET_BIT_MASKED(GEN7_COMMON_SLICE_CHICKEN1,
  709. GEN9_RHWO_OPTIMIZATION_DISABLE);
  710. /*
  711. * WA also requires GEN9_SLICE_COMMON_ECO_CHICKEN0[14:14] to be set
  712. * but we do that in per ctx batchbuffer as there is an issue
  713. * with this register not getting restored on ctx restore
  714. */
  715. }
  716. /* WaEnableSamplerGPGPUPreemptionSupport:skl,bxt,kbl */
  717. WA_SET_BIT_MASKED(GEN9_HALF_SLICE_CHICKEN7,
  718. GEN9_ENABLE_GPGPU_PREEMPTION);
  719. /* Wa4x4STCOptimizationDisable:skl,bxt,kbl,glk */
  720. /* WaDisablePartialResolveInVc:skl,bxt,kbl */
  721. WA_SET_BIT_MASKED(CACHE_MODE_1, (GEN8_4x4_STC_OPTIMIZATION_DISABLE |
  722. GEN9_PARTIAL_RESOLVE_IN_VC_DISABLE));
  723. /* WaCcsTlbPrefetchDisable:skl,bxt,kbl,glk */
  724. WA_CLR_BIT_MASKED(GEN9_HALF_SLICE_CHICKEN5,
  725. GEN9_CCS_TLB_PREFETCH_ENABLE);
  726. /* WaDisableMaskBasedCammingInRCC:bxt */
  727. if (IS_BXT_REVID(dev_priv, 0, BXT_REVID_A1))
  728. WA_SET_BIT_MASKED(SLICE_ECO_CHICKEN0,
  729. PIXEL_MASK_CAMMING_DISABLE);
  730. /* WaForceContextSaveRestoreNonCoherent:skl,bxt,kbl */
  731. WA_SET_BIT_MASKED(HDC_CHICKEN0,
  732. HDC_FORCE_CONTEXT_SAVE_RESTORE_NON_COHERENT |
  733. HDC_FORCE_CSR_NON_COHERENT_OVR_DISABLE);
  734. /* WaForceEnableNonCoherent and WaDisableHDCInvalidation are
  735. * both tied to WaForceContextSaveRestoreNonCoherent
  736. * in some hsds for skl. We keep the tie for all gen9. The
  737. * documentation is a bit hazy and so we want to get common behaviour,
  738. * even though there is no clear evidence we would need both on kbl/bxt.
  739. * This area has been source of system hangs so we play it safe
  740. * and mimic the skl regardless of what bspec says.
  741. *
  742. * Use Force Non-Coherent whenever executing a 3D context. This
  743. * is a workaround for a possible hang in the unlikely event
  744. * a TLB invalidation occurs during a PSD flush.
  745. */
  746. /* WaForceEnableNonCoherent:skl,bxt,kbl */
  747. WA_SET_BIT_MASKED(HDC_CHICKEN0,
  748. HDC_FORCE_NON_COHERENT);
  749. /* WaDisableHDCInvalidation:skl,bxt,kbl */
  750. I915_WRITE(GAM_ECOCHK, I915_READ(GAM_ECOCHK) |
  751. BDW_DISABLE_HDC_INVALIDATION);
  752. /* WaDisableSamplerPowerBypassForSOPingPong:skl,bxt,kbl */
  753. if (IS_SKYLAKE(dev_priv) ||
  754. IS_KABYLAKE(dev_priv) ||
  755. IS_BXT_REVID(dev_priv, 0, BXT_REVID_B0))
  756. WA_SET_BIT_MASKED(HALF_SLICE_CHICKEN3,
  757. GEN8_SAMPLER_POWER_BYPASS_DIS);
  758. /* WaDisableSTUnitPowerOptimization:skl,bxt,kbl,glk */
  759. WA_SET_BIT_MASKED(HALF_SLICE_CHICKEN2, GEN8_ST_PO_DISABLE);
  760. /* WaOCLCoherentLineFlush:skl,bxt,kbl */
  761. I915_WRITE(GEN8_L3SQCREG4, (I915_READ(GEN8_L3SQCREG4) |
  762. GEN8_LQSC_FLUSH_COHERENT_LINES));
  763. /* WaVFEStateAfterPipeControlwithMediaStateClear:skl,bxt,glk */
  764. ret = wa_ring_whitelist_reg(engine, GEN9_CTX_PREEMPT_REG);
  765. if (ret)
  766. return ret;
  767. /* WaEnablePreemptionGranularityControlByUMD:skl,bxt,kbl */
  768. ret= wa_ring_whitelist_reg(engine, GEN8_CS_CHICKEN1);
  769. if (ret)
  770. return ret;
  771. /* WaAllowUMDToModifyHDCChicken1:skl,bxt,kbl,glk */
  772. ret = wa_ring_whitelist_reg(engine, GEN8_HDC_CHICKEN1);
  773. if (ret)
  774. return ret;
  775. return 0;
  776. }
  777. static int skl_tune_iz_hashing(struct intel_engine_cs *engine)
  778. {
  779. struct drm_i915_private *dev_priv = engine->i915;
  780. u8 vals[3] = { 0, 0, 0 };
  781. unsigned int i;
  782. for (i = 0; i < 3; i++) {
  783. u8 ss;
  784. /*
  785. * Only consider slices where one, and only one, subslice has 7
  786. * EUs
  787. */
  788. if (!is_power_of_2(INTEL_INFO(dev_priv)->sseu.subslice_7eu[i]))
  789. continue;
  790. /*
  791. * subslice_7eu[i] != 0 (because of the check above) and
  792. * ss_max == 4 (maximum number of subslices possible per slice)
  793. *
  794. * -> 0 <= ss <= 3;
  795. */
  796. ss = ffs(INTEL_INFO(dev_priv)->sseu.subslice_7eu[i]) - 1;
  797. vals[i] = 3 - ss;
  798. }
  799. if (vals[0] == 0 && vals[1] == 0 && vals[2] == 0)
  800. return 0;
  801. /* Tune IZ hashing. See intel_device_info_runtime_init() */
  802. WA_SET_FIELD_MASKED(GEN7_GT_MODE,
  803. GEN9_IZ_HASHING_MASK(2) |
  804. GEN9_IZ_HASHING_MASK(1) |
  805. GEN9_IZ_HASHING_MASK(0),
  806. GEN9_IZ_HASHING(2, vals[2]) |
  807. GEN9_IZ_HASHING(1, vals[1]) |
  808. GEN9_IZ_HASHING(0, vals[0]));
  809. return 0;
  810. }
  811. static int skl_init_workarounds(struct intel_engine_cs *engine)
  812. {
  813. struct drm_i915_private *dev_priv = engine->i915;
  814. int ret;
  815. ret = gen9_init_workarounds(engine);
  816. if (ret)
  817. return ret;
  818. /*
  819. * Actual WA is to disable percontext preemption granularity control
  820. * until D0 which is the default case so this is equivalent to
  821. * !WaDisablePerCtxtPreemptionGranularityControl:skl
  822. */
  823. I915_WRITE(GEN7_FF_SLICE_CS_CHICKEN1,
  824. _MASKED_BIT_ENABLE(GEN9_FFSC_PERCTX_PREEMPT_CTRL));
  825. /* WaEnableGapsTsvCreditFix:skl */
  826. I915_WRITE(GEN8_GARBCNTL, (I915_READ(GEN8_GARBCNTL) |
  827. GEN9_GAPS_TSV_CREDIT_DISABLE));
  828. /* WaDisableGafsUnitClkGating:skl */
  829. WA_SET_BIT(GEN7_UCGCTL4, GEN8_EU_GAUNIT_CLOCK_GATE_DISABLE);
  830. /* WaInPlaceDecompressionHang:skl */
  831. if (IS_SKL_REVID(dev_priv, SKL_REVID_H0, REVID_FOREVER))
  832. WA_SET_BIT(GEN9_GAMT_ECO_REG_RW_IA,
  833. GAMT_ECO_ENABLE_IN_PLACE_DECOMPRESS);
  834. /* WaDisableLSQCROPERFforOCL:skl */
  835. ret = wa_ring_whitelist_reg(engine, GEN8_L3SQCREG4);
  836. if (ret)
  837. return ret;
  838. return skl_tune_iz_hashing(engine);
  839. }
  840. static int bxt_init_workarounds(struct intel_engine_cs *engine)
  841. {
  842. struct drm_i915_private *dev_priv = engine->i915;
  843. int ret;
  844. ret = gen9_init_workarounds(engine);
  845. if (ret)
  846. return ret;
  847. /* WaStoreMultiplePTEenable:bxt */
  848. /* This is a requirement according to Hardware specification */
  849. if (IS_BXT_REVID(dev_priv, 0, BXT_REVID_A1))
  850. I915_WRITE(TILECTL, I915_READ(TILECTL) | TILECTL_TLBPF);
  851. /* WaSetClckGatingDisableMedia:bxt */
  852. if (IS_BXT_REVID(dev_priv, 0, BXT_REVID_A1)) {
  853. I915_WRITE(GEN7_MISCCPCTL, (I915_READ(GEN7_MISCCPCTL) &
  854. ~GEN8_DOP_CLOCK_GATE_MEDIA_ENABLE));
  855. }
  856. /* WaDisableThreadStallDopClockGating:bxt */
  857. WA_SET_BIT_MASKED(GEN8_ROW_CHICKEN,
  858. STALL_DOP_GATING_DISABLE);
  859. /* WaDisablePooledEuLoadBalancingFix:bxt */
  860. if (IS_BXT_REVID(dev_priv, BXT_REVID_B0, REVID_FOREVER)) {
  861. WA_SET_BIT_MASKED(FF_SLICE_CS_CHICKEN2,
  862. GEN9_POOLED_EU_LOAD_BALANCING_FIX_DISABLE);
  863. }
  864. /* WaDisableSbeCacheDispatchPortSharing:bxt */
  865. if (IS_BXT_REVID(dev_priv, 0, BXT_REVID_B0)) {
  866. WA_SET_BIT_MASKED(
  867. GEN7_HALF_SLICE_CHICKEN1,
  868. GEN7_SBE_SS_CACHE_DISPATCH_PORT_SHARING_DISABLE);
  869. }
  870. /* WaDisableObjectLevelPreemptionForTrifanOrPolygon:bxt */
  871. /* WaDisableObjectLevelPreemptionForInstancedDraw:bxt */
  872. /* WaDisableObjectLevelPreemtionForInstanceId:bxt */
  873. /* WaDisableLSQCROPERFforOCL:bxt */
  874. if (IS_BXT_REVID(dev_priv, 0, BXT_REVID_A1)) {
  875. ret = wa_ring_whitelist_reg(engine, GEN9_CS_DEBUG_MODE1);
  876. if (ret)
  877. return ret;
  878. ret = wa_ring_whitelist_reg(engine, GEN8_L3SQCREG4);
  879. if (ret)
  880. return ret;
  881. }
  882. /* WaProgramL3SqcReg1DefaultForPerf:bxt */
  883. if (IS_BXT_REVID(dev_priv, BXT_REVID_B0, REVID_FOREVER))
  884. I915_WRITE(GEN8_L3SQCREG1, L3_GENERAL_PRIO_CREDITS(62) |
  885. L3_HIGH_PRIO_CREDITS(2));
  886. /* WaToEnableHwFixForPushConstHWBug:bxt */
  887. if (IS_BXT_REVID(dev_priv, BXT_REVID_C0, REVID_FOREVER))
  888. WA_SET_BIT_MASKED(COMMON_SLICE_CHICKEN2,
  889. GEN8_SBE_DISABLE_REPLAY_BUF_OPTIMIZATION);
  890. /* WaInPlaceDecompressionHang:bxt */
  891. if (IS_BXT_REVID(dev_priv, BXT_REVID_C0, REVID_FOREVER))
  892. WA_SET_BIT(GEN9_GAMT_ECO_REG_RW_IA,
  893. GAMT_ECO_ENABLE_IN_PLACE_DECOMPRESS);
  894. return 0;
  895. }
  896. static int kbl_init_workarounds(struct intel_engine_cs *engine)
  897. {
  898. struct drm_i915_private *dev_priv = engine->i915;
  899. int ret;
  900. ret = gen9_init_workarounds(engine);
  901. if (ret)
  902. return ret;
  903. /* WaEnableGapsTsvCreditFix:kbl */
  904. I915_WRITE(GEN8_GARBCNTL, (I915_READ(GEN8_GARBCNTL) |
  905. GEN9_GAPS_TSV_CREDIT_DISABLE));
  906. /* WaDisableDynamicCreditSharing:kbl */
  907. if (IS_KBL_REVID(dev_priv, 0, KBL_REVID_B0))
  908. WA_SET_BIT(GAMT_CHKN_BIT_REG,
  909. GAMT_CHKN_DISABLE_DYNAMIC_CREDIT_SHARING);
  910. /* WaDisableFenceDestinationToSLM:kbl (pre-prod) */
  911. if (IS_KBL_REVID(dev_priv, KBL_REVID_A0, KBL_REVID_A0))
  912. WA_SET_BIT_MASKED(HDC_CHICKEN0,
  913. HDC_FENCE_DEST_SLM_DISABLE);
  914. /* WaToEnableHwFixForPushConstHWBug:kbl */
  915. if (IS_KBL_REVID(dev_priv, KBL_REVID_C0, REVID_FOREVER))
  916. WA_SET_BIT_MASKED(COMMON_SLICE_CHICKEN2,
  917. GEN8_SBE_DISABLE_REPLAY_BUF_OPTIMIZATION);
  918. /* WaDisableGafsUnitClkGating:kbl */
  919. WA_SET_BIT(GEN7_UCGCTL4, GEN8_EU_GAUNIT_CLOCK_GATE_DISABLE);
  920. /* WaDisableSbeCacheDispatchPortSharing:kbl */
  921. WA_SET_BIT_MASKED(
  922. GEN7_HALF_SLICE_CHICKEN1,
  923. GEN7_SBE_SS_CACHE_DISPATCH_PORT_SHARING_DISABLE);
  924. /* WaInPlaceDecompressionHang:kbl */
  925. WA_SET_BIT(GEN9_GAMT_ECO_REG_RW_IA,
  926. GAMT_ECO_ENABLE_IN_PLACE_DECOMPRESS);
  927. /* WaDisableLSQCROPERFforOCL:kbl */
  928. ret = wa_ring_whitelist_reg(engine, GEN8_L3SQCREG4);
  929. if (ret)
  930. return ret;
  931. return 0;
  932. }
  933. static int glk_init_workarounds(struct intel_engine_cs *engine)
  934. {
  935. struct drm_i915_private *dev_priv = engine->i915;
  936. int ret;
  937. ret = gen9_init_workarounds(engine);
  938. if (ret)
  939. return ret;
  940. /* WaToEnableHwFixForPushConstHWBug:glk */
  941. WA_SET_BIT_MASKED(COMMON_SLICE_CHICKEN2,
  942. GEN8_SBE_DISABLE_REPLAY_BUF_OPTIMIZATION);
  943. return 0;
  944. }
  945. int init_workarounds_ring(struct intel_engine_cs *engine)
  946. {
  947. struct drm_i915_private *dev_priv = engine->i915;
  948. int err;
  949. WARN_ON(engine->id != RCS);
  950. dev_priv->workarounds.count = 0;
  951. dev_priv->workarounds.hw_whitelist_count[engine->id] = 0;
  952. if (IS_BROADWELL(dev_priv))
  953. err = bdw_init_workarounds(engine);
  954. else if (IS_CHERRYVIEW(dev_priv))
  955. err = chv_init_workarounds(engine);
  956. else if (IS_SKYLAKE(dev_priv))
  957. err = skl_init_workarounds(engine);
  958. else if (IS_BROXTON(dev_priv))
  959. err = bxt_init_workarounds(engine);
  960. else if (IS_KABYLAKE(dev_priv))
  961. err = kbl_init_workarounds(engine);
  962. else if (IS_GEMINILAKE(dev_priv))
  963. err = glk_init_workarounds(engine);
  964. else
  965. err = 0;
  966. if (err)
  967. return err;
  968. DRM_DEBUG_DRIVER("%s: Number of context specific w/a: %d\n",
  969. engine->name, dev_priv->workarounds.count);
  970. return 0;
  971. }
  972. int intel_ring_workarounds_emit(struct drm_i915_gem_request *req)
  973. {
  974. struct i915_workarounds *w = &req->i915->workarounds;
  975. u32 *cs;
  976. int ret, i;
  977. if (w->count == 0)
  978. return 0;
  979. ret = req->engine->emit_flush(req, EMIT_BARRIER);
  980. if (ret)
  981. return ret;
  982. cs = intel_ring_begin(req, (w->count * 2 + 2));
  983. if (IS_ERR(cs))
  984. return PTR_ERR(cs);
  985. *cs++ = MI_LOAD_REGISTER_IMM(w->count);
  986. for (i = 0; i < w->count; i++) {
  987. *cs++ = i915_mmio_reg_offset(w->reg[i].addr);
  988. *cs++ = w->reg[i].value;
  989. }
  990. *cs++ = MI_NOOP;
  991. intel_ring_advance(req, cs);
  992. ret = req->engine->emit_flush(req, EMIT_BARRIER);
  993. if (ret)
  994. return ret;
  995. return 0;
  996. }
  997. /**
  998. * intel_engine_is_idle() - Report if the engine has finished process all work
  999. * @engine: the intel_engine_cs
  1000. *
  1001. * Return true if there are no requests pending, nothing left to be submitted
  1002. * to hardware, and that the engine is idle.
  1003. */
  1004. bool intel_engine_is_idle(struct intel_engine_cs *engine)
  1005. {
  1006. struct drm_i915_private *dev_priv = engine->i915;
  1007. /* More white lies, if wedged, hw state is inconsistent */
  1008. if (i915_terminally_wedged(&dev_priv->gpu_error))
  1009. return true;
  1010. /* Any inflight/incomplete requests? */
  1011. if (!i915_seqno_passed(intel_engine_get_seqno(engine),
  1012. intel_engine_last_submit(engine)))
  1013. return false;
  1014. if (I915_SELFTEST_ONLY(engine->breadcrumbs.mock))
  1015. return true;
  1016. /* Interrupt/tasklet pending? */
  1017. if (test_bit(ENGINE_IRQ_EXECLIST, &engine->irq_posted))
  1018. return false;
  1019. /* Both ports drained, no more ELSP submission? */
  1020. if (engine->execlist_port[0].request)
  1021. return false;
  1022. /* Ring stopped? */
  1023. if (INTEL_GEN(dev_priv) > 2 && !(I915_READ_MODE(engine) & MODE_IDLE))
  1024. return false;
  1025. return true;
  1026. }
  1027. bool intel_engines_are_idle(struct drm_i915_private *dev_priv)
  1028. {
  1029. struct intel_engine_cs *engine;
  1030. enum intel_engine_id id;
  1031. if (READ_ONCE(dev_priv->gt.active_requests))
  1032. return false;
  1033. /* If the driver is wedged, HW state may be very inconsistent and
  1034. * report that it is still busy, even though we have stopped using it.
  1035. */
  1036. if (i915_terminally_wedged(&dev_priv->gpu_error))
  1037. return true;
  1038. for_each_engine(engine, dev_priv, id) {
  1039. if (!intel_engine_is_idle(engine))
  1040. return false;
  1041. }
  1042. return true;
  1043. }
  1044. void intel_engines_reset_default_submission(struct drm_i915_private *i915)
  1045. {
  1046. struct intel_engine_cs *engine;
  1047. enum intel_engine_id id;
  1048. for_each_engine(engine, i915, id)
  1049. engine->set_default_submission(engine);
  1050. }
  1051. #if IS_ENABLED(CONFIG_DRM_I915_SELFTEST)
  1052. #include "selftests/mock_engine.c"
  1053. #endif