intel_engine_cs.c 38 KB

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