History

Merge tag 'drm-intel-next-2017-01-23' of git://anongit.freedesktop.org/git/drm-intel into drm-next

Final block of feature work for 4.11: - gen8 pd cleanup from Matthew Auld - more cleanups for view/vma (Chris) - dmc support on glk (Anusha Srivatsa) - use core crc api (Tomue) - track wedged requests using fence.error (Chris) - lots of psr fixes (Nagaraju, Vathsala) - dp mst support, acked for merging through drm-intel by Takashi (Libin) - huc loading support, including uapi for libva to use it (Anusha Srivatsa) * tag 'drm-intel-next-2017-01-23' of git://anongit.freedesktop.org/git/drm-intel: (111 commits) drm/i915: Update DRIVER_DATE to 20170123 drm/i915: reinstate call to trace_i915_vma_bind drm/i915: Assert that created vma has a whole number of pages drm/i915: Assert the drm_mm_node is allocated when on the VM lists drm/i915: Treat an error from i915_vma_instance() as unlikely drm/i915: Reject vma creation larger than address space drm/i915: Use common LRU inactive vma bumping for unpin_from_display drm/i915: Do an unlocked wait before set-cache-level ioctl drm/i915/huc: Assert that HuC vma is placed in GuC accessible range drm/i915/huc: Avoid attempting to authenticate non-existent fw drm/i915: Set adjustment to zero on Up/Down interrupts if freq is already max/min drm/i915: Remove the double handling of 'flags from intel_mode_from_pipe_config() drm/i915: Remove crtc->config usage from intel_modeset_readout_hw_state() drm/i915: Release temporary load-detect state upon switching drm/i915: Remove i915_gem_object_to_ggtt() drm/i915: Remove i915_vma_create from VMA API drm/i915: Add a check that the VMA instance we lookup matches the request drm/i915: Rename some warts in the VMA API drm/i915: Track pinned vma in intel_plane_state drm/i915/get_params: Add HuC status to getparams ...

Dave Airlie committed 9 years ago

Commit a7e26412 parents c4d79c2 add632958 files · +3257 −1891Browse files

Unified · Split

58 files
  1. Documentation/sound/hd-audio/dp-mst.rst +17 −0
  2. drivers/gpu/drm/i915/Makefile +2 −0
  3. drivers/gpu/drm/i915/gvt/aperture_gm.c +10 −23
  4. drivers/gpu/drm/i915/i915_debugfs.c +95 −8
  5. drivers/gpu/drm/i915/i915_drv.c +29 −31
  6. drivers/gpu/drm/i915/i915_drv.h +26 −44
  7. drivers/gpu/drm/i915/i915_gem.c +170 −165
  8. drivers/gpu/drm/i915/i915_gem_context.c +30 −25
  9. drivers/gpu/drm/i915/i915_gem_evict.c +21 −18
  10. drivers/gpu/drm/i915/i915_gem_execbuffer.c +3 −4
  11. drivers/gpu/drm/i915/i915_gem_fence_reg.c +26 −38
  12. drivers/gpu/drm/i915/i915_gem_fence_reg.h +2 −0
  13. drivers/gpu/drm/i915/i915_gem_gtt.c +304 −134
  14. drivers/gpu/drm/i915/i915_gem_gtt.h +57 −17
  15. drivers/gpu/drm/i915/i915_gem_internal.c +7 −1
  16. drivers/gpu/drm/i915/i915_gem_object.h +23 −0
  17. drivers/gpu/drm/i915/i915_gem_render_state.c +3 −3
  18. drivers/gpu/drm/i915/i915_gem_request.c +10 −25
  19. drivers/gpu/drm/i915/i915_gem_stolen.c +9 −7
  20. drivers/gpu/drm/i915/i915_gem_tiling.c +217 −130
  21. drivers/gpu/drm/i915/i915_gpu_error.c +1 −0
  22. drivers/gpu/drm/i915/i915_guc_reg.h +6 −0
  23. drivers/gpu/drm/i915/i915_guc_submission.c +9 −594
  24. drivers/gpu/drm/i915/i915_irq.c +60 −26
  25. drivers/gpu/drm/i915/i915_reg.h +17 −3
  26. drivers/gpu/drm/i915/i915_sw_fence.c +1 −0
  27. drivers/gpu/drm/i915/i915_sysfs.c +1 −1
  28. drivers/gpu/drm/i915/i915_trace.h +8 −8
  29. drivers/gpu/drm/i915/i915_vgpu.c +12 −21
  30. drivers/gpu/drm/i915/i915_vma.c +129 −92
  31. drivers/gpu/drm/i915/i915_vma.h +31 −10
  32. drivers/gpu/drm/i915/intel_atomic_plane.c +20 −0
  33. drivers/gpu/drm/i915/intel_csr.c +10 −2
  34. drivers/gpu/drm/i915/intel_device_info.c +1 −1
  35. drivers/gpu/drm/i915/intel_display.c +87 −116
  36. drivers/gpu/drm/i915/intel_dp.c +37 −1
  37. drivers/gpu/drm/i915/intel_drv.h +13 −2
  38. drivers/gpu/drm/i915/intel_engine_cs.c +1 −1
  39. drivers/gpu/drm/i915/intel_fbc.c +21 −33
  40. drivers/gpu/drm/i915/intel_fbdev.c +5 −2
  41. drivers/gpu/drm/i915/intel_guc_fwif.h +20 −4
  42. drivers/gpu/drm/i915/intel_guc_loader.c +114 −100
  43. drivers/gpu/drm/i915/intel_guc_log.c +658 −0
  44. drivers/gpu/drm/i915/intel_huc.c +338 −0
  45. drivers/gpu/drm/i915/intel_lrc.c +6 −18
  46. drivers/gpu/drm/i915/intel_lrc.h +1 −1
  47. drivers/gpu/drm/i915/intel_overlay.c +1 −2
  48. drivers/gpu/drm/i915/intel_pipe_crc.c +88 −16
  49. drivers/gpu/drm/i915/intel_psr.c +160 −43
  50. drivers/gpu/drm/i915/intel_ringbuffer.c +8 −8
  51. drivers/gpu/drm/i915/intel_sprite.c +4 −4
  52. drivers/gpu/drm/i915/intel_uc.c +0 −26
  53. drivers/gpu/drm/i915/intel_uc.h +47 −26
  54. include/drm/drm_dp_helper.h +12 −1
  55. include/uapi/drm/i915_drm.h +1 −0
  56. sound/pci/hda/hda_codec.c +72 −4
  57. sound/pci/hda/hda_codec.h +3 −0
  58. sound/pci/hda/patch_hdmi.c +193 −52
Documentation/sound/hd-audio/dp-mst.rst+17−0
@@ -19,6 +19,23 @@ PCM · 18 unmodified lines
19===19===
20To be added20To be added
21 21
22Pin Initialization
23==================
24Each pin may have several device entries (virtual pins). On Intel platform,
25the device entries number is dynamically changed. If DP MST hub is connected,
26it is in DP MST mode, and the device entries number is 3. Otherwise, the
27device entries number is 1.
28
29To simplify the implementation, all the device entries will be initialized
30when bootup no matter whether it is in DP MST mode or not.
31
32Connection list
33===============
34DP MST reuses connection list code. The code can be reused because
35device entries on the same pin have the same connection list.
36
37This means DP MST gets the device entry connection list without the
38device entry setting.
22 39
23Jack40Jack
24====41====
drivers/gpu/drm/i915/Makefile+2−0
@@ -56,7 +56,9 @@ i915-y += i915_cmd_parser.o \ · 55 unmodified lines
56 56
57# general-purpose microcontroller (GuC) support57# general-purpose microcontroller (GuC) support
58i915-y += intel_uc.o \58i915-y += intel_uc.o \
59 intel_guc_log.o \
59 intel_guc_loader.o \60 intel_guc_loader.o \
61 intel_huc.o \
60 i915_guc_submission.o62 i915_guc_submission.o
61 63
62# autogenerated null render state64# autogenerated null render state
drivers/gpu/drm/i915/gvt/aperture_gm.c+10−23
@@ -41,47 +41,34 @@ static int alloc_gm(struct intel_vgpu *vgpu, bool high_gm) · 40 unmodified lines
41{41{
42 struct intel_gvt *gvt = vgpu->gvt;42 struct intel_gvt *gvt = vgpu->gvt;
43 struct drm_i915_private *dev_priv = gvt->dev_priv;43 struct drm_i915_private *dev_priv = gvt->dev_priv;
44 u32 alloc_flag, search_flag;44 unsigned int flags;
45 u64 start, end, size;45 u64 start, end, size;
46 struct drm_mm_node *node;46 struct drm_mm_node *node;
47 int retried = 0;
48 int ret;47 int ret;
49 48
50 if (high_gm) {49 if (high_gm) {
51 search_flag = DRM_MM_SEARCH_BELOW;
52 alloc_flag = DRM_MM_CREATE_TOP;
53 node = &vgpu->gm.high_gm_node;50 node = &vgpu->gm.high_gm_node;
54 size = vgpu_hidden_sz(vgpu);51 size = vgpu_hidden_sz(vgpu);
55 start = gvt_hidden_gmadr_base(gvt);52 start = gvt_hidden_gmadr_base(gvt);
56 end = gvt_hidden_gmadr_end(gvt);53 end = gvt_hidden_gmadr_end(gvt);
54 flags = PIN_HIGH;
57 } else {55 } else {
58 search_flag = DRM_MM_SEARCH_DEFAULT;
59 alloc_flag = DRM_MM_CREATE_DEFAULT;
60 node = &vgpu->gm.low_gm_node;56 node = &vgpu->gm.low_gm_node;
61 size = vgpu_aperture_sz(vgpu);57 size = vgpu_aperture_sz(vgpu);
62 start = gvt_aperture_gmadr_base(gvt);58 start = gvt_aperture_gmadr_base(gvt);
63 end = gvt_aperture_gmadr_end(gvt);59 end = gvt_aperture_gmadr_end(gvt);
60 flags = PIN_MAPPABLE;
64 }61 }
65 62
66 mutex_lock(&dev_priv->drm.struct_mutex);63 mutex_lock(&dev_priv->drm.struct_mutex);
67search_again:64 ret = i915_gem_gtt_insert(&dev_priv->ggtt.base, node,
68 ret = drm_mm_insert_node_in_range_generic(&dev_priv->ggtt.base.mm,65 size, 4096, I915_COLOR_UNEVICTABLE,
69 node, size, 4096,66 start, end, flags);
70 I915_COLOR_UNEVICTABLE,
71 start, end, search_flag,
72 alloc_flag);
73 if (ret) {
74 ret = i915_gem_evict_something(&dev_priv->ggtt.base,
75 size, 4096,
76 I915_COLOR_UNEVICTABLE,
77 start, end, 0);
78 if (ret == 0 && ++retried < 3)
79 goto search_again;
80
81 gvt_err("fail to alloc %s gm space from host, retried %d\n",
82 high_gm ? "high" : "low", retried);
83 }
84 mutex_unlock(&dev_priv->drm.struct_mutex);67 mutex_unlock(&dev_priv->drm.struct_mutex);
68 if (ret)
69 gvt_err("fail to alloc %s gm space from host\n",
70 high_gm ? "high" : "low");
71
85 return ret;72 return ret;
86}73}
87 74
drivers/gpu/drm/i915/i915_debugfs.c+95−8
@@ -159,8 +159,35 @@ describe_obj(struct seq_file *m, struct drm_i915_gem_object *obj) · 158 unmodified lines
159 seq_printf(m, " (%sgtt offset: %08llx, size: %08llx",159 seq_printf(m, " (%sgtt offset: %08llx, size: %08llx",
160 i915_vma_is_ggtt(vma) ? "g" : "pp",160 i915_vma_is_ggtt(vma) ? "g" : "pp",
161 vma->node.start, vma->node.size);161 vma->node.start, vma->node.size);
162 if (i915_vma_is_ggtt(vma))162 if (i915_vma_is_ggtt(vma)) {
163 seq_printf(m, ", type: %u", vma->ggtt_view.type);163 switch (vma->ggtt_view.type) {
164 case I915_GGTT_VIEW_NORMAL:
165 seq_puts(m, ", normal");
166 break;
167
168 case I915_GGTT_VIEW_PARTIAL:
169 seq_printf(m, ", partial [%08llx+%x]",
170 vma->ggtt_view.partial.offset << PAGE_SHIFT,
171 vma->ggtt_view.partial.size << PAGE_SHIFT);
172 break;
173
174 case I915_GGTT_VIEW_ROTATED:
175 seq_printf(m, ", rotated [(%ux%u, stride=%u, offset=%u), (%ux%u, stride=%u, offset=%u)]",
176 vma->ggtt_view.rotated.plane[0].width,
177 vma->ggtt_view.rotated.plane[0].height,
178 vma->ggtt_view.rotated.plane[0].stride,
179 vma->ggtt_view.rotated.plane[0].offset,
180 vma->ggtt_view.rotated.plane[1].width,
181 vma->ggtt_view.rotated.plane[1].height,
182 vma->ggtt_view.rotated.plane[1].stride,
183 vma->ggtt_view.rotated.plane[1].offset);
184 break;
185
186 default:
187 MISSING_CASE(vma->ggtt_view.type);
188 break;
189 }
190 }
164 if (vma->fence)191 if (vma->fence)
165 seq_printf(m, " , fence: %d%s",192 seq_printf(m, " , fence: %d%s",
166 vma->fence->id,193 vma->fence->id,
@@ -2325,10 +2352,40 @@ static int i915_llc(struct seq_file *m, void *data) · 2158 unmodified lines
2325 return 0;2352 return 0;
2326}2353}
2327 2354
2355static int i915_huc_load_status_info(struct seq_file *m, void *data)
2356{
2357 struct drm_i915_private *dev_priv = node_to_i915(m->private);
2358 struct intel_uc_fw *huc_fw = &dev_priv->huc.fw;
2359
2360 if (!HAS_HUC_UCODE(dev_priv))
2361 return 0;
2362
2363 seq_puts(m, "HuC firmware status:\n");
2364 seq_printf(m, "\tpath: %s\n", huc_fw->path);
2365 seq_printf(m, "\tfetch: %s\n",
2366 intel_uc_fw_status_repr(huc_fw->fetch_status));
2367 seq_printf(m, "\tload: %s\n",
2368 intel_uc_fw_status_repr(huc_fw->load_status));
2369 seq_printf(m, "\tversion wanted: %d.%d\n",
2370 huc_fw->major_ver_wanted, huc_fw->minor_ver_wanted);
2371 seq_printf(m, "\tversion found: %d.%d\n",
2372 huc_fw->major_ver_found, huc_fw->minor_ver_found);
2373 seq_printf(m, "\theader: offset is %d; size = %d\n",
2374 huc_fw->header_offset, huc_fw->header_size);
2375 seq_printf(m, "\tuCode: offset is %d; size = %d\n",
2376 huc_fw->ucode_offset, huc_fw->ucode_size);
2377 seq_printf(m, "\tRSA: offset is %d; size = %d\n",
2378 huc_fw->rsa_offset, huc_fw->rsa_size);
2379
2380 seq_printf(m, "\nHuC status 0x%08x:\n", I915_READ(HUC_STATUS2));
2381
2382 return 0;
2383}
2384
2328static int i915_guc_load_status_info(struct seq_file *m, void *data)2385static int i915_guc_load_status_info(struct seq_file *m, void *data)
2329{2386{
2330 struct drm_i915_private *dev_priv = node_to_i915(m->private);2387 struct drm_i915_private *dev_priv = node_to_i915(m->private);
2331 struct intel_guc_fw *guc_fw = &dev_priv->guc.guc_fw;2388 struct intel_uc_fw *guc_fw = &dev_priv->guc.fw;
2332 u32 tmp, i;2389 u32 tmp, i;
2333 2390
2334 if (!HAS_GUC_UCODE(dev_priv))2391 if (!HAS_GUC_UCODE(dev_priv))
@@ -2336,15 +2393,15 @@ static int i915_guc_load_status_info(struct seq_file *m, void *data) · 1 unmodified line
2336 2393
2337 seq_printf(m, "GuC firmware status:\n");2394 seq_printf(m, "GuC firmware status:\n");
2338 seq_printf(m, "\tpath: %s\n",2395 seq_printf(m, "\tpath: %s\n",
2339 guc_fw->guc_fw_path);2396 guc_fw->path);
2340 seq_printf(m, "\tfetch: %s\n",2397 seq_printf(m, "\tfetch: %s\n",
2341 intel_guc_fw_status_repr(guc_fw->guc_fw_fetch_status));2398 intel_uc_fw_status_repr(guc_fw->fetch_status));
2342 seq_printf(m, "\tload: %s\n",2399 seq_printf(m, "\tload: %s\n",
2343 intel_guc_fw_status_repr(guc_fw->guc_fw_load_status));2400 intel_uc_fw_status_repr(guc_fw->load_status));
2344 seq_printf(m, "\tversion wanted: %d.%d\n",2401 seq_printf(m, "\tversion wanted: %d.%d\n",
2345 guc_fw->guc_fw_major_wanted, guc_fw->guc_fw_minor_wanted);2402 guc_fw->major_ver_wanted, guc_fw->minor_ver_wanted);
2346 seq_printf(m, "\tversion found: %d.%d\n",2403 seq_printf(m, "\tversion found: %d.%d\n",
2347 guc_fw->guc_fw_major_found, guc_fw->guc_fw_minor_found);2404 guc_fw->major_ver_found, guc_fw->minor_ver_found);
2348 seq_printf(m, "\theader: offset is %d; size = %d\n",2405 seq_printf(m, "\theader: offset is %d; size = %d\n",
2349 guc_fw->header_offset, guc_fw->header_size);2406 guc_fw->header_offset, guc_fw->header_size);
2350 seq_printf(m, "\tuCode: offset is %d; size = %d\n",2407 seq_printf(m, "\tuCode: offset is %d; size = %d\n",
@@ -2532,6 +2589,29 @@ DEFINE_SIMPLE_ATTRIBUTE(i915_guc_log_control_fops, · 181 unmodified lines
2532 i915_guc_log_control_get, i915_guc_log_control_set,2589 i915_guc_log_control_get, i915_guc_log_control_set,
2533 "%lld\n");2590 "%lld\n");
2534 2591
2592static const char *psr2_live_status(u32 val)
2593{
2594 static const char * const live_status[] = {
2595 "IDLE",
2596 "CAPTURE",
2597 "CAPTURE_FS",
2598 "SLEEP",
2599 "BUFON_FW",
2600 "ML_UP",
2601 "SU_STANDBY",
2602 "FAST_SLEEP",
2603 "DEEP_SLEEP",
2604 "BUF_ON",
2605 "TG_ON"
2606 };
2607
2608 val = (val & EDP_PSR2_STATUS_STATE_MASK) >> EDP_PSR2_STATUS_STATE_SHIFT;
2609 if (val < ARRAY_SIZE(live_status))
2610 return live_status[val];
2611
2612 return "unknown";
2613}
2614
2535static int i915_edp_psr_status(struct seq_file *m, void *data)2615static int i915_edp_psr_status(struct seq_file *m, void *data)
2536{2616{
2537 struct drm_i915_private *dev_priv = node_to_i915(m->private);2617 struct drm_i915_private *dev_priv = node_to_i915(m->private);
@@ -2606,6 +2686,12 @@ static int i915_edp_psr_status(struct seq_file *m, void *data) · 68 unmodified lines
2606 2686
2607 seq_printf(m, "Performance_Counter: %u\n", psrperf);2687 seq_printf(m, "Performance_Counter: %u\n", psrperf);
2608 }2688 }
2689 if (dev_priv->psr.psr2_support) {
2690 u32 psr2 = I915_READ(EDP_PSR2_STATUS_CTL);
2691
2692 seq_printf(m, "EDP_PSR2_STATUS_CTL: %x [%s]\n",
2693 psr2, psr2_live_status(psr2));
2694 }
2609 mutex_unlock(&dev_priv->psr.lock);2695 mutex_unlock(&dev_priv->psr.lock);
2610 2696
2611 intel_runtime_pm_put(dev_priv);2697 intel_runtime_pm_put(dev_priv);
@@ -4553,6 +4639,7 @@ static const struct drm_info_list i915_debugfs_list[] = { · 1941 unmodified lines
4553 {"i915_guc_info", i915_guc_info, 0},4639 {"i915_guc_info", i915_guc_info, 0},
4554 {"i915_guc_load_status", i915_guc_load_status_info, 0},4640 {"i915_guc_load_status", i915_guc_load_status_info, 0},
4555 {"i915_guc_log_dump", i915_guc_log_dump, 0},4641 {"i915_guc_log_dump", i915_guc_log_dump, 0},
4642 {"i915_huc_load_status", i915_huc_load_status_info, 0},
4556 {"i915_frequency_info", i915_frequency_info, 0},4643 {"i915_frequency_info", i915_frequency_info, 0},
4557 {"i915_hangcheck_info", i915_hangcheck_info, 0},4644 {"i915_hangcheck_info", i915_hangcheck_info, 0},
4558 {"i915_drpc_info", i915_drpc_info, 0},4645 {"i915_drpc_info", i915_drpc_info, 0},
drivers/gpu/drm/i915/i915_drv.c+29−31
@@ -49,6 +49,7 @@ · 48 unmodified lines
49#include "i915_trace.h"49#include "i915_trace.h"
50#include "i915_vgpu.h"50#include "i915_vgpu.h"
51#include "intel_drv.h"51#include "intel_drv.h"
52#include "intel_uc.h"
52 53
53static struct drm_driver driver;54static struct drm_driver driver;
54 55
@@ -315,6 +316,12 @@ static int i915_getparam(struct drm_device *dev, void *data, · 260 unmodified lines
315 case I915_PARAM_MIN_EU_IN_POOL:316 case I915_PARAM_MIN_EU_IN_POOL:
316 value = INTEL_INFO(dev_priv)->sseu.min_eu_in_pool;317 value = INTEL_INFO(dev_priv)->sseu.min_eu_in_pool;
317 break;318 break;
319 case I915_PARAM_HUC_STATUS:
320 /* The register is already force-woken. We dont need
321 * any rpm here
322 */
323 value = I915_READ(HUC_STATUS2) & HUC_FW_VERIFIED;
324 break;
318 case I915_PARAM_MMAP_GTT_VERSION:325 case I915_PARAM_MMAP_GTT_VERSION:
319 /* Though we've started our numbering from 1, and so class all326 /* Though we've started our numbering from 1, and so class all
320 * earlier versions as 0, in effect their value is undefined as327 * earlier versions as 0, in effect their value is undefined as
@@ -599,6 +606,7 @@ static int i915_load_modeset_init(struct drm_device *dev) · 278 unmodified lines
599 if (ret)606 if (ret)
600 goto cleanup_irq;607 goto cleanup_irq;
601 608
609 intel_huc_init(dev_priv);
602 intel_guc_init(dev_priv);610 intel_guc_init(dev_priv);
603 611
604 ret = i915_gem_init(dev_priv);612 ret = i915_gem_init(dev_priv);
@@ -627,6 +635,7 @@ cleanup_gem: · 22 unmodified lines
627 i915_gem_fini(dev_priv);635 i915_gem_fini(dev_priv);
628cleanup_irq:636cleanup_irq:
629 intel_guc_fini(dev_priv);637 intel_guc_fini(dev_priv);
638 intel_huc_fini(dev_priv);
630 drm_irq_uninstall(dev);639 drm_irq_uninstall(dev);
631 intel_teardown_gmbus(dev_priv);640 intel_teardown_gmbus(dev_priv);
632cleanup_csr:641cleanup_csr:
@@ -1114,7 +1123,7 @@ static void i915_driver_register(struct drm_i915_private *dev_priv) · 481 unmodified lines
1114 /* Reveal our presence to userspace */1123 /* Reveal our presence to userspace */
1115 if (drm_dev_register(dev, 0) == 0) {1124 if (drm_dev_register(dev, 0) == 0) {
1116 i915_debugfs_register(dev_priv);1125 i915_debugfs_register(dev_priv);
1117 i915_guc_register(dev_priv);1126 i915_guc_log_register(dev_priv);
1118 i915_setup_sysfs(dev_priv);1127 i915_setup_sysfs(dev_priv);
1119 1128
1120 /* Depends on sysfs having been initialized */1129 /* Depends on sysfs having been initialized */
@@ -1158,7 +1167,7 @@ static void i915_driver_unregister(struct drm_i915_private *dev_priv) · 37 unmodified lines
1158 i915_perf_unregister(dev_priv);1167 i915_perf_unregister(dev_priv);
1159 1168
1160 i915_teardown_sysfs(dev_priv);1169 i915_teardown_sysfs(dev_priv);
1161 i915_guc_unregister(dev_priv);1170 i915_guc_log_unregister(dev_priv);
1162 i915_debugfs_unregister(dev_priv);1171 i915_debugfs_unregister(dev_priv);
1163 drm_dev_unregister(&dev_priv->drm);1172 drm_dev_unregister(&dev_priv->drm);
1164 1173
@@ -1314,6 +1323,7 @@ void i915_driver_unload(struct drm_device *dev) · 149 unmodified lines
1314 drain_workqueue(dev_priv->wq);1323 drain_workqueue(dev_priv->wq);
1315 1324
1316 intel_guc_fini(dev_priv);1325 intel_guc_fini(dev_priv);
1326 intel_huc_fini(dev_priv);
1317 i915_gem_fini(dev_priv);1327 i915_gem_fini(dev_priv);
1318 intel_fbc_cleanup_cfb(dev_priv);1328 intel_fbc_cleanup_cfb(dev_priv);
1319 1329
@@ -1471,7 +1481,7 @@ static int i915_drm_suspend_late(struct drm_device *dev, bool hibernation) · 151 unmodified lines
1471 1481
1472 intel_display_set_init_power(dev_priv, false);1482 intel_display_set_init_power(dev_priv, false);
1473 1483
1474 fw_csr = !IS_BROXTON(dev_priv) &&1484 fw_csr = !IS_GEN9_LP(dev_priv) &&
1475 suspend_to_idle(dev_priv) && dev_priv->csr.dmc_payload;1485 suspend_to_idle(dev_priv) && dev_priv->csr.dmc_payload;
1476 /*1486 /*
1477 * In case of firmware assisted context save/restore don't manually1487 * In case of firmware assisted context save/restore don't manually
@@ -1484,7 +1494,7 @@ static int i915_drm_suspend_late(struct drm_device *dev, bool hibernation) · 6 unmodified lines
1484 intel_power_domains_suspend(dev_priv);1494 intel_power_domains_suspend(dev_priv);
1485 1495
1486 ret = 0;1496 ret = 0;
1487 if (IS_BROXTON(dev_priv))1497 if (IS_GEN9_LP(dev_priv))
1488 bxt_enable_dc9(dev_priv);1498 bxt_enable_dc9(dev_priv);
1489 else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))1499 else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
1490 hsw_enable_pc8(dev_priv);1500 hsw_enable_pc8(dev_priv);
@@ -1692,7 +1702,7 @@ static int i915_drm_resume_early(struct drm_device *dev) · 201 unmodified lines
1692 1702
1693 intel_uncore_early_sanitize(dev_priv, true);1703 intel_uncore_early_sanitize(dev_priv, true);
1694 1704
1695 if (IS_BROXTON(dev_priv)) {1705 if (IS_GEN9_LP(dev_priv)) {
1696 if (!dev_priv->suspended_to_idle)1706 if (!dev_priv->suspended_to_idle)
1697 gen9_sanitize_dc_state(dev_priv);1707 gen9_sanitize_dc_state(dev_priv);
1698 bxt_disable_dc9(dev_priv);1708 bxt_disable_dc9(dev_priv);
@@ -1702,7 +1712,7 @@ static int i915_drm_resume_early(struct drm_device *dev) · 3 unmodified lines
1702 1712
1703 intel_uncore_sanitize(dev_priv);1713 intel_uncore_sanitize(dev_priv);
1704 1714
1705 if (IS_BROXTON(dev_priv) ||1715 if (IS_GEN9_LP(dev_priv) ||
1706 !(dev_priv->suspended_to_idle && dev_priv->csr.dmc_payload))1716 !(dev_priv->suspended_to_idle && dev_priv->csr.dmc_payload))
1707 intel_power_domains_init_hw(dev_priv, true);1717 intel_power_domains_init_hw(dev_priv, true);
1708 1718
@@ -1728,25 +1738,9 @@ static int i915_resume_switcheroo(struct drm_device *dev) · 19 unmodified lines
1728 return i915_drm_resume(dev);1738 return i915_drm_resume(dev);
1729}1739}
1730 1740
1731static void disable_engines_irq(struct drm_i915_private *dev_priv)
1732{
1733 struct intel_engine_cs *engine;
1734 enum intel_engine_id id;
1735
1736 /* Ensure irq handler finishes, and not run again. */
1737 disable_irq(dev_priv->drm.irq);
1738 for_each_engine(engine, dev_priv, id)
1739 tasklet_kill(&engine->irq_tasklet);
1740}
1741
1742static void enable_engines_irq(struct drm_i915_private *dev_priv)
1743{
1744 enable_irq(dev_priv->drm.irq);
1745}
1746
1747/**1741/**
1748 * i915_reset - reset chip after a hang1742 * i915_reset - reset chip after a hang
1749 * @dev: drm device to reset1743 * @dev_priv: device private to reset
1750 *1744 *
1751 * Reset the chip. Useful if a hang is detected. Marks the device as wedged1745 * Reset the chip. Useful if a hang is detected. Marks the device as wedged
1752 * on failure.1746 * on failure.
@@ -1776,12 +1770,15 @@ void i915_reset(struct drm_i915_private *dev_priv) · 23 unmodified lines
1776 error->reset_count++;1770 error->reset_count++;
1777 1771
1778 pr_notice("drm/i915: Resetting chip after gpu hang\n");1772 pr_notice("drm/i915: Resetting chip after gpu hang\n");
1779 i915_gem_reset_prepare(dev_priv);1773 disable_irq(dev_priv->drm.irq);
1774 ret = i915_gem_reset_prepare(dev_priv);
1775 if (ret) {
1776 DRM_ERROR("GPU recovery failed\n");
1777 intel_gpu_reset(dev_priv, ALL_ENGINES);
1778 goto error;
1779 }
1780 1780
1781 disable_engines_irq(dev_priv);
1782 ret = intel_gpu_reset(dev_priv, ALL_ENGINES);1781 ret = intel_gpu_reset(dev_priv, ALL_ENGINES);
1783 enable_engines_irq(dev_priv);
1784
1785 if (ret) {1782 if (ret) {
1786 if (ret != -ENODEV)1783 if (ret != -ENODEV)
1787 DRM_ERROR("Failed to reset chip: %i\n", ret);1784 DRM_ERROR("Failed to reset chip: %i\n", ret);
@@ -1816,6 +1813,7 @@ void i915_reset(struct drm_i915_private *dev_priv) · 28 unmodified lines
1816 i915_queue_hangcheck(dev_priv);1813 i915_queue_hangcheck(dev_priv);
1817 1814
1818wakeup:1815wakeup:
1816 enable_irq(dev_priv->drm.irq);
1819 wake_up_bit(&error->flags, I915_RESET_IN_PROGRESS);1817 wake_up_bit(&error->flags, I915_RESET_IN_PROGRESS);
1820 return;1818 return;
1821 1819
@@ -2326,7 +2324,7 @@ static int intel_runtime_suspend(struct device *kdev) · 504 unmodified lines
2326 intel_runtime_pm_disable_interrupts(dev_priv);2324 intel_runtime_pm_disable_interrupts(dev_priv);
2327 2325
2328 ret = 0;2326 ret = 0;
2329 if (IS_BROXTON(dev_priv)) {2327 if (IS_GEN9_LP(dev_priv)) {
2330 bxt_display_core_uninit(dev_priv);2328 bxt_display_core_uninit(dev_priv);
2331 bxt_enable_dc9(dev_priv);2329 bxt_enable_dc9(dev_priv);
2332 } else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {2330 } else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
@@ -2411,7 +2409,7 @@ static int intel_runtime_resume(struct device *kdev) · 78 unmodified lines
2411 if (IS_GEN6(dev_priv))2409 if (IS_GEN6(dev_priv))
2412 intel_init_pch_refclk(dev_priv);2410 intel_init_pch_refclk(dev_priv);
2413 2411
2414 if (IS_BROXTON(dev_priv)) {2412 if (IS_GEN9_LP(dev_priv)) {
2415 bxt_disable_dc9(dev_priv);2413 bxt_disable_dc9(dev_priv);
2416 bxt_display_core_init(dev_priv, true);2414 bxt_display_core_init(dev_priv, true);
2417 if (dev_priv->csr.dmc_payload &&2415 if (dev_priv->csr.dmc_payload &&
@@ -2549,8 +2547,8 @@ static const struct drm_ioctl_desc i915_ioctls[] = { · 131 unmodified lines
2549 DRM_IOCTL_DEF_DRV(I915_GEM_MMAP_GTT, i915_gem_mmap_gtt_ioctl, DRM_RENDER_ALLOW),2547 DRM_IOCTL_DEF_DRV(I915_GEM_MMAP_GTT, i915_gem_mmap_gtt_ioctl, DRM_RENDER_ALLOW),
2550 DRM_IOCTL_DEF_DRV(I915_GEM_SET_DOMAIN, i915_gem_set_domain_ioctl, DRM_RENDER_ALLOW),2548 DRM_IOCTL_DEF_DRV(I915_GEM_SET_DOMAIN, i915_gem_set_domain_ioctl, DRM_RENDER_ALLOW),
2551 DRM_IOCTL_DEF_DRV(I915_GEM_SW_FINISH, i915_gem_sw_finish_ioctl, DRM_RENDER_ALLOW),2549 DRM_IOCTL_DEF_DRV(I915_GEM_SW_FINISH, i915_gem_sw_finish_ioctl, DRM_RENDER_ALLOW),
2552 DRM_IOCTL_DEF_DRV(I915_GEM_SET_TILING, i915_gem_set_tiling, DRM_RENDER_ALLOW),2550 DRM_IOCTL_DEF_DRV(I915_GEM_SET_TILING, i915_gem_set_tiling_ioctl, DRM_RENDER_ALLOW),
2553 DRM_IOCTL_DEF_DRV(I915_GEM_GET_TILING, i915_gem_get_tiling, DRM_RENDER_ALLOW),2551 DRM_IOCTL_DEF_DRV(I915_GEM_GET_TILING, i915_gem_get_tiling_ioctl, DRM_RENDER_ALLOW),
2554 DRM_IOCTL_DEF_DRV(I915_GEM_GET_APERTURE, i915_gem_get_aperture_ioctl, DRM_RENDER_ALLOW),2552 DRM_IOCTL_DEF_DRV(I915_GEM_GET_APERTURE, i915_gem_get_aperture_ioctl, DRM_RENDER_ALLOW),
2555 DRM_IOCTL_DEF_DRV(I915_GET_PIPE_FROM_CRTC_ID, intel_get_pipe_from_crtc_id, 0),2553 DRM_IOCTL_DEF_DRV(I915_GET_PIPE_FROM_CRTC_ID, intel_get_pipe_from_crtc_id, 0),
2556 DRM_IOCTL_DEF_DRV(I915_GEM_MADVISE, i915_gem_madvise_ioctl, DRM_RENDER_ALLOW),2554 DRM_IOCTL_DEF_DRV(I915_GEM_MADVISE, i915_gem_madvise_ioctl, DRM_RENDER_ALLOW),
drivers/gpu/drm/i915/i915_drv.h+26−44
@@ -78,8 +78,8 @@ · 77 unmodified lines
78 78
79#define DRIVER_NAME "i915"79#define DRIVER_NAME "i915"
80#define DRIVER_DESC "Intel Graphics"80#define DRIVER_DESC "Intel Graphics"
81#define DRIVER_DATE "20170109"81#define DRIVER_DATE "20170123"
82#define DRIVER_TIMESTAMP 148395312182#define DRIVER_TIMESTAMP 1485156432
83 83
84#undef WARN_ON84#undef WARN_ON
85/* Many gcc seem to no see through this and fall over :( */85/* Many gcc seem to no see through this and fall over :( */
@@ -1069,6 +1069,8 @@ struct intel_fbc { · 983 unmodified lines
1069 struct work_struct underrun_work;1069 struct work_struct underrun_work;
1070 1070
1071 struct intel_fbc_state_cache {1071 struct intel_fbc_state_cache {
1072 struct i915_vma *vma;
1073
1072 struct {1074 struct {
1073 unsigned int mode_flags;1075 unsigned int mode_flags;
1074 uint32_t hsw_bdw_pixel_rate;1076 uint32_t hsw_bdw_pixel_rate;
@@ -1082,15 +1084,14 @@ struct intel_fbc { · 7 unmodified lines
1082 } plane;1084 } plane;
1083 1085
1084 struct {1086 struct {
1085 u64 ilk_ggtt_offset;
1086 const struct drm_format_info *format;1087 const struct drm_format_info *format;
1087 unsigned int stride;1088 unsigned int stride;
1088 int fence_reg;
1089 unsigned int tiling_mode;
1090 } fb;1089 } fb;
1091 } state_cache;1090 } state_cache;
1092 1091
1093 struct intel_fbc_reg_params {1092 struct intel_fbc_reg_params {
1093 struct i915_vma *vma;
1094
1094 struct {1095 struct {
1095 enum pipe pipe;1096 enum pipe pipe;
1096 enum plane plane;1097 enum plane plane;
@@ -1098,10 +1099,8 @@ struct intel_fbc { · 1 unmodified line
1098 } crtc;1099 } crtc;
1099 1100
1100 struct {1101 struct {
1101 u64 ggtt_offset;
1102 const struct drm_format_info *format;1102 const struct drm_format_info *format;
1103 unsigned int stride;1103 unsigned int stride;
1104 int fence_reg;
1105 } fb;1104 } fb;
1106 1105
1107 int cfb_size;1106 int cfb_size;
@@ -1154,6 +1153,9 @@ struct i915_psr { · 46 unmodified lines
1154 bool psr2_support;1153 bool psr2_support;
1155 bool aux_frame_sync;1154 bool aux_frame_sync;
1156 bool link_standby;1155 bool link_standby;
1156 bool y_cord_support;
1157 bool colorimetry_support;
1158 bool alpm;
1157};1159};
1158 1160
1159enum intel_pch {1161enum intel_pch {
@@ -1809,6 +1811,7 @@ struct intel_pipe_crc { · 649 unmodified lines
1809 enum intel_pipe_crc_source source;1811 enum intel_pipe_crc_source source;
1810 int head, tail;1812 int head, tail;
1811 wait_queue_head_t wq;1813 wait_queue_head_t wq;
1814 int skipped;
1812};1815};
1813 1816
1814struct i915_frontbuffer_tracking {1817struct i915_frontbuffer_tracking {
@@ -2069,6 +2072,7 @@ struct drm_i915_private { · 254 unmodified lines
2069 2072
2070 struct intel_gvt *gvt;2073 struct intel_gvt *gvt;
2071 2074
2075 struct intel_huc huc;
2072 struct intel_guc guc;2076 struct intel_guc guc;
2073 2077
2074 struct intel_csr csr;2078 struct intel_csr csr;
@@ -2843,6 +2847,7 @@ intel_info(const struct drm_i915_private *dev_priv) · 768 unmodified lines
2843#define HAS_GUC(dev_priv) ((dev_priv)->info.has_guc)2847#define HAS_GUC(dev_priv) ((dev_priv)->info.has_guc)
2844#define HAS_GUC_UCODE(dev_priv) (HAS_GUC(dev_priv))2848#define HAS_GUC_UCODE(dev_priv) (HAS_GUC(dev_priv))
2845#define HAS_GUC_SCHED(dev_priv) (HAS_GUC(dev_priv))2849#define HAS_GUC_SCHED(dev_priv) (HAS_GUC(dev_priv))
2850#define HAS_HUC_UCODE(dev_priv) (HAS_GUC(dev_priv))
2846 2851
2847#define HAS_RESOURCE_STREAMER(dev_priv) ((dev_priv)->info.has_resource_streamer)2852#define HAS_RESOURCE_STREAMER(dev_priv) ((dev_priv)->info.has_resource_streamer)
2848 2853
@@ -3101,10 +3106,10 @@ int i915_gem_throttle_ioctl(struct drm_device *dev, void *data, · 252 unmodified lines
3101 struct drm_file *file_priv);3106 struct drm_file *file_priv);
3102int i915_gem_madvise_ioctl(struct drm_device *dev, void *data,3107int i915_gem_madvise_ioctl(struct drm_device *dev, void *data,
3103 struct drm_file *file_priv);3108 struct drm_file *file_priv);
3104int i915_gem_set_tiling(struct drm_device *dev, void *data,3109int i915_gem_set_tiling_ioctl(struct drm_device *dev, void *data,
3105 struct drm_file *file_priv);3110 struct drm_file *file_priv);
3106int i915_gem_get_tiling(struct drm_device *dev, void *data,3111int i915_gem_get_tiling_ioctl(struct drm_device *dev, void *data,
3107 struct drm_file *file_priv);3112 struct drm_file *file_priv);
3108void i915_gem_init_userptr(struct drm_i915_private *dev_priv);3113void i915_gem_init_userptr(struct drm_i915_private *dev_priv);
3109int i915_gem_userptr_ioctl(struct drm_device *dev, void *data,3114int i915_gem_userptr_ioctl(struct drm_device *dev, void *data,
3110 struct drm_file *file);3115 struct drm_file *file);
@@ -3323,7 +3328,7 @@ static inline u32 i915_reset_count(struct i915_gpu_error *error) · 212 unmodified lines
3323 return READ_ONCE(error->reset_count);3328 return READ_ONCE(error->reset_count);
3324}3329}
3325 3330
3326void i915_gem_reset_prepare(struct drm_i915_private *dev_priv);3331int i915_gem_reset_prepare(struct drm_i915_private *dev_priv);
3327void i915_gem_reset_finish(struct drm_i915_private *dev_priv);3332void i915_gem_reset_finish(struct drm_i915_private *dev_priv);
3328void i915_gem_set_wedged(struct drm_i915_private *dev_priv);3333void i915_gem_set_wedged(struct drm_i915_private *dev_priv);
3329void i915_gem_clflush_object(struct drm_i915_gem_object *obj, bool force);3334void i915_gem_clflush_object(struct drm_i915_gem_object *obj, bool force);
@@ -3360,11 +3365,6 @@ int i915_gem_object_attach_phys(struct drm_i915_gem_object *obj, · 30 unmodified lines
3360int i915_gem_open(struct drm_device *dev, struct drm_file *file);3365int i915_gem_open(struct drm_device *dev, struct drm_file *file);
3361void i915_gem_release(struct drm_device *dev, struct drm_file *file);3366void i915_gem_release(struct drm_device *dev, struct drm_file *file);
3362 3367
3363u64 i915_gem_get_ggtt_size(struct drm_i915_private *dev_priv, u64 size,
3364 int tiling_mode);
3365u64 i915_gem_get_ggtt_alignment(struct drm_i915_private *dev_priv, u64 size,
3366 int tiling_mode, bool fenced);
3367
3368int i915_gem_object_set_cache_level(struct drm_i915_gem_object *obj,3368int i915_gem_object_set_cache_level(struct drm_i915_gem_object *obj,
3369 enum i915_cache_level cache_level);3369 enum i915_cache_level cache_level);
3370 3370
@@ -3374,36 +3374,12 @@ struct drm_gem_object *i915_gem_prime_import(struct drm_device *dev, · 3 unmodified lines
3374struct dma_buf *i915_gem_prime_export(struct drm_device *dev,3374struct dma_buf *i915_gem_prime_export(struct drm_device *dev,
3375 struct drm_gem_object *gem_obj, int flags);3375 struct drm_gem_object *gem_obj, int flags);
3376 3376
3377struct i915_vma *
3378i915_gem_obj_to_vma(struct drm_i915_gem_object *obj,
3379 struct i915_address_space *vm,
3380 const struct i915_ggtt_view *view);
3381
3382struct i915_vma *
3383i915_gem_obj_lookup_or_create_vma(struct drm_i915_gem_object *obj,
3384 struct i915_address_space *vm,
3385 const struct i915_ggtt_view *view);
3386
3387static inline struct i915_hw_ppgtt *3377static inline struct i915_hw_ppgtt *
3388i915_vm_to_ppgtt(struct i915_address_space *vm)3378i915_vm_to_ppgtt(struct i915_address_space *vm)
3389{3379{
3390 return container_of(vm, struct i915_hw_ppgtt, base);3380 return container_of(vm, struct i915_hw_ppgtt, base);
3391}3381}
3392 3382
3393static inline struct i915_vma *
3394i915_gem_object_to_ggtt(struct drm_i915_gem_object *obj,
3395 const struct i915_ggtt_view *view)
3396{
3397 return i915_gem_obj_to_vma(obj, &to_i915(obj->base.dev)->ggtt.base, view);
3398}
3399
3400static inline unsigned long
3401i915_gem_object_ggtt_offset(struct drm_i915_gem_object *o,
3402 const struct i915_ggtt_view *view)
3403{
3404 return i915_ggtt_offset(i915_gem_object_to_ggtt(o, view));
3405}
3406
3407/* i915_gem_fence_reg.c */3383/* i915_gem_fence_reg.c */
3408int __must_check i915_vma_get_fence(struct i915_vma *vma);3384int __must_check i915_vma_get_fence(struct i915_vma *vma);
3409int __must_check i915_vma_put_fence(struct i915_vma *vma);3385int __must_check i915_vma_put_fence(struct i915_vma *vma);
@@ -3471,8 +3447,9 @@ int __must_check i915_gem_evict_something(struct i915_address_space *vm, · 61 unmodified lines
3471 unsigned cache_level,3447 unsigned cache_level,
3472 u64 start, u64 end,3448 u64 start, u64 end,
3473 unsigned flags);3449 unsigned flags);
3474int __must_check i915_gem_evict_for_vma(struct i915_vma *vma,3450int __must_check i915_gem_evict_for_node(struct i915_address_space *vm,
3475 unsigned int flags);3451 struct drm_mm_node *node,
3452 unsigned int flags);
3476int i915_gem_evict_vm(struct i915_address_space *vm, bool do_idle);3453int i915_gem_evict_vm(struct i915_address_space *vm, bool do_idle);
3477 3454
3478/* belongs in i915_gem_gtt.h */3455/* belongs in i915_gem_gtt.h */
@@ -3506,7 +3483,7 @@ i915_gem_object_create_stolen_for_preallocated(struct drm_i915_private *dev_priv · 27 unmodified lines
3506/* i915_gem_internal.c */3483/* i915_gem_internal.c */
3507struct drm_i915_gem_object *3484struct drm_i915_gem_object *
3508i915_gem_object_create_internal(struct drm_i915_private *dev_priv,3485i915_gem_object_create_internal(struct drm_i915_private *dev_priv,
3509 unsigned int size);3486 phys_addr_t size);
3510 3487
3511/* i915_gem_shrinker.c */3488/* i915_gem_shrinker.c */
3512unsigned long i915_gem_shrink(struct drm_i915_private *dev_priv,3489unsigned long i915_gem_shrink(struct drm_i915_private *dev_priv,
@@ -3531,6 +3508,11 @@ static inline bool i915_gem_object_needs_bit17_swizzle(struct drm_i915_gem_objec · 18 unmodified lines
3531 i915_gem_object_is_tiled(obj);3508 i915_gem_object_is_tiled(obj);
3532}3509}
3533 3510
3511u32 i915_gem_fence_size(struct drm_i915_private *dev_priv, u32 size,
3512 unsigned int tiling, unsigned int stride);
3513u32 i915_gem_fence_alignment(struct drm_i915_private *dev_priv, u32 size,
3514 unsigned int tiling, unsigned int stride);
3515
3534/* i915_debugfs.c */3516/* i915_debugfs.c */
3535#ifdef CONFIG_DEBUG_FS3517#ifdef CONFIG_DEBUG_FS
3536int i915_debugfs_register(struct drm_i915_private *dev_priv);3518int i915_debugfs_register(struct drm_i915_private *dev_priv);
drivers/gpu/drm/i915/i915_gem.c+170−165
@@ -1696,12 +1696,7 @@ i915_gem_mmap_ioctl(struct drm_device *dev, void *data, · 1695 unmodified lines
1696 1696
1697static unsigned int tile_row_pages(struct drm_i915_gem_object *obj)1697static unsigned int tile_row_pages(struct drm_i915_gem_object *obj)
1698{1698{
1699 u64 size;1699 return i915_gem_object_get_tile_row_size(obj) >> PAGE_SHIFT;
1700
1701 size = i915_gem_object_get_stride(obj);
1702 size *= i915_gem_object_get_tiling(obj) == I915_TILING_Y ? 32 : 8;
1703
1704 return size >> PAGE_SHIFT;
1705}1700}
1706 1701
1707/**1702/**
@@ -1754,6 +1749,29 @@ int i915_gem_mmap_gtt_version(void) · 46 unmodified lines
1754 return 1;1749 return 1;
1755}1750}
1756 1751
1752static inline struct i915_ggtt_view
1753compute_partial_view(struct drm_i915_gem_object *obj,
1754 pgoff_t page_offset,
1755 unsigned int chunk)
1756{
1757 struct i915_ggtt_view view;
1758
1759 if (i915_gem_object_is_tiled(obj))
1760 chunk = roundup(chunk, tile_row_pages(obj));
1761
1762 view.type = I915_GGTT_VIEW_PARTIAL;
1763 view.partial.offset = rounddown(page_offset, chunk);
1764 view.partial.size =
1765 min_t(unsigned int, chunk,
1766 (obj->base.size >> PAGE_SHIFT) - view.partial.offset);
1767
1768 /* If the partial covers the entire object, just create a normal VMA. */
1769 if (chunk >= obj->base.size >> PAGE_SHIFT)
1770 view.type = I915_GGTT_VIEW_NORMAL;
1771
1772 return view;
1773}
1774
1757/**1775/**
1758 * i915_gem_fault - fault a page into the GTT1776 * i915_gem_fault - fault a page into the GTT
1759 * @area: CPU VMA in question1777 * @area: CPU VMA in question
@@ -1830,26 +1848,9 @@ int i915_gem_fault(struct vm_area_struct *area, struct vm_fault *vmf) · 70 unmodified lines
1830 /* Now pin it into the GTT as needed */1848 /* Now pin it into the GTT as needed */
1831 vma = i915_gem_object_ggtt_pin(obj, NULL, 0, 0, flags);1849 vma = i915_gem_object_ggtt_pin(obj, NULL, 0, 0, flags);
1832 if (IS_ERR(vma)) {1850 if (IS_ERR(vma)) {
1833 struct i915_ggtt_view view;
1834 unsigned int chunk_size;
1835
1836 /* Use a partial view if it is bigger than available space */1851 /* Use a partial view if it is bigger than available space */
1837 chunk_size = MIN_CHUNK_PAGES;1852 struct i915_ggtt_view view =
1838 if (i915_gem_object_is_tiled(obj))1853 compute_partial_view(obj, page_offset, MIN_CHUNK_PAGES);
1839 chunk_size = roundup(chunk_size, tile_row_pages(obj));
1840
1841 memset(&view, 0, sizeof(view));
1842 view.type = I915_GGTT_VIEW_PARTIAL;
1843 view.params.partial.offset = rounddown(page_offset, chunk_size);
1844 view.params.partial.size =
1845 min_t(unsigned int, chunk_size,
1846 vma_pages(area) - view.params.partial.offset);
1847
1848 /* If the partial covers the entire object, just create a
1849 * normal VMA.
1850 */
1851 if (chunk_size >= obj->base.size >> PAGE_SHIFT)
1852 view.type = I915_GGTT_VIEW_NORMAL;
1853 1854
1854 /* Userspace is now writing through an untracked VMA, abandon1855 /* Userspace is now writing through an untracked VMA, abandon
1855 * all hope that the hardware is able to track future writes.1856 * all hope that the hardware is able to track future writes.
@@ -1878,7 +1879,7 @@ int i915_gem_fault(struct vm_area_struct *area, struct vm_fault *vmf) · 22 unmodified lines
1878 1879
1879 /* Finally, remap it using the new GTT offset */1880 /* Finally, remap it using the new GTT offset */
1880 ret = remap_io_mapping(area,1881 ret = remap_io_mapping(area,
1881 area->vm_start + (vma->ggtt_view.params.partial.offset << PAGE_SHIFT),1882 area->vm_start + (vma->ggtt_view.partial.offset << PAGE_SHIFT),
1882 (ggtt->mappable_base + vma->node.start) >> PAGE_SHIFT,1883 (ggtt->mappable_base + vma->node.start) >> PAGE_SHIFT,
1883 min_t(u64, vma->size, area->vm_end - area->vm_start),1884 min_t(u64, vma->size, area->vm_end - area->vm_start),
1884 &ggtt->mappable);1885 &ggtt->mappable);
@@ -2021,69 +2022,6 @@ void i915_gem_runtime_suspend(struct drm_i915_private *dev_priv) · 136 unmodified lines
2021 }2022 }
2022}2023}
2023 2024
2024/**
2025 * i915_gem_get_ggtt_size - return required global GTT size for an object
2026 * @dev_priv: i915 device
2027 * @size: object size
2028 * @tiling_mode: tiling mode
2029 *
2030 * Return the required global GTT size for an object, taking into account
2031 * potential fence register mapping.
2032 */
2033u64 i915_gem_get_ggtt_size(struct drm_i915_private *dev_priv,
2034 u64 size, int tiling_mode)
2035{
2036 u64 ggtt_size;
2037
2038 GEM_BUG_ON(size == 0);
2039
2040 if (INTEL_GEN(dev_priv) >= 4 ||
2041 tiling_mode == I915_TILING_NONE)
2042 return size;
2043
2044 /* Previous chips need a power-of-two fence region when tiling */
2045 if (IS_GEN3(dev_priv))
2046 ggtt_size = 1024*1024;
2047 else
2048 ggtt_size = 512*1024;
2049
2050 while (ggtt_size < size)
2051 ggtt_size <<= 1;
2052
2053 return ggtt_size;
2054}
2055
2056/**
2057 * i915_gem_get_ggtt_alignment - return required global GTT alignment
2058 * @dev_priv: i915 device
2059 * @size: object size
2060 * @tiling_mode: tiling mode
2061 * @fenced: is fenced alignment required or not
2062 *
2063 * Return the required global GTT alignment for an object, taking into account
2064 * potential fence register mapping.
2065 */
2066u64 i915_gem_get_ggtt_alignment(struct drm_i915_private *dev_priv, u64 size,
2067 int tiling_mode, bool fenced)
2068{
2069 GEM_BUG_ON(size == 0);
2070
2071 /*
2072 * Minimum alignment is 4k (GTT page size), but might be greater
2073 * if a fence register is needed for the object.
2074 */
2075 if (INTEL_GEN(dev_priv) >= 4 ||
2076 (!fenced && (IS_G33(dev_priv) || IS_PINEVIEW(dev_priv))) ||
2077 tiling_mode == I915_TILING_NONE)
2078 return 4096;
2079
2080 /*
2081 * Previous chips need to be aligned to the size of the smallest
2082 * fence register that can contain the object.
2083 */
2084 return i915_gem_get_ggtt_size(dev_priv, size, tiling_mode);
2085}
2086
2087static int i915_gem_object_create_mmap_offset(struct drm_i915_gem_object *obj)2025static int i915_gem_object_create_mmap_offset(struct drm_i915_gem_object *obj)
2088{2026{
2089 struct drm_i915_private *dev_priv = to_i915(obj->base.dev);2027 struct drm_i915_private *dev_priv = to_i915(obj->base.dev);
@@ -2666,13 +2604,52 @@ i915_gem_find_active_request(struct intel_engine_cs *engine) · 576 unmodified lines
2666 if (__i915_gem_request_completed(request))2604 if (__i915_gem_request_completed(request))
2667 continue;2605 continue;
2668 2606
2607 GEM_BUG_ON(request->engine != engine);
2669 return request;2608 return request;
2670 }2609 }
2671 2610
2672 return NULL;2611 return NULL;
2673}2612}
2674 2613
2675static void reset_request(struct drm_i915_gem_request *request)2614static bool engine_stalled(struct intel_engine_cs *engine)
2615{
2616 if (!engine->hangcheck.stalled)
2617 return false;
2618
2619 /* Check for possible seqno movement after hang declaration */
2620 if (engine->hangcheck.seqno != intel_engine_get_seqno(engine)) {
2621 DRM_DEBUG_DRIVER("%s pardoned\n", engine->name);
2622 return false;
2623 }
2624
2625 return true;
2626}
2627
2628int i915_gem_reset_prepare(struct drm_i915_private *dev_priv)
2629{
2630 struct intel_engine_cs *engine;
2631 enum intel_engine_id id;
2632 int err = 0;
2633
2634 /* Ensure irq handler finishes, and not run again. */
2635 for_each_engine(engine, dev_priv, id) {
2636 struct drm_i915_gem_request *request;
2637
2638 tasklet_kill(&engine->irq_tasklet);
2639
2640 if (engine_stalled(engine)) {
2641 request = i915_gem_find_active_request(engine);
2642 if (request && request->fence.error == -EIO)
2643 err = -EIO; /* Previous reset failed! */
2644 }
2645 }
2646
2647 i915_gem_revoke_fences(dev_priv);
2648
2649 return err;
2650}
2651
2652static void skip_request(struct drm_i915_gem_request *request)
2676{2653{
2677 void *vaddr = request->ring->vaddr;2654 void *vaddr = request->ring->vaddr;
2678 u32 head;2655 u32 head;
@@ -2687,20 +2664,74 @@ static void reset_request(struct drm_i915_gem_request *request) · 8 unmodified lines
2687 head = 0;2664 head = 0;
2688 }2665 }
2689 memset(vaddr + head, 0, request->postfix - head);2666 memset(vaddr + head, 0, request->postfix - head);
2667
2668 dma_fence_set_error(&request->fence, -EIO);
2690}2669}
2691 2670
2692void i915_gem_reset_prepare(struct drm_i915_private *dev_priv)2671static void engine_skip_context(struct drm_i915_gem_request *request)
2693{2672{
2694 i915_gem_revoke_fences(dev_priv);2673 struct intel_engine_cs *engine = request->engine;
2674 struct i915_gem_context *hung_ctx = request->ctx;
2675 struct intel_timeline *timeline;
2676 unsigned long flags;
2677
2678 timeline = i915_gem_context_lookup_timeline(hung_ctx, engine);
2679
2680 spin_lock_irqsave(&engine->timeline->lock, flags);
2681 spin_lock(&timeline->lock);
2682
2683 list_for_each_entry_continue(request, &engine->timeline->requests, link)
2684 if (request->ctx == hung_ctx)
2685 skip_request(request);
2686
2687 list_for_each_entry(request, &timeline->requests, link)
2688 skip_request(request);
2689
2690 spin_unlock(&timeline->lock);
2691 spin_unlock_irqrestore(&engine->timeline->lock, flags);
2692}
2693
2694/* Returns true if the request was guilty of hang */
2695static bool i915_gem_reset_request(struct drm_i915_gem_request *request)
2696{
2697 /* Read once and return the resolution */
2698 const bool guilty = engine_stalled(request->engine);
2699
2700 /* The guilty request will get skipped on a hung engine.
2701 *
2702 * Users of client default contexts do not rely on logical
2703 * state preserved between batches so it is safe to execute
2704 * queued requests following the hang. Non default contexts
2705 * rely on preserved state, so skipping a batch loses the
2706 * evolution of the state and it needs to be considered corrupted.
2707 * Executing more queued batches on top of corrupted state is
2708 * risky. But we take the risk by trying to advance through
2709 * the queued requests in order to make the client behaviour
2710 * more predictable around resets, by not throwing away random
2711 * amount of batches it has prepared for execution. Sophisticated
2712 * clients can use gem_reset_stats_ioctl and dma fence status
2713 * (exported via sync_file info ioctl on explicit fences) to observe
2714 * when it loses the context state and should rebuild accordingly.
2715 *
2716 * The context ban, and ultimately the client ban, mechanism are safety
2717 * valves if client submission ends up resulting in nothing more than
2718 * subsequent hangs.
2719 */
2720
2721 if (guilty) {
2722 i915_gem_context_mark_guilty(request->ctx);
2723 skip_request(request);
2724 } else {
2725 i915_gem_context_mark_innocent(request->ctx);
2726 dma_fence_set_error(&request->fence, -EAGAIN);
2727 }
2728
2729 return guilty;
2695}2730}
2696 2731
2697static void i915_gem_reset_engine(struct intel_engine_cs *engine)2732static void i915_gem_reset_engine(struct intel_engine_cs *engine)
2698{2733{
2699 struct drm_i915_gem_request *request;2734 struct drm_i915_gem_request *request;
2700 struct i915_gem_context *hung_ctx;
2701 struct intel_timeline *timeline;
2702 unsigned long flags;
2703 bool ring_hung;
2704 2735
2705 if (engine->irq_seqno_barrier)2736 if (engine->irq_seqno_barrier)
2706 engine->irq_seqno_barrier(engine);2737 engine->irq_seqno_barrier(engine);
@@ -2709,22 +2740,7 @@ static void i915_gem_reset_engine(struct intel_engine_cs *engine) · 2 unmodified lines
2709 if (!request)2740 if (!request)
2710 return;2741 return;
2711 2742
2712 hung_ctx = request->ctx;2743 if (!i915_gem_reset_request(request))
2713
2714 ring_hung = engine->hangcheck.stalled;
2715 if (engine->hangcheck.seqno != intel_engine_get_seqno(engine)) {
2716 DRM_DEBUG_DRIVER("%s pardoned, was guilty? %s\n",
2717 engine->name,
2718 yesno(ring_hung));
2719 ring_hung = false;
2720 }
2721
2722 if (ring_hung)
2723 i915_gem_context_mark_guilty(hung_ctx);
2724 else
2725 i915_gem_context_mark_innocent(hung_ctx);
2726
2727 if (!ring_hung)
2728 return;2744 return;
2729 2745
2730 DRM_DEBUG_DRIVER("resetting %s to restart from tail of request 0x%x\n",2746 DRM_DEBUG_DRIVER("resetting %s to restart from tail of request 0x%x\n",
@@ -2734,34 +2750,8 @@ static void i915_gem_reset_engine(struct intel_engine_cs *engine) · 3 unmodified lines
2734 engine->reset_hw(engine, request);2750 engine->reset_hw(engine, request);
2735 2751
2736 /* If this context is now banned, skip all of its pending requests. */2752 /* If this context is now banned, skip all of its pending requests. */
2737 if (!i915_gem_context_is_banned(hung_ctx))2753 if (i915_gem_context_is_banned(request->ctx))
2738 return;2754 engine_skip_context(request);
2739
2740 /* Users of the default context do not rely on logical state
2741 * preserved between batches. They have to emit full state on
2742 * every batch and so it is safe to execute queued requests following
2743 * the hang.
2744 *
2745 * Other contexts preserve state, now corrupt. We want to skip all
2746 * queued requests that reference the corrupt context.
2747 */
2748 if (i915_gem_context_is_default(hung_ctx))
2749 return;
2750
2751 timeline = i915_gem_context_lookup_timeline(hung_ctx, engine);
2752
2753 spin_lock_irqsave(&engine->timeline->lock, flags);
2754 spin_lock(&timeline->lock);
2755
2756 list_for_each_entry_continue(request, &engine->timeline->requests, link)
2757 if (request->ctx == hung_ctx)
2758 reset_request(request);
2759
2760 list_for_each_entry(request, &timeline->requests, link)
2761 reset_request(request);
2762
2763 spin_unlock(&timeline->lock);
2764 spin_unlock_irqrestore(&engine->timeline->lock, flags);
2765}2755}
2766 2756
2767void i915_gem_reset_finish(struct drm_i915_private *dev_priv)2757void i915_gem_reset_finish(struct drm_i915_private *dev_priv)
@@ -2788,12 +2778,16 @@ void i915_gem_reset_finish(struct drm_i915_private *dev_priv) · 20 unmodified lines
2788 2778
2789static void nop_submit_request(struct drm_i915_gem_request *request)2779static void nop_submit_request(struct drm_i915_gem_request *request)
2790{2780{
2781 dma_fence_set_error(&request->fence, -EIO);
2791 i915_gem_request_submit(request);2782 i915_gem_request_submit(request);
2792 intel_engine_init_global_seqno(request->engine, request->global_seqno);2783 intel_engine_init_global_seqno(request->engine, request->global_seqno);
2793}2784}
2794 2785
2795static void i915_gem_cleanup_engine(struct intel_engine_cs *engine)2786static void engine_set_wedged(struct intel_engine_cs *engine)
2796{2787{
2788 struct drm_i915_gem_request *request;
2789 unsigned long flags;
2790
2797 /* We need to be sure that no thread is running the old callback as2791 /* We need to be sure that no thread is running the old callback as
2798 * we install the nop handler (otherwise we would submit a request2792 * we install the nop handler (otherwise we would submit a request
2799 * to hardware that will never complete). In order to prevent this2793 * to hardware that will never complete). In order to prevent this
@@ -2802,6 +2796,12 @@ static void i915_gem_cleanup_engine(struct intel_engine_cs *engine) · 2 unmodified lines
2802 */2796 */
2803 engine->submit_request = nop_submit_request;2797 engine->submit_request = nop_submit_request;
2804 2798
2799 /* Mark all executing requests as skipped */
2800 spin_lock_irqsave(&engine->timeline->lock, flags);
2801 list_for_each_entry(request, &engine->timeline->requests, link)
2802 dma_fence_set_error(&request->fence, -EIO);
2803 spin_unlock_irqrestore(&engine->timeline->lock, flags);
2804
2805 /* Mark all pending requests as complete so that any concurrent2805 /* Mark all pending requests as complete so that any concurrent
2806 * (lockless) lookup doesn't try and wait upon the request as we2806 * (lockless) lookup doesn't try and wait upon the request as we
2807 * reset it.2807 * reset it.
@@ -2837,7 +2837,7 @@ static int __i915_gem_set_wedged_BKL(void *data) · 29 unmodified lines
2837 enum intel_engine_id id;2837 enum intel_engine_id id;
2838 2838
2839 for_each_engine(engine, i915, id)2839 for_each_engine(engine, i915, id)
2840 i915_gem_cleanup_engine(engine);2840 engine_set_wedged(engine);
2841 2841
2842 return 0;2842 return 0;
2843}2843}
@@ -3397,7 +3397,7 @@ int i915_gem_set_caching_ioctl(struct drm_device *dev, void *data, · 553 unmodified lines
3397 struct drm_i915_gem_caching *args = data;3397 struct drm_i915_gem_caching *args = data;
3398 struct drm_i915_gem_object *obj;3398 struct drm_i915_gem_object *obj;
3399 enum i915_cache_level level;3399 enum i915_cache_level level;
3400 int ret;3400 int ret = 0;
3401 3401
3402 switch (args->caching) {3402 switch (args->caching) {
3403 case I915_CACHING_NONE:3403 case I915_CACHING_NONE:
@@ -3422,20 +3422,29 @@ int i915_gem_set_caching_ioctl(struct drm_device *dev, void *data, · 18 unmodified lines
3422 return -EINVAL;3422 return -EINVAL;
3423 }3423 }
3424 3424
3425 ret = i915_mutex_lock_interruptible(dev);3425 obj = i915_gem_object_lookup(file, args->handle);
3426 if (!obj)
3427 return -ENOENT;
3428
3429 if (obj->cache_level == level)
3430 goto out;
3431
3432 ret = i915_gem_object_wait(obj,
3433 I915_WAIT_INTERRUPTIBLE,
3434 MAX_SCHEDULE_TIMEOUT,
3435 to_rps_client(file));
3426 if (ret)3436 if (ret)
3427 return ret;3437 goto out;
3428 3438
3429 obj = i915_gem_object_lookup(file, args->handle);3439 ret = i915_mutex_lock_interruptible(dev);
3430 if (!obj) {3440 if (ret)
3431 ret = -ENOENT;3441 goto out;
3432 goto unlock;
3433 }
3434 3442
3435 ret = i915_gem_object_set_cache_level(obj, level);3443 ret = i915_gem_object_set_cache_level(obj, level);
3436 i915_gem_object_put(obj);
3437unlock:
3438 mutex_unlock(&dev->struct_mutex);3444 mutex_unlock(&dev->struct_mutex);
3445
3446out:
3447 i915_gem_object_put(obj);
3439 return ret;3448 return ret;
3440}3449}
3441 3450
@@ -3485,7 +3494,7 @@ i915_gem_object_pin_to_display_plane(struct drm_i915_gem_object *obj, · 43 unmodified lines
3485 * try to preserve the existing ABI).3494 * try to preserve the existing ABI).
3486 */3495 */
3487 vma = ERR_PTR(-ENOSPC);3496 vma = ERR_PTR(-ENOSPC);
3488 if (view->type == I915_GGTT_VIEW_NORMAL)3497 if (!view || view->type == I915_GGTT_VIEW_NORMAL)
3489 vma = i915_gem_object_ggtt_pin(obj, view, 0, alignment,3498 vma = i915_gem_object_ggtt_pin(obj, view, 0, alignment,
3490 PIN_MAPPABLE | PIN_NONBLOCK);3499 PIN_MAPPABLE | PIN_NONBLOCK);
3491 if (IS_ERR(vma)) {3500 if (IS_ERR(vma)) {
@@ -3544,11 +3553,10 @@ i915_gem_object_unpin_from_display_plane(struct i915_vma *vma) · 52 unmodified lines
3544 return;3553 return;
3545 3554
3546 if (--vma->obj->pin_display == 0)3555 if (--vma->obj->pin_display == 0)
3547 vma->display_alignment = 0;3556 vma->display_alignment = I915_GTT_MIN_ALIGNMENT;
3548 3557
3549 /* Bump the LRU to try and avoid premature eviction whilst flipping */3558 /* Bump the LRU to try and avoid premature eviction whilst flipping */
3550 if (!i915_vma_is_active(vma))3559 i915_gem_object_bump_inactive_ggtt(vma->obj);
3551 list_move_tail(&vma->vm_link, &vma->vm->inactive_list);
3552 3560
3553 i915_vma_unpin(vma);3561 i915_vma_unpin(vma);
3554}3562}
@@ -3679,8 +3687,8 @@ i915_gem_object_ggtt_pin(struct drm_i915_gem_object *obj, · 124 unmodified lines
3679 3687
3680 lockdep_assert_held(&obj->base.dev->struct_mutex);3688 lockdep_assert_held(&obj->base.dev->struct_mutex);
3681 3689
3682 vma = i915_gem_obj_lookup_or_create_vma(obj, vm, view);3690 vma = i915_vma_instance(obj, vm, view);
3683 if (IS_ERR(vma))3691 if (unlikely(IS_ERR(vma)))
3684 return vma;3692 return vma;
3685 3693
3686 if (i915_vma_misplaced(vma, size, alignment, flags)) {3694 if (i915_vma_misplaced(vma, size, alignment, flags)) {
@@ -3689,10 +3697,6 @@ i915_gem_object_ggtt_pin(struct drm_i915_gem_object *obj, · 2 unmodified lines
3689 return ERR_PTR(-ENOSPC);3697 return ERR_PTR(-ENOSPC);
3690 3698
3691 if (flags & PIN_MAPPABLE) {3699 if (flags & PIN_MAPPABLE) {
3692 u32 fence_size;
3693
3694 fence_size = i915_gem_get_ggtt_size(dev_priv, vma->size,
3695 i915_gem_object_get_tiling(obj));
3696 /* If the required space is larger than the available3700 /* If the required space is larger than the available
3697 * aperture, we will not able to find a slot for the3701 * aperture, we will not able to find a slot for the
3698 * object and unbinding the object now will be in3702 * object and unbinding the object now will be in
@@ -3700,7 +3704,7 @@ i915_gem_object_ggtt_pin(struct drm_i915_gem_object *obj, · 1 unmodified line
3700 * the object in and out of the Global GTT and3704 * the object in and out of the Global GTT and
3701 * waste a lot of cycles under the mutex.3705 * waste a lot of cycles under the mutex.
3702 */3706 */
3703 if (fence_size > dev_priv->ggtt.mappable_end)3707 if (vma->fence_size > dev_priv->ggtt.mappable_end)
3704 return ERR_PTR(-E2BIG);3708 return ERR_PTR(-E2BIG);
3705 3709
3706 /* If NONBLOCK is set the caller is optimistically3710 /* If NONBLOCK is set the caller is optimistically
@@ -3719,7 +3723,7 @@ i915_gem_object_ggtt_pin(struct drm_i915_gem_object *obj, · 12 unmodified lines
3719 * we could try to minimise harm to others.3723 * we could try to minimise harm to others.
3720 */3724 */
3721 if (flags & PIN_NONBLOCK &&3725 if (flags & PIN_NONBLOCK &&
3722 fence_size > dev_priv->ggtt.mappable_end / 2)3726 vma->fence_size > dev_priv->ggtt.mappable_end / 2)
3723 return ERR_PTR(-ENOSPC);3727 return ERR_PTR(-ENOSPC);
3724 }3728 }
3725 3729
@@ -4193,7 +4197,8 @@ static void assert_kernel_context_is_current(struct drm_i915_private *dev_priv) · 467 unmodified lines
4193 enum intel_engine_id id;4197 enum intel_engine_id id;
4194 4198
4195 for_each_engine(engine, dev_priv, id)4199 for_each_engine(engine, dev_priv, id)
4196 GEM_BUG_ON(!i915_gem_context_is_kernel(engine->last_retired_context));4200 GEM_BUG_ON(engine->last_retired_context &&
4201 !i915_gem_context_is_kernel(engine->last_retired_context));
4197}4202}
4198 4203
4199int i915_gem_suspend(struct drm_i915_private *dev_priv)4204int i915_gem_suspend(struct drm_i915_private *dev_priv)
drivers/gpu/drm/i915/i915_gem_context.c+30−25
@@ -97,7 +97,7 @@ · 96 unmodified lines
97 * part. It should be safe to decrease this, but it's more future proof as is.97 * part. It should be safe to decrease this, but it's more future proof as is.
98 */98 */
99#define GEN6_CONTEXT_ALIGN (64<<10)99#define GEN6_CONTEXT_ALIGN (64<<10)
100#define GEN7_CONTEXT_ALIGN 4096100#define GEN7_CONTEXT_ALIGN I915_GTT_MIN_ALIGNMENT
101 101
102static size_t get_context_alignment(struct drm_i915_private *dev_priv)102static size_t get_context_alignment(struct drm_i915_private *dev_priv)
103{103{
@@ -205,27 +205,6 @@ alloc_context_obj(struct drm_i915_private *dev_priv, u64 size) · 101 unmodified lines
205 return obj;205 return obj;
206}206}
207 207
208static void i915_ppgtt_close(struct i915_address_space *vm)
209{
210 struct list_head *phases[] = {
211 &vm->active_list,
212 &vm->inactive_list,
213 &vm->unbound_list,
214 NULL,
215 }, **phase;
216
217 GEM_BUG_ON(vm->closed);
218 vm->closed = true;
219
220 for (phase = phases; *phase; phase++) {
221 struct i915_vma *vma, *vn;
222
223 list_for_each_entry_safe(vma, vn, *phase, vm_link)
224 if (!i915_vma_is_closed(vma))
225 i915_vma_close(vma);
226 }
227}
228
229static void context_close(struct i915_gem_context *ctx)208static void context_close(struct i915_gem_context *ctx)
230{209{
231 i915_gem_context_set_closed(ctx);210 i915_gem_context_set_closed(ctx);
@@ -290,7 +269,7 @@ __create_hw_context(struct drm_i915_private *dev_priv, · 58 unmodified lines
290 goto err_out;269 goto err_out;
291 }270 }
292 271
293 vma = i915_vma_create(obj, &dev_priv->ggtt.base, NULL);272 vma = i915_vma_instance(obj, &dev_priv->ggtt.base, NULL);
294 if (IS_ERR(vma)) {273 if (IS_ERR(vma)) {
295 i915_gem_object_put(obj);274 i915_gem_object_put(obj);
296 ret = PTR_ERR(vma);275 ret = PTR_ERR(vma);
@@ -341,7 +320,7 @@ __create_hw_context(struct drm_i915_private *dev_priv, · 44 unmodified lines
341 if (HAS_GUC(dev_priv) && i915.enable_guc_loading)320 if (HAS_GUC(dev_priv) && i915.enable_guc_loading)
342 ctx->ggtt_offset_bias = GUC_WOPCM_TOP;321 ctx->ggtt_offset_bias = GUC_WOPCM_TOP;
343 else322 else
344 ctx->ggtt_offset_bias = 4096;323 ctx->ggtt_offset_bias = I915_GTT_PAGE_SIZE;
345 324
346 return ctx;325 return ctx;
347 326
@@ -456,7 +435,8 @@ int i915_gem_context_init(struct drm_i915_private *dev_priv) · 108 unmodified lines
456 dev_priv->hw_context_size = 0;435 dev_priv->hw_context_size = 0;
457 } else if (HAS_HW_CONTEXTS(dev_priv)) {436 } else if (HAS_HW_CONTEXTS(dev_priv)) {
458 dev_priv->hw_context_size =437 dev_priv->hw_context_size =
459 round_up(get_context_size(dev_priv), 4096);438 round_up(get_context_size(dev_priv),
439 I915_GTT_PAGE_SIZE);
460 if (dev_priv->hw_context_size > (1<<20)) {440 if (dev_priv->hw_context_size > (1<<20)) {
461 DRM_DEBUG_DRIVER("Disabling HW Contexts; invalid size %d\n",441 DRM_DEBUG_DRIVER("Disabling HW Contexts; invalid size %d\n",
462 dev_priv->hw_context_size);442 dev_priv->hw_context_size);
@@ -897,6 +877,26 @@ int i915_switch_context(struct drm_i915_gem_request *req) · 434 unmodified lines
897 return do_rcs_switch(req);877 return do_rcs_switch(req);
898}878}
899 879
880static bool engine_has_kernel_context(struct intel_engine_cs *engine)
881{
882 struct i915_gem_timeline *timeline;
883
884 list_for_each_entry(timeline, &engine->i915->gt.timelines, link) {
885 struct intel_timeline *tl;
886
887 if (timeline == &engine->i915->gt.global_timeline)
888 continue;
889
890 tl = &timeline->engine[engine->id];
891 if (i915_gem_active_peek(&tl->last_request,
892 &engine->i915->drm.struct_mutex))
893 return false;
894 }
895
896 return (!engine->last_retired_context ||
897 i915_gem_context_is_kernel(engine->last_retired_context));
898}
899
900int i915_gem_switch_to_kernel_context(struct drm_i915_private *dev_priv)900int i915_gem_switch_to_kernel_context(struct drm_i915_private *dev_priv)
901{901{
902 struct intel_engine_cs *engine;902 struct intel_engine_cs *engine;
@@ -905,10 +905,15 @@ int i915_gem_switch_to_kernel_context(struct drm_i915_private *dev_priv) · 2 unmodified lines
905 905
906 lockdep_assert_held(&dev_priv->drm.struct_mutex);906 lockdep_assert_held(&dev_priv->drm.struct_mutex);
907 907
908 i915_gem_retire_requests(dev_priv);
909
908 for_each_engine(engine, dev_priv, id) {910 for_each_engine(engine, dev_priv, id) {
909 struct drm_i915_gem_request *req;911 struct drm_i915_gem_request *req;
910 int ret;912 int ret;
911 913
914 if (engine_has_kernel_context(engine))
915 continue;
916
912 req = i915_gem_request_alloc(engine, dev_priv->kernel_context);917 req = i915_gem_request_alloc(engine, dev_priv->kernel_context);
913 if (IS_ERR(req))918 if (IS_ERR(req))
914 return PTR_ERR(req);919 return PTR_ERR(req);
drivers/gpu/drm/i915/i915_gem_evict.c+21−18
@@ -231,7 +231,8 @@ found: · 230 unmodified lines
231 231
232/**232/**
233 * i915_gem_evict_for_vma - Evict vmas to make room for binding a new one233 * i915_gem_evict_for_vma - Evict vmas to make room for binding a new one
234 * @target: address space and range to evict for234 * @vm: address space to evict from
235 * @target: range (and color) to evict for
235 * @flags: additional flags to control the eviction algorithm236 * @flags: additional flags to control the eviction algorithm
236 *237 *
237 * This function will try to evict vmas that overlap the target node.238 * This function will try to evict vmas that overlap the target node.
@@ -239,18 +240,20 @@ found: · 1 unmodified line
239 * To clarify: This is for freeing up virtual address space, not for freeing240 * To clarify: This is for freeing up virtual address space, not for freeing
240 * memory in e.g. the shrinker.241 * memory in e.g. the shrinker.
241 */242 */
242int i915_gem_evict_for_vma(struct i915_vma *target, unsigned int flags)243int i915_gem_evict_for_node(struct i915_address_space *vm,
244 struct drm_mm_node *target,
245 unsigned int flags)
243{246{
244 LIST_HEAD(eviction_list);247 LIST_HEAD(eviction_list);
245 struct drm_mm_node *node;248 struct drm_mm_node *node;
246 u64 start = target->node.start;249 u64 start = target->start;
247 u64 end = start + target->node.size;250 u64 end = start + target->size;
248 struct i915_vma *vma, *next;251 struct i915_vma *vma, *next;
249 bool check_color;252 bool check_color;
250 int ret = 0;253 int ret = 0;
251 254
252 lockdep_assert_held(&target->vm->i915->drm.struct_mutex);255 lockdep_assert_held(&vm->i915->drm.struct_mutex);
253 trace_i915_gem_evict_vma(target, flags);256 trace_i915_gem_evict_node(vm, target, flags);
254 257
255 /* Retire before we search the active list. Although we have258 /* Retire before we search the active list. Although we have
256 * reasonable accuracy in our retirement lists, we may have259 * reasonable accuracy in our retirement lists, we may have
@@ -258,18 +261,18 @@ int i915_gem_evict_for_vma(struct i915_vma *target, unsigned int flags) · 1 unmodified line
258 * retiring.261 * retiring.
259 */262 */
260 if (!(flags & PIN_NONBLOCK))263 if (!(flags & PIN_NONBLOCK))
261 i915_gem_retire_requests(target->vm->i915);264 i915_gem_retire_requests(vm->i915);
262 265
263 check_color = target->vm->mm.color_adjust;266 check_color = vm->mm.color_adjust;
264 if (check_color) {267 if (check_color) {
265 /* Expand search to cover neighbouring guard pages (or lack!) */268 /* Expand search to cover neighbouring guard pages (or lack!) */
266 if (start > target->vm->start)269 if (start > vm->start)
267 start -= 4096;270 start -= I915_GTT_PAGE_SIZE;
268 if (end < target->vm->start + target->vm->total)271 if (end < vm->start + vm->total)
269 end += 4096;272 end += I915_GTT_PAGE_SIZE;
270 }273 }
271 274
272 drm_mm_for_each_node_in_range(node, &target->vm->mm, start, end) {275 drm_mm_for_each_node_in_range(node, &vm->mm, start, end) {
273 /* If we find any non-objects (!vma), we cannot evict them */276 /* If we find any non-objects (!vma), we cannot evict them */
274 if (node->color == I915_COLOR_UNEVICTABLE) {277 if (node->color == I915_COLOR_UNEVICTABLE) {
275 ret = -ENOSPC;278 ret = -ENOSPC;
@@ -285,12 +288,12 @@ int i915_gem_evict_for_vma(struct i915_vma *target, unsigned int flags) · 9 unmodified lines
285 * those as well to make room for our guard pages.288 * those as well to make room for our guard pages.
286 */289 */
287 if (check_color) {290 if (check_color) {
288 if (vma->node.start + vma->node.size == target->node.start) {291 if (vma->node.start + vma->node.size == node->start) {
289 if (vma->node.color == target->node.color)292 if (vma->node.color == node->color)
290 continue;293 continue;
291 }294 }
292 if (vma->node.start == target->node.start + target->node.size) {295 if (vma->node.start == node->start + node->size) {
293 if (vma->node.color == target->node.color)296 if (vma->node.color == node->color)
294 continue;297 continue;
295 }298 }
296 }299 }
@@ -302,7 +305,7 @@ int i915_gem_evict_for_vma(struct i915_vma *target, unsigned int flags) · 5 unmodified lines
302 }305 }
303 306
304 /* Overlap of objects in the same batch? */307 /* Overlap of objects in the same batch? */
305 if (i915_vma_is_pinned(vma)) {308 if (i915_vma_is_pinned(vma) || !list_empty(&vma->exec_list)) {
306 ret = -ENOSPC;309 ret = -ENOSPC;
307 if (vma->exec_entry &&310 if (vma->exec_entry &&
308 vma->exec_entry->flags & EXEC_OBJECT_PINNED)311 vma->exec_entry->flags & EXEC_OBJECT_PINNED)
drivers/gpu/drm/i915/i915_gem_execbuffer.c+3−4
@@ -184,7 +184,7 @@ eb_lookup_vmas(struct eb_vmas *eb, · 183 unmodified lines
184 * from the (obj, vm) we don't run the risk of creating184 * from the (obj, vm) we don't run the risk of creating
185 * duplicated vmas for the same vm.185 * duplicated vmas for the same vm.
186 */186 */
187 vma = i915_gem_obj_lookup_or_create_vma(obj, vm, NULL);187 vma = i915_vma_instance(obj, vm, NULL);
188 if (unlikely(IS_ERR(vma))) {188 if (unlikely(IS_ERR(vma))) {
189 DRM_DEBUG("Failed to lookup VMA\n");189 DRM_DEBUG("Failed to lookup VMA\n");
190 ret = PTR_ERR(vma);190 ret = PTR_ERR(vma);
@@ -438,7 +438,7 @@ static void *reloc_iomap(struct drm_i915_gem_object *obj, · 247 unmodified lines
438 memset(&cache->node, 0, sizeof(cache->node));438 memset(&cache->node, 0, sizeof(cache->node));
439 ret = drm_mm_insert_node_in_range_generic439 ret = drm_mm_insert_node_in_range_generic
440 (&ggtt->base.mm, &cache->node,440 (&ggtt->base.mm, &cache->node,
441 4096, 0, I915_COLOR_UNEVICTABLE,441 PAGE_SIZE, 0, I915_COLOR_UNEVICTABLE,
442 0, ggtt->mappable_end,442 0, ggtt->mappable_end,
443 DRM_MM_SEARCH_DEFAULT,443 DRM_MM_SEARCH_DEFAULT,
444 DRM_MM_CREATE_DEFAULT);444 DRM_MM_CREATE_DEFAULT);
@@ -851,8 +851,7 @@ eb_vma_misplaced(struct i915_vma *vma) · 406 unmodified lines
851 WARN_ON(entry->flags & __EXEC_OBJECT_NEEDS_MAP &&851 WARN_ON(entry->flags & __EXEC_OBJECT_NEEDS_MAP &&
852 !i915_vma_is_ggtt(vma));852 !i915_vma_is_ggtt(vma));
853 853
854 if (entry->alignment &&854 if (entry->alignment && !IS_ALIGNED(vma->node.start, entry->alignment))
855 vma->node.start & (entry->alignment - 1))
856 return true;855 return true;
857 856
858 if (vma->node.size < entry->pad_to_size)857 if (vma->node.size < entry->pad_to_size)
drivers/gpu/drm/i915/i915_gem_fence_reg.c+26−38
@@ -77,16 +77,17 @@ static void i965_write_fence_reg(struct drm_i915_fence_reg *fence, · 76 unmodified lines
77 77
78 val = 0;78 val = 0;
79 if (vma) {79 if (vma) {
80 unsigned int tiling = i915_gem_object_get_tiling(vma->obj);
81 bool is_y_tiled = tiling == I915_TILING_Y;
82 unsigned int stride = i915_gem_object_get_stride(vma->obj);80 unsigned int stride = i915_gem_object_get_stride(vma->obj);
83 u32 row_size = stride * (is_y_tiled ? 32 : 8);
84 u32 size = rounddown((u32)vma->node.size, row_size);
85 81
86 val = ((vma->node.start + size - 4096) & 0xfffff000) << 32;82 GEM_BUG_ON(!i915_vma_is_map_and_fenceable(vma));
87 val |= vma->node.start & 0xfffff000;83 GEM_BUG_ON(!IS_ALIGNED(vma->node.start, I965_FENCE_PAGE));
84 GEM_BUG_ON(!IS_ALIGNED(vma->fence_size, I965_FENCE_PAGE));
85 GEM_BUG_ON(!IS_ALIGNED(stride, 128));
86
87 val = (vma->node.start + vma->fence_size - I965_FENCE_PAGE) << 32;
88 val |= vma->node.start;
88 val |= (u64)((stride / 128) - 1) << fence_pitch_shift;89 val |= (u64)((stride / 128) - 1) << fence_pitch_shift;
89 if (is_y_tiled)90 if (i915_gem_object_get_tiling(vma->obj) == I915_TILING_Y)
90 val |= BIT(I965_FENCE_TILING_Y_SHIFT);91 val |= BIT(I965_FENCE_TILING_Y_SHIFT);
91 val |= I965_FENCE_REG_VALID;92 val |= I965_FENCE_REG_VALID;
92 }93 }
@@ -122,31 +123,24 @@ static void i915_write_fence_reg(struct drm_i915_fence_reg *fence, · 29 unmodified lines
122 unsigned int tiling = i915_gem_object_get_tiling(vma->obj);123 unsigned int tiling = i915_gem_object_get_tiling(vma->obj);
123 bool is_y_tiled = tiling == I915_TILING_Y;124 bool is_y_tiled = tiling == I915_TILING_Y;
124 unsigned int stride = i915_gem_object_get_stride(vma->obj);125 unsigned int stride = i915_gem_object_get_stride(vma->obj);
125 int pitch_val;
126 int tile_width;
127 126
128 WARN((vma->node.start & ~I915_FENCE_START_MASK) ||127 GEM_BUG_ON(!i915_vma_is_map_and_fenceable(vma));
129 !is_power_of_2(vma->node.size) ||128 GEM_BUG_ON(vma->node.start & ~I915_FENCE_START_MASK);
130 (vma->node.start & (vma->node.size - 1)),129 GEM_BUG_ON(!is_power_of_2(vma->fence_size));
131 "object 0x%08llx [fenceable? %d] not 1M or pot-size (0x%08llx) aligned\n",130 GEM_BUG_ON(!IS_ALIGNED(vma->node.start, vma->fence_size));
132 vma->node.start,
133 i915_vma_is_map_and_fenceable(vma),
134 vma->node.size);
135 131
136 if (is_y_tiled && HAS_128_BYTE_Y_TILING(fence->i915))132 if (is_y_tiled && HAS_128_BYTE_Y_TILING(fence->i915))
137 tile_width = 128;133 stride /= 128;
138 else134 else
139 tile_width = 512;135 stride /= 512;
140 136 GEM_BUG_ON(!is_power_of_2(stride));
141 /* Note: pitch better be a power of two tile widths */
142 pitch_val = stride / tile_width;
143 pitch_val = ffs(pitch_val) - 1;
144 137
145 val = vma->node.start;138 val = vma->node.start;
146 if (is_y_tiled)139 if (is_y_tiled)
147 val |= BIT(I830_FENCE_TILING_Y_SHIFT);140 val |= BIT(I830_FENCE_TILING_Y_SHIFT);
148 val |= I915_FENCE_SIZE_BITS(vma->node.size);141 val |= I915_FENCE_SIZE_BITS(vma->fence_size);
149 val |= pitch_val << I830_FENCE_PITCH_SHIFT;142 val |= ilog2(stride) << I830_FENCE_PITCH_SHIFT;
143
150 val |= I830_FENCE_REG_VALID;144 val |= I830_FENCE_REG_VALID;
151 }145 }
152 146
@@ -166,25 +160,19 @@ static void i830_write_fence_reg(struct drm_i915_fence_reg *fence, · 13 unmodified lines
166 160
167 val = 0;161 val = 0;
168 if (vma) {162 if (vma) {
169 unsigned int tiling = i915_gem_object_get_tiling(vma->obj);
170 bool is_y_tiled = tiling == I915_TILING_Y;
171 unsigned int stride = i915_gem_object_get_stride(vma->obj);163 unsigned int stride = i915_gem_object_get_stride(vma->obj);
172 u32 pitch_val;
173 164
174 WARN((vma->node.start & ~I830_FENCE_START_MASK) ||165 GEM_BUG_ON(!i915_vma_is_map_and_fenceable(vma));
175 !is_power_of_2(vma->node.size) ||166 GEM_BUG_ON(vma->node.start & ~I830_FENCE_START_MASK);
176 (vma->node.start & (vma->node.size - 1)),167 GEM_BUG_ON(!is_power_of_2(vma->fence_size));
177 "object 0x%08llx not 512K or pot-size 0x%08llx aligned\n",168 GEM_BUG_ON(!is_power_of_2(stride / 128));
178 vma->node.start, vma->node.size);169 GEM_BUG_ON(!IS_ALIGNED(vma->node.start, vma->fence_size));
179
180 pitch_val = stride / 128;
181 pitch_val = ffs(pitch_val) - 1;
182 170
183 val = vma->node.start;171 val = vma->node.start;
184 if (is_y_tiled)172 if (i915_gem_object_get_tiling(vma->obj) == I915_TILING_Y)
185 val |= BIT(I830_FENCE_TILING_Y_SHIFT);173 val |= BIT(I830_FENCE_TILING_Y_SHIFT);
186 val |= I830_FENCE_SIZE_BITS(vma->node.size);174 val |= I830_FENCE_SIZE_BITS(vma->fence_size);
187 val |= pitch_val << I830_FENCE_PITCH_SHIFT;175 val |= ilog2(stride / 128) << I830_FENCE_PITCH_SHIFT;
188 val |= I830_FENCE_REG_VALID;176 val |= I830_FENCE_REG_VALID;
189 }177 }
190 178
drivers/gpu/drm/i915/i915_gem_fence_reg.h+2−0
@@ -30,6 +30,8 @@ · 29 unmodified lines
30struct drm_i915_private;30struct drm_i915_private;
31struct i915_vma;31struct i915_vma;
32 32
33#define I965_FENCE_PAGE 4096UL
34
33struct drm_i915_fence_reg {35struct drm_i915_fence_reg {
34 struct list_head link;36 struct list_head link;
35 struct drm_i915_private *i915;37 struct drm_i915_private *i915;
drivers/gpu/drm/i915/i915_gem_gtt.c+304−134
@@ -23,10 +23,14 @@ · 22 unmodified lines
23 *23 *
24 */24 */
25 25
26#include <linux/log2.h>
27#include <linux/random.h>
26#include <linux/seq_file.h>28#include <linux/seq_file.h>
27#include <linux/stop_machine.h>29#include <linux/stop_machine.h>
30
28#include <drm/drmP.h>31#include <drm/drmP.h>
29#include <drm/i915_drm.h>32#include <drm/i915_drm.h>
33
30#include "i915_drv.h"34#include "i915_drv.h"
31#include "i915_vgpu.h"35#include "i915_vgpu.h"
32#include "i915_trace.h"36#include "i915_trace.h"
@@ -99,12 +103,29 @@ · 66 unmodified lines
99static int103static int
100i915_get_ggtt_vma_pages(struct i915_vma *vma);104i915_get_ggtt_vma_pages(struct i915_vma *vma);
101 105
102const struct i915_ggtt_view i915_ggtt_view_normal = {106static void gen6_ggtt_invalidate(struct drm_i915_private *dev_priv)
103 .type = I915_GGTT_VIEW_NORMAL,107{
104};108 /* Note that as an uncached mmio write, this should flush the
105const struct i915_ggtt_view i915_ggtt_view_rotated = {109 * WCB of the writes into the GGTT before it triggers the invalidate.
106 .type = I915_GGTT_VIEW_ROTATED,110 */
107};111 I915_WRITE(GFX_FLSH_CNTL_GEN6, GFX_FLSH_CNTL_EN);
112}
113
114static void guc_ggtt_invalidate(struct drm_i915_private *dev_priv)
115{
116 gen6_ggtt_invalidate(dev_priv);
117 I915_WRITE(GEN8_GTCR, GEN8_GTCR_INVALIDATE);
118}
119
120static void gmch_ggtt_invalidate(struct drm_i915_private *dev_priv)
121{
122 intel_gtt_chipset_flush();
123}
124
125static inline void i915_ggtt_invalidate(struct drm_i915_private *i915)
126{
127 i915->ggtt.invalidate(i915);
128}
108 129
109int intel_sanitize_enable_ppgtt(struct drm_i915_private *dev_priv,130int intel_sanitize_enable_ppgtt(struct drm_i915_private *dev_priv,
110 int enable_ppgtt)131 int enable_ppgtt)
@@ -329,7 +350,7 @@ static int __setup_page_dma(struct drm_i915_private *dev_priv, · 218 unmodified lines
329 return -ENOMEM;350 return -ENOMEM;
330 351
331 p->daddr = dma_map_page(kdev,352 p->daddr = dma_map_page(kdev,
332 p->page, 0, 4096, PCI_DMA_BIDIRECTIONAL);353 p->page, 0, PAGE_SIZE, PCI_DMA_BIDIRECTIONAL);
333 354
334 if (dma_mapping_error(kdev, p->daddr)) {355 if (dma_mapping_error(kdev, p->daddr)) {
335 __free_page(p->page);356 __free_page(p->page);
@@ -353,7 +374,7 @@ static void cleanup_page_dma(struct drm_i915_private *dev_priv, · 17 unmodified lines
353 if (WARN_ON(!p->page))374 if (WARN_ON(!p->page))
354 return;375 return;
355 376
356 dma_unmap_page(&pdev->dev, p->daddr, 4096, PCI_DMA_BIDIRECTIONAL);377 dma_unmap_page(&pdev->dev, p->daddr, PAGE_SIZE, PCI_DMA_BIDIRECTIONAL);
357 __free_page(p->page);378 __free_page(p->page);
358 memset(p, 0, sizeof(*p));379 memset(p, 0, sizeof(*p));
359}380}
@@ -626,10 +647,10 @@ static void gen8_initialize_pml4(struct i915_address_space *vm, · 266 unmodified lines
626}647}
627 648
628static void649static void
629gen8_setup_page_directory(struct i915_hw_ppgtt *ppgtt,650gen8_setup_pdpe(struct i915_hw_ppgtt *ppgtt,
630 struct i915_page_directory_pointer *pdp,651 struct i915_page_directory_pointer *pdp,
631 struct i915_page_directory *pd,652 struct i915_page_directory *pd,
632 int index)653 int index)
633{654{
634 gen8_ppgtt_pdpe_t *page_directorypo;655 gen8_ppgtt_pdpe_t *page_directorypo;
635 656
@@ -642,10 +663,10 @@ gen8_setup_page_directory(struct i915_hw_ppgtt *ppgtt, · 6 unmodified lines
642}663}
643 664
644static void665static void
645gen8_setup_page_directory_pointer(struct i915_hw_ppgtt *ppgtt,666gen8_setup_pml4e(struct i915_hw_ppgtt *ppgtt,
646 struct i915_pml4 *pml4,667 struct i915_pml4 *pml4,
647 struct i915_page_directory_pointer *pdp,668 struct i915_page_directory_pointer *pdp,
648 int index)669 int index)
649{670{
650 gen8_ppgtt_pml4e_t *pagemap = kmap_px(pml4);671 gen8_ppgtt_pml4e_t *pagemap = kmap_px(pml4);
651 672
@@ -793,9 +814,6 @@ static bool gen8_ppgtt_clear_pdp(struct i915_address_space *vm, · 141 unmodified lines
793 struct i915_hw_ppgtt *ppgtt = i915_vm_to_ppgtt(vm);814 struct i915_hw_ppgtt *ppgtt = i915_vm_to_ppgtt(vm);
794 struct i915_page_directory *pd;815 struct i915_page_directory *pd;
795 uint64_t pdpe;816 uint64_t pdpe;
796 gen8_ppgtt_pdpe_t *pdpe_vaddr;
797 gen8_ppgtt_pdpe_t scratch_pdpe =
798 gen8_pdpe_encode(px_dma(vm->scratch_pd), I915_CACHE_LLC);
799 817
800 gen8_for_each_pdpe(pd, pdp, start, length, pdpe) {818 gen8_for_each_pdpe(pd, pdp, start, length, pdpe) {
801 if (WARN_ON(!pdp->page_directory[pdpe]))819 if (WARN_ON(!pdp->page_directory[pdpe]))
@@ -803,11 +821,7 @@ static bool gen8_ppgtt_clear_pdp(struct i915_address_space *vm, · 1 unmodified line
803 821
804 if (gen8_ppgtt_clear_pd(vm, pd, start, length)) {822 if (gen8_ppgtt_clear_pd(vm, pd, start, length)) {
805 __clear_bit(pdpe, pdp->used_pdpes);823 __clear_bit(pdpe, pdp->used_pdpes);
806 if (USES_FULL_48BIT_PPGTT(dev_priv)) {824 gen8_setup_pdpe(ppgtt, pdp, vm->scratch_pd, pdpe);
807 pdpe_vaddr = kmap_px(pdp);
808 pdpe_vaddr[pdpe] = scratch_pdpe;
809 kunmap_px(ppgtt, pdpe_vaddr);
810 }
811 free_pd(vm->i915, pd);825 free_pd(vm->i915, pd);
812 }826 }
813 }827 }
@@ -832,9 +846,6 @@ static void gen8_ppgtt_clear_pml4(struct i915_address_space *vm, · 18 unmodified lines
832 struct i915_hw_ppgtt *ppgtt = i915_vm_to_ppgtt(vm);846 struct i915_hw_ppgtt *ppgtt = i915_vm_to_ppgtt(vm);
833 struct i915_page_directory_pointer *pdp;847 struct i915_page_directory_pointer *pdp;
834 uint64_t pml4e;848 uint64_t pml4e;
835 gen8_ppgtt_pml4e_t *pml4e_vaddr;
836 gen8_ppgtt_pml4e_t scratch_pml4e =
837 gen8_pml4e_encode(px_dma(vm->scratch_pdp), I915_CACHE_LLC);
838 849
839 GEM_BUG_ON(!USES_FULL_48BIT_PPGTT(vm->i915));850 GEM_BUG_ON(!USES_FULL_48BIT_PPGTT(vm->i915));
840 851
@@ -844,9 +855,7 @@ static void gen8_ppgtt_clear_pml4(struct i915_address_space *vm, · 3 unmodified lines
844 855
845 if (gen8_ppgtt_clear_pdp(vm, pdp, start, length)) {856 if (gen8_ppgtt_clear_pdp(vm, pdp, start, length)) {
846 __clear_bit(pml4e, pml4->used_pml4es);857 __clear_bit(pml4e, pml4->used_pml4es);
847 pml4e_vaddr = kmap_px(pml4);858 gen8_setup_pml4e(ppgtt, pml4, vm->scratch_pdp, pml4e);
848 pml4e_vaddr[pml4e] = scratch_pml4e;
849 kunmap_px(ppgtt, pml4e_vaddr);
850 free_pdp(vm->i915, pdp);859 free_pdp(vm->i915, pdp);
851 }860 }
852 }861 }
@@ -1366,7 +1375,7 @@ static int gen8_alloc_va_range_3lvl(struct i915_address_space *vm, · 513 unmodified lines
1366 1375
1367 kunmap_px(ppgtt, page_directory);1376 kunmap_px(ppgtt, page_directory);
1368 __set_bit(pdpe, pdp->used_pdpes);1377 __set_bit(pdpe, pdp->used_pdpes);
1369 gen8_setup_page_directory(ppgtt, pdp, pd, pdpe);1378 gen8_setup_pdpe(ppgtt, pdp, pd, pdpe);
1370 }1379 }
1371 1380
1372 free_gen8_temp_bitmaps(new_page_dirs, new_page_tables);1381 free_gen8_temp_bitmaps(new_page_dirs, new_page_tables);
@@ -1425,7 +1434,7 @@ static int gen8_alloc_va_range_4lvl(struct i915_address_space *vm, · 52 unmodified lines
1425 if (ret)1434 if (ret)
1426 goto err_out;1435 goto err_out;
1427 1436
1428 gen8_setup_page_directory_pointer(ppgtt, pml4, pdp, pml4e);1437 gen8_setup_pml4e(ppgtt, pml4, pdp, pml4e);
1429 }1438 }
1430 1439
1431 bitmap_or(pml4->used_pml4es, new_pdps, pml4->used_pml4es,1440 bitmap_or(pml4->used_pml4es, new_pdps, pml4->used_pml4es,
@@ -2044,7 +2053,6 @@ static int gen6_ppgtt_allocate_page_directories(struct i915_hw_ppgtt *ppgtt) · 612 unmodified lines
2044 struct i915_address_space *vm = &ppgtt->base;2053 struct i915_address_space *vm = &ppgtt->base;
2045 struct drm_i915_private *dev_priv = ppgtt->base.i915;2054 struct drm_i915_private *dev_priv = ppgtt->base.i915;
2046 struct i915_ggtt *ggtt = &dev_priv->ggtt;2055 struct i915_ggtt *ggtt = &dev_priv->ggtt;
2047 bool retried = false;
2048 int ret;2056 int ret;
2049 2057
2050 /* PPGTT PDEs reside in the GGTT and consists of 512 entries. The2058 /* PPGTT PDEs reside in the GGTT and consists of 512 entries. The
@@ -2057,29 +2065,14 @@ static int gen6_ppgtt_allocate_page_directories(struct i915_hw_ppgtt *ppgtt) · 6 unmodified lines
2057 if (ret)2065 if (ret)
2058 return ret;2066 return ret;
2059 2067
2060alloc:2068 ret = i915_gem_gtt_insert(&ggtt->base, &ppgtt->node,
2061 ret = drm_mm_insert_node_in_range_generic(&ggtt->base.mm, &ppgtt->node,2069 GEN6_PD_SIZE, GEN6_PD_ALIGN,
2062 GEN6_PD_SIZE, GEN6_PD_ALIGN,2070 I915_COLOR_UNEVICTABLE,
2063 I915_COLOR_UNEVICTABLE,2071 0, ggtt->base.total,
2064 0, ggtt->base.total,2072 PIN_HIGH);
2065 DRM_MM_TOPDOWN);
2066 if (ret == -ENOSPC && !retried) {
2067 ret = i915_gem_evict_something(&ggtt->base,
2068 GEN6_PD_SIZE, GEN6_PD_ALIGN,
2069 I915_COLOR_UNEVICTABLE,
2070 0, ggtt->base.total,
2071 0);
2072 if (ret)
2073 goto err_out;
2074
2075 retried = true;
2076 goto alloc;
2077 }
2078
2079 if (ret)2073 if (ret)
2080 goto err_out;2074 goto err_out;
2081 2075
2082
2083 if (ppgtt->node.start < ggtt->mappable_end)2076 if (ppgtt->node.start < ggtt->mappable_end)
2084 DRM_DEBUG("Forced to use aperture for PDEs\n");2077 DRM_DEBUG("Forced to use aperture for PDEs\n");
2085 2078
@@ -2267,6 +2260,27 @@ i915_ppgtt_create(struct drm_i915_private *dev_priv, · 181 unmodified lines
2267 return ppgtt;2260 return ppgtt;
2268}2261}
2269 2262
2263void i915_ppgtt_close(struct i915_address_space *vm)
2264{
2265 struct list_head *phases[] = {
2266 &vm->active_list,
2267 &vm->inactive_list,
2268 &vm->unbound_list,
2269 NULL,
2270 }, **phase;
2271
2272 GEM_BUG_ON(vm->closed);
2273 vm->closed = true;
2274
2275 for (phase = phases; *phase; phase++) {
2276 struct i915_vma *vma, *vn;
2277
2278 list_for_each_entry_safe(vma, vn, *phase, vm_link)
2279 if (!i915_vma_is_closed(vma))
2280 i915_vma_close(vma);
2281 }
2282}
2283
2270void i915_ppgtt_release(struct kref *kref)2284void i915_ppgtt_release(struct kref *kref)
2271{2285{
2272 struct i915_hw_ppgtt *ppgtt =2286 struct i915_hw_ppgtt *ppgtt =
@@ -2331,16 +2345,6 @@ void i915_check_and_clear_faults(struct drm_i915_private *dev_priv) · 58 unmodified lines
2331 POSTING_READ(RING_FAULT_REG(dev_priv->engine[RCS]));2345 POSTING_READ(RING_FAULT_REG(dev_priv->engine[RCS]));
2332}2346}
2333 2347
2334static void i915_ggtt_flush(struct drm_i915_private *dev_priv)
2335{
2336 if (INTEL_INFO(dev_priv)->gen < 6) {
2337 intel_gtt_chipset_flush();
2338 } else {
2339 I915_WRITE(GFX_FLSH_CNTL_GEN6, GFX_FLSH_CNTL_EN);
2340 POSTING_READ(GFX_FLSH_CNTL_GEN6);
2341 }
2342}
2343
2344void i915_gem_suspend_gtt_mappings(struct drm_i915_private *dev_priv)2348void i915_gem_suspend_gtt_mappings(struct drm_i915_private *dev_priv)
2345{2349{
2346 struct i915_ggtt *ggtt = &dev_priv->ggtt;2350 struct i915_ggtt *ggtt = &dev_priv->ggtt;
@@ -2355,7 +2359,7 @@ void i915_gem_suspend_gtt_mappings(struct drm_i915_private *dev_priv) · 8 unmodified lines
2355 2359
2356 ggtt->base.clear_range(&ggtt->base, ggtt->base.start, ggtt->base.total);2360 ggtt->base.clear_range(&ggtt->base, ggtt->base.start, ggtt->base.total);
2357 2361
2358 i915_ggtt_flush(dev_priv);2362 i915_ggtt_invalidate(dev_priv);
2359}2363}
2360 2364
2361int i915_gem_gtt_prepare_pages(struct drm_i915_gem_object *obj,2365int i915_gem_gtt_prepare_pages(struct drm_i915_gem_object *obj,
@@ -2394,15 +2398,13 @@ static void gen8_ggtt_insert_page(struct i915_address_space *vm, · 32 unmodified lines
2394 enum i915_cache_level level,2398 enum i915_cache_level level,
2395 u32 unused)2399 u32 unused)
2396{2400{
2397 struct drm_i915_private *dev_priv = vm->i915;2401 struct i915_ggtt *ggtt = i915_vm_to_ggtt(vm);
2398 gen8_pte_t __iomem *pte =2402 gen8_pte_t __iomem *pte =
2399 (gen8_pte_t __iomem *)dev_priv->ggtt.gsm +2403 (gen8_pte_t __iomem *)ggtt->gsm + (offset >> PAGE_SHIFT);
2400 (offset >> PAGE_SHIFT);
2401 2404
2402 gen8_set_pte(pte, gen8_pte_encode(addr, level));2405 gen8_set_pte(pte, gen8_pte_encode(addr, level));
2403 2406
2404 I915_WRITE(GFX_FLSH_CNTL_GEN6, GFX_FLSH_CNTL_EN);2407 ggtt->invalidate(vm->i915);
2405 POSTING_READ(GFX_FLSH_CNTL_GEN6);
2406}2408}
2407 2409
2408static void gen8_ggtt_insert_entries(struct i915_address_space *vm,2410static void gen8_ggtt_insert_entries(struct i915_address_space *vm,
@@ -2410,7 +2412,6 @@ static void gen8_ggtt_insert_entries(struct i915_address_space *vm, · 1 unmodified line
2410 uint64_t start,2412 uint64_t start,
2411 enum i915_cache_level level, u32 unused)2413 enum i915_cache_level level, u32 unused)
2412{2414{
2413 struct drm_i915_private *dev_priv = vm->i915;
2414 struct i915_ggtt *ggtt = i915_vm_to_ggtt(vm);2415 struct i915_ggtt *ggtt = i915_vm_to_ggtt(vm);
2415 struct sgt_iter sgt_iter;2416 struct sgt_iter sgt_iter;
2416 gen8_pte_t __iomem *gtt_entries;2417 gen8_pte_t __iomem *gtt_entries;
@@ -2439,8 +2440,7 @@ static void gen8_ggtt_insert_entries(struct i915_address_space *vm, · 22 unmodified lines
2439 * want to flush the TLBs only after we're certain all the PTE updates2440 * want to flush the TLBs only after we're certain all the PTE updates
2440 * have finished.2441 * have finished.
2441 */2442 */
2442 I915_WRITE(GFX_FLSH_CNTL_GEN6, GFX_FLSH_CNTL_EN);2443 ggtt->invalidate(vm->i915);
2443 POSTING_READ(GFX_FLSH_CNTL_GEN6);
2444}2444}
2445 2445
2446struct insert_entries {2446struct insert_entries {
@@ -2475,15 +2475,13 @@ static void gen6_ggtt_insert_page(struct i915_address_space *vm, · 28 unmodified lines
2475 enum i915_cache_level level,2475 enum i915_cache_level level,
2476 u32 flags)2476 u32 flags)
2477{2477{
2478 struct drm_i915_private *dev_priv = vm->i915;2478 struct i915_ggtt *ggtt = i915_vm_to_ggtt(vm);
2479 gen6_pte_t __iomem *pte =2479 gen6_pte_t __iomem *pte =
2480 (gen6_pte_t __iomem *)dev_priv->ggtt.gsm +2480 (gen6_pte_t __iomem *)ggtt->gsm + (offset >> PAGE_SHIFT);
2481 (offset >> PAGE_SHIFT);
2482 2481
2483 iowrite32(vm->pte_encode(addr, level, flags), pte);2482 iowrite32(vm->pte_encode(addr, level, flags), pte);
2484 2483
2485 I915_WRITE(GFX_FLSH_CNTL_GEN6, GFX_FLSH_CNTL_EN);2484 ggtt->invalidate(vm->i915);
2486 POSTING_READ(GFX_FLSH_CNTL_GEN6);
2487}2485}
2488 2486
2489/*2487/*
@@ -2497,7 +2495,6 @@ static void gen6_ggtt_insert_entries(struct i915_address_space *vm, · 7 unmodified lines
2497 uint64_t start,2495 uint64_t start,
2498 enum i915_cache_level level, u32 flags)2496 enum i915_cache_level level, u32 flags)
2499{2497{
2500 struct drm_i915_private *dev_priv = vm->i915;
2501 struct i915_ggtt *ggtt = i915_vm_to_ggtt(vm);2498 struct i915_ggtt *ggtt = i915_vm_to_ggtt(vm);
2502 struct sgt_iter sgt_iter;2499 struct sgt_iter sgt_iter;
2503 gen6_pte_t __iomem *gtt_entries;2500 gen6_pte_t __iomem *gtt_entries;
@@ -2525,8 +2522,7 @@ static void gen6_ggtt_insert_entries(struct i915_address_space *vm, · 21 unmodified lines
2525 * want to flush the TLBs only after we're certain all the PTE updates2522 * want to flush the TLBs only after we're certain all the PTE updates
2526 * have finished.2523 * have finished.
2527 */2524 */
2528 I915_WRITE(GFX_FLSH_CNTL_GEN6, GFX_FLSH_CNTL_EN);2525 ggtt->invalidate(vm->i915);
2529 POSTING_READ(GFX_FLSH_CNTL_GEN6);
2530}2526}
2531 2527
2532static void nop_clear_range(struct i915_address_space *vm,2528static void nop_clear_range(struct i915_address_space *vm,
@@ -2723,11 +2719,11 @@ static void i915_gtt_color_adjust(const struct drm_mm_node *node, · 190 unmodified lines
2723 u64 *end)2719 u64 *end)
2724{2720{
2725 if (node->color != color)2721 if (node->color != color)
2726 *start += 4096;2722 *start += I915_GTT_PAGE_SIZE;
2727 2723
2728 node = list_next_entry(node, node_list);2724 node = list_next_entry(node, node_list);
2729 if (node->allocated && node->color != color)2725 if (node->allocated && node->color != color)
2730 *end -= 4096;2726 *end -= I915_GTT_PAGE_SIZE;
2731}2727}
2732 2728
2733int i915_gem_init_ggtt(struct drm_i915_private *dev_priv)2729int i915_gem_init_ggtt(struct drm_i915_private *dev_priv)
@@ -2754,7 +2750,7 @@ int i915_gem_init_ggtt(struct drm_i915_private *dev_priv) · 20 unmodified lines
2754 /* Reserve a mappable slot for our lockless error capture */2750 /* Reserve a mappable slot for our lockless error capture */
2755 ret = drm_mm_insert_node_in_range_generic(&ggtt->base.mm,2751 ret = drm_mm_insert_node_in_range_generic(&ggtt->base.mm,
2756 &ggtt->error_capture,2752 &ggtt->error_capture,
2757 4096, 0,2753 PAGE_SIZE, 0,
2758 I915_COLOR_UNEVICTABLE,2754 I915_COLOR_UNEVICTABLE,
2759 0, ggtt->mappable_end,2755 0, ggtt->mappable_end,
2760 0, 0);2756 0, 0);
@@ -3086,6 +3082,8 @@ static int gen8_gmch_probe(struct i915_ggtt *ggtt) · 325 unmodified lines
3086 if (IS_CHERRYVIEW(dev_priv))3082 if (IS_CHERRYVIEW(dev_priv))
3087 ggtt->base.insert_entries = gen8_ggtt_insert_entries__BKL;3083 ggtt->base.insert_entries = gen8_ggtt_insert_entries__BKL;
3088 3084
3085 ggtt->invalidate = gen6_ggtt_invalidate;
3086
3089 return ggtt_probe_common(ggtt, size);3087 return ggtt_probe_common(ggtt, size);
3090}3088}
3091 3089
@@ -3123,6 +3121,8 @@ static int gen6_gmch_probe(struct i915_ggtt *ggtt) · 31 unmodified lines
3123 ggtt->base.unbind_vma = ggtt_unbind_vma;3121 ggtt->base.unbind_vma = ggtt_unbind_vma;
3124 ggtt->base.cleanup = gen6_gmch_remove;3122 ggtt->base.cleanup = gen6_gmch_remove;
3125 3123
3124 ggtt->invalidate = gen6_ggtt_invalidate;
3125
3126 if (HAS_EDRAM(dev_priv))3126 if (HAS_EDRAM(dev_priv))
3127 ggtt->base.pte_encode = iris_pte_encode;3127 ggtt->base.pte_encode = iris_pte_encode;
3128 else if (IS_HASWELL(dev_priv))3128 else if (IS_HASWELL(dev_priv))
@@ -3166,6 +3166,8 @@ static int i915_gmch_probe(struct i915_ggtt *ggtt) · 37 unmodified lines
3166 ggtt->base.unbind_vma = ggtt_unbind_vma;3166 ggtt->base.unbind_vma = ggtt_unbind_vma;
3167 ggtt->base.cleanup = i915_gmch_remove;3167 ggtt->base.cleanup = i915_gmch_remove;
3168 3168
3169 ggtt->invalidate = gmch_ggtt_invalidate;
3170
3169 if (unlikely(ggtt->do_idle_maps))3171 if (unlikely(ggtt->do_idle_maps))
3170 DRM_INFO("applying Ironlake quirks for intel_iommu\n");3172 DRM_INFO("applying Ironlake quirks for intel_iommu\n");
3171 3173
@@ -3284,6 +3286,16 @@ int i915_ggtt_enable_hw(struct drm_i915_private *dev_priv) · 112 unmodified lines
3284 return 0;3286 return 0;
3285}3287}
3286 3288
3289void i915_ggtt_enable_guc(struct drm_i915_private *i915)
3290{
3291 i915->ggtt.invalidate = guc_ggtt_invalidate;
3292}
3293
3294void i915_ggtt_disable_guc(struct drm_i915_private *i915)
3295{
3296 i915->ggtt.invalidate = gen6_ggtt_invalidate;
3297}
3298
3287void i915_gem_restore_gtt_mappings(struct drm_i915_private *dev_priv)3299void i915_gem_restore_gtt_mappings(struct drm_i915_private *dev_priv)
3288{3300{
3289 struct i915_ggtt *ggtt = &dev_priv->ggtt;3301 struct i915_ggtt *ggtt = &dev_priv->ggtt;
@@ -3347,52 +3359,7 @@ void i915_gem_restore_gtt_mappings(struct drm_i915_private *dev_priv) · 57 unmodified lines
3347 }3359 }
3348 }3360 }
3349 3361
3350 i915_ggtt_flush(dev_priv);3362 i915_ggtt_invalidate(dev_priv);
3351}
3352
3353struct i915_vma *
3354i915_gem_obj_to_vma(struct drm_i915_gem_object *obj,
3355 struct i915_address_space *vm,
3356 const struct i915_ggtt_view *view)
3357{
3358 struct rb_node *rb;
3359
3360 rb = obj->vma_tree.rb_node;
3361 while (rb) {
3362 struct i915_vma *vma = rb_entry(rb, struct i915_vma, obj_node);
3363 long cmp;
3364
3365 cmp = i915_vma_compare(vma, vm, view);
3366 if (cmp == 0)
3367 return vma;
3368
3369 if (cmp < 0)
3370 rb = rb->rb_right;
3371 else
3372 rb = rb->rb_left;
3373 }
3374
3375 return NULL;
3376}
3377
3378struct i915_vma *
3379i915_gem_obj_lookup_or_create_vma(struct drm_i915_gem_object *obj,
3380 struct i915_address_space *vm,
3381 const struct i915_ggtt_view *view)
3382{
3383 struct i915_vma *vma;
3384
3385 lockdep_assert_held(&obj->base.dev->struct_mutex);
3386 GEM_BUG_ON(view && !i915_is_ggtt(vm));
3387
3388 vma = i915_gem_obj_to_vma(obj, vm, view);
3389 if (!vma) {
3390 vma = i915_vma_create(obj, vm, view);
3391 GEM_BUG_ON(vma != i915_gem_obj_to_vma(obj, vm, view));
3392 }
3393
3394 GEM_BUG_ON(i915_vma_is_closed(vma));
3395 return vma;
3396}3363}
3397 3364
3398static struct scatterlist *3365static struct scatterlist *
@@ -3492,7 +3459,7 @@ intel_partial_pages(const struct i915_ggtt_view *view, · 93 unmodified lines
3492{3459{
3493 struct sg_table *st;3460 struct sg_table *st;
3494 struct scatterlist *sg, *iter;3461 struct scatterlist *sg, *iter;
3495 unsigned int count = view->params.partial.size;3462 unsigned int count = view->partial.size;
3496 unsigned int offset;3463 unsigned int offset;
3497 int ret = -ENOMEM;3464 int ret = -ENOMEM;
3498 3465
@@ -3504,9 +3471,7 @@ intel_partial_pages(const struct i915_ggtt_view *view, · 5 unmodified lines
3504 if (ret)3471 if (ret)
3505 goto err_sg_alloc;3472 goto err_sg_alloc;
3506 3473
3507 iter = i915_gem_object_get_sg(obj,3474 iter = i915_gem_object_get_sg(obj, view->partial.offset, &offset);
3508 view->params.partial.offset,
3509 &offset);
3510 GEM_BUG_ON(!iter);3475 GEM_BUG_ON(!iter);
3511 3476
3512 sg = st->sgl;3477 sg = st->sgl;
@@ -3558,7 +3523,8 @@ i915_get_ggtt_vma_pages(struct i915_vma *vma) · 45 unmodified lines
3558 vma->pages = vma->obj->mm.pages;3523 vma->pages = vma->obj->mm.pages;
3559 else if (vma->ggtt_view.type == I915_GGTT_VIEW_ROTATED)3524 else if (vma->ggtt_view.type == I915_GGTT_VIEW_ROTATED)
3560 vma->pages =3525 vma->pages =
3561 intel_rotate_fb_obj_pages(&vma->ggtt_view.params.rotated, vma->obj);3526 intel_rotate_fb_obj_pages(&vma->ggtt_view.rotated,
3527 vma->obj);
3562 else if (vma->ggtt_view.type == I915_GGTT_VIEW_PARTIAL)3528 else if (vma->ggtt_view.type == I915_GGTT_VIEW_PARTIAL)
3563 vma->pages = intel_partial_pages(&vma->ggtt_view, vma->obj);3529 vma->pages = intel_partial_pages(&vma->ggtt_view, vma->obj);
3564 else3530 else
@@ -3579,3 +3545,207 @@ i915_get_ggtt_vma_pages(struct i915_vma *vma) · 14 unmodified lines
3579 return ret;3545 return ret;
3580}3546}
3581 3547
3548/**
3549 * i915_gem_gtt_reserve - reserve a node in an address_space (GTT)
3550 * @vm: the &struct i915_address_space
3551 * @node: the &struct drm_mm_node (typically i915_vma.mode)
3552 * @size: how much space to allocate inside the GTT,
3553 * must be #I915_GTT_PAGE_SIZE aligned
3554 * @offset: where to insert inside the GTT,
3555 * must be #I915_GTT_MIN_ALIGNMENT aligned, and the node
3556 * (@offset + @size) must fit within the address space
3557 * @color: color to apply to node, if this node is not from a VMA,
3558 * color must be #I915_COLOR_UNEVICTABLE
3559 * @flags: control search and eviction behaviour
3560 *
3561 * i915_gem_gtt_reserve() tries to insert the @node at the exact @offset inside
3562 * the address space (using @size and @color). If the @node does not fit, it
3563 * tries to evict any overlapping nodes from the GTT, including any
3564 * neighbouring nodes if the colors do not match (to ensure guard pages between
3565 * differing domains). See i915_gem_evict_for_node() for the gory details
3566 * on the eviction algorithm. #PIN_NONBLOCK may used to prevent waiting on
3567 * evicting active overlapping objects, and any overlapping node that is pinned
3568 * or marked as unevictable will also result in failure.
3569 *
3570 * Returns: 0 on success, -ENOSPC if no suitable hole is found, -EINTR if
3571 * asked to wait for eviction and interrupted.
3572 */
3573int i915_gem_gtt_reserve(struct i915_address_space *vm,
3574 struct drm_mm_node *node,
3575 u64 size, u64 offset, unsigned long color,
3576 unsigned int flags)
3577{
3578 int err;
3579
3580 GEM_BUG_ON(!size);
3581 GEM_BUG_ON(!IS_ALIGNED(size, I915_GTT_PAGE_SIZE));
3582 GEM_BUG_ON(!IS_ALIGNED(offset, I915_GTT_MIN_ALIGNMENT));
3583 GEM_BUG_ON(range_overflows(offset, size, vm->total));
3584 GEM_BUG_ON(vm == &vm->i915->mm.aliasing_ppgtt->base);
3585 GEM_BUG_ON(drm_mm_node_allocated(node));
3586
3587 node->size = size;
3588 node->start = offset;
3589 node->color = color;
3590
3591 err = drm_mm_reserve_node(&vm->mm, node);
3592 if (err != -ENOSPC)
3593 return err;
3594
3595 err = i915_gem_evict_for_node(vm, node, flags);
3596 if (err == 0)
3597 err = drm_mm_reserve_node(&vm->mm, node);
3598
3599 return err;
3600}
3601
3602static u64 random_offset(u64 start, u64 end, u64 len, u64 align)
3603{
3604 u64 range, addr;
3605
3606 GEM_BUG_ON(range_overflows(start, len, end));
3607 GEM_BUG_ON(round_up(start, align) > round_down(end - len, align));
3608
3609 range = round_down(end - len, align) - round_up(start, align);
3610 if (range) {
3611 if (sizeof(unsigned long) == sizeof(u64)) {
3612 addr = get_random_long();
3613 } else {
3614 addr = get_random_int();
3615 if (range > U32_MAX) {
3616 addr <<= 32;
3617 addr |= get_random_int();
3618 }
3619 }
3620 div64_u64_rem(addr, range, &addr);
3621 start += addr;
3622 }
3623
3624 return round_up(start, align);
3625}
3626
3627/**
3628 * i915_gem_gtt_insert - insert a node into an address_space (GTT)
3629 * @vm: the &struct i915_address_space
3630 * @node: the &struct drm_mm_node (typically i915_vma.node)
3631 * @size: how much space to allocate inside the GTT,
3632 * must be #I915_GTT_PAGE_SIZE aligned
3633 * @alignment: required alignment of starting offset, may be 0 but
3634 * if specified, this must be a power-of-two and at least
3635 * #I915_GTT_MIN_ALIGNMENT
3636 * @color: color to apply to node
3637 * @start: start of any range restriction inside GTT (0 for all),
3638 * must be #I915_GTT_PAGE_SIZE aligned
3639 * @end: end of any range restriction inside GTT (U64_MAX for all),
3640 * must be #I915_GTT_PAGE_SIZE aligned if not U64_MAX
3641 * @flags: control search and eviction behaviour
3642 *
3643 * i915_gem_gtt_insert() first searches for an available hole into which
3644 * is can insert the node. The hole address is aligned to @alignment and
3645 * its @size must then fit entirely within the [@start, @end] bounds. The
3646 * nodes on either side of the hole must match @color, or else a guard page
3647 * will be inserted between the two nodes (or the node evicted). If no
3648 * suitable hole is found, first a victim is randomly selected and tested
3649 * for eviction, otherwise then the LRU list of objects within the GTT
3650 * is scanned to find the first set of replacement nodes to create the hole.
3651 * Those old overlapping nodes are evicted from the GTT (and so must be
3652 * rebound before any future use). Any node that is currently pinned cannot
3653 * be evicted (see i915_vma_pin()). Similar if the node's VMA is currently
3654 * active and #PIN_NONBLOCK is specified, that node is also skipped when
3655 * searching for an eviction candidate. See i915_gem_evict_something() for
3656 * the gory details on the eviction algorithm.
3657 *
3658 * Returns: 0 on success, -ENOSPC if no suitable hole is found, -EINTR if
3659 * asked to wait for eviction and interrupted.
3660 */
3661int i915_gem_gtt_insert(struct i915_address_space *vm,
3662 struct drm_mm_node *node,
3663 u64 size, u64 alignment, unsigned long color,
3664 u64 start, u64 end, unsigned int flags)
3665{
3666 u32 search_flag, alloc_flag;
3667 u64 offset;
3668 int err;
3669
3670 lockdep_assert_held(&vm->i915->drm.struct_mutex);
3671 GEM_BUG_ON(!size);
3672 GEM_BUG_ON(!IS_ALIGNED(size, I915_GTT_PAGE_SIZE));
3673 GEM_BUG_ON(alignment && !is_power_of_2(alignment));
3674 GEM_BUG_ON(alignment && !IS_ALIGNED(alignment, I915_GTT_MIN_ALIGNMENT));
3675 GEM_BUG_ON(start >= end);
3676 GEM_BUG_ON(start > 0 && !IS_ALIGNED(start, I915_GTT_PAGE_SIZE));
3677 GEM_BUG_ON(end < U64_MAX && !IS_ALIGNED(end, I915_GTT_PAGE_SIZE));
3678 GEM_BUG_ON(vm == &vm->i915->mm.aliasing_ppgtt->base);
3679 GEM_BUG_ON(drm_mm_node_allocated(node));
3680
3681 if (unlikely(range_overflows(start, size, end)))
3682 return -ENOSPC;
3683
3684 if (unlikely(round_up(start, alignment) > round_down(end - size, alignment)))
3685 return -ENOSPC;
3686
3687 if (flags & PIN_HIGH) {
3688 search_flag = DRM_MM_SEARCH_BELOW;
3689 alloc_flag = DRM_MM_CREATE_TOP;
3690 } else {
3691 search_flag = DRM_MM_SEARCH_DEFAULT;
3692 alloc_flag = DRM_MM_CREATE_DEFAULT;
3693 }
3694
3695 /* We only allocate in PAGE_SIZE/GTT_PAGE_SIZE (4096) chunks,
3696 * so we know that we always have a minimum alignment of 4096.
3697 * The drm_mm range manager is optimised to return results
3698 * with zero alignment, so where possible use the optimal
3699 * path.
3700 */
3701 BUILD_BUG_ON(I915_GTT_MIN_ALIGNMENT > I915_GTT_PAGE_SIZE);
3702 if (alignment <= I915_GTT_MIN_ALIGNMENT)
3703 alignment = 0;
3704
3705 err = drm_mm_insert_node_in_range_generic(&vm->mm, node,
3706 size, alignment, color,
3707 start, end,
3708 search_flag, alloc_flag);
3709 if (err != -ENOSPC)
3710 return err;
3711
3712 /* No free space, pick a slot at random.
3713 *
3714 * There is a pathological case here using a GTT shared between
3715 * mmap and GPU (i.e. ggtt/aliasing_ppgtt but not full-ppgtt):
3716 *
3717 * |<-- 256 MiB aperture -->||<-- 1792 MiB unmappable -->|
3718 * (64k objects) (448k objects)
3719 *
3720 * Now imagine that the eviction LRU is ordered top-down (just because
3721 * pathology meets real life), and that we need to evict an object to
3722 * make room inside the aperture. The eviction scan then has to walk
3723 * the 448k list before it finds one within range. And now imagine that
3724 * it has to search for a new hole between every byte inside the memcpy,
3725 * for several simultaneous clients.
3726 *
3727 * On a full-ppgtt system, if we have run out of available space, there
3728 * will be lots and lots of objects in the eviction list! Again,
3729 * searching that LRU list may be slow if we are also applying any
3730 * range restrictions (e.g. restriction to low 4GiB) and so, for
3731 * simplicity and similarilty between different GTT, try the single
3732 * random replacement first.
3733 */
3734 offset = random_offset(start, end,
3735 size, alignment ?: I915_GTT_MIN_ALIGNMENT);
3736 err = i915_gem_gtt_reserve(vm, node, size, offset, color, flags);
3737 if (err != -ENOSPC)
3738 return err;
3739
3740 /* Randomly selected placement is pinned, do a search */
3741 err = i915_gem_evict_something(vm, size, alignment, color,
3742 start, end, flags);
3743 if (err)
3744 return err;
3745
3746 search_flag = DRM_MM_SEARCH_DEFAULT;
3747 return drm_mm_insert_node_in_range_generic(&vm->mm, node,
3748 size, alignment, color,
3749 start, end,
3750 search_flag, alloc_flag);
3751}
drivers/gpu/drm/i915/i915_gem_gtt.h+57−17
@@ -40,6 +40,9 @@ · 39 unmodified lines
40#include "i915_gem_timeline.h"40#include "i915_gem_timeline.h"
41#include "i915_gem_request.h"41#include "i915_gem_request.h"
42 42
43#define I915_GTT_PAGE_SIZE 4096UL
44#define I915_GTT_MIN_ALIGNMENT I915_GTT_PAGE_SIZE
45
43#define I915_FENCE_REG_NONE -146#define I915_FENCE_REG_NONE -1
44#define I915_MAX_NUM_FENCES 3247#define I915_MAX_NUM_FENCES 32
45/* 32 fences + sign bit for FENCE_REG_NONE */48/* 32 fences + sign bit for FENCE_REG_NONE */
@@ -142,34 +145,57 @@ typedef uint64_t gen8_ppgtt_pml4e_t; · 96 unmodified lines
142 145
143struct sg_table;146struct sg_table;
144 147
145enum i915_ggtt_view_type {
146 I915_GGTT_VIEW_NORMAL = 0,
147 I915_GGTT_VIEW_ROTATED,
148 I915_GGTT_VIEW_PARTIAL,
149};
150
151struct intel_rotation_info {148struct intel_rotation_info {
152 struct {149 struct intel_rotation_plane_info {
153 /* tiles */150 /* tiles */
154 unsigned int width, height, stride, offset;151 unsigned int width, height, stride, offset;
155 } plane[2];152 } plane[2];
153} __packed;
154
155static inline void assert_intel_rotation_info_is_packed(void)
156{
157 BUILD_BUG_ON(sizeof(struct intel_rotation_info) != 8*sizeof(unsigned int));
158}
159
160struct intel_partial_info {
161 u64 offset;
162 unsigned int size;
163} __packed;
164
165static inline void assert_intel_partial_info_is_packed(void)
166{
167 BUILD_BUG_ON(sizeof(struct intel_partial_info) != sizeof(u64) + sizeof(unsigned int));
168}
169
170enum i915_ggtt_view_type {
171 I915_GGTT_VIEW_NORMAL = 0,
172 I915_GGTT_VIEW_ROTATED = sizeof(struct intel_rotation_info),
173 I915_GGTT_VIEW_PARTIAL = sizeof(struct intel_partial_info),
156};174};
157 175
176static inline void assert_i915_ggtt_view_type_is_unique(void)
177{
178 /* As we encode the size of each branch inside the union into its type,
179 * we have to be careful that each branch has a unique size.
180 */
181 switch ((enum i915_ggtt_view_type)0) {
182 case I915_GGTT_VIEW_NORMAL:
183 case I915_GGTT_VIEW_PARTIAL:
184 case I915_GGTT_VIEW_ROTATED:
185 /* gcc complains if these are identical cases */
186 break;
187 }
188}
189
158struct i915_ggtt_view {190struct i915_ggtt_view {
159 enum i915_ggtt_view_type type;191 enum i915_ggtt_view_type type;
160
161 union {192 union {
162 struct {193 /* Members need to contain no holes/padding */
163 u64 offset;194 struct intel_partial_info partial;
164 unsigned int size;
165 } partial;
166 struct intel_rotation_info rotated;195 struct intel_rotation_info rotated;
167 } params;196 };
168};197};
169 198
170extern const struct i915_ggtt_view i915_ggtt_view_normal;
171extern const struct i915_ggtt_view i915_ggtt_view_rotated;
172
173enum i915_cache_level;199enum i915_cache_level;
174 200
175struct i915_vma;201struct i915_vma;
@@ -333,6 +359,7 @@ struct i915_ggtt { · 157 unmodified lines
333 359
334 /** "Graphics Stolen Memory" holds the global PTEs */360 /** "Graphics Stolen Memory" holds the global PTEs */
335 void __iomem *gsm;361 void __iomem *gsm;
362 void (*invalidate)(struct drm_i915_private *dev_priv);
336 363
337 bool do_idle_maps;364 bool do_idle_maps;
338 365
@@ -501,6 +528,8 @@ i915_vm_to_ggtt(struct i915_address_space *vm) · 162 unmodified lines
501int i915_ggtt_probe_hw(struct drm_i915_private *dev_priv);528int i915_ggtt_probe_hw(struct drm_i915_private *dev_priv);
502int i915_ggtt_init_hw(struct drm_i915_private *dev_priv);529int i915_ggtt_init_hw(struct drm_i915_private *dev_priv);
503int i915_ggtt_enable_hw(struct drm_i915_private *dev_priv);530int i915_ggtt_enable_hw(struct drm_i915_private *dev_priv);
531void i915_ggtt_enable_guc(struct drm_i915_private *i915);
532void i915_ggtt_disable_guc(struct drm_i915_private *i915);
504int i915_gem_init_ggtt(struct drm_i915_private *dev_priv);533int i915_gem_init_ggtt(struct drm_i915_private *dev_priv);
505void i915_ggtt_cleanup_hw(struct drm_i915_private *dev_priv);534void i915_ggtt_cleanup_hw(struct drm_i915_private *dev_priv);
506 535
@@ -509,6 +538,7 @@ void i915_ppgtt_release(struct kref *kref); · 2 unmodified lines
509struct i915_hw_ppgtt *i915_ppgtt_create(struct drm_i915_private *dev_priv,538struct i915_hw_ppgtt *i915_ppgtt_create(struct drm_i915_private *dev_priv,
510 struct drm_i915_file_private *fpriv,539 struct drm_i915_file_private *fpriv,
511 const char *name);540 const char *name);
541void i915_ppgtt_close(struct i915_address_space *vm);
512static inline void i915_ppgtt_get(struct i915_hw_ppgtt *ppgtt)542static inline void i915_ppgtt_get(struct i915_hw_ppgtt *ppgtt)
513{543{
514 if (ppgtt)544 if (ppgtt)
@@ -529,6 +559,16 @@ int __must_check i915_gem_gtt_prepare_pages(struct drm_i915_gem_object *obj, · 14 unmodified lines
529void i915_gem_gtt_finish_pages(struct drm_i915_gem_object *obj,559void i915_gem_gtt_finish_pages(struct drm_i915_gem_object *obj,
530 struct sg_table *pages);560 struct sg_table *pages);
531 561
562int i915_gem_gtt_reserve(struct i915_address_space *vm,
563 struct drm_mm_node *node,
564 u64 size, u64 offset, unsigned long color,
565 unsigned int flags);
566
567int i915_gem_gtt_insert(struct i915_address_space *vm,
568 struct drm_mm_node *node,
569 u64 size, u64 alignment, unsigned long color,
570 u64 start, u64 end, unsigned int flags);
571
532/* Flags used by pin/bind&friends. */572/* Flags used by pin/bind&friends. */
533#define PIN_NONBLOCK BIT(0)573#define PIN_NONBLOCK BIT(0)
534#define PIN_MAPPABLE BIT(1)574#define PIN_MAPPABLE BIT(1)
@@ -543,6 +583,6 @@ void i915_gem_gtt_finish_pages(struct drm_i915_gem_object *obj, · 8 unmodified lines
543#define PIN_HIGH BIT(9)583#define PIN_HIGH BIT(9)
544#define PIN_OFFSET_BIAS BIT(10)584#define PIN_OFFSET_BIAS BIT(10)
545#define PIN_OFFSET_FIXED BIT(11)585#define PIN_OFFSET_FIXED BIT(11)
546#define PIN_OFFSET_MASK (~4095)586#define PIN_OFFSET_MASK (-I915_GTT_PAGE_SIZE)
547 587
548#endif588#endif
drivers/gpu/drm/i915/i915_gem_internal.c+7−1
@@ -151,10 +151,16 @@ static const struct drm_i915_gem_object_ops i915_gem_object_internal_ops = { · 150 unmodified lines
151 */151 */
152struct drm_i915_gem_object *152struct drm_i915_gem_object *
153i915_gem_object_create_internal(struct drm_i915_private *i915,153i915_gem_object_create_internal(struct drm_i915_private *i915,
154 unsigned int size)154 phys_addr_t size)
155{155{
156 struct drm_i915_gem_object *obj;156 struct drm_i915_gem_object *obj;
157 157
158 GEM_BUG_ON(!size);
159 GEM_BUG_ON(!IS_ALIGNED(size, PAGE_SIZE));
160
161 if (overflows_type(size, obj->base.size))
162 return ERR_PTR(-E2BIG);
163
158 obj = i915_gem_object_alloc(i915);164 obj = i915_gem_object_alloc(i915);
159 if (!obj)165 if (!obj)
160 return ERR_PTR(-ENOMEM);166 return ERR_PTR(-ENOMEM);
drivers/gpu/drm/i915/i915_gem_object.h+23−0
@@ -317,6 +317,29 @@ i915_gem_object_get_stride(struct drm_i915_gem_object *obj) · 316 unmodified lines
317 return obj->tiling_and_stride & STRIDE_MASK;317 return obj->tiling_and_stride & STRIDE_MASK;
318}318}
319 319
320static inline unsigned int
321i915_gem_tile_height(unsigned int tiling)
322{
323 GEM_BUG_ON(!tiling);
324 return tiling == I915_TILING_Y ? 32 : 8;
325}
326
327static inline unsigned int
328i915_gem_object_get_tile_height(struct drm_i915_gem_object *obj)
329{
330 return i915_gem_tile_height(i915_gem_object_get_tiling(obj));
331}
332
333static inline unsigned int
334i915_gem_object_get_tile_row_size(struct drm_i915_gem_object *obj)
335{
336 return (i915_gem_object_get_stride(obj) *
337 i915_gem_object_get_tile_height(obj));
338}
339
340int i915_gem_object_set_tiling(struct drm_i915_gem_object *obj,
341 unsigned int tiling, unsigned int stride);
342
320static inline struct intel_engine_cs *343static inline struct intel_engine_cs *
321i915_gem_object_last_write_engine(struct drm_i915_gem_object *obj)344i915_gem_object_last_write_engine(struct drm_i915_gem_object *obj)
322{345{
drivers/gpu/drm/i915/i915_gem_render_state.c+3−3
@@ -187,20 +187,20 @@ int i915_gem_render_state_init(struct intel_engine_cs *engine) · 186 unmodified lines
187 if (!rodata)187 if (!rodata)
188 return 0;188 return 0;
189 189
190 if (rodata->batch_items * 4 > 4096)190 if (rodata->batch_items * 4 > PAGE_SIZE)
191 return -EINVAL;191 return -EINVAL;
192 192
193 so = kmalloc(sizeof(*so), GFP_KERNEL);193 so = kmalloc(sizeof(*so), GFP_KERNEL);
194 if (!so)194 if (!so)
195 return -ENOMEM;195 return -ENOMEM;
196 196
197 obj = i915_gem_object_create_internal(engine->i915, 4096);197 obj = i915_gem_object_create_internal(engine->i915, PAGE_SIZE);
198 if (IS_ERR(obj)) {198 if (IS_ERR(obj)) {
199 ret = PTR_ERR(obj);199 ret = PTR_ERR(obj);
200 goto err_free;200 goto err_free;
201 }201 }
202 202
203 so->vma = i915_vma_create(obj, &engine->i915->ggtt.base, NULL);203 so->vma = i915_vma_instance(obj, &engine->i915->ggtt.base, NULL);
204 if (IS_ERR(so->vma)) {204 if (IS_ERR(so->vma)) {
205 ret = PTR_ERR(so->vma);205 ret = PTR_ERR(so->vma);
206 goto err_obj;206 goto err_obj;
drivers/gpu/drm/i915/i915_gem_request.c+10−25
@@ -307,26 +307,6 @@ void i915_gem_request_retire_upto(struct drm_i915_gem_request *req) · 306 unmodified lines
307 } while (tmp != req);307 } while (tmp != req);
308}308}
309 309
310static int i915_gem_check_wedge(struct drm_i915_private *dev_priv)
311{
312 struct i915_gpu_error *error = &dev_priv->gpu_error;
313
314 if (i915_terminally_wedged(error))
315 return -EIO;
316
317 if (i915_reset_in_progress(error)) {
318 /* Non-interruptible callers can't handle -EAGAIN, hence return
319 * -EIO unconditionally for these.
320 */
321 if (!dev_priv->mm.interruptible)
322 return -EIO;
323
324 return -EAGAIN;
325 }
326
327 return 0;
328}
329
330static int i915_gem_init_global_seqno(struct drm_i915_private *i915, u32 seqno)310static int i915_gem_init_global_seqno(struct drm_i915_private *i915, u32 seqno)
331{311{
332 struct i915_gem_timeline *timeline = &i915->gt.global_timeline;312 struct i915_gem_timeline *timeline = &i915->gt.global_timeline;
@@ -521,12 +501,10 @@ i915_gem_request_alloc(struct intel_engine_cs *engine, · 188 unmodified lines
521 lockdep_assert_held(&dev_priv->drm.struct_mutex);501 lockdep_assert_held(&dev_priv->drm.struct_mutex);
522 502
523 /* ABI: Before userspace accesses the GPU (e.g. execbuffer), report503 /* ABI: Before userspace accesses the GPU (e.g. execbuffer), report
524 * EIO if the GPU is already wedged, or EAGAIN to drop the struct_mutex504 * EIO if the GPU is already wedged.
525 * and restart.
526 */505 */
527 ret = i915_gem_check_wedge(dev_priv);506 if (i915_terminally_wedged(&dev_priv->gpu_error))
528 if (ret)507 return ERR_PTR(-EIO);
529 return ERR_PTR(ret);
530 508
531 /* Pinning the contexts may generate requests in order to acquire509 /* Pinning the contexts may generate requests in order to acquire
532 * GGTT space, so do this first before we reserve a seqno for510 * GGTT space, so do this first before we reserve a seqno for
@@ -851,6 +829,13 @@ void __i915_add_request(struct drm_i915_gem_request *request, bool flush_caches) · 318 unmodified lines
851 lockdep_assert_held(&request->i915->drm.struct_mutex);829 lockdep_assert_held(&request->i915->drm.struct_mutex);
852 trace_i915_gem_request_add(request);830 trace_i915_gem_request_add(request);
853 831
832 /* Make sure that no request gazumped us - if it was allocated after
833 * our i915_gem_request_alloc() and called __i915_add_request() before
834 * us, the timeline will hold its seqno which is later than ours.
835 */
836 GEM_BUG_ON(i915_seqno_passed(timeline->last_submitted_seqno,
837 request->fence.seqno));
838
854 /*839 /*
855 * To ensure that this call will not fail, space for its emissions840 * To ensure that this call will not fail, space for its emissions
856 * should already have been reserved in the ring buffer. Let the ring841 * should already have been reserved in the ring buffer. Let the ring
drivers/gpu/drm/i915/i915_gem_stolen.c+9−7
@@ -647,8 +647,9 @@ i915_gem_object_create_stolen_for_preallocated(struct drm_i915_private *dev_priv · 646 unmodified lines
647 stolen_offset, gtt_offset, size);647 stolen_offset, gtt_offset, size);
648 648
649 /* KISS and expect everything to be page-aligned */649 /* KISS and expect everything to be page-aligned */
650 if (WARN_ON(size == 0) || WARN_ON(size & 4095) ||650 if (WARN_ON(size == 0) ||
651 WARN_ON(stolen_offset & 4095))651 WARN_ON(!IS_ALIGNED(size, I915_GTT_PAGE_SIZE)) ||
652 WARN_ON(!IS_ALIGNED(stolen_offset, I915_GTT_MIN_ALIGNMENT)))
652 return NULL;653 return NULL;
653 654
654 stolen = kzalloc(sizeof(*stolen), GFP_KERNEL);655 stolen = kzalloc(sizeof(*stolen), GFP_KERNEL);
@@ -682,7 +683,7 @@ i915_gem_object_create_stolen_for_preallocated(struct drm_i915_private *dev_priv · 27 unmodified lines
682 if (ret)683 if (ret)
683 goto err;684 goto err;
684 685
685 vma = i915_gem_obj_lookup_or_create_vma(obj, &ggtt->base, NULL);686 vma = i915_vma_instance(obj, &ggtt->base, NULL);
686 if (IS_ERR(vma)) {687 if (IS_ERR(vma)) {
687 ret = PTR_ERR(vma);688 ret = PTR_ERR(vma);
688 goto err_pages;689 goto err_pages;
@@ -693,15 +694,16 @@ i915_gem_object_create_stolen_for_preallocated(struct drm_i915_private *dev_priv · 4 unmodified lines
693 * setting up the GTT space. The actual reservation will occur694 * setting up the GTT space. The actual reservation will occur
694 * later.695 * later.
695 */696 */
696 vma->node.start = gtt_offset;697 ret = i915_gem_gtt_reserve(&ggtt->base, &vma->node,
697 vma->node.size = size;698 size, gtt_offset, obj->cache_level,
698 699 0);
699 ret = drm_mm_reserve_node(&ggtt->base.mm, &vma->node);
700 if (ret) {700 if (ret) {
701 DRM_DEBUG_KMS("failed to allocate stolen GTT space\n");701 DRM_DEBUG_KMS("failed to allocate stolen GTT space\n");
702 goto err_pages;702 goto err_pages;
703 }703 }
704 704
705 GEM_BUG_ON(!drm_mm_node_allocated(&vma->node));
706
705 vma->pages = obj->mm.pages;707 vma->pages = obj->mm.pages;
706 vma->flags |= I915_VMA_GLOBAL_BIND;708 vma->flags |= I915_VMA_GLOBAL_BIND;
707 __i915_vma_set_map_and_fenceable(vma);709 __i915_vma_set_map_and_fenceable(vma);
drivers/gpu/drm/i915/i915_gem_tiling.c+217−130
@@ -34,8 +34,8 @@ · 33 unmodified lines
34/**34/**
35 * DOC: buffer object tiling35 * DOC: buffer object tiling
36 *36 *
37 * i915_gem_set_tiling() and i915_gem_get_tiling() is the userspace interface to37 * i915_gem_set_tiling_ioctl() and i915_gem_get_tiling_ioctl() is the userspace
38 * declare fence register requirements.38 * interface to declare fence register requirements.
39 *39 *
40 * In principle GEM doesn't care at all about the internal data layout of an40 * In principle GEM doesn't care at all about the internal data layout of an
41 * object, and hence it also doesn't care about tiling or swizzling. There's two41 * object, and hence it also doesn't care about tiling or swizzling. There's two
@@ -58,86 +58,147 @@ · 16 unmodified lines
58 * invovlement.58 * invovlement.
59 */59 */
60 60
61/**
62 * i915_gem_fence_size - required global GTT size for a fence
63 * @i915: i915 device
64 * @size: object size
65 * @tiling: tiling mode
66 * @stride: tiling stride
67 *
68 * Return the required global GTT size for a fence (view of a tiled object),
69 * taking into account potential fence register mapping.
70 */
71u32 i915_gem_fence_size(struct drm_i915_private *i915,
72 u32 size, unsigned int tiling, unsigned int stride)
73{
74 u32 ggtt_size;
75
76 GEM_BUG_ON(!size);
77
78 if (tiling == I915_TILING_NONE)
79 return size;
80
81 GEM_BUG_ON(!stride);
82
83 if (INTEL_GEN(i915) >= 4) {
84 stride *= i915_gem_tile_height(tiling);
85 GEM_BUG_ON(!IS_ALIGNED(stride, I965_FENCE_PAGE));
86 return roundup(size, stride);
87 }
88
89 /* Previous chips need a power-of-two fence region when tiling */
90 if (IS_GEN3(i915))
91 ggtt_size = 1024*1024;
92 else
93 ggtt_size = 512*1024;
94
95 while (ggtt_size < size)
96 ggtt_size <<= 1;
97
98 return ggtt_size;
99}
100
101/**
102 * i915_gem_fence_alignment - required global GTT alignment for a fence
103 * @i915: i915 device
104 * @size: object size
105 * @tiling: tiling mode
106 * @stride: tiling stride
107 *
108 * Return the required global GTT alignment for a fence (a view of a tiled
109 * object), taking into account potential fence register mapping.
110 */
111u32 i915_gem_fence_alignment(struct drm_i915_private *i915, u32 size,
112 unsigned int tiling, unsigned int stride)
113{
114 GEM_BUG_ON(!size);
115
116 /*
117 * Minimum alignment is 4k (GTT page size), but might be greater
118 * if a fence register is needed for the object.
119 */
120 if (tiling == I915_TILING_NONE)
121 return I915_GTT_MIN_ALIGNMENT;
122
123 if (INTEL_GEN(i915) >= 4)
124 return I965_FENCE_PAGE;
125
126 /*
127 * Previous chips need to be aligned to the size of the smallest
128 * fence register that can contain the object.
129 */
130 return i915_gem_fence_size(i915, size, tiling, stride);
131}
132
61/* Check pitch constriants for all chips & tiling formats */133/* Check pitch constriants for all chips & tiling formats */
62static bool134static bool
63i915_tiling_ok(struct drm_i915_private *dev_priv,135i915_tiling_ok(struct drm_i915_gem_object *obj,
64 int stride, int size, int tiling_mode)136 unsigned int tiling, unsigned int stride)
65{137{
66 int tile_width;138 struct drm_i915_private *i915 = to_i915(obj->base.dev);
139 unsigned int tile_width;
67 140
68 /* Linear is always fine */141 /* Linear is always fine */
69 if (tiling_mode == I915_TILING_NONE)142 if (tiling == I915_TILING_NONE)
70 return true;143 return true;
71 144
72 if (tiling_mode > I915_TILING_LAST)145 if (tiling > I915_TILING_LAST)
73 return false;146 return false;
74 147
75 if (IS_GEN2(dev_priv) ||
76 (tiling_mode == I915_TILING_Y && HAS_128_BYTE_Y_TILING(dev_priv)))
77 tile_width = 128;
78 else
79 tile_width = 512;
80
81 /* check maximum stride & object size */148 /* check maximum stride & object size */
82 /* i965+ stores the end address of the gtt mapping in the fence149 /* i965+ stores the end address of the gtt mapping in the fence
83 * reg, so dont bother to check the size */150 * reg, so dont bother to check the size */
84 if (INTEL_GEN(dev_priv) >= 7) {151 if (INTEL_GEN(i915) >= 7) {
85 if (stride / 128 > GEN7_FENCE_MAX_PITCH_VAL)152 if (stride / 128 > GEN7_FENCE_MAX_PITCH_VAL)
86 return false;153 return false;
87 } else if (INTEL_GEN(dev_priv) >= 4) {154 } else if (INTEL_GEN(i915) >= 4) {
88 if (stride / 128 > I965_FENCE_MAX_PITCH_VAL)155 if (stride / 128 > I965_FENCE_MAX_PITCH_VAL)
89 return false;156 return false;
90 } else {157 } else {
91 if (stride > 8192)158 if (stride > 8192)
92 return false;159 return false;
93 160
94 if (IS_GEN3(dev_priv)) {161 if (IS_GEN3(i915)) {
95 if (size > I830_FENCE_MAX_SIZE_VAL << 20)162 if (obj->base.size > I830_FENCE_MAX_SIZE_VAL << 20)
96 return false;163 return false;
97 } else {164 } else {
98 if (size > I830_FENCE_MAX_SIZE_VAL << 19)165 if (obj->base.size > I830_FENCE_MAX_SIZE_VAL << 19)
99 return false;166 return false;
100 }167 }
101 }168 }
102 169
103 if (stride < tile_width)170 if (IS_GEN2(i915) ||
171 (tiling == I915_TILING_Y && HAS_128_BYTE_Y_TILING(i915)))
172 tile_width = 128;
173 else
174 tile_width = 512;
175
176 if (!IS_ALIGNED(stride, tile_width))
104 return false;177 return false;
105 178
106 /* 965+ just needs multiples of tile width */179 /* 965+ just needs multiples of tile width */
107 if (INTEL_GEN(dev_priv) >= 4) {180 if (INTEL_GEN(i915) >= 4)
108 if (stride & (tile_width - 1))
109 return false;
110 return true;181 return true;
111 }
112 182
113 /* Pre-965 needs power of two tile widths */183 /* Pre-965 needs power of two tile widths */
114 if (stride & (stride - 1))184 return is_power_of_2(stride);
115 return false;
116
117 return true;
118}185}
119 186
120static bool i915_vma_fence_prepare(struct i915_vma *vma, int tiling_mode)187static bool i915_vma_fence_prepare(struct i915_vma *vma,
188 int tiling_mode, unsigned int stride)
121{189{
122 struct drm_i915_private *dev_priv = vma->vm->i915;190 struct drm_i915_private *i915 = vma->vm->i915;
123 u32 size;191 u32 size, alignment;
124 192
125 if (!i915_vma_is_map_and_fenceable(vma))193 if (!i915_vma_is_map_and_fenceable(vma))
126 return true;194 return true;
127 195
128 if (INTEL_GEN(dev_priv) == 3) {196 size = i915_gem_fence_size(i915, vma->size, tiling_mode, stride);
129 if (vma->node.start & ~I915_FENCE_START_MASK)
130 return false;
131 } else {
132 if (vma->node.start & ~I830_FENCE_START_MASK)
133 return false;
134 }
135
136 size = i915_gem_get_ggtt_size(dev_priv, vma->size, tiling_mode);
137 if (vma->node.size < size)197 if (vma->node.size < size)
138 return false;198 return false;
139 199
140 if (vma->node.start & (size - 1))200 alignment = i915_gem_fence_alignment(i915, vma->size, tiling_mode, stride);
201 if (!IS_ALIGNED(vma->node.start, alignment))
141 return false;202 return false;
142 203
143 return true;204 return true;
@@ -145,20 +206,20 @@ static bool i915_vma_fence_prepare(struct i915_vma *vma, int tiling_mode) · 1 unmodified line
145 206
146/* Make the current GTT allocation valid for the change in tiling. */207/* Make the current GTT allocation valid for the change in tiling. */
147static int208static int
148i915_gem_object_fence_prepare(struct drm_i915_gem_object *obj, int tiling_mode)209i915_gem_object_fence_prepare(struct drm_i915_gem_object *obj,
210 int tiling_mode, unsigned int stride)
149{211{
150 struct drm_i915_private *dev_priv = to_i915(obj->base.dev);
151 struct i915_vma *vma;212 struct i915_vma *vma;
152 int ret;213 int ret;
153 214
154 if (tiling_mode == I915_TILING_NONE)215 if (tiling_mode == I915_TILING_NONE)
155 return 0;216 return 0;
156 217
157 if (INTEL_GEN(dev_priv) >= 4)
158 return 0;
159
160 list_for_each_entry(vma, &obj->vma_list, obj_link) {218 list_for_each_entry(vma, &obj->vma_list, obj_link) {
161 if (i915_vma_fence_prepare(vma, tiling_mode))219 if (!i915_vma_is_ggtt(vma))
220 break;
221
222 if (i915_vma_fence_prepare(vma, tiling_mode, stride))
162 continue;223 continue;
163 224
164 ret = i915_vma_unbind(vma);225 ret = i915_vma_unbind(vma);
@@ -169,8 +230,100 @@ i915_gem_object_fence_prepare(struct drm_i915_gem_object *obj, int tiling_mode) · 4 unmodified lines
169 return 0;230 return 0;
170}231}
171 232
233int
234i915_gem_object_set_tiling(struct drm_i915_gem_object *obj,
235 unsigned int tiling, unsigned int stride)
236{
237 struct drm_i915_private *i915 = to_i915(obj->base.dev);
238 struct i915_vma *vma;
239 int err;
240
241 /* Make sure we don't cross-contaminate obj->tiling_and_stride */
242 BUILD_BUG_ON(I915_TILING_LAST & STRIDE_MASK);
243
244 GEM_BUG_ON(!i915_tiling_ok(obj, tiling, stride));
245 GEM_BUG_ON(!stride ^ (tiling == I915_TILING_NONE));
246 lockdep_assert_held(&i915->drm.struct_mutex);
247
248 if ((tiling | stride) == obj->tiling_and_stride)
249 return 0;
250
251 if (obj->framebuffer_references)
252 return -EBUSY;
253
254 /* We need to rebind the object if its current allocation
255 * no longer meets the alignment restrictions for its new
256 * tiling mode. Otherwise we can just leave it alone, but
257 * need to ensure that any fence register is updated before
258 * the next fenced (either through the GTT or by the BLT unit
259 * on older GPUs) access.
260 *
261 * After updating the tiling parameters, we then flag whether
262 * we need to update an associated fence register. Note this
263 * has to also include the unfenced register the GPU uses
264 * whilst executing a fenced command for an untiled object.
265 */
266
267 err = i915_gem_object_fence_prepare(obj, tiling, stride);
268 if (err)
269 return err;
270
271 /* If the memory has unknown (i.e. varying) swizzling, we pin the
272 * pages to prevent them being swapped out and causing corruption
273 * due to the change in swizzling.
274 */
275 mutex_lock(&obj->mm.lock);
276 if (obj->mm.pages &&
277 obj->mm.madv == I915_MADV_WILLNEED &&
278 i915->quirks & QUIRK_PIN_SWIZZLED_PAGES) {
279 if (tiling == I915_TILING_NONE) {
280 GEM_BUG_ON(!obj->mm.quirked);
281 __i915_gem_object_unpin_pages(obj);
282 obj->mm.quirked = false;
283 }
284 if (!i915_gem_object_is_tiled(obj)) {
285 GEM_BUG_ON(!obj->mm.quirked);
286 __i915_gem_object_pin_pages(obj);
287 obj->mm.quirked = true;
288 }
289 }
290 mutex_unlock(&obj->mm.lock);
291
292 list_for_each_entry(vma, &obj->vma_list, obj_link) {
293 if (!i915_vma_is_ggtt(vma))
294 break;
295
296 vma->fence_size =
297 i915_gem_fence_size(i915, vma->size, tiling, stride);
298 vma->fence_alignment =
299 i915_gem_fence_alignment(i915,
300 vma->size, tiling, stride);
301
302 if (vma->fence)
303 vma->fence->dirty = true;
304 }
305
306 obj->tiling_and_stride = tiling | stride;
307
308 /* Force the fence to be reacquired for GTT access */
309 i915_gem_release_mmap(obj);
310
311 /* Try to preallocate memory required to save swizzling on put-pages */
312 if (i915_gem_object_needs_bit17_swizzle(obj)) {
313 if (!obj->bit_17) {
314 obj->bit_17 = kcalloc(BITS_TO_LONGS(obj->base.size >> PAGE_SHIFT),
315 sizeof(long), GFP_KERNEL);
316 }
317 } else {
318 kfree(obj->bit_17);
319 obj->bit_17 = NULL;
320 }
321
322 return 0;
323}
324
172/**325/**
173 * i915_gem_set_tiling - IOCTL handler to set tiling mode326 * i915_gem_set_tiling_ioctl - IOCTL handler to set tiling mode
174 * @dev: DRM device327 * @dev: DRM device
175 * @data: data pointer for the ioctl328 * @data: data pointer for the ioctl
176 * @file: DRM file for the ioctl call329 * @file: DRM file for the ioctl call
@@ -184,30 +337,19 @@ i915_gem_object_fence_prepare(struct drm_i915_gem_object *obj, int tiling_mode) · 7 unmodified lines
184 * Zero on success, negative errno on failure.337 * Zero on success, negative errno on failure.
185 */338 */
186int339int
187i915_gem_set_tiling(struct drm_device *dev, void *data,340i915_gem_set_tiling_ioctl(struct drm_device *dev, void *data,
188 struct drm_file *file)341 struct drm_file *file)
189{342{
190 struct drm_i915_gem_set_tiling *args = data;343 struct drm_i915_gem_set_tiling *args = data;
191 struct drm_i915_private *dev_priv = to_i915(dev);
192 struct drm_i915_gem_object *obj;344 struct drm_i915_gem_object *obj;
193 int err = 0;345 int err;
194
195 /* Make sure we don't cross-contaminate obj->tiling_and_stride */
196 BUILD_BUG_ON(I915_TILING_LAST & STRIDE_MASK);
197 346
198 obj = i915_gem_object_lookup(file, args->handle);347 obj = i915_gem_object_lookup(file, args->handle);
199 if (!obj)348 if (!obj)
200 return -ENOENT;349 return -ENOENT;
201 350
202 if (!i915_tiling_ok(dev_priv,351 if (!i915_tiling_ok(obj, args->tiling_mode, args->stride)) {
203 args->stride, obj->base.size, args->tiling_mode)) {352 err = -EINVAL;
204 i915_gem_object_put(obj);
205 return -EINVAL;
206 }
207
208 mutex_lock(&dev->struct_mutex);
209 if (obj->pin_display || obj->framebuffer_references) {
210 err = -EBUSY;
211 goto err;353 goto err;
212 }354 }
213 355
@@ -216,9 +358,9 @@ i915_gem_set_tiling(struct drm_device *dev, void *data, · 2 unmodified lines
216 args->stride = 0;358 args->stride = 0;
217 } else {359 } else {
218 if (args->tiling_mode == I915_TILING_X)360 if (args->tiling_mode == I915_TILING_X)
219 args->swizzle_mode = dev_priv->mm.bit_6_swizzle_x;361 args->swizzle_mode = to_i915(dev)->mm.bit_6_swizzle_x;
220 else362 else
221 args->swizzle_mode = dev_priv->mm.bit_6_swizzle_y;363 args->swizzle_mode = to_i915(dev)->mm.bit_6_swizzle_y;
222 364
223 /* Hide bit 17 swizzling from the user. This prevents old Mesa365 /* Hide bit 17 swizzling from the user. This prevents old Mesa
224 * from aborting the application on sw fallbacks to bit 17,366 * from aborting the application on sw fallbacks to bit 17,
@@ -240,79 +382,24 @@ i915_gem_set_tiling(struct drm_device *dev, void *data, · 15 unmodified lines
240 }382 }
241 }383 }
242 384
243 if (args->tiling_mode != i915_gem_object_get_tiling(obj) ||385 err = mutex_lock_interruptible(&dev->struct_mutex);
244 args->stride != i915_gem_object_get_stride(obj)) {386 if (err)
245 /* We need to rebind the object if its current allocation387 goto err;
246 * no longer meets the alignment restrictions for its new
247 * tiling mode. Otherwise we can just leave it alone, but
248 * need to ensure that any fence register is updated before
249 * the next fenced (either through the GTT or by the BLT unit
250 * on older GPUs) access.
251 *
252 * After updating the tiling parameters, we then flag whether
253 * we need to update an associated fence register. Note this
254 * has to also include the unfenced register the GPU uses
255 * whilst executing a fenced command for an untiled object.
256 */
257 388
258 err = i915_gem_object_fence_prepare(obj, args->tiling_mode);389 err = i915_gem_object_set_tiling(obj, args->tiling_mode, args->stride);
259 if (!err) {390 mutex_unlock(&dev->struct_mutex);
260 struct i915_vma *vma;391
261 392 /* We have to maintain this existing ABI... */
262 mutex_lock(&obj->mm.lock);
263 if (obj->mm.pages &&
264 obj->mm.madv == I915_MADV_WILLNEED &&
265 dev_priv->quirks & QUIRK_PIN_SWIZZLED_PAGES) {
266 if (args->tiling_mode == I915_TILING_NONE) {
267 GEM_BUG_ON(!obj->mm.quirked);
268 __i915_gem_object_unpin_pages(obj);
269 obj->mm.quirked = false;
270 }
271 if (!i915_gem_object_is_tiled(obj)) {
272 GEM_BUG_ON(!obj->mm.quirked);
273 __i915_gem_object_pin_pages(obj);
274 obj->mm.quirked = true;
275 }
276 }
277 mutex_unlock(&obj->mm.lock);
278
279 list_for_each_entry(vma, &obj->vma_list, obj_link) {
280 if (!vma->fence)
281 continue;
282
283 vma->fence->dirty = true;
284 }
285 obj->tiling_and_stride =
286 args->stride | args->tiling_mode;
287
288 /* Force the fence to be reacquired for GTT access */
289 i915_gem_release_mmap(obj);
290 }
291 }
292 /* we have to maintain this existing ABI... */
293 args->stride = i915_gem_object_get_stride(obj);393 args->stride = i915_gem_object_get_stride(obj);
294 args->tiling_mode = i915_gem_object_get_tiling(obj);394 args->tiling_mode = i915_gem_object_get_tiling(obj);
295 395
296 /* Try to preallocate memory required to save swizzling on put-pages */
297 if (i915_gem_object_needs_bit17_swizzle(obj)) {
298 if (obj->bit_17 == NULL) {
299 obj->bit_17 = kcalloc(BITS_TO_LONGS(obj->base.size >> PAGE_SHIFT),
300 sizeof(long), GFP_KERNEL);
301 }
302 } else {
303 kfree(obj->bit_17);
304 obj->bit_17 = NULL;
305 }
306
307err:396err:
308 i915_gem_object_put(obj);397 i915_gem_object_put(obj);
309 mutex_unlock(&dev->struct_mutex);
310
311 return err;398 return err;
312}399}
313 400
314/**401/**
315 * i915_gem_get_tiling - IOCTL handler to get tiling mode402 * i915_gem_get_tiling_ioctl - IOCTL handler to get tiling mode
316 * @dev: DRM device403 * @dev: DRM device
317 * @data: data pointer for the ioctl404 * @data: data pointer for the ioctl
318 * @file: DRM file for the ioctl call405 * @file: DRM file for the ioctl call
@@ -325,8 +412,8 @@ err: · 6 unmodified lines
325 * Zero on success, negative errno on failure.412 * Zero on success, negative errno on failure.
326 */413 */
327int414int
328i915_gem_get_tiling(struct drm_device *dev, void *data,415i915_gem_get_tiling_ioctl(struct drm_device *dev, void *data,
329 struct drm_file *file)416 struct drm_file *file)
330{417{
331 struct drm_i915_gem_get_tiling *args = data;418 struct drm_i915_gem_get_tiling *args = data;
332 struct drm_i915_private *dev_priv = to_i915(dev);419 struct drm_i915_private *dev_priv = to_i915(dev);
drivers/gpu/drm/i915/i915_gpu_error.c+1−0
@@ -121,6 +121,7 @@ static void __i915_error_advance(struct drm_i915_error_state_buf *e, · 120 unmodified lines
121 e->pos += len;121 e->pos += len;
122}122}
123 123
124__printf(2, 0)
124static void i915_error_vprintf(struct drm_i915_error_state_buf *e,125static void i915_error_vprintf(struct drm_i915_error_state_buf *e,
125 const char *f, va_list args)126 const char *f, va_list args)
126{127{
drivers/gpu/drm/i915/i915_guc_reg.h+6−0
@@ -61,12 +61,18 @@ · 60 unmodified lines
61#define DMA_ADDRESS_SPACE_GTT (8 << 16)61#define DMA_ADDRESS_SPACE_GTT (8 << 16)
62#define DMA_COPY_SIZE _MMIO(0xc310)62#define DMA_COPY_SIZE _MMIO(0xc310)
63#define DMA_CTRL _MMIO(0xc314)63#define DMA_CTRL _MMIO(0xc314)
64#define HUC_UKERNEL (1<<9)
64#define UOS_MOVE (1<<4)65#define UOS_MOVE (1<<4)
65#define START_DMA (1<<0)66#define START_DMA (1<<0)
66#define DMA_GUC_WOPCM_OFFSET _MMIO(0xc340)67#define DMA_GUC_WOPCM_OFFSET _MMIO(0xc340)
68#define HUC_LOADING_AGENT_VCR (0<<1)
69#define HUC_LOADING_AGENT_GUC (1<<1)
67#define GUC_WOPCM_OFFSET_VALUE 0x80000 /* 512KB */70#define GUC_WOPCM_OFFSET_VALUE 0x80000 /* 512KB */
68#define GUC_MAX_IDLE_COUNT _MMIO(0xC3E4)71#define GUC_MAX_IDLE_COUNT _MMIO(0xC3E4)
69 72
73#define HUC_STATUS2 _MMIO(0xD3B0)
74#define HUC_FW_VERIFIED (1<<7)
75
70/* Defines WOPCM space available to GuC firmware */76/* Defines WOPCM space available to GuC firmware */
71#define GUC_WOPCM_SIZE _MMIO(0xc050)77#define GUC_WOPCM_SIZE _MMIO(0xc050)
72/* GuC addresses below GUC_WOPCM_TOP don't map through the GTT */78/* GuC addresses below GUC_WOPCM_TOP don't map through the GTT */
drivers/gpu/drm/i915/i915_guc_submission.c+9−594
@@ -22,8 +22,6 @@ · 21 unmodified lines
22 *22 *
23 */23 */
24#include <linux/circ_buf.h>24#include <linux/circ_buf.h>
25#include <linux/debugfs.h>
26#include <linux/relay.h>
27#include "i915_drv.h"25#include "i915_drv.h"
28#include "intel_uc.h"26#include "intel_uc.h"
29 27
@@ -545,7 +543,7 @@ static void i915_guc_submit(struct drm_i915_gem_request *rq) · 515 unmodified lines
545 */543 */
546 544
547/**545/**
548 * guc_allocate_vma() - Allocate a GGTT VMA for GuC usage546 * intel_guc_allocate_vma() - Allocate a GGTT VMA for GuC usage
549 * @guc: the guc547 * @guc: the guc
550 * @size: size of area to allocate (both virtual space and memory)548 * @size: size of area to allocate (both virtual space and memory)
551 *549 *
@@ -557,7 +555,7 @@ static void i915_guc_submit(struct drm_i915_gem_request *rq) · 5 unmodified lines
557 *555 *
558 * Return: A i915_vma if successful, otherwise an ERR_PTR.556 * Return: A i915_vma if successful, otherwise an ERR_PTR.
559 */557 */
560static struct i915_vma *guc_allocate_vma(struct intel_guc *guc, u32 size)558struct i915_vma *intel_guc_allocate_vma(struct intel_guc *guc, u32 size)
561{559{
562 struct drm_i915_private *dev_priv = guc_to_i915(guc);560 struct drm_i915_private *dev_priv = guc_to_i915(guc);
563 struct drm_i915_gem_object *obj;561 struct drm_i915_gem_object *obj;
@@ -568,7 +566,7 @@ static struct i915_vma *guc_allocate_vma(struct intel_guc *guc, u32 size) · 4 unmodified lines
568 if (IS_ERR(obj))566 if (IS_ERR(obj))
569 return ERR_CAST(obj);567 return ERR_CAST(obj);
570 568
571 vma = i915_vma_create(obj, &dev_priv->ggtt.base, NULL);569 vma = i915_vma_instance(obj, &dev_priv->ggtt.base, NULL);
572 if (IS_ERR(vma))570 if (IS_ERR(vma))
573 goto err;571 goto err;
574 572
@@ -579,9 +577,6 @@ static struct i915_vma *guc_allocate_vma(struct intel_guc *guc, u32 size) · 4 unmodified lines
579 goto err;577 goto err;
580 }578 }
581 579
582 /* Invalidate GuC TLB to let GuC take the latest updates to GTT. */
583 I915_WRITE(GEN8_GTCR, GEN8_GTCR_INVALIDATE);
584
585 return vma;580 return vma;
586 581
587err:582err:
@@ -721,7 +716,7 @@ guc_client_alloc(struct drm_i915_private *dev_priv, · 133 unmodified lines
721 }716 }
722 717
723 /* The first page is doorbell/proc_desc. Two followed pages are wq. */718 /* The first page is doorbell/proc_desc. Two followed pages are wq. */
724 vma = guc_allocate_vma(guc, GUC_DB_SIZE + GUC_WQ_SIZE);719 vma = intel_guc_allocate_vma(guc, GUC_DB_SIZE + GUC_WQ_SIZE);
725 if (IS_ERR(vma))720 if (IS_ERR(vma))
726 goto err;721 goto err;
727 722
@@ -777,488 +772,7 @@ err: · 49 unmodified lines
777 return NULL;772 return NULL;
778}773}
779 774
780/*
781 * Sub buffer switch callback. Called whenever relay has to switch to a new
782 * sub buffer, relay stays on the same sub buffer if 0 is returned.
783 */
784static int subbuf_start_callback(struct rchan_buf *buf,
785 void *subbuf,
786 void *prev_subbuf,
787 size_t prev_padding)
788{
789 /* Use no-overwrite mode by default, where relay will stop accepting
790 * new data if there are no empty sub buffers left.
791 * There is no strict synchronization enforced by relay between Consumer
792 * and Producer. In overwrite mode, there is a possibility of getting
793 * inconsistent/garbled data, the producer could be writing on to the
794 * same sub buffer from which Consumer is reading. This can't be avoided
795 * unless Consumer is fast enough and can always run in tandem with
796 * Producer.
797 */
798 if (relay_buf_full(buf))
799 return 0;
800
801 return 1;
802}
803
804/*
805 * file_create() callback. Creates relay file in debugfs.
806 */
807static struct dentry *create_buf_file_callback(const char *filename,
808 struct dentry *parent,
809 umode_t mode,
810 struct rchan_buf *buf,
811 int *is_global)
812{
813 struct dentry *buf_file;
814
815 /* This to enable the use of a single buffer for the relay channel and
816 * correspondingly have a single file exposed to User, through which
817 * it can collect the logs in order without any post-processing.
818 * Need to set 'is_global' even if parent is NULL for early logging.
819 */
820 *is_global = 1;
821
822 if (!parent)
823 return NULL;
824
825 /* Not using the channel filename passed as an argument, since for each
826 * channel relay appends the corresponding CPU number to the filename
827 * passed in relay_open(). This should be fine as relay just needs a
828 * dentry of the file associated with the channel buffer and that file's
829 * name need not be same as the filename passed as an argument.
830 */
831 buf_file = debugfs_create_file("guc_log", mode,
832 parent, buf, &relay_file_operations);
833 return buf_file;
834}
835
836/*
837 * file_remove() default callback. Removes relay file in debugfs.
838 */
839static int remove_buf_file_callback(struct dentry *dentry)
840{
841 debugfs_remove(dentry);
842 return 0;
843}
844
845/* relay channel callbacks */
846static struct rchan_callbacks relay_callbacks = {
847 .subbuf_start = subbuf_start_callback,
848 .create_buf_file = create_buf_file_callback,
849 .remove_buf_file = remove_buf_file_callback,
850};
851
852static void guc_log_remove_relay_file(struct intel_guc *guc)
853{
854 relay_close(guc->log.relay_chan);
855}
856
857static int guc_log_create_relay_channel(struct intel_guc *guc)
858{
859 struct drm_i915_private *dev_priv = guc_to_i915(guc);
860 struct rchan *guc_log_relay_chan;
861 size_t n_subbufs, subbuf_size;
862
863 /* Keep the size of sub buffers same as shared log buffer */
864 subbuf_size = guc->log.vma->obj->base.size;
865
866 /* Store up to 8 snapshots, which is large enough to buffer sufficient
867 * boot time logs and provides enough leeway to User, in terms of
868 * latency, for consuming the logs from relay. Also doesn't take
869 * up too much memory.
870 */
871 n_subbufs = 8;
872
873 guc_log_relay_chan = relay_open(NULL, NULL, subbuf_size,
874 n_subbufs, &relay_callbacks, dev_priv);
875 if (!guc_log_relay_chan) {
876 DRM_ERROR("Couldn't create relay chan for GuC logging\n");
877 return -ENOMEM;
878 }
879
880 GEM_BUG_ON(guc_log_relay_chan->subbuf_size < subbuf_size);
881 guc->log.relay_chan = guc_log_relay_chan;
882 return 0;
883}
884
885static int guc_log_create_relay_file(struct intel_guc *guc)
886{
887 struct drm_i915_private *dev_priv = guc_to_i915(guc);
888 struct dentry *log_dir;
889 int ret;
890
891 /* For now create the log file in /sys/kernel/debug/dri/0 dir */
892 log_dir = dev_priv->drm.primary->debugfs_root;
893
894 /* If /sys/kernel/debug/dri/0 location do not exist, then debugfs is
895 * not mounted and so can't create the relay file.
896 * The relay API seems to fit well with debugfs only, for availing relay
897 * there are 3 requirements which can be met for debugfs file only in a
898 * straightforward/clean manner :-
899 * i) Need the associated dentry pointer of the file, while opening the
900 * relay channel.
901 * ii) Should be able to use 'relay_file_operations' fops for the file.
902 * iii) Set the 'i_private' field of file's inode to the pointer of
903 * relay channel buffer.
904 */
905 if (!log_dir) {
906 DRM_ERROR("Debugfs dir not available yet for GuC log file\n");
907 return -ENODEV;
908 }
909
910 ret = relay_late_setup_files(guc->log.relay_chan, "guc_log", log_dir);
911 if (ret) {
912 DRM_ERROR("Couldn't associate relay chan with file %d\n", ret);
913 return ret;
914 }
915
916 return 0;
917}
918
919static void guc_move_to_next_buf(struct intel_guc *guc)
920{
921 /* Make sure the updates made in the sub buffer are visible when
922 * Consumer sees the following update to offset inside the sub buffer.
923 */
924 smp_wmb();
925
926 /* All data has been written, so now move the offset of sub buffer. */
927 relay_reserve(guc->log.relay_chan, guc->log.vma->obj->base.size);
928
929 /* Switch to the next sub buffer */
930 relay_flush(guc->log.relay_chan);
931}
932
933static void *guc_get_write_buffer(struct intel_guc *guc)
934{
935 if (!guc->log.relay_chan)
936 return NULL;
937
938 /* Just get the base address of a new sub buffer and copy data into it
939 * ourselves. NULL will be returned in no-overwrite mode, if all sub
940 * buffers are full. Could have used the relay_write() to indirectly
941 * copy the data, but that would have been bit convoluted, as we need to
942 * write to only certain locations inside a sub buffer which cannot be
943 * done without using relay_reserve() along with relay_write(). So its
944 * better to use relay_reserve() alone.
945 */
946 return relay_reserve(guc->log.relay_chan, 0);
947}
948
949static bool
950guc_check_log_buf_overflow(struct intel_guc *guc,
951 enum guc_log_buffer_type type, unsigned int full_cnt)
952{
953 unsigned int prev_full_cnt = guc->log.prev_overflow_count[type];
954 bool overflow = false;
955
956 if (full_cnt != prev_full_cnt) {
957 overflow = true;
958
959 guc->log.prev_overflow_count[type] = full_cnt;
960 guc->log.total_overflow_count[type] += full_cnt - prev_full_cnt;
961
962 if (full_cnt < prev_full_cnt) {
963 /* buffer_full_cnt is a 4 bit counter */
964 guc->log.total_overflow_count[type] += 16;
965 }
966 DRM_ERROR_RATELIMITED("GuC log buffer overflow\n");
967 }
968
969 return overflow;
970}
971
972static unsigned int guc_get_log_buffer_size(enum guc_log_buffer_type type)
973{
974 switch (type) {
975 case GUC_ISR_LOG_BUFFER:
976 return (GUC_LOG_ISR_PAGES + 1) * PAGE_SIZE;
977 case GUC_DPC_LOG_BUFFER:
978 return (GUC_LOG_DPC_PAGES + 1) * PAGE_SIZE;
979 case GUC_CRASH_DUMP_LOG_BUFFER:
980 return (GUC_LOG_CRASH_PAGES + 1) * PAGE_SIZE;
981 default:
982 MISSING_CASE(type);
983 }
984
985 return 0;
986}
987
988static void guc_read_update_log_buffer(struct intel_guc *guc)
989{
990 unsigned int buffer_size, read_offset, write_offset, bytes_to_copy, full_cnt;
991 struct guc_log_buffer_state *log_buf_state, *log_buf_snapshot_state;
992 struct guc_log_buffer_state log_buf_state_local;
993 enum guc_log_buffer_type type;
994 void *src_data, *dst_data;
995 bool new_overflow;
996
997 if (WARN_ON(!guc->log.buf_addr))
998 return;
999
1000 /* Get the pointer to shared GuC log buffer */
1001 log_buf_state = src_data = guc->log.buf_addr;
1002
1003 /* Get the pointer to local buffer to store the logs */
1004 log_buf_snapshot_state = dst_data = guc_get_write_buffer(guc);
1005
1006 /* Actual logs are present from the 2nd page */
1007 src_data += PAGE_SIZE;
1008 dst_data += PAGE_SIZE;
1009
1010 for (type = GUC_ISR_LOG_BUFFER; type < GUC_MAX_LOG_BUFFER; type++) {
1011 /* Make a copy of the state structure, inside GuC log buffer
1012 * (which is uncached mapped), on the stack to avoid reading
1013 * from it multiple times.
1014 */
1015 memcpy(&log_buf_state_local, log_buf_state,
1016 sizeof(struct guc_log_buffer_state));
1017 buffer_size = guc_get_log_buffer_size(type);
1018 read_offset = log_buf_state_local.read_ptr;
1019 write_offset = log_buf_state_local.sampled_write_ptr;
1020 full_cnt = log_buf_state_local.buffer_full_cnt;
1021
1022 /* Bookkeeping stuff */
1023 guc->log.flush_count[type] += log_buf_state_local.flush_to_file;
1024 new_overflow = guc_check_log_buf_overflow(guc, type, full_cnt);
1025
1026 /* Update the state of shared log buffer */
1027 log_buf_state->read_ptr = write_offset;
1028 log_buf_state->flush_to_file = 0;
1029 log_buf_state++;
1030
1031 if (unlikely(!log_buf_snapshot_state))
1032 continue;
1033
1034 /* First copy the state structure in snapshot buffer */
1035 memcpy(log_buf_snapshot_state, &log_buf_state_local,
1036 sizeof(struct guc_log_buffer_state));
1037
1038 /* The write pointer could have been updated by GuC firmware,
1039 * after sending the flush interrupt to Host, for consistency
1040 * set write pointer value to same value of sampled_write_ptr
1041 * in the snapshot buffer.
1042 */
1043 log_buf_snapshot_state->write_ptr = write_offset;
1044 log_buf_snapshot_state++;
1045
1046 /* Now copy the actual logs. */
1047 if (unlikely(new_overflow)) {
1048 /* copy the whole buffer in case of overflow */
1049 read_offset = 0;
1050 write_offset = buffer_size;
1051 } else if (unlikely((read_offset > buffer_size) ||
1052 (write_offset > buffer_size))) {
1053 DRM_ERROR("invalid log buffer state\n");
1054 /* copy whole buffer as offsets are unreliable */
1055 read_offset = 0;
1056 write_offset = buffer_size;
1057 }
1058
1059 /* Just copy the newly written data */
1060 if (read_offset > write_offset) {
1061 i915_memcpy_from_wc(dst_data, src_data, write_offset);
1062 bytes_to_copy = buffer_size - read_offset;
1063 } else {
1064 bytes_to_copy = write_offset - read_offset;
1065 }
1066 i915_memcpy_from_wc(dst_data + read_offset,
1067 src_data + read_offset, bytes_to_copy);
1068
1069 src_data += buffer_size;
1070 dst_data += buffer_size;
1071 }
1072
1073 if (log_buf_snapshot_state)
1074 guc_move_to_next_buf(guc);
1075 else {
1076 /* Used rate limited to avoid deluge of messages, logs might be
1077 * getting consumed by User at a slow rate.
1078 */
1079 DRM_ERROR_RATELIMITED("no sub-buffer to capture logs\n");
1080 guc->log.capture_miss_count++;
1081 }
1082}
1083
1084static void guc_capture_logs_work(struct work_struct *work)
1085{
1086 struct drm_i915_private *dev_priv =
1087 container_of(work, struct drm_i915_private, guc.log.flush_work);
1088
1089 i915_guc_capture_logs(dev_priv);
1090}
1091
1092static void guc_log_cleanup(struct intel_guc *guc)
1093{
1094 struct drm_i915_private *dev_priv = guc_to_i915(guc);
1095
1096 lockdep_assert_held(&dev_priv->drm.struct_mutex);
1097
1098 /* First disable the flush interrupt */
1099 gen9_disable_guc_interrupts(dev_priv);
1100 775
1101 if (guc->log.flush_wq)
1102 destroy_workqueue(guc->log.flush_wq);
1103
1104 guc->log.flush_wq = NULL;
1105
1106 if (guc->log.relay_chan)
1107 guc_log_remove_relay_file(guc);
1108
1109 guc->log.relay_chan = NULL;
1110
1111 if (guc->log.buf_addr)
1112 i915_gem_object_unpin_map(guc->log.vma->obj);
1113
1114 guc->log.buf_addr = NULL;
1115}
1116
1117static int guc_log_create_extras(struct intel_guc *guc)
1118{
1119 struct drm_i915_private *dev_priv = guc_to_i915(guc);
1120 void *vaddr;
1121 int ret;
1122
1123 lockdep_assert_held(&dev_priv->drm.struct_mutex);
1124
1125 /* Nothing to do */
1126 if (i915.guc_log_level < 0)
1127 return 0;
1128
1129 if (!guc->log.buf_addr) {
1130 /* Create a WC (Uncached for read) vmalloc mapping of log
1131 * buffer pages, so that we can directly get the data
1132 * (up-to-date) from memory.
1133 */
1134 vaddr = i915_gem_object_pin_map(guc->log.vma->obj, I915_MAP_WC);
1135 if (IS_ERR(vaddr)) {
1136 ret = PTR_ERR(vaddr);
1137 DRM_ERROR("Couldn't map log buffer pages %d\n", ret);
1138 return ret;
1139 }
1140
1141 guc->log.buf_addr = vaddr;
1142 }
1143
1144 if (!guc->log.relay_chan) {
1145 /* Create a relay channel, so that we have buffers for storing
1146 * the GuC firmware logs, the channel will be linked with a file
1147 * later on when debugfs is registered.
1148 */
1149 ret = guc_log_create_relay_channel(guc);
1150 if (ret)
1151 return ret;
1152 }
1153
1154 if (!guc->log.flush_wq) {
1155 INIT_WORK(&guc->log.flush_work, guc_capture_logs_work);
1156
1157 /*
1158 * GuC log buffer flush work item has to do register access to
1159 * send the ack to GuC and this work item, if not synced before
1160 * suspend, can potentially get executed after the GFX device is
1161 * suspended.
1162 * By marking the WQ as freezable, we don't have to bother about
1163 * flushing of this work item from the suspend hooks, the pending
1164 * work item if any will be either executed before the suspend
1165 * or scheduled later on resume. This way the handling of work
1166 * item can be kept same between system suspend & rpm suspend.
1167 */
1168 guc->log.flush_wq = alloc_ordered_workqueue("i915-guc_log",
1169 WQ_HIGHPRI | WQ_FREEZABLE);
1170 if (guc->log.flush_wq == NULL) {
1171 DRM_ERROR("Couldn't allocate the wq for GuC logging\n");
1172 return -ENOMEM;
1173 }
1174 }
1175
1176 return 0;
1177}
1178
1179static void guc_log_create(struct intel_guc *guc)
1180{
1181 struct i915_vma *vma;
1182 unsigned long offset;
1183 uint32_t size, flags;
1184
1185 if (i915.guc_log_level > GUC_LOG_VERBOSITY_MAX)
1186 i915.guc_log_level = GUC_LOG_VERBOSITY_MAX;
1187
1188 /* The first page is to save log buffer state. Allocate one
1189 * extra page for others in case for overlap */
1190 size = (1 + GUC_LOG_DPC_PAGES + 1 +
1191 GUC_LOG_ISR_PAGES + 1 +
1192 GUC_LOG_CRASH_PAGES + 1) << PAGE_SHIFT;
1193
1194 vma = guc->log.vma;
1195 if (!vma) {
1196 /* We require SSE 4.1 for fast reads from the GuC log buffer and
1197 * it should be present on the chipsets supporting GuC based
1198 * submisssions.
1199 */
1200 if (WARN_ON(!i915_has_memcpy_from_wc())) {
1201 /* logging will not be enabled */
1202 i915.guc_log_level = -1;
1203 return;
1204 }
1205
1206 vma = guc_allocate_vma(guc, size);
1207 if (IS_ERR(vma)) {
1208 /* logging will be off */
1209 i915.guc_log_level = -1;
1210 return;
1211 }
1212
1213 guc->log.vma = vma;
1214
1215 if (guc_log_create_extras(guc)) {
1216 guc_log_cleanup(guc);
1217 i915_vma_unpin_and_release(&guc->log.vma);
1218 i915.guc_log_level = -1;
1219 return;
1220 }
1221 }
1222
1223 /* each allocated unit is a page */
1224 flags = GUC_LOG_VALID | GUC_LOG_NOTIFY_ON_HALF_FULL |
1225 (GUC_LOG_DPC_PAGES << GUC_LOG_DPC_SHIFT) |
1226 (GUC_LOG_ISR_PAGES << GUC_LOG_ISR_SHIFT) |
1227 (GUC_LOG_CRASH_PAGES << GUC_LOG_CRASH_SHIFT);
1228
1229 offset = guc_ggtt_offset(vma) >> PAGE_SHIFT; /* in pages */
1230 guc->log.flags = (offset << GUC_LOG_BUF_ADDR_SHIFT) | flags;
1231}
1232
1233static int guc_log_late_setup(struct intel_guc *guc)
1234{
1235 struct drm_i915_private *dev_priv = guc_to_i915(guc);
1236 int ret;
1237
1238 lockdep_assert_held(&dev_priv->drm.struct_mutex);
1239
1240 if (i915.guc_log_level < 0)
1241 return -EINVAL;
1242
1243 /* If log_level was set as -1 at boot time, then setup needed to
1244 * handle log buffer flush interrupts would not have been done yet,
1245 * so do that now.
1246 */
1247 ret = guc_log_create_extras(guc);
1248 if (ret)
1249 goto err;
1250
1251 ret = guc_log_create_relay_file(guc);
1252 if (ret)
1253 goto err;
1254
1255 return 0;
1256err:
1257 guc_log_cleanup(guc);
1258 /* logging will remain off */
1259 i915.guc_log_level = -1;
1260 return ret;
1261}
1262 776
1263static void guc_policies_init(struct guc_policies *policies)777static void guc_policies_init(struct guc_policies *policies)
1264{778{
@@ -1301,7 +815,7 @@ static void guc_addon_create(struct intel_guc *guc) · 36 unmodified lines
1301 815
1302 vma = guc->ads_vma;816 vma = guc->ads_vma;
1303 if (!vma) {817 if (!vma) {
1304 vma = guc_allocate_vma(guc, PAGE_ALIGN(size));818 vma = intel_guc_allocate_vma(guc, PAGE_ALIGN(size));
1305 if (IS_ERR(vma))819 if (IS_ERR(vma))
1306 return;820 return;
1307 821
@@ -1376,13 +890,13 @@ int i915_guc_submission_init(struct drm_i915_private *dev_priv) · 68 unmodified lines
1376 if (guc->ctx_pool_vma)890 if (guc->ctx_pool_vma)
1377 return 0; /* already allocated */891 return 0; /* already allocated */
1378 892
1379 vma = guc_allocate_vma(guc, gemsize);893 vma = intel_guc_allocate_vma(guc, gemsize);
1380 if (IS_ERR(vma))894 if (IS_ERR(vma))
1381 return PTR_ERR(vma);895 return PTR_ERR(vma);
1382 896
1383 guc->ctx_pool_vma = vma;897 guc->ctx_pool_vma = vma;
1384 ida_init(&guc->ctx_ids);898 ida_init(&guc->ctx_ids);
1385 guc_log_create(guc);899 intel_guc_log_create(guc);
1386 guc_addon_create(guc);900 guc_addon_create(guc);
1387 901
1388 guc->execbuf_client = guc_client_alloc(dev_priv,902 guc->execbuf_client = guc_client_alloc(dev_priv,
@@ -1484,7 +998,7 @@ int intel_guc_suspend(struct drm_i915_private *dev_priv) · 95 unmodified lines
1484 struct i915_gem_context *ctx;998 struct i915_gem_context *ctx;
1485 u32 data[3];999 u32 data[3];
1486 1000
1487 if (guc->guc_fw.guc_fw_load_status != GUC_FIRMWARE_SUCCESS)1001 if (guc->fw.load_status != INTEL_UC_FIRMWARE_SUCCESS)
1488 return 0;1002 return 0;
1489 1003
1490 gen9_disable_guc_interrupts(dev_priv);1004 gen9_disable_guc_interrupts(dev_priv);
@@ -1511,7 +1025,7 @@ int intel_guc_resume(struct drm_i915_private *dev_priv) · 20 unmodified lines
1511 struct i915_gem_context *ctx;1025 struct i915_gem_context *ctx;
1512 u32 data[3];1026 u32 data[3];
1513 1027
1514 if (guc->guc_fw.guc_fw_load_status != GUC_FIRMWARE_SUCCESS)1028 if (guc->fw.load_status != INTEL_UC_FIRMWARE_SUCCESS)
1515 return 0;1029 return 0;
1516 1030
1517 if (i915.guc_log_level >= 0)1031 if (i915.guc_log_level >= 0)
@@ -1527,103 +1041,4 @@ int intel_guc_resume(struct drm_i915_private *dev_priv) · 9 unmodified lines
1527 return intel_guc_send(guc, data, ARRAY_SIZE(data));1041 return intel_guc_send(guc, data, ARRAY_SIZE(data));
1528}1042}
1529 1043
1530void i915_guc_capture_logs(struct drm_i915_private *dev_priv)
1531{
1532 guc_read_update_log_buffer(&dev_priv->guc);
1533
1534 /* Generally device is expected to be active only at this
1535 * time, so get/put should be really quick.
1536 */
1537 intel_runtime_pm_get(dev_priv);
1538 intel_guc_log_flush_complete(&dev_priv->guc);
1539 intel_runtime_pm_put(dev_priv);
1540}
1541
1542void i915_guc_flush_logs(struct drm_i915_private *dev_priv)
1543{
1544 if (!i915.enable_guc_submission || (i915.guc_log_level < 0))
1545 return;
1546
1547 /* First disable the interrupts, will be renabled afterwards */
1548 gen9_disable_guc_interrupts(dev_priv);
1549
1550 /* Before initiating the forceful flush, wait for any pending/ongoing
1551 * flush to complete otherwise forceful flush may not actually happen.
1552 */
1553 flush_work(&dev_priv->guc.log.flush_work);
1554
1555 /* Ask GuC to update the log buffer state */
1556 intel_guc_log_flush(&dev_priv->guc);
1557
1558 /* GuC would have updated log buffer by now, so capture it */
1559 i915_guc_capture_logs(dev_priv);
1560}
1561
1562void i915_guc_unregister(struct drm_i915_private *dev_priv)
1563{
1564 if (!i915.enable_guc_submission)
1565 return;
1566 1044
1567 mutex_lock(&dev_priv->drm.struct_mutex);
1568 guc_log_cleanup(&dev_priv->guc);
1569 mutex_unlock(&dev_priv->drm.struct_mutex);
1570}
1571
1572void i915_guc_register(struct drm_i915_private *dev_priv)
1573{
1574 if (!i915.enable_guc_submission)
1575 return;
1576
1577 mutex_lock(&dev_priv->drm.struct_mutex);
1578 guc_log_late_setup(&dev_priv->guc);
1579 mutex_unlock(&dev_priv->drm.struct_mutex);
1580}
1581
1582int i915_guc_log_control(struct drm_i915_private *dev_priv, u64 control_val)
1583{
1584 union guc_log_control log_param;
1585 int ret;
1586
1587 log_param.value = control_val;
1588
1589 if (log_param.verbosity < GUC_LOG_VERBOSITY_MIN ||
1590 log_param.verbosity > GUC_LOG_VERBOSITY_MAX)
1591 return -EINVAL;
1592
1593 /* This combination doesn't make sense & won't have any effect */
1594 if (!log_param.logging_enabled && (i915.guc_log_level < 0))
1595 return 0;
1596
1597 ret = intel_guc_log_control(&dev_priv->guc, log_param.value);
1598 if (ret < 0) {
1599 DRM_DEBUG_DRIVER("guc_logging_control action failed %d\n", ret);
1600 return ret;
1601 }
1602
1603 i915.guc_log_level = log_param.verbosity;
1604
1605 /* If log_level was set as -1 at boot time, then the relay channel file
1606 * wouldn't have been created by now and interrupts also would not have
1607 * been enabled.
1608 */
1609 if (!dev_priv->guc.log.relay_chan) {
1610 ret = guc_log_late_setup(&dev_priv->guc);
1611 if (!ret)
1612 gen9_enable_guc_interrupts(dev_priv);
1613 } else if (!log_param.logging_enabled) {
1614 /* Once logging is disabled, GuC won't generate logs & send an
1615 * interrupt. But there could be some data in the log buffer
1616 * which is yet to be captured. So request GuC to update the log
1617 * buffer state and then collect the left over logs.
1618 */
1619 i915_guc_flush_logs(dev_priv);
1620
1621 /* As logging is disabled, update log level to reflect that */
1622 i915.guc_log_level = -1;
1623 } else {
1624 /* In case interrupts were disabled, enable them now */
1625 gen9_enable_guc_interrupts(dev_priv);
1626 }
1627
1628 return ret;
1629}
drivers/gpu/drm/i915/i915_irq.c+60−26
@@ -1170,6 +1170,9 @@ static void gen6_pm_rps_work(struct work_struct *work) · 1169 unmodified lines
1170 adj *= 2;1170 adj *= 2;
1171 else /* CHV needs even encode values */1171 else /* CHV needs even encode values */
1172 adj = IS_CHERRYVIEW(dev_priv) ? 2 : 1;1172 adj = IS_CHERRYVIEW(dev_priv) ? 2 : 1;
1173
1174 if (new_delay >= dev_priv->rps.max_freq_softlimit)
1175 adj = 0;
1173 /*1176 /*
1174 * For better performance, jump directly1177 * For better performance, jump directly
1175 * to RPe if we're below it.1178 * to RPe if we're below it.
@@ -1191,6 +1194,9 @@ static void gen6_pm_rps_work(struct work_struct *work) · 15 unmodified lines
1191 adj *= 2;1194 adj *= 2;
1192 else /* CHV needs even encode values */1195 else /* CHV needs even encode values */
1193 adj = IS_CHERRYVIEW(dev_priv) ? -2 : -1;1196 adj = IS_CHERRYVIEW(dev_priv) ? -2 : -1;
1197
1198 if (new_delay <= dev_priv->rps.min_freq_softlimit)
1199 adj = 0;
1194 } else { /* unknown event */1200 } else { /* unknown event */
1195 adj = 0;1201 adj = 0;
1196 }1202 }
@@ -1553,41 +1559,68 @@ static void display_pipe_crc_irq_handler(struct drm_i915_private *dev_priv, · 356 unmodified lines
1553{1559{
1554 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[pipe];1560 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[pipe];
1555 struct intel_pipe_crc_entry *entry;1561 struct intel_pipe_crc_entry *entry;
1562 struct intel_crtc *crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
1563 struct drm_driver *driver = dev_priv->drm.driver;
1564 uint32_t crcs[5];
1556 int head, tail;1565 int head, tail;
1557 1566
1558 spin_lock(&pipe_crc->lock);1567 spin_lock(&pipe_crc->lock);
1568 if (pipe_crc->source) {
1569 if (!pipe_crc->entries) {
1570 spin_unlock(&pipe_crc->lock);
1571 DRM_DEBUG_KMS("spurious interrupt\n");
1572 return;
1573 }
1559 1574
1560 if (!pipe_crc->entries) {1575 head = pipe_crc->head;
1561 spin_unlock(&pipe_crc->lock);1576 tail = pipe_crc->tail;
1562 DRM_DEBUG_KMS("spurious interrupt\n");
1563 return;
1564 }
1565
1566 head = pipe_crc->head;
1567 tail = pipe_crc->tail;
1568 1577
1569 if (CIRC_SPACE(head, tail, INTEL_PIPE_CRC_ENTRIES_NR) < 1) {1578 if (CIRC_SPACE(head, tail, INTEL_PIPE_CRC_ENTRIES_NR) < 1) {
1570 spin_unlock(&pipe_crc->lock);1579 spin_unlock(&pipe_crc->lock);
1571 DRM_ERROR("CRC buffer overflowing\n");1580 DRM_ERROR("CRC buffer overflowing\n");
1572 return;1581 return;
1573 }1582 }
1574 1583
1575 entry = &pipe_crc->entries[head];1584 entry = &pipe_crc->entries[head];
1576 1585
1577 entry->frame = dev_priv->drm.driver->get_vblank_counter(&dev_priv->drm,1586 entry->frame = driver->get_vblank_counter(&dev_priv->drm, pipe);
1578 pipe);1587 entry->crc[0] = crc0;
1579 entry->crc[0] = crc0;1588 entry->crc[1] = crc1;
1580 entry->crc[1] = crc1;1589 entry->crc[2] = crc2;
1581 entry->crc[2] = crc2;1590 entry->crc[3] = crc3;
1582 entry->crc[3] = crc3;1591 entry->crc[4] = crc4;
1583 entry->crc[4] = crc4;
1584 1592
1585 head = (head + 1) & (INTEL_PIPE_CRC_ENTRIES_NR - 1);1593 head = (head + 1) & (INTEL_PIPE_CRC_ENTRIES_NR - 1);
1586 pipe_crc->head = head;1594 pipe_crc->head = head;
1587 1595
1588 spin_unlock(&pipe_crc->lock);1596 spin_unlock(&pipe_crc->lock);
1589 1597
1590 wake_up_interruptible(&pipe_crc->wq);1598 wake_up_interruptible(&pipe_crc->wq);
1599 } else {
1600 /*
1601 * For some not yet identified reason, the first CRC is
1602 * bonkers. So let's just wait for the next vblank and read
1603 * out the buggy result.
1604 *
1605 * On CHV sometimes the second CRC is bonkers as well, so
1606 * don't trust that one either.
1607 */
1608 if (pipe_crc->skipped == 0 ||
1609 (IS_CHERRYVIEW(dev_priv) && pipe_crc->skipped == 1)) {
1610 pipe_crc->skipped++;
1611 spin_unlock(&pipe_crc->lock);
1612 return;
1613 }
1614 spin_unlock(&pipe_crc->lock);
1615 crcs[0] = crc0;
1616 crcs[1] = crc1;
1617 crcs[2] = crc2;
1618 crcs[3] = crc3;
1619 crcs[4] = crc4;
1620 drm_crtc_add_crc_entry(&crtc->base, true,
1621 drm_accurate_vblank_count(&crtc->base),
1622 crcs);
1623 }
1591}1624}
1592#else1625#else
1593static inline void1626static inline void
@@ -2703,12 +2736,13 @@ static void i915_clear_error_registers(struct drm_i915_private *dev_priv) · 1109 unmodified lines
2703 * i915_handle_error - handle a gpu error2736 * i915_handle_error - handle a gpu error
2704 * @dev_priv: i915 device private2737 * @dev_priv: i915 device private
2705 * @engine_mask: mask representing engines that are hung2738 * @engine_mask: mask representing engines that are hung
2739 * @fmt: Error message format string
2740 *
2706 * Do some basic checking of register state at error time and2741 * Do some basic checking of register state at error time and
2707 * dump it to the syslog. Also call i915_capture_error_state() to make2742 * dump it to the syslog. Also call i915_capture_error_state() to make
2708 * sure we get a record and make it available in debugfs. Fire a uevent2743 * sure we get a record and make it available in debugfs. Fire a uevent
2709 * so userspace knows something bad happened (should trigger collection2744 * so userspace knows something bad happened (should trigger collection
2710 * of a ring dump etc.).2745 * of a ring dump etc.).
2711 * @fmt: Error message format string
2712 */2746 */
2713void i915_handle_error(struct drm_i915_private *dev_priv,2747void i915_handle_error(struct drm_i915_private *dev_priv,
2714 u32 engine_mask,2748 u32 engine_mask,
drivers/gpu/drm/i915/i915_reg.h+17−3
@@ -3597,9 +3597,12 @@ enum { · 3596 unmodified lines
3597#define EDP_PSR_PERF_CNT_MASK 0xffffff3597#define EDP_PSR_PERF_CNT_MASK 0xffffff
3598 3598
3599#define EDP_PSR_DEBUG_CTL _MMIO(dev_priv->psr_mmio_base + 0x60)3599#define EDP_PSR_DEBUG_CTL _MMIO(dev_priv->psr_mmio_base + 0x60)
3600#define EDP_PSR_DEBUG_MASK_LPSP (1<<27)3600#define EDP_PSR_DEBUG_MASK_MAX_SLEEP (1<<28)
3601#define EDP_PSR_DEBUG_MASK_MEMUP (1<<26)3601#define EDP_PSR_DEBUG_MASK_LPSP (1<<27)
3602#define EDP_PSR_DEBUG_MASK_HPD (1<<25)3602#define EDP_PSR_DEBUG_MASK_MEMUP (1<<26)
3603#define EDP_PSR_DEBUG_MASK_HPD (1<<25)
3604#define EDP_PSR_DEBUG_MASK_DISP_REG_WRITE (1<<16)
3605#define EDP_PSR_DEBUG_EXIT_ON_PIXEL_UNDERRUN (1<<15)
3603 3606
3604#define EDP_PSR2_CTL _MMIO(0x6f900)3607#define EDP_PSR2_CTL _MMIO(0x6f900)
3605#define EDP_PSR2_ENABLE (1<<31)3608#define EDP_PSR2_ENABLE (1<<31)
@@ -3614,6 +3617,11 @@ enum { · 8 unmodified lines
3614#define EDP_PSR2_FRAME_BEFORE_SU_SHIFT 43617#define EDP_PSR2_FRAME_BEFORE_SU_SHIFT 4
3615#define EDP_PSR2_FRAME_BEFORE_SU_MASK (0xf<<4)3618#define EDP_PSR2_FRAME_BEFORE_SU_MASK (0xf<<4)
3616#define EDP_PSR2_IDLE_MASK 0xf3619#define EDP_PSR2_IDLE_MASK 0xf
3620#define EDP_FRAMES_BEFORE_SU_ENTRY (1<<4)
3621
3622#define EDP_PSR2_STATUS_CTL _MMIO(0x6f940)
3623#define EDP_PSR2_STATUS_STATE_MASK (0xf<<28)
3624#define EDP_PSR2_STATUS_STATE_SHIFT 28
3617 3625
3618/* VGA port control */3626/* VGA port control */
3619#define ADPA _MMIO(0x61100)3627#define ADPA _MMIO(0x61100)
@@ -6446,6 +6454,12 @@ enum { · 2826 unmodified lines
6446#define BDW_DPRS_MASK_VBLANK_SRD (1 << 0)6454#define BDW_DPRS_MASK_VBLANK_SRD (1 << 0)
6447#define CHICKEN_PIPESL_1(pipe) _MMIO_PIPE(pipe, _CHICKEN_PIPESL_1_A, _CHICKEN_PIPESL_1_B)6455#define CHICKEN_PIPESL_1(pipe) _MMIO_PIPE(pipe, _CHICKEN_PIPESL_1_A, _CHICKEN_PIPESL_1_B)
6448 6456
6457#define CHICKEN_TRANS_A 0x420c0
6458#define CHICKEN_TRANS_B 0x420c4
6459#define CHICKEN_TRANS(trans) _MMIO_TRANS(trans, CHICKEN_TRANS_A, CHICKEN_TRANS_B)
6460#define PSR2_VSC_ENABLE_PROG_HEADER (1<<12)
6461#define PSR2_ADD_VERTICAL_LINE_COUNT (1<<15)
6462
6449#define DISP_ARB_CTL _MMIO(0x45000)6463#define DISP_ARB_CTL _MMIO(0x45000)
6450#define DISP_FBC_MEMORY_WAKE (1<<31)6464#define DISP_FBC_MEMORY_WAKE (1<<31)
6451#define DISP_TILE_SURFACE_SWIZZLING (1<<13)6465#define DISP_TILE_SURFACE_SWIZZLING (1<<13)
drivers/gpu/drm/i915/i915_sw_fence.c+1−0
@@ -63,6 +63,7 @@ static inline void debug_fence_destroy(struct i915_sw_fence *fence) · 62 unmodified lines
63static inline void debug_fence_free(struct i915_sw_fence *fence)63static inline void debug_fence_free(struct i915_sw_fence *fence)
64{64{
65 debug_object_free(fence, &i915_sw_fence_debug_descr);65 debug_object_free(fence, &i915_sw_fence_debug_descr);
66 smp_wmb(); /* flush the change in state before reallocation */
66}67}
67 68
68static inline void debug_fence_assert(struct i915_sw_fence *fence)69static inline void debug_fence_assert(struct i915_sw_fence *fence)
drivers/gpu/drm/i915/i915_sysfs.c+1−1
@@ -58,7 +58,7 @@ static u32 calc_residency(struct drm_i915_private *dev_priv, · 57 unmodified lines
58 58
59 if (I915_READ(VLV_COUNTER_CONTROL) & VLV_COUNT_RANGE_HIGH)59 if (I915_READ(VLV_COUNTER_CONTROL) & VLV_COUNT_RANGE_HIGH)
60 units <<= 8;60 units <<= 8;
61 } else if (IS_BROXTON(dev_priv)) {61 } else if (IS_GEN9_LP(dev_priv)) {
62 units = 1;62 units = 1;
63 div = 1200; /* 833.33ns */63 div = 1200; /* 833.33ns */
64 }64 }
drivers/gpu/drm/i915/i915_trace.h+8−8
@@ -450,9 +450,9 @@ TRACE_EVENT(i915_gem_evict_vm, · 449 unmodified lines
450 TP_printk("dev=%d, vm=%p", __entry->dev, __entry->vm)450 TP_printk("dev=%d, vm=%p", __entry->dev, __entry->vm)
451);451);
452 452
453TRACE_EVENT(i915_gem_evict_vma,453TRACE_EVENT(i915_gem_evict_node,
454 TP_PROTO(struct i915_vma *vma, unsigned int flags),454 TP_PROTO(struct i915_address_space *vm, struct drm_mm_node *node, unsigned int flags),
455 TP_ARGS(vma, flags),455 TP_ARGS(vm, node, flags),
456 456
457 TP_STRUCT__entry(457 TP_STRUCT__entry(
458 __field(u32, dev)458 __field(u32, dev)
@@ -464,11 +464,11 @@ TRACE_EVENT(i915_gem_evict_vma, · 5 unmodified lines
464 ),464 ),
465 465
466 TP_fast_assign(466 TP_fast_assign(
467 __entry->dev = vma->vm->i915->drm.primary->index;467 __entry->dev = vm->i915->drm.primary->index;
468 __entry->vm = vma->vm;468 __entry->vm = vm;
469 __entry->start = vma->node.start;469 __entry->start = node->start;
470 __entry->size = vma->node.size;470 __entry->size = node->size;
471 __entry->color = vma->node.color;471 __entry->color = node->color;
472 __entry->flags = flags;472 __entry->flags = flags;
473 ),473 ),
474 474
drivers/gpu/drm/i915/i915_vgpu.c+12−21
@@ -116,22 +116,20 @@ void intel_vgt_deballoon(struct drm_i915_private *dev_priv) · 115 unmodified lines
116 memset(&bl_info, 0, sizeof(bl_info));116 memset(&bl_info, 0, sizeof(bl_info));
117}117}
118 118
119static int vgt_balloon_space(struct drm_mm *mm,119static int vgt_balloon_space(struct i915_ggtt *ggtt,
120 struct drm_mm_node *node,120 struct drm_mm_node *node,
121 unsigned long start, unsigned long end)121 unsigned long start, unsigned long end)
122{122{
123 unsigned long size = end - start;123 unsigned long size = end - start;
124 124
125 if (start == end)125 if (start >= end)
126 return -EINVAL;126 return -EINVAL;
127 127
128 DRM_INFO("balloon space: range [ 0x%lx - 0x%lx ] %lu KiB.\n",128 DRM_INFO("balloon space: range [ 0x%lx - 0x%lx ] %lu KiB.\n",
129 start, end, size / 1024);129 start, end, size / 1024);
130 130 return i915_gem_gtt_reserve(&ggtt->base, node,
131 node->start = start;131 size, start, I915_COLOR_UNEVICTABLE,
132 node->size = size;132 0);
133
134 return drm_mm_reserve_node(mm, node);
135}133}
136 134
137/**135/**
@@ -214,10 +212,8 @@ int intel_vgt_balloon(struct drm_i915_private *dev_priv) · 76 unmodified lines
214 212
215 /* Unmappable graphic memory ballooning */213 /* Unmappable graphic memory ballooning */
216 if (unmappable_base > ggtt->mappable_end) {214 if (unmappable_base > ggtt->mappable_end) {
217 ret = vgt_balloon_space(&ggtt->base.mm,215 ret = vgt_balloon_space(ggtt, &bl_info.space[2],
218 &bl_info.space[2],216 ggtt->mappable_end, unmappable_base);
219 ggtt->mappable_end,
220 unmappable_base);
221 217
222 if (ret)218 if (ret)
223 goto err;219 goto err;
@@ -228,18 +224,15 @@ int intel_vgt_balloon(struct drm_i915_private *dev_priv) · 4 unmodified lines
228 * because it is reserved to the guard page.224 * because it is reserved to the guard page.
229 */225 */
230 if (unmappable_end < ggtt_end - PAGE_SIZE) {226 if (unmappable_end < ggtt_end - PAGE_SIZE) {
231 ret = vgt_balloon_space(&ggtt->base.mm,227 ret = vgt_balloon_space(ggtt, &bl_info.space[3],
232 &bl_info.space[3],228 unmappable_end, ggtt_end - PAGE_SIZE);
233 unmappable_end,
234 ggtt_end - PAGE_SIZE);
235 if (ret)229 if (ret)
236 goto err;230 goto err;
237 }231 }
238 232
239 /* Mappable graphic memory ballooning */233 /* Mappable graphic memory ballooning */
240 if (mappable_base > ggtt->base.start) {234 if (mappable_base > ggtt->base.start) {
241 ret = vgt_balloon_space(&ggtt->base.mm,235 ret = vgt_balloon_space(ggtt, &bl_info.space[0],
242 &bl_info.space[0],
243 ggtt->base.start, mappable_base);236 ggtt->base.start, mappable_base);
244 237
245 if (ret)238 if (ret)
@@ -247,10 +240,8 @@ int intel_vgt_balloon(struct drm_i915_private *dev_priv) · 1 unmodified line
247 }240 }
248 241
249 if (mappable_end < ggtt->mappable_end) {242 if (mappable_end < ggtt->mappable_end) {
250 ret = vgt_balloon_space(&ggtt->base.mm,243 ret = vgt_balloon_space(ggtt, &bl_info.space[1],
251 &bl_info.space[1],244 mappable_end, ggtt->mappable_end);
252 mappable_end,
253 ggtt->mappable_end);
254 245
255 if (ret)246 if (ret)
256 goto err;247 goto err;
drivers/gpu/drm/i915/i915_vma.c+129−92
@@ -45,6 +45,7 @@ i915_vma_retire(struct i915_gem_active *active, · 44 unmodified lines
45 if (i915_vma_is_active(vma))45 if (i915_vma_is_active(vma))
46 return;46 return;
47 47
48 GEM_BUG_ON(!drm_mm_node_allocated(&vma->node));
48 list_move_tail(&vma->vm_link, &vma->vm->inactive_list);49 list_move_tail(&vma->vm_link, &vma->vm->inactive_list);
49 if (unlikely(i915_vma_is_closed(vma) && !i915_vma_is_pinned(vma)))50 if (unlikely(i915_vma_is_closed(vma) && !i915_vma_is_pinned(vma)))
50 WARN_ON(i915_vma_unbind(vma));51 WARN_ON(i915_vma_unbind(vma));
@@ -69,17 +70,15 @@ i915_vma_retire(struct i915_gem_active *active, · 18 unmodified lines
69}70}
70 71
71static struct i915_vma *72static struct i915_vma *
72__i915_vma_create(struct drm_i915_gem_object *obj,73vma_create(struct drm_i915_gem_object *obj,
73 struct i915_address_space *vm,74 struct i915_address_space *vm,
74 const struct i915_ggtt_view *view)75 const struct i915_ggtt_view *view)
75{76{
76 struct i915_vma *vma;77 struct i915_vma *vma;
77 struct rb_node *rb, **p;78 struct rb_node *rb, **p;
78 int i;79 int i;
79 80
80 GEM_BUG_ON(vm->closed);81 vma = kmem_cache_zalloc(vm->i915->vmas, GFP_KERNEL);
81
82 vma = kmem_cache_zalloc(to_i915(obj->base.dev)->vmas, GFP_KERNEL);
83 if (vma == NULL)82 if (vma == NULL)
84 return ERR_PTR(-ENOMEM);83 return ERR_PTR(-ENOMEM);
85 84
@@ -87,29 +86,50 @@ __i915_vma_create(struct drm_i915_gem_object *obj, · 1 unmodified line
87 for (i = 0; i < ARRAY_SIZE(vma->last_read); i++)86 for (i = 0; i < ARRAY_SIZE(vma->last_read); i++)
88 init_request_active(&vma->last_read[i], i915_vma_retire);87 init_request_active(&vma->last_read[i], i915_vma_retire);
89 init_request_active(&vma->last_fence, NULL);88 init_request_active(&vma->last_fence, NULL);
90 list_add(&vma->vm_link, &vm->unbound_list);
91 vma->vm = vm;89 vma->vm = vm;
92 vma->obj = obj;90 vma->obj = obj;
93 vma->size = obj->base.size;91 vma->size = obj->base.size;
92 vma->display_alignment = I915_GTT_MIN_ALIGNMENT;
94 93
95 if (view) {94 if (view) {
96 vma->ggtt_view = *view;95 vma->ggtt_view = *view;
97 if (view->type == I915_GGTT_VIEW_PARTIAL) {96 if (view->type == I915_GGTT_VIEW_PARTIAL) {
98 GEM_BUG_ON(range_overflows_t(u64,97 GEM_BUG_ON(range_overflows_t(u64,
99 view->params.partial.offset,98 view->partial.offset,
100 view->params.partial.size,99 view->partial.size,
101 obj->base.size >> PAGE_SHIFT));100 obj->base.size >> PAGE_SHIFT));
102 vma->size = view->params.partial.size;101 vma->size = view->partial.size;
103 vma->size <<= PAGE_SHIFT;102 vma->size <<= PAGE_SHIFT;
104 GEM_BUG_ON(vma->size >= obj->base.size);103 GEM_BUG_ON(vma->size >= obj->base.size);
105 } else if (view->type == I915_GGTT_VIEW_ROTATED) {104 } else if (view->type == I915_GGTT_VIEW_ROTATED) {
106 vma->size =105 vma->size = intel_rotation_info_size(&view->rotated);
107 intel_rotation_info_size(&view->params.rotated);
108 vma->size <<= PAGE_SHIFT;106 vma->size <<= PAGE_SHIFT;
109 }107 }
110 }108 }
111 109
110 if (unlikely(vma->size > vm->total))
111 goto err_vma;
112
113 GEM_BUG_ON(!IS_ALIGNED(vma->size, I915_GTT_PAGE_SIZE));
114
112 if (i915_is_ggtt(vm)) {115 if (i915_is_ggtt(vm)) {
116 if (unlikely(overflows_type(vma->size, u32)))
117 goto err_vma;
118
119 vma->fence_size = i915_gem_fence_size(vm->i915, vma->size,
120 i915_gem_object_get_tiling(obj),
121 i915_gem_object_get_stride(obj));
122 if (unlikely(vma->fence_size < vma->size || /* overflow */
123 vma->fence_size > vm->total))
124 goto err_vma;
125
126 GEM_BUG_ON(!IS_ALIGNED(vma->fence_size, I915_GTT_MIN_ALIGNMENT));
127
128 vma->fence_alignment = i915_gem_fence_alignment(vm->i915, vma->size,
129 i915_gem_object_get_tiling(obj),
130 i915_gem_object_get_stride(obj));
131 GEM_BUG_ON(!is_power_of_2(vma->fence_alignment));
132
113 vma->flags |= I915_VMA_GGTT;133 vma->flags |= I915_VMA_GGTT;
114 list_add(&vma->obj_link, &obj->vma_list);134 list_add(&vma->obj_link, &obj->vma_list);
115 } else {135 } else {
@@ -131,20 +151,74 @@ __i915_vma_create(struct drm_i915_gem_object *obj, · 15 unmodified lines
131 }151 }
132 rb_link_node(&vma->obj_node, rb, p);152 rb_link_node(&vma->obj_node, rb, p);
133 rb_insert_color(&vma->obj_node, &obj->vma_tree);153 rb_insert_color(&vma->obj_node, &obj->vma_tree);
154 list_add(&vma->vm_link, &vm->unbound_list);
134 155
135 return vma;156 return vma;
157
158err_vma:
159 kmem_cache_free(vm->i915->vmas, vma);
160 return ERR_PTR(-E2BIG);
136}161}
137 162
163static struct i915_vma *
164vma_lookup(struct drm_i915_gem_object *obj,
165 struct i915_address_space *vm,
166 const struct i915_ggtt_view *view)
167{
168 struct rb_node *rb;
169
170 rb = obj->vma_tree.rb_node;
171 while (rb) {
172 struct i915_vma *vma = rb_entry(rb, struct i915_vma, obj_node);
173 long cmp;
174
175 cmp = i915_vma_compare(vma, vm, view);
176 if (cmp == 0)
177 return vma;
178
179 if (cmp < 0)
180 rb = rb->rb_right;
181 else
182 rb = rb->rb_left;
183 }
184
185 return NULL;
186}
187
188/**
189 * i915_vma_instance - return the singleton instance of the VMA
190 * @obj: parent &struct drm_i915_gem_object to be mapped
191 * @vm: address space in which the mapping is located
192 * @view: additional mapping requirements
193 *
194 * i915_vma_instance() looks up an existing VMA of the @obj in the @vm with
195 * the same @view characteristics. If a match is not found, one is created.
196 * Once created, the VMA is kept until either the object is freed, or the
197 * address space is closed.
198 *
199 * Must be called with struct_mutex held.
200 *
201 * Returns the vma, or an error pointer.
202 */
138struct i915_vma *203struct i915_vma *
139i915_vma_create(struct drm_i915_gem_object *obj,204i915_vma_instance(struct drm_i915_gem_object *obj,
140 struct i915_address_space *vm,205 struct i915_address_space *vm,
141 const struct i915_ggtt_view *view)206 const struct i915_ggtt_view *view)
142{207{
208 struct i915_vma *vma;
209
143 lockdep_assert_held(&obj->base.dev->struct_mutex);210 lockdep_assert_held(&obj->base.dev->struct_mutex);
144 GEM_BUG_ON(view && !i915_is_ggtt(vm));211 GEM_BUG_ON(view && !i915_is_ggtt(vm));
145 GEM_BUG_ON(i915_gem_obj_to_vma(obj, vm, view));212 GEM_BUG_ON(vm->closed);
213
214 vma = vma_lookup(obj, vm, view);
215 if (!vma)
216 vma = vma_create(obj, vm, view);
146 217
147 return __i915_vma_create(obj, vm, view);218 GEM_BUG_ON(!IS_ERR(vma) && i915_vma_is_closed(vma));
219 GEM_BUG_ON(!IS_ERR(vma) && i915_vma_compare(vma, vm, view));
220 GEM_BUG_ON(!IS_ERR(vma) && vma_lookup(obj, vm, view) != vma);
221 return vma;
148}222}
149 223
150/**224/**
@@ -195,6 +269,7 @@ int i915_vma_bind(struct i915_vma *vma, enum i915_cache_level cache_level, · 44 unmodified lines
195 return ret;269 return ret;
196 }270 }
197 271
272 trace_i915_vma_bind(vma, bind_flags);
198 ret = vma->vm->bind_vma(vma, cache_level, bind_flags);273 ret = vma->vm->bind_vma(vma, cache_level, bind_flags);
199 if (ret)274 if (ret)
200 return ret;275 return ret;
@@ -258,7 +333,8 @@ i915_vma_misplaced(struct i915_vma *vma, u64 size, u64 alignment, u64 flags) · 57 unmodified lines
258 if (vma->node.size < size)333 if (vma->node.size < size)
259 return true;334 return true;
260 335
261 if (alignment && vma->node.start & (alignment - 1))336 GEM_BUG_ON(alignment && !is_power_of_2(alignment));
337 if (alignment && !IS_ALIGNED(vma->node.start, alignment))
262 return true;338 return true;
263 339
264 if (flags & PIN_MAPPABLE && !i915_vma_is_map_and_fenceable(vma))340 if (flags & PIN_MAPPABLE && !i915_vma_is_map_and_fenceable(vma))
@@ -277,31 +353,24 @@ i915_vma_misplaced(struct i915_vma *vma, u64 size, u64 alignment, u64 flags) · 12 unmodified lines
277 353
278void __i915_vma_set_map_and_fenceable(struct i915_vma *vma)354void __i915_vma_set_map_and_fenceable(struct i915_vma *vma)
279{355{
280 struct drm_i915_gem_object *obj = vma->obj;
281 struct drm_i915_private *dev_priv = to_i915(obj->base.dev);
282 bool mappable, fenceable;356 bool mappable, fenceable;
283 u32 fence_size, fence_alignment;
284
285 fence_size = i915_gem_get_ggtt_size(dev_priv,
286 vma->size,
287 i915_gem_object_get_tiling(obj));
288 fence_alignment = i915_gem_get_ggtt_alignment(dev_priv,
289 vma->size,
290 i915_gem_object_get_tiling(obj),
291 true);
292
293 fenceable = (vma->node.size == fence_size &&
294 (vma->node.start & (fence_alignment - 1)) == 0);
295 357
296 mappable = (vma->node.start + fence_size <=358 GEM_BUG_ON(!i915_vma_is_ggtt(vma));
297 dev_priv->ggtt.mappable_end);359 GEM_BUG_ON(!vma->fence_size);
298 360
299 /*361 /*
300 * Explicitly disable for rotated VMA since the display does not362 * Explicitly disable for rotated VMA since the display does not
301 * need the fence and the VMA is not accessible to other users.363 * need the fence and the VMA is not accessible to other users.
302 */364 */
303 if (mappable && fenceable &&365 if (vma->ggtt_view.type == I915_GGTT_VIEW_ROTATED)
304 vma->ggtt_view.type != I915_GGTT_VIEW_ROTATED)366 return;
367
368 fenceable = (vma->node.size >= vma->fence_size &&
369 IS_ALIGNED(vma->node.start, vma->fence_alignment));
370
371 mappable = vma->node.start + vma->fence_size <= i915_vm_to_ggtt(vma->vm)->mappable_end;
372
373 if (mappable && fenceable)
305 vma->flags |= I915_VMA_CAN_FENCE;374 vma->flags |= I915_VMA_CAN_FENCE;
306 else375 else
307 vma->flags &= ~I915_VMA_CAN_FENCE;376 vma->flags &= ~I915_VMA_CAN_FENCE;
@@ -368,22 +437,26 @@ i915_vma_insert(struct i915_vma *vma, u64 size, u64 alignment, u64 flags) · 60 unmodified lines
368 GEM_BUG_ON(drm_mm_node_allocated(&vma->node));437 GEM_BUG_ON(drm_mm_node_allocated(&vma->node));
369 438
370 size = max(size, vma->size);439 size = max(size, vma->size);
371 if (flags & PIN_MAPPABLE)440 alignment = max(alignment, vma->display_alignment);
372 size = i915_gem_get_ggtt_size(dev_priv, size,441 if (flags & PIN_MAPPABLE) {
373 i915_gem_object_get_tiling(obj));442 size = max_t(typeof(size), size, vma->fence_size);
443 alignment = max_t(typeof(alignment),
444 alignment, vma->fence_alignment);
445 }
374 446
375 alignment = max(max(alignment, vma->display_alignment),447 GEM_BUG_ON(!IS_ALIGNED(size, I915_GTT_PAGE_SIZE));
376 i915_gem_get_ggtt_alignment(dev_priv, size,448 GEM_BUG_ON(!IS_ALIGNED(alignment, I915_GTT_MIN_ALIGNMENT));
377 i915_gem_object_get_tiling(obj),449 GEM_BUG_ON(!is_power_of_2(alignment));
378 flags & PIN_MAPPABLE));
379 450
380 start = flags & PIN_OFFSET_BIAS ? flags & PIN_OFFSET_MASK : 0;451 start = flags & PIN_OFFSET_BIAS ? flags & PIN_OFFSET_MASK : 0;
452 GEM_BUG_ON(!IS_ALIGNED(start, I915_GTT_PAGE_SIZE));
381 453
382 end = vma->vm->total;454 end = vma->vm->total;
383 if (flags & PIN_MAPPABLE)455 if (flags & PIN_MAPPABLE)
384 end = min_t(u64, end, dev_priv->ggtt.mappable_end);456 end = min_t(u64, end, dev_priv->ggtt.mappable_end);
385 if (flags & PIN_ZONE_4G)457 if (flags & PIN_ZONE_4G)
386 end = min_t(u64, end, (1ULL << 32) - PAGE_SIZE);458 end = min_t(u64, end, (1ULL << 32) - I915_GTT_PAGE_SIZE);
459 GEM_BUG_ON(!IS_ALIGNED(end, I915_GTT_PAGE_SIZE));
387 460
388 /* If binding the object/GGTT view requires more space than the entire461 /* If binding the object/GGTT view requires more space than the entire
389 * aperture has, reject it early before evicting everything in a vain462 * aperture has, reject it early before evicting everything in a vain
@@ -403,65 +476,28 @@ i915_vma_insert(struct i915_vma *vma, u64 size, u64 alignment, u64 flags) · 13 unmodified lines
403 476
404 if (flags & PIN_OFFSET_FIXED) {477 if (flags & PIN_OFFSET_FIXED) {
405 u64 offset = flags & PIN_OFFSET_MASK;478 u64 offset = flags & PIN_OFFSET_MASK;
406 if (offset & (alignment - 1) ||479 if (!IS_ALIGNED(offset, alignment) ||
407 range_overflows(offset, size, end)) {480 range_overflows(offset, size, end)) {
408 ret = -EINVAL;481 ret = -EINVAL;
409 goto err_unpin;482 goto err_unpin;
410 }483 }
411 484
412 vma->node.start = offset;485 ret = i915_gem_gtt_reserve(vma->vm, &vma->node,
413 vma->node.size = size;486 size, offset, obj->cache_level,
414 vma->node.color = obj->cache_level;487 flags);
415 ret = drm_mm_reserve_node(&vma->vm->mm, &vma->node);488 if (ret)
416 if (ret) {489 goto err_unpin;
417 ret = i915_gem_evict_for_vma(vma, flags);
418 if (ret == 0)
419 ret = drm_mm_reserve_node(&vma->vm->mm, &vma->node);
420 if (ret)
421 goto err_unpin;
422 }
423 } else {490 } else {
424 u32 search_flag, alloc_flag;491 ret = i915_gem_gtt_insert(vma->vm, &vma->node,
425 492 size, alignment, obj->cache_level,
426 if (flags & PIN_HIGH) {493 start, end, flags);
427 search_flag = DRM_MM_SEARCH_BELOW;494 if (ret)
428 alloc_flag = DRM_MM_CREATE_TOP;
429 } else {
430 search_flag = DRM_MM_SEARCH_DEFAULT;
431 alloc_flag = DRM_MM_CREATE_DEFAULT;
432 }
433
434 /* We only allocate in PAGE_SIZE/GTT_PAGE_SIZE (4096) chunks,
435 * so we know that we always have a minimum alignment of 4096.
436 * The drm_mm range manager is optimised to return results
437 * with zero alignment, so where possible use the optimal
438 * path.
439 */
440 if (alignment <= 4096)
441 alignment = 0;
442
443search_free:
444 ret = drm_mm_insert_node_in_range_generic(&vma->vm->mm,
445 &vma->node,
446 size, alignment,
447 obj->cache_level,
448 start, end,
449 search_flag,
450 alloc_flag);
451 if (ret) {
452 ret = i915_gem_evict_something(vma->vm, size, alignment,
453 obj->cache_level,
454 start, end,
455 flags);
456 if (ret == 0)
457 goto search_free;
458
459 goto err_unpin;495 goto err_unpin;
460 }
461 496
462 GEM_BUG_ON(vma->node.start < start);497 GEM_BUG_ON(vma->node.start < start);
463 GEM_BUG_ON(vma->node.start + vma->node.size > end);498 GEM_BUG_ON(vma->node.start + vma->node.size > end);
464 }499 }
500 GEM_BUG_ON(!drm_mm_node_allocated(&vma->node));
465 GEM_BUG_ON(!i915_gem_valid_gtt_space(vma, obj->cache_level));501 GEM_BUG_ON(!i915_gem_valid_gtt_space(vma, obj->cache_level));
466 502
467 list_move_tail(&obj->global_link, &dev_priv->mm.bound_list);503 list_move_tail(&obj->global_link, &dev_priv->mm.bound_list);
@@ -504,6 +540,7 @@ int __i915_vma_do_pin(struct i915_vma *vma, · 36 unmodified lines
504 if ((bound ^ vma->flags) & I915_VMA_GLOBAL_BIND)540 if ((bound ^ vma->flags) & I915_VMA_GLOBAL_BIND)
505 __i915_vma_set_map_and_fenceable(vma);541 __i915_vma_set_map_and_fenceable(vma);
506 542
543 GEM_BUG_ON(!drm_mm_node_allocated(&vma->node));
507 GEM_BUG_ON(i915_vma_misplaced(vma, size, alignment, flags));544 GEM_BUG_ON(i915_vma_misplaced(vma, size, alignment, flags));
508 return 0;545 return 0;
509 546
drivers/gpu/drm/i915/i915_vma.h+31−10
@@ -55,6 +55,9 @@ struct i915_vma { · 54 unmodified lines
55 u64 size;55 u64 size;
56 u64 display_alignment;56 u64 display_alignment;
57 57
58 u32 fence_size;
59 u32 fence_alignment;
60
58 unsigned int flags;61 unsigned int flags;
59 /**62 /**
60 * How many users have pinned this object in GTT space. The following63 * How many users have pinned this object in GTT space. The following
@@ -109,9 +112,9 @@ struct i915_vma { · 48 unmodified lines
109};112};
110 113
111struct i915_vma *114struct i915_vma *
112i915_vma_create(struct drm_i915_gem_object *obj,115i915_vma_instance(struct drm_i915_gem_object *obj,
113 struct i915_address_space *vm,116 struct i915_address_space *vm,
114 const struct i915_ggtt_view *view);117 const struct i915_ggtt_view *view);
115 118
116void i915_vma_unpin_and_release(struct i915_vma **p_vma);119void i915_vma_unpin_and_release(struct i915_vma **p_vma);
117 120
@@ -196,15 +199,30 @@ i915_vma_compare(struct i915_vma *vma, · 78 unmodified lines
196 if (cmp)199 if (cmp)
197 return cmp;200 return cmp;
198 201
202 BUILD_BUG_ON(I915_GGTT_VIEW_NORMAL != 0);
203 cmp = vma->ggtt_view.type;
199 if (!view)204 if (!view)
200 return vma->ggtt_view.type;205 return cmp;
201 206
202 if (vma->ggtt_view.type != view->type)207 cmp -= view->type;
203 return vma->ggtt_view.type - view->type;208 if (cmp)
209 return cmp;
204 210
205 return memcmp(&vma->ggtt_view.params,211 /* ggtt_view.type also encodes its size so that we both distinguish
206 &view->params,212 * different views using it as a "type" and also use a compact (no
207 sizeof(view->params));213 * accessing of uninitialised padding bytes) memcmp without storing
214 * an extra parameter or adding more code.
215 *
216 * To ensure that the memcmp is valid for all branches of the union,
217 * even though the code looks like it is just comparing one branch,
218 * we assert above that all branches have the same address, and that
219 * each branch has a unique type/size.
220 */
221 BUILD_BUG_ON(I915_GGTT_VIEW_NORMAL >= I915_GGTT_VIEW_PARTIAL);
222 BUILD_BUG_ON(I915_GGTT_VIEW_PARTIAL >= I915_GGTT_VIEW_ROTATED);
223 BUILD_BUG_ON(offsetof(typeof(*view), rotated) !=
224 offsetof(typeof(*view), partial));
225 return memcmp(&vma->ggtt_view.partial, &view->partial, view->type);
208}226}
209 227
210int i915_vma_bind(struct i915_vma *vma, enum i915_cache_level cache_level,228int i915_vma_bind(struct i915_vma *vma, enum i915_cache_level cache_level,
@@ -229,8 +247,11 @@ i915_vma_pin(struct i915_vma *vma, u64 size, u64 alignment, u64 flags) · 18 unmodified lines
229 /* Pin early to prevent the shrinker/eviction logic from destroying247 /* Pin early to prevent the shrinker/eviction logic from destroying
230 * our vma as we insert and bind.248 * our vma as we insert and bind.
231 */249 */
232 if (likely(((++vma->flags ^ flags) & I915_VMA_BIND_MASK) == 0))250 if (likely(((++vma->flags ^ flags) & I915_VMA_BIND_MASK) == 0)) {
251 GEM_BUG_ON(!drm_mm_node_allocated(&vma->node));
252 GEM_BUG_ON(i915_vma_misplaced(vma, size, alignment, flags));
233 return 0;253 return 0;
254 }
234 255
235 return __i915_vma_do_pin(vma, size, alignment, flags);256 return __i915_vma_do_pin(vma, size, alignment, flags);
236}257}
drivers/gpu/drm/i915/intel_atomic_plane.c+20−0
@@ -85,6 +85,8 @@ intel_plane_duplicate_state(struct drm_plane *plane) · 84 unmodified lines
85 85
86 __drm_atomic_helper_plane_duplicate_state(plane, state);86 __drm_atomic_helper_plane_duplicate_state(plane, state);
87 87
88 intel_state->vma = NULL;
89
88 return state;90 return state;
89}91}
90 92
@@ -100,6 +102,24 @@ void · 9 unmodified lines
100intel_plane_destroy_state(struct drm_plane *plane,102intel_plane_destroy_state(struct drm_plane *plane,
101 struct drm_plane_state *state)103 struct drm_plane_state *state)
102{104{
105 struct i915_vma *vma;
106
107 vma = fetch_and_zero(&to_intel_plane_state(state)->vma);
108
109 /*
110 * FIXME: Normally intel_cleanup_plane_fb handles destruction of vma.
111 * We currently don't clear all planes during driver unload, so we have
112 * to be able to unpin vma here for now.
113 *
114 * Normally this can only happen during unload when kmscon is disabled
115 * and userspace doesn't attempt to set a framebuffer at all.
116 */
117 if (vma) {
118 mutex_lock(&plane->dev->struct_mutex);
119 intel_unpin_fb_vma(vma);
120 mutex_unlock(&plane->dev->struct_mutex);
121 }
122
103 drm_atomic_helper_plane_destroy_state(plane, state);123 drm_atomic_helper_plane_destroy_state(plane, state);
104}124}
105 125
drivers/gpu/drm/i915/intel_csr.c+10−2
@@ -34,6 +34,10 @@ · 33 unmodified lines
34 * low-power state and comes back to normal.34 * low-power state and comes back to normal.
35 */35 */
36 36
37#define I915_CSR_GLK "i915/glk_dmc_ver1_01.bin"
38MODULE_FIRMWARE(I915_CSR_GLK);
39#define GLK_CSR_VERSION_REQUIRED CSR_VERSION(1, 1)
40
37#define I915_CSR_KBL "i915/kbl_dmc_ver1_01.bin"41#define I915_CSR_KBL "i915/kbl_dmc_ver1_01.bin"
38MODULE_FIRMWARE(I915_CSR_KBL);42MODULE_FIRMWARE(I915_CSR_KBL);
39#define KBL_CSR_VERSION_REQUIRED CSR_VERSION(1, 1)43#define KBL_CSR_VERSION_REQUIRED CSR_VERSION(1, 1)
@@ -286,7 +290,9 @@ static uint32_t *parse_csr_fw(struct drm_i915_private *dev_priv, · 246 unmodified lines
286 290
287 csr->version = css_header->version;291 csr->version = css_header->version;
288 292
289 if (IS_KABYLAKE(dev_priv)) {293 if (IS_GEMINILAKE(dev_priv)) {
294 required_version = GLK_CSR_VERSION_REQUIRED;
295 } else if (IS_KABYLAKE(dev_priv)) {
290 required_version = KBL_CSR_VERSION_REQUIRED;296 required_version = KBL_CSR_VERSION_REQUIRED;
291 } else if (IS_SKYLAKE(dev_priv)) {297 } else if (IS_SKYLAKE(dev_priv)) {
292 required_version = SKL_CSR_VERSION_REQUIRED;298 required_version = SKL_CSR_VERSION_REQUIRED;
@@ -435,7 +441,9 @@ void intel_csr_ucode_init(struct drm_i915_private *dev_priv) · 142 unmodified lines
435 if (!HAS_CSR(dev_priv))441 if (!HAS_CSR(dev_priv))
436 return;442 return;
437 443
438 if (IS_KABYLAKE(dev_priv))444 if (IS_GEMINILAKE(dev_priv))
445 csr->fw_path = I915_CSR_GLK;
446 else if (IS_KABYLAKE(dev_priv))
439 csr->fw_path = I915_CSR_KBL;447 csr->fw_path = I915_CSR_KBL;
440 else if (IS_SKYLAKE(dev_priv))448 else if (IS_SKYLAKE(dev_priv))
441 csr->fw_path = I915_CSR_SKL;449 csr->fw_path = I915_CSR_SKL;
drivers/gpu/drm/i915/intel_device_info.c+1−1
@@ -192,7 +192,7 @@ static void gen9_sseu_info_init(struct drm_i915_private *dev_priv) · 191 unmodified lines
192 (IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev_priv)) &&192 (IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev_priv)) &&
193 hweight8(sseu->slice_mask) > 1;193 hweight8(sseu->slice_mask) > 1;
194 sseu->has_subslice_pg =194 sseu->has_subslice_pg =
195 IS_BROXTON(dev_priv) && sseu_subslice_total(sseu) > 1;195 IS_GEN9_LP(dev_priv) && sseu_subslice_total(sseu) > 1;
196 sseu->has_eu_pg = sseu->eu_per_subslice > 2;196 sseu->has_eu_pg = sseu->eu_per_subslice > 2;
197 197
198 if (IS_BROXTON(dev_priv)) {198 if (IS_BROXTON(dev_priv)) {
drivers/gpu/drm/i915/intel_display.c+87−116
@@ -2137,11 +2137,10 @@ intel_fill_fb_ggtt_view(struct i915_ggtt_view *view, · 2136 unmodified lines
2137 const struct drm_framebuffer *fb,2137 const struct drm_framebuffer *fb,
2138 unsigned int rotation)2138 unsigned int rotation)
2139{2139{
2140 view->type = I915_GGTT_VIEW_NORMAL;
2140 if (drm_rotation_90_or_270(rotation)) {2141 if (drm_rotation_90_or_270(rotation)) {
2141 *view = i915_ggtt_view_rotated;2142 view->type = I915_GGTT_VIEW_ROTATED;
2142 view->params.rotated = to_intel_framebuffer(fb)->rot_info;2143 view->rotated = to_intel_framebuffer(fb)->rot_info;
2143 } else {
2144 *view = i915_ggtt_view_normal;
2145 }2144 }
2146}2145}
2147 2146
@@ -2235,24 +2234,19 @@ intel_pin_and_fence_fb_obj(struct drm_framebuffer *fb, unsigned int rotation) · 87 unmodified lines
2235 i915_vma_pin_fence(vma);2234 i915_vma_pin_fence(vma);
2236 }2235 }
2237 2236
2237 i915_vma_get(vma);
2238err:2238err:
2239 intel_runtime_pm_put(dev_priv);2239 intel_runtime_pm_put(dev_priv);
2240 return vma;2240 return vma;
2241}2241}
2242 2242
2243void intel_unpin_fb_obj(struct drm_framebuffer *fb, unsigned int rotation)2243void intel_unpin_fb_vma(struct i915_vma *vma)
2244{2244{
2245 struct drm_i915_gem_object *obj = intel_fb_obj(fb);2245 lockdep_assert_held(&vma->vm->i915->drm.struct_mutex);
2246 struct i915_ggtt_view view;
2247 struct i915_vma *vma;
2248
2249 WARN_ON(!mutex_is_locked(&obj->base.dev->struct_mutex));
2250
2251 intel_fill_fb_ggtt_view(&view, fb, rotation);
2252 vma = i915_gem_object_to_ggtt(obj, &view);
2253 2246
2254 i915_vma_unpin_fence(vma);2247 i915_vma_unpin_fence(vma);
2255 i915_gem_object_unpin_from_display_plane(vma);2248 i915_gem_object_unpin_from_display_plane(vma);
2249 i915_vma_put(vma);
2256}2250}
2257 2251
2258static int intel_fb_pitch(const struct drm_framebuffer *fb, int plane,2252static int intel_fb_pitch(const struct drm_framebuffer *fb, int plane,
@@ -2745,7 +2739,6 @@ intel_find_initial_plane_obj(struct intel_crtc *intel_crtc, · 486 unmodified lines
2745 struct drm_device *dev = intel_crtc->base.dev;2739 struct drm_device *dev = intel_crtc->base.dev;
2746 struct drm_i915_private *dev_priv = to_i915(dev);2740 struct drm_i915_private *dev_priv = to_i915(dev);
2747 struct drm_crtc *c;2741 struct drm_crtc *c;
2748 struct intel_crtc *i;
2749 struct drm_i915_gem_object *obj;2742 struct drm_i915_gem_object *obj;
2750 struct drm_plane *primary = intel_crtc->base.primary;2743 struct drm_plane *primary = intel_crtc->base.primary;
2751 struct drm_plane_state *plane_state = primary->state;2744 struct drm_plane_state *plane_state = primary->state;
@@ -2770,20 +2763,20 @@ intel_find_initial_plane_obj(struct intel_crtc *intel_crtc, · 18 unmodified lines
2770 * an fb with another CRTC instead2763 * an fb with another CRTC instead
2771 */2764 */
2772 for_each_crtc(dev, c) {2765 for_each_crtc(dev, c) {
2773 i = to_intel_crtc(c);2766 struct intel_plane_state *state;
2774 2767
2775 if (c == &intel_crtc->base)2768 if (c == &intel_crtc->base)
2776 continue;2769 continue;
2777 2770
2778 if (!i->active)2771 if (!to_intel_crtc(c)->active)
2779 continue;2772 continue;
2780 2773
2781 fb = c->primary->fb;2774 state = to_intel_plane_state(c->primary->state);
2782 if (!fb)2775 if (!state->vma)
2783 continue;2776 continue;
2784 2777
2785 obj = intel_fb_obj(fb);2778 if (intel_plane_ggtt_offset(state) == plane_config->base) {
2786 if (i915_gem_object_ggtt_offset(obj, NULL) == plane_config->base) {2779 fb = c->primary->fb;
2787 drm_framebuffer_reference(fb);2780 drm_framebuffer_reference(fb);
2788 goto valid_fb;2781 goto valid_fb;
2789 }2782 }
@@ -2796,7 +2789,7 @@ intel_find_initial_plane_obj(struct intel_crtc *intel_crtc, · 6 unmodified lines
2796 * simplest solution is to just disable the primary plane now and2789 * simplest solution is to just disable the primary plane now and
2797 * pretend the BIOS never had it enabled.2790 * pretend the BIOS never had it enabled.
2798 */2791 */
2799 to_intel_plane_state(plane_state)->base.visible = false;2792 plane_state->visible = false;
2800 crtc_state->plane_mask &= ~(1 << drm_plane_index(primary));2793 crtc_state->plane_mask &= ~(1 << drm_plane_index(primary));
2801 intel_pre_disable_primary_noatomic(&intel_crtc->base);2794 intel_pre_disable_primary_noatomic(&intel_crtc->base);
2802 intel_plane->disable_plane(primary, &intel_crtc->base);2795 intel_plane->disable_plane(primary, &intel_crtc->base);
@@ -2804,6 +2797,19 @@ intel_find_initial_plane_obj(struct intel_crtc *intel_crtc, · 1 unmodified line
2804 return;2797 return;
2805 2798
2806valid_fb:2799valid_fb:
2800 mutex_lock(&dev->struct_mutex);
2801 intel_state->vma =
2802 intel_pin_and_fence_fb_obj(fb, primary->state->rotation);
2803 mutex_unlock(&dev->struct_mutex);
2804 if (IS_ERR(intel_state->vma)) {
2805 DRM_ERROR("failed to pin boot fb on pipe %d: %li\n",
2806 intel_crtc->pipe, PTR_ERR(intel_state->vma));
2807
2808 intel_state->vma = NULL;
2809 drm_framebuffer_unreference(fb);
2810 return;
2811 }
2812
2807 plane_state->src_x = 0;2813 plane_state->src_x = 0;
2808 plane_state->src_y = 0;2814 plane_state->src_y = 0;
2809 plane_state->src_w = fb->width << 16;2815 plane_state->src_w = fb->width << 16;
@@ -3099,13 +3105,13 @@ static void i9xx_update_primary_plane(struct drm_plane *primary, · 289 unmodified lines
3099 I915_WRITE(DSPSTRIDE(plane), fb->pitches[0]);3105 I915_WRITE(DSPSTRIDE(plane), fb->pitches[0]);
3100 if (INTEL_GEN(dev_priv) >= 4) {3106 if (INTEL_GEN(dev_priv) >= 4) {
3101 I915_WRITE(DSPSURF(plane),3107 I915_WRITE(DSPSURF(plane),
3102 intel_fb_gtt_offset(fb, rotation) +3108 intel_plane_ggtt_offset(plane_state) +
3103 intel_crtc->dspaddr_offset);3109 intel_crtc->dspaddr_offset);
3104 I915_WRITE(DSPTILEOFF(plane), (y << 16) | x);3110 I915_WRITE(DSPTILEOFF(plane), (y << 16) | x);
3105 I915_WRITE(DSPLINOFF(plane), linear_offset);3111 I915_WRITE(DSPLINOFF(plane), linear_offset);
3106 } else {3112 } else {
3107 I915_WRITE(DSPADDR(plane),3113 I915_WRITE(DSPADDR(plane),
3108 intel_fb_gtt_offset(fb, rotation) +3114 intel_plane_ggtt_offset(plane_state) +
3109 intel_crtc->dspaddr_offset);3115 intel_crtc->dspaddr_offset);
3110 }3116 }
3111 POSTING_READ(reg);3117 POSTING_READ(reg);
@@ -3202,7 +3208,7 @@ static void ironlake_update_primary_plane(struct drm_plane *primary, · 90 unmodified lines
3202 3208
3203 I915_WRITE(DSPSTRIDE(plane), fb->pitches[0]);3209 I915_WRITE(DSPSTRIDE(plane), fb->pitches[0]);
3204 I915_WRITE(DSPSURF(plane),3210 I915_WRITE(DSPSURF(plane),
3205 intel_fb_gtt_offset(fb, rotation) +3211 intel_plane_ggtt_offset(plane_state) +
3206 intel_crtc->dspaddr_offset);3212 intel_crtc->dspaddr_offset);
3207 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {3213 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
3208 I915_WRITE(DSPOFFSET(plane), (y << 16) | x);3214 I915_WRITE(DSPOFFSET(plane), (y << 16) | x);
@@ -3225,23 +3231,6 @@ u32 intel_fb_stride_alignment(const struct drm_i915_private *dev_priv, · 16 unmodified lines
3225 }3231 }
3226}3232}
3227 3233
3228u32 intel_fb_gtt_offset(struct drm_framebuffer *fb,
3229 unsigned int rotation)
3230{
3231 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
3232 struct i915_ggtt_view view;
3233 struct i915_vma *vma;
3234
3235 intel_fill_fb_ggtt_view(&view, fb, rotation);
3236
3237 vma = i915_gem_object_to_ggtt(obj, &view);
3238 if (WARN(!vma, "ggtt vma for display object not found! (view=%u)\n",
3239 view.type))
3240 return -1;
3241
3242 return i915_ggtt_offset(vma);
3243}
3244
3245static void skl_detach_scaler(struct intel_crtc *intel_crtc, int id)3234static void skl_detach_scaler(struct intel_crtc *intel_crtc, int id)
3246{3235{
3247 struct drm_device *dev = intel_crtc->base.dev;3236 struct drm_device *dev = intel_crtc->base.dev;
@@ -3437,7 +3426,7 @@ static void skylake_update_primary_plane(struct drm_plane *plane, · 189 unmodified lines
3437 }3426 }
3438 3427
3439 I915_WRITE(PLANE_SURF(pipe, plane_id),3428 I915_WRITE(PLANE_SURF(pipe, plane_id),
3440 intel_fb_gtt_offset(fb, rotation) + surf_addr);3429 intel_plane_ggtt_offset(plane_state) + surf_addr);
3441 3430
3442 POSTING_READ(PLANE_SURF(pipe, plane_id));3431 POSTING_READ(PLANE_SURF(pipe, plane_id));
3443}3432}
@@ -3561,23 +3550,19 @@ void intel_prepare_reset(struct drm_i915_private *dev_priv) · 117 unmodified lines
3561 state = drm_atomic_helper_duplicate_state(dev, ctx);3550 state = drm_atomic_helper_duplicate_state(dev, ctx);
3562 if (IS_ERR(state)) {3551 if (IS_ERR(state)) {
3563 ret = PTR_ERR(state);3552 ret = PTR_ERR(state);
3564 state = NULL;
3565 DRM_ERROR("Duplicating state failed with %i\n", ret);3553 DRM_ERROR("Duplicating state failed with %i\n", ret);
3566 goto err;3554 return;
3567 }3555 }
3568 3556
3569 ret = drm_atomic_helper_disable_all(dev, ctx);3557 ret = drm_atomic_helper_disable_all(dev, ctx);
3570 if (ret) {3558 if (ret) {
3571 DRM_ERROR("Suspending crtc's failed with %i\n", ret);3559 DRM_ERROR("Suspending crtc's failed with %i\n", ret);
3572 goto err;3560 drm_atomic_state_put(state);
3561 return;
3573 }3562 }
3574 3563
3575 dev_priv->modeset_restore_state = state;3564 dev_priv->modeset_restore_state = state;
3576 state->acquire_ctx = ctx;3565 state->acquire_ctx = ctx;
3577 return;
3578
3579err:
3580 drm_atomic_state_put(state);
3581}3566}
3582 3567
3583void intel_finish_reset(struct drm_i915_private *dev_priv)3568void intel_finish_reset(struct drm_i915_private *dev_priv)
@@ -6886,13 +6871,13 @@ static void intel_crtc_disable_noatomic(struct drm_crtc *crtc) · 3302 unmodified lines
6886 if (!intel_crtc->active)6871 if (!intel_crtc->active)
6887 return;6872 return;
6888 6873
6889 if (to_intel_plane_state(crtc->primary->state)->base.visible) {6874 if (crtc->primary->state->visible) {
6890 WARN_ON(intel_crtc->flip_work);6875 WARN_ON(intel_crtc->flip_work);
6891 6876
6892 intel_pre_disable_primary_noatomic(crtc);6877 intel_pre_disable_primary_noatomic(crtc);
6893 6878
6894 intel_crtc_disable_planes(crtc, 1 << drm_plane_index(crtc->primary));6879 intel_crtc_disable_planes(crtc, 1 << drm_plane_index(crtc->primary));
6895 to_intel_plane_state(crtc->primary->state)->base.visible = false;6880 crtc->primary->state->visible = false;
6896 }6881 }
6897 6882
6898 state = drm_atomic_state_alloc(crtc->dev);6883 state = drm_atomic_state_alloc(crtc->dev);
@@ -8406,7 +8391,6 @@ void intel_mode_from_pipe_config(struct drm_display_mode *mode, · 1507 unmodified lines
8406 mode->type = DRM_MODE_TYPE_DRIVER;8391 mode->type = DRM_MODE_TYPE_DRIVER;
8407 8392
8408 mode->clock = pipe_config->base.adjusted_mode.crtc_clock;8393 mode->clock = pipe_config->base.adjusted_mode.crtc_clock;
8409 mode->flags |= pipe_config->base.adjusted_mode.flags;
8410 8394
8411 mode->hsync = drm_mode_hsync(mode);8395 mode->hsync = drm_mode_hsync(mode);
8412 mode->vrefresh = drm_mode_vrefresh(mode);8396 mode->vrefresh = drm_mode_vrefresh(mode);
@@ -11291,6 +11275,7 @@ found: · 2878 unmodified lines
11291 }11275 }
11292 11276
11293 old->restore_state = restore_state;11277 old->restore_state = restore_state;
11278 drm_atomic_state_put(state);
11294 11279
11295 /* let the connector get through one full cycle before testing */11280 /* let the connector get through one full cycle before testing */
11296 intel_wait_for_vblank(dev_priv, intel_crtc->pipe);11281 intel_wait_for_vblank(dev_priv, intel_crtc->pipe);
@@ -11570,7 +11555,7 @@ static void intel_unpin_work_fn(struct work_struct *__work) · 273 unmodified lines
11570 flush_work(&work->mmio_work);11555 flush_work(&work->mmio_work);
11571 11556
11572 mutex_lock(&dev->struct_mutex);11557 mutex_lock(&dev->struct_mutex);
11573 intel_unpin_fb_obj(work->old_fb, primary->state->rotation);11558 intel_unpin_fb_vma(work->old_vma);
11574 i915_gem_object_put(work->pending_flip_obj);11559 i915_gem_object_put(work->pending_flip_obj);
11575 mutex_unlock(&dev->struct_mutex);11560 mutex_unlock(&dev->struct_mutex);
11576 11561
@@ -12280,8 +12265,10 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc, · 703 unmodified lines
12280 goto cleanup_pending;12265 goto cleanup_pending;
12281 }12266 }
12282 12267
12283 work->gtt_offset = intel_fb_gtt_offset(fb, primary->state->rotation);12268 work->old_vma = to_intel_plane_state(primary->state)->vma;
12284 work->gtt_offset += intel_crtc->dspaddr_offset;12269 to_intel_plane_state(primary->state)->vma = vma;
12270
12271 work->gtt_offset = i915_ggtt_offset(vma) + intel_crtc->dspaddr_offset;
12285 work->rotation = crtc->primary->state->rotation;12272 work->rotation = crtc->primary->state->rotation;
12286 12273
12287 /*12274 /*
@@ -12336,7 +12323,8 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc, · 48 unmodified lines
12336cleanup_request:12323cleanup_request:
12337 i915_add_request_no_flush(request);12324 i915_add_request_no_flush(request);
12338cleanup_unpin:12325cleanup_unpin:
12339 intel_unpin_fb_obj(fb, crtc->primary->state->rotation);12326 to_intel_plane_state(primary->state)->vma = work->old_vma;
12327 intel_unpin_fb_vma(vma);
12340cleanup_pending:12328cleanup_pending:
12341 atomic_dec(&intel_crtc->unpin_work_count);12329 atomic_dec(&intel_crtc->unpin_work_count);
12342unlock:12330unlock:
@@ -12466,7 +12454,7 @@ int intel_plane_atomic_calc_changes(struct drm_crtc_state *crtc_state, · 123 unmodified lines
12466 }12454 }
12467 12455
12468 was_visible = old_plane_state->base.visible;12456 was_visible = old_plane_state->base.visible;
12469 visible = to_intel_plane_state(plane_state)->base.visible;12457 visible = plane_state->visible;
12470 12458
12471 if (!was_crtc_enabled && WARN_ON(was_visible))12459 if (!was_crtc_enabled && WARN_ON(was_visible))
12472 was_visible = false;12460 was_visible = false;
@@ -12482,7 +12470,7 @@ int intel_plane_atomic_calc_changes(struct drm_crtc_state *crtc_state, · 9 unmodified lines
12482 * only combine the results from all planes in the current place?12470 * only combine the results from all planes in the current place?
12483 */12471 */
12484 if (!is_crtc_enabled)12472 if (!is_crtc_enabled)
12485 to_intel_plane_state(plane_state)->base.visible = visible = false;12473 plane_state->visible = visible = false;
12486 12474
12487 if (!was_visible && !visible)12475 if (!was_visible && !visible)
12488 return 0;12476 return 0;
@@ -14740,6 +14728,7 @@ static const struct drm_crtc_funcs intel_crtc_funcs = { · 2251 unmodified lines
14740 .page_flip = intel_crtc_page_flip,14728 .page_flip = intel_crtc_page_flip,
14741 .atomic_duplicate_state = intel_crtc_duplicate_state,14729 .atomic_duplicate_state = intel_crtc_duplicate_state,
14742 .atomic_destroy_state = intel_crtc_destroy_state,14730 .atomic_destroy_state = intel_crtc_destroy_state,
14731 .set_crc_source = intel_crtc_set_crc_source,
14743};14732};
14744 14733
14745/**14734/**
@@ -14836,6 +14825,8 @@ intel_prepare_plane_fb(struct drm_plane *plane, · 90 unmodified lines
14836 DRM_DEBUG_KMS("failed to pin object\n");14825 DRM_DEBUG_KMS("failed to pin object\n");
14837 return PTR_ERR(vma);14826 return PTR_ERR(vma);
14838 }14827 }
14828
14829 to_intel_plane_state(new_state)->vma = vma;
14839 }14830 }
14840 14831
14841 return 0;14832 return 0;
@@ -14854,19 +14845,12 @@ void · 12 unmodified lines
14854intel_cleanup_plane_fb(struct drm_plane *plane,14845intel_cleanup_plane_fb(struct drm_plane *plane,
14855 struct drm_plane_state *old_state)14846 struct drm_plane_state *old_state)
14856{14847{
14857 struct drm_i915_private *dev_priv = to_i915(plane->dev);14848 struct i915_vma *vma;
14858 struct intel_plane_state *old_intel_state;
14859 struct drm_i915_gem_object *old_obj = intel_fb_obj(old_state->fb);
14860 struct drm_i915_gem_object *obj = intel_fb_obj(plane->state->fb);
14861
14862 old_intel_state = to_intel_plane_state(old_state);
14863
14864 if (!obj && !old_obj)
14865 return;
14866 14849
14867 if (old_obj && (plane->type != DRM_PLANE_TYPE_CURSOR ||14850 /* Should only be called after a successful intel_prepare_plane_fb()! */
14868 !INTEL_INFO(dev_priv)->cursor_needs_physical))14851 vma = fetch_and_zero(&to_intel_plane_state(old_state)->vma);
14869 intel_unpin_fb_obj(old_state->fb, old_state->rotation);14852 if (vma)
14853 intel_unpin_fb_vma(vma);
14870}14854}
14871 14855
14872int14856int
@@ -15018,6 +15002,7 @@ intel_legacy_cursor_update(struct drm_plane *plane, · 145 unmodified lines
15018 struct intel_plane *intel_plane = to_intel_plane(plane);15002 struct intel_plane *intel_plane = to_intel_plane(plane);
15019 struct drm_framebuffer *old_fb;15003 struct drm_framebuffer *old_fb;
15020 struct drm_crtc_state *crtc_state = crtc->state;15004 struct drm_crtc_state *crtc_state = crtc->state;
15005 struct i915_vma *old_vma;
15021 15006
15022 /*15007 /*
15023 * When crtc is inactive or there is a modeset pending,15008 * When crtc is inactive or there is a modeset pending,
@@ -15089,9 +15074,12 @@ intel_legacy_cursor_update(struct drm_plane *plane, · 65 unmodified lines
15089 ret = PTR_ERR(vma);15074 ret = PTR_ERR(vma);
15090 goto out_unlock;15075 goto out_unlock;
15091 }15076 }
15077
15078 to_intel_plane_state(new_plane_state)->vma = vma;
15092 }15079 }
15093 15080
15094 old_fb = old_plane_state->fb;15081 old_fb = old_plane_state->fb;
15082 old_vma = to_intel_plane_state(old_plane_state)->vma;
15095 15083
15096 i915_gem_track_fb(intel_fb_obj(old_fb), intel_fb_obj(fb),15084 i915_gem_track_fb(intel_fb_obj(old_fb), intel_fb_obj(fb),
15097 intel_plane->frontbuffer_bit);15085 intel_plane->frontbuffer_bit);
@@ -15101,6 +15089,7 @@ intel_legacy_cursor_update(struct drm_plane *plane, · 3 unmodified lines
15101 *to_intel_plane_state(old_plane_state) = *to_intel_plane_state(new_plane_state);15089 *to_intel_plane_state(old_plane_state) = *to_intel_plane_state(new_plane_state);
15102 new_plane_state->fence = NULL;15090 new_plane_state->fence = NULL;
15103 new_plane_state->fb = old_fb;15091 new_plane_state->fb = old_fb;
15092 to_intel_plane_state(new_plane_state)->vma = old_vma;
15104 15093
15105 intel_plane->update_plane(plane,15094 intel_plane->update_plane(plane,
15106 to_intel_crtc_state(crtc->state),15095 to_intel_crtc_state(crtc->state),
@@ -15339,7 +15328,7 @@ intel_update_cursor_plane(struct drm_plane *plane, · 232 unmodified lines
15339 if (!obj)15328 if (!obj)
15340 addr = 0;15329 addr = 0;
15341 else if (!INTEL_INFO(dev_priv)->cursor_needs_physical)15330 else if (!INTEL_INFO(dev_priv)->cursor_needs_physical)
15342 addr = i915_gem_object_ggtt_offset(obj, NULL);15331 addr = intel_plane_ggtt_offset(state);
15343 else15332 else
15344 addr = obj->phys_handle->busaddr;15333 addr = obj->phys_handle->busaddr;
15345 15334
@@ -16843,7 +16832,7 @@ static void intel_sanitize_crtc(struct intel_crtc *crtc) · 1497 unmodified lines
16843 * Temporarily change the plane mapping and disable everything16832 * Temporarily change the plane mapping and disable everything
16844 * ... */16833 * ... */
16845 plane = crtc->plane;16834 plane = crtc->plane;
16846 to_intel_plane_state(crtc->base.primary->state)->base.visible = true;16835 crtc->base.primary->state->visible = true;
16847 crtc->plane = !plane;16836 crtc->plane = !plane;
16848 intel_crtc_disable_noatomic(&crtc->base);16837 intel_crtc_disable_noatomic(&crtc->base);
16849 crtc->plane = plane;16838 crtc->plane = plane;
@@ -16995,7 +16984,8 @@ static void intel_modeset_readout_hw_state(struct drm_device *dev) · 145 unmodified lines
16995 dev_priv->active_crtcs = 0;16984 dev_priv->active_crtcs = 0;
16996 16985
16997 for_each_intel_crtc(dev, crtc) {16986 for_each_intel_crtc(dev, crtc) {
16998 struct intel_crtc_state *crtc_state = crtc->config;16987 struct intel_crtc_state *crtc_state =
16988 to_intel_crtc_state(crtc->base.state);
16999 16989
17000 __drm_atomic_helper_crtc_destroy_state(&crtc_state->base);16990 __drm_atomic_helper_crtc_destroy_state(&crtc_state->base);
17001 memset(crtc_state, 0, sizeof(*crtc_state));16991 memset(crtc_state, 0, sizeof(*crtc_state));
@@ -17014,7 +17004,7 @@ static void intel_modeset_readout_hw_state(struct drm_device *dev) · 12 unmodified lines
17014 17004
17015 DRM_DEBUG_KMS("[CRTC:%d:%s] hw state readout: %s\n",17005 DRM_DEBUG_KMS("[CRTC:%d:%s] hw state readout: %s\n",
17016 crtc->base.base.id, crtc->base.name,17006 crtc->base.base.id, crtc->base.name,
17017 enableddisabled(crtc->active));17007 enableddisabled(crtc_state->base.active));
17018 }17008 }
17019 17009
17020 for (i = 0; i < dev_priv->num_shared_dpll; i++) {17010 for (i = 0; i < dev_priv->num_shared_dpll; i++) {
@@ -17024,7 +17014,11 @@ static void intel_modeset_readout_hw_state(struct drm_device *dev) · 3 unmodified lines
17024 &pll->state.hw_state);17014 &pll->state.hw_state);
17025 pll->state.crtc_mask = 0;17015 pll->state.crtc_mask = 0;
17026 for_each_intel_crtc(dev, crtc) {17016 for_each_intel_crtc(dev, crtc) {
17027 if (crtc->active && crtc->config->shared_dpll == pll)17017 struct intel_crtc_state *crtc_state =
17018 to_intel_crtc_state(crtc->base.state);
17019
17020 if (crtc_state->base.active &&
17021 crtc_state->shared_dpll == pll)
17028 pll->state.crtc_mask |= 1 << crtc->pipe;17022 pll->state.crtc_mask |= 1 << crtc->pipe;
17029 }17023 }
17030 pll->active_mask = pll->state.crtc_mask;17024 pll->active_mask = pll->state.crtc_mask;
@@ -17037,11 +17031,14 @@ static void intel_modeset_readout_hw_state(struct drm_device *dev) · 6 unmodified lines
17037 pipe = 0;17031 pipe = 0;
17038 17032
17039 if (encoder->get_hw_state(encoder, &pipe)) {17033 if (encoder->get_hw_state(encoder, &pipe)) {
17034 struct intel_crtc_state *crtc_state;
17035
17040 crtc = intel_get_crtc_for_pipe(dev_priv, pipe);17036 crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
17037 crtc_state = to_intel_crtc_state(crtc->base.state);
17041 17038
17042 encoder->base.crtc = &crtc->base;17039 encoder->base.crtc = &crtc->base;
17043 crtc->config->output_types |= 1 << encoder->type;17040 crtc_state->output_types |= 1 << encoder->type;
17044 encoder->get_config(encoder, crtc->config);17041 encoder->get_config(encoder, crtc_state);
17045 } else {17042 } else {
17046 encoder->base.crtc = NULL;17043 encoder->base.crtc = NULL;
17047 }17044 }
@@ -17082,14 +17079,16 @@ static void intel_modeset_readout_hw_state(struct drm_device *dev) · 34 unmodified lines
17082 }17079 }
17083 17080
17084 for_each_intel_crtc(dev, crtc) {17081 for_each_intel_crtc(dev, crtc) {
17082 struct intel_crtc_state *crtc_state =
17083 to_intel_crtc_state(crtc->base.state);
17085 int pixclk = 0;17084 int pixclk = 0;
17086 17085
17087 crtc->base.hwmode = crtc->config->base.adjusted_mode;17086 crtc->base.hwmode = crtc_state->base.adjusted_mode;
17088 17087
17089 memset(&crtc->base.mode, 0, sizeof(crtc->base.mode));17088 memset(&crtc->base.mode, 0, sizeof(crtc->base.mode));
17090 if (crtc->base.state->active) {17089 if (crtc_state->base.active) {
17091 intel_mode_from_pipe_config(&crtc->base.mode, crtc->config);17090 intel_mode_from_pipe_config(&crtc->base.mode, crtc_state);
17092 intel_mode_from_pipe_config(&crtc->base.state->adjusted_mode, crtc->config);17091 intel_mode_from_pipe_config(&crtc_state->base.adjusted_mode, crtc_state);
17093 WARN_ON(drm_atomic_set_mode_for_crtc(crtc->base.state, &crtc->base.mode));17092 WARN_ON(drm_atomic_set_mode_for_crtc(crtc->base.state, &crtc->base.mode));
17094 17093
17095 /*17094 /*
@@ -17101,17 +17100,17 @@ static void intel_modeset_readout_hw_state(struct drm_device *dev) · 5 unmodified lines
17101 * set a flag to indicate that a full recalculation is17100 * set a flag to indicate that a full recalculation is
17102 * needed on the next commit.17101 * needed on the next commit.
17103 */17102 */
17104 crtc->base.state->mode.private_flags = I915_MODE_FLAG_INHERITED;17103 crtc_state->base.mode.private_flags = I915_MODE_FLAG_INHERITED;
17105 17104
17106 if (INTEL_GEN(dev_priv) >= 9 || IS_BROADWELL(dev_priv))17105 if (INTEL_GEN(dev_priv) >= 9 || IS_BROADWELL(dev_priv))
17107 pixclk = ilk_pipe_pixel_rate(crtc->config);17106 pixclk = ilk_pipe_pixel_rate(crtc_state);
17108 else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))17107 else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
17109 pixclk = crtc->config->base.adjusted_mode.crtc_clock;17108 pixclk = crtc_state->base.adjusted_mode.crtc_clock;
17110 else17109 else
17111 WARN_ON(dev_priv->display.modeset_calc_cdclk);17110 WARN_ON(dev_priv->display.modeset_calc_cdclk);
17112 17111
17113 /* pixel rate mustn't exceed 95% of cdclk with IPS on BDW */17112 /* pixel rate mustn't exceed 95% of cdclk with IPS on BDW */
17114 if (IS_BROADWELL(dev_priv) && crtc->config->ips_enabled)17113 if (IS_BROADWELL(dev_priv) && crtc_state->ips_enabled)
17115 pixclk = DIV_ROUND_UP(pixclk * 100, 95);17114 pixclk = DIV_ROUND_UP(pixclk * 100, 95);
17116 17115
17117 drm_calc_timestamping_constants(&crtc->base, &crtc->base.hwmode);17116 drm_calc_timestamping_constants(&crtc->base, &crtc->base.hwmode);
@@ -17120,7 +17119,7 @@ static void intel_modeset_readout_hw_state(struct drm_device *dev) · 2 unmodified lines
17120 17119
17121 dev_priv->min_pixclk[crtc->pipe] = pixclk;17120 dev_priv->min_pixclk[crtc->pipe] = pixclk;
17122 17121
17123 intel_pipe_config_sanity_check(dev_priv, crtc->config);17122 intel_pipe_config_sanity_check(dev_priv, crtc_state);
17124 }17123 }
17125}17124}
17126 17125
@@ -17221,47 +17220,19 @@ void intel_display_resume(struct drm_device *dev) · 94 unmodified lines
17221 17220
17222 if (ret)17221 if (ret)
17223 DRM_ERROR("Restoring old state failed with %i\n", ret);17222 DRM_ERROR("Restoring old state failed with %i\n", ret);
17224 drm_atomic_state_put(state);17223 if (state)
17224 drm_atomic_state_put(state);
17225}17225}
17226 17226
17227void intel_modeset_gem_init(struct drm_device *dev)17227void intel_modeset_gem_init(struct drm_device *dev)
17228{17228{
17229 struct drm_i915_private *dev_priv = to_i915(dev);17229 struct drm_i915_private *dev_priv = to_i915(dev);
17230 struct drm_crtc *c;
17231 struct drm_i915_gem_object *obj;
17232 17230
17233 intel_init_gt_powersave(dev_priv);17231 intel_init_gt_powersave(dev_priv);
17234 17232
17235 intel_modeset_init_hw(dev);17233 intel_modeset_init_hw(dev);
17236 17234
17237 intel_setup_overlay(dev_priv);17235 intel_setup_overlay(dev_priv);
17238
17239 /*
17240 * Make sure any fbs we allocated at startup are properly
17241 * pinned & fenced. When we do the allocation it's too early
17242 * for this.
17243 */
17244 for_each_crtc(dev, c) {
17245 struct i915_vma *vma;
17246
17247 obj = intel_fb_obj(c->primary->fb);
17248 if (obj == NULL)
17249 continue;
17250
17251 mutex_lock(&dev->struct_mutex);
17252 vma = intel_pin_and_fence_fb_obj(c->primary->fb,
17253 c->primary->state->rotation);
17254 mutex_unlock(&dev->struct_mutex);
17255 if (IS_ERR(vma)) {
17256 DRM_ERROR("failed to pin boot fb on pipe %d\n",
17257 to_intel_crtc(c)->pipe);
17258 drm_framebuffer_unreference(c->primary->fb);
17259 c->primary->fb = NULL;
17260 c->primary->crtc = c->primary->state->crtc = NULL;
17261 update_state_fb(c->primary);
17262 c->state->plane_mask &= ~(1 << drm_plane_index(c->primary));
17263 }
17264 }
17265}17236}
17266 17237
17267int intel_connector_register(struct drm_connector *connector)17238int intel_connector_register(struct drm_connector *connector)
drivers/gpu/drm/i915/intel_dp.c+37−1
@@ -3042,6 +3042,32 @@ intel_dp_get_link_status(struct intel_dp *intel_dp, uint8_t link_status[DP_LINK_ · 3041 unmodified lines
3042 DP_LINK_STATUS_SIZE) == DP_LINK_STATUS_SIZE;3042 DP_LINK_STATUS_SIZE) == DP_LINK_STATUS_SIZE;
3043}3043}
3044 3044
3045static bool intel_dp_get_y_cord_status(struct intel_dp *intel_dp)
3046{
3047 uint8_t psr_caps = 0;
3048
3049 drm_dp_dpcd_readb(&intel_dp->aux, DP_PSR_CAPS, &psr_caps);
3050 return psr_caps & DP_PSR2_SU_Y_COORDINATE_REQUIRED;
3051}
3052
3053static bool intel_dp_get_colorimetry_status(struct intel_dp *intel_dp)
3054{
3055 uint8_t dprx = 0;
3056
3057 drm_dp_dpcd_readb(&intel_dp->aux,
3058 DP_DPRX_FEATURE_ENUMERATION_LIST,
3059 &dprx);
3060 return dprx & DP_VSC_SDP_EXT_FOR_COLORIMETRY_SUPPORTED;
3061}
3062
3063static bool intel_dp_get_alpm_status(struct intel_dp *intel_dp)
3064{
3065 uint8_t alpm_caps = 0;
3066
3067 drm_dp_dpcd_readb(&intel_dp->aux, DP_RECEIVER_ALPM_CAP, &alpm_caps);
3068 return alpm_caps & DP_ALPM_CAP;
3069}
3070
3045/* These are source-specific values. */3071/* These are source-specific values. */
3046uint8_t3072uint8_t
3047intel_dp_voltage_max(struct intel_dp *intel_dp)3073intel_dp_voltage_max(struct intel_dp *intel_dp)
@@ -3412,7 +3438,7 @@ intel_dp_set_signal_levels(struct intel_dp *intel_dp) · 364 unmodified lines
3412 if (HAS_DDI(dev_priv)) {3438 if (HAS_DDI(dev_priv)) {
3413 signal_levels = ddi_signal_levels(intel_dp);3439 signal_levels = ddi_signal_levels(intel_dp);
3414 3440
3415 if (IS_BROXTON(dev_priv))3441 if (IS_GEN9_LP(dev_priv))
3416 signal_levels = 0;3442 signal_levels = 0;
3417 else3443 else
3418 mask = DDI_BUF_EMP_MASK;3444 mask = DDI_BUF_EMP_MASK;
@@ -3620,6 +3646,16 @@ intel_edp_init_dpcd(struct intel_dp *intel_dp) · 201 unmodified lines
3620 dev_priv->psr.psr2_support = dev_priv->psr.aux_frame_sync;3646 dev_priv->psr.psr2_support = dev_priv->psr.aux_frame_sync;
3621 DRM_DEBUG_KMS("PSR2 %s on sink",3647 DRM_DEBUG_KMS("PSR2 %s on sink",
3622 dev_priv->psr.psr2_support ? "supported" : "not supported");3648 dev_priv->psr.psr2_support ? "supported" : "not supported");
3649
3650 if (dev_priv->psr.psr2_support) {
3651 dev_priv->psr.y_cord_support =
3652 intel_dp_get_y_cord_status(intel_dp);
3653 dev_priv->psr.colorimetry_support =
3654 intel_dp_get_colorimetry_status(intel_dp);
3655 dev_priv->psr.alpm =
3656 intel_dp_get_alpm_status(intel_dp);
3657 }
3658
3623 }3659 }
3624 3660
3625 /* Read the eDP Display control capabilities registers */3661 /* Read the eDP Display control capabilities registers */
drivers/gpu/drm/i915/intel_drv.h+13−2
@@ -376,6 +376,7 @@ struct intel_atomic_state { · 375 unmodified lines
376struct intel_plane_state {376struct intel_plane_state {
377 struct drm_plane_state base;377 struct drm_plane_state base;
378 struct drm_rect clip;378 struct drm_rect clip;
379 struct i915_vma *vma;
379 380
380 struct {381 struct {
381 u32 offset;382 u32 offset;
@@ -1067,6 +1068,7 @@ struct intel_flip_work { · 685 unmodified lines
1067 struct work_struct mmio_work;1068 struct work_struct mmio_work;
1068 1069
1069 struct drm_crtc *crtc;1070 struct drm_crtc *crtc;
1071 struct i915_vma *old_vma;
1070 struct drm_framebuffer *old_fb;1072 struct drm_framebuffer *old_fb;
1071 struct drm_i915_gem_object *pending_flip_obj;1073 struct drm_i915_gem_object *pending_flip_obj;
1072 struct drm_pending_vblank_event *event;1074 struct drm_pending_vblank_event *event;
@@ -1302,7 +1304,7 @@ void intel_release_load_detect_pipe(struct drm_connector *connector, · 229 unmodified lines
1302 struct drm_modeset_acquire_ctx *ctx);1304 struct drm_modeset_acquire_ctx *ctx);
1303struct i915_vma *1305struct i915_vma *
1304intel_pin_and_fence_fb_obj(struct drm_framebuffer *fb, unsigned int rotation);1306intel_pin_and_fence_fb_obj(struct drm_framebuffer *fb, unsigned int rotation);
1305void intel_unpin_fb_obj(struct drm_framebuffer *fb, unsigned int rotation);1307void intel_unpin_fb_vma(struct i915_vma *vma);
1306struct drm_framebuffer *1308struct drm_framebuffer *
1307__intel_framebuffer_create(struct drm_device *dev,1309__intel_framebuffer_create(struct drm_device *dev,
1308 struct drm_mode_fb_cmd2 *mode_cmd,1310 struct drm_mode_fb_cmd2 *mode_cmd,
@@ -1391,7 +1393,10 @@ void intel_mode_from_pipe_config(struct drm_display_mode *mode, · 82 unmodified lines
1391int skl_update_scaler_crtc(struct intel_crtc_state *crtc_state);1393int skl_update_scaler_crtc(struct intel_crtc_state *crtc_state);
1392int skl_max_scale(struct intel_crtc *crtc, struct intel_crtc_state *crtc_state);1394int skl_max_scale(struct intel_crtc *crtc, struct intel_crtc_state *crtc_state);
1393 1395
1394u32 intel_fb_gtt_offset(struct drm_framebuffer *fb, unsigned int rotation);1396static inline u32 intel_plane_ggtt_offset(const struct intel_plane_state *state)
1397{
1398 return i915_ggtt_offset(state->vma);
1399}
1395 1400
1396u32 skl_plane_ctl_format(uint32_t pixel_format);1401u32 skl_plane_ctl_format(uint32_t pixel_format);
1397u32 skl_plane_ctl_tiling(uint64_t fb_modifier);1402u32 skl_plane_ctl_tiling(uint64_t fb_modifier);
@@ -1880,5 +1885,11 @@ void lspcon_wait_pcon_mode(struct intel_lspcon *lspcon); · 482 unmodified lines
1880/* intel_pipe_crc.c */1885/* intel_pipe_crc.c */
1881int intel_pipe_crc_create(struct drm_minor *minor);1886int intel_pipe_crc_create(struct drm_minor *minor);
1882void intel_pipe_crc_cleanup(struct drm_minor *minor);1887void intel_pipe_crc_cleanup(struct drm_minor *minor);
1888#ifdef CONFIG_DEBUG_FS
1889int intel_crtc_set_crc_source(struct drm_crtc *crtc, const char *source_name,
1890 size_t *values_cnt);
1891#else
1892#define intel_crtc_set_crc_source NULL
1893#endif
1883extern const struct file_operations i915_display_crc_ctl_fops;1894extern const struct file_operations i915_display_crc_ctl_fops;
1884#endif /* __INTEL_DRV_H__ */1895#endif /* __INTEL_DRV_H__ */
drivers/gpu/drm/i915/intel_engine_cs.c+1−1
@@ -264,7 +264,7 @@ int intel_engine_create_scratch(struct intel_engine_cs *engine, int size) · 263 unmodified lines
264 return PTR_ERR(obj);264 return PTR_ERR(obj);
265 }265 }
266 266
267 vma = i915_vma_create(obj, &engine->i915->ggtt.base, NULL);267 vma = i915_vma_instance(obj, &engine->i915->ggtt.base, NULL);
268 if (IS_ERR(vma)) {268 if (IS_ERR(vma)) {
269 ret = PTR_ERR(vma);269 ret = PTR_ERR(vma);
270 goto err_unref;270 goto err_unref;
drivers/gpu/drm/i915/intel_fbc.c+21−33
@@ -173,7 +173,7 @@ static void i8xx_fbc_activate(struct drm_i915_private *dev_priv) · 172 unmodified lines
173 if (IS_I945GM(dev_priv))173 if (IS_I945GM(dev_priv))
174 fbc_ctl |= FBC_CTL_C3_IDLE; /* 945 needs special SR handling */174 fbc_ctl |= FBC_CTL_C3_IDLE; /* 945 needs special SR handling */
175 fbc_ctl |= (cfb_pitch & 0xff) << FBC_CTL_STRIDE_SHIFT;175 fbc_ctl |= (cfb_pitch & 0xff) << FBC_CTL_STRIDE_SHIFT;
176 fbc_ctl |= params->fb.fence_reg;176 fbc_ctl |= params->vma->fence->id;
177 I915_WRITE(FBC_CONTROL, fbc_ctl);177 I915_WRITE(FBC_CONTROL, fbc_ctl);
178}178}
179 179
@@ -193,8 +193,8 @@ static void g4x_fbc_activate(struct drm_i915_private *dev_priv) · 13 unmodified lines
193 else193 else
194 dpfc_ctl |= DPFC_CTL_LIMIT_1X;194 dpfc_ctl |= DPFC_CTL_LIMIT_1X;
195 195
196 if (params->fb.fence_reg != I915_FENCE_REG_NONE) {196 if (params->vma->fence) {
197 dpfc_ctl |= DPFC_CTL_FENCE_EN | params->fb.fence_reg;197 dpfc_ctl |= DPFC_CTL_FENCE_EN | params->vma->fence->id;
198 I915_WRITE(DPFC_FENCE_YOFF, params->crtc.fence_y_offset);198 I915_WRITE(DPFC_FENCE_YOFF, params->crtc.fence_y_offset);
199 } else {199 } else {
200 I915_WRITE(DPFC_FENCE_YOFF, 0);200 I915_WRITE(DPFC_FENCE_YOFF, 0);
@@ -251,13 +251,14 @@ static void ilk_fbc_activate(struct drm_i915_private *dev_priv) · 50 unmodified lines
251 break;251 break;
252 }252 }
253 253
254 if (params->fb.fence_reg != I915_FENCE_REG_NONE) {254 if (params->vma->fence) {
255 dpfc_ctl |= DPFC_CTL_FENCE_EN;255 dpfc_ctl |= DPFC_CTL_FENCE_EN;
256 if (IS_GEN5(dev_priv))256 if (IS_GEN5(dev_priv))
257 dpfc_ctl |= params->fb.fence_reg;257 dpfc_ctl |= params->vma->fence->id;
258 if (IS_GEN6(dev_priv)) {258 if (IS_GEN6(dev_priv)) {
259 I915_WRITE(SNB_DPFC_CTL_SA,259 I915_WRITE(SNB_DPFC_CTL_SA,
260 SNB_CPU_FENCE_ENABLE | params->fb.fence_reg);260 SNB_CPU_FENCE_ENABLE |
261 params->vma->fence->id);
261 I915_WRITE(DPFC_CPU_FENCE_OFFSET,262 I915_WRITE(DPFC_CPU_FENCE_OFFSET,
262 params->crtc.fence_y_offset);263 params->crtc.fence_y_offset);
263 }264 }
@@ -269,7 +270,8 @@ static void ilk_fbc_activate(struct drm_i915_private *dev_priv) · 5 unmodified lines
269 }270 }
270 271
271 I915_WRITE(ILK_DPFC_FENCE_YOFF, params->crtc.fence_y_offset);272 I915_WRITE(ILK_DPFC_FENCE_YOFF, params->crtc.fence_y_offset);
272 I915_WRITE(ILK_FBC_RT_BASE, params->fb.ggtt_offset | ILK_FBC_RT_VALID);273 I915_WRITE(ILK_FBC_RT_BASE,
274 i915_ggtt_offset(params->vma) | ILK_FBC_RT_VALID);
273 /* enable it... */275 /* enable it... */
274 I915_WRITE(ILK_DPFC_CONTROL, dpfc_ctl | DPFC_CTL_EN);276 I915_WRITE(ILK_DPFC_CONTROL, dpfc_ctl | DPFC_CTL_EN);
275 277
@@ -319,10 +321,11 @@ static void gen7_fbc_activate(struct drm_i915_private *dev_priv) · 43 unmodified lines
319 break;321 break;
320 }322 }
321 323
322 if (params->fb.fence_reg != I915_FENCE_REG_NONE) {324 if (params->vma->fence) {
323 dpfc_ctl |= IVB_DPFC_CTL_FENCE_EN;325 dpfc_ctl |= IVB_DPFC_CTL_FENCE_EN;
324 I915_WRITE(SNB_DPFC_CTL_SA,326 I915_WRITE(SNB_DPFC_CTL_SA,
325 SNB_CPU_FENCE_ENABLE | params->fb.fence_reg);327 SNB_CPU_FENCE_ENABLE |
328 params->vma->fence->id);
326 I915_WRITE(DPFC_CPU_FENCE_OFFSET, params->crtc.fence_y_offset);329 I915_WRITE(DPFC_CPU_FENCE_OFFSET, params->crtc.fence_y_offset);
327 } else {330 } else {
328 I915_WRITE(SNB_DPFC_CTL_SA,0);331 I915_WRITE(SNB_DPFC_CTL_SA,0);
@@ -727,14 +730,6 @@ static bool intel_fbc_hw_tracking_covers_screen(struct intel_crtc *crtc) · 398 unmodified lines
727 return effective_w <= max_w && effective_h <= max_h;730 return effective_w <= max_w && effective_h <= max_h;
728}731}
729 732
730/* XXX replace me when we have VMA tracking for intel_plane_state */
731static int get_fence_id(struct drm_framebuffer *fb)
732{
733 struct i915_vma *vma = i915_gem_object_to_ggtt(intel_fb_obj(fb), NULL);
734
735 return vma && vma->fence ? vma->fence->id : I915_FENCE_REG_NONE;
736}
737
738static void intel_fbc_update_state_cache(struct intel_crtc *crtc,733static void intel_fbc_update_state_cache(struct intel_crtc *crtc,
739 struct intel_crtc_state *crtc_state,734 struct intel_crtc_state *crtc_state,
740 struct intel_plane_state *plane_state)735 struct intel_plane_state *plane_state)
@@ -743,7 +738,8 @@ static void intel_fbc_update_state_cache(struct intel_crtc *crtc, · 2 unmodified lines
743 struct intel_fbc *fbc = &dev_priv->fbc;738 struct intel_fbc *fbc = &dev_priv->fbc;
744 struct intel_fbc_state_cache *cache = &fbc->state_cache;739 struct intel_fbc_state_cache *cache = &fbc->state_cache;
745 struct drm_framebuffer *fb = plane_state->base.fb;740 struct drm_framebuffer *fb = plane_state->base.fb;
746 struct drm_i915_gem_object *obj;741
742 cache->vma = NULL;
747 743
748 cache->crtc.mode_flags = crtc_state->base.adjusted_mode.flags;744 cache->crtc.mode_flags = crtc_state->base.adjusted_mode.flags;
749 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))745 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
@@ -758,16 +754,10 @@ static void intel_fbc_update_state_cache(struct intel_crtc *crtc, · 8 unmodified lines
758 if (!cache->plane.visible)754 if (!cache->plane.visible)
759 return;755 return;
760 756
761 obj = intel_fb_obj(fb);
762
763 /* FIXME: We lack the proper locking here, so only run this on the
764 * platforms that need. */
765 if (IS_GEN(dev_priv, 5, 6))
766 cache->fb.ilk_ggtt_offset = i915_gem_object_ggtt_offset(obj, NULL);
767 cache->fb.format = fb->format;757 cache->fb.format = fb->format;
768 cache->fb.stride = fb->pitches[0];758 cache->fb.stride = fb->pitches[0];
769 cache->fb.fence_reg = get_fence_id(fb);759
770 cache->fb.tiling_mode = i915_gem_object_get_tiling(obj);760 cache->vma = plane_state->vma;
771}761}
772 762
773static bool intel_fbc_can_activate(struct intel_crtc *crtc)763static bool intel_fbc_can_activate(struct intel_crtc *crtc)
@@ -784,7 +774,7 @@ static bool intel_fbc_can_activate(struct intel_crtc *crtc) · 10 unmodified lines
784 return false;774 return false;
785 }775 }
786 776
787 if (!cache->plane.visible) {777 if (!cache->vma) {
788 fbc->no_fbc_reason = "primary plane not visible";778 fbc->no_fbc_reason = "primary plane not visible";
789 return false;779 return false;
790 }780 }
@@ -807,8 +797,7 @@ static bool intel_fbc_can_activate(struct intel_crtc *crtc) · 16 unmodified lines
807 * so have no fence associated with it) due to aperture constaints797 * so have no fence associated with it) due to aperture constaints
808 * at the time of pinning.798 * at the time of pinning.
809 */799 */
810 if (cache->fb.tiling_mode != I915_TILING_X ||800 if (!cache->vma->fence) {
811 cache->fb.fence_reg == I915_FENCE_REG_NONE) {
812 fbc->no_fbc_reason = "framebuffer not tiled or fenced";801 fbc->no_fbc_reason = "framebuffer not tiled or fenced";
813 return false;802 return false;
814 }803 }
@@ -888,17 +877,16 @@ static void intel_fbc_get_reg_params(struct intel_crtc *crtc, · 73 unmodified lines
888 * zero. */877 * zero. */
889 memset(params, 0, sizeof(*params));878 memset(params, 0, sizeof(*params));
890 879
880 params->vma = cache->vma;
881
891 params->crtc.pipe = crtc->pipe;882 params->crtc.pipe = crtc->pipe;
892 params->crtc.plane = crtc->plane;883 params->crtc.plane = crtc->plane;
893 params->crtc.fence_y_offset = get_crtc_fence_y_offset(crtc);884 params->crtc.fence_y_offset = get_crtc_fence_y_offset(crtc);
894 885
895 params->fb.format = cache->fb.format;886 params->fb.format = cache->fb.format;
896 params->fb.stride = cache->fb.stride;887 params->fb.stride = cache->fb.stride;
897 params->fb.fence_reg = cache->fb.fence_reg;
898 888
899 params->cfb_size = intel_fbc_calculate_cfb_size(dev_priv, cache);889 params->cfb_size = intel_fbc_calculate_cfb_size(dev_priv, cache);
900
901 params->fb.ggtt_offset = cache->fb.ilk_ggtt_offset;
902}890}
903 891
904static bool intel_fbc_reg_params_equal(struct intel_fbc_reg_params *params1,892static bool intel_fbc_reg_params_equal(struct intel_fbc_reg_params *params1,
@@ -1296,7 +1284,7 @@ void intel_fbc_init_pipe_state(struct drm_i915_private *dev_priv) · 391 unmodified lines
1296 1284
1297 for_each_intel_crtc(&dev_priv->drm, crtc)1285 for_each_intel_crtc(&dev_priv->drm, crtc)
1298 if (intel_crtc_active(crtc) &&1286 if (intel_crtc_active(crtc) &&
1299 to_intel_plane_state(crtc->base.primary->state)->base.visible)1287 crtc->base.primary->state->visible)
1300 dev_priv->fbc.visible_pipes_mask |= (1 << crtc->pipe);1288 dev_priv->fbc.visible_pipes_mask |= (1 << crtc->pipe);
1301}1289}
1302 1290
drivers/gpu/drm/i915/intel_fbdev.c+5−2
@@ -284,7 +284,7 @@ static int intelfb_create(struct drm_fb_helper *helper, · 283 unmodified lines
284out_destroy_fbi:284out_destroy_fbi:
285 drm_fb_helper_release_fbi(helper);285 drm_fb_helper_release_fbi(helper);
286out_unpin:286out_unpin:
287 intel_unpin_fb_obj(&ifbdev->fb->base, DRM_ROTATE_0);287 intel_unpin_fb_vma(vma);
288out_unlock:288out_unlock:
289 mutex_unlock(&dev->struct_mutex);289 mutex_unlock(&dev->struct_mutex);
290 return ret;290 return ret;
@@ -549,7 +549,7 @@ static void intel_fbdev_destroy(struct intel_fbdev *ifbdev) · 258 unmodified lines
549 549
550 if (ifbdev->fb) {550 if (ifbdev->fb) {
551 mutex_lock(&ifbdev->helper.dev->struct_mutex);551 mutex_lock(&ifbdev->helper.dev->struct_mutex);
552 intel_unpin_fb_obj(&ifbdev->fb->base, DRM_ROTATE_0);552 intel_unpin_fb_vma(ifbdev->vma);
553 mutex_unlock(&ifbdev->helper.dev->struct_mutex);553 mutex_unlock(&ifbdev->helper.dev->struct_mutex);
554 554
555 drm_framebuffer_remove(&ifbdev->fb->base);555 drm_framebuffer_remove(&ifbdev->fb->base);
@@ -742,6 +742,9 @@ void intel_fbdev_initial_config_async(struct drm_device *dev) · 186 unmodified lines
742{742{
743 struct intel_fbdev *ifbdev = to_i915(dev)->fbdev;743 struct intel_fbdev *ifbdev = to_i915(dev)->fbdev;
744 744
745 if (!ifbdev)
746 return;
747
745 ifbdev->cookie = async_schedule(intel_fbdev_initial_config, ifbdev);748 ifbdev->cookie = async_schedule(intel_fbdev_initial_config, ifbdev);
746}749}
747 750
drivers/gpu/drm/i915/intel_guc_fwif.h+20−4
@@ -145,7 +145,7 @@ · 144 unmodified lines
145 * The GuC firmware layout looks like this:145 * The GuC firmware layout looks like this:
146 *146 *
147 * +-------------------------------+147 * +-------------------------------+
148 * | guc_css_header |148 * | uc_css_header |
149 * | |149 * | |
150 * | contains major/minor version |150 * | contains major/minor version |
151 * +-------------------------------+151 * +-------------------------------+
@@ -172,9 +172,16 @@ · 20 unmodified lines
172 * 3. Length info of each component can be found in header, in dwords.172 * 3. Length info of each component can be found in header, in dwords.
173 * 4. Modulus and exponent key are not required by driver. They may not appear173 * 4. Modulus and exponent key are not required by driver. They may not appear
174 * in fw. So driver will load a truncated firmware in this case.174 * in fw. So driver will load a truncated firmware in this case.
175 *
176 * HuC firmware layout is same as GuC firmware.
177 *
178 * HuC firmware css header is different. However, the only difference is where
179 * the version information is saved. The uc_css_header is unified to support
180 * both. Driver should get HuC version from uc_css_header.huc_sw_version, while
181 * uc_css_header.guc_sw_version for GuC.
175 */182 */
176 183
177struct guc_css_header {184struct uc_css_header {
178 uint32_t module_type;185 uint32_t module_type;
179 /* header_size includes all non-uCode bits, including css_header, rsa186 /* header_size includes all non-uCode bits, including css_header, rsa
180 * key, modulus key and exponent data. */187 * key, modulus key and exponent data. */
@@ -205,8 +212,16 @@ struct guc_css_header { · 24 unmodified lines
205 212
206 char username[8];213 char username[8];
207 char buildnumber[12];214 char buildnumber[12];
208 uint32_t device_id;215 union {
209 uint32_t guc_sw_version;216 struct {
217 uint32_t branch_client_version;
218 uint32_t sw_version;
219 } guc;
220 struct {
221 uint32_t sw_version;
222 uint32_t reserved;
223 } huc;
224 };
210 uint32_t prod_preprod_fw;225 uint32_t prod_preprod_fw;
211 uint32_t reserved[12];226 uint32_t reserved[12];
212 uint32_t header_info;227 uint32_t header_info;
@@ -490,6 +505,7 @@ enum intel_guc_action { · 277 unmodified lines
490 INTEL_GUC_ACTION_ENTER_S_STATE = 0x501,505 INTEL_GUC_ACTION_ENTER_S_STATE = 0x501,
491 INTEL_GUC_ACTION_EXIT_S_STATE = 0x502,506 INTEL_GUC_ACTION_EXIT_S_STATE = 0x502,
492 INTEL_GUC_ACTION_SLPC_REQUEST = 0x3003,507 INTEL_GUC_ACTION_SLPC_REQUEST = 0x3003,
508 INTEL_GUC_ACTION_AUTHENTICATE_HUC = 0x4000,
493 INTEL_GUC_ACTION_UK_LOG_ENABLE_LOGGING = 0x0E000,509 INTEL_GUC_ACTION_UK_LOG_ENABLE_LOGGING = 0x0E000,
494 INTEL_GUC_ACTION_LIMIT510 INTEL_GUC_ACTION_LIMIT
495};511};
drivers/gpu/drm/i915/intel_guc_loader.c+114−100
@@ -51,12 +51,6 @@ · 50 unmodified lines
51 * 512K. In order to exclude 0-512K address space from GGTT, all gfx objects51 * 512K. In order to exclude 0-512K address space from GGTT, all gfx objects
52 * used by GuC is pinned with PIN_OFFSET_BIAS along with size of WOPCM.52 * used by GuC is pinned with PIN_OFFSET_BIAS along with size of WOPCM.
53 *53 *
54 * Firmware log:
55 * Firmware log is enabled by setting i915.guc_log_level to non-negative level.
56 * Log data is printed out via reading debugfs i915_guc_log_dump. Reading from
57 * i915_guc_load_status will print out firmware loading status and scratch
58 * registers value.
59 *
60 */54 */
61 55
62#define SKL_FW_MAJOR 656#define SKL_FW_MAJOR 6
@@ -81,16 +75,16 @@ MODULE_FIRMWARE(I915_BXT_GUC_UCODE); · 18 unmodified lines
81MODULE_FIRMWARE(I915_KBL_GUC_UCODE);75MODULE_FIRMWARE(I915_KBL_GUC_UCODE);
82 76
83/* User-friendly representation of an enum */77/* User-friendly representation of an enum */
84const char *intel_guc_fw_status_repr(enum intel_guc_fw_status status)78const char *intel_uc_fw_status_repr(enum intel_uc_fw_status status)
85{79{
86 switch (status) {80 switch (status) {
87 case GUC_FIRMWARE_FAIL:81 case INTEL_UC_FIRMWARE_FAIL:
88 return "FAIL";82 return "FAIL";
89 case GUC_FIRMWARE_NONE:83 case INTEL_UC_FIRMWARE_NONE:
90 return "NONE";84 return "NONE";
91 case GUC_FIRMWARE_PENDING:85 case INTEL_UC_FIRMWARE_PENDING:
92 return "PENDING";86 return "PENDING";
93 case GUC_FIRMWARE_SUCCESS:87 case INTEL_UC_FIRMWARE_SUCCESS:
94 return "SUCCESS";88 return "SUCCESS";
95 default:89 default:
96 return "UNKNOWN!";90 return "UNKNOWN!";
@@ -278,7 +272,7 @@ static inline bool guc_ucode_response(struct drm_i915_private *dev_priv, · 181 unmodified lines
278static int guc_ucode_xfer_dma(struct drm_i915_private *dev_priv,272static int guc_ucode_xfer_dma(struct drm_i915_private *dev_priv,
279 struct i915_vma *vma)273 struct i915_vma *vma)
280{274{
281 struct intel_guc_fw *guc_fw = &dev_priv->guc.guc_fw;275 struct intel_uc_fw *guc_fw = &dev_priv->guc.fw;
282 unsigned long offset;276 unsigned long offset;
283 struct sg_table *sg = vma->pages;277 struct sg_table *sg = vma->pages;
284 u32 status, rsa[UOS_RSA_SCRATCH_MAX_COUNT];278 u32 status, rsa[UOS_RSA_SCRATCH_MAX_COUNT];
@@ -334,12 +328,12 @@ static int guc_ucode_xfer_dma(struct drm_i915_private *dev_priv, · 49 unmodified lines
334 return ret;328 return ret;
335}329}
336 330
337static u32 guc_wopcm_size(struct drm_i915_private *dev_priv)331u32 intel_guc_wopcm_size(struct drm_i915_private *dev_priv)
338{332{
339 u32 wopcm_size = GUC_WOPCM_TOP;333 u32 wopcm_size = GUC_WOPCM_TOP;
340 334
341 /* On BXT, the top of WOPCM is reserved for RC6 context */335 /* On BXT, the top of WOPCM is reserved for RC6 context */
342 if (IS_BROXTON(dev_priv))336 if (IS_GEN9_LP(dev_priv))
343 wopcm_size -= BXT_GUC_WOPCM_RC6_RESERVED;337 wopcm_size -= BXT_GUC_WOPCM_RC6_RESERVED;
344 338
345 return wopcm_size;339 return wopcm_size;
@@ -350,29 +344,27 @@ static u32 guc_wopcm_size(struct drm_i915_private *dev_priv) · 4 unmodified lines
350 */344 */
351static int guc_ucode_xfer(struct drm_i915_private *dev_priv)345static int guc_ucode_xfer(struct drm_i915_private *dev_priv)
352{346{
353 struct intel_guc_fw *guc_fw = &dev_priv->guc.guc_fw;347 struct intel_uc_fw *guc_fw = &dev_priv->guc.fw;
354 struct i915_vma *vma;348 struct i915_vma *vma;
355 int ret;349 int ret;
356 350
357 ret = i915_gem_object_set_to_gtt_domain(guc_fw->guc_fw_obj, false);351 ret = i915_gem_object_set_to_gtt_domain(guc_fw->obj, false);
358 if (ret) {352 if (ret) {
359 DRM_DEBUG_DRIVER("set-domain failed %d\n", ret);353 DRM_DEBUG_DRIVER("set-domain failed %d\n", ret);
360 return ret;354 return ret;
361 }355 }
362 356
363 vma = i915_gem_object_ggtt_pin(guc_fw->guc_fw_obj, NULL, 0, 0, 0);357 vma = i915_gem_object_ggtt_pin(guc_fw->obj, NULL, 0, 0,
358 PIN_OFFSET_BIAS | GUC_WOPCM_TOP);
364 if (IS_ERR(vma)) {359 if (IS_ERR(vma)) {
365 DRM_DEBUG_DRIVER("pin failed %d\n", (int)PTR_ERR(vma));360 DRM_DEBUG_DRIVER("pin failed %d\n", (int)PTR_ERR(vma));
366 return PTR_ERR(vma);361 return PTR_ERR(vma);
367 }362 }
368 363
369 /* Invalidate GuC TLB to let GuC take the latest updates to GTT. */
370 I915_WRITE(GEN8_GTCR, GEN8_GTCR_INVALIDATE);
371
372 intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL);364 intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL);
373 365
374 /* init WOPCM */366 /* init WOPCM */
375 I915_WRITE(GUC_WOPCM_SIZE, guc_wopcm_size(dev_priv));367 I915_WRITE(GUC_WOPCM_SIZE, intel_guc_wopcm_size(dev_priv));
376 I915_WRITE(DMA_GUC_WOPCM_OFFSET, GUC_WOPCM_OFFSET_VALUE);368 I915_WRITE(DMA_GUC_WOPCM_OFFSET, GUC_WOPCM_OFFSET_VALUE);
377 369
378 /* Enable MIA caching. GuC clock gating is disabled. */370 /* Enable MIA caching. GuC clock gating is disabled. */
@@ -388,7 +380,7 @@ static int guc_ucode_xfer(struct drm_i915_private *dev_priv) · 9 unmodified lines
388 if (IS_BXT_REVID(dev_priv, 0, BXT_REVID_B0))380 if (IS_BXT_REVID(dev_priv, 0, BXT_REVID_B0))
389 I915_WRITE(GEN6_GFXPAUSE, 0x30FFF);381 I915_WRITE(GEN6_GFXPAUSE, 0x30FFF);
390 382
391 if (IS_BROXTON(dev_priv))383 if (IS_GEN9_LP(dev_priv))
392 I915_WRITE(GEN9LP_GT_PM_CONFIG, GT_DOORBELL_ENABLE);384 I915_WRITE(GEN9LP_GT_PM_CONFIG, GT_DOORBELL_ENABLE);
393 else385 else
394 I915_WRITE(GEN9_GT_PM_CONFIG, GT_DOORBELL_ENABLE);386 I915_WRITE(GEN9_GT_PM_CONFIG, GT_DOORBELL_ENABLE);
@@ -450,14 +442,14 @@ static int guc_hw_reset(struct drm_i915_private *dev_priv) · 55 unmodified lines
450 */442 */
451int intel_guc_setup(struct drm_i915_private *dev_priv)443int intel_guc_setup(struct drm_i915_private *dev_priv)
452{444{
453 struct intel_guc_fw *guc_fw = &dev_priv->guc.guc_fw;445 struct intel_uc_fw *guc_fw = &dev_priv->guc.fw;
454 const char *fw_path = guc_fw->guc_fw_path;446 const char *fw_path = guc_fw->path;
455 int retries, ret, err;447 int retries, ret, err;
456 448
457 DRM_DEBUG_DRIVER("GuC fw status: path %s, fetch %s, load %s\n",449 DRM_DEBUG_DRIVER("GuC fw status: path %s, fetch %s, load %s\n",
458 fw_path,450 fw_path,
459 intel_guc_fw_status_repr(guc_fw->guc_fw_fetch_status),451 intel_uc_fw_status_repr(guc_fw->fetch_status),
460 intel_guc_fw_status_repr(guc_fw->guc_fw_load_status));452 intel_uc_fw_status_repr(guc_fw->load_status));
461 453
462 /* Loading forbidden, or no firmware to load? */454 /* Loading forbidden, or no firmware to load? */
463 if (!i915.enable_guc_loading) {455 if (!i915.enable_guc_loading) {
@@ -475,10 +467,10 @@ int intel_guc_setup(struct drm_i915_private *dev_priv) · 11 unmodified lines
475 }467 }
476 468
477 /* Fetch failed, or already fetched but failed to load? */469 /* Fetch failed, or already fetched but failed to load? */
478 if (guc_fw->guc_fw_fetch_status != GUC_FIRMWARE_SUCCESS) {470 if (guc_fw->fetch_status != INTEL_UC_FIRMWARE_SUCCESS) {
479 err = -EIO;471 err = -EIO;
480 goto fail;472 goto fail;
481 } else if (guc_fw->guc_fw_load_status == GUC_FIRMWARE_FAIL) {473 } else if (guc_fw->load_status == INTEL_UC_FIRMWARE_FAIL) {
482 err = -ENOEXEC;474 err = -ENOEXEC;
483 goto fail;475 goto fail;
484 }476 }
@@ -486,11 +478,14 @@ int intel_guc_setup(struct drm_i915_private *dev_priv) · 1 unmodified line
486 guc_interrupts_release(dev_priv);478 guc_interrupts_release(dev_priv);
487 gen9_reset_guc_interrupts(dev_priv);479 gen9_reset_guc_interrupts(dev_priv);
488 480
489 guc_fw->guc_fw_load_status = GUC_FIRMWARE_PENDING;481 /* We need to notify the guc whenever we change the GGTT */
482 i915_ggtt_enable_guc(dev_priv);
483
484 guc_fw->load_status = INTEL_UC_FIRMWARE_PENDING;
490 485
491 DRM_DEBUG_DRIVER("GuC fw status: fetch %s, load %s\n",486 DRM_DEBUG_DRIVER("GuC fw status: fetch %s, load %s\n",
492 intel_guc_fw_status_repr(guc_fw->guc_fw_fetch_status),487 intel_uc_fw_status_repr(guc_fw->fetch_status),
493 intel_guc_fw_status_repr(guc_fw->guc_fw_load_status));488 intel_uc_fw_status_repr(guc_fw->load_status));
494 489
495 err = i915_guc_submission_init(dev_priv);490 err = i915_guc_submission_init(dev_priv);
496 if (err)491 if (err)
@@ -511,6 +506,7 @@ int intel_guc_setup(struct drm_i915_private *dev_priv) · 14 unmodified lines
511 if (err)506 if (err)
512 goto fail;507 goto fail;
513 508
509 intel_huc_load(dev_priv);
514 err = guc_ucode_xfer(dev_priv);510 err = guc_ucode_xfer(dev_priv);
515 if (!err)511 if (!err)
516 break;512 break;
@@ -522,11 +518,13 @@ int intel_guc_setup(struct drm_i915_private *dev_priv) · 5 unmodified lines
522 "retry %d more time(s)\n", err, retries);518 "retry %d more time(s)\n", err, retries);
523 }519 }
524 520
525 guc_fw->guc_fw_load_status = GUC_FIRMWARE_SUCCESS;521 guc_fw->load_status = INTEL_UC_FIRMWARE_SUCCESS;
526 522
527 DRM_DEBUG_DRIVER("GuC fw status: fetch %s, load %s\n",523 DRM_DEBUG_DRIVER("GuC fw status: fetch %s, load %s\n",
528 intel_guc_fw_status_repr(guc_fw->guc_fw_fetch_status),524 intel_uc_fw_status_repr(guc_fw->fetch_status),
529 intel_guc_fw_status_repr(guc_fw->guc_fw_load_status));525 intel_uc_fw_status_repr(guc_fw->load_status));
526
527 intel_guc_auth_huc(dev_priv);
530 528
531 if (i915.enable_guc_submission) {529 if (i915.enable_guc_submission) {
532 if (i915.guc_log_level >= 0)530 if (i915.guc_log_level >= 0)
@@ -541,12 +539,13 @@ int intel_guc_setup(struct drm_i915_private *dev_priv) · 8 unmodified lines
541 return 0;539 return 0;
542 540
543fail:541fail:
544 if (guc_fw->guc_fw_load_status == GUC_FIRMWARE_PENDING)542 if (guc_fw->load_status == INTEL_UC_FIRMWARE_PENDING)
545 guc_fw->guc_fw_load_status = GUC_FIRMWARE_FAIL;543 guc_fw->load_status = INTEL_UC_FIRMWARE_FAIL;
546 544
547 guc_interrupts_release(dev_priv);545 guc_interrupts_release(dev_priv);
548 i915_guc_submission_disable(dev_priv);546 i915_guc_submission_disable(dev_priv);
549 i915_guc_submission_fini(dev_priv);547 i915_guc_submission_fini(dev_priv);
548 i915_ggtt_disable_guc(dev_priv);
550 549
551 /*550 /*
552 * We've failed to load the firmware :(551 * We've failed to load the firmware :(
@@ -587,93 +586,108 @@ fail: · 34 unmodified lines
587 return ret;586 return ret;
588}587}
589 588
590static void guc_fw_fetch(struct drm_i915_private *dev_priv,589void intel_uc_fw_fetch(struct drm_i915_private *dev_priv,
591 struct intel_guc_fw *guc_fw)590 struct intel_uc_fw *uc_fw)
592{591{
593 struct pci_dev *pdev = dev_priv->drm.pdev;592 struct pci_dev *pdev = dev_priv->drm.pdev;
594 struct drm_i915_gem_object *obj;593 struct drm_i915_gem_object *obj;
595 const struct firmware *fw = NULL;594 const struct firmware *fw = NULL;
596 struct guc_css_header *css;595 struct uc_css_header *css;
597 size_t size;596 size_t size;
598 int err;597 int err;
599 598
600 DRM_DEBUG_DRIVER("before requesting firmware: GuC fw fetch status %s\n",599 DRM_DEBUG_DRIVER("before requesting firmware: uC fw fetch status %s\n",
601 intel_guc_fw_status_repr(guc_fw->guc_fw_fetch_status));600 intel_uc_fw_status_repr(uc_fw->fetch_status));
602 601
603 err = request_firmware(&fw, guc_fw->guc_fw_path, &pdev->dev);602 err = request_firmware(&fw, uc_fw->path, &pdev->dev);
604 if (err)603 if (err)
605 goto fail;604 goto fail;
606 if (!fw)605 if (!fw)
607 goto fail;606 goto fail;
608 607
609 DRM_DEBUG_DRIVER("fetch GuC fw from %s succeeded, fw %p\n",608 DRM_DEBUG_DRIVER("fetch uC fw from %s succeeded, fw %p\n",
610 guc_fw->guc_fw_path, fw);609 uc_fw->path, fw);
611 610
612 /* Check the size of the blob before examining buffer contents */611 /* Check the size of the blob before examining buffer contents */
613 if (fw->size < sizeof(struct guc_css_header)) {612 if (fw->size < sizeof(struct uc_css_header)) {
614 DRM_NOTE("Firmware header is missing\n");613 DRM_NOTE("Firmware header is missing\n");
615 goto fail;614 goto fail;
616 }615 }
617 616
618 css = (struct guc_css_header *)fw->data;617 css = (struct uc_css_header *)fw->data;
619 618
620 /* Firmware bits always start from header */619 /* Firmware bits always start from header */
621 guc_fw->header_offset = 0;620 uc_fw->header_offset = 0;
622 guc_fw->header_size = (css->header_size_dw - css->modulus_size_dw -621 uc_fw->header_size = (css->header_size_dw - css->modulus_size_dw -
623 css->key_size_dw - css->exponent_size_dw) * sizeof(u32);622 css->key_size_dw - css->exponent_size_dw) * sizeof(u32);
624 623
625 if (guc_fw->header_size != sizeof(struct guc_css_header)) {624 if (uc_fw->header_size != sizeof(struct uc_css_header)) {
626 DRM_NOTE("CSS header definition mismatch\n");625 DRM_NOTE("CSS header definition mismatch\n");
627 goto fail;626 goto fail;
628 }627 }
629 628
630 /* then, uCode */629 /* then, uCode */
631 guc_fw->ucode_offset = guc_fw->header_offset + guc_fw->header_size;630 uc_fw->ucode_offset = uc_fw->header_offset + uc_fw->header_size;
632 guc_fw->ucode_size = (css->size_dw - css->header_size_dw) * sizeof(u32);631 uc_fw->ucode_size = (css->size_dw - css->header_size_dw) * sizeof(u32);
633 632
634 /* now RSA */633 /* now RSA */
635 if (css->key_size_dw != UOS_RSA_SCRATCH_MAX_COUNT) {634 if (css->key_size_dw != UOS_RSA_SCRATCH_MAX_COUNT) {
636 DRM_NOTE("RSA key size is bad\n");635 DRM_NOTE("RSA key size is bad\n");
637 goto fail;636 goto fail;
638 }637 }
639 guc_fw->rsa_offset = guc_fw->ucode_offset + guc_fw->ucode_size;638 uc_fw->rsa_offset = uc_fw->ucode_offset + uc_fw->ucode_size;
640 guc_fw->rsa_size = css->key_size_dw * sizeof(u32);639 uc_fw->rsa_size = css->key_size_dw * sizeof(u32);
641 640
642 /* At least, it should have header, uCode and RSA. Size of all three. */641 /* At least, it should have header, uCode and RSA. Size of all three. */
643 size = guc_fw->header_size + guc_fw->ucode_size + guc_fw->rsa_size;642 size = uc_fw->header_size + uc_fw->ucode_size + uc_fw->rsa_size;
644 if (fw->size < size) {643 if (fw->size < size) {
645 DRM_NOTE("Missing firmware components\n");644 DRM_NOTE("Missing firmware components\n");
646 goto fail;645 goto fail;
647 }646 }
648 647
649 /* Header and uCode will be loaded to WOPCM. Size of the two. */
650 size = guc_fw->header_size + guc_fw->ucode_size;
651 if (size > guc_wopcm_size(dev_priv)) {
652 DRM_NOTE("Firmware is too large to fit in WOPCM\n");
653 goto fail;
654 }
655
656 /*648 /*
657 * The GuC firmware image has the version number embedded at a well-known649 * The GuC firmware image has the version number embedded at a well-known
658 * offset within the firmware blob; note that major / minor version are650 * offset within the firmware blob; note that major / minor version are
659 * TWO bytes each (i.e. u16), although all pointers and offsets are defined651 * TWO bytes each (i.e. u16), although all pointers and offsets are defined
660 * in terms of bytes (u8).652 * in terms of bytes (u8).
661 */653 */
662 guc_fw->guc_fw_major_found = css->guc_sw_version >> 16;654 switch (uc_fw->fw) {
663 guc_fw->guc_fw_minor_found = css->guc_sw_version & 0xFFFF;655 case INTEL_UC_FW_TYPE_GUC:
664 656 /* Header and uCode will be loaded to WOPCM. Size of the two. */
665 if (guc_fw->guc_fw_major_found != guc_fw->guc_fw_major_wanted ||657 size = uc_fw->header_size + uc_fw->ucode_size;
666 guc_fw->guc_fw_minor_found < guc_fw->guc_fw_minor_wanted) {658
667 DRM_NOTE("GuC firmware version %d.%d, required %d.%d\n",659 /* Top 32k of WOPCM is reserved (8K stack + 24k RC6 context). */
668 guc_fw->guc_fw_major_found, guc_fw->guc_fw_minor_found,660 if (size > intel_guc_wopcm_size(dev_priv)) {
669 guc_fw->guc_fw_major_wanted, guc_fw->guc_fw_minor_wanted);661 DRM_ERROR("Firmware is too large to fit in WOPCM\n");
662 goto fail;
663 }
664 uc_fw->major_ver_found = css->guc.sw_version >> 16;
665 uc_fw->minor_ver_found = css->guc.sw_version & 0xFFFF;
666 break;
667
668 case INTEL_UC_FW_TYPE_HUC:
669 uc_fw->major_ver_found = css->huc.sw_version >> 16;
670 uc_fw->minor_ver_found = css->huc.sw_version & 0xFFFF;
671 break;
672
673 default:
674 DRM_ERROR("Unknown firmware type %d\n", uc_fw->fw);
675 err = -ENOEXEC;
676 goto fail;
677 }
678
679 if (uc_fw->major_ver_found != uc_fw->major_ver_wanted ||
680 uc_fw->minor_ver_found < uc_fw->minor_ver_wanted) {
681 DRM_NOTE("uC firmware version %d.%d, required %d.%d\n",
682 uc_fw->major_ver_found, uc_fw->minor_ver_found,
683 uc_fw->major_ver_wanted, uc_fw->minor_ver_wanted);
670 err = -ENOEXEC;684 err = -ENOEXEC;
671 goto fail;685 goto fail;
672 }686 }
673 687
674 DRM_DEBUG_DRIVER("firmware version %d.%d OK (minimum %d.%d)\n",688 DRM_DEBUG_DRIVER("firmware version %d.%d OK (minimum %d.%d)\n",
675 guc_fw->guc_fw_major_found, guc_fw->guc_fw_minor_found,689 uc_fw->major_ver_found, uc_fw->minor_ver_found,
676 guc_fw->guc_fw_major_wanted, guc_fw->guc_fw_minor_wanted);690 uc_fw->major_ver_wanted, uc_fw->minor_ver_wanted);
677 691
678 mutex_lock(&dev_priv->drm.struct_mutex);692 mutex_lock(&dev_priv->drm.struct_mutex);
679 obj = i915_gem_object_create_from_data(dev_priv, fw->data, fw->size);693 obj = i915_gem_object_create_from_data(dev_priv, fw->data, fw->size);
@@ -683,31 +697,31 @@ static void guc_fw_fetch(struct drm_i915_private *dev_priv, · 3 unmodified lines
683 goto fail;697 goto fail;
684 }698 }
685 699
686 guc_fw->guc_fw_obj = obj;700 uc_fw->obj = obj;
687 guc_fw->guc_fw_size = fw->size;701 uc_fw->size = fw->size;
688 702
689 DRM_DEBUG_DRIVER("GuC fw fetch status SUCCESS, obj %p\n",703 DRM_DEBUG_DRIVER("uC fw fetch status SUCCESS, obj %p\n",
690 guc_fw->guc_fw_obj);704 uc_fw->obj);
691 705
692 release_firmware(fw);706 release_firmware(fw);
693 guc_fw->guc_fw_fetch_status = GUC_FIRMWARE_SUCCESS;707 uc_fw->fetch_status = INTEL_UC_FIRMWARE_SUCCESS;
694 return;708 return;
695 709
696fail:710fail:
697 DRM_WARN("Failed to fetch valid GuC firmware from %s (error %d)\n",711 DRM_WARN("Failed to fetch valid uC firmware from %s (error %d)\n",
698 guc_fw->guc_fw_path, err);712 uc_fw->path, err);
699 DRM_DEBUG_DRIVER("GuC fw fetch status FAIL; err %d, fw %p, obj %p\n",713 DRM_DEBUG_DRIVER("uC fw fetch status FAIL; err %d, fw %p, obj %p\n",
700 err, fw, guc_fw->guc_fw_obj);714 err, fw, uc_fw->obj);
701 715
702 mutex_lock(&dev_priv->drm.struct_mutex);716 mutex_lock(&dev_priv->drm.struct_mutex);
703 obj = guc_fw->guc_fw_obj;717 obj = uc_fw->obj;
704 if (obj)718 if (obj)
705 i915_gem_object_put(obj);719 i915_gem_object_put(obj);
706 guc_fw->guc_fw_obj = NULL;720 uc_fw->obj = NULL;
707 mutex_unlock(&dev_priv->drm.struct_mutex);721 mutex_unlock(&dev_priv->drm.struct_mutex);
708 722
709 release_firmware(fw); /* OK even if fw is NULL */723 release_firmware(fw); /* OK even if fw is NULL */
710 guc_fw->guc_fw_fetch_status = GUC_FIRMWARE_FAIL;724 uc_fw->fetch_status = INTEL_UC_FIRMWARE_FAIL;
711}725}
712 726
713/**727/**
@@ -721,7 +735,7 @@ fail: · 7 unmodified lines
721 */735 */
722void intel_guc_init(struct drm_i915_private *dev_priv)736void intel_guc_init(struct drm_i915_private *dev_priv)
723{737{
724 struct intel_guc_fw *guc_fw = &dev_priv->guc.guc_fw;738 struct intel_uc_fw *guc_fw = &dev_priv->guc.fw;
725 const char *fw_path;739 const char *fw_path;
726 740
727 if (!HAS_GUC(dev_priv)) {741 if (!HAS_GUC(dev_priv)) {
@@ -739,23 +753,23 @@ void intel_guc_init(struct drm_i915_private *dev_priv) · 11 unmodified lines
739 fw_path = NULL;753 fw_path = NULL;
740 } else if (IS_SKYLAKE(dev_priv)) {754 } else if (IS_SKYLAKE(dev_priv)) {
741 fw_path = I915_SKL_GUC_UCODE;755 fw_path = I915_SKL_GUC_UCODE;
742 guc_fw->guc_fw_major_wanted = SKL_FW_MAJOR;756 guc_fw->major_ver_wanted = SKL_FW_MAJOR;
743 guc_fw->guc_fw_minor_wanted = SKL_FW_MINOR;757 guc_fw->minor_ver_wanted = SKL_FW_MINOR;
744 } else if (IS_BROXTON(dev_priv)) {758 } else if (IS_BROXTON(dev_priv)) {
745 fw_path = I915_BXT_GUC_UCODE;759 fw_path = I915_BXT_GUC_UCODE;
746 guc_fw->guc_fw_major_wanted = BXT_FW_MAJOR;760 guc_fw->major_ver_wanted = BXT_FW_MAJOR;
747 guc_fw->guc_fw_minor_wanted = BXT_FW_MINOR;761 guc_fw->minor_ver_wanted = BXT_FW_MINOR;
748 } else if (IS_KABYLAKE(dev_priv)) {762 } else if (IS_KABYLAKE(dev_priv)) {
749 fw_path = I915_KBL_GUC_UCODE;763 fw_path = I915_KBL_GUC_UCODE;
750 guc_fw->guc_fw_major_wanted = KBL_FW_MAJOR;764 guc_fw->major_ver_wanted = KBL_FW_MAJOR;
751 guc_fw->guc_fw_minor_wanted = KBL_FW_MINOR;765 guc_fw->minor_ver_wanted = KBL_FW_MINOR;
752 } else {766 } else {
753 fw_path = ""; /* unknown device */767 fw_path = ""; /* unknown device */
754 }768 }
755 769
756 guc_fw->guc_fw_path = fw_path;770 guc_fw->path = fw_path;
757 guc_fw->guc_fw_fetch_status = GUC_FIRMWARE_NONE;771 guc_fw->fetch_status = INTEL_UC_FIRMWARE_NONE;
758 guc_fw->guc_fw_load_status = GUC_FIRMWARE_NONE;772 guc_fw->load_status = INTEL_UC_FIRMWARE_NONE;
759 773
760 /* Early (and silent) return if GuC loading is disabled */774 /* Early (and silent) return if GuC loading is disabled */
761 if (!i915.enable_guc_loading)775 if (!i915.enable_guc_loading)
@@ -765,9 +779,9 @@ void intel_guc_init(struct drm_i915_private *dev_priv) · 3 unmodified lines
765 if (*fw_path == '\0')779 if (*fw_path == '\0')
766 return;780 return;
767 781
768 guc_fw->guc_fw_fetch_status = GUC_FIRMWARE_PENDING;782 guc_fw->fetch_status = INTEL_UC_FIRMWARE_PENDING;
769 DRM_DEBUG_DRIVER("GuC firmware pending, path %s\n", fw_path);783 DRM_DEBUG_DRIVER("GuC firmware pending, path %s\n", fw_path);
770 guc_fw_fetch(dev_priv, guc_fw);784 intel_uc_fw_fetch(dev_priv, guc_fw);
771 /* status must now be FAIL or SUCCESS */785 /* status must now be FAIL or SUCCESS */
772}786}
773 787
@@ -777,17 +791,17 @@ void intel_guc_init(struct drm_i915_private *dev_priv) · 3 unmodified lines
777 */791 */
778void intel_guc_fini(struct drm_i915_private *dev_priv)792void intel_guc_fini(struct drm_i915_private *dev_priv)
779{793{
780 struct intel_guc_fw *guc_fw = &dev_priv->guc.guc_fw;794 struct intel_uc_fw *guc_fw = &dev_priv->guc.fw;
781 795
782 mutex_lock(&dev_priv->drm.struct_mutex);796 mutex_lock(&dev_priv->drm.struct_mutex);
783 guc_interrupts_release(dev_priv);797 guc_interrupts_release(dev_priv);
784 i915_guc_submission_disable(dev_priv);798 i915_guc_submission_disable(dev_priv);
785 i915_guc_submission_fini(dev_priv);799 i915_guc_submission_fini(dev_priv);
786 800
787 if (guc_fw->guc_fw_obj)801 if (guc_fw->obj)
788 i915_gem_object_put(guc_fw->guc_fw_obj);802 i915_gem_object_put(guc_fw->obj);
789 guc_fw->guc_fw_obj = NULL;803 guc_fw->obj = NULL;
790 mutex_unlock(&dev_priv->drm.struct_mutex);804 mutex_unlock(&dev_priv->drm.struct_mutex);
791 805
792 guc_fw->guc_fw_fetch_status = GUC_FIRMWARE_NONE;806 guc_fw->fetch_status = INTEL_UC_FIRMWARE_NONE;
793}807}
drivers/gpu/drm/i915/intel_guc_log.c+658−0
@@ -0,0 +1,658 @@
1/*
2 * Copyright © 2014-2017 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 <linux/debugfs.h>
25#include <linux/relay.h>
26#include "i915_drv.h"
27
28static void guc_log_capture_logs(struct intel_guc *guc);
29
30/**
31 * DOC: GuC firmware log
32 *
33 * Firmware log is enabled by setting i915.guc_log_level to non-negative level.
34 * Log data is printed out via reading debugfs i915_guc_log_dump. Reading from
35 * i915_guc_load_status will print out firmware loading status and scratch
36 * registers value.
37 *
38 */
39
40static int guc_log_flush_complete(struct intel_guc *guc)
41{
42 u32 action[] = {
43 INTEL_GUC_ACTION_LOG_BUFFER_FILE_FLUSH_COMPLETE
44 };
45
46 return intel_guc_send(guc, action, ARRAY_SIZE(action));
47}
48
49static int guc_log_flush(struct intel_guc *guc)
50{
51 u32 action[] = {
52 INTEL_GUC_ACTION_FORCE_LOG_BUFFER_FLUSH,
53 0
54 };
55
56 return intel_guc_send(guc, action, ARRAY_SIZE(action));
57}
58
59static int guc_log_control(struct intel_guc *guc, u32 control_val)
60{
61 u32 action[] = {
62 INTEL_GUC_ACTION_UK_LOG_ENABLE_LOGGING,
63 control_val
64 };
65
66 return intel_guc_send(guc, action, ARRAY_SIZE(action));
67}
68
69
70/*
71 * Sub buffer switch callback. Called whenever relay has to switch to a new
72 * sub buffer, relay stays on the same sub buffer if 0 is returned.
73 */
74static int subbuf_start_callback(struct rchan_buf *buf,
75 void *subbuf,
76 void *prev_subbuf,
77 size_t prev_padding)
78{
79 /* Use no-overwrite mode by default, where relay will stop accepting
80 * new data if there are no empty sub buffers left.
81 * There is no strict synchronization enforced by relay between Consumer
82 * and Producer. In overwrite mode, there is a possibility of getting
83 * inconsistent/garbled data, the producer could be writing on to the
84 * same sub buffer from which Consumer is reading. This can't be avoided
85 * unless Consumer is fast enough and can always run in tandem with
86 * Producer.
87 */
88 if (relay_buf_full(buf))
89 return 0;
90
91 return 1;
92}
93
94/*
95 * file_create() callback. Creates relay file in debugfs.
96 */
97static struct dentry *create_buf_file_callback(const char *filename,
98 struct dentry *parent,
99 umode_t mode,
100 struct rchan_buf *buf,
101 int *is_global)
102{
103 struct dentry *buf_file;
104
105 /* This to enable the use of a single buffer for the relay channel and
106 * correspondingly have a single file exposed to User, through which
107 * it can collect the logs in order without any post-processing.
108 * Need to set 'is_global' even if parent is NULL for early logging.
109 */
110 *is_global = 1;
111
112 if (!parent)
113 return NULL;
114
115 /* Not using the channel filename passed as an argument, since for each
116 * channel relay appends the corresponding CPU number to the filename
117 * passed in relay_open(). This should be fine as relay just needs a
118 * dentry of the file associated with the channel buffer and that file's
119 * name need not be same as the filename passed as an argument.
120 */
121 buf_file = debugfs_create_file("guc_log", mode,
122 parent, buf, &relay_file_operations);
123 return buf_file;
124}
125
126/*
127 * file_remove() default callback. Removes relay file in debugfs.
128 */
129static int remove_buf_file_callback(struct dentry *dentry)
130{
131 debugfs_remove(dentry);
132 return 0;
133}
134
135/* relay channel callbacks */
136static struct rchan_callbacks relay_callbacks = {
137 .subbuf_start = subbuf_start_callback,
138 .create_buf_file = create_buf_file_callback,
139 .remove_buf_file = remove_buf_file_callback,
140};
141
142static void guc_log_remove_relay_file(struct intel_guc *guc)
143{
144 relay_close(guc->log.relay_chan);
145}
146
147static int guc_log_create_relay_channel(struct intel_guc *guc)
148{
149 struct drm_i915_private *dev_priv = guc_to_i915(guc);
150 struct rchan *guc_log_relay_chan;
151 size_t n_subbufs, subbuf_size;
152
153 /* Keep the size of sub buffers same as shared log buffer */
154 subbuf_size = guc->log.vma->obj->base.size;
155
156 /* Store up to 8 snapshots, which is large enough to buffer sufficient
157 * boot time logs and provides enough leeway to User, in terms of
158 * latency, for consuming the logs from relay. Also doesn't take
159 * up too much memory.
160 */
161 n_subbufs = 8;
162
163 guc_log_relay_chan = relay_open(NULL, NULL, subbuf_size,
164 n_subbufs, &relay_callbacks, dev_priv);
165 if (!guc_log_relay_chan) {
166 DRM_ERROR("Couldn't create relay chan for GuC logging\n");
167 return -ENOMEM;
168 }
169
170 GEM_BUG_ON(guc_log_relay_chan->subbuf_size < subbuf_size);
171 guc->log.relay_chan = guc_log_relay_chan;
172 return 0;
173}
174
175static int guc_log_create_relay_file(struct intel_guc *guc)
176{
177 struct drm_i915_private *dev_priv = guc_to_i915(guc);
178 struct dentry *log_dir;
179 int ret;
180
181 /* For now create the log file in /sys/kernel/debug/dri/0 dir */
182 log_dir = dev_priv->drm.primary->debugfs_root;
183
184 /* If /sys/kernel/debug/dri/0 location do not exist, then debugfs is
185 * not mounted and so can't create the relay file.
186 * The relay API seems to fit well with debugfs only, for availing relay
187 * there are 3 requirements which can be met for debugfs file only in a
188 * straightforward/clean manner :-
189 * i) Need the associated dentry pointer of the file, while opening the
190 * relay channel.
191 * ii) Should be able to use 'relay_file_operations' fops for the file.
192 * iii) Set the 'i_private' field of file's inode to the pointer of
193 * relay channel buffer.
194 */
195 if (!log_dir) {
196 DRM_ERROR("Debugfs dir not available yet for GuC log file\n");
197 return -ENODEV;
198 }
199
200 ret = relay_late_setup_files(guc->log.relay_chan, "guc_log", log_dir);
201 if (ret) {
202 DRM_ERROR("Couldn't associate relay chan with file %d\n", ret);
203 return ret;
204 }
205
206 return 0;
207}
208
209static void guc_move_to_next_buf(struct intel_guc *guc)
210{
211 /* Make sure the updates made in the sub buffer are visible when
212 * Consumer sees the following update to offset inside the sub buffer.
213 */
214 smp_wmb();
215
216 /* All data has been written, so now move the offset of sub buffer. */
217 relay_reserve(guc->log.relay_chan, guc->log.vma->obj->base.size);
218
219 /* Switch to the next sub buffer */
220 relay_flush(guc->log.relay_chan);
221}
222
223static void *guc_get_write_buffer(struct intel_guc *guc)
224{
225 if (!guc->log.relay_chan)
226 return NULL;
227
228 /* Just get the base address of a new sub buffer and copy data into it
229 * ourselves. NULL will be returned in no-overwrite mode, if all sub
230 * buffers are full. Could have used the relay_write() to indirectly
231 * copy the data, but that would have been bit convoluted, as we need to
232 * write to only certain locations inside a sub buffer which cannot be
233 * done without using relay_reserve() along with relay_write(). So its
234 * better to use relay_reserve() alone.
235 */
236 return relay_reserve(guc->log.relay_chan, 0);
237}
238
239static bool guc_check_log_buf_overflow(struct intel_guc *guc,
240 enum guc_log_buffer_type type,
241 unsigned int full_cnt)
242{
243 unsigned int prev_full_cnt = guc->log.prev_overflow_count[type];
244 bool overflow = false;
245
246 if (full_cnt != prev_full_cnt) {
247 overflow = true;
248
249 guc->log.prev_overflow_count[type] = full_cnt;
250 guc->log.total_overflow_count[type] += full_cnt - prev_full_cnt;
251
252 if (full_cnt < prev_full_cnt) {
253 /* buffer_full_cnt is a 4 bit counter */
254 guc->log.total_overflow_count[type] += 16;
255 }
256 DRM_ERROR_RATELIMITED("GuC log buffer overflow\n");
257 }
258
259 return overflow;
260}
261
262static unsigned int guc_get_log_buffer_size(enum guc_log_buffer_type type)
263{
264 switch (type) {
265 case GUC_ISR_LOG_BUFFER:
266 return (GUC_LOG_ISR_PAGES + 1) * PAGE_SIZE;
267 case GUC_DPC_LOG_BUFFER:
268 return (GUC_LOG_DPC_PAGES + 1) * PAGE_SIZE;
269 case GUC_CRASH_DUMP_LOG_BUFFER:
270 return (GUC_LOG_CRASH_PAGES + 1) * PAGE_SIZE;
271 default:
272 MISSING_CASE(type);
273 }
274
275 return 0;
276}
277
278static void guc_read_update_log_buffer(struct intel_guc *guc)
279{
280 unsigned int buffer_size, read_offset, write_offset, bytes_to_copy, full_cnt;
281 struct guc_log_buffer_state *log_buf_state, *log_buf_snapshot_state;
282 struct guc_log_buffer_state log_buf_state_local;
283 enum guc_log_buffer_type type;
284 void *src_data, *dst_data;
285 bool new_overflow;
286
287 if (WARN_ON(!guc->log.buf_addr))
288 return;
289
290 /* Get the pointer to shared GuC log buffer */
291 log_buf_state = src_data = guc->log.buf_addr;
292
293 /* Get the pointer to local buffer to store the logs */
294 log_buf_snapshot_state = dst_data = guc_get_write_buffer(guc);
295
296 /* Actual logs are present from the 2nd page */
297 src_data += PAGE_SIZE;
298 dst_data += PAGE_SIZE;
299
300 for (type = GUC_ISR_LOG_BUFFER; type < GUC_MAX_LOG_BUFFER; type++) {
301 /* Make a copy of the state structure, inside GuC log buffer
302 * (which is uncached mapped), on the stack to avoid reading
303 * from it multiple times.
304 */
305 memcpy(&log_buf_state_local, log_buf_state,
306 sizeof(struct guc_log_buffer_state));
307 buffer_size = guc_get_log_buffer_size(type);
308 read_offset = log_buf_state_local.read_ptr;
309 write_offset = log_buf_state_local.sampled_write_ptr;
310 full_cnt = log_buf_state_local.buffer_full_cnt;
311
312 /* Bookkeeping stuff */
313 guc->log.flush_count[type] += log_buf_state_local.flush_to_file;
314 new_overflow = guc_check_log_buf_overflow(guc, type, full_cnt);
315
316 /* Update the state of shared log buffer */
317 log_buf_state->read_ptr = write_offset;
318 log_buf_state->flush_to_file = 0;
319 log_buf_state++;
320
321 if (unlikely(!log_buf_snapshot_state))
322 continue;
323
324 /* First copy the state structure in snapshot buffer */
325 memcpy(log_buf_snapshot_state, &log_buf_state_local,
326 sizeof(struct guc_log_buffer_state));
327
328 /* The write pointer could have been updated by GuC firmware,
329 * after sending the flush interrupt to Host, for consistency
330 * set write pointer value to same value of sampled_write_ptr
331 * in the snapshot buffer.
332 */
333 log_buf_snapshot_state->write_ptr = write_offset;
334 log_buf_snapshot_state++;
335
336 /* Now copy the actual logs. */
337 if (unlikely(new_overflow)) {
338 /* copy the whole buffer in case of overflow */
339 read_offset = 0;
340 write_offset = buffer_size;
341 } else if (unlikely((read_offset > buffer_size) ||
342 (write_offset > buffer_size))) {
343 DRM_ERROR("invalid log buffer state\n");
344 /* copy whole buffer as offsets are unreliable */
345 read_offset = 0;
346 write_offset = buffer_size;
347 }
348
349 /* Just copy the newly written data */
350 if (read_offset > write_offset) {
351 i915_memcpy_from_wc(dst_data, src_data, write_offset);
352 bytes_to_copy = buffer_size - read_offset;
353 } else {
354 bytes_to_copy = write_offset - read_offset;
355 }
356 i915_memcpy_from_wc(dst_data + read_offset,
357 src_data + read_offset, bytes_to_copy);
358
359 src_data += buffer_size;
360 dst_data += buffer_size;
361 }
362
363 if (log_buf_snapshot_state)
364 guc_move_to_next_buf(guc);
365 else {
366 /* Used rate limited to avoid deluge of messages, logs might be
367 * getting consumed by User at a slow rate.
368 */
369 DRM_ERROR_RATELIMITED("no sub-buffer to capture logs\n");
370 guc->log.capture_miss_count++;
371 }
372}
373
374static void guc_log_cleanup(struct intel_guc *guc)
375{
376 struct drm_i915_private *dev_priv = guc_to_i915(guc);
377
378 lockdep_assert_held(&dev_priv->drm.struct_mutex);
379
380 /* First disable the flush interrupt */
381 gen9_disable_guc_interrupts(dev_priv);
382
383 if (guc->log.flush_wq)
384 destroy_workqueue(guc->log.flush_wq);
385
386 guc->log.flush_wq = NULL;
387
388 if (guc->log.relay_chan)
389 guc_log_remove_relay_file(guc);
390
391 guc->log.relay_chan = NULL;
392
393 if (guc->log.buf_addr)
394 i915_gem_object_unpin_map(guc->log.vma->obj);
395
396 guc->log.buf_addr = NULL;
397}
398
399static void capture_logs_work(struct work_struct *work)
400{
401 struct intel_guc *guc =
402 container_of(work, struct intel_guc, log.flush_work);
403
404 guc_log_capture_logs(guc);
405}
406
407static int guc_log_create_extras(struct intel_guc *guc)
408{
409 struct drm_i915_private *dev_priv = guc_to_i915(guc);
410 void *vaddr;
411 int ret;
412
413 lockdep_assert_held(&dev_priv->drm.struct_mutex);
414
415 /* Nothing to do */
416 if (i915.guc_log_level < 0)
417 return 0;
418
419 if (!guc->log.buf_addr) {
420 /* Create a WC (Uncached for read) vmalloc mapping of log
421 * buffer pages, so that we can directly get the data
422 * (up-to-date) from memory.
423 */
424 vaddr = i915_gem_object_pin_map(guc->log.vma->obj, I915_MAP_WC);
425 if (IS_ERR(vaddr)) {
426 ret = PTR_ERR(vaddr);
427 DRM_ERROR("Couldn't map log buffer pages %d\n", ret);
428 return ret;
429 }
430
431 guc->log.buf_addr = vaddr;
432 }
433
434 if (!guc->log.relay_chan) {
435 /* Create a relay channel, so that we have buffers for storing
436 * the GuC firmware logs, the channel will be linked with a file
437 * later on when debugfs is registered.
438 */
439 ret = guc_log_create_relay_channel(guc);
440 if (ret)
441 return ret;
442 }
443
444 if (!guc->log.flush_wq) {
445 INIT_WORK(&guc->log.flush_work, capture_logs_work);
446
447 /*
448 * GuC log buffer flush work item has to do register access to
449 * send the ack to GuC and this work item, if not synced before
450 * suspend, can potentially get executed after the GFX device is
451 * suspended.
452 * By marking the WQ as freezable, we don't have to bother about
453 * flushing of this work item from the suspend hooks, the pending
454 * work item if any will be either executed before the suspend
455 * or scheduled later on resume. This way the handling of work
456 * item can be kept same between system suspend & rpm suspend.
457 */
458 guc->log.flush_wq = alloc_ordered_workqueue("i915-guc_log",
459 WQ_HIGHPRI | WQ_FREEZABLE);
460 if (guc->log.flush_wq == NULL) {
461 DRM_ERROR("Couldn't allocate the wq for GuC logging\n");
462 return -ENOMEM;
463 }
464 }
465
466 return 0;
467}
468
469void intel_guc_log_create(struct intel_guc *guc)
470{
471 struct i915_vma *vma;
472 unsigned long offset;
473 uint32_t size, flags;
474
475 if (i915.guc_log_level > GUC_LOG_VERBOSITY_MAX)
476 i915.guc_log_level = GUC_LOG_VERBOSITY_MAX;
477
478 /* The first page is to save log buffer state. Allocate one
479 * extra page for others in case for overlap */
480 size = (1 + GUC_LOG_DPC_PAGES + 1 +
481 GUC_LOG_ISR_PAGES + 1 +
482 GUC_LOG_CRASH_PAGES + 1) << PAGE_SHIFT;
483
484 vma = guc->log.vma;
485 if (!vma) {
486 /* We require SSE 4.1 for fast reads from the GuC log buffer and
487 * it should be present on the chipsets supporting GuC based
488 * submisssions.
489 */
490 if (WARN_ON(!i915_has_memcpy_from_wc())) {
491 /* logging will not be enabled */
492 i915.guc_log_level = -1;
493 return;
494 }
495
496 vma = intel_guc_allocate_vma(guc, size);
497 if (IS_ERR(vma)) {
498 /* logging will be off */
499 i915.guc_log_level = -1;
500 return;
501 }
502
503 guc->log.vma = vma;
504
505 if (guc_log_create_extras(guc)) {
506 guc_log_cleanup(guc);
507 i915_vma_unpin_and_release(&guc->log.vma);
508 i915.guc_log_level = -1;
509 return;
510 }
511 }
512
513 /* each allocated unit is a page */
514 flags = GUC_LOG_VALID | GUC_LOG_NOTIFY_ON_HALF_FULL |
515 (GUC_LOG_DPC_PAGES << GUC_LOG_DPC_SHIFT) |
516 (GUC_LOG_ISR_PAGES << GUC_LOG_ISR_SHIFT) |
517 (GUC_LOG_CRASH_PAGES << GUC_LOG_CRASH_SHIFT);
518
519 offset = guc_ggtt_offset(vma) >> PAGE_SHIFT; /* in pages */
520 guc->log.flags = (offset << GUC_LOG_BUF_ADDR_SHIFT) | flags;
521}
522
523static int guc_log_late_setup(struct intel_guc *guc)
524{
525 struct drm_i915_private *dev_priv = guc_to_i915(guc);
526 int ret;
527
528 lockdep_assert_held(&dev_priv->drm.struct_mutex);
529
530 if (i915.guc_log_level < 0)
531 return -EINVAL;
532
533 /* If log_level was set as -1 at boot time, then setup needed to
534 * handle log buffer flush interrupts would not have been done yet,
535 * so do that now.
536 */
537 ret = guc_log_create_extras(guc);
538 if (ret)
539 goto err;
540
541 ret = guc_log_create_relay_file(guc);
542 if (ret)
543 goto err;
544
545 return 0;
546err:
547 guc_log_cleanup(guc);
548 /* logging will remain off */
549 i915.guc_log_level = -1;
550 return ret;
551}
552
553static void guc_log_capture_logs(struct intel_guc *guc)
554{
555 struct drm_i915_private *dev_priv = guc_to_i915(guc);
556
557 guc_read_update_log_buffer(guc);
558
559 /* Generally device is expected to be active only at this
560 * time, so get/put should be really quick.
561 */
562 intel_runtime_pm_get(dev_priv);
563 guc_log_flush_complete(guc);
564 intel_runtime_pm_put(dev_priv);
565}
566
567static void guc_flush_logs(struct intel_guc *guc)
568{
569 struct drm_i915_private *dev_priv = guc_to_i915(guc);
570
571 if (!i915.enable_guc_submission || (i915.guc_log_level < 0))
572 return;
573
574 /* First disable the interrupts, will be renabled afterwards */
575 gen9_disable_guc_interrupts(dev_priv);
576
577 /* Before initiating the forceful flush, wait for any pending/ongoing
578 * flush to complete otherwise forceful flush may not actually happen.
579 */
580 flush_work(&guc->log.flush_work);
581
582 /* Ask GuC to update the log buffer state */
583 guc_log_flush(guc);
584
585 /* GuC would have updated log buffer by now, so capture it */
586 guc_log_capture_logs(guc);
587}
588
589int i915_guc_log_control(struct drm_i915_private *dev_priv, u64 control_val)
590{
591 struct intel_guc *guc = &dev_priv->guc;
592
593 union guc_log_control log_param;
594 int ret;
595
596 log_param.value = control_val;
597
598 if (log_param.verbosity < GUC_LOG_VERBOSITY_MIN ||
599 log_param.verbosity > GUC_LOG_VERBOSITY_MAX)
600 return -EINVAL;
601
602 /* This combination doesn't make sense & won't have any effect */
603 if (!log_param.logging_enabled && (i915.guc_log_level < 0))
604 return 0;
605
606 ret = guc_log_control(guc, log_param.value);
607 if (ret < 0) {
608 DRM_DEBUG_DRIVER("guc_logging_control action failed %d\n", ret);
609 return ret;
610 }
611
612 i915.guc_log_level = log_param.verbosity;
613
614 /* If log_level was set as -1 at boot time, then the relay channel file
615 * wouldn't have been created by now and interrupts also would not have
616 * been enabled.
617 */
618 if (!dev_priv->guc.log.relay_chan) {
619 ret = guc_log_late_setup(guc);
620 if (!ret)
621 gen9_enable_guc_interrupts(dev_priv);
622 } else if (!log_param.logging_enabled) {
623 /* Once logging is disabled, GuC won't generate logs & send an
624 * interrupt. But there could be some data in the log buffer
625 * which is yet to be captured. So request GuC to update the log
626 * buffer state and then collect the left over logs.
627 */
628 guc_flush_logs(guc);
629
630 /* As logging is disabled, update log level to reflect that */
631 i915.guc_log_level = -1;
632 } else {
633 /* In case interrupts were disabled, enable them now */
634 gen9_enable_guc_interrupts(dev_priv);
635 }
636
637 return ret;
638}
639
640void i915_guc_log_register(struct drm_i915_private *dev_priv)
641{
642 if (!i915.enable_guc_submission)
643 return;
644
645 mutex_lock(&dev_priv->drm.struct_mutex);
646 guc_log_late_setup(&dev_priv->guc);
647 mutex_unlock(&dev_priv->drm.struct_mutex);
648}
649
650void i915_guc_log_unregister(struct drm_i915_private *dev_priv)
651{
652 if (!i915.enable_guc_submission)
653 return;
654
655 mutex_lock(&dev_priv->drm.struct_mutex);
656 guc_log_cleanup(&dev_priv->guc);
657 mutex_unlock(&dev_priv->drm.struct_mutex);
658}
drivers/gpu/drm/i915/intel_huc.c+338−0
@@ -0,0 +1,338 @@
1/*
2 * Copyright © 2016-2017 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 <linux/firmware.h>
25#include "i915_drv.h"
26#include "intel_uc.h"
27
28/**
29 * DOC: HuC Firmware
30 *
31 * Motivation:
32 * GEN9 introduces a new dedicated firmware for usage in media HEVC (High
33 * Efficiency Video Coding) operations. Userspace can use the firmware
34 * capabilities by adding HuC specific commands to batch buffers.
35 *
36 * Implementation:
37 * The same firmware loader is used as the GuC. However, the actual
38 * loading to HW is deferred until GEM initialization is done.
39 *
40 * Note that HuC firmware loading must be done before GuC loading.
41 */
42
43#define BXT_HUC_FW_MAJOR 01
44#define BXT_HUC_FW_MINOR 07
45#define BXT_BLD_NUM 1398
46
47#define SKL_HUC_FW_MAJOR 01
48#define SKL_HUC_FW_MINOR 07
49#define SKL_BLD_NUM 1398
50
51#define KBL_HUC_FW_MAJOR 02
52#define KBL_HUC_FW_MINOR 00
53#define KBL_BLD_NUM 1810
54
55#define HUC_FW_PATH(platform, major, minor, bld_num) \
56 "i915/" __stringify(platform) "_huc_ver" __stringify(major) "_" \
57 __stringify(minor) "_" __stringify(bld_num) ".bin"
58
59#define I915_SKL_HUC_UCODE HUC_FW_PATH(skl, SKL_HUC_FW_MAJOR, \
60 SKL_HUC_FW_MINOR, SKL_BLD_NUM)
61MODULE_FIRMWARE(I915_SKL_HUC_UCODE);
62
63#define I915_BXT_HUC_UCODE HUC_FW_PATH(bxt, BXT_HUC_FW_MAJOR, \
64 BXT_HUC_FW_MINOR, BXT_BLD_NUM)
65MODULE_FIRMWARE(I915_BXT_HUC_UCODE);
66
67#define I915_KBL_HUC_UCODE HUC_FW_PATH(kbl, KBL_HUC_FW_MAJOR, \
68 KBL_HUC_FW_MINOR, KBL_BLD_NUM)
69MODULE_FIRMWARE(I915_KBL_HUC_UCODE);
70
71/**
72 * huc_ucode_xfer() - DMA's the firmware
73 * @dev_priv: the drm_i915_private device
74 *
75 * Transfer the firmware image to RAM for execution by the microcontroller.
76 *
77 * Return: 0 on success, non-zero on failure
78 */
79static int huc_ucode_xfer(struct drm_i915_private *dev_priv)
80{
81 struct intel_uc_fw *huc_fw = &dev_priv->huc.fw;
82 struct i915_vma *vma;
83 unsigned long offset = 0;
84 u32 size;
85 int ret;
86
87 ret = i915_gem_object_set_to_gtt_domain(huc_fw->obj, false);
88 if (ret) {
89 DRM_DEBUG_DRIVER("set-domain failed %d\n", ret);
90 return ret;
91 }
92
93 vma = i915_gem_object_ggtt_pin(huc_fw->obj, NULL, 0, 0,
94 PIN_OFFSET_BIAS | GUC_WOPCM_TOP);
95 if (IS_ERR(vma)) {
96 DRM_DEBUG_DRIVER("pin failed %d\n", (int)PTR_ERR(vma));
97 return PTR_ERR(vma);
98 }
99
100 intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL);
101
102 /* init WOPCM */
103 I915_WRITE(GUC_WOPCM_SIZE, intel_guc_wopcm_size(dev_priv));
104 I915_WRITE(DMA_GUC_WOPCM_OFFSET, GUC_WOPCM_OFFSET_VALUE |
105 HUC_LOADING_AGENT_GUC);
106
107 /* Set the source address for the uCode */
108 offset = guc_ggtt_offset(vma) + huc_fw->header_offset;
109 I915_WRITE(DMA_ADDR_0_LOW, lower_32_bits(offset));
110 I915_WRITE(DMA_ADDR_0_HIGH, upper_32_bits(offset) & 0xFFFF);
111
112 /* Hardware doesn't look at destination address for HuC. Set it to 0,
113 * but still program the correct address space.
114 */
115 I915_WRITE(DMA_ADDR_1_LOW, 0);
116 I915_WRITE(DMA_ADDR_1_HIGH, DMA_ADDRESS_SPACE_WOPCM);
117
118 size = huc_fw->header_size + huc_fw->ucode_size;
119 I915_WRITE(DMA_COPY_SIZE, size);
120
121 /* Start the DMA */
122 I915_WRITE(DMA_CTRL, _MASKED_BIT_ENABLE(HUC_UKERNEL | START_DMA));
123
124 /* Wait for DMA to finish */
125 ret = wait_for((I915_READ(DMA_CTRL) & START_DMA) == 0, 100);
126
127 DRM_DEBUG_DRIVER("HuC DMA transfer wait over with ret %d\n", ret);
128
129 /* Disable the bits once DMA is over */
130 I915_WRITE(DMA_CTRL, _MASKED_BIT_DISABLE(HUC_UKERNEL));
131
132 intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL);
133
134 /*
135 * We keep the object pages for reuse during resume. But we can unpin it
136 * now that DMA has completed, so it doesn't continue to take up space.
137 */
138 i915_vma_unpin(vma);
139
140 return ret;
141}
142
143/**
144 * intel_huc_init() - initiate HuC firmware loading request
145 * @dev_priv: the drm_i915_private device
146 *
147 * Called early during driver load, but after GEM is initialised. The loading
148 * will continue only when driver explicitly specify firmware name and version.
149 * All other cases are considered as INTEL_UC_FIRMWARE_NONE either because HW
150 * is not capable or driver yet support it. And there will be no error message
151 * for INTEL_UC_FIRMWARE_NONE cases.
152 *
153 * The DMA-copying to HW is done later when intel_huc_load() is called.
154 */
155void intel_huc_init(struct drm_i915_private *dev_priv)
156{
157 struct intel_huc *huc = &dev_priv->huc;
158 struct intel_uc_fw *huc_fw = &huc->fw;
159 const char *fw_path = NULL;
160
161 huc_fw->path = NULL;
162 huc_fw->fetch_status = INTEL_UC_FIRMWARE_NONE;
163 huc_fw->load_status = INTEL_UC_FIRMWARE_NONE;
164 huc_fw->fw = INTEL_UC_FW_TYPE_HUC;
165
166 if (!HAS_HUC_UCODE(dev_priv))
167 return;
168
169 if (IS_SKYLAKE(dev_priv)) {
170 fw_path = I915_SKL_HUC_UCODE;
171 huc_fw->major_ver_wanted = SKL_HUC_FW_MAJOR;
172 huc_fw->minor_ver_wanted = SKL_HUC_FW_MINOR;
173 } else if (IS_BROXTON(dev_priv)) {
174 fw_path = I915_BXT_HUC_UCODE;
175 huc_fw->major_ver_wanted = BXT_HUC_FW_MAJOR;
176 huc_fw->minor_ver_wanted = BXT_HUC_FW_MINOR;
177 } else if (IS_KABYLAKE(dev_priv)) {
178 fw_path = I915_KBL_HUC_UCODE;
179 huc_fw->major_ver_wanted = KBL_HUC_FW_MAJOR;
180 huc_fw->minor_ver_wanted = KBL_HUC_FW_MINOR;
181 }
182
183 huc_fw->path = fw_path;
184 huc_fw->fetch_status = INTEL_UC_FIRMWARE_PENDING;
185
186 DRM_DEBUG_DRIVER("HuC firmware pending, path %s\n", fw_path);
187
188 WARN(huc_fw->path == NULL, "HuC present but no fw path\n");
189
190 intel_uc_fw_fetch(dev_priv, huc_fw);
191}
192
193/**
194 * intel_huc_load() - load HuC uCode to device
195 * @dev_priv: the drm_i915_private device
196 *
197 * Called from guc_setup() during driver loading and also after a GPU reset.
198 * Be note that HuC loading must be done before GuC loading.
199 *
200 * The firmware image should have already been fetched into memory by the
201 * earlier call to intel_huc_init(), so here we need only check that
202 * is succeeded, and then transfer the image to the h/w.
203 *
204 * Return: non-zero code on error
205 */
206int intel_huc_load(struct drm_i915_private *dev_priv)
207{
208 struct intel_uc_fw *huc_fw = &dev_priv->huc.fw;
209 int err;
210
211 if (huc_fw->fetch_status == INTEL_UC_FIRMWARE_NONE)
212 return 0;
213
214 DRM_DEBUG_DRIVER("%s fw status: fetch %s, load %s\n",
215 huc_fw->path,
216 intel_uc_fw_status_repr(huc_fw->fetch_status),
217 intel_uc_fw_status_repr(huc_fw->load_status));
218
219 if (huc_fw->fetch_status == INTEL_UC_FIRMWARE_SUCCESS &&
220 huc_fw->load_status == INTEL_UC_FIRMWARE_FAIL)
221 return -ENOEXEC;
222
223 huc_fw->load_status = INTEL_UC_FIRMWARE_PENDING;
224
225 switch (huc_fw->fetch_status) {
226 case INTEL_UC_FIRMWARE_FAIL:
227 /* something went wrong :( */
228 err = -EIO;
229 goto fail;
230
231 case INTEL_UC_FIRMWARE_NONE:
232 case INTEL_UC_FIRMWARE_PENDING:
233 default:
234 /* "can't happen" */
235 WARN_ONCE(1, "HuC fw %s invalid fetch_status %s [%d]\n",
236 huc_fw->path,
237 intel_uc_fw_status_repr(huc_fw->fetch_status),
238 huc_fw->fetch_status);
239 err = -ENXIO;
240 goto fail;
241
242 case INTEL_UC_FIRMWARE_SUCCESS:
243 break;
244 }
245
246 err = huc_ucode_xfer(dev_priv);
247 if (err)
248 goto fail;
249
250 huc_fw->load_status = INTEL_UC_FIRMWARE_SUCCESS;
251
252 DRM_DEBUG_DRIVER("%s fw status: fetch %s, load %s\n",
253 huc_fw->path,
254 intel_uc_fw_status_repr(huc_fw->fetch_status),
255 intel_uc_fw_status_repr(huc_fw->load_status));
256
257 return 0;
258
259fail:
260 if (huc_fw->load_status == INTEL_UC_FIRMWARE_PENDING)
261 huc_fw->load_status = INTEL_UC_FIRMWARE_FAIL;
262
263 DRM_ERROR("Failed to complete HuC uCode load with ret %d\n", err);
264
265 return err;
266}
267
268/**
269 * intel_huc_fini() - clean up resources allocated for HuC
270 * @dev_priv: the drm_i915_private device
271 *
272 * Cleans up by releasing the huc firmware GEM obj.
273 */
274void intel_huc_fini(struct drm_i915_private *dev_priv)
275{
276 struct intel_uc_fw *huc_fw = &dev_priv->huc.fw;
277
278 mutex_lock(&dev_priv->drm.struct_mutex);
279 if (huc_fw->obj)
280 i915_gem_object_put(huc_fw->obj);
281 huc_fw->obj = NULL;
282 mutex_unlock(&dev_priv->drm.struct_mutex);
283
284 huc_fw->fetch_status = INTEL_UC_FIRMWARE_NONE;
285}
286
287/**
288 * intel_guc_auth_huc() - authenticate ucode
289 * @dev_priv: the drm_i915_device
290 *
291 * Triggers a HuC fw authentication request to the GuC via intel_guc_action_
292 * authenticate_huc interface.
293 */
294void intel_guc_auth_huc(struct drm_i915_private *dev_priv)
295{
296 struct intel_guc *guc = &dev_priv->guc;
297 struct intel_huc *huc = &dev_priv->huc;
298 struct i915_vma *vma;
299 int ret;
300 u32 data[2];
301
302 if (huc->fw.load_status != INTEL_UC_FIRMWARE_SUCCESS)
303 return;
304
305 vma = i915_gem_object_ggtt_pin(huc->fw.obj, NULL, 0, 0,
306 PIN_OFFSET_BIAS | GUC_WOPCM_TOP);
307 if (IS_ERR(vma)) {
308 DRM_ERROR("failed to pin huc fw object %d\n",
309 (int)PTR_ERR(vma));
310 return;
311 }
312
313 /* Specify auth action and where public signature is. */
314 data[0] = INTEL_GUC_ACTION_AUTHENTICATE_HUC;
315 data[1] = guc_ggtt_offset(vma) + huc->fw.rsa_offset;
316
317 ret = intel_guc_send(guc, data, ARRAY_SIZE(data));
318 if (ret) {
319 DRM_ERROR("HuC: GuC did not ack Auth request %d\n", ret);
320 goto out;
321 }
322
323 /* Check authentication status, it should be done by now */
324 ret = intel_wait_for_register(dev_priv,
325 HUC_STATUS2,
326 HUC_FW_VERIFIED,
327 HUC_FW_VERIFIED,
328 50);
329
330 if (ret) {
331 DRM_ERROR("HuC: Authentication failed %d\n", ret);
332 goto out;
333 }
334
335out:
336 i915_vma_unpin(vma);
337}
338
drivers/gpu/drm/i915/intel_lrc.c+6−18
@@ -811,12 +811,6 @@ static int execlists_context_pin(struct intel_engine_cs *engine, · 810 unmodified lines
811 811
812 ce->state->obj->mm.dirty = true;812 ce->state->obj->mm.dirty = true;
813 813
814 /* Invalidate GuC TLB. */
815 if (i915.enable_guc_submission) {
816 struct drm_i915_private *dev_priv = ctx->i915;
817 I915_WRITE(GEN8_GTCR, GEN8_GTCR_INVALIDATE);
818 }
819
820 i915_gem_context_get(ctx);814 i915_gem_context_get(ctx);
821 return 0;815 return 0;
822 816
@@ -1231,7 +1225,7 @@ static int lrc_setup_wa_ctx_obj(struct intel_engine_cs *engine, u32 size) · 408 unmodified lines
1231 if (IS_ERR(obj))1225 if (IS_ERR(obj))
1232 return PTR_ERR(obj);1226 return PTR_ERR(obj);
1233 1227
1234 vma = i915_vma_create(obj, &engine->i915->ggtt.base, NULL);1228 vma = i915_vma_instance(obj, &engine->i915->ggtt.base, NULL);
1235 if (IS_ERR(vma)) {1229 if (IS_ERR(vma)) {
1236 err = PTR_ERR(vma);1230 err = PTR_ERR(vma);
1237 goto err;1231 goto err;
@@ -1917,7 +1911,7 @@ int logical_render_ring_init(struct intel_engine_cs *engine) · 679 unmodified lines
1917 engine->emit_breadcrumb = gen8_emit_breadcrumb_render;1911 engine->emit_breadcrumb = gen8_emit_breadcrumb_render;
1918 engine->emit_breadcrumb_sz = gen8_emit_breadcrumb_render_sz;1912 engine->emit_breadcrumb_sz = gen8_emit_breadcrumb_render_sz;
1919 1913
1920 ret = intel_engine_create_scratch(engine, 4096);1914 ret = intel_engine_create_scratch(engine, PAGE_SIZE);
1921 if (ret)1915 if (ret)
1922 return ret;1916 return ret;
1923 1917
@@ -2093,19 +2087,12 @@ static void execlists_init_reg_state(u32 *reg_state, · 169 unmodified lines
2093 ASSIGN_CTX_REG(reg_state, CTX_PDP0_LDW, GEN8_RING_PDP_LDW(engine, 0),2087 ASSIGN_CTX_REG(reg_state, CTX_PDP0_LDW, GEN8_RING_PDP_LDW(engine, 0),
2094 0);2088 0);
2095 2089
2096 if (USES_FULL_48BIT_PPGTT(ppgtt->base.dev)) {2090 if (ppgtt && USES_FULL_48BIT_PPGTT(ppgtt->base.dev)) {
2097 /* 64b PPGTT (48bit canonical)2091 /* 64b PPGTT (48bit canonical)
2098 * PDP0_DESCRIPTOR contains the base address to PML4 and2092 * PDP0_DESCRIPTOR contains the base address to PML4 and
2099 * other PDP Descriptors are ignored.2093 * other PDP Descriptors are ignored.
2100 */2094 */
2101 ASSIGN_CTX_PML4(ppgtt, reg_state);2095 ASSIGN_CTX_PML4(ppgtt, reg_state);
2102 } else {
2103 /* 32b PPGTT
2104 * PDP*_DESCRIPTOR contains the base address of space supported.
2105 * With dynamic page allocation, PDPs may not be allocated at
2106 * this point. Point the unallocated PDPs to the scratch page
2107 */
2108 execlists_update_context_pdps(ppgtt, reg_state);
2109 }2096 }
2110 2097
2111 if (engine->id == RCS) {2098 if (engine->id == RCS) {
@@ -2199,7 +2186,8 @@ static int execlists_context_deferred_alloc(struct i915_gem_context *ctx, · 87 unmodified lines
2199 2186
2200 WARN_ON(ce->state);2187 WARN_ON(ce->state);
2201 2188
2202 context_size = round_up(intel_lr_context_size(engine), 4096);2189 context_size = round_up(intel_lr_context_size(engine),
2190 I915_GTT_PAGE_SIZE);
2203 2191
2204 /* One extra page as the sharing data between driver and GuC */2192 /* One extra page as the sharing data between driver and GuC */
2205 context_size += PAGE_SIZE * LRC_PPHWSP_PN;2193 context_size += PAGE_SIZE * LRC_PPHWSP_PN;
@@ -2210,7 +2198,7 @@ static int execlists_context_deferred_alloc(struct i915_gem_context *ctx, · 4 unmodified lines
2210 return PTR_ERR(ctx_obj);2198 return PTR_ERR(ctx_obj);
2211 }2199 }
2212 2200
2213 vma = i915_vma_create(ctx_obj, &ctx->i915->ggtt.base, NULL);2201 vma = i915_vma_instance(ctx_obj, &ctx->i915->ggtt.base, NULL);
2214 if (IS_ERR(vma)) {2202 if (IS_ERR(vma)) {
2215 ret = PTR_ERR(vma);2203 ret = PTR_ERR(vma);
2216 goto error_deref_obj;2204 goto error_deref_obj;
drivers/gpu/drm/i915/intel_lrc.h+1−1
@@ -26,7 +26,7 @@ · 25 unmodified lines
26 26
27#include "intel_ringbuffer.h"27#include "intel_ringbuffer.h"
28 28
29#define GEN8_LR_CONTEXT_ALIGN 409629#define GEN8_LR_CONTEXT_ALIGN I915_GTT_MIN_ALIGNMENT
30 30
31/* Execlists regs */31/* Execlists regs */
32#define RING_ELSP(engine) _MMIO((engine)->mmio_base + 0x230)32#define RING_ELSP(engine) _MMIO((engine)->mmio_base + 0x230)
drivers/gpu/drm/i915/intel_overlay.c+1−2
@@ -811,8 +811,7 @@ static int intel_overlay_do_put_image(struct intel_overlay *overlay, · 810 unmodified lines
811 if (ret != 0)811 if (ret != 0)
812 return ret;812 return ret;
813 813
814 vma = i915_gem_object_pin_to_display_plane(new_bo, 0,814 vma = i915_gem_object_pin_to_display_plane(new_bo, 0, NULL);
815 &i915_ggtt_view_normal);
816 if (IS_ERR(vma))815 if (IS_ERR(vma))
817 return PTR_ERR(vma);816 return PTR_ERR(vma);
818 817
drivers/gpu/drm/i915/intel_pipe_crc.c+88−16
@@ -560,14 +560,14 @@ static void hsw_trans_edp_pipe_A_crc_wa(struct drm_i915_private *dev_priv, · 559 unmodified lines
560 state = drm_atomic_state_alloc(dev);560 state = drm_atomic_state_alloc(dev);
561 if (!state) {561 if (!state) {
562 ret = -ENOMEM;562 ret = -ENOMEM;
563 goto out;563 goto unlock;
564 }564 }
565 565
566 state->acquire_ctx = drm_modeset_legacy_acquire_ctx(&crtc->base);566 state->acquire_ctx = drm_modeset_legacy_acquire_ctx(&crtc->base);
567 pipe_config = intel_atomic_get_crtc_state(state, crtc);567 pipe_config = intel_atomic_get_crtc_state(state, crtc);
568 if (IS_ERR(pipe_config)) {568 if (IS_ERR(pipe_config)) {
569 ret = PTR_ERR(pipe_config);569 ret = PTR_ERR(pipe_config);
570 goto out;570 goto put_state;
571 }571 }
572 572
573 pipe_config->pch_pfit.force_thru = enable;573 pipe_config->pch_pfit.force_thru = enable;
@@ -576,10 +576,12 @@ static void hsw_trans_edp_pipe_A_crc_wa(struct drm_i915_private *dev_priv, · 2 unmodified lines
576 pipe_config->base.connectors_changed = true;576 pipe_config->base.connectors_changed = true;
577 577
578 ret = drm_atomic_commit(state);578 ret = drm_atomic_commit(state);
579out:579
580put_state:
581 drm_atomic_state_put(state);
582unlock:
580 WARN(ret, "Toggling workaround to %i returns %i\n", enable, ret);583 WARN(ret, "Toggling workaround to %i returns %i\n", enable, ret);
581 drm_modeset_unlock_all(dev);584 drm_modeset_unlock_all(dev);
582 drm_atomic_state_put(state);
583}585}
584 586
585static int ivb_pipe_crc_ctl_reg(struct drm_i915_private *dev_priv,587static int ivb_pipe_crc_ctl_reg(struct drm_i915_private *dev_priv,
@@ -613,6 +615,22 @@ static int ivb_pipe_crc_ctl_reg(struct drm_i915_private *dev_priv, · 27 unmodified lines
613 return 0;615 return 0;
614}616}
615 617
618static int get_new_crc_ctl_reg(struct drm_i915_private *dev_priv,
619 enum pipe pipe,
620 enum intel_pipe_crc_source *source, u32 *val)
621{
622 if (IS_GEN2(dev_priv))
623 return i8xx_pipe_crc_ctl_reg(source, val);
624 else if (INTEL_GEN(dev_priv) < 5)
625 return i9xx_pipe_crc_ctl_reg(dev_priv, pipe, source, val);
626 else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
627 return vlv_pipe_crc_ctl_reg(dev_priv, pipe, source, val);
628 else if (IS_GEN5(dev_priv) || IS_GEN6(dev_priv))
629 return ilk_pipe_crc_ctl_reg(source, val);
630 else
631 return ivb_pipe_crc_ctl_reg(dev_priv, pipe, source, val);
632}
633
616static int pipe_crc_set_source(struct drm_i915_private *dev_priv,634static int pipe_crc_set_source(struct drm_i915_private *dev_priv,
617 enum pipe pipe,635 enum pipe pipe,
618 enum intel_pipe_crc_source source)636 enum intel_pipe_crc_source source)
@@ -636,17 +654,7 @@ static int pipe_crc_set_source(struct drm_i915_private *dev_priv, · 17 unmodified lines
636 return -EIO;654 return -EIO;
637 }655 }
638 656
639 if (IS_GEN2(dev_priv))657 ret = get_new_crc_ctl_reg(dev_priv, pipe, &source, &val);
640 ret = i8xx_pipe_crc_ctl_reg(&source, &val);
641 else if (INTEL_GEN(dev_priv) < 5)
642 ret = i9xx_pipe_crc_ctl_reg(dev_priv, pipe, &source, &val);
643 else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
644 ret = vlv_pipe_crc_ctl_reg(dev_priv, pipe, &source, &val);
645 else if (IS_GEN5(dev_priv) || IS_GEN6(dev_priv))
646 ret = ilk_pipe_crc_ctl_reg(&source, &val);
647 else
648 ret = ivb_pipe_crc_ctl_reg(dev_priv, pipe, &source, &val);
649
650 if (ret != 0)658 if (ret != 0)
651 goto out;659 goto out;
652 660
@@ -687,7 +695,7 @@ static int pipe_crc_set_source(struct drm_i915_private *dev_priv, · 34 unmodified lines
687 POSTING_READ(PIPE_CRC_CTL(pipe));695 POSTING_READ(PIPE_CRC_CTL(pipe));
688 696
689 /* real source -> none transition */697 /* real source -> none transition */
690 if (source == INTEL_PIPE_CRC_SOURCE_NONE) {698 if (!source) {
691 struct intel_pipe_crc_entry *entries;699 struct intel_pipe_crc_entry *entries;
692 struct intel_crtc *crtc = intel_get_crtc_for_pipe(dev_priv,700 struct intel_crtc *crtc = intel_get_crtc_for_pipe(dev_priv,
693 pipe);701 pipe);
@@ -809,6 +817,11 @@ display_crc_ctl_parse_source(const char *buf, enum intel_pipe_crc_source *s) · 115 unmodified lines
809{817{
810 int i;818 int i;
811 819
820 if (!buf) {
821 *s = INTEL_PIPE_CRC_SOURCE_NONE;
822 return 0;
823 }
824
812 for (i = 0; i < ARRAY_SIZE(pipe_crc_sources); i++)825 for (i = 0; i < ARRAY_SIZE(pipe_crc_sources); i++)
813 if (!strcmp(buf, pipe_crc_sources[i])) {826 if (!strcmp(buf, pipe_crc_sources[i])) {
814 *s = i;827 *s = i;
@@ -937,3 +950,62 @@ void intel_pipe_crc_cleanup(struct drm_minor *minor) · 122 unmodified lines
937 drm_debugfs_remove_files(info_list, 1, minor);950 drm_debugfs_remove_files(info_list, 1, minor);
938 }951 }
939}952}
953
954int intel_crtc_set_crc_source(struct drm_crtc *crtc, const char *source_name,
955 size_t *values_cnt)
956{
957 struct drm_i915_private *dev_priv = crtc->dev->dev_private;
958 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[crtc->index];
959 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
960 enum intel_display_power_domain power_domain;
961 enum intel_pipe_crc_source source;
962 u32 val = 0; /* shut up gcc */
963 int ret = 0;
964
965 if (display_crc_ctl_parse_source(source_name, &source) < 0) {
966 DRM_DEBUG_DRIVER("unknown source %s\n", source_name);
967 return -EINVAL;
968 }
969
970 power_domain = POWER_DOMAIN_PIPE(crtc->index);
971 if (!intel_display_power_get_if_enabled(dev_priv, power_domain)) {
972 DRM_DEBUG_KMS("Trying to capture CRC while pipe is off\n");
973 return -EIO;
974 }
975
976 ret = get_new_crc_ctl_reg(dev_priv, crtc->index, &source, &val);
977 if (ret != 0)
978 goto out;
979
980 if (source) {
981 /*
982 * When IPS gets enabled, the pipe CRC changes. Since IPS gets
983 * enabled and disabled dynamically based on package C states,
984 * user space can't make reliable use of the CRCs, so let's just
985 * completely disable it.
986 */
987 hsw_disable_ips(intel_crtc);
988 }
989
990 I915_WRITE(PIPE_CRC_CTL(crtc->index), val);
991 POSTING_READ(PIPE_CRC_CTL(crtc->index));
992
993 if (!source) {
994 if (IS_G4X(dev_priv))
995 g4x_undo_pipe_scramble_reset(dev_priv, crtc->index);
996 else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
997 vlv_undo_pipe_scramble_reset(dev_priv, crtc->index);
998 else if (IS_HASWELL(dev_priv) && crtc->index == PIPE_A)
999 hsw_trans_edp_pipe_A_crc_wa(dev_priv, false);
1000
1001 hsw_enable_ips(intel_crtc);
1002 }
1003
1004 pipe_crc->skipped = 0;
1005 *values_cnt = 5;
1006
1007out:
1008 intel_display_power_put(dev_priv, power_domain);
1009
1010 return ret;
1011}
drivers/gpu/drm/i915/intel_psr.c+160−43
@@ -122,13 +122,26 @@ static void vlv_psr_setup_vsc(struct intel_dp *intel_dp) · 121 unmodified lines
122static void skl_psr_setup_su_vsc(struct intel_dp *intel_dp)122static void skl_psr_setup_su_vsc(struct intel_dp *intel_dp)
123{123{
124 struct edp_vsc_psr psr_vsc;124 struct edp_vsc_psr psr_vsc;
125 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
126 struct drm_device *dev = intel_dig_port->base.base.dev;
127 struct drm_i915_private *dev_priv = to_i915(dev);
125 128
126 /* Prepare VSC Header for SU as per EDP 1.4 spec, Table 6.11 */129 /* Prepare VSC Header for SU as per EDP 1.4 spec, Table 6.11 */
127 memset(&psr_vsc, 0, sizeof(psr_vsc));130 memset(&psr_vsc, 0, sizeof(psr_vsc));
128 psr_vsc.sdp_header.HB0 = 0;131 psr_vsc.sdp_header.HB0 = 0;
129 psr_vsc.sdp_header.HB1 = 0x7;132 psr_vsc.sdp_header.HB1 = 0x7;
130 psr_vsc.sdp_header.HB2 = 0x3;133 if (dev_priv->psr.colorimetry_support &&
131 psr_vsc.sdp_header.HB3 = 0xb;134 dev_priv->psr.y_cord_support) {
135 psr_vsc.sdp_header.HB2 = 0x5;
136 psr_vsc.sdp_header.HB3 = 0x13;
137 } else if (dev_priv->psr.y_cord_support) {
138 psr_vsc.sdp_header.HB2 = 0x4;
139 psr_vsc.sdp_header.HB3 = 0xe;
140 } else {
141 psr_vsc.sdp_header.HB2 = 0x3;
142 psr_vsc.sdp_header.HB3 = 0xc;
143 }
144
132 intel_psr_write_vsc(intel_dp, &psr_vsc);145 intel_psr_write_vsc(intel_dp, &psr_vsc);
133}146}
134 147
@@ -196,7 +209,11 @@ static void hsw_psr_enable_sink(struct intel_dp *intel_dp) · 61 unmodified lines
196 drm_dp_dpcd_writeb(&intel_dp->aux,209 drm_dp_dpcd_writeb(&intel_dp->aux,
197 DP_SINK_DEVICE_AUX_FRAME_SYNC_CONF,210 DP_SINK_DEVICE_AUX_FRAME_SYNC_CONF,
198 DP_AUX_FRAME_SYNC_ENABLE);211 DP_AUX_FRAME_SYNC_ENABLE);
199 212 /* Enable ALPM at sink for psr2 */
213 if (dev_priv->psr.psr2_support && dev_priv->psr.alpm)
214 drm_dp_dpcd_writeb(&intel_dp->aux,
215 DP_RECEIVER_ALPM_CONFIG,
216 DP_ALPM_ENABLE);
200 if (dev_priv->psr.link_standby)217 if (dev_priv->psr.link_standby)
201 drm_dp_dpcd_writeb(&intel_dp->aux, DP_PSR_EN_CFG,218 drm_dp_dpcd_writeb(&intel_dp->aux, DP_PSR_EN_CFG,
202 DP_PSR_ENABLE | DP_PSR_MAIN_LINK_ACTIVE);219 DP_PSR_ENABLE | DP_PSR_MAIN_LINK_ACTIVE);
@@ -248,7 +265,7 @@ static void vlv_psr_activate(struct intel_dp *intel_dp) · 45 unmodified lines
248 VLV_EDP_PSR_ACTIVE_ENTRY);265 VLV_EDP_PSR_ACTIVE_ENTRY);
249}266}
250 267
251static void hsw_psr_enable_source(struct intel_dp *intel_dp)268static void intel_enable_source_psr1(struct intel_dp *intel_dp)
252{269{
253 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);270 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
254 struct drm_device *dev = dig_port->base.base.dev;271 struct drm_device *dev = dig_port->base.base.dev;
@@ -299,14 +316,31 @@ static void hsw_psr_enable_source(struct intel_dp *intel_dp) · 44 unmodified lines
299 val |= EDP_PSR_TP1_TP2_SEL;316 val |= EDP_PSR_TP1_TP2_SEL;
300 317
301 I915_WRITE(EDP_PSR_CTL, val);318 I915_WRITE(EDP_PSR_CTL, val);
319}
302 320
303 if (!dev_priv->psr.psr2_support)321static void intel_enable_source_psr2(struct intel_dp *intel_dp)
304 return;322{
323 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
324 struct drm_device *dev = dig_port->base.base.dev;
325 struct drm_i915_private *dev_priv = to_i915(dev);
326 /*
327 * Let's respect VBT in case VBT asks a higher idle_frame value.
328 * Let's use 6 as the minimum to cover all known cases including
329 * the off-by-one issue that HW has in some cases. Also there are
330 * cases where sink should be able to train
331 * with the 5 or 6 idle patterns.
332 */
333 uint32_t idle_frames = max(6, dev_priv->vbt.psr.idle_frames);
334 uint32_t val;
335
336 val = idle_frames << EDP_PSR_IDLE_FRAME_SHIFT;
305 337
306 /* FIXME: selective update is probably totally broken because it doesn't338 /* FIXME: selective update is probably totally broken because it doesn't
307 * mesh at all with our frontbuffer tracking. And the hw alone isn't339 * mesh at all with our frontbuffer tracking. And the hw alone isn't
308 * good enough. */340 * good enough. */
309 val = EDP_PSR2_ENABLE | EDP_SU_TRACK_ENABLE;341 val |= EDP_PSR2_ENABLE |
342 EDP_SU_TRACK_ENABLE |
343 EDP_FRAMES_BEFORE_SU_ENTRY;
310 344
311 if (dev_priv->vbt.psr.tp2_tp3_wakeup_time > 5)345 if (dev_priv->vbt.psr.tp2_tp3_wakeup_time > 5)
312 val |= EDP_PSR2_TP2_TIME_2500;346 val |= EDP_PSR2_TP2_TIME_2500;
@@ -320,6 +354,19 @@ static void hsw_psr_enable_source(struct intel_dp *intel_dp) · 7 unmodified lines
320 I915_WRITE(EDP_PSR2_CTL, val);354 I915_WRITE(EDP_PSR2_CTL, val);
321}355}
322 356
357static void hsw_psr_enable_source(struct intel_dp *intel_dp)
358{
359 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
360 struct drm_device *dev = dig_port->base.base.dev;
361 struct drm_i915_private *dev_priv = to_i915(dev);
362
363 /* psr1 and psr2 are mutually exclusive.*/
364 if (dev_priv->psr.psr2_support)
365 intel_enable_source_psr2(intel_dp);
366 else
367 intel_enable_source_psr1(intel_dp);
368}
369
323static bool intel_psr_match_conditions(struct intel_dp *intel_dp)370static bool intel_psr_match_conditions(struct intel_dp *intel_dp)
324{371{
325 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);372 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
@@ -387,6 +434,22 @@ static bool intel_psr_match_conditions(struct intel_dp *intel_dp) · 61 unmodified lines
387 return false;434 return false;
388 }435 }
389 436
437 /* PSR2 is restricted to work with panel resolutions upto 3200x2000 */
438 if (intel_crtc->config->pipe_src_w > 3200 ||
439 intel_crtc->config->pipe_src_h > 2000) {
440 dev_priv->psr.psr2_support = false;
441 return false;
442 }
443
444 /*
445 * FIXME:enable psr2 only for y-cordinate psr2 panels
446 * After gtc implementation , remove this restriction.
447 */
448 if (!dev_priv->psr.y_cord_support && dev_priv->psr.psr2_support) {
449 DRM_DEBUG_KMS("PSR2 disabled, panel does not support Y coordinate\n");
450 return false;
451 }
452
390 dev_priv->psr.source_ok = true;453 dev_priv->psr.source_ok = true;
391 return true;454 return true;
392}455}
@@ -397,7 +460,10 @@ static void intel_psr_activate(struct intel_dp *intel_dp) · 4 unmodified lines
397 struct drm_device *dev = intel_dig_port->base.base.dev;460 struct drm_device *dev = intel_dig_port->base.base.dev;
398 struct drm_i915_private *dev_priv = to_i915(dev);461 struct drm_i915_private *dev_priv = to_i915(dev);
399 462
400 WARN_ON(I915_READ(EDP_PSR_CTL) & EDP_PSR_ENABLE);463 if (dev_priv->psr.psr2_support)
464 WARN_ON(I915_READ(EDP_PSR2_CTL) & EDP_PSR2_ENABLE);
465 else
466 WARN_ON(I915_READ(EDP_PSR_CTL) & EDP_PSR_ENABLE);
401 WARN_ON(dev_priv->psr.active);467 WARN_ON(dev_priv->psr.active);
402 lockdep_assert_held(&dev_priv->psr.lock);468 lockdep_assert_held(&dev_priv->psr.lock);
403 469
@@ -426,6 +492,8 @@ void intel_psr_enable(struct intel_dp *intel_dp) · 22 unmodified lines
426 struct drm_device *dev = intel_dig_port->base.base.dev;492 struct drm_device *dev = intel_dig_port->base.base.dev;
427 struct drm_i915_private *dev_priv = to_i915(dev);493 struct drm_i915_private *dev_priv = to_i915(dev);
428 struct intel_crtc *crtc = to_intel_crtc(intel_dig_port->base.base.crtc);494 struct intel_crtc *crtc = to_intel_crtc(intel_dig_port->base.base.crtc);
495 enum transcoder cpu_transcoder = crtc->config->cpu_transcoder;
496 u32 chicken;
429 497
430 if (!HAS_PSR(dev_priv)) {498 if (!HAS_PSR(dev_priv)) {
431 DRM_DEBUG_KMS("PSR not supported on this platform\n");499 DRM_DEBUG_KMS("PSR not supported on this platform\n");
@@ -449,26 +517,34 @@ void intel_psr_enable(struct intel_dp *intel_dp) · 17 unmodified lines
449 dev_priv->psr.busy_frontbuffer_bits = 0;517 dev_priv->psr.busy_frontbuffer_bits = 0;
450 518
451 if (HAS_DDI(dev_priv)) {519 if (HAS_DDI(dev_priv)) {
452 hsw_psr_setup_vsc(intel_dp);
453
454 if (dev_priv->psr.psr2_support) {520 if (dev_priv->psr.psr2_support) {
455 /* PSR2 is restricted to work with panel resolutions upto 3200x2000 */521 skl_psr_setup_su_vsc(intel_dp);
456 if (crtc->config->pipe_src_w > 3200 ||522 chicken = PSR2_VSC_ENABLE_PROG_HEADER;
457 crtc->config->pipe_src_h > 2000)523 if (dev_priv->psr.y_cord_support)
458 dev_priv->psr.psr2_support = false;524 chicken |= PSR2_ADD_VERTICAL_LINE_COUNT;
459 else525 I915_WRITE(CHICKEN_TRANS(cpu_transcoder), chicken);
460 skl_psr_setup_su_vsc(intel_dp);526 I915_WRITE(EDP_PSR_DEBUG_CTL,
527 EDP_PSR_DEBUG_MASK_MEMUP |
528 EDP_PSR_DEBUG_MASK_HPD |
529 EDP_PSR_DEBUG_MASK_LPSP |
530 EDP_PSR_DEBUG_MASK_MAX_SLEEP |
531 EDP_PSR_DEBUG_MASK_DISP_REG_WRITE);
532 } else {
533 /* set up vsc header for psr1 */
534 hsw_psr_setup_vsc(intel_dp);
535 /*
536 * Per Spec: Avoid continuous PSR exit by masking MEMUP
537 * and HPD. also mask LPSP to avoid dependency on other
538 * drivers that might block runtime_pm besides
539 * preventing other hw tracking issues now we can rely
540 * on frontbuffer tracking.
541 */
542 I915_WRITE(EDP_PSR_DEBUG_CTL,
543 EDP_PSR_DEBUG_MASK_MEMUP |
544 EDP_PSR_DEBUG_MASK_HPD |
545 EDP_PSR_DEBUG_MASK_LPSP);
461 }546 }
462 547
463 /*
464 * Per Spec: Avoid continuous PSR exit by masking MEMUP and HPD.
465 * Also mask LPSP to avoid dependency on other drivers that
466 * might block runtime_pm besides preventing other hw tracking
467 * issues now we can rely on frontbuffer tracking.
468 */
469 I915_WRITE(EDP_PSR_DEBUG_CTL, EDP_PSR_DEBUG_MASK_MEMUP |
470 EDP_PSR_DEBUG_MASK_HPD | EDP_PSR_DEBUG_MASK_LPSP);
471
472 /* Enable PSR on the panel */548 /* Enable PSR on the panel */
473 hsw_psr_enable_sink(intel_dp);549 hsw_psr_enable_sink(intel_dp);
474 550
@@ -544,20 +620,42 @@ static void hsw_psr_disable(struct intel_dp *intel_dp) · 69 unmodified lines
544 struct drm_i915_private *dev_priv = to_i915(dev);620 struct drm_i915_private *dev_priv = to_i915(dev);
545 621
546 if (dev_priv->psr.active) {622 if (dev_priv->psr.active) {
547 I915_WRITE(EDP_PSR_CTL,623 i915_reg_t psr_ctl;
548 I915_READ(EDP_PSR_CTL) & ~EDP_PSR_ENABLE);624 u32 psr_status_mask;
625
626 if (dev_priv->psr.aux_frame_sync)
627 drm_dp_dpcd_writeb(&intel_dp->aux,
628 DP_SINK_DEVICE_AUX_FRAME_SYNC_CONF,
629 0);
630
631 if (dev_priv->psr.psr2_support) {
632 psr_ctl = EDP_PSR2_CTL;
633 psr_status_mask = EDP_PSR2_STATUS_STATE_MASK;
634
635 I915_WRITE(psr_ctl,
636 I915_READ(psr_ctl) &
637 ~(EDP_PSR2_ENABLE | EDP_SU_TRACK_ENABLE));
638
639 } else {
640 psr_ctl = EDP_PSR_STATUS_CTL;
641 psr_status_mask = EDP_PSR_STATUS_STATE_MASK;
642
643 I915_WRITE(psr_ctl,
644 I915_READ(psr_ctl) & ~EDP_PSR_ENABLE);
645 }
549 646
550 /* Wait till PSR is idle */647 /* Wait till PSR is idle */
551 if (intel_wait_for_register(dev_priv,648 if (intel_wait_for_register(dev_priv,
552 EDP_PSR_STATUS_CTL,649 psr_ctl, psr_status_mask, 0,
553 EDP_PSR_STATUS_STATE_MASK,
554 0,
555 2000))650 2000))
556 DRM_ERROR("Timed out waiting for PSR Idle State\n");651 DRM_ERROR("Timed out waiting for PSR Idle State\n");
557 652
558 dev_priv->psr.active = false;653 dev_priv->psr.active = false;
559 } else {654 } else {
560 WARN_ON(I915_READ(EDP_PSR_CTL) & EDP_PSR_ENABLE);655 if (dev_priv->psr.psr2_support)
656 WARN_ON(I915_READ(EDP_PSR2_CTL) & EDP_PSR2_ENABLE);
657 else
658 WARN_ON(I915_READ(EDP_PSR_CTL) & EDP_PSR_ENABLE);
561 }659 }
562}660}
563 661
@@ -608,13 +706,24 @@ static void intel_psr_work(struct work_struct *work) · 44 unmodified lines
608 * and be ready for re-enable.706 * and be ready for re-enable.
609 */707 */
610 if (HAS_DDI(dev_priv)) {708 if (HAS_DDI(dev_priv)) {
611 if (intel_wait_for_register(dev_priv,709 if (dev_priv->psr.psr2_support) {
612 EDP_PSR_STATUS_CTL,710 if (intel_wait_for_register(dev_priv,
613 EDP_PSR_STATUS_STATE_MASK,711 EDP_PSR2_STATUS_CTL,
614 0,712 EDP_PSR2_STATUS_STATE_MASK,
615 50)) {713 0,
616 DRM_ERROR("Timed out waiting for PSR Idle for re-enable\n");714 50)) {
617 return;715 DRM_ERROR("Timed out waiting for PSR2 Idle for re-enable\n");
716 return;
717 }
718 } else {
719 if (intel_wait_for_register(dev_priv,
720 EDP_PSR_STATUS_CTL,
721 EDP_PSR_STATUS_STATE_MASK,
722 0,
723 50)) {
724 DRM_ERROR("Timed out waiting for PSR Idle for re-enable\n");
725 return;
726 }
618 }727 }
619 } else {728 } else {
620 if (intel_wait_for_register(dev_priv,729 if (intel_wait_for_register(dev_priv,
@@ -656,11 +765,19 @@ static void intel_psr_exit(struct drm_i915_private *dev_priv) · 35 unmodified lines
656 return;765 return;
657 766
658 if (HAS_DDI(dev_priv)) {767 if (HAS_DDI(dev_priv)) {
659 val = I915_READ(EDP_PSR_CTL);768 if (dev_priv->psr.aux_frame_sync)
660 769 drm_dp_dpcd_writeb(&intel_dp->aux,
661 WARN_ON(!(val & EDP_PSR_ENABLE));770 DP_SINK_DEVICE_AUX_FRAME_SYNC_CONF,
662 771 0);
663 I915_WRITE(EDP_PSR_CTL, val & ~EDP_PSR_ENABLE);772 if (dev_priv->psr.psr2_support) {
773 val = I915_READ(EDP_PSR2_CTL);
774 WARN_ON(!(val & EDP_PSR2_ENABLE));
775 I915_WRITE(EDP_PSR2_CTL, val & ~EDP_PSR2_ENABLE);
776 } else {
777 val = I915_READ(EDP_PSR_CTL);
778 WARN_ON(!(val & EDP_PSR_ENABLE));
779 I915_WRITE(EDP_PSR_CTL, val & ~EDP_PSR_ENABLE);
780 }
664 } else {781 } else {
665 val = I915_READ(VLV_PSRCTL(pipe));782 val = I915_READ(VLV_PSRCTL(pipe));
666 783
drivers/gpu/drm/i915/intel_ringbuffer.c+8−8
@@ -1728,7 +1728,7 @@ static int init_status_page(struct intel_engine_cs *engine) · 1727 unmodified lines
1728 void *vaddr;1728 void *vaddr;
1729 int ret;1729 int ret;
1730 1730
1731 obj = i915_gem_object_create_internal(engine->i915, 4096);1731 obj = i915_gem_object_create_internal(engine->i915, PAGE_SIZE);
1732 if (IS_ERR(obj)) {1732 if (IS_ERR(obj)) {
1733 DRM_ERROR("Failed to allocate status page\n");1733 DRM_ERROR("Failed to allocate status page\n");
1734 return PTR_ERR(obj);1734 return PTR_ERR(obj);
@@ -1738,7 +1738,7 @@ static int init_status_page(struct intel_engine_cs *engine) · 3 unmodified lines
1738 if (ret)1738 if (ret)
1739 goto err;1739 goto err;
1740 1740
1741 vma = i915_vma_create(obj, &engine->i915->ggtt.base, NULL);1741 vma = i915_vma_instance(obj, &engine->i915->ggtt.base, NULL);
1742 if (IS_ERR(vma)) {1742 if (IS_ERR(vma)) {
1743 ret = PTR_ERR(vma);1743 ret = PTR_ERR(vma);
1744 goto err;1744 goto err;
@@ -1769,7 +1769,7 @@ static int init_status_page(struct intel_engine_cs *engine) · 24 unmodified lines
1769 1769
1770 engine->status_page.vma = vma;1770 engine->status_page.vma = vma;
1771 engine->status_page.ggtt_offset = i915_ggtt_offset(vma);1771 engine->status_page.ggtt_offset = i915_ggtt_offset(vma);
1772 engine->status_page.page_addr = memset(vaddr, 0, 4096);1772 engine->status_page.page_addr = memset(vaddr, 0, PAGE_SIZE);
1773 1773
1774 DRM_DEBUG_DRIVER("%s hws offset: 0x%08x\n",1774 DRM_DEBUG_DRIVER("%s hws offset: 0x%08x\n",
1775 engine->name, i915_ggtt_offset(vma));1775 engine->name, i915_ggtt_offset(vma));
@@ -1872,7 +1872,7 @@ intel_ring_create_vma(struct drm_i915_private *dev_priv, int size) · 96 unmodified lines
1872 /* mark ring buffers as read-only from GPU side by default */1872 /* mark ring buffers as read-only from GPU side by default */
1873 obj->gt_ro = 1;1873 obj->gt_ro = 1;
1874 1874
1875 vma = i915_vma_create(obj, &dev_priv->ggtt.base, NULL);1875 vma = i915_vma_instance(obj, &dev_priv->ggtt.base, NULL);
1876 if (IS_ERR(vma))1876 if (IS_ERR(vma))
1877 goto err;1877 goto err;
1878 1878
@@ -2041,7 +2041,7 @@ static int intel_init_ring_buffer(struct intel_engine_cs *engine) · 162 unmodified lines
2041 }2041 }
2042 2042
2043 /* Ring wraparound at offset 0 sometimes hangs. No idea why. */2043 /* Ring wraparound at offset 0 sometimes hangs. No idea why. */
2044 ret = intel_ring_pin(ring, 4096);2044 ret = intel_ring_pin(ring, I915_GTT_PAGE_SIZE);
2045 if (ret) {2045 if (ret) {
2046 intel_ring_free(ring);2046 intel_ring_free(ring);
2047 goto error;2047 goto error;
@@ -2458,11 +2458,11 @@ static void intel_ring_init_semaphores(struct drm_i915_private *dev_priv, · 410 unmodified lines
2458 if (INTEL_GEN(dev_priv) >= 8 && !dev_priv->semaphore) {2458 if (INTEL_GEN(dev_priv) >= 8 && !dev_priv->semaphore) {
2459 struct i915_vma *vma;2459 struct i915_vma *vma;
2460 2460
2461 obj = i915_gem_object_create(dev_priv, 4096);2461 obj = i915_gem_object_create(dev_priv, PAGE_SIZE);
2462 if (IS_ERR(obj))2462 if (IS_ERR(obj))
2463 goto err;2463 goto err;
2464 2464
2465 vma = i915_vma_create(obj, &dev_priv->ggtt.base, NULL);2465 vma = i915_vma_instance(obj, &dev_priv->ggtt.base, NULL);
2466 if (IS_ERR(vma))2466 if (IS_ERR(vma))
2467 goto err_obj;2467 goto err_obj;
2468 2468
@@ -2675,7 +2675,7 @@ int intel_init_render_ring_buffer(struct intel_engine_cs *engine) · 206 unmodified lines
2675 return ret;2675 return ret;
2676 2676
2677 if (INTEL_GEN(dev_priv) >= 6) {2677 if (INTEL_GEN(dev_priv) >= 6) {
2678 ret = intel_engine_create_scratch(engine, 4096);2678 ret = intel_engine_create_scratch(engine, PAGE_SIZE);
2679 if (ret)2679 if (ret)
2680 return ret;2680 return ret;
2681 } else if (HAS_BROKEN_CS_TLB(dev_priv)) {2681 } else if (HAS_BROKEN_CS_TLB(dev_priv)) {
drivers/gpu/drm/i915/intel_sprite.c+4−4
@@ -273,7 +273,7 @@ skl_update_plane(struct drm_plane *drm_plane, · 272 unmodified lines
273 273
274 I915_WRITE(PLANE_CTL(pipe, plane_id), plane_ctl);274 I915_WRITE(PLANE_CTL(pipe, plane_id), plane_ctl);
275 I915_WRITE(PLANE_SURF(pipe, plane_id),275 I915_WRITE(PLANE_SURF(pipe, plane_id),
276 intel_fb_gtt_offset(fb, rotation) + surf_addr);276 intel_plane_ggtt_offset(plane_state) + surf_addr);
277 POSTING_READ(PLANE_SURF(pipe, plane_id));277 POSTING_READ(PLANE_SURF(pipe, plane_id));
278}278}
279 279
@@ -458,7 +458,7 @@ vlv_update_plane(struct drm_plane *dplane, · 178 unmodified lines
458 I915_WRITE(SPSIZE(pipe, plane_id), (crtc_h << 16) | crtc_w);458 I915_WRITE(SPSIZE(pipe, plane_id), (crtc_h << 16) | crtc_w);
459 I915_WRITE(SPCNTR(pipe, plane_id), sprctl);459 I915_WRITE(SPCNTR(pipe, plane_id), sprctl);
460 I915_WRITE(SPSURF(pipe, plane_id),460 I915_WRITE(SPSURF(pipe, plane_id),
461 intel_fb_gtt_offset(fb, rotation) + sprsurf_offset);461 intel_plane_ggtt_offset(plane_state) + sprsurf_offset);
462 POSTING_READ(SPSURF(pipe, plane_id));462 POSTING_READ(SPSURF(pipe, plane_id));
463}463}
464 464
@@ -594,7 +594,7 @@ ivb_update_plane(struct drm_plane *plane, · 129 unmodified lines
594 I915_WRITE(SPRSCALE(pipe), sprscale);594 I915_WRITE(SPRSCALE(pipe), sprscale);
595 I915_WRITE(SPRCTL(pipe), sprctl);595 I915_WRITE(SPRCTL(pipe), sprctl);
596 I915_WRITE(SPRSURF(pipe),596 I915_WRITE(SPRSURF(pipe),
597 intel_fb_gtt_offset(fb, rotation) + sprsurf_offset);597 intel_plane_ggtt_offset(plane_state) + sprsurf_offset);
598 POSTING_READ(SPRSURF(pipe));598 POSTING_READ(SPRSURF(pipe));
599}599}
600 600
@@ -721,7 +721,7 @@ ilk_update_plane(struct drm_plane *plane, · 120 unmodified lines
721 I915_WRITE(DVSSCALE(pipe), dvsscale);721 I915_WRITE(DVSSCALE(pipe), dvsscale);
722 I915_WRITE(DVSCNTR(pipe), dvscntr);722 I915_WRITE(DVSCNTR(pipe), dvscntr);
723 I915_WRITE(DVSSURF(pipe),723 I915_WRITE(DVSSURF(pipe),
724 intel_fb_gtt_offset(fb, rotation) + dvssurf_offset);724 intel_plane_ggtt_offset(plane_state) + dvssurf_offset);
725 POSTING_READ(DVSSURF(pipe));725 POSTING_READ(DVSSURF(pipe));
726}726}
727 727
drivers/gpu/drm/i915/intel_uc.c+0−26
@@ -114,29 +114,3 @@ int intel_guc_sample_forcewake(struct intel_guc *guc) · 113 unmodified lines
114 return intel_guc_send(guc, action, ARRAY_SIZE(action));114 return intel_guc_send(guc, action, ARRAY_SIZE(action));
115}115}
116 116
117int intel_guc_log_flush_complete(struct intel_guc *guc)
118{
119 u32 action[] = { INTEL_GUC_ACTION_LOG_BUFFER_FILE_FLUSH_COMPLETE };
120
121 return intel_guc_send(guc, action, ARRAY_SIZE(action));
122}
123
124int intel_guc_log_flush(struct intel_guc *guc)
125{
126 u32 action[] = {
127 INTEL_GUC_ACTION_FORCE_LOG_BUFFER_FLUSH,
128 0
129 };
130
131 return intel_guc_send(guc, action, ARRAY_SIZE(action));
132}
133
134int intel_guc_log_control(struct intel_guc *guc, u32 control_val)
135{
136 u32 action[] = {
137 INTEL_GUC_ACTION_UK_LOG_ENABLE_LOGGING,
138 control_val
139 };
140
141 return intel_guc_send(guc, action, ARRAY_SIZE(action));
142}
drivers/gpu/drm/i915/intel_uc.h+47−26
@@ -93,29 +93,35 @@ struct i915_guc_client { · 92 unmodified lines
93 uint64_t submissions[I915_NUM_ENGINES];93 uint64_t submissions[I915_NUM_ENGINES];
94};94};
95 95
96enum intel_guc_fw_status {96enum intel_uc_fw_status {
97 GUC_FIRMWARE_FAIL = -1,97 INTEL_UC_FIRMWARE_FAIL = -1,
98 GUC_FIRMWARE_NONE = 0,98 INTEL_UC_FIRMWARE_NONE = 0,
99 GUC_FIRMWARE_PENDING,99 INTEL_UC_FIRMWARE_PENDING,
100 GUC_FIRMWARE_SUCCESS100 INTEL_UC_FIRMWARE_SUCCESS
101};
102
103enum intel_uc_fw_type {
104 INTEL_UC_FW_TYPE_GUC,
105 INTEL_UC_FW_TYPE_HUC
101};106};
102 107
103/*108/*
104 * This structure encapsulates all the data needed during the process109 * This structure encapsulates all the data needed during the process
105 * of fetching, caching, and loading the firmware image into the GuC.110 * of fetching, caching, and loading the firmware image into the GuC.
106 */111 */
107struct intel_guc_fw {112struct intel_uc_fw {
108 const char * guc_fw_path;113 const char *path;
109 size_t guc_fw_size;114 size_t size;
110 struct drm_i915_gem_object * guc_fw_obj;115 struct drm_i915_gem_object *obj;
111 enum intel_guc_fw_status guc_fw_fetch_status;116 enum intel_uc_fw_status fetch_status;
112 enum intel_guc_fw_status guc_fw_load_status;117 enum intel_uc_fw_status load_status;
113 118
114 uint16_t guc_fw_major_wanted;119 uint16_t major_ver_wanted;
115 uint16_t guc_fw_minor_wanted;120 uint16_t minor_ver_wanted;
116 uint16_t guc_fw_major_found;121 uint16_t major_ver_found;
117 uint16_t guc_fw_minor_found;122 uint16_t minor_ver_found;
118 123
124 enum intel_uc_fw_type fw;
119 uint32_t header_size;125 uint32_t header_size;
120 uint32_t header_offset;126 uint32_t header_offset;
121 uint32_t rsa_size;127 uint32_t rsa_size;
@@ -141,7 +147,7 @@ struct intel_guc_log { · 19 unmodified lines
141};147};
142 148
143struct intel_guc {149struct intel_guc {
144 struct intel_guc_fw guc_fw;150 struct intel_uc_fw fw;
145 struct intel_guc_log log;151 struct intel_guc_log log;
146 152
147 /* intel_guc_recv interrupt related state */153 /* intel_guc_recv interrupt related state */
@@ -170,21 +176,28 @@ struct intel_guc { · 22 unmodified lines
170 struct mutex send_mutex;176 struct mutex send_mutex;
171};177};
172 178
179struct intel_huc {
180 /* Generic uC firmware management */
181 struct intel_uc_fw fw;
182
183 /* HuC-specific additions */
184};
185
173/* intel_uc.c */186/* intel_uc.c */
174void intel_uc_init_early(struct drm_i915_private *dev_priv);187void intel_uc_init_early(struct drm_i915_private *dev_priv);
175int intel_guc_send(struct intel_guc *guc, const u32 *action, u32 len);188int intel_guc_send(struct intel_guc *guc, const u32 *action, u32 len);
176int intel_guc_sample_forcewake(struct intel_guc *guc);189int intel_guc_sample_forcewake(struct intel_guc *guc);
177int intel_guc_log_flush_complete(struct intel_guc *guc);
178int intel_guc_log_flush(struct intel_guc *guc);
179int intel_guc_log_control(struct intel_guc *guc, u32 control_val);
180 190
181/* intel_guc_loader.c */191/* intel_guc_loader.c */
182extern void intel_guc_init(struct drm_i915_private *dev_priv);192extern void intel_guc_init(struct drm_i915_private *dev_priv);
183extern int intel_guc_setup(struct drm_i915_private *dev_priv);193extern int intel_guc_setup(struct drm_i915_private *dev_priv);
184extern void intel_guc_fini(struct drm_i915_private *dev_priv);194extern void intel_guc_fini(struct drm_i915_private *dev_priv);
185extern const char *intel_guc_fw_status_repr(enum intel_guc_fw_status status);195extern const char *intel_uc_fw_status_repr(enum intel_uc_fw_status status);
186extern int intel_guc_suspend(struct drm_i915_private *dev_priv);196extern int intel_guc_suspend(struct drm_i915_private *dev_priv);
187extern int intel_guc_resume(struct drm_i915_private *dev_priv);197extern int intel_guc_resume(struct drm_i915_private *dev_priv);
198void intel_uc_fw_fetch(struct drm_i915_private *dev_priv,
199 struct intel_uc_fw *uc_fw);
200u32 intel_guc_wopcm_size(struct drm_i915_private *dev_priv);
188 201
189/* i915_guc_submission.c */202/* i915_guc_submission.c */
190int i915_guc_submission_init(struct drm_i915_private *dev_priv);203int i915_guc_submission_init(struct drm_i915_private *dev_priv);
@@ -193,10 +206,12 @@ int i915_guc_wq_reserve(struct drm_i915_gem_request *rq); · 2 unmodified lines
193void i915_guc_wq_unreserve(struct drm_i915_gem_request *request);206void i915_guc_wq_unreserve(struct drm_i915_gem_request *request);
194void i915_guc_submission_disable(struct drm_i915_private *dev_priv);207void i915_guc_submission_disable(struct drm_i915_private *dev_priv);
195void i915_guc_submission_fini(struct drm_i915_private *dev_priv);208void i915_guc_submission_fini(struct drm_i915_private *dev_priv);
196void i915_guc_capture_logs(struct drm_i915_private *dev_priv);209struct i915_vma *intel_guc_allocate_vma(struct intel_guc *guc, u32 size);
197void i915_guc_flush_logs(struct drm_i915_private *dev_priv);210
198void i915_guc_register(struct drm_i915_private *dev_priv);211/* intel_guc_log.c */
199void i915_guc_unregister(struct drm_i915_private *dev_priv);212void intel_guc_log_create(struct intel_guc *guc);
213void i915_guc_log_register(struct drm_i915_private *dev_priv);
214void i915_guc_log_unregister(struct drm_i915_private *dev_priv);
200int i915_guc_log_control(struct drm_i915_private *dev_priv, u64 control_val);215int i915_guc_log_control(struct drm_i915_private *dev_priv, u64 control_val);
201 216
202static inline u32 guc_ggtt_offset(struct i915_vma *vma)217static inline u32 guc_ggtt_offset(struct i915_vma *vma)
@@ -207,4 +222,10 @@ static inline u32 guc_ggtt_offset(struct i915_vma *vma) · 4 unmodified lines
207 return offset;222 return offset;
208}223}
209 224
225/* intel_huc.c */
226void intel_huc_init(struct drm_i915_private *dev_priv);
227void intel_huc_fini(struct drm_i915_private *dev_priv);
228int intel_huc_load(struct drm_i915_private *dev_priv);
229void intel_guc_auth_huc(struct drm_i915_private *dev_priv);
230
210#endif231#endif
include/drm/drm_dp_helper.h+12−1
@@ -194,7 +194,8 @@ · 193 unmodified lines
194# define DP_PSR_SETUP_TIME_0 (6 << 1)194# define DP_PSR_SETUP_TIME_0 (6 << 1)
195# define DP_PSR_SETUP_TIME_MASK (7 << 1)195# define DP_PSR_SETUP_TIME_MASK (7 << 1)
196# define DP_PSR_SETUP_TIME_SHIFT 1196# define DP_PSR_SETUP_TIME_SHIFT 1
197 197# define DP_PSR2_SU_Y_COORDINATE_REQUIRED (1 << 4) /* eDP 1.4a */
198# define DP_PSR2_SU_GRANULARITY_REQUIRED (1 << 5) /* eDP 1.4b */
198/*199/*
199 * 0x80-0x8f describe downstream port capabilities, but there are two layouts200 * 0x80-0x8f describe downstream port capabilities, but there are two layouts
200 * based on whether DP_DETAILED_CAP_INFO_AVAILABLE was set. If it was not,201 * based on whether DP_DETAILED_CAP_INFO_AVAILABLE was set. If it was not,
@@ -568,6 +569,16 @@ · 367 unmodified lines
568#define DP_RECEIVER_ALPM_STATUS 0x200b /* eDP 1.4 */569#define DP_RECEIVER_ALPM_STATUS 0x200b /* eDP 1.4 */
569# define DP_ALPM_LOCK_TIMEOUT_ERROR (1 << 0)570# define DP_ALPM_LOCK_TIMEOUT_ERROR (1 << 0)
570 571
572#define DP_DPRX_FEATURE_ENUMERATION_LIST 0x2210 /* DP 1.3 */
573# define DP_GTC_CAP (1 << 0) /* DP 1.3 */
574# define DP_SST_SPLIT_SDP_CAP (1 << 1) /* DP 1.4 */
575# define DP_AV_SYNC_CAP (1 << 2) /* DP 1.3 */
576# define DP_VSC_SDP_EXT_FOR_COLORIMETRY_SUPPORTED (1 << 3) /* DP 1.3 */
577# define DP_VSC_EXT_VESA_SDP_SUPPORTED (1 << 4) /* DP 1.4 */
578# define DP_VSC_EXT_VESA_SDP_CHAINING_SUPPORTED (1 << 5) /* DP 1.4 */
579# define DP_VSC_EXT_CEA_SDP_SUPPORTED (1 << 6) /* DP 1.4 */
580# define DP_VSC_EXT_CEA_SDP_CHAINING_SUPPORTED (1 << 7) /* DP 1.4 */
581
571/* DP 1.2 Sideband message defines */582/* DP 1.2 Sideband message defines */
572/* peer device type - DP 1.2a Table 2-92 */583/* peer device type - DP 1.2a Table 2-92 */
573#define DP_PEER_DEVICE_NONE 0x0584#define DP_PEER_DEVICE_NONE 0x0
include/uapi/drm/i915_drm.h+1−0
@@ -395,6 +395,7 @@ typedef struct drm_i915_irq_wait { · 394 unmodified lines
395 * priorities and the driver will attempt to execute batches in priority order.395 * priorities and the driver will attempt to execute batches in priority order.
396 */396 */
397#define I915_PARAM_HAS_SCHEDULER 41397#define I915_PARAM_HAS_SCHEDULER 41
398#define I915_PARAM_HUC_STATUS 42
398 399
399typedef struct drm_i915_getparam {400typedef struct drm_i915_getparam {
400 __s32 param;401 __s32 param;
sound/pci/hda/hda_codec.c+72−4
@@ -311,9 +311,15 @@ int snd_hda_get_conn_index(struct hda_codec *codec, hda_nid_t mux, · 310 unmodified lines
311}311}
312EXPORT_SYMBOL_GPL(snd_hda_get_conn_index);312EXPORT_SYMBOL_GPL(snd_hda_get_conn_index);
313 313
314 314/**
315/* return DEVLIST_LEN parameter of the given widget */315 * snd_hda_get_num_devices - get DEVLIST_LEN parameter of the given widget
316static unsigned int get_num_devices(struct hda_codec *codec, hda_nid_t nid)316 * @codec: the HDA codec
317 * @nid: NID of the pin to parse
318 *
319 * Get the device entry number on the given widget. This is a feature of
320 * DP MST audio. Each pin can have several device entries in it.
321 */
322unsigned int snd_hda_get_num_devices(struct hda_codec *codec, hda_nid_t nid)
317{323{
318 unsigned int wcaps = get_wcaps(codec, nid);324 unsigned int wcaps = get_wcaps(codec, nid);
319 unsigned int parm;325 unsigned int parm;
@@ -327,6 +333,7 @@ static unsigned int get_num_devices(struct hda_codec *codec, hda_nid_t nid) · 7 unmodified lines
327 parm = 0;333 parm = 0;
328 return parm & AC_DEV_LIST_LEN_MASK;334 return parm & AC_DEV_LIST_LEN_MASK;
329}335}
336EXPORT_SYMBOL_GPL(snd_hda_get_num_devices);
330 337
331/**338/**
332 * snd_hda_get_devices - copy device list without cache339 * snd_hda_get_devices - copy device list without cache
@@ -344,7 +351,7 @@ int snd_hda_get_devices(struct hda_codec *codec, hda_nid_t nid, · 11 unmodified lines
344 unsigned int parm;351 unsigned int parm;
345 int i, dev_len, devices;352 int i, dev_len, devices;
346 353
347 parm = get_num_devices(codec, nid);354 parm = snd_hda_get_num_devices(codec, nid);
348 if (!parm) /* not multi-stream capable */355 if (!parm) /* not multi-stream capable */
349 return 0;356 return 0;
350 357
@@ -368,6 +375,63 @@ int snd_hda_get_devices(struct hda_codec *codec, hda_nid_t nid, · 17 unmodified lines
368 return devices;375 return devices;
369}376}
370 377
378/**
379 * snd_hda_get_dev_select - get device entry select on the pin
380 * @codec: the HDA codec
381 * @nid: NID of the pin to get device entry select
382 *
383 * Get the devcie entry select on the pin. Return the device entry
384 * id selected on the pin. Return 0 means the first device entry
385 * is selected or MST is not supported.
386 */
387int snd_hda_get_dev_select(struct hda_codec *codec, hda_nid_t nid)
388{
389 /* not support dp_mst will always return 0, using first dev_entry */
390 if (!codec->dp_mst)
391 return 0;
392
393 return snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_DEVICE_SEL, 0);
394}
395EXPORT_SYMBOL_GPL(snd_hda_get_dev_select);
396
397/**
398 * snd_hda_set_dev_select - set device entry select on the pin
399 * @codec: the HDA codec
400 * @nid: NID of the pin to set device entry select
401 * @dev_id: device entry id to be set
402 *
403 * Set the device entry select on the pin nid.
404 */
405int snd_hda_set_dev_select(struct hda_codec *codec, hda_nid_t nid, int dev_id)
406{
407 int ret, num_devices;
408
409 /* not support dp_mst will always return 0, using first dev_entry */
410 if (!codec->dp_mst)
411 return 0;
412
413 /* AC_PAR_DEVLIST_LEN is 0 based. */
414 num_devices = snd_hda_get_num_devices(codec, nid) + 1;
415 /* If Device List Length is 0 (num_device = 1),
416 * the pin is not multi stream capable.
417 * Do nothing in this case.
418 */
419 if (num_devices == 1)
420 return 0;
421
422 /* Behavior of setting index being equal to or greater than
423 * Device List Length is not predictable
424 */
425 if (num_devices <= dev_id)
426 return -EINVAL;
427
428 ret = snd_hda_codec_write(codec, nid, 0,
429 AC_VERB_SET_DEVICE_SEL, dev_id);
430
431 return ret;
432}
433EXPORT_SYMBOL_GPL(snd_hda_set_dev_select);
434
371/*435/*
372 * read widget caps for each widget and store in cache436 * read widget caps for each widget and store in cache
373 */437 */
@@ -403,6 +467,10 @@ static int read_pin_defaults(struct hda_codec *codec) · 29 unmodified lines
403 pin->nid = nid;467 pin->nid = nid;
404 pin->cfg = snd_hda_codec_read(codec, nid, 0,468 pin->cfg = snd_hda_codec_read(codec, nid, 0,
405 AC_VERB_GET_CONFIG_DEFAULT, 0);469 AC_VERB_GET_CONFIG_DEFAULT, 0);
470 /*
471 * all device entries are the same widget control so far
472 * fixme: if any codec is different, need fix here
473 */
406 pin->ctrl = snd_hda_codec_read(codec, nid, 0,474 pin->ctrl = snd_hda_codec_read(codec, nid, 0,
407 AC_VERB_GET_PIN_WIDGET_CONTROL,475 AC_VERB_GET_PIN_WIDGET_CONTROL,
408 0);476 0);
sound/pci/hda/hda_codec.h+3−0
@@ -347,8 +347,11 @@ int snd_hda_override_conn_list(struct hda_codec *codec, hda_nid_t nid, int nums, · 346 unmodified lines
347 const hda_nid_t *list);347 const hda_nid_t *list);
348int snd_hda_get_conn_index(struct hda_codec *codec, hda_nid_t mux,348int snd_hda_get_conn_index(struct hda_codec *codec, hda_nid_t mux,
349 hda_nid_t nid, int recursive);349 hda_nid_t nid, int recursive);
350unsigned int snd_hda_get_num_devices(struct hda_codec *codec, hda_nid_t nid);
350int snd_hda_get_devices(struct hda_codec *codec, hda_nid_t nid,351int snd_hda_get_devices(struct hda_codec *codec, hda_nid_t nid,
351 u8 *dev_list, int max_devices);352 u8 *dev_list, int max_devices);
353int snd_hda_get_dev_select(struct hda_codec *codec, hda_nid_t nid);
354int snd_hda_set_dev_select(struct hda_codec *codec, hda_nid_t nid, int dev_id);
352 355
353struct hda_verb {356struct hda_verb {
354 hda_nid_t nid;357 hda_nid_t nid;
sound/pci/hda/patch_hdmi.c+193−52
@@ -76,6 +76,7 @@ struct hdmi_spec_per_cvt { · 75 unmodified lines
76 76
77struct hdmi_spec_per_pin {77struct hdmi_spec_per_pin {
78 hda_nid_t pin_nid;78 hda_nid_t pin_nid;
79 int dev_id;
79 /* pin idx, different device entries on the same pin use the same idx */80 /* pin idx, different device entries on the same pin use the same idx */
80 int pin_nid_idx;81 int pin_nid_idx;
81 int num_mux_nids;82 int num_mux_nids;
@@ -130,7 +131,23 @@ struct hdmi_spec { · 48 unmodified lines
130 struct snd_array cvts; /* struct hdmi_spec_per_cvt */131 struct snd_array cvts; /* struct hdmi_spec_per_cvt */
131 hda_nid_t cvt_nids[4]; /* only for haswell fix */132 hda_nid_t cvt_nids[4]; /* only for haswell fix */
132 133
134 /*
135 * num_pins is the number of virtual pins
136 * for example, there are 3 pins, and each pin
137 * has 4 device entries, then the num_pins is 12
138 */
133 int num_pins;139 int num_pins;
140 /*
141 * num_nids is the number of real pins
142 * In the above example, num_nids is 3
143 */
144 int num_nids;
145 /*
146 * dev_num is the number of device entries
147 * on each pin.
148 * In the above example, dev_num is 4
149 */
150 int dev_num;
134 struct snd_array pins; /* struct hdmi_spec_per_pin */151 struct snd_array pins; /* struct hdmi_spec_per_pin */
135 struct hdmi_pcm pcm_rec[16];152 struct hdmi_pcm pcm_rec[16];
136 struct mutex pcm_lock;153 struct mutex pcm_lock;
@@ -217,14 +234,26 @@ union audio_infoframe { · 80 unmodified lines
217/* obtain hda_pcm object assigned to idx */234/* obtain hda_pcm object assigned to idx */
218#define get_pcm_rec(spec, idx) (get_hdmi_pcm(spec, idx)->pcm)235#define get_pcm_rec(spec, idx) (get_hdmi_pcm(spec, idx)->pcm)
219 236
220static int pin_nid_to_pin_index(struct hda_codec *codec, hda_nid_t pin_nid)237static int pin_id_to_pin_index(struct hda_codec *codec,
238 hda_nid_t pin_nid, int dev_id)
221{239{
222 struct hdmi_spec *spec = codec->spec;240 struct hdmi_spec *spec = codec->spec;
223 int pin_idx;241 int pin_idx;
242 struct hdmi_spec_per_pin *per_pin;
243
244 /*
245 * (dev_id == -1) means it is NON-MST pin
246 * return the first virtual pin on this port
247 */
248 if (dev_id == -1)
249 dev_id = 0;
224 250
225 for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++)251 for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) {
226 if (get_pin(spec, pin_idx)->pin_nid == pin_nid)252 per_pin = get_pin(spec, pin_idx);
253 if ((per_pin->pin_nid == pin_nid) &&
254 (per_pin->dev_id == dev_id))
227 return pin_idx;255 return pin_idx;
256 }
228 257
229 codec_warn(codec, "HDMI: pin nid %d not registered\n", pin_nid);258 codec_warn(codec, "HDMI: pin nid %d not registered\n", pin_nid);
230 return -EINVAL;259 return -EINVAL;
@@ -724,10 +753,11 @@ static void hdmi_setup_audio_infoframe(struct hda_codec *codec, · 493 unmodified lines
724 753
725static bool hdmi_present_sense(struct hdmi_spec_per_pin *per_pin, int repoll);754static bool hdmi_present_sense(struct hdmi_spec_per_pin *per_pin, int repoll);
726 755
727static void check_presence_and_report(struct hda_codec *codec, hda_nid_t nid)756static void check_presence_and_report(struct hda_codec *codec, hda_nid_t nid,
757 int dev_id)
728{758{
729 struct hdmi_spec *spec = codec->spec;759 struct hdmi_spec *spec = codec->spec;
730 int pin_idx = pin_nid_to_pin_index(codec, nid);760 int pin_idx = pin_id_to_pin_index(codec, nid, dev_id);
731 761
732 if (pin_idx < 0)762 if (pin_idx < 0)
733 return;763 return;
@@ -738,7 +768,8 @@ static void check_presence_and_report(struct hda_codec *codec, hda_nid_t nid) · 4 unmodified lines
738static void jack_callback(struct hda_codec *codec,768static void jack_callback(struct hda_codec *codec,
739 struct hda_jack_callback *jack)769 struct hda_jack_callback *jack)
740{770{
741 check_presence_and_report(codec, jack->nid);771 /* hda_jack don't support DP MST */
772 check_presence_and_report(codec, jack->nid, 0);
742}773}
743 774
744static void hdmi_intrinsic_event(struct hda_codec *codec, unsigned int res)775static void hdmi_intrinsic_event(struct hda_codec *codec, unsigned int res)
@@ -747,6 +778,12 @@ static void hdmi_intrinsic_event(struct hda_codec *codec, unsigned int res) · 2 unmodified lines
747 struct hda_jack_tbl *jack;778 struct hda_jack_tbl *jack;
748 int dev_entry = (res & AC_UNSOL_RES_DE) >> AC_UNSOL_RES_DE_SHIFT;779 int dev_entry = (res & AC_UNSOL_RES_DE) >> AC_UNSOL_RES_DE_SHIFT;
749 780
781 /*
782 * assume DP MST uses dyn_pcm_assign and acomp and
783 * never comes here
784 * if DP MST supports unsol event, below code need
785 * consider dev_entry
786 */
750 jack = snd_hda_jack_tbl_get_from_tag(codec, tag);787 jack = snd_hda_jack_tbl_get_from_tag(codec, tag);
751 if (!jack)788 if (!jack)
752 return;789 return;
@@ -757,7 +794,8 @@ static void hdmi_intrinsic_event(struct hda_codec *codec, unsigned int res) · 4 unmodified lines
757 codec->addr, jack->nid, dev_entry, !!(res & AC_UNSOL_RES_IA),794 codec->addr, jack->nid, dev_entry, !!(res & AC_UNSOL_RES_IA),
758 !!(res & AC_UNSOL_RES_PD), !!(res & AC_UNSOL_RES_ELDV));795 !!(res & AC_UNSOL_RES_PD), !!(res & AC_UNSOL_RES_ELDV));
759 796
760 check_presence_and_report(codec, jack->nid);797 /* hda_jack don't support DP MST */
798 check_presence_and_report(codec, jack->nid, 0);
761}799}
762 800
763static void hdmi_non_intrinsic_event(struct hda_codec *codec, unsigned int res)801static void hdmi_non_intrinsic_event(struct hda_codec *codec, unsigned int res)
@@ -970,28 +1008,60 @@ static int intel_cvt_id_to_mux_idx(struct hdmi_spec *spec, · 206 unmodified lines
970 * by any other pins.1008 * by any other pins.
971 */1009 */
972static void intel_not_share_assigned_cvt(struct hda_codec *codec,1010static void intel_not_share_assigned_cvt(struct hda_codec *codec,
973 hda_nid_t pin_nid, int mux_idx)1011 hda_nid_t pin_nid,
1012 int dev_id, int mux_idx)
974{1013{
975 struct hdmi_spec *spec = codec->spec;1014 struct hdmi_spec *spec = codec->spec;
976 hda_nid_t nid;1015 hda_nid_t nid;
977 int cvt_idx, curr;1016 int cvt_idx, curr;
978 struct hdmi_spec_per_cvt *per_cvt;1017 struct hdmi_spec_per_cvt *per_cvt;
1018 struct hdmi_spec_per_pin *per_pin;
1019 int pin_idx;
1020
1021 /* configure the pins connections */
1022 for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) {
1023 int dev_id_saved;
1024 int dev_num;
979 1025
980 /* configure all pins, including "no physical connection" ones */1026 per_pin = get_pin(spec, pin_idx);
981 for_each_hda_codec_node(nid, codec) {1027 /*
982 unsigned int wid_caps = get_wcaps(codec, nid);1028 * pin not connected to monitor
983 unsigned int wid_type = get_wcaps_type(wid_caps);1029 * no need to operate on it
1030 */
1031 if (!per_pin->pcm)
1032 continue;
984 1033
985 if (wid_type != AC_WID_PIN)1034 if ((per_pin->pin_nid == pin_nid) &&
1035 (per_pin->dev_id == dev_id))
986 continue;1036 continue;
987 1037
988 if (nid == pin_nid)1038 /*
1039 * if per_pin->dev_id >= dev_num,
1040 * snd_hda_get_dev_select() will fail,
1041 * and the following operation is unpredictable.
1042 * So skip this situation.
1043 */
1044 dev_num = snd_hda_get_num_devices(codec, per_pin->pin_nid) + 1;
1045 if (per_pin->dev_id >= dev_num)
989 continue;1046 continue;
990 1047
1048 nid = per_pin->pin_nid;
1049
1050 /*
1051 * Calling this function should not impact
1052 * on the device entry selection
1053 * So let's save the dev id for each pin,
1054 * and restore it when return
1055 */
1056 dev_id_saved = snd_hda_get_dev_select(codec, nid);
1057 snd_hda_set_dev_select(codec, nid, per_pin->dev_id);
991 curr = snd_hda_codec_read(codec, nid, 0,1058 curr = snd_hda_codec_read(codec, nid, 0,
992 AC_VERB_GET_CONNECT_SEL, 0);1059 AC_VERB_GET_CONNECT_SEL, 0);
993 if (curr != mux_idx)1060 if (curr != mux_idx) {
1061 snd_hda_set_dev_select(codec, nid, dev_id_saved);
994 continue;1062 continue;
1063 }
1064
995 1065
996 /* choose an unassigned converter. The conveters in the1066 /* choose an unassigned converter. The conveters in the
997 * connection list are in the same order as in the codec.1067 * connection list are in the same order as in the codec.
@@ -1008,12 +1078,13 @@ static void intel_not_share_assigned_cvt(struct hda_codec *codec, · 10 unmodified lines
1008 break;1078 break;
1009 }1079 }
1010 }1080 }
1081 snd_hda_set_dev_select(codec, nid, dev_id_saved);
1011 }1082 }
1012}1083}
1013 1084
1014/* A wrapper of intel_not_share_asigned_cvt() */1085/* A wrapper of intel_not_share_asigned_cvt() */
1015static void intel_not_share_assigned_cvt_nid(struct hda_codec *codec,1086static void intel_not_share_assigned_cvt_nid(struct hda_codec *codec,
1016 hda_nid_t pin_nid, hda_nid_t cvt_nid)1087 hda_nid_t pin_nid, int dev_id, hda_nid_t cvt_nid)
1017{1088{
1018 int mux_idx;1089 int mux_idx;
1019 struct hdmi_spec *spec = codec->spec;1090 struct hdmi_spec *spec = codec->spec;
@@ -1025,7 +1096,7 @@ static void intel_not_share_assigned_cvt_nid(struct hda_codec *codec, · 5 unmodified lines
1025 */1096 */
1026 mux_idx = intel_cvt_id_to_mux_idx(spec, cvt_nid);1097 mux_idx = intel_cvt_id_to_mux_idx(spec, cvt_nid);
1027 if (mux_idx >= 0)1098 if (mux_idx >= 0)
1028 intel_not_share_assigned_cvt(codec, pin_nid, mux_idx);1099 intel_not_share_assigned_cvt(codec, pin_nid, dev_id, mux_idx);
1029}1100}
1030 1101
1031/* skeleton caller of pin_cvt_fixup ops */1102/* skeleton caller of pin_cvt_fixup ops */
@@ -1140,6 +1211,7 @@ static int hdmi_pcm_open(struct hda_pcm_stream *hinfo, · 108 unmodified lines
1140 per_pin->cvt_nid = per_cvt->cvt_nid;1211 per_pin->cvt_nid = per_cvt->cvt_nid;
1141 hinfo->nid = per_cvt->cvt_nid;1212 hinfo->nid = per_cvt->cvt_nid;
1142 1213
1214 snd_hda_set_dev_select(codec, per_pin->pin_nid, per_pin->dev_id);
1143 snd_hda_codec_write_cache(codec, per_pin->pin_nid, 0,1215 snd_hda_codec_write_cache(codec, per_pin->pin_nid, 0,
1144 AC_VERB_SET_CONNECT_SEL,1216 AC_VERB_SET_CONNECT_SEL,
1145 per_pin->mux_idx);1217 per_pin->mux_idx);
@@ -1198,6 +1270,7 @@ static int hdmi_read_pin_conn(struct hda_codec *codec, int pin_idx) · 52 unmodified lines
1198 return -EINVAL;1270 return -EINVAL;
1199 }1271 }
1200 1272
1273 /* all the device entries on the same pin have the same conn list */
1201 per_pin->num_mux_nids = snd_hda_get_connections(codec, pin_nid,1274 per_pin->num_mux_nids = snd_hda_get_connections(codec, pin_nid,
1202 per_pin->mux_nids,1275 per_pin->mux_nids,
1203 HDA_MAX_CONNECTIONS);1276 HDA_MAX_CONNECTIONS);
@@ -1215,13 +1288,13 @@ static int hdmi_find_pcm_slot(struct hdmi_spec *spec, · 11 unmodified lines
1215 return per_pin->pin_nid_idx;1288 return per_pin->pin_nid_idx;
1216 1289
1217 /* have a second try; check the "reserved area" over num_pins */1290 /* have a second try; check the "reserved area" over num_pins */
1218 for (i = spec->num_pins; i < spec->pcm_used; i++) {1291 for (i = spec->num_nids; i < spec->pcm_used; i++) {
1219 if (!test_bit(i, &spec->pcm_bitmap))1292 if (!test_bit(i, &spec->pcm_bitmap))
1220 return i;1293 return i;
1221 }1294 }
1222 1295
1223 /* the last try; check the empty slots in pins */1296 /* the last try; check the empty slots in pins */
1224 for (i = 0; i < spec->num_pins; i++) {1297 for (i = 0; i < spec->num_nids; i++) {
1225 if (!test_bit(i, &spec->pcm_bitmap))1298 if (!test_bit(i, &spec->pcm_bitmap))
1226 return i;1299 return i;
1227 }1300 }
@@ -1296,10 +1369,13 @@ static void hdmi_pcm_setup_pin(struct hdmi_spec *spec, · 68 unmodified lines
1296 per_pin->cvt_nid = hinfo->nid;1369 per_pin->cvt_nid = hinfo->nid;
1297 1370
1298 mux_idx = hdmi_get_pin_cvt_mux(spec, per_pin, hinfo->nid);1371 mux_idx = hdmi_get_pin_cvt_mux(spec, per_pin, hinfo->nid);
1299 if (mux_idx < per_pin->num_mux_nids)1372 if (mux_idx < per_pin->num_mux_nids) {
1373 snd_hda_set_dev_select(codec, per_pin->pin_nid,
1374 per_pin->dev_id);
1300 snd_hda_codec_write_cache(codec, per_pin->pin_nid, 0,1375 snd_hda_codec_write_cache(codec, per_pin->pin_nid, 0,
1301 AC_VERB_SET_CONNECT_SEL,1376 AC_VERB_SET_CONNECT_SEL,
1302 mux_idx);1377 mux_idx);
1378 }
1303 snd_hda_spdif_ctls_assign(codec, per_pin->pcm_idx, hinfo->nid);1379 snd_hda_spdif_ctls_assign(codec, per_pin->pcm_idx, hinfo->nid);
1304 1380
1305 non_pcm = check_non_pcm_per_cvt(codec, hinfo->nid);1381 non_pcm = check_non_pcm_per_cvt(codec, hinfo->nid);
@@ -1467,6 +1543,11 @@ static struct snd_jack *pin_idx_to_jack(struct hda_codec *codec, · 161 unmodified lines
1467 if (per_pin->pcm_idx >= 0 && spec->dyn_pcm_assign)1543 if (per_pin->pcm_idx >= 0 && spec->dyn_pcm_assign)
1468 jack = spec->pcm_rec[per_pin->pcm_idx].jack;1544 jack = spec->pcm_rec[per_pin->pcm_idx].jack;
1469 else if (!spec->dyn_pcm_assign) {1545 else if (!spec->dyn_pcm_assign) {
1546 /*
1547 * jack tbl doesn't support DP MST
1548 * DP MST will use dyn_pcm_assign,
1549 * so DP MST will never come here
1550 */
1470 jack_tbl = snd_hda_jack_tbl_get(codec, per_pin->pin_nid);1551 jack_tbl = snd_hda_jack_tbl_get(codec, per_pin->pin_nid);
1471 if (jack_tbl)1552 if (jack_tbl)
1472 jack = jack_tbl->jack;1553 jack = jack_tbl->jack;
@@ -1485,9 +1566,9 @@ static void sync_eld_via_acomp(struct hda_codec *codec, · 12 unmodified lines
1485 1566
1486 mutex_lock(&per_pin->lock);1567 mutex_lock(&per_pin->lock);
1487 eld->monitor_present = false;1568 eld->monitor_present = false;
1488 size = snd_hdac_acomp_get_eld(&codec->core, per_pin->pin_nid, -1,1569 size = snd_hdac_acomp_get_eld(&codec->core, per_pin->pin_nid,
1489 &eld->monitor_present, eld->eld_buffer,1570 per_pin->dev_id, &eld->monitor_present,
1490 ELD_MAX_SIZE);1571 eld->eld_buffer, ELD_MAX_SIZE);
1491 if (size > 0) {1572 if (size > 0) {
1492 size = min(size, ELD_MAX_SIZE);1573 size = min(size, ELD_MAX_SIZE);
1493 if (snd_hdmi_parse_eld(codec, &eld->info,1574 if (snd_hdmi_parse_eld(codec, &eld->info,
@@ -1565,38 +1646,81 @@ static int hdmi_add_pin(struct hda_codec *codec, hda_nid_t pin_nid) · 71 unmodified lines
1565 int pin_idx;1646 int pin_idx;
1566 struct hdmi_spec_per_pin *per_pin;1647 struct hdmi_spec_per_pin *per_pin;
1567 int err;1648 int err;
1649 int dev_num, i;
1568 1650
1569 caps = snd_hda_query_pin_caps(codec, pin_nid);1651 caps = snd_hda_query_pin_caps(codec, pin_nid);
1570 if (!(caps & (AC_PINCAP_HDMI | AC_PINCAP_DP)))1652 if (!(caps & (AC_PINCAP_HDMI | AC_PINCAP_DP)))
1571 return 0;1653 return 0;
1572 1654
1655 /*
1656 * For DP MST audio, Configuration Default is the same for
1657 * all device entries on the same pin
1658 */
1573 config = snd_hda_codec_get_pincfg(codec, pin_nid);1659 config = snd_hda_codec_get_pincfg(codec, pin_nid);
1574 if (get_defcfg_connect(config) == AC_JACK_PORT_NONE)1660 if (get_defcfg_connect(config) == AC_JACK_PORT_NONE)
1575 return 0;1661 return 0;
1576 1662
1577 if (is_haswell_plus(codec))1663 /*
1578 intel_haswell_fixup_connect_list(codec, pin_nid);1664 * To simplify the implementation, malloc all
1579 1665 * the virtual pins in the initialization statically
1580 pin_idx = spec->num_pins;1666 */
1581 per_pin = snd_array_new(&spec->pins);1667 if (is_haswell_plus(codec)) {
1582 if (!per_pin)1668 /*
1583 return -ENOMEM;1669 * On Intel platforms, device entries number is
1584 1670 * changed dynamically. If there is a DP MST
1585 per_pin->pin_nid = pin_nid;1671 * hub connected, the device entries number is 3.
1586 per_pin->non_pcm = false;1672 * Otherwise, it is 1.
1587 if (spec->dyn_pcm_assign)1673 * Here we manually set dev_num to 3, so that
1588 per_pin->pcm_idx = -1;1674 * we can initialize all the device entries when
1589 else {1675 * bootup statically.
1590 per_pin->pcm = get_hdmi_pcm(spec, pin_idx);1676 */
1591 per_pin->pcm_idx = pin_idx;1677 dev_num = 3;
1678 spec->dev_num = 3;
1679 } else if (spec->dyn_pcm_assign && codec->dp_mst) {
1680 dev_num = snd_hda_get_num_devices(codec, pin_nid) + 1;
1681 /*
1682 * spec->dev_num is the maxinum number of device entries
1683 * among all the pins
1684 */
1685 spec->dev_num = (spec->dev_num > dev_num) ?
1686 spec->dev_num : dev_num;
1687 } else {
1688 /*
1689 * If the platform doesn't support DP MST,
1690 * manually set dev_num to 1. This means
1691 * the pin has only one device entry.
1692 */
1693 dev_num = 1;
1694 spec->dev_num = 1;
1592 }1695 }
1593 per_pin->pin_nid_idx = pin_idx;
1594 1696
1595 err = hdmi_read_pin_conn(codec, pin_idx);1697 for (i = 0; i < dev_num; i++) {
1596 if (err < 0)1698 pin_idx = spec->num_pins;
1597 return err;1699 per_pin = snd_array_new(&spec->pins);
1598 1700
1599 spec->num_pins++;1701 if (!per_pin)
1702 return -ENOMEM;
1703
1704 if (spec->dyn_pcm_assign) {
1705 per_pin->pcm = NULL;
1706 per_pin->pcm_idx = -1;
1707 } else {
1708 per_pin->pcm = get_hdmi_pcm(spec, pin_idx);
1709 per_pin->pcm_idx = pin_idx;
1710 }
1711 per_pin->pin_nid = pin_nid;
1712 per_pin->pin_nid_idx = spec->num_nids;
1713 per_pin->dev_id = i;
1714 per_pin->non_pcm = false;
1715 snd_hda_set_dev_select(codec, pin_nid, i);
1716 if (is_haswell_plus(codec))
1717 intel_haswell_fixup_connect_list(codec, pin_nid);
1718 err = hdmi_read_pin_conn(codec, pin_idx);
1719 if (err < 0)
1720 return err;
1721 spec->num_pins++;
1722 }
1723 spec->num_nids++;
1600 1724
1601 return 0;1725 return 0;
1602}1726}
@@ -1744,7 +1868,7 @@ static int generic_hdmi_playback_pcm_prepare(struct hda_pcm_stream *hinfo, · 141 unmodified lines
1744 /* Call sync_audio_rate to set the N/CTS/M manually if necessary */1868 /* Call sync_audio_rate to set the N/CTS/M manually if necessary */
1745 /* Todo: add DP1.2 MST audio support later */1869 /* Todo: add DP1.2 MST audio support later */
1746 if (codec_has_acomp(codec))1870 if (codec_has_acomp(codec))
1747 snd_hdac_sync_audio_rate(&codec->core, pin_nid, -1,1871 snd_hdac_sync_audio_rate(&codec->core, pin_nid, per_pin->dev_id,
1748 runtime->rate);1872 runtime->rate);
1749 1873
1750 non_pcm = check_non_pcm_per_cvt(codec, cvt_nid);1874 non_pcm = check_non_pcm_per_cvt(codec, cvt_nid);
@@ -1762,6 +1886,7 @@ static int generic_hdmi_playback_pcm_prepare(struct hda_pcm_stream *hinfo, · 11 unmodified lines
1762 pinctl | PIN_OUT);1886 pinctl | PIN_OUT);
1763 }1887 }
1764 1888
1889 /* snd_hda_set_dev_select() has been called before */
1765 err = spec->ops.setup_stream(codec, cvt_nid, pin_nid,1890 err = spec->ops.setup_stream(codec, cvt_nid, pin_nid,
1766 stream_tag, format);1891 stream_tag, format);
1767 mutex_unlock(&spec->pcm_lock);1892 mutex_unlock(&spec->pcm_lock);
@@ -1897,17 +2022,23 @@ static bool is_hdmi_pcm_attached(struct hdac_device *hdac, int pcm_idx) · 129 unmodified lines
1897static int generic_hdmi_build_pcms(struct hda_codec *codec)2022static int generic_hdmi_build_pcms(struct hda_codec *codec)
1898{2023{
1899 struct hdmi_spec *spec = codec->spec;2024 struct hdmi_spec *spec = codec->spec;
1900 int pin_idx;2025 int idx;
1901 2026
1902 for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) {2027 /*
2028 * for non-mst mode, pcm number is the same as before
2029 * for DP MST mode, pcm number is (nid number + dev_num - 1)
2030 * dev_num is the device entry number in a pin
2031 *
2032 */
2033 for (idx = 0; idx < spec->num_nids + spec->dev_num - 1; idx++) {
1903 struct hda_pcm *info;2034 struct hda_pcm *info;
1904 struct hda_pcm_stream *pstr;2035 struct hda_pcm_stream *pstr;
1905 2036
1906 info = snd_hda_codec_pcm_new(codec, "HDMI %d", pin_idx);2037 info = snd_hda_codec_pcm_new(codec, "HDMI %d", idx);
1907 if (!info)2038 if (!info)
1908 return -ENOMEM;2039 return -ENOMEM;
1909 2040
1910 spec->pcm_rec[pin_idx].pcm = info;2041 spec->pcm_rec[idx].pcm = info;
1911 spec->pcm_used++;2042 spec->pcm_used++;
1912 info->pcm_type = HDA_PCM_TYPE_HDMI;2043 info->pcm_type = HDA_PCM_TYPE_HDMI;
1913 info->own_chmap = true;2044 info->own_chmap = true;
@@ -1915,6 +2046,9 @@ static int generic_hdmi_build_pcms(struct hda_codec *codec) · 1 unmodified line
1915 pstr = &info->stream[SNDRV_PCM_STREAM_PLAYBACK];2046 pstr = &info->stream[SNDRV_PCM_STREAM_PLAYBACK];
1916 pstr->substreams = 1;2047 pstr->substreams = 1;
1917 pstr->ops = generic_ops;2048 pstr->ops = generic_ops;
2049 /* pcm number is less than 16 */
2050 if (spec->pcm_used >= 16)
2051 break;
1918 /* other pstr fields are set in open */2052 /* other pstr fields are set in open */
1919 }2053 }
1920 2054
@@ -2070,7 +2204,9 @@ static int generic_hdmi_init(struct hda_codec *codec) · 149 unmodified lines
2070 for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) {2204 for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) {
2071 struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx);2205 struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx);
2072 hda_nid_t pin_nid = per_pin->pin_nid;2206 hda_nid_t pin_nid = per_pin->pin_nid;
2207 int dev_id = per_pin->dev_id;
2073 2208
2209 snd_hda_set_dev_select(codec, pin_nid, dev_id);
2074 hdmi_init_pin(codec, pin_nid);2210 hdmi_init_pin(codec, pin_nid);
2075 if (!codec_has_acomp(codec))2211 if (!codec_has_acomp(codec))
2076 snd_hda_jack_detect_enable_callback(codec, pin_nid,2212 snd_hda_jack_detect_enable_callback(codec, pin_nid,
@@ -2178,6 +2314,7 @@ static int alloc_generic_hdmi(struct hda_codec *codec) · 101 unmodified lines
2178 return -ENOMEM;2314 return -ENOMEM;
2179 2315
2180 spec->ops = generic_standard_hdmi_ops;2316 spec->ops = generic_standard_hdmi_ops;
2317 spec->dev_num = 1; /* initialize to 1 */
2181 mutex_init(&spec->pcm_lock);2318 mutex_init(&spec->pcm_lock);
2182 snd_hdac_register_chmap_ops(&codec->core, &spec->chmap);2319 snd_hdac_register_chmap_ops(&codec->core, &spec->chmap);
2183 2320
@@ -2295,6 +2432,7 @@ static void intel_pin_eld_notify(void *audio_ptr, int port, int pipe) · 111 unmodified lines
2295{2432{
2296 struct hda_codec *codec = audio_ptr;2433 struct hda_codec *codec = audio_ptr;
2297 int pin_nid;2434 int pin_nid;
2435 int dev_id = pipe;
2298 2436
2299 /* we assume only from port-B to port-D */2437 /* we assume only from port-B to port-D */
2300 if (port < 1 || port > 3)2438 if (port < 1 || port > 3)
@@ -2321,7 +2459,7 @@ static void intel_pin_eld_notify(void *audio_ptr, int port, int pipe) · 20 unmodified lines
2321 return;2459 return;
2322 2460
2323 snd_hdac_i915_set_bclk(&codec->bus->core);2461 snd_hdac_i915_set_bclk(&codec->bus->core);
2324 check_presence_and_report(codec, pin_nid);2462 check_presence_and_report(codec, pin_nid, dev_id);
2325}2463}
2326 2464
2327/* register i915 component pin_eld_notify callback */2465/* register i915 component pin_eld_notify callback */
@@ -2354,11 +2492,13 @@ static void i915_pin_cvt_fixup(struct hda_codec *codec, · 26 unmodified lines
2354 hda_nid_t cvt_nid)2492 hda_nid_t cvt_nid)
2355{2493{
2356 if (per_pin) {2494 if (per_pin) {
2495 snd_hda_set_dev_select(codec, per_pin->pin_nid,
2496 per_pin->dev_id);
2357 intel_verify_pin_cvt_connect(codec, per_pin);2497 intel_verify_pin_cvt_connect(codec, per_pin);
2358 intel_not_share_assigned_cvt(codec, per_pin->pin_nid,2498 intel_not_share_assigned_cvt(codec, per_pin->pin_nid,
2359 per_pin->mux_idx);2499 per_pin->dev_id, per_pin->mux_idx);
2360 } else {2500 } else {
2361 intel_not_share_assigned_cvt_nid(codec, 0, cvt_nid);2501 intel_not_share_assigned_cvt_nid(codec, 0, 0, cvt_nid);
2362 }2502 }
2363}2503}
2364 2504
@@ -2378,6 +2518,8 @@ static int patch_i915_hsw_hdmi(struct hda_codec *codec) · 13 unmodified lines
2378 if (err < 0)2518 if (err < 0)
2379 return err;2519 return err;
2380 spec = codec->spec;2520 spec = codec->spec;
2521 codec->dp_mst = true;
2522 spec->dyn_pcm_assign = true;
2381 2523
2382 intel_haswell_enable_all_pins(codec, true);2524 intel_haswell_enable_all_pins(codec, true);
2383 intel_haswell_fixup_enable_dp12(codec);2525 intel_haswell_fixup_enable_dp12(codec);
@@ -2389,7 +2531,6 @@ static int patch_i915_hsw_hdmi(struct hda_codec *codec) · 5 unmodified lines
2389 codec->core.link_power_control = 1;2531 codec->core.link_power_control = 1;
2390 2532
2391 codec->patch_ops.set_power_state = haswell_set_power_state;2533 codec->patch_ops.set_power_state = haswell_set_power_state;
2392 codec->dp_mst = true;
2393 codec->depop_delay = 0;2534 codec->depop_delay = 0;
2394 codec->auto_runtime_pm = 1;2535 codec->auto_runtime_pm = 1;
2395 2536

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t