intel_engine_cs.c 36 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307
  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. struct intel_ring *ring;
  414. int ret;
  415. engine->set_default_submission(engine);
  416. /* We may need to do things with the shrinker which
  417. * require us to immediately switch back to the default
  418. * context. This can cause a problem as pinning the
  419. * default context also requires GTT space which may not
  420. * be available. To avoid this we always pin the default
  421. * context.
  422. */
  423. ring = engine->context_pin(engine, engine->i915->kernel_context);
  424. if (IS_ERR(ring))
  425. return PTR_ERR(ring);
  426. ret = intel_engine_init_breadcrumbs(engine);
  427. if (ret)
  428. goto err_unpin;
  429. ret = i915_gem_render_state_init(engine);
  430. if (ret)
  431. goto err_unpin;
  432. return 0;
  433. err_unpin:
  434. engine->context_unpin(engine, engine->i915->kernel_context);
  435. return ret;
  436. }
  437. /**
  438. * intel_engines_cleanup_common - cleans up the engine state created by
  439. * the common initiailizers.
  440. * @engine: Engine to cleanup.
  441. *
  442. * This cleans up everything created by the common helpers.
  443. */
  444. void intel_engine_cleanup_common(struct intel_engine_cs *engine)
  445. {
  446. intel_engine_cleanup_scratch(engine);
  447. i915_gem_render_state_fini(engine);
  448. intel_engine_fini_breadcrumbs(engine);
  449. intel_engine_cleanup_cmd_parser(engine);
  450. i915_gem_batch_pool_fini(&engine->batch_pool);
  451. engine->context_unpin(engine, engine->i915->kernel_context);
  452. }
  453. u64 intel_engine_get_active_head(struct intel_engine_cs *engine)
  454. {
  455. struct drm_i915_private *dev_priv = engine->i915;
  456. u64 acthd;
  457. if (INTEL_GEN(dev_priv) >= 8)
  458. acthd = I915_READ64_2x32(RING_ACTHD(engine->mmio_base),
  459. RING_ACTHD_UDW(engine->mmio_base));
  460. else if (INTEL_GEN(dev_priv) >= 4)
  461. acthd = I915_READ(RING_ACTHD(engine->mmio_base));
  462. else
  463. acthd = I915_READ(ACTHD);
  464. return acthd;
  465. }
  466. u64 intel_engine_get_last_batch_head(struct intel_engine_cs *engine)
  467. {
  468. struct drm_i915_private *dev_priv = engine->i915;
  469. u64 bbaddr;
  470. if (INTEL_GEN(dev_priv) >= 8)
  471. bbaddr = I915_READ64_2x32(RING_BBADDR(engine->mmio_base),
  472. RING_BBADDR_UDW(engine->mmio_base));
  473. else
  474. bbaddr = I915_READ(RING_BBADDR(engine->mmio_base));
  475. return bbaddr;
  476. }
  477. const char *i915_cache_level_str(struct drm_i915_private *i915, int type)
  478. {
  479. switch (type) {
  480. case I915_CACHE_NONE: return " uncached";
  481. case I915_CACHE_LLC: return HAS_LLC(i915) ? " LLC" : " snooped";
  482. case I915_CACHE_L3_LLC: return " L3+LLC";
  483. case I915_CACHE_WT: return " WT";
  484. default: return "";
  485. }
  486. }
  487. static inline uint32_t
  488. read_subslice_reg(struct drm_i915_private *dev_priv, int slice,
  489. int subslice, i915_reg_t reg)
  490. {
  491. uint32_t mcr;
  492. uint32_t ret;
  493. enum forcewake_domains fw_domains;
  494. fw_domains = intel_uncore_forcewake_for_reg(dev_priv, reg,
  495. FW_REG_READ);
  496. fw_domains |= intel_uncore_forcewake_for_reg(dev_priv,
  497. GEN8_MCR_SELECTOR,
  498. FW_REG_READ | FW_REG_WRITE);
  499. spin_lock_irq(&dev_priv->uncore.lock);
  500. intel_uncore_forcewake_get__locked(dev_priv, fw_domains);
  501. mcr = I915_READ_FW(GEN8_MCR_SELECTOR);
  502. /*
  503. * The HW expects the slice and sublice selectors to be reset to 0
  504. * after reading out the registers.
  505. */
  506. WARN_ON_ONCE(mcr & (GEN8_MCR_SLICE_MASK | GEN8_MCR_SUBSLICE_MASK));
  507. mcr &= ~(GEN8_MCR_SLICE_MASK | GEN8_MCR_SUBSLICE_MASK);
  508. mcr |= GEN8_MCR_SLICE(slice) | GEN8_MCR_SUBSLICE(subslice);
  509. I915_WRITE_FW(GEN8_MCR_SELECTOR, mcr);
  510. ret = I915_READ_FW(reg);
  511. mcr &= ~(GEN8_MCR_SLICE_MASK | GEN8_MCR_SUBSLICE_MASK);
  512. I915_WRITE_FW(GEN8_MCR_SELECTOR, mcr);
  513. intel_uncore_forcewake_put__locked(dev_priv, fw_domains);
  514. spin_unlock_irq(&dev_priv->uncore.lock);
  515. return ret;
  516. }
  517. /* NB: please notice the memset */
  518. void intel_engine_get_instdone(struct intel_engine_cs *engine,
  519. struct intel_instdone *instdone)
  520. {
  521. struct drm_i915_private *dev_priv = engine->i915;
  522. u32 mmio_base = engine->mmio_base;
  523. int slice;
  524. int subslice;
  525. memset(instdone, 0, sizeof(*instdone));
  526. switch (INTEL_GEN(dev_priv)) {
  527. default:
  528. instdone->instdone = I915_READ(RING_INSTDONE(mmio_base));
  529. if (engine->id != RCS)
  530. break;
  531. instdone->slice_common = I915_READ(GEN7_SC_INSTDONE);
  532. for_each_instdone_slice_subslice(dev_priv, slice, subslice) {
  533. instdone->sampler[slice][subslice] =
  534. read_subslice_reg(dev_priv, slice, subslice,
  535. GEN7_SAMPLER_INSTDONE);
  536. instdone->row[slice][subslice] =
  537. read_subslice_reg(dev_priv, slice, subslice,
  538. GEN7_ROW_INSTDONE);
  539. }
  540. break;
  541. case 7:
  542. instdone->instdone = I915_READ(RING_INSTDONE(mmio_base));
  543. if (engine->id != RCS)
  544. break;
  545. instdone->slice_common = I915_READ(GEN7_SC_INSTDONE);
  546. instdone->sampler[0][0] = I915_READ(GEN7_SAMPLER_INSTDONE);
  547. instdone->row[0][0] = I915_READ(GEN7_ROW_INSTDONE);
  548. break;
  549. case 6:
  550. case 5:
  551. case 4:
  552. instdone->instdone = I915_READ(RING_INSTDONE(mmio_base));
  553. if (engine->id == RCS)
  554. /* HACK: Using the wrong struct member */
  555. instdone->slice_common = I915_READ(GEN4_INSTDONE1);
  556. break;
  557. case 3:
  558. case 2:
  559. instdone->instdone = I915_READ(GEN2_INSTDONE);
  560. break;
  561. }
  562. }
  563. static int wa_add(struct drm_i915_private *dev_priv,
  564. i915_reg_t addr,
  565. const u32 mask, const u32 val)
  566. {
  567. const u32 idx = dev_priv->workarounds.count;
  568. if (WARN_ON(idx >= I915_MAX_WA_REGS))
  569. return -ENOSPC;
  570. dev_priv->workarounds.reg[idx].addr = addr;
  571. dev_priv->workarounds.reg[idx].value = val;
  572. dev_priv->workarounds.reg[idx].mask = mask;
  573. dev_priv->workarounds.count++;
  574. return 0;
  575. }
  576. #define WA_REG(addr, mask, val) do { \
  577. const int r = wa_add(dev_priv, (addr), (mask), (val)); \
  578. if (r) \
  579. return r; \
  580. } while (0)
  581. #define WA_SET_BIT_MASKED(addr, mask) \
  582. WA_REG(addr, (mask), _MASKED_BIT_ENABLE(mask))
  583. #define WA_CLR_BIT_MASKED(addr, mask) \
  584. WA_REG(addr, (mask), _MASKED_BIT_DISABLE(mask))
  585. #define WA_SET_FIELD_MASKED(addr, mask, value) \
  586. WA_REG(addr, mask, _MASKED_FIELD(mask, value))
  587. #define WA_SET_BIT(addr, mask) WA_REG(addr, mask, I915_READ(addr) | (mask))
  588. #define WA_CLR_BIT(addr, mask) WA_REG(addr, mask, I915_READ(addr) & ~(mask))
  589. #define WA_WRITE(addr, val) WA_REG(addr, 0xffffffff, val)
  590. static int wa_ring_whitelist_reg(struct intel_engine_cs *engine,
  591. i915_reg_t reg)
  592. {
  593. struct drm_i915_private *dev_priv = engine->i915;
  594. struct i915_workarounds *wa = &dev_priv->workarounds;
  595. const uint32_t index = wa->hw_whitelist_count[engine->id];
  596. if (WARN_ON(index >= RING_MAX_NONPRIV_SLOTS))
  597. return -EINVAL;
  598. WA_WRITE(RING_FORCE_TO_NONPRIV(engine->mmio_base, index),
  599. i915_mmio_reg_offset(reg));
  600. wa->hw_whitelist_count[engine->id]++;
  601. return 0;
  602. }
  603. static int gen8_init_workarounds(struct intel_engine_cs *engine)
  604. {
  605. struct drm_i915_private *dev_priv = engine->i915;
  606. WA_SET_BIT_MASKED(INSTPM, INSTPM_FORCE_ORDERING);
  607. /* WaDisableAsyncFlipPerfMode:bdw,chv */
  608. WA_SET_BIT_MASKED(MI_MODE, ASYNC_FLIP_PERF_DISABLE);
  609. /* WaDisablePartialInstShootdown:bdw,chv */
  610. WA_SET_BIT_MASKED(GEN8_ROW_CHICKEN,
  611. PARTIAL_INSTRUCTION_SHOOTDOWN_DISABLE);
  612. /* Use Force Non-Coherent whenever executing a 3D context. This is a
  613. * workaround for for a possible hang in the unlikely event a TLB
  614. * invalidation occurs during a PSD flush.
  615. */
  616. /* WaForceEnableNonCoherent:bdw,chv */
  617. /* WaHdcDisableFetchWhenMasked:bdw,chv */
  618. WA_SET_BIT_MASKED(HDC_CHICKEN0,
  619. HDC_DONOT_FETCH_MEM_WHEN_MASKED |
  620. HDC_FORCE_NON_COHERENT);
  621. /* From the Haswell PRM, Command Reference: Registers, CACHE_MODE_0:
  622. * "The Hierarchical Z RAW Stall Optimization allows non-overlapping
  623. * polygons in the same 8x4 pixel/sample area to be processed without
  624. * stalling waiting for the earlier ones to write to Hierarchical Z
  625. * buffer."
  626. *
  627. * This optimization is off by default for BDW and CHV; turn it on.
  628. */
  629. WA_CLR_BIT_MASKED(CACHE_MODE_0_GEN7, HIZ_RAW_STALL_OPT_DISABLE);
  630. /* Wa4x4STCOptimizationDisable:bdw,chv */
  631. WA_SET_BIT_MASKED(CACHE_MODE_1, GEN8_4x4_STC_OPTIMIZATION_DISABLE);
  632. /*
  633. * BSpec recommends 8x4 when MSAA is used,
  634. * however in practice 16x4 seems fastest.
  635. *
  636. * Note that PS/WM thread counts depend on the WIZ hashing
  637. * disable bit, which we don't touch here, but it's good
  638. * to keep in mind (see 3DSTATE_PS and 3DSTATE_WM).
  639. */
  640. WA_SET_FIELD_MASKED(GEN7_GT_MODE,
  641. GEN6_WIZ_HASHING_MASK,
  642. GEN6_WIZ_HASHING_16x4);
  643. return 0;
  644. }
  645. static int bdw_init_workarounds(struct intel_engine_cs *engine)
  646. {
  647. struct drm_i915_private *dev_priv = engine->i915;
  648. int ret;
  649. ret = gen8_init_workarounds(engine);
  650. if (ret)
  651. return ret;
  652. /* WaDisableThreadStallDopClockGating:bdw (pre-production) */
  653. WA_SET_BIT_MASKED(GEN8_ROW_CHICKEN, STALL_DOP_GATING_DISABLE);
  654. /* WaDisableDopClockGating:bdw
  655. *
  656. * Also see the related UCGTCL1 write in broadwell_init_clock_gating()
  657. * to disable EUTC clock gating.
  658. */
  659. WA_SET_BIT_MASKED(GEN7_ROW_CHICKEN2,
  660. DOP_CLOCK_GATING_DISABLE);
  661. WA_SET_BIT_MASKED(HALF_SLICE_CHICKEN3,
  662. GEN8_SAMPLER_POWER_BYPASS_DIS);
  663. WA_SET_BIT_MASKED(HDC_CHICKEN0,
  664. /* WaForceContextSaveRestoreNonCoherent:bdw */
  665. HDC_FORCE_CONTEXT_SAVE_RESTORE_NON_COHERENT |
  666. /* WaDisableFenceDestinationToSLM:bdw (pre-prod) */
  667. (IS_BDW_GT3(dev_priv) ? HDC_FENCE_DEST_SLM_DISABLE : 0));
  668. return 0;
  669. }
  670. static int chv_init_workarounds(struct intel_engine_cs *engine)
  671. {
  672. struct drm_i915_private *dev_priv = engine->i915;
  673. int ret;
  674. ret = gen8_init_workarounds(engine);
  675. if (ret)
  676. return ret;
  677. /* WaDisableThreadStallDopClockGating:chv */
  678. WA_SET_BIT_MASKED(GEN8_ROW_CHICKEN, STALL_DOP_GATING_DISABLE);
  679. /* Improve HiZ throughput on CHV. */
  680. WA_SET_BIT_MASKED(HIZ_CHICKEN, CHV_HZ_8X8_MODE_IN_1X);
  681. return 0;
  682. }
  683. static int gen9_init_workarounds(struct intel_engine_cs *engine)
  684. {
  685. struct drm_i915_private *dev_priv = engine->i915;
  686. int ret;
  687. /* WaConextSwitchWithConcurrentTLBInvalidate:skl,bxt,kbl,glk */
  688. I915_WRITE(GEN9_CSFE_CHICKEN1_RCS, _MASKED_BIT_ENABLE(GEN9_PREEMPT_GPGPU_SYNC_SWITCH_DISABLE));
  689. /* WaEnableLbsSlaRetryTimerDecrement:skl,bxt,kbl,glk */
  690. I915_WRITE(BDW_SCRATCH1, I915_READ(BDW_SCRATCH1) |
  691. GEN9_LBS_SLA_RETRY_TIMER_DECREMENT_ENABLE);
  692. /* WaDisableKillLogic:bxt,skl,kbl */
  693. I915_WRITE(GAM_ECOCHK, I915_READ(GAM_ECOCHK) |
  694. ECOCHK_DIS_TLB);
  695. /* WaClearFlowControlGpgpuContextSave:skl,bxt,kbl,glk */
  696. /* WaDisablePartialInstShootdown:skl,bxt,kbl,glk */
  697. WA_SET_BIT_MASKED(GEN8_ROW_CHICKEN,
  698. FLOW_CONTROL_ENABLE |
  699. PARTIAL_INSTRUCTION_SHOOTDOWN_DISABLE);
  700. /* Syncing dependencies between camera and graphics:skl,bxt,kbl */
  701. WA_SET_BIT_MASKED(HALF_SLICE_CHICKEN3,
  702. GEN9_DISABLE_OCL_OOB_SUPPRESS_LOGIC);
  703. /* WaDisableDgMirrorFixInHalfSliceChicken5:bxt */
  704. if (IS_BXT_REVID(dev_priv, 0, BXT_REVID_A1))
  705. WA_CLR_BIT_MASKED(GEN9_HALF_SLICE_CHICKEN5,
  706. GEN9_DG_MIRROR_FIX_ENABLE);
  707. /* WaSetDisablePixMaskCammingAndRhwoInCommonSliceChicken:bxt */
  708. if (IS_BXT_REVID(dev_priv, 0, BXT_REVID_A1)) {
  709. WA_SET_BIT_MASKED(GEN7_COMMON_SLICE_CHICKEN1,
  710. GEN9_RHWO_OPTIMIZATION_DISABLE);
  711. /*
  712. * WA also requires GEN9_SLICE_COMMON_ECO_CHICKEN0[14:14] to be set
  713. * but we do that in per ctx batchbuffer as there is an issue
  714. * with this register not getting restored on ctx restore
  715. */
  716. }
  717. /* WaEnableYV12BugFixInHalfSliceChicken7:skl,bxt,kbl,glk */
  718. /* WaEnableSamplerGPGPUPreemptionSupport:skl,bxt,kbl */
  719. WA_SET_BIT_MASKED(GEN9_HALF_SLICE_CHICKEN7,
  720. GEN9_ENABLE_YV12_BUGFIX |
  721. GEN9_ENABLE_GPGPU_PREEMPTION);
  722. /* Wa4x4STCOptimizationDisable:skl,bxt,kbl,glk */
  723. /* WaDisablePartialResolveInVc:skl,bxt,kbl */
  724. WA_SET_BIT_MASKED(CACHE_MODE_1, (GEN8_4x4_STC_OPTIMIZATION_DISABLE |
  725. GEN9_PARTIAL_RESOLVE_IN_VC_DISABLE));
  726. /* WaCcsTlbPrefetchDisable:skl,bxt,kbl,glk */
  727. WA_CLR_BIT_MASKED(GEN9_HALF_SLICE_CHICKEN5,
  728. GEN9_CCS_TLB_PREFETCH_ENABLE);
  729. /* WaDisableMaskBasedCammingInRCC:bxt */
  730. if (IS_BXT_REVID(dev_priv, 0, BXT_REVID_A1))
  731. WA_SET_BIT_MASKED(SLICE_ECO_CHICKEN0,
  732. PIXEL_MASK_CAMMING_DISABLE);
  733. /* WaForceContextSaveRestoreNonCoherent:skl,bxt,kbl */
  734. WA_SET_BIT_MASKED(HDC_CHICKEN0,
  735. HDC_FORCE_CONTEXT_SAVE_RESTORE_NON_COHERENT |
  736. HDC_FORCE_CSR_NON_COHERENT_OVR_DISABLE);
  737. /* WaForceEnableNonCoherent and WaDisableHDCInvalidation are
  738. * both tied to WaForceContextSaveRestoreNonCoherent
  739. * in some hsds for skl. We keep the tie for all gen9. The
  740. * documentation is a bit hazy and so we want to get common behaviour,
  741. * even though there is no clear evidence we would need both on kbl/bxt.
  742. * This area has been source of system hangs so we play it safe
  743. * and mimic the skl regardless of what bspec says.
  744. *
  745. * Use Force Non-Coherent whenever executing a 3D context. This
  746. * is a workaround for a possible hang in the unlikely event
  747. * a TLB invalidation occurs during a PSD flush.
  748. */
  749. /* WaForceEnableNonCoherent:skl,bxt,kbl */
  750. WA_SET_BIT_MASKED(HDC_CHICKEN0,
  751. HDC_FORCE_NON_COHERENT);
  752. /* WaDisableHDCInvalidation:skl,bxt,kbl */
  753. I915_WRITE(GAM_ECOCHK, I915_READ(GAM_ECOCHK) |
  754. BDW_DISABLE_HDC_INVALIDATION);
  755. /* WaDisableSamplerPowerBypassForSOPingPong:skl,bxt,kbl */
  756. if (IS_SKYLAKE(dev_priv) ||
  757. IS_KABYLAKE(dev_priv) ||
  758. IS_BXT_REVID(dev_priv, 0, BXT_REVID_B0))
  759. WA_SET_BIT_MASKED(HALF_SLICE_CHICKEN3,
  760. GEN8_SAMPLER_POWER_BYPASS_DIS);
  761. /* WaDisableSTUnitPowerOptimization:skl,bxt,kbl,glk */
  762. WA_SET_BIT_MASKED(HALF_SLICE_CHICKEN2, GEN8_ST_PO_DISABLE);
  763. /* WaOCLCoherentLineFlush:skl,bxt,kbl */
  764. I915_WRITE(GEN8_L3SQCREG4, (I915_READ(GEN8_L3SQCREG4) |
  765. GEN8_LQSC_FLUSH_COHERENT_LINES));
  766. /* WaVFEStateAfterPipeControlwithMediaStateClear:skl,bxt,glk */
  767. ret = wa_ring_whitelist_reg(engine, GEN9_CTX_PREEMPT_REG);
  768. if (ret)
  769. return ret;
  770. /* WaEnablePreemptionGranularityControlByUMD:skl,bxt,kbl */
  771. ret= wa_ring_whitelist_reg(engine, GEN8_CS_CHICKEN1);
  772. if (ret)
  773. return ret;
  774. /* WaAllowUMDToModifyHDCChicken1:skl,bxt,kbl,glk */
  775. ret = wa_ring_whitelist_reg(engine, GEN8_HDC_CHICKEN1);
  776. if (ret)
  777. return ret;
  778. return 0;
  779. }
  780. static int skl_tune_iz_hashing(struct intel_engine_cs *engine)
  781. {
  782. struct drm_i915_private *dev_priv = engine->i915;
  783. u8 vals[3] = { 0, 0, 0 };
  784. unsigned int i;
  785. for (i = 0; i < 3; i++) {
  786. u8 ss;
  787. /*
  788. * Only consider slices where one, and only one, subslice has 7
  789. * EUs
  790. */
  791. if (!is_power_of_2(INTEL_INFO(dev_priv)->sseu.subslice_7eu[i]))
  792. continue;
  793. /*
  794. * subslice_7eu[i] != 0 (because of the check above) and
  795. * ss_max == 4 (maximum number of subslices possible per slice)
  796. *
  797. * -> 0 <= ss <= 3;
  798. */
  799. ss = ffs(INTEL_INFO(dev_priv)->sseu.subslice_7eu[i]) - 1;
  800. vals[i] = 3 - ss;
  801. }
  802. if (vals[0] == 0 && vals[1] == 0 && vals[2] == 0)
  803. return 0;
  804. /* Tune IZ hashing. See intel_device_info_runtime_init() */
  805. WA_SET_FIELD_MASKED(GEN7_GT_MODE,
  806. GEN9_IZ_HASHING_MASK(2) |
  807. GEN9_IZ_HASHING_MASK(1) |
  808. GEN9_IZ_HASHING_MASK(0),
  809. GEN9_IZ_HASHING(2, vals[2]) |
  810. GEN9_IZ_HASHING(1, vals[1]) |
  811. GEN9_IZ_HASHING(0, vals[0]));
  812. return 0;
  813. }
  814. static int skl_init_workarounds(struct intel_engine_cs *engine)
  815. {
  816. struct drm_i915_private *dev_priv = engine->i915;
  817. int ret;
  818. ret = gen9_init_workarounds(engine);
  819. if (ret)
  820. return ret;
  821. /*
  822. * Actual WA is to disable percontext preemption granularity control
  823. * until D0 which is the default case so this is equivalent to
  824. * !WaDisablePerCtxtPreemptionGranularityControl:skl
  825. */
  826. I915_WRITE(GEN7_FF_SLICE_CS_CHICKEN1,
  827. _MASKED_BIT_ENABLE(GEN9_FFSC_PERCTX_PREEMPT_CTRL));
  828. /* WaEnableGapsTsvCreditFix:skl */
  829. I915_WRITE(GEN8_GARBCNTL, (I915_READ(GEN8_GARBCNTL) |
  830. GEN9_GAPS_TSV_CREDIT_DISABLE));
  831. /* WaDisableGafsUnitClkGating:skl */
  832. WA_SET_BIT(GEN7_UCGCTL4, GEN8_EU_GAUNIT_CLOCK_GATE_DISABLE);
  833. /* WaInPlaceDecompressionHang:skl */
  834. if (IS_SKL_REVID(dev_priv, SKL_REVID_H0, REVID_FOREVER))
  835. WA_SET_BIT(GEN9_GAMT_ECO_REG_RW_IA,
  836. GAMT_ECO_ENABLE_IN_PLACE_DECOMPRESS);
  837. /* WaDisableLSQCROPERFforOCL:skl */
  838. ret = wa_ring_whitelist_reg(engine, GEN8_L3SQCREG4);
  839. if (ret)
  840. return ret;
  841. return skl_tune_iz_hashing(engine);
  842. }
  843. static int bxt_init_workarounds(struct intel_engine_cs *engine)
  844. {
  845. struct drm_i915_private *dev_priv = engine->i915;
  846. int ret;
  847. ret = gen9_init_workarounds(engine);
  848. if (ret)
  849. return ret;
  850. /* WaStoreMultiplePTEenable:bxt */
  851. /* This is a requirement according to Hardware specification */
  852. if (IS_BXT_REVID(dev_priv, 0, BXT_REVID_A1))
  853. I915_WRITE(TILECTL, I915_READ(TILECTL) | TILECTL_TLBPF);
  854. /* WaSetClckGatingDisableMedia:bxt */
  855. if (IS_BXT_REVID(dev_priv, 0, BXT_REVID_A1)) {
  856. I915_WRITE(GEN7_MISCCPCTL, (I915_READ(GEN7_MISCCPCTL) &
  857. ~GEN8_DOP_CLOCK_GATE_MEDIA_ENABLE));
  858. }
  859. /* WaDisableThreadStallDopClockGating:bxt */
  860. WA_SET_BIT_MASKED(GEN8_ROW_CHICKEN,
  861. STALL_DOP_GATING_DISABLE);
  862. /* WaDisablePooledEuLoadBalancingFix:bxt */
  863. if (IS_BXT_REVID(dev_priv, BXT_REVID_B0, REVID_FOREVER)) {
  864. WA_SET_BIT_MASKED(FF_SLICE_CS_CHICKEN2,
  865. GEN9_POOLED_EU_LOAD_BALANCING_FIX_DISABLE);
  866. }
  867. /* WaDisableSbeCacheDispatchPortSharing:bxt */
  868. if (IS_BXT_REVID(dev_priv, 0, BXT_REVID_B0)) {
  869. WA_SET_BIT_MASKED(
  870. GEN7_HALF_SLICE_CHICKEN1,
  871. GEN7_SBE_SS_CACHE_DISPATCH_PORT_SHARING_DISABLE);
  872. }
  873. /* WaDisableObjectLevelPreemptionForTrifanOrPolygon:bxt */
  874. /* WaDisableObjectLevelPreemptionForInstancedDraw:bxt */
  875. /* WaDisableObjectLevelPreemtionForInstanceId:bxt */
  876. /* WaDisableLSQCROPERFforOCL:bxt */
  877. if (IS_BXT_REVID(dev_priv, 0, BXT_REVID_A1)) {
  878. ret = wa_ring_whitelist_reg(engine, GEN9_CS_DEBUG_MODE1);
  879. if (ret)
  880. return ret;
  881. ret = wa_ring_whitelist_reg(engine, GEN8_L3SQCREG4);
  882. if (ret)
  883. return ret;
  884. }
  885. /* WaProgramL3SqcReg1DefaultForPerf:bxt */
  886. if (IS_BXT_REVID(dev_priv, BXT_REVID_B0, REVID_FOREVER))
  887. I915_WRITE(GEN8_L3SQCREG1, L3_GENERAL_PRIO_CREDITS(62) |
  888. L3_HIGH_PRIO_CREDITS(2));
  889. /* WaToEnableHwFixForPushConstHWBug:bxt */
  890. if (IS_BXT_REVID(dev_priv, BXT_REVID_C0, REVID_FOREVER))
  891. WA_SET_BIT_MASKED(COMMON_SLICE_CHICKEN2,
  892. GEN8_SBE_DISABLE_REPLAY_BUF_OPTIMIZATION);
  893. /* WaInPlaceDecompressionHang:bxt */
  894. if (IS_BXT_REVID(dev_priv, BXT_REVID_C0, REVID_FOREVER))
  895. WA_SET_BIT(GEN9_GAMT_ECO_REG_RW_IA,
  896. GAMT_ECO_ENABLE_IN_PLACE_DECOMPRESS);
  897. return 0;
  898. }
  899. static int kbl_init_workarounds(struct intel_engine_cs *engine)
  900. {
  901. struct drm_i915_private *dev_priv = engine->i915;
  902. int ret;
  903. ret = gen9_init_workarounds(engine);
  904. if (ret)
  905. return ret;
  906. /* WaEnableGapsTsvCreditFix:kbl */
  907. I915_WRITE(GEN8_GARBCNTL, (I915_READ(GEN8_GARBCNTL) |
  908. GEN9_GAPS_TSV_CREDIT_DISABLE));
  909. /* WaDisableDynamicCreditSharing:kbl */
  910. if (IS_KBL_REVID(dev_priv, 0, KBL_REVID_B0))
  911. WA_SET_BIT(GAMT_CHKN_BIT_REG,
  912. GAMT_CHKN_DISABLE_DYNAMIC_CREDIT_SHARING);
  913. /* WaDisableFenceDestinationToSLM:kbl (pre-prod) */
  914. if (IS_KBL_REVID(dev_priv, KBL_REVID_A0, KBL_REVID_A0))
  915. WA_SET_BIT_MASKED(HDC_CHICKEN0,
  916. HDC_FENCE_DEST_SLM_DISABLE);
  917. /* WaToEnableHwFixForPushConstHWBug:kbl */
  918. if (IS_KBL_REVID(dev_priv, KBL_REVID_C0, REVID_FOREVER))
  919. WA_SET_BIT_MASKED(COMMON_SLICE_CHICKEN2,
  920. GEN8_SBE_DISABLE_REPLAY_BUF_OPTIMIZATION);
  921. /* WaDisableGafsUnitClkGating:kbl */
  922. WA_SET_BIT(GEN7_UCGCTL4, GEN8_EU_GAUNIT_CLOCK_GATE_DISABLE);
  923. /* WaDisableSbeCacheDispatchPortSharing:kbl */
  924. WA_SET_BIT_MASKED(
  925. GEN7_HALF_SLICE_CHICKEN1,
  926. GEN7_SBE_SS_CACHE_DISPATCH_PORT_SHARING_DISABLE);
  927. /* WaInPlaceDecompressionHang:kbl */
  928. WA_SET_BIT(GEN9_GAMT_ECO_REG_RW_IA,
  929. GAMT_ECO_ENABLE_IN_PLACE_DECOMPRESS);
  930. /* WaDisableLSQCROPERFforOCL:kbl */
  931. ret = wa_ring_whitelist_reg(engine, GEN8_L3SQCREG4);
  932. if (ret)
  933. return ret;
  934. return 0;
  935. }
  936. static int glk_init_workarounds(struct intel_engine_cs *engine)
  937. {
  938. struct drm_i915_private *dev_priv = engine->i915;
  939. int ret;
  940. ret = gen9_init_workarounds(engine);
  941. if (ret)
  942. return ret;
  943. /* WaToEnableHwFixForPushConstHWBug:glk */
  944. WA_SET_BIT_MASKED(COMMON_SLICE_CHICKEN2,
  945. GEN8_SBE_DISABLE_REPLAY_BUF_OPTIMIZATION);
  946. return 0;
  947. }
  948. int init_workarounds_ring(struct intel_engine_cs *engine)
  949. {
  950. struct drm_i915_private *dev_priv = engine->i915;
  951. int err;
  952. WARN_ON(engine->id != RCS);
  953. dev_priv->workarounds.count = 0;
  954. dev_priv->workarounds.hw_whitelist_count[engine->id] = 0;
  955. if (IS_BROADWELL(dev_priv))
  956. err = bdw_init_workarounds(engine);
  957. else if (IS_CHERRYVIEW(dev_priv))
  958. err = chv_init_workarounds(engine);
  959. else if (IS_SKYLAKE(dev_priv))
  960. err = skl_init_workarounds(engine);
  961. else if (IS_BROXTON(dev_priv))
  962. err = bxt_init_workarounds(engine);
  963. else if (IS_KABYLAKE(dev_priv))
  964. err = kbl_init_workarounds(engine);
  965. else if (IS_GEMINILAKE(dev_priv))
  966. err = glk_init_workarounds(engine);
  967. else
  968. err = 0;
  969. if (err)
  970. return err;
  971. DRM_DEBUG_DRIVER("%s: Number of context specific w/a: %d\n",
  972. engine->name, dev_priv->workarounds.count);
  973. return 0;
  974. }
  975. int intel_ring_workarounds_emit(struct drm_i915_gem_request *req)
  976. {
  977. struct i915_workarounds *w = &req->i915->workarounds;
  978. u32 *cs;
  979. int ret, i;
  980. if (w->count == 0)
  981. return 0;
  982. ret = req->engine->emit_flush(req, EMIT_BARRIER);
  983. if (ret)
  984. return ret;
  985. cs = intel_ring_begin(req, (w->count * 2 + 2));
  986. if (IS_ERR(cs))
  987. return PTR_ERR(cs);
  988. *cs++ = MI_LOAD_REGISTER_IMM(w->count);
  989. for (i = 0; i < w->count; i++) {
  990. *cs++ = i915_mmio_reg_offset(w->reg[i].addr);
  991. *cs++ = w->reg[i].value;
  992. }
  993. *cs++ = MI_NOOP;
  994. intel_ring_advance(req, cs);
  995. ret = req->engine->emit_flush(req, EMIT_BARRIER);
  996. if (ret)
  997. return ret;
  998. return 0;
  999. }
  1000. static bool ring_is_idle(struct intel_engine_cs *engine)
  1001. {
  1002. struct drm_i915_private *dev_priv = engine->i915;
  1003. bool idle = true;
  1004. intel_runtime_pm_get(dev_priv);
  1005. /* No bit for gen2, so assume the CS parser is idle */
  1006. if (INTEL_GEN(dev_priv) > 2 && !(I915_READ_MODE(engine) & MODE_IDLE))
  1007. idle = false;
  1008. intel_runtime_pm_put(dev_priv);
  1009. return idle;
  1010. }
  1011. /**
  1012. * intel_engine_is_idle() - Report if the engine has finished process all work
  1013. * @engine: the intel_engine_cs
  1014. *
  1015. * Return true if there are no requests pending, nothing left to be submitted
  1016. * to hardware, and that the engine is idle.
  1017. */
  1018. bool intel_engine_is_idle(struct intel_engine_cs *engine)
  1019. {
  1020. struct drm_i915_private *dev_priv = engine->i915;
  1021. /* More white lies, if wedged, hw state is inconsistent */
  1022. if (i915_terminally_wedged(&dev_priv->gpu_error))
  1023. return true;
  1024. /* Any inflight/incomplete requests? */
  1025. if (!i915_seqno_passed(intel_engine_get_seqno(engine),
  1026. intel_engine_last_submit(engine)))
  1027. return false;
  1028. if (I915_SELFTEST_ONLY(engine->breadcrumbs.mock))
  1029. return true;
  1030. /* Interrupt/tasklet pending? */
  1031. if (test_bit(ENGINE_IRQ_EXECLIST, &engine->irq_posted))
  1032. return false;
  1033. /* Both ports drained, no more ELSP submission? */
  1034. if (port_request(&engine->execlist_port[0]))
  1035. return false;
  1036. /* Ring stopped? */
  1037. if (!ring_is_idle(engine))
  1038. return false;
  1039. return true;
  1040. }
  1041. bool intel_engines_are_idle(struct drm_i915_private *dev_priv)
  1042. {
  1043. struct intel_engine_cs *engine;
  1044. enum intel_engine_id id;
  1045. if (READ_ONCE(dev_priv->gt.active_requests))
  1046. return false;
  1047. /* If the driver is wedged, HW state may be very inconsistent and
  1048. * report that it is still busy, even though we have stopped using it.
  1049. */
  1050. if (i915_terminally_wedged(&dev_priv->gpu_error))
  1051. return true;
  1052. for_each_engine(engine, dev_priv, id) {
  1053. if (!intel_engine_is_idle(engine))
  1054. return false;
  1055. }
  1056. return true;
  1057. }
  1058. void intel_engines_reset_default_submission(struct drm_i915_private *i915)
  1059. {
  1060. struct intel_engine_cs *engine;
  1061. enum intel_engine_id id;
  1062. for_each_engine(engine, i915, id)
  1063. engine->set_default_submission(engine);
  1064. }
  1065. void intel_engines_mark_idle(struct drm_i915_private *i915)
  1066. {
  1067. struct intel_engine_cs *engine;
  1068. enum intel_engine_id id;
  1069. for_each_engine(engine, i915, id) {
  1070. intel_engine_disarm_breadcrumbs(engine);
  1071. i915_gem_batch_pool_fini(&engine->batch_pool);
  1072. engine->no_priolist = false;
  1073. }
  1074. }
  1075. #if IS_ENABLED(CONFIG_DRM_I915_SELFTEST)
  1076. #include "selftests/mock_engine.c"
  1077. #endif