Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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

Final drm/i915 features for v5.6:
- DP MST fixes (José)
- Fix intel_bw_state memory leak (Pankaj Bharadiya)
- Switch context id allocation to xarray (Tvrtko)
- ICL/EHL/TGL workarounds (Matt Roper, Tvrtko)
- Debugfs for LMEM details (Lukasz Fiedorowicz)
- Prefer platform acronyms over codenames in symbols (Lucas)
- Tiled and port sync mode fixes for fbdev and DP (Manasi)
- DSI panel and backlight enable GPIO fixes (Hans de Goede)
- Relax audio min CDCLK requirements on non-GLK (Kai Vehmanen)
- Plane alignment and dimension check fixes (Imre)
- Fix state checks for PSR (José)
- Remove ICL+ clock gating programming (José)
- Static checker fixes around bool usage (Ma Feng)
- Bring back tests for self-contained headers in i915 (Masahiro Yamada)
- Fix DP MST disable sequence (Ville)
- Start converting i915 to the new drm device based logging macros (Wambui Karuga)
- Add DSI VBT I2C sequence execution (Vivek Kasireddy)
- Start using function pointers and ops structs in uc code (Michal)
- Fix PMU names to not use colons or dashes (Tvrtko)
- TGL media decompression support (DK, Imre)
- Split i915_gem_gtt.[ch] to more manageable chunks (Matthew Auld)
- Create dumb buffers in LMEM where available (Ram)
- Extend mmap support for LMEM (Abdiel)
- Selftest updates (Chris)
- Hack bump up CDCLK on TGL to avoid underruns (Stan)
- Use intel_encoder and intel_connector more instead of drm counterparts (Ville)
- Build error fixes (Zhang Xiaoxu)
- Fixes related to GPU and engine initialization/resume (Chris)
- Support for prefaulting discontiguous objects (Abdiel)
- Support discontiguous LMEM object maps (Chris)
- Various GEM and GT improvements and fixes (Chris)
- Merge pinctrl dependencies branch for the DSI GPIO updates (Jani)
- Backmerge drm-next for new logging macros (Jani)

Signed-off-by: Dave Airlie <airlied@redhat.com>
From: Jani Nikula <jani.nikula@intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/87sgkil0v9.fsf@intel.com

+9169 -7170
+1 -1
arch/arm/mach-u300/core.c
··· 201 201 }; 202 202 203 203 /* Pin control settings */ 204 - static struct pinctrl_map __initdata u300_pinmux_map[] = { 204 + static const struct pinctrl_map u300_pinmux_map[] = { 205 205 /* anonymous maps for chip power and EMIFs */ 206 206 PIN_MAP_MUX_GROUP_HOG_DEFAULT("pinctrl-u300", NULL, "power"), 207 207 PIN_MAP_MUX_GROUP_HOG_DEFAULT("pinctrl-u300", NULL, "emif0"),
+72
drivers/gpu/drm/drm_client_modeset.c
··· 115 115 } 116 116 117 117 static struct drm_display_mode * 118 + drm_connector_get_tiled_mode(struct drm_connector *connector) 119 + { 120 + struct drm_display_mode *mode; 121 + 122 + list_for_each_entry(mode, &connector->modes, head) { 123 + if (mode->hdisplay == connector->tile_h_size && 124 + mode->vdisplay == connector->tile_v_size) 125 + return mode; 126 + } 127 + return NULL; 128 + } 129 + 130 + static struct drm_display_mode * 131 + drm_connector_fallback_non_tiled_mode(struct drm_connector *connector) 132 + { 133 + struct drm_display_mode *mode; 134 + 135 + list_for_each_entry(mode, &connector->modes, head) { 136 + if (mode->hdisplay == connector->tile_h_size && 137 + mode->vdisplay == connector->tile_v_size) 138 + continue; 139 + return mode; 140 + } 141 + return NULL; 142 + } 143 + 144 + static struct drm_display_mode * 118 145 drm_connector_has_preferred_mode(struct drm_connector *connector, int width, int height) 119 146 { 120 147 struct drm_display_mode *mode; ··· 375 348 struct drm_connector *connector; 376 349 u64 conn_configured = 0; 377 350 int tile_pass = 0; 351 + int num_tiled_conns = 0; 378 352 int i; 353 + 354 + for (i = 0; i < connector_count; i++) { 355 + if (connectors[i]->has_tile && 356 + connectors[i]->status == connector_status_connected) 357 + num_tiled_conns++; 358 + } 379 359 380 360 retry: 381 361 for (i = 0; i < connector_count; i++) { ··· 433 399 list_for_each_entry(modes[i], &connector->modes, head) 434 400 break; 435 401 } 402 + /* 403 + * In case of tiled mode if all tiles not present fallback to 404 + * first available non tiled mode. 405 + * After all tiles are present, try to find the tiled mode 406 + * for all and if tiled mode not present due to fbcon size 407 + * limitations, use first non tiled mode only for 408 + * tile 0,0 and set to no mode for all other tiles. 409 + */ 410 + if (connector->has_tile) { 411 + if (num_tiled_conns < 412 + connector->num_h_tile * connector->num_v_tile || 413 + (connector->tile_h_loc == 0 && 414 + connector->tile_v_loc == 0 && 415 + !drm_connector_get_tiled_mode(connector))) { 416 + DRM_DEBUG_KMS("Falling back to non tiled mode on Connector %d\n", 417 + connector->base.id); 418 + modes[i] = drm_connector_fallback_non_tiled_mode(connector); 419 + } else { 420 + modes[i] = drm_connector_get_tiled_mode(connector); 421 + } 422 + } 423 + 436 424 DRM_DEBUG_KMS("found mode %s\n", modes[i] ? modes[i]->name : 437 425 "none"); 438 426 conn_configured |= BIT_ULL(i); ··· 571 515 bool fallback = true, ret = true; 572 516 int num_connectors_enabled = 0; 573 517 int num_connectors_detected = 0; 518 + int num_tiled_conns = 0; 574 519 struct drm_modeset_acquire_ctx ctx; 575 520 576 521 if (!drm_drv_uses_atomic_modeset(dev)) ··· 589 532 memcpy(save_enabled, enabled, count); 590 533 mask = GENMASK(count - 1, 0); 591 534 conn_configured = 0; 535 + for (i = 0; i < count; i++) { 536 + if (connectors[i]->has_tile && 537 + connectors[i]->status == connector_status_connected) 538 + num_tiled_conns++; 539 + } 592 540 retry: 593 541 conn_seq = conn_configured; 594 542 for (i = 0; i < count; i++) { ··· 692 630 DRM_DEBUG_KMS("looking for current mode on connector %s\n", 693 631 connector->name); 694 632 modes[i] = &connector->state->crtc->mode; 633 + } 634 + /* 635 + * In case of tiled modes, if all tiles are not present 636 + * then fallback to a non tiled mode. 637 + */ 638 + if (connector->has_tile && 639 + num_tiled_conns < connector->num_h_tile * connector->num_v_tile) { 640 + DRM_DEBUG_KMS("Falling back to non tiled mode on Connector %d\n", 641 + connector->base.id); 642 + modes[i] = drm_connector_fallback_non_tiled_mode(connector); 695 643 } 696 644 crtcs[i] = new_crtc; 697 645
+3 -1
drivers/gpu/drm/drm_fb_helper.c
··· 1561 1561 for (j = 0; j < mode_set->num_connectors; j++) { 1562 1562 struct drm_connector *connector = mode_set->connectors[j]; 1563 1563 1564 - if (connector->has_tile) { 1564 + if (connector->has_tile && 1565 + desired_mode->hdisplay == connector->tile_h_size && 1566 + desired_mode->vdisplay == connector->tile_v_size) { 1565 1567 lasth = (connector->tile_h_loc == (connector->num_h_tile - 1)); 1566 1568 lastv = (connector->tile_v_loc == (connector->num_v_tile - 1)); 1567 1569 /* cloning to multiple tiles is just crazy-talk, so: */
+1
drivers/gpu/drm/i915/.gitignore
··· 1 + *.hdrtest
+30 -8
drivers/gpu/drm/i915/Makefile
··· 31 31 subdir-ccflags-y += \ 32 32 $(call as-instr,movntdqa (%eax)$(comma)%xmm0,-DCONFIG_AS_MOVNTDQA) 33 33 34 - # Extra header tests 35 - header-test-pattern-$(CONFIG_DRM_I915_WERROR) := *.h 36 - 37 34 subdir-ccflags-y += -I$(srctree)/$(src) 38 35 39 36 # Please keep these build lists sorted! ··· 70 73 i915-$(CONFIG_PERF_EVENTS) += i915_pmu.o 71 74 72 75 # "Graphics Technology" (aka we talk to the gpu) 73 - obj-y += gt/ 74 76 gt-y += \ 75 77 gt/debugfs_engines.o \ 76 78 gt/debugfs_gt.o \ 77 79 gt/debugfs_gt_pm.o \ 80 + gt/gen6_ppgtt.o \ 81 + gt/gen8_ppgtt.o \ 78 82 gt/intel_breadcrumbs.o \ 79 83 gt/intel_context.o \ 80 84 gt/intel_engine_cs.o \ ··· 83 85 gt/intel_engine_pm.o \ 84 86 gt/intel_engine_pool.o \ 85 87 gt/intel_engine_user.o \ 88 + gt/intel_ggtt.o \ 86 89 gt/intel_gt.o \ 87 90 gt/intel_gt_irq.o \ 88 91 gt/intel_gt_pm.o \ 89 92 gt/intel_gt_pm_irq.o \ 90 93 gt/intel_gt_requests.o \ 94 + gt/intel_gtt.o \ 91 95 gt/intel_llc.o \ 92 96 gt/intel_lrc.o \ 93 97 gt/intel_mocs.o \ 98 + gt/intel_ppgtt.o \ 94 99 gt/intel_rc6.o \ 95 100 gt/intel_renderstate.o \ 96 101 gt/intel_reset.o \ ··· 112 111 i915-y += $(gt-y) 113 112 114 113 # GEM (Graphics Execution Management) code 115 - obj-y += gem/ 116 114 gem-y += \ 117 115 gem/i915_gem_busy.o \ 118 116 gem/i915_gem_clflush.o \ ··· 157 157 intel_wopcm.o 158 158 159 159 # general-purpose microcontroller (GuC) support 160 - obj-y += gt/uc/ 161 160 i915-y += gt/uc/intel_uc.o \ 162 161 gt/uc/intel_uc_fw.o \ 163 162 gt/uc/intel_guc.o \ ··· 169 170 gt/uc/intel_huc_fw.o 170 171 171 172 # modesetting core code 172 - obj-y += display/ 173 173 i915-y += \ 174 174 display/intel_atomic.o \ 175 175 display/intel_atomic_plane.o \ ··· 233 235 display/vlv_dsi_pll.o 234 236 235 237 # perf code 236 - obj-y += oa/ 237 238 i915-y += \ 238 239 oa/i915_oa_hsw.o \ 239 240 oa/i915_oa_bdw.o \ ··· 257 260 gem/selftests/igt_gem_utils.o \ 258 261 selftests/i915_random.o \ 259 262 selftests/i915_selftest.o \ 263 + selftests/igt_atomic.o \ 260 264 selftests/igt_flush_test.o \ 261 265 selftests/igt_live_test.o \ 262 266 selftests/igt_mmap.o \ ··· 274 276 275 277 obj-$(CONFIG_DRM_I915) += i915.o 276 278 obj-$(CONFIG_DRM_I915_GVT_KVMGT) += gvt/kvmgt.o 279 + 280 + # header test 281 + 282 + # exclude some broken headers from the test coverage 283 + no-header-test := \ 284 + display/intel_vbt_defs.h \ 285 + gvt/execlist.h \ 286 + gvt/fb_decoder.h \ 287 + gvt/gtt.h \ 288 + gvt/gvt.h \ 289 + gvt/interrupt.h \ 290 + gvt/mmio_context.h \ 291 + gvt/mpt.h \ 292 + gvt/scheduler.h 293 + 294 + extra-$(CONFIG_DRM_I915_WERROR) += \ 295 + $(patsubst %.h,%.hdrtest, $(filter-out $(no-header-test), \ 296 + $(shell cd $(srctree)/$(src) && find * -name '*.h'))) 297 + 298 + quiet_cmd_hdrtest = HDRTEST $(patsubst %.hdrtest,%.h,$@) 299 + cmd_hdrtest = $(CC) $(c_flags) -S -o /dev/null -x c /dev/null -include $<; touch $@ 300 + 301 + $(obj)/%.hdrtest: $(src)/%.h FORCE 302 + $(call if_changed_dep,hdrtest)
-6
drivers/gpu/drm/i915/display/Makefile
··· 1 - # For building individual subdir files on the command line 2 - subdir-ccflags-y += -I$(srctree)/$(src)/.. 3 - 4 - # Extra header tests 5 - header-test-pattern-$(CONFIG_DRM_I915_WERROR) := *.h 6 - header-test- := intel_vbt_defs.h
+32 -31
drivers/gpu/drm/i915/display/icl_dsi.c
··· 77 77 static void wait_for_cmds_dispatched_to_panel(struct intel_encoder *encoder) 78 78 { 79 79 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 80 - struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base); 80 + struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder); 81 81 struct mipi_dsi_device *dsi; 82 82 enum port port; 83 83 enum transcoder dsi_trans; ··· 202 202 static void dsi_program_swing_and_deemphasis(struct intel_encoder *encoder) 203 203 { 204 204 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 205 - struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base); 205 + struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder); 206 206 enum phy phy; 207 207 u32 tmp; 208 208 int lane; ··· 267 267 const struct intel_crtc_state *pipe_config) 268 268 { 269 269 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 270 - struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base); 270 + struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder); 271 271 u32 dss_ctl1; 272 272 273 273 dss_ctl1 = I915_READ(DSS_CTL1); ··· 306 306 static int afe_clk(struct intel_encoder *encoder, 307 307 const struct intel_crtc_state *crtc_state) 308 308 { 309 - struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base); 309 + struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder); 310 310 int bpp; 311 311 312 312 if (crtc_state->dsc.compression_enable) ··· 321 321 const struct intel_crtc_state *crtc_state) 322 322 { 323 323 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 324 - struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base); 324 + struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder); 325 325 enum port port; 326 326 int afe_clk_khz; 327 327 u32 esc_clk_div_m; ··· 360 360 static void gen11_dsi_enable_io_power(struct intel_encoder *encoder) 361 361 { 362 362 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 363 - struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base); 363 + struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder); 364 364 enum port port; 365 365 u32 tmp; 366 366 ··· 376 376 static void gen11_dsi_power_up_lanes(struct intel_encoder *encoder) 377 377 { 378 378 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 379 - struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base); 379 + struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder); 380 380 enum phy phy; 381 381 382 382 for_each_dsi_phy(phy, intel_dsi->phys) ··· 387 387 static void gen11_dsi_config_phy_lanes_sequence(struct intel_encoder *encoder) 388 388 { 389 389 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 390 - struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base); 390 + struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder); 391 391 enum phy phy; 392 392 u32 tmp; 393 393 int lane; ··· 436 436 static void gen11_dsi_voltage_swing_program_seq(struct intel_encoder *encoder) 437 437 { 438 438 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 439 - struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base); 439 + struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder); 440 440 u32 tmp; 441 441 enum phy phy; 442 442 ··· 488 488 static void gen11_dsi_enable_ddi_buffer(struct intel_encoder *encoder) 489 489 { 490 490 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 491 - struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base); 491 + struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder); 492 492 u32 tmp; 493 493 enum port port; 494 494 ··· 509 509 const struct intel_crtc_state *crtc_state) 510 510 { 511 511 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 512 - struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base); 512 + struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder); 513 513 u32 tmp; 514 514 enum port port; 515 515 enum phy phy; ··· 575 575 static void gen11_dsi_gate_clocks(struct intel_encoder *encoder) 576 576 { 577 577 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 578 - struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base); 578 + struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder); 579 579 u32 tmp; 580 580 enum phy phy; 581 581 ··· 591 591 static void gen11_dsi_ungate_clocks(struct intel_encoder *encoder) 592 592 { 593 593 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 594 - struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base); 594 + struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder); 595 595 u32 tmp; 596 596 enum phy phy; 597 597 ··· 608 608 const struct intel_crtc_state *crtc_state) 609 609 { 610 610 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 611 - struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base); 611 + struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder); 612 612 struct intel_shared_dpll *pll = crtc_state->shared_dpll; 613 613 enum phy phy; 614 614 u32 val; ··· 640 640 const struct intel_crtc_state *pipe_config) 641 641 { 642 642 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 643 - struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base); 643 + struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder); 644 644 struct intel_crtc *intel_crtc = to_intel_crtc(pipe_config->uapi.crtc); 645 645 enum pipe pipe = intel_crtc->pipe; 646 646 u32 tmp; ··· 789 789 const struct intel_crtc_state *crtc_state) 790 790 { 791 791 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 792 - struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base); 792 + struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder); 793 793 const struct drm_display_mode *adjusted_mode = 794 794 &crtc_state->hw.adjusted_mode; 795 795 enum port port; ··· 923 923 static void gen11_dsi_enable_transcoder(struct intel_encoder *encoder) 924 924 { 925 925 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 926 - struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base); 926 + struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder); 927 927 enum port port; 928 928 enum transcoder dsi_trans; 929 929 u32 tmp; ··· 945 945 const struct intel_crtc_state *crtc_state) 946 946 { 947 947 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 948 - struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base); 948 + struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder); 949 949 enum port port; 950 950 enum transcoder dsi_trans; 951 951 u32 tmp, hs_tx_timeout, lp_rx_timeout, ta_timeout, divisor, mul; ··· 1026 1026 static void gen11_dsi_powerup_panel(struct intel_encoder *encoder) 1027 1027 { 1028 1028 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 1029 - struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base); 1029 + struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder); 1030 1030 struct mipi_dsi_device *dsi; 1031 1031 enum port port; 1032 1032 enum transcoder dsi_trans; ··· 1077 1077 const struct intel_crtc_state *pipe_config, 1078 1078 const struct drm_connector_state *conn_state) 1079 1079 { 1080 - struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base); 1080 + struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder); 1081 1081 1082 1082 /* step3b */ 1083 1083 gen11_dsi_map_pll(encoder, pipe_config); ··· 1104 1104 static void gen11_dsi_disable_transcoder(struct intel_encoder *encoder) 1105 1105 { 1106 1106 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 1107 - struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base); 1107 + struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder); 1108 1108 enum port port; 1109 1109 enum transcoder dsi_trans; 1110 1110 u32 tmp; ··· 1126 1126 1127 1127 static void gen11_dsi_powerdown_panel(struct intel_encoder *encoder) 1128 1128 { 1129 - struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base); 1129 + struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder); 1130 1130 1131 1131 intel_dsi_vbt_exec_sequence(intel_dsi, MIPI_SEQ_DISPLAY_OFF); 1132 1132 intel_dsi_vbt_exec_sequence(intel_dsi, MIPI_SEQ_ASSERT_RESET); ··· 1139 1139 static void gen11_dsi_deconfigure_trancoder(struct intel_encoder *encoder) 1140 1140 { 1141 1141 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 1142 - struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base); 1142 + struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder); 1143 1143 enum port port; 1144 1144 enum transcoder dsi_trans; 1145 1145 u32 tmp; ··· 1180 1180 static void gen11_dsi_disable_port(struct intel_encoder *encoder) 1181 1181 { 1182 1182 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 1183 - struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base); 1183 + struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder); 1184 1184 u32 tmp; 1185 1185 enum port port; 1186 1186 ··· 1202 1202 static void gen11_dsi_disable_io_power(struct intel_encoder *encoder) 1203 1203 { 1204 1204 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 1205 - struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base); 1205 + struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder); 1206 1206 enum port port; 1207 1207 u32 tmp; 1208 1208 ··· 1229 1229 const struct intel_crtc_state *old_crtc_state, 1230 1230 const struct drm_connector_state *old_conn_state) 1231 1231 { 1232 - struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base); 1232 + struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder); 1233 1233 1234 1234 /* step1: turn off backlight */ 1235 1235 intel_dsi_vbt_exec_sequence(intel_dsi, MIPI_SEQ_BACKLIGHT_OFF); ··· 1259 1259 1260 1260 intel_dsc_disable(old_crtc_state); 1261 1261 1262 - skylake_scaler_disable(old_crtc_state); 1262 + skl_scaler_disable(old_crtc_state); 1263 1263 } 1264 1264 1265 1265 static enum drm_mode_status gen11_dsi_mode_valid(struct drm_connector *connector, ··· 1272 1272 static void gen11_dsi_get_timings(struct intel_encoder *encoder, 1273 1273 struct intel_crtc_state *pipe_config) 1274 1274 { 1275 - struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base); 1275 + struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder); 1276 1276 struct drm_display_mode *adjusted_mode = 1277 1277 &pipe_config->hw.adjusted_mode; 1278 1278 ··· 1313 1313 { 1314 1314 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 1315 1315 struct intel_crtc *crtc = to_intel_crtc(pipe_config->uapi.crtc); 1316 - struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base); 1316 + struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder); 1317 1317 1318 1318 intel_dsc_get_config(encoder, pipe_config); 1319 1319 ··· 1417 1417 { 1418 1418 struct drm_i915_private *i915 = to_i915(encoder->base.dev); 1419 1419 1420 - get_dsi_io_power_domains(i915, enc_to_intel_dsi(&encoder->base)); 1420 + get_dsi_io_power_domains(i915, 1421 + enc_to_intel_dsi(encoder)); 1421 1422 1422 1423 if (crtc_state->dsc.compression_enable) 1423 1424 intel_display_power_get(i915, ··· 1429 1428 enum pipe *pipe) 1430 1429 { 1431 1430 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 1432 - struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base); 1431 + struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder); 1433 1432 enum transcoder dsi_trans; 1434 1433 intel_wakeref_t wakeref; 1435 1434 enum port port;
+34
drivers/gpu/drm/i915/display/intel_atomic.c
··· 37 37 #include "intel_atomic.h" 38 38 #include "intel_display_types.h" 39 39 #include "intel_hdcp.h" 40 + #include "intel_psr.h" 40 41 #include "intel_sprite.h" 41 42 42 43 /** ··· 130 129 struct drm_crtc_state *crtc_state; 131 130 132 131 intel_hdcp_atomic_check(conn, old_state, new_state); 132 + intel_psr_atomic_check(conn, old_state, new_state); 133 133 134 134 if (!new_state->crtc) 135 135 return 0; ··· 174 172 175 173 __drm_atomic_helper_connector_duplicate_state(connector, &state->base); 176 174 return &state->base; 175 + } 176 + 177 + /** 178 + * intel_connector_needs_modeset - check if connector needs a modeset 179 + */ 180 + bool 181 + intel_connector_needs_modeset(struct intel_atomic_state *state, 182 + struct drm_connector *connector) 183 + { 184 + const struct drm_connector_state *old_conn_state, *new_conn_state; 185 + 186 + old_conn_state = drm_atomic_get_old_connector_state(&state->base, connector); 187 + new_conn_state = drm_atomic_get_new_connector_state(&state->base, connector); 188 + 189 + return old_conn_state->crtc != new_conn_state->crtc || 190 + (new_conn_state->crtc && 191 + drm_atomic_crtc_needs_modeset(drm_atomic_get_new_crtc_state(&state->base, 192 + new_conn_state->crtc))); 193 + } 194 + 195 + struct intel_digital_connector_state * 196 + intel_atomic_get_digital_connector_state(struct intel_atomic_state *state, 197 + struct intel_connector *connector) 198 + { 199 + struct drm_connector_state *conn_state; 200 + 201 + conn_state = drm_atomic_get_connector_state(&state->base, 202 + &connector->base); 203 + if (IS_ERR(conn_state)) 204 + return ERR_CAST(conn_state); 205 + 206 + return to_intel_digital_connector_state(conn_state); 177 207 } 178 208 179 209 /**
+6
drivers/gpu/drm/i915/display/intel_atomic.h
··· 17 17 struct drm_i915_private; 18 18 struct drm_property; 19 19 struct intel_atomic_state; 20 + struct intel_connector; 20 21 struct intel_crtc; 21 22 struct intel_crtc_state; 22 23 ··· 33 32 struct drm_atomic_state *state); 34 33 struct drm_connector_state * 35 34 intel_digital_connector_duplicate_state(struct drm_connector *connector); 35 + bool intel_connector_needs_modeset(struct intel_atomic_state *state, 36 + struct drm_connector *connector); 37 + struct intel_digital_connector_state * 38 + intel_atomic_get_digital_connector_state(struct intel_atomic_state *state, 39 + struct intel_connector *connector); 36 40 37 41 struct drm_crtc_state *intel_crtc_duplicate_state(struct drm_crtc *crtc); 38 42 void intel_crtc_destroy_state(struct drm_crtc *crtc,
+4 -4
drivers/gpu/drm/i915/display/intel_audio.c
··· 707 707 DRM_DEBUG_DRIVER("ELD on [CONNECTOR:%d:%s], [ENCODER:%d:%s]\n", 708 708 connector->base.id, 709 709 connector->name, 710 - connector->encoder->base.id, 711 - connector->encoder->name); 710 + encoder->base.base.id, 711 + encoder->base.name); 712 712 713 713 connector->eld[6] = drm_av_sync_delay(connector, adjusted_mode) / 2; 714 714 ··· 856 856 } 857 857 858 858 /* Force CDCLK to 2*BCLK as long as we need audio powered. */ 859 - if (INTEL_GEN(dev_priv) >= 10 || IS_GEMINILAKE(dev_priv)) 859 + if (IS_GEMINILAKE(dev_priv)) 860 860 glk_force_audio_cdclk(dev_priv, true); 861 861 862 862 if (INTEL_GEN(dev_priv) >= 10 || IS_GEMINILAKE(dev_priv)) ··· 875 875 876 876 /* Stop forcing CDCLK to 2*BCLK if no need for audio to be powered. */ 877 877 if (--dev_priv->audio_power_refcount == 0) 878 - if (INTEL_GEN(dev_priv) >= 10 || IS_GEMINILAKE(dev_priv)) 878 + if (IS_GEMINILAKE(dev_priv)) 879 879 glk_force_audio_cdclk(dev_priv, false); 880 880 881 881 intel_display_power_put(dev_priv, POWER_DOMAIN_AUDIO, cookie);
+5
drivers/gpu/drm/i915/display/intel_bw.c
··· 486 486 487 487 return 0; 488 488 } 489 + 490 + void intel_bw_cleanup(struct drm_i915_private *dev_priv) 491 + { 492 + drm_atomic_private_obj_fini(&dev_priv->bw_obj); 493 + }
+1
drivers/gpu/drm/i915/display/intel_bw.h
··· 25 25 26 26 void intel_bw_init_hw(struct drm_i915_private *dev_priv); 27 27 int intel_bw_init(struct drm_i915_private *dev_priv); 28 + void intel_bw_cleanup(struct drm_i915_private *dev_priv); 28 29 int intel_bw_atomic_check(struct intel_atomic_state *state); 29 30 void intel_bw_crtc_update(struct intel_bw_state *bw_state, 30 31 const struct intel_crtc_state *crtc_state);
+12
drivers/gpu/drm/i915/display/intel_cdclk.c
··· 2004 2004 /* Account for additional needs from the planes */ 2005 2005 min_cdclk = max(intel_planes_min_cdclk(crtc_state), min_cdclk); 2006 2006 2007 + /* 2008 + * HACK. Currently for TGL platforms we calculate 2009 + * min_cdclk initially based on pixel_rate divided 2010 + * by 2, accounting for also plane requirements, 2011 + * however in some cases the lowest possible CDCLK 2012 + * doesn't work and causing the underruns. 2013 + * Explicitly stating here that this seems to be currently 2014 + * rather a Hack, than final solution. 2015 + */ 2016 + if (IS_TIGERLAKE(dev_priv)) 2017 + min_cdclk = max(min_cdclk, (int)crtc_state->pixel_rate); 2018 + 2007 2019 if (min_cdclk > dev_priv->max_cdclk_freq) { 2008 2020 DRM_DEBUG_KMS("required cdclk (%d kHz) exceeds max (%d kHz)\n", 2009 2021 min_cdclk, dev_priv->max_cdclk_freq);
+13 -13
drivers/gpu/drm/i915/display/intel_crt.c
··· 65 65 return container_of(encoder, struct intel_crt, base); 66 66 } 67 67 68 - static struct intel_crt *intel_attached_crt(struct drm_connector *connector) 68 + static struct intel_crt *intel_attached_crt(struct intel_connector *connector) 69 69 { 70 70 return intel_encoder_to_crt(intel_attached_encoder(connector)); 71 71 } ··· 247 247 248 248 intel_ddi_disable_transcoder_func(old_crtc_state); 249 249 250 - ironlake_pfit_disable(old_crtc_state); 250 + ilk_pfit_disable(old_crtc_state); 251 251 252 252 intel_ddi_disable_pipe_clock(old_crtc_state); 253 253 ··· 351 351 352 352 /* The FDI receiver on LPT only supports 8bpc and only has 2 lanes. */ 353 353 if (HAS_PCH_LPT(dev_priv) && 354 - (ironlake_get_lanes_required(mode->clock, 270000, 24) > 2)) 354 + ilk_get_lanes_required(mode->clock, 270000, 24) > 2) 355 355 return MODE_CLOCK_HIGH; 356 356 357 357 /* HSW/BDW FDI limited to 4k */ ··· 427 427 return 0; 428 428 } 429 429 430 - static bool intel_ironlake_crt_detect_hotplug(struct drm_connector *connector) 430 + static bool ilk_crt_detect_hotplug(struct drm_connector *connector) 431 431 { 432 432 struct drm_device *dev = connector->dev; 433 - struct intel_crt *crt = intel_attached_crt(connector); 433 + struct intel_crt *crt = intel_attached_crt(to_intel_connector(connector)); 434 434 struct drm_i915_private *dev_priv = to_i915(dev); 435 435 u32 adpa; 436 436 bool ret; ··· 440 440 bool turn_off_dac = HAS_PCH_SPLIT(dev_priv); 441 441 u32 save_adpa; 442 442 443 - crt->force_hotplug_required = 0; 443 + crt->force_hotplug_required = false; 444 444 445 445 save_adpa = adpa = I915_READ(crt->adpa_reg); 446 446 DRM_DEBUG_KMS("trigger hotplug detect cycle: adpa=0x%x\n", adpa); ··· 477 477 static bool valleyview_crt_detect_hotplug(struct drm_connector *connector) 478 478 { 479 479 struct drm_device *dev = connector->dev; 480 - struct intel_crt *crt = intel_attached_crt(connector); 480 + struct intel_crt *crt = intel_attached_crt(to_intel_connector(connector)); 481 481 struct drm_i915_private *dev_priv = to_i915(dev); 482 482 bool reenable_hpd; 483 483 u32 adpa; ··· 535 535 int i, tries = 0; 536 536 537 537 if (HAS_PCH_SPLIT(dev_priv)) 538 - return intel_ironlake_crt_detect_hotplug(connector); 538 + return ilk_crt_detect_hotplug(connector); 539 539 540 540 if (IS_VALLEYVIEW(dev_priv)) 541 541 return valleyview_crt_detect_hotplug(connector); ··· 609 609 610 610 static bool intel_crt_detect_ddc(struct drm_connector *connector) 611 611 { 612 - struct intel_crt *crt = intel_attached_crt(connector); 612 + struct intel_crt *crt = intel_attached_crt(to_intel_connector(connector)); 613 613 struct drm_i915_private *dev_priv = to_i915(crt->base.base.dev); 614 614 struct edid *edid; 615 615 struct i2c_adapter *i2c; ··· 795 795 bool force) 796 796 { 797 797 struct drm_i915_private *dev_priv = to_i915(connector->dev); 798 - struct intel_crt *crt = intel_attached_crt(connector); 798 + struct intel_crt *crt = intel_attached_crt(to_intel_connector(connector)); 799 799 struct intel_encoder *intel_encoder = &crt->base; 800 800 intel_wakeref_t wakeref; 801 801 int status, ret; ··· 886 886 { 887 887 struct drm_device *dev = connector->dev; 888 888 struct drm_i915_private *dev_priv = to_i915(dev); 889 - struct intel_crt *crt = intel_attached_crt(connector); 889 + struct intel_crt *crt = intel_attached_crt(to_intel_connector(connector)); 890 890 struct intel_encoder *intel_encoder = &crt->base; 891 891 intel_wakeref_t wakeref; 892 892 struct i2c_adapter *i2c; ··· 925 925 POSTING_READ(crt->adpa_reg); 926 926 927 927 DRM_DEBUG_KMS("crt adpa set to 0x%x\n", adpa); 928 - crt->force_hotplug_required = 1; 928 + crt->force_hotplug_required = true; 929 929 } 930 930 931 931 } ··· 1063 1063 /* 1064 1064 * Configure the automatic hotplug detection stuff 1065 1065 */ 1066 - crt->force_hotplug_required = 0; 1066 + crt->force_hotplug_required = false; 1067 1067 1068 1068 /* 1069 1069 * TODO: find a proper way to discover whether we need to set the the
+85 -133
drivers/gpu/drm/i915/display/intel_ddi.c
··· 34 34 #include "intel_ddi.h" 35 35 #include "intel_display_types.h" 36 36 #include "intel_dp.h" 37 + #include "intel_dp_mst.h" 37 38 #include "intel_dp_link_training.h" 38 39 #include "intel_dpio_phy.h" 39 40 #include "intel_dsi.h" ··· 1238 1237 1239 1238 static void intel_ddi_init_dp_buf_reg(struct intel_encoder *encoder) 1240 1239 { 1241 - struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base); 1240 + struct intel_dp *intel_dp = enc_to_intel_dp(encoder); 1242 1241 struct intel_digital_port *intel_dig_port = 1243 - enc_to_dig_port(&encoder->base); 1242 + enc_to_dig_port(encoder); 1244 1243 1245 1244 intel_dp->DP = intel_dig_port->saved_port_bits | 1246 1245 DDI_BUF_CTL_ENABLE | DDI_BUF_TRANS_SELECT(0); ··· 1900 1899 temp |= TRANS_DDI_MODE_SELECT_DP_MST; 1901 1900 temp |= DDI_PORT_WIDTH(crtc_state->lane_count); 1902 1901 1903 - if (INTEL_GEN(dev_priv) >= 12) 1904 - temp |= TRANS_DDI_MST_TRANSPORT_SELECT(crtc_state->cpu_transcoder); 1902 + if (INTEL_GEN(dev_priv) >= 12) { 1903 + enum transcoder master; 1904 + 1905 + master = crtc_state->mst_master_transcoder; 1906 + WARN_ON(master == INVALID_TRANSCODER); 1907 + temp |= TRANS_DDI_MST_TRANSPORT_SELECT(master); 1908 + } 1905 1909 } else { 1906 1910 temp |= TRANS_DDI_MODE_SELECT_DP_SST; 1907 1911 temp |= DDI_PORT_WIDTH(crtc_state->lane_count); ··· 1950 1944 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc); 1951 1945 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); 1952 1946 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder; 1953 - i915_reg_t reg = TRANS_DDI_FUNC_CTL(cpu_transcoder); 1954 - u32 val = I915_READ(reg); 1947 + u32 val; 1948 + 1949 + val = I915_READ(TRANS_DDI_FUNC_CTL(cpu_transcoder)); 1950 + val &= ~TRANS_DDI_FUNC_ENABLE; 1955 1951 1956 1952 if (INTEL_GEN(dev_priv) >= 12) { 1957 - val &= ~(TRANS_DDI_FUNC_ENABLE | TGL_TRANS_DDI_PORT_MASK | 1958 - TRANS_DDI_DP_VC_PAYLOAD_ALLOC); 1953 + if (!intel_dp_mst_is_master_trans(crtc_state)) 1954 + val &= ~TGL_TRANS_DDI_PORT_MASK; 1959 1955 } else { 1960 - val &= ~(TRANS_DDI_FUNC_ENABLE | TRANS_DDI_PORT_MASK | 1961 - TRANS_DDI_DP_VC_PAYLOAD_ALLOC); 1956 + val &= ~TRANS_DDI_PORT_MASK; 1962 1957 } 1963 - I915_WRITE(reg, val); 1958 + I915_WRITE(TRANS_DDI_FUNC_CTL(cpu_transcoder), val); 1964 1959 1965 1960 if (dev_priv->quirks & QUIRK_INCREASE_DDI_DISABLED_TIME && 1966 1961 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI)) { ··· 2224 2217 if (WARN_ON(intel_crtc_has_type(crtc_state, INTEL_OUTPUT_DP_MST))) 2225 2218 return; 2226 2219 2227 - dig_port = enc_to_dig_port(&encoder->base); 2220 + dig_port = enc_to_dig_port(encoder); 2228 2221 intel_display_power_get(dev_priv, dig_port->ddi_io_power_domain); 2229 2222 2230 2223 /* ··· 2294 2287 static void skl_ddi_set_iboost(struct intel_encoder *encoder, 2295 2288 int level, enum intel_output_type type) 2296 2289 { 2297 - struct intel_digital_port *intel_dig_port = enc_to_dig_port(&encoder->base); 2290 + struct intel_digital_port *intel_dig_port = enc_to_dig_port(encoder); 2298 2291 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 2299 2292 enum port port = encoder->port; 2300 2293 u8 iboost; ··· 2365 2358 u8 intel_ddi_dp_voltage_max(struct intel_encoder *encoder) 2366 2359 { 2367 2360 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 2368 - struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base); 2361 + struct intel_dp *intel_dp = enc_to_intel_dp(encoder); 2369 2362 enum port port = encoder->port; 2370 2363 enum phy phy = intel_port_to_phy(dev_priv, port); 2371 2364 int n_entries; ··· 2504 2497 width = 4; 2505 2498 rate = 0; /* Rate is always < than 6GHz for HDMI */ 2506 2499 } else { 2507 - struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base); 2500 + struct intel_dp *intel_dp = enc_to_intel_dp(encoder); 2508 2501 2509 2502 width = intel_dp->lane_count; 2510 2503 rate = intel_dp->link_rate; ··· 2630 2623 width = 4; 2631 2624 /* Rate is always < than 6GHz for HDMI */ 2632 2625 } else { 2633 - struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base); 2626 + struct intel_dp *intel_dp = enc_to_intel_dp(encoder); 2634 2627 2635 2628 width = intel_dp->lane_count; 2636 2629 rate = intel_dp->link_rate; ··· 3168 3161 } 3169 3162 3170 3163 static void 3171 - icl_phy_set_clock_gating(struct intel_digital_port *dig_port, bool enable) 3172 - { 3173 - struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev); 3174 - enum tc_port tc_port = intel_port_to_tc(dev_priv, dig_port->base.port); 3175 - u32 val, bits; 3176 - int ln; 3177 - 3178 - if (tc_port == PORT_TC_NONE) 3179 - return; 3180 - 3181 - bits = MG_DP_MODE_CFG_TR2PWR_GATING | MG_DP_MODE_CFG_TRPWR_GATING | 3182 - MG_DP_MODE_CFG_CLNPWR_GATING | MG_DP_MODE_CFG_DIGPWR_GATING | 3183 - MG_DP_MODE_CFG_GAONPWR_GATING; 3184 - 3185 - for (ln = 0; ln < 2; ln++) { 3186 - if (INTEL_GEN(dev_priv) >= 12) { 3187 - I915_WRITE(HIP_INDEX_REG(tc_port), HIP_INDEX_VAL(tc_port, ln)); 3188 - val = I915_READ(DKL_DP_MODE(tc_port)); 3189 - } else { 3190 - val = I915_READ(MG_DP_MODE(ln, tc_port)); 3191 - } 3192 - 3193 - if (enable) 3194 - val |= bits; 3195 - else 3196 - val &= ~bits; 3197 - 3198 - if (INTEL_GEN(dev_priv) >= 12) 3199 - I915_WRITE(DKL_DP_MODE(tc_port), val); 3200 - else 3201 - I915_WRITE(MG_DP_MODE(ln, tc_port), val); 3202 - } 3203 - 3204 - if (INTEL_GEN(dev_priv) == 11) { 3205 - bits = MG_MISC_SUS0_CFG_TR2PWR_GATING | 3206 - MG_MISC_SUS0_CFG_CL2PWR_GATING | 3207 - MG_MISC_SUS0_CFG_GAONPWR_GATING | 3208 - MG_MISC_SUS0_CFG_TRPWR_GATING | 3209 - MG_MISC_SUS0_CFG_CL1PWR_GATING | 3210 - MG_MISC_SUS0_CFG_DGPWR_GATING; 3211 - 3212 - val = I915_READ(MG_MISC_SUS0(tc_port)); 3213 - if (enable) 3214 - val |= (bits | MG_MISC_SUS0_SUSCLK_DYNCLKGATE_MODE(3)); 3215 - else 3216 - val &= ~(bits | MG_MISC_SUS0_SUSCLK_DYNCLKGATE_MODE_MASK); 3217 - I915_WRITE(MG_MISC_SUS0(tc_port), val); 3218 - } 3219 - } 3220 - 3221 - static void 3222 3164 icl_program_mg_dp_mode(struct intel_digital_port *intel_dig_port, 3223 3165 const struct intel_crtc_state *crtc_state) 3224 3166 { ··· 3273 3317 if (!crtc_state->fec_enable) 3274 3318 return; 3275 3319 3276 - intel_dp = enc_to_intel_dp(&encoder->base); 3320 + intel_dp = enc_to_intel_dp(encoder); 3277 3321 val = I915_READ(intel_dp->regs.dp_tp_ctl); 3278 3322 val |= DP_TP_CTL_FEC_ENABLE; 3279 3323 I915_WRITE(intel_dp->regs.dp_tp_ctl, val); ··· 3293 3337 if (!crtc_state->fec_enable) 3294 3338 return; 3295 3339 3296 - intel_dp = enc_to_intel_dp(&encoder->base); 3340 + intel_dp = enc_to_intel_dp(encoder); 3297 3341 val = I915_READ(intel_dp->regs.dp_tp_ctl); 3298 3342 val &= ~DP_TP_CTL_FEC_ENABLE; 3299 3343 I915_WRITE(intel_dp->regs.dp_tp_ctl, val); ··· 3384 3428 const struct intel_crtc_state *crtc_state, 3385 3429 const struct drm_connector_state *conn_state) 3386 3430 { 3387 - struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base); 3431 + struct intel_dp *intel_dp = enc_to_intel_dp(encoder); 3388 3432 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 3389 3433 enum phy phy = intel_port_to_phy(dev_priv, encoder->port); 3390 - struct intel_digital_port *dig_port = enc_to_dig_port(&encoder->base); 3434 + struct intel_digital_port *dig_port = enc_to_dig_port(encoder); 3391 3435 bool is_mst = intel_crtc_has_type(crtc_state, INTEL_OUTPUT_DP_MST); 3392 3436 int level = intel_ddi_dp_level(intel_dp); 3393 3437 enum transcoder transcoder = crtc_state->cpu_transcoder; ··· 3414 3458 * (DFLEXDPSP.DPX4TXLATC) 3415 3459 * 3416 3460 * This was done before tgl_ddi_pre_enable_dp by 3417 - * haswell_crtc_enable()->intel_encoders_pre_pll_enable(). 3461 + * hsw_crtc_enable()->intel_encoders_pre_pll_enable(). 3418 3462 */ 3419 3463 3420 3464 /* 3421 3465 * 4. Enable the port PLL. 3422 3466 * 3423 3467 * The PLL enabling itself was already done before this function by 3424 - * haswell_crtc_enable()->intel_enable_shared_dpll(). We need only 3468 + * hsw_crtc_enable()->intel_enable_shared_dpll(). We need only 3425 3469 * configure the PLL to port mapping here. 3426 3470 */ 3427 3471 intel_ddi_clk_select(encoder, crtc_state); ··· 3464 3508 * This will be handled by the intel_dp_start_link_train() farther 3465 3509 * down this function. 3466 3510 */ 3467 - 3468 - /* 3469 - * 7.d Type C with DP alternate or fixed/legacy/static connection - 3470 - * Disable PHY clock gating per Type-C DDI Buffer page 3471 - */ 3472 - icl_phy_set_clock_gating(dig_port, false); 3473 3511 3474 3512 /* 7.e Configure voltage swing and related IO settings */ 3475 3513 tgl_ddi_vswing_sequence(encoder, crtc_state->port_clock, level, ··· 3516 3566 if (!is_trans_port_sync_mode(crtc_state)) 3517 3567 intel_dp_stop_link_train(intel_dp); 3518 3568 3519 - /* 3520 - * TODO: enable clock gating 3521 - * 3522 - * It is not written in DP enabling sequence but "PHY Clockgating 3523 - * programming" states that clock gating should be enabled after the 3524 - * link training but doing so causes all the following trainings to fail 3525 - * so not enabling it for now. 3526 - */ 3527 - 3528 3569 /* 7.l Configure and enable FEC if needed */ 3529 3570 intel_ddi_enable_fec(encoder, crtc_state); 3530 3571 intel_dsc_enable(encoder, crtc_state); ··· 3525 3584 const struct intel_crtc_state *crtc_state, 3526 3585 const struct drm_connector_state *conn_state) 3527 3586 { 3528 - struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base); 3587 + struct intel_dp *intel_dp = enc_to_intel_dp(encoder); 3529 3588 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 3530 3589 enum port port = encoder->port; 3531 3590 enum phy phy = intel_port_to_phy(dev_priv, port); 3532 - struct intel_digital_port *dig_port = enc_to_dig_port(&encoder->base); 3591 + struct intel_digital_port *dig_port = enc_to_dig_port(encoder); 3533 3592 bool is_mst = intel_crtc_has_type(crtc_state, INTEL_OUTPUT_DP_MST); 3534 3593 int level = intel_ddi_dp_level(intel_dp); 3535 3594 3536 - WARN_ON(is_mst && (port == PORT_A || port == PORT_E)); 3595 + if (INTEL_GEN(dev_priv) < 11) 3596 + WARN_ON(is_mst && (port == PORT_A || port == PORT_E)); 3597 + else 3598 + WARN_ON(is_mst && port == PORT_A); 3537 3599 3538 3600 intel_dp_set_link_params(intel_dp, crtc_state->port_clock, 3539 3601 crtc_state->lane_count, is_mst); ··· 3554 3610 dig_port->ddi_io_power_domain); 3555 3611 3556 3612 icl_program_mg_dp_mode(dig_port, crtc_state); 3557 - icl_phy_set_clock_gating(dig_port, false); 3558 3613 3559 3614 if (INTEL_GEN(dev_priv) >= 11) 3560 3615 icl_ddi_vswing_sequence(encoder, crtc_state->port_clock, ··· 3587 3644 3588 3645 intel_ddi_enable_fec(encoder, crtc_state); 3589 3646 3590 - icl_phy_set_clock_gating(dig_port, true); 3591 - 3592 3647 if (!is_mst) 3593 3648 intel_ddi_enable_pipe_clock(crtc_state); 3594 3649 ··· 3615 3674 const struct intel_crtc_state *crtc_state, 3616 3675 const struct drm_connector_state *conn_state) 3617 3676 { 3618 - struct intel_digital_port *intel_dig_port = enc_to_dig_port(&encoder->base); 3677 + struct intel_digital_port *intel_dig_port = enc_to_dig_port(encoder); 3619 3678 struct intel_hdmi *intel_hdmi = &intel_dig_port->hdmi; 3620 3679 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 3621 3680 enum port port = encoder->port; 3622 3681 int level = intel_ddi_hdmi_level(dev_priv, port); 3623 - struct intel_digital_port *dig_port = enc_to_dig_port(&encoder->base); 3682 + struct intel_digital_port *dig_port = enc_to_dig_port(encoder); 3624 3683 3625 3684 intel_dp_dual_mode_set_tmds_output(intel_hdmi, true); 3626 3685 intel_ddi_clk_select(encoder, crtc_state); ··· 3628 3687 intel_display_power_get(dev_priv, dig_port->ddi_io_power_domain); 3629 3688 3630 3689 icl_program_mg_dp_mode(dig_port, crtc_state); 3631 - icl_phy_set_clock_gating(dig_port, false); 3632 3690 3633 3691 if (INTEL_GEN(dev_priv) >= 12) 3634 3692 tgl_ddi_vswing_sequence(encoder, crtc_state->port_clock, ··· 3641 3701 bxt_ddi_vswing_sequence(encoder, level, INTEL_OUTPUT_HDMI); 3642 3702 else 3643 3703 intel_prepare_hdmi_ddi_buffers(encoder, level); 3644 - 3645 - icl_phy_set_clock_gating(dig_port, true); 3646 3704 3647 3705 if (IS_GEN9_BC(dev_priv)) 3648 3706 skl_ddi_set_iboost(encoder, level, INTEL_OUTPUT_HDMI); ··· 3684 3746 intel_ddi_pre_enable_hdmi(encoder, crtc_state, conn_state); 3685 3747 } else { 3686 3748 struct intel_lspcon *lspcon = 3687 - enc_to_intel_lspcon(&encoder->base); 3749 + enc_to_intel_lspcon(encoder); 3688 3750 3689 3751 intel_ddi_pre_enable_dp(encoder, crtc_state, conn_state); 3690 3752 if (lspcon->active) { 3691 3753 struct intel_digital_port *dig_port = 3692 - enc_to_dig_port(&encoder->base); 3754 + enc_to_dig_port(encoder); 3693 3755 3694 3756 dig_port->set_infoframes(encoder, 3695 3757 crtc_state->has_infoframe, ··· 3714 3776 } 3715 3777 3716 3778 if (intel_crtc_has_dp_encoder(crtc_state)) { 3717 - struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base); 3779 + struct intel_dp *intel_dp = enc_to_intel_dp(encoder); 3718 3780 3719 3781 val = I915_READ(intel_dp->regs.dp_tp_ctl); 3720 3782 val &= ~(DP_TP_CTL_ENABLE | DP_TP_CTL_LINK_TRAIN_MASK); ··· 3734 3796 const struct drm_connector_state *old_conn_state) 3735 3797 { 3736 3798 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 3737 - struct intel_digital_port *dig_port = enc_to_dig_port(&encoder->base); 3799 + struct intel_digital_port *dig_port = enc_to_dig_port(encoder); 3738 3800 struct intel_dp *intel_dp = &dig_port->dp; 3739 3801 bool is_mst = intel_crtc_has_type(old_crtc_state, 3740 3802 INTEL_OUTPUT_DP_MST); ··· 3746 3808 */ 3747 3809 intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_OFF); 3748 3810 3749 - if (INTEL_GEN(dev_priv) < 12 && !is_mst) 3750 - intel_ddi_disable_pipe_clock(old_crtc_state); 3811 + if (INTEL_GEN(dev_priv) >= 12) { 3812 + if (is_mst) { 3813 + enum transcoder cpu_transcoder = old_crtc_state->cpu_transcoder; 3814 + u32 val; 3815 + 3816 + val = I915_READ(TRANS_DDI_FUNC_CTL(cpu_transcoder)); 3817 + val &= ~TGL_TRANS_DDI_PORT_MASK; 3818 + I915_WRITE(TRANS_DDI_FUNC_CTL(cpu_transcoder), val); 3819 + } 3820 + } else { 3821 + if (!is_mst) 3822 + intel_ddi_disable_pipe_clock(old_crtc_state); 3823 + } 3751 3824 3752 3825 intel_disable_ddi_buf(encoder, old_crtc_state); 3753 3826 ··· 3787 3838 const struct drm_connector_state *old_conn_state) 3788 3839 { 3789 3840 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 3790 - struct intel_digital_port *dig_port = enc_to_dig_port(&encoder->base); 3841 + struct intel_digital_port *dig_port = enc_to_dig_port(encoder); 3791 3842 struct intel_hdmi *intel_hdmi = &dig_port->hdmi; 3792 3843 3793 3844 dig_port->set_infoframes(encoder, false, ··· 3809 3860 { 3810 3861 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->uapi.crtc); 3811 3862 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); 3812 - i915_reg_t reg; 3813 - u32 trans_ddi_func_ctl2_val; 3814 3863 3815 3864 if (old_crtc_state->master_transcoder == INVALID_TRANSCODER) 3816 3865 return; ··· 3816 3869 DRM_DEBUG_KMS("Disabling Transcoder Port Sync on Slave Transcoder %s\n", 3817 3870 transcoder_name(old_crtc_state->cpu_transcoder)); 3818 3871 3819 - reg = TRANS_DDI_FUNC_CTL2(old_crtc_state->cpu_transcoder); 3820 - trans_ddi_func_ctl2_val = ~(PORT_SYNC_MODE_ENABLE | 3821 - PORT_SYNC_MODE_MASTER_SELECT_MASK); 3822 - I915_WRITE(reg, trans_ddi_func_ctl2_val); 3872 + I915_WRITE(TRANS_DDI_FUNC_CTL2(old_crtc_state->cpu_transcoder), 0); 3823 3873 } 3824 3874 3825 3875 static void intel_ddi_post_disable(struct intel_encoder *encoder, ··· 3824 3880 const struct drm_connector_state *old_conn_state) 3825 3881 { 3826 3882 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 3827 - struct intel_digital_port *dig_port = enc_to_dig_port(&encoder->base); 3883 + struct intel_digital_port *dig_port = enc_to_dig_port(encoder); 3828 3884 enum phy phy = intel_port_to_phy(dev_priv, encoder->port); 3829 3885 bool is_tc_port = intel_phy_is_tc(dev_priv, phy); 3830 3886 3831 - intel_crtc_vblank_off(old_crtc_state); 3887 + if (!intel_crtc_has_type(old_crtc_state, INTEL_OUTPUT_DP_MST)) { 3888 + intel_crtc_vblank_off(old_crtc_state); 3832 3889 3833 - intel_disable_pipe(old_crtc_state); 3890 + intel_disable_pipe(old_crtc_state); 3834 3891 3835 - if (INTEL_GEN(dev_priv) >= 11) 3836 - icl_disable_transcoder_port_sync(old_crtc_state); 3892 + if (INTEL_GEN(dev_priv) >= 11) 3893 + icl_disable_transcoder_port_sync(old_crtc_state); 3837 3894 3838 - intel_ddi_disable_transcoder_func(old_crtc_state); 3895 + intel_ddi_disable_transcoder_func(old_crtc_state); 3839 3896 3840 - intel_dsc_disable(old_crtc_state); 3897 + intel_dsc_disable(old_crtc_state); 3841 3898 3842 - if (INTEL_GEN(dev_priv) >= 9) 3843 - skylake_scaler_disable(old_crtc_state); 3844 - else 3845 - ironlake_pfit_disable(old_crtc_state); 3899 + if (INTEL_GEN(dev_priv) >= 9) 3900 + skl_scaler_disable(old_crtc_state); 3901 + else 3902 + ilk_pfit_disable(old_crtc_state); 3903 + } 3846 3904 3847 3905 /* 3848 3906 * When called from DP MST code: ··· 3916 3970 const struct drm_connector_state *conn_state) 3917 3971 { 3918 3972 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 3919 - struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base); 3973 + struct intel_dp *intel_dp = enc_to_intel_dp(encoder); 3920 3974 enum port port = encoder->port; 3921 3975 3922 3976 if (port == PORT_A && INTEL_GEN(dev_priv) < 9) ··· 3957 4011 const struct drm_connector_state *conn_state) 3958 4012 { 3959 4013 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 3960 - struct intel_digital_port *dig_port = enc_to_dig_port(&encoder->base); 4014 + struct intel_digital_port *dig_port = enc_to_dig_port(encoder); 3961 4015 struct drm_connector *connector = conn_state->connector; 3962 4016 enum port port = encoder->port; 3963 4017 ··· 4034 4088 const struct intel_crtc_state *old_crtc_state, 4035 4089 const struct drm_connector_state *old_conn_state) 4036 4090 { 4037 - struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base); 4091 + struct intel_dp *intel_dp = enc_to_intel_dp(encoder); 4038 4092 4039 4093 intel_dp->link_trained = false; 4040 4094 ··· 4082 4136 const struct intel_crtc_state *crtc_state, 4083 4137 const struct drm_connector_state *conn_state) 4084 4138 { 4085 - struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base); 4139 + struct intel_dp *intel_dp = enc_to_intel_dp(encoder); 4086 4140 4087 4141 intel_ddi_set_dp_msa(crtc_state, conn_state); 4088 4142 ··· 4146 4200 4147 4201 WARN_ON(crtc && crtc->active); 4148 4202 4149 - intel_tc_port_get_link(enc_to_dig_port(&encoder->base), required_lanes); 4203 + intel_tc_port_get_link(enc_to_dig_port(encoder), 4204 + required_lanes); 4150 4205 if (crtc_state && crtc_state->hw.active) 4151 4206 intel_update_active_dpll(state, crtc, encoder); 4152 4207 } ··· 4157 4210 struct intel_encoder *encoder, 4158 4211 struct intel_crtc *crtc) 4159 4212 { 4160 - intel_tc_port_put_link(enc_to_dig_port(&encoder->base)); 4213 + intel_tc_port_put_link(enc_to_dig_port(encoder)); 4161 4214 } 4162 4215 4163 4216 static void ··· 4166 4219 const struct drm_connector_state *conn_state) 4167 4220 { 4168 4221 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 4169 - struct intel_digital_port *dig_port = enc_to_dig_port(&encoder->base); 4222 + struct intel_digital_port *dig_port = enc_to_dig_port(encoder); 4170 4223 enum phy phy = intel_port_to_phy(dev_priv, encoder->port); 4171 4224 bool is_tc_port = intel_phy_is_tc(dev_priv, phy); 4172 4225 ··· 4352 4405 pipe_config->output_types |= BIT(INTEL_OUTPUT_DP_MST); 4353 4406 pipe_config->lane_count = 4354 4407 ((temp & DDI_PORT_WIDTH_MASK) >> DDI_PORT_WIDTH_SHIFT) + 1; 4408 + 4409 + if (INTEL_GEN(dev_priv) >= 12) 4410 + pipe_config->mst_master_transcoder = 4411 + REG_FIELD_GET(TRANS_DDI_MST_TRANSPORT_SELECT_MASK, temp); 4412 + 4355 4413 intel_dp_get_m_n(intel_crtc, pipe_config); 4356 4414 break; 4357 4415 default: ··· 4470 4518 4471 4519 static void intel_ddi_encoder_destroy(struct drm_encoder *encoder) 4472 4520 { 4473 - struct intel_digital_port *dig_port = enc_to_dig_port(encoder); 4521 + struct intel_digital_port *dig_port = enc_to_dig_port(to_intel_encoder(encoder)); 4474 4522 4475 4523 intel_dp_encoder_flush_work(encoder); 4476 4524 ··· 4537 4585 struct drm_modeset_acquire_ctx *ctx) 4538 4586 { 4539 4587 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 4540 - struct intel_hdmi *hdmi = enc_to_intel_hdmi(&encoder->base); 4588 + struct intel_hdmi *hdmi = enc_to_intel_hdmi(encoder); 4541 4589 struct intel_connector *connector = hdmi->attached_connector; 4542 4590 struct i2c_adapter *adapter = 4543 4591 intel_gmbus_get_adapter(dev_priv, hdmi->ddc_bus); ··· 4609 4657 struct intel_connector *connector, 4610 4658 bool irq_received) 4611 4659 { 4612 - struct intel_digital_port *dig_port = enc_to_dig_port(&encoder->base); 4660 + struct intel_digital_port *dig_port = enc_to_dig_port(encoder); 4613 4661 struct drm_modeset_acquire_ctx ctx; 4614 4662 enum intel_hotplug_state state; 4615 4663 int ret;
+746 -342
drivers/gpu/drm/i915/display/intel_display.c
··· 46 46 #include "display/intel_crt.h" 47 47 #include "display/intel_ddi.h" 48 48 #include "display/intel_dp.h" 49 + #include "display/intel_dp_mst.h" 49 50 #include "display/intel_dsi.h" 50 51 #include "display/intel_dvo.h" 51 52 #include "display/intel_gmbus.h" ··· 146 145 147 146 static void i9xx_crtc_clock_get(struct intel_crtc *crtc, 148 147 struct intel_crtc_state *pipe_config); 149 - static void ironlake_pch_clock_get(struct intel_crtc *crtc, 150 - struct intel_crtc_state *pipe_config); 148 + static void ilk_pch_clock_get(struct intel_crtc *crtc, 149 + struct intel_crtc_state *pipe_config); 151 150 152 151 static int intel_framebuffer_init(struct intel_framebuffer *ifb, 153 152 struct drm_i915_gem_object *obj, ··· 158 157 const struct intel_link_m_n *m_n, 159 158 const struct intel_link_m_n *m2_n2); 160 159 static void i9xx_set_pipeconf(const struct intel_crtc_state *crtc_state); 161 - static void ironlake_set_pipeconf(const struct intel_crtc_state *crtc_state); 162 - static void haswell_set_pipeconf(const struct intel_crtc_state *crtc_state); 160 + static void ilk_set_pipeconf(const struct intel_crtc_state *crtc_state); 161 + static void hsw_set_pipeconf(const struct intel_crtc_state *crtc_state); 163 162 static void bdw_set_pipemisc(const struct intel_crtc_state *crtc_state); 164 163 static void vlv_prepare_pll(struct intel_crtc *crtc, 165 164 const struct intel_crtc_state *pipe_config); 166 165 static void chv_prepare_pll(struct intel_crtc *crtc, 167 166 const struct intel_crtc_state *pipe_config); 168 - static void skylake_pfit_enable(const struct intel_crtc_state *crtc_state); 169 - static void ironlake_pfit_enable(const struct intel_crtc_state *crtc_state); 167 + static void skl_pfit_enable(const struct intel_crtc_state *crtc_state); 168 + static void ilk_pfit_enable(const struct intel_crtc_state *crtc_state); 170 169 static void intel_modeset_setup_hw_state(struct drm_device *dev, 171 170 struct drm_modeset_acquire_ctx *ctx); 172 171 static struct intel_crtc_state *intel_crtc_state_alloc(struct intel_crtc *crtc); ··· 370 369 }, 371 370 }; 372 371 373 - static const struct intel_limit intel_limits_pineview_sdvo = { 372 + static const struct intel_limit pnv_limits_sdvo = { 374 373 .dot = { .min = 20000, .max = 400000}, 375 374 .vco = { .min = 1700000, .max = 3500000 }, 376 375 /* Pineview's Ncounter is a ring counter */ ··· 385 384 .p2_slow = 10, .p2_fast = 5 }, 386 385 }; 387 386 388 - static const struct intel_limit intel_limits_pineview_lvds = { 387 + static const struct intel_limit pnv_limits_lvds = { 389 388 .dot = { .min = 20000, .max = 400000 }, 390 389 .vco = { .min = 1700000, .max = 3500000 }, 391 390 .n = { .min = 3, .max = 6 }, ··· 403 402 * We calculate clock using (register_value + 2) for N/M1/M2, so here 404 403 * the range value for them is (actual_value - 2). 405 404 */ 406 - static const struct intel_limit intel_limits_ironlake_dac = { 405 + static const struct intel_limit ilk_limits_dac = { 407 406 .dot = { .min = 25000, .max = 350000 }, 408 407 .vco = { .min = 1760000, .max = 3510000 }, 409 408 .n = { .min = 1, .max = 5 }, ··· 416 415 .p2_slow = 10, .p2_fast = 5 }, 417 416 }; 418 417 419 - static const struct intel_limit intel_limits_ironlake_single_lvds = { 418 + static const struct intel_limit ilk_limits_single_lvds = { 420 419 .dot = { .min = 25000, .max = 350000 }, 421 420 .vco = { .min = 1760000, .max = 3510000 }, 422 421 .n = { .min = 1, .max = 3 }, ··· 429 428 .p2_slow = 14, .p2_fast = 14 }, 430 429 }; 431 430 432 - static const struct intel_limit intel_limits_ironlake_dual_lvds = { 431 + static const struct intel_limit ilk_limits_dual_lvds = { 433 432 .dot = { .min = 25000, .max = 350000 }, 434 433 .vco = { .min = 1760000, .max = 3510000 }, 435 434 .n = { .min = 1, .max = 3 }, ··· 443 442 }; 444 443 445 444 /* LVDS 100mhz refclk limits. */ 446 - static const struct intel_limit intel_limits_ironlake_single_lvds_100m = { 445 + static const struct intel_limit ilk_limits_single_lvds_100m = { 447 446 .dot = { .min = 25000, .max = 350000 }, 448 447 .vco = { .min = 1760000, .max = 3510000 }, 449 448 .n = { .min = 1, .max = 2 }, ··· 456 455 .p2_slow = 14, .p2_fast = 14 }, 457 456 }; 458 457 459 - static const struct intel_limit intel_limits_ironlake_dual_lvds_100m = { 458 + static const struct intel_limit ilk_limits_dual_lvds_100m = { 460 459 .dot = { .min = 25000, .max = 350000 }, 461 460 .vco = { .min = 1760000, .max = 3510000 }, 462 461 .n = { .min = 1, .max = 3 }, ··· 550 549 is_trans_port_sync_mode(const struct intel_crtc_state *crtc_state) 551 550 { 552 551 return (crtc_state->master_transcoder != INVALID_TRANSCODER || 553 - crtc_state->sync_mode_slaves_mask); 554 - } 555 - 556 - static bool 557 - is_trans_port_sync_master(const struct intel_crtc_state *crtc_state) 558 - { 559 - return (crtc_state->master_transcoder == INVALID_TRANSCODER && 560 552 crtc_state->sync_mode_slaves_mask); 561 553 } 562 554 ··· 1631 1637 I915_READ(dpll_reg) & port_mask, expected_mask); 1632 1638 } 1633 1639 1634 - static void ironlake_enable_pch_transcoder(const struct intel_crtc_state *crtc_state) 1640 + static void ilk_enable_pch_transcoder(const struct intel_crtc_state *crtc_state) 1635 1641 { 1636 1642 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc); 1637 1643 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); ··· 1729 1735 DRM_ERROR("Failed to enable PCH transcoder\n"); 1730 1736 } 1731 1737 1732 - static void ironlake_disable_pch_transcoder(struct drm_i915_private *dev_priv, 1733 - enum pipe pipe) 1738 + static void ilk_disable_pch_transcoder(struct drm_i915_private *dev_priv, 1739 + enum pipe pipe) 1734 1740 { 1735 1741 i915_reg_t reg; 1736 1742 u32 val; ··· 1938 1944 1939 1945 static bool is_gen12_ccs_modifier(u64 modifier) 1940 1946 { 1941 - return modifier == I915_FORMAT_MOD_Y_TILED_GEN12_RC_CCS; 1947 + return modifier == I915_FORMAT_MOD_Y_TILED_GEN12_RC_CCS || 1948 + modifier == I915_FORMAT_MOD_Y_TILED_GEN12_MC_CCS; 1949 + 1942 1950 } 1943 1951 1944 1952 static bool is_gen12_ccs_plane(const struct drm_framebuffer *fb, int plane) ··· 1973 1977 } 1974 1978 1975 1979 /* Return either the main plane's CCS or - if not a CCS FB - UV plane */ 1976 - static int 1977 - intel_main_to_aux_plane(const struct drm_framebuffer *fb, int main_plane) 1980 + int intel_main_to_aux_plane(const struct drm_framebuffer *fb, int main_plane) 1978 1981 { 1979 1982 if (is_ccs_modifier(fb->modifier)) 1980 1983 return main_to_ccs_plane(fb, main_plane); ··· 1987 1992 { 1988 1993 return info->is_yuv && 1989 1994 info->num_planes == (is_ccs_modifier(modifier) ? 4 : 2); 1995 + } 1996 + 1997 + static bool is_semiplanar_uv_plane(const struct drm_framebuffer *fb, 1998 + int color_plane) 1999 + { 2000 + return intel_format_info_is_yuv_semiplanar(fb->format, fb->modifier) && 2001 + color_plane == 1; 1990 2002 } 1991 2003 1992 2004 static unsigned int ··· 2015 2013 return 128; 2016 2014 /* fall through */ 2017 2015 case I915_FORMAT_MOD_Y_TILED_GEN12_RC_CCS: 2016 + case I915_FORMAT_MOD_Y_TILED_GEN12_MC_CCS: 2018 2017 if (is_ccs_plane(fb, color_plane)) 2019 2018 return 64; 2020 2019 /* fall through */ ··· 2069 2066 2070 2067 *tile_width = tile_width_bytes / cpp; 2071 2068 *tile_height = intel_tile_height(fb, color_plane); 2069 + } 2070 + 2071 + static unsigned int intel_tile_row_size(const struct drm_framebuffer *fb, 2072 + int color_plane) 2073 + { 2074 + unsigned int tile_width, tile_height; 2075 + 2076 + intel_tile_dims(fb, color_plane, &tile_width, &tile_height); 2077 + 2078 + return fb->pitches[color_plane] * tile_height; 2072 2079 } 2073 2080 2074 2081 unsigned int ··· 2155 2142 struct drm_i915_private *dev_priv = to_i915(fb->dev); 2156 2143 2157 2144 /* AUX_DIST needs only 4K alignment */ 2158 - if (is_aux_plane(fb, color_plane)) 2145 + if ((INTEL_GEN(dev_priv) < 12 && is_aux_plane(fb, color_plane)) || 2146 + is_ccs_plane(fb, color_plane)) 2159 2147 return 4096; 2160 2148 2161 2149 switch (fb->modifier) { ··· 2166 2152 if (INTEL_GEN(dev_priv) >= 9) 2167 2153 return 256 * 1024; 2168 2154 return 0; 2155 + case I915_FORMAT_MOD_Y_TILED_GEN12_MC_CCS: 2156 + if (is_semiplanar_uv_plane(fb, color_plane)) 2157 + return intel_tile_row_size(fb, color_plane); 2158 + /* Fall-through */ 2169 2159 case I915_FORMAT_MOD_Y_TILED_GEN12_RC_CCS: 2170 2160 return 16 * 1024; 2171 2161 case I915_FORMAT_MOD_Y_TILED_CCS: 2172 2162 case I915_FORMAT_MOD_Yf_TILED_CCS: 2173 2163 case I915_FORMAT_MOD_Y_TILED: 2164 + if (INTEL_GEN(dev_priv) >= 12 && 2165 + is_semiplanar_uv_plane(fb, color_plane)) 2166 + return intel_tile_row_size(fb, color_plane); 2167 + /* Fall-through */ 2174 2168 case I915_FORMAT_MOD_Yf_TILED: 2175 2169 return 1 * 1024 * 1024; 2176 2170 default: ··· 2215 2193 return ERR_PTR(-EINVAL); 2216 2194 2217 2195 alignment = intel_surf_alignment(fb, 0); 2196 + if (WARN_ON(alignment && !is_power_of_2(alignment))) 2197 + return ERR_PTR(-EINVAL); 2218 2198 2219 2199 /* Note that the w/a also requires 64 PTE of padding following the 2220 2200 * bo. We currently fill all unused PTE with the shadow page and so ··· 2455 2431 unsigned int cpp = fb->format->cpp[color_plane]; 2456 2432 u32 offset, offset_aligned; 2457 2433 2458 - if (alignment) 2459 - alignment--; 2460 - 2461 2434 if (!is_surface_linear(fb, color_plane)) { 2462 2435 unsigned int tile_size, tile_width, tile_height; 2463 2436 unsigned int tile_rows, tiles, pitch_tiles; ··· 2476 2455 *x %= tile_width; 2477 2456 2478 2457 offset = (tile_rows * pitch_tiles + tiles) * tile_size; 2479 - offset_aligned = offset & ~alignment; 2458 + 2459 + offset_aligned = offset; 2460 + if (alignment) 2461 + offset_aligned = rounddown(offset_aligned, alignment); 2480 2462 2481 2463 intel_adjust_tile_offset(x, y, tile_width, tile_height, 2482 2464 tile_size, pitch_tiles, 2483 2465 offset, offset_aligned); 2484 2466 } else { 2485 2467 offset = *y * pitch + *x * cpp; 2486 - offset_aligned = offset & ~alignment; 2487 - 2488 - *y = (offset & alignment) / pitch; 2489 - *x = ((offset & alignment) - *y * pitch) / cpp; 2468 + offset_aligned = offset; 2469 + if (alignment) { 2470 + offset_aligned = rounddown(offset_aligned, alignment); 2471 + *y = (offset % alignment) / pitch; 2472 + *x = ((offset % alignment) - *y * pitch) / cpp; 2473 + } else { 2474 + *y = *x = 0; 2475 + } 2490 2476 } 2491 2477 2492 2478 return offset_aligned; ··· 2526 2498 { 2527 2499 struct drm_i915_private *dev_priv = to_i915(fb->dev); 2528 2500 unsigned int height; 2501 + u32 alignment; 2529 2502 2530 - if (fb->modifier != DRM_FORMAT_MOD_LINEAR && 2531 - fb->offsets[color_plane] % intel_tile_size(dev_priv)) { 2503 + if (INTEL_GEN(dev_priv) >= 12 && 2504 + is_semiplanar_uv_plane(fb, color_plane)) 2505 + alignment = intel_tile_row_size(fb, color_plane); 2506 + else if (fb->modifier != DRM_FORMAT_MOD_LINEAR) 2507 + alignment = intel_tile_size(dev_priv); 2508 + else 2509 + alignment = 0; 2510 + 2511 + if (alignment != 0 && fb->offsets[color_plane] % alignment) { 2532 2512 DRM_DEBUG_KMS("Misaligned offset 0x%08x for color plane %d\n", 2533 2513 fb->offsets[color_plane], color_plane); 2534 2514 return -EINVAL; ··· 2573 2537 case I915_FORMAT_MOD_Y_TILED: 2574 2538 case I915_FORMAT_MOD_Y_TILED_CCS: 2575 2539 case I915_FORMAT_MOD_Y_TILED_GEN12_RC_CCS: 2540 + case I915_FORMAT_MOD_Y_TILED_GEN12_MC_CCS: 2576 2541 return I915_TILING_Y; 2577 2542 default: 2578 2543 return I915_TILING_NONE; ··· 2625 2588 { .format = DRM_FORMAT_ABGR8888, .depth = 32, .num_planes = 2, 2626 2589 .char_per_block = { 4, 1 }, .block_w = { 1, 2 }, .block_h = { 1, 1 }, 2627 2590 .hsub = 1, .vsub = 1, .has_alpha = true }, 2591 + { .format = DRM_FORMAT_YUYV, .num_planes = 2, 2592 + .char_per_block = { 2, 1 }, .block_w = { 1, 2 }, .block_h = { 1, 1 }, 2593 + .hsub = 2, .vsub = 1, .is_yuv = true }, 2594 + { .format = DRM_FORMAT_YVYU, .num_planes = 2, 2595 + .char_per_block = { 2, 1 }, .block_w = { 1, 2 }, .block_h = { 1, 1 }, 2596 + .hsub = 2, .vsub = 1, .is_yuv = true }, 2597 + { .format = DRM_FORMAT_UYVY, .num_planes = 2, 2598 + .char_per_block = { 2, 1 }, .block_w = { 1, 2 }, .block_h = { 1, 1 }, 2599 + .hsub = 2, .vsub = 1, .is_yuv = true }, 2600 + { .format = DRM_FORMAT_VYUY, .num_planes = 2, 2601 + .char_per_block = { 2, 1 }, .block_w = { 1, 2 }, .block_h = { 1, 1 }, 2602 + .hsub = 2, .vsub = 1, .is_yuv = true }, 2603 + { .format = DRM_FORMAT_NV12, .num_planes = 4, 2604 + .char_per_block = { 1, 2, 1, 1 }, .block_w = { 1, 1, 4, 4 }, .block_h = { 1, 1, 1, 1 }, 2605 + .hsub = 2, .vsub = 2, .is_yuv = true }, 2606 + { .format = DRM_FORMAT_P010, .num_planes = 4, 2607 + .char_per_block = { 2, 4, 1, 1 }, .block_w = { 1, 1, 2, 2 }, .block_h = { 1, 1, 1, 1 }, 2608 + .hsub = 2, .vsub = 2, .is_yuv = true }, 2609 + { .format = DRM_FORMAT_P012, .num_planes = 4, 2610 + .char_per_block = { 2, 4, 1, 1 }, .block_w = { 1, 1, 2, 2 }, .block_h = { 1, 1, 1, 1 }, 2611 + .hsub = 2, .vsub = 2, .is_yuv = true }, 2612 + { .format = DRM_FORMAT_P016, .num_planes = 4, 2613 + .char_per_block = { 2, 4, 1, 1 }, .block_w = { 1, 1, 2, 2 }, .block_h = { 1, 1, 1, 1 }, 2614 + .hsub = 2, .vsub = 2, .is_yuv = true }, 2628 2615 }; 2629 2616 2630 2617 static const struct drm_format_info * ··· 2675 2614 ARRAY_SIZE(skl_ccs_formats), 2676 2615 cmd->pixel_format); 2677 2616 case I915_FORMAT_MOD_Y_TILED_GEN12_RC_CCS: 2617 + case I915_FORMAT_MOD_Y_TILED_GEN12_MC_CCS: 2678 2618 return lookup_format_info(gen12_ccs_formats, 2679 2619 ARRAY_SIZE(gen12_ccs_formats), 2680 2620 cmd->pixel_format); ··· 2687 2625 bool is_ccs_modifier(u64 modifier) 2688 2626 { 2689 2627 return modifier == I915_FORMAT_MOD_Y_TILED_GEN12_RC_CCS || 2628 + modifier == I915_FORMAT_MOD_Y_TILED_GEN12_MC_CCS || 2690 2629 modifier == I915_FORMAT_MOD_Y_TILED_CCS || 2691 2630 modifier == I915_FORMAT_MOD_Yf_TILED_CCS; 2692 2631 } ··· 2761 2698 } 2762 2699 2763 2700 tile_width = intel_tile_width_bytes(fb, color_plane); 2764 - if (is_ccs_modifier(fb->modifier) && color_plane == 0) { 2701 + if (is_ccs_modifier(fb->modifier)) { 2765 2702 /* 2766 2703 * Display WA #0531: skl,bxt,kbl,glk 2767 2704 * ··· 2771 2708 * require the entire fb to accommodate that to avoid 2772 2709 * potential runtime errors at plane configuration time. 2773 2710 */ 2774 - if (IS_GEN(dev_priv, 9) && fb->width > 3840) 2711 + if (IS_GEN(dev_priv, 9) && color_plane == 0 && fb->width > 3840) 2775 2712 tile_width *= 4; 2776 2713 /* 2777 2714 * The main surface pitch must be padded to a multiple of four ··· 2939 2876 static void 2940 2877 intel_fb_plane_dims(int *w, int *h, struct drm_framebuffer *fb, int color_plane) 2941 2878 { 2879 + int main_plane = is_ccs_plane(fb, color_plane) ? 2880 + ccs_to_main_plane(fb, color_plane) : 0; 2881 + int main_hsub, main_vsub; 2942 2882 int hsub, vsub; 2943 2883 2884 + intel_fb_plane_get_subsampling(&main_hsub, &main_vsub, fb, main_plane); 2944 2885 intel_fb_plane_get_subsampling(&hsub, &vsub, fb, color_plane); 2945 - *w = fb->width / hsub; 2946 - *h = fb->height / vsub; 2886 + *w = fb->width / main_hsub / hsub; 2887 + *h = fb->height / main_vsub / vsub; 2947 2888 } 2948 2889 2949 2890 /* ··· 3665 3598 return 5120; 3666 3599 case I915_FORMAT_MOD_Y_TILED_CCS: 3667 3600 case I915_FORMAT_MOD_Yf_TILED_CCS: 3601 + case I915_FORMAT_MOD_Y_TILED_GEN12_MC_CCS: 3668 3602 /* FIXME AUX plane? */ 3669 3603 case I915_FORMAT_MOD_Y_TILED: 3670 3604 case I915_FORMAT_MOD_Yf_TILED: ··· 3724 3656 return 4320; 3725 3657 } 3726 3658 3727 - static bool skl_check_main_ccs_coordinates(struct intel_plane_state *plane_state, 3728 - int main_x, int main_y, u32 main_offset) 3659 + static bool 3660 + skl_check_main_ccs_coordinates(struct intel_plane_state *plane_state, 3661 + int main_x, int main_y, u32 main_offset, 3662 + int ccs_plane) 3729 3663 { 3730 3664 const struct drm_framebuffer *fb = plane_state->hw.fb; 3731 - int ccs_plane = main_to_ccs_plane(fb, 0); 3732 3665 int aux_x = plane_state->color_plane[ccs_plane].x; 3733 3666 int aux_y = plane_state->color_plane[ccs_plane].y; 3734 3667 u32 aux_offset = plane_state->color_plane[ccs_plane].offset; ··· 3806 3737 intel_add_fb_offsets(&x, &y, plane_state, 0); 3807 3738 offset = intel_plane_compute_aligned_offset(&x, &y, plane_state, 0); 3808 3739 alignment = intel_surf_alignment(fb, 0); 3740 + if (WARN_ON(alignment && !is_power_of_2(alignment))) 3741 + return -EINVAL; 3809 3742 3810 3743 /* 3811 3744 * AUX surface offset is specified as the distance from the ··· 3843 3772 * they match with the main surface x/y offsets. 3844 3773 */ 3845 3774 if (is_ccs_modifier(fb->modifier)) { 3846 - while (!skl_check_main_ccs_coordinates(plane_state, x, y, offset)) { 3775 + while (!skl_check_main_ccs_coordinates(plane_state, x, y, 3776 + offset, aux_plane)) { 3847 3777 if (offset == 0) 3848 3778 break; 3849 3779 ··· 3877 3805 { 3878 3806 const struct drm_framebuffer *fb = plane_state->hw.fb; 3879 3807 unsigned int rotation = plane_state->hw.rotation; 3880 - int max_width = skl_max_plane_width(fb, 1, rotation); 3808 + int uv_plane = 1; 3809 + int max_width = skl_max_plane_width(fb, uv_plane, rotation); 3881 3810 int max_height = 4096; 3882 3811 int x = plane_state->uapi.src.x1 >> 17; 3883 3812 int y = plane_state->uapi.src.y1 >> 17; ··· 3886 3813 int h = drm_rect_height(&plane_state->uapi.src) >> 17; 3887 3814 u32 offset; 3888 3815 3889 - intel_add_fb_offsets(&x, &y, plane_state, 1); 3890 - offset = intel_plane_compute_aligned_offset(&x, &y, plane_state, 1); 3816 + intel_add_fb_offsets(&x, &y, plane_state, uv_plane); 3817 + offset = intel_plane_compute_aligned_offset(&x, &y, 3818 + plane_state, uv_plane); 3891 3819 3892 3820 /* FIXME not quite sure how/if these apply to the chroma plane */ 3893 3821 if (w > max_width || h > max_height) { ··· 3897 3823 return -EINVAL; 3898 3824 } 3899 3825 3900 - plane_state->color_plane[1].offset = offset; 3901 - plane_state->color_plane[1].x = x; 3902 - plane_state->color_plane[1].y = y; 3826 + if (is_ccs_modifier(fb->modifier)) { 3827 + int ccs_plane = main_to_ccs_plane(fb, uv_plane); 3828 + int aux_offset = plane_state->color_plane[ccs_plane].offset; 3829 + int alignment = intel_surf_alignment(fb, uv_plane); 3830 + 3831 + if (offset > aux_offset) 3832 + offset = intel_plane_adjust_aligned_offset(&x, &y, 3833 + plane_state, 3834 + uv_plane, 3835 + offset, 3836 + aux_offset & ~(alignment - 1)); 3837 + 3838 + while (!skl_check_main_ccs_coordinates(plane_state, x, y, 3839 + offset, ccs_plane)) { 3840 + if (offset == 0) 3841 + break; 3842 + 3843 + offset = intel_plane_adjust_aligned_offset(&x, &y, 3844 + plane_state, 3845 + uv_plane, 3846 + offset, offset - alignment); 3847 + } 3848 + 3849 + if (x != plane_state->color_plane[ccs_plane].x || 3850 + y != plane_state->color_plane[ccs_plane].y) { 3851 + DRM_DEBUG_KMS("Unable to find suitable display surface offset due to CCS\n"); 3852 + return -EINVAL; 3853 + } 3854 + } 3855 + 3856 + plane_state->color_plane[uv_plane].offset = offset; 3857 + plane_state->color_plane[uv_plane].x = x; 3858 + plane_state->color_plane[uv_plane].y = y; 3903 3859 3904 3860 return 0; 3905 3861 } ··· 3939 3835 const struct drm_framebuffer *fb = plane_state->hw.fb; 3940 3836 int src_x = plane_state->uapi.src.x1 >> 16; 3941 3837 int src_y = plane_state->uapi.src.y1 >> 16; 3942 - int hsub; 3943 - int vsub; 3944 - int x; 3945 - int y; 3946 3838 u32 offset; 3839 + int ccs_plane; 3947 3840 3948 - intel_fb_plane_get_subsampling(&hsub, &vsub, fb, 1); 3949 - x = src_x / hsub; 3950 - y = src_y / vsub; 3951 - intel_add_fb_offsets(&x, &y, plane_state, 1); 3952 - offset = intel_plane_compute_aligned_offset(&x, &y, plane_state, 1); 3841 + for (ccs_plane = 0; ccs_plane < fb->format->num_planes; ccs_plane++) { 3842 + int main_hsub, main_vsub; 3843 + int hsub, vsub; 3844 + int x, y; 3953 3845 3954 - plane_state->color_plane[1].offset = offset; 3955 - plane_state->color_plane[1].x = x * hsub + src_x % hsub; 3956 - plane_state->color_plane[1].y = y * vsub + src_y % vsub; 3846 + if (!is_ccs_plane(fb, ccs_plane)) 3847 + continue; 3848 + 3849 + intel_fb_plane_get_subsampling(&main_hsub, &main_vsub, fb, 3850 + ccs_to_main_plane(fb, ccs_plane)); 3851 + intel_fb_plane_get_subsampling(&hsub, &vsub, fb, ccs_plane); 3852 + 3853 + hsub *= main_hsub; 3854 + vsub *= main_vsub; 3855 + x = src_x / hsub; 3856 + y = src_y / vsub; 3857 + 3858 + intel_add_fb_offsets(&x, &y, plane_state, ccs_plane); 3859 + 3860 + offset = intel_plane_compute_aligned_offset(&x, &y, 3861 + plane_state, 3862 + ccs_plane); 3863 + 3864 + plane_state->color_plane[ccs_plane].offset = offset; 3865 + plane_state->color_plane[ccs_plane].x = (x * hsub + 3866 + src_x % hsub) / 3867 + main_hsub; 3868 + plane_state->color_plane[ccs_plane].y = (y * vsub + 3869 + src_y % vsub) / 3870 + main_vsub; 3871 + } 3957 3872 3958 3873 return 0; 3959 3874 } ··· 3981 3858 { 3982 3859 const struct drm_framebuffer *fb = plane_state->hw.fb; 3983 3860 int ret; 3861 + bool needs_aux = false; 3984 3862 3985 3863 ret = intel_plane_compute_gtt(plane_state); 3986 3864 if (ret) ··· 3991 3867 return 0; 3992 3868 3993 3869 /* 3994 - * Handle the AUX surface first since 3995 - * the main surface setup depends on it. 3870 + * Handle the AUX surface first since the main surface setup depends on 3871 + * it. 3996 3872 */ 3997 - if (intel_format_info_is_yuv_semiplanar(fb->format, 3998 - fb->modifier)) { 3999 - ret = skl_check_nv12_aux_surface(plane_state); 4000 - if (ret) 4001 - return ret; 4002 - } else if (is_ccs_modifier(fb->modifier)) { 3873 + if (is_ccs_modifier(fb->modifier)) { 3874 + needs_aux = true; 4003 3875 ret = skl_check_ccs_aux_surface(plane_state); 4004 3876 if (ret) 4005 3877 return ret; 4006 - } else { 4007 - plane_state->color_plane[1].offset = ~0xfff; 4008 - plane_state->color_plane[1].x = 0; 4009 - plane_state->color_plane[1].y = 0; 3878 + } 3879 + 3880 + if (intel_format_info_is_yuv_semiplanar(fb->format, 3881 + fb->modifier)) { 3882 + needs_aux = true; 3883 + ret = skl_check_nv12_aux_surface(plane_state); 3884 + if (ret) 3885 + return ret; 3886 + } 3887 + 3888 + if (!needs_aux) { 3889 + int i; 3890 + 3891 + for (i = 1; i < fb->format->num_planes; i++) { 3892 + plane_state->color_plane[i].offset = ~0xfff; 3893 + plane_state->color_plane[i].x = 0; 3894 + plane_state->color_plane[i].y = 0; 3895 + } 4010 3896 } 4011 3897 4012 3898 ret = skl_check_main_surface(plane_state); ··· 4606 4472 return PLANE_CTL_TILED_Y | 4607 4473 PLANE_CTL_RENDER_DECOMPRESSION_ENABLE | 4608 4474 PLANE_CTL_CLEAR_COLOR_DISABLE; 4475 + case I915_FORMAT_MOD_Y_TILED_GEN12_MC_CCS: 4476 + return PLANE_CTL_TILED_Y | PLANE_CTL_MEDIA_DECOMPRESSION_ENABLE; 4609 4477 case I915_FORMAT_MOD_Yf_TILED: 4610 4478 return PLANE_CTL_TILED_YF; 4611 4479 case I915_FORMAT_MOD_Yf_TILED_CCS: ··· 5005 4869 } 5006 4870 5007 4871 /* The FDI link training functions for ILK/Ibexpeak. */ 5008 - static void ironlake_fdi_link_train(struct intel_crtc *crtc, 5009 - const struct intel_crtc_state *crtc_state) 4872 + static void ilk_fdi_link_train(struct intel_crtc *crtc, 4873 + const struct intel_crtc_state *crtc_state) 5010 4874 { 5011 4875 struct drm_device *dev = crtc->base.dev; 5012 4876 struct drm_i915_private *dev_priv = to_i915(dev); ··· 5358 5222 DRM_DEBUG_KMS("FDI train done.\n"); 5359 5223 } 5360 5224 5361 - static void ironlake_fdi_pll_enable(const struct intel_crtc_state *crtc_state) 5225 + static void ilk_fdi_pll_enable(const struct intel_crtc_state *crtc_state) 5362 5226 { 5363 5227 struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->uapi.crtc); 5364 5228 struct drm_i915_private *dev_priv = to_i915(intel_crtc->base.dev); ··· 5395 5259 } 5396 5260 } 5397 5261 5398 - static void ironlake_fdi_pll_disable(struct intel_crtc *intel_crtc) 5262 + static void ilk_fdi_pll_disable(struct intel_crtc *intel_crtc) 5399 5263 { 5400 5264 struct drm_device *dev = intel_crtc->base.dev; 5401 5265 struct drm_i915_private *dev_priv = to_i915(dev); ··· 5425 5289 udelay(100); 5426 5290 } 5427 5291 5428 - static void ironlake_fdi_disable(struct intel_crtc *crtc) 5292 + static void ilk_fdi_disable(struct intel_crtc *crtc) 5429 5293 { 5430 5294 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); 5431 5295 enum pipe pipe = crtc->pipe; ··· 5632 5496 desired_divisor << auxdiv); 5633 5497 } 5634 5498 5635 - static void ironlake_pch_transcoder_set_timings(const struct intel_crtc_state *crtc_state, 5636 - enum pipe pch_transcoder) 5499 + static void ilk_pch_transcoder_set_timings(const struct intel_crtc_state *crtc_state, 5500 + enum pipe pch_transcoder) 5637 5501 { 5638 5502 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc); 5639 5503 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); ··· 5676 5540 POSTING_READ(SOUTH_CHICKEN1); 5677 5541 } 5678 5542 5679 - static void ivybridge_update_fdi_bc_bifurcation(const struct intel_crtc_state *crtc_state) 5543 + static void ivb_update_fdi_bc_bifurcation(const struct intel_crtc_state *crtc_state) 5680 5544 { 5681 5545 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc); 5682 5546 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); ··· 5737 5601 * - DP transcoding bits 5738 5602 * - transcoder 5739 5603 */ 5740 - static void ironlake_pch_enable(const struct intel_atomic_state *state, 5741 - const struct intel_crtc_state *crtc_state) 5604 + static void ilk_pch_enable(const struct intel_atomic_state *state, 5605 + const struct intel_crtc_state *crtc_state) 5742 5606 { 5743 5607 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc); 5744 5608 struct drm_device *dev = crtc->base.dev; ··· 5749 5613 assert_pch_transcoder_disabled(dev_priv, pipe); 5750 5614 5751 5615 if (IS_IVYBRIDGE(dev_priv)) 5752 - ivybridge_update_fdi_bc_bifurcation(crtc_state); 5616 + ivb_update_fdi_bc_bifurcation(crtc_state); 5753 5617 5754 5618 /* Write the TU size bits before fdi link training, so that error 5755 5619 * detection works. */ ··· 5786 5650 5787 5651 /* set transcoder timing, panel must allow it */ 5788 5652 assert_panel_unlocked(dev_priv, pipe); 5789 - ironlake_pch_transcoder_set_timings(crtc_state, pipe); 5653 + ilk_pch_transcoder_set_timings(crtc_state, pipe); 5790 5654 5791 5655 intel_fdi_normal_train(crtc); 5792 5656 ··· 5818 5682 I915_WRITE(reg, temp); 5819 5683 } 5820 5684 5821 - ironlake_enable_pch_transcoder(crtc_state); 5685 + ilk_enable_pch_transcoder(crtc_state); 5822 5686 } 5823 5687 5824 5688 static void lpt_pch_enable(const struct intel_atomic_state *state, ··· 5833 5697 lpt_program_iclkip(crtc_state); 5834 5698 5835 5699 /* Set transcoder timing. */ 5836 - ironlake_pch_transcoder_set_timings(crtc_state, PIPE_A); 5700 + ilk_pch_transcoder_set_timings(crtc_state, PIPE_A); 5837 5701 5838 5702 lpt_enable_pch_transcoder(dev_priv, cpu_transcoder); 5839 5703 } ··· 6137 6001 return 0; 6138 6002 } 6139 6003 6140 - void skylake_scaler_disable(const struct intel_crtc_state *old_crtc_state) 6004 + void skl_scaler_disable(const struct intel_crtc_state *old_crtc_state) 6141 6005 { 6142 6006 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->uapi.crtc); 6143 6007 int i; ··· 6146 6010 skl_detach_scaler(crtc, i); 6147 6011 } 6148 6012 6149 - static void skylake_pfit_enable(const struct intel_crtc_state *crtc_state) 6013 + static void skl_pfit_enable(const struct intel_crtc_state *crtc_state) 6150 6014 { 6151 6015 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc); 6152 6016 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); ··· 6183 6047 } 6184 6048 } 6185 6049 6186 - static void ironlake_pfit_enable(const struct intel_crtc_state *crtc_state) 6050 + static void ilk_pfit_enable(const struct intel_crtc_state *crtc_state) 6187 6051 { 6188 6052 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc); 6189 6053 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); ··· 6547 6411 if (connector->mst_port) 6548 6412 return &dp_to_dig_port(connector->mst_port)->base; 6549 6413 6550 - encoder = intel_attached_encoder(&connector->base); 6414 + encoder = intel_attached_encoder(connector); 6551 6415 WARN_ON(!encoder); 6552 6416 6553 6417 return encoder; 6554 6418 } 6555 6419 6556 - static bool 6557 - intel_connector_needs_modeset(struct intel_atomic_state *state, 6558 - const struct drm_connector_state *old_conn_state, 6559 - const struct drm_connector_state *new_conn_state) 6560 - { 6561 - struct intel_crtc *old_crtc = old_conn_state->crtc ? 6562 - to_intel_crtc(old_conn_state->crtc) : NULL; 6563 - struct intel_crtc *new_crtc = new_conn_state->crtc ? 6564 - to_intel_crtc(new_conn_state->crtc) : NULL; 6565 - 6566 - return new_crtc != old_crtc || 6567 - (new_crtc && 6568 - needs_modeset(intel_atomic_get_new_crtc_state(state, new_crtc))); 6569 - } 6570 - 6571 6420 static void intel_encoders_update_prepare(struct intel_atomic_state *state) 6572 6421 { 6573 - struct drm_connector_state *old_conn_state; 6574 6422 struct drm_connector_state *new_conn_state; 6575 - struct drm_connector *conn; 6423 + struct drm_connector *connector; 6576 6424 int i; 6577 6425 6578 - for_each_oldnew_connector_in_state(&state->base, conn, 6579 - old_conn_state, new_conn_state, i) { 6426 + for_each_new_connector_in_state(&state->base, connector, new_conn_state, 6427 + i) { 6428 + struct intel_connector *intel_connector; 6580 6429 struct intel_encoder *encoder; 6581 6430 struct intel_crtc *crtc; 6582 6431 6583 - if (!intel_connector_needs_modeset(state, 6584 - old_conn_state, 6585 - new_conn_state)) 6432 + if (!intel_connector_needs_modeset(state, connector)) 6586 6433 continue; 6587 6434 6588 - encoder = intel_connector_primary_encoder(to_intel_connector(conn)); 6435 + intel_connector = to_intel_connector(connector); 6436 + encoder = intel_connector_primary_encoder(intel_connector); 6589 6437 if (!encoder->update_prepare) 6590 6438 continue; 6591 6439 ··· 6581 6461 6582 6462 static void intel_encoders_update_complete(struct intel_atomic_state *state) 6583 6463 { 6584 - struct drm_connector_state *old_conn_state; 6585 6464 struct drm_connector_state *new_conn_state; 6586 - struct drm_connector *conn; 6465 + struct drm_connector *connector; 6587 6466 int i; 6588 6467 6589 - for_each_oldnew_connector_in_state(&state->base, conn, 6590 - old_conn_state, new_conn_state, i) { 6468 + for_each_new_connector_in_state(&state->base, connector, new_conn_state, 6469 + i) { 6470 + struct intel_connector *intel_connector; 6591 6471 struct intel_encoder *encoder; 6592 6472 struct intel_crtc *crtc; 6593 6473 6594 - if (!intel_connector_needs_modeset(state, 6595 - old_conn_state, 6596 - new_conn_state)) 6474 + if (!intel_connector_needs_modeset(state, connector)) 6597 6475 continue; 6598 6476 6599 - encoder = intel_connector_primary_encoder(to_intel_connector(conn)); 6477 + intel_connector = to_intel_connector(connector); 6478 + encoder = intel_connector_primary_encoder(intel_connector); 6600 6479 if (!encoder->update_complete) 6601 6480 continue; 6602 6481 ··· 6762 6643 plane->disable_plane(plane, crtc_state); 6763 6644 } 6764 6645 6765 - static void ironlake_crtc_enable(struct intel_atomic_state *state, 6766 - struct intel_crtc *crtc) 6646 + static void ilk_crtc_enable(struct intel_atomic_state *state, 6647 + struct intel_crtc *crtc) 6767 6648 { 6768 6649 const struct intel_crtc_state *new_crtc_state = 6769 6650 intel_atomic_get_new_crtc_state(state, crtc); ··· 6799 6680 intel_cpu_transcoder_set_m_n(new_crtc_state, 6800 6681 &new_crtc_state->fdi_m_n, NULL); 6801 6682 6802 - ironlake_set_pipeconf(new_crtc_state); 6683 + ilk_set_pipeconf(new_crtc_state); 6803 6684 6804 6685 crtc->active = true; 6805 6686 ··· 6809 6690 /* Note: FDI PLL enabling _must_ be done before we enable the 6810 6691 * cpu pipes, hence this is separate from all the other fdi/pch 6811 6692 * enabling. */ 6812 - ironlake_fdi_pll_enable(new_crtc_state); 6693 + ilk_fdi_pll_enable(new_crtc_state); 6813 6694 } else { 6814 6695 assert_fdi_tx_disabled(dev_priv, pipe); 6815 6696 assert_fdi_rx_disabled(dev_priv, pipe); 6816 6697 } 6817 6698 6818 - ironlake_pfit_enable(new_crtc_state); 6699 + ilk_pfit_enable(new_crtc_state); 6819 6700 6820 6701 /* 6821 6702 * On ILK+ LUT must be loaded before the pipe is running but with ··· 6831 6712 intel_enable_pipe(new_crtc_state); 6832 6713 6833 6714 if (new_crtc_state->has_pch_encoder) 6834 - ironlake_pch_enable(state, new_crtc_state); 6715 + ilk_pch_enable(state, new_crtc_state); 6835 6716 6836 6717 intel_crtc_vblank_on(new_crtc_state); 6837 6718 ··· 6906 6787 I915_WRITE(reg, val); 6907 6788 } 6908 6789 6909 - static void haswell_crtc_enable(struct intel_atomic_state *state, 6910 - struct intel_crtc *crtc) 6790 + static void hsw_crtc_enable(struct intel_atomic_state *state, 6791 + struct intel_crtc *crtc) 6911 6792 { 6912 6793 const struct intel_crtc_state *new_crtc_state = 6913 6794 intel_atomic_get_new_crtc_state(state, crtc); ··· 6948 6829 6949 6830 if (!transcoder_is_dsi(cpu_transcoder)) { 6950 6831 hsw_set_frame_start_delay(new_crtc_state); 6951 - haswell_set_pipeconf(new_crtc_state); 6832 + hsw_set_pipeconf(new_crtc_state); 6952 6833 } 6953 6834 6954 6835 if (INTEL_GEN(dev_priv) >= 9 || IS_BROADWELL(dev_priv)) ··· 6963 6844 glk_pipe_scaler_clock_gating_wa(dev_priv, pipe, true); 6964 6845 6965 6846 if (INTEL_GEN(dev_priv) >= 9) 6966 - skylake_pfit_enable(new_crtc_state); 6847 + skl_pfit_enable(new_crtc_state); 6967 6848 else 6968 - ironlake_pfit_enable(new_crtc_state); 6849 + ilk_pfit_enable(new_crtc_state); 6969 6850 6970 6851 /* 6971 6852 * On ILK+ LUT must be loaded before the pipe is running but with ··· 7014 6895 } 7015 6896 } 7016 6897 7017 - void ironlake_pfit_disable(const struct intel_crtc_state *old_crtc_state) 6898 + void ilk_pfit_disable(const struct intel_crtc_state *old_crtc_state) 7018 6899 { 7019 6900 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->uapi.crtc); 7020 6901 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); ··· 7029 6910 } 7030 6911 } 7031 6912 7032 - static void ironlake_crtc_disable(struct intel_atomic_state *state, 7033 - struct intel_crtc *crtc) 6913 + static void ilk_crtc_disable(struct intel_atomic_state *state, 6914 + struct intel_crtc *crtc) 7034 6915 { 7035 6916 const struct intel_crtc_state *old_crtc_state = 7036 6917 intel_atomic_get_old_crtc_state(state, crtc); ··· 7051 6932 7052 6933 intel_disable_pipe(old_crtc_state); 7053 6934 7054 - ironlake_pfit_disable(old_crtc_state); 6935 + ilk_pfit_disable(old_crtc_state); 7055 6936 7056 6937 if (old_crtc_state->has_pch_encoder) 7057 - ironlake_fdi_disable(crtc); 6938 + ilk_fdi_disable(crtc); 7058 6939 7059 6940 intel_encoders_post_disable(state, crtc); 7060 6941 7061 6942 if (old_crtc_state->has_pch_encoder) { 7062 - ironlake_disable_pch_transcoder(dev_priv, pipe); 6943 + ilk_disable_pch_transcoder(dev_priv, pipe); 7063 6944 7064 6945 if (HAS_PCH_CPT(dev_priv)) { 7065 6946 i915_reg_t reg; ··· 7079 6960 I915_WRITE(PCH_DPLL_SEL, temp); 7080 6961 } 7081 6962 7082 - ironlake_fdi_pll_disable(crtc); 6963 + ilk_fdi_pll_disable(crtc); 7083 6964 } 7084 6965 7085 6966 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true); 7086 6967 intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, true); 7087 6968 } 7088 6969 7089 - static void haswell_crtc_disable(struct intel_atomic_state *state, 7090 - struct intel_crtc *crtc) 6970 + static void hsw_crtc_disable(struct intel_atomic_state *state, 6971 + struct intel_crtc *crtc) 7091 6972 { 7092 6973 /* 7093 6974 * FIXME collapse everything to one hook. ··· 7624 7505 return 0; 7625 7506 } 7626 7507 7627 - static int ironlake_check_fdi_lanes(struct drm_device *dev, enum pipe pipe, 7628 - struct intel_crtc_state *pipe_config) 7508 + static int ilk_check_fdi_lanes(struct drm_device *dev, enum pipe pipe, 7509 + struct intel_crtc_state *pipe_config) 7629 7510 { 7630 7511 struct drm_i915_private *dev_priv = to_i915(dev); 7631 7512 struct drm_atomic_state *state = pipe_config->uapi.state; ··· 7697 7578 } 7698 7579 7699 7580 #define RETRY 1 7700 - static int ironlake_fdi_compute_config(struct intel_crtc *intel_crtc, 7701 - struct intel_crtc_state *pipe_config) 7581 + static int ilk_fdi_compute_config(struct intel_crtc *intel_crtc, 7582 + struct intel_crtc_state *pipe_config) 7702 7583 { 7703 7584 struct drm_device *dev = intel_crtc->base.dev; 7704 7585 const struct drm_display_mode *adjusted_mode = &pipe_config->hw.adjusted_mode; ··· 7717 7598 7718 7599 fdi_dotclock = adjusted_mode->crtc_clock; 7719 7600 7720 - lane = ironlake_get_lanes_required(fdi_dotclock, link_bw, 7721 - pipe_config->pipe_bpp); 7601 + lane = ilk_get_lanes_required(fdi_dotclock, link_bw, 7602 + pipe_config->pipe_bpp); 7722 7603 7723 7604 pipe_config->fdi_lanes = lane; 7724 7605 7725 7606 intel_link_compute_m_n(pipe_config->pipe_bpp, lane, fdi_dotclock, 7726 7607 link_bw, &pipe_config->fdi_m_n, false, false); 7727 7608 7728 - ret = ironlake_check_fdi_lanes(dev, intel_crtc->pipe, pipe_config); 7609 + ret = ilk_check_fdi_lanes(dev, intel_crtc->pipe, pipe_config); 7729 7610 if (ret == -EDEADLK) 7730 7611 return ret; 7731 7612 ··· 7931 7812 intel_crtc_compute_pixel_rate(pipe_config); 7932 7813 7933 7814 if (pipe_config->has_pch_encoder) 7934 - return ironlake_fdi_compute_config(crtc, pipe_config); 7815 + return ilk_fdi_compute_config(crtc, pipe_config); 7935 7816 7936 7817 return 0; 7937 7818 } ··· 8914 8795 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk); 8915 8796 } 8916 8797 8917 - limit = &intel_limits_pineview_lvds; 8798 + limit = &pnv_limits_lvds; 8918 8799 } else { 8919 - limit = &intel_limits_pineview_sdvo; 8800 + limit = &pnv_limits_sdvo; 8920 8801 } 8921 8802 8922 8803 if (!crtc_state->clock_set && ··· 9343 9224 return ret; 9344 9225 } 9345 9226 9346 - static void ironlake_init_pch_refclk(struct drm_i915_private *dev_priv) 9227 + static void ilk_init_pch_refclk(struct drm_i915_private *dev_priv) 9347 9228 { 9348 9229 struct intel_encoder *encoder; 9349 9230 int i; ··· 9841 9722 void intel_init_pch_refclk(struct drm_i915_private *dev_priv) 9842 9723 { 9843 9724 if (HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv)) 9844 - ironlake_init_pch_refclk(dev_priv); 9725 + ilk_init_pch_refclk(dev_priv); 9845 9726 else if (HAS_PCH_LPT(dev_priv)) 9846 9727 lpt_init_pch_refclk(dev_priv); 9847 9728 } 9848 9729 9849 - static void ironlake_set_pipeconf(const struct intel_crtc_state *crtc_state) 9730 + static void ilk_set_pipeconf(const struct intel_crtc_state *crtc_state) 9850 9731 { 9851 9732 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc); 9852 9733 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); ··· 9902 9783 POSTING_READ(PIPECONF(pipe)); 9903 9784 } 9904 9785 9905 - static void haswell_set_pipeconf(const struct intel_crtc_state *crtc_state) 9786 + static void hsw_set_pipeconf(const struct intel_crtc_state *crtc_state) 9906 9787 { 9907 9788 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc); 9908 9789 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); ··· 9990 9871 } 9991 9872 } 9992 9873 9993 - int ironlake_get_lanes_required(int target_clock, int link_bw, int bpp) 9874 + int ilk_get_lanes_required(int target_clock, int link_bw, int bpp) 9994 9875 { 9995 9876 /* 9996 9877 * Account for spread spectrum to avoid ··· 10001 9882 return DIV_ROUND_UP(bps, link_bw * 8); 10002 9883 } 10003 9884 10004 - static bool ironlake_needs_fb_cb_tune(struct dpll *dpll, int factor) 9885 + static bool ilk_needs_fb_cb_tune(struct dpll *dpll, int factor) 10005 9886 { 10006 9887 return i9xx_dpll_compute_m(dpll) < factor * dpll->n; 10007 9888 } 10008 9889 10009 - static void ironlake_compute_dpll(struct intel_crtc *crtc, 10010 - struct intel_crtc_state *crtc_state, 10011 - struct dpll *reduced_clock) 9890 + static void ilk_compute_dpll(struct intel_crtc *crtc, 9891 + struct intel_crtc_state *crtc_state, 9892 + struct dpll *reduced_clock) 10012 9893 { 10013 9894 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); 10014 9895 u32 dpll, fp, fp2; ··· 10028 9909 10029 9910 fp = i9xx_dpll_compute_fp(&crtc_state->dpll); 10030 9911 10031 - if (ironlake_needs_fb_cb_tune(&crtc_state->dpll, factor)) 9912 + if (ilk_needs_fb_cb_tune(&crtc_state->dpll, factor)) 10032 9913 fp |= FP_CB_TUNE; 10033 9914 10034 9915 if (reduced_clock) { ··· 10108 9989 crtc_state->dpll_hw_state.fp1 = fp2; 10109 9990 } 10110 9991 10111 - static int ironlake_crtc_compute_clock(struct intel_crtc *crtc, 10112 - struct intel_crtc_state *crtc_state) 9992 + static int ilk_crtc_compute_clock(struct intel_crtc *crtc, 9993 + struct intel_crtc_state *crtc_state) 10113 9994 { 10114 9995 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); 10115 9996 struct intel_atomic_state *state = ··· 10133 10014 10134 10015 if (intel_is_dual_link_lvds(dev_priv)) { 10135 10016 if (refclk == 100000) 10136 - limit = &intel_limits_ironlake_dual_lvds_100m; 10017 + limit = &ilk_limits_dual_lvds_100m; 10137 10018 else 10138 - limit = &intel_limits_ironlake_dual_lvds; 10019 + limit = &ilk_limits_dual_lvds; 10139 10020 } else { 10140 10021 if (refclk == 100000) 10141 - limit = &intel_limits_ironlake_single_lvds_100m; 10022 + limit = &ilk_limits_single_lvds_100m; 10142 10023 else 10143 - limit = &intel_limits_ironlake_single_lvds; 10024 + limit = &ilk_limits_single_lvds; 10144 10025 } 10145 10026 } else { 10146 - limit = &intel_limits_ironlake_dac; 10027 + limit = &ilk_limits_dac; 10147 10028 } 10148 10029 10149 10030 if (!crtc_state->clock_set && ··· 10153 10034 return -EINVAL; 10154 10035 } 10155 10036 10156 - ironlake_compute_dpll(crtc, crtc_state, NULL); 10037 + ilk_compute_dpll(crtc, crtc_state, NULL); 10157 10038 10158 10039 if (!intel_reserve_shared_dplls(state, crtc, NULL)) { 10159 10040 DRM_DEBUG_KMS("failed to find PLL for pipe %c\n", ··· 10228 10109 &pipe_config->dp_m2_n2); 10229 10110 } 10230 10111 10231 - static void ironlake_get_fdi_m_n_config(struct intel_crtc *crtc, 10232 - struct intel_crtc_state *pipe_config) 10112 + static void ilk_get_fdi_m_n_config(struct intel_crtc *crtc, 10113 + struct intel_crtc_state *pipe_config) 10233 10114 { 10234 10115 intel_cpu_transcoder_get_m_n(crtc, pipe_config->cpu_transcoder, 10235 10116 &pipe_config->fdi_m_n, NULL); 10236 10117 } 10237 10118 10238 - static void skylake_get_pfit_config(struct intel_crtc *crtc, 10239 - struct intel_crtc_state *pipe_config) 10119 + static void skl_get_pfit_config(struct intel_crtc *crtc, 10120 + struct intel_crtc_state *pipe_config) 10240 10121 { 10241 10122 struct drm_device *dev = crtc->base.dev; 10242 10123 struct drm_i915_private *dev_priv = to_i915(dev); ··· 10267 10148 } 10268 10149 10269 10150 static void 10270 - skylake_get_initial_plane_config(struct intel_crtc *crtc, 10271 - struct intel_initial_plane_config *plane_config) 10151 + skl_get_initial_plane_config(struct intel_crtc *crtc, 10152 + struct intel_initial_plane_config *plane_config) 10272 10153 { 10273 10154 struct drm_device *dev = crtc->base.dev; 10274 10155 struct drm_i915_private *dev_priv = to_i915(dev); ··· 10329 10210 fb->modifier = INTEL_GEN(dev_priv) >= 12 ? 10330 10211 I915_FORMAT_MOD_Y_TILED_GEN12_RC_CCS : 10331 10212 I915_FORMAT_MOD_Y_TILED_CCS; 10213 + else if (val & PLANE_CTL_MEDIA_DECOMPRESSION_ENABLE) 10214 + fb->modifier = I915_FORMAT_MOD_Y_TILED_GEN12_MC_CCS; 10332 10215 else 10333 10216 fb->modifier = I915_FORMAT_MOD_Y_TILED; 10334 10217 break; ··· 10397 10276 kfree(intel_fb); 10398 10277 } 10399 10278 10400 - static void ironlake_get_pfit_config(struct intel_crtc *crtc, 10401 - struct intel_crtc_state *pipe_config) 10279 + static void ilk_get_pfit_config(struct intel_crtc *crtc, 10280 + struct intel_crtc_state *pipe_config) 10402 10281 { 10403 10282 struct drm_device *dev = crtc->base.dev; 10404 10283 struct drm_i915_private *dev_priv = to_i915(dev); ··· 10421 10300 } 10422 10301 } 10423 10302 10424 - static bool ironlake_get_pipe_config(struct intel_crtc *crtc, 10425 - struct intel_crtc_state *pipe_config) 10303 + static bool ilk_get_pipe_config(struct intel_crtc *crtc, 10304 + struct intel_crtc_state *pipe_config) 10426 10305 { 10427 10306 struct drm_device *dev = crtc->base.dev; 10428 10307 struct drm_i915_private *dev_priv = to_i915(dev); ··· 10493 10372 pipe_config->fdi_lanes = ((FDI_DP_PORT_WIDTH_MASK & tmp) >> 10494 10373 FDI_DP_PORT_WIDTH_SHIFT) + 1; 10495 10374 10496 - ironlake_get_fdi_m_n_config(crtc, pipe_config); 10375 + ilk_get_fdi_m_n_config(crtc, pipe_config); 10497 10376 10498 10377 if (HAS_PCH_IBX(dev_priv)) { 10499 10378 /* ··· 10521 10400 ((tmp & PLL_REF_SDVO_HDMI_MULTIPLIER_MASK) 10522 10401 >> PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT) + 1; 10523 10402 10524 - ironlake_pch_clock_get(crtc, pipe_config); 10403 + ilk_pch_clock_get(crtc, pipe_config); 10525 10404 } else { 10526 10405 pipe_config->pixel_multiplier = 1; 10527 10406 } ··· 10529 10408 intel_get_pipe_timings(crtc, pipe_config); 10530 10409 intel_get_pipe_src_size(crtc, pipe_config); 10531 10410 10532 - ironlake_get_pfit_config(crtc, pipe_config); 10411 + ilk_get_pfit_config(crtc, pipe_config); 10533 10412 10534 10413 ret = true; 10535 10414 ··· 10538 10417 10539 10418 return ret; 10540 10419 } 10541 - static int haswell_crtc_compute_clock(struct intel_crtc *crtc, 10542 - struct intel_crtc_state *crtc_state) 10420 + 10421 + static int hsw_crtc_compute_clock(struct intel_crtc *crtc, 10422 + struct intel_crtc_state *crtc_state) 10543 10423 { 10544 10424 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); 10545 10425 struct intel_atomic_state *state = ··· 10561 10439 return 0; 10562 10440 } 10563 10441 10564 - static void cannonlake_get_ddi_pll(struct drm_i915_private *dev_priv, 10565 - enum port port, 10566 - struct intel_crtc_state *pipe_config) 10442 + static void cnl_get_ddi_pll(struct drm_i915_private *dev_priv, enum port port, 10443 + struct intel_crtc_state *pipe_config) 10567 10444 { 10568 10445 enum intel_dpll_id id; 10569 10446 u32 temp; ··· 10576 10455 pipe_config->shared_dpll = intel_get_shared_dpll_by_id(dev_priv, id); 10577 10456 } 10578 10457 10579 - static void icelake_get_ddi_pll(struct drm_i915_private *dev_priv, 10580 - enum port port, 10581 - struct intel_crtc_state *pipe_config) 10458 + static void icl_get_ddi_pll(struct drm_i915_private *dev_priv, enum port port, 10459 + struct intel_crtc_state *pipe_config) 10582 10460 { 10583 10461 enum phy phy = intel_port_to_phy(dev_priv, port); 10584 10462 enum icl_port_dpll_id port_dpll_id; ··· 10636 10516 pipe_config->shared_dpll = intel_get_shared_dpll_by_id(dev_priv, id); 10637 10517 } 10638 10518 10639 - static void skylake_get_ddi_pll(struct drm_i915_private *dev_priv, 10640 - enum port port, 10641 - struct intel_crtc_state *pipe_config) 10519 + static void skl_get_ddi_pll(struct drm_i915_private *dev_priv, enum port port, 10520 + struct intel_crtc_state *pipe_config) 10642 10521 { 10643 10522 enum intel_dpll_id id; 10644 10523 u32 temp; ··· 10651 10532 pipe_config->shared_dpll = intel_get_shared_dpll_by_id(dev_priv, id); 10652 10533 } 10653 10534 10654 - static void haswell_get_ddi_pll(struct drm_i915_private *dev_priv, 10655 - enum port port, 10656 - struct intel_crtc_state *pipe_config) 10535 + static void hsw_get_ddi_pll(struct drm_i915_private *dev_priv, enum port port, 10536 + struct intel_crtc_state *pipe_config) 10657 10537 { 10658 10538 enum intel_dpll_id id; 10659 10539 u32 ddi_pll_sel = I915_READ(PORT_CLK_SEL(port)); ··· 10840 10722 return transcoder_is_dsi(pipe_config->cpu_transcoder); 10841 10723 } 10842 10724 10843 - static void haswell_get_ddi_port_state(struct intel_crtc *crtc, 10844 - struct intel_crtc_state *pipe_config) 10725 + static void hsw_get_ddi_port_state(struct intel_crtc *crtc, 10726 + struct intel_crtc_state *pipe_config) 10845 10727 { 10846 10728 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); 10847 10729 enum transcoder cpu_transcoder = pipe_config->cpu_transcoder; ··· 10861 10743 } 10862 10744 10863 10745 if (INTEL_GEN(dev_priv) >= 11) 10864 - icelake_get_ddi_pll(dev_priv, port, pipe_config); 10746 + icl_get_ddi_pll(dev_priv, port, pipe_config); 10865 10747 else if (IS_CANNONLAKE(dev_priv)) 10866 - cannonlake_get_ddi_pll(dev_priv, port, pipe_config); 10748 + cnl_get_ddi_pll(dev_priv, port, pipe_config); 10867 10749 else if (IS_GEN9_BC(dev_priv)) 10868 - skylake_get_ddi_pll(dev_priv, port, pipe_config); 10750 + skl_get_ddi_pll(dev_priv, port, pipe_config); 10869 10751 else if (IS_GEN9_LP(dev_priv)) 10870 10752 bxt_get_ddi_pll(dev_priv, port, pipe_config); 10871 10753 else 10872 - haswell_get_ddi_pll(dev_priv, port, pipe_config); 10754 + hsw_get_ddi_pll(dev_priv, port, pipe_config); 10873 10755 10874 10756 pll = pipe_config->shared_dpll; 10875 10757 if (pll) { ··· 10890 10772 pipe_config->fdi_lanes = ((FDI_DP_PORT_WIDTH_MASK & tmp) >> 10891 10773 FDI_DP_PORT_WIDTH_SHIFT) + 1; 10892 10774 10893 - ironlake_get_fdi_m_n_config(crtc, pipe_config); 10775 + ilk_get_fdi_m_n_config(crtc, pipe_config); 10894 10776 } 10895 10777 } 10896 10778 ··· 10912 10794 return master_select - 1; 10913 10795 } 10914 10796 10915 - static void icelake_get_trans_port_sync_config(struct intel_crtc_state *crtc_state) 10797 + static void icl_get_trans_port_sync_config(struct intel_crtc_state *crtc_state) 10916 10798 { 10917 10799 struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev); 10918 10800 u32 transcoders; ··· 10947 10829 crtc_state->sync_mode_slaves_mask); 10948 10830 } 10949 10831 10950 - static bool haswell_get_pipe_config(struct intel_crtc *crtc, 10951 - struct intel_crtc_state *pipe_config) 10832 + static bool hsw_get_pipe_config(struct intel_crtc *crtc, 10833 + struct intel_crtc_state *pipe_config) 10952 10834 { 10953 10835 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); 10954 10836 intel_wakeref_t wakerefs[POWER_DOMAIN_NUM], wf; ··· 10983 10865 10984 10866 if (!transcoder_is_dsi(pipe_config->cpu_transcoder) || 10985 10867 INTEL_GEN(dev_priv) >= 11) { 10986 - haswell_get_ddi_port_state(crtc, pipe_config); 10868 + hsw_get_ddi_port_state(crtc, pipe_config); 10987 10869 intel_get_pipe_timings(crtc, pipe_config); 10988 10870 } 10989 10871 ··· 11040 10922 power_domain_mask |= BIT_ULL(power_domain); 11041 10923 11042 10924 if (INTEL_GEN(dev_priv) >= 9) 11043 - skylake_get_pfit_config(crtc, pipe_config); 10925 + skl_get_pfit_config(crtc, pipe_config); 11044 10926 else 11045 - ironlake_get_pfit_config(crtc, pipe_config); 10927 + ilk_get_pfit_config(crtc, pipe_config); 11046 10928 } 11047 10929 11048 10930 if (hsw_crtc_supports_ips(crtc)) { ··· 11068 10950 11069 10951 if (INTEL_GEN(dev_priv) >= 11 && 11070 10952 !transcoder_is_dsi(pipe_config->cpu_transcoder)) 11071 - icelake_get_trans_port_sync_config(pipe_config); 10953 + icl_get_trans_port_sync_config(pipe_config); 11072 10954 11073 10955 out: 11074 10956 for_each_power_domain(power_domain, power_domain_mask) ··· 11688 11570 { 11689 11571 struct intel_crtc *intel_crtc; 11690 11572 struct intel_encoder *intel_encoder = 11691 - intel_attached_encoder(connector); 11573 + intel_attached_encoder(to_intel_connector(connector)); 11692 11574 struct drm_crtc *possible_crtc; 11693 11575 struct drm_encoder *encoder = &intel_encoder->base; 11694 11576 struct drm_crtc *crtc = NULL; ··· 11842 11724 struct drm_modeset_acquire_ctx *ctx) 11843 11725 { 11844 11726 struct intel_encoder *intel_encoder = 11845 - intel_attached_encoder(connector); 11727 + intel_attached_encoder(to_intel_connector(connector)); 11846 11728 struct drm_encoder *encoder = &intel_encoder->base; 11847 11729 struct drm_atomic_state *state = old->restore_state; 11848 11730 int ret; ··· 11985 11867 return div_u64(mul_u32_u32(m_n->link_m, link_freq), m_n->link_n); 11986 11868 } 11987 11869 11988 - static void ironlake_pch_clock_get(struct intel_crtc *crtc, 11989 - struct intel_crtc_state *pipe_config) 11870 + static void ilk_pch_clock_get(struct intel_crtc *crtc, 11871 + struct intel_crtc_state *pipe_config) 11990 11872 { 11991 11873 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); 11992 11874 ··· 12015 11897 crtc_state->hsw_workaround_pipe = INVALID_PIPE; 12016 11898 crtc_state->output_format = INTEL_OUTPUT_FORMAT_INVALID; 12017 11899 crtc_state->scaler_state.scaler_id = -1; 11900 + crtc_state->mst_master_transcoder = INVALID_TRANSCODER; 12018 11901 } 12019 11902 12020 11903 static struct intel_crtc_state *intel_crtc_state_alloc(struct intel_crtc *crtc) ··· 12397 12278 return !old_crtc_state->c8_planes != !new_crtc_state->c8_planes; 12398 12279 } 12399 12280 12400 - static int icl_add_sync_mode_crtcs(struct intel_crtc_state *crtc_state) 12281 + static bool 12282 + intel_atomic_is_master_connector(struct intel_crtc_state *crtc_state) 12283 + { 12284 + struct drm_crtc *crtc = crtc_state->uapi.crtc; 12285 + struct drm_atomic_state *state = crtc_state->uapi.state; 12286 + struct drm_connector *connector; 12287 + struct drm_connector_state *connector_state; 12288 + int i; 12289 + 12290 + for_each_new_connector_in_state(state, connector, connector_state, i) { 12291 + if (connector_state->crtc != crtc) 12292 + continue; 12293 + if (connector->has_tile && 12294 + connector->tile_h_loc == connector->num_h_tile - 1 && 12295 + connector->tile_v_loc == connector->num_v_tile - 1) 12296 + return true; 12297 + } 12298 + 12299 + return false; 12300 + } 12301 + 12302 + static void reset_port_sync_mode_state(struct intel_crtc_state *crtc_state) 12303 + { 12304 + crtc_state->master_transcoder = INVALID_TRANSCODER; 12305 + crtc_state->sync_mode_slaves_mask = 0; 12306 + } 12307 + 12308 + static int icl_compute_port_sync_crtc_state(struct drm_connector *connector, 12309 + struct intel_crtc_state *crtc_state, 12310 + int num_tiled_conns) 12401 12311 { 12402 12312 struct drm_crtc *crtc = crtc_state->uapi.crtc; 12403 12313 struct intel_atomic_state *state = to_intel_atomic_state(crtc_state->uapi.state); 12404 12314 struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev); 12405 - struct drm_connector *master_connector, *connector; 12406 - struct drm_connector_state *connector_state; 12315 + struct drm_connector *master_connector; 12407 12316 struct drm_connector_list_iter conn_iter; 12408 12317 struct drm_crtc *master_crtc = NULL; 12409 12318 struct drm_crtc_state *master_crtc_state; 12410 12319 struct intel_crtc_state *master_pipe_config; 12411 - int i, tile_group_id; 12412 12320 12413 12321 if (INTEL_GEN(dev_priv) < 11) 12322 + return 0; 12323 + 12324 + if (!intel_crtc_has_type(crtc_state, INTEL_OUTPUT_DP)) 12414 12325 return 0; 12415 12326 12416 12327 /* ··· 12449 12300 * to the last horizonal and last vertical tile a master/genlock CRTC. 12450 12301 * All the other CRTCs corresponding to other tiles of the same Tile group 12451 12302 * are the slave CRTCs and hold a pointer to their genlock CRTC. 12303 + * If all tiles not present do not make master slave assignments. 12452 12304 */ 12453 - for_each_new_connector_in_state(&state->base, connector, connector_state, i) { 12454 - if (connector_state->crtc != crtc) 12455 - continue; 12456 - if (!connector->has_tile) 12457 - continue; 12458 - if (crtc_state->hw.mode.hdisplay != connector->tile_h_size || 12459 - crtc_state->hw.mode.vdisplay != connector->tile_v_size) 12460 - return 0; 12461 - if (connector->tile_h_loc == connector->num_h_tile - 1 && 12462 - connector->tile_v_loc == connector->num_v_tile - 1) 12463 - continue; 12464 - crtc_state->sync_mode_slaves_mask = 0; 12465 - tile_group_id = connector->tile_group->id; 12466 - drm_connector_list_iter_begin(&dev_priv->drm, &conn_iter); 12467 - drm_for_each_connector_iter(master_connector, &conn_iter) { 12468 - struct drm_connector_state *master_conn_state = NULL; 12469 - 12470 - if (!master_connector->has_tile) 12471 - continue; 12472 - if (master_connector->tile_h_loc != master_connector->num_h_tile - 1 || 12473 - master_connector->tile_v_loc != master_connector->num_v_tile - 1) 12474 - continue; 12475 - if (master_connector->tile_group->id != tile_group_id) 12476 - continue; 12477 - 12478 - master_conn_state = drm_atomic_get_connector_state(&state->base, 12479 - master_connector); 12480 - if (IS_ERR(master_conn_state)) { 12481 - drm_connector_list_iter_end(&conn_iter); 12482 - return PTR_ERR(master_conn_state); 12483 - } 12484 - if (master_conn_state->crtc) { 12485 - master_crtc = master_conn_state->crtc; 12486 - break; 12487 - } 12488 - } 12489 - drm_connector_list_iter_end(&conn_iter); 12490 - 12491 - if (!master_crtc) { 12492 - DRM_DEBUG_KMS("Could not find Master CRTC for Slave CRTC %d\n", 12493 - connector_state->crtc->base.id); 12494 - return -EINVAL; 12495 - } 12496 - 12497 - master_crtc_state = drm_atomic_get_crtc_state(&state->base, 12498 - master_crtc); 12499 - if (IS_ERR(master_crtc_state)) 12500 - return PTR_ERR(master_crtc_state); 12501 - 12502 - master_pipe_config = to_intel_crtc_state(master_crtc_state); 12503 - crtc_state->master_transcoder = master_pipe_config->cpu_transcoder; 12504 - master_pipe_config->sync_mode_slaves_mask |= 12505 - BIT(crtc_state->cpu_transcoder); 12506 - DRM_DEBUG_KMS("Master Transcoder = %s added for Slave CRTC = %d, slave transcoder bitmask = %d\n", 12507 - transcoder_name(crtc_state->master_transcoder), 12508 - crtc_state->uapi.crtc->base.id, 12509 - master_pipe_config->sync_mode_slaves_mask); 12305 + if (!connector->has_tile || 12306 + crtc_state->hw.mode.hdisplay != connector->tile_h_size || 12307 + crtc_state->hw.mode.vdisplay != connector->tile_v_size || 12308 + num_tiled_conns < connector->num_h_tile * connector->num_v_tile) { 12309 + reset_port_sync_mode_state(crtc_state); 12310 + return 0; 12510 12311 } 12312 + /* Last Horizontal and last vertical tile connector is a master 12313 + * Master's crtc state is already populated in slave for port sync 12314 + */ 12315 + if (connector->tile_h_loc == connector->num_h_tile - 1 && 12316 + connector->tile_v_loc == connector->num_v_tile - 1) 12317 + return 0; 12318 + 12319 + /* Loop through all connectors and configure the Slave crtc_state 12320 + * to point to the correct master. 12321 + */ 12322 + drm_connector_list_iter_begin(&dev_priv->drm, &conn_iter); 12323 + drm_for_each_connector_iter(master_connector, &conn_iter) { 12324 + struct drm_connector_state *master_conn_state = NULL; 12325 + 12326 + if (!(master_connector->has_tile && 12327 + master_connector->tile_group->id == connector->tile_group->id)) 12328 + continue; 12329 + if (master_connector->tile_h_loc != master_connector->num_h_tile - 1 || 12330 + master_connector->tile_v_loc != master_connector->num_v_tile - 1) 12331 + continue; 12332 + 12333 + master_conn_state = drm_atomic_get_connector_state(&state->base, 12334 + master_connector); 12335 + if (IS_ERR(master_conn_state)) { 12336 + drm_connector_list_iter_end(&conn_iter); 12337 + return PTR_ERR(master_conn_state); 12338 + } 12339 + if (master_conn_state->crtc) { 12340 + master_crtc = master_conn_state->crtc; 12341 + break; 12342 + } 12343 + } 12344 + drm_connector_list_iter_end(&conn_iter); 12345 + 12346 + if (!master_crtc) { 12347 + DRM_DEBUG_KMS("Could not find Master CRTC for Slave CRTC %d\n", 12348 + crtc->base.id); 12349 + return -EINVAL; 12350 + } 12351 + 12352 + master_crtc_state = drm_atomic_get_crtc_state(&state->base, 12353 + master_crtc); 12354 + if (IS_ERR(master_crtc_state)) 12355 + return PTR_ERR(master_crtc_state); 12356 + 12357 + master_pipe_config = to_intel_crtc_state(master_crtc_state); 12358 + crtc_state->master_transcoder = master_pipe_config->cpu_transcoder; 12359 + master_pipe_config->sync_mode_slaves_mask |= 12360 + BIT(crtc_state->cpu_transcoder); 12361 + DRM_DEBUG_KMS("Master Transcoder = %s added for Slave CRTC = %d, slave transcoder bitmask = %d\n", 12362 + transcoder_name(crtc_state->master_transcoder), 12363 + crtc->base.id, 12364 + master_pipe_config->sync_mode_slaves_mask); 12511 12365 12512 12366 return 0; 12513 12367 } ··· 12907 12755 pipe_config->csc_mode, pipe_config->gamma_mode, 12908 12756 pipe_config->gamma_enable, pipe_config->csc_enable); 12909 12757 12758 + DRM_DEBUG_KMS("MST master transcoder: %s\n", 12759 + transcoder_name(pipe_config->mst_master_transcoder)); 12760 + 12910 12761 dump_planes: 12911 12762 if (!state) 12912 12763 return; ··· 13056 12901 saved_state->wm = crtc_state->wm; 13057 12902 /* 13058 12903 * Save the slave bitmask which gets filled for master crtc state during 13059 - * slave atomic check call. 12904 + * slave atomic check call. For all other CRTCs reset the port sync variables 12905 + * crtc_state->master_transcoder needs to be set to INVALID 13060 12906 */ 13061 - if (is_trans_port_sync_master(crtc_state)) 12907 + reset_port_sync_mode_state(saved_state); 12908 + if (intel_atomic_is_master_connector(crtc_state)) 13062 12909 saved_state->sync_mode_slaves_mask = 13063 12910 crtc_state->sync_mode_slaves_mask; 13064 12911 ··· 13081 12924 struct drm_connector *connector; 13082 12925 struct drm_connector_state *connector_state; 13083 12926 int base_bpp, ret; 13084 - int i; 12927 + int i, tile_group_id = -1, num_tiled_conns = 0; 13085 12928 bool retry = true; 13086 12929 13087 12930 pipe_config->cpu_transcoder = ··· 13151 12994 drm_mode_set_crtcinfo(&pipe_config->hw.adjusted_mode, 13152 12995 CRTC_STEREO_DOUBLE); 13153 12996 13154 - /* Set the crtc_state defaults for trans_port_sync */ 13155 - pipe_config->master_transcoder = INVALID_TRANSCODER; 13156 - ret = icl_add_sync_mode_crtcs(pipe_config); 13157 - if (ret) { 13158 - DRM_DEBUG_KMS("Cannot assign Sync Mode CRTCs: %d\n", 13159 - ret); 13160 - return ret; 12997 + /* Get tile_group_id of tiled connector */ 12998 + for_each_new_connector_in_state(state, connector, connector_state, i) { 12999 + if (connector_state->crtc == crtc && 13000 + connector->has_tile) { 13001 + tile_group_id = connector->tile_group->id; 13002 + break; 13003 + } 13004 + } 13005 + 13006 + /* Get total number of tiled connectors in state that belong to 13007 + * this tile group. 13008 + */ 13009 + for_each_new_connector_in_state(state, connector, connector_state, i) { 13010 + if (connector->has_tile && 13011 + connector->tile_group->id == tile_group_id) 13012 + num_tiled_conns++; 13161 13013 } 13162 13014 13163 13015 /* Pass our mode to the connectors and the CRTC to give them a chance to ··· 13176 13010 for_each_new_connector_in_state(state, connector, connector_state, i) { 13177 13011 if (connector_state->crtc != crtc) 13178 13012 continue; 13013 + 13014 + ret = icl_compute_port_sync_crtc_state(connector, pipe_config, 13015 + num_tiled_conns); 13016 + if (ret) { 13017 + DRM_DEBUG_KMS("Cannot assign Sync Mode CRTCs: %d\n", 13018 + ret); 13019 + return ret; 13020 + } 13179 13021 13180 13022 encoder = to_intel_encoder(connector_state->best_encoder); 13181 13023 ret = encoder->compute_config(encoder, pipe_config, ··· 13709 13535 PIPE_CONF_CHECK_I(dsc.dsc_split); 13710 13536 PIPE_CONF_CHECK_I(dsc.compressed_bpp); 13711 13537 13538 + PIPE_CONF_CHECK_I(mst_master_transcoder); 13539 + 13712 13540 #undef PIPE_CONF_CHECK_X 13713 13541 #undef PIPE_CONF_CHECK_I 13714 13542 #undef PIPE_CONF_CHECK_BOOL ··· 14224 14048 * multiple pipes, and planes are enabled after the pipe, we need to wait at 14225 14049 * least 2 vblanks on the first pipe before enabling planes on the second pipe. 14226 14050 */ 14227 - static int haswell_mode_set_planes_workaround(struct intel_atomic_state *state) 14051 + static int hsw_mode_set_planes_workaround(struct intel_atomic_state *state) 14228 14052 { 14229 14053 struct intel_crtc_state *crtc_state; 14230 14054 struct intel_crtc *crtc; ··· 14319 14143 intel_modeset_clear_plls(state); 14320 14144 14321 14145 if (IS_HASWELL(dev_priv)) 14322 - return haswell_mode_set_planes_workaround(state); 14146 + return hsw_mode_set_planes_workaround(state); 14323 14147 14324 14148 return 0; 14325 14149 } ··· 14349 14173 14350 14174 new_crtc_state->uapi.mode_changed = false; 14351 14175 new_crtc_state->update_pipe = true; 14176 + } 14352 14177 14178 + static void intel_crtc_copy_fastset(const struct intel_crtc_state *old_crtc_state, 14179 + struct intel_crtc_state *new_crtc_state) 14180 + { 14353 14181 /* 14354 14182 * If we're not doing the full modeset we want to 14355 14183 * keep the current M/N values as they may be ··· 14476 14296 return 0; 14477 14297 } 14478 14298 14299 + static bool intel_cpu_transcoder_needs_modeset(struct intel_atomic_state *state, 14300 + enum transcoder transcoder) 14301 + { 14302 + struct intel_crtc_state *new_crtc_state; 14303 + struct intel_crtc *crtc; 14304 + int i; 14305 + 14306 + for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) 14307 + if (new_crtc_state->cpu_transcoder == transcoder) 14308 + return needs_modeset(new_crtc_state); 14309 + 14310 + return false; 14311 + } 14312 + 14313 + static void 14314 + intel_modeset_synced_crtcs(struct intel_atomic_state *state, 14315 + u8 transcoders) 14316 + { 14317 + struct intel_crtc_state *new_crtc_state; 14318 + struct intel_crtc *crtc; 14319 + int i; 14320 + 14321 + for_each_new_intel_crtc_in_state(state, crtc, 14322 + new_crtc_state, i) { 14323 + if (transcoders & BIT(new_crtc_state->cpu_transcoder)) { 14324 + new_crtc_state->uapi.mode_changed = true; 14325 + new_crtc_state->update_pipe = false; 14326 + } 14327 + } 14328 + } 14329 + 14330 + static int 14331 + intel_modeset_all_tiles(struct intel_atomic_state *state, int tile_grp_id) 14332 + { 14333 + struct drm_i915_private *dev_priv = to_i915(state->base.dev); 14334 + struct drm_connector *connector; 14335 + struct drm_connector_list_iter conn_iter; 14336 + int ret = 0; 14337 + 14338 + drm_connector_list_iter_begin(&dev_priv->drm, &conn_iter); 14339 + drm_for_each_connector_iter(connector, &conn_iter) { 14340 + struct drm_connector_state *conn_state; 14341 + struct drm_crtc_state *crtc_state; 14342 + 14343 + if (!connector->has_tile || 14344 + connector->tile_group->id != tile_grp_id) 14345 + continue; 14346 + conn_state = drm_atomic_get_connector_state(&state->base, 14347 + connector); 14348 + if (IS_ERR(conn_state)) { 14349 + ret = PTR_ERR(conn_state); 14350 + break; 14351 + } 14352 + 14353 + if (!conn_state->crtc) 14354 + continue; 14355 + 14356 + crtc_state = drm_atomic_get_crtc_state(&state->base, 14357 + conn_state->crtc); 14358 + if (IS_ERR(crtc_state)) { 14359 + ret = PTR_ERR(crtc_state); 14360 + break; 14361 + } 14362 + crtc_state->mode_changed = true; 14363 + ret = drm_atomic_add_affected_connectors(&state->base, 14364 + conn_state->crtc); 14365 + if (ret) 14366 + break; 14367 + } 14368 + drm_connector_list_iter_end(&conn_iter); 14369 + 14370 + return ret; 14371 + } 14372 + 14373 + static int 14374 + intel_atomic_check_tiled_conns(struct intel_atomic_state *state) 14375 + { 14376 + struct drm_i915_private *dev_priv = to_i915(state->base.dev); 14377 + struct drm_connector *connector; 14378 + struct drm_connector_state *old_conn_state, *new_conn_state; 14379 + int i, ret; 14380 + 14381 + if (INTEL_GEN(dev_priv) < 11) 14382 + return 0; 14383 + 14384 + /* Is tiled, mark all other tiled CRTCs as needing a modeset */ 14385 + for_each_oldnew_connector_in_state(&state->base, connector, 14386 + old_conn_state, new_conn_state, i) { 14387 + if (!connector->has_tile) 14388 + continue; 14389 + if (!intel_connector_needs_modeset(state, connector)) 14390 + continue; 14391 + 14392 + ret = intel_modeset_all_tiles(state, connector->tile_group->id); 14393 + if (ret) 14394 + return ret; 14395 + } 14396 + 14397 + return 0; 14398 + } 14399 + 14479 14400 /** 14480 14401 * intel_atomic_check - validate state object 14481 14402 * @dev: drm device ··· 14604 14323 if (ret) 14605 14324 goto fail; 14606 14325 14326 + /** 14327 + * This check adds all the connectors in current state that belong to 14328 + * the same tile group to a full modeset. 14329 + * This function directly sets the mode_changed to true and we also call 14330 + * drm_atomic_add_affected_connectors(). Hence we are not explicitly 14331 + * calling drm_atomic_helper_check_modeset() after this. 14332 + * 14333 + * Fixme: Handle some corner cases where one of the 14334 + * tiled connectors gets disconnected and tile info is lost but since it 14335 + * was previously synced to other conn, we need to add that to the modeset. 14336 + */ 14337 + ret = intel_atomic_check_tiled_conns(state); 14338 + if (ret) 14339 + goto fail; 14340 + 14607 14341 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state, 14608 14342 new_crtc_state, i) { 14609 14343 if (!needs_modeset(new_crtc_state)) { ··· 14630 14334 14631 14335 if (!new_crtc_state->uapi.enable) { 14632 14336 intel_crtc_copy_uapi_to_hw_state(new_crtc_state); 14633 - 14634 - any_ms = true; 14635 14337 continue; 14636 14338 } 14637 14339 ··· 14642 14348 goto fail; 14643 14349 14644 14350 intel_crtc_check_fastset(old_crtc_state, new_crtc_state); 14351 + } 14645 14352 14646 - if (needs_modeset(new_crtc_state)) 14353 + /** 14354 + * Check if fastset is allowed by external dependencies like other 14355 + * pipes and transcoders. 14356 + * 14357 + * Right now it only forces a fullmodeset when the MST master 14358 + * transcoder did not changed but the pipe of the master transcoder 14359 + * needs a fullmodeset so all slaves also needs to do a fullmodeset or 14360 + * in case of port synced crtcs, if one of the synced crtcs 14361 + * needs a full modeset, all other synced crtcs should be 14362 + * forced a full modeset. 14363 + */ 14364 + for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) { 14365 + if (!new_crtc_state->hw.enable || needs_modeset(new_crtc_state)) 14366 + continue; 14367 + 14368 + if (intel_dp_mst_is_slave_trans(new_crtc_state)) { 14369 + enum transcoder master = new_crtc_state->mst_master_transcoder; 14370 + 14371 + if (intel_cpu_transcoder_needs_modeset(state, master)) { 14372 + new_crtc_state->uapi.mode_changed = true; 14373 + new_crtc_state->update_pipe = false; 14374 + } 14375 + } else if (is_trans_port_sync_mode(new_crtc_state)) { 14376 + u8 trans = new_crtc_state->sync_mode_slaves_mask | 14377 + BIT(new_crtc_state->master_transcoder); 14378 + 14379 + intel_modeset_synced_crtcs(state, trans); 14380 + } 14381 + } 14382 + 14383 + for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state, 14384 + new_crtc_state, i) { 14385 + if (needs_modeset(new_crtc_state)) { 14647 14386 any_ms = true; 14387 + continue; 14388 + } 14389 + 14390 + if (!new_crtc_state->update_pipe) 14391 + continue; 14392 + 14393 + intel_crtc_copy_fastset(old_crtc_state, new_crtc_state); 14648 14394 } 14649 14395 14650 14396 if (any_ms && !check_digital_port_conflicts(state)) { ··· 14806 14472 skl_detach_scalers(new_crtc_state); 14807 14473 14808 14474 if (new_crtc_state->pch_pfit.enabled) 14809 - skylake_pfit_enable(new_crtc_state); 14475 + skl_pfit_enable(new_crtc_state); 14810 14476 } else if (HAS_PCH_SPLIT(dev_priv)) { 14811 14477 if (new_crtc_state->pch_pfit.enabled) 14812 - ironlake_pfit_enable(new_crtc_state); 14478 + ilk_pfit_enable(new_crtc_state); 14813 14479 else if (old_crtc_state->pch_pfit.enabled) 14814 - ironlake_pfit_disable(old_crtc_state); 14480 + ilk_pfit_disable(old_crtc_state); 14815 14481 } 14816 14482 14817 14483 if (INTEL_GEN(dev_priv) >= 11) ··· 14953 14619 u32 handled = 0; 14954 14620 int i; 14955 14621 14956 - /* Only disable port sync slaves */ 14622 + /* Only disable port sync and MST slaves */ 14957 14623 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state, 14958 14624 new_crtc_state, i) { 14959 14625 if (!needs_modeset(new_crtc_state)) ··· 14967 14633 * slave CRTCs are disabled first and then master CRTC since 14968 14634 * Slave vblanks are masked till Master Vblanks. 14969 14635 */ 14970 - if (!is_trans_port_sync_slave(old_crtc_state)) 14636 + if (!is_trans_port_sync_slave(old_crtc_state) && 14637 + !intel_dp_mst_is_slave_trans(old_crtc_state)) 14971 14638 continue; 14972 14639 14973 14640 intel_pre_plane_update(state, crtc); ··· 15029 14694 if (conn_state->crtc == &crtc->base) 15030 14695 break; 15031 14696 } 15032 - intel_dp = enc_to_intel_dp(&intel_attached_encoder(conn)->base); 14697 + intel_dp = enc_to_intel_dp(intel_attached_encoder(to_intel_connector(conn))); 15033 14698 intel_dp_stop_link_train(intel_dp); 15034 14699 } 15035 14700 14701 + /* 14702 + * TODO: This is only called from port sync and it is identical to what will be 14703 + * executed again in intel_update_crtc() over port sync pipes 14704 + */ 15036 14705 static void intel_post_crtc_enable_updates(struct intel_crtc *crtc, 15037 14706 struct intel_atomic_state *state) 15038 14707 { ··· 15125 14786 u8 hw_enabled_slices = dev_priv->wm.skl_hw.ddb.enabled_slices; 15126 14787 u8 required_slices = state->wm_results.ddb.enabled_slices; 15127 14788 struct skl_ddb_entry entries[I915_MAX_PIPES] = {}; 15128 - u8 dirty_pipes = 0; 14789 + const u8 num_pipes = INTEL_NUM_PIPES(dev_priv); 14790 + u8 update_pipes = 0, modeset_pipes = 0; 15129 14791 int i; 15130 14792 15131 14793 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) { 14794 + if (!new_crtc_state->hw.active) 14795 + continue; 14796 + 15132 14797 /* ignore allocations for crtc's that have been turned off. */ 15133 - if (!needs_modeset(new_crtc_state) && new_crtc_state->hw.active) 14798 + if (!needs_modeset(new_crtc_state)) { 15134 14799 entries[i] = old_crtc_state->wm.skl.ddb; 15135 - if (new_crtc_state->hw.active) 15136 - dirty_pipes |= BIT(crtc->pipe); 14800 + update_pipes |= BIT(crtc->pipe); 14801 + } else { 14802 + modeset_pipes |= BIT(crtc->pipe); 14803 + } 15137 14804 } 15138 14805 15139 14806 /* If 2nd DBuf slice required, enable it here */ ··· 15149 14804 /* 15150 14805 * Whenever the number of active pipes changes, we need to make sure we 15151 14806 * update the pipes in the right order so that their ddb allocations 15152 - * never overlap with eachother inbetween CRTC updates. Otherwise we'll 14807 + * never overlap with each other between CRTC updates. Otherwise we'll 15153 14808 * cause pipe underruns and other bad stuff. 14809 + * 14810 + * So first lets enable all pipes that do not need a fullmodeset as 14811 + * those don't have any external dependency. 15154 14812 */ 15155 - while (dirty_pipes) { 14813 + while (update_pipes) { 15156 14814 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state, 15157 14815 new_crtc_state, i) { 15158 14816 enum pipe pipe = crtc->pipe; 15159 - bool modeset = needs_modeset(new_crtc_state); 15160 14817 15161 - if ((dirty_pipes & BIT(pipe)) == 0) 14818 + if ((update_pipes & BIT(pipe)) == 0) 15162 14819 continue; 15163 14820 15164 14821 if (skl_ddb_allocation_overlaps(&new_crtc_state->wm.skl.ddb, 15165 - entries, 15166 - INTEL_NUM_PIPES(dev_priv), i)) 14822 + entries, num_pipes, i)) 15167 14823 continue; 15168 14824 15169 14825 entries[i] = new_crtc_state->wm.skl.ddb; 15170 - dirty_pipes &= ~BIT(pipe); 14826 + update_pipes &= ~BIT(pipe); 15171 14827 15172 - if (modeset && is_trans_port_sync_mode(new_crtc_state)) { 15173 - if (is_trans_port_sync_master(new_crtc_state)) 15174 - intel_update_trans_port_sync_crtcs(crtc, 15175 - state, 15176 - old_crtc_state, 15177 - new_crtc_state); 15178 - else 15179 - continue; 15180 - } else { 15181 - intel_update_crtc(crtc, state, old_crtc_state, 15182 - new_crtc_state); 15183 - } 14828 + intel_update_crtc(crtc, state, old_crtc_state, 14829 + new_crtc_state); 15184 14830 15185 14831 /* 15186 14832 * If this is an already active pipe, it's DDB changed, ··· 15181 14845 */ 15182 14846 if (!skl_ddb_entry_equal(&new_crtc_state->wm.skl.ddb, 15183 14847 &old_crtc_state->wm.skl.ddb) && 15184 - !modeset && dirty_pipes) 14848 + (update_pipes | modeset_pipes)) 15185 14849 intel_wait_for_vblank(dev_priv, pipe); 15186 14850 } 15187 14851 } 14852 + 14853 + /* 14854 + * Enable all pipes that needs a modeset and do not depends on other 14855 + * pipes 14856 + */ 14857 + for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state, 14858 + new_crtc_state, i) { 14859 + enum pipe pipe = crtc->pipe; 14860 + 14861 + if ((modeset_pipes & BIT(pipe)) == 0) 14862 + continue; 14863 + 14864 + if (intel_dp_mst_is_slave_trans(new_crtc_state) || 14865 + is_trans_port_sync_slave(new_crtc_state)) 14866 + continue; 14867 + 14868 + WARN_ON(skl_ddb_allocation_overlaps(&new_crtc_state->wm.skl.ddb, 14869 + entries, num_pipes, i)); 14870 + 14871 + entries[i] = new_crtc_state->wm.skl.ddb; 14872 + modeset_pipes &= ~BIT(pipe); 14873 + 14874 + if (is_trans_port_sync_mode(new_crtc_state)) { 14875 + struct intel_crtc *slave_crtc; 14876 + 14877 + intel_update_trans_port_sync_crtcs(crtc, state, 14878 + old_crtc_state, 14879 + new_crtc_state); 14880 + 14881 + slave_crtc = intel_get_slave_crtc(new_crtc_state); 14882 + /* TODO: update entries[] of slave */ 14883 + modeset_pipes &= ~BIT(slave_crtc->pipe); 14884 + 14885 + } else { 14886 + intel_update_crtc(crtc, state, old_crtc_state, 14887 + new_crtc_state); 14888 + } 14889 + } 14890 + 14891 + /* 14892 + * Finally enable all pipes that needs a modeset and depends on 14893 + * other pipes, right now it is only MST slaves as both port sync slave 14894 + * and master are enabled together 14895 + */ 14896 + for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state, 14897 + new_crtc_state, i) { 14898 + enum pipe pipe = crtc->pipe; 14899 + 14900 + if ((modeset_pipes & BIT(pipe)) == 0) 14901 + continue; 14902 + 14903 + WARN_ON(skl_ddb_allocation_overlaps(&new_crtc_state->wm.skl.ddb, 14904 + entries, num_pipes, i)); 14905 + 14906 + entries[i] = new_crtc_state->wm.skl.ddb; 14907 + modeset_pipes &= ~BIT(pipe); 14908 + 14909 + intel_update_crtc(crtc, state, old_crtc_state, new_crtc_state); 14910 + } 14911 + 14912 + WARN_ON(modeset_pipes); 15188 14913 15189 14914 /* If 2nd DBuf slice is no more required disable it */ 15190 14915 if (INTEL_GEN(dev_priv) >= 11 && required_slices < hw_enabled_slices) ··· 16983 16586 } 16984 16587 16985 16588 /* FIXME need to adjust LINOFF/TILEOFF accordingly. */ 16986 - if (mode_cmd->offsets[0] != 0) 16589 + if (mode_cmd->offsets[0] != 0) { 16590 + DRM_DEBUG_KMS("plane 0 offset (0x%08x) must be 0\n", 16591 + mode_cmd->offsets[0]); 16987 16592 goto err; 16593 + } 16988 16594 16989 16595 drm_helper_mode_fill_fb_struct(&dev_priv->drm, fb, mode_cmd); 16990 16596 ··· 17214 16814 intel_init_cdclk_hooks(dev_priv); 17215 16815 17216 16816 if (INTEL_GEN(dev_priv) >= 9) { 17217 - dev_priv->display.get_pipe_config = haswell_get_pipe_config; 16817 + dev_priv->display.get_pipe_config = hsw_get_pipe_config; 17218 16818 dev_priv->display.get_initial_plane_config = 17219 - skylake_get_initial_plane_config; 17220 - dev_priv->display.crtc_compute_clock = 17221 - haswell_crtc_compute_clock; 17222 - dev_priv->display.crtc_enable = haswell_crtc_enable; 17223 - dev_priv->display.crtc_disable = haswell_crtc_disable; 16819 + skl_get_initial_plane_config; 16820 + dev_priv->display.crtc_compute_clock = hsw_crtc_compute_clock; 16821 + dev_priv->display.crtc_enable = hsw_crtc_enable; 16822 + dev_priv->display.crtc_disable = hsw_crtc_disable; 17224 16823 } else if (HAS_DDI(dev_priv)) { 17225 - dev_priv->display.get_pipe_config = haswell_get_pipe_config; 16824 + dev_priv->display.get_pipe_config = hsw_get_pipe_config; 17226 16825 dev_priv->display.get_initial_plane_config = 17227 16826 i9xx_get_initial_plane_config; 17228 16827 dev_priv->display.crtc_compute_clock = 17229 - haswell_crtc_compute_clock; 17230 - dev_priv->display.crtc_enable = haswell_crtc_enable; 17231 - dev_priv->display.crtc_disable = haswell_crtc_disable; 16828 + hsw_crtc_compute_clock; 16829 + dev_priv->display.crtc_enable = hsw_crtc_enable; 16830 + dev_priv->display.crtc_disable = hsw_crtc_disable; 17232 16831 } else if (HAS_PCH_SPLIT(dev_priv)) { 17233 - dev_priv->display.get_pipe_config = ironlake_get_pipe_config; 16832 + dev_priv->display.get_pipe_config = ilk_get_pipe_config; 17234 16833 dev_priv->display.get_initial_plane_config = 17235 16834 i9xx_get_initial_plane_config; 17236 16835 dev_priv->display.crtc_compute_clock = 17237 - ironlake_crtc_compute_clock; 17238 - dev_priv->display.crtc_enable = ironlake_crtc_enable; 17239 - dev_priv->display.crtc_disable = ironlake_crtc_disable; 16836 + ilk_crtc_compute_clock; 16837 + dev_priv->display.crtc_enable = ilk_crtc_enable; 16838 + dev_priv->display.crtc_disable = ilk_crtc_disable; 17240 16839 } else if (IS_CHERRYVIEW(dev_priv)) { 17241 16840 dev_priv->display.get_pipe_config = i9xx_get_pipe_config; 17242 16841 dev_priv->display.get_initial_plane_config = ··· 17281 16882 } 17282 16883 17283 16884 if (IS_GEN(dev_priv, 5)) { 17284 - dev_priv->display.fdi_link_train = ironlake_fdi_link_train; 16885 + dev_priv->display.fdi_link_train = ilk_fdi_link_train; 17285 16886 } else if (IS_GEN(dev_priv, 6)) { 17286 16887 dev_priv->display.fdi_link_train = gen6_fdi_link_train; 17287 16888 } else if (IS_IVYBRIDGE(dev_priv)) { ··· 18226 17827 18227 17828 static void intel_early_display_was(struct drm_i915_private *dev_priv) 18228 17829 { 18229 - /* Display WA #1185 WaDisableDARBFClkGating:cnl,glk */ 18230 - if (IS_CANNONLAKE(dev_priv) || IS_GEMINILAKE(dev_priv)) 17830 + /* 17831 + * Display WA #1185 WaDisableDARBFClkGating:cnl,glk,icl,ehl,tgl 17832 + * Also known as Wa_14010480278. 17833 + */ 17834 + if (IS_GEN_RANGE(dev_priv, 10, 12) || IS_GEMINILAKE(dev_priv)) 18231 17835 I915_WRITE(GEN9_CLKGATE_DIS_0, I915_READ(GEN9_CLKGATE_DIS_0) | 18232 17836 DARBF_GATING_DIS); 18233 17837 ··· 18330 17928 /* We need to sanitize only the MST primary port. */ 18331 17929 if (encoder->type != INTEL_OUTPUT_DP_MST && 18332 17930 intel_phy_is_tc(dev_priv, phy)) 18333 - intel_tc_port_sanitize(enc_to_dig_port(&encoder->base)); 17931 + intel_tc_port_sanitize(enc_to_dig_port(encoder)); 18334 17932 } 18335 17933 18336 17934 get_encoder_power_domains(dev_priv); ··· 18502 18100 intel_overlay_cleanup(i915); 18503 18101 18504 18102 intel_gmbus_teardown(i915); 18103 + 18104 + intel_bw_cleanup(i915); 18505 18105 18506 18106 destroy_workqueue(i915->flip_wq); 18507 18107 destroy_workqueue(i915->modeset_wq);
+4 -3
drivers/gpu/drm/i915/display/intel_display.h
··· 474 474 struct intel_link_m_n *m_n, 475 475 bool constant_n, bool fec_enable); 476 476 bool is_ccs_modifier(u64 modifier); 477 + int intel_main_to_aux_plane(const struct drm_framebuffer *fb, int main_plane); 477 478 void lpt_disable_clkout_dp(struct drm_i915_private *dev_priv); 478 479 u32 intel_plane_fb_max_stride(struct drm_i915_private *dev_priv, 479 480 u32 pixel_format, u64 modifier); ··· 522 521 u32 intel_crtc_get_vblank_counter(struct intel_crtc *crtc); 523 522 void intel_crtc_vblank_off(const struct intel_crtc_state *crtc_state); 524 523 525 - int ironlake_get_lanes_required(int target_clock, int link_bw, int bpp); 524 + int ilk_get_lanes_required(int target_clock, int link_bw, int bpp); 526 525 void vlv_wait_port_ready(struct drm_i915_private *dev_priv, 527 526 struct intel_digital_port *dport, 528 527 unsigned int expected_mask); ··· 579 578 580 579 u16 skl_scaler_calc_phase(int sub, int scale, bool chroma_center); 581 580 int skl_update_scaler_crtc(struct intel_crtc_state *crtc_state); 582 - void skylake_scaler_disable(const struct intel_crtc_state *old_crtc_state); 583 - void ironlake_pfit_disable(const struct intel_crtc_state *old_crtc_state); 581 + void skl_scaler_disable(const struct intel_crtc_state *old_crtc_state); 582 + void ilk_pfit_disable(const struct intel_crtc_state *old_crtc_state); 584 583 u32 glk_plane_color_ctl(const struct intel_crtc_state *crtc_state, 585 584 const struct intel_plane_state *plane_state); 586 585 u32 glk_plane_color_ctl_crtc(const struct intel_crtc_state *crtc_state);
+3 -3
drivers/gpu/drm/i915/display/intel_display_power.c
··· 514 514 if (encoder->type == INTEL_OUTPUT_DP_MST) 515 515 continue; 516 516 517 - dig_port = enc_to_dig_port(&encoder->base); 517 + dig_port = enc_to_dig_port(encoder); 518 518 if (WARN_ON(!dig_port)) 519 519 continue; 520 520 ··· 1664 1664 { 1665 1665 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 1666 1666 struct i915_power_domains *power_domains = &dev_priv->power_domains; 1667 - enum dpio_phy phy = vlv_dport_to_phy(enc_to_dig_port(&encoder->base)); 1668 - enum dpio_channel ch = vlv_dport_to_channel(enc_to_dig_port(&encoder->base)); 1667 + enum dpio_phy phy = vlv_dport_to_phy(enc_to_dig_port(encoder)); 1668 + enum dpio_channel ch = vlv_dport_to_channel(enc_to_dig_port(encoder)); 1669 1669 1670 1670 mutex_lock(&power_domains->lock); 1671 1671
+18 -14
drivers/gpu/drm/i915/display/intel_display_types.h
··· 90 90 /* for each plane in the normal GTT view */ 91 91 struct { 92 92 unsigned int x, y; 93 - } normal[2]; 94 - /* for each plane in the rotated GTT view */ 93 + } normal[4]; 94 + /* for each plane in the rotated GTT view for no-CCS formats */ 95 95 struct { 96 96 unsigned int x, y; 97 97 unsigned int pitch; /* pixels */ ··· 555 555 */ 556 556 u32 stride; 557 557 int x, y; 558 - } color_plane[2]; 558 + } color_plane[4]; 559 559 560 560 /* plane control register */ 561 561 u32 ctl; ··· 1054 1054 1055 1055 /* Bitmask to indicate slaves attached */ 1056 1056 u8 sync_mode_slaves_mask; 1057 + 1058 + /* Only valid on TGL+ */ 1059 + enum transcoder mst_master_transcoder; 1057 1060 }; 1058 1061 1059 1062 struct intel_crtc { ··· 1438 1435 }; 1439 1436 1440 1437 static inline struct intel_encoder * 1441 - intel_attached_encoder(struct drm_connector *connector) 1438 + intel_attached_encoder(struct intel_connector *connector) 1442 1439 { 1443 - return to_intel_connector(connector)->encoder; 1440 + return connector->encoder; 1444 1441 } 1445 1442 1446 1443 static inline bool intel_encoder_is_dig_port(struct intel_encoder *encoder) ··· 1457 1454 } 1458 1455 1459 1456 static inline struct intel_digital_port * 1460 - enc_to_dig_port(struct drm_encoder *encoder) 1457 + enc_to_dig_port(struct intel_encoder *encoder) 1461 1458 { 1462 - struct intel_encoder *intel_encoder = to_intel_encoder(encoder); 1459 + struct intel_encoder *intel_encoder = encoder; 1463 1460 1464 1461 if (intel_encoder_is_dig_port(intel_encoder)) 1465 - return container_of(encoder, struct intel_digital_port, 1462 + return container_of(&encoder->base, struct intel_digital_port, 1466 1463 base.base); 1467 1464 else 1468 1465 return NULL; ··· 1471 1468 static inline struct intel_digital_port * 1472 1469 conn_to_dig_port(struct intel_connector *connector) 1473 1470 { 1474 - return enc_to_dig_port(&intel_attached_encoder(&connector->base)->base); 1471 + return enc_to_dig_port(intel_attached_encoder(connector)); 1475 1472 } 1476 1473 1477 1474 static inline struct intel_dp_mst_encoder * 1478 - enc_to_mst(struct drm_encoder *encoder) 1475 + enc_to_mst(struct intel_encoder *encoder) 1479 1476 { 1480 - return container_of(encoder, struct intel_dp_mst_encoder, base.base); 1477 + return container_of(&encoder->base, struct intel_dp_mst_encoder, 1478 + base.base); 1481 1479 } 1482 1480 1483 - static inline struct intel_dp *enc_to_intel_dp(struct drm_encoder *encoder) 1481 + static inline struct intel_dp *enc_to_intel_dp(struct intel_encoder *encoder) 1484 1482 { 1485 1483 return &enc_to_dig_port(encoder)->dp; 1486 1484 } ··· 1494 1490 return true; 1495 1491 case INTEL_OUTPUT_DDI: 1496 1492 /* Skip pure HDMI/DVI DDI encoders */ 1497 - return i915_mmio_reg_valid(enc_to_intel_dp(&encoder->base)->output_reg); 1493 + return i915_mmio_reg_valid(enc_to_intel_dp(encoder)->output_reg); 1498 1494 default: 1499 1495 return false; 1500 1496 } 1501 1497 } 1502 1498 1503 1499 static inline struct intel_lspcon * 1504 - enc_to_intel_lspcon(struct drm_encoder *encoder) 1500 + enc_to_intel_lspcon(struct intel_encoder *encoder) 1505 1501 { 1506 1502 return &enc_to_dig_port(encoder)->lspcon; 1507 1503 }
+57 -57
drivers/gpu/drm/i915/display/intel_dp.c
··· 146 146 return intel_dig_port->base.type == INTEL_OUTPUT_EDP; 147 147 } 148 148 149 - static struct intel_dp *intel_attached_dp(struct drm_connector *connector) 149 + static struct intel_dp *intel_attached_dp(struct intel_connector *connector) 150 150 { 151 - return enc_to_intel_dp(&intel_attached_encoder(connector)->base); 151 + return enc_to_intel_dp(intel_attached_encoder(connector)); 152 152 } 153 153 154 154 static void intel_dp_link_down(struct intel_encoder *encoder, ··· 614 614 intel_dp_mode_valid(struct drm_connector *connector, 615 615 struct drm_display_mode *mode) 616 616 { 617 - struct intel_dp *intel_dp = intel_attached_dp(connector); 617 + struct intel_dp *intel_dp = intel_attached_dp(to_intel_connector(connector)); 618 618 struct intel_connector *intel_connector = to_intel_connector(connector); 619 619 struct drm_display_mode *fixed_mode = intel_connector->panel.fixed_mode; 620 620 struct drm_i915_private *dev_priv = to_i915(connector->dev); ··· 834 834 * Pick one that's not used by other ports. 835 835 */ 836 836 for_each_intel_dp(&dev_priv->drm, encoder) { 837 - struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base); 837 + struct intel_dp *intel_dp = enc_to_intel_dp(encoder); 838 838 839 839 if (encoder->type == INTEL_OUTPUT_EDP) { 840 840 WARN_ON(intel_dp->active_pipe != INVALID_PIPE && ··· 1031 1031 */ 1032 1032 1033 1033 for_each_intel_dp(&dev_priv->drm, encoder) { 1034 - struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base); 1034 + struct intel_dp *intel_dp = enc_to_intel_dp(encoder); 1035 1035 1036 1036 WARN_ON(intel_dp->active_pipe != INVALID_PIPE); 1037 1037 ··· 2034 2034 static int intel_dp_dsc_compute_params(struct intel_encoder *encoder, 2035 2035 struct intel_crtc_state *crtc_state) 2036 2036 { 2037 - struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base); 2037 + struct intel_dp *intel_dp = enc_to_intel_dp(encoder); 2038 2038 struct drm_dsc_config *vdsc_cfg = &crtc_state->dsc.config; 2039 2039 u8 line_buf_depth; 2040 2040 int ret; ··· 2205 2205 struct drm_connector_state *conn_state) 2206 2206 { 2207 2207 struct drm_display_mode *adjusted_mode = &pipe_config->hw.adjusted_mode; 2208 - struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base); 2208 + struct intel_dp *intel_dp = enc_to_intel_dp(encoder); 2209 2209 struct link_config_limits limits; 2210 2210 int common_len; 2211 2211 int ret; ··· 2366 2366 { 2367 2367 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 2368 2368 struct drm_display_mode *adjusted_mode = &pipe_config->hw.adjusted_mode; 2369 - struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base); 2370 - struct intel_lspcon *lspcon = enc_to_intel_lspcon(&encoder->base); 2369 + struct intel_dp *intel_dp = enc_to_intel_dp(encoder); 2370 + struct intel_lspcon *lspcon = enc_to_intel_lspcon(encoder); 2371 2371 enum port port = encoder->port; 2372 2372 struct intel_crtc *intel_crtc = to_intel_crtc(pipe_config->uapi.crtc); 2373 2373 struct intel_connector *intel_connector = intel_dp->attached_connector; ··· 2482 2482 const struct intel_crtc_state *pipe_config) 2483 2483 { 2484 2484 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 2485 - struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base); 2485 + struct intel_dp *intel_dp = enc_to_intel_dp(encoder); 2486 2486 enum port port = encoder->port; 2487 2487 struct intel_crtc *crtc = to_intel_crtc(pipe_config->uapi.crtc); 2488 2488 const struct drm_display_mode *adjusted_mode = &pipe_config->hw.adjusted_mode; ··· 2509 2509 * 2510 2510 * CPT PCH is quite different, having many bits moved 2511 2511 * to the TRANS_DP_CTL register instead. That 2512 - * configuration happens (oddly) in ironlake_pch_enable 2512 + * configuration happens (oddly) in ilk_pch_enable 2513 2513 */ 2514 2514 2515 2515 /* Preserve the BIOS-computed detected bit. This is ··· 2653 2653 * is locked 2654 2654 */ 2655 2655 2656 - static u32 ironlake_get_pp_control(struct intel_dp *intel_dp) 2656 + static u32 ilk_get_pp_control(struct intel_dp *intel_dp) 2657 2657 { 2658 2658 struct drm_i915_private *dev_priv = dp_to_i915(intel_dp); 2659 2659 u32 control; ··· 2703 2703 if (!edp_have_panel_power(intel_dp)) 2704 2704 wait_panel_power_cycle(intel_dp); 2705 2705 2706 - pp = ironlake_get_pp_control(intel_dp); 2706 + pp = ilk_get_pp_control(intel_dp); 2707 2707 pp |= EDP_FORCE_VDD; 2708 2708 2709 2709 pp_stat_reg = _pp_stat_reg(intel_dp); ··· 2768 2768 intel_dig_port->base.base.base.id, 2769 2769 intel_dig_port->base.base.name); 2770 2770 2771 - pp = ironlake_get_pp_control(intel_dp); 2771 + pp = ilk_get_pp_control(intel_dp); 2772 2772 pp &= ~EDP_FORCE_VDD; 2773 2773 2774 2774 pp_ctrl_reg = _pp_ctrl_reg(intel_dp); ··· 2864 2864 wait_panel_power_cycle(intel_dp); 2865 2865 2866 2866 pp_ctrl_reg = _pp_ctrl_reg(intel_dp); 2867 - pp = ironlake_get_pp_control(intel_dp); 2867 + pp = ilk_get_pp_control(intel_dp); 2868 2868 if (IS_GEN(dev_priv, 5)) { 2869 2869 /* ILK workaround: disable reset around power sequence */ 2870 2870 pp &= ~PANEL_POWER_RESET; ··· 2919 2919 WARN(!intel_dp->want_panel_vdd, "Need [ENCODER:%d:%s] VDD to turn off panel\n", 2920 2920 dig_port->base.base.base.id, dig_port->base.base.name); 2921 2921 2922 - pp = ironlake_get_pp_control(intel_dp); 2922 + pp = ilk_get_pp_control(intel_dp); 2923 2923 /* We need to switch off panel power _and_ force vdd, for otherwise some 2924 2924 * panels get very unhappy and cease to work. */ 2925 2925 pp &= ~(PANEL_POWER_ON | PANEL_POWER_RESET | EDP_FORCE_VDD | ··· 2968 2968 i915_reg_t pp_ctrl_reg = _pp_ctrl_reg(intel_dp); 2969 2969 u32 pp; 2970 2970 2971 - pp = ironlake_get_pp_control(intel_dp); 2971 + pp = ilk_get_pp_control(intel_dp); 2972 2972 pp |= EDP_BLC_ENABLE; 2973 2973 2974 2974 I915_WRITE(pp_ctrl_reg, pp); ··· 2980 2980 void intel_edp_backlight_on(const struct intel_crtc_state *crtc_state, 2981 2981 const struct drm_connector_state *conn_state) 2982 2982 { 2983 - struct intel_dp *intel_dp = enc_to_intel_dp(conn_state->best_encoder); 2983 + struct intel_dp *intel_dp = enc_to_intel_dp(to_intel_encoder(conn_state->best_encoder)); 2984 2984 2985 2985 if (!intel_dp_is_edp(intel_dp)) 2986 2986 return; ··· 3004 3004 i915_reg_t pp_ctrl_reg = _pp_ctrl_reg(intel_dp); 3005 3005 u32 pp; 3006 3006 3007 - pp = ironlake_get_pp_control(intel_dp); 3007 + pp = ilk_get_pp_control(intel_dp); 3008 3008 pp &= ~EDP_BLC_ENABLE; 3009 3009 3010 3010 I915_WRITE(pp_ctrl_reg, pp); ··· 3018 3018 /* Disable backlight PP control and backlight PWM. */ 3019 3019 void intel_edp_backlight_off(const struct drm_connector_state *old_conn_state) 3020 3020 { 3021 - struct intel_dp *intel_dp = enc_to_intel_dp(old_conn_state->best_encoder); 3021 + struct intel_dp *intel_dp = enc_to_intel_dp(to_intel_encoder(old_conn_state->best_encoder)); 3022 3022 3023 3023 if (!intel_dp_is_edp(intel_dp)) 3024 3024 return; ··· 3036 3036 static void intel_edp_backlight_power(struct intel_connector *connector, 3037 3037 bool enable) 3038 3038 { 3039 - struct intel_dp *intel_dp = intel_attached_dp(&connector->base); 3039 + struct intel_dp *intel_dp = intel_attached_dp(connector); 3040 3040 intel_wakeref_t wakeref; 3041 3041 bool is_enabled; 3042 3042 3043 3043 is_enabled = false; 3044 3044 with_pps_lock(intel_dp, wakeref) 3045 - is_enabled = ironlake_get_pp_control(intel_dp) & EDP_BLC_ENABLE; 3045 + is_enabled = ilk_get_pp_control(intel_dp) & EDP_BLC_ENABLE; 3046 3046 if (is_enabled == enable) 3047 3047 return; 3048 3048 ··· 3079 3079 #define assert_edp_pll_enabled(d) assert_edp_pll((d), true) 3080 3080 #define assert_edp_pll_disabled(d) assert_edp_pll((d), false) 3081 3081 3082 - static void ironlake_edp_pll_on(struct intel_dp *intel_dp, 3083 - const struct intel_crtc_state *pipe_config) 3082 + static void ilk_edp_pll_on(struct intel_dp *intel_dp, 3083 + const struct intel_crtc_state *pipe_config) 3084 3084 { 3085 3085 struct intel_crtc *crtc = to_intel_crtc(pipe_config->uapi.crtc); 3086 3086 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); 3087 3087 3088 - assert_pipe_disabled(dev_priv, crtc->pipe); 3088 + assert_pipe_disabled(dev_priv, pipe_config->cpu_transcoder); 3089 3089 assert_dp_port_disabled(intel_dp); 3090 3090 assert_edp_pll_disabled(dev_priv); 3091 3091 ··· 3119 3119 udelay(200); 3120 3120 } 3121 3121 3122 - static void ironlake_edp_pll_off(struct intel_dp *intel_dp, 3123 - const struct intel_crtc_state *old_crtc_state) 3122 + static void ilk_edp_pll_off(struct intel_dp *intel_dp, 3123 + const struct intel_crtc_state *old_crtc_state) 3124 3124 { 3125 3125 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->uapi.crtc); 3126 3126 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); 3127 3127 3128 - assert_pipe_disabled(dev_priv, crtc->pipe); 3128 + assert_pipe_disabled(dev_priv, old_crtc_state->cpu_transcoder); 3129 3129 assert_dp_port_disabled(intel_dp); 3130 3130 assert_edp_pll_enabled(dev_priv); 3131 3131 ··· 3258 3258 enum pipe *pipe) 3259 3259 { 3260 3260 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 3261 - struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base); 3261 + struct intel_dp *intel_dp = enc_to_intel_dp(encoder); 3262 3262 intel_wakeref_t wakeref; 3263 3263 bool ret; 3264 3264 ··· 3279 3279 struct intel_crtc_state *pipe_config) 3280 3280 { 3281 3281 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 3282 - struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base); 3282 + struct intel_dp *intel_dp = enc_to_intel_dp(encoder); 3283 3283 u32 tmp, flags = 0; 3284 3284 enum port port = encoder->port; 3285 3285 struct intel_crtc *crtc = to_intel_crtc(pipe_config->uapi.crtc); ··· 3363 3363 const struct intel_crtc_state *old_crtc_state, 3364 3364 const struct drm_connector_state *old_conn_state) 3365 3365 { 3366 - struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base); 3366 + struct intel_dp *intel_dp = enc_to_intel_dp(encoder); 3367 3367 3368 3368 intel_dp->link_trained = false; 3369 3369 ··· 3397 3397 const struct intel_crtc_state *old_crtc_state, 3398 3398 const struct drm_connector_state *old_conn_state) 3399 3399 { 3400 - struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base); 3400 + struct intel_dp *intel_dp = enc_to_intel_dp(encoder); 3401 3401 enum port port = encoder->port; 3402 3402 3403 3403 /* ··· 3410 3410 3411 3411 /* Only ilk+ has port A */ 3412 3412 if (port == PORT_A) 3413 - ironlake_edp_pll_off(intel_dp, old_crtc_state); 3413 + ilk_edp_pll_off(intel_dp, old_crtc_state); 3414 3414 } 3415 3415 3416 3416 static void vlv_post_disable_dp(struct intel_encoder *encoder, ··· 3548 3548 const struct drm_connector_state *conn_state) 3549 3549 { 3550 3550 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 3551 - struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base); 3551 + struct intel_dp *intel_dp = enc_to_intel_dp(encoder); 3552 3552 struct intel_crtc *crtc = to_intel_crtc(pipe_config->uapi.crtc); 3553 3553 u32 dp_reg = I915_READ(intel_dp->output_reg); 3554 3554 enum pipe pipe = crtc->pipe; ··· 3608 3608 const struct intel_crtc_state *pipe_config, 3609 3609 const struct drm_connector_state *conn_state) 3610 3610 { 3611 - struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base); 3611 + struct intel_dp *intel_dp = enc_to_intel_dp(encoder); 3612 3612 enum port port = encoder->port; 3613 3613 3614 3614 intel_dp_prepare(encoder, pipe_config); 3615 3615 3616 3616 /* Only ilk+ has port A */ 3617 3617 if (port == PORT_A) 3618 - ironlake_edp_pll_on(intel_dp, pipe_config); 3618 + ilk_edp_pll_on(intel_dp, pipe_config); 3619 3619 } 3620 3620 3621 3621 static void vlv_detach_power_sequencer(struct intel_dp *intel_dp) ··· 3658 3658 lockdep_assert_held(&dev_priv->pps_mutex); 3659 3659 3660 3660 for_each_intel_dp(&dev_priv->drm, encoder) { 3661 - struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base); 3661 + struct intel_dp *intel_dp = enc_to_intel_dp(encoder); 3662 3662 3663 3663 WARN(intel_dp->active_pipe == pipe, 3664 3664 "stealing pipe %c power sequencer from active [ENCODER:%d:%s]\n", ··· 3681 3681 const struct intel_crtc_state *crtc_state) 3682 3682 { 3683 3683 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 3684 - struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base); 3684 + struct intel_dp *intel_dp = enc_to_intel_dp(encoder); 3685 3685 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc); 3686 3686 3687 3687 lockdep_assert_held(&dev_priv->pps_mutex); ··· 4203 4203 const struct intel_crtc_state *old_crtc_state) 4204 4204 { 4205 4205 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 4206 - struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base); 4206 + struct intel_dp *intel_dp = enc_to_intel_dp(encoder); 4207 4207 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->uapi.crtc); 4208 4208 enum port port = encoder->port; 4209 4209 u32 DP = intel_dp->DP; ··· 4903 4903 intel_dp->compliance.test_data.hdisplay = be16_to_cpu(h_width); 4904 4904 intel_dp->compliance.test_data.vdisplay = be16_to_cpu(v_height); 4905 4905 /* Set test active flag here so userspace doesn't interrupt things */ 4906 - intel_dp->compliance.test_active = 1; 4906 + intel_dp->compliance.test_active = true; 4907 4907 4908 4908 return DP_TEST_ACK; 4909 4909 } ··· 4947 4947 } 4948 4948 4949 4949 /* Set test active flag here so userspace doesn't interrupt things */ 4950 - intel_dp->compliance.test_active = 1; 4950 + intel_dp->compliance.test_active = true; 4951 4951 4952 4952 return test_result; 4953 4953 } ··· 5096 5096 struct drm_modeset_acquire_ctx *ctx) 5097 5097 { 5098 5098 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 5099 - struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base); 5099 + struct intel_dp *intel_dp = enc_to_intel_dp(encoder); 5100 5100 struct intel_connector *connector = intel_dp->attached_connector; 5101 5101 struct drm_connector_state *conn_state; 5102 5102 struct intel_crtc_state *crtc_state; ··· 5536 5536 static bool icp_digital_port_connected(struct intel_encoder *encoder) 5537 5537 { 5538 5538 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 5539 - struct intel_digital_port *dig_port = enc_to_dig_port(&encoder->base); 5539 + struct intel_digital_port *dig_port = enc_to_dig_port(encoder); 5540 5540 enum phy phy = intel_port_to_phy(dev_priv, encoder->port); 5541 5541 5542 5542 if (intel_phy_is_combo(dev_priv, phy)) ··· 5651 5651 bool force) 5652 5652 { 5653 5653 struct drm_i915_private *dev_priv = to_i915(connector->dev); 5654 - struct intel_dp *intel_dp = intel_attached_dp(connector); 5654 + struct intel_dp *intel_dp = intel_attached_dp(to_intel_connector(connector)); 5655 5655 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp); 5656 5656 struct intel_encoder *encoder = &dig_port->base; 5657 5657 enum drm_connector_status status; ··· 5755 5755 static void 5756 5756 intel_dp_force(struct drm_connector *connector) 5757 5757 { 5758 - struct intel_dp *intel_dp = intel_attached_dp(connector); 5758 + struct intel_dp *intel_dp = intel_attached_dp(to_intel_connector(connector)); 5759 5759 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp); 5760 5760 struct intel_encoder *intel_encoder = &dig_port->base; 5761 5761 struct drm_i915_private *dev_priv = to_i915(intel_encoder->base.dev); ··· 5790 5790 } 5791 5791 5792 5792 /* if eDP has no EDID, fall back to fixed mode */ 5793 - if (intel_dp_is_edp(intel_attached_dp(connector)) && 5793 + if (intel_dp_is_edp(intel_attached_dp(to_intel_connector(connector))) && 5794 5794 intel_connector->panel.fixed_mode) { 5795 5795 struct drm_display_mode *mode; 5796 5796 ··· 5808 5808 static int 5809 5809 intel_dp_connector_register(struct drm_connector *connector) 5810 5810 { 5811 - struct intel_dp *intel_dp = intel_attached_dp(connector); 5811 + struct intel_dp *intel_dp = intel_attached_dp(to_intel_connector(connector)); 5812 5812 int ret; 5813 5813 5814 5814 ret = intel_connector_register(connector); ··· 5830 5830 static void 5831 5831 intel_dp_connector_unregister(struct drm_connector *connector) 5832 5832 { 5833 - struct intel_dp *intel_dp = intel_attached_dp(connector); 5833 + struct intel_dp *intel_dp = intel_attached_dp(to_intel_connector(connector)); 5834 5834 5835 5835 drm_dp_cec_unregister_connector(&intel_dp->aux); 5836 5836 drm_dp_aux_unregister(&intel_dp->aux); ··· 5839 5839 5840 5840 void intel_dp_encoder_flush_work(struct drm_encoder *encoder) 5841 5841 { 5842 - struct intel_digital_port *intel_dig_port = enc_to_dig_port(encoder); 5842 + struct intel_digital_port *intel_dig_port = enc_to_dig_port(to_intel_encoder(encoder)); 5843 5843 struct intel_dp *intel_dp = &intel_dig_port->dp; 5844 5844 5845 5845 intel_dp_mst_encoder_cleanup(intel_dig_port); ··· 5868 5868 intel_dp_encoder_flush_work(encoder); 5869 5869 5870 5870 drm_encoder_cleanup(encoder); 5871 - kfree(enc_to_dig_port(encoder)); 5871 + kfree(enc_to_dig_port(to_intel_encoder(encoder))); 5872 5872 } 5873 5873 5874 5874 void intel_dp_encoder_suspend(struct intel_encoder *intel_encoder) 5875 5875 { 5876 - struct intel_dp *intel_dp = enc_to_intel_dp(&intel_encoder->base); 5876 + struct intel_dp *intel_dp = enc_to_intel_dp(intel_encoder); 5877 5877 intel_wakeref_t wakeref; 5878 5878 5879 5879 if (!intel_dp_is_edp(intel_dp)) ··· 5904 5904 int intel_dp_hdcp_write_an_aksv(struct intel_digital_port *intel_dig_port, 5905 5905 u8 *an) 5906 5906 { 5907 - struct intel_dp *intel_dp = enc_to_intel_dp(&intel_dig_port->base.base); 5907 + struct intel_dp *intel_dp = enc_to_intel_dp(to_intel_encoder(&intel_dig_port->base.base)); 5908 5908 static const struct drm_dp_aux_msg msg = { 5909 5909 .request = DP_AUX_NATIVE_WRITE, 5910 5910 .address = DP_AUX_HDCP_AKSV, ··· 6514 6514 void intel_dp_encoder_reset(struct drm_encoder *encoder) 6515 6515 { 6516 6516 struct drm_i915_private *dev_priv = to_i915(encoder->dev); 6517 - struct intel_dp *intel_dp = enc_to_intel_dp(encoder); 6517 + struct intel_dp *intel_dp = enc_to_intel_dp(to_intel_encoder(encoder)); 6518 6518 struct intel_lspcon *lspcon = dp_to_lspcon(intel_dp); 6519 6519 intel_wakeref_t wakeref; 6520 6520 ··· 6693 6693 6694 6694 intel_pps_get_registers(intel_dp, &regs); 6695 6695 6696 - pp_ctl = ironlake_get_pp_control(intel_dp); 6696 + pp_ctl = ilk_get_pp_control(intel_dp); 6697 6697 6698 6698 /* Ensure PPS is unlocked */ 6699 6699 if (!HAS_DDI(dev_priv)) ··· 6863 6863 * soon as the new power sequencer gets initialized. 6864 6864 */ 6865 6865 if (force_disable_vdd) { 6866 - u32 pp = ironlake_get_pp_control(intel_dp); 6866 + u32 pp = ilk_get_pp_control(intel_dp); 6867 6867 6868 6868 WARN(pp & PANEL_POWER_ON, "Panel power already on\n"); 6869 6869 ··· 7660 7660 if (encoder->type != INTEL_OUTPUT_DDI) 7661 7661 continue; 7662 7662 7663 - intel_dp = enc_to_intel_dp(&encoder->base); 7663 + intel_dp = enc_to_intel_dp(encoder); 7664 7664 7665 7665 if (!intel_dp->can_mst) 7666 7666 continue; ··· 7681 7681 if (encoder->type != INTEL_OUTPUT_DDI) 7682 7682 continue; 7683 7683 7684 - intel_dp = enc_to_intel_dp(&encoder->base); 7684 + intel_dp = enc_to_intel_dp(encoder); 7685 7685 7686 7686 if (!intel_dp->can_mst) 7687 7687 continue;
+8 -7
drivers/gpu/drm/i915/display/intel_dp_aux_backlight.c
··· 57 57 */ 58 58 static u32 intel_dp_aux_get_backlight(struct intel_connector *connector) 59 59 { 60 - struct intel_dp *intel_dp = enc_to_intel_dp(&connector->encoder->base); 60 + struct intel_dp *intel_dp = enc_to_intel_dp(connector->encoder); 61 61 u8 read_val[2] = { 0x0 }; 62 62 u16 level = 0; 63 63 ··· 82 82 intel_dp_aux_set_backlight(const struct drm_connector_state *conn_state, u32 level) 83 83 { 84 84 struct intel_connector *connector = to_intel_connector(conn_state->connector); 85 - struct intel_dp *intel_dp = enc_to_intel_dp(&connector->encoder->base); 85 + struct intel_dp *intel_dp = enc_to_intel_dp(connector->encoder); 86 86 u8 vals[2] = { 0x0 }; 87 87 88 88 vals[0] = level; ··· 110 110 static bool intel_dp_aux_set_pwm_freq(struct intel_connector *connector) 111 111 { 112 112 struct drm_i915_private *dev_priv = to_i915(connector->base.dev); 113 - struct intel_dp *intel_dp = enc_to_intel_dp(&connector->encoder->base); 113 + struct intel_dp *intel_dp = enc_to_intel_dp(connector->encoder); 114 114 int freq, fxp, fxp_min, fxp_max, fxp_actual, f = 1; 115 115 u8 pn, pn_min, pn_max; 116 116 ··· 178 178 const struct drm_connector_state *conn_state) 179 179 { 180 180 struct intel_connector *connector = to_intel_connector(conn_state->connector); 181 - struct intel_dp *intel_dp = enc_to_intel_dp(&connector->encoder->base); 181 + struct intel_dp *intel_dp = enc_to_intel_dp(connector->encoder); 182 182 u8 dpcd_buf, new_dpcd_buf, edp_backlight_mode; 183 183 184 184 if (drm_dp_dpcd_readb(&intel_dp->aux, ··· 222 222 223 223 static void intel_dp_aux_disable_backlight(const struct drm_connector_state *old_conn_state) 224 224 { 225 - set_aux_backlight_enable(enc_to_intel_dp(old_conn_state->best_encoder), false); 225 + set_aux_backlight_enable(enc_to_intel_dp(to_intel_encoder(old_conn_state->best_encoder)), 226 + false); 226 227 } 227 228 228 229 static int intel_dp_aux_setup_backlight(struct intel_connector *connector, 229 230 enum pipe pipe) 230 231 { 231 - struct intel_dp *intel_dp = enc_to_intel_dp(&connector->encoder->base); 232 + struct intel_dp *intel_dp = enc_to_intel_dp(connector->encoder); 232 233 struct intel_panel *panel = &connector->panel; 233 234 234 235 if (intel_dp->edp_dpcd[2] & DP_EDP_BACKLIGHT_BRIGHTNESS_BYTE_COUNT) ··· 248 247 static bool 249 248 intel_dp_aux_display_control_capable(struct intel_connector *connector) 250 249 { 251 - struct intel_dp *intel_dp = enc_to_intel_dp(&connector->encoder->base); 250 + struct intel_dp *intel_dp = enc_to_intel_dp(connector->encoder); 252 251 253 252 /* Check the eDP Display control capabilities registers to determine if 254 253 * the panel can support backlight control over the aux channel
+167 -35
drivers/gpu/drm/i915/display/intel_dp_mst.c
··· 43 43 struct link_config_limits *limits) 44 44 { 45 45 struct drm_atomic_state *state = crtc_state->uapi.state; 46 - struct intel_dp_mst_encoder *intel_mst = enc_to_mst(&encoder->base); 46 + struct intel_dp_mst_encoder *intel_mst = enc_to_mst(encoder); 47 47 struct intel_dp *intel_dp = &intel_mst->primary->dp; 48 48 struct intel_connector *connector = 49 49 to_intel_connector(conn_state->connector); ··· 88 88 return 0; 89 89 } 90 90 91 + /* 92 + * Iterate over all connectors and return the smallest transcoder in the MST 93 + * stream 94 + */ 95 + static enum transcoder 96 + intel_dp_mst_master_trans_compute(struct intel_atomic_state *state, 97 + struct intel_dp *mst_port) 98 + { 99 + struct drm_i915_private *dev_priv = to_i915(state->base.dev); 100 + struct intel_digital_connector_state *conn_state; 101 + struct intel_connector *connector; 102 + enum pipe ret = I915_MAX_PIPES; 103 + int i; 104 + 105 + if (INTEL_GEN(dev_priv) < 12) 106 + return INVALID_TRANSCODER; 107 + 108 + for_each_new_intel_connector_in_state(state, connector, conn_state, i) { 109 + struct intel_crtc_state *crtc_state; 110 + struct intel_crtc *crtc; 111 + 112 + if (connector->mst_port != mst_port || !conn_state->base.crtc) 113 + continue; 114 + 115 + crtc = to_intel_crtc(conn_state->base.crtc); 116 + crtc_state = intel_atomic_get_new_crtc_state(state, crtc); 117 + if (!crtc_state->uapi.active) 118 + continue; 119 + 120 + /* 121 + * Using crtc->pipe because crtc_state->cpu_transcoder is 122 + * computed, so others CRTCs could have non-computed 123 + * cpu_transcoder 124 + */ 125 + if (crtc->pipe < ret) 126 + ret = crtc->pipe; 127 + } 128 + 129 + if (ret == I915_MAX_PIPES) 130 + return INVALID_TRANSCODER; 131 + 132 + /* Simple cast works because TGL don't have a eDP transcoder */ 133 + return (enum transcoder)ret; 134 + } 135 + 91 136 static int intel_dp_mst_compute_config(struct intel_encoder *encoder, 92 137 struct intel_crtc_state *pipe_config, 93 138 struct drm_connector_state *conn_state) 94 139 { 140 + struct intel_atomic_state *state = to_intel_atomic_state(conn_state->state); 95 141 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 96 - struct intel_dp_mst_encoder *intel_mst = enc_to_mst(&encoder->base); 142 + struct intel_dp_mst_encoder *intel_mst = enc_to_mst(encoder); 97 143 struct intel_dp *intel_dp = &intel_mst->primary->dp; 98 144 struct intel_connector *connector = 99 145 to_intel_connector(conn_state->connector); ··· 201 155 202 156 intel_ddi_compute_min_voltage_level(dev_priv, pipe_config); 203 157 158 + pipe_config->mst_master_transcoder = intel_dp_mst_master_trans_compute(state, intel_dp); 159 + 160 + return 0; 161 + } 162 + 163 + /* 164 + * If one of the connectors in a MST stream needs a modeset, mark all CRTCs 165 + * that shares the same MST stream as mode changed, 166 + * intel_modeset_pipe_config()+intel_crtc_check_fastset() will take care to do 167 + * a fastset when possible. 168 + */ 169 + static int 170 + intel_dp_mst_atomic_master_trans_check(struct intel_connector *connector, 171 + struct intel_atomic_state *state) 172 + { 173 + struct drm_i915_private *dev_priv = to_i915(state->base.dev); 174 + struct drm_connector_list_iter connector_list_iter; 175 + struct intel_connector *connector_iter; 176 + 177 + if (INTEL_GEN(dev_priv) < 12) 178 + return 0; 179 + 180 + if (!intel_connector_needs_modeset(state, &connector->base)) 181 + return 0; 182 + 183 + drm_connector_list_iter_begin(&dev_priv->drm, &connector_list_iter); 184 + for_each_intel_connector_iter(connector_iter, &connector_list_iter) { 185 + struct intel_digital_connector_state *conn_iter_state; 186 + struct intel_crtc_state *crtc_state; 187 + struct intel_crtc *crtc; 188 + int ret; 189 + 190 + if (connector_iter->mst_port != connector->mst_port || 191 + connector_iter == connector) 192 + continue; 193 + 194 + conn_iter_state = intel_atomic_get_digital_connector_state(state, 195 + connector_iter); 196 + if (IS_ERR(conn_iter_state)) { 197 + drm_connector_list_iter_end(&connector_list_iter); 198 + return PTR_ERR(conn_iter_state); 199 + } 200 + 201 + if (!conn_iter_state->base.crtc) 202 + continue; 203 + 204 + crtc = to_intel_crtc(conn_iter_state->base.crtc); 205 + crtc_state = intel_atomic_get_crtc_state(&state->base, crtc); 206 + if (IS_ERR(crtc_state)) { 207 + drm_connector_list_iter_end(&connector_list_iter); 208 + return PTR_ERR(crtc_state); 209 + } 210 + 211 + ret = drm_atomic_add_affected_planes(&state->base, &crtc->base); 212 + if (ret) { 213 + drm_connector_list_iter_end(&connector_list_iter); 214 + return ret; 215 + } 216 + crtc_state->uapi.mode_changed = true; 217 + } 218 + drm_connector_list_iter_end(&connector_list_iter); 219 + 204 220 return 0; 205 221 } 206 222 207 223 static int 208 224 intel_dp_mst_atomic_check(struct drm_connector *connector, 209 - struct drm_atomic_state *state) 225 + struct drm_atomic_state *_state) 210 226 { 227 + struct intel_atomic_state *state = to_intel_atomic_state(_state); 211 228 struct drm_connector_state *new_conn_state = 212 - drm_atomic_get_new_connector_state(state, connector); 229 + drm_atomic_get_new_connector_state(&state->base, connector); 213 230 struct drm_connector_state *old_conn_state = 214 - drm_atomic_get_old_connector_state(state, connector); 231 + drm_atomic_get_old_connector_state(&state->base, connector); 215 232 struct intel_connector *intel_connector = 216 233 to_intel_connector(connector); 217 234 struct drm_crtc *new_crtc = new_conn_state->crtc; 218 235 struct drm_dp_mst_topology_mgr *mgr; 219 236 int ret; 220 237 221 - ret = intel_digital_connector_atomic_check(connector, state); 238 + ret = intel_digital_connector_atomic_check(connector, &state->base); 239 + if (ret) 240 + return ret; 241 + 242 + ret = intel_dp_mst_atomic_master_trans_check(intel_connector, state); 222 243 if (ret) 223 244 return ret; 224 245 ··· 296 183 * connector 297 184 */ 298 185 if (new_crtc) { 299 - struct intel_atomic_state *intel_state = 300 - to_intel_atomic_state(state); 301 186 struct intel_crtc *intel_crtc = to_intel_crtc(new_crtc); 302 187 struct intel_crtc_state *crtc_state = 303 - intel_atomic_get_new_crtc_state(intel_state, 304 - intel_crtc); 188 + intel_atomic_get_new_crtc_state(state, intel_crtc); 305 189 306 190 if (!crtc_state || 307 191 !drm_atomic_crtc_needs_modeset(&crtc_state->uapi) || ··· 306 196 return 0; 307 197 } 308 198 309 - mgr = &enc_to_mst(old_conn_state->best_encoder)->primary->dp.mst_mgr; 310 - ret = drm_dp_atomic_release_vcpi_slots(state, mgr, 199 + mgr = &enc_to_mst(to_intel_encoder(old_conn_state->best_encoder))->primary->dp.mst_mgr; 200 + ret = drm_dp_atomic_release_vcpi_slots(&state->base, mgr, 311 201 intel_connector->port); 312 202 313 203 return ret; ··· 317 207 const struct intel_crtc_state *old_crtc_state, 318 208 const struct drm_connector_state *old_conn_state) 319 209 { 320 - struct intel_dp_mst_encoder *intel_mst = enc_to_mst(&encoder->base); 210 + struct intel_dp_mst_encoder *intel_mst = enc_to_mst(encoder); 321 211 struct intel_digital_port *intel_dig_port = intel_mst->primary; 322 212 struct intel_dp *intel_dp = &intel_dig_port->dp; 323 213 struct intel_connector *connector = ··· 341 231 const struct intel_crtc_state *old_crtc_state, 342 232 const struct drm_connector_state *old_conn_state) 343 233 { 344 - struct intel_dp_mst_encoder *intel_mst = enc_to_mst(&encoder->base); 234 + struct intel_dp_mst_encoder *intel_mst = enc_to_mst(encoder); 345 235 struct intel_digital_port *intel_dig_port = intel_mst->primary; 346 236 struct intel_dp *intel_dp = &intel_dig_port->dp; 347 237 struct intel_connector *connector = 348 238 to_intel_connector(old_conn_state->connector); 349 239 struct drm_i915_private *dev_priv = to_i915(connector->base.dev); 350 240 bool last_mst_stream; 241 + u32 val; 351 242 352 243 intel_dp->active_mst_links--; 353 244 last_mst_stream = intel_dp->active_mst_links == 0; 245 + WARN_ON(INTEL_GEN(dev_priv) >= 12 && last_mst_stream && 246 + !intel_dp_mst_is_master_trans(old_crtc_state)); 354 247 355 248 intel_crtc_vblank_off(old_crtc_state); 356 249 357 250 intel_disable_pipe(old_crtc_state); 358 251 252 + drm_dp_update_payload_part2(&intel_dp->mst_mgr); 253 + 254 + val = I915_READ(TRANS_DDI_FUNC_CTL(old_crtc_state->cpu_transcoder)); 255 + val &= ~TRANS_DDI_DP_VC_PAYLOAD_ALLOC; 256 + I915_WRITE(TRANS_DDI_FUNC_CTL(old_crtc_state->cpu_transcoder), val); 257 + 258 + if (intel_de_wait_for_set(dev_priv, intel_dp->regs.dp_tp_status, 259 + DP_TP_STATUS_ACT_SENT, 1)) 260 + DRM_ERROR("Timed out waiting for ACT sent when disabling\n"); 261 + drm_dp_check_act_status(&intel_dp->mst_mgr); 262 + 263 + drm_dp_mst_deallocate_vcpi(&intel_dp->mst_mgr, connector->port); 264 + 359 265 intel_ddi_disable_transcoder_func(old_crtc_state); 360 266 361 267 if (INTEL_GEN(dev_priv) >= 9) 362 - skylake_scaler_disable(old_crtc_state); 268 + skl_scaler_disable(old_crtc_state); 363 269 else 364 - ironlake_pfit_disable(old_crtc_state); 270 + ilk_pfit_disable(old_crtc_state); 365 271 272 + /* 273 + * Power down mst path before disabling the port, otherwise we end 274 + * up getting interrupts from the sink upon detecting link loss. 275 + */ 276 + drm_dp_send_power_updown_phy(&intel_dp->mst_mgr, connector->port, 277 + false); 366 278 /* 367 279 * From TGL spec: "If multi-stream slave transcoder: Configure 368 280 * Transcoder Clock Select to direct no clock to the transcoder" ··· 395 263 if (INTEL_GEN(dev_priv) < 12 || !last_mst_stream) 396 264 intel_ddi_disable_pipe_clock(old_crtc_state); 397 265 398 - /* this can fail */ 399 - drm_dp_check_act_status(&intel_dp->mst_mgr); 400 - /* and this can also fail */ 401 - drm_dp_update_payload_part2(&intel_dp->mst_mgr); 402 - 403 - drm_dp_mst_deallocate_vcpi(&intel_dp->mst_mgr, connector->port); 404 - 405 - /* 406 - * Power down mst path before disabling the port, otherwise we end 407 - * up getting interrupts from the sink upon detecting link loss. 408 - */ 409 - drm_dp_send_power_updown_phy(&intel_dp->mst_mgr, connector->port, 410 - false); 411 266 412 267 intel_mst->connector = NULL; 413 268 if (last_mst_stream) ··· 408 289 const struct intel_crtc_state *pipe_config, 409 290 const struct drm_connector_state *conn_state) 410 291 { 411 - struct intel_dp_mst_encoder *intel_mst = enc_to_mst(&encoder->base); 292 + struct intel_dp_mst_encoder *intel_mst = enc_to_mst(encoder); 412 293 struct intel_digital_port *intel_dig_port = intel_mst->primary; 413 294 struct intel_dp *intel_dp = &intel_dig_port->dp; 414 295 ··· 421 302 const struct intel_crtc_state *pipe_config, 422 303 const struct drm_connector_state *conn_state) 423 304 { 424 - struct intel_dp_mst_encoder *intel_mst = enc_to_mst(&encoder->base); 305 + struct intel_dp_mst_encoder *intel_mst = enc_to_mst(encoder); 425 306 struct intel_digital_port *intel_dig_port = intel_mst->primary; 426 307 struct intel_dp *intel_dp = &intel_dig_port->dp; 427 308 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); ··· 437 318 connector->encoder = encoder; 438 319 intel_mst->connector = connector; 439 320 first_mst_stream = intel_dp->active_mst_links == 0; 321 + WARN_ON(INTEL_GEN(dev_priv) >= 12 && first_mst_stream && 322 + !intel_dp_mst_is_master_trans(pipe_config)); 440 323 441 324 DRM_DEBUG_KMS("active links %d\n", intel_dp->active_mst_links); 442 325 ··· 481 360 const struct intel_crtc_state *pipe_config, 482 361 const struct drm_connector_state *conn_state) 483 362 { 484 - struct intel_dp_mst_encoder *intel_mst = enc_to_mst(&encoder->base); 363 + struct intel_dp_mst_encoder *intel_mst = enc_to_mst(encoder); 485 364 struct intel_digital_port *intel_dig_port = intel_mst->primary; 486 365 struct intel_dp *intel_dp = &intel_dig_port->dp; 487 366 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); ··· 502 381 static bool intel_dp_mst_enc_get_hw_state(struct intel_encoder *encoder, 503 382 enum pipe *pipe) 504 383 { 505 - struct intel_dp_mst_encoder *intel_mst = enc_to_mst(&encoder->base); 384 + struct intel_dp_mst_encoder *intel_mst = enc_to_mst(encoder); 506 385 *pipe = intel_mst->pipe; 507 386 if (intel_mst->connector) 508 387 return true; ··· 512 391 static void intel_dp_mst_enc_get_config(struct intel_encoder *encoder, 513 392 struct intel_crtc_state *pipe_config) 514 393 { 515 - struct intel_dp_mst_encoder *intel_mst = enc_to_mst(&encoder->base); 394 + struct intel_dp_mst_encoder *intel_mst = enc_to_mst(encoder); 516 395 struct intel_digital_port *intel_dig_port = intel_mst->primary; 517 396 518 397 intel_ddi_get_config(&intel_dig_port->base, pipe_config); ··· 620 499 621 500 static void intel_dp_mst_encoder_destroy(struct drm_encoder *encoder) 622 501 { 623 - struct intel_dp_mst_encoder *intel_mst = enc_to_mst(encoder); 502 + struct intel_dp_mst_encoder *intel_mst = enc_to_mst(to_intel_encoder(encoder)); 624 503 625 504 drm_encoder_cleanup(encoder); 626 505 kfree(intel_mst); ··· 843 722 844 723 drm_dp_mst_topology_mgr_destroy(&intel_dp->mst_mgr); 845 724 /* encoders will get killed by normal cleanup */ 725 + } 726 + 727 + bool intel_dp_mst_is_master_trans(const struct intel_crtc_state *crtc_state) 728 + { 729 + return crtc_state->mst_master_transcoder == crtc_state->cpu_transcoder; 730 + } 731 + 732 + bool intel_dp_mst_is_slave_trans(const struct intel_crtc_state *crtc_state) 733 + { 734 + return crtc_state->mst_master_transcoder != INVALID_TRANSCODER && 735 + crtc_state->mst_master_transcoder != crtc_state->cpu_transcoder; 846 736 }
+5
drivers/gpu/drm/i915/display/intel_dp_mst.h
··· 6 6 #ifndef __INTEL_DP_MST_H__ 7 7 #define __INTEL_DP_MST_H__ 8 8 9 + #include <linux/types.h> 10 + 9 11 struct intel_digital_port; 12 + struct intel_crtc_state; 10 13 11 14 int intel_dp_mst_encoder_init(struct intel_digital_port *intel_dig_port, int conn_id); 12 15 void intel_dp_mst_encoder_cleanup(struct intel_digital_port *intel_dig_port); 13 16 int intel_dp_mst_encoder_active_links(struct intel_digital_port *intel_dig_port); 17 + bool intel_dp_mst_is_master_trans(const struct intel_crtc_state *crtc_state); 18 + bool intel_dp_mst_is_slave_trans(const struct intel_crtc_state *crtc_state); 14 19 15 20 #endif /* __INTEL_DP_MST_H__ */
+9 -9
drivers/gpu/drm/i915/display/intel_dpio_phy.c
··· 642 642 bool uniq_trans_scale) 643 643 { 644 644 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 645 - struct intel_digital_port *dport = enc_to_dig_port(&encoder->base); 645 + struct intel_digital_port *dport = enc_to_dig_port(encoder); 646 646 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->base.crtc); 647 647 enum dpio_channel ch = vlv_dport_to_channel(dport); 648 648 enum pipe pipe = intel_crtc->pipe; ··· 738 738 bool reset) 739 739 { 740 740 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 741 - enum dpio_channel ch = vlv_dport_to_channel(enc_to_dig_port(&encoder->base)); 741 + enum dpio_channel ch = vlv_dport_to_channel(enc_to_dig_port(encoder)); 742 742 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc); 743 743 enum pipe pipe = crtc->pipe; 744 744 u32 val; ··· 781 781 void chv_phy_pre_pll_enable(struct intel_encoder *encoder, 782 782 const struct intel_crtc_state *crtc_state) 783 783 { 784 - struct intel_digital_port *dport = enc_to_dig_port(&encoder->base); 784 + struct intel_digital_port *dport = enc_to_dig_port(encoder); 785 785 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 786 786 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc); 787 787 enum dpio_channel ch = vlv_dport_to_channel(dport); ··· 861 861 void chv_phy_pre_encoder_enable(struct intel_encoder *encoder, 862 862 const struct intel_crtc_state *crtc_state) 863 863 { 864 - struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base); 864 + struct intel_dp *intel_dp = enc_to_intel_dp(encoder); 865 865 struct intel_digital_port *dport = dp_to_dig_port(intel_dp); 866 866 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 867 867 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc); ··· 940 940 941 941 void chv_phy_release_cl2_override(struct intel_encoder *encoder) 942 942 { 943 - struct intel_digital_port *dport = enc_to_dig_port(&encoder->base); 943 + struct intel_digital_port *dport = enc_to_dig_port(encoder); 944 944 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 945 945 946 946 if (dport->release_cl2_override) { ··· 989 989 { 990 990 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 991 991 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->base.crtc); 992 - struct intel_digital_port *dport = enc_to_dig_port(&encoder->base); 992 + struct intel_digital_port *dport = enc_to_dig_port(encoder); 993 993 enum dpio_channel port = vlv_dport_to_channel(dport); 994 994 enum pipe pipe = intel_crtc->pipe; 995 995 ··· 1014 1014 void vlv_phy_pre_pll_enable(struct intel_encoder *encoder, 1015 1015 const struct intel_crtc_state *crtc_state) 1016 1016 { 1017 - struct intel_digital_port *dport = enc_to_dig_port(&encoder->base); 1017 + struct intel_digital_port *dport = enc_to_dig_port(encoder); 1018 1018 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 1019 1019 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc); 1020 1020 enum dpio_channel port = vlv_dport_to_channel(dport); ··· 1043 1043 void vlv_phy_pre_encoder_enable(struct intel_encoder *encoder, 1044 1044 const struct intel_crtc_state *crtc_state) 1045 1045 { 1046 - struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base); 1046 + struct intel_dp *intel_dp = enc_to_intel_dp(encoder); 1047 1047 struct intel_digital_port *dport = dp_to_dig_port(intel_dp); 1048 1048 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 1049 1049 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc); ··· 1073 1073 void vlv_phy_reset_lanes(struct intel_encoder *encoder, 1074 1074 const struct intel_crtc_state *old_crtc_state) 1075 1075 { 1076 - struct intel_digital_port *dport = enc_to_dig_port(&encoder->base); 1076 + struct intel_digital_port *dport = enc_to_dig_port(encoder); 1077 1077 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 1078 1078 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->uapi.crtc); 1079 1079 enum dpio_channel port = vlv_dport_to_channel(dport);
+2 -2
drivers/gpu/drm/i915/display/intel_dpll_mgr.c
··· 2972 2972 enum icl_port_dpll_id port_dpll_id = ICL_PORT_DPLL_DEFAULT; 2973 2973 2974 2974 primary_port = encoder->type == INTEL_OUTPUT_DP_MST ? 2975 - enc_to_mst(&encoder->base)->primary : 2976 - enc_to_dig_port(&encoder->base); 2975 + enc_to_mst(encoder)->primary : 2976 + enc_to_dig_port(encoder); 2977 2977 2978 2978 if (primary_port && 2979 2979 (primary_port->tc_mode == TC_PORT_DP_ALT ||
+10 -4
drivers/gpu/drm/i915/display/intel_dsi.h
··· 45 45 struct intel_dsi_host *dsi_hosts[I915_MAX_PORTS]; 46 46 intel_wakeref_t io_wakeref[I915_MAX_PORTS]; 47 47 48 - /* GPIO Desc for CRC based Panel control */ 48 + /* GPIO Desc for panel and backlight control */ 49 49 struct gpio_desc *gpio_panel; 50 + struct gpio_desc *gpio_backlight; 50 51 51 52 struct intel_connector *attached_connector; 52 53 ··· 68 67 69 68 /* number of DSI lanes */ 70 69 unsigned int lane_count; 70 + 71 + /* i2c bus associated with the slave device */ 72 + int i2c_bus_num; 71 73 72 74 /* 73 75 * video mode pixel format ··· 145 141 #define for_each_dsi_phy(__phy, __phys_mask) \ 146 142 for_each_phy_masked(__phy, __phys_mask) 147 143 148 - static inline struct intel_dsi *enc_to_intel_dsi(struct drm_encoder *encoder) 144 + static inline struct intel_dsi *enc_to_intel_dsi(struct intel_encoder *encoder) 149 145 { 150 - return container_of(encoder, struct intel_dsi, base.base); 146 + return container_of(&encoder->base, struct intel_dsi, base.base); 151 147 } 152 148 153 149 static inline bool is_vid_mode(struct intel_dsi *intel_dsi) ··· 162 158 163 159 static inline u16 intel_dsi_encoder_ports(struct intel_encoder *encoder) 164 160 { 165 - return enc_to_intel_dsi(&encoder->base)->ports; 161 + return enc_to_intel_dsi(encoder)->ports; 166 162 } 167 163 168 164 /* icl_dsi.c */ ··· 207 203 208 204 /* intel_dsi_vbt.c */ 209 205 bool intel_dsi_vbt_init(struct intel_dsi *intel_dsi, u16 panel_id); 206 + void intel_dsi_vbt_gpio_init(struct intel_dsi *intel_dsi, bool panel_is_on); 207 + void intel_dsi_vbt_gpio_cleanup(struct intel_dsi *intel_dsi); 210 208 void intel_dsi_vbt_exec_sequence(struct intel_dsi *intel_dsi, 211 209 enum mipi_seq seq_id); 212 210 void intel_dsi_msleep(struct intel_dsi *intel_dsi, int msec);
+4 -4
drivers/gpu/drm/i915/display/intel_dsi_dcs_backlight.c
··· 46 46 static u32 dcs_get_backlight(struct intel_connector *connector) 47 47 { 48 48 struct intel_encoder *encoder = connector->encoder; 49 - struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base); 49 + struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder); 50 50 struct mipi_dsi_device *dsi_device; 51 51 u8 data = 0; 52 52 enum port port; ··· 64 64 65 65 static void dcs_set_backlight(const struct drm_connector_state *conn_state, u32 level) 66 66 { 67 - struct intel_dsi *intel_dsi = enc_to_intel_dsi(conn_state->best_encoder); 67 + struct intel_dsi *intel_dsi = enc_to_intel_dsi(to_intel_encoder(conn_state->best_encoder)); 68 68 struct mipi_dsi_device *dsi_device; 69 69 u8 data = level; 70 70 enum port port; ··· 79 79 80 80 static void dcs_disable_backlight(const struct drm_connector_state *conn_state) 81 81 { 82 - struct intel_dsi *intel_dsi = enc_to_intel_dsi(conn_state->best_encoder); 82 + struct intel_dsi *intel_dsi = enc_to_intel_dsi(to_intel_encoder(conn_state->best_encoder)); 83 83 struct mipi_dsi_device *dsi_device; 84 84 enum port port; 85 85 ··· 113 113 static void dcs_enable_backlight(const struct intel_crtc_state *crtc_state, 114 114 const struct drm_connector_state *conn_state) 115 115 { 116 - struct intel_dsi *intel_dsi = enc_to_intel_dsi(conn_state->best_encoder); 116 + struct intel_dsi *intel_dsi = enc_to_intel_dsi(to_intel_encoder(conn_state->best_encoder)); 117 117 struct intel_panel *panel = &to_intel_connector(conn_state->connector)->panel; 118 118 struct mipi_dsi_device *dsi_device; 119 119 enum port port;
+225 -4
drivers/gpu/drm/i915/display/intel_dsi_vbt.c
··· 25 25 */ 26 26 27 27 #include <linux/gpio/consumer.h> 28 + #include <linux/gpio/machine.h> 28 29 #include <linux/mfd/intel_soc_pmic.h> 30 + #include <linux/pinctrl/consumer.h> 31 + #include <linux/pinctrl/machine.h> 29 32 #include <linux/slab.h> 30 33 31 34 #include <asm/intel-mid.h> ··· 84 81 { VLV_GPIO_NC_9_PANEL1_VDDEN }, 85 82 { VLV_GPIO_NC_10_PANEL1_BKLTEN }, 86 83 { VLV_GPIO_NC_11_PANEL1_BKLTCTL }, 84 + }; 85 + 86 + struct i2c_adapter_lookup { 87 + u16 slave_addr; 88 + struct intel_dsi *intel_dsi; 89 + acpi_handle dev_handle; 87 90 }; 88 91 89 92 #define CHV_GPIO_IDX_START_N 0 ··· 384 375 return data; 385 376 } 386 377 378 + static int i2c_adapter_lookup(struct acpi_resource *ares, void *data) 379 + { 380 + struct i2c_adapter_lookup *lookup = data; 381 + struct intel_dsi *intel_dsi = lookup->intel_dsi; 382 + struct acpi_resource_i2c_serialbus *sb; 383 + struct i2c_adapter *adapter; 384 + acpi_handle adapter_handle; 385 + acpi_status status; 386 + 387 + if (intel_dsi->i2c_bus_num >= 0 || 388 + !i2c_acpi_get_i2c_resource(ares, &sb)) 389 + return 1; 390 + 391 + if (lookup->slave_addr != sb->slave_address) 392 + return 1; 393 + 394 + status = acpi_get_handle(lookup->dev_handle, 395 + sb->resource_source.string_ptr, 396 + &adapter_handle); 397 + if (ACPI_FAILURE(status)) 398 + return 1; 399 + 400 + adapter = i2c_acpi_find_adapter_by_handle(adapter_handle); 401 + if (adapter) 402 + intel_dsi->i2c_bus_num = adapter->nr; 403 + 404 + return 1; 405 + } 406 + 387 407 static const u8 *mipi_exec_i2c(struct intel_dsi *intel_dsi, const u8 *data) 388 408 { 389 - DRM_DEBUG_KMS("Skipping I2C element execution\n"); 409 + struct drm_device *drm_dev = intel_dsi->base.base.dev; 410 + struct device *dev = &drm_dev->pdev->dev; 411 + struct i2c_adapter *adapter; 412 + struct acpi_device *acpi_dev; 413 + struct list_head resource_list; 414 + struct i2c_adapter_lookup lookup; 415 + struct i2c_msg msg; 416 + int ret; 417 + u8 vbt_i2c_bus_num = *(data + 2); 418 + u16 slave_addr = *(u16 *)(data + 3); 419 + u8 reg_offset = *(data + 5); 420 + u8 payload_size = *(data + 6); 421 + u8 *payload_data; 390 422 391 - return data + *(data + 6) + 7; 423 + if (intel_dsi->i2c_bus_num < 0) { 424 + intel_dsi->i2c_bus_num = vbt_i2c_bus_num; 425 + 426 + acpi_dev = ACPI_COMPANION(dev); 427 + if (acpi_dev) { 428 + memset(&lookup, 0, sizeof(lookup)); 429 + lookup.slave_addr = slave_addr; 430 + lookup.intel_dsi = intel_dsi; 431 + lookup.dev_handle = acpi_device_handle(acpi_dev); 432 + 433 + INIT_LIST_HEAD(&resource_list); 434 + acpi_dev_get_resources(acpi_dev, &resource_list, 435 + i2c_adapter_lookup, 436 + &lookup); 437 + acpi_dev_free_resource_list(&resource_list); 438 + } 439 + } 440 + 441 + adapter = i2c_get_adapter(intel_dsi->i2c_bus_num); 442 + if (!adapter) { 443 + DRM_DEV_ERROR(dev, "Cannot find a valid i2c bus for xfer\n"); 444 + goto err_bus; 445 + } 446 + 447 + payload_data = kzalloc(payload_size + 1, GFP_KERNEL); 448 + if (!payload_data) 449 + goto err_alloc; 450 + 451 + payload_data[0] = reg_offset; 452 + memcpy(&payload_data[1], (data + 7), payload_size); 453 + 454 + msg.addr = slave_addr; 455 + msg.flags = 0; 456 + msg.len = payload_size + 1; 457 + msg.buf = payload_data; 458 + 459 + ret = i2c_transfer(adapter, &msg, 1); 460 + if (ret < 0) 461 + DRM_DEV_ERROR(dev, 462 + "Failed to xfer payload of size (%u) to reg (%u)\n", 463 + payload_size, reg_offset); 464 + 465 + kfree(payload_data); 466 + err_alloc: 467 + i2c_put_adapter(adapter); 468 + err_bus: 469 + return data + payload_size + 7; 392 470 } 393 471 394 472 static const u8 *mipi_exec_spi(struct intel_dsi *intel_dsi, const u8 *data) ··· 549 453 return "(unknown)"; 550 454 } 551 455 552 - void intel_dsi_vbt_exec_sequence(struct intel_dsi *intel_dsi, 553 - enum mipi_seq seq_id) 456 + static void intel_dsi_vbt_exec(struct intel_dsi *intel_dsi, 457 + enum mipi_seq seq_id) 554 458 { 555 459 struct drm_i915_private *dev_priv = to_i915(intel_dsi->base.base.dev); 556 460 const u8 *data; ··· 613 517 return; 614 518 } 615 519 } 520 + } 521 + 522 + void intel_dsi_vbt_exec_sequence(struct intel_dsi *intel_dsi, 523 + enum mipi_seq seq_id) 524 + { 525 + if (seq_id == MIPI_SEQ_POWER_ON && intel_dsi->gpio_panel) 526 + gpiod_set_value_cansleep(intel_dsi->gpio_panel, 1); 527 + if (seq_id == MIPI_SEQ_BACKLIGHT_ON && intel_dsi->gpio_backlight) 528 + gpiod_set_value_cansleep(intel_dsi->gpio_backlight, 1); 529 + 530 + intel_dsi_vbt_exec(intel_dsi, seq_id); 531 + 532 + if (seq_id == MIPI_SEQ_POWER_OFF && intel_dsi->gpio_panel) 533 + gpiod_set_value_cansleep(intel_dsi->gpio_panel, 0); 534 + if (seq_id == MIPI_SEQ_BACKLIGHT_OFF && intel_dsi->gpio_backlight) 535 + gpiod_set_value_cansleep(intel_dsi->gpio_backlight, 0); 616 536 } 617 537 618 538 void intel_dsi_msleep(struct intel_dsi *intel_dsi, int msec) ··· 776 664 intel_dsi->panel_off_delay = pps->panel_off_delay / 10; 777 665 intel_dsi->panel_pwr_cycle_delay = pps->panel_power_cycle_delay / 10; 778 666 667 + intel_dsi->i2c_bus_num = -1; 668 + 779 669 /* a regular driver would get the device in probe */ 780 670 for_each_dsi_port(port, intel_dsi->ports) { 781 671 mipi_dsi_attach(intel_dsi->dsi_hosts[port]->device); 782 672 } 783 673 784 674 return true; 675 + } 676 + 677 + /* 678 + * On some BYT/CHT devs some sequences are incomplete and we need to manually 679 + * control some GPIOs. We need to add a GPIO lookup table before we get these. 680 + * If the GOP did not initialize the panel (HDMI inserted) we may need to also 681 + * change the pinmux for the SoC's PWM0 pin from GPIO to PWM. 682 + */ 683 + static struct gpiod_lookup_table pmic_panel_gpio_table = { 684 + /* Intel GFX is consumer */ 685 + .dev_id = "0000:00:02.0", 686 + .table = { 687 + /* Panel EN/DISABLE */ 688 + GPIO_LOOKUP("gpio_crystalcove", 94, "panel", GPIO_ACTIVE_HIGH), 689 + { } 690 + }, 691 + }; 692 + 693 + static struct gpiod_lookup_table soc_panel_gpio_table = { 694 + .dev_id = "0000:00:02.0", 695 + .table = { 696 + GPIO_LOOKUP("INT33FC:01", 10, "backlight", GPIO_ACTIVE_HIGH), 697 + GPIO_LOOKUP("INT33FC:01", 11, "panel", GPIO_ACTIVE_HIGH), 698 + { } 699 + }, 700 + }; 701 + 702 + static const struct pinctrl_map soc_pwm_pinctrl_map[] = { 703 + PIN_MAP_MUX_GROUP("0000:00:02.0", "soc_pwm0", "INT33FC:00", 704 + "pwm0_grp", "pwm"), 705 + }; 706 + 707 + void intel_dsi_vbt_gpio_init(struct intel_dsi *intel_dsi, bool panel_is_on) 708 + { 709 + struct drm_device *dev = intel_dsi->base.base.dev; 710 + struct drm_i915_private *dev_priv = to_i915(dev); 711 + struct mipi_config *mipi_config = dev_priv->vbt.dsi.config; 712 + enum gpiod_flags flags = panel_is_on ? GPIOD_OUT_HIGH : GPIOD_OUT_LOW; 713 + bool want_backlight_gpio = false; 714 + bool want_panel_gpio = false; 715 + struct pinctrl *pinctrl; 716 + int ret; 717 + 718 + if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) && 719 + mipi_config->pwm_blc == PPS_BLC_PMIC) { 720 + gpiod_add_lookup_table(&pmic_panel_gpio_table); 721 + want_panel_gpio = true; 722 + } 723 + 724 + if (IS_VALLEYVIEW(dev_priv) && mipi_config->pwm_blc == PPS_BLC_SOC) { 725 + gpiod_add_lookup_table(&soc_panel_gpio_table); 726 + want_panel_gpio = true; 727 + want_backlight_gpio = true; 728 + 729 + /* Ensure PWM0 pin is muxed as PWM instead of GPIO */ 730 + ret = pinctrl_register_mappings(soc_pwm_pinctrl_map, 731 + ARRAY_SIZE(soc_pwm_pinctrl_map)); 732 + if (ret) 733 + DRM_ERROR("Failed to register pwm0 pinmux mapping\n"); 734 + 735 + pinctrl = devm_pinctrl_get_select(dev->dev, "soc_pwm0"); 736 + if (IS_ERR(pinctrl)) 737 + DRM_ERROR("Failed to set pinmux to PWM\n"); 738 + } 739 + 740 + if (want_panel_gpio) { 741 + intel_dsi->gpio_panel = gpiod_get(dev->dev, "panel", flags); 742 + if (IS_ERR(intel_dsi->gpio_panel)) { 743 + DRM_ERROR("Failed to own gpio for panel control\n"); 744 + intel_dsi->gpio_panel = NULL; 745 + } 746 + } 747 + 748 + if (want_backlight_gpio) { 749 + intel_dsi->gpio_backlight = 750 + gpiod_get(dev->dev, "backlight", flags); 751 + if (IS_ERR(intel_dsi->gpio_backlight)) { 752 + DRM_ERROR("Failed to own gpio for backlight control\n"); 753 + intel_dsi->gpio_backlight = NULL; 754 + } 755 + } 756 + } 757 + 758 + void intel_dsi_vbt_gpio_cleanup(struct intel_dsi *intel_dsi) 759 + { 760 + struct drm_device *dev = intel_dsi->base.base.dev; 761 + struct drm_i915_private *dev_priv = to_i915(dev); 762 + struct mipi_config *mipi_config = dev_priv->vbt.dsi.config; 763 + 764 + if (intel_dsi->gpio_panel) { 765 + gpiod_put(intel_dsi->gpio_panel); 766 + intel_dsi->gpio_panel = NULL; 767 + } 768 + 769 + if (intel_dsi->gpio_backlight) { 770 + gpiod_put(intel_dsi->gpio_backlight); 771 + intel_dsi->gpio_backlight = NULL; 772 + } 773 + 774 + if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) && 775 + mipi_config->pwm_blc == PPS_BLC_PMIC) 776 + gpiod_remove_lookup_table(&pmic_panel_gpio_table); 777 + 778 + if (IS_VALLEYVIEW(dev_priv) && mipi_config->pwm_blc == PPS_BLC_SOC) { 779 + pinctrl_unregister_mappings(soc_pwm_pinctrl_map); 780 + gpiod_remove_lookup_table(&soc_panel_gpio_table); 781 + } 785 782 }
+4 -4
drivers/gpu/drm/i915/display/intel_dvo.c
··· 125 125 return container_of(encoder, struct intel_dvo, base); 126 126 } 127 127 128 - static struct intel_dvo *intel_attached_dvo(struct drm_connector *connector) 128 + static struct intel_dvo *intel_attached_dvo(struct intel_connector *connector) 129 129 { 130 130 return enc_to_dvo(intel_attached_encoder(connector)); 131 131 } ··· 134 134 { 135 135 struct drm_device *dev = connector->base.dev; 136 136 struct drm_i915_private *dev_priv = to_i915(dev); 137 - struct intel_dvo *intel_dvo = intel_attached_dvo(&connector->base); 137 + struct intel_dvo *intel_dvo = intel_attached_dvo(connector); 138 138 u32 tmp; 139 139 140 140 tmp = I915_READ(intel_dvo->dev.dvo_reg); ··· 220 220 intel_dvo_mode_valid(struct drm_connector *connector, 221 221 struct drm_display_mode *mode) 222 222 { 223 - struct intel_dvo *intel_dvo = intel_attached_dvo(connector); 223 + struct intel_dvo *intel_dvo = intel_attached_dvo(to_intel_connector(connector)); 224 224 const struct drm_display_mode *fixed_mode = 225 225 to_intel_connector(connector)->panel.fixed_mode; 226 226 int max_dotclk = to_i915(connector->dev)->max_dotclk_freq; ··· 311 311 static enum drm_connector_status 312 312 intel_dvo_detect(struct drm_connector *connector, bool force) 313 313 { 314 - struct intel_dvo *intel_dvo = intel_attached_dvo(connector); 314 + struct intel_dvo *intel_dvo = intel_attached_dvo(to_intel_connector(connector)); 315 315 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n", 316 316 connector->base.id, connector->name); 317 317 return intel_dvo->dev.dev_ops->detect(&intel_dvo->dev);
+12 -12
drivers/gpu/drm/i915/display/intel_fifo_underrun.c
··· 126 126 } 127 127 } 128 128 129 - static void ironlake_set_fifo_underrun_reporting(struct drm_device *dev, 130 - enum pipe pipe, bool enable) 129 + static void ilk_set_fifo_underrun_reporting(struct drm_device *dev, 130 + enum pipe pipe, bool enable) 131 131 { 132 132 struct drm_i915_private *dev_priv = to_i915(dev); 133 133 u32 bit = (pipe == PIPE_A) ? ··· 139 139 ilk_disable_display_irq(dev_priv, bit); 140 140 } 141 141 142 - static void ivybridge_check_fifo_underruns(struct intel_crtc *crtc) 142 + static void ivb_check_fifo_underruns(struct intel_crtc *crtc) 143 143 { 144 144 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); 145 145 enum pipe pipe = crtc->pipe; ··· 157 157 DRM_ERROR("fifo underrun on pipe %c\n", pipe_name(pipe)); 158 158 } 159 159 160 - static void ivybridge_set_fifo_underrun_reporting(struct drm_device *dev, 161 - enum pipe pipe, 162 - bool enable, bool old) 160 + static void ivb_set_fifo_underrun_reporting(struct drm_device *dev, 161 + enum pipe pipe, bool enable, 162 + bool old) 163 163 { 164 164 struct drm_i915_private *dev_priv = to_i915(dev); 165 165 if (enable) { ··· 180 180 } 181 181 } 182 182 183 - static void broadwell_set_fifo_underrun_reporting(struct drm_device *dev, 184 - enum pipe pipe, bool enable) 183 + static void bdw_set_fifo_underrun_reporting(struct drm_device *dev, 184 + enum pipe pipe, bool enable) 185 185 { 186 186 struct drm_i915_private *dev_priv = to_i915(dev); 187 187 ··· 264 264 if (HAS_GMCH(dev_priv)) 265 265 i9xx_set_fifo_underrun_reporting(dev, pipe, enable, old); 266 266 else if (IS_GEN_RANGE(dev_priv, 5, 6)) 267 - ironlake_set_fifo_underrun_reporting(dev, pipe, enable); 267 + ilk_set_fifo_underrun_reporting(dev, pipe, enable); 268 268 else if (IS_GEN(dev_priv, 7)) 269 - ivybridge_set_fifo_underrun_reporting(dev, pipe, enable, old); 269 + ivb_set_fifo_underrun_reporting(dev, pipe, enable, old); 270 270 else if (INTEL_GEN(dev_priv) >= 8) 271 - broadwell_set_fifo_underrun_reporting(dev, pipe, enable); 271 + bdw_set_fifo_underrun_reporting(dev, pipe, enable); 272 272 273 273 return old; 274 274 } ··· 427 427 if (HAS_GMCH(dev_priv)) 428 428 i9xx_check_fifo_underruns(crtc); 429 429 else if (IS_GEN(dev_priv, 7)) 430 - ivybridge_check_fifo_underruns(crtc); 430 + ivb_check_fifo_underruns(crtc); 431 431 } 432 432 433 433 spin_unlock_irq(&dev_priv->irq_lock);
+33 -32
drivers/gpu/drm/i915/display/intel_hdmi.c
··· 85 85 "HDMI transcoder function enabled, expecting disabled\n"); 86 86 } 87 87 88 - struct intel_hdmi *enc_to_intel_hdmi(struct drm_encoder *encoder) 88 + struct intel_hdmi *enc_to_intel_hdmi(struct intel_encoder *encoder) 89 89 { 90 90 struct intel_digital_port *intel_dig_port = 91 - container_of(encoder, struct intel_digital_port, base.base); 91 + container_of(&encoder->base, struct intel_digital_port, 92 + base.base); 92 93 return &intel_dig_port->hdmi; 93 94 } 94 95 95 - static struct intel_hdmi *intel_attached_hdmi(struct drm_connector *connector) 96 + static struct intel_hdmi *intel_attached_hdmi(struct intel_connector *connector) 96 97 { 97 - return enc_to_intel_hdmi(&intel_attached_encoder(connector)->base); 98 + return enc_to_intel_hdmi(intel_attached_encoder(connector)); 98 99 } 99 100 100 101 static u32 g4x_infoframe_index(unsigned int type) ··· 603 602 const struct intel_crtc_state *crtc_state) 604 603 { 605 604 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 606 - struct intel_digital_port *dig_port = enc_to_dig_port(&encoder->base); 605 + struct intel_digital_port *dig_port = enc_to_dig_port(encoder); 607 606 u32 val, ret = 0; 608 607 int i; 609 608 ··· 647 646 enum hdmi_infoframe_type type, 648 647 const union hdmi_infoframe *frame) 649 648 { 650 - struct intel_digital_port *intel_dig_port = enc_to_dig_port(&encoder->base); 649 + struct intel_digital_port *intel_dig_port = enc_to_dig_port(encoder); 651 650 u8 buffer[VIDEO_DIP_DATA_SIZE]; 652 651 ssize_t len; 653 652 ··· 676 675 enum hdmi_infoframe_type type, 677 676 union hdmi_infoframe *frame) 678 677 { 679 - struct intel_digital_port *intel_dig_port = enc_to_dig_port(&encoder->base); 678 + struct intel_digital_port *intel_dig_port = enc_to_dig_port(encoder); 680 679 u8 buffer[VIDEO_DIP_DATA_SIZE]; 681 680 int ret; 682 681 ··· 856 855 const struct drm_connector_state *conn_state) 857 856 { 858 857 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 859 - struct intel_digital_port *intel_dig_port = enc_to_dig_port(&encoder->base); 858 + struct intel_digital_port *intel_dig_port = enc_to_dig_port(encoder); 860 859 struct intel_hdmi *intel_hdmi = &intel_dig_port->hdmi; 861 860 i915_reg_t reg = VIDEO_DIP_CTL; 862 861 u32 val = I915_READ(reg); ··· 1039 1038 { 1040 1039 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 1041 1040 struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->uapi.crtc); 1042 - struct intel_digital_port *intel_dig_port = enc_to_dig_port(&encoder->base); 1041 + struct intel_digital_port *intel_dig_port = enc_to_dig_port(encoder); 1043 1042 struct intel_hdmi *intel_hdmi = &intel_dig_port->hdmi; 1044 1043 i915_reg_t reg = TVIDEO_DIP_CTL(intel_crtc->pipe); 1045 1044 u32 val = I915_READ(reg); ··· 1098 1097 { 1099 1098 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 1100 1099 struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->uapi.crtc); 1101 - struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&encoder->base); 1100 + struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder); 1102 1101 i915_reg_t reg = TVIDEO_DIP_CTL(intel_crtc->pipe); 1103 1102 u32 val = I915_READ(reg); 1104 1103 ··· 1147 1146 { 1148 1147 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 1149 1148 struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->uapi.crtc); 1150 - struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&encoder->base); 1149 + struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder); 1151 1150 i915_reg_t reg = VLV_TVIDEO_DIP_CTL(intel_crtc->pipe); 1152 1151 u32 val = I915_READ(reg); 1153 1152 u32 port = VIDEO_DIP_PORT(encoder->port); ··· 1738 1737 struct drm_device *dev = encoder->base.dev; 1739 1738 struct drm_i915_private *dev_priv = to_i915(dev); 1740 1739 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc); 1741 - struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&encoder->base); 1740 + struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder); 1742 1741 const struct drm_display_mode *adjusted_mode = &crtc_state->hw.adjusted_mode; 1743 1742 u32 hdmi_val; 1744 1743 ··· 1775 1774 enum pipe *pipe) 1776 1775 { 1777 1776 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 1778 - struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&encoder->base); 1777 + struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder); 1779 1778 intel_wakeref_t wakeref; 1780 1779 bool ret; 1781 1780 ··· 1794 1793 static void intel_hdmi_get_config(struct intel_encoder *encoder, 1795 1794 struct intel_crtc_state *pipe_config) 1796 1795 { 1797 - struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&encoder->base); 1796 + struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder); 1798 1797 struct drm_device *dev = encoder->base.dev; 1799 1798 struct drm_i915_private *dev_priv = to_i915(dev); 1800 1799 u32 tmp, flags = 0; ··· 1875 1874 { 1876 1875 struct drm_device *dev = encoder->base.dev; 1877 1876 struct drm_i915_private *dev_priv = to_i915(dev); 1878 - struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&encoder->base); 1877 + struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder); 1879 1878 u32 temp; 1880 1879 1881 1880 temp = I915_READ(intel_hdmi->hdmi_reg); ··· 1897 1896 { 1898 1897 struct drm_device *dev = encoder->base.dev; 1899 1898 struct drm_i915_private *dev_priv = to_i915(dev); 1900 - struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&encoder->base); 1899 + struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder); 1901 1900 u32 temp; 1902 1901 1903 1902 temp = I915_READ(intel_hdmi->hdmi_reg); ··· 1948 1947 struct drm_device *dev = encoder->base.dev; 1949 1948 struct drm_i915_private *dev_priv = to_i915(dev); 1950 1949 struct intel_crtc *crtc = to_intel_crtc(pipe_config->uapi.crtc); 1951 - struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&encoder->base); 1950 + struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder); 1952 1951 enum pipe pipe = crtc->pipe; 1953 1952 u32 temp; 1954 1953 ··· 2008 2007 { 2009 2008 struct drm_device *dev = encoder->base.dev; 2010 2009 struct drm_i915_private *dev_priv = to_i915(dev); 2011 - struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&encoder->base); 2010 + struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder); 2012 2011 struct intel_digital_port *intel_dig_port = 2013 2012 hdmi_to_dig_port(intel_hdmi); 2014 2013 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->uapi.crtc); ··· 2161 2160 intel_hdmi_mode_valid(struct drm_connector *connector, 2162 2161 struct drm_display_mode *mode) 2163 2162 { 2164 - struct intel_hdmi *hdmi = intel_attached_hdmi(connector); 2163 + struct intel_hdmi *hdmi = intel_attached_hdmi(to_intel_connector(connector)); 2165 2164 struct drm_device *dev = intel_hdmi_to_dev(hdmi); 2166 2165 struct drm_i915_private *dev_priv = to_i915(dev); 2167 2166 enum drm_mode_status status; ··· 2317 2316 struct intel_crtc_state *crtc_state, 2318 2317 int clock, bool force_dvi) 2319 2318 { 2320 - struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&encoder->base); 2319 + struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder); 2321 2320 int bpc; 2322 2321 2323 2322 for (bpc = 12; bpc >= 10; bpc -= 2) { ··· 2335 2334 struct intel_crtc_state *crtc_state, 2336 2335 bool force_dvi) 2337 2336 { 2338 - struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&encoder->base); 2337 + struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder); 2339 2338 const struct drm_display_mode *adjusted_mode = 2340 2339 &crtc_state->hw.adjusted_mode; 2341 2340 int bpc, clock = adjusted_mode->crtc_clock; ··· 2405 2404 struct intel_crtc_state *pipe_config, 2406 2405 struct drm_connector_state *conn_state) 2407 2406 { 2408 - struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&encoder->base); 2407 + struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder); 2409 2408 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 2410 2409 struct drm_display_mode *adjusted_mode = &pipe_config->hw.adjusted_mode; 2411 2410 struct drm_connector *connector = conn_state->connector; ··· 2497 2496 static void 2498 2497 intel_hdmi_unset_edid(struct drm_connector *connector) 2499 2498 { 2500 - struct intel_hdmi *intel_hdmi = intel_attached_hdmi(connector); 2499 + struct intel_hdmi *intel_hdmi = intel_attached_hdmi(to_intel_connector(connector)); 2501 2500 2502 2501 intel_hdmi->has_hdmi_sink = false; 2503 2502 intel_hdmi->has_audio = false; ··· 2513 2512 intel_hdmi_dp_dual_mode_detect(struct drm_connector *connector, bool has_edid) 2514 2513 { 2515 2514 struct drm_i915_private *dev_priv = to_i915(connector->dev); 2516 - struct intel_hdmi *hdmi = intel_attached_hdmi(connector); 2515 + struct intel_hdmi *hdmi = intel_attached_hdmi(to_intel_connector(connector)); 2517 2516 enum port port = hdmi_to_dig_port(hdmi)->base.port; 2518 2517 struct i2c_adapter *adapter = 2519 2518 intel_gmbus_get_adapter(dev_priv, hdmi->ddc_bus); ··· 2560 2559 intel_hdmi_set_edid(struct drm_connector *connector) 2561 2560 { 2562 2561 struct drm_i915_private *dev_priv = to_i915(connector->dev); 2563 - struct intel_hdmi *intel_hdmi = intel_attached_hdmi(connector); 2562 + struct intel_hdmi *intel_hdmi = intel_attached_hdmi(to_intel_connector(connector)); 2564 2563 intel_wakeref_t wakeref; 2565 2564 struct edid *edid; 2566 2565 bool connected = false; ··· 2601 2600 { 2602 2601 enum drm_connector_status status = connector_status_disconnected; 2603 2602 struct drm_i915_private *dev_priv = to_i915(connector->dev); 2604 - struct intel_hdmi *intel_hdmi = intel_attached_hdmi(connector); 2603 + struct intel_hdmi *intel_hdmi = intel_attached_hdmi(to_intel_connector(connector)); 2605 2604 struct intel_encoder *encoder = &hdmi_to_dig_port(intel_hdmi)->base; 2606 2605 intel_wakeref_t wakeref; 2607 2606 ··· 2664 2663 const struct drm_connector_state *conn_state) 2665 2664 { 2666 2665 struct intel_digital_port *intel_dig_port = 2667 - enc_to_dig_port(&encoder->base); 2666 + enc_to_dig_port(encoder); 2668 2667 2669 2668 intel_hdmi_prepare(encoder, pipe_config); 2670 2669 ··· 2677 2676 const struct intel_crtc_state *pipe_config, 2678 2677 const struct drm_connector_state *conn_state) 2679 2678 { 2680 - struct intel_digital_port *dport = enc_to_dig_port(&encoder->base); 2679 + struct intel_digital_port *dport = enc_to_dig_port(encoder); 2681 2680 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 2682 2681 2683 2682 vlv_phy_pre_encoder_enable(encoder, pipe_config); ··· 2747 2746 const struct intel_crtc_state *pipe_config, 2748 2747 const struct drm_connector_state *conn_state) 2749 2748 { 2750 - struct intel_digital_port *dport = enc_to_dig_port(&encoder->base); 2749 + struct intel_digital_port *dport = enc_to_dig_port(encoder); 2751 2750 struct drm_device *dev = encoder->base.dev; 2752 2751 struct drm_i915_private *dev_priv = to_i915(dev); 2753 2752 ··· 2773 2772 intel_hdmi_get_i2c_adapter(struct drm_connector *connector) 2774 2773 { 2775 2774 struct drm_i915_private *dev_priv = to_i915(connector->dev); 2776 - struct intel_hdmi *intel_hdmi = intel_attached_hdmi(connector); 2775 + struct intel_hdmi *intel_hdmi = intel_attached_hdmi(to_intel_connector(connector)); 2777 2776 2778 2777 return intel_gmbus_get_adapter(dev_priv, intel_hdmi->ddc_bus); 2779 2778 } ··· 2817 2816 2818 2817 static void intel_hdmi_destroy(struct drm_connector *connector) 2819 2818 { 2820 - struct cec_notifier *n = intel_attached_hdmi(connector)->cec_notifier; 2819 + struct cec_notifier *n = intel_attached_hdmi(to_intel_connector(connector))->cec_notifier; 2821 2820 2822 2821 cec_notifier_conn_unregister(n); 2823 2822 ··· 2907 2906 bool scrambling) 2908 2907 { 2909 2908 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 2910 - struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&encoder->base); 2909 + struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder); 2911 2910 struct drm_scrambling *sink_scrambling = 2912 2911 &connector->display_info.hdmi.scdc.scrambling; 2913 2912 struct i2c_adapter *adapter =
+1 -1
drivers/gpu/drm/i915/display/intel_hdmi.h
··· 29 29 enum port port); 30 30 void intel_hdmi_init_connector(struct intel_digital_port *intel_dig_port, 31 31 struct intel_connector *intel_connector); 32 - struct intel_hdmi *enc_to_intel_hdmi(struct drm_encoder *encoder); 32 + struct intel_hdmi *enc_to_intel_hdmi(struct intel_encoder *encoder); 33 33 int intel_hdmi_compute_config(struct intel_encoder *encoder, 34 34 struct intel_crtc_state *pipe_config, 35 35 struct drm_connector_state *conn_state);
+2 -2
drivers/gpu/drm/i915/display/intel_hotplug.c
··· 302 302 static bool intel_encoder_has_hpd_pulse(struct intel_encoder *encoder) 303 303 { 304 304 return intel_encoder_is_dig_port(encoder) && 305 - enc_to_dig_port(&encoder->base)->hpd_pulse != NULL; 305 + enc_to_dig_port(encoder)->hpd_pulse != NULL; 306 306 } 307 307 308 308 static void i915_digport_work_func(struct work_struct *work) ··· 335 335 if (!long_hpd && !short_hpd) 336 336 continue; 337 337 338 - dig_port = enc_to_dig_port(&encoder->base); 338 + dig_port = enc_to_dig_port(encoder); 339 339 340 340 ret = dig_port->hpd_pulse(dig_port, long_hpd); 341 341 if (ret == IRQ_NONE) {
+4 -4
drivers/gpu/drm/i915/display/intel_lspcon.c
··· 434 434 const void *frame, ssize_t len) 435 435 { 436 436 bool ret; 437 - struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base); 438 - struct intel_lspcon *lspcon = enc_to_intel_lspcon(&encoder->base); 437 + struct intel_dp *intel_dp = enc_to_intel_dp(encoder); 438 + struct intel_lspcon *lspcon = enc_to_intel_lspcon(encoder); 439 439 440 440 /* LSPCON only needs AVI IF */ 441 441 if (type != HDMI_INFOFRAME_TYPE_AVI) ··· 472 472 ssize_t ret; 473 473 union hdmi_infoframe frame; 474 474 u8 buf[VIDEO_DIP_DATA_SIZE]; 475 - struct intel_digital_port *dig_port = enc_to_dig_port(&encoder->base); 475 + struct intel_digital_port *dig_port = enc_to_dig_port(encoder); 476 476 struct intel_lspcon *lspcon = &dig_port->lspcon; 477 477 const struct drm_display_mode *adjusted_mode = 478 478 &crtc_state->hw.adjusted_mode; ··· 522 522 const struct intel_crtc_state *pipe_config) 523 523 { 524 524 /* FIXME actually read this from the hw */ 525 - return enc_to_intel_lspcon(&encoder->base)->active; 525 + return enc_to_intel_lspcon(encoder)->active; 526 526 } 527 527 528 528 void lspcon_resume(struct intel_lspcon *lspcon)
+1 -1
drivers/gpu/drm/i915/display/intel_pipe_crc.c
··· 98 98 break; 99 99 case INTEL_OUTPUT_DP: 100 100 case INTEL_OUTPUT_EDP: 101 - dig_port = enc_to_dig_port(&encoder->base); 101 + dig_port = enc_to_dig_port(encoder); 102 102 switch (dig_port->base.port) { 103 103 case PORT_B: 104 104 *source = INTEL_PIPE_CRC_SOURCE_DP_B;
+24
drivers/gpu/drm/i915/display/intel_psr.c
··· 1523 1523 1524 1524 return ret; 1525 1525 } 1526 + 1527 + void intel_psr_atomic_check(struct drm_connector *connector, 1528 + struct drm_connector_state *old_state, 1529 + struct drm_connector_state *new_state) 1530 + { 1531 + struct drm_i915_private *dev_priv = to_i915(connector->dev); 1532 + struct intel_connector *intel_connector; 1533 + struct intel_digital_port *dig_port; 1534 + struct drm_crtc_state *crtc_state; 1535 + 1536 + if (!CAN_PSR(dev_priv) || !new_state->crtc || 1537 + dev_priv->psr.initially_probed) 1538 + return; 1539 + 1540 + intel_connector = to_intel_connector(connector); 1541 + dig_port = enc_to_dig_port(intel_connector->encoder); 1542 + if (dev_priv->psr.dp != &dig_port->dp) 1543 + return; 1544 + 1545 + crtc_state = drm_atomic_get_new_crtc_state(new_state->state, 1546 + new_state->crtc); 1547 + crtc_state->mode_changed = true; 1548 + dev_priv->psr.initially_probed = true; 1549 + }
+5
drivers/gpu/drm/i915/display/intel_psr.h
··· 8 8 9 9 #include "intel_frontbuffer.h" 10 10 11 + struct drm_connector; 12 + struct drm_connector_state; 11 13 struct drm_i915_private; 12 14 struct intel_crtc_state; 13 15 struct intel_dp; ··· 37 35 int intel_psr_wait_for_idle(const struct intel_crtc_state *new_crtc_state, 38 36 u32 *out_value); 39 37 bool intel_psr_enabled(struct intel_dp *intel_dp); 38 + void intel_psr_atomic_check(struct drm_connector *connector, 39 + struct drm_connector_state *old_state, 40 + struct drm_connector_state *new_state); 40 41 41 42 #endif /* __INTEL_PSR_H__ */
+11 -11
drivers/gpu/drm/i915/display/intel_sdvo.c
··· 180 180 return container_of(encoder, struct intel_sdvo, base); 181 181 } 182 182 183 - static struct intel_sdvo *intel_attached_sdvo(struct drm_connector *connector) 183 + static struct intel_sdvo *intel_attached_sdvo(struct intel_connector *connector) 184 184 { 185 185 return to_sdvo(intel_attached_encoder(connector)); 186 186 } ··· 1551 1551 { 1552 1552 struct intel_sdvo_connector *intel_sdvo_connector = 1553 1553 to_intel_sdvo_connector(&connector->base); 1554 - struct intel_sdvo *intel_sdvo = intel_attached_sdvo(&connector->base); 1554 + struct intel_sdvo *intel_sdvo = intel_attached_sdvo(connector); 1555 1555 u16 active_outputs = 0; 1556 1556 1557 1557 intel_sdvo_get_active_outputs(intel_sdvo, &active_outputs); ··· 1823 1823 intel_sdvo_mode_valid(struct drm_connector *connector, 1824 1824 struct drm_display_mode *mode) 1825 1825 { 1826 - struct intel_sdvo *intel_sdvo = intel_attached_sdvo(connector); 1826 + struct intel_sdvo *intel_sdvo = intel_attached_sdvo(to_intel_connector(connector)); 1827 1827 struct intel_sdvo_connector *intel_sdvo_connector = 1828 1828 to_intel_sdvo_connector(connector); 1829 1829 int max_dotclk = to_i915(connector->dev)->max_dotclk_freq; ··· 1941 1941 static struct edid * 1942 1942 intel_sdvo_get_edid(struct drm_connector *connector) 1943 1943 { 1944 - struct intel_sdvo *sdvo = intel_attached_sdvo(connector); 1944 + struct intel_sdvo *sdvo = intel_attached_sdvo(to_intel_connector(connector)); 1945 1945 return drm_get_edid(connector, &sdvo->ddc); 1946 1946 } 1947 1947 ··· 1959 1959 static enum drm_connector_status 1960 1960 intel_sdvo_tmds_sink_detect(struct drm_connector *connector) 1961 1961 { 1962 - struct intel_sdvo *intel_sdvo = intel_attached_sdvo(connector); 1962 + struct intel_sdvo *intel_sdvo = intel_attached_sdvo(to_intel_connector(connector)); 1963 1963 struct intel_sdvo_connector *intel_sdvo_connector = 1964 1964 to_intel_sdvo_connector(connector); 1965 1965 enum drm_connector_status status; ··· 2028 2028 intel_sdvo_detect(struct drm_connector *connector, bool force) 2029 2029 { 2030 2030 u16 response; 2031 - struct intel_sdvo *intel_sdvo = intel_attached_sdvo(connector); 2031 + struct intel_sdvo *intel_sdvo = intel_attached_sdvo(to_intel_connector(connector)); 2032 2032 struct intel_sdvo_connector *intel_sdvo_connector = to_intel_sdvo_connector(connector); 2033 2033 enum drm_connector_status ret; 2034 2034 ··· 2175 2175 2176 2176 static void intel_sdvo_get_tv_modes(struct drm_connector *connector) 2177 2177 { 2178 - struct intel_sdvo *intel_sdvo = intel_attached_sdvo(connector); 2178 + struct intel_sdvo *intel_sdvo = intel_attached_sdvo(to_intel_connector(connector)); 2179 2179 const struct drm_connector_state *conn_state = connector->state; 2180 2180 struct intel_sdvo_sdtv_resolution_request tv_res; 2181 2181 u32 reply = 0, format_map = 0; ··· 2215 2215 2216 2216 static void intel_sdvo_get_lvds_modes(struct drm_connector *connector) 2217 2217 { 2218 - struct intel_sdvo *intel_sdvo = intel_attached_sdvo(connector); 2218 + struct intel_sdvo *intel_sdvo = intel_attached_sdvo(to_intel_connector(connector)); 2219 2219 struct drm_i915_private *dev_priv = to_i915(connector->dev); 2220 2220 struct drm_display_mode *newmode; 2221 2221 ··· 2379 2379 static int 2380 2380 intel_sdvo_connector_register(struct drm_connector *connector) 2381 2381 { 2382 - struct intel_sdvo *sdvo = intel_attached_sdvo(connector); 2382 + struct intel_sdvo *sdvo = intel_attached_sdvo(to_intel_connector(connector)); 2383 2383 int ret; 2384 2384 2385 2385 ret = intel_connector_register(connector); ··· 2394 2394 static void 2395 2395 intel_sdvo_connector_unregister(struct drm_connector *connector) 2396 2396 { 2397 - struct intel_sdvo *sdvo = intel_attached_sdvo(connector); 2397 + struct intel_sdvo *sdvo = intel_attached_sdvo(to_intel_connector(connector)); 2398 2398 2399 2399 sysfs_remove_link(&connector->kdev->kobj, 2400 2400 sdvo->ddc.dev.kobj.name); ··· 2932 2932 2933 2933 list_for_each_entry_safe(connector, tmp, 2934 2934 &dev->mode_config.connector_list, head) { 2935 - if (intel_attached_encoder(connector) == &intel_sdvo->base) { 2935 + if (intel_attached_encoder(to_intel_connector(connector)) == &intel_sdvo->base) { 2936 2936 drm_connector_unregister(connector); 2937 2937 intel_connector_destroy(connector); 2938 2938 }
+44 -11
drivers/gpu/drm/i915/display/intel_sprite.c
··· 583 583 const struct drm_intel_sprite_colorkey *key = &plane_state->ckey; 584 584 u32 surf_addr = plane_state->color_plane[color_plane].offset; 585 585 u32 stride = skl_plane_stride(plane_state, color_plane); 586 - u32 aux_dist = plane_state->color_plane[1].offset - surf_addr; 587 - u32 aux_stride = skl_plane_stride(plane_state, 1); 586 + const struct drm_framebuffer *fb = plane_state->hw.fb; 587 + int aux_plane = intel_main_to_aux_plane(fb, color_plane); 588 + u32 aux_dist = plane_state->color_plane[aux_plane].offset - surf_addr; 589 + u32 aux_stride = skl_plane_stride(plane_state, aux_plane); 588 590 int crtc_x = plane_state->uapi.dst.x1; 589 591 int crtc_y = plane_state->uapi.dst.y1; 590 592 u32 x = plane_state->color_plane[color_plane].x; 591 593 u32 y = plane_state->color_plane[color_plane].y; 592 594 u32 src_w = drm_rect_width(&plane_state->uapi.src) >> 16; 593 595 u32 src_h = drm_rect_height(&plane_state->uapi.src) >> 16; 594 - const struct drm_framebuffer *fb = plane_state->hw.fb; 595 596 u8 alpha = plane_state->hw.alpha >> 8; 596 597 u32 plane_color_ctl = 0; 597 598 unsigned long irqflags; ··· 2107 2106 fb->modifier == I915_FORMAT_MOD_Yf_TILED || 2108 2107 fb->modifier == I915_FORMAT_MOD_Y_TILED_CCS || 2109 2108 fb->modifier == I915_FORMAT_MOD_Yf_TILED_CCS || 2110 - fb->modifier == I915_FORMAT_MOD_Y_TILED_GEN12_RC_CCS)) { 2109 + fb->modifier == I915_FORMAT_MOD_Y_TILED_GEN12_RC_CCS || 2110 + fb->modifier == I915_FORMAT_MOD_Y_TILED_GEN12_MC_CCS)) { 2111 2111 DRM_DEBUG_KMS("Y/Yf tiling not supported in IF-ID mode\n"); 2112 2112 return -EINVAL; 2113 2113 } ··· 2580 2578 DRM_FORMAT_MOD_INVALID 2581 2579 }; 2582 2580 2583 - static const u64 gen12_plane_format_modifiers_ccs[] = { 2581 + static const u64 gen12_plane_format_modifiers_mc_ccs[] = { 2582 + I915_FORMAT_MOD_Y_TILED_GEN12_MC_CCS, 2583 + I915_FORMAT_MOD_Y_TILED_GEN12_RC_CCS, 2584 + I915_FORMAT_MOD_Y_TILED, 2585 + I915_FORMAT_MOD_X_TILED, 2586 + DRM_FORMAT_MOD_LINEAR, 2587 + DRM_FORMAT_MOD_INVALID 2588 + }; 2589 + 2590 + static const u64 gen12_plane_format_modifiers_rc_ccs[] = { 2584 2591 I915_FORMAT_MOD_Y_TILED_GEN12_RC_CCS, 2585 2592 I915_FORMAT_MOD_Y_TILED, 2586 2593 I915_FORMAT_MOD_X_TILED, ··· 2754 2743 } 2755 2744 } 2756 2745 2746 + static bool gen12_plane_supports_mc_ccs(enum plane_id plane_id) 2747 + { 2748 + return plane_id < PLANE_SPRITE4; 2749 + } 2750 + 2757 2751 static bool gen12_plane_format_mod_supported(struct drm_plane *_plane, 2758 2752 u32 format, u64 modifier) 2759 2753 { 2754 + struct intel_plane *plane = to_intel_plane(_plane); 2755 + 2760 2756 switch (modifier) { 2757 + case I915_FORMAT_MOD_Y_TILED_GEN12_MC_CCS: 2758 + if (!gen12_plane_supports_mc_ccs(plane->id)) 2759 + return false; 2760 + /* fall through */ 2761 2761 case DRM_FORMAT_MOD_LINEAR: 2762 2762 case I915_FORMAT_MOD_X_TILED: 2763 2763 case I915_FORMAT_MOD_Y_TILED: ··· 2786 2764 if (is_ccs_modifier(modifier)) 2787 2765 return true; 2788 2766 /* fall through */ 2789 - case DRM_FORMAT_RGB565: 2790 - case DRM_FORMAT_XRGB2101010: 2791 - case DRM_FORMAT_XBGR2101010: 2792 - case DRM_FORMAT_ARGB2101010: 2793 - case DRM_FORMAT_ABGR2101010: 2794 2767 case DRM_FORMAT_YUYV: 2795 2768 case DRM_FORMAT_YVYU: 2796 2769 case DRM_FORMAT_UYVY: ··· 2794 2777 case DRM_FORMAT_P010: 2795 2778 case DRM_FORMAT_P012: 2796 2779 case DRM_FORMAT_P016: 2780 + if (modifier == I915_FORMAT_MOD_Y_TILED_GEN12_MC_CCS) 2781 + return true; 2782 + /* fall through */ 2783 + case DRM_FORMAT_RGB565: 2784 + case DRM_FORMAT_XRGB2101010: 2785 + case DRM_FORMAT_XBGR2101010: 2786 + case DRM_FORMAT_ARGB2101010: 2787 + case DRM_FORMAT_ABGR2101010: 2797 2788 case DRM_FORMAT_XVYU2101010: 2798 2789 case DRM_FORMAT_C8: 2799 2790 case DRM_FORMAT_XBGR16161616F: ··· 2935 2910 } 2936 2911 } 2937 2912 2913 + static const u64 *gen12_get_plane_modifiers(enum plane_id plane_id) 2914 + { 2915 + if (gen12_plane_supports_mc_ccs(plane_id)) 2916 + return gen12_plane_format_modifiers_mc_ccs; 2917 + else 2918 + return gen12_plane_format_modifiers_rc_ccs; 2919 + } 2920 + 2938 2921 static bool skl_plane_has_ccs(struct drm_i915_private *dev_priv, 2939 2922 enum pipe pipe, enum plane_id plane_id) 2940 2923 { ··· 3008 2975 3009 2976 plane->has_ccs = skl_plane_has_ccs(dev_priv, pipe, plane_id); 3010 2977 if (INTEL_GEN(dev_priv) >= 12) { 3011 - modifiers = gen12_plane_format_modifiers_ccs; 2978 + modifiers = gen12_get_plane_modifiers(plane_id); 3012 2979 plane_funcs = &gen12_plane_funcs; 3013 2980 } else { 3014 2981 if (plane->has_ccs)
+4 -4
drivers/gpu/drm/i915/display/intel_tv.c
··· 898 898 return container_of(encoder, struct intel_tv, base); 899 899 } 900 900 901 - static struct intel_tv *intel_attached_tv(struct drm_connector *connector) 901 + static struct intel_tv *intel_attached_tv(struct intel_connector *connector) 902 902 { 903 903 return enc_to_tv(intel_attached_encoder(connector)); 904 904 } ··· 1527 1527 ((video_levels->black << TV_BLACK_LEVEL_SHIFT) | 1528 1528 (video_levels->blank << TV_BLANK_LEVEL_SHIFT))); 1529 1529 1530 - assert_pipe_disabled(dev_priv, intel_crtc->pipe); 1530 + assert_pipe_disabled(dev_priv, pipe_config->cpu_transcoder); 1531 1531 1532 1532 /* Filter ctl must be set before TV_WIN_SIZE */ 1533 1533 tv_filter_ctl = TV_AUTO_SCALE; ··· 1662 1662 */ 1663 1663 static void intel_tv_find_better_format(struct drm_connector *connector) 1664 1664 { 1665 - struct intel_tv *intel_tv = intel_attached_tv(connector); 1665 + struct intel_tv *intel_tv = intel_attached_tv(to_intel_connector(connector)); 1666 1666 const struct tv_mode *tv_mode = intel_tv_mode_find(connector->state); 1667 1667 int i; 1668 1668 ··· 1689 1689 struct drm_modeset_acquire_ctx *ctx, 1690 1690 bool force) 1691 1691 { 1692 - struct intel_tv *intel_tv = intel_attached_tv(connector); 1692 + struct intel_tv *intel_tv = intel_attached_tv(to_intel_connector(connector)); 1693 1693 enum drm_connector_status status; 1694 1694 int type; 1695 1695
+2 -2
drivers/gpu/drm/i915/display/intel_vdsc.c
··· 943 943 const struct intel_crtc_state *crtc_state) 944 944 { 945 945 const struct drm_dsc_config *vdsc_cfg = &crtc_state->dsc.config; 946 - struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base); 946 + struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder); 947 947 struct mipi_dsi_device *dsi; 948 948 struct drm_dsc_picture_parameter_set pps; 949 949 enum port port; ··· 961 961 static void intel_dsc_dp_pps_write(struct intel_encoder *encoder, 962 962 const struct intel_crtc_state *crtc_state) 963 963 { 964 - struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base); 964 + struct intel_dp *intel_dp = enc_to_intel_dp(encoder); 965 965 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp); 966 966 const struct drm_dsc_config *vdsc_cfg = &crtc_state->dsc.config; 967 967 struct drm_dsc_pps_infoframe dp_dsc_pps_sdp;
+23 -44
drivers/gpu/drm/i915/display/vlv_dsi.c
··· 23 23 * Author: Jani Nikula <jani.nikula@intel.com> 24 24 */ 25 25 26 - #include <linux/gpio/consumer.h> 27 26 #include <linux/slab.h> 28 27 29 28 #include <drm/drm_atomic_helper.h> ··· 318 319 static bool glk_dsi_enable_io(struct intel_encoder *encoder) 319 320 { 320 321 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 321 - struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base); 322 + struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder); 322 323 enum port port; 323 324 u32 tmp; 324 325 bool cold_boot = false; ··· 366 367 static void glk_dsi_device_ready(struct intel_encoder *encoder) 367 368 { 368 369 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 369 - struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base); 370 + struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder); 370 371 enum port port; 371 372 u32 val; 372 373 ··· 437 438 static void bxt_dsi_device_ready(struct intel_encoder *encoder) 438 439 { 439 440 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 440 - struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base); 441 + struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder); 441 442 enum port port; 442 443 u32 val; 443 444 ··· 464 465 static void vlv_dsi_device_ready(struct intel_encoder *encoder) 465 466 { 466 467 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 467 - struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base); 468 + struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder); 468 469 enum port port; 469 470 u32 val; 470 471 ··· 515 516 static void glk_dsi_enter_low_power_mode(struct intel_encoder *encoder) 516 517 { 517 518 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 518 - struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base); 519 + struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder); 519 520 enum port port; 520 521 u32 val; 521 522 ··· 545 546 static void glk_dsi_disable_mipi_io(struct intel_encoder *encoder) 546 547 { 547 548 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 548 - struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base); 549 + struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder); 549 550 enum port port; 550 551 u32 tmp; 551 552 ··· 578 579 static void vlv_dsi_clear_device_ready(struct intel_encoder *encoder) 579 580 { 580 581 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 581 - struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base); 582 + struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder); 582 583 enum port port; 583 584 584 585 DRM_DEBUG_KMS("\n"); ··· 624 625 { 625 626 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 626 627 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc); 627 - struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base); 628 + struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder); 628 629 enum port port; 629 630 630 631 if (intel_dsi->dual_link == DSI_DUAL_LINK_FRONT_BACK) { ··· 680 681 { 681 682 struct drm_device *dev = encoder->base.dev; 682 683 struct drm_i915_private *dev_priv = to_i915(dev); 683 - struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base); 684 + struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder); 684 685 enum port port; 685 686 686 687 for_each_dsi_port(port, intel_dsi->ports) { ··· 744 745 const struct intel_crtc_state *pipe_config, 745 746 const struct drm_connector_state *conn_state) 746 747 { 747 - struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base); 748 + struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder); 748 749 struct drm_crtc *crtc = pipe_config->uapi.crtc; 749 750 struct drm_i915_private *dev_priv = to_i915(crtc->dev); 750 751 struct intel_crtc *intel_crtc = to_intel_crtc(crtc); ··· 792 793 if (!IS_GEMINILAKE(dev_priv)) 793 794 intel_dsi_prepare(encoder, pipe_config); 794 795 795 - /* Power on, try both CRC pmic gpio and VBT */ 796 - if (intel_dsi->gpio_panel) 797 - gpiod_set_value_cansleep(intel_dsi->gpio_panel, 1); 798 796 intel_dsi_vbt_exec_sequence(intel_dsi, MIPI_SEQ_POWER_ON); 799 797 intel_dsi_msleep(intel_dsi, intel_dsi->panel_on_delay); 800 798 ··· 846 850 const struct intel_crtc_state *old_crtc_state, 847 851 const struct drm_connector_state *old_conn_state) 848 852 { 849 - struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base); 853 + struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder); 850 854 enum port port; 851 855 852 856 DRM_DEBUG_KMS("\n"); ··· 882 886 const struct drm_connector_state *old_conn_state) 883 887 { 884 888 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 885 - struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base); 889 + struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder); 886 890 enum port port; 887 891 u32 val; 888 892 ··· 891 895 if (IS_GEN9_LP(dev_priv)) { 892 896 intel_crtc_vblank_off(old_crtc_state); 893 897 894 - skylake_scaler_disable(old_crtc_state); 898 + skl_scaler_disable(old_crtc_state); 895 899 } 896 900 897 901 if (is_vid_mode(intel_dsi)) { ··· 941 945 /* Assert reset */ 942 946 intel_dsi_vbt_exec_sequence(intel_dsi, MIPI_SEQ_ASSERT_RESET); 943 947 944 - /* Power off, try both CRC pmic gpio and VBT */ 945 948 intel_dsi_msleep(intel_dsi, intel_dsi->panel_off_delay); 946 949 intel_dsi_vbt_exec_sequence(intel_dsi, MIPI_SEQ_POWER_OFF); 947 - if (intel_dsi->gpio_panel) 948 - gpiod_set_value_cansleep(intel_dsi->gpio_panel, 0); 949 950 950 951 /* 951 952 * FIXME As we do with eDP, just make a note of the time here ··· 955 962 enum pipe *pipe) 956 963 { 957 964 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 958 - struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base); 965 + struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder); 959 966 intel_wakeref_t wakeref; 960 967 enum port port; 961 968 bool active = false; ··· 1034 1041 &pipe_config->hw.adjusted_mode; 1035 1042 struct drm_display_mode *adjusted_mode_sw; 1036 1043 struct intel_crtc *crtc = to_intel_crtc(pipe_config->uapi.crtc); 1037 - struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base); 1044 + struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder); 1038 1045 unsigned int lane_count = intel_dsi->lane_count; 1039 1046 unsigned int bpp, fmt; 1040 1047 enum port port; ··· 1227 1234 { 1228 1235 struct drm_device *dev = encoder->dev; 1229 1236 struct drm_i915_private *dev_priv = to_i915(dev); 1230 - struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder); 1237 + struct intel_dsi *intel_dsi = enc_to_intel_dsi(to_intel_encoder(encoder)); 1231 1238 enum port port; 1232 1239 unsigned int bpp = mipi_dsi_pixel_format_to_bpp(intel_dsi->pixel_format); 1233 1240 unsigned int lane_count = intel_dsi->lane_count; ··· 1315 1322 struct drm_device *dev = encoder->dev; 1316 1323 struct drm_i915_private *dev_priv = to_i915(dev); 1317 1324 struct intel_crtc *intel_crtc = to_intel_crtc(pipe_config->uapi.crtc); 1318 - struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder); 1325 + struct intel_dsi *intel_dsi = enc_to_intel_dsi(to_intel_encoder(encoder)); 1319 1326 const struct drm_display_mode *adjusted_mode = &pipe_config->hw.adjusted_mode; 1320 1327 enum port port; 1321 1328 unsigned int bpp = mipi_dsi_pixel_format_to_bpp(intel_dsi->pixel_format); ··· 1505 1512 static void intel_dsi_unprepare(struct intel_encoder *encoder) 1506 1513 { 1507 1514 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 1508 - struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base); 1515 + struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder); 1509 1516 enum port port; 1510 1517 u32 val; 1511 1518 ··· 1532 1539 1533 1540 static void intel_dsi_encoder_destroy(struct drm_encoder *encoder) 1534 1541 { 1535 - struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder); 1542 + struct intel_dsi *intel_dsi = enc_to_intel_dsi(to_intel_encoder(encoder)); 1536 1543 1537 - /* dispose of the gpios */ 1538 - if (intel_dsi->gpio_panel) 1539 - gpiod_put(intel_dsi->gpio_panel); 1540 - 1544 + intel_dsi_vbt_gpio_cleanup(intel_dsi); 1541 1545 intel_encoder_destroy(encoder); 1542 1546 } 1543 1547 ··· 1815 1825 struct drm_connector *connector; 1816 1826 struct drm_display_mode *current_mode, *fixed_mode; 1817 1827 enum port port; 1828 + enum pipe pipe; 1818 1829 1819 1830 DRM_DEBUG_KMS("\n"); 1820 1831 ··· 1914 1923 1915 1924 vlv_dphy_param_init(intel_dsi); 1916 1925 1917 - /* 1918 - * In case of BYT with CRC PMIC, we need to use GPIO for 1919 - * Panel control. 1920 - */ 1921 - if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) && 1922 - (dev_priv->vbt.dsi.config->pwm_blc == PPS_BLC_PMIC)) { 1923 - intel_dsi->gpio_panel = 1924 - gpiod_get(dev->dev, "panel", GPIOD_OUT_HIGH); 1925 - 1926 - if (IS_ERR(intel_dsi->gpio_panel)) { 1927 - DRM_ERROR("Failed to own gpio for panel control\n"); 1928 - intel_dsi->gpio_panel = NULL; 1929 - } 1930 - } 1926 + intel_dsi_vbt_gpio_init(intel_dsi, 1927 + intel_dsi_get_hw_state(intel_encoder, &pipe)); 1931 1928 1932 1929 drm_connector_init(dev, connector, &intel_dsi_connector_funcs, 1933 1930 DRM_MODE_CONNECTOR_DSI);
+6 -6
drivers/gpu/drm/i915/display/vlv_dsi_pll.c
··· 117 117 struct intel_crtc_state *config) 118 118 { 119 119 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 120 - struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base); 120 + struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder); 121 121 int ret; 122 122 u32 dsi_clk; 123 123 ··· 255 255 struct intel_crtc_state *config) 256 256 { 257 257 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 258 - struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base); 258 + struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder); 259 259 int bpp = mipi_dsi_pixel_format_to_bpp(intel_dsi->pixel_format); 260 260 u32 dsi_clock, pclk; 261 261 u32 pll_ctl, pll_div; ··· 321 321 u32 pclk; 322 322 u32 dsi_clk; 323 323 u32 dsi_ratio; 324 - struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base); 324 + struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder); 325 325 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 326 326 int bpp = mipi_dsi_pixel_format_to_bpp(intel_dsi->pixel_format); 327 327 ··· 341 341 { 342 342 u32 temp; 343 343 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 344 - struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base); 344 + struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder); 345 345 346 346 temp = I915_READ(MIPI_CTRL(port)); 347 347 temp &= ~ESCAPE_CLOCK_DIVIDER_MASK; ··· 455 455 struct intel_crtc_state *config) 456 456 { 457 457 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 458 - struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base); 458 + struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder); 459 459 u8 dsi_ratio, dsi_ratio_min, dsi_ratio_max; 460 460 u32 dsi_clk; 461 461 ··· 503 503 const struct intel_crtc_state *config) 504 504 { 505 505 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 506 - struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base); 506 + struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder); 507 507 enum port port; 508 508 u32 val; 509 509
-5
drivers/gpu/drm/i915/gem/Makefile
··· 1 - # For building individual subdir files on the command line 2 - subdir-ccflags-y += -I$(srctree)/$(src)/.. 3 - 4 - # Extra header tests 5 - header-test-pattern-$(CONFIG_DRM_I915_WERROR) := *.h
+30 -37
drivers/gpu/drm/i915/gem/i915_gem_context.c
··· 69 69 70 70 #include <drm/i915_drm.h> 71 71 72 + #include "gt/gen6_ppgtt.h" 72 73 #include "gt/intel_context.h" 73 74 #include "gt/intel_engine_heartbeat.h" 74 75 #include "gt/intel_engine_pm.h" ··· 706 705 if (HAS_FULL_PPGTT(i915)) { 707 706 struct i915_ppgtt *ppgtt; 708 707 709 - ppgtt = i915_ppgtt_create(i915); 708 + ppgtt = i915_ppgtt_create(&i915->gt); 710 709 if (IS_ERR(ppgtt)) { 711 710 DRM_DEBUG_DRIVER("PPGTT setup failed (%ld)\n", 712 711 PTR_ERR(ppgtt)); ··· 761 760 flush_work(&i915->gem.contexts.free_work); 762 761 } 763 762 764 - static int context_idr_cleanup(int id, void *p, void *data) 765 - { 766 - context_close(p); 767 - return 0; 768 - } 769 - 770 763 static int vm_idr_cleanup(int id, void *p, void *data) 771 764 { 772 765 i915_vm_put(p); ··· 768 773 } 769 774 770 775 static int gem_context_register(struct i915_gem_context *ctx, 771 - struct drm_i915_file_private *fpriv) 776 + struct drm_i915_file_private *fpriv, 777 + u32 *id) 772 778 { 773 779 struct i915_address_space *vm; 774 780 int ret; ··· 787 791 current->comm, pid_nr(ctx->pid)); 788 792 789 793 /* And finally expose ourselves to userspace via the idr */ 790 - mutex_lock(&fpriv->context_idr_lock); 791 - ret = idr_alloc(&fpriv->context_idr, ctx, 0, 0, GFP_KERNEL); 792 - mutex_unlock(&fpriv->context_idr_lock); 793 - if (ret >= 0) 794 - goto out; 794 + ret = xa_alloc(&fpriv->context_xa, id, ctx, xa_limit_32b, GFP_KERNEL); 795 + if (ret) 796 + put_pid(fetch_and_zero(&ctx->pid)); 795 797 796 - put_pid(fetch_and_zero(&ctx->pid)); 797 - out: 798 798 return ret; 799 799 } 800 800 ··· 800 808 struct drm_i915_file_private *file_priv = file->driver_priv; 801 809 struct i915_gem_context *ctx; 802 810 int err; 811 + u32 id; 803 812 804 - mutex_init(&file_priv->context_idr_lock); 813 + xa_init_flags(&file_priv->context_xa, XA_FLAGS_ALLOC); 814 + 805 815 mutex_init(&file_priv->vm_idr_lock); 806 - 807 - idr_init(&file_priv->context_idr); 808 816 idr_init_base(&file_priv->vm_idr, 1); 809 817 810 818 ctx = i915_gem_create_context(i915, 0); ··· 813 821 goto err; 814 822 } 815 823 816 - err = gem_context_register(ctx, file_priv); 824 + err = gem_context_register(ctx, file_priv, &id); 817 825 if (err < 0) 818 826 goto err_ctx; 819 827 820 - GEM_BUG_ON(err > 0); 821 - 828 + GEM_BUG_ON(id); 822 829 return 0; 823 830 824 831 err_ctx: 825 832 context_close(ctx); 826 833 err: 827 834 idr_destroy(&file_priv->vm_idr); 828 - idr_destroy(&file_priv->context_idr); 835 + xa_destroy(&file_priv->context_xa); 829 836 mutex_destroy(&file_priv->vm_idr_lock); 830 - mutex_destroy(&file_priv->context_idr_lock); 831 837 return err; 832 838 } 833 839 ··· 833 843 { 834 844 struct drm_i915_file_private *file_priv = file->driver_priv; 835 845 struct drm_i915_private *i915 = file_priv->dev_priv; 846 + struct i915_gem_context *ctx; 847 + unsigned long idx; 836 848 837 - idr_for_each(&file_priv->context_idr, context_idr_cleanup, NULL); 838 - idr_destroy(&file_priv->context_idr); 839 - mutex_destroy(&file_priv->context_idr_lock); 849 + xa_for_each(&file_priv->context_xa, idx, ctx) 850 + context_close(ctx); 851 + xa_destroy(&file_priv->context_xa); 840 852 841 853 idr_for_each(&file_priv->vm_idr, vm_idr_cleanup, NULL); 842 854 idr_destroy(&file_priv->vm_idr); ··· 862 870 if (args->flags) 863 871 return -EINVAL; 864 872 865 - ppgtt = i915_ppgtt_create(i915); 873 + ppgtt = i915_ppgtt_create(&i915->gt); 866 874 if (IS_ERR(ppgtt)) 867 875 return PTR_ERR(ppgtt); 868 876 ··· 1236 1244 * image, or into the registers directory, does not stick). Pristine 1237 1245 * and idle contexts will be configured on pinning. 1238 1246 */ 1239 - if (!intel_context_is_pinned(ce)) 1247 + if (!intel_context_pin_if_active(ce)) 1240 1248 return 0; 1241 1249 1242 1250 rq = intel_engine_create_kernel_request(ce->engine); 1243 - if (IS_ERR(rq)) 1244 - return PTR_ERR(rq); 1251 + if (IS_ERR(rq)) { 1252 + ret = PTR_ERR(rq); 1253 + goto out_unpin; 1254 + } 1245 1255 1246 1256 /* Serialise with the remote context */ 1247 1257 ret = intel_context_prepare_remote_request(ce, rq); ··· 1251 1257 ret = gen8_emit_rpcs_config(rq, ce, sseu); 1252 1258 1253 1259 i915_request_add(rq); 1260 + out_unpin: 1261 + intel_context_unpin(ce); 1254 1262 return ret; 1255 1263 } 1256 1264 ··· 2183 2187 struct drm_i915_gem_context_create_ext *args = data; 2184 2188 struct create_ext ext_data; 2185 2189 int ret; 2190 + u32 id; 2186 2191 2187 2192 if (!DRIVER_CAPS(i915)->has_logical_contexts) 2188 2193 return -ENODEV; ··· 2215 2218 goto err_ctx; 2216 2219 } 2217 2220 2218 - ret = gem_context_register(ext_data.ctx, ext_data.fpriv); 2221 + ret = gem_context_register(ext_data.ctx, ext_data.fpriv, &id); 2219 2222 if (ret < 0) 2220 2223 goto err_ctx; 2221 2224 2222 - args->ctx_id = ret; 2225 + args->ctx_id = id; 2223 2226 DRM_DEBUG("HW context %d created\n", args->ctx_id); 2224 2227 2225 2228 return 0; ··· 2242 2245 if (!args->ctx_id) 2243 2246 return -ENOENT; 2244 2247 2245 - if (mutex_lock_interruptible(&file_priv->context_idr_lock)) 2246 - return -EINTR; 2247 - 2248 - ctx = idr_remove(&file_priv->context_idr, args->ctx_id); 2249 - mutex_unlock(&file_priv->context_idr_lock); 2248 + ctx = xa_erase(&file_priv->context_xa, args->ctx_id); 2250 2249 if (!ctx) 2251 2250 return -ENOENT; 2252 2251
-1
drivers/gpu/drm/i915/gem/i915_gem_context.h
··· 13 13 14 14 #include "i915_drv.h" 15 15 #include "i915_gem.h" 16 - #include "i915_gem_gtt.h" 17 16 #include "i915_scheduler.h" 18 17 #include "intel_device_info.h" 19 18
+1 -1
drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c
··· 2173 2173 } 2174 2174 2175 2175 if (intel_context_nopreempt(eb->context)) 2176 - eb->request->flags |= I915_REQUEST_NOPREEMPT; 2176 + __set_bit(I915_FENCE_FLAG_NOPREEMPT, &eb->request->fence.flags); 2177 2177 2178 2178 return 0; 2179 2179 }
-40
drivers/gpu/drm/i915/gem/i915_gem_lmem.c
··· 16 16 .release = i915_gem_object_release_memory_region, 17 17 }; 18 18 19 - /* XXX: Time to vfunc your life up? */ 20 - void __iomem * 21 - i915_gem_object_lmem_io_map_page(struct drm_i915_gem_object *obj, 22 - unsigned long n) 23 - { 24 - resource_size_t offset; 25 - 26 - offset = i915_gem_object_get_dma_address(obj, n); 27 - offset -= obj->mm.region->region.start; 28 - 29 - return io_mapping_map_wc(&obj->mm.region->iomap, offset, PAGE_SIZE); 30 - } 31 - 32 - void __iomem * 33 - i915_gem_object_lmem_io_map_page_atomic(struct drm_i915_gem_object *obj, 34 - unsigned long n) 35 - { 36 - resource_size_t offset; 37 - 38 - offset = i915_gem_object_get_dma_address(obj, n); 39 - offset -= obj->mm.region->region.start; 40 - 41 - return io_mapping_map_atomic_wc(&obj->mm.region->iomap, offset); 42 - } 43 - 44 - void __iomem * 45 - i915_gem_object_lmem_io_map(struct drm_i915_gem_object *obj, 46 - unsigned long n, 47 - unsigned long size) 48 - { 49 - resource_size_t offset; 50 - 51 - GEM_BUG_ON(!i915_gem_object_is_contiguous(obj)); 52 - 53 - offset = i915_gem_object_get_dma_address(obj, n); 54 - offset -= obj->mm.region->region.start; 55 - 56 - return io_mapping_map_wc(&obj->mm.region->iomap, offset, size); 57 - } 58 - 59 19 bool i915_gem_object_is_lmem(struct drm_i915_gem_object *obj) 60 20 { 61 21 return obj->ops == &i915_gem_lmem_obj_ops;
-8
drivers/gpu/drm/i915/gem/i915_gem_lmem.h
··· 14 14 15 15 extern const struct drm_i915_gem_object_ops i915_gem_lmem_obj_ops; 16 16 17 - void __iomem *i915_gem_object_lmem_io_map(struct drm_i915_gem_object *obj, 18 - unsigned long n, unsigned long size); 19 - void __iomem *i915_gem_object_lmem_io_map_page(struct drm_i915_gem_object *obj, 20 - unsigned long n); 21 - void __iomem * 22 - i915_gem_object_lmem_io_map_page_atomic(struct drm_i915_gem_object *obj, 23 - unsigned long n); 24 - 25 17 bool i915_gem_object_is_lmem(struct drm_i915_gem_object *obj); 26 18 27 19 struct drm_i915_gem_object *
+80 -22
drivers/gpu/drm/i915/gem/i915_gem_mman.c
··· 4 4 * Copyright © 2014-2016 Intel Corporation 5 5 */ 6 6 7 + #include <linux/anon_inodes.h> 7 8 #include <linux/mman.h> 8 9 #include <linux/pfn_t.h> 9 10 #include <linux/sizes.h> ··· 213 212 case -EIO: /* shmemfs failure from swap device */ 214 213 case -EFAULT: /* purged object */ 215 214 case -ENODEV: /* bad object, how did you get here! */ 215 + case -ENXIO: /* unable to access backing store (on device) */ 216 216 return VM_FAULT_SIGBUS; 217 217 218 218 case -ENOSPC: /* shmemfs allocation failure */ ··· 238 236 struct vm_area_struct *area = vmf->vma; 239 237 struct i915_mmap_offset *mmo = area->vm_private_data; 240 238 struct drm_i915_gem_object *obj = mmo->obj; 241 - unsigned long i, size = area->vm_end - area->vm_start; 242 - bool write = area->vm_flags & VM_WRITE; 243 - vm_fault_t ret = VM_FAULT_SIGBUS; 239 + resource_size_t iomap; 244 240 int err; 245 241 246 - if (!i915_gem_object_has_struct_page(obj)) 247 - return ret; 248 - 249 242 /* Sanity check that we allow writing into this object */ 250 - if (i915_gem_object_is_readonly(obj) && write) 251 - return ret; 243 + if (unlikely(i915_gem_object_is_readonly(obj) && 244 + area->vm_flags & VM_WRITE)) 245 + return VM_FAULT_SIGBUS; 252 246 253 247 err = i915_gem_object_pin_pages(obj); 254 248 if (err) 255 - return i915_error_to_vmf_fault(err); 249 + goto out; 256 250 257 - /* PTEs are revoked in obj->ops->put_pages() */ 258 - for (i = 0; i < size >> PAGE_SHIFT; i++) { 259 - struct page *page = i915_gem_object_get_page(obj, i); 260 - 261 - ret = vmf_insert_pfn(area, 262 - (unsigned long)area->vm_start + i * PAGE_SIZE, 263 - page_to_pfn(page)); 264 - if (ret != VM_FAULT_NOPAGE) 265 - break; 251 + iomap = -1; 252 + if (!i915_gem_object_type_has(obj, I915_GEM_OBJECT_HAS_STRUCT_PAGE)) { 253 + iomap = obj->mm.region->iomap.base; 254 + iomap -= obj->mm.region->region.start; 266 255 } 267 256 268 - if (write) { 257 + /* PTEs are revoked in obj->ops->put_pages() */ 258 + err = remap_io_sg(area, 259 + area->vm_start, area->vm_end - area->vm_start, 260 + obj->mm.pages->sgl, iomap); 261 + 262 + if (area->vm_flags & VM_WRITE) { 269 263 GEM_BUG_ON(!i915_gem_object_has_pinned_pages(obj)); 270 - obj->cache_dirty = true; /* XXX flush after PAT update? */ 271 264 obj->mm.dirty = true; 272 265 } 273 266 274 267 i915_gem_object_unpin_pages(obj); 275 268 276 - return ret; 269 + out: 270 + return i915_error_to_vmf_fault(err); 277 271 } 278 272 279 273 static vm_fault_t vm_fault_gtt(struct vm_fault *vmf) ··· 558 560 } 559 561 560 562 if (mmap_type != I915_MMAP_TYPE_GTT && 561 - !i915_gem_object_has_struct_page(obj)) { 563 + !i915_gem_object_type_has(obj, 564 + I915_GEM_OBJECT_HAS_STRUCT_PAGE | 565 + I915_GEM_OBJECT_HAS_IOMEM)) { 562 566 err = -ENODEV; 563 567 goto out; 564 568 } ··· 694 694 .close = vm_close, 695 695 }; 696 696 697 + static int singleton_release(struct inode *inode, struct file *file) 698 + { 699 + struct drm_i915_private *i915 = file->private_data; 700 + 701 + cmpxchg(&i915->gem.mmap_singleton, file, NULL); 702 + drm_dev_put(&i915->drm); 703 + 704 + return 0; 705 + } 706 + 707 + static const struct file_operations singleton_fops = { 708 + .owner = THIS_MODULE, 709 + .release = singleton_release, 710 + }; 711 + 712 + static struct file *mmap_singleton(struct drm_i915_private *i915) 713 + { 714 + struct file *file; 715 + 716 + rcu_read_lock(); 717 + file = i915->gem.mmap_singleton; 718 + if (file && !get_file_rcu(file)) 719 + file = NULL; 720 + rcu_read_unlock(); 721 + if (file) 722 + return file; 723 + 724 + file = anon_inode_getfile("i915.gem", &singleton_fops, i915, O_RDWR); 725 + if (IS_ERR(file)) 726 + return file; 727 + 728 + /* Everyone shares a single global address space */ 729 + file->f_mapping = i915->drm.anon_inode->i_mapping; 730 + 731 + smp_store_mb(i915->gem.mmap_singleton, file); 732 + drm_dev_get(&i915->drm); 733 + 734 + return file; 735 + } 736 + 697 737 /* 698 738 * This overcomes the limitation in drm_gem_mmap's assignment of a 699 739 * drm_gem_object as the vma->vm_private_data. Since we need to ··· 747 707 struct drm_device *dev = priv->minor->dev; 748 708 struct i915_mmap_offset *mmo = NULL; 749 709 struct drm_gem_object *obj = NULL; 710 + struct file *anon; 750 711 751 712 if (drm_dev_is_unplugged(dev)) 752 713 return -ENODEV; ··· 796 755 vma->vm_flags &= ~VM_MAYWRITE; 797 756 } 798 757 758 + anon = mmap_singleton(to_i915(obj->dev)); 759 + if (IS_ERR(anon)) { 760 + drm_gem_object_put_unlocked(obj); 761 + return PTR_ERR(anon); 762 + } 763 + 799 764 vma->vm_flags |= VM_PFNMAP | VM_DONTEXPAND | VM_DONTDUMP; 800 765 vma->vm_private_data = mmo; 766 + 767 + /* 768 + * We keep the ref on mmo->obj, not vm_file, but we require 769 + * vma->vm_file->f_mapping, see vma_link(), for later revocation. 770 + * Our userspace is accustomed to having per-file resource cleanup 771 + * (i.e. contexts, objects and requests) on their close(fd), which 772 + * requires avoiding extraneous references to their filp, hence why 773 + * we prefer to use an anonymous file for their mmaps. 774 + */ 775 + fput(vma->vm_file); 776 + vma->vm_file = anon; 801 777 802 778 switch (mmo->mmap_type) { 803 779 case I915_MMAP_TYPE_WC:
+1
drivers/gpu/drm/i915/gem/i915_gem_object.h
··· 16 16 #include "display/intel_frontbuffer.h" 17 17 #include "i915_gem_object_types.h" 18 18 #include "i915_gem_gtt.h" 19 + #include "i915_vma_types.h" 19 20 20 21 void i915_gem_init__objects(struct drm_i915_private *i915); 21 22
+47 -32
drivers/gpu/drm/i915/gem/i915_gem_pages.c
··· 158 158 159 159 static void unmap_object(struct drm_i915_gem_object *obj, void *ptr) 160 160 { 161 - if (i915_gem_object_is_lmem(obj)) 162 - io_mapping_unmap((void __force __iomem *)ptr); 163 - else if (is_vmalloc_addr(ptr)) 161 + if (is_vmalloc_addr(ptr)) 164 162 vunmap(ptr); 165 163 else 166 164 kunmap(kmap_to_page(ptr)); ··· 234 236 return err; 235 237 } 236 238 239 + static inline pte_t iomap_pte(resource_size_t base, 240 + dma_addr_t offset, 241 + pgprot_t prot) 242 + { 243 + return pte_mkspecial(pfn_pte((base + offset) >> PAGE_SHIFT, prot)); 244 + } 245 + 237 246 /* The 'mapping' part of i915_gem_object_pin_map() below */ 238 247 static void *i915_gem_object_map(struct drm_i915_gem_object *obj, 239 248 enum i915_map_type type) 240 249 { 241 - unsigned long n_pages = obj->base.size >> PAGE_SHIFT; 250 + unsigned long n_pte = obj->base.size >> PAGE_SHIFT; 242 251 struct sg_table *sgt = obj->mm.pages; 243 - struct sgt_iter sgt_iter; 244 - struct page *page; 245 - struct page *stack_pages[32]; 246 - struct page **pages = stack_pages; 247 - unsigned long i = 0; 252 + pte_t *stack[32], **mem; 253 + struct vm_struct *area; 248 254 pgprot_t pgprot; 249 - void *addr; 250 255 251 - if (i915_gem_object_is_lmem(obj)) { 252 - void __iomem *io; 253 - 254 - if (type != I915_MAP_WC) 255 - return NULL; 256 - 257 - io = i915_gem_object_lmem_io_map(obj, 0, obj->base.size); 258 - return (void __force *)io; 259 - } 256 + if (!i915_gem_object_has_struct_page(obj) && type != I915_MAP_WC) 257 + return NULL; 260 258 261 259 /* A single page can always be kmapped */ 262 - if (n_pages == 1 && type == I915_MAP_WB) 260 + if (n_pte == 1 && type == I915_MAP_WB) 263 261 return kmap(sg_page(sgt->sgl)); 264 262 265 - if (n_pages > ARRAY_SIZE(stack_pages)) { 263 + mem = stack; 264 + if (n_pte > ARRAY_SIZE(stack)) { 266 265 /* Too big for stack -- allocate temporary array instead */ 267 - pages = kvmalloc_array(n_pages, sizeof(*pages), GFP_KERNEL); 268 - if (!pages) 266 + mem = kvmalloc_array(n_pte, sizeof(*mem), GFP_KERNEL); 267 + if (!mem) 269 268 return NULL; 270 269 } 271 270 272 - for_each_sgt_page(page, sgt_iter, sgt) 273 - pages[i++] = page; 274 - 275 - /* Check that we have the expected number of pages */ 276 - GEM_BUG_ON(i != n_pages); 271 + area = alloc_vm_area(obj->base.size, mem); 272 + if (!area) { 273 + if (mem != stack) 274 + kvfree(mem); 275 + return NULL; 276 + } 277 277 278 278 switch (type) { 279 279 default: ··· 284 288 pgprot = pgprot_writecombine(PAGE_KERNEL_IO); 285 289 break; 286 290 } 287 - addr = vmap(pages, n_pages, 0, pgprot); 288 291 289 - if (pages != stack_pages) 290 - kvfree(pages); 292 + if (i915_gem_object_has_struct_page(obj)) { 293 + struct sgt_iter iter; 294 + struct page *page; 295 + pte_t **ptes = mem; 291 296 292 - return addr; 297 + for_each_sgt_page(page, iter, sgt) 298 + **ptes++ = mk_pte(page, pgprot); 299 + } else { 300 + resource_size_t iomap; 301 + struct sgt_iter iter; 302 + pte_t **ptes = mem; 303 + dma_addr_t addr; 304 + 305 + iomap = obj->mm.region->iomap.base; 306 + iomap -= obj->mm.region->region.start; 307 + 308 + for_each_sgt_daddr(addr, iter, sgt) 309 + **ptes++ = iomap_pte(iomap, addr, pgprot); 310 + } 311 + 312 + if (mem != stack) 313 + kvfree(mem); 314 + 315 + return area->addr; 293 316 } 294 317 295 318 /* get, pin, and map the pages of the object into kernel space */
+3
drivers/gpu/drm/i915/gem/i915_gem_region.c
··· 107 107 { 108 108 INIT_LIST_HEAD(&obj->mm.blocks); 109 109 obj->mm.region = intel_memory_region_get(mem); 110 + 110 111 obj->flags |= flags; 112 + if (obj->base.size <= mem->min_page_size) 113 + obj->flags |= I915_BO_ALLOC_CONTIGUOUS; 111 114 112 115 mutex_lock(&mem->objects.lock); 113 116
+2
drivers/gpu/drm/i915/gem/i915_gem_shmem.c
··· 594 594 err); 595 595 } 596 596 597 + intel_memory_region_set_name(mem, "system"); 598 + 597 599 return 0; /* Don't error, we can simply fallback to the kernel mnt */ 598 600 } 599 601
+2
drivers/gpu/drm/i915/gem/i915_gem_stolen.c
··· 645 645 646 646 static int init_stolen(struct intel_memory_region *mem) 647 647 { 648 + intel_memory_region_set_name(mem, "stolen"); 649 + 648 650 /* 649 651 * Initialise stolen early so that we may reserve preallocated 650 652 * objects for the BIOS to KMS transition.
+6
drivers/gpu/drm/i915/gem/selftests/huge_gem_object.h
··· 7 7 #ifndef __HUGE_GEM_OBJECT_H 8 8 #define __HUGE_GEM_OBJECT_H 9 9 10 + #include <linux/types.h> 11 + 12 + #include "gem/i915_gem_object_types.h" 13 + 14 + struct drm_i915_private; 15 + 10 16 struct drm_i915_gem_object * 11 17 huge_gem_object(struct drm_i915_private *i915, 12 18 phys_addr_t phys_size,
+18 -25
drivers/gpu/drm/i915/gem/selftests/huge_pages.c
··· 1017 1017 return err; 1018 1018 } 1019 1019 1020 - static int __cpu_check_lmem(struct drm_i915_gem_object *obj, u32 dword, u32 val) 1020 + static int __cpu_check_vmap(struct drm_i915_gem_object *obj, u32 dword, u32 val) 1021 1021 { 1022 - unsigned long n; 1022 + unsigned long n = obj->base.size >> PAGE_SHIFT; 1023 + u32 *ptr; 1023 1024 int err; 1024 1025 1025 - i915_gem_object_lock(obj); 1026 - err = i915_gem_object_set_to_wc_domain(obj, false); 1027 - i915_gem_object_unlock(obj); 1026 + err = i915_gem_object_wait(obj, 0, MAX_SCHEDULE_TIMEOUT); 1028 1027 if (err) 1029 1028 return err; 1030 1029 1031 - err = i915_gem_object_pin_pages(obj); 1032 - if (err) 1033 - return err; 1030 + ptr = i915_gem_object_pin_map(obj, I915_MAP_WC); 1031 + if (IS_ERR(ptr)) 1032 + return PTR_ERR(ptr); 1034 1033 1035 - for (n = 0; n < obj->base.size >> PAGE_SHIFT; ++n) { 1036 - u32 __iomem *base; 1037 - u32 read_val; 1038 - 1039 - base = i915_gem_object_lmem_io_map_page_atomic(obj, n); 1040 - 1041 - read_val = ioread32(base + dword); 1042 - io_mapping_unmap_atomic(base); 1043 - if (read_val != val) { 1044 - pr_err("n=%lu base[%u]=%u, val=%u\n", 1045 - n, dword, read_val, val); 1034 + ptr += dword; 1035 + while (n--) { 1036 + if (*ptr != val) { 1037 + pr_err("base[%u]=%08x, val=%08x\n", 1038 + dword, *ptr, val); 1046 1039 err = -EINVAL; 1047 1040 break; 1048 1041 } 1042 + 1043 + ptr += PAGE_SIZE / sizeof(*ptr); 1049 1044 } 1050 1045 1051 - i915_gem_object_unpin_pages(obj); 1046 + i915_gem_object_unpin_map(obj); 1052 1047 return err; 1053 1048 } 1054 1049 ··· 1051 1056 { 1052 1057 if (i915_gem_object_has_struct_page(obj)) 1053 1058 return __cpu_check_shmem(obj, dword, val); 1054 - else if (i915_gem_object_is_lmem(obj)) 1055 - return __cpu_check_lmem(obj, dword, val); 1056 - 1057 - return -ENODEV; 1059 + else 1060 + return __cpu_check_vmap(obj, dword, val); 1058 1061 } 1059 1062 1060 1063 static int __igt_write_huge(struct intel_context *ce, ··· 1865 1872 mkwrite_device_info(dev_priv)->ppgtt_type = INTEL_PPGTT_FULL; 1866 1873 mkwrite_device_info(dev_priv)->ppgtt_size = 48; 1867 1874 1868 - ppgtt = i915_ppgtt_create(dev_priv); 1875 + ppgtt = i915_ppgtt_create(&dev_priv->gt); 1869 1876 if (IS_ERR(ppgtt)) { 1870 1877 err = PTR_ERR(ppgtt); 1871 1878 goto out_unlock;
+8 -4
drivers/gpu/drm/i915/gem/selftests/i915_gem_coherency.c
··· 325 325 values = offsets + ncachelines; 326 326 327 327 ctx.engine = random_engine(i915, &prng); 328 - GEM_BUG_ON(!ctx.engine); 328 + if (!ctx.engine) { 329 + err = -ENODEV; 330 + goto out_free; 331 + } 329 332 pr_info("%s: using %s\n", __func__, ctx.engine->name); 330 333 intel_engine_pm_get(ctx.engine); 331 334 ··· 357 354 ctx.obj = i915_gem_object_create_internal(i915, PAGE_SIZE); 358 355 if (IS_ERR(ctx.obj)) { 359 356 err = PTR_ERR(ctx.obj); 360 - goto free; 357 + goto out_pm; 361 358 } 362 359 363 360 i915_random_reorder(offsets, ncachelines, &prng); ··· 408 405 } 409 406 } 410 407 } 411 - free: 408 + out_pm: 412 409 intel_engine_pm_put(ctx.engine); 410 + out_free: 413 411 kfree(offsets); 414 412 return err; 415 413 416 414 put_object: 417 415 i915_gem_object_put(ctx.obj); 418 - goto free; 416 + goto out_pm; 419 417 } 420 418 421 419 int i915_gem_coherency_live_selftests(struct drm_i915_private *i915)
+346 -88
drivers/gpu/drm/i915/gem/selftests/i915_gem_mman.c
··· 9 9 #include "gt/intel_engine_pm.h" 10 10 #include "gt/intel_gt.h" 11 11 #include "gt/intel_gt_pm.h" 12 + #include "gem/i915_gem_region.h" 12 13 #include "huge_gem_object.h" 13 14 #include "i915_selftest.h" 14 15 #include "selftests/i915_random.h" ··· 726 725 goto out; 727 726 } 728 727 729 - #define expand32(x) (((x) << 0) | ((x) << 8) | ((x) << 16) | ((x) << 24)) 730 - static int igt_mmap(void *arg, enum i915_mmap_type type) 728 + static int gtt_set(struct drm_i915_gem_object *obj) 731 729 { 732 - struct drm_i915_private *i915 = arg; 733 - struct drm_i915_gem_object *obj; 734 - struct i915_mmap_offset *mmo; 735 - struct vm_area_struct *area; 736 - unsigned long addr; 737 - void *vaddr; 738 - int err = 0, i; 730 + struct i915_vma *vma; 731 + void __iomem *map; 732 + int err = 0; 739 733 740 - if (!i915_ggtt_has_aperture(&i915->ggtt)) 741 - return 0; 734 + vma = i915_gem_object_ggtt_pin(obj, NULL, 0, 0, PIN_MAPPABLE); 735 + if (IS_ERR(vma)) 736 + return PTR_ERR(vma); 742 737 743 - obj = i915_gem_object_create_internal(i915, PAGE_SIZE); 744 - if (IS_ERR(obj)) 745 - return PTR_ERR(obj); 746 - 747 - vaddr = i915_gem_object_pin_map(obj, I915_MAP_WB); 748 - if (IS_ERR(vaddr)) { 749 - err = PTR_ERR(vaddr); 738 + intel_gt_pm_get(vma->vm->gt); 739 + map = i915_vma_pin_iomap(vma); 740 + i915_vma_unpin(vma); 741 + if (IS_ERR(map)) { 742 + err = PTR_ERR(map); 750 743 goto out; 751 744 } 752 - memset(vaddr, POISON_INUSE, PAGE_SIZE); 745 + 746 + memset_io(map, POISON_INUSE, obj->base.size); 747 + i915_vma_unpin_iomap(vma); 748 + 749 + out: 750 + intel_gt_pm_put(vma->vm->gt); 751 + return err; 752 + } 753 + 754 + static int gtt_check(struct drm_i915_gem_object *obj) 755 + { 756 + struct i915_vma *vma; 757 + void __iomem *map; 758 + int err = 0; 759 + 760 + vma = i915_gem_object_ggtt_pin(obj, NULL, 0, 0, PIN_MAPPABLE); 761 + if (IS_ERR(vma)) 762 + return PTR_ERR(vma); 763 + 764 + intel_gt_pm_get(vma->vm->gt); 765 + map = i915_vma_pin_iomap(vma); 766 + i915_vma_unpin(vma); 767 + if (IS_ERR(map)) { 768 + err = PTR_ERR(map); 769 + goto out; 770 + } 771 + 772 + if (memchr_inv((void __force *)map, POISON_FREE, obj->base.size)) { 773 + pr_err("%s: Write via mmap did not land in backing store (GTT)\n", 774 + obj->mm.region->name); 775 + err = -EINVAL; 776 + } 777 + i915_vma_unpin_iomap(vma); 778 + 779 + out: 780 + intel_gt_pm_put(vma->vm->gt); 781 + return err; 782 + } 783 + 784 + static int wc_set(struct drm_i915_gem_object *obj) 785 + { 786 + void *vaddr; 787 + 788 + vaddr = i915_gem_object_pin_map(obj, I915_MAP_WC); 789 + if (IS_ERR(vaddr)) 790 + return PTR_ERR(vaddr); 791 + 792 + memset(vaddr, POISON_INUSE, obj->base.size); 753 793 i915_gem_object_flush_map(obj); 754 794 i915_gem_object_unpin_map(obj); 755 795 756 - mmo = mmap_offset_attach(obj, type, NULL); 757 - if (IS_ERR(mmo)) { 758 - err = PTR_ERR(mmo); 759 - goto out; 796 + return 0; 797 + } 798 + 799 + static int wc_check(struct drm_i915_gem_object *obj) 800 + { 801 + void *vaddr; 802 + int err = 0; 803 + 804 + vaddr = i915_gem_object_pin_map(obj, I915_MAP_WC); 805 + if (IS_ERR(vaddr)) 806 + return PTR_ERR(vaddr); 807 + 808 + if (memchr_inv(vaddr, POISON_FREE, obj->base.size)) { 809 + pr_err("%s: Write via mmap did not land in backing store (WC)\n", 810 + obj->mm.region->name); 811 + err = -EINVAL; 760 812 } 813 + i915_gem_object_unpin_map(obj); 814 + 815 + return err; 816 + } 817 + 818 + static bool can_mmap(struct drm_i915_gem_object *obj, enum i915_mmap_type type) 819 + { 820 + if (type == I915_MMAP_TYPE_GTT && 821 + !i915_ggtt_has_aperture(&to_i915(obj->base.dev)->ggtt)) 822 + return false; 823 + 824 + if (type != I915_MMAP_TYPE_GTT && 825 + !i915_gem_object_type_has(obj, 826 + I915_GEM_OBJECT_HAS_STRUCT_PAGE | 827 + I915_GEM_OBJECT_HAS_IOMEM)) 828 + return false; 829 + 830 + return true; 831 + } 832 + 833 + #define expand32(x) (((x) << 0) | ((x) << 8) | ((x) << 16) | ((x) << 24)) 834 + static int __igt_mmap(struct drm_i915_private *i915, 835 + struct drm_i915_gem_object *obj, 836 + enum i915_mmap_type type) 837 + { 838 + struct i915_mmap_offset *mmo; 839 + struct vm_area_struct *area; 840 + unsigned long addr; 841 + int err, i; 842 + 843 + if (!can_mmap(obj, type)) 844 + return 0; 845 + 846 + err = wc_set(obj); 847 + if (err == -ENXIO) 848 + err = gtt_set(obj); 849 + if (err) 850 + return err; 851 + 852 + mmo = mmap_offset_attach(obj, type, NULL); 853 + if (IS_ERR(mmo)) 854 + return PTR_ERR(mmo); 761 855 762 856 addr = igt_mmap_node(i915, &mmo->vma_node, 0, PROT_WRITE, MAP_SHARED); 763 - if (IS_ERR_VALUE(addr)) { 764 - err = addr; 765 - goto out; 766 - } 857 + if (IS_ERR_VALUE(addr)) 858 + return addr; 767 859 768 - pr_debug("igt_mmap() @ %lx\n", addr); 860 + pr_debug("igt_mmap(%s, %d) @ %lx\n", obj->mm.region->name, type, addr); 769 861 770 862 area = find_vma(current->mm, addr); 771 863 if (!area) { 772 - pr_err("Did not create a vm_area_struct for the mmap\n"); 864 + pr_err("%s: Did not create a vm_area_struct for the mmap\n", 865 + obj->mm.region->name); 773 866 err = -EINVAL; 774 867 goto out_unmap; 775 868 } 776 869 777 870 if (area->vm_private_data != mmo) { 778 - pr_err("vm_area_struct did not point back to our mmap_offset object!\n"); 871 + pr_err("%s: vm_area_struct did not point back to our mmap_offset object!\n", 872 + obj->mm.region->name); 779 873 err = -EINVAL; 780 874 goto out_unmap; 781 875 } 782 876 783 - for (i = 0; i < PAGE_SIZE / sizeof(u32); i++) { 877 + for (i = 0; i < obj->base.size / sizeof(u32); i++) { 784 878 u32 __user *ux = u64_to_user_ptr((u64)(addr + i * sizeof(*ux))); 785 879 u32 x; 786 880 787 881 if (get_user(x, ux)) { 788 - pr_err("Unable to read from mmap, offset:%zd\n", 789 - i * sizeof(x)); 882 + pr_err("%s: Unable to read from mmap, offset:%zd\n", 883 + obj->mm.region->name, i * sizeof(x)); 790 884 err = -EFAULT; 791 - break; 885 + goto out_unmap; 792 886 } 793 887 794 888 if (x != expand32(POISON_INUSE)) { 795 - pr_err("Read incorrect value from mmap, offset:%zd, found:%x, expected:%x\n", 889 + pr_err("%s: Read incorrect value from mmap, offset:%zd, found:%x, expected:%x\n", 890 + obj->mm.region->name, 796 891 i * sizeof(x), x, expand32(POISON_INUSE)); 797 892 err = -EINVAL; 798 - break; 893 + goto out_unmap; 799 894 } 800 895 801 896 x = expand32(POISON_FREE); 802 897 if (put_user(x, ux)) { 803 - pr_err("Unable to write to mmap, offset:%zd\n", 804 - i * sizeof(x)); 898 + pr_err("%s: Unable to write to mmap, offset:%zd\n", 899 + obj->mm.region->name, i * sizeof(x)); 805 900 err = -EFAULT; 806 - break; 901 + goto out_unmap; 807 902 } 808 903 } 809 904 905 + if (type == I915_MMAP_TYPE_GTT) 906 + intel_gt_flush_ggtt_writes(&i915->gt); 907 + 908 + err = wc_check(obj); 909 + if (err == -ENXIO) 910 + err = gtt_check(obj); 810 911 out_unmap: 811 - vm_munmap(addr, PAGE_SIZE); 812 - 813 - vaddr = i915_gem_object_pin_map(obj, I915_MAP_FORCE_WC); 814 - if (IS_ERR(vaddr)) { 815 - err = PTR_ERR(vaddr); 816 - goto out; 817 - } 818 - if (err == 0 && memchr_inv(vaddr, POISON_FREE, PAGE_SIZE)) { 819 - pr_err("Write via mmap did not land in backing store\n"); 820 - err = -EINVAL; 821 - } 822 - i915_gem_object_unpin_map(obj); 823 - 824 - out: 825 - i915_gem_object_put(obj); 912 + vm_munmap(addr, obj->base.size); 826 913 return err; 827 914 } 828 915 829 - static int igt_mmap_gtt(void *arg) 916 + static int igt_mmap(void *arg) 830 917 { 831 - return igt_mmap(arg, I915_MMAP_TYPE_GTT); 918 + struct drm_i915_private *i915 = arg; 919 + struct intel_memory_region *mr; 920 + enum intel_region_id id; 921 + 922 + for_each_memory_region(mr, i915, id) { 923 + unsigned long sizes[] = { 924 + PAGE_SIZE, 925 + mr->min_page_size, 926 + SZ_4M, 927 + }; 928 + int i; 929 + 930 + for (i = 0; i < ARRAY_SIZE(sizes); i++) { 931 + struct drm_i915_gem_object *obj; 932 + int err; 933 + 934 + obj = i915_gem_object_create_region(mr, sizes[i], 0); 935 + if (obj == ERR_PTR(-ENODEV)) 936 + continue; 937 + 938 + if (IS_ERR(obj)) 939 + return PTR_ERR(obj); 940 + 941 + err = __igt_mmap(i915, obj, I915_MMAP_TYPE_GTT); 942 + if (err == 0) 943 + err = __igt_mmap(i915, obj, I915_MMAP_TYPE_WC); 944 + 945 + i915_gem_object_put(obj); 946 + if (err) 947 + return err; 948 + } 949 + } 950 + 951 + return 0; 832 952 } 833 953 834 - static int igt_mmap_cpu(void *arg) 954 + static int __igt_mmap_gpu(struct drm_i915_private *i915, 955 + struct drm_i915_gem_object *obj, 956 + enum i915_mmap_type type) 835 957 { 836 - return igt_mmap(arg, I915_MMAP_TYPE_WC); 958 + struct intel_engine_cs *engine; 959 + struct i915_mmap_offset *mmo; 960 + unsigned long addr; 961 + u32 __user *ux; 962 + u32 bbe; 963 + int err; 964 + 965 + /* 966 + * Verify that the mmap access into the backing store aligns with 967 + * that of the GPU, i.e. that mmap is indeed writing into the same 968 + * page as being read by the GPU. 969 + */ 970 + 971 + if (!can_mmap(obj, type)) 972 + return 0; 973 + 974 + err = wc_set(obj); 975 + if (err == -ENXIO) 976 + err = gtt_set(obj); 977 + if (err) 978 + return err; 979 + 980 + mmo = mmap_offset_attach(obj, type, NULL); 981 + if (IS_ERR(mmo)) 982 + return PTR_ERR(mmo); 983 + 984 + addr = igt_mmap_node(i915, &mmo->vma_node, 0, PROT_WRITE, MAP_SHARED); 985 + if (IS_ERR_VALUE(addr)) 986 + return addr; 987 + 988 + ux = u64_to_user_ptr((u64)addr); 989 + bbe = MI_BATCH_BUFFER_END; 990 + if (put_user(bbe, ux)) { 991 + pr_err("%s: Unable to write to mmap\n", obj->mm.region->name); 992 + err = -EFAULT; 993 + goto out_unmap; 994 + } 995 + 996 + if (type == I915_MMAP_TYPE_GTT) 997 + intel_gt_flush_ggtt_writes(&i915->gt); 998 + 999 + for_each_uabi_engine(engine, i915) { 1000 + struct i915_request *rq; 1001 + struct i915_vma *vma; 1002 + 1003 + vma = i915_vma_instance(obj, engine->kernel_context->vm, NULL); 1004 + if (IS_ERR(vma)) { 1005 + err = PTR_ERR(vma); 1006 + goto out_unmap; 1007 + } 1008 + 1009 + err = i915_vma_pin(vma, 0, 0, PIN_USER); 1010 + if (err) 1011 + goto out_unmap; 1012 + 1013 + rq = i915_request_create(engine->kernel_context); 1014 + if (IS_ERR(rq)) { 1015 + err = PTR_ERR(rq); 1016 + goto out_unpin; 1017 + } 1018 + 1019 + i915_vma_lock(vma); 1020 + err = i915_request_await_object(rq, vma->obj, false); 1021 + if (err == 0) 1022 + err = i915_vma_move_to_active(vma, rq, 0); 1023 + i915_vma_unlock(vma); 1024 + 1025 + err = engine->emit_bb_start(rq, vma->node.start, 0, 0); 1026 + i915_request_get(rq); 1027 + i915_request_add(rq); 1028 + 1029 + if (i915_request_wait(rq, 0, HZ / 5) < 0) { 1030 + struct drm_printer p = 1031 + drm_info_printer(engine->i915->drm.dev); 1032 + 1033 + pr_err("%s(%s, %s): Failed to execute batch\n", 1034 + __func__, engine->name, obj->mm.region->name); 1035 + intel_engine_dump(engine, &p, 1036 + "%s\n", engine->name); 1037 + 1038 + intel_gt_set_wedged(engine->gt); 1039 + err = -EIO; 1040 + } 1041 + i915_request_put(rq); 1042 + 1043 + out_unpin: 1044 + i915_vma_unpin(vma); 1045 + if (err) 1046 + goto out_unmap; 1047 + } 1048 + 1049 + out_unmap: 1050 + vm_munmap(addr, obj->base.size); 1051 + return err; 1052 + } 1053 + 1054 + static int igt_mmap_gpu(void *arg) 1055 + { 1056 + struct drm_i915_private *i915 = arg; 1057 + struct intel_memory_region *mr; 1058 + enum intel_region_id id; 1059 + 1060 + for_each_memory_region(mr, i915, id) { 1061 + struct drm_i915_gem_object *obj; 1062 + int err; 1063 + 1064 + obj = i915_gem_object_create_region(mr, PAGE_SIZE, 0); 1065 + if (obj == ERR_PTR(-ENODEV)) 1066 + continue; 1067 + 1068 + if (IS_ERR(obj)) 1069 + return PTR_ERR(obj); 1070 + 1071 + err = __igt_mmap_gpu(i915, obj, I915_MMAP_TYPE_GTT); 1072 + if (err == 0) 1073 + err = __igt_mmap_gpu(i915, obj, I915_MMAP_TYPE_WC); 1074 + 1075 + i915_gem_object_put(obj); 1076 + if (err) 1077 + return err; 1078 + } 1079 + 1080 + return 0; 837 1081 } 838 1082 839 1083 static int check_present_pte(pte_t *pte, unsigned long addr, void *data) ··· 1133 887 return __get_user(c, end - 1); 1134 888 } 1135 889 1136 - static int igt_mmap_revoke(void *arg, enum i915_mmap_type type) 890 + static int __igt_mmap_revoke(struct drm_i915_private *i915, 891 + struct drm_i915_gem_object *obj, 892 + enum i915_mmap_type type) 1137 893 { 1138 - struct drm_i915_private *i915 = arg; 1139 - struct drm_i915_gem_object *obj; 1140 894 struct i915_mmap_offset *mmo; 1141 895 unsigned long addr; 1142 896 int err; 1143 897 1144 - if (!i915_ggtt_has_aperture(&i915->ggtt)) 898 + if (!can_mmap(obj, type)) 1145 899 return 0; 1146 900 1147 - obj = i915_gem_object_create_internal(i915, SZ_4M); 1148 - if (IS_ERR(obj)) 1149 - return PTR_ERR(obj); 1150 - 1151 901 mmo = mmap_offset_attach(obj, type, NULL); 1152 - if (IS_ERR(mmo)) { 1153 - err = PTR_ERR(mmo); 1154 - goto out; 1155 - } 902 + if (IS_ERR(mmo)) 903 + return PTR_ERR(mmo); 1156 904 1157 905 addr = igt_mmap_node(i915, &mmo->vma_node, 0, PROT_WRITE, MAP_SHARED); 1158 - if (IS_ERR_VALUE(addr)) { 1159 - err = addr; 1160 - goto out; 1161 - } 906 + if (IS_ERR_VALUE(addr)) 907 + return addr; 1162 908 1163 909 err = prefault_range(addr, obj->base.size); 1164 910 if (err) ··· 1160 922 !atomic_read(&obj->bind_count)); 1161 923 1162 924 err = check_present(addr, obj->base.size); 1163 - if (err) 925 + if (err) { 926 + pr_err("%s: was not present\n", obj->mm.region->name); 1164 927 goto out_unmap; 928 + } 1165 929 1166 930 /* 1167 931 * After unbinding the object from the GGTT, its address may be reused ··· 1187 947 } 1188 948 1189 949 err = check_absent(addr, obj->base.size); 1190 - if (err) 950 + if (err) { 951 + pr_err("%s: was not absent\n", obj->mm.region->name); 1191 952 goto out_unmap; 953 + } 1192 954 1193 955 out_unmap: 1194 956 vm_munmap(addr, obj->base.size); 1195 - out: 1196 - i915_gem_object_put(obj); 1197 957 return err; 1198 958 } 1199 959 1200 - static int igt_mmap_gtt_revoke(void *arg) 960 + static int igt_mmap_revoke(void *arg) 1201 961 { 1202 - return igt_mmap_revoke(arg, I915_MMAP_TYPE_GTT); 1203 - } 962 + struct drm_i915_private *i915 = arg; 963 + struct intel_memory_region *mr; 964 + enum intel_region_id id; 1204 965 1205 - static int igt_mmap_cpu_revoke(void *arg) 1206 - { 1207 - return igt_mmap_revoke(arg, I915_MMAP_TYPE_WC); 966 + for_each_memory_region(mr, i915, id) { 967 + struct drm_i915_gem_object *obj; 968 + int err; 969 + 970 + obj = i915_gem_object_create_region(mr, PAGE_SIZE, 0); 971 + if (obj == ERR_PTR(-ENODEV)) 972 + continue; 973 + 974 + if (IS_ERR(obj)) 975 + return PTR_ERR(obj); 976 + 977 + err = __igt_mmap_revoke(i915, obj, I915_MMAP_TYPE_GTT); 978 + if (err == 0) 979 + err = __igt_mmap_revoke(i915, obj, I915_MMAP_TYPE_WC); 980 + 981 + i915_gem_object_put(obj); 982 + if (err) 983 + return err; 984 + } 985 + 986 + return 0; 1208 987 } 1209 988 1210 989 int i915_gem_mman_live_selftests(struct drm_i915_private *i915) ··· 1232 973 SUBTEST(igt_partial_tiling), 1233 974 SUBTEST(igt_smoke_tiling), 1234 975 SUBTEST(igt_mmap_offset_exhaustion), 1235 - SUBTEST(igt_mmap_gtt), 1236 - SUBTEST(igt_mmap_cpu), 1237 - SUBTEST(igt_mmap_gtt_revoke), 1238 - SUBTEST(igt_mmap_cpu_revoke), 976 + SUBTEST(igt_mmap), 977 + SUBTEST(igt_mmap_revoke), 978 + SUBTEST(igt_mmap_gpu), 1239 979 }; 1240 980 1241 981 return i915_subtests(tests, i915);
+2 -1
drivers/gpu/drm/i915/gem/selftests/mock_context.c
··· 77 77 { 78 78 struct i915_gem_context *ctx; 79 79 int err; 80 + u32 id; 80 81 81 82 ctx = i915_gem_create_context(i915, 0); 82 83 if (IS_ERR(ctx)) 83 84 return ctx; 84 85 85 - err = gem_context_register(ctx, to_drm_file(file)->driver_priv); 86 + err = gem_context_register(ctx, to_drm_file(file)->driver_priv, &id); 86 87 if (err < 0) 87 88 goto err_ctx; 88 89
+2
drivers/gpu/drm/i915/gem/selftests/mock_gem_object.h
··· 7 7 #ifndef __MOCK_GEM_OBJECT_H__ 8 8 #define __MOCK_GEM_OBJECT_H__ 9 9 10 + #include "gem/i915_gem_object_types.h" 11 + 10 12 struct mock_object { 11 13 struct drm_i915_gem_object base; 12 14 };
-5
drivers/gpu/drm/i915/gt/Makefile
··· 1 - # For building individual subdir files on the command line 2 - subdir-ccflags-y += -I$(srctree)/$(src)/.. 3 - 4 - # Extra header tests 5 - header-test-pattern-$(CONFIG_DRM_I915_WERROR) := *.h
+482
drivers/gpu/drm/i915/gt/gen6_ppgtt.c
··· 1 + // SPDX-License-Identifier: MIT 2 + /* 3 + * Copyright © 2020 Intel Corporation 4 + */ 5 + 6 + #include <linux/log2.h> 7 + 8 + #include "gen6_ppgtt.h" 9 + #include "i915_scatterlist.h" 10 + #include "i915_trace.h" 11 + #include "i915_vgpu.h" 12 + #include "intel_gt.h" 13 + 14 + /* Write pde (index) from the page directory @pd to the page table @pt */ 15 + static inline void gen6_write_pde(const struct gen6_ppgtt *ppgtt, 16 + const unsigned int pde, 17 + const struct i915_page_table *pt) 18 + { 19 + /* Caller needs to make sure the write completes if necessary */ 20 + iowrite32(GEN6_PDE_ADDR_ENCODE(px_dma(pt)) | GEN6_PDE_VALID, 21 + ppgtt->pd_addr + pde); 22 + } 23 + 24 + void gen7_ppgtt_enable(struct intel_gt *gt) 25 + { 26 + struct drm_i915_private *i915 = gt->i915; 27 + struct intel_uncore *uncore = gt->uncore; 28 + struct intel_engine_cs *engine; 29 + enum intel_engine_id id; 30 + u32 ecochk; 31 + 32 + intel_uncore_rmw(uncore, GAC_ECO_BITS, 0, ECOBITS_PPGTT_CACHE64B); 33 + 34 + ecochk = intel_uncore_read(uncore, GAM_ECOCHK); 35 + if (IS_HASWELL(i915)) { 36 + ecochk |= ECOCHK_PPGTT_WB_HSW; 37 + } else { 38 + ecochk |= ECOCHK_PPGTT_LLC_IVB; 39 + ecochk &= ~ECOCHK_PPGTT_GFDT_IVB; 40 + } 41 + intel_uncore_write(uncore, GAM_ECOCHK, ecochk); 42 + 43 + for_each_engine(engine, gt, id) { 44 + /* GFX_MODE is per-ring on gen7+ */ 45 + ENGINE_WRITE(engine, 46 + RING_MODE_GEN7, 47 + _MASKED_BIT_ENABLE(GFX_PPGTT_ENABLE)); 48 + } 49 + } 50 + 51 + void gen6_ppgtt_enable(struct intel_gt *gt) 52 + { 53 + struct intel_uncore *uncore = gt->uncore; 54 + 55 + intel_uncore_rmw(uncore, 56 + GAC_ECO_BITS, 57 + 0, 58 + ECOBITS_SNB_BIT | ECOBITS_PPGTT_CACHE64B); 59 + 60 + intel_uncore_rmw(uncore, 61 + GAB_CTL, 62 + 0, 63 + GAB_CTL_CONT_AFTER_PAGEFAULT); 64 + 65 + intel_uncore_rmw(uncore, 66 + GAM_ECOCHK, 67 + 0, 68 + ECOCHK_SNB_BIT | ECOCHK_PPGTT_CACHE64B); 69 + 70 + if (HAS_PPGTT(uncore->i915)) /* may be disabled for VT-d */ 71 + intel_uncore_write(uncore, 72 + GFX_MODE, 73 + _MASKED_BIT_ENABLE(GFX_PPGTT_ENABLE)); 74 + } 75 + 76 + /* PPGTT support for Sandybdrige/Gen6 and later */ 77 + static void gen6_ppgtt_clear_range(struct i915_address_space *vm, 78 + u64 start, u64 length) 79 + { 80 + struct gen6_ppgtt * const ppgtt = to_gen6_ppgtt(i915_vm_to_ppgtt(vm)); 81 + const unsigned int first_entry = start / I915_GTT_PAGE_SIZE; 82 + const gen6_pte_t scratch_pte = vm->scratch[0].encode; 83 + unsigned int pde = first_entry / GEN6_PTES; 84 + unsigned int pte = first_entry % GEN6_PTES; 85 + unsigned int num_entries = length / I915_GTT_PAGE_SIZE; 86 + 87 + while (num_entries) { 88 + struct i915_page_table * const pt = 89 + i915_pt_entry(ppgtt->base.pd, pde++); 90 + const unsigned int count = min(num_entries, GEN6_PTES - pte); 91 + gen6_pte_t *vaddr; 92 + 93 + GEM_BUG_ON(px_base(pt) == px_base(&vm->scratch[1])); 94 + 95 + num_entries -= count; 96 + 97 + GEM_BUG_ON(count > atomic_read(&pt->used)); 98 + if (!atomic_sub_return(count, &pt->used)) 99 + ppgtt->scan_for_unused_pt = true; 100 + 101 + /* 102 + * Note that the hw doesn't support removing PDE on the fly 103 + * (they are cached inside the context with no means to 104 + * invalidate the cache), so we can only reset the PTE 105 + * entries back to scratch. 106 + */ 107 + 108 + vaddr = kmap_atomic_px(pt); 109 + memset32(vaddr + pte, scratch_pte, count); 110 + kunmap_atomic(vaddr); 111 + 112 + pte = 0; 113 + } 114 + } 115 + 116 + static void gen6_ppgtt_insert_entries(struct i915_address_space *vm, 117 + struct i915_vma *vma, 118 + enum i915_cache_level cache_level, 119 + u32 flags) 120 + { 121 + struct i915_ppgtt *ppgtt = i915_vm_to_ppgtt(vm); 122 + struct i915_page_directory * const pd = ppgtt->pd; 123 + unsigned int first_entry = vma->node.start / I915_GTT_PAGE_SIZE; 124 + unsigned int act_pt = first_entry / GEN6_PTES; 125 + unsigned int act_pte = first_entry % GEN6_PTES; 126 + const u32 pte_encode = vm->pte_encode(0, cache_level, flags); 127 + struct sgt_dma iter = sgt_dma(vma); 128 + gen6_pte_t *vaddr; 129 + 130 + GEM_BUG_ON(pd->entry[act_pt] == &vm->scratch[1]); 131 + 132 + vaddr = kmap_atomic_px(i915_pt_entry(pd, act_pt)); 133 + do { 134 + vaddr[act_pte] = pte_encode | GEN6_PTE_ADDR_ENCODE(iter.dma); 135 + 136 + iter.dma += I915_GTT_PAGE_SIZE; 137 + if (iter.dma == iter.max) { 138 + iter.sg = __sg_next(iter.sg); 139 + if (!iter.sg) 140 + break; 141 + 142 + iter.dma = sg_dma_address(iter.sg); 143 + iter.max = iter.dma + iter.sg->length; 144 + } 145 + 146 + if (++act_pte == GEN6_PTES) { 147 + kunmap_atomic(vaddr); 148 + vaddr = kmap_atomic_px(i915_pt_entry(pd, ++act_pt)); 149 + act_pte = 0; 150 + } 151 + } while (1); 152 + kunmap_atomic(vaddr); 153 + 154 + vma->page_sizes.gtt = I915_GTT_PAGE_SIZE; 155 + } 156 + 157 + static void gen6_flush_pd(struct gen6_ppgtt *ppgtt, u64 start, u64 end) 158 + { 159 + struct i915_page_directory * const pd = ppgtt->base.pd; 160 + struct i915_page_table *pt; 161 + unsigned int pde; 162 + 163 + start = round_down(start, SZ_64K); 164 + end = round_up(end, SZ_64K) - start; 165 + 166 + mutex_lock(&ppgtt->flush); 167 + 168 + gen6_for_each_pde(pt, pd, start, end, pde) 169 + gen6_write_pde(ppgtt, pde, pt); 170 + 171 + mb(); 172 + ioread32(ppgtt->pd_addr + pde - 1); 173 + gen6_ggtt_invalidate(ppgtt->base.vm.gt->ggtt); 174 + mb(); 175 + 176 + mutex_unlock(&ppgtt->flush); 177 + } 178 + 179 + static int gen6_alloc_va_range(struct i915_address_space *vm, 180 + u64 start, u64 length) 181 + { 182 + struct gen6_ppgtt *ppgtt = to_gen6_ppgtt(i915_vm_to_ppgtt(vm)); 183 + struct i915_page_directory * const pd = ppgtt->base.pd; 184 + struct i915_page_table *pt, *alloc = NULL; 185 + intel_wakeref_t wakeref; 186 + u64 from = start; 187 + unsigned int pde; 188 + int ret = 0; 189 + 190 + wakeref = intel_runtime_pm_get(&vm->i915->runtime_pm); 191 + 192 + spin_lock(&pd->lock); 193 + gen6_for_each_pde(pt, pd, start, length, pde) { 194 + const unsigned int count = gen6_pte_count(start, length); 195 + 196 + if (px_base(pt) == px_base(&vm->scratch[1])) { 197 + spin_unlock(&pd->lock); 198 + 199 + pt = fetch_and_zero(&alloc); 200 + if (!pt) 201 + pt = alloc_pt(vm); 202 + if (IS_ERR(pt)) { 203 + ret = PTR_ERR(pt); 204 + goto unwind_out; 205 + } 206 + 207 + fill32_px(pt, vm->scratch[0].encode); 208 + 209 + spin_lock(&pd->lock); 210 + if (pd->entry[pde] == &vm->scratch[1]) { 211 + pd->entry[pde] = pt; 212 + } else { 213 + alloc = pt; 214 + pt = pd->entry[pde]; 215 + } 216 + } 217 + 218 + atomic_add(count, &pt->used); 219 + } 220 + spin_unlock(&pd->lock); 221 + 222 + if (i915_vma_is_bound(ppgtt->vma, I915_VMA_GLOBAL_BIND)) 223 + gen6_flush_pd(ppgtt, from, start); 224 + 225 + goto out; 226 + 227 + unwind_out: 228 + gen6_ppgtt_clear_range(vm, from, start - from); 229 + out: 230 + if (alloc) 231 + free_px(vm, alloc); 232 + intel_runtime_pm_put(&vm->i915->runtime_pm, wakeref); 233 + return ret; 234 + } 235 + 236 + static int gen6_ppgtt_init_scratch(struct gen6_ppgtt *ppgtt) 237 + { 238 + struct i915_address_space * const vm = &ppgtt->base.vm; 239 + struct i915_page_directory * const pd = ppgtt->base.pd; 240 + int ret; 241 + 242 + ret = setup_scratch_page(vm, __GFP_HIGHMEM); 243 + if (ret) 244 + return ret; 245 + 246 + vm->scratch[0].encode = 247 + vm->pte_encode(px_dma(&vm->scratch[0]), 248 + I915_CACHE_NONE, PTE_READ_ONLY); 249 + 250 + if (unlikely(setup_page_dma(vm, px_base(&vm->scratch[1])))) { 251 + cleanup_scratch_page(vm); 252 + return -ENOMEM; 253 + } 254 + 255 + fill32_px(&vm->scratch[1], vm->scratch[0].encode); 256 + memset_p(pd->entry, &vm->scratch[1], I915_PDES); 257 + 258 + return 0; 259 + } 260 + 261 + static void gen6_ppgtt_free_pd(struct gen6_ppgtt *ppgtt) 262 + { 263 + struct i915_page_directory * const pd = ppgtt->base.pd; 264 + struct i915_page_dma * const scratch = 265 + px_base(&ppgtt->base.vm.scratch[1]); 266 + struct i915_page_table *pt; 267 + u32 pde; 268 + 269 + gen6_for_all_pdes(pt, pd, pde) 270 + if (px_base(pt) != scratch) 271 + free_px(&ppgtt->base.vm, pt); 272 + } 273 + 274 + static void gen6_ppgtt_cleanup(struct i915_address_space *vm) 275 + { 276 + struct gen6_ppgtt *ppgtt = to_gen6_ppgtt(i915_vm_to_ppgtt(vm)); 277 + 278 + __i915_vma_put(ppgtt->vma); 279 + 280 + gen6_ppgtt_free_pd(ppgtt); 281 + free_scratch(vm); 282 + 283 + mutex_destroy(&ppgtt->flush); 284 + mutex_destroy(&ppgtt->pin_mutex); 285 + kfree(ppgtt->base.pd); 286 + } 287 + 288 + static int pd_vma_set_pages(struct i915_vma *vma) 289 + { 290 + vma->pages = ERR_PTR(-ENODEV); 291 + return 0; 292 + } 293 + 294 + static void pd_vma_clear_pages(struct i915_vma *vma) 295 + { 296 + GEM_BUG_ON(!vma->pages); 297 + 298 + vma->pages = NULL; 299 + } 300 + 301 + static int pd_vma_bind(struct i915_vma *vma, 302 + enum i915_cache_level cache_level, 303 + u32 unused) 304 + { 305 + struct i915_ggtt *ggtt = i915_vm_to_ggtt(vma->vm); 306 + struct gen6_ppgtt *ppgtt = vma->private; 307 + u32 ggtt_offset = i915_ggtt_offset(vma) / I915_GTT_PAGE_SIZE; 308 + 309 + px_base(ppgtt->base.pd)->ggtt_offset = ggtt_offset * sizeof(gen6_pte_t); 310 + ppgtt->pd_addr = (gen6_pte_t __iomem *)ggtt->gsm + ggtt_offset; 311 + 312 + gen6_flush_pd(ppgtt, 0, ppgtt->base.vm.total); 313 + return 0; 314 + } 315 + 316 + static void pd_vma_unbind(struct i915_vma *vma) 317 + { 318 + struct gen6_ppgtt *ppgtt = vma->private; 319 + struct i915_page_directory * const pd = ppgtt->base.pd; 320 + struct i915_page_dma * const scratch = 321 + px_base(&ppgtt->base.vm.scratch[1]); 322 + struct i915_page_table *pt; 323 + unsigned int pde; 324 + 325 + if (!ppgtt->scan_for_unused_pt) 326 + return; 327 + 328 + /* Free all no longer used page tables */ 329 + gen6_for_all_pdes(pt, ppgtt->base.pd, pde) { 330 + if (px_base(pt) == scratch || atomic_read(&pt->used)) 331 + continue; 332 + 333 + free_px(&ppgtt->base.vm, pt); 334 + pd->entry[pde] = scratch; 335 + } 336 + 337 + ppgtt->scan_for_unused_pt = false; 338 + } 339 + 340 + static const struct i915_vma_ops pd_vma_ops = { 341 + .set_pages = pd_vma_set_pages, 342 + .clear_pages = pd_vma_clear_pages, 343 + .bind_vma = pd_vma_bind, 344 + .unbind_vma = pd_vma_unbind, 345 + }; 346 + 347 + static struct i915_vma *pd_vma_create(struct gen6_ppgtt *ppgtt, int size) 348 + { 349 + struct i915_ggtt *ggtt = ppgtt->base.vm.gt->ggtt; 350 + struct i915_vma *vma; 351 + 352 + GEM_BUG_ON(!IS_ALIGNED(size, I915_GTT_PAGE_SIZE)); 353 + GEM_BUG_ON(size > ggtt->vm.total); 354 + 355 + vma = i915_vma_alloc(); 356 + if (!vma) 357 + return ERR_PTR(-ENOMEM); 358 + 359 + i915_active_init(&vma->active, NULL, NULL); 360 + 361 + kref_init(&vma->ref); 362 + mutex_init(&vma->pages_mutex); 363 + vma->vm = i915_vm_get(&ggtt->vm); 364 + vma->ops = &pd_vma_ops; 365 + vma->private = ppgtt; 366 + 367 + vma->size = size; 368 + vma->fence_size = size; 369 + atomic_set(&vma->flags, I915_VMA_GGTT); 370 + vma->ggtt_view.type = I915_GGTT_VIEW_ROTATED; /* prevent fencing */ 371 + 372 + INIT_LIST_HEAD(&vma->obj_link); 373 + INIT_LIST_HEAD(&vma->closed_link); 374 + 375 + return vma; 376 + } 377 + 378 + int gen6_ppgtt_pin(struct i915_ppgtt *base) 379 + { 380 + struct gen6_ppgtt *ppgtt = to_gen6_ppgtt(base); 381 + int err; 382 + 383 + GEM_BUG_ON(!atomic_read(&ppgtt->base.vm.open)); 384 + 385 + /* 386 + * Workaround the limited maximum vma->pin_count and the aliasing_ppgtt 387 + * which will be pinned into every active context. 388 + * (When vma->pin_count becomes atomic, I expect we will naturally 389 + * need a larger, unpacked, type and kill this redundancy.) 390 + */ 391 + if (atomic_add_unless(&ppgtt->pin_count, 1, 0)) 392 + return 0; 393 + 394 + if (mutex_lock_interruptible(&ppgtt->pin_mutex)) 395 + return -EINTR; 396 + 397 + /* 398 + * PPGTT PDEs reside in the GGTT and consists of 512 entries. The 399 + * allocator works in address space sizes, so it's multiplied by page 400 + * size. We allocate at the top of the GTT to avoid fragmentation. 401 + */ 402 + err = 0; 403 + if (!atomic_read(&ppgtt->pin_count)) 404 + err = i915_ggtt_pin(ppgtt->vma, GEN6_PD_ALIGN, PIN_HIGH); 405 + if (!err) 406 + atomic_inc(&ppgtt->pin_count); 407 + mutex_unlock(&ppgtt->pin_mutex); 408 + 409 + return err; 410 + } 411 + 412 + void gen6_ppgtt_unpin(struct i915_ppgtt *base) 413 + { 414 + struct gen6_ppgtt *ppgtt = to_gen6_ppgtt(base); 415 + 416 + GEM_BUG_ON(!atomic_read(&ppgtt->pin_count)); 417 + if (atomic_dec_and_test(&ppgtt->pin_count)) 418 + i915_vma_unpin(ppgtt->vma); 419 + } 420 + 421 + void gen6_ppgtt_unpin_all(struct i915_ppgtt *base) 422 + { 423 + struct gen6_ppgtt *ppgtt = to_gen6_ppgtt(base); 424 + 425 + if (!atomic_read(&ppgtt->pin_count)) 426 + return; 427 + 428 + i915_vma_unpin(ppgtt->vma); 429 + atomic_set(&ppgtt->pin_count, 0); 430 + } 431 + 432 + struct i915_ppgtt *gen6_ppgtt_create(struct intel_gt *gt) 433 + { 434 + struct i915_ggtt * const ggtt = gt->ggtt; 435 + struct gen6_ppgtt *ppgtt; 436 + int err; 437 + 438 + ppgtt = kzalloc(sizeof(*ppgtt), GFP_KERNEL); 439 + if (!ppgtt) 440 + return ERR_PTR(-ENOMEM); 441 + 442 + mutex_init(&ppgtt->flush); 443 + mutex_init(&ppgtt->pin_mutex); 444 + 445 + ppgtt_init(&ppgtt->base, gt); 446 + ppgtt->base.vm.top = 1; 447 + 448 + ppgtt->base.vm.bind_async_flags = I915_VMA_LOCAL_BIND; 449 + ppgtt->base.vm.allocate_va_range = gen6_alloc_va_range; 450 + ppgtt->base.vm.clear_range = gen6_ppgtt_clear_range; 451 + ppgtt->base.vm.insert_entries = gen6_ppgtt_insert_entries; 452 + ppgtt->base.vm.cleanup = gen6_ppgtt_cleanup; 453 + 454 + ppgtt->base.vm.pte_encode = ggtt->vm.pte_encode; 455 + 456 + ppgtt->base.pd = __alloc_pd(sizeof(*ppgtt->base.pd)); 457 + if (!ppgtt->base.pd) { 458 + err = -ENOMEM; 459 + goto err_free; 460 + } 461 + 462 + err = gen6_ppgtt_init_scratch(ppgtt); 463 + if (err) 464 + goto err_pd; 465 + 466 + ppgtt->vma = pd_vma_create(ppgtt, GEN6_PD_SIZE); 467 + if (IS_ERR(ppgtt->vma)) { 468 + err = PTR_ERR(ppgtt->vma); 469 + goto err_scratch; 470 + } 471 + 472 + return &ppgtt->base; 473 + 474 + err_scratch: 475 + free_scratch(&ppgtt->base.vm); 476 + err_pd: 477 + kfree(ppgtt->base.pd); 478 + err_free: 479 + mutex_destroy(&ppgtt->pin_mutex); 480 + kfree(ppgtt); 481 + return ERR_PTR(err); 482 + }
+76
drivers/gpu/drm/i915/gt/gen6_ppgtt.h
··· 1 + /* SPDX-License-Identifier: MIT */ 2 + /* 3 + * Copyright © 2020 Intel Corporation 4 + */ 5 + 6 + #ifndef __GEN6_PPGTT_H__ 7 + #define __GEN6_PPGTT_H__ 8 + 9 + #include "intel_gtt.h" 10 + 11 + struct gen6_ppgtt { 12 + struct i915_ppgtt base; 13 + 14 + struct mutex flush; 15 + struct i915_vma *vma; 16 + gen6_pte_t __iomem *pd_addr; 17 + 18 + atomic_t pin_count; 19 + struct mutex pin_mutex; 20 + 21 + bool scan_for_unused_pt; 22 + }; 23 + 24 + static inline u32 gen6_pte_index(u32 addr) 25 + { 26 + return i915_pte_index(addr, GEN6_PDE_SHIFT); 27 + } 28 + 29 + static inline u32 gen6_pte_count(u32 addr, u32 length) 30 + { 31 + return i915_pte_count(addr, length, GEN6_PDE_SHIFT); 32 + } 33 + 34 + static inline u32 gen6_pde_index(u32 addr) 35 + { 36 + return i915_pde_index(addr, GEN6_PDE_SHIFT); 37 + } 38 + 39 + #define __to_gen6_ppgtt(base) container_of(base, struct gen6_ppgtt, base) 40 + 41 + static inline struct gen6_ppgtt *to_gen6_ppgtt(struct i915_ppgtt *base) 42 + { 43 + BUILD_BUG_ON(offsetof(struct gen6_ppgtt, base)); 44 + return __to_gen6_ppgtt(base); 45 + } 46 + 47 + /* 48 + * gen6_for_each_pde() iterates over every pde from start until start+length. 49 + * If start and start+length are not perfectly divisible, the macro will round 50 + * down and up as needed. Start=0 and length=2G effectively iterates over 51 + * every PDE in the system. The macro modifies ALL its parameters except 'pd', 52 + * so each of the other parameters should preferably be a simple variable, or 53 + * at most an lvalue with no side-effects! 54 + */ 55 + #define gen6_for_each_pde(pt, pd, start, length, iter) \ 56 + for (iter = gen6_pde_index(start); \ 57 + length > 0 && iter < I915_PDES && \ 58 + (pt = i915_pt_entry(pd, iter), true); \ 59 + ({ u32 temp = ALIGN(start+1, 1 << GEN6_PDE_SHIFT); \ 60 + temp = min(temp - start, length); \ 61 + start += temp, length -= temp; }), ++iter) 62 + 63 + #define gen6_for_all_pdes(pt, pd, iter) \ 64 + for (iter = 0; \ 65 + iter < I915_PDES && \ 66 + (pt = i915_pt_entry(pd, iter), true); \ 67 + ++iter) 68 + 69 + int gen6_ppgtt_pin(struct i915_ppgtt *base); 70 + void gen6_ppgtt_unpin(struct i915_ppgtt *base); 71 + void gen6_ppgtt_unpin_all(struct i915_ppgtt *base); 72 + void gen6_ppgtt_enable(struct intel_gt *gt); 73 + void gen7_ppgtt_enable(struct intel_gt *gt); 74 + struct i915_ppgtt *gen6_ppgtt_create(struct intel_gt *gt); 75 + 76 + #endif
+723
drivers/gpu/drm/i915/gt/gen8_ppgtt.c
··· 1 + // SPDX-License-Identifier: MIT 2 + /* 3 + * Copyright © 2020 Intel Corporation 4 + */ 5 + 6 + #include <linux/log2.h> 7 + 8 + #include "gen8_ppgtt.h" 9 + #include "i915_scatterlist.h" 10 + #include "i915_trace.h" 11 + #include "i915_vgpu.h" 12 + #include "intel_gt.h" 13 + #include "intel_gtt.h" 14 + 15 + static u64 gen8_pde_encode(const dma_addr_t addr, 16 + const enum i915_cache_level level) 17 + { 18 + u64 pde = addr | _PAGE_PRESENT | _PAGE_RW; 19 + 20 + if (level != I915_CACHE_NONE) 21 + pde |= PPAT_CACHED_PDE; 22 + else 23 + pde |= PPAT_UNCACHED; 24 + 25 + return pde; 26 + } 27 + 28 + static void gen8_ppgtt_notify_vgt(struct i915_ppgtt *ppgtt, bool create) 29 + { 30 + struct drm_i915_private *i915 = ppgtt->vm.i915; 31 + struct intel_uncore *uncore = ppgtt->vm.gt->uncore; 32 + enum vgt_g2v_type msg; 33 + int i; 34 + 35 + if (create) 36 + atomic_inc(px_used(ppgtt->pd)); /* never remove */ 37 + else 38 + atomic_dec(px_used(ppgtt->pd)); 39 + 40 + mutex_lock(&i915->vgpu.lock); 41 + 42 + if (i915_vm_is_4lvl(&ppgtt->vm)) { 43 + const u64 daddr = px_dma(ppgtt->pd); 44 + 45 + intel_uncore_write(uncore, 46 + vgtif_reg(pdp[0].lo), lower_32_bits(daddr)); 47 + intel_uncore_write(uncore, 48 + vgtif_reg(pdp[0].hi), upper_32_bits(daddr)); 49 + 50 + msg = create ? 51 + VGT_G2V_PPGTT_L4_PAGE_TABLE_CREATE : 52 + VGT_G2V_PPGTT_L4_PAGE_TABLE_DESTROY; 53 + } else { 54 + for (i = 0; i < GEN8_3LVL_PDPES; i++) { 55 + const u64 daddr = i915_page_dir_dma_addr(ppgtt, i); 56 + 57 + intel_uncore_write(uncore, 58 + vgtif_reg(pdp[i].lo), 59 + lower_32_bits(daddr)); 60 + intel_uncore_write(uncore, 61 + vgtif_reg(pdp[i].hi), 62 + upper_32_bits(daddr)); 63 + } 64 + 65 + msg = create ? 66 + VGT_G2V_PPGTT_L3_PAGE_TABLE_CREATE : 67 + VGT_G2V_PPGTT_L3_PAGE_TABLE_DESTROY; 68 + } 69 + 70 + /* g2v_notify atomically (via hv trap) consumes the message packet. */ 71 + intel_uncore_write(uncore, vgtif_reg(g2v_notify), msg); 72 + 73 + mutex_unlock(&i915->vgpu.lock); 74 + } 75 + 76 + /* Index shifts into the pagetable are offset by GEN8_PTE_SHIFT [12] */ 77 + #define GEN8_PAGE_SIZE (SZ_4K) /* page and page-directory sizes are the same */ 78 + #define GEN8_PTE_SHIFT (ilog2(GEN8_PAGE_SIZE)) 79 + #define GEN8_PDES (GEN8_PAGE_SIZE / sizeof(u64)) 80 + #define gen8_pd_shift(lvl) ((lvl) * ilog2(GEN8_PDES)) 81 + #define gen8_pd_index(i, lvl) i915_pde_index((i), gen8_pd_shift(lvl)) 82 + #define __gen8_pte_shift(lvl) (GEN8_PTE_SHIFT + gen8_pd_shift(lvl)) 83 + #define __gen8_pte_index(a, lvl) i915_pde_index((a), __gen8_pte_shift(lvl)) 84 + 85 + #define as_pd(x) container_of((x), typeof(struct i915_page_directory), pt) 86 + 87 + static inline unsigned int 88 + gen8_pd_range(u64 start, u64 end, int lvl, unsigned int *idx) 89 + { 90 + const int shift = gen8_pd_shift(lvl); 91 + const u64 mask = ~0ull << gen8_pd_shift(lvl + 1); 92 + 93 + GEM_BUG_ON(start >= end); 94 + end += ~mask >> gen8_pd_shift(1); 95 + 96 + *idx = i915_pde_index(start, shift); 97 + if ((start ^ end) & mask) 98 + return GEN8_PDES - *idx; 99 + else 100 + return i915_pde_index(end, shift) - *idx; 101 + } 102 + 103 + static inline bool gen8_pd_contains(u64 start, u64 end, int lvl) 104 + { 105 + const u64 mask = ~0ull << gen8_pd_shift(lvl + 1); 106 + 107 + GEM_BUG_ON(start >= end); 108 + return (start ^ end) & mask && (start & ~mask) == 0; 109 + } 110 + 111 + static inline unsigned int gen8_pt_count(u64 start, u64 end) 112 + { 113 + GEM_BUG_ON(start >= end); 114 + if ((start ^ end) >> gen8_pd_shift(1)) 115 + return GEN8_PDES - (start & (GEN8_PDES - 1)); 116 + else 117 + return end - start; 118 + } 119 + 120 + static inline unsigned int 121 + gen8_pd_top_count(const struct i915_address_space *vm) 122 + { 123 + unsigned int shift = __gen8_pte_shift(vm->top); 124 + return (vm->total + (1ull << shift) - 1) >> shift; 125 + } 126 + 127 + static inline struct i915_page_directory * 128 + gen8_pdp_for_page_index(struct i915_address_space * const vm, const u64 idx) 129 + { 130 + struct i915_ppgtt * const ppgtt = i915_vm_to_ppgtt(vm); 131 + 132 + if (vm->top == 2) 133 + return ppgtt->pd; 134 + else 135 + return i915_pd_entry(ppgtt->pd, gen8_pd_index(idx, vm->top)); 136 + } 137 + 138 + static inline struct i915_page_directory * 139 + gen8_pdp_for_page_address(struct i915_address_space * const vm, const u64 addr) 140 + { 141 + return gen8_pdp_for_page_index(vm, addr >> GEN8_PTE_SHIFT); 142 + } 143 + 144 + static void __gen8_ppgtt_cleanup(struct i915_address_space *vm, 145 + struct i915_page_directory *pd, 146 + int count, int lvl) 147 + { 148 + if (lvl) { 149 + void **pde = pd->entry; 150 + 151 + do { 152 + if (!*pde) 153 + continue; 154 + 155 + __gen8_ppgtt_cleanup(vm, *pde, GEN8_PDES, lvl - 1); 156 + } while (pde++, --count); 157 + } 158 + 159 + free_px(vm, pd); 160 + } 161 + 162 + static void gen8_ppgtt_cleanup(struct i915_address_space *vm) 163 + { 164 + struct i915_ppgtt *ppgtt = i915_vm_to_ppgtt(vm); 165 + 166 + if (intel_vgpu_active(vm->i915)) 167 + gen8_ppgtt_notify_vgt(ppgtt, false); 168 + 169 + __gen8_ppgtt_cleanup(vm, ppgtt->pd, gen8_pd_top_count(vm), vm->top); 170 + free_scratch(vm); 171 + } 172 + 173 + static u64 __gen8_ppgtt_clear(struct i915_address_space * const vm, 174 + struct i915_page_directory * const pd, 175 + u64 start, const u64 end, int lvl) 176 + { 177 + const struct i915_page_scratch * const scratch = &vm->scratch[lvl]; 178 + unsigned int idx, len; 179 + 180 + GEM_BUG_ON(end > vm->total >> GEN8_PTE_SHIFT); 181 + 182 + len = gen8_pd_range(start, end, lvl--, &idx); 183 + DBG("%s(%p):{ lvl:%d, start:%llx, end:%llx, idx:%d, len:%d, used:%d }\n", 184 + __func__, vm, lvl + 1, start, end, 185 + idx, len, atomic_read(px_used(pd))); 186 + GEM_BUG_ON(!len || len >= atomic_read(px_used(pd))); 187 + 188 + do { 189 + struct i915_page_table *pt = pd->entry[idx]; 190 + 191 + if (atomic_fetch_inc(&pt->used) >> gen8_pd_shift(1) && 192 + gen8_pd_contains(start, end, lvl)) { 193 + DBG("%s(%p):{ lvl:%d, idx:%d, start:%llx, end:%llx } removing pd\n", 194 + __func__, vm, lvl + 1, idx, start, end); 195 + clear_pd_entry(pd, idx, scratch); 196 + __gen8_ppgtt_cleanup(vm, as_pd(pt), I915_PDES, lvl); 197 + start += (u64)I915_PDES << gen8_pd_shift(lvl); 198 + continue; 199 + } 200 + 201 + if (lvl) { 202 + start = __gen8_ppgtt_clear(vm, as_pd(pt), 203 + start, end, lvl); 204 + } else { 205 + unsigned int count; 206 + u64 *vaddr; 207 + 208 + count = gen8_pt_count(start, end); 209 + DBG("%s(%p):{ lvl:%d, start:%llx, end:%llx, idx:%d, len:%d, used:%d } removing pte\n", 210 + __func__, vm, lvl, start, end, 211 + gen8_pd_index(start, 0), count, 212 + atomic_read(&pt->used)); 213 + GEM_BUG_ON(!count || count >= atomic_read(&pt->used)); 214 + 215 + vaddr = kmap_atomic_px(pt); 216 + memset64(vaddr + gen8_pd_index(start, 0), 217 + vm->scratch[0].encode, 218 + count); 219 + kunmap_atomic(vaddr); 220 + 221 + atomic_sub(count, &pt->used); 222 + start += count; 223 + } 224 + 225 + if (release_pd_entry(pd, idx, pt, scratch)) 226 + free_px(vm, pt); 227 + } while (idx++, --len); 228 + 229 + return start; 230 + } 231 + 232 + static void gen8_ppgtt_clear(struct i915_address_space *vm, 233 + u64 start, u64 length) 234 + { 235 + GEM_BUG_ON(!IS_ALIGNED(start, BIT_ULL(GEN8_PTE_SHIFT))); 236 + GEM_BUG_ON(!IS_ALIGNED(length, BIT_ULL(GEN8_PTE_SHIFT))); 237 + GEM_BUG_ON(range_overflows(start, length, vm->total)); 238 + 239 + start >>= GEN8_PTE_SHIFT; 240 + length >>= GEN8_PTE_SHIFT; 241 + GEM_BUG_ON(length == 0); 242 + 243 + __gen8_ppgtt_clear(vm, i915_vm_to_ppgtt(vm)->pd, 244 + start, start + length, vm->top); 245 + } 246 + 247 + static int __gen8_ppgtt_alloc(struct i915_address_space * const vm, 248 + struct i915_page_directory * const pd, 249 + u64 * const start, const u64 end, int lvl) 250 + { 251 + const struct i915_page_scratch * const scratch = &vm->scratch[lvl]; 252 + struct i915_page_table *alloc = NULL; 253 + unsigned int idx, len; 254 + int ret = 0; 255 + 256 + GEM_BUG_ON(end > vm->total >> GEN8_PTE_SHIFT); 257 + 258 + len = gen8_pd_range(*start, end, lvl--, &idx); 259 + DBG("%s(%p):{ lvl:%d, start:%llx, end:%llx, idx:%d, len:%d, used:%d }\n", 260 + __func__, vm, lvl + 1, *start, end, 261 + idx, len, atomic_read(px_used(pd))); 262 + GEM_BUG_ON(!len || (idx + len - 1) >> gen8_pd_shift(1)); 263 + 264 + spin_lock(&pd->lock); 265 + GEM_BUG_ON(!atomic_read(px_used(pd))); /* Must be pinned! */ 266 + do { 267 + struct i915_page_table *pt = pd->entry[idx]; 268 + 269 + if (!pt) { 270 + spin_unlock(&pd->lock); 271 + 272 + DBG("%s(%p):{ lvl:%d, idx:%d } allocating new tree\n", 273 + __func__, vm, lvl + 1, idx); 274 + 275 + pt = fetch_and_zero(&alloc); 276 + if (lvl) { 277 + if (!pt) { 278 + pt = &alloc_pd(vm)->pt; 279 + if (IS_ERR(pt)) { 280 + ret = PTR_ERR(pt); 281 + goto out; 282 + } 283 + } 284 + 285 + fill_px(pt, vm->scratch[lvl].encode); 286 + } else { 287 + if (!pt) { 288 + pt = alloc_pt(vm); 289 + if (IS_ERR(pt)) { 290 + ret = PTR_ERR(pt); 291 + goto out; 292 + } 293 + } 294 + 295 + if (intel_vgpu_active(vm->i915) || 296 + gen8_pt_count(*start, end) < I915_PDES) 297 + fill_px(pt, vm->scratch[lvl].encode); 298 + } 299 + 300 + spin_lock(&pd->lock); 301 + if (likely(!pd->entry[idx])) 302 + set_pd_entry(pd, idx, pt); 303 + else 304 + alloc = pt, pt = pd->entry[idx]; 305 + } 306 + 307 + if (lvl) { 308 + atomic_inc(&pt->used); 309 + spin_unlock(&pd->lock); 310 + 311 + ret = __gen8_ppgtt_alloc(vm, as_pd(pt), 312 + start, end, lvl); 313 + if (unlikely(ret)) { 314 + if (release_pd_entry(pd, idx, pt, scratch)) 315 + free_px(vm, pt); 316 + goto out; 317 + } 318 + 319 + spin_lock(&pd->lock); 320 + atomic_dec(&pt->used); 321 + GEM_BUG_ON(!atomic_read(&pt->used)); 322 + } else { 323 + unsigned int count = gen8_pt_count(*start, end); 324 + 325 + DBG("%s(%p):{ lvl:%d, start:%llx, end:%llx, idx:%d, len:%d, used:%d } inserting pte\n", 326 + __func__, vm, lvl, *start, end, 327 + gen8_pd_index(*start, 0), count, 328 + atomic_read(&pt->used)); 329 + 330 + atomic_add(count, &pt->used); 331 + /* All other pdes may be simultaneously removed */ 332 + GEM_BUG_ON(atomic_read(&pt->used) > NALLOC * I915_PDES); 333 + *start += count; 334 + } 335 + } while (idx++, --len); 336 + spin_unlock(&pd->lock); 337 + out: 338 + if (alloc) 339 + free_px(vm, alloc); 340 + return ret; 341 + } 342 + 343 + static int gen8_ppgtt_alloc(struct i915_address_space *vm, 344 + u64 start, u64 length) 345 + { 346 + u64 from; 347 + int err; 348 + 349 + GEM_BUG_ON(!IS_ALIGNED(start, BIT_ULL(GEN8_PTE_SHIFT))); 350 + GEM_BUG_ON(!IS_ALIGNED(length, BIT_ULL(GEN8_PTE_SHIFT))); 351 + GEM_BUG_ON(range_overflows(start, length, vm->total)); 352 + 353 + start >>= GEN8_PTE_SHIFT; 354 + length >>= GEN8_PTE_SHIFT; 355 + GEM_BUG_ON(length == 0); 356 + from = start; 357 + 358 + err = __gen8_ppgtt_alloc(vm, i915_vm_to_ppgtt(vm)->pd, 359 + &start, start + length, vm->top); 360 + if (unlikely(err && from != start)) 361 + __gen8_ppgtt_clear(vm, i915_vm_to_ppgtt(vm)->pd, 362 + from, start, vm->top); 363 + 364 + return err; 365 + } 366 + 367 + static __always_inline u64 368 + gen8_ppgtt_insert_pte(struct i915_ppgtt *ppgtt, 369 + struct i915_page_directory *pdp, 370 + struct sgt_dma *iter, 371 + u64 idx, 372 + enum i915_cache_level cache_level, 373 + u32 flags) 374 + { 375 + struct i915_page_directory *pd; 376 + const gen8_pte_t pte_encode = gen8_pte_encode(0, cache_level, flags); 377 + gen8_pte_t *vaddr; 378 + 379 + pd = i915_pd_entry(pdp, gen8_pd_index(idx, 2)); 380 + vaddr = kmap_atomic_px(i915_pt_entry(pd, gen8_pd_index(idx, 1))); 381 + do { 382 + vaddr[gen8_pd_index(idx, 0)] = pte_encode | iter->dma; 383 + 384 + iter->dma += I915_GTT_PAGE_SIZE; 385 + if (iter->dma >= iter->max) { 386 + iter->sg = __sg_next(iter->sg); 387 + if (!iter->sg) { 388 + idx = 0; 389 + break; 390 + } 391 + 392 + iter->dma = sg_dma_address(iter->sg); 393 + iter->max = iter->dma + iter->sg->length; 394 + } 395 + 396 + if (gen8_pd_index(++idx, 0) == 0) { 397 + if (gen8_pd_index(idx, 1) == 0) { 398 + /* Limited by sg length for 3lvl */ 399 + if (gen8_pd_index(idx, 2) == 0) 400 + break; 401 + 402 + pd = pdp->entry[gen8_pd_index(idx, 2)]; 403 + } 404 + 405 + kunmap_atomic(vaddr); 406 + vaddr = kmap_atomic_px(i915_pt_entry(pd, gen8_pd_index(idx, 1))); 407 + } 408 + } while (1); 409 + kunmap_atomic(vaddr); 410 + 411 + return idx; 412 + } 413 + 414 + static void gen8_ppgtt_insert_huge(struct i915_vma *vma, 415 + struct sgt_dma *iter, 416 + enum i915_cache_level cache_level, 417 + u32 flags) 418 + { 419 + const gen8_pte_t pte_encode = gen8_pte_encode(0, cache_level, flags); 420 + u64 start = vma->node.start; 421 + dma_addr_t rem = iter->sg->length; 422 + 423 + GEM_BUG_ON(!i915_vm_is_4lvl(vma->vm)); 424 + 425 + do { 426 + struct i915_page_directory * const pdp = 427 + gen8_pdp_for_page_address(vma->vm, start); 428 + struct i915_page_directory * const pd = 429 + i915_pd_entry(pdp, __gen8_pte_index(start, 2)); 430 + gen8_pte_t encode = pte_encode; 431 + unsigned int maybe_64K = -1; 432 + unsigned int page_size; 433 + gen8_pte_t *vaddr; 434 + u16 index; 435 + 436 + if (vma->page_sizes.sg & I915_GTT_PAGE_SIZE_2M && 437 + IS_ALIGNED(iter->dma, I915_GTT_PAGE_SIZE_2M) && 438 + rem >= I915_GTT_PAGE_SIZE_2M && 439 + !__gen8_pte_index(start, 0)) { 440 + index = __gen8_pte_index(start, 1); 441 + encode |= GEN8_PDE_PS_2M; 442 + page_size = I915_GTT_PAGE_SIZE_2M; 443 + 444 + vaddr = kmap_atomic_px(pd); 445 + } else { 446 + struct i915_page_table *pt = 447 + i915_pt_entry(pd, __gen8_pte_index(start, 1)); 448 + 449 + index = __gen8_pte_index(start, 0); 450 + page_size = I915_GTT_PAGE_SIZE; 451 + 452 + if (!index && 453 + vma->page_sizes.sg & I915_GTT_PAGE_SIZE_64K && 454 + IS_ALIGNED(iter->dma, I915_GTT_PAGE_SIZE_64K) && 455 + (IS_ALIGNED(rem, I915_GTT_PAGE_SIZE_64K) || 456 + rem >= (I915_PDES - index) * I915_GTT_PAGE_SIZE)) 457 + maybe_64K = __gen8_pte_index(start, 1); 458 + 459 + vaddr = kmap_atomic_px(pt); 460 + } 461 + 462 + do { 463 + GEM_BUG_ON(iter->sg->length < page_size); 464 + vaddr[index++] = encode | iter->dma; 465 + 466 + start += page_size; 467 + iter->dma += page_size; 468 + rem -= page_size; 469 + if (iter->dma >= iter->max) { 470 + iter->sg = __sg_next(iter->sg); 471 + if (!iter->sg) 472 + break; 473 + 474 + rem = iter->sg->length; 475 + iter->dma = sg_dma_address(iter->sg); 476 + iter->max = iter->dma + rem; 477 + 478 + if (maybe_64K != -1 && index < I915_PDES && 479 + !(IS_ALIGNED(iter->dma, I915_GTT_PAGE_SIZE_64K) && 480 + (IS_ALIGNED(rem, I915_GTT_PAGE_SIZE_64K) || 481 + rem >= (I915_PDES - index) * I915_GTT_PAGE_SIZE))) 482 + maybe_64K = -1; 483 + 484 + if (unlikely(!IS_ALIGNED(iter->dma, page_size))) 485 + break; 486 + } 487 + } while (rem >= page_size && index < I915_PDES); 488 + 489 + kunmap_atomic(vaddr); 490 + 491 + /* 492 + * Is it safe to mark the 2M block as 64K? -- Either we have 493 + * filled whole page-table with 64K entries, or filled part of 494 + * it and have reached the end of the sg table and we have 495 + * enough padding. 496 + */ 497 + if (maybe_64K != -1 && 498 + (index == I915_PDES || 499 + (i915_vm_has_scratch_64K(vma->vm) && 500 + !iter->sg && IS_ALIGNED(vma->node.start + 501 + vma->node.size, 502 + I915_GTT_PAGE_SIZE_2M)))) { 503 + vaddr = kmap_atomic_px(pd); 504 + vaddr[maybe_64K] |= GEN8_PDE_IPS_64K; 505 + kunmap_atomic(vaddr); 506 + page_size = I915_GTT_PAGE_SIZE_64K; 507 + 508 + /* 509 + * We write all 4K page entries, even when using 64K 510 + * pages. In order to verify that the HW isn't cheating 511 + * by using the 4K PTE instead of the 64K PTE, we want 512 + * to remove all the surplus entries. If the HW skipped 513 + * the 64K PTE, it will read/write into the scratch page 514 + * instead - which we detect as missing results during 515 + * selftests. 516 + */ 517 + if (I915_SELFTEST_ONLY(vma->vm->scrub_64K)) { 518 + u16 i; 519 + 520 + encode = vma->vm->scratch[0].encode; 521 + vaddr = kmap_atomic_px(i915_pt_entry(pd, maybe_64K)); 522 + 523 + for (i = 1; i < index; i += 16) 524 + memset64(vaddr + i, encode, 15); 525 + 526 + kunmap_atomic(vaddr); 527 + } 528 + } 529 + 530 + vma->page_sizes.gtt |= page_size; 531 + } while (iter->sg); 532 + } 533 + 534 + static void gen8_ppgtt_insert(struct i915_address_space *vm, 535 + struct i915_vma *vma, 536 + enum i915_cache_level cache_level, 537 + u32 flags) 538 + { 539 + struct i915_ppgtt * const ppgtt = i915_vm_to_ppgtt(vm); 540 + struct sgt_dma iter = sgt_dma(vma); 541 + 542 + if (vma->page_sizes.sg > I915_GTT_PAGE_SIZE) { 543 + gen8_ppgtt_insert_huge(vma, &iter, cache_level, flags); 544 + } else { 545 + u64 idx = vma->node.start >> GEN8_PTE_SHIFT; 546 + 547 + do { 548 + struct i915_page_directory * const pdp = 549 + gen8_pdp_for_page_index(vm, idx); 550 + 551 + idx = gen8_ppgtt_insert_pte(ppgtt, pdp, &iter, idx, 552 + cache_level, flags); 553 + } while (idx); 554 + 555 + vma->page_sizes.gtt = I915_GTT_PAGE_SIZE; 556 + } 557 + } 558 + 559 + static int gen8_init_scratch(struct i915_address_space *vm) 560 + { 561 + int ret; 562 + int i; 563 + 564 + /* 565 + * If everybody agrees to not to write into the scratch page, 566 + * we can reuse it for all vm, keeping contexts and processes separate. 567 + */ 568 + if (vm->has_read_only && vm->gt->vm && !i915_is_ggtt(vm->gt->vm)) { 569 + struct i915_address_space *clone = vm->gt->vm; 570 + 571 + GEM_BUG_ON(!clone->has_read_only); 572 + 573 + vm->scratch_order = clone->scratch_order; 574 + memcpy(vm->scratch, clone->scratch, sizeof(vm->scratch)); 575 + px_dma(&vm->scratch[0]) = 0; /* no xfer of ownership */ 576 + return 0; 577 + } 578 + 579 + ret = setup_scratch_page(vm, __GFP_HIGHMEM); 580 + if (ret) 581 + return ret; 582 + 583 + vm->scratch[0].encode = 584 + gen8_pte_encode(px_dma(&vm->scratch[0]), 585 + I915_CACHE_LLC, vm->has_read_only); 586 + 587 + for (i = 1; i <= vm->top; i++) { 588 + if (unlikely(setup_page_dma(vm, px_base(&vm->scratch[i])))) 589 + goto free_scratch; 590 + 591 + fill_px(&vm->scratch[i], vm->scratch[i - 1].encode); 592 + vm->scratch[i].encode = 593 + gen8_pde_encode(px_dma(&vm->scratch[i]), 594 + I915_CACHE_LLC); 595 + } 596 + 597 + return 0; 598 + 599 + free_scratch: 600 + free_scratch(vm); 601 + return -ENOMEM; 602 + } 603 + 604 + static int gen8_preallocate_top_level_pdp(struct i915_ppgtt *ppgtt) 605 + { 606 + struct i915_address_space *vm = &ppgtt->vm; 607 + struct i915_page_directory *pd = ppgtt->pd; 608 + unsigned int idx; 609 + 610 + GEM_BUG_ON(vm->top != 2); 611 + GEM_BUG_ON(gen8_pd_top_count(vm) != GEN8_3LVL_PDPES); 612 + 613 + for (idx = 0; idx < GEN8_3LVL_PDPES; idx++) { 614 + struct i915_page_directory *pde; 615 + 616 + pde = alloc_pd(vm); 617 + if (IS_ERR(pde)) 618 + return PTR_ERR(pde); 619 + 620 + fill_px(pde, vm->scratch[1].encode); 621 + set_pd_entry(pd, idx, pde); 622 + atomic_inc(px_used(pde)); /* keep pinned */ 623 + } 624 + wmb(); 625 + 626 + return 0; 627 + } 628 + 629 + static struct i915_page_directory * 630 + gen8_alloc_top_pd(struct i915_address_space *vm) 631 + { 632 + const unsigned int count = gen8_pd_top_count(vm); 633 + struct i915_page_directory *pd; 634 + 635 + GEM_BUG_ON(count > ARRAY_SIZE(pd->entry)); 636 + 637 + pd = __alloc_pd(offsetof(typeof(*pd), entry[count])); 638 + if (unlikely(!pd)) 639 + return ERR_PTR(-ENOMEM); 640 + 641 + if (unlikely(setup_page_dma(vm, px_base(pd)))) { 642 + kfree(pd); 643 + return ERR_PTR(-ENOMEM); 644 + } 645 + 646 + fill_page_dma(px_base(pd), vm->scratch[vm->top].encode, count); 647 + atomic_inc(px_used(pd)); /* mark as pinned */ 648 + return pd; 649 + } 650 + 651 + /* 652 + * GEN8 legacy ppgtt programming is accomplished through a max 4 PDP registers 653 + * with a net effect resembling a 2-level page table in normal x86 terms. Each 654 + * PDP represents 1GB of memory 4 * 512 * 512 * 4096 = 4GB legacy 32b address 655 + * space. 656 + * 657 + */ 658 + struct i915_ppgtt *gen8_ppgtt_create(struct intel_gt *gt) 659 + { 660 + struct i915_ppgtt *ppgtt; 661 + int err; 662 + 663 + ppgtt = kzalloc(sizeof(*ppgtt), GFP_KERNEL); 664 + if (!ppgtt) 665 + return ERR_PTR(-ENOMEM); 666 + 667 + ppgtt_init(ppgtt, gt); 668 + ppgtt->vm.top = i915_vm_is_4lvl(&ppgtt->vm) ? 3 : 2; 669 + 670 + /* 671 + * From bdw, there is hw support for read-only pages in the PPGTT. 672 + * 673 + * Gen11 has HSDES#:1807136187 unresolved. Disable ro support 674 + * for now. 675 + * 676 + * Gen12 has inherited the same read-only fault issue from gen11. 677 + */ 678 + ppgtt->vm.has_read_only = !IS_GEN_RANGE(gt->i915, 11, 12); 679 + 680 + /* 681 + * There are only few exceptions for gen >=6. chv and bxt. 682 + * And we are not sure about the latter so play safe for now. 683 + */ 684 + if (IS_CHERRYVIEW(gt->i915) || IS_BROXTON(gt->i915)) 685 + ppgtt->vm.pt_kmap_wc = true; 686 + 687 + err = gen8_init_scratch(&ppgtt->vm); 688 + if (err) 689 + goto err_free; 690 + 691 + ppgtt->pd = gen8_alloc_top_pd(&ppgtt->vm); 692 + if (IS_ERR(ppgtt->pd)) { 693 + err = PTR_ERR(ppgtt->pd); 694 + goto err_free_scratch; 695 + } 696 + 697 + if (!i915_vm_is_4lvl(&ppgtt->vm)) { 698 + err = gen8_preallocate_top_level_pdp(ppgtt); 699 + if (err) 700 + goto err_free_pd; 701 + } 702 + 703 + ppgtt->vm.bind_async_flags = I915_VMA_LOCAL_BIND; 704 + ppgtt->vm.insert_entries = gen8_ppgtt_insert; 705 + ppgtt->vm.allocate_va_range = gen8_ppgtt_alloc; 706 + ppgtt->vm.clear_range = gen8_ppgtt_clear; 707 + 708 + if (intel_vgpu_active(gt->i915)) 709 + gen8_ppgtt_notify_vgt(ppgtt, true); 710 + 711 + ppgtt->vm.cleanup = gen8_ppgtt_cleanup; 712 + 713 + return ppgtt; 714 + 715 + err_free_pd: 716 + __gen8_ppgtt_cleanup(&ppgtt->vm, ppgtt->pd, 717 + gen8_pd_top_count(&ppgtt->vm), ppgtt->vm.top); 718 + err_free_scratch: 719 + free_scratch(&ppgtt->vm); 720 + err_free: 721 + kfree(ppgtt); 722 + return ERR_PTR(err); 723 + }
+13
drivers/gpu/drm/i915/gt/gen8_ppgtt.h
··· 1 + /* SPDX-License-Identifier: MIT */ 2 + /* 3 + * Copyright © 2020 Intel Corporation 4 + */ 5 + 6 + #ifndef __GEN8_PPGTT_H__ 7 + #define __GEN8_PPGTT_H__ 8 + 9 + struct intel_gt; 10 + 11 + struct i915_ppgtt *gen8_ppgtt_create(struct intel_gt *gt); 12 + 13 + #endif
+181 -127
drivers/gpu/drm/i915/gt/intel_context.c
··· 43 43 return ce; 44 44 } 45 45 46 - int __intel_context_do_pin(struct intel_context *ce) 46 + int intel_context_alloc_state(struct intel_context *ce) 47 47 { 48 - int err; 48 + int err = 0; 49 49 50 50 if (mutex_lock_interruptible(&ce->pin_mutex)) 51 51 return -EINTR; 52 52 53 - if (likely(!atomic_read(&ce->pin_count))) { 54 - intel_wakeref_t wakeref; 53 + if (!test_bit(CONTEXT_ALLOC_BIT, &ce->flags)) { 54 + err = ce->ops->alloc(ce); 55 + if (unlikely(err)) 56 + goto unlock; 55 57 56 - if (unlikely(!test_bit(CONTEXT_ALLOC_BIT, &ce->flags))) { 57 - err = ce->ops->alloc(ce); 58 - if (unlikely(err)) 59 - goto err; 60 - 61 - __set_bit(CONTEXT_ALLOC_BIT, &ce->flags); 62 - } 63 - 64 - err = 0; 65 - with_intel_runtime_pm(ce->engine->uncore->rpm, wakeref) 66 - err = ce->ops->pin(ce); 67 - if (err) 68 - goto err; 69 - 70 - CE_TRACE(ce, "pin ring:{head:%04x, tail:%04x}\n", 71 - ce->ring->head, ce->ring->tail); 72 - 73 - smp_mb__before_atomic(); /* flush pin before it is visible */ 58 + set_bit(CONTEXT_ALLOC_BIT, &ce->flags); 74 59 } 75 60 76 - atomic_inc(&ce->pin_count); 77 - GEM_BUG_ON(!intel_context_is_pinned(ce)); /* no overflow! */ 78 - 79 - mutex_unlock(&ce->pin_mutex); 80 - return 0; 81 - 82 - err: 61 + unlock: 83 62 mutex_unlock(&ce->pin_mutex); 84 63 return err; 85 64 } 86 65 87 - void intel_context_unpin(struct intel_context *ce) 88 - { 89 - if (likely(atomic_add_unless(&ce->pin_count, -1, 1))) 90 - return; 91 - 92 - /* We may be called from inside intel_context_pin() to evict another */ 93 - intel_context_get(ce); 94 - mutex_lock_nested(&ce->pin_mutex, SINGLE_DEPTH_NESTING); 95 - 96 - if (likely(atomic_dec_and_test(&ce->pin_count))) { 97 - CE_TRACE(ce, "retire\n"); 98 - 99 - ce->ops->unpin(ce); 100 - 101 - intel_context_active_release(ce); 102 - } 103 - 104 - mutex_unlock(&ce->pin_mutex); 105 - intel_context_put(ce); 106 - } 107 - 108 - static int __context_pin_state(struct i915_vma *vma) 109 - { 110 - unsigned int bias = i915_ggtt_pin_bias(vma) | PIN_OFFSET_BIAS; 111 - int err; 112 - 113 - err = i915_ggtt_pin(vma, 0, bias | PIN_HIGH); 114 - if (err) 115 - return err; 116 - 117 - /* 118 - * And mark it as a globally pinned object to let the shrinker know 119 - * it cannot reclaim the object until we release it. 120 - */ 121 - i915_vma_make_unshrinkable(vma); 122 - vma->obj->mm.dirty = true; 123 - 124 - return 0; 125 - } 126 - 127 - static void __context_unpin_state(struct i915_vma *vma) 128 - { 129 - i915_vma_make_shrinkable(vma); 130 - __i915_vma_unpin(vma); 131 - } 132 - 133 - __i915_active_call 134 - static void __intel_context_retire(struct i915_active *active) 135 - { 136 - struct intel_context *ce = container_of(active, typeof(*ce), active); 137 - 138 - CE_TRACE(ce, "retire\n"); 139 - 140 - set_bit(CONTEXT_VALID_BIT, &ce->flags); 141 - if (ce->state) 142 - __context_unpin_state(ce->state); 143 - 144 - intel_timeline_unpin(ce->timeline); 145 - intel_ring_unpin(ce->ring); 146 - 147 - intel_context_put(ce); 148 - } 149 - 150 - static int __intel_context_active(struct i915_active *active) 151 - { 152 - struct intel_context *ce = container_of(active, typeof(*ce), active); 153 - int err; 154 - 155 - intel_context_get(ce); 156 - 157 - err = intel_ring_pin(ce->ring); 158 - if (err) 159 - goto err_put; 160 - 161 - err = intel_timeline_pin(ce->timeline); 162 - if (err) 163 - goto err_ring; 164 - 165 - if (!ce->state) 166 - return 0; 167 - 168 - err = __context_pin_state(ce->state); 169 - if (err) 170 - goto err_timeline; 171 - 172 - return 0; 173 - 174 - err_timeline: 175 - intel_timeline_unpin(ce->timeline); 176 - err_ring: 177 - intel_ring_unpin(ce->ring); 178 - err_put: 179 - intel_context_put(ce); 180 - return err; 181 - } 182 - 183 - int intel_context_active_acquire(struct intel_context *ce) 66 + static int intel_context_active_acquire(struct intel_context *ce) 184 67 { 185 68 int err; 186 69 ··· 84 201 return 0; 85 202 } 86 203 87 - void intel_context_active_release(struct intel_context *ce) 204 + static void intel_context_active_release(struct intel_context *ce) 88 205 { 89 206 /* Nodes preallocated in intel_context_active() */ 90 207 i915_active_acquire_barrier(&ce->active); 91 208 i915_active_release(&ce->active); 209 + } 210 + 211 + int __intel_context_do_pin(struct intel_context *ce) 212 + { 213 + int err; 214 + 215 + if (unlikely(!test_bit(CONTEXT_ALLOC_BIT, &ce->flags))) { 216 + err = intel_context_alloc_state(ce); 217 + if (err) 218 + return err; 219 + } 220 + 221 + if (mutex_lock_interruptible(&ce->pin_mutex)) 222 + return -EINTR; 223 + 224 + if (likely(!atomic_read(&ce->pin_count))) { 225 + err = intel_context_active_acquire(ce); 226 + if (unlikely(err)) 227 + goto err; 228 + 229 + err = ce->ops->pin(ce); 230 + if (unlikely(err)) 231 + goto err_active; 232 + 233 + CE_TRACE(ce, "pin ring:{head:%04x, tail:%04x}\n", 234 + ce->ring->head, ce->ring->tail); 235 + 236 + smp_mb__before_atomic(); /* flush pin before it is visible */ 237 + } 238 + 239 + atomic_inc(&ce->pin_count); 240 + GEM_BUG_ON(!intel_context_is_pinned(ce)); /* no overflow! */ 241 + 242 + mutex_unlock(&ce->pin_mutex); 243 + return 0; 244 + 245 + err_active: 246 + intel_context_active_release(ce); 247 + err: 248 + mutex_unlock(&ce->pin_mutex); 249 + return err; 250 + } 251 + 252 + void intel_context_unpin(struct intel_context *ce) 253 + { 254 + if (!atomic_dec_and_test(&ce->pin_count)) 255 + return; 256 + 257 + CE_TRACE(ce, "unpin\n"); 258 + ce->ops->unpin(ce); 259 + 260 + /* 261 + * Once released, we may asynchronously drop the active reference. 262 + * As that may be the only reference keeping the context alive, 263 + * take an extra now so that it is not freed before we finish 264 + * dereferencing it. 265 + */ 266 + intel_context_get(ce); 267 + intel_context_active_release(ce); 268 + intel_context_put(ce); 269 + } 270 + 271 + static int __context_pin_state(struct i915_vma *vma) 272 + { 273 + unsigned int bias = i915_ggtt_pin_bias(vma) | PIN_OFFSET_BIAS; 274 + int err; 275 + 276 + err = i915_ggtt_pin(vma, 0, bias | PIN_HIGH); 277 + if (err) 278 + return err; 279 + 280 + err = i915_active_acquire(&vma->active); 281 + if (err) 282 + goto err_unpin; 283 + 284 + /* 285 + * And mark it as a globally pinned object to let the shrinker know 286 + * it cannot reclaim the object until we release it. 287 + */ 288 + i915_vma_make_unshrinkable(vma); 289 + vma->obj->mm.dirty = true; 290 + 291 + return 0; 292 + 293 + err_unpin: 294 + i915_vma_unpin(vma); 295 + return err; 296 + } 297 + 298 + static void __context_unpin_state(struct i915_vma *vma) 299 + { 300 + i915_vma_make_shrinkable(vma); 301 + i915_active_release(&vma->active); 302 + __i915_vma_unpin(vma); 303 + } 304 + 305 + static int __ring_active(struct intel_ring *ring) 306 + { 307 + int err; 308 + 309 + err = i915_active_acquire(&ring->vma->active); 310 + if (err) 311 + return err; 312 + 313 + err = intel_ring_pin(ring); 314 + if (err) 315 + goto err_active; 316 + 317 + return 0; 318 + 319 + err_active: 320 + i915_active_release(&ring->vma->active); 321 + return err; 322 + } 323 + 324 + static void __ring_retire(struct intel_ring *ring) 325 + { 326 + intel_ring_unpin(ring); 327 + i915_active_release(&ring->vma->active); 328 + } 329 + 330 + __i915_active_call 331 + static void __intel_context_retire(struct i915_active *active) 332 + { 333 + struct intel_context *ce = container_of(active, typeof(*ce), active); 334 + 335 + CE_TRACE(ce, "retire\n"); 336 + 337 + set_bit(CONTEXT_VALID_BIT, &ce->flags); 338 + if (ce->state) 339 + __context_unpin_state(ce->state); 340 + 341 + intel_timeline_unpin(ce->timeline); 342 + __ring_retire(ce->ring); 343 + 344 + intel_context_put(ce); 345 + } 346 + 347 + static int __intel_context_active(struct i915_active *active) 348 + { 349 + struct intel_context *ce = container_of(active, typeof(*ce), active); 350 + int err; 351 + 352 + CE_TRACE(ce, "active\n"); 353 + 354 + intel_context_get(ce); 355 + 356 + err = __ring_active(ce->ring); 357 + if (err) 358 + goto err_put; 359 + 360 + err = intel_timeline_pin(ce->timeline); 361 + if (err) 362 + goto err_ring; 363 + 364 + if (!ce->state) 365 + return 0; 366 + 367 + err = __context_pin_state(ce->state); 368 + if (err) 369 + goto err_timeline; 370 + 371 + return 0; 372 + 373 + err_timeline: 374 + intel_timeline_unpin(ce->timeline); 375 + err_ring: 376 + __ring_retire(ce->ring); 377 + err_put: 378 + intel_context_put(ce); 379 + return err; 92 380 } 93 381 94 382 void
+9 -5
drivers/gpu/drm/i915/gt/intel_context.h
··· 19 19 20 20 #define CE_TRACE(ce, fmt, ...) do { \ 21 21 const struct intel_context *ce__ = (ce); \ 22 - ENGINE_TRACE(ce__->engine, "context:%llx" fmt, \ 22 + ENGINE_TRACE(ce__->engine, "context:%llx " fmt, \ 23 23 ce__->timeline->fence_context, \ 24 24 ##__VA_ARGS__); \ 25 25 } while (0) ··· 30 30 31 31 struct intel_context * 32 32 intel_context_create(struct intel_engine_cs *engine); 33 + 34 + int intel_context_alloc_state(struct intel_context *ce); 33 35 34 36 void intel_context_free(struct intel_context *ce); 35 37 ··· 78 76 79 77 int __intel_context_do_pin(struct intel_context *ce); 80 78 79 + static inline bool intel_context_pin_if_active(struct intel_context *ce) 80 + { 81 + return atomic_inc_not_zero(&ce->pin_count); 82 + } 83 + 81 84 static inline int intel_context_pin(struct intel_context *ce) 82 85 { 83 - if (likely(atomic_inc_not_zero(&ce->pin_count))) 86 + if (likely(intel_context_pin_if_active(ce))) 84 87 return 0; 85 88 86 89 return __intel_context_do_pin(ce); ··· 122 115 if (!--ce->active_count) 123 116 ce->ops->exit(ce); 124 117 } 125 - 126 - int intel_context_active_acquire(struct intel_context *ce); 127 - void intel_context_active_release(struct intel_context *ce); 128 118 129 119 static inline struct intel_context *intel_context_get(struct intel_context *ce) 130 120 {
+2
drivers/gpu/drm/i915/gt/intel_context_types.h
··· 17 17 #include "intel_engine_types.h" 18 18 #include "intel_sseu.h" 19 19 20 + #define CONTEXT_REDZONE POISON_INUSE 21 + 20 22 struct i915_gem_context; 21 23 struct i915_vma; 22 24 struct intel_context;
+2 -2
drivers/gpu/drm/i915/gt/intel_engine.h
··· 202 202 u64 intel_engine_get_active_head(const struct intel_engine_cs *engine); 203 203 u64 intel_engine_get_last_batch_head(const struct intel_engine_cs *engine); 204 204 205 - void intel_engine_get_instdone(struct intel_engine_cs *engine, 205 + void intel_engine_get_instdone(const struct intel_engine_cs *engine, 206 206 struct intel_instdone *instdone); 207 207 208 208 void intel_engine_init_execlists(struct intel_engine_cs *engine); ··· 282 282 283 283 bool intel_engines_are_idle(struct intel_gt *gt); 284 284 bool intel_engine_is_idle(struct intel_engine_cs *engine); 285 - bool intel_engine_flush_submission(struct intel_engine_cs *engine); 285 + void intel_engine_flush_submission(struct intel_engine_cs *engine); 286 286 287 287 void intel_engines_reset_default_submission(struct intel_gt *gt); 288 288
+4 -8
drivers/gpu/drm/i915/gt/intel_engine_cs.c
··· 914 914 } 915 915 916 916 static u32 917 - read_subslice_reg(struct intel_engine_cs *engine, int slice, int subslice, 918 - i915_reg_t reg) 917 + read_subslice_reg(const struct intel_engine_cs *engine, 918 + int slice, int subslice, i915_reg_t reg) 919 919 { 920 920 struct drm_i915_private *i915 = engine->i915; 921 921 struct intel_uncore *uncore = engine->uncore; ··· 959 959 } 960 960 961 961 /* NB: please notice the memset */ 962 - void intel_engine_get_instdone(struct intel_engine_cs *engine, 962 + void intel_engine_get_instdone(const struct intel_engine_cs *engine, 963 963 struct intel_instdone *instdone) 964 964 { 965 965 struct drm_i915_private *i915 = engine->i915; ··· 1047 1047 return idle; 1048 1048 } 1049 1049 1050 - bool intel_engine_flush_submission(struct intel_engine_cs *engine) 1050 + void intel_engine_flush_submission(struct intel_engine_cs *engine) 1051 1051 { 1052 1052 struct tasklet_struct *t = &engine->execlists.tasklet; 1053 - bool active = tasklet_is_locked(t); 1054 1053 1055 1054 if (__tasklet_is_scheduled(t)) { 1056 1055 local_bh_disable(); ··· 1060 1061 tasklet_unlock(t); 1061 1062 } 1062 1063 local_bh_enable(); 1063 - active = true; 1064 1064 } 1065 1065 1066 1066 /* Otherwise flush the tasklet if it was running on another cpu */ 1067 1067 tasklet_unlock_wait(t); 1068 - 1069 - return active; 1070 1068 } 1071 1069 1072 1070 /**
+1 -1
drivers/gpu/drm/i915/gt/intel_engine_heartbeat.c
··· 199 199 goto out_unlock; 200 200 } 201 201 202 - rq->flags |= I915_REQUEST_SENTINEL; 202 + __set_bit(I915_FENCE_FLAG_SENTINEL, &rq->fence.flags); 203 203 idle_pulse(engine, rq); 204 204 205 205 __i915_request_commit(rq);
+26 -4
drivers/gpu/drm/i915/gt/intel_engine_pm.c
··· 20 20 { 21 21 struct intel_engine_cs *engine = 22 22 container_of(wf, typeof(*engine), wakeref); 23 + struct intel_context *ce; 23 24 void *map; 24 25 25 26 ENGINE_TRACE(engine, "\n"); ··· 34 33 I915_MAP_WB); 35 34 if (!IS_ERR_OR_NULL(map)) 36 35 engine->pinned_default_state = map; 36 + 37 + /* Discard stale context state from across idling */ 38 + ce = engine->kernel_context; 39 + if (ce) { 40 + GEM_BUG_ON(test_bit(CONTEXT_VALID_BIT, &ce->flags)); 41 + 42 + /* First poison the image to verify we never fully trust it */ 43 + if (IS_ENABLED(CONFIG_DRM_I915_DEBUG_GEM) && ce->state) { 44 + struct drm_i915_gem_object *obj = ce->state->obj; 45 + int type = i915_coherent_map_type(engine->i915); 46 + 47 + map = i915_gem_object_pin_map(obj, type); 48 + if (!IS_ERR(map)) { 49 + memset(map, CONTEXT_REDZONE, obj->base.size); 50 + i915_gem_object_flush_map(obj); 51 + i915_gem_object_unpin_map(obj); 52 + } 53 + } 54 + 55 + ce->ops->reset(ce); 56 + } 37 57 38 58 if (engine->unpark) 39 59 engine->unpark(engine); ··· 145 123 unsigned long flags; 146 124 bool result = true; 147 125 126 + /* GPU is pointing to the void, as good as in the kernel context. */ 127 + if (intel_gt_is_wedged(engine->gt)) 128 + return true; 129 + 148 130 GEM_BUG_ON(!intel_context_is_barrier(ce)); 149 131 150 132 /* Already inside the kernel context, safe to power down. */ 151 133 if (engine->wakeref_serial == engine->serial) 152 - return true; 153 - 154 - /* GPU is pointing to the void, as good as in the kernel context. */ 155 - if (intel_gt_is_wedged(engine->gt)) 156 134 return true; 157 135 158 136 /*
+4
drivers/gpu/drm/i915/gt/intel_engine_user.c
··· 11 11 #include "i915_drv.h" 12 12 #include "intel_engine.h" 13 13 #include "intel_engine_user.h" 14 + #include "intel_gt.h" 14 15 15 16 struct intel_engine_cs * 16 17 intel_engine_lookup_user(struct drm_i915_private *i915, u8 class, u8 instance) ··· 200 199 container_of((struct rb_node *)it, typeof(*engine), 201 200 uabi_node); 202 201 char old[sizeof(engine->name)]; 202 + 203 + if (intel_gt_has_init_error(engine->gt)) 204 + continue; /* ignore incomplete engines */ 203 205 204 206 GEM_BUG_ON(engine->class >= ARRAY_SIZE(uabi_classes)); 205 207 engine->uabi_class = uabi_classes[engine->class];
+1486
drivers/gpu/drm/i915/gt/intel_ggtt.c
··· 1 + // SPDX-License-Identifier: MIT 2 + /* 3 + * Copyright © 2020 Intel Corporation 4 + */ 5 + 6 + #include <linux/stop_machine.h> 7 + 8 + #include <asm/set_memory.h> 9 + #include <asm/smp.h> 10 + 11 + #include "intel_gt.h" 12 + #include "i915_drv.h" 13 + #include "i915_scatterlist.h" 14 + #include "i915_vgpu.h" 15 + 16 + #include "intel_gtt.h" 17 + 18 + static int 19 + i915_get_ggtt_vma_pages(struct i915_vma *vma); 20 + 21 + static void i915_ggtt_color_adjust(const struct drm_mm_node *node, 22 + unsigned long color, 23 + u64 *start, 24 + u64 *end) 25 + { 26 + if (i915_node_color_differs(node, color)) 27 + *start += I915_GTT_PAGE_SIZE; 28 + 29 + /* 30 + * Also leave a space between the unallocated reserved node after the 31 + * GTT and any objects within the GTT, i.e. we use the color adjustment 32 + * to insert a guard page to prevent prefetches crossing over the 33 + * GTT boundary. 34 + */ 35 + node = list_next_entry(node, node_list); 36 + if (node->color != color) 37 + *end -= I915_GTT_PAGE_SIZE; 38 + } 39 + 40 + static int ggtt_init_hw(struct i915_ggtt *ggtt) 41 + { 42 + struct drm_i915_private *i915 = ggtt->vm.i915; 43 + 44 + i915_address_space_init(&ggtt->vm, VM_CLASS_GGTT); 45 + 46 + ggtt->vm.is_ggtt = true; 47 + 48 + /* Only VLV supports read-only GGTT mappings */ 49 + ggtt->vm.has_read_only = IS_VALLEYVIEW(i915); 50 + 51 + if (!HAS_LLC(i915) && !HAS_PPGTT(i915)) 52 + ggtt->vm.mm.color_adjust = i915_ggtt_color_adjust; 53 + 54 + if (ggtt->mappable_end) { 55 + if (!io_mapping_init_wc(&ggtt->iomap, 56 + ggtt->gmadr.start, 57 + ggtt->mappable_end)) { 58 + ggtt->vm.cleanup(&ggtt->vm); 59 + return -EIO; 60 + } 61 + 62 + ggtt->mtrr = arch_phys_wc_add(ggtt->gmadr.start, 63 + ggtt->mappable_end); 64 + } 65 + 66 + i915_ggtt_init_fences(ggtt); 67 + 68 + return 0; 69 + } 70 + 71 + /** 72 + * i915_ggtt_init_hw - Initialize GGTT hardware 73 + * @i915: i915 device 74 + */ 75 + int i915_ggtt_init_hw(struct drm_i915_private *i915) 76 + { 77 + int ret; 78 + 79 + stash_init(&i915->mm.wc_stash); 80 + 81 + /* 82 + * Note that we use page colouring to enforce a guard page at the 83 + * end of the address space. This is required as the CS may prefetch 84 + * beyond the end of the batch buffer, across the page boundary, 85 + * and beyond the end of the GTT if we do not provide a guard. 86 + */ 87 + ret = ggtt_init_hw(&i915->ggtt); 88 + if (ret) 89 + return ret; 90 + 91 + return 0; 92 + } 93 + 94 + /* 95 + * Certain Gen5 chipsets require require idling the GPU before 96 + * unmapping anything from the GTT when VT-d is enabled. 97 + */ 98 + static bool needs_idle_maps(struct drm_i915_private *i915) 99 + { 100 + /* 101 + * Query intel_iommu to see if we need the workaround. Presumably that 102 + * was loaded first. 103 + */ 104 + return IS_GEN(i915, 5) && IS_MOBILE(i915) && intel_vtd_active(); 105 + } 106 + 107 + static void ggtt_suspend_mappings(struct i915_ggtt *ggtt) 108 + { 109 + struct drm_i915_private *i915 = ggtt->vm.i915; 110 + 111 + /* 112 + * Don't bother messing with faults pre GEN6 as we have little 113 + * documentation supporting that it's a good idea. 114 + */ 115 + if (INTEL_GEN(i915) < 6) 116 + return; 117 + 118 + intel_gt_check_and_clear_faults(ggtt->vm.gt); 119 + 120 + ggtt->vm.clear_range(&ggtt->vm, 0, ggtt->vm.total); 121 + 122 + ggtt->invalidate(ggtt); 123 + } 124 + 125 + void i915_gem_suspend_gtt_mappings(struct drm_i915_private *i915) 126 + { 127 + ggtt_suspend_mappings(&i915->ggtt); 128 + } 129 + 130 + void gen6_ggtt_invalidate(struct i915_ggtt *ggtt) 131 + { 132 + struct intel_uncore *uncore = ggtt->vm.gt->uncore; 133 + 134 + spin_lock_irq(&uncore->lock); 135 + intel_uncore_write_fw(uncore, GFX_FLSH_CNTL_GEN6, GFX_FLSH_CNTL_EN); 136 + intel_uncore_read_fw(uncore, GFX_FLSH_CNTL_GEN6); 137 + spin_unlock_irq(&uncore->lock); 138 + } 139 + 140 + static void gen8_ggtt_invalidate(struct i915_ggtt *ggtt) 141 + { 142 + struct intel_uncore *uncore = ggtt->vm.gt->uncore; 143 + 144 + /* 145 + * Note that as an uncached mmio write, this will flush the 146 + * WCB of the writes into the GGTT before it triggers the invalidate. 147 + */ 148 + intel_uncore_write_fw(uncore, GFX_FLSH_CNTL_GEN6, GFX_FLSH_CNTL_EN); 149 + } 150 + 151 + static void guc_ggtt_invalidate(struct i915_ggtt *ggtt) 152 + { 153 + struct intel_uncore *uncore = ggtt->vm.gt->uncore; 154 + struct drm_i915_private *i915 = ggtt->vm.i915; 155 + 156 + gen8_ggtt_invalidate(ggtt); 157 + 158 + if (INTEL_GEN(i915) >= 12) 159 + intel_uncore_write_fw(uncore, GEN12_GUC_TLB_INV_CR, 160 + GEN12_GUC_TLB_INV_CR_INVALIDATE); 161 + else 162 + intel_uncore_write_fw(uncore, GEN8_GTCR, GEN8_GTCR_INVALIDATE); 163 + } 164 + 165 + static void gmch_ggtt_invalidate(struct i915_ggtt *ggtt) 166 + { 167 + intel_gtt_chipset_flush(); 168 + } 169 + 170 + static void gen8_set_pte(void __iomem *addr, gen8_pte_t pte) 171 + { 172 + writeq(pte, addr); 173 + } 174 + 175 + static void gen8_ggtt_insert_page(struct i915_address_space *vm, 176 + dma_addr_t addr, 177 + u64 offset, 178 + enum i915_cache_level level, 179 + u32 unused) 180 + { 181 + struct i915_ggtt *ggtt = i915_vm_to_ggtt(vm); 182 + gen8_pte_t __iomem *pte = 183 + (gen8_pte_t __iomem *)ggtt->gsm + offset / I915_GTT_PAGE_SIZE; 184 + 185 + gen8_set_pte(pte, gen8_pte_encode(addr, level, 0)); 186 + 187 + ggtt->invalidate(ggtt); 188 + } 189 + 190 + static void gen8_ggtt_insert_entries(struct i915_address_space *vm, 191 + struct i915_vma *vma, 192 + enum i915_cache_level level, 193 + u32 flags) 194 + { 195 + struct i915_ggtt *ggtt = i915_vm_to_ggtt(vm); 196 + struct sgt_iter sgt_iter; 197 + gen8_pte_t __iomem *gtt_entries; 198 + const gen8_pte_t pte_encode = gen8_pte_encode(0, level, 0); 199 + dma_addr_t addr; 200 + 201 + /* 202 + * Note that we ignore PTE_READ_ONLY here. The caller must be careful 203 + * not to allow the user to override access to a read only page. 204 + */ 205 + 206 + gtt_entries = (gen8_pte_t __iomem *)ggtt->gsm; 207 + gtt_entries += vma->node.start / I915_GTT_PAGE_SIZE; 208 + for_each_sgt_daddr(addr, sgt_iter, vma->pages) 209 + gen8_set_pte(gtt_entries++, pte_encode | addr); 210 + 211 + /* 212 + * We want to flush the TLBs only after we're certain all the PTE 213 + * updates have finished. 214 + */ 215 + ggtt->invalidate(ggtt); 216 + } 217 + 218 + static void gen6_ggtt_insert_page(struct i915_address_space *vm, 219 + dma_addr_t addr, 220 + u64 offset, 221 + enum i915_cache_level level, 222 + u32 flags) 223 + { 224 + struct i915_ggtt *ggtt = i915_vm_to_ggtt(vm); 225 + gen6_pte_t __iomem *pte = 226 + (gen6_pte_t __iomem *)ggtt->gsm + offset / I915_GTT_PAGE_SIZE; 227 + 228 + iowrite32(vm->pte_encode(addr, level, flags), pte); 229 + 230 + ggtt->invalidate(ggtt); 231 + } 232 + 233 + /* 234 + * Binds an object into the global gtt with the specified cache level. 235 + * The object will be accessible to the GPU via commands whose operands 236 + * reference offsets within the global GTT as well as accessible by the GPU 237 + * through the GMADR mapped BAR (i915->mm.gtt->gtt). 238 + */ 239 + static void gen6_ggtt_insert_entries(struct i915_address_space *vm, 240 + struct i915_vma *vma, 241 + enum i915_cache_level level, 242 + u32 flags) 243 + { 244 + struct i915_ggtt *ggtt = i915_vm_to_ggtt(vm); 245 + gen6_pte_t __iomem *entries = (gen6_pte_t __iomem *)ggtt->gsm; 246 + unsigned int i = vma->node.start / I915_GTT_PAGE_SIZE; 247 + struct sgt_iter iter; 248 + dma_addr_t addr; 249 + 250 + for_each_sgt_daddr(addr, iter, vma->pages) 251 + iowrite32(vm->pte_encode(addr, level, flags), &entries[i++]); 252 + 253 + /* 254 + * We want to flush the TLBs only after we're certain all the PTE 255 + * updates have finished. 256 + */ 257 + ggtt->invalidate(ggtt); 258 + } 259 + 260 + static void nop_clear_range(struct i915_address_space *vm, 261 + u64 start, u64 length) 262 + { 263 + } 264 + 265 + static void gen8_ggtt_clear_range(struct i915_address_space *vm, 266 + u64 start, u64 length) 267 + { 268 + struct i915_ggtt *ggtt = i915_vm_to_ggtt(vm); 269 + unsigned int first_entry = start / I915_GTT_PAGE_SIZE; 270 + unsigned int num_entries = length / I915_GTT_PAGE_SIZE; 271 + const gen8_pte_t scratch_pte = vm->scratch[0].encode; 272 + gen8_pte_t __iomem *gtt_base = 273 + (gen8_pte_t __iomem *)ggtt->gsm + first_entry; 274 + const int max_entries = ggtt_total_entries(ggtt) - first_entry; 275 + int i; 276 + 277 + if (WARN(num_entries > max_entries, 278 + "First entry = %d; Num entries = %d (max=%d)\n", 279 + first_entry, num_entries, max_entries)) 280 + num_entries = max_entries; 281 + 282 + for (i = 0; i < num_entries; i++) 283 + gen8_set_pte(&gtt_base[i], scratch_pte); 284 + } 285 + 286 + static void bxt_vtd_ggtt_wa(struct i915_address_space *vm) 287 + { 288 + /* 289 + * Make sure the internal GAM fifo has been cleared of all GTT 290 + * writes before exiting stop_machine(). This guarantees that 291 + * any aperture accesses waiting to start in another process 292 + * cannot back up behind the GTT writes causing a hang. 293 + * The register can be any arbitrary GAM register. 294 + */ 295 + intel_uncore_posting_read_fw(vm->gt->uncore, GFX_FLSH_CNTL_GEN6); 296 + } 297 + 298 + struct insert_page { 299 + struct i915_address_space *vm; 300 + dma_addr_t addr; 301 + u64 offset; 302 + enum i915_cache_level level; 303 + }; 304 + 305 + static int bxt_vtd_ggtt_insert_page__cb(void *_arg) 306 + { 307 + struct insert_page *arg = _arg; 308 + 309 + gen8_ggtt_insert_page(arg->vm, arg->addr, arg->offset, arg->level, 0); 310 + bxt_vtd_ggtt_wa(arg->vm); 311 + 312 + return 0; 313 + } 314 + 315 + static void bxt_vtd_ggtt_insert_page__BKL(struct i915_address_space *vm, 316 + dma_addr_t addr, 317 + u64 offset, 318 + enum i915_cache_level level, 319 + u32 unused) 320 + { 321 + struct insert_page arg = { vm, addr, offset, level }; 322 + 323 + stop_machine(bxt_vtd_ggtt_insert_page__cb, &arg, NULL); 324 + } 325 + 326 + struct insert_entries { 327 + struct i915_address_space *vm; 328 + struct i915_vma *vma; 329 + enum i915_cache_level level; 330 + u32 flags; 331 + }; 332 + 333 + static int bxt_vtd_ggtt_insert_entries__cb(void *_arg) 334 + { 335 + struct insert_entries *arg = _arg; 336 + 337 + gen8_ggtt_insert_entries(arg->vm, arg->vma, arg->level, arg->flags); 338 + bxt_vtd_ggtt_wa(arg->vm); 339 + 340 + return 0; 341 + } 342 + 343 + static void bxt_vtd_ggtt_insert_entries__BKL(struct i915_address_space *vm, 344 + struct i915_vma *vma, 345 + enum i915_cache_level level, 346 + u32 flags) 347 + { 348 + struct insert_entries arg = { vm, vma, level, flags }; 349 + 350 + stop_machine(bxt_vtd_ggtt_insert_entries__cb, &arg, NULL); 351 + } 352 + 353 + struct clear_range { 354 + struct i915_address_space *vm; 355 + u64 start; 356 + u64 length; 357 + }; 358 + 359 + static int bxt_vtd_ggtt_clear_range__cb(void *_arg) 360 + { 361 + struct clear_range *arg = _arg; 362 + 363 + gen8_ggtt_clear_range(arg->vm, arg->start, arg->length); 364 + bxt_vtd_ggtt_wa(arg->vm); 365 + 366 + return 0; 367 + } 368 + 369 + static void bxt_vtd_ggtt_clear_range__BKL(struct i915_address_space *vm, 370 + u64 start, 371 + u64 length) 372 + { 373 + struct clear_range arg = { vm, start, length }; 374 + 375 + stop_machine(bxt_vtd_ggtt_clear_range__cb, &arg, NULL); 376 + } 377 + 378 + static void gen6_ggtt_clear_range(struct i915_address_space *vm, 379 + u64 start, u64 length) 380 + { 381 + struct i915_ggtt *ggtt = i915_vm_to_ggtt(vm); 382 + unsigned int first_entry = start / I915_GTT_PAGE_SIZE; 383 + unsigned int num_entries = length / I915_GTT_PAGE_SIZE; 384 + gen6_pte_t scratch_pte, __iomem *gtt_base = 385 + (gen6_pte_t __iomem *)ggtt->gsm + first_entry; 386 + const int max_entries = ggtt_total_entries(ggtt) - first_entry; 387 + int i; 388 + 389 + if (WARN(num_entries > max_entries, 390 + "First entry = %d; Num entries = %d (max=%d)\n", 391 + first_entry, num_entries, max_entries)) 392 + num_entries = max_entries; 393 + 394 + scratch_pte = vm->scratch[0].encode; 395 + for (i = 0; i < num_entries; i++) 396 + iowrite32(scratch_pte, &gtt_base[i]); 397 + } 398 + 399 + static void i915_ggtt_insert_page(struct i915_address_space *vm, 400 + dma_addr_t addr, 401 + u64 offset, 402 + enum i915_cache_level cache_level, 403 + u32 unused) 404 + { 405 + unsigned int flags = (cache_level == I915_CACHE_NONE) ? 406 + AGP_USER_MEMORY : AGP_USER_CACHED_MEMORY; 407 + 408 + intel_gtt_insert_page(addr, offset >> PAGE_SHIFT, flags); 409 + } 410 + 411 + static void i915_ggtt_insert_entries(struct i915_address_space *vm, 412 + struct i915_vma *vma, 413 + enum i915_cache_level cache_level, 414 + u32 unused) 415 + { 416 + unsigned int flags = (cache_level == I915_CACHE_NONE) ? 417 + AGP_USER_MEMORY : AGP_USER_CACHED_MEMORY; 418 + 419 + intel_gtt_insert_sg_entries(vma->pages, vma->node.start >> PAGE_SHIFT, 420 + flags); 421 + } 422 + 423 + static void i915_ggtt_clear_range(struct i915_address_space *vm, 424 + u64 start, u64 length) 425 + { 426 + intel_gtt_clear_range(start >> PAGE_SHIFT, length >> PAGE_SHIFT); 427 + } 428 + 429 + static int ggtt_bind_vma(struct i915_vma *vma, 430 + enum i915_cache_level cache_level, 431 + u32 flags) 432 + { 433 + struct drm_i915_gem_object *obj = vma->obj; 434 + u32 pte_flags; 435 + 436 + /* Applicable to VLV (gen8+ do not support RO in the GGTT) */ 437 + pte_flags = 0; 438 + if (i915_gem_object_is_readonly(obj)) 439 + pte_flags |= PTE_READ_ONLY; 440 + 441 + vma->vm->insert_entries(vma->vm, vma, cache_level, pte_flags); 442 + 443 + vma->page_sizes.gtt = I915_GTT_PAGE_SIZE; 444 + 445 + /* 446 + * Without aliasing PPGTT there's no difference between 447 + * GLOBAL/LOCAL_BIND, it's all the same ptes. Hence unconditionally 448 + * upgrade to both bound if we bind either to avoid double-binding. 449 + */ 450 + atomic_or(I915_VMA_GLOBAL_BIND | I915_VMA_LOCAL_BIND, &vma->flags); 451 + 452 + return 0; 453 + } 454 + 455 + static void ggtt_unbind_vma(struct i915_vma *vma) 456 + { 457 + vma->vm->clear_range(vma->vm, vma->node.start, vma->size); 458 + } 459 + 460 + static int ggtt_reserve_guc_top(struct i915_ggtt *ggtt) 461 + { 462 + u64 size; 463 + int ret; 464 + 465 + if (!USES_GUC(ggtt->vm.i915)) 466 + return 0; 467 + 468 + GEM_BUG_ON(ggtt->vm.total <= GUC_GGTT_TOP); 469 + size = ggtt->vm.total - GUC_GGTT_TOP; 470 + 471 + ret = i915_gem_gtt_reserve(&ggtt->vm, &ggtt->uc_fw, size, 472 + GUC_GGTT_TOP, I915_COLOR_UNEVICTABLE, 473 + PIN_NOEVICT); 474 + if (ret) 475 + DRM_DEBUG_DRIVER("Failed to reserve top of GGTT for GuC\n"); 476 + 477 + return ret; 478 + } 479 + 480 + static void ggtt_release_guc_top(struct i915_ggtt *ggtt) 481 + { 482 + if (drm_mm_node_allocated(&ggtt->uc_fw)) 483 + drm_mm_remove_node(&ggtt->uc_fw); 484 + } 485 + 486 + static void cleanup_init_ggtt(struct i915_ggtt *ggtt) 487 + { 488 + ggtt_release_guc_top(ggtt); 489 + if (drm_mm_node_allocated(&ggtt->error_capture)) 490 + drm_mm_remove_node(&ggtt->error_capture); 491 + mutex_destroy(&ggtt->error_mutex); 492 + } 493 + 494 + static int init_ggtt(struct i915_ggtt *ggtt) 495 + { 496 + /* 497 + * Let GEM Manage all of the aperture. 498 + * 499 + * However, leave one page at the end still bound to the scratch page. 500 + * There are a number of places where the hardware apparently prefetches 501 + * past the end of the object, and we've seen multiple hangs with the 502 + * GPU head pointer stuck in a batchbuffer bound at the last page of the 503 + * aperture. One page should be enough to keep any prefetching inside 504 + * of the aperture. 505 + */ 506 + unsigned long hole_start, hole_end; 507 + struct drm_mm_node *entry; 508 + int ret; 509 + 510 + /* 511 + * GuC requires all resources that we're sharing with it to be placed in 512 + * non-WOPCM memory. If GuC is not present or not in use we still need a 513 + * small bias as ring wraparound at offset 0 sometimes hangs. No idea 514 + * why. 515 + */ 516 + ggtt->pin_bias = max_t(u32, I915_GTT_PAGE_SIZE, 517 + intel_wopcm_guc_size(&ggtt->vm.i915->wopcm)); 518 + 519 + ret = intel_vgt_balloon(ggtt); 520 + if (ret) 521 + return ret; 522 + 523 + mutex_init(&ggtt->error_mutex); 524 + if (ggtt->mappable_end) { 525 + /* Reserve a mappable slot for our lockless error capture */ 526 + ret = drm_mm_insert_node_in_range(&ggtt->vm.mm, 527 + &ggtt->error_capture, 528 + PAGE_SIZE, 0, 529 + I915_COLOR_UNEVICTABLE, 530 + 0, ggtt->mappable_end, 531 + DRM_MM_INSERT_LOW); 532 + if (ret) 533 + return ret; 534 + } 535 + 536 + /* 537 + * The upper portion of the GuC address space has a sizeable hole 538 + * (several MB) that is inaccessible by GuC. Reserve this range within 539 + * GGTT as it can comfortably hold GuC/HuC firmware images. 540 + */ 541 + ret = ggtt_reserve_guc_top(ggtt); 542 + if (ret) 543 + goto err; 544 + 545 + /* Clear any non-preallocated blocks */ 546 + drm_mm_for_each_hole(entry, &ggtt->vm.mm, hole_start, hole_end) { 547 + DRM_DEBUG_KMS("clearing unused GTT space: [%lx, %lx]\n", 548 + hole_start, hole_end); 549 + ggtt->vm.clear_range(&ggtt->vm, hole_start, 550 + hole_end - hole_start); 551 + } 552 + 553 + /* And finally clear the reserved guard page */ 554 + ggtt->vm.clear_range(&ggtt->vm, ggtt->vm.total - PAGE_SIZE, PAGE_SIZE); 555 + 556 + return 0; 557 + 558 + err: 559 + cleanup_init_ggtt(ggtt); 560 + return ret; 561 + } 562 + 563 + static int aliasing_gtt_bind_vma(struct i915_vma *vma, 564 + enum i915_cache_level cache_level, 565 + u32 flags) 566 + { 567 + u32 pte_flags; 568 + int ret; 569 + 570 + /* Currently applicable only to VLV */ 571 + pte_flags = 0; 572 + if (i915_gem_object_is_readonly(vma->obj)) 573 + pte_flags |= PTE_READ_ONLY; 574 + 575 + if (flags & I915_VMA_LOCAL_BIND) { 576 + struct i915_ppgtt *alias = i915_vm_to_ggtt(vma->vm)->alias; 577 + 578 + if (flags & I915_VMA_ALLOC) { 579 + ret = alias->vm.allocate_va_range(&alias->vm, 580 + vma->node.start, 581 + vma->size); 582 + if (ret) 583 + return ret; 584 + 585 + set_bit(I915_VMA_ALLOC_BIT, __i915_vma_flags(vma)); 586 + } 587 + 588 + GEM_BUG_ON(!test_bit(I915_VMA_ALLOC_BIT, 589 + __i915_vma_flags(vma))); 590 + alias->vm.insert_entries(&alias->vm, vma, 591 + cache_level, pte_flags); 592 + } 593 + 594 + if (flags & I915_VMA_GLOBAL_BIND) 595 + vma->vm->insert_entries(vma->vm, vma, cache_level, pte_flags); 596 + 597 + return 0; 598 + } 599 + 600 + static void aliasing_gtt_unbind_vma(struct i915_vma *vma) 601 + { 602 + if (i915_vma_is_bound(vma, I915_VMA_GLOBAL_BIND)) { 603 + struct i915_address_space *vm = vma->vm; 604 + 605 + vm->clear_range(vm, vma->node.start, vma->size); 606 + } 607 + 608 + if (test_and_clear_bit(I915_VMA_ALLOC_BIT, __i915_vma_flags(vma))) { 609 + struct i915_address_space *vm = 610 + &i915_vm_to_ggtt(vma->vm)->alias->vm; 611 + 612 + vm->clear_range(vm, vma->node.start, vma->size); 613 + } 614 + } 615 + 616 + static int init_aliasing_ppgtt(struct i915_ggtt *ggtt) 617 + { 618 + struct i915_ppgtt *ppgtt; 619 + int err; 620 + 621 + ppgtt = i915_ppgtt_create(ggtt->vm.gt); 622 + if (IS_ERR(ppgtt)) 623 + return PTR_ERR(ppgtt); 624 + 625 + if (GEM_WARN_ON(ppgtt->vm.total < ggtt->vm.total)) { 626 + err = -ENODEV; 627 + goto err_ppgtt; 628 + } 629 + 630 + /* 631 + * Note we only pre-allocate as far as the end of the global 632 + * GTT. On 48b / 4-level page-tables, the difference is very, 633 + * very significant! We have to preallocate as GVT/vgpu does 634 + * not like the page directory disappearing. 635 + */ 636 + err = ppgtt->vm.allocate_va_range(&ppgtt->vm, 0, ggtt->vm.total); 637 + if (err) 638 + goto err_ppgtt; 639 + 640 + ggtt->alias = ppgtt; 641 + ggtt->vm.bind_async_flags |= ppgtt->vm.bind_async_flags; 642 + 643 + GEM_BUG_ON(ggtt->vm.vma_ops.bind_vma != ggtt_bind_vma); 644 + ggtt->vm.vma_ops.bind_vma = aliasing_gtt_bind_vma; 645 + 646 + GEM_BUG_ON(ggtt->vm.vma_ops.unbind_vma != ggtt_unbind_vma); 647 + ggtt->vm.vma_ops.unbind_vma = aliasing_gtt_unbind_vma; 648 + 649 + return 0; 650 + 651 + err_ppgtt: 652 + i915_vm_put(&ppgtt->vm); 653 + return err; 654 + } 655 + 656 + static void fini_aliasing_ppgtt(struct i915_ggtt *ggtt) 657 + { 658 + struct i915_ppgtt *ppgtt; 659 + 660 + ppgtt = fetch_and_zero(&ggtt->alias); 661 + if (!ppgtt) 662 + return; 663 + 664 + i915_vm_put(&ppgtt->vm); 665 + 666 + ggtt->vm.vma_ops.bind_vma = ggtt_bind_vma; 667 + ggtt->vm.vma_ops.unbind_vma = ggtt_unbind_vma; 668 + } 669 + 670 + int i915_init_ggtt(struct drm_i915_private *i915) 671 + { 672 + int ret; 673 + 674 + ret = init_ggtt(&i915->ggtt); 675 + if (ret) 676 + return ret; 677 + 678 + if (INTEL_PPGTT(i915) == INTEL_PPGTT_ALIASING) { 679 + ret = init_aliasing_ppgtt(&i915->ggtt); 680 + if (ret) 681 + cleanup_init_ggtt(&i915->ggtt); 682 + } 683 + 684 + return 0; 685 + } 686 + 687 + static void ggtt_cleanup_hw(struct i915_ggtt *ggtt) 688 + { 689 + struct i915_vma *vma, *vn; 690 + 691 + atomic_set(&ggtt->vm.open, 0); 692 + 693 + rcu_barrier(); /* flush the RCU'ed__i915_vm_release */ 694 + flush_workqueue(ggtt->vm.i915->wq); 695 + 696 + mutex_lock(&ggtt->vm.mutex); 697 + 698 + list_for_each_entry_safe(vma, vn, &ggtt->vm.bound_list, vm_link) 699 + WARN_ON(__i915_vma_unbind(vma)); 700 + 701 + if (drm_mm_node_allocated(&ggtt->error_capture)) 702 + drm_mm_remove_node(&ggtt->error_capture); 703 + mutex_destroy(&ggtt->error_mutex); 704 + 705 + ggtt_release_guc_top(ggtt); 706 + intel_vgt_deballoon(ggtt); 707 + 708 + ggtt->vm.cleanup(&ggtt->vm); 709 + 710 + mutex_unlock(&ggtt->vm.mutex); 711 + i915_address_space_fini(&ggtt->vm); 712 + 713 + arch_phys_wc_del(ggtt->mtrr); 714 + 715 + if (ggtt->iomap.size) 716 + io_mapping_fini(&ggtt->iomap); 717 + } 718 + 719 + /** 720 + * i915_ggtt_driver_release - Clean up GGTT hardware initialization 721 + * @i915: i915 device 722 + */ 723 + void i915_ggtt_driver_release(struct drm_i915_private *i915) 724 + { 725 + struct pagevec *pvec; 726 + 727 + fini_aliasing_ppgtt(&i915->ggtt); 728 + 729 + ggtt_cleanup_hw(&i915->ggtt); 730 + 731 + pvec = &i915->mm.wc_stash.pvec; 732 + if (pvec->nr) { 733 + set_pages_array_wb(pvec->pages, pvec->nr); 734 + __pagevec_release(pvec); 735 + } 736 + } 737 + 738 + static unsigned int gen6_get_total_gtt_size(u16 snb_gmch_ctl) 739 + { 740 + snb_gmch_ctl >>= SNB_GMCH_GGMS_SHIFT; 741 + snb_gmch_ctl &= SNB_GMCH_GGMS_MASK; 742 + return snb_gmch_ctl << 20; 743 + } 744 + 745 + static unsigned int gen8_get_total_gtt_size(u16 bdw_gmch_ctl) 746 + { 747 + bdw_gmch_ctl >>= BDW_GMCH_GGMS_SHIFT; 748 + bdw_gmch_ctl &= BDW_GMCH_GGMS_MASK; 749 + if (bdw_gmch_ctl) 750 + bdw_gmch_ctl = 1 << bdw_gmch_ctl; 751 + 752 + #ifdef CONFIG_X86_32 753 + /* Limit 32b platforms to a 2GB GGTT: 4 << 20 / pte size * I915_GTT_PAGE_SIZE */ 754 + if (bdw_gmch_ctl > 4) 755 + bdw_gmch_ctl = 4; 756 + #endif 757 + 758 + return bdw_gmch_ctl << 20; 759 + } 760 + 761 + static unsigned int chv_get_total_gtt_size(u16 gmch_ctrl) 762 + { 763 + gmch_ctrl >>= SNB_GMCH_GGMS_SHIFT; 764 + gmch_ctrl &= SNB_GMCH_GGMS_MASK; 765 + 766 + if (gmch_ctrl) 767 + return 1 << (20 + gmch_ctrl); 768 + 769 + return 0; 770 + } 771 + 772 + static int ggtt_probe_common(struct i915_ggtt *ggtt, u64 size) 773 + { 774 + struct drm_i915_private *i915 = ggtt->vm.i915; 775 + struct pci_dev *pdev = i915->drm.pdev; 776 + phys_addr_t phys_addr; 777 + int ret; 778 + 779 + /* For Modern GENs the PTEs and register space are split in the BAR */ 780 + phys_addr = pci_resource_start(pdev, 0) + pci_resource_len(pdev, 0) / 2; 781 + 782 + /* 783 + * On BXT+/CNL+ writes larger than 64 bit to the GTT pagetable range 784 + * will be dropped. For WC mappings in general we have 64 byte burst 785 + * writes when the WC buffer is flushed, so we can't use it, but have to 786 + * resort to an uncached mapping. The WC issue is easily caught by the 787 + * readback check when writing GTT PTE entries. 788 + */ 789 + if (IS_GEN9_LP(i915) || INTEL_GEN(i915) >= 10) 790 + ggtt->gsm = ioremap_nocache(phys_addr, size); 791 + else 792 + ggtt->gsm = ioremap_wc(phys_addr, size); 793 + if (!ggtt->gsm) { 794 + DRM_ERROR("Failed to map the ggtt page table\n"); 795 + return -ENOMEM; 796 + } 797 + 798 + ret = setup_scratch_page(&ggtt->vm, GFP_DMA32); 799 + if (ret) { 800 + DRM_ERROR("Scratch setup failed\n"); 801 + /* iounmap will also get called at remove, but meh */ 802 + iounmap(ggtt->gsm); 803 + return ret; 804 + } 805 + 806 + ggtt->vm.scratch[0].encode = 807 + ggtt->vm.pte_encode(px_dma(&ggtt->vm.scratch[0]), 808 + I915_CACHE_NONE, 0); 809 + 810 + return 0; 811 + } 812 + 813 + int ggtt_set_pages(struct i915_vma *vma) 814 + { 815 + int ret; 816 + 817 + GEM_BUG_ON(vma->pages); 818 + 819 + ret = i915_get_ggtt_vma_pages(vma); 820 + if (ret) 821 + return ret; 822 + 823 + vma->page_sizes = vma->obj->mm.page_sizes; 824 + 825 + return 0; 826 + } 827 + 828 + static void gen6_gmch_remove(struct i915_address_space *vm) 829 + { 830 + struct i915_ggtt *ggtt = i915_vm_to_ggtt(vm); 831 + 832 + iounmap(ggtt->gsm); 833 + cleanup_scratch_page(vm); 834 + } 835 + 836 + static struct resource pci_resource(struct pci_dev *pdev, int bar) 837 + { 838 + return (struct resource)DEFINE_RES_MEM(pci_resource_start(pdev, bar), 839 + pci_resource_len(pdev, bar)); 840 + } 841 + 842 + static int gen8_gmch_probe(struct i915_ggtt *ggtt) 843 + { 844 + struct drm_i915_private *i915 = ggtt->vm.i915; 845 + struct pci_dev *pdev = i915->drm.pdev; 846 + unsigned int size; 847 + u16 snb_gmch_ctl; 848 + int err; 849 + 850 + /* TODO: We're not aware of mappable constraints on gen8 yet */ 851 + if (!IS_DGFX(i915)) { 852 + ggtt->gmadr = pci_resource(pdev, 2); 853 + ggtt->mappable_end = resource_size(&ggtt->gmadr); 854 + } 855 + 856 + err = pci_set_dma_mask(pdev, DMA_BIT_MASK(39)); 857 + if (!err) 858 + err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(39)); 859 + if (err) 860 + DRM_ERROR("Can't set DMA mask/consistent mask (%d)\n", err); 861 + 862 + pci_read_config_word(pdev, SNB_GMCH_CTRL, &snb_gmch_ctl); 863 + if (IS_CHERRYVIEW(i915)) 864 + size = chv_get_total_gtt_size(snb_gmch_ctl); 865 + else 866 + size = gen8_get_total_gtt_size(snb_gmch_ctl); 867 + 868 + ggtt->vm.total = (size / sizeof(gen8_pte_t)) * I915_GTT_PAGE_SIZE; 869 + ggtt->vm.cleanup = gen6_gmch_remove; 870 + ggtt->vm.insert_page = gen8_ggtt_insert_page; 871 + ggtt->vm.clear_range = nop_clear_range; 872 + if (intel_scanout_needs_vtd_wa(i915)) 873 + ggtt->vm.clear_range = gen8_ggtt_clear_range; 874 + 875 + ggtt->vm.insert_entries = gen8_ggtt_insert_entries; 876 + 877 + /* Serialize GTT updates with aperture access on BXT if VT-d is on. */ 878 + if (intel_ggtt_update_needs_vtd_wa(i915) || 879 + IS_CHERRYVIEW(i915) /* fails with concurrent use/update */) { 880 + ggtt->vm.insert_entries = bxt_vtd_ggtt_insert_entries__BKL; 881 + ggtt->vm.insert_page = bxt_vtd_ggtt_insert_page__BKL; 882 + if (ggtt->vm.clear_range != nop_clear_range) 883 + ggtt->vm.clear_range = bxt_vtd_ggtt_clear_range__BKL; 884 + } 885 + 886 + ggtt->invalidate = gen8_ggtt_invalidate; 887 + 888 + ggtt->vm.vma_ops.bind_vma = ggtt_bind_vma; 889 + ggtt->vm.vma_ops.unbind_vma = ggtt_unbind_vma; 890 + ggtt->vm.vma_ops.set_pages = ggtt_set_pages; 891 + ggtt->vm.vma_ops.clear_pages = clear_pages; 892 + 893 + ggtt->vm.pte_encode = gen8_pte_encode; 894 + 895 + setup_private_pat(ggtt->vm.gt->uncore); 896 + 897 + return ggtt_probe_common(ggtt, size); 898 + } 899 + 900 + static u64 snb_pte_encode(dma_addr_t addr, 901 + enum i915_cache_level level, 902 + u32 flags) 903 + { 904 + gen6_pte_t pte = GEN6_PTE_ADDR_ENCODE(addr) | GEN6_PTE_VALID; 905 + 906 + switch (level) { 907 + case I915_CACHE_L3_LLC: 908 + case I915_CACHE_LLC: 909 + pte |= GEN6_PTE_CACHE_LLC; 910 + break; 911 + case I915_CACHE_NONE: 912 + pte |= GEN6_PTE_UNCACHED; 913 + break; 914 + default: 915 + MISSING_CASE(level); 916 + } 917 + 918 + return pte; 919 + } 920 + 921 + static u64 ivb_pte_encode(dma_addr_t addr, 922 + enum i915_cache_level level, 923 + u32 flags) 924 + { 925 + gen6_pte_t pte = GEN6_PTE_ADDR_ENCODE(addr) | GEN6_PTE_VALID; 926 + 927 + switch (level) { 928 + case I915_CACHE_L3_LLC: 929 + pte |= GEN7_PTE_CACHE_L3_LLC; 930 + break; 931 + case I915_CACHE_LLC: 932 + pte |= GEN6_PTE_CACHE_LLC; 933 + break; 934 + case I915_CACHE_NONE: 935 + pte |= GEN6_PTE_UNCACHED; 936 + break; 937 + default: 938 + MISSING_CASE(level); 939 + } 940 + 941 + return pte; 942 + } 943 + 944 + static u64 byt_pte_encode(dma_addr_t addr, 945 + enum i915_cache_level level, 946 + u32 flags) 947 + { 948 + gen6_pte_t pte = GEN6_PTE_ADDR_ENCODE(addr) | GEN6_PTE_VALID; 949 + 950 + if (!(flags & PTE_READ_ONLY)) 951 + pte |= BYT_PTE_WRITEABLE; 952 + 953 + if (level != I915_CACHE_NONE) 954 + pte |= BYT_PTE_SNOOPED_BY_CPU_CACHES; 955 + 956 + return pte; 957 + } 958 + 959 + static u64 hsw_pte_encode(dma_addr_t addr, 960 + enum i915_cache_level level, 961 + u32 flags) 962 + { 963 + gen6_pte_t pte = HSW_PTE_ADDR_ENCODE(addr) | GEN6_PTE_VALID; 964 + 965 + if (level != I915_CACHE_NONE) 966 + pte |= HSW_WB_LLC_AGE3; 967 + 968 + return pte; 969 + } 970 + 971 + static u64 iris_pte_encode(dma_addr_t addr, 972 + enum i915_cache_level level, 973 + u32 flags) 974 + { 975 + gen6_pte_t pte = HSW_PTE_ADDR_ENCODE(addr) | GEN6_PTE_VALID; 976 + 977 + switch (level) { 978 + case I915_CACHE_NONE: 979 + break; 980 + case I915_CACHE_WT: 981 + pte |= HSW_WT_ELLC_LLC_AGE3; 982 + break; 983 + default: 984 + pte |= HSW_WB_ELLC_LLC_AGE3; 985 + break; 986 + } 987 + 988 + return pte; 989 + } 990 + 991 + static int gen6_gmch_probe(struct i915_ggtt *ggtt) 992 + { 993 + struct drm_i915_private *i915 = ggtt->vm.i915; 994 + struct pci_dev *pdev = i915->drm.pdev; 995 + unsigned int size; 996 + u16 snb_gmch_ctl; 997 + int err; 998 + 999 + ggtt->gmadr = pci_resource(pdev, 2); 1000 + ggtt->mappable_end = resource_size(&ggtt->gmadr); 1001 + 1002 + /* 1003 + * 64/512MB is the current min/max we actually know of, but this is 1004 + * just a coarse sanity check. 1005 + */ 1006 + if (ggtt->mappable_end < (64<<20) || ggtt->mappable_end > (512<<20)) { 1007 + DRM_ERROR("Unknown GMADR size (%pa)\n", &ggtt->mappable_end); 1008 + return -ENXIO; 1009 + } 1010 + 1011 + err = pci_set_dma_mask(pdev, DMA_BIT_MASK(40)); 1012 + if (!err) 1013 + err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(40)); 1014 + if (err) 1015 + DRM_ERROR("Can't set DMA mask/consistent mask (%d)\n", err); 1016 + pci_read_config_word(pdev, SNB_GMCH_CTRL, &snb_gmch_ctl); 1017 + 1018 + size = gen6_get_total_gtt_size(snb_gmch_ctl); 1019 + ggtt->vm.total = (size / sizeof(gen6_pte_t)) * I915_GTT_PAGE_SIZE; 1020 + 1021 + ggtt->vm.clear_range = nop_clear_range; 1022 + if (!HAS_FULL_PPGTT(i915) || intel_scanout_needs_vtd_wa(i915)) 1023 + ggtt->vm.clear_range = gen6_ggtt_clear_range; 1024 + ggtt->vm.insert_page = gen6_ggtt_insert_page; 1025 + ggtt->vm.insert_entries = gen6_ggtt_insert_entries; 1026 + ggtt->vm.cleanup = gen6_gmch_remove; 1027 + 1028 + ggtt->invalidate = gen6_ggtt_invalidate; 1029 + 1030 + if (HAS_EDRAM(i915)) 1031 + ggtt->vm.pte_encode = iris_pte_encode; 1032 + else if (IS_HASWELL(i915)) 1033 + ggtt->vm.pte_encode = hsw_pte_encode; 1034 + else if (IS_VALLEYVIEW(i915)) 1035 + ggtt->vm.pte_encode = byt_pte_encode; 1036 + else if (INTEL_GEN(i915) >= 7) 1037 + ggtt->vm.pte_encode = ivb_pte_encode; 1038 + else 1039 + ggtt->vm.pte_encode = snb_pte_encode; 1040 + 1041 + ggtt->vm.vma_ops.bind_vma = ggtt_bind_vma; 1042 + ggtt->vm.vma_ops.unbind_vma = ggtt_unbind_vma; 1043 + ggtt->vm.vma_ops.set_pages = ggtt_set_pages; 1044 + ggtt->vm.vma_ops.clear_pages = clear_pages; 1045 + 1046 + return ggtt_probe_common(ggtt, size); 1047 + } 1048 + 1049 + static void i915_gmch_remove(struct i915_address_space *vm) 1050 + { 1051 + intel_gmch_remove(); 1052 + } 1053 + 1054 + static int i915_gmch_probe(struct i915_ggtt *ggtt) 1055 + { 1056 + struct drm_i915_private *i915 = ggtt->vm.i915; 1057 + phys_addr_t gmadr_base; 1058 + int ret; 1059 + 1060 + ret = intel_gmch_probe(i915->bridge_dev, i915->drm.pdev, NULL); 1061 + if (!ret) { 1062 + DRM_ERROR("failed to set up gmch\n"); 1063 + return -EIO; 1064 + } 1065 + 1066 + intel_gtt_get(&ggtt->vm.total, &gmadr_base, &ggtt->mappable_end); 1067 + 1068 + ggtt->gmadr = 1069 + (struct resource)DEFINE_RES_MEM(gmadr_base, ggtt->mappable_end); 1070 + 1071 + ggtt->do_idle_maps = needs_idle_maps(i915); 1072 + ggtt->vm.insert_page = i915_ggtt_insert_page; 1073 + ggtt->vm.insert_entries = i915_ggtt_insert_entries; 1074 + ggtt->vm.clear_range = i915_ggtt_clear_range; 1075 + ggtt->vm.cleanup = i915_gmch_remove; 1076 + 1077 + ggtt->invalidate = gmch_ggtt_invalidate; 1078 + 1079 + ggtt->vm.vma_ops.bind_vma = ggtt_bind_vma; 1080 + ggtt->vm.vma_ops.unbind_vma = ggtt_unbind_vma; 1081 + ggtt->vm.vma_ops.set_pages = ggtt_set_pages; 1082 + ggtt->vm.vma_ops.clear_pages = clear_pages; 1083 + 1084 + if (unlikely(ggtt->do_idle_maps)) 1085 + dev_notice(i915->drm.dev, 1086 + "Applying Ironlake quirks for intel_iommu\n"); 1087 + 1088 + return 0; 1089 + } 1090 + 1091 + static int ggtt_probe_hw(struct i915_ggtt *ggtt, struct intel_gt *gt) 1092 + { 1093 + struct drm_i915_private *i915 = gt->i915; 1094 + int ret; 1095 + 1096 + ggtt->vm.gt = gt; 1097 + ggtt->vm.i915 = i915; 1098 + ggtt->vm.dma = &i915->drm.pdev->dev; 1099 + 1100 + if (INTEL_GEN(i915) <= 5) 1101 + ret = i915_gmch_probe(ggtt); 1102 + else if (INTEL_GEN(i915) < 8) 1103 + ret = gen6_gmch_probe(ggtt); 1104 + else 1105 + ret = gen8_gmch_probe(ggtt); 1106 + if (ret) 1107 + return ret; 1108 + 1109 + if ((ggtt->vm.total - 1) >> 32) { 1110 + DRM_ERROR("We never expected a Global GTT with more than 32bits" 1111 + " of address space! Found %lldM!\n", 1112 + ggtt->vm.total >> 20); 1113 + ggtt->vm.total = 1ULL << 32; 1114 + ggtt->mappable_end = 1115 + min_t(u64, ggtt->mappable_end, ggtt->vm.total); 1116 + } 1117 + 1118 + if (ggtt->mappable_end > ggtt->vm.total) { 1119 + DRM_ERROR("mappable aperture extends past end of GGTT," 1120 + " aperture=%pa, total=%llx\n", 1121 + &ggtt->mappable_end, ggtt->vm.total); 1122 + ggtt->mappable_end = ggtt->vm.total; 1123 + } 1124 + 1125 + /* GMADR is the PCI mmio aperture into the global GTT. */ 1126 + DRM_DEBUG_DRIVER("GGTT size = %lluM\n", ggtt->vm.total >> 20); 1127 + DRM_DEBUG_DRIVER("GMADR size = %lluM\n", (u64)ggtt->mappable_end >> 20); 1128 + DRM_DEBUG_DRIVER("DSM size = %lluM\n", 1129 + (u64)resource_size(&intel_graphics_stolen_res) >> 20); 1130 + 1131 + return 0; 1132 + } 1133 + 1134 + /** 1135 + * i915_ggtt_probe_hw - Probe GGTT hardware location 1136 + * @i915: i915 device 1137 + */ 1138 + int i915_ggtt_probe_hw(struct drm_i915_private *i915) 1139 + { 1140 + int ret; 1141 + 1142 + ret = ggtt_probe_hw(&i915->ggtt, &i915->gt); 1143 + if (ret) 1144 + return ret; 1145 + 1146 + if (intel_vtd_active()) 1147 + dev_info(i915->drm.dev, "VT-d active for gfx access\n"); 1148 + 1149 + return 0; 1150 + } 1151 + 1152 + int i915_ggtt_enable_hw(struct drm_i915_private *i915) 1153 + { 1154 + if (INTEL_GEN(i915) < 6 && !intel_enable_gtt()) 1155 + return -EIO; 1156 + 1157 + return 0; 1158 + } 1159 + 1160 + void i915_ggtt_enable_guc(struct i915_ggtt *ggtt) 1161 + { 1162 + GEM_BUG_ON(ggtt->invalidate != gen8_ggtt_invalidate); 1163 + 1164 + ggtt->invalidate = guc_ggtt_invalidate; 1165 + 1166 + ggtt->invalidate(ggtt); 1167 + } 1168 + 1169 + void i915_ggtt_disable_guc(struct i915_ggtt *ggtt) 1170 + { 1171 + /* XXX Temporary pardon for error unload */ 1172 + if (ggtt->invalidate == gen8_ggtt_invalidate) 1173 + return; 1174 + 1175 + /* We should only be called after i915_ggtt_enable_guc() */ 1176 + GEM_BUG_ON(ggtt->invalidate != guc_ggtt_invalidate); 1177 + 1178 + ggtt->invalidate = gen8_ggtt_invalidate; 1179 + 1180 + ggtt->invalidate(ggtt); 1181 + } 1182 + 1183 + static void ggtt_restore_mappings(struct i915_ggtt *ggtt) 1184 + { 1185 + struct i915_vma *vma; 1186 + bool flush = false; 1187 + int open; 1188 + 1189 + intel_gt_check_and_clear_faults(ggtt->vm.gt); 1190 + 1191 + mutex_lock(&ggtt->vm.mutex); 1192 + 1193 + /* First fill our portion of the GTT with scratch pages */ 1194 + ggtt->vm.clear_range(&ggtt->vm, 0, ggtt->vm.total); 1195 + 1196 + /* Skip rewriting PTE on VMA unbind. */ 1197 + open = atomic_xchg(&ggtt->vm.open, 0); 1198 + 1199 + /* clflush objects bound into the GGTT and rebind them. */ 1200 + list_for_each_entry(vma, &ggtt->vm.bound_list, vm_link) { 1201 + struct drm_i915_gem_object *obj = vma->obj; 1202 + 1203 + if (!i915_vma_is_bound(vma, I915_VMA_GLOBAL_BIND)) 1204 + continue; 1205 + 1206 + clear_bit(I915_VMA_GLOBAL_BIND_BIT, __i915_vma_flags(vma)); 1207 + WARN_ON(i915_vma_bind(vma, 1208 + obj ? obj->cache_level : 0, 1209 + PIN_GLOBAL, NULL)); 1210 + if (obj) { /* only used during resume => exclusive access */ 1211 + flush |= fetch_and_zero(&obj->write_domain); 1212 + obj->read_domains |= I915_GEM_DOMAIN_GTT; 1213 + } 1214 + } 1215 + 1216 + atomic_set(&ggtt->vm.open, open); 1217 + ggtt->invalidate(ggtt); 1218 + 1219 + mutex_unlock(&ggtt->vm.mutex); 1220 + 1221 + if (flush) 1222 + wbinvd_on_all_cpus(); 1223 + } 1224 + 1225 + void i915_gem_restore_gtt_mappings(struct drm_i915_private *i915) 1226 + { 1227 + struct i915_ggtt *ggtt = &i915->ggtt; 1228 + 1229 + ggtt_restore_mappings(ggtt); 1230 + 1231 + if (INTEL_GEN(i915) >= 8) 1232 + setup_private_pat(ggtt->vm.gt->uncore); 1233 + } 1234 + 1235 + static struct scatterlist * 1236 + rotate_pages(struct drm_i915_gem_object *obj, unsigned int offset, 1237 + unsigned int width, unsigned int height, 1238 + unsigned int stride, 1239 + struct sg_table *st, struct scatterlist *sg) 1240 + { 1241 + unsigned int column, row; 1242 + unsigned int src_idx; 1243 + 1244 + for (column = 0; column < width; column++) { 1245 + src_idx = stride * (height - 1) + column + offset; 1246 + for (row = 0; row < height; row++) { 1247 + st->nents++; 1248 + /* 1249 + * We don't need the pages, but need to initialize 1250 + * the entries so the sg list can be happily traversed. 1251 + * The only thing we need are DMA addresses. 1252 + */ 1253 + sg_set_page(sg, NULL, I915_GTT_PAGE_SIZE, 0); 1254 + sg_dma_address(sg) = 1255 + i915_gem_object_get_dma_address(obj, src_idx); 1256 + sg_dma_len(sg) = I915_GTT_PAGE_SIZE; 1257 + sg = sg_next(sg); 1258 + src_idx -= stride; 1259 + } 1260 + } 1261 + 1262 + return sg; 1263 + } 1264 + 1265 + static noinline struct sg_table * 1266 + intel_rotate_pages(struct intel_rotation_info *rot_info, 1267 + struct drm_i915_gem_object *obj) 1268 + { 1269 + unsigned int size = intel_rotation_info_size(rot_info); 1270 + struct sg_table *st; 1271 + struct scatterlist *sg; 1272 + int ret = -ENOMEM; 1273 + int i; 1274 + 1275 + /* Allocate target SG list. */ 1276 + st = kmalloc(sizeof(*st), GFP_KERNEL); 1277 + if (!st) 1278 + goto err_st_alloc; 1279 + 1280 + ret = sg_alloc_table(st, size, GFP_KERNEL); 1281 + if (ret) 1282 + goto err_sg_alloc; 1283 + 1284 + st->nents = 0; 1285 + sg = st->sgl; 1286 + 1287 + for (i = 0 ; i < ARRAY_SIZE(rot_info->plane); i++) { 1288 + sg = rotate_pages(obj, rot_info->plane[i].offset, 1289 + rot_info->plane[i].width, rot_info->plane[i].height, 1290 + rot_info->plane[i].stride, st, sg); 1291 + } 1292 + 1293 + return st; 1294 + 1295 + err_sg_alloc: 1296 + kfree(st); 1297 + err_st_alloc: 1298 + 1299 + DRM_DEBUG_DRIVER("Failed to create rotated mapping for object size %zu! (%ux%u tiles, %u pages)\n", 1300 + obj->base.size, rot_info->plane[0].width, rot_info->plane[0].height, size); 1301 + 1302 + return ERR_PTR(ret); 1303 + } 1304 + 1305 + static struct scatterlist * 1306 + remap_pages(struct drm_i915_gem_object *obj, unsigned int offset, 1307 + unsigned int width, unsigned int height, 1308 + unsigned int stride, 1309 + struct sg_table *st, struct scatterlist *sg) 1310 + { 1311 + unsigned int row; 1312 + 1313 + for (row = 0; row < height; row++) { 1314 + unsigned int left = width * I915_GTT_PAGE_SIZE; 1315 + 1316 + while (left) { 1317 + dma_addr_t addr; 1318 + unsigned int length; 1319 + 1320 + /* 1321 + * We don't need the pages, but need to initialize 1322 + * the entries so the sg list can be happily traversed. 1323 + * The only thing we need are DMA addresses. 1324 + */ 1325 + 1326 + addr = i915_gem_object_get_dma_address_len(obj, offset, &length); 1327 + 1328 + length = min(left, length); 1329 + 1330 + st->nents++; 1331 + 1332 + sg_set_page(sg, NULL, length, 0); 1333 + sg_dma_address(sg) = addr; 1334 + sg_dma_len(sg) = length; 1335 + sg = sg_next(sg); 1336 + 1337 + offset += length / I915_GTT_PAGE_SIZE; 1338 + left -= length; 1339 + } 1340 + 1341 + offset += stride - width; 1342 + } 1343 + 1344 + return sg; 1345 + } 1346 + 1347 + static noinline struct sg_table * 1348 + intel_remap_pages(struct intel_remapped_info *rem_info, 1349 + struct drm_i915_gem_object *obj) 1350 + { 1351 + unsigned int size = intel_remapped_info_size(rem_info); 1352 + struct sg_table *st; 1353 + struct scatterlist *sg; 1354 + int ret = -ENOMEM; 1355 + int i; 1356 + 1357 + /* Allocate target SG list. */ 1358 + st = kmalloc(sizeof(*st), GFP_KERNEL); 1359 + if (!st) 1360 + goto err_st_alloc; 1361 + 1362 + ret = sg_alloc_table(st, size, GFP_KERNEL); 1363 + if (ret) 1364 + goto err_sg_alloc; 1365 + 1366 + st->nents = 0; 1367 + sg = st->sgl; 1368 + 1369 + for (i = 0 ; i < ARRAY_SIZE(rem_info->plane); i++) { 1370 + sg = remap_pages(obj, rem_info->plane[i].offset, 1371 + rem_info->plane[i].width, rem_info->plane[i].height, 1372 + rem_info->plane[i].stride, st, sg); 1373 + } 1374 + 1375 + i915_sg_trim(st); 1376 + 1377 + return st; 1378 + 1379 + err_sg_alloc: 1380 + kfree(st); 1381 + err_st_alloc: 1382 + 1383 + DRM_DEBUG_DRIVER("Failed to create remapped mapping for object size %zu! (%ux%u tiles, %u pages)\n", 1384 + obj->base.size, rem_info->plane[0].width, rem_info->plane[0].height, size); 1385 + 1386 + return ERR_PTR(ret); 1387 + } 1388 + 1389 + static noinline struct sg_table * 1390 + intel_partial_pages(const struct i915_ggtt_view *view, 1391 + struct drm_i915_gem_object *obj) 1392 + { 1393 + struct sg_table *st; 1394 + struct scatterlist *sg, *iter; 1395 + unsigned int count = view->partial.size; 1396 + unsigned int offset; 1397 + int ret = -ENOMEM; 1398 + 1399 + st = kmalloc(sizeof(*st), GFP_KERNEL); 1400 + if (!st) 1401 + goto err_st_alloc; 1402 + 1403 + ret = sg_alloc_table(st, count, GFP_KERNEL); 1404 + if (ret) 1405 + goto err_sg_alloc; 1406 + 1407 + iter = i915_gem_object_get_sg(obj, view->partial.offset, &offset); 1408 + GEM_BUG_ON(!iter); 1409 + 1410 + sg = st->sgl; 1411 + st->nents = 0; 1412 + do { 1413 + unsigned int len; 1414 + 1415 + len = min(iter->length - (offset << PAGE_SHIFT), 1416 + count << PAGE_SHIFT); 1417 + sg_set_page(sg, NULL, len, 0); 1418 + sg_dma_address(sg) = 1419 + sg_dma_address(iter) + (offset << PAGE_SHIFT); 1420 + sg_dma_len(sg) = len; 1421 + 1422 + st->nents++; 1423 + count -= len >> PAGE_SHIFT; 1424 + if (count == 0) { 1425 + sg_mark_end(sg); 1426 + i915_sg_trim(st); /* Drop any unused tail entries. */ 1427 + 1428 + return st; 1429 + } 1430 + 1431 + sg = __sg_next(sg); 1432 + iter = __sg_next(iter); 1433 + offset = 0; 1434 + } while (1); 1435 + 1436 + err_sg_alloc: 1437 + kfree(st); 1438 + err_st_alloc: 1439 + return ERR_PTR(ret); 1440 + } 1441 + 1442 + static int 1443 + i915_get_ggtt_vma_pages(struct i915_vma *vma) 1444 + { 1445 + int ret; 1446 + 1447 + /* 1448 + * The vma->pages are only valid within the lifespan of the borrowed 1449 + * obj->mm.pages. When the obj->mm.pages sg_table is regenerated, so 1450 + * must be the vma->pages. A simple rule is that vma->pages must only 1451 + * be accessed when the obj->mm.pages are pinned. 1452 + */ 1453 + GEM_BUG_ON(!i915_gem_object_has_pinned_pages(vma->obj)); 1454 + 1455 + switch (vma->ggtt_view.type) { 1456 + default: 1457 + GEM_BUG_ON(vma->ggtt_view.type); 1458 + /* fall through */ 1459 + case I915_GGTT_VIEW_NORMAL: 1460 + vma->pages = vma->obj->mm.pages; 1461 + return 0; 1462 + 1463 + case I915_GGTT_VIEW_ROTATED: 1464 + vma->pages = 1465 + intel_rotate_pages(&vma->ggtt_view.rotated, vma->obj); 1466 + break; 1467 + 1468 + case I915_GGTT_VIEW_REMAPPED: 1469 + vma->pages = 1470 + intel_remap_pages(&vma->ggtt_view.remapped, vma->obj); 1471 + break; 1472 + 1473 + case I915_GGTT_VIEW_PARTIAL: 1474 + vma->pages = intel_partial_pages(&vma->ggtt_view, vma->obj); 1475 + break; 1476 + } 1477 + 1478 + ret = 0; 1479 + if (IS_ERR(vma->pages)) { 1480 + ret = PTR_ERR(vma->pages); 1481 + vma->pages = NULL; 1482 + DRM_ERROR("Failed to get pages for VMA view type %u (%d)!\n", 1483 + vma->ggtt_view.type, ret); 1484 + } 1485 + return ret; 1486 + }
+4 -11
drivers/gpu/drm/i915/gt/intel_gt.c
··· 38 38 void intel_gt_init_hw_early(struct intel_gt *gt, struct i915_ggtt *ggtt) 39 39 { 40 40 gt->ggtt = ggtt; 41 - 42 - intel_gt_sanitize(gt, false); 43 41 } 44 42 45 43 static void init_unused_ring(struct intel_gt *gt, u32 base) ··· 74 76 struct drm_i915_private *i915 = gt->i915; 75 77 struct intel_uncore *uncore = gt->uncore; 76 78 int ret; 77 - 78 - ret = intel_gt_terminally_wedged(gt); 79 - if (ret) 80 - return ret; 81 79 82 80 gt->last_init_time = ktime_get(); 83 81 ··· 366 372 static struct i915_address_space *kernel_vm(struct intel_gt *gt) 367 373 { 368 374 if (INTEL_PPGTT(gt->i915) > INTEL_PPGTT_ALIASING) 369 - return &i915_ppgtt_create(gt->i915)->vm; 375 + return &i915_ppgtt_create(gt)->vm; 370 376 else 371 377 return i915_vm_get(&gt->ggtt->vm); 372 378 } ··· 404 410 struct intel_context *ce; 405 411 struct i915_request *rq; 406 412 413 + /* We must be able to switch to something! */ 414 + GEM_BUG_ON(!engine->kernel_context); 415 + 407 416 err = intel_renderstate_init(&so, engine); 408 417 if (err) 409 418 goto out; 410 - 411 - /* We must be able to switch to something! */ 412 - GEM_BUG_ON(!engine->kernel_context); 413 - engine->serial++; /* force the kernel context switch */ 414 419 415 420 ce = intel_context_create(engine); 416 421 if (IS_ERR(ce)) {
+6 -1
drivers/gpu/drm/i915/gt/intel_gt.h
··· 58 58 return i915_ggtt_offset(gt->scratch) + field; 59 59 } 60 60 61 - static inline bool intel_gt_is_wedged(struct intel_gt *gt) 61 + static inline bool intel_gt_is_wedged(const struct intel_gt *gt) 62 62 { 63 63 return __intel_reset_failed(&gt->reset); 64 + } 65 + 66 + static inline bool intel_gt_has_init_error(const struct intel_gt *gt) 67 + { 68 + return test_bit(I915_WEDGED_ON_INIT, &gt->reset.flags); 64 69 } 65 70 66 71 #endif /* __INTEL_GT_H__ */
+18 -25
drivers/gpu/drm/i915/gt/intel_gt_pm.c
··· 126 126 return __intel_gt_reset(gt, ALL_ENGINES) == 0; 127 127 } 128 128 129 - /** 130 - * intel_gt_sanitize: called after the GPU has lost power 131 - * @gt: the i915 GT container 132 - * @force: ignore a failed reset and sanitize engine state anyway 133 - * 134 - * Anytime we reset the GPU, either with an explicit GPU reset or through a 135 - * PCI power cycle, the GPU loses state and we must reset our state tracking 136 - * to match. Note that calling intel_gt_sanitize() if the GPU has not 137 - * been reset results in much confusion! 138 - */ 139 - void intel_gt_sanitize(struct intel_gt *gt, bool force) 129 + static void gt_sanitize(struct intel_gt *gt, bool force) 140 130 { 141 131 struct intel_engine_cs *engine; 142 132 enum intel_engine_id id; ··· 179 189 enum intel_engine_id id; 180 190 int err; 181 191 192 + err = intel_gt_has_init_error(gt); 193 + if (err) 194 + return err; 195 + 182 196 GT_TRACE(gt, "\n"); 183 197 184 198 /* ··· 195 201 196 202 intel_uncore_forcewake_get(gt->uncore, FORCEWAKE_ALL); 197 203 intel_rc6_sanitize(&gt->rc6); 204 + gt_sanitize(gt, true); 205 + if (intel_gt_is_wedged(gt)) { 206 + err = -EIO; 207 + goto out_fw; 208 + } 198 209 199 210 /* Only when the HW is re-initialised, can we replay the requests */ 200 211 err = intel_gt_init_hw(gt); 201 212 if (err) { 202 213 dev_err(gt->i915->drm.dev, 203 214 "Failed to initialize GPU, declaring it wedged!\n"); 204 - intel_gt_set_wedged(gt); 205 - goto err_fw; 215 + goto err_wedged; 206 216 } 207 217 208 218 intel_rps_enable(&gt->rps); 209 219 intel_llc_enable(&gt->llc); 210 220 211 221 for_each_engine(engine, gt, id) { 212 - struct intel_context *ce; 213 - 214 222 intel_engine_pm_get(engine); 215 - 216 - ce = engine->kernel_context; 217 - if (ce) { 218 - GEM_BUG_ON(!intel_context_is_pinned(ce)); 219 - ce->ops->reset(ce); 220 - } 221 223 222 224 engine->serial++; /* kernel context lost */ 223 225 err = engine->resume(engine); ··· 223 233 dev_err(gt->i915->drm.dev, 224 234 "Failed to restart %s (%d)\n", 225 235 engine->name, err); 226 - break; 236 + goto err_wedged; 227 237 } 228 238 } 229 239 ··· 233 243 234 244 user_forcewake(gt, false); 235 245 236 - err_fw: 246 + out_fw: 237 247 intel_uncore_forcewake_put(gt->uncore, FORCEWAKE_ALL); 238 248 intel_gt_pm_put(gt); 239 - 240 249 return err; 250 + 251 + err_wedged: 252 + intel_gt_set_wedged(gt); 253 + goto out_fw; 241 254 } 242 255 243 256 static void wait_for_suspend(struct intel_gt *gt) ··· 308 315 intel_llc_disable(&gt->llc); 309 316 } 310 317 311 - intel_gt_sanitize(gt, false); 318 + gt_sanitize(gt, false); 312 319 313 320 GT_TRACE(gt, "\n"); 314 321 }
-2
drivers/gpu/drm/i915/gt/intel_gt_pm.h
··· 51 51 void intel_gt_pm_init(struct intel_gt *gt); 52 52 void intel_gt_pm_fini(struct intel_gt *gt); 53 53 54 - void intel_gt_sanitize(struct intel_gt *gt, bool force); 55 - 56 54 void intel_gt_suspend_prepare(struct intel_gt *gt); 57 55 void intel_gt_suspend_late(struct intel_gt *gt); 58 56 int intel_gt_resume(struct intel_gt *gt);
+12 -10
drivers/gpu/drm/i915/gt/intel_gt_requests.c
··· 14 14 #include "intel_gt_requests.h" 15 15 #include "intel_timeline.h" 16 16 17 - static void retire_requests(struct intel_timeline *tl) 17 + static bool retire_requests(struct intel_timeline *tl) 18 18 { 19 19 struct i915_request *rq, *rn; 20 20 21 21 list_for_each_entry_safe(rq, rn, &tl->requests, link) 22 22 if (!i915_request_retire(rq)) 23 - break; 23 + return false; 24 + 25 + /* And check nothing new was submitted */ 26 + return !i915_active_fence_isset(&tl->last_request); 24 27 } 25 28 26 29 static bool flush_submission(struct intel_gt *gt) ··· 32 29 enum intel_engine_id id; 33 30 bool active = false; 34 31 32 + if (!intel_gt_pm_is_awake(gt)) 33 + return false; 34 + 35 35 for_each_engine(engine, gt, id) { 36 - active |= intel_engine_flush_submission(engine); 36 + intel_engine_flush_submission(engine); 37 37 active |= flush_work(&engine->retire_work); 38 + active |= flush_work(&engine->wakeref.work); 38 39 } 39 40 40 41 return active; ··· 127 120 timeout = -timeout, interruptible = false; 128 121 129 122 flush_submission(gt); /* kick the ksoftirqd tasklets */ 130 - 131 123 spin_lock(&timelines->lock); 132 124 list_for_each_entry_safe(tl, tn, &timelines->active_list, link) { 133 125 if (!mutex_trylock(&tl->mutex)) { ··· 151 145 } 152 146 } 153 147 154 - retire_requests(tl); 148 + if (!retire_requests(tl) || flush_submission(gt)) 149 + active_count++; 155 150 156 151 spin_lock(&timelines->lock); 157 152 ··· 160 153 list_safe_reset_next(tl, tn, link); 161 154 if (atomic_dec_and_test(&tl->active_count)) 162 155 list_del(&tl->link); 163 - else 164 - active_count += i915_active_fence_isset(&tl->last_request); 165 156 166 157 mutex_unlock(&tl->mutex); 167 158 ··· 173 168 174 169 list_for_each_entry_safe(tl, tn, &free, link) 175 170 __intel_timeline_free(&tl->kref); 176 - 177 - if (flush_submission(gt)) 178 - active_count++; 179 171 180 172 return active_count ? timeout : 0; 181 173 }
+598
drivers/gpu/drm/i915/gt/intel_gtt.c
··· 1 + // SPDX-License-Identifier: MIT 2 + /* 3 + * Copyright © 2020 Intel Corporation 4 + */ 5 + 6 + #include <linux/slab.h> /* fault-inject.h is not standalone! */ 7 + 8 + #include <linux/fault-inject.h> 9 + 10 + #include "i915_trace.h" 11 + #include "intel_gt.h" 12 + #include "intel_gtt.h" 13 + 14 + void stash_init(struct pagestash *stash) 15 + { 16 + pagevec_init(&stash->pvec); 17 + spin_lock_init(&stash->lock); 18 + } 19 + 20 + static struct page *stash_pop_page(struct pagestash *stash) 21 + { 22 + struct page *page = NULL; 23 + 24 + spin_lock(&stash->lock); 25 + if (likely(stash->pvec.nr)) 26 + page = stash->pvec.pages[--stash->pvec.nr]; 27 + spin_unlock(&stash->lock); 28 + 29 + return page; 30 + } 31 + 32 + static void stash_push_pagevec(struct pagestash *stash, struct pagevec *pvec) 33 + { 34 + unsigned int nr; 35 + 36 + spin_lock_nested(&stash->lock, SINGLE_DEPTH_NESTING); 37 + 38 + nr = min_t(typeof(nr), pvec->nr, pagevec_space(&stash->pvec)); 39 + memcpy(stash->pvec.pages + stash->pvec.nr, 40 + pvec->pages + pvec->nr - nr, 41 + sizeof(pvec->pages[0]) * nr); 42 + stash->pvec.nr += nr; 43 + 44 + spin_unlock(&stash->lock); 45 + 46 + pvec->nr -= nr; 47 + } 48 + 49 + static struct page *vm_alloc_page(struct i915_address_space *vm, gfp_t gfp) 50 + { 51 + struct pagevec stack; 52 + struct page *page; 53 + 54 + if (I915_SELFTEST_ONLY(should_fail(&vm->fault_attr, 1))) 55 + i915_gem_shrink_all(vm->i915); 56 + 57 + page = stash_pop_page(&vm->free_pages); 58 + if (page) 59 + return page; 60 + 61 + if (!vm->pt_kmap_wc) 62 + return alloc_page(gfp); 63 + 64 + /* Look in our global stash of WC pages... */ 65 + page = stash_pop_page(&vm->i915->mm.wc_stash); 66 + if (page) 67 + return page; 68 + 69 + /* 70 + * Otherwise batch allocate pages to amortize cost of set_pages_wc. 71 + * 72 + * We have to be careful as page allocation may trigger the shrinker 73 + * (via direct reclaim) which will fill up the WC stash underneath us. 74 + * So we add our WB pages into a temporary pvec on the stack and merge 75 + * them into the WC stash after all the allocations are complete. 76 + */ 77 + pagevec_init(&stack); 78 + do { 79 + struct page *page; 80 + 81 + page = alloc_page(gfp); 82 + if (unlikely(!page)) 83 + break; 84 + 85 + stack.pages[stack.nr++] = page; 86 + } while (pagevec_space(&stack)); 87 + 88 + if (stack.nr && !set_pages_array_wc(stack.pages, stack.nr)) { 89 + page = stack.pages[--stack.nr]; 90 + 91 + /* Merge spare WC pages to the global stash */ 92 + if (stack.nr) 93 + stash_push_pagevec(&vm->i915->mm.wc_stash, &stack); 94 + 95 + /* Push any surplus WC pages onto the local VM stash */ 96 + if (stack.nr) 97 + stash_push_pagevec(&vm->free_pages, &stack); 98 + } 99 + 100 + /* Return unwanted leftovers */ 101 + if (unlikely(stack.nr)) { 102 + WARN_ON_ONCE(set_pages_array_wb(stack.pages, stack.nr)); 103 + __pagevec_release(&stack); 104 + } 105 + 106 + return page; 107 + } 108 + 109 + static void vm_free_pages_release(struct i915_address_space *vm, 110 + bool immediate) 111 + { 112 + struct pagevec *pvec = &vm->free_pages.pvec; 113 + struct pagevec stack; 114 + 115 + lockdep_assert_held(&vm->free_pages.lock); 116 + GEM_BUG_ON(!pagevec_count(pvec)); 117 + 118 + if (vm->pt_kmap_wc) { 119 + /* 120 + * When we use WC, first fill up the global stash and then 121 + * only if full immediately free the overflow. 122 + */ 123 + stash_push_pagevec(&vm->i915->mm.wc_stash, pvec); 124 + 125 + /* 126 + * As we have made some room in the VM's free_pages, 127 + * we can wait for it to fill again. Unless we are 128 + * inside i915_address_space_fini() and must 129 + * immediately release the pages! 130 + */ 131 + if (pvec->nr <= (immediate ? 0 : PAGEVEC_SIZE - 1)) 132 + return; 133 + 134 + /* 135 + * We have to drop the lock to allow ourselves to sleep, 136 + * so take a copy of the pvec and clear the stash for 137 + * others to use it as we sleep. 138 + */ 139 + stack = *pvec; 140 + pagevec_reinit(pvec); 141 + spin_unlock(&vm->free_pages.lock); 142 + 143 + pvec = &stack; 144 + set_pages_array_wb(pvec->pages, pvec->nr); 145 + 146 + spin_lock(&vm->free_pages.lock); 147 + } 148 + 149 + __pagevec_release(pvec); 150 + } 151 + 152 + static void vm_free_page(struct i915_address_space *vm, struct page *page) 153 + { 154 + /* 155 + * On !llc, we need to change the pages back to WB. We only do so 156 + * in bulk, so we rarely need to change the page attributes here, 157 + * but doing so requires a stop_machine() from deep inside arch/x86/mm. 158 + * To make detection of the possible sleep more likely, use an 159 + * unconditional might_sleep() for everybody. 160 + */ 161 + might_sleep(); 162 + spin_lock(&vm->free_pages.lock); 163 + while (!pagevec_space(&vm->free_pages.pvec)) 164 + vm_free_pages_release(vm, false); 165 + GEM_BUG_ON(pagevec_count(&vm->free_pages.pvec) >= PAGEVEC_SIZE); 166 + pagevec_add(&vm->free_pages.pvec, page); 167 + spin_unlock(&vm->free_pages.lock); 168 + } 169 + 170 + void __i915_vm_close(struct i915_address_space *vm) 171 + { 172 + struct i915_vma *vma, *vn; 173 + 174 + mutex_lock(&vm->mutex); 175 + list_for_each_entry_safe(vma, vn, &vm->bound_list, vm_link) { 176 + struct drm_i915_gem_object *obj = vma->obj; 177 + 178 + /* Keep the obj (and hence the vma) alive as _we_ destroy it */ 179 + if (!kref_get_unless_zero(&obj->base.refcount)) 180 + continue; 181 + 182 + atomic_and(~I915_VMA_PIN_MASK, &vma->flags); 183 + WARN_ON(__i915_vma_unbind(vma)); 184 + __i915_vma_put(vma); 185 + 186 + i915_gem_object_put(obj); 187 + } 188 + GEM_BUG_ON(!list_empty(&vm->bound_list)); 189 + mutex_unlock(&vm->mutex); 190 + } 191 + 192 + void i915_address_space_fini(struct i915_address_space *vm) 193 + { 194 + spin_lock(&vm->free_pages.lock); 195 + if (pagevec_count(&vm->free_pages.pvec)) 196 + vm_free_pages_release(vm, true); 197 + GEM_BUG_ON(pagevec_count(&vm->free_pages.pvec)); 198 + spin_unlock(&vm->free_pages.lock); 199 + 200 + drm_mm_takedown(&vm->mm); 201 + 202 + mutex_destroy(&vm->mutex); 203 + } 204 + 205 + static void __i915_vm_release(struct work_struct *work) 206 + { 207 + struct i915_address_space *vm = 208 + container_of(work, struct i915_address_space, rcu.work); 209 + 210 + vm->cleanup(vm); 211 + i915_address_space_fini(vm); 212 + 213 + kfree(vm); 214 + } 215 + 216 + void i915_vm_release(struct kref *kref) 217 + { 218 + struct i915_address_space *vm = 219 + container_of(kref, struct i915_address_space, ref); 220 + 221 + GEM_BUG_ON(i915_is_ggtt(vm)); 222 + trace_i915_ppgtt_release(vm); 223 + 224 + queue_rcu_work(vm->i915->wq, &vm->rcu); 225 + } 226 + 227 + void i915_address_space_init(struct i915_address_space *vm, int subclass) 228 + { 229 + kref_init(&vm->ref); 230 + INIT_RCU_WORK(&vm->rcu, __i915_vm_release); 231 + atomic_set(&vm->open, 1); 232 + 233 + /* 234 + * The vm->mutex must be reclaim safe (for use in the shrinker). 235 + * Do a dummy acquire now under fs_reclaim so that any allocation 236 + * attempt holding the lock is immediately reported by lockdep. 237 + */ 238 + mutex_init(&vm->mutex); 239 + lockdep_set_subclass(&vm->mutex, subclass); 240 + i915_gem_shrinker_taints_mutex(vm->i915, &vm->mutex); 241 + 242 + GEM_BUG_ON(!vm->total); 243 + drm_mm_init(&vm->mm, 0, vm->total); 244 + vm->mm.head_node.color = I915_COLOR_UNEVICTABLE; 245 + 246 + stash_init(&vm->free_pages); 247 + 248 + INIT_LIST_HEAD(&vm->bound_list); 249 + } 250 + 251 + void clear_pages(struct i915_vma *vma) 252 + { 253 + GEM_BUG_ON(!vma->pages); 254 + 255 + if (vma->pages != vma->obj->mm.pages) { 256 + sg_free_table(vma->pages); 257 + kfree(vma->pages); 258 + } 259 + vma->pages = NULL; 260 + 261 + memset(&vma->page_sizes, 0, sizeof(vma->page_sizes)); 262 + } 263 + 264 + static int __setup_page_dma(struct i915_address_space *vm, 265 + struct i915_page_dma *p, 266 + gfp_t gfp) 267 + { 268 + p->page = vm_alloc_page(vm, gfp | I915_GFP_ALLOW_FAIL); 269 + if (unlikely(!p->page)) 270 + return -ENOMEM; 271 + 272 + p->daddr = dma_map_page_attrs(vm->dma, 273 + p->page, 0, PAGE_SIZE, 274 + PCI_DMA_BIDIRECTIONAL, 275 + DMA_ATTR_SKIP_CPU_SYNC | 276 + DMA_ATTR_NO_WARN); 277 + if (unlikely(dma_mapping_error(vm->dma, p->daddr))) { 278 + vm_free_page(vm, p->page); 279 + return -ENOMEM; 280 + } 281 + 282 + return 0; 283 + } 284 + 285 + int setup_page_dma(struct i915_address_space *vm, struct i915_page_dma *p) 286 + { 287 + return __setup_page_dma(vm, p, __GFP_HIGHMEM); 288 + } 289 + 290 + void cleanup_page_dma(struct i915_address_space *vm, struct i915_page_dma *p) 291 + { 292 + dma_unmap_page(vm->dma, p->daddr, PAGE_SIZE, PCI_DMA_BIDIRECTIONAL); 293 + vm_free_page(vm, p->page); 294 + } 295 + 296 + void 297 + fill_page_dma(const struct i915_page_dma *p, const u64 val, unsigned int count) 298 + { 299 + kunmap_atomic(memset64(kmap_atomic(p->page), val, count)); 300 + } 301 + 302 + int setup_scratch_page(struct i915_address_space *vm, gfp_t gfp) 303 + { 304 + unsigned long size; 305 + 306 + /* 307 + * In order to utilize 64K pages for an object with a size < 2M, we will 308 + * need to support a 64K scratch page, given that every 16th entry for a 309 + * page-table operating in 64K mode must point to a properly aligned 64K 310 + * region, including any PTEs which happen to point to scratch. 311 + * 312 + * This is only relevant for the 48b PPGTT where we support 313 + * huge-gtt-pages, see also i915_vma_insert(). However, as we share the 314 + * scratch (read-only) between all vm, we create one 64k scratch page 315 + * for all. 316 + */ 317 + size = I915_GTT_PAGE_SIZE_4K; 318 + if (i915_vm_is_4lvl(vm) && 319 + HAS_PAGE_SIZES(vm->i915, I915_GTT_PAGE_SIZE_64K)) { 320 + size = I915_GTT_PAGE_SIZE_64K; 321 + gfp |= __GFP_NOWARN; 322 + } 323 + gfp |= __GFP_ZERO | __GFP_RETRY_MAYFAIL; 324 + 325 + do { 326 + unsigned int order = get_order(size); 327 + struct page *page; 328 + dma_addr_t addr; 329 + 330 + page = alloc_pages(gfp, order); 331 + if (unlikely(!page)) 332 + goto skip; 333 + 334 + addr = dma_map_page_attrs(vm->dma, 335 + page, 0, size, 336 + PCI_DMA_BIDIRECTIONAL, 337 + DMA_ATTR_SKIP_CPU_SYNC | 338 + DMA_ATTR_NO_WARN); 339 + if (unlikely(dma_mapping_error(vm->dma, addr))) 340 + goto free_page; 341 + 342 + if (unlikely(!IS_ALIGNED(addr, size))) 343 + goto unmap_page; 344 + 345 + vm->scratch[0].base.page = page; 346 + vm->scratch[0].base.daddr = addr; 347 + vm->scratch_order = order; 348 + return 0; 349 + 350 + unmap_page: 351 + dma_unmap_page(vm->dma, addr, size, PCI_DMA_BIDIRECTIONAL); 352 + free_page: 353 + __free_pages(page, order); 354 + skip: 355 + if (size == I915_GTT_PAGE_SIZE_4K) 356 + return -ENOMEM; 357 + 358 + size = I915_GTT_PAGE_SIZE_4K; 359 + gfp &= ~__GFP_NOWARN; 360 + } while (1); 361 + } 362 + 363 + void cleanup_scratch_page(struct i915_address_space *vm) 364 + { 365 + struct i915_page_dma *p = px_base(&vm->scratch[0]); 366 + unsigned int order = vm->scratch_order; 367 + 368 + dma_unmap_page(vm->dma, p->daddr, BIT(order) << PAGE_SHIFT, 369 + PCI_DMA_BIDIRECTIONAL); 370 + __free_pages(p->page, order); 371 + } 372 + 373 + void free_scratch(struct i915_address_space *vm) 374 + { 375 + int i; 376 + 377 + if (!px_dma(&vm->scratch[0])) /* set to 0 on clones */ 378 + return; 379 + 380 + for (i = 1; i <= vm->top; i++) { 381 + if (!px_dma(&vm->scratch[i])) 382 + break; 383 + cleanup_page_dma(vm, px_base(&vm->scratch[i])); 384 + } 385 + 386 + cleanup_scratch_page(vm); 387 + } 388 + 389 + void gtt_write_workarounds(struct intel_gt *gt) 390 + { 391 + struct drm_i915_private *i915 = gt->i915; 392 + struct intel_uncore *uncore = gt->uncore; 393 + 394 + /* 395 + * This function is for gtt related workarounds. This function is 396 + * called on driver load and after a GPU reset, so you can place 397 + * workarounds here even if they get overwritten by GPU reset. 398 + */ 399 + /* WaIncreaseDefaultTLBEntries:chv,bdw,skl,bxt,kbl,glk,cfl,cnl,icl */ 400 + if (IS_BROADWELL(i915)) 401 + intel_uncore_write(uncore, 402 + GEN8_L3_LRA_1_GPGPU, 403 + GEN8_L3_LRA_1_GPGPU_DEFAULT_VALUE_BDW); 404 + else if (IS_CHERRYVIEW(i915)) 405 + intel_uncore_write(uncore, 406 + GEN8_L3_LRA_1_GPGPU, 407 + GEN8_L3_LRA_1_GPGPU_DEFAULT_VALUE_CHV); 408 + else if (IS_GEN9_LP(i915)) 409 + intel_uncore_write(uncore, 410 + GEN8_L3_LRA_1_GPGPU, 411 + GEN9_L3_LRA_1_GPGPU_DEFAULT_VALUE_BXT); 412 + else if (INTEL_GEN(i915) >= 9 && INTEL_GEN(i915) <= 11) 413 + intel_uncore_write(uncore, 414 + GEN8_L3_LRA_1_GPGPU, 415 + GEN9_L3_LRA_1_GPGPU_DEFAULT_VALUE_SKL); 416 + 417 + /* 418 + * To support 64K PTEs we need to first enable the use of the 419 + * Intermediate-Page-Size(IPS) bit of the PDE field via some magical 420 + * mmio, otherwise the page-walker will simply ignore the IPS bit. This 421 + * shouldn't be needed after GEN10. 422 + * 423 + * 64K pages were first introduced from BDW+, although technically they 424 + * only *work* from gen9+. For pre-BDW we instead have the option for 425 + * 32K pages, but we don't currently have any support for it in our 426 + * driver. 427 + */ 428 + if (HAS_PAGE_SIZES(i915, I915_GTT_PAGE_SIZE_64K) && 429 + INTEL_GEN(i915) <= 10) 430 + intel_uncore_rmw(uncore, 431 + GEN8_GAMW_ECO_DEV_RW_IA, 432 + 0, 433 + GAMW_ECO_ENABLE_64K_IPS_FIELD); 434 + 435 + if (IS_GEN_RANGE(i915, 8, 11)) { 436 + bool can_use_gtt_cache = true; 437 + 438 + /* 439 + * According to the BSpec if we use 2M/1G pages then we also 440 + * need to disable the GTT cache. At least on BDW we can see 441 + * visual corruption when using 2M pages, and not disabling the 442 + * GTT cache. 443 + */ 444 + if (HAS_PAGE_SIZES(i915, I915_GTT_PAGE_SIZE_2M)) 445 + can_use_gtt_cache = false; 446 + 447 + /* WaGttCachingOffByDefault */ 448 + intel_uncore_write(uncore, 449 + HSW_GTT_CACHE_EN, 450 + can_use_gtt_cache ? GTT_CACHE_EN_ALL : 0); 451 + WARN_ON_ONCE(can_use_gtt_cache && 452 + intel_uncore_read(uncore, 453 + HSW_GTT_CACHE_EN) == 0); 454 + } 455 + } 456 + 457 + u64 gen8_pte_encode(dma_addr_t addr, 458 + enum i915_cache_level level, 459 + u32 flags) 460 + { 461 + gen8_pte_t pte = addr | _PAGE_PRESENT | _PAGE_RW; 462 + 463 + if (unlikely(flags & PTE_READ_ONLY)) 464 + pte &= ~_PAGE_RW; 465 + 466 + switch (level) { 467 + case I915_CACHE_NONE: 468 + pte |= PPAT_UNCACHED; 469 + break; 470 + case I915_CACHE_WT: 471 + pte |= PPAT_DISPLAY_ELLC; 472 + break; 473 + default: 474 + pte |= PPAT_CACHED; 475 + break; 476 + } 477 + 478 + return pte; 479 + } 480 + 481 + static void tgl_setup_private_ppat(struct intel_uncore *uncore) 482 + { 483 + /* TGL doesn't support LLC or AGE settings */ 484 + intel_uncore_write(uncore, GEN12_PAT_INDEX(0), GEN8_PPAT_WB); 485 + intel_uncore_write(uncore, GEN12_PAT_INDEX(1), GEN8_PPAT_WC); 486 + intel_uncore_write(uncore, GEN12_PAT_INDEX(2), GEN8_PPAT_WT); 487 + intel_uncore_write(uncore, GEN12_PAT_INDEX(3), GEN8_PPAT_UC); 488 + intel_uncore_write(uncore, GEN12_PAT_INDEX(4), GEN8_PPAT_WB); 489 + intel_uncore_write(uncore, GEN12_PAT_INDEX(5), GEN8_PPAT_WB); 490 + intel_uncore_write(uncore, GEN12_PAT_INDEX(6), GEN8_PPAT_WB); 491 + intel_uncore_write(uncore, GEN12_PAT_INDEX(7), GEN8_PPAT_WB); 492 + } 493 + 494 + static void cnl_setup_private_ppat(struct intel_uncore *uncore) 495 + { 496 + intel_uncore_write(uncore, 497 + GEN10_PAT_INDEX(0), 498 + GEN8_PPAT_WB | GEN8_PPAT_LLC); 499 + intel_uncore_write(uncore, 500 + GEN10_PAT_INDEX(1), 501 + GEN8_PPAT_WC | GEN8_PPAT_LLCELLC); 502 + intel_uncore_write(uncore, 503 + GEN10_PAT_INDEX(2), 504 + GEN8_PPAT_WT | GEN8_PPAT_LLCELLC); 505 + intel_uncore_write(uncore, 506 + GEN10_PAT_INDEX(3), 507 + GEN8_PPAT_UC); 508 + intel_uncore_write(uncore, 509 + GEN10_PAT_INDEX(4), 510 + GEN8_PPAT_WB | GEN8_PPAT_LLCELLC | GEN8_PPAT_AGE(0)); 511 + intel_uncore_write(uncore, 512 + GEN10_PAT_INDEX(5), 513 + GEN8_PPAT_WB | GEN8_PPAT_LLCELLC | GEN8_PPAT_AGE(1)); 514 + intel_uncore_write(uncore, 515 + GEN10_PAT_INDEX(6), 516 + GEN8_PPAT_WB | GEN8_PPAT_LLCELLC | GEN8_PPAT_AGE(2)); 517 + intel_uncore_write(uncore, 518 + GEN10_PAT_INDEX(7), 519 + GEN8_PPAT_WB | GEN8_PPAT_LLCELLC | GEN8_PPAT_AGE(3)); 520 + } 521 + 522 + /* 523 + * The GGTT and PPGTT need a private PPAT setup in order to handle cacheability 524 + * bits. When using advanced contexts each context stores its own PAT, but 525 + * writing this data shouldn't be harmful even in those cases. 526 + */ 527 + static void bdw_setup_private_ppat(struct intel_uncore *uncore) 528 + { 529 + u64 pat; 530 + 531 + pat = GEN8_PPAT(0, GEN8_PPAT_WB | GEN8_PPAT_LLC) | /* for normal objects, no eLLC */ 532 + GEN8_PPAT(1, GEN8_PPAT_WC | GEN8_PPAT_LLCELLC) | /* for something pointing to ptes? */ 533 + GEN8_PPAT(2, GEN8_PPAT_WT | GEN8_PPAT_LLCELLC) | /* for scanout with eLLC */ 534 + GEN8_PPAT(3, GEN8_PPAT_UC) | /* Uncached objects, mostly for scanout */ 535 + GEN8_PPAT(4, GEN8_PPAT_WB | GEN8_PPAT_LLCELLC | GEN8_PPAT_AGE(0)) | 536 + GEN8_PPAT(5, GEN8_PPAT_WB | GEN8_PPAT_LLCELLC | GEN8_PPAT_AGE(1)) | 537 + GEN8_PPAT(6, GEN8_PPAT_WB | GEN8_PPAT_LLCELLC | GEN8_PPAT_AGE(2)) | 538 + GEN8_PPAT(7, GEN8_PPAT_WB | GEN8_PPAT_LLCELLC | GEN8_PPAT_AGE(3)); 539 + 540 + intel_uncore_write(uncore, GEN8_PRIVATE_PAT_LO, lower_32_bits(pat)); 541 + intel_uncore_write(uncore, GEN8_PRIVATE_PAT_HI, upper_32_bits(pat)); 542 + } 543 + 544 + static void chv_setup_private_ppat(struct intel_uncore *uncore) 545 + { 546 + u64 pat; 547 + 548 + /* 549 + * Map WB on BDW to snooped on CHV. 550 + * 551 + * Only the snoop bit has meaning for CHV, the rest is 552 + * ignored. 553 + * 554 + * The hardware will never snoop for certain types of accesses: 555 + * - CPU GTT (GMADR->GGTT->no snoop->memory) 556 + * - PPGTT page tables 557 + * - some other special cycles 558 + * 559 + * As with BDW, we also need to consider the following for GT accesses: 560 + * "For GGTT, there is NO pat_sel[2:0] from the entry, 561 + * so RTL will always use the value corresponding to 562 + * pat_sel = 000". 563 + * Which means we must set the snoop bit in PAT entry 0 564 + * in order to keep the global status page working. 565 + */ 566 + 567 + pat = GEN8_PPAT(0, CHV_PPAT_SNOOP) | 568 + GEN8_PPAT(1, 0) | 569 + GEN8_PPAT(2, 0) | 570 + GEN8_PPAT(3, 0) | 571 + GEN8_PPAT(4, CHV_PPAT_SNOOP) | 572 + GEN8_PPAT(5, CHV_PPAT_SNOOP) | 573 + GEN8_PPAT(6, CHV_PPAT_SNOOP) | 574 + GEN8_PPAT(7, CHV_PPAT_SNOOP); 575 + 576 + intel_uncore_write(uncore, GEN8_PRIVATE_PAT_LO, lower_32_bits(pat)); 577 + intel_uncore_write(uncore, GEN8_PRIVATE_PAT_HI, upper_32_bits(pat)); 578 + } 579 + 580 + void setup_private_pat(struct intel_uncore *uncore) 581 + { 582 + struct drm_i915_private *i915 = uncore->i915; 583 + 584 + GEM_BUG_ON(INTEL_GEN(i915) < 8); 585 + 586 + if (INTEL_GEN(i915) >= 12) 587 + tgl_setup_private_ppat(uncore); 588 + else if (INTEL_GEN(i915) >= 10) 589 + cnl_setup_private_ppat(uncore); 590 + else if (IS_CHERRYVIEW(i915) || IS_GEN9_LP(i915)) 591 + chv_setup_private_ppat(uncore); 592 + else 593 + bdw_setup_private_ppat(uncore); 594 + } 595 + 596 + #if IS_ENABLED(CONFIG_DRM_I915_SELFTEST) 597 + #include "selftests/mock_gtt.c" 598 + #endif
+587
drivers/gpu/drm/i915/gt/intel_gtt.h
··· 1 + /* SPDX-License-Identifier: MIT */ 2 + /* 3 + * Copyright © 2020 Intel Corporation 4 + * 5 + * Please try to maintain the following order within this file unless it makes 6 + * sense to do otherwise. From top to bottom: 7 + * 1. typedefs 8 + * 2. #defines, and macros 9 + * 3. structure definitions 10 + * 4. function prototypes 11 + * 12 + * Within each section, please try to order by generation in ascending order, 13 + * from top to bottom (ie. gen6 on the top, gen8 on the bottom). 14 + */ 15 + 16 + #ifndef __INTEL_GTT_H__ 17 + #define __INTEL_GTT_H__ 18 + 19 + #include <linux/io-mapping.h> 20 + #include <linux/kref.h> 21 + #include <linux/mm.h> 22 + #include <linux/pagevec.h> 23 + #include <linux/scatterlist.h> 24 + #include <linux/workqueue.h> 25 + 26 + #include <drm/drm_mm.h> 27 + 28 + #include "gt/intel_reset.h" 29 + #include "i915_gem_fence_reg.h" 30 + #include "i915_selftest.h" 31 + #include "i915_vma_types.h" 32 + 33 + #define I915_GFP_ALLOW_FAIL (GFP_KERNEL | __GFP_RETRY_MAYFAIL | __GFP_NOWARN) 34 + 35 + #if IS_ENABLED(CONFIG_DRM_I915_TRACE_GTT) 36 + #define DBG(...) trace_printk(__VA_ARGS__) 37 + #else 38 + #define DBG(...) 39 + #endif 40 + 41 + #define NALLOC 3 /* 1 normal, 1 for concurrent threads, 1 for preallocation */ 42 + 43 + #define I915_GTT_PAGE_SIZE_4K BIT_ULL(12) 44 + #define I915_GTT_PAGE_SIZE_64K BIT_ULL(16) 45 + #define I915_GTT_PAGE_SIZE_2M BIT_ULL(21) 46 + 47 + #define I915_GTT_PAGE_SIZE I915_GTT_PAGE_SIZE_4K 48 + #define I915_GTT_MAX_PAGE_SIZE I915_GTT_PAGE_SIZE_2M 49 + 50 + #define I915_GTT_PAGE_MASK -I915_GTT_PAGE_SIZE 51 + 52 + #define I915_GTT_MIN_ALIGNMENT I915_GTT_PAGE_SIZE 53 + 54 + #define I915_FENCE_REG_NONE -1 55 + #define I915_MAX_NUM_FENCES 32 56 + /* 32 fences + sign bit for FENCE_REG_NONE */ 57 + #define I915_MAX_NUM_FENCE_BITS 6 58 + 59 + typedef u32 gen6_pte_t; 60 + typedef u64 gen8_pte_t; 61 + 62 + #define ggtt_total_entries(ggtt) ((ggtt)->vm.total >> PAGE_SHIFT) 63 + 64 + #define I915_PTES(pte_len) ((unsigned int)(PAGE_SIZE / (pte_len))) 65 + #define I915_PTE_MASK(pte_len) (I915_PTES(pte_len) - 1) 66 + #define I915_PDES 512 67 + #define I915_PDE_MASK (I915_PDES - 1) 68 + 69 + /* gen6-hsw has bit 11-4 for physical addr bit 39-32 */ 70 + #define GEN6_GTT_ADDR_ENCODE(addr) ((addr) | (((addr) >> 28) & 0xff0)) 71 + #define GEN6_PTE_ADDR_ENCODE(addr) GEN6_GTT_ADDR_ENCODE(addr) 72 + #define GEN6_PDE_ADDR_ENCODE(addr) GEN6_GTT_ADDR_ENCODE(addr) 73 + #define GEN6_PTE_CACHE_LLC (2 << 1) 74 + #define GEN6_PTE_UNCACHED (1 << 1) 75 + #define GEN6_PTE_VALID REG_BIT(0) 76 + 77 + #define GEN6_PTES I915_PTES(sizeof(gen6_pte_t)) 78 + #define GEN6_PD_SIZE (I915_PDES * PAGE_SIZE) 79 + #define GEN6_PD_ALIGN (PAGE_SIZE * 16) 80 + #define GEN6_PDE_SHIFT 22 81 + #define GEN6_PDE_VALID REG_BIT(0) 82 + #define NUM_PTE(pde_shift) (1 << (pde_shift - PAGE_SHIFT)) 83 + 84 + #define GEN7_PTE_CACHE_L3_LLC (3 << 1) 85 + 86 + #define BYT_PTE_SNOOPED_BY_CPU_CACHES REG_BIT(2) 87 + #define BYT_PTE_WRITEABLE REG_BIT(1) 88 + 89 + /* 90 + * Cacheability Control is a 4-bit value. The low three bits are stored in bits 91 + * 3:1 of the PTE, while the fourth bit is stored in bit 11 of the PTE. 92 + */ 93 + #define HSW_CACHEABILITY_CONTROL(bits) ((((bits) & 0x7) << 1) | \ 94 + (((bits) & 0x8) << (11 - 3))) 95 + #define HSW_WB_LLC_AGE3 HSW_CACHEABILITY_CONTROL(0x2) 96 + #define HSW_WB_LLC_AGE0 HSW_CACHEABILITY_CONTROL(0x3) 97 + #define HSW_WB_ELLC_LLC_AGE3 HSW_CACHEABILITY_CONTROL(0x8) 98 + #define HSW_WB_ELLC_LLC_AGE0 HSW_CACHEABILITY_CONTROL(0xb) 99 + #define HSW_WT_ELLC_LLC_AGE3 HSW_CACHEABILITY_CONTROL(0x7) 100 + #define HSW_WT_ELLC_LLC_AGE0 HSW_CACHEABILITY_CONTROL(0x6) 101 + #define HSW_PTE_UNCACHED (0) 102 + #define HSW_GTT_ADDR_ENCODE(addr) ((addr) | (((addr) >> 28) & 0x7f0)) 103 + #define HSW_PTE_ADDR_ENCODE(addr) HSW_GTT_ADDR_ENCODE(addr) 104 + 105 + /* 106 + * GEN8 32b style address is defined as a 3 level page table: 107 + * 31:30 | 29:21 | 20:12 | 11:0 108 + * PDPE | PDE | PTE | offset 109 + * The difference as compared to normal x86 3 level page table is the PDPEs are 110 + * programmed via register. 111 + * 112 + * GEN8 48b style address is defined as a 4 level page table: 113 + * 47:39 | 38:30 | 29:21 | 20:12 | 11:0 114 + * PML4E | PDPE | PDE | PTE | offset 115 + */ 116 + #define GEN8_3LVL_PDPES 4 117 + 118 + #define PPAT_UNCACHED (_PAGE_PWT | _PAGE_PCD) 119 + #define PPAT_CACHED_PDE 0 /* WB LLC */ 120 + #define PPAT_CACHED _PAGE_PAT /* WB LLCeLLC */ 121 + #define PPAT_DISPLAY_ELLC _PAGE_PCD /* WT eLLC */ 122 + 123 + #define CHV_PPAT_SNOOP REG_BIT(6) 124 + #define GEN8_PPAT_AGE(x) ((x)<<4) 125 + #define GEN8_PPAT_LLCeLLC (3<<2) 126 + #define GEN8_PPAT_LLCELLC (2<<2) 127 + #define GEN8_PPAT_LLC (1<<2) 128 + #define GEN8_PPAT_WB (3<<0) 129 + #define GEN8_PPAT_WT (2<<0) 130 + #define GEN8_PPAT_WC (1<<0) 131 + #define GEN8_PPAT_UC (0<<0) 132 + #define GEN8_PPAT_ELLC_OVERRIDE (0<<2) 133 + #define GEN8_PPAT(i, x) ((u64)(x) << ((i) * 8)) 134 + 135 + #define GEN8_PDE_IPS_64K BIT(11) 136 + #define GEN8_PDE_PS_2M BIT(7) 137 + 138 + #define for_each_sgt_daddr(__dp, __iter, __sgt) \ 139 + __for_each_sgt_daddr(__dp, __iter, __sgt, I915_GTT_PAGE_SIZE) 140 + 141 + struct i915_page_dma { 142 + struct page *page; 143 + union { 144 + dma_addr_t daddr; 145 + 146 + /* 147 + * For gen6/gen7 only. This is the offset in the GGTT 148 + * where the page directory entries for PPGTT begin 149 + */ 150 + u32 ggtt_offset; 151 + }; 152 + }; 153 + 154 + struct i915_page_scratch { 155 + struct i915_page_dma base; 156 + u64 encode; 157 + }; 158 + 159 + struct i915_page_table { 160 + struct i915_page_dma base; 161 + atomic_t used; 162 + }; 163 + 164 + struct i915_page_directory { 165 + struct i915_page_table pt; 166 + spinlock_t lock; 167 + void *entry[512]; 168 + }; 169 + 170 + #define __px_choose_expr(x, type, expr, other) \ 171 + __builtin_choose_expr( \ 172 + __builtin_types_compatible_p(typeof(x), type) || \ 173 + __builtin_types_compatible_p(typeof(x), const type), \ 174 + ({ type __x = (type)(x); expr; }), \ 175 + other) 176 + 177 + #define px_base(px) \ 178 + __px_choose_expr(px, struct i915_page_dma *, __x, \ 179 + __px_choose_expr(px, struct i915_page_scratch *, &__x->base, \ 180 + __px_choose_expr(px, struct i915_page_table *, &__x->base, \ 181 + __px_choose_expr(px, struct i915_page_directory *, &__x->pt.base, \ 182 + (void)0)))) 183 + #define px_dma(px) (px_base(px)->daddr) 184 + 185 + #define px_pt(px) \ 186 + __px_choose_expr(px, struct i915_page_table *, __x, \ 187 + __px_choose_expr(px, struct i915_page_directory *, &__x->pt, \ 188 + (void)0)) 189 + #define px_used(px) (&px_pt(px)->used) 190 + 191 + enum i915_cache_level; 192 + 193 + struct drm_i915_file_private; 194 + struct drm_i915_gem_object; 195 + struct i915_vma; 196 + struct intel_gt; 197 + 198 + struct i915_vma_ops { 199 + /* Map an object into an address space with the given cache flags. */ 200 + int (*bind_vma)(struct i915_vma *vma, 201 + enum i915_cache_level cache_level, 202 + u32 flags); 203 + /* 204 + * Unmap an object from an address space. This usually consists of 205 + * setting the valid PTE entries to a reserved scratch page. 206 + */ 207 + void (*unbind_vma)(struct i915_vma *vma); 208 + 209 + int (*set_pages)(struct i915_vma *vma); 210 + void (*clear_pages)(struct i915_vma *vma); 211 + }; 212 + 213 + struct pagestash { 214 + spinlock_t lock; 215 + struct pagevec pvec; 216 + }; 217 + 218 + void stash_init(struct pagestash *stash); 219 + 220 + struct i915_address_space { 221 + struct kref ref; 222 + struct rcu_work rcu; 223 + 224 + struct drm_mm mm; 225 + struct intel_gt *gt; 226 + struct drm_i915_private *i915; 227 + struct device *dma; 228 + /* 229 + * Every address space belongs to a struct file - except for the global 230 + * GTT that is owned by the driver (and so @file is set to NULL). In 231 + * principle, no information should leak from one context to another 232 + * (or between files/processes etc) unless explicitly shared by the 233 + * owner. Tracking the owner is important in order to free up per-file 234 + * objects along with the file, to aide resource tracking, and to 235 + * assign blame. 236 + */ 237 + struct drm_i915_file_private *file; 238 + u64 total; /* size addr space maps (ex. 2GB for ggtt) */ 239 + u64 reserved; /* size addr space reserved */ 240 + 241 + unsigned int bind_async_flags; 242 + 243 + /* 244 + * Each active user context has its own address space (in full-ppgtt). 245 + * Since the vm may be shared between multiple contexts, we count how 246 + * many contexts keep us "open". Once open hits zero, we are closed 247 + * and do not allow any new attachments, and proceed to shutdown our 248 + * vma and page directories. 249 + */ 250 + atomic_t open; 251 + 252 + struct mutex mutex; /* protects vma and our lists */ 253 + #define VM_CLASS_GGTT 0 254 + #define VM_CLASS_PPGTT 1 255 + 256 + struct i915_page_scratch scratch[4]; 257 + unsigned int scratch_order; 258 + unsigned int top; 259 + 260 + /** 261 + * List of vma currently bound. 262 + */ 263 + struct list_head bound_list; 264 + 265 + struct pagestash free_pages; 266 + 267 + /* Global GTT */ 268 + bool is_ggtt:1; 269 + 270 + /* Some systems require uncached updates of the page directories */ 271 + bool pt_kmap_wc:1; 272 + 273 + /* Some systems support read-only mappings for GGTT and/or PPGTT */ 274 + bool has_read_only:1; 275 + 276 + u64 (*pte_encode)(dma_addr_t addr, 277 + enum i915_cache_level level, 278 + u32 flags); /* Create a valid PTE */ 279 + #define PTE_READ_ONLY BIT(0) 280 + 281 + int (*allocate_va_range)(struct i915_address_space *vm, 282 + u64 start, u64 length); 283 + void (*clear_range)(struct i915_address_space *vm, 284 + u64 start, u64 length); 285 + void (*insert_page)(struct i915_address_space *vm, 286 + dma_addr_t addr, 287 + u64 offset, 288 + enum i915_cache_level cache_level, 289 + u32 flags); 290 + void (*insert_entries)(struct i915_address_space *vm, 291 + struct i915_vma *vma, 292 + enum i915_cache_level cache_level, 293 + u32 flags); 294 + void (*cleanup)(struct i915_address_space *vm); 295 + 296 + struct i915_vma_ops vma_ops; 297 + 298 + I915_SELFTEST_DECLARE(struct fault_attr fault_attr); 299 + I915_SELFTEST_DECLARE(bool scrub_64K); 300 + }; 301 + 302 + /* 303 + * The Graphics Translation Table is the way in which GEN hardware translates a 304 + * Graphics Virtual Address into a Physical Address. In addition to the normal 305 + * collateral associated with any va->pa translations GEN hardware also has a 306 + * portion of the GTT which can be mapped by the CPU and remain both coherent 307 + * and correct (in cases like swizzling). That region is referred to as GMADR in 308 + * the spec. 309 + */ 310 + struct i915_ggtt { 311 + struct i915_address_space vm; 312 + 313 + struct io_mapping iomap; /* Mapping to our CPU mappable region */ 314 + struct resource gmadr; /* GMADR resource */ 315 + resource_size_t mappable_end; /* End offset that we can CPU map */ 316 + 317 + /** "Graphics Stolen Memory" holds the global PTEs */ 318 + void __iomem *gsm; 319 + void (*invalidate)(struct i915_ggtt *ggtt); 320 + 321 + /** PPGTT used for aliasing the PPGTT with the GTT */ 322 + struct i915_ppgtt *alias; 323 + 324 + bool do_idle_maps; 325 + 326 + int mtrr; 327 + 328 + /** Bit 6 swizzling required for X tiling */ 329 + u32 bit_6_swizzle_x; 330 + /** Bit 6 swizzling required for Y tiling */ 331 + u32 bit_6_swizzle_y; 332 + 333 + u32 pin_bias; 334 + 335 + unsigned int num_fences; 336 + struct i915_fence_reg fence_regs[I915_MAX_NUM_FENCES]; 337 + struct list_head fence_list; 338 + 339 + /** 340 + * List of all objects in gtt_space, currently mmaped by userspace. 341 + * All objects within this list must also be on bound_list. 342 + */ 343 + struct list_head userfault_list; 344 + 345 + /* Manual runtime pm autosuspend delay for user GGTT mmaps */ 346 + struct intel_wakeref_auto userfault_wakeref; 347 + 348 + struct mutex error_mutex; 349 + struct drm_mm_node error_capture; 350 + struct drm_mm_node uc_fw; 351 + }; 352 + 353 + struct i915_ppgtt { 354 + struct i915_address_space vm; 355 + 356 + struct i915_page_directory *pd; 357 + }; 358 + 359 + #define i915_is_ggtt(vm) ((vm)->is_ggtt) 360 + 361 + static inline bool 362 + i915_vm_is_4lvl(const struct i915_address_space *vm) 363 + { 364 + return (vm->total - 1) >> 32; 365 + } 366 + 367 + static inline bool 368 + i915_vm_has_scratch_64K(struct i915_address_space *vm) 369 + { 370 + return vm->scratch_order == get_order(I915_GTT_PAGE_SIZE_64K); 371 + } 372 + 373 + static inline bool 374 + i915_vm_has_cache_coloring(struct i915_address_space *vm) 375 + { 376 + return i915_is_ggtt(vm) && vm->mm.color_adjust; 377 + } 378 + 379 + static inline struct i915_ggtt * 380 + i915_vm_to_ggtt(struct i915_address_space *vm) 381 + { 382 + BUILD_BUG_ON(offsetof(struct i915_ggtt, vm)); 383 + GEM_BUG_ON(!i915_is_ggtt(vm)); 384 + return container_of(vm, struct i915_ggtt, vm); 385 + } 386 + 387 + static inline struct i915_ppgtt * 388 + i915_vm_to_ppgtt(struct i915_address_space *vm) 389 + { 390 + BUILD_BUG_ON(offsetof(struct i915_ppgtt, vm)); 391 + GEM_BUG_ON(i915_is_ggtt(vm)); 392 + return container_of(vm, struct i915_ppgtt, vm); 393 + } 394 + 395 + static inline struct i915_address_space * 396 + i915_vm_get(struct i915_address_space *vm) 397 + { 398 + kref_get(&vm->ref); 399 + return vm; 400 + } 401 + 402 + void i915_vm_release(struct kref *kref); 403 + 404 + static inline void i915_vm_put(struct i915_address_space *vm) 405 + { 406 + kref_put(&vm->ref, i915_vm_release); 407 + } 408 + 409 + static inline struct i915_address_space * 410 + i915_vm_open(struct i915_address_space *vm) 411 + { 412 + GEM_BUG_ON(!atomic_read(&vm->open)); 413 + atomic_inc(&vm->open); 414 + return i915_vm_get(vm); 415 + } 416 + 417 + static inline bool 418 + i915_vm_tryopen(struct i915_address_space *vm) 419 + { 420 + if (atomic_add_unless(&vm->open, 1, 0)) 421 + return i915_vm_get(vm); 422 + 423 + return false; 424 + } 425 + 426 + void __i915_vm_close(struct i915_address_space *vm); 427 + 428 + static inline void 429 + i915_vm_close(struct i915_address_space *vm) 430 + { 431 + GEM_BUG_ON(!atomic_read(&vm->open)); 432 + if (atomic_dec_and_test(&vm->open)) 433 + __i915_vm_close(vm); 434 + 435 + i915_vm_put(vm); 436 + } 437 + 438 + void i915_address_space_init(struct i915_address_space *vm, int subclass); 439 + void i915_address_space_fini(struct i915_address_space *vm); 440 + 441 + static inline u32 i915_pte_index(u64 address, unsigned int pde_shift) 442 + { 443 + const u32 mask = NUM_PTE(pde_shift) - 1; 444 + 445 + return (address >> PAGE_SHIFT) & mask; 446 + } 447 + 448 + /* 449 + * Helper to counts the number of PTEs within the given length. This count 450 + * does not cross a page table boundary, so the max value would be 451 + * GEN6_PTES for GEN6, and GEN8_PTES for GEN8. 452 + */ 453 + static inline u32 i915_pte_count(u64 addr, u64 length, unsigned int pde_shift) 454 + { 455 + const u64 mask = ~((1ULL << pde_shift) - 1); 456 + u64 end; 457 + 458 + GEM_BUG_ON(length == 0); 459 + GEM_BUG_ON(offset_in_page(addr | length)); 460 + 461 + end = addr + length; 462 + 463 + if ((addr & mask) != (end & mask)) 464 + return NUM_PTE(pde_shift) - i915_pte_index(addr, pde_shift); 465 + 466 + return i915_pte_index(end, pde_shift) - i915_pte_index(addr, pde_shift); 467 + } 468 + 469 + static inline u32 i915_pde_index(u64 addr, u32 shift) 470 + { 471 + return (addr >> shift) & I915_PDE_MASK; 472 + } 473 + 474 + static inline struct i915_page_table * 475 + i915_pt_entry(const struct i915_page_directory * const pd, 476 + const unsigned short n) 477 + { 478 + return pd->entry[n]; 479 + } 480 + 481 + static inline struct i915_page_directory * 482 + i915_pd_entry(const struct i915_page_directory * const pdp, 483 + const unsigned short n) 484 + { 485 + return pdp->entry[n]; 486 + } 487 + 488 + static inline dma_addr_t 489 + i915_page_dir_dma_addr(const struct i915_ppgtt *ppgtt, const unsigned int n) 490 + { 491 + struct i915_page_dma *pt = ppgtt->pd->entry[n]; 492 + 493 + return px_dma(pt ?: px_base(&ppgtt->vm.scratch[ppgtt->vm.top])); 494 + } 495 + 496 + void ppgtt_init(struct i915_ppgtt *ppgtt, struct intel_gt *gt); 497 + 498 + int i915_ggtt_probe_hw(struct drm_i915_private *i915); 499 + int i915_ggtt_init_hw(struct drm_i915_private *i915); 500 + int i915_ggtt_enable_hw(struct drm_i915_private *i915); 501 + void i915_ggtt_enable_guc(struct i915_ggtt *ggtt); 502 + void i915_ggtt_disable_guc(struct i915_ggtt *ggtt); 503 + int i915_init_ggtt(struct drm_i915_private *i915); 504 + void i915_ggtt_driver_release(struct drm_i915_private *i915); 505 + 506 + static inline bool i915_ggtt_has_aperture(const struct i915_ggtt *ggtt) 507 + { 508 + return ggtt->mappable_end > 0; 509 + } 510 + 511 + int i915_ppgtt_init_hw(struct intel_gt *gt); 512 + 513 + struct i915_ppgtt *i915_ppgtt_create(struct intel_gt *gt); 514 + 515 + void i915_gem_suspend_gtt_mappings(struct drm_i915_private *i915); 516 + void i915_gem_restore_gtt_mappings(struct drm_i915_private *i915); 517 + 518 + u64 gen8_pte_encode(dma_addr_t addr, 519 + enum i915_cache_level level, 520 + u32 flags); 521 + 522 + int setup_page_dma(struct i915_address_space *vm, struct i915_page_dma *p); 523 + void cleanup_page_dma(struct i915_address_space *vm, struct i915_page_dma *p); 524 + 525 + #define kmap_atomic_px(px) kmap_atomic(px_base(px)->page) 526 + 527 + void 528 + fill_page_dma(const struct i915_page_dma *p, const u64 val, unsigned int count); 529 + 530 + #define fill_px(px, v) fill_page_dma(px_base(px), (v), PAGE_SIZE / sizeof(u64)) 531 + #define fill32_px(px, v) do { \ 532 + u64 v__ = lower_32_bits(v); \ 533 + fill_px((px), v__ << 32 | v__); \ 534 + } while (0) 535 + 536 + int setup_scratch_page(struct i915_address_space *vm, gfp_t gfp); 537 + void cleanup_scratch_page(struct i915_address_space *vm); 538 + void free_scratch(struct i915_address_space *vm); 539 + 540 + struct i915_page_table *alloc_pt(struct i915_address_space *vm); 541 + struct i915_page_directory *alloc_pd(struct i915_address_space *vm); 542 + struct i915_page_directory *__alloc_pd(size_t sz); 543 + 544 + void free_pd(struct i915_address_space *vm, struct i915_page_dma *pd); 545 + 546 + #define free_px(vm, px) free_pd(vm, px_base(px)) 547 + 548 + void 549 + __set_pd_entry(struct i915_page_directory * const pd, 550 + const unsigned short idx, 551 + struct i915_page_dma * const to, 552 + u64 (*encode)(const dma_addr_t, const enum i915_cache_level)); 553 + 554 + #define set_pd_entry(pd, idx, to) \ 555 + __set_pd_entry((pd), (idx), px_base(to), gen8_pde_encode) 556 + 557 + void 558 + clear_pd_entry(struct i915_page_directory * const pd, 559 + const unsigned short idx, 560 + const struct i915_page_scratch * const scratch); 561 + 562 + bool 563 + release_pd_entry(struct i915_page_directory * const pd, 564 + const unsigned short idx, 565 + struct i915_page_table * const pt, 566 + const struct i915_page_scratch * const scratch); 567 + void gen6_ggtt_invalidate(struct i915_ggtt *ggtt); 568 + 569 + int ggtt_set_pages(struct i915_vma *vma); 570 + int ppgtt_set_pages(struct i915_vma *vma); 571 + void clear_pages(struct i915_vma *vma); 572 + 573 + void gtt_write_workarounds(struct intel_gt *gt); 574 + 575 + void setup_private_pat(struct intel_uncore *uncore); 576 + 577 + static inline struct sgt_dma { 578 + struct scatterlist *sg; 579 + dma_addr_t dma, max; 580 + } sgt_dma(struct i915_vma *vma) { 581 + struct scatterlist *sg = vma->pages->sgl; 582 + dma_addr_t addr = sg_dma_address(sg); 583 + 584 + return (struct sgt_dma){ sg, addr, addr + sg->length }; 585 + } 586 + 587 + #endif
+186 -73
drivers/gpu/drm/i915/gt/intel_lrc.c
··· 488 488 return desc; 489 489 } 490 490 491 - static u32 *set_offsets(u32 *regs, 491 + static inline unsigned int dword_in_page(void *addr) 492 + { 493 + return offset_in_page(addr) / sizeof(u32); 494 + } 495 + 496 + static void set_offsets(u32 *regs, 492 497 const u8 *data, 493 - const struct intel_engine_cs *engine) 498 + const struct intel_engine_cs *engine, 499 + bool clear) 494 500 #define NOP(x) (BIT(7) | (x)) 495 - #define LRI(count, flags) ((flags) << 6 | (count)) 501 + #define LRI(count, flags) ((flags) << 6 | (count) | BUILD_BUG_ON_ZERO(count >= BIT(6))) 496 502 #define POSTED BIT(0) 497 503 #define REG(x) (((x) >> 2) | BUILD_BUG_ON_ZERO(x >= 0x200)) 498 504 #define REG16(x) \ 499 505 (((x) >> 9) | BIT(7) | BUILD_BUG_ON_ZERO(x >= 0x10000)), \ 500 506 (((x) >> 2) & 0x7f) 501 - #define END() 0 507 + #define END(x) 0, (x) 502 508 { 503 509 const u32 base = engine->mmio_base; 504 510 ··· 512 506 u8 count, flags; 513 507 514 508 if (*data & BIT(7)) { /* skip */ 515 - regs += *data++ & ~BIT(7); 509 + count = *data++ & ~BIT(7); 510 + if (clear) 511 + memset32(regs, MI_NOOP, count); 512 + regs += count; 516 513 continue; 517 514 } 518 515 ··· 541 532 offset |= v & ~BIT(7); 542 533 } while (v & BIT(7)); 543 534 544 - *regs = base + (offset << 2); 535 + regs[0] = base + (offset << 2); 536 + if (clear) 537 + regs[1] = 0; 545 538 regs += 2; 546 539 } while (--count); 547 540 } 548 541 549 - return regs; 542 + if (clear) { 543 + u8 count = *++data; 544 + 545 + /* Clear past the tail for HW access */ 546 + GEM_BUG_ON(dword_in_page(regs) > count); 547 + memset32(regs, MI_NOOP, count - dword_in_page(regs)); 548 + 549 + /* Close the batch; used mainly by live_lrc_layout() */ 550 + *regs = MI_BATCH_BUFFER_END; 551 + if (INTEL_GEN(engine->i915) >= 10) 552 + *regs |= BIT(0); 553 + } 550 554 } 551 555 552 556 static const u8 gen8_xcs_offsets[] = { ··· 594 572 REG16(0x200), 595 573 REG(0x028), 596 574 597 - END(), 575 + END(80) 598 576 }; 599 577 600 578 static const u8 gen9_xcs_offsets[] = { ··· 678 656 REG16(0x67c), 679 657 REG(0x068), 680 658 681 - END(), 659 + END(176) 682 660 }; 683 661 684 662 static const u8 gen12_xcs_offsets[] = { ··· 710 688 REG16(0x274), 711 689 REG16(0x270), 712 690 713 - END(), 691 + END(80) 714 692 }; 715 693 716 694 static const u8 gen8_rcs_offsets[] = { ··· 747 725 LRI(1, 0), 748 726 REG(0x0c8), 749 727 750 - END(), 728 + END(80) 729 + }; 730 + 731 + static const u8 gen9_rcs_offsets[] = { 732 + NOP(1), 733 + LRI(14, POSTED), 734 + REG16(0x244), 735 + REG(0x34), 736 + REG(0x30), 737 + REG(0x38), 738 + REG(0x3c), 739 + REG(0x168), 740 + REG(0x140), 741 + REG(0x110), 742 + REG(0x11c), 743 + REG(0x114), 744 + REG(0x118), 745 + REG(0x1c0), 746 + REG(0x1c4), 747 + REG(0x1c8), 748 + 749 + NOP(3), 750 + LRI(9, POSTED), 751 + REG16(0x3a8), 752 + REG16(0x28c), 753 + REG16(0x288), 754 + REG16(0x284), 755 + REG16(0x280), 756 + REG16(0x27c), 757 + REG16(0x278), 758 + REG16(0x274), 759 + REG16(0x270), 760 + 761 + NOP(13), 762 + LRI(1, 0), 763 + REG(0xc8), 764 + 765 + NOP(13), 766 + LRI(44, POSTED), 767 + REG(0x28), 768 + REG(0x9c), 769 + REG(0xc0), 770 + REG(0x178), 771 + REG(0x17c), 772 + REG16(0x358), 773 + REG(0x170), 774 + REG(0x150), 775 + REG(0x154), 776 + REG(0x158), 777 + REG16(0x41c), 778 + REG16(0x600), 779 + REG16(0x604), 780 + REG16(0x608), 781 + REG16(0x60c), 782 + REG16(0x610), 783 + REG16(0x614), 784 + REG16(0x618), 785 + REG16(0x61c), 786 + REG16(0x620), 787 + REG16(0x624), 788 + REG16(0x628), 789 + REG16(0x62c), 790 + REG16(0x630), 791 + REG16(0x634), 792 + REG16(0x638), 793 + REG16(0x63c), 794 + REG16(0x640), 795 + REG16(0x644), 796 + REG16(0x648), 797 + REG16(0x64c), 798 + REG16(0x650), 799 + REG16(0x654), 800 + REG16(0x658), 801 + REG16(0x65c), 802 + REG16(0x660), 803 + REG16(0x664), 804 + REG16(0x668), 805 + REG16(0x66c), 806 + REG16(0x670), 807 + REG16(0x674), 808 + REG16(0x678), 809 + REG16(0x67c), 810 + REG(0x68), 811 + 812 + END(176) 751 813 }; 752 814 753 815 static const u8 gen11_rcs_offsets[] = { ··· 872 766 LRI(1, 0), 873 767 REG(0x0c8), 874 768 875 - END(), 769 + END(80) 876 770 }; 877 771 878 772 static const u8 gen12_rcs_offsets[] = { ··· 913 807 LRI(1, 0), 914 808 REG(0x0c8), 915 809 916 - END(), 810 + END(80) 917 811 }; 918 812 919 813 #undef END ··· 938 832 return gen12_rcs_offsets; 939 833 else if (INTEL_GEN(engine->i915) >= 11) 940 834 return gen11_rcs_offsets; 835 + else if (INTEL_GEN(engine->i915) >= 9) 836 + return gen9_rcs_offsets; 941 837 else 942 838 return gen8_rcs_offsets; 943 839 } else { ··· 1216 1108 /* We don't need a strict matching tag, just different values */ 1217 1109 ce->lrc_desc &= ~GENMASK_ULL(47, 37); 1218 1110 ce->lrc_desc |= 1219 - (u64)(engine->context_tag++ % NUM_CONTEXT_TAG) << 1111 + (u64)(++engine->context_tag % NUM_CONTEXT_TAG) << 1220 1112 GEN11_SW_CTX_ID_SHIFT; 1221 1113 BUILD_BUG_ON(NUM_CONTEXT_TAG > GEN12_MAX_CONTEXT_HW_ID); 1222 1114 } ··· 1350 1242 * before its image is complete leading to invalid PD chasing. 1351 1243 */ 1352 1244 wmb(); 1353 - 1354 - /* Wa_1607138340:tgl */ 1355 - if (IS_TGL_REVID(rq->i915, TGL_REVID_A0, TGL_REVID_A0)) 1356 - desc |= CTX_DESC_FORCE_RESTORE; 1357 1245 1358 1246 ce->lrc_desc &= ~CTX_DESC_FORCE_RESTORE; 1359 1247 return desc; ··· 1534 1430 if (i915_request_completed(next)) 1535 1431 return true; 1536 1432 1537 - if (unlikely((prev->flags ^ next->flags) & 1538 - (I915_REQUEST_NOPREEMPT | I915_REQUEST_SENTINEL))) 1433 + if (unlikely((prev->fence.flags ^ next->fence.flags) & 1434 + (I915_FENCE_FLAG_NOPREEMPT | I915_FENCE_FLAG_SENTINEL))) 1539 1435 return false; 1540 1436 1541 1437 if (!can_merge_ctx(prev->context, next->context)) ··· 1547 1443 static void virtual_update_register_offsets(u32 *regs, 1548 1444 struct intel_engine_cs *engine) 1549 1445 { 1550 - set_offsets(regs, reg_offsets(engine), engine); 1446 + set_offsets(regs, reg_offsets(engine), engine, false); 1551 1447 } 1552 1448 1553 1449 static bool virtual_matches(const struct virtual_engine *ve, ··· 1694 1590 { 1695 1591 const struct i915_request *rq = *engine->execlists.active; 1696 1592 1697 - if (i915_request_completed(rq)) 1593 + if (!rq || i915_request_completed(rq)) 1698 1594 return 0; 1699 1595 1700 1596 if (engine->execlists.switch_priority_hint < effective_prio(rq)) ··· 1738 1634 1739 1635 set_timer_ms(&engine->execlists.preempt, 1740 1636 active_preempt_timeout(engine)); 1637 + } 1638 + 1639 + static inline void clear_ports(struct i915_request **ports, int count) 1640 + { 1641 + memset_p((void **)ports, NULL, count); 1741 1642 } 1742 1643 1743 1644 static void execlists_dequeue(struct intel_engine_cs *engine) ··· 2105 1996 2106 1997 goto skip_submit; 2107 1998 } 1999 + clear_ports(port + 1, last_port - port); 2108 2000 2109 - memset(port + 1, 0, (last_port - port) * sizeof(*port)); 2110 2001 execlists_submit_ports(engine); 2111 - 2112 2002 set_preempt_timeout(engine); 2113 2003 } else { 2114 2004 skip_submit: ··· 2122 2014 2123 2015 for (port = execlists->pending; *port; port++) 2124 2016 execlists_schedule_out(*port); 2125 - memset(execlists->pending, 0, sizeof(execlists->pending)); 2017 + clear_ports(execlists->pending, ARRAY_SIZE(execlists->pending)); 2126 2018 2127 2019 /* Mark the end of active before we overwrite *active */ 2128 2020 for (port = xchg(&execlists->active, execlists->pending); *port; port++) 2129 2021 execlists_schedule_out(*port); 2130 - WRITE_ONCE(execlists->active, 2131 - memset(execlists->inflight, 0, sizeof(execlists->inflight))); 2022 + clear_ports(execlists->inflight, ARRAY_SIZE(execlists->inflight)); 2023 + 2024 + WRITE_ONCE(execlists->active, execlists->inflight); 2132 2025 } 2133 2026 2134 2027 static inline void ··· 2285 2176 2286 2177 /* Point active to the new ELSP; prevent overwriting */ 2287 2178 WRITE_ONCE(execlists->active, execlists->pending); 2288 - set_timeslice(engine); 2289 2179 2290 2180 if (!inject_preempt_hang(execlists)) 2291 2181 ring_set_paused(engine, 0); ··· 2325 2217 } while (head != tail); 2326 2218 2327 2219 execlists->csb_head = head; 2220 + set_timeslice(engine); 2328 2221 2329 2222 /* 2330 2223 * Gen11 has proven to fail wrt global observation point between ··· 2508 2399 2509 2400 vaddr += engine->context_size; 2510 2401 2511 - memset(vaddr, POISON_INUSE, I915_GTT_PAGE_SIZE); 2402 + memset(vaddr, CONTEXT_REDZONE, I915_GTT_PAGE_SIZE); 2512 2403 } 2513 2404 2514 2405 static void ··· 2519 2410 2520 2411 vaddr += engine->context_size; 2521 2412 2522 - if (memchr_inv(vaddr, POISON_INUSE, I915_GTT_PAGE_SIZE)) 2413 + if (memchr_inv(vaddr, CONTEXT_REDZONE, I915_GTT_PAGE_SIZE)) 2523 2414 dev_err_once(engine->i915->drm.dev, 2524 2415 "%s context redzone overwritten!\n", 2525 2416 engine->name); ··· 2562 2453 struct intel_engine_cs *engine) 2563 2454 { 2564 2455 void *vaddr; 2565 - int ret; 2566 2456 2567 2457 GEM_BUG_ON(!ce->state); 2568 - 2569 - ret = intel_context_active_acquire(ce); 2570 - if (ret) 2571 - goto err; 2572 2458 GEM_BUG_ON(!i915_vma_is_pinned(ce->state)); 2573 2459 2574 2460 vaddr = i915_gem_object_pin_map(ce->state->obj, 2575 2461 i915_coherent_map_type(engine->i915) | 2576 2462 I915_MAP_OVERRIDE); 2577 - if (IS_ERR(vaddr)) { 2578 - ret = PTR_ERR(vaddr); 2579 - goto unpin_active; 2580 - } 2463 + if (IS_ERR(vaddr)) 2464 + return PTR_ERR(vaddr); 2581 2465 2582 - ce->lrc_desc = lrc_descriptor(ce, engine); 2466 + ce->lrc_desc = lrc_descriptor(ce, engine) | CTX_DESC_FORCE_RESTORE; 2583 2467 ce->lrc_reg_state = vaddr + LRC_STATE_PN * PAGE_SIZE; 2584 2468 __execlists_update_reg_state(ce, engine); 2585 2469 2586 2470 return 0; 2587 - 2588 - unpin_active: 2589 - intel_context_active_release(ce); 2590 - err: 2591 - return ret; 2592 2471 } 2593 2472 2594 2473 static int execlists_context_pin(struct intel_context *ce) ··· 2591 2494 2592 2495 static void execlists_context_reset(struct intel_context *ce) 2593 2496 { 2497 + CE_TRACE(ce, "reset\n"); 2498 + GEM_BUG_ON(!intel_context_is_pinned(ce)); 2499 + 2594 2500 /* 2595 2501 * Because we emit WA_TAIL_DWORDS there may be a disparity 2596 2502 * between our bookkeeping in ce->ring->head and ce->ring->tail and ··· 2610 2510 * So to avoid that we reset the context images upon resume. For 2611 2511 * simplicity, we just zero everything out. 2612 2512 */ 2613 - intel_ring_reset(ce->ring, 0); 2513 + intel_ring_reset(ce->ring, ce->ring->emit); 2514 + 2515 + /* Scrub away the garbage */ 2516 + execlists_init_reg_state(ce->lrc_reg_state, 2517 + ce, ce->engine, ce->ring, true); 2614 2518 __execlists_update_reg_state(ce, ce->engine); 2519 + 2520 + ce->lrc_desc |= CTX_DESC_FORCE_RESTORE; 2615 2521 } 2616 2522 2617 2523 static const struct intel_context_ops execlists_context_ops = { ··· 3031 2925 RING_HWS_PGA, 3032 2926 i915_ggtt_offset(engine->status_page.vma)); 3033 2927 ENGINE_POSTING_READ(engine, RING_HWS_PGA); 2928 + 2929 + engine->context_tag = 0; 3034 2930 } 3035 2931 3036 2932 static bool unexpected_starting_state(struct intel_engine_cs *engine) ··· 3138 3030 &execlists->csb_status[reset_value]); 3139 3031 } 3140 3032 3141 - static void __execlists_reset_reg_state(const struct intel_context *ce, 3142 - const struct intel_engine_cs *engine) 3033 + static void __reset_stop_ring(u32 *regs, const struct intel_engine_cs *engine) 3143 3034 { 3144 - u32 *regs = ce->lrc_reg_state; 3145 3035 int x; 3146 3036 3147 3037 x = lrc_ring_mi_mode(engine); ··· 3147 3041 regs[x + 1] &= ~STOP_RING; 3148 3042 regs[x + 1] |= STOP_RING << 16; 3149 3043 } 3044 + } 3045 + 3046 + static void __execlists_reset_reg_state(const struct intel_context *ce, 3047 + const struct intel_engine_cs *engine) 3048 + { 3049 + u32 *regs = ce->lrc_reg_state; 3050 + 3051 + __reset_stop_ring(regs, engine); 3150 3052 } 3151 3053 3152 3054 static void __execlists_reset(struct intel_engine_cs *engine, bool stalled) ··· 3909 3795 { 3910 3796 /* Default vfuncs which can be overriden by each engine. */ 3911 3797 3912 - engine->release = execlists_release; 3913 3798 engine->resume = execlists_resume; 3914 3799 3915 3800 engine->cops = &execlists_context_ops; ··· 4023 3910 4024 3911 reset_csb_pointers(engine); 4025 3912 3913 + /* Finally, take ownership and responsibility for cleanup! */ 3914 + engine->release = execlists_release; 3915 + 4026 3916 return 0; 4027 3917 } 4028 3918 ··· 4065 3949 4066 3950 static void init_common_reg_state(u32 * const regs, 4067 3951 const struct intel_engine_cs *engine, 4068 - const struct intel_ring *ring) 3952 + const struct intel_ring *ring, 3953 + bool inhibit) 4069 3954 { 4070 - regs[CTX_CONTEXT_CONTROL] = 4071 - _MASKED_BIT_DISABLE(CTX_CTRL_ENGINE_CTX_RESTORE_INHIBIT) | 4072 - _MASKED_BIT_ENABLE(CTX_CTRL_INHIBIT_SYN_CTX_SWITCH); 3955 + u32 ctl; 3956 + 3957 + ctl = _MASKED_BIT_ENABLE(CTX_CTRL_INHIBIT_SYN_CTX_SWITCH); 3958 + ctl |= _MASKED_BIT_DISABLE(CTX_CTRL_ENGINE_CTX_RESTORE_INHIBIT); 3959 + if (inhibit) 3960 + ctl |= CTX_CTRL_ENGINE_CTX_RESTORE_INHIBIT; 4073 3961 if (INTEL_GEN(engine->i915) < 11) 4074 - regs[CTX_CONTEXT_CONTROL] |= 4075 - _MASKED_BIT_DISABLE(CTX_CTRL_ENGINE_CTX_SAVE_INHIBIT | 4076 - CTX_CTRL_RS_CTX_ENABLE); 3962 + ctl |= _MASKED_BIT_DISABLE(CTX_CTRL_ENGINE_CTX_SAVE_INHIBIT | 3963 + CTX_CTRL_RS_CTX_ENABLE); 3964 + regs[CTX_CONTEXT_CONTROL] = ctl; 4077 3965 4078 3966 regs[CTX_RING_CTL] = RING_CTL_SIZE(ring->size) | RING_VALID; 4079 - regs[CTX_BB_STATE] = RING_BB_PPGTT; 4080 3967 } 4081 3968 4082 3969 static void init_wa_bb_reg_state(u32 * const regs, ··· 4135 4016 const struct intel_context *ce, 4136 4017 const struct intel_engine_cs *engine, 4137 4018 const struct intel_ring *ring, 4138 - bool close) 4019 + bool inhibit) 4139 4020 { 4140 4021 /* 4141 4022 * A context is actually a big batch buffer with several ··· 4147 4028 * 4148 4029 * Must keep consistent with virtual_update_register_offsets(). 4149 4030 */ 4150 - u32 *bbe = set_offsets(regs, reg_offsets(engine), engine); 4031 + set_offsets(regs, reg_offsets(engine), engine, inhibit); 4151 4032 4152 - if (close) { /* Close the batch; used mainly by live_lrc_layout() */ 4153 - *bbe = MI_BATCH_BUFFER_END; 4154 - if (INTEL_GEN(engine->i915) >= 10) 4155 - *bbe |= BIT(0); 4156 - } 4157 - 4158 - init_common_reg_state(regs, engine, ring); 4033 + init_common_reg_state(regs, engine, ring, inhibit); 4159 4034 init_ppgtt_reg_state(regs, vm_alias(ce->vm)); 4160 4035 4161 4036 init_wa_bb_reg_state(regs, engine, 4162 4037 INTEL_GEN(engine->i915) >= 12 ? 4163 4038 GEN12_CTX_BB_PER_CTX_PTR : 4164 4039 CTX_BB_PER_CTX_PTR); 4040 + 4041 + __reset_stop_ring(regs, engine); 4165 4042 } 4166 4043 4167 4044 static int ··· 4168 4053 { 4169 4054 bool inhibit = true; 4170 4055 void *vaddr; 4171 - u32 *regs; 4172 4056 int ret; 4173 4057 4174 4058 vaddr = i915_gem_object_pin_map(ctx_obj, I915_MAP_WB); ··· 4197 4083 4198 4084 /* The second page of the context object contains some fields which must 4199 4085 * be set up prior to the first execution. */ 4200 - regs = vaddr + LRC_STATE_PN * PAGE_SIZE; 4201 - execlists_init_reg_state(regs, ce, engine, ring, inhibit); 4202 - if (inhibit) 4203 - regs[CTX_CONTEXT_CONTROL] |= 4204 - _MASKED_BIT_ENABLE(CTX_CTRL_ENGINE_CTX_RESTORE_INHIBIT); 4086 + execlists_init_reg_state(vaddr + LRC_STATE_PN * PAGE_SIZE, 4087 + ce, engine, ring, inhibit); 4205 4088 4206 4089 ret = 0; 4207 4090 err_unpin_ctx: ··· 4592 4481 ve->base.gt = siblings[0]->gt; 4593 4482 ve->base.uncore = siblings[0]->uncore; 4594 4483 ve->base.id = -1; 4484 + 4595 4485 ve->base.class = OTHER_CLASS; 4596 4486 ve->base.uabi_class = I915_ENGINE_CLASS_INVALID; 4597 4487 ve->base.instance = I915_ENGINE_CLASS_INVALID_VIRTUAL; 4488 + ve->base.uabi_instance = I915_ENGINE_CLASS_INVALID_VIRTUAL; 4598 4489 4599 4490 /* 4600 4491 * The decision on whether to submit a request using semaphores
+9 -9
drivers/gpu/drm/i915/gt/intel_mocs.c
··· 127 127 LE_0_PAGETABLE | LE_TC_2_LLC_ELLC | LE_LRUM(3), \ 128 128 L3_3_WB) 129 129 130 - static const struct drm_i915_mocs_entry skylake_mocs_table[] = { 130 + static const struct drm_i915_mocs_entry skl_mocs_table[] = { 131 131 GEN9_MOCS_ENTRIES, 132 132 MOCS_ENTRY(I915_MOCS_CACHED, 133 133 LE_3_WB | LE_TC_2_LLC_ELLC | LE_LRUM(3), ··· 233 233 LE_3_WB | LE_TC_1_LLC | LE_LRUM(3), \ 234 234 L3_1_UC) 235 235 236 - static const struct drm_i915_mocs_entry tigerlake_mocs_table[] = { 236 + static const struct drm_i915_mocs_entry tgl_mocs_table[] = { 237 237 /* Base - Error (Reserved for Non-Use) */ 238 238 MOCS_ENTRY(0, 0x0, 0x0), 239 239 /* Base - Reserved */ ··· 267 267 L3_3_WB), 268 268 }; 269 269 270 - static const struct drm_i915_mocs_entry icelake_mocs_table[] = { 270 + static const struct drm_i915_mocs_entry icl_mocs_table[] = { 271 271 /* Base - Uncached (Deprecated) */ 272 272 MOCS_ENTRY(I915_MOCS_UNCACHED, 273 273 LE_1_UC | LE_TC_1_LLC, ··· 284 284 struct drm_i915_mocs_table *table) 285 285 { 286 286 if (INTEL_GEN(i915) >= 12) { 287 - table->size = ARRAY_SIZE(tigerlake_mocs_table); 288 - table->table = tigerlake_mocs_table; 287 + table->size = ARRAY_SIZE(tgl_mocs_table); 288 + table->table = tgl_mocs_table; 289 289 table->n_entries = GEN11_NUM_MOCS_ENTRIES; 290 290 } else if (IS_GEN(i915, 11)) { 291 - table->size = ARRAY_SIZE(icelake_mocs_table); 292 - table->table = icelake_mocs_table; 291 + table->size = ARRAY_SIZE(icl_mocs_table); 292 + table->table = icl_mocs_table; 293 293 table->n_entries = GEN11_NUM_MOCS_ENTRIES; 294 294 } else if (IS_GEN9_BC(i915) || IS_CANNONLAKE(i915)) { 295 - table->size = ARRAY_SIZE(skylake_mocs_table); 295 + table->size = ARRAY_SIZE(skl_mocs_table); 296 296 table->n_entries = GEN9_NUM_MOCS_ENTRIES; 297 - table->table = skylake_mocs_table; 297 + table->table = skl_mocs_table; 298 298 } else if (IS_GEN9_LP(i915)) { 299 299 table->size = ARRAY_SIZE(broxton_mocs_table); 300 300 table->n_entries = GEN9_NUM_MOCS_ENTRIES;
+218
drivers/gpu/drm/i915/gt/intel_ppgtt.c
··· 1 + // SPDX-License-Identifier: MIT 2 + /* 3 + * Copyright © 2020 Intel Corporation 4 + */ 5 + 6 + #include <linux/slab.h> 7 + 8 + #include "i915_trace.h" 9 + #include "intel_gtt.h" 10 + #include "gen6_ppgtt.h" 11 + #include "gen8_ppgtt.h" 12 + 13 + struct i915_page_table *alloc_pt(struct i915_address_space *vm) 14 + { 15 + struct i915_page_table *pt; 16 + 17 + pt = kmalloc(sizeof(*pt), I915_GFP_ALLOW_FAIL); 18 + if (unlikely(!pt)) 19 + return ERR_PTR(-ENOMEM); 20 + 21 + if (unlikely(setup_page_dma(vm, &pt->base))) { 22 + kfree(pt); 23 + return ERR_PTR(-ENOMEM); 24 + } 25 + 26 + atomic_set(&pt->used, 0); 27 + return pt; 28 + } 29 + 30 + struct i915_page_directory *__alloc_pd(size_t sz) 31 + { 32 + struct i915_page_directory *pd; 33 + 34 + pd = kzalloc(sz, I915_GFP_ALLOW_FAIL); 35 + if (unlikely(!pd)) 36 + return NULL; 37 + 38 + spin_lock_init(&pd->lock); 39 + return pd; 40 + } 41 + 42 + struct i915_page_directory *alloc_pd(struct i915_address_space *vm) 43 + { 44 + struct i915_page_directory *pd; 45 + 46 + pd = __alloc_pd(sizeof(*pd)); 47 + if (unlikely(!pd)) 48 + return ERR_PTR(-ENOMEM); 49 + 50 + if (unlikely(setup_page_dma(vm, px_base(pd)))) { 51 + kfree(pd); 52 + return ERR_PTR(-ENOMEM); 53 + } 54 + 55 + return pd; 56 + } 57 + 58 + void free_pd(struct i915_address_space *vm, struct i915_page_dma *pd) 59 + { 60 + cleanup_page_dma(vm, pd); 61 + kfree(pd); 62 + } 63 + 64 + static inline void 65 + write_dma_entry(struct i915_page_dma * const pdma, 66 + const unsigned short idx, 67 + const u64 encoded_entry) 68 + { 69 + u64 * const vaddr = kmap_atomic(pdma->page); 70 + 71 + vaddr[idx] = encoded_entry; 72 + kunmap_atomic(vaddr); 73 + } 74 + 75 + void 76 + __set_pd_entry(struct i915_page_directory * const pd, 77 + const unsigned short idx, 78 + struct i915_page_dma * const to, 79 + u64 (*encode)(const dma_addr_t, const enum i915_cache_level)) 80 + { 81 + /* Each thread pre-pins the pd, and we may have a thread per pde. */ 82 + GEM_BUG_ON(atomic_read(px_used(pd)) > NALLOC * ARRAY_SIZE(pd->entry)); 83 + 84 + atomic_inc(px_used(pd)); 85 + pd->entry[idx] = to; 86 + write_dma_entry(px_base(pd), idx, encode(to->daddr, I915_CACHE_LLC)); 87 + } 88 + 89 + void 90 + clear_pd_entry(struct i915_page_directory * const pd, 91 + const unsigned short idx, 92 + const struct i915_page_scratch * const scratch) 93 + { 94 + GEM_BUG_ON(atomic_read(px_used(pd)) == 0); 95 + 96 + write_dma_entry(px_base(pd), idx, scratch->encode); 97 + pd->entry[idx] = NULL; 98 + atomic_dec(px_used(pd)); 99 + } 100 + 101 + bool 102 + release_pd_entry(struct i915_page_directory * const pd, 103 + const unsigned short idx, 104 + struct i915_page_table * const pt, 105 + const struct i915_page_scratch * const scratch) 106 + { 107 + bool free = false; 108 + 109 + if (atomic_add_unless(&pt->used, -1, 1)) 110 + return false; 111 + 112 + spin_lock(&pd->lock); 113 + if (atomic_dec_and_test(&pt->used)) { 114 + clear_pd_entry(pd, idx, scratch); 115 + free = true; 116 + } 117 + spin_unlock(&pd->lock); 118 + 119 + return free; 120 + } 121 + 122 + int i915_ppgtt_init_hw(struct intel_gt *gt) 123 + { 124 + struct drm_i915_private *i915 = gt->i915; 125 + 126 + gtt_write_workarounds(gt); 127 + 128 + if (IS_GEN(i915, 6)) 129 + gen6_ppgtt_enable(gt); 130 + else if (IS_GEN(i915, 7)) 131 + gen7_ppgtt_enable(gt); 132 + 133 + return 0; 134 + } 135 + 136 + static struct i915_ppgtt * 137 + __ppgtt_create(struct intel_gt *gt) 138 + { 139 + if (INTEL_GEN(gt->i915) < 8) 140 + return gen6_ppgtt_create(gt); 141 + else 142 + return gen8_ppgtt_create(gt); 143 + } 144 + 145 + struct i915_ppgtt *i915_ppgtt_create(struct intel_gt *gt) 146 + { 147 + struct i915_ppgtt *ppgtt; 148 + 149 + ppgtt = __ppgtt_create(gt); 150 + if (IS_ERR(ppgtt)) 151 + return ppgtt; 152 + 153 + trace_i915_ppgtt_create(&ppgtt->vm); 154 + 155 + return ppgtt; 156 + } 157 + 158 + static int ppgtt_bind_vma(struct i915_vma *vma, 159 + enum i915_cache_level cache_level, 160 + u32 flags) 161 + { 162 + u32 pte_flags; 163 + int err; 164 + 165 + if (flags & I915_VMA_ALLOC) { 166 + err = vma->vm->allocate_va_range(vma->vm, 167 + vma->node.start, vma->size); 168 + if (err) 169 + return err; 170 + 171 + set_bit(I915_VMA_ALLOC_BIT, __i915_vma_flags(vma)); 172 + } 173 + 174 + /* Applicable to VLV, and gen8+ */ 175 + pte_flags = 0; 176 + if (i915_gem_object_is_readonly(vma->obj)) 177 + pte_flags |= PTE_READ_ONLY; 178 + 179 + GEM_BUG_ON(!test_bit(I915_VMA_ALLOC_BIT, __i915_vma_flags(vma))); 180 + vma->vm->insert_entries(vma->vm, vma, cache_level, pte_flags); 181 + wmb(); 182 + 183 + return 0; 184 + } 185 + 186 + static void ppgtt_unbind_vma(struct i915_vma *vma) 187 + { 188 + if (test_and_clear_bit(I915_VMA_ALLOC_BIT, __i915_vma_flags(vma))) 189 + vma->vm->clear_range(vma->vm, vma->node.start, vma->size); 190 + } 191 + 192 + int ppgtt_set_pages(struct i915_vma *vma) 193 + { 194 + GEM_BUG_ON(vma->pages); 195 + 196 + vma->pages = vma->obj->mm.pages; 197 + 198 + vma->page_sizes = vma->obj->mm.page_sizes; 199 + 200 + return 0; 201 + } 202 + 203 + void ppgtt_init(struct i915_ppgtt *ppgtt, struct intel_gt *gt) 204 + { 205 + struct drm_i915_private *i915 = gt->i915; 206 + 207 + ppgtt->vm.gt = gt; 208 + ppgtt->vm.i915 = i915; 209 + ppgtt->vm.dma = &i915->drm.pdev->dev; 210 + ppgtt->vm.total = BIT_ULL(INTEL_INFO(i915)->ppgtt_size); 211 + 212 + i915_address_space_init(&ppgtt->vm, VM_CLASS_PPGTT); 213 + 214 + ppgtt->vm.vma_ops.bind_vma = ppgtt_bind_vma; 215 + ppgtt->vm.vma_ops.unbind_vma = ppgtt_unbind_vma; 216 + ppgtt->vm.vma_ops.set_pages = ppgtt_set_pages; 217 + ppgtt->vm.vma_ops.clear_pages = clear_pages; 218 + }
+17 -20
drivers/gpu/drm/i915/gt/intel_reset.c
··· 147 147 148 148 void __i915_request_reset(struct i915_request *rq, bool guilty) 149 149 { 150 - GEM_TRACE("%s rq=%llx:%lld, guilty? %s\n", 151 - rq->engine->name, 152 - rq->fence.context, 153 - rq->fence.seqno, 154 - yesno(guilty)); 150 + RQ_TRACE(rq, "guilty? %s\n", yesno(guilty)); 155 151 156 152 GEM_BUG_ON(i915_request_completed(rq)); 157 153 ··· 247 251 return ret; 248 252 } 249 253 250 - static int ironlake_do_reset(struct intel_gt *gt, 251 - intel_engine_mask_t engine_mask, 252 - unsigned int retry) 254 + static int ilk_do_reset(struct intel_gt *gt, intel_engine_mask_t engine_mask, 255 + unsigned int retry) 253 256 { 254 257 struct intel_uncore *uncore = gt->uncore; 255 258 int ret; ··· 592 597 else if (INTEL_GEN(i915) >= 6) 593 598 return gen6_reset_engines; 594 599 else if (INTEL_GEN(i915) >= 5) 595 - return ironlake_do_reset; 600 + return ilk_do_reset; 596 601 else if (IS_G4X(i915)) 597 602 return g4x_do_reset; 598 603 else if (IS_G33(i915) || IS_PINEVIEW(i915)) ··· 620 625 */ 621 626 intel_uncore_forcewake_get(gt->uncore, FORCEWAKE_ALL); 622 627 for (retry = 0; ret == -ETIMEDOUT && retry < retries; retry++) { 623 - GEM_TRACE("engine_mask=%x\n", engine_mask); 628 + GT_TRACE(gt, "engine_mask=%x\n", engine_mask); 624 629 preempt_disable(); 625 630 ret = reset(gt, engine_mask, retry); 626 631 preempt_enable(); ··· 780 785 struct intel_engine_cs *engine = request->engine; 781 786 unsigned long flags; 782 787 783 - GEM_TRACE("%s fence %llx:%lld -> -EIO\n", 784 - engine->name, request->fence.context, request->fence.seqno); 788 + RQ_TRACE(request, "-EIO\n"); 785 789 dma_fence_set_error(&request->fence, -EIO); 786 790 787 791 spin_lock_irqsave(&engine->active.lock, flags); ··· 807 813 intel_engine_dump(engine, &p, "%s\n", engine->name); 808 814 } 809 815 810 - GEM_TRACE("start\n"); 816 + GT_TRACE(gt, "start\n"); 811 817 812 818 /* 813 819 * First, stop submission to hw, but do not yet complete requests by ··· 838 844 839 845 reset_finish(gt, awake); 840 846 841 - GEM_TRACE("end\n"); 847 + GT_TRACE(gt, "end\n"); 842 848 } 843 849 844 850 void intel_gt_set_wedged(struct intel_gt *gt) ··· 864 870 if (test_bit(I915_WEDGED_ON_INIT, &gt->reset.flags)) 865 871 return false; 866 872 867 - GEM_TRACE("start\n"); 873 + GT_TRACE(gt, "start\n"); 868 874 869 875 /* 870 876 * Before unwedging, make sure that all pending operations ··· 926 932 */ 927 933 intel_engines_reset_default_submission(gt); 928 934 929 - GEM_TRACE("end\n"); 935 + GT_TRACE(gt, "end\n"); 930 936 931 937 smp_mb__before_atomic(); /* complete takeover before enabling execbuf */ 932 938 clear_bit(I915_WEDGED, &gt->reset.flags); ··· 1001 1007 intel_engine_mask_t awake; 1002 1008 int ret; 1003 1009 1004 - GEM_TRACE("flags=%lx\n", gt->reset.flags); 1010 + GT_TRACE(gt, "flags=%lx\n", gt->reset.flags); 1005 1011 1006 1012 might_sleep(); 1007 1013 GEM_BUG_ON(!test_bit(I915_RESET_BACKOFF, &gt->reset.flags)); ··· 1230 1236 engine_mask &= INTEL_INFO(gt->i915)->engine_mask; 1231 1237 1232 1238 if (flags & I915_ERROR_CAPTURE) { 1233 - i915_capture_error_state(gt->i915, engine_mask, msg); 1239 + i915_capture_error_state(gt->i915); 1234 1240 intel_gt_clear_error_registers(gt, engine_mask); 1235 1241 } 1236 1242 ··· 1323 1329 if (!intel_gt_is_wedged(gt)) 1324 1330 return 0; 1325 1331 1326 - /* Reset still in progress? Maybe we will recover? */ 1327 - if (!test_bit(I915_RESET_BACKOFF, &gt->reset.flags)) 1332 + if (intel_gt_has_init_error(gt)) 1328 1333 return -EIO; 1329 1334 1335 + /* Reset still in progress? Maybe we will recover? */ 1330 1336 if (wait_event_interruptible(gt->reset.queue, 1331 1337 !test_bit(I915_RESET_BACKOFF, 1332 1338 &gt->reset.flags))) ··· 1348 1354 init_waitqueue_head(&gt->reset.queue); 1349 1355 mutex_init(&gt->reset.mutex); 1350 1356 init_srcu_struct(&gt->reset.backoff_srcu); 1357 + 1358 + /* no GPU until we are ready! */ 1359 + __set_bit(I915_WEDGED, &gt->reset.flags); 1351 1360 } 1352 1361 1353 1362 void intel_gt_fini_reset(struct intel_gt *gt)
+19 -33
drivers/gpu/drm/i915/gt/intel_ring_submission.c
··· 33 33 34 34 #include "gem/i915_gem_context.h" 35 35 36 + #include "gen6_ppgtt.h" 36 37 #include "i915_drv.h" 37 38 #include "i915_trace.h" 38 39 #include "intel_context.h" ··· 1329 1328 1330 1329 static int ring_context_pin(struct intel_context *ce) 1331 1330 { 1332 - int err; 1333 - 1334 - err = intel_context_active_acquire(ce); 1335 - if (err) 1336 - return err; 1337 - 1338 - err = __context_pin_ppgtt(ce); 1339 - if (err) 1340 - goto err_active; 1341 - 1342 - return 0; 1343 - 1344 - err_active: 1345 - intel_context_active_release(ce); 1346 - return err; 1331 + return __context_pin_ppgtt(ce); 1347 1332 } 1348 1333 1349 1334 static void ring_context_reset(struct intel_context *ce) 1350 1335 { 1351 - intel_ring_reset(ce->ring, 0); 1336 + intel_ring_reset(ce->ring, ce->ring->emit); 1352 1337 } 1353 1338 1354 1339 static const struct intel_context_ops ring_context_ops = { ··· 1381 1394 1382 1395 intel_ring_advance(rq, cs); 1383 1396 1384 - return 0; 1397 + return rq->engine->emit_flush(rq, EMIT_FLUSH); 1385 1398 } 1386 1399 1387 1400 static inline int mi_set_context(struct i915_request *rq, u32 flags) ··· 1394 1407 bool force_restore = false; 1395 1408 int len; 1396 1409 u32 *cs; 1397 - 1398 - flags |= MI_MM_SPACE_GTT; 1399 - if (IS_HASWELL(i915)) 1400 - /* These flags are for resource streamer on HSW+ */ 1401 - flags |= HSW_MI_RS_SAVE_STATE_EN | HSW_MI_RS_RESTORE_STATE_EN; 1402 - else 1403 - /* We need to save the extended state for powersaving modes */ 1404 - flags |= MI_SAVE_EXT_STATE_EN | MI_RESTORE_EXT_STATE_EN; 1405 1410 1406 1411 len = 4; 1407 1412 if (IS_GEN(i915, 7)) ··· 1571 1592 if (ret) 1572 1593 return ret; 1573 1594 1574 - return rq->engine->emit_flush(rq, EMIT_FLUSH); 1595 + return rq->engine->emit_flush(rq, EMIT_INVALIDATE); 1575 1596 } 1576 1597 1577 1598 static int switch_context(struct i915_request *rq) ··· 1586 1607 return ret; 1587 1608 1588 1609 if (ce->state) { 1589 - u32 hw_flags; 1610 + u32 flags; 1590 1611 1591 1612 GEM_BUG_ON(rq->engine->id != RCS0); 1592 1613 1593 - hw_flags = 0; 1594 - if (!test_bit(CONTEXT_VALID_BIT, &ce->flags)) 1595 - hw_flags = MI_RESTORE_INHIBIT; 1614 + /* For resource streamer on HSW+ and power context elsewhere */ 1615 + BUILD_BUG_ON(HSW_MI_RS_SAVE_STATE_EN != MI_SAVE_EXT_STATE_EN); 1616 + BUILD_BUG_ON(HSW_MI_RS_RESTORE_STATE_EN != MI_RESTORE_EXT_STATE_EN); 1596 1617 1597 - ret = mi_set_context(rq, hw_flags); 1618 + flags = MI_SAVE_EXT_STATE_EN | MI_MM_SPACE_GTT; 1619 + if (test_bit(CONTEXT_VALID_BIT, &ce->flags)) 1620 + flags |= MI_RESTORE_EXT_STATE_EN; 1621 + else 1622 + flags |= MI_RESTORE_INHIBIT; 1623 + 1624 + ret = mi_set_context(rq, flags); 1598 1625 if (ret) 1599 1626 return ret; 1600 1627 } ··· 1827 1842 1828 1843 setup_irq(engine); 1829 1844 1830 - engine->release = ring_release; 1831 - 1832 1845 engine->resume = xcs_resume; 1833 1846 engine->reset.prepare = reset_prepare; 1834 1847 engine->reset.rewind = reset_rewind; ··· 1991 2008 engine->legacy.timeline = timeline; 1992 2009 1993 2010 GEM_BUG_ON(timeline->hwsp_ggtt != engine->status_page.vma); 2011 + 2012 + /* Finally, take ownership and responsibility for cleanup! */ 2013 + engine->release = ring_release; 1994 2014 1995 2015 return 0; 1996 2016
+1 -1
drivers/gpu/drm/i915/gt/intel_rps.c
··· 777 777 spin_lock_irqsave(&rq->lock, flags); 778 778 if (!i915_request_has_waitboost(rq) && 779 779 !dma_fence_is_signaled_locked(&rq->fence)) { 780 - rq->flags |= I915_REQUEST_WAITBOOST; 780 + set_bit(I915_FENCE_FLAG_BOOST, &rq->fence.flags); 781 781 782 782 if (!atomic_fetch_inc(&rps->num_waiters) && 783 783 READ_ONCE(rps->cur_freq) < rps->boost_freq)
-1
drivers/gpu/drm/i915/gt/intel_timeline.c
··· 348 348 * use atomic to manipulate tl->active_count. 349 349 */ 350 350 lockdep_assert_held(&tl->mutex); 351 - GEM_BUG_ON(!atomic_read(&tl->pin_count)); 352 351 353 352 if (atomic_add_unless(&tl->active_count, 1, 0)) 354 353 return;
+1 -1
drivers/gpu/drm/i915/gt/intel_workarounds.c
··· 254 254 255 255 /* WaDisableDopClockGating:bdw 256 256 * 257 - * Also see the related UCGTCL1 write in broadwell_init_clock_gating() 257 + * Also see the related UCGTCL1 write in bdw_init_clock_gating() 258 258 * to disable EUTC clock gating. 259 259 */ 260 260 WA_SET_BIT_MASKED(GEN7_ROW_CHICKEN2,
+6 -1
drivers/gpu/drm/i915/gt/mock_engine.c
··· 149 149 150 150 static int mock_context_pin(struct intel_context *ce) 151 151 { 152 - return intel_context_active_acquire(ce); 152 + return 0; 153 + } 154 + 155 + static void mock_context_reset(struct intel_context *ce) 156 + { 153 157 } 154 158 155 159 static const struct intel_context_ops mock_context_ops = { ··· 165 161 .enter = intel_context_enter_engine, 166 162 .exit = intel_context_exit_engine, 167 163 164 + .reset = mock_context_reset, 168 165 .destroy = mock_context_destroy, 169 166 }; 170 167
+2 -2
drivers/gpu/drm/i915/gt/selftest_hangcheck.c
··· 1312 1312 if (INTEL_PPGTT(gt->i915) < INTEL_PPGTT_FULL) 1313 1313 return 0; 1314 1314 1315 - ppgtt = i915_ppgtt_create(gt->i915); 1315 + ppgtt = i915_ppgtt_create(gt); 1316 1316 if (IS_ERR(ppgtt)) 1317 1317 return PTR_ERR(ppgtt); 1318 1318 ··· 1498 1498 struct intel_engine_cs *engine = gt->engine[RCS0]; 1499 1499 struct hang h; 1500 1500 struct i915_request *rq; 1501 - struct i915_gpu_state *error; 1501 + struct i915_gpu_coredump *error; 1502 1502 int err; 1503 1503 1504 1504 /* Check that we can issue a global GPU and engine reset */
+35 -13
drivers/gpu/drm/i915/gt/selftest_lrc.c
··· 527 527 return rq; 528 528 } 529 529 530 - static void wait_for_submit(struct intel_engine_cs *engine, 531 - struct i915_request *rq) 530 + static int wait_for_submit(struct intel_engine_cs *engine, 531 + struct i915_request *rq, 532 + unsigned long timeout) 532 533 { 534 + timeout += jiffies; 533 535 do { 534 536 cond_resched(); 535 537 intel_engine_flush_submission(engine); 536 - } while (!i915_request_is_active(rq)); 538 + if (i915_request_is_active(rq)) 539 + return 0; 540 + } while (time_before(jiffies, timeout)); 541 + 542 + return -ETIME; 537 543 } 538 544 539 545 static long timeslice_threshold(const struct intel_engine_cs *engine) ··· 607 601 goto err_heartbeat; 608 602 } 609 603 engine->schedule(rq, &attr); 610 - wait_for_submit(engine, rq); 604 + err = wait_for_submit(engine, rq, HZ / 2); 605 + if (err) { 606 + pr_err("%s: Timed out trying to submit semaphores\n", 607 + engine->name); 608 + goto err_rq; 609 + } 611 610 612 611 /* ELSP[1]: nop request */ 613 612 nop = nop_request(engine); ··· 620 609 err = PTR_ERR(nop); 621 610 goto err_rq; 622 611 } 623 - wait_for_submit(engine, nop); 612 + err = wait_for_submit(engine, nop, HZ / 2); 624 613 i915_request_put(nop); 614 + if (err) { 615 + pr_err("%s: Timed out trying to submit nop\n", 616 + engine->name); 617 + goto err_rq; 618 + } 625 619 626 620 GEM_BUG_ON(i915_request_completed(rq)); 627 621 GEM_BUG_ON(execlists_active(&engine->execlists) != rq); ··· 1153 1137 } 1154 1138 1155 1139 /* Low priority client, but unpreemptable! */ 1156 - rq_a->flags |= I915_REQUEST_NOPREEMPT; 1140 + __set_bit(I915_FENCE_FLAG_NOPREEMPT, &rq_a->fence.flags); 1157 1141 1158 1142 i915_request_add(rq_a); 1159 1143 if (!igt_wait_for_spinner(&a.spin, rq_a)) { ··· 3378 3362 struct intel_gt *gt = arg; 3379 3363 struct intel_engine_cs *engine; 3380 3364 enum intel_engine_id id; 3381 - u32 *mem; 3365 + u32 *lrc; 3382 3366 int err; 3383 3367 3384 3368 /* ··· 3386 3370 * match the layout saved by HW. 3387 3371 */ 3388 3372 3389 - mem = kmalloc(PAGE_SIZE, GFP_KERNEL); 3390 - if (!mem) 3373 + lrc = kmalloc(PAGE_SIZE, GFP_KERNEL); 3374 + if (!lrc) 3391 3375 return -ENOMEM; 3392 3376 3393 3377 err = 0; 3394 3378 for_each_engine(engine, gt, id) { 3395 - u32 *hw, *lrc; 3379 + u32 *hw; 3396 3380 int dw; 3397 3381 3398 3382 if (!engine->default_state) ··· 3406 3390 } 3407 3391 hw += LRC_STATE_PN * PAGE_SIZE / sizeof(*hw); 3408 3392 3409 - lrc = memset(mem, 0, PAGE_SIZE); 3410 - execlists_init_reg_state(lrc, 3393 + execlists_init_reg_state(memset(lrc, POISON_INUSE, PAGE_SIZE), 3411 3394 engine->kernel_context, 3412 3395 engine, 3413 3396 engine->kernel_context->ring, ··· 3417 3402 u32 lri = hw[dw]; 3418 3403 3419 3404 if (lri == 0) { 3405 + dw++; 3406 + continue; 3407 + } 3408 + 3409 + if (lrc[dw] == 0) { 3410 + pr_debug("%s: skipped instruction %x at dword %d\n", 3411 + engine->name, lri, dw); 3420 3412 dw++; 3421 3413 continue; 3422 3414 } ··· 3476 3454 break; 3477 3455 } 3478 3456 3479 - kfree(mem); 3457 + kfree(lrc); 3480 3458 return err; 3481 3459 } 3482 3460
-5
drivers/gpu/drm/i915/gt/uc/Makefile
··· 1 - # For building individual subdir files on the command line 2 - subdir-ccflags-y += -I$(srctree)/$(src)/../.. 3 - 4 - # Extra header tests 5 - header-test-pattern-$(CONFIG_DRM_I915_WERROR) := *.h
+49 -26
drivers/gpu/drm/i915/gt/uc/intel_uc.c
··· 12 12 13 13 #include "i915_drv.h" 14 14 15 + static const struct intel_uc_ops uc_ops_off; 16 + static const struct intel_uc_ops uc_ops_on; 17 + 15 18 /* Reset GuC providing us with fresh state for both GuC and HuC. 16 19 */ 17 20 static int __intel_uc_reset_hw(struct intel_uc *uc) ··· 92 89 intel_huc_init_early(&uc->huc); 93 90 94 91 __confirm_options(uc); 92 + 93 + if (intel_uc_uses_guc(uc)) 94 + uc->ops = &uc_ops_on; 95 + else 96 + uc->ops = &uc_ops_off; 95 97 } 96 98 97 99 void intel_uc_driver_late_release(struct intel_uc *uc) ··· 253 245 DRM_INFO("GuC communication disabled\n"); 254 246 } 255 247 256 - void intel_uc_fetch_firmwares(struct intel_uc *uc) 248 + static void __uc_fetch_firmwares(struct intel_uc *uc) 257 249 { 258 250 int err; 259 251 260 - if (!intel_uc_uses_guc(uc)) 261 - return; 252 + GEM_BUG_ON(!intel_uc_uses_guc(uc)); 262 253 263 254 err = intel_uc_fw_fetch(&uc->guc.fw); 264 255 if (err) ··· 267 260 intel_uc_fw_fetch(&uc->huc.fw); 268 261 } 269 262 270 - void intel_uc_cleanup_firmwares(struct intel_uc *uc) 263 + static void __uc_cleanup_firmwares(struct intel_uc *uc) 271 264 { 272 265 intel_uc_fw_cleanup_fetch(&uc->huc.fw); 273 266 intel_uc_fw_cleanup_fetch(&uc->guc.fw); 274 267 } 275 268 276 - void intel_uc_init(struct intel_uc *uc) 269 + static void __uc_init(struct intel_uc *uc) 277 270 { 278 271 struct intel_guc *guc = &uc->guc; 279 272 struct intel_huc *huc = &uc->huc; 280 273 int ret; 281 274 282 - if (!intel_uc_uses_guc(uc)) 283 - return; 275 + GEM_BUG_ON(!intel_uc_uses_guc(uc)); 284 276 285 277 /* XXX: GuC submission is unavailable for now */ 286 278 GEM_BUG_ON(intel_uc_supports_guc_submission(uc)); ··· 294 288 intel_huc_init(huc); 295 289 } 296 290 297 - void intel_uc_fini(struct intel_uc *uc) 291 + static void __uc_fini(struct intel_uc *uc) 298 292 { 299 293 intel_huc_fini(&uc->huc); 300 294 intel_guc_fini(&uc->guc); ··· 313 307 intel_guc_sanitize(guc); 314 308 315 309 return __intel_uc_reset_hw(uc); 316 - } 317 - 318 - void intel_uc_sanitize(struct intel_uc *uc) 319 - { 320 - if (!intel_uc_supports_guc(uc)) 321 - return; 322 - 323 - __uc_sanitize(uc); 324 310 } 325 311 326 312 /* Initialize and verify the uC regs related to uC positioning in WOPCM */ ··· 378 380 (intel_uncore_read(uncore, DMA_GUC_WOPCM_OFFSET) & GUC_WOPCM_OFFSET_VALID); 379 381 } 380 382 381 - int intel_uc_init_hw(struct intel_uc *uc) 383 + static int __uc_check_hw(struct intel_uc *uc) 382 384 { 383 - struct drm_i915_private *i915 = uc_to_gt(uc)->i915; 384 - struct intel_guc *guc = &uc->guc; 385 - struct intel_huc *huc = &uc->huc; 386 - int ret, attempts; 387 - 388 385 if (!intel_uc_supports_guc(uc)) 389 386 return 0; 390 387 ··· 388 395 * before on this system after reboot, otherwise we risk GPU hangs. 389 396 * To check if GuC was loaded before we look at WOPCM registers. 390 397 */ 391 - if (!intel_uc_uses_guc(uc) && !uc_is_wopcm_locked(uc)) 392 - return 0; 398 + if (uc_is_wopcm_locked(uc)) 399 + return -EIO; 400 + 401 + return 0; 402 + } 403 + 404 + static int __uc_init_hw(struct intel_uc *uc) 405 + { 406 + struct drm_i915_private *i915 = uc_to_gt(uc)->i915; 407 + struct intel_guc *guc = &uc->guc; 408 + struct intel_huc *huc = &uc->huc; 409 + int ret, attempts; 410 + 411 + GEM_BUG_ON(!intel_uc_supports_guc(uc)); 412 + GEM_BUG_ON(!intel_uc_uses_guc(uc)); 393 413 394 414 if (!intel_uc_fw_is_available(&guc->fw)) { 395 - ret = uc_is_wopcm_locked(uc) || 415 + ret = __uc_check_hw(uc) || 396 416 intel_uc_fw_is_overridden(&guc->fw) || 397 417 intel_uc_supports_guc_submission(uc) ? 398 418 intel_uc_fw_status_to_error(guc->fw.status) : 0; ··· 501 495 return -EIO; 502 496 } 503 497 504 - void intel_uc_fini_hw(struct intel_uc *uc) 498 + static void __uc_fini_hw(struct intel_uc *uc) 505 499 { 506 500 struct intel_guc *guc = &uc->guc; 507 501 ··· 601 595 */ 602 596 return __uc_resume(uc, true); 603 597 } 598 + 599 + static const struct intel_uc_ops uc_ops_off = { 600 + .init_hw = __uc_check_hw, 601 + }; 602 + 603 + static const struct intel_uc_ops uc_ops_on = { 604 + .sanitize = __uc_sanitize, 605 + 606 + .init_fw = __uc_fetch_firmwares, 607 + .fini_fw = __uc_cleanup_firmwares, 608 + 609 + .init = __uc_init, 610 + .fini = __uc_fini, 611 + 612 + .init_hw = __uc_init_hw, 613 + .fini_hw = __uc_fini_hw, 614 + };
+29 -7
drivers/gpu/drm/i915/gt/uc/intel_uc.h
··· 10 10 #include "intel_huc.h" 11 11 #include "i915_params.h" 12 12 13 + struct intel_uc; 14 + 15 + struct intel_uc_ops { 16 + int (*sanitize)(struct intel_uc *uc); 17 + void (*init_fw)(struct intel_uc *uc); 18 + void (*fini_fw)(struct intel_uc *uc); 19 + void (*init)(struct intel_uc *uc); 20 + void (*fini)(struct intel_uc *uc); 21 + int (*init_hw)(struct intel_uc *uc); 22 + void (*fini_hw)(struct intel_uc *uc); 23 + }; 24 + 13 25 struct intel_uc { 26 + struct intel_uc_ops const *ops; 14 27 struct intel_guc guc; 15 28 struct intel_huc huc; 16 29 ··· 34 21 void intel_uc_init_early(struct intel_uc *uc); 35 22 void intel_uc_driver_late_release(struct intel_uc *uc); 36 23 void intel_uc_init_mmio(struct intel_uc *uc); 37 - void intel_uc_fetch_firmwares(struct intel_uc *uc); 38 - void intel_uc_cleanup_firmwares(struct intel_uc *uc); 39 - void intel_uc_sanitize(struct intel_uc *uc); 40 - void intel_uc_init(struct intel_uc *uc); 41 - int intel_uc_init_hw(struct intel_uc *uc); 42 - void intel_uc_fini_hw(struct intel_uc *uc); 43 - void intel_uc_fini(struct intel_uc *uc); 44 24 void intel_uc_reset_prepare(struct intel_uc *uc); 45 25 void intel_uc_suspend(struct intel_uc *uc); 46 26 void intel_uc_runtime_suspend(struct intel_uc *uc); ··· 69 63 { 70 64 return intel_huc_is_enabled(&uc->huc); 71 65 } 66 + 67 + #define intel_uc_ops_function(_NAME, _OPS, _TYPE, _RET) \ 68 + static inline _TYPE intel_uc_##_NAME(struct intel_uc *uc) \ 69 + { \ 70 + if (uc->ops->_OPS) \ 71 + return uc->ops->_OPS(uc); \ 72 + return _RET; \ 73 + } 74 + intel_uc_ops_function(sanitize, sanitize, int, 0); 75 + intel_uc_ops_function(fetch_firmwares, init_fw, void, ); 76 + intel_uc_ops_function(cleanup_firmwares, fini_fw, void, ); 77 + intel_uc_ops_function(init, init, void, ); 78 + intel_uc_ops_function(fini, fini, void, ); 79 + intel_uc_ops_function(init_hw, init_hw, int, 0); 80 + intel_uc_ops_function(fini_hw, fini_hw, void, ); 81 + #undef intel_uc_ops_function 72 82 73 83 #endif
+4 -4
drivers/gpu/drm/i915/gvt/handlers.c
··· 2675 2675 return 0; 2676 2676 } 2677 2677 2678 - static int init_broadwell_mmio_info(struct intel_gvt *gvt) 2678 + static int init_bdw_mmio_info(struct intel_gvt *gvt) 2679 2679 { 2680 2680 struct drm_i915_private *dev_priv = gvt->dev_priv; 2681 2681 int ret; ··· 3364 3364 goto err; 3365 3365 3366 3366 if (IS_BROADWELL(dev_priv)) { 3367 - ret = init_broadwell_mmio_info(gvt); 3367 + ret = init_bdw_mmio_info(gvt); 3368 3368 if (ret) 3369 3369 goto err; 3370 3370 } else if (IS_SKYLAKE(dev_priv) 3371 3371 || IS_KABYLAKE(dev_priv) 3372 3372 || IS_COFFEELAKE(dev_priv)) { 3373 - ret = init_broadwell_mmio_info(gvt); 3373 + ret = init_bdw_mmio_info(gvt); 3374 3374 if (ret) 3375 3375 goto err; 3376 3376 ret = init_skl_mmio_info(gvt); 3377 3377 if (ret) 3378 3378 goto err; 3379 3379 } else if (IS_BROXTON(dev_priv)) { 3380 - ret = init_broadwell_mmio_info(gvt); 3380 + ret = init_bdw_mmio_info(gvt); 3381 3381 if (ret) 3382 3382 goto err; 3383 3383 ret = init_skl_mmio_info(gvt);
+1 -1
drivers/gpu/drm/i915/gvt/scheduler.c
··· 1224 1224 enum intel_engine_id i; 1225 1225 int ret; 1226 1226 1227 - ppgtt = i915_ppgtt_create(i915); 1227 + ppgtt = i915_ppgtt_create(&i915->gt); 1228 1228 if (IS_ERR(ppgtt)) 1229 1229 return PTR_ERR(ppgtt); 1230 1230
+15 -4
drivers/gpu/drm/i915/i915_active.c
··· 605 605 struct intel_engine_cs *engine) 606 606 { 607 607 intel_engine_mask_t tmp, mask = engine->mask; 608 + struct llist_node *pos = NULL, *next; 608 609 struct intel_gt *gt = engine->gt; 609 - struct llist_node *pos, *next; 610 610 int err; 611 611 612 612 GEM_BUG_ON(i915_active_is_idle(ref)); 613 - GEM_BUG_ON(!llist_empty(&ref->preallocated_barriers)); 613 + 614 + /* Wait until the previous preallocation is completed */ 615 + while (!llist_empty(&ref->preallocated_barriers)) 616 + cond_resched(); 614 617 615 618 /* 616 619 * Preallocate a node for each physical engine supporting the target ··· 656 653 GEM_BUG_ON(rcu_access_pointer(node->base.fence) != ERR_PTR(-EAGAIN)); 657 654 658 655 GEM_BUG_ON(barrier_to_engine(node) != engine); 659 - llist_add(barrier_to_ll(node), &ref->preallocated_barriers); 656 + next = barrier_to_ll(node); 657 + next->next = pos; 658 + if (!pos) 659 + pos = next; 660 660 intel_engine_pm_get(engine); 661 661 } 662 + 663 + GEM_BUG_ON(!llist_empty(&ref->preallocated_barriers)); 664 + llist_add_batch(next, pos, &ref->preallocated_barriers); 662 665 663 666 return 0; 664 667 665 668 unwind: 666 - llist_for_each_safe(pos, next, take_preallocated_barriers(ref)) { 669 + while (pos) { 667 670 struct active_node *node = barrier_from_ll(pos); 671 + 672 + pos = pos->next; 668 673 669 674 atomic_dec(&ref->count); 670 675 intel_engine_pm_put(barrier_to_engine(node));
+3 -1
drivers/gpu/drm/i915/i915_buddy.c
··· 262 262 { 263 263 struct i915_buddy_block *block, *on; 264 264 265 - list_for_each_entry_safe(block, on, objects, link) 265 + list_for_each_entry_safe(block, on, objects, link) { 266 266 i915_buddy_free(mm, block); 267 + cond_resched(); 268 + } 267 269 INIT_LIST_HEAD(objects); 268 270 } 269 271
+40 -38
drivers/gpu/drm/i915/i915_debugfs.c
··· 321 321 322 322 for_each_gem_engine(ce, 323 323 i915_gem_context_lock_engines(ctx), it) { 324 - intel_context_lock_pinned(ce); 325 - if (intel_context_is_pinned(ce)) { 324 + if (intel_context_pin_if_active(ce)) { 326 325 rcu_read_lock(); 327 326 if (ce->state) 328 327 per_file_stats(0, 329 328 ce->state->obj, &kstats); 330 329 per_file_stats(0, ce->ring->vma->obj, &kstats); 331 330 rcu_read_unlock(); 331 + intel_context_unpin(ce); 332 332 } 333 - intel_context_unlock_pinned(ce); 334 333 } 335 334 i915_gem_context_unlock_engines(ctx); 336 335 ··· 366 367 static int i915_gem_object_info(struct seq_file *m, void *data) 367 368 { 368 369 struct drm_i915_private *i915 = node_to_i915(m->private); 370 + struct intel_memory_region *mr; 371 + enum intel_region_id id; 369 372 370 373 seq_printf(m, "%u shrinkable [%u free] objects, %llu bytes\n", 371 374 i915->mm.shrink_count, 372 375 atomic_read(&i915->mm.free_count), 373 376 i915->mm.shrink_memory); 374 - 377 + for_each_memory_region(mr, i915, id) 378 + seq_printf(m, "%s: total:%pa, available:%pa bytes\n", 379 + mr->name, &mr->total, &mr->avail); 375 380 seq_putc(m, '\n'); 376 381 377 382 print_context_stats(m, i915); ··· 685 682 static ssize_t gpu_state_read(struct file *file, char __user *ubuf, 686 683 size_t count, loff_t *pos) 687 684 { 688 - struct i915_gpu_state *error; 685 + struct i915_gpu_coredump *error; 689 686 ssize_t ret; 690 687 void *buf; 691 688 ··· 698 695 if (!buf) 699 696 return -ENOMEM; 700 697 701 - ret = i915_gpu_state_copy_to_buffer(error, buf, *pos, count); 698 + ret = i915_gpu_coredump_copy_to_buffer(error, buf, *pos, count); 702 699 if (ret <= 0) 703 700 goto out; 704 701 ··· 714 711 715 712 static int gpu_state_release(struct inode *inode, struct file *file) 716 713 { 717 - i915_gpu_state_put(file->private_data); 714 + i915_gpu_coredump_put(file->private_data); 718 715 return 0; 719 716 } 720 717 721 718 static int i915_gpu_info_open(struct inode *inode, struct file *file) 722 719 { 723 720 struct drm_i915_private *i915 = inode->i_private; 724 - struct i915_gpu_state *gpu; 721 + struct i915_gpu_coredump *gpu; 725 722 intel_wakeref_t wakeref; 726 723 727 724 gpu = NULL; 728 725 with_intel_runtime_pm(&i915->runtime_pm, wakeref) 729 - gpu = i915_capture_gpu_state(i915); 726 + gpu = i915_gpu_coredump(i915); 730 727 if (IS_ERR(gpu)) 731 728 return PTR_ERR(gpu); 732 729 ··· 748 745 size_t cnt, 749 746 loff_t *ppos) 750 747 { 751 - struct i915_gpu_state *error = filp->private_data; 748 + struct i915_gpu_coredump *error = filp->private_data; 752 749 753 750 if (!error) 754 751 return 0; ··· 761 758 762 759 static int i915_error_state_open(struct inode *inode, struct file *file) 763 760 { 764 - struct i915_gpu_state *error; 761 + struct i915_gpu_coredump *error; 765 762 766 763 error = i915_first_error_state(inode->i_private); 767 764 if (IS_ERR(error)) ··· 1004 1001 return ret; 1005 1002 } 1006 1003 1007 - static int ironlake_drpc_info(struct seq_file *m) 1004 + static int ilk_drpc_info(struct seq_file *m) 1008 1005 { 1009 1006 struct drm_i915_private *i915 = node_to_i915(m->private); 1010 1007 struct intel_uncore *uncore = &i915->uncore; ··· 1212 1209 else if (INTEL_GEN(dev_priv) >= 6) 1213 1210 err = gen6_drpc_info(m); 1214 1211 else 1215 - err = ironlake_drpc_info(m); 1212 + err = ilk_drpc_info(m); 1216 1213 } 1217 1214 1218 1215 return err; ··· 1512 1509 1513 1510 for_each_gem_engine(ce, 1514 1511 i915_gem_context_lock_engines(ctx), it) { 1515 - intel_context_lock_pinned(ce); 1516 - if (intel_context_is_pinned(ce)) { 1512 + if (intel_context_pin_if_active(ce)) { 1517 1513 seq_printf(m, "%s: ", ce->engine->name); 1518 1514 if (ce->state) 1519 1515 describe_obj(m, ce->state->obj); 1520 1516 describe_ctx_ring(m, ce->ring); 1521 1517 seq_putc(m, '\n'); 1518 + intel_context_unpin(ce); 1522 1519 } 1523 - intel_context_unlock_pinned(ce); 1524 1520 } 1525 1521 i915_gem_context_unlock_engines(ctx); 1526 1522 ··· 1979 1977 struct drm_connector *connector = m->private; 1980 1978 struct drm_i915_private *dev_priv = to_i915(connector->dev); 1981 1979 struct intel_dp *intel_dp = 1982 - enc_to_intel_dp(&intel_attached_encoder(connector)->base); 1980 + enc_to_intel_dp(intel_attached_encoder(to_intel_connector(connector))); 1983 1981 int ret; 1984 1982 1985 1983 if (!CAN_PSR(dev_priv)) { ··· 2391 2389 struct intel_connector *intel_connector) 2392 2390 { 2393 2391 struct intel_encoder *intel_encoder = intel_connector->encoder; 2394 - struct intel_dp *intel_dp = enc_to_intel_dp(&intel_encoder->base); 2392 + struct intel_dp *intel_dp = enc_to_intel_dp(intel_encoder); 2395 2393 2396 2394 seq_printf(m, "\tDPCD rev: %x\n", intel_dp->dpcd[DP_DPCD_REV]); 2397 2395 seq_printf(m, "\taudio support: %s\n", yesno(intel_dp->has_audio)); ··· 2411 2409 { 2412 2410 struct intel_encoder *intel_encoder = intel_connector->encoder; 2413 2411 struct intel_dp_mst_encoder *intel_mst = 2414 - enc_to_mst(&intel_encoder->base); 2412 + enc_to_mst(intel_encoder); 2415 2413 struct intel_digital_port *intel_dig_port = intel_mst->primary; 2416 2414 struct intel_dp *intel_dp = &intel_dig_port->dp; 2417 2415 bool has_audio = drm_dp_mst_port_has_audio(&intel_dp->mst_mgr, ··· 2424 2422 struct intel_connector *intel_connector) 2425 2423 { 2426 2424 struct intel_encoder *intel_encoder = intel_connector->encoder; 2427 - struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&intel_encoder->base); 2425 + struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(intel_encoder); 2428 2426 2429 2427 seq_printf(m, "\taudio support: %s\n", yesno(intel_hdmi->has_audio)); 2430 2428 if (intel_connector->hdcp.shim) { ··· 3014 3012 if (connector->connector_type != DRM_MODE_CONNECTOR_DisplayPort) 3015 3013 continue; 3016 3014 3017 - intel_encoder = intel_attached_encoder(connector); 3015 + intel_encoder = intel_attached_encoder(to_intel_connector(connector)); 3018 3016 if (!intel_encoder || intel_encoder->type == INTEL_OUTPUT_DP_MST) 3019 3017 continue; 3020 3018 3021 - intel_dig_port = enc_to_dig_port(&intel_encoder->base); 3019 + intel_dig_port = enc_to_dig_port(intel_encoder); 3022 3020 if (!intel_dig_port->dp.can_mst) 3023 3021 continue; 3024 3022 ··· 3068 3066 continue; 3069 3067 3070 3068 if (encoder && connector->status == connector_status_connected) { 3071 - intel_dp = enc_to_intel_dp(&encoder->base); 3069 + intel_dp = enc_to_intel_dp(encoder); 3072 3070 status = kstrtoint(input_buffer, 10, &val); 3073 3071 if (status < 0) 3074 3072 break; ··· 3077 3075 * testing code, only accept an actual value of 1 here 3078 3076 */ 3079 3077 if (val == 1) 3080 - intel_dp->compliance.test_active = 1; 3078 + intel_dp->compliance.test_active = true; 3081 3079 else 3082 - intel_dp->compliance.test_active = 0; 3080 + intel_dp->compliance.test_active = false; 3083 3081 } 3084 3082 } 3085 3083 drm_connector_list_iter_end(&conn_iter); ··· 3112 3110 continue; 3113 3111 3114 3112 if (encoder && connector->status == connector_status_connected) { 3115 - intel_dp = enc_to_intel_dp(&encoder->base); 3113 + intel_dp = enc_to_intel_dp(encoder); 3116 3114 if (intel_dp->compliance.test_active) 3117 3115 seq_puts(m, "1"); 3118 3116 else ··· 3162 3160 continue; 3163 3161 3164 3162 if (encoder && connector->status == connector_status_connected) { 3165 - intel_dp = enc_to_intel_dp(&encoder->base); 3163 + intel_dp = enc_to_intel_dp(encoder); 3166 3164 if (intel_dp->compliance.test_type == 3167 3165 DP_TEST_LINK_EDID_READ) 3168 3166 seq_printf(m, "%lx", ··· 3206 3204 continue; 3207 3205 3208 3206 if (encoder && connector->status == connector_status_connected) { 3209 - intel_dp = enc_to_intel_dp(&encoder->base); 3207 + intel_dp = enc_to_intel_dp(encoder); 3210 3208 seq_printf(m, "%02lx", intel_dp->compliance.test_type); 3211 3209 } else 3212 3210 seq_puts(m, "0"); ··· 3817 3815 #undef SS_MAX 3818 3816 } 3819 3817 3820 - static void broadwell_sseu_device_status(struct drm_i915_private *dev_priv, 3821 - struct sseu_dev_info *sseu) 3818 + static void bdw_sseu_device_status(struct drm_i915_private *dev_priv, 3819 + struct sseu_dev_info *sseu) 3822 3820 { 3823 3821 const struct intel_runtime_info *info = RUNTIME_INFO(dev_priv); 3824 3822 u32 slice_info = I915_READ(GEN8_GT_SLICE_INFO); ··· 3903 3901 if (IS_CHERRYVIEW(dev_priv)) 3904 3902 cherryview_sseu_device_status(dev_priv, &sseu); 3905 3903 else if (IS_BROADWELL(dev_priv)) 3906 - broadwell_sseu_device_status(dev_priv, &sseu); 3904 + bdw_sseu_device_status(dev_priv, &sseu); 3907 3905 else if (IS_GEN(dev_priv, 9)) 3908 3906 gen9_sseu_device_status(dev_priv, &sseu); 3909 3907 else if (INTEL_GEN(dev_priv) >= 10) ··· 4144 4142 drm_connector_mask(connector))) 4145 4143 continue; 4146 4144 4147 - encoder = intel_attached_encoder(connector); 4145 + encoder = intel_attached_encoder(to_intel_connector(connector)); 4148 4146 if (encoder->type != INTEL_OUTPUT_EDP) 4149 4147 continue; 4150 4148 4151 4149 DRM_DEBUG_DRIVER("Manually %sabling DRRS. %llu\n", 4152 4150 val ? "en" : "dis", val); 4153 4151 4154 - intel_dp = enc_to_intel_dp(&encoder->base); 4152 + intel_dp = enc_to_intel_dp(encoder); 4155 4153 if (val) 4156 4154 intel_edp_drrs_enable(intel_dp, 4157 4155 crtc_state); ··· 4355 4353 { 4356 4354 struct drm_connector *connector = m->private; 4357 4355 struct intel_dp *intel_dp = 4358 - enc_to_intel_dp(&intel_attached_encoder(connector)->base); 4356 + enc_to_intel_dp(intel_attached_encoder(to_intel_connector(connector))); 4359 4357 u8 buf[16]; 4360 4358 ssize_t err; 4361 4359 int i; ··· 4390 4388 { 4391 4389 struct drm_connector *connector = m->private; 4392 4390 struct intel_dp *intel_dp = 4393 - enc_to_intel_dp(&intel_attached_encoder(connector)->base); 4391 + enc_to_intel_dp(intel_attached_encoder(to_intel_connector(connector))); 4394 4392 4395 4393 if (connector->status != connector_status_connected) 4396 4394 return -ENODEV; ··· 4468 4466 } else if (ret) { 4469 4467 break; 4470 4468 } 4471 - intel_dp = enc_to_intel_dp(&intel_attached_encoder(connector)->base); 4469 + intel_dp = enc_to_intel_dp(intel_attached_encoder(to_intel_connector(connector))); 4472 4470 crtc_state = to_intel_crtc_state(crtc->state); 4473 4471 seq_printf(m, "DSC_Enabled: %s\n", 4474 4472 yesno(crtc_state->dsc.compression_enable)); ··· 4495 4493 int ret; 4496 4494 struct drm_connector *connector = 4497 4495 ((struct seq_file *)file->private_data)->private; 4498 - struct intel_encoder *encoder = intel_attached_encoder(connector); 4499 - struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base); 4496 + struct intel_encoder *encoder = intel_attached_encoder(to_intel_connector(connector)); 4497 + struct intel_dp *intel_dp = enc_to_intel_dp(encoder); 4500 4498 4501 4499 if (len == 0) 4502 4500 return 0;
+10 -1
drivers/gpu/drm/i915/i915_drv.c
··· 469 469 i915->vlv_s0ix_state = NULL; 470 470 } 471 471 472 + static void sanitize_gpu(struct drm_i915_private *i915) 473 + { 474 + if (!INTEL_INFO(i915)->gpu_reset_clobbers_display) 475 + __intel_gt_reset(&i915->gt, ALL_ENGINES); 476 + } 477 + 472 478 /** 473 479 * i915_driver_early_probe - setup state not requiring device access 474 480 * @dev_priv: device private ··· 607 601 ret = intel_engines_init_mmio(&dev_priv->gt); 608 602 if (ret) 609 603 goto err_uncore; 604 + 605 + /* As early as possible, scrub existing GPU state before clobbering */ 606 + sanitize_gpu(dev_priv); 610 607 611 608 return 0; 612 609 ··· 1826 1817 1827 1818 disable_rpm_wakeref_asserts(&dev_priv->runtime_pm); 1828 1819 1829 - intel_gt_sanitize(&dev_priv->gt, true); 1820 + sanitize_gpu(dev_priv); 1830 1821 1831 1822 ret = i915_ggtt_enable_hw(dev_priv); 1832 1823 if (ret)
+24 -8
drivers/gpu/drm/i915/i915_drv.h
··· 46 46 #include <linux/dma-resv.h> 47 47 #include <linux/shmem_fs.h> 48 48 #include <linux/stackdepot.h> 49 + #include <linux/xarray.h> 49 50 50 51 #include <drm/intel-gtt.h> 51 52 #include <drm/drm_legacy.h> /* for struct drm_dma_handle */ ··· 111 110 112 111 #define DRIVER_NAME "i915" 113 112 #define DRIVER_DESC "Intel Graphics" 114 - #define DRIVER_DATE "20191223" 115 - #define DRIVER_TIMESTAMP 1577120893 113 + #define DRIVER_DATE "20200114" 114 + #define DRIVER_TIMESTAMP 1579001978 116 115 117 116 struct drm_i915_gem_object; 118 117 ··· 202 201 struct list_head request_list; 203 202 } mm; 204 203 205 - struct idr context_idr; 206 - struct mutex context_idr_lock; /* guards context_idr */ 204 + struct xarray context_xa; 207 205 208 206 struct idr vm_idr; 209 207 struct mutex vm_idr_lock; /* guards vm_idr */ ··· 505 505 bool dc3co_enabled; 506 506 u32 dc3co_exit_delay; 507 507 struct delayed_work idle_work; 508 + bool initially_probed; 508 509 }; 509 510 510 511 #define QUIRK_LVDS_SSC_DISABLE (1<<1) ··· 1253 1252 struct llist_head free_list; 1254 1253 struct work_struct free_work; 1255 1254 } contexts; 1255 + 1256 + /* 1257 + * We replace the local file with a global mappings as the 1258 + * backing storage for the mmap is on the device and not 1259 + * on the struct file, and we do not want to prolong the 1260 + * lifetime of the local fd. To minimise the number of 1261 + * anonymous inodes we create, we use a global singleton to 1262 + * share the global mapping. 1263 + */ 1264 + struct file *mmap_singleton; 1256 1265 } gem; 1257 1266 1258 1267 u8 pch_ssc_use; ··· 1668 1657 (IS_BROADWELL(dev_priv) || IS_GEN(dev_priv, 9)) 1669 1658 1670 1659 /* WaRsDisableCoarsePowerGating:skl,cnl */ 1671 - #define NEEDS_WaRsDisableCoarsePowerGating(dev_priv) \ 1672 - IS_GEN_RANGE(dev_priv, 9, 10) 1660 + #define NEEDS_WaRsDisableCoarsePowerGating(dev_priv) \ 1661 + (IS_CANNONLAKE(dev_priv) || \ 1662 + IS_SKL_GT3(dev_priv) || \ 1663 + IS_SKL_GT4(dev_priv)) 1673 1664 1674 1665 #define HAS_GMBUS_IRQ(dev_priv) (INTEL_GEN(dev_priv) >= 4) 1675 1666 #define HAS_GMBUS_BURST_READ(dev_priv) (INTEL_GEN(dev_priv) >= 10 || \ ··· 1874 1861 } 1875 1862 1876 1863 static inline u32 i915_reset_engine_count(struct i915_gpu_error *error, 1877 - struct intel_engine_cs *engine) 1864 + const struct intel_engine_cs *engine) 1878 1865 { 1879 1866 return atomic_read(&error->reset_engine_count[engine->uabi_class]); 1880 1867 } ··· 1902 1889 static inline struct i915_gem_context * 1903 1890 __i915_gem_context_lookup_rcu(struct drm_i915_file_private *file_priv, u32 id) 1904 1891 { 1905 - return idr_find(&file_priv->context_idr, id); 1892 + return xa_load(&file_priv->context_xa, id); 1906 1893 } 1907 1894 1908 1895 static inline struct i915_gem_context * ··· 2028 2015 int remap_io_mapping(struct vm_area_struct *vma, 2029 2016 unsigned long addr, unsigned long pfn, unsigned long size, 2030 2017 struct io_mapping *iomap); 2018 + int remap_io_sg(struct vm_area_struct *vma, 2019 + unsigned long addr, unsigned long size, 2020 + struct scatterlist *sgl, resource_size_t iobase); 2031 2021 2032 2022 static inline int intel_hws_csb_write_index(struct drm_i915_private *i915) 2033 2023 {
+24 -9
drivers/gpu/drm/i915/i915_gem.c
··· 45 45 #include "gem/i915_gem_context.h" 46 46 #include "gem/i915_gem_ioctls.h" 47 47 #include "gem/i915_gem_mman.h" 48 + #include "gem/i915_gem_region.h" 48 49 #include "gt/intel_engine_user.h" 49 50 #include "gt/intel_gt.h" 50 51 #include "gt/intel_gt_pm.h" ··· 201 200 202 201 static int 203 202 i915_gem_create(struct drm_file *file, 204 - struct drm_i915_private *dev_priv, 203 + struct intel_memory_region *mr, 205 204 u64 *size_p, 206 205 u32 *handle_p) 207 206 { ··· 210 209 u64 size; 211 210 int ret; 212 211 213 - size = round_up(*size_p, PAGE_SIZE); 212 + GEM_BUG_ON(!is_power_of_2(mr->min_page_size)); 213 + size = round_up(*size_p, mr->min_page_size); 214 214 if (size == 0) 215 215 return -EINVAL; 216 216 217 + /* For most of the ABI (e.g. mmap) we think in system pages */ 218 + GEM_BUG_ON(!IS_ALIGNED(size, PAGE_SIZE)); 219 + 217 220 /* Allocate the new object */ 218 - obj = i915_gem_object_create_shmem(dev_priv, size); 221 + obj = i915_gem_object_create_region(mr, size, 0); 219 222 if (IS_ERR(obj)) 220 223 return PTR_ERR(obj); 221 224 ··· 239 234 struct drm_device *dev, 240 235 struct drm_mode_create_dumb *args) 241 236 { 237 + enum intel_memory_type mem_type; 242 238 int cpp = DIV_ROUND_UP(args->bpp, 8); 243 239 u32 format; 244 240 ··· 266 260 args->pitch = ALIGN(args->pitch, 4096); 267 261 268 262 args->size = args->pitch * args->height; 269 - return i915_gem_create(file, to_i915(dev), 263 + 264 + mem_type = INTEL_MEMORY_SYSTEM; 265 + if (HAS_LMEM(to_i915(dev))) 266 + mem_type = INTEL_MEMORY_LOCAL; 267 + 268 + return i915_gem_create(file, 269 + intel_memory_region_by_type(to_i915(dev), 270 + mem_type), 270 271 &args->size, &args->handle); 271 272 } 272 273 ··· 287 274 i915_gem_create_ioctl(struct drm_device *dev, void *data, 288 275 struct drm_file *file) 289 276 { 290 - struct drm_i915_private *dev_priv = to_i915(dev); 277 + struct drm_i915_private *i915 = to_i915(dev); 291 278 struct drm_i915_gem_create *args = data; 292 279 293 - i915_gem_flush_free_objects(dev_priv); 280 + i915_gem_flush_free_objects(i915); 294 281 295 - return i915_gem_create(file, dev_priv, 282 + return i915_gem_create(file, 283 + intel_memory_region_by_type(i915, 284 + INTEL_MEMORY_SYSTEM), 296 285 &args->size, &args->handle); 297 286 } 298 287 ··· 1187 1172 1188 1173 void i915_gem_driver_release(struct drm_i915_private *dev_priv) 1189 1174 { 1175 + i915_gem_driver_release__contexts(dev_priv); 1176 + 1190 1177 intel_gt_driver_release(&dev_priv->gt); 1191 1178 1192 1179 intel_wa_list_free(&dev_priv->gt_wa_list); 1193 1180 1194 1181 intel_uc_cleanup_firmwares(&dev_priv->gt.uc); 1195 1182 i915_gem_cleanup_userptr(dev_priv); 1196 - 1197 - i915_gem_driver_release__contexts(dev_priv); 1198 1183 1199 1184 i915_gem_drain_freed_objects(dev_priv); 1200 1185
+3
drivers/gpu/drm/i915/i915_gem_fence_reg.c
··· 412 412 { 413 413 int err; 414 414 415 + if (!vma->fence && !i915_gem_object_is_tiled(vma->obj)) 416 + return 0; 417 + 415 418 /* 416 419 * Note that we revoke fences on runtime suspend. Therefore the user 417 420 * must keep the device awake whilst using the fence.
+2 -3558
drivers/gpu/drm/i915/i915_gem_gtt.c
··· 1 + // SPDX-License-Identifier: MIT 1 2 /* 2 3 * Copyright © 2010 Daniel Vetter 3 - * Copyright © 2011-2014 Intel Corporation 4 - * 5 - * Permission is hereby granted, free of charge, to any person obtaining a 6 - * copy of this software and associated documentation files (the "Software"), 7 - * to deal in the Software without restriction, including without limitation 8 - * the rights to use, copy, modify, merge, publish, distribute, sublicense, 9 - * and/or sell copies of the Software, and to permit persons to whom the 10 - * Software is furnished to do so, subject to the following conditions: 11 - * 12 - * The above copyright notice and this permission notice (including the next 13 - * paragraph) shall be included in all copies or substantial portions of the 14 - * Software. 15 - * 16 - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 19 - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21 - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 22 - * IN THE SOFTWARE. 23 - * 4 + * Copyright © 2020 Intel Corporation 24 5 */ 25 6 26 7 #include <linux/slab.h> /* fault-inject.h is not standalone! */ ··· 25 44 #include "i915_scatterlist.h" 26 45 #include "i915_trace.h" 27 46 #include "i915_vgpu.h" 28 - 29 - #define I915_GFP_ALLOW_FAIL (GFP_KERNEL | __GFP_RETRY_MAYFAIL | __GFP_NOWARN) 30 - 31 - #if IS_ENABLED(CONFIG_DRM_I915_TRACE_GTT) 32 - #define DBG(...) trace_printk(__VA_ARGS__) 33 - #else 34 - #define DBG(...) 35 - #endif 36 - 37 - #define NALLOC 3 /* 1 normal, 1 for concurrent threads, 1 for preallocation */ 38 - 39 - /** 40 - * DOC: Global GTT views 41 - * 42 - * Background and previous state 43 - * 44 - * Historically objects could exists (be bound) in global GTT space only as 45 - * singular instances with a view representing all of the object's backing pages 46 - * in a linear fashion. This view will be called a normal view. 47 - * 48 - * To support multiple views of the same object, where the number of mapped 49 - * pages is not equal to the backing store, or where the layout of the pages 50 - * is not linear, concept of a GGTT view was added. 51 - * 52 - * One example of an alternative view is a stereo display driven by a single 53 - * image. In this case we would have a framebuffer looking like this 54 - * (2x2 pages): 55 - * 56 - * 12 57 - * 34 58 - * 59 - * Above would represent a normal GGTT view as normally mapped for GPU or CPU 60 - * rendering. In contrast, fed to the display engine would be an alternative 61 - * view which could look something like this: 62 - * 63 - * 1212 64 - * 3434 65 - * 66 - * In this example both the size and layout of pages in the alternative view is 67 - * different from the normal view. 68 - * 69 - * Implementation and usage 70 - * 71 - * GGTT views are implemented using VMAs and are distinguished via enum 72 - * i915_ggtt_view_type and struct i915_ggtt_view. 73 - * 74 - * A new flavour of core GEM functions which work with GGTT bound objects were 75 - * added with the _ggtt_ infix, and sometimes with _view postfix to avoid 76 - * renaming in large amounts of code. They take the struct i915_ggtt_view 77 - * parameter encapsulating all metadata required to implement a view. 78 - * 79 - * As a helper for callers which are only interested in the normal view, 80 - * globally const i915_ggtt_view_normal singleton instance exists. All old core 81 - * GEM API functions, the ones not taking the view parameter, are operating on, 82 - * or with the normal GGTT view. 83 - * 84 - * Code wanting to add or use a new GGTT view needs to: 85 - * 86 - * 1. Add a new enum with a suitable name. 87 - * 2. Extend the metadata in the i915_ggtt_view structure if required. 88 - * 3. Add support to i915_get_vma_pages(). 89 - * 90 - * New views are required to build a scatter-gather table from within the 91 - * i915_get_vma_pages function. This table is stored in the vma.ggtt_view and 92 - * exists for the lifetime of an VMA. 93 - * 94 - * Core API is designed to have copy semantics which means that passed in 95 - * struct i915_ggtt_view does not need to be persistent (left around after 96 - * calling the core API functions). 97 - * 98 - */ 99 - 100 - #define as_pd(x) container_of((x), typeof(struct i915_page_directory), pt) 101 - 102 - static int 103 - i915_get_ggtt_vma_pages(struct i915_vma *vma); 104 - 105 - static void gen6_ggtt_invalidate(struct i915_ggtt *ggtt) 106 - { 107 - struct intel_uncore *uncore = ggtt->vm.gt->uncore; 108 - 109 - spin_lock_irq(&uncore->lock); 110 - intel_uncore_write_fw(uncore, GFX_FLSH_CNTL_GEN6, GFX_FLSH_CNTL_EN); 111 - intel_uncore_read_fw(uncore, GFX_FLSH_CNTL_GEN6); 112 - spin_unlock_irq(&uncore->lock); 113 - } 114 - 115 - static void gen8_ggtt_invalidate(struct i915_ggtt *ggtt) 116 - { 117 - struct intel_uncore *uncore = ggtt->vm.gt->uncore; 118 - 119 - /* 120 - * Note that as an uncached mmio write, this will flush the 121 - * WCB of the writes into the GGTT before it triggers the invalidate. 122 - */ 123 - intel_uncore_write_fw(uncore, GFX_FLSH_CNTL_GEN6, GFX_FLSH_CNTL_EN); 124 - } 125 - 126 - static void guc_ggtt_invalidate(struct i915_ggtt *ggtt) 127 - { 128 - struct intel_uncore *uncore = ggtt->vm.gt->uncore; 129 - struct drm_i915_private *i915 = ggtt->vm.i915; 130 - 131 - gen8_ggtt_invalidate(ggtt); 132 - 133 - if (INTEL_GEN(i915) >= 12) 134 - intel_uncore_write_fw(uncore, GEN12_GUC_TLB_INV_CR, 135 - GEN12_GUC_TLB_INV_CR_INVALIDATE); 136 - else 137 - intel_uncore_write_fw(uncore, GEN8_GTCR, GEN8_GTCR_INVALIDATE); 138 - } 139 - 140 - static void gmch_ggtt_invalidate(struct i915_ggtt *ggtt) 141 - { 142 - intel_gtt_chipset_flush(); 143 - } 144 - 145 - static int ppgtt_bind_vma(struct i915_vma *vma, 146 - enum i915_cache_level cache_level, 147 - u32 flags) 148 - { 149 - u32 pte_flags; 150 - int err; 151 - 152 - if (flags & I915_VMA_ALLOC) { 153 - err = vma->vm->allocate_va_range(vma->vm, 154 - vma->node.start, vma->size); 155 - if (err) 156 - return err; 157 - 158 - set_bit(I915_VMA_ALLOC_BIT, __i915_vma_flags(vma)); 159 - } 160 - 161 - /* Applicable to VLV, and gen8+ */ 162 - pte_flags = 0; 163 - if (i915_gem_object_is_readonly(vma->obj)) 164 - pte_flags |= PTE_READ_ONLY; 165 - 166 - GEM_BUG_ON(!test_bit(I915_VMA_ALLOC_BIT, __i915_vma_flags(vma))); 167 - vma->vm->insert_entries(vma->vm, vma, cache_level, pte_flags); 168 - wmb(); 169 - 170 - return 0; 171 - } 172 - 173 - static void ppgtt_unbind_vma(struct i915_vma *vma) 174 - { 175 - if (test_and_clear_bit(I915_VMA_ALLOC_BIT, __i915_vma_flags(vma))) 176 - vma->vm->clear_range(vma->vm, vma->node.start, vma->size); 177 - } 178 - 179 - static int ppgtt_set_pages(struct i915_vma *vma) 180 - { 181 - GEM_BUG_ON(vma->pages); 182 - 183 - vma->pages = vma->obj->mm.pages; 184 - 185 - vma->page_sizes = vma->obj->mm.page_sizes; 186 - 187 - return 0; 188 - } 189 - 190 - static void clear_pages(struct i915_vma *vma) 191 - { 192 - GEM_BUG_ON(!vma->pages); 193 - 194 - if (vma->pages != vma->obj->mm.pages) { 195 - sg_free_table(vma->pages); 196 - kfree(vma->pages); 197 - } 198 - vma->pages = NULL; 199 - 200 - memset(&vma->page_sizes, 0, sizeof(vma->page_sizes)); 201 - } 202 - 203 - static u64 gen8_pte_encode(dma_addr_t addr, 204 - enum i915_cache_level level, 205 - u32 flags) 206 - { 207 - gen8_pte_t pte = addr | _PAGE_PRESENT | _PAGE_RW; 208 - 209 - if (unlikely(flags & PTE_READ_ONLY)) 210 - pte &= ~_PAGE_RW; 211 - 212 - switch (level) { 213 - case I915_CACHE_NONE: 214 - pte |= PPAT_UNCACHED; 215 - break; 216 - case I915_CACHE_WT: 217 - pte |= PPAT_DISPLAY_ELLC; 218 - break; 219 - default: 220 - pte |= PPAT_CACHED; 221 - break; 222 - } 223 - 224 - return pte; 225 - } 226 - 227 - static u64 gen8_pde_encode(const dma_addr_t addr, 228 - const enum i915_cache_level level) 229 - { 230 - u64 pde = _PAGE_PRESENT | _PAGE_RW; 231 - pde |= addr; 232 - if (level != I915_CACHE_NONE) 233 - pde |= PPAT_CACHED_PDE; 234 - else 235 - pde |= PPAT_UNCACHED; 236 - return pde; 237 - } 238 - 239 - static u64 snb_pte_encode(dma_addr_t addr, 240 - enum i915_cache_level level, 241 - u32 flags) 242 - { 243 - gen6_pte_t pte = GEN6_PTE_VALID; 244 - pte |= GEN6_PTE_ADDR_ENCODE(addr); 245 - 246 - switch (level) { 247 - case I915_CACHE_L3_LLC: 248 - case I915_CACHE_LLC: 249 - pte |= GEN6_PTE_CACHE_LLC; 250 - break; 251 - case I915_CACHE_NONE: 252 - pte |= GEN6_PTE_UNCACHED; 253 - break; 254 - default: 255 - MISSING_CASE(level); 256 - } 257 - 258 - return pte; 259 - } 260 - 261 - static u64 ivb_pte_encode(dma_addr_t addr, 262 - enum i915_cache_level level, 263 - u32 flags) 264 - { 265 - gen6_pte_t pte = GEN6_PTE_VALID; 266 - pte |= GEN6_PTE_ADDR_ENCODE(addr); 267 - 268 - switch (level) { 269 - case I915_CACHE_L3_LLC: 270 - pte |= GEN7_PTE_CACHE_L3_LLC; 271 - break; 272 - case I915_CACHE_LLC: 273 - pte |= GEN6_PTE_CACHE_LLC; 274 - break; 275 - case I915_CACHE_NONE: 276 - pte |= GEN6_PTE_UNCACHED; 277 - break; 278 - default: 279 - MISSING_CASE(level); 280 - } 281 - 282 - return pte; 283 - } 284 - 285 - static u64 byt_pte_encode(dma_addr_t addr, 286 - enum i915_cache_level level, 287 - u32 flags) 288 - { 289 - gen6_pte_t pte = GEN6_PTE_VALID; 290 - pte |= GEN6_PTE_ADDR_ENCODE(addr); 291 - 292 - if (!(flags & PTE_READ_ONLY)) 293 - pte |= BYT_PTE_WRITEABLE; 294 - 295 - if (level != I915_CACHE_NONE) 296 - pte |= BYT_PTE_SNOOPED_BY_CPU_CACHES; 297 - 298 - return pte; 299 - } 300 - 301 - static u64 hsw_pte_encode(dma_addr_t addr, 302 - enum i915_cache_level level, 303 - u32 flags) 304 - { 305 - gen6_pte_t pte = GEN6_PTE_VALID; 306 - pte |= HSW_PTE_ADDR_ENCODE(addr); 307 - 308 - if (level != I915_CACHE_NONE) 309 - pte |= HSW_WB_LLC_AGE3; 310 - 311 - return pte; 312 - } 313 - 314 - static u64 iris_pte_encode(dma_addr_t addr, 315 - enum i915_cache_level level, 316 - u32 flags) 317 - { 318 - gen6_pte_t pte = GEN6_PTE_VALID; 319 - pte |= HSW_PTE_ADDR_ENCODE(addr); 320 - 321 - switch (level) { 322 - case I915_CACHE_NONE: 323 - break; 324 - case I915_CACHE_WT: 325 - pte |= HSW_WT_ELLC_LLC_AGE3; 326 - break; 327 - default: 328 - pte |= HSW_WB_ELLC_LLC_AGE3; 329 - break; 330 - } 331 - 332 - return pte; 333 - } 334 - 335 - static void stash_init(struct pagestash *stash) 336 - { 337 - pagevec_init(&stash->pvec); 338 - spin_lock_init(&stash->lock); 339 - } 340 - 341 - static struct page *stash_pop_page(struct pagestash *stash) 342 - { 343 - struct page *page = NULL; 344 - 345 - spin_lock(&stash->lock); 346 - if (likely(stash->pvec.nr)) 347 - page = stash->pvec.pages[--stash->pvec.nr]; 348 - spin_unlock(&stash->lock); 349 - 350 - return page; 351 - } 352 - 353 - static void stash_push_pagevec(struct pagestash *stash, struct pagevec *pvec) 354 - { 355 - unsigned int nr; 356 - 357 - spin_lock_nested(&stash->lock, SINGLE_DEPTH_NESTING); 358 - 359 - nr = min_t(typeof(nr), pvec->nr, pagevec_space(&stash->pvec)); 360 - memcpy(stash->pvec.pages + stash->pvec.nr, 361 - pvec->pages + pvec->nr - nr, 362 - sizeof(pvec->pages[0]) * nr); 363 - stash->pvec.nr += nr; 364 - 365 - spin_unlock(&stash->lock); 366 - 367 - pvec->nr -= nr; 368 - } 369 - 370 - static struct page *vm_alloc_page(struct i915_address_space *vm, gfp_t gfp) 371 - { 372 - struct pagevec stack; 373 - struct page *page; 374 - 375 - if (I915_SELFTEST_ONLY(should_fail(&vm->fault_attr, 1))) 376 - i915_gem_shrink_all(vm->i915); 377 - 378 - page = stash_pop_page(&vm->free_pages); 379 - if (page) 380 - return page; 381 - 382 - if (!vm->pt_kmap_wc) 383 - return alloc_page(gfp); 384 - 385 - /* Look in our global stash of WC pages... */ 386 - page = stash_pop_page(&vm->i915->mm.wc_stash); 387 - if (page) 388 - return page; 389 - 390 - /* 391 - * Otherwise batch allocate pages to amortize cost of set_pages_wc. 392 - * 393 - * We have to be careful as page allocation may trigger the shrinker 394 - * (via direct reclaim) which will fill up the WC stash underneath us. 395 - * So we add our WB pages into a temporary pvec on the stack and merge 396 - * them into the WC stash after all the allocations are complete. 397 - */ 398 - pagevec_init(&stack); 399 - do { 400 - struct page *page; 401 - 402 - page = alloc_page(gfp); 403 - if (unlikely(!page)) 404 - break; 405 - 406 - stack.pages[stack.nr++] = page; 407 - } while (pagevec_space(&stack)); 408 - 409 - if (stack.nr && !set_pages_array_wc(stack.pages, stack.nr)) { 410 - page = stack.pages[--stack.nr]; 411 - 412 - /* Merge spare WC pages to the global stash */ 413 - if (stack.nr) 414 - stash_push_pagevec(&vm->i915->mm.wc_stash, &stack); 415 - 416 - /* Push any surplus WC pages onto the local VM stash */ 417 - if (stack.nr) 418 - stash_push_pagevec(&vm->free_pages, &stack); 419 - } 420 - 421 - /* Return unwanted leftovers */ 422 - if (unlikely(stack.nr)) { 423 - WARN_ON_ONCE(set_pages_array_wb(stack.pages, stack.nr)); 424 - __pagevec_release(&stack); 425 - } 426 - 427 - return page; 428 - } 429 - 430 - static void vm_free_pages_release(struct i915_address_space *vm, 431 - bool immediate) 432 - { 433 - struct pagevec *pvec = &vm->free_pages.pvec; 434 - struct pagevec stack; 435 - 436 - lockdep_assert_held(&vm->free_pages.lock); 437 - GEM_BUG_ON(!pagevec_count(pvec)); 438 - 439 - if (vm->pt_kmap_wc) { 440 - /* 441 - * When we use WC, first fill up the global stash and then 442 - * only if full immediately free the overflow. 443 - */ 444 - stash_push_pagevec(&vm->i915->mm.wc_stash, pvec); 445 - 446 - /* 447 - * As we have made some room in the VM's free_pages, 448 - * we can wait for it to fill again. Unless we are 449 - * inside i915_address_space_fini() and must 450 - * immediately release the pages! 451 - */ 452 - if (pvec->nr <= (immediate ? 0 : PAGEVEC_SIZE - 1)) 453 - return; 454 - 455 - /* 456 - * We have to drop the lock to allow ourselves to sleep, 457 - * so take a copy of the pvec and clear the stash for 458 - * others to use it as we sleep. 459 - */ 460 - stack = *pvec; 461 - pagevec_reinit(pvec); 462 - spin_unlock(&vm->free_pages.lock); 463 - 464 - pvec = &stack; 465 - set_pages_array_wb(pvec->pages, pvec->nr); 466 - 467 - spin_lock(&vm->free_pages.lock); 468 - } 469 - 470 - __pagevec_release(pvec); 471 - } 472 - 473 - static void vm_free_page(struct i915_address_space *vm, struct page *page) 474 - { 475 - /* 476 - * On !llc, we need to change the pages back to WB. We only do so 477 - * in bulk, so we rarely need to change the page attributes here, 478 - * but doing so requires a stop_machine() from deep inside arch/x86/mm. 479 - * To make detection of the possible sleep more likely, use an 480 - * unconditional might_sleep() for everybody. 481 - */ 482 - might_sleep(); 483 - spin_lock(&vm->free_pages.lock); 484 - while (!pagevec_space(&vm->free_pages.pvec)) 485 - vm_free_pages_release(vm, false); 486 - GEM_BUG_ON(pagevec_count(&vm->free_pages.pvec) >= PAGEVEC_SIZE); 487 - pagevec_add(&vm->free_pages.pvec, page); 488 - spin_unlock(&vm->free_pages.lock); 489 - } 490 - 491 - static void i915_address_space_fini(struct i915_address_space *vm) 492 - { 493 - spin_lock(&vm->free_pages.lock); 494 - if (pagevec_count(&vm->free_pages.pvec)) 495 - vm_free_pages_release(vm, true); 496 - GEM_BUG_ON(pagevec_count(&vm->free_pages.pvec)); 497 - spin_unlock(&vm->free_pages.lock); 498 - 499 - drm_mm_takedown(&vm->mm); 500 - 501 - mutex_destroy(&vm->mutex); 502 - } 503 - 504 - void __i915_vm_close(struct i915_address_space *vm) 505 - { 506 - struct i915_vma *vma, *vn; 507 - 508 - mutex_lock(&vm->mutex); 509 - list_for_each_entry_safe(vma, vn, &vm->bound_list, vm_link) { 510 - struct drm_i915_gem_object *obj = vma->obj; 511 - 512 - /* Keep the obj (and hence the vma) alive as _we_ destroy it */ 513 - if (!kref_get_unless_zero(&obj->base.refcount)) 514 - continue; 515 - 516 - atomic_and(~I915_VMA_PIN_MASK, &vma->flags); 517 - WARN_ON(__i915_vma_unbind(vma)); 518 - __i915_vma_put(vma); 519 - 520 - i915_gem_object_put(obj); 521 - } 522 - GEM_BUG_ON(!list_empty(&vm->bound_list)); 523 - mutex_unlock(&vm->mutex); 524 - } 525 - 526 - static void __i915_vm_release(struct work_struct *work) 527 - { 528 - struct i915_address_space *vm = 529 - container_of(work, struct i915_address_space, rcu.work); 530 - 531 - vm->cleanup(vm); 532 - i915_address_space_fini(vm); 533 - 534 - kfree(vm); 535 - } 536 - 537 - void i915_vm_release(struct kref *kref) 538 - { 539 - struct i915_address_space *vm = 540 - container_of(kref, struct i915_address_space, ref); 541 - 542 - GEM_BUG_ON(i915_is_ggtt(vm)); 543 - trace_i915_ppgtt_release(vm); 544 - 545 - queue_rcu_work(vm->i915->wq, &vm->rcu); 546 - } 547 - 548 - static void i915_address_space_init(struct i915_address_space *vm, int subclass) 549 - { 550 - kref_init(&vm->ref); 551 - INIT_RCU_WORK(&vm->rcu, __i915_vm_release); 552 - atomic_set(&vm->open, 1); 553 - 554 - /* 555 - * The vm->mutex must be reclaim safe (for use in the shrinker). 556 - * Do a dummy acquire now under fs_reclaim so that any allocation 557 - * attempt holding the lock is immediately reported by lockdep. 558 - */ 559 - mutex_init(&vm->mutex); 560 - lockdep_set_subclass(&vm->mutex, subclass); 561 - i915_gem_shrinker_taints_mutex(vm->i915, &vm->mutex); 562 - 563 - GEM_BUG_ON(!vm->total); 564 - drm_mm_init(&vm->mm, 0, vm->total); 565 - vm->mm.head_node.color = I915_COLOR_UNEVICTABLE; 566 - 567 - stash_init(&vm->free_pages); 568 - 569 - INIT_LIST_HEAD(&vm->bound_list); 570 - } 571 - 572 - static int __setup_page_dma(struct i915_address_space *vm, 573 - struct i915_page_dma *p, 574 - gfp_t gfp) 575 - { 576 - p->page = vm_alloc_page(vm, gfp | I915_GFP_ALLOW_FAIL); 577 - if (unlikely(!p->page)) 578 - return -ENOMEM; 579 - 580 - p->daddr = dma_map_page_attrs(vm->dma, 581 - p->page, 0, PAGE_SIZE, 582 - PCI_DMA_BIDIRECTIONAL, 583 - DMA_ATTR_SKIP_CPU_SYNC | 584 - DMA_ATTR_NO_WARN); 585 - if (unlikely(dma_mapping_error(vm->dma, p->daddr))) { 586 - vm_free_page(vm, p->page); 587 - return -ENOMEM; 588 - } 589 - 590 - return 0; 591 - } 592 - 593 - static int setup_page_dma(struct i915_address_space *vm, 594 - struct i915_page_dma *p) 595 - { 596 - return __setup_page_dma(vm, p, __GFP_HIGHMEM); 597 - } 598 - 599 - static void cleanup_page_dma(struct i915_address_space *vm, 600 - struct i915_page_dma *p) 601 - { 602 - dma_unmap_page(vm->dma, p->daddr, PAGE_SIZE, PCI_DMA_BIDIRECTIONAL); 603 - vm_free_page(vm, p->page); 604 - } 605 - 606 - #define kmap_atomic_px(px) kmap_atomic(px_base(px)->page) 607 - 608 - static void 609 - fill_page_dma(const struct i915_page_dma *p, const u64 val, unsigned int count) 610 - { 611 - kunmap_atomic(memset64(kmap_atomic(p->page), val, count)); 612 - } 613 - 614 - #define fill_px(px, v) fill_page_dma(px_base(px), (v), PAGE_SIZE / sizeof(u64)) 615 - #define fill32_px(px, v) do { \ 616 - u64 v__ = lower_32_bits(v); \ 617 - fill_px((px), v__ << 32 | v__); \ 618 - } while (0) 619 - 620 - static int 621 - setup_scratch_page(struct i915_address_space *vm, gfp_t gfp) 622 - { 623 - unsigned long size; 624 - 625 - /* 626 - * In order to utilize 64K pages for an object with a size < 2M, we will 627 - * need to support a 64K scratch page, given that every 16th entry for a 628 - * page-table operating in 64K mode must point to a properly aligned 64K 629 - * region, including any PTEs which happen to point to scratch. 630 - * 631 - * This is only relevant for the 48b PPGTT where we support 632 - * huge-gtt-pages, see also i915_vma_insert(). However, as we share the 633 - * scratch (read-only) between all vm, we create one 64k scratch page 634 - * for all. 635 - */ 636 - size = I915_GTT_PAGE_SIZE_4K; 637 - if (i915_vm_is_4lvl(vm) && 638 - HAS_PAGE_SIZES(vm->i915, I915_GTT_PAGE_SIZE_64K)) { 639 - size = I915_GTT_PAGE_SIZE_64K; 640 - gfp |= __GFP_NOWARN; 641 - } 642 - gfp |= __GFP_ZERO | __GFP_RETRY_MAYFAIL; 643 - 644 - do { 645 - unsigned int order = get_order(size); 646 - struct page *page; 647 - dma_addr_t addr; 648 - 649 - page = alloc_pages(gfp, order); 650 - if (unlikely(!page)) 651 - goto skip; 652 - 653 - addr = dma_map_page_attrs(vm->dma, 654 - page, 0, size, 655 - PCI_DMA_BIDIRECTIONAL, 656 - DMA_ATTR_SKIP_CPU_SYNC | 657 - DMA_ATTR_NO_WARN); 658 - if (unlikely(dma_mapping_error(vm->dma, addr))) 659 - goto free_page; 660 - 661 - if (unlikely(!IS_ALIGNED(addr, size))) 662 - goto unmap_page; 663 - 664 - vm->scratch[0].base.page = page; 665 - vm->scratch[0].base.daddr = addr; 666 - vm->scratch_order = order; 667 - return 0; 668 - 669 - unmap_page: 670 - dma_unmap_page(vm->dma, addr, size, PCI_DMA_BIDIRECTIONAL); 671 - free_page: 672 - __free_pages(page, order); 673 - skip: 674 - if (size == I915_GTT_PAGE_SIZE_4K) 675 - return -ENOMEM; 676 - 677 - size = I915_GTT_PAGE_SIZE_4K; 678 - gfp &= ~__GFP_NOWARN; 679 - } while (1); 680 - } 681 - 682 - static void cleanup_scratch_page(struct i915_address_space *vm) 683 - { 684 - struct i915_page_dma *p = px_base(&vm->scratch[0]); 685 - unsigned int order = vm->scratch_order; 686 - 687 - dma_unmap_page(vm->dma, p->daddr, BIT(order) << PAGE_SHIFT, 688 - PCI_DMA_BIDIRECTIONAL); 689 - __free_pages(p->page, order); 690 - } 691 - 692 - static void free_scratch(struct i915_address_space *vm) 693 - { 694 - int i; 695 - 696 - if (!px_dma(&vm->scratch[0])) /* set to 0 on clones */ 697 - return; 698 - 699 - for (i = 1; i <= vm->top; i++) { 700 - if (!px_dma(&vm->scratch[i])) 701 - break; 702 - cleanup_page_dma(vm, px_base(&vm->scratch[i])); 703 - } 704 - 705 - cleanup_scratch_page(vm); 706 - } 707 - 708 - static struct i915_page_table *alloc_pt(struct i915_address_space *vm) 709 - { 710 - struct i915_page_table *pt; 711 - 712 - pt = kmalloc(sizeof(*pt), I915_GFP_ALLOW_FAIL); 713 - if (unlikely(!pt)) 714 - return ERR_PTR(-ENOMEM); 715 - 716 - if (unlikely(setup_page_dma(vm, &pt->base))) { 717 - kfree(pt); 718 - return ERR_PTR(-ENOMEM); 719 - } 720 - 721 - atomic_set(&pt->used, 0); 722 - return pt; 723 - } 724 - 725 - static struct i915_page_directory *__alloc_pd(size_t sz) 726 - { 727 - struct i915_page_directory *pd; 728 - 729 - pd = kzalloc(sz, I915_GFP_ALLOW_FAIL); 730 - if (unlikely(!pd)) 731 - return NULL; 732 - 733 - spin_lock_init(&pd->lock); 734 - return pd; 735 - } 736 - 737 - static struct i915_page_directory *alloc_pd(struct i915_address_space *vm) 738 - { 739 - struct i915_page_directory *pd; 740 - 741 - pd = __alloc_pd(sizeof(*pd)); 742 - if (unlikely(!pd)) 743 - return ERR_PTR(-ENOMEM); 744 - 745 - if (unlikely(setup_page_dma(vm, px_base(pd)))) { 746 - kfree(pd); 747 - return ERR_PTR(-ENOMEM); 748 - } 749 - 750 - return pd; 751 - } 752 - 753 - static void free_pd(struct i915_address_space *vm, struct i915_page_dma *pd) 754 - { 755 - cleanup_page_dma(vm, pd); 756 - kfree(pd); 757 - } 758 - 759 - #define free_px(vm, px) free_pd(vm, px_base(px)) 760 - 761 - static inline void 762 - write_dma_entry(struct i915_page_dma * const pdma, 763 - const unsigned short idx, 764 - const u64 encoded_entry) 765 - { 766 - u64 * const vaddr = kmap_atomic(pdma->page); 767 - 768 - vaddr[idx] = encoded_entry; 769 - kunmap_atomic(vaddr); 770 - } 771 - 772 - static inline void 773 - __set_pd_entry(struct i915_page_directory * const pd, 774 - const unsigned short idx, 775 - struct i915_page_dma * const to, 776 - u64 (*encode)(const dma_addr_t, const enum i915_cache_level)) 777 - { 778 - /* Each thread pre-pins the pd, and we may have a thread per pde. */ 779 - GEM_BUG_ON(atomic_read(px_used(pd)) > NALLOC * ARRAY_SIZE(pd->entry)); 780 - 781 - atomic_inc(px_used(pd)); 782 - pd->entry[idx] = to; 783 - write_dma_entry(px_base(pd), idx, encode(to->daddr, I915_CACHE_LLC)); 784 - } 785 - 786 - #define set_pd_entry(pd, idx, to) \ 787 - __set_pd_entry((pd), (idx), px_base(to), gen8_pde_encode) 788 - 789 - static inline void 790 - clear_pd_entry(struct i915_page_directory * const pd, 791 - const unsigned short idx, 792 - const struct i915_page_scratch * const scratch) 793 - { 794 - GEM_BUG_ON(atomic_read(px_used(pd)) == 0); 795 - 796 - write_dma_entry(px_base(pd), idx, scratch->encode); 797 - pd->entry[idx] = NULL; 798 - atomic_dec(px_used(pd)); 799 - } 800 - 801 - static bool 802 - release_pd_entry(struct i915_page_directory * const pd, 803 - const unsigned short idx, 804 - struct i915_page_table * const pt, 805 - const struct i915_page_scratch * const scratch) 806 - { 807 - bool free = false; 808 - 809 - if (atomic_add_unless(&pt->used, -1, 1)) 810 - return false; 811 - 812 - spin_lock(&pd->lock); 813 - if (atomic_dec_and_test(&pt->used)) { 814 - clear_pd_entry(pd, idx, scratch); 815 - free = true; 816 - } 817 - spin_unlock(&pd->lock); 818 - 819 - return free; 820 - } 821 - 822 - static void gen8_ppgtt_notify_vgt(struct i915_ppgtt *ppgtt, bool create) 823 - { 824 - struct drm_i915_private *dev_priv = ppgtt->vm.i915; 825 - enum vgt_g2v_type msg; 826 - int i; 827 - 828 - if (create) 829 - atomic_inc(px_used(ppgtt->pd)); /* never remove */ 830 - else 831 - atomic_dec(px_used(ppgtt->pd)); 832 - 833 - mutex_lock(&dev_priv->vgpu.lock); 834 - 835 - if (i915_vm_is_4lvl(&ppgtt->vm)) { 836 - const u64 daddr = px_dma(ppgtt->pd); 837 - 838 - I915_WRITE(vgtif_reg(pdp[0].lo), lower_32_bits(daddr)); 839 - I915_WRITE(vgtif_reg(pdp[0].hi), upper_32_bits(daddr)); 840 - 841 - msg = (create ? VGT_G2V_PPGTT_L4_PAGE_TABLE_CREATE : 842 - VGT_G2V_PPGTT_L4_PAGE_TABLE_DESTROY); 843 - } else { 844 - for (i = 0; i < GEN8_3LVL_PDPES; i++) { 845 - const u64 daddr = i915_page_dir_dma_addr(ppgtt, i); 846 - 847 - I915_WRITE(vgtif_reg(pdp[i].lo), lower_32_bits(daddr)); 848 - I915_WRITE(vgtif_reg(pdp[i].hi), upper_32_bits(daddr)); 849 - } 850 - 851 - msg = (create ? VGT_G2V_PPGTT_L3_PAGE_TABLE_CREATE : 852 - VGT_G2V_PPGTT_L3_PAGE_TABLE_DESTROY); 853 - } 854 - 855 - /* g2v_notify atomically (via hv trap) consumes the message packet. */ 856 - I915_WRITE(vgtif_reg(g2v_notify), msg); 857 - 858 - mutex_unlock(&dev_priv->vgpu.lock); 859 - } 860 - 861 - /* Index shifts into the pagetable are offset by GEN8_PTE_SHIFT [12] */ 862 - #define GEN8_PAGE_SIZE (SZ_4K) /* page and page-directory sizes are the same */ 863 - #define GEN8_PTE_SHIFT (ilog2(GEN8_PAGE_SIZE)) 864 - #define GEN8_PDES (GEN8_PAGE_SIZE / sizeof(u64)) 865 - #define gen8_pd_shift(lvl) ((lvl) * ilog2(GEN8_PDES)) 866 - #define gen8_pd_index(i, lvl) i915_pde_index((i), gen8_pd_shift(lvl)) 867 - #define __gen8_pte_shift(lvl) (GEN8_PTE_SHIFT + gen8_pd_shift(lvl)) 868 - #define __gen8_pte_index(a, lvl) i915_pde_index((a), __gen8_pte_shift(lvl)) 869 - 870 - static inline unsigned int 871 - gen8_pd_range(u64 start, u64 end, int lvl, unsigned int *idx) 872 - { 873 - const int shift = gen8_pd_shift(lvl); 874 - const u64 mask = ~0ull << gen8_pd_shift(lvl + 1); 875 - 876 - GEM_BUG_ON(start >= end); 877 - end += ~mask >> gen8_pd_shift(1); 878 - 879 - *idx = i915_pde_index(start, shift); 880 - if ((start ^ end) & mask) 881 - return GEN8_PDES - *idx; 882 - else 883 - return i915_pde_index(end, shift) - *idx; 884 - } 885 - 886 - static inline bool gen8_pd_contains(u64 start, u64 end, int lvl) 887 - { 888 - const u64 mask = ~0ull << gen8_pd_shift(lvl + 1); 889 - 890 - GEM_BUG_ON(start >= end); 891 - return (start ^ end) & mask && (start & ~mask) == 0; 892 - } 893 - 894 - static inline unsigned int gen8_pt_count(u64 start, u64 end) 895 - { 896 - GEM_BUG_ON(start >= end); 897 - if ((start ^ end) >> gen8_pd_shift(1)) 898 - return GEN8_PDES - (start & (GEN8_PDES - 1)); 899 - else 900 - return end - start; 901 - } 902 - 903 - static inline unsigned int gen8_pd_top_count(const struct i915_address_space *vm) 904 - { 905 - unsigned int shift = __gen8_pte_shift(vm->top); 906 - return (vm->total + (1ull << shift) - 1) >> shift; 907 - } 908 - 909 - static inline struct i915_page_directory * 910 - gen8_pdp_for_page_index(struct i915_address_space * const vm, const u64 idx) 911 - { 912 - struct i915_ppgtt * const ppgtt = i915_vm_to_ppgtt(vm); 913 - 914 - if (vm->top == 2) 915 - return ppgtt->pd; 916 - else 917 - return i915_pd_entry(ppgtt->pd, gen8_pd_index(idx, vm->top)); 918 - } 919 - 920 - static inline struct i915_page_directory * 921 - gen8_pdp_for_page_address(struct i915_address_space * const vm, const u64 addr) 922 - { 923 - return gen8_pdp_for_page_index(vm, addr >> GEN8_PTE_SHIFT); 924 - } 925 - 926 - static void __gen8_ppgtt_cleanup(struct i915_address_space *vm, 927 - struct i915_page_directory *pd, 928 - int count, int lvl) 929 - { 930 - if (lvl) { 931 - void **pde = pd->entry; 932 - 933 - do { 934 - if (!*pde) 935 - continue; 936 - 937 - __gen8_ppgtt_cleanup(vm, *pde, GEN8_PDES, lvl - 1); 938 - } while (pde++, --count); 939 - } 940 - 941 - free_px(vm, pd); 942 - } 943 - 944 - static void gen8_ppgtt_cleanup(struct i915_address_space *vm) 945 - { 946 - struct i915_ppgtt *ppgtt = i915_vm_to_ppgtt(vm); 947 - 948 - if (intel_vgpu_active(vm->i915)) 949 - gen8_ppgtt_notify_vgt(ppgtt, false); 950 - 951 - __gen8_ppgtt_cleanup(vm, ppgtt->pd, gen8_pd_top_count(vm), vm->top); 952 - free_scratch(vm); 953 - } 954 - 955 - static u64 __gen8_ppgtt_clear(struct i915_address_space * const vm, 956 - struct i915_page_directory * const pd, 957 - u64 start, const u64 end, int lvl) 958 - { 959 - const struct i915_page_scratch * const scratch = &vm->scratch[lvl]; 960 - unsigned int idx, len; 961 - 962 - GEM_BUG_ON(end > vm->total >> GEN8_PTE_SHIFT); 963 - 964 - len = gen8_pd_range(start, end, lvl--, &idx); 965 - DBG("%s(%p):{ lvl:%d, start:%llx, end:%llx, idx:%d, len:%d, used:%d }\n", 966 - __func__, vm, lvl + 1, start, end, 967 - idx, len, atomic_read(px_used(pd))); 968 - GEM_BUG_ON(!len || len >= atomic_read(px_used(pd))); 969 - 970 - do { 971 - struct i915_page_table *pt = pd->entry[idx]; 972 - 973 - if (atomic_fetch_inc(&pt->used) >> gen8_pd_shift(1) && 974 - gen8_pd_contains(start, end, lvl)) { 975 - DBG("%s(%p):{ lvl:%d, idx:%d, start:%llx, end:%llx } removing pd\n", 976 - __func__, vm, lvl + 1, idx, start, end); 977 - clear_pd_entry(pd, idx, scratch); 978 - __gen8_ppgtt_cleanup(vm, as_pd(pt), I915_PDES, lvl); 979 - start += (u64)I915_PDES << gen8_pd_shift(lvl); 980 - continue; 981 - } 982 - 983 - if (lvl) { 984 - start = __gen8_ppgtt_clear(vm, as_pd(pt), 985 - start, end, lvl); 986 - } else { 987 - unsigned int count; 988 - u64 *vaddr; 989 - 990 - count = gen8_pt_count(start, end); 991 - DBG("%s(%p):{ lvl:%d, start:%llx, end:%llx, idx:%d, len:%d, used:%d } removing pte\n", 992 - __func__, vm, lvl, start, end, 993 - gen8_pd_index(start, 0), count, 994 - atomic_read(&pt->used)); 995 - GEM_BUG_ON(!count || count >= atomic_read(&pt->used)); 996 - 997 - vaddr = kmap_atomic_px(pt); 998 - memset64(vaddr + gen8_pd_index(start, 0), 999 - vm->scratch[0].encode, 1000 - count); 1001 - kunmap_atomic(vaddr); 1002 - 1003 - atomic_sub(count, &pt->used); 1004 - start += count; 1005 - } 1006 - 1007 - if (release_pd_entry(pd, idx, pt, scratch)) 1008 - free_px(vm, pt); 1009 - } while (idx++, --len); 1010 - 1011 - return start; 1012 - } 1013 - 1014 - static void gen8_ppgtt_clear(struct i915_address_space *vm, 1015 - u64 start, u64 length) 1016 - { 1017 - GEM_BUG_ON(!IS_ALIGNED(start, BIT_ULL(GEN8_PTE_SHIFT))); 1018 - GEM_BUG_ON(!IS_ALIGNED(length, BIT_ULL(GEN8_PTE_SHIFT))); 1019 - GEM_BUG_ON(range_overflows(start, length, vm->total)); 1020 - 1021 - start >>= GEN8_PTE_SHIFT; 1022 - length >>= GEN8_PTE_SHIFT; 1023 - GEM_BUG_ON(length == 0); 1024 - 1025 - __gen8_ppgtt_clear(vm, i915_vm_to_ppgtt(vm)->pd, 1026 - start, start + length, vm->top); 1027 - } 1028 - 1029 - static int __gen8_ppgtt_alloc(struct i915_address_space * const vm, 1030 - struct i915_page_directory * const pd, 1031 - u64 * const start, const u64 end, int lvl) 1032 - { 1033 - const struct i915_page_scratch * const scratch = &vm->scratch[lvl]; 1034 - struct i915_page_table *alloc = NULL; 1035 - unsigned int idx, len; 1036 - int ret = 0; 1037 - 1038 - GEM_BUG_ON(end > vm->total >> GEN8_PTE_SHIFT); 1039 - 1040 - len = gen8_pd_range(*start, end, lvl--, &idx); 1041 - DBG("%s(%p):{ lvl:%d, start:%llx, end:%llx, idx:%d, len:%d, used:%d }\n", 1042 - __func__, vm, lvl + 1, *start, end, 1043 - idx, len, atomic_read(px_used(pd))); 1044 - GEM_BUG_ON(!len || (idx + len - 1) >> gen8_pd_shift(1)); 1045 - 1046 - spin_lock(&pd->lock); 1047 - GEM_BUG_ON(!atomic_read(px_used(pd))); /* Must be pinned! */ 1048 - do { 1049 - struct i915_page_table *pt = pd->entry[idx]; 1050 - 1051 - if (!pt) { 1052 - spin_unlock(&pd->lock); 1053 - 1054 - DBG("%s(%p):{ lvl:%d, idx:%d } allocating new tree\n", 1055 - __func__, vm, lvl + 1, idx); 1056 - 1057 - pt = fetch_and_zero(&alloc); 1058 - if (lvl) { 1059 - if (!pt) { 1060 - pt = &alloc_pd(vm)->pt; 1061 - if (IS_ERR(pt)) { 1062 - ret = PTR_ERR(pt); 1063 - goto out; 1064 - } 1065 - } 1066 - 1067 - fill_px(pt, vm->scratch[lvl].encode); 1068 - } else { 1069 - if (!pt) { 1070 - pt = alloc_pt(vm); 1071 - if (IS_ERR(pt)) { 1072 - ret = PTR_ERR(pt); 1073 - goto out; 1074 - } 1075 - } 1076 - 1077 - if (intel_vgpu_active(vm->i915) || 1078 - gen8_pt_count(*start, end) < I915_PDES) 1079 - fill_px(pt, vm->scratch[lvl].encode); 1080 - } 1081 - 1082 - spin_lock(&pd->lock); 1083 - if (likely(!pd->entry[idx])) 1084 - set_pd_entry(pd, idx, pt); 1085 - else 1086 - alloc = pt, pt = pd->entry[idx]; 1087 - } 1088 - 1089 - if (lvl) { 1090 - atomic_inc(&pt->used); 1091 - spin_unlock(&pd->lock); 1092 - 1093 - ret = __gen8_ppgtt_alloc(vm, as_pd(pt), 1094 - start, end, lvl); 1095 - if (unlikely(ret)) { 1096 - if (release_pd_entry(pd, idx, pt, scratch)) 1097 - free_px(vm, pt); 1098 - goto out; 1099 - } 1100 - 1101 - spin_lock(&pd->lock); 1102 - atomic_dec(&pt->used); 1103 - GEM_BUG_ON(!atomic_read(&pt->used)); 1104 - } else { 1105 - unsigned int count = gen8_pt_count(*start, end); 1106 - 1107 - DBG("%s(%p):{ lvl:%d, start:%llx, end:%llx, idx:%d, len:%d, used:%d } inserting pte\n", 1108 - __func__, vm, lvl, *start, end, 1109 - gen8_pd_index(*start, 0), count, 1110 - atomic_read(&pt->used)); 1111 - 1112 - atomic_add(count, &pt->used); 1113 - /* All other pdes may be simultaneously removed */ 1114 - GEM_BUG_ON(atomic_read(&pt->used) > NALLOC * I915_PDES); 1115 - *start += count; 1116 - } 1117 - } while (idx++, --len); 1118 - spin_unlock(&pd->lock); 1119 - out: 1120 - if (alloc) 1121 - free_px(vm, alloc); 1122 - return ret; 1123 - } 1124 - 1125 - static int gen8_ppgtt_alloc(struct i915_address_space *vm, 1126 - u64 start, u64 length) 1127 - { 1128 - u64 from; 1129 - int err; 1130 - 1131 - GEM_BUG_ON(!IS_ALIGNED(start, BIT_ULL(GEN8_PTE_SHIFT))); 1132 - GEM_BUG_ON(!IS_ALIGNED(length, BIT_ULL(GEN8_PTE_SHIFT))); 1133 - GEM_BUG_ON(range_overflows(start, length, vm->total)); 1134 - 1135 - start >>= GEN8_PTE_SHIFT; 1136 - length >>= GEN8_PTE_SHIFT; 1137 - GEM_BUG_ON(length == 0); 1138 - from = start; 1139 - 1140 - err = __gen8_ppgtt_alloc(vm, i915_vm_to_ppgtt(vm)->pd, 1141 - &start, start + length, vm->top); 1142 - if (unlikely(err && from != start)) 1143 - __gen8_ppgtt_clear(vm, i915_vm_to_ppgtt(vm)->pd, 1144 - from, start, vm->top); 1145 - 1146 - return err; 1147 - } 1148 - 1149 - static inline struct sgt_dma { 1150 - struct scatterlist *sg; 1151 - dma_addr_t dma, max; 1152 - } sgt_dma(struct i915_vma *vma) { 1153 - struct scatterlist *sg = vma->pages->sgl; 1154 - dma_addr_t addr = sg_dma_address(sg); 1155 - return (struct sgt_dma) { sg, addr, addr + sg->length }; 1156 - } 1157 - 1158 - static __always_inline u64 1159 - gen8_ppgtt_insert_pte(struct i915_ppgtt *ppgtt, 1160 - struct i915_page_directory *pdp, 1161 - struct sgt_dma *iter, 1162 - u64 idx, 1163 - enum i915_cache_level cache_level, 1164 - u32 flags) 1165 - { 1166 - struct i915_page_directory *pd; 1167 - const gen8_pte_t pte_encode = gen8_pte_encode(0, cache_level, flags); 1168 - gen8_pte_t *vaddr; 1169 - 1170 - pd = i915_pd_entry(pdp, gen8_pd_index(idx, 2)); 1171 - vaddr = kmap_atomic_px(i915_pt_entry(pd, gen8_pd_index(idx, 1))); 1172 - do { 1173 - vaddr[gen8_pd_index(idx, 0)] = pte_encode | iter->dma; 1174 - 1175 - iter->dma += I915_GTT_PAGE_SIZE; 1176 - if (iter->dma >= iter->max) { 1177 - iter->sg = __sg_next(iter->sg); 1178 - if (!iter->sg) { 1179 - idx = 0; 1180 - break; 1181 - } 1182 - 1183 - iter->dma = sg_dma_address(iter->sg); 1184 - iter->max = iter->dma + iter->sg->length; 1185 - } 1186 - 1187 - if (gen8_pd_index(++idx, 0) == 0) { 1188 - if (gen8_pd_index(idx, 1) == 0) { 1189 - /* Limited by sg length for 3lvl */ 1190 - if (gen8_pd_index(idx, 2) == 0) 1191 - break; 1192 - 1193 - pd = pdp->entry[gen8_pd_index(idx, 2)]; 1194 - } 1195 - 1196 - kunmap_atomic(vaddr); 1197 - vaddr = kmap_atomic_px(i915_pt_entry(pd, gen8_pd_index(idx, 1))); 1198 - } 1199 - } while (1); 1200 - kunmap_atomic(vaddr); 1201 - 1202 - return idx; 1203 - } 1204 - 1205 - static void gen8_ppgtt_insert_huge(struct i915_vma *vma, 1206 - struct sgt_dma *iter, 1207 - enum i915_cache_level cache_level, 1208 - u32 flags) 1209 - { 1210 - const gen8_pte_t pte_encode = gen8_pte_encode(0, cache_level, flags); 1211 - u64 start = vma->node.start; 1212 - dma_addr_t rem = iter->sg->length; 1213 - 1214 - GEM_BUG_ON(!i915_vm_is_4lvl(vma->vm)); 1215 - 1216 - do { 1217 - struct i915_page_directory * const pdp = 1218 - gen8_pdp_for_page_address(vma->vm, start); 1219 - struct i915_page_directory * const pd = 1220 - i915_pd_entry(pdp, __gen8_pte_index(start, 2)); 1221 - gen8_pte_t encode = pte_encode; 1222 - unsigned int maybe_64K = -1; 1223 - unsigned int page_size; 1224 - gen8_pte_t *vaddr; 1225 - u16 index; 1226 - 1227 - if (vma->page_sizes.sg & I915_GTT_PAGE_SIZE_2M && 1228 - IS_ALIGNED(iter->dma, I915_GTT_PAGE_SIZE_2M) && 1229 - rem >= I915_GTT_PAGE_SIZE_2M && 1230 - !__gen8_pte_index(start, 0)) { 1231 - index = __gen8_pte_index(start, 1); 1232 - encode |= GEN8_PDE_PS_2M; 1233 - page_size = I915_GTT_PAGE_SIZE_2M; 1234 - 1235 - vaddr = kmap_atomic_px(pd); 1236 - } else { 1237 - struct i915_page_table *pt = 1238 - i915_pt_entry(pd, __gen8_pte_index(start, 1)); 1239 - 1240 - index = __gen8_pte_index(start, 0); 1241 - page_size = I915_GTT_PAGE_SIZE; 1242 - 1243 - if (!index && 1244 - vma->page_sizes.sg & I915_GTT_PAGE_SIZE_64K && 1245 - IS_ALIGNED(iter->dma, I915_GTT_PAGE_SIZE_64K) && 1246 - (IS_ALIGNED(rem, I915_GTT_PAGE_SIZE_64K) || 1247 - rem >= (I915_PDES - index) * I915_GTT_PAGE_SIZE)) 1248 - maybe_64K = __gen8_pte_index(start, 1); 1249 - 1250 - vaddr = kmap_atomic_px(pt); 1251 - } 1252 - 1253 - do { 1254 - GEM_BUG_ON(iter->sg->length < page_size); 1255 - vaddr[index++] = encode | iter->dma; 1256 - 1257 - start += page_size; 1258 - iter->dma += page_size; 1259 - rem -= page_size; 1260 - if (iter->dma >= iter->max) { 1261 - iter->sg = __sg_next(iter->sg); 1262 - if (!iter->sg) 1263 - break; 1264 - 1265 - rem = iter->sg->length; 1266 - iter->dma = sg_dma_address(iter->sg); 1267 - iter->max = iter->dma + rem; 1268 - 1269 - if (maybe_64K != -1 && index < I915_PDES && 1270 - !(IS_ALIGNED(iter->dma, I915_GTT_PAGE_SIZE_64K) && 1271 - (IS_ALIGNED(rem, I915_GTT_PAGE_SIZE_64K) || 1272 - rem >= (I915_PDES - index) * I915_GTT_PAGE_SIZE))) 1273 - maybe_64K = -1; 1274 - 1275 - if (unlikely(!IS_ALIGNED(iter->dma, page_size))) 1276 - break; 1277 - } 1278 - } while (rem >= page_size && index < I915_PDES); 1279 - 1280 - kunmap_atomic(vaddr); 1281 - 1282 - /* 1283 - * Is it safe to mark the 2M block as 64K? -- Either we have 1284 - * filled whole page-table with 64K entries, or filled part of 1285 - * it and have reached the end of the sg table and we have 1286 - * enough padding. 1287 - */ 1288 - if (maybe_64K != -1 && 1289 - (index == I915_PDES || 1290 - (i915_vm_has_scratch_64K(vma->vm) && 1291 - !iter->sg && IS_ALIGNED(vma->node.start + 1292 - vma->node.size, 1293 - I915_GTT_PAGE_SIZE_2M)))) { 1294 - vaddr = kmap_atomic_px(pd); 1295 - vaddr[maybe_64K] |= GEN8_PDE_IPS_64K; 1296 - kunmap_atomic(vaddr); 1297 - page_size = I915_GTT_PAGE_SIZE_64K; 1298 - 1299 - /* 1300 - * We write all 4K page entries, even when using 64K 1301 - * pages. In order to verify that the HW isn't cheating 1302 - * by using the 4K PTE instead of the 64K PTE, we want 1303 - * to remove all the surplus entries. If the HW skipped 1304 - * the 64K PTE, it will read/write into the scratch page 1305 - * instead - which we detect as missing results during 1306 - * selftests. 1307 - */ 1308 - if (I915_SELFTEST_ONLY(vma->vm->scrub_64K)) { 1309 - u16 i; 1310 - 1311 - encode = vma->vm->scratch[0].encode; 1312 - vaddr = kmap_atomic_px(i915_pt_entry(pd, maybe_64K)); 1313 - 1314 - for (i = 1; i < index; i += 16) 1315 - memset64(vaddr + i, encode, 15); 1316 - 1317 - kunmap_atomic(vaddr); 1318 - } 1319 - } 1320 - 1321 - vma->page_sizes.gtt |= page_size; 1322 - } while (iter->sg); 1323 - } 1324 - 1325 - static void gen8_ppgtt_insert(struct i915_address_space *vm, 1326 - struct i915_vma *vma, 1327 - enum i915_cache_level cache_level, 1328 - u32 flags) 1329 - { 1330 - struct i915_ppgtt * const ppgtt = i915_vm_to_ppgtt(vm); 1331 - struct sgt_dma iter = sgt_dma(vma); 1332 - 1333 - if (vma->page_sizes.sg > I915_GTT_PAGE_SIZE) { 1334 - gen8_ppgtt_insert_huge(vma, &iter, cache_level, flags); 1335 - } else { 1336 - u64 idx = vma->node.start >> GEN8_PTE_SHIFT; 1337 - 1338 - do { 1339 - struct i915_page_directory * const pdp = 1340 - gen8_pdp_for_page_index(vm, idx); 1341 - 1342 - idx = gen8_ppgtt_insert_pte(ppgtt, pdp, &iter, idx, 1343 - cache_level, flags); 1344 - } while (idx); 1345 - 1346 - vma->page_sizes.gtt = I915_GTT_PAGE_SIZE; 1347 - } 1348 - } 1349 - 1350 - static int gen8_init_scratch(struct i915_address_space *vm) 1351 - { 1352 - int ret; 1353 - int i; 1354 - 1355 - /* 1356 - * If everybody agrees to not to write into the scratch page, 1357 - * we can reuse it for all vm, keeping contexts and processes separate. 1358 - */ 1359 - if (vm->has_read_only && vm->gt->vm && !i915_is_ggtt(vm->gt->vm)) { 1360 - struct i915_address_space *clone = vm->gt->vm; 1361 - 1362 - GEM_BUG_ON(!clone->has_read_only); 1363 - 1364 - vm->scratch_order = clone->scratch_order; 1365 - memcpy(vm->scratch, clone->scratch, sizeof(vm->scratch)); 1366 - px_dma(&vm->scratch[0]) = 0; /* no xfer of ownership */ 1367 - return 0; 1368 - } 1369 - 1370 - ret = setup_scratch_page(vm, __GFP_HIGHMEM); 1371 - if (ret) 1372 - return ret; 1373 - 1374 - vm->scratch[0].encode = 1375 - gen8_pte_encode(px_dma(&vm->scratch[0]), 1376 - I915_CACHE_LLC, vm->has_read_only); 1377 - 1378 - for (i = 1; i <= vm->top; i++) { 1379 - if (unlikely(setup_page_dma(vm, px_base(&vm->scratch[i])))) 1380 - goto free_scratch; 1381 - 1382 - fill_px(&vm->scratch[i], vm->scratch[i - 1].encode); 1383 - vm->scratch[i].encode = 1384 - gen8_pde_encode(px_dma(&vm->scratch[i]), 1385 - I915_CACHE_LLC); 1386 - } 1387 - 1388 - return 0; 1389 - 1390 - free_scratch: 1391 - free_scratch(vm); 1392 - return -ENOMEM; 1393 - } 1394 - 1395 - static int gen8_preallocate_top_level_pdp(struct i915_ppgtt *ppgtt) 1396 - { 1397 - struct i915_address_space *vm = &ppgtt->vm; 1398 - struct i915_page_directory *pd = ppgtt->pd; 1399 - unsigned int idx; 1400 - 1401 - GEM_BUG_ON(vm->top != 2); 1402 - GEM_BUG_ON(gen8_pd_top_count(vm) != GEN8_3LVL_PDPES); 1403 - 1404 - for (idx = 0; idx < GEN8_3LVL_PDPES; idx++) { 1405 - struct i915_page_directory *pde; 1406 - 1407 - pde = alloc_pd(vm); 1408 - if (IS_ERR(pde)) 1409 - return PTR_ERR(pde); 1410 - 1411 - fill_px(pde, vm->scratch[1].encode); 1412 - set_pd_entry(pd, idx, pde); 1413 - atomic_inc(px_used(pde)); /* keep pinned */ 1414 - } 1415 - wmb(); 1416 - 1417 - return 0; 1418 - } 1419 - 1420 - static void ppgtt_init(struct i915_ppgtt *ppgtt, struct intel_gt *gt) 1421 - { 1422 - struct drm_i915_private *i915 = gt->i915; 1423 - 1424 - ppgtt->vm.gt = gt; 1425 - ppgtt->vm.i915 = i915; 1426 - ppgtt->vm.dma = &i915->drm.pdev->dev; 1427 - ppgtt->vm.total = BIT_ULL(INTEL_INFO(i915)->ppgtt_size); 1428 - 1429 - i915_address_space_init(&ppgtt->vm, VM_CLASS_PPGTT); 1430 - 1431 - ppgtt->vm.vma_ops.bind_vma = ppgtt_bind_vma; 1432 - ppgtt->vm.vma_ops.unbind_vma = ppgtt_unbind_vma; 1433 - ppgtt->vm.vma_ops.set_pages = ppgtt_set_pages; 1434 - ppgtt->vm.vma_ops.clear_pages = clear_pages; 1435 - } 1436 - 1437 - static struct i915_page_directory * 1438 - gen8_alloc_top_pd(struct i915_address_space *vm) 1439 - { 1440 - const unsigned int count = gen8_pd_top_count(vm); 1441 - struct i915_page_directory *pd; 1442 - 1443 - GEM_BUG_ON(count > ARRAY_SIZE(pd->entry)); 1444 - 1445 - pd = __alloc_pd(offsetof(typeof(*pd), entry[count])); 1446 - if (unlikely(!pd)) 1447 - return ERR_PTR(-ENOMEM); 1448 - 1449 - if (unlikely(setup_page_dma(vm, px_base(pd)))) { 1450 - kfree(pd); 1451 - return ERR_PTR(-ENOMEM); 1452 - } 1453 - 1454 - fill_page_dma(px_base(pd), vm->scratch[vm->top].encode, count); 1455 - atomic_inc(px_used(pd)); /* mark as pinned */ 1456 - return pd; 1457 - } 1458 - 1459 - /* 1460 - * GEN8 legacy ppgtt programming is accomplished through a max 4 PDP registers 1461 - * with a net effect resembling a 2-level page table in normal x86 terms. Each 1462 - * PDP represents 1GB of memory 4 * 512 * 512 * 4096 = 4GB legacy 32b address 1463 - * space. 1464 - * 1465 - */ 1466 - static struct i915_ppgtt *gen8_ppgtt_create(struct drm_i915_private *i915) 1467 - { 1468 - struct i915_ppgtt *ppgtt; 1469 - int err; 1470 - 1471 - ppgtt = kzalloc(sizeof(*ppgtt), GFP_KERNEL); 1472 - if (!ppgtt) 1473 - return ERR_PTR(-ENOMEM); 1474 - 1475 - ppgtt_init(ppgtt, &i915->gt); 1476 - ppgtt->vm.top = i915_vm_is_4lvl(&ppgtt->vm) ? 3 : 2; 1477 - 1478 - /* 1479 - * From bdw, there is hw support for read-only pages in the PPGTT. 1480 - * 1481 - * Gen11 has HSDES#:1807136187 unresolved. Disable ro support 1482 - * for now. 1483 - * 1484 - * Gen12 has inherited the same read-only fault issue from gen11. 1485 - */ 1486 - ppgtt->vm.has_read_only = !IS_GEN_RANGE(i915, 11, 12); 1487 - 1488 - /* There are only few exceptions for gen >=6. chv and bxt. 1489 - * And we are not sure about the latter so play safe for now. 1490 - */ 1491 - if (IS_CHERRYVIEW(i915) || IS_BROXTON(i915)) 1492 - ppgtt->vm.pt_kmap_wc = true; 1493 - 1494 - err = gen8_init_scratch(&ppgtt->vm); 1495 - if (err) 1496 - goto err_free; 1497 - 1498 - ppgtt->pd = gen8_alloc_top_pd(&ppgtt->vm); 1499 - if (IS_ERR(ppgtt->pd)) { 1500 - err = PTR_ERR(ppgtt->pd); 1501 - goto err_free_scratch; 1502 - } 1503 - 1504 - if (!i915_vm_is_4lvl(&ppgtt->vm)) { 1505 - err = gen8_preallocate_top_level_pdp(ppgtt); 1506 - if (err) 1507 - goto err_free_pd; 1508 - } 1509 - 1510 - ppgtt->vm.bind_async_flags = I915_VMA_LOCAL_BIND; 1511 - ppgtt->vm.insert_entries = gen8_ppgtt_insert; 1512 - ppgtt->vm.allocate_va_range = gen8_ppgtt_alloc; 1513 - ppgtt->vm.clear_range = gen8_ppgtt_clear; 1514 - 1515 - if (intel_vgpu_active(i915)) 1516 - gen8_ppgtt_notify_vgt(ppgtt, true); 1517 - 1518 - ppgtt->vm.cleanup = gen8_ppgtt_cleanup; 1519 - 1520 - return ppgtt; 1521 - 1522 - err_free_pd: 1523 - __gen8_ppgtt_cleanup(&ppgtt->vm, ppgtt->pd, 1524 - gen8_pd_top_count(&ppgtt->vm), ppgtt->vm.top); 1525 - err_free_scratch: 1526 - free_scratch(&ppgtt->vm); 1527 - err_free: 1528 - kfree(ppgtt); 1529 - return ERR_PTR(err); 1530 - } 1531 - 1532 - /* Write pde (index) from the page directory @pd to the page table @pt */ 1533 - static inline void gen6_write_pde(const struct gen6_ppgtt *ppgtt, 1534 - const unsigned int pde, 1535 - const struct i915_page_table *pt) 1536 - { 1537 - /* Caller needs to make sure the write completes if necessary */ 1538 - iowrite32(GEN6_PDE_ADDR_ENCODE(px_dma(pt)) | GEN6_PDE_VALID, 1539 - ppgtt->pd_addr + pde); 1540 - } 1541 - 1542 - static void gen7_ppgtt_enable(struct intel_gt *gt) 1543 - { 1544 - struct drm_i915_private *i915 = gt->i915; 1545 - struct intel_uncore *uncore = gt->uncore; 1546 - struct intel_engine_cs *engine; 1547 - enum intel_engine_id id; 1548 - u32 ecochk; 1549 - 1550 - intel_uncore_rmw(uncore, GAC_ECO_BITS, 0, ECOBITS_PPGTT_CACHE64B); 1551 - 1552 - ecochk = intel_uncore_read(uncore, GAM_ECOCHK); 1553 - if (IS_HASWELL(i915)) { 1554 - ecochk |= ECOCHK_PPGTT_WB_HSW; 1555 - } else { 1556 - ecochk |= ECOCHK_PPGTT_LLC_IVB; 1557 - ecochk &= ~ECOCHK_PPGTT_GFDT_IVB; 1558 - } 1559 - intel_uncore_write(uncore, GAM_ECOCHK, ecochk); 1560 - 1561 - for_each_engine(engine, gt, id) { 1562 - /* GFX_MODE is per-ring on gen7+ */ 1563 - ENGINE_WRITE(engine, 1564 - RING_MODE_GEN7, 1565 - _MASKED_BIT_ENABLE(GFX_PPGTT_ENABLE)); 1566 - } 1567 - } 1568 - 1569 - static void gen6_ppgtt_enable(struct intel_gt *gt) 1570 - { 1571 - struct intel_uncore *uncore = gt->uncore; 1572 - 1573 - intel_uncore_rmw(uncore, 1574 - GAC_ECO_BITS, 1575 - 0, 1576 - ECOBITS_SNB_BIT | ECOBITS_PPGTT_CACHE64B); 1577 - 1578 - intel_uncore_rmw(uncore, 1579 - GAB_CTL, 1580 - 0, 1581 - GAB_CTL_CONT_AFTER_PAGEFAULT); 1582 - 1583 - intel_uncore_rmw(uncore, 1584 - GAM_ECOCHK, 1585 - 0, 1586 - ECOCHK_SNB_BIT | ECOCHK_PPGTT_CACHE64B); 1587 - 1588 - if (HAS_PPGTT(uncore->i915)) /* may be disabled for VT-d */ 1589 - intel_uncore_write(uncore, 1590 - GFX_MODE, 1591 - _MASKED_BIT_ENABLE(GFX_PPGTT_ENABLE)); 1592 - } 1593 - 1594 - /* PPGTT support for Sandybdrige/Gen6 and later */ 1595 - static void gen6_ppgtt_clear_range(struct i915_address_space *vm, 1596 - u64 start, u64 length) 1597 - { 1598 - struct gen6_ppgtt * const ppgtt = to_gen6_ppgtt(i915_vm_to_ppgtt(vm)); 1599 - const unsigned int first_entry = start / I915_GTT_PAGE_SIZE; 1600 - const gen6_pte_t scratch_pte = vm->scratch[0].encode; 1601 - unsigned int pde = first_entry / GEN6_PTES; 1602 - unsigned int pte = first_entry % GEN6_PTES; 1603 - unsigned int num_entries = length / I915_GTT_PAGE_SIZE; 1604 - 1605 - while (num_entries) { 1606 - struct i915_page_table * const pt = 1607 - i915_pt_entry(ppgtt->base.pd, pde++); 1608 - const unsigned int count = min(num_entries, GEN6_PTES - pte); 1609 - gen6_pte_t *vaddr; 1610 - 1611 - GEM_BUG_ON(px_base(pt) == px_base(&vm->scratch[1])); 1612 - 1613 - num_entries -= count; 1614 - 1615 - GEM_BUG_ON(count > atomic_read(&pt->used)); 1616 - if (!atomic_sub_return(count, &pt->used)) 1617 - ppgtt->scan_for_unused_pt = true; 1618 - 1619 - /* 1620 - * Note that the hw doesn't support removing PDE on the fly 1621 - * (they are cached inside the context with no means to 1622 - * invalidate the cache), so we can only reset the PTE 1623 - * entries back to scratch. 1624 - */ 1625 - 1626 - vaddr = kmap_atomic_px(pt); 1627 - memset32(vaddr + pte, scratch_pte, count); 1628 - kunmap_atomic(vaddr); 1629 - 1630 - pte = 0; 1631 - } 1632 - } 1633 - 1634 - static void gen6_ppgtt_insert_entries(struct i915_address_space *vm, 1635 - struct i915_vma *vma, 1636 - enum i915_cache_level cache_level, 1637 - u32 flags) 1638 - { 1639 - struct i915_ppgtt *ppgtt = i915_vm_to_ppgtt(vm); 1640 - struct i915_page_directory * const pd = ppgtt->pd; 1641 - unsigned first_entry = vma->node.start / I915_GTT_PAGE_SIZE; 1642 - unsigned act_pt = first_entry / GEN6_PTES; 1643 - unsigned act_pte = first_entry % GEN6_PTES; 1644 - const u32 pte_encode = vm->pte_encode(0, cache_level, flags); 1645 - struct sgt_dma iter = sgt_dma(vma); 1646 - gen6_pte_t *vaddr; 1647 - 1648 - GEM_BUG_ON(pd->entry[act_pt] == &vm->scratch[1]); 1649 - 1650 - vaddr = kmap_atomic_px(i915_pt_entry(pd, act_pt)); 1651 - do { 1652 - vaddr[act_pte] = pte_encode | GEN6_PTE_ADDR_ENCODE(iter.dma); 1653 - 1654 - iter.dma += I915_GTT_PAGE_SIZE; 1655 - if (iter.dma == iter.max) { 1656 - iter.sg = __sg_next(iter.sg); 1657 - if (!iter.sg) 1658 - break; 1659 - 1660 - iter.dma = sg_dma_address(iter.sg); 1661 - iter.max = iter.dma + iter.sg->length; 1662 - } 1663 - 1664 - if (++act_pte == GEN6_PTES) { 1665 - kunmap_atomic(vaddr); 1666 - vaddr = kmap_atomic_px(i915_pt_entry(pd, ++act_pt)); 1667 - act_pte = 0; 1668 - } 1669 - } while (1); 1670 - kunmap_atomic(vaddr); 1671 - 1672 - vma->page_sizes.gtt = I915_GTT_PAGE_SIZE; 1673 - } 1674 - 1675 - static void gen6_flush_pd(struct gen6_ppgtt *ppgtt, u64 start, u64 end) 1676 - { 1677 - struct i915_page_directory * const pd = ppgtt->base.pd; 1678 - struct i915_page_table *pt; 1679 - unsigned int pde; 1680 - 1681 - start = round_down(start, SZ_64K); 1682 - end = round_up(end, SZ_64K) - start; 1683 - 1684 - mutex_lock(&ppgtt->flush); 1685 - 1686 - gen6_for_each_pde(pt, pd, start, end, pde) 1687 - gen6_write_pde(ppgtt, pde, pt); 1688 - 1689 - mb(); 1690 - ioread32(ppgtt->pd_addr + pde - 1); 1691 - gen6_ggtt_invalidate(ppgtt->base.vm.gt->ggtt); 1692 - mb(); 1693 - 1694 - mutex_unlock(&ppgtt->flush); 1695 - } 1696 - 1697 - static int gen6_alloc_va_range(struct i915_address_space *vm, 1698 - u64 start, u64 length) 1699 - { 1700 - struct gen6_ppgtt *ppgtt = to_gen6_ppgtt(i915_vm_to_ppgtt(vm)); 1701 - struct i915_page_directory * const pd = ppgtt->base.pd; 1702 - struct i915_page_table *pt, *alloc = NULL; 1703 - intel_wakeref_t wakeref; 1704 - u64 from = start; 1705 - unsigned int pde; 1706 - int ret = 0; 1707 - 1708 - wakeref = intel_runtime_pm_get(&vm->i915->runtime_pm); 1709 - 1710 - spin_lock(&pd->lock); 1711 - gen6_for_each_pde(pt, pd, start, length, pde) { 1712 - const unsigned int count = gen6_pte_count(start, length); 1713 - 1714 - if (px_base(pt) == px_base(&vm->scratch[1])) { 1715 - spin_unlock(&pd->lock); 1716 - 1717 - pt = fetch_and_zero(&alloc); 1718 - if (!pt) 1719 - pt = alloc_pt(vm); 1720 - if (IS_ERR(pt)) { 1721 - ret = PTR_ERR(pt); 1722 - goto unwind_out; 1723 - } 1724 - 1725 - fill32_px(pt, vm->scratch[0].encode); 1726 - 1727 - spin_lock(&pd->lock); 1728 - if (pd->entry[pde] == &vm->scratch[1]) { 1729 - pd->entry[pde] = pt; 1730 - } else { 1731 - alloc = pt; 1732 - pt = pd->entry[pde]; 1733 - } 1734 - } 1735 - 1736 - atomic_add(count, &pt->used); 1737 - } 1738 - spin_unlock(&pd->lock); 1739 - 1740 - if (i915_vma_is_bound(ppgtt->vma, I915_VMA_GLOBAL_BIND)) 1741 - gen6_flush_pd(ppgtt, from, start); 1742 - 1743 - goto out; 1744 - 1745 - unwind_out: 1746 - gen6_ppgtt_clear_range(vm, from, start - from); 1747 - out: 1748 - if (alloc) 1749 - free_px(vm, alloc); 1750 - intel_runtime_pm_put(&vm->i915->runtime_pm, wakeref); 1751 - return ret; 1752 - } 1753 - 1754 - static int gen6_ppgtt_init_scratch(struct gen6_ppgtt *ppgtt) 1755 - { 1756 - struct i915_address_space * const vm = &ppgtt->base.vm; 1757 - struct i915_page_directory * const pd = ppgtt->base.pd; 1758 - int ret; 1759 - 1760 - ret = setup_scratch_page(vm, __GFP_HIGHMEM); 1761 - if (ret) 1762 - return ret; 1763 - 1764 - vm->scratch[0].encode = 1765 - vm->pte_encode(px_dma(&vm->scratch[0]), 1766 - I915_CACHE_NONE, PTE_READ_ONLY); 1767 - 1768 - if (unlikely(setup_page_dma(vm, px_base(&vm->scratch[1])))) { 1769 - cleanup_scratch_page(vm); 1770 - return -ENOMEM; 1771 - } 1772 - 1773 - fill32_px(&vm->scratch[1], vm->scratch[0].encode); 1774 - memset_p(pd->entry, &vm->scratch[1], I915_PDES); 1775 - 1776 - return 0; 1777 - } 1778 - 1779 - static void gen6_ppgtt_free_pd(struct gen6_ppgtt *ppgtt) 1780 - { 1781 - struct i915_page_directory * const pd = ppgtt->base.pd; 1782 - struct i915_page_dma * const scratch = 1783 - px_base(&ppgtt->base.vm.scratch[1]); 1784 - struct i915_page_table *pt; 1785 - u32 pde; 1786 - 1787 - gen6_for_all_pdes(pt, pd, pde) 1788 - if (px_base(pt) != scratch) 1789 - free_px(&ppgtt->base.vm, pt); 1790 - } 1791 - 1792 - static void gen6_ppgtt_cleanup(struct i915_address_space *vm) 1793 - { 1794 - struct gen6_ppgtt *ppgtt = to_gen6_ppgtt(i915_vm_to_ppgtt(vm)); 1795 - 1796 - __i915_vma_put(ppgtt->vma); 1797 - 1798 - gen6_ppgtt_free_pd(ppgtt); 1799 - free_scratch(vm); 1800 - 1801 - mutex_destroy(&ppgtt->flush); 1802 - mutex_destroy(&ppgtt->pin_mutex); 1803 - kfree(ppgtt->base.pd); 1804 - } 1805 - 1806 - static int pd_vma_set_pages(struct i915_vma *vma) 1807 - { 1808 - vma->pages = ERR_PTR(-ENODEV); 1809 - return 0; 1810 - } 1811 - 1812 - static void pd_vma_clear_pages(struct i915_vma *vma) 1813 - { 1814 - GEM_BUG_ON(!vma->pages); 1815 - 1816 - vma->pages = NULL; 1817 - } 1818 - 1819 - static int pd_vma_bind(struct i915_vma *vma, 1820 - enum i915_cache_level cache_level, 1821 - u32 unused) 1822 - { 1823 - struct i915_ggtt *ggtt = i915_vm_to_ggtt(vma->vm); 1824 - struct gen6_ppgtt *ppgtt = vma->private; 1825 - u32 ggtt_offset = i915_ggtt_offset(vma) / I915_GTT_PAGE_SIZE; 1826 - 1827 - px_base(ppgtt->base.pd)->ggtt_offset = ggtt_offset * sizeof(gen6_pte_t); 1828 - ppgtt->pd_addr = (gen6_pte_t __iomem *)ggtt->gsm + ggtt_offset; 1829 - 1830 - gen6_flush_pd(ppgtt, 0, ppgtt->base.vm.total); 1831 - return 0; 1832 - } 1833 - 1834 - static void pd_vma_unbind(struct i915_vma *vma) 1835 - { 1836 - struct gen6_ppgtt *ppgtt = vma->private; 1837 - struct i915_page_directory * const pd = ppgtt->base.pd; 1838 - struct i915_page_dma * const scratch = 1839 - px_base(&ppgtt->base.vm.scratch[1]); 1840 - struct i915_page_table *pt; 1841 - unsigned int pde; 1842 - 1843 - if (!ppgtt->scan_for_unused_pt) 1844 - return; 1845 - 1846 - /* Free all no longer used page tables */ 1847 - gen6_for_all_pdes(pt, ppgtt->base.pd, pde) { 1848 - if (px_base(pt) == scratch || atomic_read(&pt->used)) 1849 - continue; 1850 - 1851 - free_px(&ppgtt->base.vm, pt); 1852 - pd->entry[pde] = scratch; 1853 - } 1854 - 1855 - ppgtt->scan_for_unused_pt = false; 1856 - } 1857 - 1858 - static const struct i915_vma_ops pd_vma_ops = { 1859 - .set_pages = pd_vma_set_pages, 1860 - .clear_pages = pd_vma_clear_pages, 1861 - .bind_vma = pd_vma_bind, 1862 - .unbind_vma = pd_vma_unbind, 1863 - }; 1864 - 1865 - static struct i915_vma *pd_vma_create(struct gen6_ppgtt *ppgtt, int size) 1866 - { 1867 - struct i915_ggtt *ggtt = ppgtt->base.vm.gt->ggtt; 1868 - struct i915_vma *vma; 1869 - 1870 - GEM_BUG_ON(!IS_ALIGNED(size, I915_GTT_PAGE_SIZE)); 1871 - GEM_BUG_ON(size > ggtt->vm.total); 1872 - 1873 - vma = i915_vma_alloc(); 1874 - if (!vma) 1875 - return ERR_PTR(-ENOMEM); 1876 - 1877 - i915_active_init(&vma->active, NULL, NULL); 1878 - 1879 - kref_init(&vma->ref); 1880 - mutex_init(&vma->pages_mutex); 1881 - vma->vm = i915_vm_get(&ggtt->vm); 1882 - vma->ops = &pd_vma_ops; 1883 - vma->private = ppgtt; 1884 - 1885 - vma->size = size; 1886 - vma->fence_size = size; 1887 - atomic_set(&vma->flags, I915_VMA_GGTT); 1888 - vma->ggtt_view.type = I915_GGTT_VIEW_ROTATED; /* prevent fencing */ 1889 - 1890 - INIT_LIST_HEAD(&vma->obj_link); 1891 - INIT_LIST_HEAD(&vma->closed_link); 1892 - 1893 - return vma; 1894 - } 1895 - 1896 - int gen6_ppgtt_pin(struct i915_ppgtt *base) 1897 - { 1898 - struct gen6_ppgtt *ppgtt = to_gen6_ppgtt(base); 1899 - int err = 0; 1900 - 1901 - GEM_BUG_ON(!atomic_read(&ppgtt->base.vm.open)); 1902 - 1903 - /* 1904 - * Workaround the limited maximum vma->pin_count and the aliasing_ppgtt 1905 - * which will be pinned into every active context. 1906 - * (When vma->pin_count becomes atomic, I expect we will naturally 1907 - * need a larger, unpacked, type and kill this redundancy.) 1908 - */ 1909 - if (atomic_add_unless(&ppgtt->pin_count, 1, 0)) 1910 - return 0; 1911 - 1912 - if (mutex_lock_interruptible(&ppgtt->pin_mutex)) 1913 - return -EINTR; 1914 - 1915 - /* 1916 - * PPGTT PDEs reside in the GGTT and consists of 512 entries. The 1917 - * allocator works in address space sizes, so it's multiplied by page 1918 - * size. We allocate at the top of the GTT to avoid fragmentation. 1919 - */ 1920 - if (!atomic_read(&ppgtt->pin_count)) { 1921 - err = i915_ggtt_pin(ppgtt->vma, GEN6_PD_ALIGN, PIN_HIGH); 1922 - } 1923 - if (!err) 1924 - atomic_inc(&ppgtt->pin_count); 1925 - mutex_unlock(&ppgtt->pin_mutex); 1926 - 1927 - return err; 1928 - } 1929 - 1930 - void gen6_ppgtt_unpin(struct i915_ppgtt *base) 1931 - { 1932 - struct gen6_ppgtt *ppgtt = to_gen6_ppgtt(base); 1933 - 1934 - GEM_BUG_ON(!atomic_read(&ppgtt->pin_count)); 1935 - if (atomic_dec_and_test(&ppgtt->pin_count)) 1936 - i915_vma_unpin(ppgtt->vma); 1937 - } 1938 - 1939 - void gen6_ppgtt_unpin_all(struct i915_ppgtt *base) 1940 - { 1941 - struct gen6_ppgtt *ppgtt = to_gen6_ppgtt(base); 1942 - 1943 - if (!atomic_read(&ppgtt->pin_count)) 1944 - return; 1945 - 1946 - i915_vma_unpin(ppgtt->vma); 1947 - atomic_set(&ppgtt->pin_count, 0); 1948 - } 1949 - 1950 - static struct i915_ppgtt *gen6_ppgtt_create(struct drm_i915_private *i915) 1951 - { 1952 - struct i915_ggtt * const ggtt = &i915->ggtt; 1953 - struct gen6_ppgtt *ppgtt; 1954 - int err; 1955 - 1956 - ppgtt = kzalloc(sizeof(*ppgtt), GFP_KERNEL); 1957 - if (!ppgtt) 1958 - return ERR_PTR(-ENOMEM); 1959 - 1960 - mutex_init(&ppgtt->flush); 1961 - mutex_init(&ppgtt->pin_mutex); 1962 - 1963 - ppgtt_init(&ppgtt->base, &i915->gt); 1964 - ppgtt->base.vm.top = 1; 1965 - 1966 - ppgtt->base.vm.bind_async_flags = I915_VMA_LOCAL_BIND; 1967 - ppgtt->base.vm.allocate_va_range = gen6_alloc_va_range; 1968 - ppgtt->base.vm.clear_range = gen6_ppgtt_clear_range; 1969 - ppgtt->base.vm.insert_entries = gen6_ppgtt_insert_entries; 1970 - ppgtt->base.vm.cleanup = gen6_ppgtt_cleanup; 1971 - 1972 - ppgtt->base.vm.pte_encode = ggtt->vm.pte_encode; 1973 - 1974 - ppgtt->base.pd = __alloc_pd(sizeof(*ppgtt->base.pd)); 1975 - if (!ppgtt->base.pd) { 1976 - err = -ENOMEM; 1977 - goto err_free; 1978 - } 1979 - 1980 - err = gen6_ppgtt_init_scratch(ppgtt); 1981 - if (err) 1982 - goto err_pd; 1983 - 1984 - ppgtt->vma = pd_vma_create(ppgtt, GEN6_PD_SIZE); 1985 - if (IS_ERR(ppgtt->vma)) { 1986 - err = PTR_ERR(ppgtt->vma); 1987 - goto err_scratch; 1988 - } 1989 - 1990 - return &ppgtt->base; 1991 - 1992 - err_scratch: 1993 - free_scratch(&ppgtt->base.vm); 1994 - err_pd: 1995 - kfree(ppgtt->base.pd); 1996 - err_free: 1997 - mutex_destroy(&ppgtt->pin_mutex); 1998 - kfree(ppgtt); 1999 - return ERR_PTR(err); 2000 - } 2001 - 2002 - static void gtt_write_workarounds(struct intel_gt *gt) 2003 - { 2004 - struct drm_i915_private *i915 = gt->i915; 2005 - struct intel_uncore *uncore = gt->uncore; 2006 - 2007 - /* This function is for gtt related workarounds. This function is 2008 - * called on driver load and after a GPU reset, so you can place 2009 - * workarounds here even if they get overwritten by GPU reset. 2010 - */ 2011 - /* WaIncreaseDefaultTLBEntries:chv,bdw,skl,bxt,kbl,glk,cfl,cnl,icl */ 2012 - if (IS_BROADWELL(i915)) 2013 - intel_uncore_write(uncore, 2014 - GEN8_L3_LRA_1_GPGPU, 2015 - GEN8_L3_LRA_1_GPGPU_DEFAULT_VALUE_BDW); 2016 - else if (IS_CHERRYVIEW(i915)) 2017 - intel_uncore_write(uncore, 2018 - GEN8_L3_LRA_1_GPGPU, 2019 - GEN8_L3_LRA_1_GPGPU_DEFAULT_VALUE_CHV); 2020 - else if (IS_GEN9_LP(i915)) 2021 - intel_uncore_write(uncore, 2022 - GEN8_L3_LRA_1_GPGPU, 2023 - GEN9_L3_LRA_1_GPGPU_DEFAULT_VALUE_BXT); 2024 - else if (INTEL_GEN(i915) >= 9 && INTEL_GEN(i915) <= 11) 2025 - intel_uncore_write(uncore, 2026 - GEN8_L3_LRA_1_GPGPU, 2027 - GEN9_L3_LRA_1_GPGPU_DEFAULT_VALUE_SKL); 2028 - 2029 - /* 2030 - * To support 64K PTEs we need to first enable the use of the 2031 - * Intermediate-Page-Size(IPS) bit of the PDE field via some magical 2032 - * mmio, otherwise the page-walker will simply ignore the IPS bit. This 2033 - * shouldn't be needed after GEN10. 2034 - * 2035 - * 64K pages were first introduced from BDW+, although technically they 2036 - * only *work* from gen9+. For pre-BDW we instead have the option for 2037 - * 32K pages, but we don't currently have any support for it in our 2038 - * driver. 2039 - */ 2040 - if (HAS_PAGE_SIZES(i915, I915_GTT_PAGE_SIZE_64K) && 2041 - INTEL_GEN(i915) <= 10) 2042 - intel_uncore_rmw(uncore, 2043 - GEN8_GAMW_ECO_DEV_RW_IA, 2044 - 0, 2045 - GAMW_ECO_ENABLE_64K_IPS_FIELD); 2046 - 2047 - if (IS_GEN_RANGE(i915, 8, 11)) { 2048 - bool can_use_gtt_cache = true; 2049 - 2050 - /* 2051 - * According to the BSpec if we use 2M/1G pages then we also 2052 - * need to disable the GTT cache. At least on BDW we can see 2053 - * visual corruption when using 2M pages, and not disabling the 2054 - * GTT cache. 2055 - */ 2056 - if (HAS_PAGE_SIZES(i915, I915_GTT_PAGE_SIZE_2M)) 2057 - can_use_gtt_cache = false; 2058 - 2059 - /* WaGttCachingOffByDefault */ 2060 - intel_uncore_write(uncore, 2061 - HSW_GTT_CACHE_EN, 2062 - can_use_gtt_cache ? GTT_CACHE_EN_ALL : 0); 2063 - WARN_ON_ONCE(can_use_gtt_cache && 2064 - intel_uncore_read(uncore, 2065 - HSW_GTT_CACHE_EN) == 0); 2066 - } 2067 - } 2068 - 2069 - int i915_ppgtt_init_hw(struct intel_gt *gt) 2070 - { 2071 - struct drm_i915_private *i915 = gt->i915; 2072 - 2073 - gtt_write_workarounds(gt); 2074 - 2075 - if (IS_GEN(i915, 6)) 2076 - gen6_ppgtt_enable(gt); 2077 - else if (IS_GEN(i915, 7)) 2078 - gen7_ppgtt_enable(gt); 2079 - 2080 - return 0; 2081 - } 2082 - 2083 - static struct i915_ppgtt * 2084 - __ppgtt_create(struct drm_i915_private *i915) 2085 - { 2086 - if (INTEL_GEN(i915) < 8) 2087 - return gen6_ppgtt_create(i915); 2088 - else 2089 - return gen8_ppgtt_create(i915); 2090 - } 2091 - 2092 - struct i915_ppgtt * 2093 - i915_ppgtt_create(struct drm_i915_private *i915) 2094 - { 2095 - struct i915_ppgtt *ppgtt; 2096 - 2097 - ppgtt = __ppgtt_create(i915); 2098 - if (IS_ERR(ppgtt)) 2099 - return ppgtt; 2100 - 2101 - trace_i915_ppgtt_create(&ppgtt->vm); 2102 - 2103 - return ppgtt; 2104 - } 2105 - 2106 - /* Certain Gen5 chipsets require require idling the GPU before 2107 - * unmapping anything from the GTT when VT-d is enabled. 2108 - */ 2109 - static bool needs_idle_maps(struct drm_i915_private *dev_priv) 2110 - { 2111 - /* Query intel_iommu to see if we need the workaround. Presumably that 2112 - * was loaded first. 2113 - */ 2114 - return IS_GEN(dev_priv, 5) && IS_MOBILE(dev_priv) && intel_vtd_active(); 2115 - } 2116 - 2117 - static void ggtt_suspend_mappings(struct i915_ggtt *ggtt) 2118 - { 2119 - struct drm_i915_private *i915 = ggtt->vm.i915; 2120 - 2121 - /* Don't bother messing with faults pre GEN6 as we have little 2122 - * documentation supporting that it's a good idea. 2123 - */ 2124 - if (INTEL_GEN(i915) < 6) 2125 - return; 2126 - 2127 - intel_gt_check_and_clear_faults(ggtt->vm.gt); 2128 - 2129 - ggtt->vm.clear_range(&ggtt->vm, 0, ggtt->vm.total); 2130 - 2131 - ggtt->invalidate(ggtt); 2132 - } 2133 - 2134 - void i915_gem_suspend_gtt_mappings(struct drm_i915_private *i915) 2135 - { 2136 - ggtt_suspend_mappings(&i915->ggtt); 2137 - } 2138 47 2139 48 int i915_gem_gtt_prepare_pages(struct drm_i915_gem_object *obj, 2140 49 struct sg_table *pages) ··· 52 2181 return -ENOSPC; 53 2182 } 54 2183 55 - static void gen8_set_pte(void __iomem *addr, gen8_pte_t pte) 56 - { 57 - writeq(pte, addr); 58 - } 59 - 60 - static void gen8_ggtt_insert_page(struct i915_address_space *vm, 61 - dma_addr_t addr, 62 - u64 offset, 63 - enum i915_cache_level level, 64 - u32 unused) 65 - { 66 - struct i915_ggtt *ggtt = i915_vm_to_ggtt(vm); 67 - gen8_pte_t __iomem *pte = 68 - (gen8_pte_t __iomem *)ggtt->gsm + offset / I915_GTT_PAGE_SIZE; 69 - 70 - gen8_set_pte(pte, gen8_pte_encode(addr, level, 0)); 71 - 72 - ggtt->invalidate(ggtt); 73 - } 74 - 75 - static void gen8_ggtt_insert_entries(struct i915_address_space *vm, 76 - struct i915_vma *vma, 77 - enum i915_cache_level level, 78 - u32 flags) 79 - { 80 - struct i915_ggtt *ggtt = i915_vm_to_ggtt(vm); 81 - struct sgt_iter sgt_iter; 82 - gen8_pte_t __iomem *gtt_entries; 83 - const gen8_pte_t pte_encode = gen8_pte_encode(0, level, 0); 84 - dma_addr_t addr; 85 - 86 - /* 87 - * Note that we ignore PTE_READ_ONLY here. The caller must be careful 88 - * not to allow the user to override access to a read only page. 89 - */ 90 - 91 - gtt_entries = (gen8_pte_t __iomem *)ggtt->gsm; 92 - gtt_entries += vma->node.start / I915_GTT_PAGE_SIZE; 93 - for_each_sgt_daddr(addr, sgt_iter, vma->pages) 94 - gen8_set_pte(gtt_entries++, pte_encode | addr); 95 - 96 - /* 97 - * We want to flush the TLBs only after we're certain all the PTE 98 - * updates have finished. 99 - */ 100 - ggtt->invalidate(ggtt); 101 - } 102 - 103 - static void gen6_ggtt_insert_page(struct i915_address_space *vm, 104 - dma_addr_t addr, 105 - u64 offset, 106 - enum i915_cache_level level, 107 - u32 flags) 108 - { 109 - struct i915_ggtt *ggtt = i915_vm_to_ggtt(vm); 110 - gen6_pte_t __iomem *pte = 111 - (gen6_pte_t __iomem *)ggtt->gsm + offset / I915_GTT_PAGE_SIZE; 112 - 113 - iowrite32(vm->pte_encode(addr, level, flags), pte); 114 - 115 - ggtt->invalidate(ggtt); 116 - } 117 - 118 - /* 119 - * Binds an object into the global gtt with the specified cache level. The object 120 - * will be accessible to the GPU via commands whose operands reference offsets 121 - * within the global GTT as well as accessible by the GPU through the GMADR 122 - * mapped BAR (dev_priv->mm.gtt->gtt). 123 - */ 124 - static void gen6_ggtt_insert_entries(struct i915_address_space *vm, 125 - struct i915_vma *vma, 126 - enum i915_cache_level level, 127 - u32 flags) 128 - { 129 - struct i915_ggtt *ggtt = i915_vm_to_ggtt(vm); 130 - gen6_pte_t __iomem *entries = (gen6_pte_t __iomem *)ggtt->gsm; 131 - unsigned int i = vma->node.start / I915_GTT_PAGE_SIZE; 132 - struct sgt_iter iter; 133 - dma_addr_t addr; 134 - for_each_sgt_daddr(addr, iter, vma->pages) 135 - iowrite32(vm->pte_encode(addr, level, flags), &entries[i++]); 136 - 137 - /* 138 - * We want to flush the TLBs only after we're certain all the PTE 139 - * updates have finished. 140 - */ 141 - ggtt->invalidate(ggtt); 142 - } 143 - 144 - static void nop_clear_range(struct i915_address_space *vm, 145 - u64 start, u64 length) 146 - { 147 - } 148 - 149 - static void gen8_ggtt_clear_range(struct i915_address_space *vm, 150 - u64 start, u64 length) 151 - { 152 - struct i915_ggtt *ggtt = i915_vm_to_ggtt(vm); 153 - unsigned first_entry = start / I915_GTT_PAGE_SIZE; 154 - unsigned num_entries = length / I915_GTT_PAGE_SIZE; 155 - const gen8_pte_t scratch_pte = vm->scratch[0].encode; 156 - gen8_pte_t __iomem *gtt_base = 157 - (gen8_pte_t __iomem *)ggtt->gsm + first_entry; 158 - const int max_entries = ggtt_total_entries(ggtt) - first_entry; 159 - int i; 160 - 161 - if (WARN(num_entries > max_entries, 162 - "First entry = %d; Num entries = %d (max=%d)\n", 163 - first_entry, num_entries, max_entries)) 164 - num_entries = max_entries; 165 - 166 - for (i = 0; i < num_entries; i++) 167 - gen8_set_pte(&gtt_base[i], scratch_pte); 168 - } 169 - 170 - static void bxt_vtd_ggtt_wa(struct i915_address_space *vm) 171 - { 172 - struct drm_i915_private *dev_priv = vm->i915; 173 - 174 - /* 175 - * Make sure the internal GAM fifo has been cleared of all GTT 176 - * writes before exiting stop_machine(). This guarantees that 177 - * any aperture accesses waiting to start in another process 178 - * cannot back up behind the GTT writes causing a hang. 179 - * The register can be any arbitrary GAM register. 180 - */ 181 - POSTING_READ(GFX_FLSH_CNTL_GEN6); 182 - } 183 - 184 - struct insert_page { 185 - struct i915_address_space *vm; 186 - dma_addr_t addr; 187 - u64 offset; 188 - enum i915_cache_level level; 189 - }; 190 - 191 - static int bxt_vtd_ggtt_insert_page__cb(void *_arg) 192 - { 193 - struct insert_page *arg = _arg; 194 - 195 - gen8_ggtt_insert_page(arg->vm, arg->addr, arg->offset, arg->level, 0); 196 - bxt_vtd_ggtt_wa(arg->vm); 197 - 198 - return 0; 199 - } 200 - 201 - static void bxt_vtd_ggtt_insert_page__BKL(struct i915_address_space *vm, 202 - dma_addr_t addr, 203 - u64 offset, 204 - enum i915_cache_level level, 205 - u32 unused) 206 - { 207 - struct insert_page arg = { vm, addr, offset, level }; 208 - 209 - stop_machine(bxt_vtd_ggtt_insert_page__cb, &arg, NULL); 210 - } 211 - 212 - struct insert_entries { 213 - struct i915_address_space *vm; 214 - struct i915_vma *vma; 215 - enum i915_cache_level level; 216 - u32 flags; 217 - }; 218 - 219 - static int bxt_vtd_ggtt_insert_entries__cb(void *_arg) 220 - { 221 - struct insert_entries *arg = _arg; 222 - 223 - gen8_ggtt_insert_entries(arg->vm, arg->vma, arg->level, arg->flags); 224 - bxt_vtd_ggtt_wa(arg->vm); 225 - 226 - return 0; 227 - } 228 - 229 - static void bxt_vtd_ggtt_insert_entries__BKL(struct i915_address_space *vm, 230 - struct i915_vma *vma, 231 - enum i915_cache_level level, 232 - u32 flags) 233 - { 234 - struct insert_entries arg = { vm, vma, level, flags }; 235 - 236 - stop_machine(bxt_vtd_ggtt_insert_entries__cb, &arg, NULL); 237 - } 238 - 239 - struct clear_range { 240 - struct i915_address_space *vm; 241 - u64 start; 242 - u64 length; 243 - }; 244 - 245 - static int bxt_vtd_ggtt_clear_range__cb(void *_arg) 246 - { 247 - struct clear_range *arg = _arg; 248 - 249 - gen8_ggtt_clear_range(arg->vm, arg->start, arg->length); 250 - bxt_vtd_ggtt_wa(arg->vm); 251 - 252 - return 0; 253 - } 254 - 255 - static void bxt_vtd_ggtt_clear_range__BKL(struct i915_address_space *vm, 256 - u64 start, 257 - u64 length) 258 - { 259 - struct clear_range arg = { vm, start, length }; 260 - 261 - stop_machine(bxt_vtd_ggtt_clear_range__cb, &arg, NULL); 262 - } 263 - 264 - static void gen6_ggtt_clear_range(struct i915_address_space *vm, 265 - u64 start, u64 length) 266 - { 267 - struct i915_ggtt *ggtt = i915_vm_to_ggtt(vm); 268 - unsigned first_entry = start / I915_GTT_PAGE_SIZE; 269 - unsigned num_entries = length / I915_GTT_PAGE_SIZE; 270 - gen6_pte_t scratch_pte, __iomem *gtt_base = 271 - (gen6_pte_t __iomem *)ggtt->gsm + first_entry; 272 - const int max_entries = ggtt_total_entries(ggtt) - first_entry; 273 - int i; 274 - 275 - if (WARN(num_entries > max_entries, 276 - "First entry = %d; Num entries = %d (max=%d)\n", 277 - first_entry, num_entries, max_entries)) 278 - num_entries = max_entries; 279 - 280 - scratch_pte = vm->scratch[0].encode; 281 - for (i = 0; i < num_entries; i++) 282 - iowrite32(scratch_pte, &gtt_base[i]); 283 - } 284 - 285 - static void i915_ggtt_insert_page(struct i915_address_space *vm, 286 - dma_addr_t addr, 287 - u64 offset, 288 - enum i915_cache_level cache_level, 289 - u32 unused) 290 - { 291 - unsigned int flags = (cache_level == I915_CACHE_NONE) ? 292 - AGP_USER_MEMORY : AGP_USER_CACHED_MEMORY; 293 - 294 - intel_gtt_insert_page(addr, offset >> PAGE_SHIFT, flags); 295 - } 296 - 297 - static void i915_ggtt_insert_entries(struct i915_address_space *vm, 298 - struct i915_vma *vma, 299 - enum i915_cache_level cache_level, 300 - u32 unused) 301 - { 302 - unsigned int flags = (cache_level == I915_CACHE_NONE) ? 303 - AGP_USER_MEMORY : AGP_USER_CACHED_MEMORY; 304 - 305 - intel_gtt_insert_sg_entries(vma->pages, vma->node.start >> PAGE_SHIFT, 306 - flags); 307 - } 308 - 309 - static void i915_ggtt_clear_range(struct i915_address_space *vm, 310 - u64 start, u64 length) 311 - { 312 - intel_gtt_clear_range(start >> PAGE_SHIFT, length >> PAGE_SHIFT); 313 - } 314 - 315 - static int ggtt_bind_vma(struct i915_vma *vma, 316 - enum i915_cache_level cache_level, 317 - u32 flags) 318 - { 319 - struct drm_i915_private *i915 = vma->vm->i915; 320 - struct drm_i915_gem_object *obj = vma->obj; 321 - intel_wakeref_t wakeref; 322 - u32 pte_flags; 323 - 324 - /* Applicable to VLV (gen8+ do not support RO in the GGTT) */ 325 - pte_flags = 0; 326 - if (i915_gem_object_is_readonly(obj)) 327 - pte_flags |= PTE_READ_ONLY; 328 - 329 - with_intel_runtime_pm(&i915->runtime_pm, wakeref) 330 - vma->vm->insert_entries(vma->vm, vma, cache_level, pte_flags); 331 - 332 - vma->page_sizes.gtt = I915_GTT_PAGE_SIZE; 333 - 334 - /* 335 - * Without aliasing PPGTT there's no difference between 336 - * GLOBAL/LOCAL_BIND, it's all the same ptes. Hence unconditionally 337 - * upgrade to both bound if we bind either to avoid double-binding. 338 - */ 339 - atomic_or(I915_VMA_GLOBAL_BIND | I915_VMA_LOCAL_BIND, &vma->flags); 340 - 341 - return 0; 342 - } 343 - 344 - static void ggtt_unbind_vma(struct i915_vma *vma) 345 - { 346 - struct drm_i915_private *i915 = vma->vm->i915; 347 - intel_wakeref_t wakeref; 348 - 349 - with_intel_runtime_pm(&i915->runtime_pm, wakeref) 350 - vma->vm->clear_range(vma->vm, vma->node.start, vma->size); 351 - } 352 - 353 - static int aliasing_gtt_bind_vma(struct i915_vma *vma, 354 - enum i915_cache_level cache_level, 355 - u32 flags) 356 - { 357 - struct drm_i915_private *i915 = vma->vm->i915; 358 - u32 pte_flags; 359 - int ret; 360 - 361 - /* Currently applicable only to VLV */ 362 - pte_flags = 0; 363 - if (i915_gem_object_is_readonly(vma->obj)) 364 - pte_flags |= PTE_READ_ONLY; 365 - 366 - if (flags & I915_VMA_LOCAL_BIND) { 367 - struct i915_ppgtt *alias = i915_vm_to_ggtt(vma->vm)->alias; 368 - 369 - if (flags & I915_VMA_ALLOC) { 370 - ret = alias->vm.allocate_va_range(&alias->vm, 371 - vma->node.start, 372 - vma->size); 373 - if (ret) 374 - return ret; 375 - 376 - set_bit(I915_VMA_ALLOC_BIT, __i915_vma_flags(vma)); 377 - } 378 - 379 - GEM_BUG_ON(!test_bit(I915_VMA_ALLOC_BIT, 380 - __i915_vma_flags(vma))); 381 - alias->vm.insert_entries(&alias->vm, vma, 382 - cache_level, pte_flags); 383 - } 384 - 385 - if (flags & I915_VMA_GLOBAL_BIND) { 386 - intel_wakeref_t wakeref; 387 - 388 - with_intel_runtime_pm(&i915->runtime_pm, wakeref) { 389 - vma->vm->insert_entries(vma->vm, vma, 390 - cache_level, pte_flags); 391 - } 392 - } 393 - 394 - return 0; 395 - } 396 - 397 - static void aliasing_gtt_unbind_vma(struct i915_vma *vma) 398 - { 399 - struct drm_i915_private *i915 = vma->vm->i915; 400 - 401 - if (i915_vma_is_bound(vma, I915_VMA_GLOBAL_BIND)) { 402 - struct i915_address_space *vm = vma->vm; 403 - intel_wakeref_t wakeref; 404 - 405 - with_intel_runtime_pm(&i915->runtime_pm, wakeref) 406 - vm->clear_range(vm, vma->node.start, vma->size); 407 - } 408 - 409 - if (test_and_clear_bit(I915_VMA_ALLOC_BIT, __i915_vma_flags(vma))) { 410 - struct i915_address_space *vm = 411 - &i915_vm_to_ggtt(vma->vm)->alias->vm; 412 - 413 - vm->clear_range(vm, vma->node.start, vma->size); 414 - } 415 - } 416 - 417 2184 void i915_gem_gtt_finish_pages(struct drm_i915_gem_object *obj, 418 2185 struct sg_table *pages) 419 2186 { ··· 70 2561 } 71 2562 72 2563 dma_unmap_sg(kdev, pages->sgl, pages->nents, PCI_DMA_BIDIRECTIONAL); 73 - } 74 - 75 - static int ggtt_set_pages(struct i915_vma *vma) 76 - { 77 - int ret; 78 - 79 - GEM_BUG_ON(vma->pages); 80 - 81 - ret = i915_get_ggtt_vma_pages(vma); 82 - if (ret) 83 - return ret; 84 - 85 - vma->page_sizes = vma->obj->mm.page_sizes; 86 - 87 - return 0; 88 - } 89 - 90 - static void i915_ggtt_color_adjust(const struct drm_mm_node *node, 91 - unsigned long color, 92 - u64 *start, 93 - u64 *end) 94 - { 95 - if (i915_node_color_differs(node, color)) 96 - *start += I915_GTT_PAGE_SIZE; 97 - 98 - /* Also leave a space between the unallocated reserved node after the 99 - * GTT and any objects within the GTT, i.e. we use the color adjustment 100 - * to insert a guard page to prevent prefetches crossing over the 101 - * GTT boundary. 102 - */ 103 - node = list_next_entry(node, node_list); 104 - if (node->color != color) 105 - *end -= I915_GTT_PAGE_SIZE; 106 - } 107 - 108 - static int init_aliasing_ppgtt(struct i915_ggtt *ggtt) 109 - { 110 - struct i915_ppgtt *ppgtt; 111 - int err; 112 - 113 - ppgtt = i915_ppgtt_create(ggtt->vm.i915); 114 - if (IS_ERR(ppgtt)) 115 - return PTR_ERR(ppgtt); 116 - 117 - if (GEM_WARN_ON(ppgtt->vm.total < ggtt->vm.total)) { 118 - err = -ENODEV; 119 - goto err_ppgtt; 120 - } 121 - 122 - /* 123 - * Note we only pre-allocate as far as the end of the global 124 - * GTT. On 48b / 4-level page-tables, the difference is very, 125 - * very significant! We have to preallocate as GVT/vgpu does 126 - * not like the page directory disappearing. 127 - */ 128 - err = ppgtt->vm.allocate_va_range(&ppgtt->vm, 0, ggtt->vm.total); 129 - if (err) 130 - goto err_ppgtt; 131 - 132 - ggtt->alias = ppgtt; 133 - ggtt->vm.bind_async_flags |= ppgtt->vm.bind_async_flags; 134 - 135 - GEM_BUG_ON(ggtt->vm.vma_ops.bind_vma != ggtt_bind_vma); 136 - ggtt->vm.vma_ops.bind_vma = aliasing_gtt_bind_vma; 137 - 138 - GEM_BUG_ON(ggtt->vm.vma_ops.unbind_vma != ggtt_unbind_vma); 139 - ggtt->vm.vma_ops.unbind_vma = aliasing_gtt_unbind_vma; 140 - 141 - return 0; 142 - 143 - err_ppgtt: 144 - i915_vm_put(&ppgtt->vm); 145 - return err; 146 - } 147 - 148 - static void fini_aliasing_ppgtt(struct i915_ggtt *ggtt) 149 - { 150 - struct i915_ppgtt *ppgtt; 151 - 152 - ppgtt = fetch_and_zero(&ggtt->alias); 153 - if (!ppgtt) 154 - return; 155 - 156 - i915_vm_put(&ppgtt->vm); 157 - 158 - ggtt->vm.vma_ops.bind_vma = ggtt_bind_vma; 159 - ggtt->vm.vma_ops.unbind_vma = ggtt_unbind_vma; 160 - } 161 - 162 - static int ggtt_reserve_guc_top(struct i915_ggtt *ggtt) 163 - { 164 - u64 size; 165 - int ret; 166 - 167 - if (!USES_GUC(ggtt->vm.i915)) 168 - return 0; 169 - 170 - GEM_BUG_ON(ggtt->vm.total <= GUC_GGTT_TOP); 171 - size = ggtt->vm.total - GUC_GGTT_TOP; 172 - 173 - ret = i915_gem_gtt_reserve(&ggtt->vm, &ggtt->uc_fw, size, 174 - GUC_GGTT_TOP, I915_COLOR_UNEVICTABLE, 175 - PIN_NOEVICT); 176 - if (ret) 177 - DRM_DEBUG_DRIVER("Failed to reserve top of GGTT for GuC\n"); 178 - 179 - return ret; 180 - } 181 - 182 - static void ggtt_release_guc_top(struct i915_ggtt *ggtt) 183 - { 184 - if (drm_mm_node_allocated(&ggtt->uc_fw)) 185 - drm_mm_remove_node(&ggtt->uc_fw); 186 - } 187 - 188 - static void cleanup_init_ggtt(struct i915_ggtt *ggtt) 189 - { 190 - ggtt_release_guc_top(ggtt); 191 - if (drm_mm_node_allocated(&ggtt->error_capture)) 192 - drm_mm_remove_node(&ggtt->error_capture); 193 - } 194 - 195 - static int init_ggtt(struct i915_ggtt *ggtt) 196 - { 197 - /* Let GEM Manage all of the aperture. 198 - * 199 - * However, leave one page at the end still bound to the scratch page. 200 - * There are a number of places where the hardware apparently prefetches 201 - * past the end of the object, and we've seen multiple hangs with the 202 - * GPU head pointer stuck in a batchbuffer bound at the last page of the 203 - * aperture. One page should be enough to keep any prefetching inside 204 - * of the aperture. 205 - */ 206 - unsigned long hole_start, hole_end; 207 - struct drm_mm_node *entry; 208 - int ret; 209 - 210 - /* 211 - * GuC requires all resources that we're sharing with it to be placed in 212 - * non-WOPCM memory. If GuC is not present or not in use we still need a 213 - * small bias as ring wraparound at offset 0 sometimes hangs. No idea 214 - * why. 215 - */ 216 - ggtt->pin_bias = max_t(u32, I915_GTT_PAGE_SIZE, 217 - intel_wopcm_guc_size(&ggtt->vm.i915->wopcm)); 218 - 219 - ret = intel_vgt_balloon(ggtt); 220 - if (ret) 221 - return ret; 222 - 223 - if (ggtt->mappable_end) { 224 - /* Reserve a mappable slot for our lockless error capture */ 225 - ret = drm_mm_insert_node_in_range(&ggtt->vm.mm, &ggtt->error_capture, 226 - PAGE_SIZE, 0, I915_COLOR_UNEVICTABLE, 227 - 0, ggtt->mappable_end, 228 - DRM_MM_INSERT_LOW); 229 - if (ret) 230 - return ret; 231 - } 232 - 233 - /* 234 - * The upper portion of the GuC address space has a sizeable hole 235 - * (several MB) that is inaccessible by GuC. Reserve this range within 236 - * GGTT as it can comfortably hold GuC/HuC firmware images. 237 - */ 238 - ret = ggtt_reserve_guc_top(ggtt); 239 - if (ret) 240 - goto err; 241 - 242 - /* Clear any non-preallocated blocks */ 243 - drm_mm_for_each_hole(entry, &ggtt->vm.mm, hole_start, hole_end) { 244 - DRM_DEBUG_KMS("clearing unused GTT space: [%lx, %lx]\n", 245 - hole_start, hole_end); 246 - ggtt->vm.clear_range(&ggtt->vm, hole_start, 247 - hole_end - hole_start); 248 - } 249 - 250 - /* And finally clear the reserved guard page */ 251 - ggtt->vm.clear_range(&ggtt->vm, ggtt->vm.total - PAGE_SIZE, PAGE_SIZE); 252 - 253 - return 0; 254 - 255 - err: 256 - cleanup_init_ggtt(ggtt); 257 - return ret; 258 - } 259 - 260 - int i915_init_ggtt(struct drm_i915_private *i915) 261 - { 262 - int ret; 263 - 264 - ret = init_ggtt(&i915->ggtt); 265 - if (ret) 266 - return ret; 267 - 268 - if (INTEL_PPGTT(i915) == INTEL_PPGTT_ALIASING) { 269 - ret = init_aliasing_ppgtt(&i915->ggtt); 270 - if (ret) 271 - cleanup_init_ggtt(&i915->ggtt); 272 - } 273 - 274 - return 0; 275 - } 276 - 277 - static void ggtt_cleanup_hw(struct i915_ggtt *ggtt) 278 - { 279 - struct i915_vma *vma, *vn; 280 - 281 - atomic_set(&ggtt->vm.open, 0); 282 - 283 - rcu_barrier(); /* flush the RCU'ed__i915_vm_release */ 284 - flush_workqueue(ggtt->vm.i915->wq); 285 - 286 - mutex_lock(&ggtt->vm.mutex); 287 - 288 - list_for_each_entry_safe(vma, vn, &ggtt->vm.bound_list, vm_link) 289 - WARN_ON(__i915_vma_unbind(vma)); 290 - 291 - if (drm_mm_node_allocated(&ggtt->error_capture)) 292 - drm_mm_remove_node(&ggtt->error_capture); 293 - 294 - ggtt_release_guc_top(ggtt); 295 - intel_vgt_deballoon(ggtt); 296 - 297 - ggtt->vm.cleanup(&ggtt->vm); 298 - 299 - mutex_unlock(&ggtt->vm.mutex); 300 - i915_address_space_fini(&ggtt->vm); 301 - 302 - arch_phys_wc_del(ggtt->mtrr); 303 - 304 - if (ggtt->iomap.size) 305 - io_mapping_fini(&ggtt->iomap); 306 - } 307 - 308 - /** 309 - * i915_ggtt_driver_release - Clean up GGTT hardware initialization 310 - * @i915: i915 device 311 - */ 312 - void i915_ggtt_driver_release(struct drm_i915_private *i915) 313 - { 314 - struct pagevec *pvec; 315 - 316 - fini_aliasing_ppgtt(&i915->ggtt); 317 - 318 - ggtt_cleanup_hw(&i915->ggtt); 319 - 320 - pvec = &i915->mm.wc_stash.pvec; 321 - if (pvec->nr) { 322 - set_pages_array_wb(pvec->pages, pvec->nr); 323 - __pagevec_release(pvec); 324 - } 325 - } 326 - 327 - static unsigned int gen6_get_total_gtt_size(u16 snb_gmch_ctl) 328 - { 329 - snb_gmch_ctl >>= SNB_GMCH_GGMS_SHIFT; 330 - snb_gmch_ctl &= SNB_GMCH_GGMS_MASK; 331 - return snb_gmch_ctl << 20; 332 - } 333 - 334 - static unsigned int gen8_get_total_gtt_size(u16 bdw_gmch_ctl) 335 - { 336 - bdw_gmch_ctl >>= BDW_GMCH_GGMS_SHIFT; 337 - bdw_gmch_ctl &= BDW_GMCH_GGMS_MASK; 338 - if (bdw_gmch_ctl) 339 - bdw_gmch_ctl = 1 << bdw_gmch_ctl; 340 - 341 - #ifdef CONFIG_X86_32 342 - /* Limit 32b platforms to a 2GB GGTT: 4 << 20 / pte size * I915_GTT_PAGE_SIZE */ 343 - if (bdw_gmch_ctl > 4) 344 - bdw_gmch_ctl = 4; 345 - #endif 346 - 347 - return bdw_gmch_ctl << 20; 348 - } 349 - 350 - static unsigned int chv_get_total_gtt_size(u16 gmch_ctrl) 351 - { 352 - gmch_ctrl >>= SNB_GMCH_GGMS_SHIFT; 353 - gmch_ctrl &= SNB_GMCH_GGMS_MASK; 354 - 355 - if (gmch_ctrl) 356 - return 1 << (20 + gmch_ctrl); 357 - 358 - return 0; 359 - } 360 - 361 - static int ggtt_probe_common(struct i915_ggtt *ggtt, u64 size) 362 - { 363 - struct drm_i915_private *dev_priv = ggtt->vm.i915; 364 - struct pci_dev *pdev = dev_priv->drm.pdev; 365 - phys_addr_t phys_addr; 366 - int ret; 367 - 368 - /* For Modern GENs the PTEs and register space are split in the BAR */ 369 - phys_addr = pci_resource_start(pdev, 0) + pci_resource_len(pdev, 0) / 2; 370 - 371 - /* 372 - * On BXT+/CNL+ writes larger than 64 bit to the GTT pagetable range 373 - * will be dropped. For WC mappings in general we have 64 byte burst 374 - * writes when the WC buffer is flushed, so we can't use it, but have to 375 - * resort to an uncached mapping. The WC issue is easily caught by the 376 - * readback check when writing GTT PTE entries. 377 - */ 378 - if (IS_GEN9_LP(dev_priv) || INTEL_GEN(dev_priv) >= 10) 379 - ggtt->gsm = ioremap_nocache(phys_addr, size); 380 - else 381 - ggtt->gsm = ioremap_wc(phys_addr, size); 382 - if (!ggtt->gsm) { 383 - DRM_ERROR("Failed to map the ggtt page table\n"); 384 - return -ENOMEM; 385 - } 386 - 387 - ret = setup_scratch_page(&ggtt->vm, GFP_DMA32); 388 - if (ret) { 389 - DRM_ERROR("Scratch setup failed\n"); 390 - /* iounmap will also get called at remove, but meh */ 391 - iounmap(ggtt->gsm); 392 - return ret; 393 - } 394 - 395 - ggtt->vm.scratch[0].encode = 396 - ggtt->vm.pte_encode(px_dma(&ggtt->vm.scratch[0]), 397 - I915_CACHE_NONE, 0); 398 - 399 - return 0; 400 - } 401 - 402 - static void tgl_setup_private_ppat(struct intel_uncore *uncore) 403 - { 404 - /* TGL doesn't support LLC or AGE settings */ 405 - intel_uncore_write(uncore, GEN12_PAT_INDEX(0), GEN8_PPAT_WB); 406 - intel_uncore_write(uncore, GEN12_PAT_INDEX(1), GEN8_PPAT_WC); 407 - intel_uncore_write(uncore, GEN12_PAT_INDEX(2), GEN8_PPAT_WT); 408 - intel_uncore_write(uncore, GEN12_PAT_INDEX(3), GEN8_PPAT_UC); 409 - intel_uncore_write(uncore, GEN12_PAT_INDEX(4), GEN8_PPAT_WB); 410 - intel_uncore_write(uncore, GEN12_PAT_INDEX(5), GEN8_PPAT_WB); 411 - intel_uncore_write(uncore, GEN12_PAT_INDEX(6), GEN8_PPAT_WB); 412 - intel_uncore_write(uncore, GEN12_PAT_INDEX(7), GEN8_PPAT_WB); 413 - } 414 - 415 - static void cnl_setup_private_ppat(struct intel_uncore *uncore) 416 - { 417 - intel_uncore_write(uncore, 418 - GEN10_PAT_INDEX(0), 419 - GEN8_PPAT_WB | GEN8_PPAT_LLC); 420 - intel_uncore_write(uncore, 421 - GEN10_PAT_INDEX(1), 422 - GEN8_PPAT_WC | GEN8_PPAT_LLCELLC); 423 - intel_uncore_write(uncore, 424 - GEN10_PAT_INDEX(2), 425 - GEN8_PPAT_WT | GEN8_PPAT_LLCELLC); 426 - intel_uncore_write(uncore, 427 - GEN10_PAT_INDEX(3), 428 - GEN8_PPAT_UC); 429 - intel_uncore_write(uncore, 430 - GEN10_PAT_INDEX(4), 431 - GEN8_PPAT_WB | GEN8_PPAT_LLCELLC | GEN8_PPAT_AGE(0)); 432 - intel_uncore_write(uncore, 433 - GEN10_PAT_INDEX(5), 434 - GEN8_PPAT_WB | GEN8_PPAT_LLCELLC | GEN8_PPAT_AGE(1)); 435 - intel_uncore_write(uncore, 436 - GEN10_PAT_INDEX(6), 437 - GEN8_PPAT_WB | GEN8_PPAT_LLCELLC | GEN8_PPAT_AGE(2)); 438 - intel_uncore_write(uncore, 439 - GEN10_PAT_INDEX(7), 440 - GEN8_PPAT_WB | GEN8_PPAT_LLCELLC | GEN8_PPAT_AGE(3)); 441 - } 442 - 443 - /* The GGTT and PPGTT need a private PPAT setup in order to handle cacheability 444 - * bits. When using advanced contexts each context stores its own PAT, but 445 - * writing this data shouldn't be harmful even in those cases. */ 446 - static void bdw_setup_private_ppat(struct intel_uncore *uncore) 447 - { 448 - u64 pat; 449 - 450 - pat = GEN8_PPAT(0, GEN8_PPAT_WB | GEN8_PPAT_LLC) | /* for normal objects, no eLLC */ 451 - GEN8_PPAT(1, GEN8_PPAT_WC | GEN8_PPAT_LLCELLC) | /* for something pointing to ptes? */ 452 - GEN8_PPAT(2, GEN8_PPAT_WT | GEN8_PPAT_LLCELLC) | /* for scanout with eLLC */ 453 - GEN8_PPAT(3, GEN8_PPAT_UC) | /* Uncached objects, mostly for scanout */ 454 - GEN8_PPAT(4, GEN8_PPAT_WB | GEN8_PPAT_LLCELLC | GEN8_PPAT_AGE(0)) | 455 - GEN8_PPAT(5, GEN8_PPAT_WB | GEN8_PPAT_LLCELLC | GEN8_PPAT_AGE(1)) | 456 - GEN8_PPAT(6, GEN8_PPAT_WB | GEN8_PPAT_LLCELLC | GEN8_PPAT_AGE(2)) | 457 - GEN8_PPAT(7, GEN8_PPAT_WB | GEN8_PPAT_LLCELLC | GEN8_PPAT_AGE(3)); 458 - 459 - intel_uncore_write(uncore, GEN8_PRIVATE_PAT_LO, lower_32_bits(pat)); 460 - intel_uncore_write(uncore, GEN8_PRIVATE_PAT_HI, upper_32_bits(pat)); 461 - } 462 - 463 - static void chv_setup_private_ppat(struct intel_uncore *uncore) 464 - { 465 - u64 pat; 466 - 467 - /* 468 - * Map WB on BDW to snooped on CHV. 469 - * 470 - * Only the snoop bit has meaning for CHV, the rest is 471 - * ignored. 472 - * 473 - * The hardware will never snoop for certain types of accesses: 474 - * - CPU GTT (GMADR->GGTT->no snoop->memory) 475 - * - PPGTT page tables 476 - * - some other special cycles 477 - * 478 - * As with BDW, we also need to consider the following for GT accesses: 479 - * "For GGTT, there is NO pat_sel[2:0] from the entry, 480 - * so RTL will always use the value corresponding to 481 - * pat_sel = 000". 482 - * Which means we must set the snoop bit in PAT entry 0 483 - * in order to keep the global status page working. 484 - */ 485 - 486 - pat = GEN8_PPAT(0, CHV_PPAT_SNOOP) | 487 - GEN8_PPAT(1, 0) | 488 - GEN8_PPAT(2, 0) | 489 - GEN8_PPAT(3, 0) | 490 - GEN8_PPAT(4, CHV_PPAT_SNOOP) | 491 - GEN8_PPAT(5, CHV_PPAT_SNOOP) | 492 - GEN8_PPAT(6, CHV_PPAT_SNOOP) | 493 - GEN8_PPAT(7, CHV_PPAT_SNOOP); 494 - 495 - intel_uncore_write(uncore, GEN8_PRIVATE_PAT_LO, lower_32_bits(pat)); 496 - intel_uncore_write(uncore, GEN8_PRIVATE_PAT_HI, upper_32_bits(pat)); 497 - } 498 - 499 - static void gen6_gmch_remove(struct i915_address_space *vm) 500 - { 501 - struct i915_ggtt *ggtt = i915_vm_to_ggtt(vm); 502 - 503 - iounmap(ggtt->gsm); 504 - cleanup_scratch_page(vm); 505 - } 506 - 507 - static void setup_private_pat(struct intel_uncore *uncore) 508 - { 509 - struct drm_i915_private *i915 = uncore->i915; 510 - 511 - GEM_BUG_ON(INTEL_GEN(i915) < 8); 512 - 513 - if (INTEL_GEN(i915) >= 12) 514 - tgl_setup_private_ppat(uncore); 515 - else if (INTEL_GEN(i915) >= 10) 516 - cnl_setup_private_ppat(uncore); 517 - else if (IS_CHERRYVIEW(i915) || IS_GEN9_LP(i915)) 518 - chv_setup_private_ppat(uncore); 519 - else 520 - bdw_setup_private_ppat(uncore); 521 - } 522 - 523 - static struct resource pci_resource(struct pci_dev *pdev, int bar) 524 - { 525 - return (struct resource)DEFINE_RES_MEM(pci_resource_start(pdev, bar), 526 - pci_resource_len(pdev, bar)); 527 - } 528 - 529 - static int gen8_gmch_probe(struct i915_ggtt *ggtt) 530 - { 531 - struct drm_i915_private *dev_priv = ggtt->vm.i915; 532 - struct pci_dev *pdev = dev_priv->drm.pdev; 533 - unsigned int size; 534 - u16 snb_gmch_ctl; 535 - int err; 536 - 537 - /* TODO: We're not aware of mappable constraints on gen8 yet */ 538 - if (!IS_DGFX(dev_priv)) { 539 - ggtt->gmadr = pci_resource(pdev, 2); 540 - ggtt->mappable_end = resource_size(&ggtt->gmadr); 541 - } 542 - 543 - err = pci_set_dma_mask(pdev, DMA_BIT_MASK(39)); 544 - if (!err) 545 - err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(39)); 546 - if (err) 547 - DRM_ERROR("Can't set DMA mask/consistent mask (%d)\n", err); 548 - 549 - pci_read_config_word(pdev, SNB_GMCH_CTRL, &snb_gmch_ctl); 550 - if (IS_CHERRYVIEW(dev_priv)) 551 - size = chv_get_total_gtt_size(snb_gmch_ctl); 552 - else 553 - size = gen8_get_total_gtt_size(snb_gmch_ctl); 554 - 555 - ggtt->vm.total = (size / sizeof(gen8_pte_t)) * I915_GTT_PAGE_SIZE; 556 - ggtt->vm.cleanup = gen6_gmch_remove; 557 - ggtt->vm.insert_page = gen8_ggtt_insert_page; 558 - ggtt->vm.clear_range = nop_clear_range; 559 - if (intel_scanout_needs_vtd_wa(dev_priv)) 560 - ggtt->vm.clear_range = gen8_ggtt_clear_range; 561 - 562 - ggtt->vm.insert_entries = gen8_ggtt_insert_entries; 563 - 564 - /* Serialize GTT updates with aperture access on BXT if VT-d is on. */ 565 - if (intel_ggtt_update_needs_vtd_wa(dev_priv) || 566 - IS_CHERRYVIEW(dev_priv) /* fails with concurrent use/update */) { 567 - ggtt->vm.insert_entries = bxt_vtd_ggtt_insert_entries__BKL; 568 - ggtt->vm.insert_page = bxt_vtd_ggtt_insert_page__BKL; 569 - if (ggtt->vm.clear_range != nop_clear_range) 570 - ggtt->vm.clear_range = bxt_vtd_ggtt_clear_range__BKL; 571 - } 572 - 573 - ggtt->invalidate = gen8_ggtt_invalidate; 574 - 575 - ggtt->vm.vma_ops.bind_vma = ggtt_bind_vma; 576 - ggtt->vm.vma_ops.unbind_vma = ggtt_unbind_vma; 577 - ggtt->vm.vma_ops.set_pages = ggtt_set_pages; 578 - ggtt->vm.vma_ops.clear_pages = clear_pages; 579 - 580 - ggtt->vm.pte_encode = gen8_pte_encode; 581 - 582 - setup_private_pat(ggtt->vm.gt->uncore); 583 - 584 - return ggtt_probe_common(ggtt, size); 585 - } 586 - 587 - static int gen6_gmch_probe(struct i915_ggtt *ggtt) 588 - { 589 - struct drm_i915_private *dev_priv = ggtt->vm.i915; 590 - struct pci_dev *pdev = dev_priv->drm.pdev; 591 - unsigned int size; 592 - u16 snb_gmch_ctl; 593 - int err; 594 - 595 - ggtt->gmadr = 596 - (struct resource) DEFINE_RES_MEM(pci_resource_start(pdev, 2), 597 - pci_resource_len(pdev, 2)); 598 - ggtt->mappable_end = resource_size(&ggtt->gmadr); 599 - 600 - /* 64/512MB is the current min/max we actually know of, but this is just 601 - * a coarse sanity check. 602 - */ 603 - if (ggtt->mappable_end < (64<<20) || ggtt->mappable_end > (512<<20)) { 604 - DRM_ERROR("Unknown GMADR size (%pa)\n", &ggtt->mappable_end); 605 - return -ENXIO; 606 - } 607 - 608 - err = pci_set_dma_mask(pdev, DMA_BIT_MASK(40)); 609 - if (!err) 610 - err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(40)); 611 - if (err) 612 - DRM_ERROR("Can't set DMA mask/consistent mask (%d)\n", err); 613 - pci_read_config_word(pdev, SNB_GMCH_CTRL, &snb_gmch_ctl); 614 - 615 - size = gen6_get_total_gtt_size(snb_gmch_ctl); 616 - ggtt->vm.total = (size / sizeof(gen6_pte_t)) * I915_GTT_PAGE_SIZE; 617 - 618 - ggtt->vm.clear_range = nop_clear_range; 619 - if (!HAS_FULL_PPGTT(dev_priv) || intel_scanout_needs_vtd_wa(dev_priv)) 620 - ggtt->vm.clear_range = gen6_ggtt_clear_range; 621 - ggtt->vm.insert_page = gen6_ggtt_insert_page; 622 - ggtt->vm.insert_entries = gen6_ggtt_insert_entries; 623 - ggtt->vm.cleanup = gen6_gmch_remove; 624 - 625 - ggtt->invalidate = gen6_ggtt_invalidate; 626 - 627 - if (HAS_EDRAM(dev_priv)) 628 - ggtt->vm.pte_encode = iris_pte_encode; 629 - else if (IS_HASWELL(dev_priv)) 630 - ggtt->vm.pte_encode = hsw_pte_encode; 631 - else if (IS_VALLEYVIEW(dev_priv)) 632 - ggtt->vm.pte_encode = byt_pte_encode; 633 - else if (INTEL_GEN(dev_priv) >= 7) 634 - ggtt->vm.pte_encode = ivb_pte_encode; 635 - else 636 - ggtt->vm.pte_encode = snb_pte_encode; 637 - 638 - ggtt->vm.vma_ops.bind_vma = ggtt_bind_vma; 639 - ggtt->vm.vma_ops.unbind_vma = ggtt_unbind_vma; 640 - ggtt->vm.vma_ops.set_pages = ggtt_set_pages; 641 - ggtt->vm.vma_ops.clear_pages = clear_pages; 642 - 643 - return ggtt_probe_common(ggtt, size); 644 - } 645 - 646 - static void i915_gmch_remove(struct i915_address_space *vm) 647 - { 648 - intel_gmch_remove(); 649 - } 650 - 651 - static int i915_gmch_probe(struct i915_ggtt *ggtt) 652 - { 653 - struct drm_i915_private *dev_priv = ggtt->vm.i915; 654 - phys_addr_t gmadr_base; 655 - int ret; 656 - 657 - ret = intel_gmch_probe(dev_priv->bridge_dev, dev_priv->drm.pdev, NULL); 658 - if (!ret) { 659 - DRM_ERROR("failed to set up gmch\n"); 660 - return -EIO; 661 - } 662 - 663 - intel_gtt_get(&ggtt->vm.total, &gmadr_base, &ggtt->mappable_end); 664 - 665 - ggtt->gmadr = 666 - (struct resource) DEFINE_RES_MEM(gmadr_base, 667 - ggtt->mappable_end); 668 - 669 - ggtt->do_idle_maps = needs_idle_maps(dev_priv); 670 - ggtt->vm.insert_page = i915_ggtt_insert_page; 671 - ggtt->vm.insert_entries = i915_ggtt_insert_entries; 672 - ggtt->vm.clear_range = i915_ggtt_clear_range; 673 - ggtt->vm.cleanup = i915_gmch_remove; 674 - 675 - ggtt->invalidate = gmch_ggtt_invalidate; 676 - 677 - ggtt->vm.vma_ops.bind_vma = ggtt_bind_vma; 678 - ggtt->vm.vma_ops.unbind_vma = ggtt_unbind_vma; 679 - ggtt->vm.vma_ops.set_pages = ggtt_set_pages; 680 - ggtt->vm.vma_ops.clear_pages = clear_pages; 681 - 682 - if (unlikely(ggtt->do_idle_maps)) 683 - dev_notice(dev_priv->drm.dev, 684 - "Applying Ironlake quirks for intel_iommu\n"); 685 - 686 - return 0; 687 - } 688 - 689 - static int ggtt_probe_hw(struct i915_ggtt *ggtt, struct intel_gt *gt) 690 - { 691 - struct drm_i915_private *i915 = gt->i915; 692 - int ret; 693 - 694 - ggtt->vm.gt = gt; 695 - ggtt->vm.i915 = i915; 696 - ggtt->vm.dma = &i915->drm.pdev->dev; 697 - 698 - if (INTEL_GEN(i915) <= 5) 699 - ret = i915_gmch_probe(ggtt); 700 - else if (INTEL_GEN(i915) < 8) 701 - ret = gen6_gmch_probe(ggtt); 702 - else 703 - ret = gen8_gmch_probe(ggtt); 704 - if (ret) 705 - return ret; 706 - 707 - if ((ggtt->vm.total - 1) >> 32) { 708 - DRM_ERROR("We never expected a Global GTT with more than 32bits" 709 - " of address space! Found %lldM!\n", 710 - ggtt->vm.total >> 20); 711 - ggtt->vm.total = 1ULL << 32; 712 - ggtt->mappable_end = 713 - min_t(u64, ggtt->mappable_end, ggtt->vm.total); 714 - } 715 - 716 - if (ggtt->mappable_end > ggtt->vm.total) { 717 - DRM_ERROR("mappable aperture extends past end of GGTT," 718 - " aperture=%pa, total=%llx\n", 719 - &ggtt->mappable_end, ggtt->vm.total); 720 - ggtt->mappable_end = ggtt->vm.total; 721 - } 722 - 723 - /* GMADR is the PCI mmio aperture into the global GTT. */ 724 - DRM_DEBUG_DRIVER("GGTT size = %lluM\n", ggtt->vm.total >> 20); 725 - DRM_DEBUG_DRIVER("GMADR size = %lluM\n", (u64)ggtt->mappable_end >> 20); 726 - DRM_DEBUG_DRIVER("DSM size = %lluM\n", 727 - (u64)resource_size(&intel_graphics_stolen_res) >> 20); 728 - 729 - return 0; 730 - } 731 - 732 - /** 733 - * i915_ggtt_probe_hw - Probe GGTT hardware location 734 - * @i915: i915 device 735 - */ 736 - int i915_ggtt_probe_hw(struct drm_i915_private *i915) 737 - { 738 - int ret; 739 - 740 - ret = ggtt_probe_hw(&i915->ggtt, &i915->gt); 741 - if (ret) 742 - return ret; 743 - 744 - if (intel_vtd_active()) 745 - dev_info(i915->drm.dev, "VT-d active for gfx access\n"); 746 - 747 - return 0; 748 - } 749 - 750 - static int ggtt_init_hw(struct i915_ggtt *ggtt) 751 - { 752 - struct drm_i915_private *i915 = ggtt->vm.i915; 753 - 754 - i915_address_space_init(&ggtt->vm, VM_CLASS_GGTT); 755 - 756 - ggtt->vm.is_ggtt = true; 757 - 758 - /* Only VLV supports read-only GGTT mappings */ 759 - ggtt->vm.has_read_only = IS_VALLEYVIEW(i915); 760 - 761 - if (!HAS_LLC(i915) && !HAS_PPGTT(i915)) 762 - ggtt->vm.mm.color_adjust = i915_ggtt_color_adjust; 763 - 764 - if (ggtt->mappable_end) { 765 - if (!io_mapping_init_wc(&ggtt->iomap, 766 - ggtt->gmadr.start, 767 - ggtt->mappable_end)) { 768 - ggtt->vm.cleanup(&ggtt->vm); 769 - return -EIO; 770 - } 771 - 772 - ggtt->mtrr = arch_phys_wc_add(ggtt->gmadr.start, 773 - ggtt->mappable_end); 774 - } 775 - 776 - i915_ggtt_init_fences(ggtt); 777 - 778 - return 0; 779 - } 780 - 781 - /** 782 - * i915_ggtt_init_hw - Initialize GGTT hardware 783 - * @dev_priv: i915 device 784 - */ 785 - int i915_ggtt_init_hw(struct drm_i915_private *dev_priv) 786 - { 787 - int ret; 788 - 789 - stash_init(&dev_priv->mm.wc_stash); 790 - 791 - /* Note that we use page colouring to enforce a guard page at the 792 - * end of the address space. This is required as the CS may prefetch 793 - * beyond the end of the batch buffer, across the page boundary, 794 - * and beyond the end of the GTT if we do not provide a guard. 795 - */ 796 - ret = ggtt_init_hw(&dev_priv->ggtt); 797 - if (ret) 798 - return ret; 799 - 800 - return 0; 801 - } 802 - 803 - int i915_ggtt_enable_hw(struct drm_i915_private *dev_priv) 804 - { 805 - if (INTEL_GEN(dev_priv) < 6 && !intel_enable_gtt()) 806 - return -EIO; 807 - 808 - return 0; 809 - } 810 - 811 - void i915_ggtt_enable_guc(struct i915_ggtt *ggtt) 812 - { 813 - GEM_BUG_ON(ggtt->invalidate != gen8_ggtt_invalidate); 814 - 815 - ggtt->invalidate = guc_ggtt_invalidate; 816 - 817 - ggtt->invalidate(ggtt); 818 - } 819 - 820 - void i915_ggtt_disable_guc(struct i915_ggtt *ggtt) 821 - { 822 - /* XXX Temporary pardon for error unload */ 823 - if (ggtt->invalidate == gen8_ggtt_invalidate) 824 - return; 825 - 826 - /* We should only be called after i915_ggtt_enable_guc() */ 827 - GEM_BUG_ON(ggtt->invalidate != guc_ggtt_invalidate); 828 - 829 - ggtt->invalidate = gen8_ggtt_invalidate; 830 - 831 - ggtt->invalidate(ggtt); 832 - } 833 - 834 - static void ggtt_restore_mappings(struct i915_ggtt *ggtt) 835 - { 836 - struct i915_vma *vma, *vn; 837 - bool flush = false; 838 - int open; 839 - 840 - intel_gt_check_and_clear_faults(ggtt->vm.gt); 841 - 842 - mutex_lock(&ggtt->vm.mutex); 843 - 844 - /* First fill our portion of the GTT with scratch pages */ 845 - ggtt->vm.clear_range(&ggtt->vm, 0, ggtt->vm.total); 846 - 847 - /* Skip rewriting PTE on VMA unbind. */ 848 - open = atomic_xchg(&ggtt->vm.open, 0); 849 - 850 - /* clflush objects bound into the GGTT and rebind them. */ 851 - list_for_each_entry_safe(vma, vn, &ggtt->vm.bound_list, vm_link) { 852 - struct drm_i915_gem_object *obj = vma->obj; 853 - 854 - if (!i915_vma_is_bound(vma, I915_VMA_GLOBAL_BIND)) 855 - continue; 856 - 857 - if (!__i915_vma_unbind(vma)) 858 - continue; 859 - 860 - clear_bit(I915_VMA_GLOBAL_BIND_BIT, __i915_vma_flags(vma)); 861 - WARN_ON(i915_vma_bind(vma, 862 - obj ? obj->cache_level : 0, 863 - PIN_GLOBAL, NULL)); 864 - if (obj) { /* only used during resume => exclusive access */ 865 - flush |= fetch_and_zero(&obj->write_domain); 866 - obj->read_domains |= I915_GEM_DOMAIN_GTT; 867 - } 868 - } 869 - 870 - atomic_set(&ggtt->vm.open, open); 871 - ggtt->invalidate(ggtt); 872 - 873 - mutex_unlock(&ggtt->vm.mutex); 874 - 875 - if (flush) 876 - wbinvd_on_all_cpus(); 877 - } 878 - 879 - void i915_gem_restore_gtt_mappings(struct drm_i915_private *i915) 880 - { 881 - struct i915_ggtt *ggtt = &i915->ggtt; 882 - 883 - ggtt_restore_mappings(ggtt); 884 - 885 - if (INTEL_GEN(i915) >= 8) 886 - setup_private_pat(ggtt->vm.gt->uncore); 887 - } 888 - 889 - static struct scatterlist * 890 - rotate_pages(struct drm_i915_gem_object *obj, unsigned int offset, 891 - unsigned int width, unsigned int height, 892 - unsigned int stride, 893 - struct sg_table *st, struct scatterlist *sg) 894 - { 895 - unsigned int column, row; 896 - unsigned int src_idx; 897 - 898 - for (column = 0; column < width; column++) { 899 - src_idx = stride * (height - 1) + column + offset; 900 - for (row = 0; row < height; row++) { 901 - st->nents++; 902 - /* We don't need the pages, but need to initialize 903 - * the entries so the sg list can be happily traversed. 904 - * The only thing we need are DMA addresses. 905 - */ 906 - sg_set_page(sg, NULL, I915_GTT_PAGE_SIZE, 0); 907 - sg_dma_address(sg) = 908 - i915_gem_object_get_dma_address(obj, src_idx); 909 - sg_dma_len(sg) = I915_GTT_PAGE_SIZE; 910 - sg = sg_next(sg); 911 - src_idx -= stride; 912 - } 913 - } 914 - 915 - return sg; 916 - } 917 - 918 - static noinline struct sg_table * 919 - intel_rotate_pages(struct intel_rotation_info *rot_info, 920 - struct drm_i915_gem_object *obj) 921 - { 922 - unsigned int size = intel_rotation_info_size(rot_info); 923 - struct sg_table *st; 924 - struct scatterlist *sg; 925 - int ret = -ENOMEM; 926 - int i; 927 - 928 - /* Allocate target SG list. */ 929 - st = kmalloc(sizeof(*st), GFP_KERNEL); 930 - if (!st) 931 - goto err_st_alloc; 932 - 933 - ret = sg_alloc_table(st, size, GFP_KERNEL); 934 - if (ret) 935 - goto err_sg_alloc; 936 - 937 - st->nents = 0; 938 - sg = st->sgl; 939 - 940 - for (i = 0 ; i < ARRAY_SIZE(rot_info->plane); i++) { 941 - sg = rotate_pages(obj, rot_info->plane[i].offset, 942 - rot_info->plane[i].width, rot_info->plane[i].height, 943 - rot_info->plane[i].stride, st, sg); 944 - } 945 - 946 - return st; 947 - 948 - err_sg_alloc: 949 - kfree(st); 950 - err_st_alloc: 951 - 952 - DRM_DEBUG_DRIVER("Failed to create rotated mapping for object size %zu! (%ux%u tiles, %u pages)\n", 953 - obj->base.size, rot_info->plane[0].width, rot_info->plane[0].height, size); 954 - 955 - return ERR_PTR(ret); 956 - } 957 - 958 - static struct scatterlist * 959 - remap_pages(struct drm_i915_gem_object *obj, unsigned int offset, 960 - unsigned int width, unsigned int height, 961 - unsigned int stride, 962 - struct sg_table *st, struct scatterlist *sg) 963 - { 964 - unsigned int row; 965 - 966 - for (row = 0; row < height; row++) { 967 - unsigned int left = width * I915_GTT_PAGE_SIZE; 968 - 969 - while (left) { 970 - dma_addr_t addr; 971 - unsigned int length; 972 - 973 - /* We don't need the pages, but need to initialize 974 - * the entries so the sg list can be happily traversed. 975 - * The only thing we need are DMA addresses. 976 - */ 977 - 978 - addr = i915_gem_object_get_dma_address_len(obj, offset, &length); 979 - 980 - length = min(left, length); 981 - 982 - st->nents++; 983 - 984 - sg_set_page(sg, NULL, length, 0); 985 - sg_dma_address(sg) = addr; 986 - sg_dma_len(sg) = length; 987 - sg = sg_next(sg); 988 - 989 - offset += length / I915_GTT_PAGE_SIZE; 990 - left -= length; 991 - } 992 - 993 - offset += stride - width; 994 - } 995 - 996 - return sg; 997 - } 998 - 999 - static noinline struct sg_table * 1000 - intel_remap_pages(struct intel_remapped_info *rem_info, 1001 - struct drm_i915_gem_object *obj) 1002 - { 1003 - unsigned int size = intel_remapped_info_size(rem_info); 1004 - struct sg_table *st; 1005 - struct scatterlist *sg; 1006 - int ret = -ENOMEM; 1007 - int i; 1008 - 1009 - /* Allocate target SG list. */ 1010 - st = kmalloc(sizeof(*st), GFP_KERNEL); 1011 - if (!st) 1012 - goto err_st_alloc; 1013 - 1014 - ret = sg_alloc_table(st, size, GFP_KERNEL); 1015 - if (ret) 1016 - goto err_sg_alloc; 1017 - 1018 - st->nents = 0; 1019 - sg = st->sgl; 1020 - 1021 - for (i = 0 ; i < ARRAY_SIZE(rem_info->plane); i++) { 1022 - sg = remap_pages(obj, rem_info->plane[i].offset, 1023 - rem_info->plane[i].width, rem_info->plane[i].height, 1024 - rem_info->plane[i].stride, st, sg); 1025 - } 1026 - 1027 - i915_sg_trim(st); 1028 - 1029 - return st; 1030 - 1031 - err_sg_alloc: 1032 - kfree(st); 1033 - err_st_alloc: 1034 - 1035 - DRM_DEBUG_DRIVER("Failed to create remapped mapping for object size %zu! (%ux%u tiles, %u pages)\n", 1036 - obj->base.size, rem_info->plane[0].width, rem_info->plane[0].height, size); 1037 - 1038 - return ERR_PTR(ret); 1039 - } 1040 - 1041 - static noinline struct sg_table * 1042 - intel_partial_pages(const struct i915_ggtt_view *view, 1043 - struct drm_i915_gem_object *obj) 1044 - { 1045 - struct sg_table *st; 1046 - struct scatterlist *sg, *iter; 1047 - unsigned int count = view->partial.size; 1048 - unsigned int offset; 1049 - int ret = -ENOMEM; 1050 - 1051 - st = kmalloc(sizeof(*st), GFP_KERNEL); 1052 - if (!st) 1053 - goto err_st_alloc; 1054 - 1055 - ret = sg_alloc_table(st, count, GFP_KERNEL); 1056 - if (ret) 1057 - goto err_sg_alloc; 1058 - 1059 - iter = i915_gem_object_get_sg(obj, view->partial.offset, &offset); 1060 - GEM_BUG_ON(!iter); 1061 - 1062 - sg = st->sgl; 1063 - st->nents = 0; 1064 - do { 1065 - unsigned int len; 1066 - 1067 - len = min(iter->length - (offset << PAGE_SHIFT), 1068 - count << PAGE_SHIFT); 1069 - sg_set_page(sg, NULL, len, 0); 1070 - sg_dma_address(sg) = 1071 - sg_dma_address(iter) + (offset << PAGE_SHIFT); 1072 - sg_dma_len(sg) = len; 1073 - 1074 - st->nents++; 1075 - count -= len >> PAGE_SHIFT; 1076 - if (count == 0) { 1077 - sg_mark_end(sg); 1078 - i915_sg_trim(st); /* Drop any unused tail entries. */ 1079 - 1080 - return st; 1081 - } 1082 - 1083 - sg = __sg_next(sg); 1084 - iter = __sg_next(iter); 1085 - offset = 0; 1086 - } while (1); 1087 - 1088 - err_sg_alloc: 1089 - kfree(st); 1090 - err_st_alloc: 1091 - return ERR_PTR(ret); 1092 - } 1093 - 1094 - static int 1095 - i915_get_ggtt_vma_pages(struct i915_vma *vma) 1096 - { 1097 - int ret; 1098 - 1099 - /* The vma->pages are only valid within the lifespan of the borrowed 1100 - * obj->mm.pages. When the obj->mm.pages sg_table is regenerated, so 1101 - * must be the vma->pages. A simple rule is that vma->pages must only 1102 - * be accessed when the obj->mm.pages are pinned. 1103 - */ 1104 - GEM_BUG_ON(!i915_gem_object_has_pinned_pages(vma->obj)); 1105 - 1106 - switch (vma->ggtt_view.type) { 1107 - default: 1108 - GEM_BUG_ON(vma->ggtt_view.type); 1109 - /* fall through */ 1110 - case I915_GGTT_VIEW_NORMAL: 1111 - vma->pages = vma->obj->mm.pages; 1112 - return 0; 1113 - 1114 - case I915_GGTT_VIEW_ROTATED: 1115 - vma->pages = 1116 - intel_rotate_pages(&vma->ggtt_view.rotated, vma->obj); 1117 - break; 1118 - 1119 - case I915_GGTT_VIEW_REMAPPED: 1120 - vma->pages = 1121 - intel_remap_pages(&vma->ggtt_view.remapped, vma->obj); 1122 - break; 1123 - 1124 - case I915_GGTT_VIEW_PARTIAL: 1125 - vma->pages = intel_partial_pages(&vma->ggtt_view, vma->obj); 1126 - break; 1127 - } 1128 - 1129 - ret = 0; 1130 - if (IS_ERR(vma->pages)) { 1131 - ret = PTR_ERR(vma->pages); 1132 - vma->pages = NULL; 1133 - DRM_ERROR("Failed to get pages for VMA view type %u (%d)!\n", 1134 - vma->ggtt_view.type, ret); 1135 - } 1136 - return ret; 1137 2564 } 1138 2565 1139 2566 /** ··· 293 3848 } 294 3849 295 3850 #if IS_ENABLED(CONFIG_DRM_I915_SELFTEST) 296 - #include "selftests/mock_gtt.c" 297 3851 #include "selftests/i915_gem_gtt.c" 298 3852 #endif
+6 -624
drivers/gpu/drm/i915/i915_gem_gtt.h
··· 1 + /* SPDX-License-Identifier: MIT */ 1 2 /* 2 - * Copyright © 2014 Intel Corporation 3 - * 4 - * Permission is hereby granted, free of charge, to any person obtaining a 5 - * copy of this software and associated documentation files (the "Software"), 6 - * to deal in the Software without restriction, including without limitation 7 - * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 - * and/or sell copies of the Software, and to permit persons to whom the 9 - * Software is furnished to do so, subject to the following conditions: 10 - * 11 - * The above copyright notice and this permission notice (including the next 12 - * paragraph) shall be included in all copies or substantial portions of the 13 - * Software. 14 - * 15 - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18 - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20 - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 21 - * IN THE SOFTWARE. 22 - * 23 - * Please try to maintain the following order within this file unless it makes 24 - * sense to do otherwise. From top to bottom: 25 - * 1. typedefs 26 - * 2. #defines, and macros 27 - * 3. structure definitions 28 - * 4. function prototypes 29 - * 30 - * Within each section, please try to order by generation in ascending order, 31 - * from top to bottom (ie. gen6 on the top, gen8 on the bottom). 3 + * Copyright © 2020 Intel Corporation 32 4 */ 33 5 34 6 #ifndef __I915_GEM_GTT_H__ 35 7 #define __I915_GEM_GTT_H__ 36 8 37 9 #include <linux/io-mapping.h> 38 - #include <linux/kref.h> 39 - #include <linux/mm.h> 40 - #include <linux/pagevec.h> 41 - #include <linux/workqueue.h> 10 + #include <linux/types.h> 42 11 43 12 #include <drm/drm_mm.h> 44 13 45 - #include "gt/intel_reset.h" 46 - #include "i915_gem_fence_reg.h" 47 - #include "i915_request.h" 14 + #include "gt/intel_gtt.h" 48 15 #include "i915_scatterlist.h" 49 - #include "i915_selftest.h" 50 - #include "gt/intel_timeline.h" 51 16 52 - #define I915_GTT_PAGE_SIZE_4K BIT_ULL(12) 53 - #define I915_GTT_PAGE_SIZE_64K BIT_ULL(16) 54 - #define I915_GTT_PAGE_SIZE_2M BIT_ULL(21) 55 - 56 - #define I915_GTT_PAGE_SIZE I915_GTT_PAGE_SIZE_4K 57 - #define I915_GTT_MAX_PAGE_SIZE I915_GTT_PAGE_SIZE_2M 58 - 59 - #define I915_GTT_PAGE_MASK -I915_GTT_PAGE_SIZE 60 - 61 - #define I915_GTT_MIN_ALIGNMENT I915_GTT_PAGE_SIZE 62 - 63 - #define I915_FENCE_REG_NONE -1 64 - #define I915_MAX_NUM_FENCES 32 65 - /* 32 fences + sign bit for FENCE_REG_NONE */ 66 - #define I915_MAX_NUM_FENCE_BITS 6 67 - 68 - struct drm_i915_file_private; 69 17 struct drm_i915_gem_object; 70 - struct i915_vma; 71 - struct intel_gt; 72 - 73 - typedef u32 gen6_pte_t; 74 - typedef u64 gen8_pte_t; 75 - 76 - #define ggtt_total_entries(ggtt) ((ggtt)->vm.total >> PAGE_SHIFT) 77 - 78 - /* gen6-hsw has bit 11-4 for physical addr bit 39-32 */ 79 - #define GEN6_GTT_ADDR_ENCODE(addr) ((addr) | (((addr) >> 28) & 0xff0)) 80 - #define GEN6_PTE_ADDR_ENCODE(addr) GEN6_GTT_ADDR_ENCODE(addr) 81 - #define GEN6_PDE_ADDR_ENCODE(addr) GEN6_GTT_ADDR_ENCODE(addr) 82 - #define GEN6_PTE_CACHE_LLC (2 << 1) 83 - #define GEN6_PTE_UNCACHED (1 << 1) 84 - #define GEN6_PTE_VALID (1 << 0) 85 - 86 - #define I915_PTES(pte_len) ((unsigned int)(PAGE_SIZE / (pte_len))) 87 - #define I915_PTE_MASK(pte_len) (I915_PTES(pte_len) - 1) 88 - #define I915_PDES 512 89 - #define I915_PDE_MASK (I915_PDES - 1) 90 - #define NUM_PTE(pde_shift) (1 << (pde_shift - PAGE_SHIFT)) 91 - 92 - #define GEN6_PTES I915_PTES(sizeof(gen6_pte_t)) 93 - #define GEN6_PD_SIZE (I915_PDES * PAGE_SIZE) 94 - #define GEN6_PD_ALIGN (PAGE_SIZE * 16) 95 - #define GEN6_PDE_SHIFT 22 96 - #define GEN6_PDE_VALID (1 << 0) 97 - 98 - #define GEN7_PTE_CACHE_L3_LLC (3 << 1) 99 - 100 - #define BYT_PTE_SNOOPED_BY_CPU_CACHES (1 << 2) 101 - #define BYT_PTE_WRITEABLE (1 << 1) 102 - 103 - /* Cacheability Control is a 4-bit value. The low three bits are stored in bits 104 - * 3:1 of the PTE, while the fourth bit is stored in bit 11 of the PTE. 105 - */ 106 - #define HSW_CACHEABILITY_CONTROL(bits) ((((bits) & 0x7) << 1) | \ 107 - (((bits) & 0x8) << (11 - 3))) 108 - #define HSW_WB_LLC_AGE3 HSW_CACHEABILITY_CONTROL(0x2) 109 - #define HSW_WB_LLC_AGE0 HSW_CACHEABILITY_CONTROL(0x3) 110 - #define HSW_WB_ELLC_LLC_AGE3 HSW_CACHEABILITY_CONTROL(0x8) 111 - #define HSW_WB_ELLC_LLC_AGE0 HSW_CACHEABILITY_CONTROL(0xb) 112 - #define HSW_WT_ELLC_LLC_AGE3 HSW_CACHEABILITY_CONTROL(0x7) 113 - #define HSW_WT_ELLC_LLC_AGE0 HSW_CACHEABILITY_CONTROL(0x6) 114 - #define HSW_PTE_UNCACHED (0) 115 - #define HSW_GTT_ADDR_ENCODE(addr) ((addr) | (((addr) >> 28) & 0x7f0)) 116 - #define HSW_PTE_ADDR_ENCODE(addr) HSW_GTT_ADDR_ENCODE(addr) 117 - 118 - /* 119 - * GEN8 32b style address is defined as a 3 level page table: 120 - * 31:30 | 29:21 | 20:12 | 11:0 121 - * PDPE | PDE | PTE | offset 122 - * The difference as compared to normal x86 3 level page table is the PDPEs are 123 - * programmed via register. 124 - * 125 - * GEN8 48b style address is defined as a 4 level page table: 126 - * 47:39 | 38:30 | 29:21 | 20:12 | 11:0 127 - * PML4E | PDPE | PDE | PTE | offset 128 - */ 129 - #define GEN8_3LVL_PDPES 4 130 - 131 - #define PPAT_UNCACHED (_PAGE_PWT | _PAGE_PCD) 132 - #define PPAT_CACHED_PDE 0 /* WB LLC */ 133 - #define PPAT_CACHED _PAGE_PAT /* WB LLCeLLC */ 134 - #define PPAT_DISPLAY_ELLC _PAGE_PCD /* WT eLLC */ 135 - 136 - #define CHV_PPAT_SNOOP (1<<6) 137 - #define GEN8_PPAT_AGE(x) ((x)<<4) 138 - #define GEN8_PPAT_LLCeLLC (3<<2) 139 - #define GEN8_PPAT_LLCELLC (2<<2) 140 - #define GEN8_PPAT_LLC (1<<2) 141 - #define GEN8_PPAT_WB (3<<0) 142 - #define GEN8_PPAT_WT (2<<0) 143 - #define GEN8_PPAT_WC (1<<0) 144 - #define GEN8_PPAT_UC (0<<0) 145 - #define GEN8_PPAT_ELLC_OVERRIDE (0<<2) 146 - #define GEN8_PPAT(i, x) ((u64)(x) << ((i) * 8)) 147 - 148 - #define GEN8_PDE_IPS_64K BIT(11) 149 - #define GEN8_PDE_PS_2M BIT(7) 150 - 151 - #define for_each_sgt_daddr(__dp, __iter, __sgt) \ 152 - __for_each_sgt_daddr(__dp, __iter, __sgt, I915_GTT_PAGE_SIZE) 153 - 154 - struct intel_remapped_plane_info { 155 - /* in gtt pages */ 156 - unsigned int width, height, stride, offset; 157 - } __packed; 158 - 159 - struct intel_remapped_info { 160 - struct intel_remapped_plane_info plane[2]; 161 - unsigned int unused_mbz; 162 - } __packed; 163 - 164 - struct intel_rotation_info { 165 - struct intel_remapped_plane_info plane[2]; 166 - } __packed; 167 - 168 - struct intel_partial_info { 169 - u64 offset; 170 - unsigned int size; 171 - } __packed; 172 - 173 - enum i915_ggtt_view_type { 174 - I915_GGTT_VIEW_NORMAL = 0, 175 - I915_GGTT_VIEW_ROTATED = sizeof(struct intel_rotation_info), 176 - I915_GGTT_VIEW_PARTIAL = sizeof(struct intel_partial_info), 177 - I915_GGTT_VIEW_REMAPPED = sizeof(struct intel_remapped_info), 178 - }; 179 - 180 - static inline void assert_i915_gem_gtt_types(void) 181 - { 182 - BUILD_BUG_ON(sizeof(struct intel_rotation_info) != 8*sizeof(unsigned int)); 183 - BUILD_BUG_ON(sizeof(struct intel_partial_info) != sizeof(u64) + sizeof(unsigned int)); 184 - BUILD_BUG_ON(sizeof(struct intel_remapped_info) != 9*sizeof(unsigned int)); 185 - 186 - /* Check that rotation/remapped shares offsets for simplicity */ 187 - BUILD_BUG_ON(offsetof(struct intel_remapped_info, plane[0]) != 188 - offsetof(struct intel_rotation_info, plane[0])); 189 - BUILD_BUG_ON(offsetofend(struct intel_remapped_info, plane[1]) != 190 - offsetofend(struct intel_rotation_info, plane[1])); 191 - 192 - /* As we encode the size of each branch inside the union into its type, 193 - * we have to be careful that each branch has a unique size. 194 - */ 195 - switch ((enum i915_ggtt_view_type)0) { 196 - case I915_GGTT_VIEW_NORMAL: 197 - case I915_GGTT_VIEW_PARTIAL: 198 - case I915_GGTT_VIEW_ROTATED: 199 - case I915_GGTT_VIEW_REMAPPED: 200 - /* gcc complains if these are identical cases */ 201 - break; 202 - } 203 - } 204 - 205 - struct i915_ggtt_view { 206 - enum i915_ggtt_view_type type; 207 - union { 208 - /* Members need to contain no holes/padding */ 209 - struct intel_partial_info partial; 210 - struct intel_rotation_info rotated; 211 - struct intel_remapped_info remapped; 212 - }; 213 - }; 214 - 215 - enum i915_cache_level; 216 - 217 - struct i915_vma; 218 - 219 - struct i915_page_dma { 220 - struct page *page; 221 - union { 222 - dma_addr_t daddr; 223 - 224 - /* For gen6/gen7 only. This is the offset in the GGTT 225 - * where the page directory entries for PPGTT begin 226 - */ 227 - u32 ggtt_offset; 228 - }; 229 - }; 230 - 231 - struct i915_page_scratch { 232 - struct i915_page_dma base; 233 - u64 encode; 234 - }; 235 - 236 - struct i915_page_table { 237 - struct i915_page_dma base; 238 - atomic_t used; 239 - }; 240 - 241 - struct i915_page_directory { 242 - struct i915_page_table pt; 243 - spinlock_t lock; 244 - void *entry[512]; 245 - }; 246 - 247 - #define __px_choose_expr(x, type, expr, other) \ 248 - __builtin_choose_expr( \ 249 - __builtin_types_compatible_p(typeof(x), type) || \ 250 - __builtin_types_compatible_p(typeof(x), const type), \ 251 - ({ type __x = (type)(x); expr; }), \ 252 - other) 253 - 254 - #define px_base(px) \ 255 - __px_choose_expr(px, struct i915_page_dma *, __x, \ 256 - __px_choose_expr(px, struct i915_page_scratch *, &__x->base, \ 257 - __px_choose_expr(px, struct i915_page_table *, &__x->base, \ 258 - __px_choose_expr(px, struct i915_page_directory *, &__x->pt.base, \ 259 - (void)0)))) 260 - #define px_dma(px) (px_base(px)->daddr) 261 - 262 - #define px_pt(px) \ 263 - __px_choose_expr(px, struct i915_page_table *, __x, \ 264 - __px_choose_expr(px, struct i915_page_directory *, &__x->pt, \ 265 - (void)0)) 266 - #define px_used(px) (&px_pt(px)->used) 267 - 268 - struct i915_vma_ops { 269 - /* Map an object into an address space with the given cache flags. */ 270 - int (*bind_vma)(struct i915_vma *vma, 271 - enum i915_cache_level cache_level, 272 - u32 flags); 273 - /* 274 - * Unmap an object from an address space. This usually consists of 275 - * setting the valid PTE entries to a reserved scratch page. 276 - */ 277 - void (*unbind_vma)(struct i915_vma *vma); 278 - 279 - int (*set_pages)(struct i915_vma *vma); 280 - void (*clear_pages)(struct i915_vma *vma); 281 - }; 282 - 283 - struct pagestash { 284 - spinlock_t lock; 285 - struct pagevec pvec; 286 - }; 287 - 288 - struct i915_address_space { 289 - struct kref ref; 290 - struct rcu_work rcu; 291 - 292 - struct drm_mm mm; 293 - struct intel_gt *gt; 294 - struct drm_i915_private *i915; 295 - struct device *dma; 296 - /* Every address space belongs to a struct file - except for the global 297 - * GTT that is owned by the driver (and so @file is set to NULL). In 298 - * principle, no information should leak from one context to another 299 - * (or between files/processes etc) unless explicitly shared by the 300 - * owner. Tracking the owner is important in order to free up per-file 301 - * objects along with the file, to aide resource tracking, and to 302 - * assign blame. 303 - */ 304 - struct drm_i915_file_private *file; 305 - u64 total; /* size addr space maps (ex. 2GB for ggtt) */ 306 - u64 reserved; /* size addr space reserved */ 307 - 308 - unsigned int bind_async_flags; 309 - 310 - /* 311 - * Each active user context has its own address space (in full-ppgtt). 312 - * Since the vm may be shared between multiple contexts, we count how 313 - * many contexts keep us "open". Once open hits zero, we are closed 314 - * and do not allow any new attachments, and proceed to shutdown our 315 - * vma and page directories. 316 - */ 317 - atomic_t open; 318 - 319 - struct mutex mutex; /* protects vma and our lists */ 320 - #define VM_CLASS_GGTT 0 321 - #define VM_CLASS_PPGTT 1 322 - 323 - struct i915_page_scratch scratch[4]; 324 - unsigned int scratch_order; 325 - unsigned int top; 326 - 327 - /** 328 - * List of vma currently bound. 329 - */ 330 - struct list_head bound_list; 331 - 332 - struct pagestash free_pages; 333 - 334 - /* Global GTT */ 335 - bool is_ggtt:1; 336 - 337 - /* Some systems require uncached updates of the page directories */ 338 - bool pt_kmap_wc:1; 339 - 340 - /* Some systems support read-only mappings for GGTT and/or PPGTT */ 341 - bool has_read_only:1; 342 - 343 - u64 (*pte_encode)(dma_addr_t addr, 344 - enum i915_cache_level level, 345 - u32 flags); /* Create a valid PTE */ 346 - #define PTE_READ_ONLY (1<<0) 347 - 348 - int (*allocate_va_range)(struct i915_address_space *vm, 349 - u64 start, u64 length); 350 - void (*clear_range)(struct i915_address_space *vm, 351 - u64 start, u64 length); 352 - void (*insert_page)(struct i915_address_space *vm, 353 - dma_addr_t addr, 354 - u64 offset, 355 - enum i915_cache_level cache_level, 356 - u32 flags); 357 - void (*insert_entries)(struct i915_address_space *vm, 358 - struct i915_vma *vma, 359 - enum i915_cache_level cache_level, 360 - u32 flags); 361 - void (*cleanup)(struct i915_address_space *vm); 362 - 363 - struct i915_vma_ops vma_ops; 364 - 365 - I915_SELFTEST_DECLARE(struct fault_attr fault_attr); 366 - I915_SELFTEST_DECLARE(bool scrub_64K); 367 - }; 368 - 369 - #define i915_is_ggtt(vm) ((vm)->is_ggtt) 370 - 371 - static inline bool 372 - i915_vm_is_4lvl(const struct i915_address_space *vm) 373 - { 374 - return (vm->total - 1) >> 32; 375 - } 376 - 377 - static inline bool 378 - i915_vm_has_scratch_64K(struct i915_address_space *vm) 379 - { 380 - return vm->scratch_order == get_order(I915_GTT_PAGE_SIZE_64K); 381 - } 382 - 383 - static inline bool 384 - i915_vm_has_cache_coloring(struct i915_address_space *vm) 385 - { 386 - return i915_is_ggtt(vm) && vm->mm.color_adjust; 387 - } 388 - 389 - /* The Graphics Translation Table is the way in which GEN hardware translates a 390 - * Graphics Virtual Address into a Physical Address. In addition to the normal 391 - * collateral associated with any va->pa translations GEN hardware also has a 392 - * portion of the GTT which can be mapped by the CPU and remain both coherent 393 - * and correct (in cases like swizzling). That region is referred to as GMADR in 394 - * the spec. 395 - */ 396 - struct i915_ggtt { 397 - struct i915_address_space vm; 398 - 399 - struct io_mapping iomap; /* Mapping to our CPU mappable region */ 400 - struct resource gmadr; /* GMADR resource */ 401 - resource_size_t mappable_end; /* End offset that we can CPU map */ 402 - 403 - /** "Graphics Stolen Memory" holds the global PTEs */ 404 - void __iomem *gsm; 405 - void (*invalidate)(struct i915_ggtt *ggtt); 406 - 407 - /** PPGTT used for aliasing the PPGTT with the GTT */ 408 - struct i915_ppgtt *alias; 409 - 410 - bool do_idle_maps; 411 - 412 - int mtrr; 413 - 414 - /** Bit 6 swizzling required for X tiling */ 415 - u32 bit_6_swizzle_x; 416 - /** Bit 6 swizzling required for Y tiling */ 417 - u32 bit_6_swizzle_y; 418 - 419 - u32 pin_bias; 420 - 421 - unsigned int num_fences; 422 - struct i915_fence_reg fence_regs[I915_MAX_NUM_FENCES]; 423 - struct list_head fence_list; 424 - 425 - /** List of all objects in gtt_space, currently mmaped by userspace. 426 - * All objects within this list must also be on bound_list. 427 - */ 428 - struct list_head userfault_list; 429 - 430 - /* Manual runtime pm autosuspend delay for user GGTT mmaps */ 431 - struct intel_wakeref_auto userfault_wakeref; 432 - 433 - struct drm_mm_node error_capture; 434 - struct drm_mm_node uc_fw; 435 - }; 436 - 437 - struct i915_ppgtt { 438 - struct i915_address_space vm; 439 - 440 - struct i915_page_directory *pd; 441 - }; 442 - 443 - struct gen6_ppgtt { 444 - struct i915_ppgtt base; 445 - 446 - struct mutex flush; 447 - struct i915_vma *vma; 448 - gen6_pte_t __iomem *pd_addr; 449 - 450 - atomic_t pin_count; 451 - struct mutex pin_mutex; 452 - 453 - bool scan_for_unused_pt; 454 - }; 455 - 456 - #define __to_gen6_ppgtt(base) container_of(base, struct gen6_ppgtt, base) 457 - 458 - static inline struct gen6_ppgtt *to_gen6_ppgtt(struct i915_ppgtt *base) 459 - { 460 - BUILD_BUG_ON(offsetof(struct gen6_ppgtt, base)); 461 - return __to_gen6_ppgtt(base); 462 - } 463 - 464 - /* 465 - * gen6_for_each_pde() iterates over every pde from start until start+length. 466 - * If start and start+length are not perfectly divisible, the macro will round 467 - * down and up as needed. Start=0 and length=2G effectively iterates over 468 - * every PDE in the system. The macro modifies ALL its parameters except 'pd', 469 - * so each of the other parameters should preferably be a simple variable, or 470 - * at most an lvalue with no side-effects! 471 - */ 472 - #define gen6_for_each_pde(pt, pd, start, length, iter) \ 473 - for (iter = gen6_pde_index(start); \ 474 - length > 0 && iter < I915_PDES && \ 475 - (pt = i915_pt_entry(pd, iter), true); \ 476 - ({ u32 temp = ALIGN(start+1, 1 << GEN6_PDE_SHIFT); \ 477 - temp = min(temp - start, length); \ 478 - start += temp, length -= temp; }), ++iter) 479 - 480 - #define gen6_for_all_pdes(pt, pd, iter) \ 481 - for (iter = 0; \ 482 - iter < I915_PDES && \ 483 - (pt = i915_pt_entry(pd, iter), true); \ 484 - ++iter) 485 - 486 - static inline u32 i915_pte_index(u64 address, unsigned int pde_shift) 487 - { 488 - const u32 mask = NUM_PTE(pde_shift) - 1; 489 - 490 - return (address >> PAGE_SHIFT) & mask; 491 - } 492 - 493 - /* Helper to counts the number of PTEs within the given length. This count 494 - * does not cross a page table boundary, so the max value would be 495 - * GEN6_PTES for GEN6, and GEN8_PTES for GEN8. 496 - */ 497 - static inline u32 i915_pte_count(u64 addr, u64 length, unsigned int pde_shift) 498 - { 499 - const u64 mask = ~((1ULL << pde_shift) - 1); 500 - u64 end; 501 - 502 - GEM_BUG_ON(length == 0); 503 - GEM_BUG_ON(offset_in_page(addr | length)); 504 - 505 - end = addr + length; 506 - 507 - if ((addr & mask) != (end & mask)) 508 - return NUM_PTE(pde_shift) - i915_pte_index(addr, pde_shift); 509 - 510 - return i915_pte_index(end, pde_shift) - i915_pte_index(addr, pde_shift); 511 - } 512 - 513 - static inline u32 i915_pde_index(u64 addr, u32 shift) 514 - { 515 - return (addr >> shift) & I915_PDE_MASK; 516 - } 517 - 518 - static inline u32 gen6_pte_index(u32 addr) 519 - { 520 - return i915_pte_index(addr, GEN6_PDE_SHIFT); 521 - } 522 - 523 - static inline u32 gen6_pte_count(u32 addr, u32 length) 524 - { 525 - return i915_pte_count(addr, length, GEN6_PDE_SHIFT); 526 - } 527 - 528 - static inline u32 gen6_pde_index(u32 addr) 529 - { 530 - return i915_pde_index(addr, GEN6_PDE_SHIFT); 531 - } 532 - 533 - static inline struct i915_page_table * 534 - i915_pt_entry(const struct i915_page_directory * const pd, 535 - const unsigned short n) 536 - { 537 - return pd->entry[n]; 538 - } 539 - 540 - static inline struct i915_page_directory * 541 - i915_pd_entry(const struct i915_page_directory * const pdp, 542 - const unsigned short n) 543 - { 544 - return pdp->entry[n]; 545 - } 546 - 547 - static inline dma_addr_t 548 - i915_page_dir_dma_addr(const struct i915_ppgtt *ppgtt, const unsigned int n) 549 - { 550 - struct i915_page_dma *pt = ppgtt->pd->entry[n]; 551 - 552 - return px_dma(pt ?: px_base(&ppgtt->vm.scratch[ppgtt->vm.top])); 553 - } 554 - 555 - static inline struct i915_ggtt * 556 - i915_vm_to_ggtt(struct i915_address_space *vm) 557 - { 558 - BUILD_BUG_ON(offsetof(struct i915_ggtt, vm)); 559 - GEM_BUG_ON(!i915_is_ggtt(vm)); 560 - return container_of(vm, struct i915_ggtt, vm); 561 - } 562 - 563 - static inline struct i915_ppgtt * 564 - i915_vm_to_ppgtt(struct i915_address_space *vm) 565 - { 566 - BUILD_BUG_ON(offsetof(struct i915_ppgtt, vm)); 567 - GEM_BUG_ON(i915_is_ggtt(vm)); 568 - return container_of(vm, struct i915_ppgtt, vm); 569 - } 570 - 571 - int i915_ggtt_probe_hw(struct drm_i915_private *dev_priv); 572 - int i915_ggtt_init_hw(struct drm_i915_private *dev_priv); 573 - int i915_ggtt_enable_hw(struct drm_i915_private *dev_priv); 574 - void i915_ggtt_enable_guc(struct i915_ggtt *ggtt); 575 - void i915_ggtt_disable_guc(struct i915_ggtt *ggtt); 576 - int i915_init_ggtt(struct drm_i915_private *dev_priv); 577 - void i915_ggtt_driver_release(struct drm_i915_private *dev_priv); 578 - 579 - static inline bool i915_ggtt_has_aperture(const struct i915_ggtt *ggtt) 580 - { 581 - return ggtt->mappable_end > 0; 582 - } 583 - 584 - int i915_ppgtt_init_hw(struct intel_gt *gt); 585 - 586 - struct i915_ppgtt *i915_ppgtt_create(struct drm_i915_private *dev_priv); 587 - 588 - static inline struct i915_address_space * 589 - i915_vm_get(struct i915_address_space *vm) 590 - { 591 - kref_get(&vm->ref); 592 - return vm; 593 - } 594 - 595 - void i915_vm_release(struct kref *kref); 596 - 597 - static inline void i915_vm_put(struct i915_address_space *vm) 598 - { 599 - kref_put(&vm->ref, i915_vm_release); 600 - } 601 - 602 - static inline struct i915_address_space * 603 - i915_vm_open(struct i915_address_space *vm) 604 - { 605 - GEM_BUG_ON(!atomic_read(&vm->open)); 606 - atomic_inc(&vm->open); 607 - return i915_vm_get(vm); 608 - } 609 - 610 - static inline bool 611 - i915_vm_tryopen(struct i915_address_space *vm) 612 - { 613 - if (atomic_add_unless(&vm->open, 1, 0)) 614 - return i915_vm_get(vm); 615 - 616 - return false; 617 - } 618 - 619 - void __i915_vm_close(struct i915_address_space *vm); 620 - 621 - static inline void 622 - i915_vm_close(struct i915_address_space *vm) 623 - { 624 - GEM_BUG_ON(!atomic_read(&vm->open)); 625 - if (atomic_dec_and_test(&vm->open)) 626 - __i915_vm_close(vm); 627 - 628 - i915_vm_put(vm); 629 - } 630 - 631 - int gen6_ppgtt_pin(struct i915_ppgtt *base); 632 - void gen6_ppgtt_unpin(struct i915_ppgtt *base); 633 - void gen6_ppgtt_unpin_all(struct i915_ppgtt *base); 634 - 635 - void i915_gem_suspend_gtt_mappings(struct drm_i915_private *dev_priv); 636 - void i915_gem_restore_gtt_mappings(struct drm_i915_private *dev_priv); 18 + struct i915_address_space; 637 19 638 20 int __must_check i915_gem_gtt_prepare_pages(struct drm_i915_gem_object *obj, 639 21 struct sg_table *pages); ··· 46 664 #define PIN_GLOBAL BIT_ULL(10) /* I915_VMA_GLOBAL_BIND */ 47 665 #define PIN_USER BIT_ULL(11) /* I915_VMA_LOCAL_BIND */ 48 666 49 - #define PIN_OFFSET_MASK (-I915_GTT_PAGE_SIZE) 667 + #define PIN_OFFSET_MASK I915_GTT_PAGE_MASK 50 668 51 669 #endif
+656 -614
drivers/gpu/drm/i915/i915_gpu_error.c
··· 41 41 42 42 #include "gem/i915_gem_context.h" 43 43 #include "gem/i915_gem_lmem.h" 44 + #include "gt/intel_gt_pm.h" 44 45 45 46 #include "i915_drv.h" 46 47 #include "i915_gpu_error.h" ··· 233 232 234 233 #ifdef CONFIG_DRM_I915_COMPRESS_ERROR 235 234 236 - struct compress { 235 + struct i915_vma_compress { 237 236 struct pagevec pool; 238 237 struct z_stream_s zstream; 239 238 void *tmp; 240 - bool wc; 241 239 }; 242 240 243 - static bool compress_init(struct compress *c) 241 + static bool compress_init(struct i915_vma_compress *c) 244 242 { 245 243 struct z_stream_s *zstream = &c->zstream; 246 244 ··· 261 261 return true; 262 262 } 263 263 264 - static bool compress_start(struct compress *c) 264 + static bool compress_start(struct i915_vma_compress *c) 265 265 { 266 266 struct z_stream_s *zstream = &c->zstream; 267 267 void *workspace = zstream->workspace; ··· 272 272 return zlib_deflateInit(zstream, Z_DEFAULT_COMPRESSION) == Z_OK; 273 273 } 274 274 275 - static void *compress_next_page(struct compress *c, 276 - struct drm_i915_error_object *dst) 275 + static void *compress_next_page(struct i915_vma_compress *c, 276 + struct i915_vma_coredump *dst) 277 277 { 278 278 void *page; 279 279 ··· 287 287 return dst->pages[dst->page_count++] = page; 288 288 } 289 289 290 - static int compress_page(struct compress *c, 290 + static int compress_page(struct i915_vma_compress *c, 291 291 void *src, 292 - struct drm_i915_error_object *dst) 292 + struct i915_vma_coredump *dst, 293 + bool wc) 293 294 { 294 295 struct z_stream_s *zstream = &c->zstream; 295 296 296 297 zstream->next_in = src; 297 - if (c->wc && c->tmp && i915_memcpy_from_wc(c->tmp, src, PAGE_SIZE)) 298 + if (wc && c->tmp && i915_memcpy_from_wc(c->tmp, src, PAGE_SIZE)) 298 299 zstream->next_in = c->tmp; 299 300 zstream->avail_in = PAGE_SIZE; 300 301 ··· 319 318 return 0; 320 319 } 321 320 322 - static int compress_flush(struct compress *c, 323 - struct drm_i915_error_object *dst) 321 + static int compress_flush(struct i915_vma_compress *c, 322 + struct i915_vma_coredump *dst) 324 323 { 325 324 struct z_stream_s *zstream = &c->zstream; 326 325 ··· 348 347 return 0; 349 348 } 350 349 351 - static void compress_finish(struct compress *c) 350 + static void compress_finish(struct i915_vma_compress *c) 352 351 { 353 352 zlib_deflateEnd(&c->zstream); 354 353 } 355 354 356 - static void compress_fini(struct compress *c) 355 + static void compress_fini(struct i915_vma_compress *c) 357 356 { 358 357 kfree(c->zstream.workspace); 359 358 if (c->tmp) ··· 368 367 369 368 #else 370 369 371 - struct compress { 370 + struct i915_vma_compress { 372 371 struct pagevec pool; 373 - bool wc; 374 372 }; 375 373 376 - static bool compress_init(struct compress *c) 374 + static bool compress_init(struct i915_vma_compress *c) 377 375 { 378 376 return pool_init(&c->pool, ALLOW_FAIL) == 0; 379 377 } 380 378 381 - static bool compress_start(struct compress *c) 379 + static bool compress_start(struct i915_vma_compress *c) 382 380 { 383 381 return true; 384 382 } 385 383 386 - static int compress_page(struct compress *c, 384 + static int compress_page(struct i915_vma_compress *c, 387 385 void *src, 388 - struct drm_i915_error_object *dst) 386 + struct i915_vma_coredump *dst, 387 + bool wc) 389 388 { 390 389 void *ptr; 391 390 ··· 393 392 if (!ptr) 394 393 return -ENOMEM; 395 394 396 - if (!(c->wc && i915_memcpy_from_wc(ptr, src, PAGE_SIZE))) 395 + if (!(wc && i915_memcpy_from_wc(ptr, src, PAGE_SIZE))) 397 396 memcpy(ptr, src, PAGE_SIZE); 398 397 dst->pages[dst->page_count++] = ptr; 399 398 400 399 return 0; 401 400 } 402 401 403 - static int compress_flush(struct compress *c, 404 - struct drm_i915_error_object *dst) 402 + static int compress_flush(struct i915_vma_compress *c, 403 + struct i915_vma_coredump *dst) 405 404 { 406 405 return 0; 407 406 } 408 407 409 - static void compress_finish(struct compress *c) 408 + static void compress_finish(struct i915_vma_compress *c) 410 409 { 411 410 } 412 411 413 - static void compress_fini(struct compress *c) 412 + static void compress_fini(struct i915_vma_compress *c) 414 413 { 415 414 pool_fini(&c->pool); 416 415 } ··· 423 422 #endif 424 423 425 424 static void error_print_instdone(struct drm_i915_error_state_buf *m, 426 - const struct drm_i915_error_engine *ee) 425 + const struct intel_engine_coredump *ee) 427 426 { 428 427 const struct sseu_dev_info *sseu = &RUNTIME_INFO(m->i915)->sseu; 429 428 int slice; ··· 454 453 455 454 static void error_print_request(struct drm_i915_error_state_buf *m, 456 455 const char *prefix, 457 - const struct drm_i915_error_request *erq, 458 - const unsigned long epoch) 456 + const struct i915_request_coredump *erq) 459 457 { 460 458 if (!erq->seqno) 461 459 return; 462 460 463 - err_printf(m, "%s pid %d, seqno %8x:%08x%s%s, prio %d, emitted %dms, start %08x, head %08x, tail %08x\n", 461 + err_printf(m, "%s pid %d, seqno %8x:%08x%s%s, prio %d, start %08x, head %08x, tail %08x\n", 464 462 prefix, erq->pid, erq->context, erq->seqno, 465 463 test_bit(DMA_FENCE_FLAG_SIGNALED_BIT, 466 464 &erq->flags) ? "!" : "", 467 465 test_bit(DMA_FENCE_FLAG_ENABLE_SIGNAL_BIT, 468 466 &erq->flags) ? "+" : "", 469 467 erq->sched_attr.priority, 470 - jiffies_to_msecs(erq->jiffies - epoch), 471 468 erq->start, erq->head, erq->tail); 472 469 } 473 470 474 471 static void error_print_context(struct drm_i915_error_state_buf *m, 475 472 const char *header, 476 - const struct drm_i915_error_context *ctx) 473 + const struct i915_gem_context_coredump *ctx) 477 474 { 478 475 err_printf(m, "%s%s[%d] prio %d, guilty %d active %d\n", 479 476 header, ctx->comm, ctx->pid, ctx->sched_attr.priority, 480 477 ctx->guilty, ctx->active); 481 478 } 482 479 483 - static void error_print_engine(struct drm_i915_error_state_buf *m, 484 - const struct drm_i915_error_engine *ee, 485 - const unsigned long epoch) 480 + static struct i915_vma_coredump * 481 + __find_vma(struct i915_vma_coredump *vma, const char *name) 486 482 { 483 + while (vma) { 484 + if (strcmp(vma->name, name) == 0) 485 + return vma; 486 + vma = vma->next; 487 + } 488 + 489 + return NULL; 490 + } 491 + 492 + static struct i915_vma_coredump * 493 + find_batch(const struct intel_engine_coredump *ee) 494 + { 495 + return __find_vma(ee->vma, "batch"); 496 + } 497 + 498 + static void error_print_engine(struct drm_i915_error_state_buf *m, 499 + const struct intel_engine_coredump *ee) 500 + { 501 + struct i915_vma_coredump *batch; 487 502 int n; 488 503 489 504 err_printf(m, "%s command stream:\n", ee->engine->name); 490 - err_printf(m, " IDLE?: %s\n", yesno(ee->idle)); 505 + err_printf(m, " CCID: 0x%08x\n", ee->ccid); 491 506 err_printf(m, " START: 0x%08x\n", ee->start); 492 507 err_printf(m, " HEAD: 0x%08x [0x%08x]\n", ee->head, ee->rq_head); 493 508 err_printf(m, " TAIL: 0x%08x [0x%08x, 0x%08x]\n", ··· 518 501 519 502 error_print_instdone(m, ee); 520 503 521 - if (ee->batchbuffer) { 522 - u64 start = ee->batchbuffer->gtt_offset; 523 - u64 end = start + ee->batchbuffer->gtt_size; 504 + batch = find_batch(ee); 505 + if (batch) { 506 + u64 start = batch->gtt_offset; 507 + u64 end = start + batch->gtt_size; 524 508 525 509 err_printf(m, " batch: [0x%08x_%08x, 0x%08x_%08x]\n", 526 510 upper_32_bits(start), lower_32_bits(start), ··· 553 535 ee->vm_info.pp_dir_base); 554 536 } 555 537 } 556 - err_printf(m, " ring->head: 0x%08x\n", ee->cpu_ring_head); 557 - err_printf(m, " ring->tail: 0x%08x\n", ee->cpu_ring_tail); 558 538 err_printf(m, " engine reset count: %u\n", ee->reset_count); 559 539 560 540 for (n = 0; n < ee->num_ports; n++) { 561 541 err_printf(m, " ELSP[%d]:", n); 562 - error_print_request(m, " ", &ee->execlist[n], epoch); 542 + error_print_request(m, " ", &ee->execlist[n]); 563 543 } 564 544 565 545 error_print_context(m, " Active context: ", &ee->context); ··· 572 556 va_end(args); 573 557 } 574 558 575 - static void print_error_obj(struct drm_i915_error_state_buf *m, 559 + static void print_error_vma(struct drm_i915_error_state_buf *m, 576 560 const struct intel_engine_cs *engine, 577 - const char *name, 578 - const struct drm_i915_error_object *obj) 561 + const struct i915_vma_coredump *vma) 579 562 { 580 563 char out[ASCII85_BUFSZ]; 581 564 int page; 582 565 583 - if (!obj) 566 + if (!vma) 584 567 return; 585 568 586 - if (name) { 587 - err_printf(m, "%s --- %s = 0x%08x %08x\n", 588 - engine ? engine->name : "global", name, 589 - upper_32_bits(obj->gtt_offset), 590 - lower_32_bits(obj->gtt_offset)); 591 - } 569 + err_printf(m, "%s --- %s = 0x%08x %08x\n", 570 + engine ? engine->name : "global", vma->name, 571 + upper_32_bits(vma->gtt_offset), 572 + lower_32_bits(vma->gtt_offset)); 592 573 593 - if (obj->gtt_page_sizes > I915_GTT_PAGE_SIZE_4K) 594 - err_printf(m, "gtt_page_sizes = 0x%08x\n", obj->gtt_page_sizes); 574 + if (vma->gtt_page_sizes > I915_GTT_PAGE_SIZE_4K) 575 + err_printf(m, "gtt_page_sizes = 0x%08x\n", vma->gtt_page_sizes); 595 576 596 577 err_compression_marker(m); 597 - for (page = 0; page < obj->page_count; page++) { 578 + for (page = 0; page < vma->page_count; page++) { 598 579 int i, len; 599 580 600 581 len = PAGE_SIZE; 601 - if (page == obj->page_count - 1) 602 - len -= obj->unused; 582 + if (page == vma->page_count - 1) 583 + len -= vma->unused; 603 584 len = ascii85_encode_len(len); 604 585 605 586 for (i = 0; i < len; i++) 606 - err_puts(m, ascii85_encode(obj->pages[page][i], out)); 587 + err_puts(m, ascii85_encode(vma->pages[page][i], out)); 607 588 } 608 589 err_puts(m, "\n"); 609 590 } ··· 639 626 } 640 627 641 628 static void err_print_uc(struct drm_i915_error_state_buf *m, 642 - const struct i915_error_uc *error_uc) 629 + const struct intel_uc_coredump *error_uc) 643 630 { 644 631 struct drm_printer p = i915_error_printer(m); 645 - const struct i915_gpu_state *error = 646 - container_of(error_uc, typeof(*error), uc); 647 - 648 - if (!error->device_info.has_gt_uc) 649 - return; 650 632 651 633 intel_uc_fw_dump(&error_uc->guc_fw, &p); 652 634 intel_uc_fw_dump(&error_uc->huc_fw, &p); 653 - print_error_obj(m, NULL, "GuC log buffer", error_uc->guc_log); 635 + print_error_vma(m, NULL, error_uc->guc_log); 654 636 } 655 637 656 638 static void err_free_sgl(struct scatterlist *sgl) ··· 665 657 } 666 658 } 667 659 668 - static void __err_print_to_sgl(struct drm_i915_error_state_buf *m, 669 - struct i915_gpu_state *error) 660 + static void err_print_gt(struct drm_i915_error_state_buf *m, 661 + struct intel_gt_coredump *gt) 670 662 { 671 - const struct drm_i915_error_engine *ee; 663 + const struct intel_engine_coredump *ee; 664 + int i; 665 + 666 + err_printf(m, "GT awake: %s\n", yesno(gt->awake)); 667 + err_printf(m, "EIR: 0x%08x\n", gt->eir); 668 + err_printf(m, "IER: 0x%08x\n", gt->ier); 669 + for (i = 0; i < gt->ngtier; i++) 670 + err_printf(m, "GTIER[%d]: 0x%08x\n", i, gt->gtier[i]); 671 + err_printf(m, "PGTBL_ER: 0x%08x\n", gt->pgtbl_er); 672 + err_printf(m, "FORCEWAKE: 0x%08x\n", gt->forcewake); 673 + err_printf(m, "DERRMR: 0x%08x\n", gt->derrmr); 674 + 675 + for (i = 0; i < gt->nfence; i++) 676 + err_printf(m, " fence[%d] = %08llx\n", i, gt->fence[i]); 677 + 678 + if (IS_GEN_RANGE(m->i915, 6, 11)) { 679 + err_printf(m, "ERROR: 0x%08x\n", gt->error); 680 + err_printf(m, "DONE_REG: 0x%08x\n", gt->done_reg); 681 + } 682 + 683 + if (INTEL_GEN(m->i915) >= 8) 684 + err_printf(m, "FAULT_TLB_DATA: 0x%08x 0x%08x\n", 685 + gt->fault_data1, gt->fault_data0); 686 + 687 + if (IS_GEN(m->i915, 7)) 688 + err_printf(m, "ERR_INT: 0x%08x\n", gt->err_int); 689 + 690 + if (IS_GEN_RANGE(m->i915, 8, 11)) 691 + err_printf(m, "GTT_CACHE_EN: 0x%08x\n", gt->gtt_cache); 692 + 693 + if (IS_GEN(m->i915, 12)) 694 + err_printf(m, "AUX_ERR_DBG: 0x%08x\n", gt->aux_err); 695 + 696 + if (INTEL_GEN(m->i915) >= 12) { 697 + int i; 698 + 699 + for (i = 0; i < GEN12_SFC_DONE_MAX; i++) 700 + err_printf(m, " SFC_DONE[%d]: 0x%08x\n", i, 701 + gt->sfc_done[i]); 702 + 703 + err_printf(m, " GAM_DONE: 0x%08x\n", gt->gam_done); 704 + } 705 + 706 + for (ee = gt->engine; ee; ee = ee->next) { 707 + const struct i915_vma_coredump *vma; 708 + 709 + error_print_engine(m, ee); 710 + for (vma = ee->vma; vma; vma = vma->next) 711 + print_error_vma(m, ee->engine, vma); 712 + } 713 + 714 + if (gt->uc) 715 + err_print_uc(m, gt->uc); 716 + } 717 + 718 + static void __err_print_to_sgl(struct drm_i915_error_state_buf *m, 719 + struct i915_gpu_coredump *error) 720 + { 721 + const struct intel_engine_coredump *ee; 672 722 struct timespec64 ts; 673 - int i, j; 674 723 675 724 if (*error->error_msg) 676 725 err_printf(m, "%s\n", error->error_msg); ··· 747 682 err_printf(m, "Capture: %lu jiffies; %d ms ago\n", 748 683 error->capture, jiffies_to_msecs(jiffies - error->capture)); 749 684 750 - for (ee = error->engine; ee; ee = ee->next) 685 + for (ee = error->gt ? error->gt->engine : NULL; ee; ee = ee->next) 751 686 err_printf(m, "Active process (on ring %s): %s [%d]\n", 752 687 ee->engine->name, 753 688 ee->context.comm, ··· 773 708 CSR_VERSION_MINOR(csr->version)); 774 709 } 775 710 776 - err_printf(m, "GT awake: %s\n", yesno(error->awake)); 777 711 err_printf(m, "RPM wakelock: %s\n", yesno(error->wakelock)); 778 712 err_printf(m, "PM suspended: %s\n", yesno(error->suspended)); 779 - err_printf(m, "EIR: 0x%08x\n", error->eir); 780 - err_printf(m, "IER: 0x%08x\n", error->ier); 781 - for (i = 0; i < error->ngtier; i++) 782 - err_printf(m, "GTIER[%d]: 0x%08x\n", i, error->gtier[i]); 783 - err_printf(m, "PGTBL_ER: 0x%08x\n", error->pgtbl_er); 784 - err_printf(m, "FORCEWAKE: 0x%08x\n", error->forcewake); 785 - err_printf(m, "DERRMR: 0x%08x\n", error->derrmr); 786 - err_printf(m, "CCID: 0x%08x\n", error->ccid); 787 713 788 - for (i = 0; i < error->nfence; i++) 789 - err_printf(m, " fence[%d] = %08llx\n", i, error->fence[i]); 790 - 791 - if (IS_GEN_RANGE(m->i915, 6, 11)) { 792 - err_printf(m, "ERROR: 0x%08x\n", error->error); 793 - err_printf(m, "DONE_REG: 0x%08x\n", error->done_reg); 794 - } 795 - 796 - if (INTEL_GEN(m->i915) >= 8) 797 - err_printf(m, "FAULT_TLB_DATA: 0x%08x 0x%08x\n", 798 - error->fault_data1, error->fault_data0); 799 - 800 - if (IS_GEN(m->i915, 7)) 801 - err_printf(m, "ERR_INT: 0x%08x\n", error->err_int); 802 - 803 - if (IS_GEN_RANGE(m->i915, 8, 11)) 804 - err_printf(m, "GTT_CACHE_EN: 0x%08x\n", error->gtt_cache); 805 - 806 - if (IS_GEN(m->i915, 12)) 807 - err_printf(m, "AUX_ERR_DBG: 0x%08x\n", error->aux_err); 808 - 809 - if (INTEL_GEN(m->i915) >= 12) { 810 - int i; 811 - 812 - for (i = 0; i < GEN12_SFC_DONE_MAX; i++) 813 - err_printf(m, " SFC_DONE[%d]: 0x%08x\n", i, 814 - error->sfc_done[i]); 815 - 816 - err_printf(m, " GAM_DONE: 0x%08x\n", error->gam_done); 817 - } 818 - 819 - for (ee = error->engine; ee; ee = ee->next) 820 - error_print_engine(m, ee, error->capture); 821 - 822 - for (ee = error->engine; ee; ee = ee->next) { 823 - const struct drm_i915_error_object *obj; 824 - 825 - obj = ee->batchbuffer; 826 - if (obj) { 827 - err_puts(m, ee->engine->name); 828 - if (ee->context.pid) 829 - err_printf(m, " (submitted by %s [%d])", 830 - ee->context.comm, 831 - ee->context.pid); 832 - err_printf(m, " --- gtt_offset = 0x%08x %08x\n", 833 - upper_32_bits(obj->gtt_offset), 834 - lower_32_bits(obj->gtt_offset)); 835 - print_error_obj(m, ee->engine, NULL, obj); 836 - } 837 - 838 - for (j = 0; j < ee->user_bo_count; j++) 839 - print_error_obj(m, ee->engine, "user", ee->user_bo[j]); 840 - 841 - if (ee->num_requests) { 842 - err_printf(m, "%s --- %d requests\n", 843 - ee->engine->name, 844 - ee->num_requests); 845 - for (j = 0; j < ee->num_requests; j++) 846 - error_print_request(m, " ", 847 - &ee->requests[j], 848 - error->capture); 849 - } 850 - 851 - print_error_obj(m, ee->engine, "ringbuffer", ee->ringbuffer); 852 - print_error_obj(m, ee->engine, "HW Status", ee->hws_page); 853 - print_error_obj(m, ee->engine, "HW context", ee->ctx); 854 - print_error_obj(m, ee->engine, "WA context", ee->wa_ctx); 855 - print_error_obj(m, ee->engine, 856 - "WA batchbuffer", ee->wa_batchbuffer); 857 - print_error_obj(m, ee->engine, 858 - "NULL context", ee->default_state); 859 - } 714 + if (error->gt) 715 + err_print_gt(m, error->gt); 860 716 861 717 if (error->overlay) 862 718 intel_overlay_print_error_state(m, error->overlay); ··· 788 802 err_print_capabilities(m, &error->device_info, &error->runtime_info, 789 803 &error->driver_caps); 790 804 err_print_params(m, &error->params); 791 - err_print_uc(m, &error->uc); 792 805 } 793 806 794 - static int err_print_to_sgl(struct i915_gpu_state *error) 807 + static int err_print_to_sgl(struct i915_gpu_coredump *error) 795 808 { 796 809 struct drm_i915_error_state_buf m; 797 810 ··· 827 842 return 0; 828 843 } 829 844 830 - ssize_t i915_gpu_state_copy_to_buffer(struct i915_gpu_state *error, 831 - char *buf, loff_t off, size_t rem) 845 + ssize_t i915_gpu_coredump_copy_to_buffer(struct i915_gpu_coredump *error, 846 + char *buf, loff_t off, size_t rem) 832 847 { 833 848 struct scatterlist *sg; 834 849 size_t count; ··· 891 906 return count; 892 907 } 893 908 894 - static void i915_error_object_free(struct drm_i915_error_object *obj) 909 + static void i915_vma_coredump_free(struct i915_vma_coredump *vma) 895 910 { 896 - int page; 911 + while (vma) { 912 + struct i915_vma_coredump *next = vma->next; 913 + int page; 897 914 898 - if (obj == NULL) 899 - return; 915 + for (page = 0; page < vma->page_count; page++) 916 + free_page((unsigned long)vma->pages[page]); 900 917 901 - for (page = 0; page < obj->page_count; page++) 902 - free_page((unsigned long)obj->pages[page]); 903 - 904 - kfree(obj); 918 + kfree(vma); 919 + vma = next; 920 + } 905 921 } 906 922 907 - 908 - static void cleanup_params(struct i915_gpu_state *error) 923 + static void cleanup_params(struct i915_gpu_coredump *error) 909 924 { 910 925 i915_params_free(&error->params); 911 926 } 912 927 913 - static void cleanup_uc_state(struct i915_gpu_state *error) 928 + static void cleanup_uc(struct intel_uc_coredump *uc) 914 929 { 915 - struct i915_error_uc *error_uc = &error->uc; 930 + kfree(uc->guc_fw.path); 931 + kfree(uc->huc_fw.path); 932 + i915_vma_coredump_free(uc->guc_log); 916 933 917 - kfree(error_uc->guc_fw.path); 918 - kfree(error_uc->huc_fw.path); 919 - i915_error_object_free(error_uc->guc_log); 934 + kfree(uc); 920 935 } 921 936 922 - void __i915_gpu_state_free(struct kref *error_ref) 937 + static void cleanup_gt(struct intel_gt_coredump *gt) 923 938 { 924 - struct i915_gpu_state *error = 925 - container_of(error_ref, typeof(*error), ref); 926 - long i; 939 + while (gt->engine) { 940 + struct intel_engine_coredump *ee = gt->engine; 927 941 928 - while (error->engine) { 929 - struct drm_i915_error_engine *ee = error->engine; 942 + gt->engine = ee->next; 930 943 931 - error->engine = ee->next; 932 - 933 - for (i = 0; i < ee->user_bo_count; i++) 934 - i915_error_object_free(ee->user_bo[i]); 935 - kfree(ee->user_bo); 936 - 937 - i915_error_object_free(ee->batchbuffer); 938 - i915_error_object_free(ee->wa_batchbuffer); 939 - i915_error_object_free(ee->ringbuffer); 940 - i915_error_object_free(ee->hws_page); 941 - i915_error_object_free(ee->ctx); 942 - i915_error_object_free(ee->wa_ctx); 943 - 944 - kfree(ee->requests); 944 + i915_vma_coredump_free(ee->vma); 945 945 kfree(ee); 946 + } 947 + 948 + if (gt->uc) 949 + cleanup_uc(gt->uc); 950 + 951 + kfree(gt); 952 + } 953 + 954 + void __i915_gpu_coredump_free(struct kref *error_ref) 955 + { 956 + struct i915_gpu_coredump *error = 957 + container_of(error_ref, typeof(*error), ref); 958 + 959 + while (error->gt) { 960 + struct intel_gt_coredump *gt = error->gt; 961 + 962 + error->gt = gt->next; 963 + cleanup_gt(gt); 946 964 } 947 965 948 966 kfree(error->overlay); 949 967 kfree(error->display); 950 968 951 969 cleanup_params(error); 952 - cleanup_uc_state(error); 953 970 954 971 err_free_sgl(error->sgl); 955 972 kfree(error); 956 973 } 957 974 958 - static struct drm_i915_error_object * 959 - i915_error_object_create(struct drm_i915_private *i915, 960 - struct i915_vma *vma, 961 - struct compress *compress) 975 + static struct i915_vma_coredump * 976 + i915_vma_coredump_create(const struct intel_gt *gt, 977 + const struct i915_vma *vma, 978 + const char *name, 979 + struct i915_vma_compress *compress) 962 980 { 963 - struct i915_ggtt *ggtt = &i915->ggtt; 981 + struct i915_ggtt *ggtt = gt->ggtt; 964 982 const u64 slot = ggtt->error_capture.start; 965 - struct drm_i915_error_object *dst; 983 + struct i915_vma_coredump *dst; 966 984 unsigned long num_pages; 967 985 struct sgt_iter iter; 968 986 int ret; 969 987 970 988 might_sleep(); 971 989 972 - if (!vma || !vma->pages) 990 + if (!vma || !vma->pages || !compress) 973 991 return NULL; 974 992 975 993 num_pages = min_t(u64, vma->size, vma->obj->base.size) >> PAGE_SHIFT; ··· 986 998 return NULL; 987 999 } 988 1000 1001 + strcpy(dst->name, name); 1002 + dst->next = NULL; 1003 + 989 1004 dst->gtt_offset = vma->node.start; 990 1005 dst->gtt_size = vma->node.size; 991 1006 dst->gtt_page_sizes = vma->page_sizes.gtt; 992 1007 dst->num_pages = num_pages; 993 1008 dst->page_count = 0; 994 1009 dst->unused = 0; 995 - 996 - compress->wc = i915_gem_object_is_lmem(vma->obj) || 997 - drm_mm_node_allocated(&ggtt->error_capture); 998 1010 999 1011 ret = -EINVAL; 1000 1012 if (drm_mm_node_allocated(&ggtt->error_capture)) { ··· 1004 1016 for_each_sgt_daddr(dma, iter, vma->pages) { 1005 1017 ggtt->vm.insert_page(&ggtt->vm, dma, slot, 1006 1018 I915_CACHE_NONE, 0); 1019 + mb(); 1007 1020 1008 1021 s = io_mapping_map_wc(&ggtt->iomap, slot, PAGE_SIZE); 1009 - ret = compress_page(compress, (void __force *)s, dst); 1022 + ret = compress_page(compress, 1023 + (void __force *)s, dst, 1024 + true); 1010 1025 io_mapping_unmap(s); 1011 1026 if (ret) 1012 1027 break; ··· 1022 1031 void __iomem *s; 1023 1032 1024 1033 s = io_mapping_map_wc(&mem->iomap, dma, PAGE_SIZE); 1025 - ret = compress_page(compress, (void __force *)s, dst); 1034 + ret = compress_page(compress, 1035 + (void __force *)s, dst, 1036 + true); 1026 1037 io_mapping_unmap(s); 1027 1038 if (ret) 1028 1039 break; ··· 1038 1045 drm_clflush_pages(&page, 1); 1039 1046 1040 1047 s = kmap(page); 1041 - ret = compress_page(compress, s, dst); 1048 + ret = compress_page(compress, s, dst, false); 1042 1049 kunmap(page); 1043 1050 1044 1051 drm_clflush_pages(&page, 1); ··· 1059 1066 return dst; 1060 1067 } 1061 1068 1062 - /* 1063 - * Generate a semi-unique error code. The code is not meant to have meaning, The 1064 - * code's only purpose is to try to prevent false duplicated bug reports by 1065 - * grossly estimating a GPU error state. 1066 - * 1067 - * TODO Ideally, hashing the batchbuffer would be a very nice way to determine 1068 - * the hang if we could strip the GTT offset information from it. 1069 - * 1070 - * It's only a small step better than a random number in its current form. 1071 - */ 1072 - static u32 i915_error_generate_code(struct i915_gpu_state *error) 1069 + static void gt_record_fences(struct intel_gt_coredump *gt) 1073 1070 { 1074 - const struct drm_i915_error_engine *ee = error->engine; 1075 - 1076 - /* 1077 - * IPEHR would be an ideal way to detect errors, as it's the gross 1078 - * measure of "the command that hung." However, has some very common 1079 - * synchronization commands which almost always appear in the case 1080 - * strictly a client bug. Use instdone to differentiate those some. 1081 - */ 1082 - return ee ? ee->ipehr ^ ee->instdone.instdone : 0; 1083 - } 1084 - 1085 - static void gem_record_fences(struct i915_gpu_state *error) 1086 - { 1087 - struct drm_i915_private *dev_priv = error->i915; 1088 - struct intel_uncore *uncore = &dev_priv->uncore; 1071 + struct i915_ggtt *ggtt = gt->_gt->ggtt; 1072 + struct intel_uncore *uncore = gt->_gt->uncore; 1089 1073 int i; 1090 1074 1091 - if (INTEL_GEN(dev_priv) >= 6) { 1092 - for (i = 0; i < dev_priv->ggtt.num_fences; i++) 1093 - error->fence[i] = 1075 + if (INTEL_GEN(uncore->i915) >= 6) { 1076 + for (i = 0; i < ggtt->num_fences; i++) 1077 + gt->fence[i] = 1094 1078 intel_uncore_read64(uncore, 1095 1079 FENCE_REG_GEN6_LO(i)); 1096 - } else if (INTEL_GEN(dev_priv) >= 4) { 1097 - for (i = 0; i < dev_priv->ggtt.num_fences; i++) 1098 - error->fence[i] = 1080 + } else if (INTEL_GEN(uncore->i915) >= 4) { 1081 + for (i = 0; i < ggtt->num_fences; i++) 1082 + gt->fence[i] = 1099 1083 intel_uncore_read64(uncore, 1100 1084 FENCE_REG_965_LO(i)); 1101 1085 } else { 1102 - for (i = 0; i < dev_priv->ggtt.num_fences; i++) 1103 - error->fence[i] = 1086 + for (i = 0; i < ggtt->num_fences; i++) 1087 + gt->fence[i] = 1104 1088 intel_uncore_read(uncore, FENCE_REG(i)); 1105 1089 } 1106 - error->nfence = i; 1090 + gt->nfence = i; 1107 1091 } 1108 1092 1109 - static void error_record_engine_registers(struct i915_gpu_state *error, 1110 - struct intel_engine_cs *engine, 1111 - struct drm_i915_error_engine *ee) 1093 + static void engine_record_registers(struct intel_engine_coredump *ee) 1112 1094 { 1113 - struct drm_i915_private *dev_priv = engine->i915; 1095 + const struct intel_engine_cs *engine = ee->engine; 1096 + struct drm_i915_private *i915 = engine->i915; 1114 1097 1115 - if (INTEL_GEN(dev_priv) >= 6) { 1098 + if (INTEL_GEN(i915) >= 6) { 1116 1099 ee->rc_psmi = ENGINE_READ(engine, RING_PSMI_CTL); 1117 1100 1118 - if (INTEL_GEN(dev_priv) >= 12) 1119 - ee->fault_reg = I915_READ(GEN12_RING_FAULT_REG); 1120 - else if (INTEL_GEN(dev_priv) >= 8) 1121 - ee->fault_reg = I915_READ(GEN8_RING_FAULT_REG); 1101 + if (INTEL_GEN(i915) >= 12) 1102 + ee->fault_reg = intel_uncore_read(engine->uncore, 1103 + GEN12_RING_FAULT_REG); 1104 + else if (INTEL_GEN(i915) >= 8) 1105 + ee->fault_reg = intel_uncore_read(engine->uncore, 1106 + GEN8_RING_FAULT_REG); 1122 1107 else 1123 1108 ee->fault_reg = GEN6_RING_FAULT_REG_READ(engine); 1124 1109 } 1125 1110 1126 - if (INTEL_GEN(dev_priv) >= 4) { 1111 + if (INTEL_GEN(i915) >= 4) { 1127 1112 ee->faddr = ENGINE_READ(engine, RING_DMA_FADD); 1128 1113 ee->ipeir = ENGINE_READ(engine, RING_IPEIR); 1129 1114 ee->ipehr = ENGINE_READ(engine, RING_IPEHR); 1130 1115 ee->instps = ENGINE_READ(engine, RING_INSTPS); 1131 1116 ee->bbaddr = ENGINE_READ(engine, RING_BBADDR); 1132 - if (INTEL_GEN(dev_priv) >= 8) { 1117 + ee->ccid = ENGINE_READ(engine, CCID); 1118 + if (INTEL_GEN(i915) >= 8) { 1133 1119 ee->faddr |= (u64)ENGINE_READ(engine, RING_DMA_FADD_UDW) << 32; 1134 1120 ee->bbaddr |= (u64)ENGINE_READ(engine, RING_BBADDR_UDW) << 32; 1135 1121 } ··· 1127 1155 ee->head = ENGINE_READ(engine, RING_HEAD); 1128 1156 ee->tail = ENGINE_READ(engine, RING_TAIL); 1129 1157 ee->ctl = ENGINE_READ(engine, RING_CTL); 1130 - if (INTEL_GEN(dev_priv) > 2) 1158 + if (INTEL_GEN(i915) > 2) 1131 1159 ee->mode = ENGINE_READ(engine, RING_MI_MODE); 1132 1160 1133 - if (!HWS_NEEDS_PHYSICAL(dev_priv)) { 1161 + if (!HWS_NEEDS_PHYSICAL(i915)) { 1134 1162 i915_reg_t mmio; 1135 1163 1136 - if (IS_GEN(dev_priv, 7)) { 1164 + if (IS_GEN(i915, 7)) { 1137 1165 switch (engine->id) { 1138 1166 default: 1139 1167 MISSING_CASE(engine->id); ··· 1158 1186 mmio = RING_HWS_PGA(engine->mmio_base); 1159 1187 } 1160 1188 1161 - ee->hws = I915_READ(mmio); 1189 + ee->hws = intel_uncore_read(engine->uncore, mmio); 1162 1190 } 1163 1191 1164 - ee->idle = intel_engine_is_idle(engine); 1165 - ee->reset_count = i915_reset_engine_count(&dev_priv->gpu_error, 1166 - engine); 1192 + ee->reset_count = i915_reset_engine_count(&i915->gpu_error, engine); 1167 1193 1168 - if (HAS_PPGTT(dev_priv)) { 1194 + if (HAS_PPGTT(i915)) { 1169 1195 int i; 1170 1196 1171 1197 ee->vm_info.gfx_mode = ENGINE_READ(engine, RING_MODE_GEN7); 1172 1198 1173 - if (IS_GEN(dev_priv, 6)) { 1199 + if (IS_GEN(i915, 6)) { 1174 1200 ee->vm_info.pp_dir_base = 1175 1201 ENGINE_READ(engine, RING_PP_DIR_BASE_READ); 1176 - } else if (IS_GEN(dev_priv, 7)) { 1202 + } else if (IS_GEN(i915, 7)) { 1177 1203 ee->vm_info.pp_dir_base = 1178 1204 ENGINE_READ(engine, RING_PP_DIR_BASE); 1179 - } else if (INTEL_GEN(dev_priv) >= 8) { 1205 + } else if (INTEL_GEN(i915) >= 8) { 1180 1206 u32 base = engine->mmio_base; 1181 1207 1182 1208 for (i = 0; i < 4; i++) { 1183 1209 ee->vm_info.pdp[i] = 1184 - I915_READ(GEN8_RING_PDP_UDW(base, i)); 1210 + intel_uncore_read(engine->uncore, 1211 + GEN8_RING_PDP_UDW(base, i)); 1185 1212 ee->vm_info.pdp[i] <<= 32; 1186 1213 ee->vm_info.pdp[i] |= 1187 - I915_READ(GEN8_RING_PDP_LDW(base, i)); 1214 + intel_uncore_read(engine->uncore, 1215 + GEN8_RING_PDP_LDW(base, i)); 1188 1216 } 1189 1217 } 1190 1218 } 1191 1219 } 1192 1220 1193 1221 static void record_request(const struct i915_request *request, 1194 - struct drm_i915_error_request *erq) 1222 + struct i915_request_coredump *erq) 1195 1223 { 1196 1224 const struct i915_gem_context *ctx; 1197 1225 ··· 1199 1227 erq->context = request->fence.context; 1200 1228 erq->seqno = request->fence.seqno; 1201 1229 erq->sched_attr = request->sched.attr; 1202 - erq->jiffies = request->emitted_jiffies; 1203 1230 erq->start = i915_ggtt_offset(request->ring->vma); 1204 1231 erq->head = request->head; 1205 1232 erq->tail = request->tail; ··· 1211 1240 rcu_read_unlock(); 1212 1241 } 1213 1242 1214 - static void engine_record_requests(struct intel_engine_cs *engine, 1215 - struct i915_request *first, 1216 - struct drm_i915_error_engine *ee) 1243 + static void engine_record_execlists(struct intel_engine_coredump *ee) 1217 1244 { 1218 - struct i915_request *request; 1219 - int count; 1220 - 1221 - count = 0; 1222 - request = first; 1223 - list_for_each_entry_from(request, &engine->active.requests, sched.link) 1224 - count++; 1225 - if (!count) 1226 - return; 1227 - 1228 - ee->requests = kcalloc(count, sizeof(*ee->requests), ATOMIC_MAYFAIL); 1229 - if (!ee->requests) 1230 - return; 1231 - 1232 - ee->num_requests = count; 1233 - 1234 - count = 0; 1235 - request = first; 1236 - list_for_each_entry_from(request, 1237 - &engine->active.requests, sched.link) { 1238 - if (count >= ee->num_requests) { 1239 - /* 1240 - * If the ring request list was changed in 1241 - * between the point where the error request 1242 - * list was created and dimensioned and this 1243 - * point then just exit early to avoid crashes. 1244 - * 1245 - * We don't need to communicate that the 1246 - * request list changed state during error 1247 - * state capture and that the error state is 1248 - * slightly incorrect as a consequence since we 1249 - * are typically only interested in the request 1250 - * list state at the point of error state 1251 - * capture, not in any changes happening during 1252 - * the capture. 1253 - */ 1254 - break; 1255 - } 1256 - 1257 - record_request(request, &ee->requests[count++]); 1258 - } 1259 - ee->num_requests = count; 1260 - } 1261 - 1262 - static void error_record_engine_execlists(const struct intel_engine_cs *engine, 1263 - struct drm_i915_error_engine *ee) 1264 - { 1265 - const struct intel_engine_execlists * const execlists = &engine->execlists; 1266 - struct i915_request * const *port = execlists->active; 1245 + const struct intel_engine_execlists * const el = &ee->engine->execlists; 1246 + struct i915_request * const *port = el->active; 1267 1247 unsigned int n = 0; 1268 1248 1269 1249 while (*port) ··· 1223 1301 ee->num_ports = n; 1224 1302 } 1225 1303 1226 - static bool record_context(struct drm_i915_error_context *e, 1304 + static bool record_context(struct i915_gem_context_coredump *e, 1227 1305 const struct i915_request *rq) 1228 1306 { 1229 1307 struct i915_gem_context *ctx; ··· 1256 1334 return capture; 1257 1335 } 1258 1336 1259 - struct capture_vma { 1260 - struct capture_vma *next; 1261 - void **slot; 1337 + struct intel_engine_capture_vma { 1338 + struct intel_engine_capture_vma *next; 1339 + struct i915_vma *vma; 1340 + char name[16]; 1262 1341 }; 1263 1342 1264 - static struct capture_vma * 1265 - capture_vma(struct capture_vma *next, 1343 + static struct intel_engine_capture_vma * 1344 + capture_vma(struct intel_engine_capture_vma *next, 1266 1345 struct i915_vma *vma, 1267 - struct drm_i915_error_object **out) 1346 + const char *name, 1347 + gfp_t gfp) 1268 1348 { 1269 - struct capture_vma *c; 1349 + struct intel_engine_capture_vma *c; 1270 1350 1271 - *out = NULL; 1272 1351 if (!vma) 1273 1352 return next; 1274 1353 1275 - c = kmalloc(sizeof(*c), ATOMIC_MAYFAIL); 1354 + c = kmalloc(sizeof(*c), gfp); 1276 1355 if (!c) 1277 1356 return next; 1278 1357 ··· 1282 1359 return next; 1283 1360 } 1284 1361 1285 - c->slot = (void **)out; 1286 - *c->slot = i915_vma_get(vma); 1362 + strcpy(c->name, name); 1363 + c->vma = i915_vma_get(vma); 1287 1364 1288 1365 c->next = next; 1289 1366 return c; 1290 1367 } 1291 1368 1292 - static struct capture_vma * 1293 - request_record_user_bo(struct i915_request *request, 1294 - struct drm_i915_error_engine *ee, 1295 - struct capture_vma *capture) 1369 + static struct intel_engine_capture_vma * 1370 + capture_user(struct intel_engine_capture_vma *capture, 1371 + const struct i915_request *rq, 1372 + gfp_t gfp) 1296 1373 { 1297 1374 struct i915_capture_list *c; 1298 - struct drm_i915_error_object **bo; 1299 - long count, max; 1300 1375 1301 - max = 0; 1302 - for (c = request->capture_list; c; c = c->next) 1303 - max++; 1304 - if (!max) 1305 - return capture; 1306 - 1307 - bo = kmalloc_array(max, sizeof(*bo), ATOMIC_MAYFAIL); 1308 - if (!bo) { 1309 - /* If we can't capture everything, try to capture something. */ 1310 - max = min_t(long, max, PAGE_SIZE / sizeof(*bo)); 1311 - bo = kmalloc_array(max, sizeof(*bo), ATOMIC_MAYFAIL); 1312 - } 1313 - if (!bo) 1314 - return capture; 1315 - 1316 - count = 0; 1317 - for (c = request->capture_list; c; c = c->next) { 1318 - capture = capture_vma(capture, c->vma, &bo[count]); 1319 - if (++count == max) 1320 - break; 1321 - } 1322 - 1323 - ee->user_bo = bo; 1324 - ee->user_bo_count = count; 1376 + for (c = rq->capture_list; c; c = c->next) 1377 + capture = capture_vma(capture, c->vma, "user", gfp); 1325 1378 1326 1379 return capture; 1327 1380 } 1328 1381 1329 - static struct drm_i915_error_object * 1330 - capture_object(struct drm_i915_private *dev_priv, 1382 + static struct i915_vma_coredump * 1383 + capture_object(const struct intel_gt *gt, 1331 1384 struct drm_i915_gem_object *obj, 1332 - struct compress *compress) 1385 + const char *name, 1386 + struct i915_vma_compress *compress) 1333 1387 { 1334 1388 if (obj && i915_gem_object_has_pages(obj)) { 1335 1389 struct i915_vma fake = { ··· 1316 1416 .obj = obj, 1317 1417 }; 1318 1418 1319 - return i915_error_object_create(dev_priv, &fake, compress); 1419 + return i915_vma_coredump_create(gt, &fake, name, compress); 1320 1420 } else { 1321 1421 return NULL; 1322 1422 } 1323 1423 } 1324 1424 1325 - static void 1326 - gem_record_rings(struct i915_gpu_state *error, struct compress *compress) 1425 + static void add_vma(struct intel_engine_coredump *ee, 1426 + struct i915_vma_coredump *vma) 1327 1427 { 1328 - struct drm_i915_private *i915 = error->i915; 1329 - struct intel_engine_cs *engine; 1330 - struct drm_i915_error_engine *ee; 1428 + if (vma) { 1429 + vma->next = ee->vma; 1430 + ee->vma = vma; 1431 + } 1432 + } 1331 1433 1332 - ee = kzalloc(sizeof(*ee), GFP_KERNEL); 1434 + struct intel_engine_coredump * 1435 + intel_engine_coredump_alloc(struct intel_engine_cs *engine, gfp_t gfp) 1436 + { 1437 + struct intel_engine_coredump *ee; 1438 + 1439 + ee = kzalloc(sizeof(*ee), gfp); 1333 1440 if (!ee) 1334 - return; 1441 + return NULL; 1335 1442 1336 - for_each_uabi_engine(engine, i915) { 1337 - struct capture_vma *capture = NULL; 1338 - struct i915_request *request; 1339 - unsigned long flags; 1443 + ee->engine = engine; 1444 + 1445 + engine_record_registers(ee); 1446 + engine_record_execlists(ee); 1447 + 1448 + return ee; 1449 + } 1450 + 1451 + struct intel_engine_capture_vma * 1452 + intel_engine_coredump_add_request(struct intel_engine_coredump *ee, 1453 + struct i915_request *rq, 1454 + gfp_t gfp) 1455 + { 1456 + struct intel_engine_capture_vma *vma = NULL; 1457 + 1458 + ee->simulated |= record_context(&ee->context, rq); 1459 + if (ee->simulated) 1460 + return NULL; 1461 + 1462 + /* 1463 + * We need to copy these to an anonymous buffer 1464 + * as the simplest method to avoid being overwritten 1465 + * by userspace. 1466 + */ 1467 + vma = capture_vma(vma, rq->batch, "batch", gfp); 1468 + vma = capture_user(vma, rq, gfp); 1469 + vma = capture_vma(vma, rq->ring->vma, "ring", gfp); 1470 + vma = capture_vma(vma, rq->context->state, "HW context", gfp); 1471 + 1472 + ee->rq_head = rq->head; 1473 + ee->rq_post = rq->postfix; 1474 + ee->rq_tail = rq->tail; 1475 + 1476 + return vma; 1477 + } 1478 + 1479 + void 1480 + intel_engine_coredump_add_vma(struct intel_engine_coredump *ee, 1481 + struct intel_engine_capture_vma *capture, 1482 + struct i915_vma_compress *compress) 1483 + { 1484 + const struct intel_engine_cs *engine = ee->engine; 1485 + 1486 + while (capture) { 1487 + struct intel_engine_capture_vma *this = capture; 1488 + struct i915_vma *vma = this->vma; 1489 + 1490 + add_vma(ee, 1491 + i915_vma_coredump_create(engine->gt, 1492 + vma, this->name, 1493 + compress)); 1494 + 1495 + i915_active_release(&vma->active); 1496 + i915_vma_put(vma); 1497 + 1498 + capture = this->next; 1499 + kfree(this); 1500 + } 1501 + 1502 + add_vma(ee, 1503 + i915_vma_coredump_create(engine->gt, 1504 + engine->status_page.vma, 1505 + "HW Status", 1506 + compress)); 1507 + 1508 + add_vma(ee, 1509 + i915_vma_coredump_create(engine->gt, 1510 + engine->wa_ctx.vma, 1511 + "WA context", 1512 + compress)); 1513 + 1514 + add_vma(ee, 1515 + capture_object(engine->gt, 1516 + engine->default_state, 1517 + "NULL context", 1518 + compress)); 1519 + } 1520 + 1521 + static struct intel_engine_coredump * 1522 + capture_engine(struct intel_engine_cs *engine, 1523 + struct i915_vma_compress *compress) 1524 + { 1525 + struct intel_engine_capture_vma *capture = NULL; 1526 + struct intel_engine_coredump *ee; 1527 + struct i915_request *rq; 1528 + unsigned long flags; 1529 + 1530 + ee = intel_engine_coredump_alloc(engine, GFP_KERNEL); 1531 + if (!ee) 1532 + return NULL; 1533 + 1534 + spin_lock_irqsave(&engine->active.lock, flags); 1535 + rq = intel_engine_find_active_request(engine); 1536 + if (rq) 1537 + capture = intel_engine_coredump_add_request(ee, rq, 1538 + ATOMIC_MAYFAIL); 1539 + spin_unlock_irqrestore(&engine->active.lock, flags); 1540 + if (!capture) { 1541 + kfree(ee); 1542 + return NULL; 1543 + } 1544 + 1545 + intel_engine_coredump_add_vma(ee, capture, compress); 1546 + 1547 + return ee; 1548 + } 1549 + 1550 + static void 1551 + gt_record_engines(struct intel_gt_coredump *gt, 1552 + struct i915_vma_compress *compress) 1553 + { 1554 + struct intel_engine_cs *engine; 1555 + enum intel_engine_id id; 1556 + 1557 + for_each_engine(engine, gt->_gt, id) { 1558 + struct intel_engine_coredump *ee; 1340 1559 1341 1560 /* Refill our page pool before entering atomic section */ 1342 1561 pool_refill(&compress->pool, ALLOW_FAIL); 1343 1562 1344 - spin_lock_irqsave(&engine->active.lock, flags); 1345 - request = intel_engine_find_active_request(engine); 1346 - if (!request) { 1347 - spin_unlock_irqrestore(&engine->active.lock, flags); 1563 + ee = capture_engine(engine, compress); 1564 + if (!ee) 1565 + continue; 1566 + 1567 + gt->simulated |= ee->simulated; 1568 + if (ee->simulated) { 1569 + kfree(ee); 1348 1570 continue; 1349 1571 } 1350 1572 1351 - error->simulated |= record_context(&ee->context, request); 1352 - 1353 - /* 1354 - * We need to copy these to an anonymous buffer 1355 - * as the simplest method to avoid being overwritten 1356 - * by userspace. 1357 - */ 1358 - capture = capture_vma(capture, 1359 - request->batch, 1360 - &ee->batchbuffer); 1361 - 1362 - if (HAS_BROKEN_CS_TLB(i915)) 1363 - capture = capture_vma(capture, 1364 - engine->gt->scratch, 1365 - &ee->wa_batchbuffer); 1366 - 1367 - capture = request_record_user_bo(request, ee, capture); 1368 - 1369 - capture = capture_vma(capture, 1370 - request->context->state, 1371 - &ee->ctx); 1372 - 1373 - capture = capture_vma(capture, 1374 - request->ring->vma, 1375 - &ee->ringbuffer); 1376 - 1377 - ee->cpu_ring_head = request->ring->head; 1378 - ee->cpu_ring_tail = request->ring->tail; 1379 - 1380 - ee->rq_head = request->head; 1381 - ee->rq_post = request->postfix; 1382 - ee->rq_tail = request->tail; 1383 - 1384 - engine_record_requests(engine, request, ee); 1385 - spin_unlock_irqrestore(&engine->active.lock, flags); 1386 - 1387 - error_record_engine_registers(error, engine, ee); 1388 - error_record_engine_execlists(engine, ee); 1389 - 1390 - while (capture) { 1391 - struct capture_vma *this = capture; 1392 - struct i915_vma *vma = *this->slot; 1393 - 1394 - *this->slot = 1395 - i915_error_object_create(i915, vma, compress); 1396 - 1397 - i915_active_release(&vma->active); 1398 - i915_vma_put(vma); 1399 - 1400 - capture = this->next; 1401 - kfree(this); 1402 - } 1403 - 1404 - ee->hws_page = 1405 - i915_error_object_create(i915, 1406 - engine->status_page.vma, 1407 - compress); 1408 - 1409 - ee->wa_ctx = 1410 - i915_error_object_create(i915, 1411 - engine->wa_ctx.vma, 1412 - compress); 1413 - 1414 - ee->default_state = 1415 - capture_object(i915, engine->default_state, compress); 1416 - 1417 - ee->engine = engine; 1418 - 1419 - ee->next = error->engine; 1420 - error->engine = ee; 1421 - 1422 - ee = kzalloc(sizeof(*ee), GFP_KERNEL); 1423 - if (!ee) 1424 - return; 1573 + ee->next = gt->engine; 1574 + gt->engine = ee; 1425 1575 } 1426 - 1427 - kfree(ee); 1428 1576 } 1429 1577 1430 - static void 1431 - capture_uc_state(struct i915_gpu_state *error, struct compress *compress) 1578 + static struct intel_uc_coredump * 1579 + gt_record_uc(struct intel_gt_coredump *gt, 1580 + struct i915_vma_compress *compress) 1432 1581 { 1433 - struct drm_i915_private *i915 = error->i915; 1434 - struct i915_error_uc *error_uc = &error->uc; 1435 - struct intel_uc *uc = &i915->gt.uc; 1582 + const struct intel_uc *uc = &gt->_gt->uc; 1583 + struct intel_uc_coredump *error_uc; 1436 1584 1437 - /* Capturing uC state won't be useful if there is no GuC */ 1438 - if (!error->device_info.has_gt_uc) 1439 - return; 1585 + error_uc = kzalloc(sizeof(*error_uc), ALLOW_FAIL); 1586 + if (!error_uc) 1587 + return NULL; 1440 1588 1441 1589 memcpy(&error_uc->guc_fw, &uc->guc.fw, sizeof(uc->guc.fw)); 1442 1590 memcpy(&error_uc->huc_fw, &uc->huc.fw, sizeof(uc->huc.fw)); ··· 1495 1547 */ 1496 1548 error_uc->guc_fw.path = kstrdup(uc->guc.fw.path, ALLOW_FAIL); 1497 1549 error_uc->huc_fw.path = kstrdup(uc->huc.fw.path, ALLOW_FAIL); 1498 - error_uc->guc_log = i915_error_object_create(i915, 1499 - uc->guc.log.vma, 1500 - compress); 1550 + error_uc->guc_log = 1551 + i915_vma_coredump_create(gt->_gt, 1552 + uc->guc.log.vma, "GuC log buffer", 1553 + compress); 1554 + 1555 + return error_uc; 1556 + } 1557 + 1558 + static void gt_capture_prepare(struct intel_gt_coredump *gt) 1559 + { 1560 + struct i915_ggtt *ggtt = gt->_gt->ggtt; 1561 + 1562 + mutex_lock(&ggtt->error_mutex); 1563 + } 1564 + 1565 + static void gt_capture_finish(struct intel_gt_coredump *gt) 1566 + { 1567 + struct i915_ggtt *ggtt = gt->_gt->ggtt; 1568 + 1569 + if (drm_mm_node_allocated(&ggtt->error_capture)) 1570 + ggtt->vm.clear_range(&ggtt->vm, 1571 + ggtt->error_capture.start, 1572 + PAGE_SIZE); 1573 + 1574 + mutex_unlock(&ggtt->error_mutex); 1501 1575 } 1502 1576 1503 1577 /* Capture all registers which don't fit into another category. */ 1504 - static void capture_reg_state(struct i915_gpu_state *error) 1578 + static void gt_record_regs(struct intel_gt_coredump *gt) 1505 1579 { 1506 - struct drm_i915_private *i915 = error->i915; 1507 - struct intel_uncore *uncore = &i915->uncore; 1580 + struct intel_uncore *uncore = gt->_gt->uncore; 1581 + struct drm_i915_private *i915 = uncore->i915; 1508 1582 int i; 1509 1583 1510 - /* General organization 1584 + /* 1585 + * General organization 1511 1586 * 1. Registers specific to a single generation 1512 1587 * 2. Registers which belong to multiple generations 1513 1588 * 3. Feature specific registers. ··· 1540 1569 1541 1570 /* 1: Registers specific to a single generation */ 1542 1571 if (IS_VALLEYVIEW(i915)) { 1543 - error->gtier[0] = intel_uncore_read(uncore, GTIER); 1544 - error->ier = intel_uncore_read(uncore, VLV_IER); 1545 - error->forcewake = intel_uncore_read_fw(uncore, FORCEWAKE_VLV); 1572 + gt->gtier[0] = intel_uncore_read(uncore, GTIER); 1573 + gt->ier = intel_uncore_read(uncore, VLV_IER); 1574 + gt->forcewake = intel_uncore_read_fw(uncore, FORCEWAKE_VLV); 1546 1575 } 1547 1576 1548 1577 if (IS_GEN(i915, 7)) 1549 - error->err_int = intel_uncore_read(uncore, GEN7_ERR_INT); 1578 + gt->err_int = intel_uncore_read(uncore, GEN7_ERR_INT); 1550 1579 1551 1580 if (INTEL_GEN(i915) >= 12) { 1552 - error->fault_data0 = intel_uncore_read(uncore, 1553 - GEN12_FAULT_TLB_DATA0); 1554 - error->fault_data1 = intel_uncore_read(uncore, 1555 - GEN12_FAULT_TLB_DATA1); 1581 + gt->fault_data0 = intel_uncore_read(uncore, 1582 + GEN12_FAULT_TLB_DATA0); 1583 + gt->fault_data1 = intel_uncore_read(uncore, 1584 + GEN12_FAULT_TLB_DATA1); 1556 1585 } else if (INTEL_GEN(i915) >= 8) { 1557 - error->fault_data0 = intel_uncore_read(uncore, 1558 - GEN8_FAULT_TLB_DATA0); 1559 - error->fault_data1 = intel_uncore_read(uncore, 1560 - GEN8_FAULT_TLB_DATA1); 1586 + gt->fault_data0 = intel_uncore_read(uncore, 1587 + GEN8_FAULT_TLB_DATA0); 1588 + gt->fault_data1 = intel_uncore_read(uncore, 1589 + GEN8_FAULT_TLB_DATA1); 1561 1590 } 1562 1591 1563 1592 if (IS_GEN(i915, 6)) { 1564 - error->forcewake = intel_uncore_read_fw(uncore, FORCEWAKE); 1565 - error->gab_ctl = intel_uncore_read(uncore, GAB_CTL); 1566 - error->gfx_mode = intel_uncore_read(uncore, GFX_MODE); 1593 + gt->forcewake = intel_uncore_read_fw(uncore, FORCEWAKE); 1594 + gt->gab_ctl = intel_uncore_read(uncore, GAB_CTL); 1595 + gt->gfx_mode = intel_uncore_read(uncore, GFX_MODE); 1567 1596 } 1568 1597 1569 1598 /* 2: Registers which belong to multiple generations */ 1570 1599 if (INTEL_GEN(i915) >= 7) 1571 - error->forcewake = intel_uncore_read_fw(uncore, FORCEWAKE_MT); 1600 + gt->forcewake = intel_uncore_read_fw(uncore, FORCEWAKE_MT); 1572 1601 1573 1602 if (INTEL_GEN(i915) >= 6) { 1574 - error->derrmr = intel_uncore_read(uncore, DERRMR); 1603 + gt->derrmr = intel_uncore_read(uncore, DERRMR); 1575 1604 if (INTEL_GEN(i915) < 12) { 1576 - error->error = intel_uncore_read(uncore, ERROR_GEN6); 1577 - error->done_reg = intel_uncore_read(uncore, DONE_REG); 1605 + gt->error = intel_uncore_read(uncore, ERROR_GEN6); 1606 + gt->done_reg = intel_uncore_read(uncore, DONE_REG); 1578 1607 } 1579 1608 } 1580 - 1581 - if (INTEL_GEN(i915) >= 5) 1582 - error->ccid = intel_uncore_read(uncore, CCID(RENDER_RING_BASE)); 1583 1609 1584 1610 /* 3: Feature specific registers */ 1585 1611 if (IS_GEN_RANGE(i915, 6, 7)) { 1586 - error->gam_ecochk = intel_uncore_read(uncore, GAM_ECOCHK); 1587 - error->gac_eco = intel_uncore_read(uncore, GAC_ECO_BITS); 1612 + gt->gam_ecochk = intel_uncore_read(uncore, GAM_ECOCHK); 1613 + gt->gac_eco = intel_uncore_read(uncore, GAC_ECO_BITS); 1588 1614 } 1589 1615 1590 1616 if (IS_GEN_RANGE(i915, 8, 11)) 1591 - error->gtt_cache = intel_uncore_read(uncore, HSW_GTT_CACHE_EN); 1617 + gt->gtt_cache = intel_uncore_read(uncore, HSW_GTT_CACHE_EN); 1592 1618 1593 1619 if (IS_GEN(i915, 12)) 1594 - error->aux_err = intel_uncore_read(uncore, GEN12_AUX_ERR_DBG); 1620 + gt->aux_err = intel_uncore_read(uncore, GEN12_AUX_ERR_DBG); 1595 1621 1596 1622 if (INTEL_GEN(i915) >= 12) { 1597 1623 for (i = 0; i < GEN12_SFC_DONE_MAX; i++) { 1598 - error->sfc_done[i] = 1624 + gt->sfc_done[i] = 1599 1625 intel_uncore_read(uncore, GEN12_SFC_DONE(i)); 1600 1626 } 1601 1627 1602 - error->gam_done = intel_uncore_read(uncore, GEN12_GAM_DONE); 1628 + gt->gam_done = intel_uncore_read(uncore, GEN12_GAM_DONE); 1603 1629 } 1604 1630 1605 1631 /* 4: Everything else */ 1606 1632 if (INTEL_GEN(i915) >= 11) { 1607 - error->ier = intel_uncore_read(uncore, GEN8_DE_MISC_IER); 1608 - error->gtier[0] = 1633 + gt->ier = intel_uncore_read(uncore, GEN8_DE_MISC_IER); 1634 + gt->gtier[0] = 1609 1635 intel_uncore_read(uncore, 1610 1636 GEN11_RENDER_COPY_INTR_ENABLE); 1611 - error->gtier[1] = 1637 + gt->gtier[1] = 1612 1638 intel_uncore_read(uncore, GEN11_VCS_VECS_INTR_ENABLE); 1613 - error->gtier[2] = 1639 + gt->gtier[2] = 1614 1640 intel_uncore_read(uncore, GEN11_GUC_SG_INTR_ENABLE); 1615 - error->gtier[3] = 1641 + gt->gtier[3] = 1616 1642 intel_uncore_read(uncore, 1617 1643 GEN11_GPM_WGBOXPERF_INTR_ENABLE); 1618 - error->gtier[4] = 1644 + gt->gtier[4] = 1619 1645 intel_uncore_read(uncore, 1620 1646 GEN11_CRYPTO_RSVD_INTR_ENABLE); 1621 - error->gtier[5] = 1647 + gt->gtier[5] = 1622 1648 intel_uncore_read(uncore, 1623 1649 GEN11_GUNIT_CSME_INTR_ENABLE); 1624 - error->ngtier = 6; 1650 + gt->ngtier = 6; 1625 1651 } else if (INTEL_GEN(i915) >= 8) { 1626 - error->ier = intel_uncore_read(uncore, GEN8_DE_MISC_IER); 1652 + gt->ier = intel_uncore_read(uncore, GEN8_DE_MISC_IER); 1627 1653 for (i = 0; i < 4; i++) 1628 - error->gtier[i] = intel_uncore_read(uncore, 1629 - GEN8_GT_IER(i)); 1630 - error->ngtier = 4; 1654 + gt->gtier[i] = 1655 + intel_uncore_read(uncore, GEN8_GT_IER(i)); 1656 + gt->ngtier = 4; 1631 1657 } else if (HAS_PCH_SPLIT(i915)) { 1632 - error->ier = intel_uncore_read(uncore, DEIER); 1633 - error->gtier[0] = intel_uncore_read(uncore, GTIER); 1634 - error->ngtier = 1; 1658 + gt->ier = intel_uncore_read(uncore, DEIER); 1659 + gt->gtier[0] = intel_uncore_read(uncore, GTIER); 1660 + gt->ngtier = 1; 1635 1661 } else if (IS_GEN(i915, 2)) { 1636 - error->ier = intel_uncore_read16(uncore, GEN2_IER); 1662 + gt->ier = intel_uncore_read16(uncore, GEN2_IER); 1637 1663 } else if (!IS_VALLEYVIEW(i915)) { 1638 - error->ier = intel_uncore_read(uncore, GEN2_IER); 1664 + gt->ier = intel_uncore_read(uncore, GEN2_IER); 1639 1665 } 1640 - error->eir = intel_uncore_read(uncore, EIR); 1641 - error->pgtbl_er = intel_uncore_read(uncore, PGTBL_ER); 1666 + gt->eir = intel_uncore_read(uncore, EIR); 1667 + gt->pgtbl_er = intel_uncore_read(uncore, PGTBL_ER); 1642 1668 } 1643 1669 1644 - static const char * 1645 - error_msg(struct i915_gpu_state *error, 1646 - intel_engine_mask_t engines, const char *msg) 1670 + /* 1671 + * Generate a semi-unique error code. The code is not meant to have meaning, The 1672 + * code's only purpose is to try to prevent false duplicated bug reports by 1673 + * grossly estimating a GPU error state. 1674 + * 1675 + * TODO Ideally, hashing the batchbuffer would be a very nice way to determine 1676 + * the hang if we could strip the GTT offset information from it. 1677 + * 1678 + * It's only a small step better than a random number in its current form. 1679 + */ 1680 + static u32 generate_ecode(const struct intel_engine_coredump *ee) 1647 1681 { 1682 + /* 1683 + * IPEHR would be an ideal way to detect errors, as it's the gross 1684 + * measure of "the command that hung." However, has some very common 1685 + * synchronization commands which almost always appear in the case 1686 + * strictly a client bug. Use instdone to differentiate those some. 1687 + */ 1688 + return ee ? ee->ipehr ^ ee->instdone.instdone : 0; 1689 + } 1690 + 1691 + static const char *error_msg(struct i915_gpu_coredump *error) 1692 + { 1693 + struct intel_engine_coredump *first = NULL; 1694 + struct intel_gt_coredump *gt; 1695 + intel_engine_mask_t engines; 1648 1696 int len; 1649 1697 1698 + engines = 0; 1699 + for (gt = error->gt; gt; gt = gt->next) { 1700 + struct intel_engine_coredump *cs; 1701 + 1702 + if (gt->engine && !first) 1703 + first = gt->engine; 1704 + 1705 + for (cs = gt->engine; cs; cs = cs->next) 1706 + engines |= cs->engine->mask; 1707 + } 1708 + 1650 1709 len = scnprintf(error->error_msg, sizeof(error->error_msg), 1651 - "GPU HANG: ecode %d:%x:0x%08x", 1710 + "GPU HANG: ecode %d:%x:%08x", 1652 1711 INTEL_GEN(error->i915), engines, 1653 - i915_error_generate_code(error)); 1654 - if (error->engine) { 1712 + generate_ecode(first)); 1713 + if (first) { 1655 1714 /* Just show the first executing process, more is confusing */ 1656 1715 len += scnprintf(error->error_msg + len, 1657 1716 sizeof(error->error_msg) - len, 1658 1717 ", in %s [%d]", 1659 - error->engine->context.comm, 1660 - error->engine->context.pid); 1718 + first->context.comm, first->context.pid); 1661 1719 } 1662 - if (msg) 1663 - len += scnprintf(error->error_msg + len, 1664 - sizeof(error->error_msg) - len, 1665 - ", %s", msg); 1666 1720 1667 1721 return error->error_msg; 1668 1722 } 1669 1723 1670 - static void capture_gen_state(struct i915_gpu_state *error) 1724 + static void capture_gen(struct i915_gpu_coredump *error) 1671 1725 { 1672 1726 struct drm_i915_private *i915 = error->i915; 1673 1727 1674 - error->awake = i915->gt.awake; 1675 1728 error->wakelock = atomic_read(&i915->runtime_pm.wakeref_count); 1676 1729 error->suspended = i915->runtime_pm.suspended; 1677 1730 ··· 1706 1711 error->reset_count = i915_reset_count(&i915->gpu_error); 1707 1712 error->suspend_count = i915->suspend_count; 1708 1713 1714 + i915_params_copy(&error->params, &i915_modparams); 1709 1715 memcpy(&error->device_info, 1710 1716 INTEL_INFO(i915), 1711 1717 sizeof(error->device_info)); ··· 1716 1720 error->driver_caps = i915->caps; 1717 1721 } 1718 1722 1719 - static void capture_params(struct i915_gpu_state *error) 1723 + struct i915_gpu_coredump * 1724 + i915_gpu_coredump_alloc(struct drm_i915_private *i915, gfp_t gfp) 1720 1725 { 1721 - i915_params_copy(&error->params, &i915_modparams); 1722 - } 1726 + struct i915_gpu_coredump *error; 1723 1727 1724 - static void capture_finish(struct i915_gpu_state *error) 1725 - { 1726 - struct i915_ggtt *ggtt = &error->i915->ggtt; 1728 + if (!i915_modparams.error_capture) 1729 + return NULL; 1727 1730 1728 - if (drm_mm_node_allocated(&ggtt->error_capture)) { 1729 - const u64 slot = ggtt->error_capture.start; 1730 - 1731 - ggtt->vm.clear_range(&ggtt->vm, slot, PAGE_SIZE); 1732 - } 1733 - } 1734 - 1735 - #define DAY_AS_SECONDS(x) (24 * 60 * 60 * (x)) 1736 - 1737 - struct i915_gpu_state * 1738 - i915_capture_gpu_state(struct drm_i915_private *i915) 1739 - { 1740 - struct i915_gpu_state *error; 1741 - struct compress compress; 1742 - 1743 - /* Check if GPU capture has been disabled */ 1744 - error = READ_ONCE(i915->gpu_error.first_error); 1745 - if (IS_ERR(error)) 1746 - return error; 1747 - 1748 - error = kzalloc(sizeof(*error), ALLOW_FAIL); 1749 - if (!error) { 1750 - i915_disable_error_state(i915, -ENOMEM); 1751 - return ERR_PTR(-ENOMEM); 1752 - } 1753 - 1754 - if (!compress_init(&compress)) { 1755 - kfree(error); 1756 - i915_disable_error_state(i915, -ENOMEM); 1757 - return ERR_PTR(-ENOMEM); 1758 - } 1731 + error = kzalloc(sizeof(*error), gfp); 1732 + if (!error) 1733 + return NULL; 1759 1734 1760 1735 kref_init(&error->ref); 1761 1736 error->i915 = i915; ··· 1736 1769 error->uptime = ktime_sub(ktime_get(), i915->gt.last_init_time); 1737 1770 error->capture = jiffies; 1738 1771 1739 - capture_params(error); 1740 - capture_gen_state(error); 1741 - capture_uc_state(error, &compress); 1742 - capture_reg_state(error); 1743 - gem_record_fences(error); 1744 - gem_record_rings(error, &compress); 1745 - 1746 - error->overlay = intel_overlay_capture_error_state(i915); 1747 - error->display = intel_display_capture_error_state(i915); 1748 - 1749 - capture_finish(error); 1750 - compress_fini(&compress); 1772 + capture_gen(error); 1751 1773 1752 1774 return error; 1753 1775 } 1754 1776 1755 - /** 1756 - * i915_capture_error_state - capture an error record for later analysis 1757 - * @i915: i915 device 1758 - * @engine_mask: the mask of engines triggering the hang 1759 - * @msg: a message to insert into the error capture header 1760 - * 1761 - * Should be called when an error is detected (either a hang or an error 1762 - * interrupt) to capture error state from the time of the error. Fills 1763 - * out a structure which becomes available in debugfs for user level tools 1764 - * to pick up. 1765 - */ 1766 - void i915_capture_error_state(struct drm_i915_private *i915, 1767 - intel_engine_mask_t engine_mask, 1768 - const char *msg) 1777 + #define DAY_AS_SECONDS(x) (24 * 60 * 60 * (x)) 1778 + 1779 + struct intel_gt_coredump * 1780 + intel_gt_coredump_alloc(struct intel_gt *gt, gfp_t gfp) 1769 1781 { 1770 - static bool warned; 1771 - struct i915_gpu_state *error; 1772 - unsigned long flags; 1782 + struct intel_gt_coredump *gc; 1773 1783 1774 - if (!i915_modparams.error_capture) 1784 + gc = kzalloc(sizeof(*gc), gfp); 1785 + if (!gc) 1786 + return NULL; 1787 + 1788 + gc->_gt = gt; 1789 + gc->awake = intel_gt_pm_is_awake(gt); 1790 + 1791 + gt_record_regs(gc); 1792 + gt_record_fences(gc); 1793 + 1794 + return gc; 1795 + } 1796 + 1797 + struct i915_vma_compress * 1798 + i915_vma_capture_prepare(struct intel_gt_coredump *gt) 1799 + { 1800 + struct i915_vma_compress *compress; 1801 + 1802 + compress = kmalloc(sizeof(*compress), ALLOW_FAIL); 1803 + if (!compress) 1804 + return NULL; 1805 + 1806 + if (!compress_init(compress)) { 1807 + kfree(compress); 1808 + return NULL; 1809 + } 1810 + 1811 + gt_capture_prepare(gt); 1812 + 1813 + return compress; 1814 + } 1815 + 1816 + void i915_vma_capture_finish(struct intel_gt_coredump *gt, 1817 + struct i915_vma_compress *compress) 1818 + { 1819 + if (!compress) 1775 1820 return; 1776 1821 1777 - if (READ_ONCE(i915->gpu_error.first_error)) 1778 - return; 1822 + gt_capture_finish(gt); 1779 1823 1780 - error = i915_capture_gpu_state(i915); 1824 + compress_fini(compress); 1825 + kfree(compress); 1826 + } 1827 + 1828 + struct i915_gpu_coredump *i915_gpu_coredump(struct drm_i915_private *i915) 1829 + { 1830 + struct i915_gpu_coredump *error; 1831 + 1832 + /* Check if GPU capture has been disabled */ 1833 + error = READ_ONCE(i915->gpu_error.first_error); 1781 1834 if (IS_ERR(error)) 1782 - return; 1835 + return error; 1783 1836 1784 - dev_info(i915->drm.dev, "%s\n", error_msg(error, engine_mask, msg)); 1837 + error = i915_gpu_coredump_alloc(i915, ALLOW_FAIL); 1838 + if (!error) 1839 + return ERR_PTR(-ENOMEM); 1785 1840 1786 - if (!error->simulated) { 1787 - spin_lock_irqsave(&i915->gpu_error.lock, flags); 1788 - if (!i915->gpu_error.first_error) { 1789 - i915->gpu_error.first_error = error; 1790 - error = NULL; 1841 + error->gt = intel_gt_coredump_alloc(&i915->gt, ALLOW_FAIL); 1842 + if (error->gt) { 1843 + struct i915_vma_compress *compress; 1844 + 1845 + compress = i915_vma_capture_prepare(error->gt); 1846 + if (!compress) { 1847 + kfree(error->gt); 1848 + kfree(error); 1849 + return ERR_PTR(-ENOMEM); 1791 1850 } 1792 - spin_unlock_irqrestore(&i915->gpu_error.lock, flags); 1851 + 1852 + gt_record_engines(error->gt, compress); 1853 + 1854 + if (INTEL_INFO(i915)->has_gt_uc) 1855 + error->gt->uc = gt_record_uc(error->gt, compress); 1856 + 1857 + i915_vma_capture_finish(error->gt, compress); 1858 + 1859 + error->simulated |= error->gt->simulated; 1793 1860 } 1794 1861 1795 - if (error) { 1796 - __i915_gpu_state_free(&error->ref); 1862 + error->overlay = intel_overlay_capture_error_state(i915); 1863 + error->display = intel_display_capture_error_state(i915); 1864 + 1865 + return error; 1866 + } 1867 + 1868 + void i915_error_state_store(struct i915_gpu_coredump *error) 1869 + { 1870 + struct drm_i915_private *i915; 1871 + static bool warned; 1872 + 1873 + if (IS_ERR_OR_NULL(error)) 1797 1874 return; 1798 - } 1875 + 1876 + i915 = error->i915; 1877 + dev_info(i915->drm.dev, "%s\n", error_msg(error)); 1878 + 1879 + if (error->simulated || 1880 + cmpxchg(&i915->gpu_error.first_error, NULL, error)) 1881 + return; 1882 + 1883 + i915_gpu_coredump_get(error); 1799 1884 1800 1885 if (!xchg(&warned, true) && 1801 1886 ktime_get_real_seconds() - DRIVER_TIMESTAMP < DAY_AS_SECONDS(180)) { ··· 1860 1841 } 1861 1842 } 1862 1843 1863 - struct i915_gpu_state * 1844 + /** 1845 + * i915_capture_error_state - capture an error record for later analysis 1846 + * @i915: i915 device 1847 + * 1848 + * Should be called when an error is detected (either a hang or an error 1849 + * interrupt) to capture error state from the time of the error. Fills 1850 + * out a structure which becomes available in debugfs for user level tools 1851 + * to pick up. 1852 + */ 1853 + void i915_capture_error_state(struct drm_i915_private *i915) 1854 + { 1855 + struct i915_gpu_coredump *error; 1856 + 1857 + error = i915_gpu_coredump(i915); 1858 + if (IS_ERR(error)) { 1859 + cmpxchg(&i915->gpu_error.first_error, NULL, error); 1860 + return; 1861 + } 1862 + 1863 + i915_error_state_store(error); 1864 + i915_gpu_coredump_put(error); 1865 + } 1866 + 1867 + struct i915_gpu_coredump * 1864 1868 i915_first_error_state(struct drm_i915_private *i915) 1865 1869 { 1866 - struct i915_gpu_state *error; 1870 + struct i915_gpu_coredump *error; 1867 1871 1868 1872 spin_lock_irq(&i915->gpu_error.lock); 1869 1873 error = i915->gpu_error.first_error; 1870 1874 if (!IS_ERR_OR_NULL(error)) 1871 - i915_gpu_state_get(error); 1875 + i915_gpu_coredump_get(error); 1872 1876 spin_unlock_irq(&i915->gpu_error.lock); 1873 1877 1874 1878 return error; ··· 1899 1857 1900 1858 void i915_reset_error_state(struct drm_i915_private *i915) 1901 1859 { 1902 - struct i915_gpu_state *error; 1860 + struct i915_gpu_coredump *error; 1903 1861 1904 1862 spin_lock_irq(&i915->gpu_error.lock); 1905 1863 error = i915->gpu_error.first_error; ··· 1908 1866 spin_unlock_irq(&i915->gpu_error.lock); 1909 1867 1910 1868 if (!IS_ERR_OR_NULL(error)) 1911 - i915_gpu_state_put(error); 1869 + i915_gpu_coredump_put(error); 1912 1870 } 1913 1871 1914 1872 void i915_disable_error_state(struct drm_i915_private *i915, int err)
+207 -122
drivers/gpu/drm/i915/i915_gpu_error.h
··· 25 25 #include "i915_scheduler.h" 26 26 27 27 struct drm_i915_private; 28 + struct i915_vma_compress; 29 + struct intel_engine_capture_vma; 28 30 struct intel_overlay_error_state; 29 31 struct intel_display_error_state; 30 32 31 - struct i915_gpu_state { 32 - struct kref ref; 33 - ktime_t time; 34 - ktime_t boottime; 35 - ktime_t uptime; 36 - unsigned long capture; 33 + struct i915_vma_coredump { 34 + struct i915_vma_coredump *next; 37 35 38 - struct drm_i915_private *i915; 36 + char name[20]; 39 37 40 - char error_msg[128]; 38 + u64 gtt_offset; 39 + u64 gtt_size; 40 + u32 gtt_page_sizes; 41 + 42 + int num_pages; 43 + int page_count; 44 + int unused; 45 + u32 *pages[0]; 46 + }; 47 + 48 + struct i915_request_coredump { 49 + unsigned long flags; 50 + pid_t pid; 51 + u32 context; 52 + u32 seqno; 53 + u32 start; 54 + u32 head; 55 + u32 tail; 56 + struct i915_sched_attr sched_attr; 57 + }; 58 + 59 + struct intel_engine_coredump { 60 + const struct intel_engine_cs *engine; 61 + 41 62 bool simulated; 42 - bool awake; 43 - bool wakelock; 44 - bool suspended; 45 - int iommu; 46 63 u32 reset_count; 47 - u32 suspend_count; 48 - struct intel_device_info device_info; 49 - struct intel_runtime_info runtime_info; 50 - struct intel_driver_caps driver_caps; 51 - struct i915_params params; 52 64 53 - struct i915_error_uc { 54 - struct intel_uc_fw guc_fw; 55 - struct intel_uc_fw huc_fw; 56 - struct drm_i915_error_object *guc_log; 57 - } uc; 65 + /* position of active request inside the ring */ 66 + u32 rq_head, rq_post, rq_tail; 67 + 68 + /* Register state */ 69 + u32 ccid; 70 + u32 start; 71 + u32 tail; 72 + u32 head; 73 + u32 ctl; 74 + u32 mode; 75 + u32 hws; 76 + u32 ipeir; 77 + u32 ipehr; 78 + u32 bbstate; 79 + u32 instpm; 80 + u32 instps; 81 + u64 bbaddr; 82 + u64 acthd; 83 + u32 fault_reg; 84 + u64 faddr; 85 + u32 rc_psmi; /* sleep state */ 86 + struct intel_instdone instdone; 87 + 88 + struct i915_gem_context_coredump { 89 + char comm[TASK_COMM_LEN]; 90 + pid_t pid; 91 + int active; 92 + int guilty; 93 + struct i915_sched_attr sched_attr; 94 + } context; 95 + 96 + struct i915_vma_coredump *vma; 97 + 98 + struct i915_request_coredump execlist[EXECLIST_MAX_PORTS]; 99 + unsigned int num_ports; 100 + 101 + struct { 102 + u32 gfx_mode; 103 + union { 104 + u64 pdp[4]; 105 + u32 pp_dir_base; 106 + }; 107 + } vm_info; 108 + 109 + struct intel_engine_coredump *next; 110 + }; 111 + 112 + struct intel_gt_coredump { 113 + const struct intel_gt *_gt; 114 + bool awake; 115 + bool simulated; 58 116 59 117 /* Generic register state */ 60 118 u32 eir; 61 119 u32 pgtbl_er; 62 120 u32 ier; 63 121 u32 gtier[6], ngtier; 64 - u32 ccid; 65 122 u32 derrmr; 66 123 u32 forcewake; 67 124 u32 error; /* gen6+ */ ··· 137 80 138 81 u32 nfence; 139 82 u64 fence[I915_MAX_NUM_FENCES]; 83 + 84 + struct intel_engine_coredump *engine; 85 + 86 + struct intel_uc_coredump { 87 + struct intel_uc_fw guc_fw; 88 + struct intel_uc_fw huc_fw; 89 + struct i915_vma_coredump *guc_log; 90 + } *uc; 91 + 92 + struct intel_gt_coredump *next; 93 + }; 94 + 95 + struct i915_gpu_coredump { 96 + struct kref ref; 97 + ktime_t time; 98 + ktime_t boottime; 99 + ktime_t uptime; 100 + unsigned long capture; 101 + 102 + struct drm_i915_private *i915; 103 + 104 + struct intel_gt_coredump *gt; 105 + 106 + char error_msg[128]; 107 + bool simulated; 108 + bool wakelock; 109 + bool suspended; 110 + int iommu; 111 + u32 reset_count; 112 + u32 suspend_count; 113 + 114 + struct intel_device_info device_info; 115 + struct intel_runtime_info runtime_info; 116 + struct intel_driver_caps driver_caps; 117 + struct i915_params params; 118 + 140 119 struct intel_overlay_error_state *overlay; 141 120 struct intel_display_error_state *display; 142 - 143 - struct drm_i915_error_engine { 144 - const struct intel_engine_cs *engine; 145 - 146 - /* Software tracked state */ 147 - bool idle; 148 - int num_requests; 149 - u32 reset_count; 150 - 151 - /* position of active request inside the ring */ 152 - u32 rq_head, rq_post, rq_tail; 153 - 154 - /* our own tracking of ring head and tail */ 155 - u32 cpu_ring_head; 156 - u32 cpu_ring_tail; 157 - 158 - /* Register state */ 159 - u32 start; 160 - u32 tail; 161 - u32 head; 162 - u32 ctl; 163 - u32 mode; 164 - u32 hws; 165 - u32 ipeir; 166 - u32 ipehr; 167 - u32 bbstate; 168 - u32 instpm; 169 - u32 instps; 170 - u64 bbaddr; 171 - u64 acthd; 172 - u32 fault_reg; 173 - u64 faddr; 174 - u32 rc_psmi; /* sleep state */ 175 - struct intel_instdone instdone; 176 - 177 - struct drm_i915_error_context { 178 - char comm[TASK_COMM_LEN]; 179 - pid_t pid; 180 - int active; 181 - int guilty; 182 - struct i915_sched_attr sched_attr; 183 - } context; 184 - 185 - struct drm_i915_error_object { 186 - u64 gtt_offset; 187 - u64 gtt_size; 188 - u32 gtt_page_sizes; 189 - int num_pages; 190 - int page_count; 191 - int unused; 192 - u32 *pages[0]; 193 - } *ringbuffer, *batchbuffer, *wa_batchbuffer, *ctx, *hws_page; 194 - 195 - struct drm_i915_error_object **user_bo; 196 - long user_bo_count; 197 - 198 - struct drm_i915_error_object *wa_ctx; 199 - struct drm_i915_error_object *default_state; 200 - 201 - struct drm_i915_error_request { 202 - unsigned long flags; 203 - long jiffies; 204 - pid_t pid; 205 - u32 context; 206 - u32 seqno; 207 - u32 start; 208 - u32 head; 209 - u32 tail; 210 - struct i915_sched_attr sched_attr; 211 - } *requests, execlist[EXECLIST_MAX_PORTS]; 212 - unsigned int num_ports; 213 - 214 - struct { 215 - u32 gfx_mode; 216 - union { 217 - u64 pdp[4]; 218 - u32 pp_dir_base; 219 - }; 220 - } vm_info; 221 - 222 - struct drm_i915_error_engine *next; 223 - } *engine; 224 121 225 122 struct scatterlist *sgl, *fit; 226 123 }; ··· 183 172 /* For reset and error_state handling. */ 184 173 spinlock_t lock; 185 174 /* Protected by the above dev->gpu_error.lock. */ 186 - struct i915_gpu_state *first_error; 175 + struct i915_gpu_coredump *first_error; 187 176 188 177 atomic_t pending_fb_pin; 189 178 ··· 211 200 __printf(2, 3) 212 201 void i915_error_printf(struct drm_i915_error_state_buf *e, const char *f, ...); 213 202 214 - struct i915_gpu_state *i915_capture_gpu_state(struct drm_i915_private *i915); 215 - void i915_capture_error_state(struct drm_i915_private *dev_priv, 216 - intel_engine_mask_t engine_mask, 217 - const char *error_msg); 203 + struct i915_gpu_coredump *i915_gpu_coredump(struct drm_i915_private *i915); 204 + void i915_capture_error_state(struct drm_i915_private *i915); 218 205 219 - static inline struct i915_gpu_state * 220 - i915_gpu_state_get(struct i915_gpu_state *gpu) 206 + struct i915_gpu_coredump * 207 + i915_gpu_coredump_alloc(struct drm_i915_private *i915, gfp_t gfp); 208 + 209 + struct intel_gt_coredump * 210 + intel_gt_coredump_alloc(struct intel_gt *gt, gfp_t gfp); 211 + 212 + struct intel_engine_coredump * 213 + intel_engine_coredump_alloc(struct intel_engine_cs *engine, gfp_t gfp); 214 + 215 + struct intel_engine_capture_vma * 216 + intel_engine_coredump_add_request(struct intel_engine_coredump *ee, 217 + struct i915_request *rq, 218 + gfp_t gfp); 219 + 220 + void intel_engine_coredump_add_vma(struct intel_engine_coredump *ee, 221 + struct intel_engine_capture_vma *capture, 222 + struct i915_vma_compress *compress); 223 + 224 + struct i915_vma_compress * 225 + i915_vma_capture_prepare(struct intel_gt_coredump *gt); 226 + 227 + void i915_vma_capture_finish(struct intel_gt_coredump *gt, 228 + struct i915_vma_compress *compress); 229 + 230 + void i915_error_state_store(struct i915_gpu_coredump *error); 231 + 232 + static inline struct i915_gpu_coredump * 233 + i915_gpu_coredump_get(struct i915_gpu_coredump *gpu) 221 234 { 222 235 kref_get(&gpu->ref); 223 236 return gpu; 224 237 } 225 238 226 - ssize_t i915_gpu_state_copy_to_buffer(struct i915_gpu_state *error, 227 - char *buf, loff_t offset, size_t count); 239 + ssize_t 240 + i915_gpu_coredump_copy_to_buffer(struct i915_gpu_coredump *error, 241 + char *buf, loff_t offset, size_t count); 228 242 229 - void __i915_gpu_state_free(struct kref *kref); 230 - static inline void i915_gpu_state_put(struct i915_gpu_state *gpu) 243 + void __i915_gpu_coredump_free(struct kref *kref); 244 + static inline void i915_gpu_coredump_put(struct i915_gpu_coredump *gpu) 231 245 { 232 246 if (gpu) 233 - kref_put(&gpu->ref, __i915_gpu_state_free); 247 + kref_put(&gpu->ref, __i915_gpu_coredump_free); 234 248 } 235 249 236 - struct i915_gpu_state *i915_first_error_state(struct drm_i915_private *i915); 250 + struct i915_gpu_coredump *i915_first_error_state(struct drm_i915_private *i915); 237 251 void i915_reset_error_state(struct drm_i915_private *i915); 238 252 void i915_disable_error_state(struct drm_i915_private *i915, int err); 239 253 240 254 #else 241 255 242 - static inline void i915_capture_error_state(struct drm_i915_private *dev_priv, 243 - u32 engine_mask, 244 - const char *error_msg) 256 + static inline void i915_capture_error_state(struct drm_i915_private *i915) 245 257 { 246 258 } 247 259 248 - static inline struct i915_gpu_state * 260 + static inline struct i915_gpu_coredump * 261 + i915_gpu_coredump_alloc(struct drm_i915_private *i915, gfp_t gfp) 262 + { 263 + return NULL; 264 + } 265 + 266 + static inline struct intel_gt_coredump * 267 + intel_gt_coredump_alloc(struct intel_gt *gt, gfp_t gfp) 268 + { 269 + return NULL; 270 + } 271 + 272 + static inline struct intel_engine_coredump * 273 + intel_engine_coredump_alloc(struct intel_engine_cs *engine, gfp_t gfp) 274 + { 275 + return NULL; 276 + } 277 + 278 + static inline struct intel_engine_capture_vma * 279 + intel_engine_coredump_add_request(struct intel_engine_coredump *ee, 280 + struct i915_request *rq, 281 + gfp_t gfp) 282 + { 283 + return NULL; 284 + } 285 + 286 + static inline void 287 + intel_engine_coredump_add_vma(struct intel_engine_coredump *ee, 288 + struct intel_engine_capture_vma *capture, 289 + struct i915_vma_compress *compress) 290 + { 291 + } 292 + 293 + static inline struct i915_vma_compress * 294 + i915_vma_capture_prepare(struct intel_gt_coredump *gt) 295 + { 296 + return NULL; 297 + } 298 + 299 + static inline void 300 + i915_vma_capture_finish(struct intel_gt_coredump *gt, 301 + struct i915_vma_compress *compress) 302 + { 303 + } 304 + 305 + static inline void 306 + i915_error_state_store(struct drm_i915_private *i915, 307 + struct i915_gpu_coredump *error) 308 + { 309 + } 310 + 311 + static inline struct i915_gpu_coredump * 249 312 i915_first_error_state(struct drm_i915_private *i915) 250 313 { 251 314 return ERR_PTR(-ENODEV);
+9 -9
drivers/gpu/drm/i915/i915_irq.c
··· 893 893 } 894 894 895 895 /** 896 - * ivybridge_parity_work - Workqueue called when a parity error interrupt 896 + * ivb_parity_work - Workqueue called when a parity error interrupt 897 897 * occurred. 898 898 * @work: workqueue struct 899 899 * ··· 901 901 * this event, userspace should try to remap the bad rows since statistically 902 902 * it is likely the same row is more likely to go bad again. 903 903 */ 904 - static void ivybridge_parity_work(struct work_struct *work) 904 + static void ivb_parity_work(struct work_struct *work) 905 905 { 906 906 struct drm_i915_private *dev_priv = 907 907 container_of(work, typeof(*dev_priv), l3_parity.error_work); ··· 2031 2031 * 4 - Process the interrupt(s) that had bits set in the IIRs. 2032 2032 * 5 - Re-enable Master Interrupt Control. 2033 2033 */ 2034 - static irqreturn_t ironlake_irq_handler(int irq, void *arg) 2034 + static irqreturn_t ilk_irq_handler(int irq, void *arg) 2035 2035 { 2036 2036 struct drm_i915_private *dev_priv = arg; 2037 2037 u32 de_iir, gt_iir, de_ier, sde_ier = 0; ··· 2742 2742 2743 2743 /* drm_dma.h hooks 2744 2744 */ 2745 - static void ironlake_irq_reset(struct drm_i915_private *dev_priv) 2745 + static void ilk_irq_reset(struct drm_i915_private *dev_priv) 2746 2746 { 2747 2747 struct intel_uncore *uncore = &dev_priv->uncore; 2748 2748 ··· 3225 3225 spt_hpd_detection_setup(dev_priv); 3226 3226 } 3227 3227 3228 - static void ironlake_irq_postinstall(struct drm_i915_private *dev_priv) 3228 + static void ilk_irq_postinstall(struct drm_i915_private *dev_priv) 3229 3229 { 3230 3230 struct intel_uncore *uncore = &dev_priv->uncore; 3231 3231 u32 display_mask, extra_mask; ··· 3899 3899 3900 3900 intel_hpd_init_work(dev_priv); 3901 3901 3902 - INIT_WORK(&dev_priv->l3_parity.error_work, ivybridge_parity_work); 3902 + INIT_WORK(&dev_priv->l3_parity.error_work, ivb_parity_work); 3903 3903 for (i = 0; i < MAX_L3_SLICES; ++i) 3904 3904 dev_priv->l3_parity.remap_info[i] = NULL; 3905 3905 ··· 3980 3980 else if (INTEL_GEN(dev_priv) >= 8) 3981 3981 return gen8_irq_handler; 3982 3982 else 3983 - return ironlake_irq_handler; 3983 + return ilk_irq_handler; 3984 3984 } 3985 3985 } 3986 3986 ··· 4003 4003 else if (INTEL_GEN(dev_priv) >= 8) 4004 4004 gen8_irq_reset(dev_priv); 4005 4005 else 4006 - ironlake_irq_reset(dev_priv); 4006 + ilk_irq_reset(dev_priv); 4007 4007 } 4008 4008 } 4009 4009 ··· 4026 4026 else if (INTEL_GEN(dev_priv) >= 8) 4027 4027 gen8_irq_postinstall(dev_priv); 4028 4028 else 4029 - ironlake_irq_postinstall(dev_priv); 4029 + ilk_irq_postinstall(dev_priv); 4030 4030 } 4031 4031 } 4032 4032
+69
drivers/gpu/drm/i915/i915_mm.c
··· 33 33 struct mm_struct *mm; 34 34 unsigned long pfn; 35 35 pgprot_t prot; 36 + 37 + struct sgt_iter sgt; 38 + resource_size_t iobase; 36 39 }; 37 40 38 41 static int remap_pfn(pte_t *pte, unsigned long addr, void *data) ··· 45 42 /* Special PTE are not associated with any struct page */ 46 43 set_pte_at(r->mm, addr, pte, pte_mkspecial(pfn_pte(r->pfn, r->prot))); 47 44 r->pfn++; 45 + 46 + return 0; 47 + } 48 + 49 + #define use_dma(io) ((io) != -1) 50 + 51 + static inline unsigned long sgt_pfn(const struct remap_pfn *r) 52 + { 53 + if (use_dma(r->iobase)) 54 + return (r->sgt.dma + r->sgt.curr + r->iobase) >> PAGE_SHIFT; 55 + else 56 + return r->sgt.pfn + (r->sgt.curr >> PAGE_SHIFT); 57 + } 58 + 59 + static int remap_sg(pte_t *pte, unsigned long addr, void *data) 60 + { 61 + struct remap_pfn *r = data; 62 + 63 + if (GEM_WARN_ON(!r->sgt.pfn)) 64 + return -EINVAL; 65 + 66 + /* Special PTE are not associated with any struct page */ 67 + set_pte_at(r->mm, addr, pte, 68 + pte_mkspecial(pfn_pte(sgt_pfn(r), r->prot))); 69 + r->pfn++; /* track insertions in case we need to unwind later */ 70 + 71 + r->sgt.curr += PAGE_SIZE; 72 + if (r->sgt.curr >= r->sgt.max) 73 + r->sgt = __sgt_iter(__sg_next(r->sgt.sgp), use_dma(r->iobase)); 48 74 49 75 return 0; 50 76 } ··· 107 75 err = apply_to_page_range(r.mm, addr, size, remap_pfn, &r); 108 76 if (unlikely(err)) { 109 77 zap_vma_ptes(vma, addr, (r.pfn - pfn) << PAGE_SHIFT); 78 + return err; 79 + } 80 + 81 + return 0; 82 + } 83 + 84 + /** 85 + * remap_io_sg - remap an IO mapping to userspace 86 + * @vma: user vma to map to 87 + * @addr: target user address to start at 88 + * @size: size of map area 89 + * @sgl: Start sg entry 90 + * @iobase: Use stored dma address offset by this address or pfn if -1 91 + * 92 + * Note: this is only safe if the mm semaphore is held when called. 93 + */ 94 + int remap_io_sg(struct vm_area_struct *vma, 95 + unsigned long addr, unsigned long size, 96 + struct scatterlist *sgl, resource_size_t iobase) 97 + { 98 + struct remap_pfn r = { 99 + .mm = vma->vm_mm, 100 + .prot = vma->vm_page_prot, 101 + .sgt = __sgt_iter(sgl, use_dma(iobase)), 102 + .iobase = iobase, 103 + }; 104 + int err; 105 + 106 + /* We rely on prevalidation of the io-mapping to skip track_pfn(). */ 107 + GEM_BUG_ON((vma->vm_flags & EXPECTED_FLAGS) != EXPECTED_FLAGS); 108 + 109 + if (!use_dma(iobase)) 110 + flush_cache_range(vma, addr, size); 111 + 112 + err = apply_to_page_range(r.mm, addr, size, remap_sg, &r); 113 + if (unlikely(err)) { 114 + zap_vma_ptes(vma, addr, r.pfn << PAGE_SHIFT); 110 115 return err; 111 116 } 112 117
+115 -115
drivers/gpu/drm/i915/i915_pci.c
··· 193 193 GEN_DEFAULT_PAGE_SIZES, \ 194 194 GEN_DEFAULT_REGIONS 195 195 196 - static const struct intel_device_info intel_i830_info = { 196 + static const struct intel_device_info i830_info = { 197 197 I830_FEATURES, 198 198 PLATFORM(INTEL_I830), 199 199 }; 200 200 201 - static const struct intel_device_info intel_i845g_info = { 201 + static const struct intel_device_info i845g_info = { 202 202 I845_FEATURES, 203 203 PLATFORM(INTEL_I845G), 204 204 }; 205 205 206 - static const struct intel_device_info intel_i85x_info = { 206 + static const struct intel_device_info i85x_info = { 207 207 I830_FEATURES, 208 208 PLATFORM(INTEL_I85X), 209 209 .display.has_fbc = 1, 210 210 }; 211 211 212 - static const struct intel_device_info intel_i865g_info = { 212 + static const struct intel_device_info i865g_info = { 213 213 I845_FEATURES, 214 214 PLATFORM(INTEL_I865G), 215 215 }; ··· 228 228 GEN_DEFAULT_PAGE_SIZES, \ 229 229 GEN_DEFAULT_REGIONS 230 230 231 - static const struct intel_device_info intel_i915g_info = { 231 + static const struct intel_device_info i915g_info = { 232 232 GEN3_FEATURES, 233 233 PLATFORM(INTEL_I915G), 234 234 .has_coherent_ggtt = false, ··· 239 239 .unfenced_needs_alignment = 1, 240 240 }; 241 241 242 - static const struct intel_device_info intel_i915gm_info = { 242 + static const struct intel_device_info i915gm_info = { 243 243 GEN3_FEATURES, 244 244 PLATFORM(INTEL_I915GM), 245 245 .is_mobile = 1, ··· 252 252 .unfenced_needs_alignment = 1, 253 253 }; 254 254 255 - static const struct intel_device_info intel_i945g_info = { 255 + static const struct intel_device_info i945g_info = { 256 256 GEN3_FEATURES, 257 257 PLATFORM(INTEL_I945G), 258 258 .display.has_hotplug = 1, ··· 263 263 .unfenced_needs_alignment = 1, 264 264 }; 265 265 266 - static const struct intel_device_info intel_i945gm_info = { 266 + static const struct intel_device_info i945gm_info = { 267 267 GEN3_FEATURES, 268 268 PLATFORM(INTEL_I945GM), 269 269 .is_mobile = 1, ··· 277 277 .unfenced_needs_alignment = 1, 278 278 }; 279 279 280 - static const struct intel_device_info intel_g33_info = { 280 + static const struct intel_device_info g33_info = { 281 281 GEN3_FEATURES, 282 282 PLATFORM(INTEL_G33), 283 283 .display.has_hotplug = 1, 284 284 .display.has_overlay = 1, 285 285 }; 286 286 287 - static const struct intel_device_info intel_pineview_g_info = { 287 + static const struct intel_device_info pnv_g_info = { 288 288 GEN3_FEATURES, 289 289 PLATFORM(INTEL_PINEVIEW), 290 290 .display.has_hotplug = 1, 291 291 .display.has_overlay = 1, 292 292 }; 293 293 294 - static const struct intel_device_info intel_pineview_m_info = { 294 + static const struct intel_device_info pnv_m_info = { 295 295 GEN3_FEATURES, 296 296 PLATFORM(INTEL_PINEVIEW), 297 297 .is_mobile = 1, ··· 314 314 GEN_DEFAULT_PAGE_SIZES, \ 315 315 GEN_DEFAULT_REGIONS 316 316 317 - static const struct intel_device_info intel_i965g_info = { 317 + static const struct intel_device_info i965g_info = { 318 318 GEN4_FEATURES, 319 319 PLATFORM(INTEL_I965G), 320 320 .display.has_overlay = 1, ··· 322 322 .has_snoop = false, 323 323 }; 324 324 325 - static const struct intel_device_info intel_i965gm_info = { 325 + static const struct intel_device_info i965gm_info = { 326 326 GEN4_FEATURES, 327 327 PLATFORM(INTEL_I965GM), 328 328 .is_mobile = 1, ··· 333 333 .has_snoop = false, 334 334 }; 335 335 336 - static const struct intel_device_info intel_g45_info = { 336 + static const struct intel_device_info g45_info = { 337 337 GEN4_FEATURES, 338 338 PLATFORM(INTEL_G45), 339 339 .engine_mask = BIT(RCS0) | BIT(VCS0), 340 340 .gpu_reset_clobbers_display = false, 341 341 }; 342 342 343 - static const struct intel_device_info intel_gm45_info = { 343 + static const struct intel_device_info gm45_info = { 344 344 GEN4_FEATURES, 345 345 PLATFORM(INTEL_GM45), 346 346 .is_mobile = 1, ··· 365 365 GEN_DEFAULT_PAGE_SIZES, \ 366 366 GEN_DEFAULT_REGIONS 367 367 368 - static const struct intel_device_info intel_ironlake_d_info = { 368 + static const struct intel_device_info ilk_d_info = { 369 369 GEN5_FEATURES, 370 370 PLATFORM(INTEL_IRONLAKE), 371 371 }; 372 372 373 - static const struct intel_device_info intel_ironlake_m_info = { 373 + static const struct intel_device_info ilk_m_info = { 374 374 GEN5_FEATURES, 375 375 PLATFORM(INTEL_IRONLAKE), 376 376 .is_mobile = 1, ··· 400 400 GEN6_FEATURES, \ 401 401 PLATFORM(INTEL_SANDYBRIDGE) 402 402 403 - static const struct intel_device_info intel_sandybridge_d_gt1_info = { 403 + static const struct intel_device_info snb_d_gt1_info = { 404 404 SNB_D_PLATFORM, 405 405 .gt = 1, 406 406 }; 407 407 408 - static const struct intel_device_info intel_sandybridge_d_gt2_info = { 408 + static const struct intel_device_info snb_d_gt2_info = { 409 409 SNB_D_PLATFORM, 410 410 .gt = 2, 411 411 }; ··· 416 416 .is_mobile = 1 417 417 418 418 419 - static const struct intel_device_info intel_sandybridge_m_gt1_info = { 419 + static const struct intel_device_info snb_m_gt1_info = { 420 420 SNB_M_PLATFORM, 421 421 .gt = 1, 422 422 }; 423 423 424 - static const struct intel_device_info intel_sandybridge_m_gt2_info = { 424 + static const struct intel_device_info snb_m_gt2_info = { 425 425 SNB_M_PLATFORM, 426 426 .gt = 2, 427 427 }; ··· 450 450 PLATFORM(INTEL_IVYBRIDGE), \ 451 451 .has_l3_dpf = 1 452 452 453 - static const struct intel_device_info intel_ivybridge_d_gt1_info = { 453 + static const struct intel_device_info ivb_d_gt1_info = { 454 454 IVB_D_PLATFORM, 455 455 .gt = 1, 456 456 }; 457 457 458 - static const struct intel_device_info intel_ivybridge_d_gt2_info = { 458 + static const struct intel_device_info ivb_d_gt2_info = { 459 459 IVB_D_PLATFORM, 460 460 .gt = 2, 461 461 }; ··· 466 466 .is_mobile = 1, \ 467 467 .has_l3_dpf = 1 468 468 469 - static const struct intel_device_info intel_ivybridge_m_gt1_info = { 469 + static const struct intel_device_info ivb_m_gt1_info = { 470 470 IVB_M_PLATFORM, 471 471 .gt = 1, 472 472 }; 473 473 474 - static const struct intel_device_info intel_ivybridge_m_gt2_info = { 474 + static const struct intel_device_info ivb_m_gt2_info = { 475 475 IVB_M_PLATFORM, 476 476 .gt = 2, 477 477 }; 478 478 479 - static const struct intel_device_info intel_ivybridge_q_info = { 479 + static const struct intel_device_info ivb_q_info = { 480 480 GEN7_FEATURES, 481 481 PLATFORM(INTEL_IVYBRIDGE), 482 482 .gt = 2, ··· 484 484 .has_l3_dpf = 1, 485 485 }; 486 486 487 - static const struct intel_device_info intel_valleyview_info = { 487 + static const struct intel_device_info vlv_info = { 488 488 PLATFORM(INTEL_VALLEYVIEW), 489 489 GEN(7), 490 490 .is_lp = 1, ··· 523 523 PLATFORM(INTEL_HASWELL), \ 524 524 .has_l3_dpf = 1 525 525 526 - static const struct intel_device_info intel_haswell_gt1_info = { 526 + static const struct intel_device_info hsw_gt1_info = { 527 527 HSW_PLATFORM, 528 528 .gt = 1, 529 529 }; 530 530 531 - static const struct intel_device_info intel_haswell_gt2_info = { 531 + static const struct intel_device_info hsw_gt2_info = { 532 532 HSW_PLATFORM, 533 533 .gt = 2, 534 534 }; 535 535 536 - static const struct intel_device_info intel_haswell_gt3_info = { 536 + static const struct intel_device_info hsw_gt3_info = { 537 537 HSW_PLATFORM, 538 538 .gt = 3, 539 539 }; ··· 551 551 GEN8_FEATURES, \ 552 552 PLATFORM(INTEL_BROADWELL) 553 553 554 - static const struct intel_device_info intel_broadwell_gt1_info = { 554 + static const struct intel_device_info bdw_gt1_info = { 555 555 BDW_PLATFORM, 556 556 .gt = 1, 557 557 }; 558 558 559 - static const struct intel_device_info intel_broadwell_gt2_info = { 559 + static const struct intel_device_info bdw_gt2_info = { 560 560 BDW_PLATFORM, 561 561 .gt = 2, 562 562 }; 563 563 564 - static const struct intel_device_info intel_broadwell_rsvd_info = { 564 + static const struct intel_device_info bdw_rsvd_info = { 565 565 BDW_PLATFORM, 566 566 .gt = 3, 567 567 /* According to the device ID those devices are GT3, they were ··· 569 569 */ 570 570 }; 571 571 572 - static const struct intel_device_info intel_broadwell_gt3_info = { 572 + static const struct intel_device_info bdw_gt3_info = { 573 573 BDW_PLATFORM, 574 574 .gt = 3, 575 575 .engine_mask = 576 576 BIT(RCS0) | BIT(VCS0) | BIT(BCS0) | BIT(VECS0) | BIT(VCS1), 577 577 }; 578 578 579 - static const struct intel_device_info intel_cherryview_info = { 579 + static const struct intel_device_info chv_info = { 580 580 PLATFORM(INTEL_CHERRYVIEW), 581 581 GEN(8), 582 582 .pipe_mask = BIT(PIPE_A) | BIT(PIPE_B) | BIT(PIPE_C), ··· 621 621 GEN9_FEATURES, \ 622 622 PLATFORM(INTEL_SKYLAKE) 623 623 624 - static const struct intel_device_info intel_skylake_gt1_info = { 624 + static const struct intel_device_info skl_gt1_info = { 625 625 SKL_PLATFORM, 626 626 .gt = 1, 627 627 }; 628 628 629 - static const struct intel_device_info intel_skylake_gt2_info = { 629 + static const struct intel_device_info skl_gt2_info = { 630 630 SKL_PLATFORM, 631 631 .gt = 2, 632 632 }; ··· 637 637 BIT(RCS0) | BIT(VCS0) | BIT(BCS0) | BIT(VECS0) | BIT(VCS1) 638 638 639 639 640 - static const struct intel_device_info intel_skylake_gt3_info = { 640 + static const struct intel_device_info skl_gt3_info = { 641 641 SKL_GT3_PLUS_PLATFORM, 642 642 .gt = 3, 643 643 }; 644 644 645 - static const struct intel_device_info intel_skylake_gt4_info = { 645 + static const struct intel_device_info skl_gt4_info = { 646 646 SKL_GT3_PLUS_PLATFORM, 647 647 .gt = 4, 648 648 }; ··· 679 679 GEN9_DEFAULT_PAGE_SIZES, \ 680 680 GEN_DEFAULT_REGIONS 681 681 682 - static const struct intel_device_info intel_broxton_info = { 682 + static const struct intel_device_info bxt_info = { 683 683 GEN9_LP_FEATURES, 684 684 PLATFORM(INTEL_BROXTON), 685 685 .ddb_size = 512, 686 686 }; 687 687 688 - static const struct intel_device_info intel_geminilake_info = { 688 + static const struct intel_device_info glk_info = { 689 689 GEN9_LP_FEATURES, 690 690 PLATFORM(INTEL_GEMINILAKE), 691 691 .ddb_size = 1024, ··· 696 696 GEN9_FEATURES, \ 697 697 PLATFORM(INTEL_KABYLAKE) 698 698 699 - static const struct intel_device_info intel_kabylake_gt1_info = { 699 + static const struct intel_device_info kbl_gt1_info = { 700 700 KBL_PLATFORM, 701 701 .gt = 1, 702 702 }; 703 703 704 - static const struct intel_device_info intel_kabylake_gt2_info = { 704 + static const struct intel_device_info kbl_gt2_info = { 705 705 KBL_PLATFORM, 706 706 .gt = 2, 707 707 }; 708 708 709 - static const struct intel_device_info intel_kabylake_gt3_info = { 709 + static const struct intel_device_info kbl_gt3_info = { 710 710 KBL_PLATFORM, 711 711 .gt = 3, 712 712 .engine_mask = ··· 717 717 GEN9_FEATURES, \ 718 718 PLATFORM(INTEL_COFFEELAKE) 719 719 720 - static const struct intel_device_info intel_coffeelake_gt1_info = { 720 + static const struct intel_device_info cfl_gt1_info = { 721 721 CFL_PLATFORM, 722 722 .gt = 1, 723 723 }; 724 724 725 - static const struct intel_device_info intel_coffeelake_gt2_info = { 725 + static const struct intel_device_info cfl_gt2_info = { 726 726 CFL_PLATFORM, 727 727 .gt = 2, 728 728 }; 729 729 730 - static const struct intel_device_info intel_coffeelake_gt3_info = { 730 + static const struct intel_device_info cfl_gt3_info = { 731 731 CFL_PLATFORM, 732 732 .gt = 3, 733 733 .engine_mask = ··· 742 742 .has_coherent_ggtt = false, \ 743 743 GLK_COLORS 744 744 745 - static const struct intel_device_info intel_cannonlake_info = { 745 + static const struct intel_device_info cnl_info = { 746 746 GEN10_FEATURES, 747 747 PLATFORM(INTEL_CANNONLAKE), 748 748 .gt = 2, ··· 777 777 .has_logical_ring_elsq = 1, \ 778 778 .color = { .degamma_lut_size = 33, .gamma_lut_size = 262145 } 779 779 780 - static const struct intel_device_info intel_icelake_11_info = { 780 + static const struct intel_device_info icl_info = { 781 781 GEN11_FEATURES, 782 782 PLATFORM(INTEL_ICELAKE), 783 783 .engine_mask = 784 784 BIT(RCS0) | BIT(BCS0) | BIT(VECS0) | BIT(VCS0) | BIT(VCS2), 785 785 }; 786 786 787 - static const struct intel_device_info intel_elkhartlake_info = { 787 + static const struct intel_device_info ehl_info = { 788 788 GEN11_FEATURES, 789 789 PLATFORM(INTEL_ELKHARTLAKE), 790 790 .require_force_probe = 1, ··· 815 815 .has_global_mocs = 1, \ 816 816 .display.has_dsb = 1 817 817 818 - static const struct intel_device_info intel_tigerlake_12_info = { 818 + static const struct intel_device_info tgl_info = { 819 819 GEN12_FEATURES, 820 820 PLATFORM(INTEL_TIGERLAKE), 821 821 .pipe_mask = BIT(PIPE_A) | BIT(PIPE_B) | BIT(PIPE_C) | BIT(PIPE_D), ··· 840 840 * PCI ID matches, otherwise we'll use the wrong info struct above. 841 841 */ 842 842 static const struct pci_device_id pciidlist[] = { 843 - INTEL_I830_IDS(&intel_i830_info), 844 - INTEL_I845G_IDS(&intel_i845g_info), 845 - INTEL_I85X_IDS(&intel_i85x_info), 846 - INTEL_I865G_IDS(&intel_i865g_info), 847 - INTEL_I915G_IDS(&intel_i915g_info), 848 - INTEL_I915GM_IDS(&intel_i915gm_info), 849 - INTEL_I945G_IDS(&intel_i945g_info), 850 - INTEL_I945GM_IDS(&intel_i945gm_info), 851 - INTEL_I965G_IDS(&intel_i965g_info), 852 - INTEL_G33_IDS(&intel_g33_info), 853 - INTEL_I965GM_IDS(&intel_i965gm_info), 854 - INTEL_GM45_IDS(&intel_gm45_info), 855 - INTEL_G45_IDS(&intel_g45_info), 856 - INTEL_PINEVIEW_G_IDS(&intel_pineview_g_info), 857 - INTEL_PINEVIEW_M_IDS(&intel_pineview_m_info), 858 - INTEL_IRONLAKE_D_IDS(&intel_ironlake_d_info), 859 - INTEL_IRONLAKE_M_IDS(&intel_ironlake_m_info), 860 - INTEL_SNB_D_GT1_IDS(&intel_sandybridge_d_gt1_info), 861 - INTEL_SNB_D_GT2_IDS(&intel_sandybridge_d_gt2_info), 862 - INTEL_SNB_M_GT1_IDS(&intel_sandybridge_m_gt1_info), 863 - INTEL_SNB_M_GT2_IDS(&intel_sandybridge_m_gt2_info), 864 - INTEL_IVB_Q_IDS(&intel_ivybridge_q_info), /* must be first IVB */ 865 - INTEL_IVB_M_GT1_IDS(&intel_ivybridge_m_gt1_info), 866 - INTEL_IVB_M_GT2_IDS(&intel_ivybridge_m_gt2_info), 867 - INTEL_IVB_D_GT1_IDS(&intel_ivybridge_d_gt1_info), 868 - INTEL_IVB_D_GT2_IDS(&intel_ivybridge_d_gt2_info), 869 - INTEL_HSW_GT1_IDS(&intel_haswell_gt1_info), 870 - INTEL_HSW_GT2_IDS(&intel_haswell_gt2_info), 871 - INTEL_HSW_GT3_IDS(&intel_haswell_gt3_info), 872 - INTEL_VLV_IDS(&intel_valleyview_info), 873 - INTEL_BDW_GT1_IDS(&intel_broadwell_gt1_info), 874 - INTEL_BDW_GT2_IDS(&intel_broadwell_gt2_info), 875 - INTEL_BDW_GT3_IDS(&intel_broadwell_gt3_info), 876 - INTEL_BDW_RSVD_IDS(&intel_broadwell_rsvd_info), 877 - INTEL_CHV_IDS(&intel_cherryview_info), 878 - INTEL_SKL_GT1_IDS(&intel_skylake_gt1_info), 879 - INTEL_SKL_GT2_IDS(&intel_skylake_gt2_info), 880 - INTEL_SKL_GT3_IDS(&intel_skylake_gt3_info), 881 - INTEL_SKL_GT4_IDS(&intel_skylake_gt4_info), 882 - INTEL_BXT_IDS(&intel_broxton_info), 883 - INTEL_GLK_IDS(&intel_geminilake_info), 884 - INTEL_KBL_GT1_IDS(&intel_kabylake_gt1_info), 885 - INTEL_KBL_GT2_IDS(&intel_kabylake_gt2_info), 886 - INTEL_KBL_GT3_IDS(&intel_kabylake_gt3_info), 887 - INTEL_KBL_GT4_IDS(&intel_kabylake_gt3_info), 888 - INTEL_AML_KBL_GT2_IDS(&intel_kabylake_gt2_info), 889 - INTEL_CFL_S_GT1_IDS(&intel_coffeelake_gt1_info), 890 - INTEL_CFL_S_GT2_IDS(&intel_coffeelake_gt2_info), 891 - INTEL_CFL_H_GT1_IDS(&intel_coffeelake_gt1_info), 892 - INTEL_CFL_H_GT2_IDS(&intel_coffeelake_gt2_info), 893 - INTEL_CFL_U_GT2_IDS(&intel_coffeelake_gt2_info), 894 - INTEL_CFL_U_GT3_IDS(&intel_coffeelake_gt3_info), 895 - INTEL_WHL_U_GT1_IDS(&intel_coffeelake_gt1_info), 896 - INTEL_WHL_U_GT2_IDS(&intel_coffeelake_gt2_info), 897 - INTEL_AML_CFL_GT2_IDS(&intel_coffeelake_gt2_info), 898 - INTEL_WHL_U_GT3_IDS(&intel_coffeelake_gt3_info), 899 - INTEL_CML_GT1_IDS(&intel_coffeelake_gt1_info), 900 - INTEL_CML_GT2_IDS(&intel_coffeelake_gt2_info), 901 - INTEL_CML_U_GT1_IDS(&intel_coffeelake_gt1_info), 902 - INTEL_CML_U_GT2_IDS(&intel_coffeelake_gt2_info), 903 - INTEL_CNL_IDS(&intel_cannonlake_info), 904 - INTEL_ICL_11_IDS(&intel_icelake_11_info), 905 - INTEL_EHL_IDS(&intel_elkhartlake_info), 906 - INTEL_TGL_12_IDS(&intel_tigerlake_12_info), 843 + INTEL_I830_IDS(&i830_info), 844 + INTEL_I845G_IDS(&i845g_info), 845 + INTEL_I85X_IDS(&i85x_info), 846 + INTEL_I865G_IDS(&i865g_info), 847 + INTEL_I915G_IDS(&i915g_info), 848 + INTEL_I915GM_IDS(&i915gm_info), 849 + INTEL_I945G_IDS(&i945g_info), 850 + INTEL_I945GM_IDS(&i945gm_info), 851 + INTEL_I965G_IDS(&i965g_info), 852 + INTEL_G33_IDS(&g33_info), 853 + INTEL_I965GM_IDS(&i965gm_info), 854 + INTEL_GM45_IDS(&gm45_info), 855 + INTEL_G45_IDS(&g45_info), 856 + INTEL_PINEVIEW_G_IDS(&pnv_g_info), 857 + INTEL_PINEVIEW_M_IDS(&pnv_m_info), 858 + INTEL_IRONLAKE_D_IDS(&ilk_d_info), 859 + INTEL_IRONLAKE_M_IDS(&ilk_m_info), 860 + INTEL_SNB_D_GT1_IDS(&snb_d_gt1_info), 861 + INTEL_SNB_D_GT2_IDS(&snb_d_gt2_info), 862 + INTEL_SNB_M_GT1_IDS(&snb_m_gt1_info), 863 + INTEL_SNB_M_GT2_IDS(&snb_m_gt2_info), 864 + INTEL_IVB_Q_IDS(&ivb_q_info), /* must be first IVB */ 865 + INTEL_IVB_M_GT1_IDS(&ivb_m_gt1_info), 866 + INTEL_IVB_M_GT2_IDS(&ivb_m_gt2_info), 867 + INTEL_IVB_D_GT1_IDS(&ivb_d_gt1_info), 868 + INTEL_IVB_D_GT2_IDS(&ivb_d_gt2_info), 869 + INTEL_HSW_GT1_IDS(&hsw_gt1_info), 870 + INTEL_HSW_GT2_IDS(&hsw_gt2_info), 871 + INTEL_HSW_GT3_IDS(&hsw_gt3_info), 872 + INTEL_VLV_IDS(&vlv_info), 873 + INTEL_BDW_GT1_IDS(&bdw_gt1_info), 874 + INTEL_BDW_GT2_IDS(&bdw_gt2_info), 875 + INTEL_BDW_GT3_IDS(&bdw_gt3_info), 876 + INTEL_BDW_RSVD_IDS(&bdw_rsvd_info), 877 + INTEL_CHV_IDS(&chv_info), 878 + INTEL_SKL_GT1_IDS(&skl_gt1_info), 879 + INTEL_SKL_GT2_IDS(&skl_gt2_info), 880 + INTEL_SKL_GT3_IDS(&skl_gt3_info), 881 + INTEL_SKL_GT4_IDS(&skl_gt4_info), 882 + INTEL_BXT_IDS(&bxt_info), 883 + INTEL_GLK_IDS(&glk_info), 884 + INTEL_KBL_GT1_IDS(&kbl_gt1_info), 885 + INTEL_KBL_GT2_IDS(&kbl_gt2_info), 886 + INTEL_KBL_GT3_IDS(&kbl_gt3_info), 887 + INTEL_KBL_GT4_IDS(&kbl_gt3_info), 888 + INTEL_AML_KBL_GT2_IDS(&kbl_gt2_info), 889 + INTEL_CFL_S_GT1_IDS(&cfl_gt1_info), 890 + INTEL_CFL_S_GT2_IDS(&cfl_gt2_info), 891 + INTEL_CFL_H_GT1_IDS(&cfl_gt1_info), 892 + INTEL_CFL_H_GT2_IDS(&cfl_gt2_info), 893 + INTEL_CFL_U_GT2_IDS(&cfl_gt2_info), 894 + INTEL_CFL_U_GT3_IDS(&cfl_gt3_info), 895 + INTEL_WHL_U_GT1_IDS(&cfl_gt1_info), 896 + INTEL_WHL_U_GT2_IDS(&cfl_gt2_info), 897 + INTEL_AML_CFL_GT2_IDS(&cfl_gt2_info), 898 + INTEL_WHL_U_GT3_IDS(&cfl_gt3_info), 899 + INTEL_CML_GT1_IDS(&cfl_gt1_info), 900 + INTEL_CML_GT2_IDS(&cfl_gt2_info), 901 + INTEL_CML_U_GT1_IDS(&cfl_gt1_info), 902 + INTEL_CML_U_GT2_IDS(&cfl_gt2_info), 903 + INTEL_CNL_IDS(&cnl_info), 904 + INTEL_ICL_11_IDS(&icl_info), 905 + INTEL_EHL_IDS(&ehl_info), 906 + INTEL_TGL_12_IDS(&tgl_info), 907 907 {0, 0, 0} 908 908 }; 909 909 MODULE_DEVICE_TABLE(pci, pciidlist);
+5 -10
drivers/gpu/drm/i915/i915_perf.c
··· 2159 2159 struct i915_request *rq; 2160 2160 int err; 2161 2161 2162 - lockdep_assert_held(&ce->pin_mutex); 2163 - 2164 2162 rq = intel_engine_create_kernel_request(ce->engine); 2165 2163 if (IS_ERR(rq)) 2166 2164 return PTR_ERR(rq); ··· 2201 2203 if (ce->engine->class != RENDER_CLASS) 2202 2204 continue; 2203 2205 2204 - err = intel_context_lock_pinned(ce); 2205 - if (err) 2206 - break; 2206 + /* Otherwise OA settings will be set upon first use */ 2207 + if (!intel_context_pin_if_active(ce)) 2208 + continue; 2207 2209 2208 2210 flex->value = intel_sseu_make_rpcs(ctx->i915, &ce->sseu); 2211 + err = gen8_modify_context(ce, flex, count); 2209 2212 2210 - /* Otherwise OA settings will be set upon first use */ 2211 - if (intel_context_is_pinned(ce)) 2212 - err = gen8_modify_context(ce, flex, count); 2213 - 2214 - intel_context_unlock_pinned(ce); 2213 + intel_context_unpin(ce); 2215 2214 if (err) 2216 2215 break; 2217 2216 }
+8 -3
drivers/gpu/drm/i915/i915_pmu.c
··· 1117 1117 hrtimer_init(&pmu->timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL); 1118 1118 pmu->timer.function = i915_sample; 1119 1119 1120 - if (!is_igp(i915)) 1120 + if (!is_igp(i915)) { 1121 1121 pmu->name = kasprintf(GFP_KERNEL, 1122 - "i915-%s", 1122 + "i915_%s", 1123 1123 dev_name(i915->drm.dev)); 1124 - else 1124 + if (pmu->name) { 1125 + /* tools/perf reserves colons as special. */ 1126 + strreplace((char *)pmu->name, ':', '_'); 1127 + } 1128 + } else { 1125 1129 pmu->name = "i915"; 1130 + } 1126 1131 if (!pmu->name) 1127 1132 goto err; 1128 1133
+8 -21
drivers/gpu/drm/i915/i915_reg.h
··· 2244 2244 MG_DP_MODE_LN1_ACU_PORT1) 2245 2245 #define MG_DP_MODE_CFG_DP_X2_MODE (1 << 7) 2246 2246 #define MG_DP_MODE_CFG_DP_X1_MODE (1 << 6) 2247 - #define MG_DP_MODE_CFG_TR2PWR_GATING (1 << 5) 2248 - #define MG_DP_MODE_CFG_TRPWR_GATING (1 << 4) 2249 - #define MG_DP_MODE_CFG_CLNPWR_GATING (1 << 3) 2250 - #define MG_DP_MODE_CFG_DIGPWR_GATING (1 << 2) 2251 - #define MG_DP_MODE_CFG_GAONPWR_GATING (1 << 1) 2252 - 2253 - #define MG_MISC_SUS0_PORT1 0x168814 2254 - #define MG_MISC_SUS0_PORT2 0x169814 2255 - #define MG_MISC_SUS0_PORT3 0x16A814 2256 - #define MG_MISC_SUS0_PORT4 0x16B814 2257 - #define MG_MISC_SUS0(tc_port) \ 2258 - _MMIO(_PORT(tc_port, MG_MISC_SUS0_PORT1, MG_MISC_SUS0_PORT2)) 2259 - #define MG_MISC_SUS0_SUSCLK_DYNCLKGATE_MODE_MASK (3 << 14) 2260 - #define MG_MISC_SUS0_SUSCLK_DYNCLKGATE_MODE(x) ((x) << 14) 2261 - #define MG_MISC_SUS0_CFG_TR2PWR_GATING (1 << 12) 2262 - #define MG_MISC_SUS0_CFG_CL2PWR_GATING (1 << 11) 2263 - #define MG_MISC_SUS0_CFG_GAONPWR_GATING (1 << 10) 2264 - #define MG_MISC_SUS0_CFG_TRPWR_GATING (1 << 7) 2265 - #define MG_MISC_SUS0_CFG_CL1PWR_GATING (1 << 6) 2266 - #define MG_MISC_SUS0_CFG_DGPWR_GATING (1 << 5) 2267 2247 2268 2248 /* The spec defines this only for BXT PHY0, but lets assume that this 2269 2249 * would exist for PHY1 too if it had a second channel. ··· 4157 4177 #define CPSSUNIT_CLKGATE_DIS REG_BIT(9) 4158 4178 4159 4179 #define UNSLICE_UNIT_LEVEL_CLKGATE _MMIO(0x9434) 4160 - #define VFUNIT_CLKGATE_DIS (1 << 20) 4180 + #define VFUNIT_CLKGATE_DIS REG_BIT(20) 4181 + #define HSUNIT_CLKGATE_DIS REG_BIT(8) 4182 + #define VSUNIT_CLKGATE_DIS REG_BIT(3) 4183 + 4184 + #define UNSLICE_UNIT_LEVEL_CLKGATE2 _MMIO(0x94e4) 4185 + #define VSUNIT_CLKGATE_DIS_TGL REG_BIT(19) 4186 + #define PSDUNIT_CLKGATE_DIS REG_BIT(5) 4161 4187 4162 4188 #define INF_UNIT_LEVEL_CLKGATE _MMIO(0x9560) 4163 4189 #define CGPSF_CLKGATE_DIS (1 << 3) ··· 6794 6808 #define PLANE_CTL_TILED_Y (4 << 10) 6795 6809 #define PLANE_CTL_TILED_YF (5 << 10) 6796 6810 #define PLANE_CTL_FLIP_HORIZONTAL (1 << 8) 6811 + #define PLANE_CTL_MEDIA_DECOMPRESSION_ENABLE (1 << 4) /* TGL+ */ 6797 6812 #define PLANE_CTL_ALPHA_MASK (0x3 << 4) /* Pre-GLK */ 6798 6813 #define PLANE_CTL_ALPHA_DISABLE (0 << 4) 6799 6814 #define PLANE_CTL_ALPHA_SW_PREMULTIPLY (2 << 4)
-1
drivers/gpu/drm/i915/i915_request.c
··· 658 658 rq->engine = ce->engine; 659 659 rq->ring = ce->ring; 660 660 rq->execution_mask = ce->engine->mask; 661 - rq->flags = 0; 662 661 663 662 RCU_INIT_POINTER(rq->timeline, tl); 664 663 RCU_INIT_POINTER(rq->hwsp_cacheline, tl->hwsp_cacheline);
+36 -9
drivers/gpu/drm/i915/i915_request.h
··· 51 51 52 52 #define RQ_TRACE(rq, fmt, ...) do { \ 53 53 const struct i915_request *rq__ = (rq); \ 54 - ENGINE_TRACE(rq__->engine, "fence %llx:%lld, current %d" fmt, \ 54 + ENGINE_TRACE(rq__->engine, "fence %llx:%lld, current %d " fmt, \ 55 55 rq__->fence.context, rq__->fence.seqno, \ 56 56 hwsp_seqno(rq__), ##__VA_ARGS__); \ 57 57 } while (0) ··· 77 77 * a request is on the various signal_list. 78 78 */ 79 79 I915_FENCE_FLAG_SIGNAL, 80 + 81 + /* 82 + * I915_FENCE_FLAG_NOPREEMPT - this request should not be preempted 83 + * 84 + * The execution of some requests should not be interrupted. This is 85 + * a sensitive operation as it makes the request super important, 86 + * blocking other higher priority work. Abuse of this flag will 87 + * lead to quality of service issues. 88 + */ 89 + I915_FENCE_FLAG_NOPREEMPT, 90 + 91 + /* 92 + * I915_FENCE_FLAG_SENTINEL - this request should be last in the queue 93 + * 94 + * A high priority sentinel request may be submitted to clear the 95 + * submission queue. As it will be the only request in-flight, upon 96 + * execution all other active requests will have been preempted and 97 + * unsubmitted. This preemptive pulse is used to re-evaluate the 98 + * in-flight requests, particularly in cases where an active context 99 + * is banned and those active requests need to be cancelled. 100 + */ 101 + I915_FENCE_FLAG_SENTINEL, 102 + 103 + /* 104 + * I915_FENCE_FLAG_BOOST - upclock the gpu for this request 105 + * 106 + * Some requests are more important than others! In particular, a 107 + * request that the user is waiting on is typically required for 108 + * interactive latency, for which we want to minimise by upclocking 109 + * the GPU. Here we track such boost requests on a per-request basis. 110 + */ 111 + I915_FENCE_FLAG_BOOST, 80 112 }; 81 113 82 114 /** ··· 256 224 257 225 /** Time at which this request was emitted, in jiffies. */ 258 226 unsigned long emitted_jiffies; 259 - 260 - unsigned long flags; 261 - #define I915_REQUEST_WAITBOOST BIT(0) 262 - #define I915_REQUEST_NOPREEMPT BIT(1) 263 - #define I915_REQUEST_SENTINEL BIT(2) 264 227 265 228 /** timeline->request entry for this request */ 266 229 struct list_head link; ··· 469 442 470 443 static inline bool i915_request_has_waitboost(const struct i915_request *rq) 471 444 { 472 - return rq->flags & I915_REQUEST_WAITBOOST; 445 + return test_bit(I915_FENCE_FLAG_BOOST, &rq->fence.flags); 473 446 } 474 447 475 448 static inline bool i915_request_has_nopreempt(const struct i915_request *rq) 476 449 { 477 450 /* Preemption should only be disabled very rarely */ 478 - return unlikely(rq->flags & I915_REQUEST_NOPREEMPT); 451 + return unlikely(test_bit(I915_FENCE_FLAG_NOPREEMPT, &rq->fence.flags)); 479 452 } 480 453 481 454 static inline bool i915_request_has_sentinel(const struct i915_request *rq) 482 455 { 483 - return unlikely(rq->flags & I915_REQUEST_SENTINEL); 456 + return unlikely(test_bit(I915_FENCE_FLAG_SENTINEL, &rq->fence.flags)); 484 457 } 485 458 486 459 static inline struct intel_timeline *
+3 -3
drivers/gpu/drm/i915/i915_sysfs.c
··· 498 498 499 499 struct device *kdev = kobj_to_dev(kobj); 500 500 struct drm_i915_private *i915 = kdev_minor_to_i915(kdev); 501 - struct i915_gpu_state *gpu; 501 + struct i915_gpu_coredump *gpu; 502 502 ssize_t ret; 503 503 504 504 gpu = i915_first_error_state(i915); 505 505 if (IS_ERR(gpu)) { 506 506 ret = PTR_ERR(gpu); 507 507 } else if (gpu) { 508 - ret = i915_gpu_state_copy_to_buffer(gpu, buf, off, count); 509 - i915_gpu_state_put(gpu); 508 + ret = i915_gpu_coredump_copy_to_buffer(gpu, buf, off, count); 509 + i915_gpu_coredump_put(gpu); 510 510 } else { 511 511 const char *str = "No error state collected\n"; 512 512 size_t len = strlen(str);
+16 -2
drivers/gpu/drm/i915/i915_vma.c
··· 423 423 void __iomem *ptr; 424 424 int err; 425 425 426 - /* Access through the GTT requires the device to be awake. */ 427 - assert_rpm_wakelock_held(vma->vm->gt->uncore->rpm); 428 426 if (GEM_WARN_ON(!i915_vma_is_map_and_fenceable(vma))) { 429 427 err = -ENODEV; 430 428 goto err; ··· 454 456 goto err_unpin; 455 457 456 458 i915_vma_set_ggtt_write(vma); 459 + 460 + /* NB Access through the GTT requires the device to be awake. */ 457 461 return ptr; 458 462 459 463 err_unpin: ··· 858 858 int i915_vma_pin(struct i915_vma *vma, u64 size, u64 alignment, u64 flags) 859 859 { 860 860 struct i915_vma_work *work = NULL; 861 + intel_wakeref_t wakeref = 0; 861 862 unsigned int bound; 862 863 int err; 863 864 ··· 883 882 goto err_pages; 884 883 } 885 884 } 885 + 886 + if (flags & PIN_GLOBAL) 887 + wakeref = intel_runtime_pm_get(&vma->vm->i915->runtime_pm); 886 888 887 889 /* No more allocations allowed once we hold vm->mutex */ 888 890 err = mutex_lock_interruptible(&vma->vm->mutex); ··· 950 946 err_fence: 951 947 if (work) 952 948 dma_fence_work_commit(&work->base); 949 + if (wakeref) 950 + intel_runtime_pm_put(&vma->vm->i915->runtime_pm, wakeref); 953 951 err_pages: 954 952 vma_put_pages(vma); 955 953 return err; ··· 1252 1246 int i915_vma_unbind(struct i915_vma *vma) 1253 1247 { 1254 1248 struct i915_address_space *vm = vma->vm; 1249 + intel_wakeref_t wakeref = 0; 1255 1250 int err; 1256 1251 1257 1252 if (!drm_mm_node_allocated(&vma->node)) 1258 1253 return 0; 1254 + 1255 + if (i915_vma_is_bound(vma, I915_VMA_GLOBAL_BIND)) 1256 + /* XXX not always required: nop_clear_range */ 1257 + wakeref = intel_runtime_pm_get(&vm->i915->runtime_pm); 1259 1258 1260 1259 err = mutex_lock_interruptible(&vm->mutex); 1261 1260 if (err) ··· 1268 1257 1269 1258 err = __i915_vma_unbind(vma); 1270 1259 mutex_unlock(&vm->mutex); 1260 + 1261 + if (wakeref) 1262 + intel_runtime_pm_put(&vm->i915->runtime_pm, wakeref); 1271 1263 1272 1264 return err; 1273 1265 }
+3 -137
drivers/gpu/drm/i915/i915_vma.h
··· 30 30 31 31 #include <drm/drm_mm.h> 32 32 33 + #include "gem/i915_gem_object.h" 34 + 33 35 #include "i915_gem_gtt.h" 34 36 #include "i915_gem_fence_reg.h" 35 - #include "gem/i915_gem_object.h" 36 37 37 38 #include "i915_active.h" 38 39 #include "i915_request.h" 39 - 40 - enum i915_cache_level; 41 - 42 - /** 43 - * DOC: Virtual Memory Address 44 - * 45 - * A VMA represents a GEM BO that is bound into an address space. Therefore, a 46 - * VMA's presence cannot be guaranteed before binding, or after unbinding the 47 - * object into/from the address space. 48 - * 49 - * To make things as simple as possible (ie. no refcounting), a VMA's lifetime 50 - * will always be <= an objects lifetime. So object refcounting should cover us. 51 - */ 52 - struct i915_vma { 53 - struct drm_mm_node node; 54 - 55 - struct i915_address_space *vm; 56 - const struct i915_vma_ops *ops; 57 - 58 - struct drm_i915_gem_object *obj; 59 - struct dma_resv *resv; /** Alias of obj->resv */ 60 - 61 - struct sg_table *pages; 62 - void __iomem *iomap; 63 - void *private; /* owned by creator */ 64 - 65 - struct i915_fence_reg *fence; 66 - 67 - u64 size; 68 - u64 display_alignment; 69 - struct i915_page_sizes page_sizes; 70 - 71 - /* mmap-offset associated with fencing for this vma */ 72 - struct i915_mmap_offset *mmo; 73 - 74 - u32 fence_size; 75 - u32 fence_alignment; 76 - 77 - /** 78 - * Count of the number of times this vma has been opened by different 79 - * handles (but same file) for execbuf, i.e. the number of aliases 80 - * that exist in the ctx->handle_vmas LUT for this vma. 81 - */ 82 - struct kref ref; 83 - atomic_t open_count; 84 - atomic_t flags; 85 - /** 86 - * How many users have pinned this object in GTT space. 87 - * 88 - * This is a tightly bound, fairly small number of users, so we 89 - * stuff inside the flags field so that we can both check for overflow 90 - * and detect a no-op i915_vma_pin() in a single check, while also 91 - * pinning the vma. 92 - * 93 - * The worst case display setup would have the same vma pinned for 94 - * use on each plane on each crtc, while also building the next atomic 95 - * state and holding a pin for the length of the cleanup queue. In the 96 - * future, the flip queue may be increased from 1. 97 - * Estimated worst case: 3 [qlen] * 4 [max crtcs] * 7 [max planes] = 84 98 - * 99 - * For GEM, the number of concurrent users for pwrite/pread is 100 - * unbounded. For execbuffer, it is currently one but will in future 101 - * be extended to allow multiple clients to pin vma concurrently. 102 - * 103 - * We also use suballocated pages, with each suballocation claiming 104 - * its own pin on the shared vma. At present, this is limited to 105 - * exclusive cachelines of a single page, so a maximum of 64 possible 106 - * users. 107 - */ 108 - #define I915_VMA_PIN_MASK 0x3ff 109 - #define I915_VMA_OVERFLOW 0x200 110 - 111 - /** Flags and address space this VMA is bound to */ 112 - #define I915_VMA_GLOBAL_BIND_BIT 10 113 - #define I915_VMA_LOCAL_BIND_BIT 11 114 - 115 - #define I915_VMA_GLOBAL_BIND ((int)BIT(I915_VMA_GLOBAL_BIND_BIT)) 116 - #define I915_VMA_LOCAL_BIND ((int)BIT(I915_VMA_LOCAL_BIND_BIT)) 117 - 118 - #define I915_VMA_BIND_MASK (I915_VMA_GLOBAL_BIND | I915_VMA_LOCAL_BIND) 119 - 120 - #define I915_VMA_ALLOC_BIT 12 121 - #define I915_VMA_ALLOC ((int)BIT(I915_VMA_ALLOC_BIT)) 122 - 123 - #define I915_VMA_ERROR_BIT 13 124 - #define I915_VMA_ERROR ((int)BIT(I915_VMA_ERROR_BIT)) 125 - 126 - #define I915_VMA_GGTT_BIT 14 127 - #define I915_VMA_CAN_FENCE_BIT 15 128 - #define I915_VMA_USERFAULT_BIT 16 129 - #define I915_VMA_GGTT_WRITE_BIT 17 130 - 131 - #define I915_VMA_GGTT ((int)BIT(I915_VMA_GGTT_BIT)) 132 - #define I915_VMA_CAN_FENCE ((int)BIT(I915_VMA_CAN_FENCE_BIT)) 133 - #define I915_VMA_USERFAULT ((int)BIT(I915_VMA_USERFAULT_BIT)) 134 - #define I915_VMA_GGTT_WRITE ((int)BIT(I915_VMA_GGTT_WRITE_BIT)) 135 - 136 - struct i915_active active; 137 - 138 - #define I915_VMA_PAGES_BIAS 24 139 - #define I915_VMA_PAGES_ACTIVE (BIT(24) | 1) 140 - atomic_t pages_count; /* number of active binds to the pages */ 141 - struct mutex pages_mutex; /* protect acquire/release of backing pages */ 142 - 143 - /** 144 - * Support different GGTT views into the same object. 145 - * This means there can be multiple VMA mappings per object and per VM. 146 - * i915_ggtt_view_type is used to distinguish between those entries. 147 - * The default one of zero (I915_GGTT_VIEW_NORMAL) is default and also 148 - * assumed in GEM functions which take no ggtt view parameter. 149 - */ 150 - struct i915_ggtt_view ggtt_view; 151 - 152 - /** This object's place on the active/inactive lists */ 153 - struct list_head vm_link; 154 - 155 - struct list_head obj_link; /* Link in the object's VMA list */ 156 - struct rb_node obj_node; 157 - struct hlist_node obj_hash; 158 - 159 - /** This vma's place in the execbuf reservation list */ 160 - struct list_head exec_link; 161 - struct list_head reloc_link; 162 - 163 - /** This vma's place in the eviction list */ 164 - struct list_head evict_link; 165 - 166 - struct list_head closed_link; 167 - 168 - /** 169 - * Used for performing relocations during execbuffer insertion. 170 - */ 171 - unsigned int *exec_flags; 172 - struct hlist_node exec_node; 173 - u32 exec_handle; 174 - }; 40 + #include "i915_vma_types.h" 175 41 176 42 struct i915_vma * 177 43 i915_vma_instance(struct drm_i915_gem_object *obj,
+294
drivers/gpu/drm/i915/i915_vma_types.h
··· 1 + /* SPDX-License-Identifier: MIT */ 2 + /* 3 + * Copyright © 2016 Intel Corporation 4 + * 5 + * Permission is hereby granted, free of charge, to any person obtaining a 6 + * copy of this software and associated documentation files (the "Software"), 7 + * to deal in the Software without restriction, including without limitation 8 + * the rights to use, copy, modify, merge, publish, distribute, sublicense, 9 + * and/or sell copies of the Software, and to permit persons to whom the 10 + * Software is furnished to do so, subject to the following conditions: 11 + * 12 + * The above copyright notice and this permission notice (including the next 13 + * paragraph) shall be included in all copies or substantial portions of the 14 + * Software. 15 + * 16 + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 19 + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21 + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 22 + * IN THE SOFTWARE. 23 + * 24 + */ 25 + 26 + #ifndef __I915_VMA_TYPES_H__ 27 + #define __I915_VMA_TYPES_H__ 28 + 29 + #include <linux/rbtree.h> 30 + 31 + #include <drm/drm_mm.h> 32 + 33 + #include "gem/i915_gem_object_types.h" 34 + 35 + enum i915_cache_level; 36 + 37 + /** 38 + * DOC: Global GTT views 39 + * 40 + * Background and previous state 41 + * 42 + * Historically objects could exists (be bound) in global GTT space only as 43 + * singular instances with a view representing all of the object's backing pages 44 + * in a linear fashion. This view will be called a normal view. 45 + * 46 + * To support multiple views of the same object, where the number of mapped 47 + * pages is not equal to the backing store, or where the layout of the pages 48 + * is not linear, concept of a GGTT view was added. 49 + * 50 + * One example of an alternative view is a stereo display driven by a single 51 + * image. In this case we would have a framebuffer looking like this 52 + * (2x2 pages): 53 + * 54 + * 12 55 + * 34 56 + * 57 + * Above would represent a normal GGTT view as normally mapped for GPU or CPU 58 + * rendering. In contrast, fed to the display engine would be an alternative 59 + * view which could look something like this: 60 + * 61 + * 1212 62 + * 3434 63 + * 64 + * In this example both the size and layout of pages in the alternative view is 65 + * different from the normal view. 66 + * 67 + * Implementation and usage 68 + * 69 + * GGTT views are implemented using VMAs and are distinguished via enum 70 + * i915_ggtt_view_type and struct i915_ggtt_view. 71 + * 72 + * A new flavour of core GEM functions which work with GGTT bound objects were 73 + * added with the _ggtt_ infix, and sometimes with _view postfix to avoid 74 + * renaming in large amounts of code. They take the struct i915_ggtt_view 75 + * parameter encapsulating all metadata required to implement a view. 76 + * 77 + * As a helper for callers which are only interested in the normal view, 78 + * globally const i915_ggtt_view_normal singleton instance exists. All old core 79 + * GEM API functions, the ones not taking the view parameter, are operating on, 80 + * or with the normal GGTT view. 81 + * 82 + * Code wanting to add or use a new GGTT view needs to: 83 + * 84 + * 1. Add a new enum with a suitable name. 85 + * 2. Extend the metadata in the i915_ggtt_view structure if required. 86 + * 3. Add support to i915_get_vma_pages(). 87 + * 88 + * New views are required to build a scatter-gather table from within the 89 + * i915_get_vma_pages function. This table is stored in the vma.ggtt_view and 90 + * exists for the lifetime of an VMA. 91 + * 92 + * Core API is designed to have copy semantics which means that passed in 93 + * struct i915_ggtt_view does not need to be persistent (left around after 94 + * calling the core API functions). 95 + * 96 + */ 97 + 98 + struct intel_remapped_plane_info { 99 + /* in gtt pages */ 100 + unsigned int width, height, stride, offset; 101 + } __packed; 102 + 103 + struct intel_remapped_info { 104 + struct intel_remapped_plane_info plane[2]; 105 + unsigned int unused_mbz; 106 + } __packed; 107 + 108 + struct intel_rotation_info { 109 + struct intel_remapped_plane_info plane[2]; 110 + } __packed; 111 + 112 + struct intel_partial_info { 113 + u64 offset; 114 + unsigned int size; 115 + } __packed; 116 + 117 + enum i915_ggtt_view_type { 118 + I915_GGTT_VIEW_NORMAL = 0, 119 + I915_GGTT_VIEW_ROTATED = sizeof(struct intel_rotation_info), 120 + I915_GGTT_VIEW_PARTIAL = sizeof(struct intel_partial_info), 121 + I915_GGTT_VIEW_REMAPPED = sizeof(struct intel_remapped_info), 122 + }; 123 + 124 + static inline void assert_i915_gem_gtt_types(void) 125 + { 126 + BUILD_BUG_ON(sizeof(struct intel_rotation_info) != 8*sizeof(unsigned int)); 127 + BUILD_BUG_ON(sizeof(struct intel_partial_info) != sizeof(u64) + sizeof(unsigned int)); 128 + BUILD_BUG_ON(sizeof(struct intel_remapped_info) != 9*sizeof(unsigned int)); 129 + 130 + /* Check that rotation/remapped shares offsets for simplicity */ 131 + BUILD_BUG_ON(offsetof(struct intel_remapped_info, plane[0]) != 132 + offsetof(struct intel_rotation_info, plane[0])); 133 + BUILD_BUG_ON(offsetofend(struct intel_remapped_info, plane[1]) != 134 + offsetofend(struct intel_rotation_info, plane[1])); 135 + 136 + /* As we encode the size of each branch inside the union into its type, 137 + * we have to be careful that each branch has a unique size. 138 + */ 139 + switch ((enum i915_ggtt_view_type)0) { 140 + case I915_GGTT_VIEW_NORMAL: 141 + case I915_GGTT_VIEW_PARTIAL: 142 + case I915_GGTT_VIEW_ROTATED: 143 + case I915_GGTT_VIEW_REMAPPED: 144 + /* gcc complains if these are identical cases */ 145 + break; 146 + } 147 + } 148 + 149 + struct i915_ggtt_view { 150 + enum i915_ggtt_view_type type; 151 + union { 152 + /* Members need to contain no holes/padding */ 153 + struct intel_partial_info partial; 154 + struct intel_rotation_info rotated; 155 + struct intel_remapped_info remapped; 156 + }; 157 + }; 158 + 159 + /** 160 + * DOC: Virtual Memory Address 161 + * 162 + * A VMA represents a GEM BO that is bound into an address space. Therefore, a 163 + * VMA's presence cannot be guaranteed before binding, or after unbinding the 164 + * object into/from the address space. 165 + * 166 + * To make things as simple as possible (ie. no refcounting), a VMA's lifetime 167 + * will always be <= an objects lifetime. So object refcounting should cover us. 168 + */ 169 + struct i915_vma { 170 + struct drm_mm_node node; 171 + 172 + struct i915_address_space *vm; 173 + const struct i915_vma_ops *ops; 174 + 175 + struct drm_i915_gem_object *obj; 176 + struct dma_resv *resv; /** Alias of obj->resv */ 177 + 178 + struct sg_table *pages; 179 + void __iomem *iomap; 180 + void *private; /* owned by creator */ 181 + 182 + struct i915_fence_reg *fence; 183 + 184 + u64 size; 185 + u64 display_alignment; 186 + struct i915_page_sizes page_sizes; 187 + 188 + /* mmap-offset associated with fencing for this vma */ 189 + struct i915_mmap_offset *mmo; 190 + 191 + u32 fence_size; 192 + u32 fence_alignment; 193 + 194 + /** 195 + * Count of the number of times this vma has been opened by different 196 + * handles (but same file) for execbuf, i.e. the number of aliases 197 + * that exist in the ctx->handle_vmas LUT for this vma. 198 + */ 199 + struct kref ref; 200 + atomic_t open_count; 201 + atomic_t flags; 202 + /** 203 + * How many users have pinned this object in GTT space. 204 + * 205 + * This is a tightly bound, fairly small number of users, so we 206 + * stuff inside the flags field so that we can both check for overflow 207 + * and detect a no-op i915_vma_pin() in a single check, while also 208 + * pinning the vma. 209 + * 210 + * The worst case display setup would have the same vma pinned for 211 + * use on each plane on each crtc, while also building the next atomic 212 + * state and holding a pin for the length of the cleanup queue. In the 213 + * future, the flip queue may be increased from 1. 214 + * Estimated worst case: 3 [qlen] * 4 [max crtcs] * 7 [max planes] = 84 215 + * 216 + * For GEM, the number of concurrent users for pwrite/pread is 217 + * unbounded. For execbuffer, it is currently one but will in future 218 + * be extended to allow multiple clients to pin vma concurrently. 219 + * 220 + * We also use suballocated pages, with each suballocation claiming 221 + * its own pin on the shared vma. At present, this is limited to 222 + * exclusive cachelines of a single page, so a maximum of 64 possible 223 + * users. 224 + */ 225 + #define I915_VMA_PIN_MASK 0x3ff 226 + #define I915_VMA_OVERFLOW 0x200 227 + 228 + /** Flags and address space this VMA is bound to */ 229 + #define I915_VMA_GLOBAL_BIND_BIT 10 230 + #define I915_VMA_LOCAL_BIND_BIT 11 231 + 232 + #define I915_VMA_GLOBAL_BIND ((int)BIT(I915_VMA_GLOBAL_BIND_BIT)) 233 + #define I915_VMA_LOCAL_BIND ((int)BIT(I915_VMA_LOCAL_BIND_BIT)) 234 + 235 + #define I915_VMA_BIND_MASK (I915_VMA_GLOBAL_BIND | I915_VMA_LOCAL_BIND) 236 + 237 + #define I915_VMA_ALLOC_BIT 12 238 + #define I915_VMA_ALLOC ((int)BIT(I915_VMA_ALLOC_BIT)) 239 + 240 + #define I915_VMA_ERROR_BIT 13 241 + #define I915_VMA_ERROR ((int)BIT(I915_VMA_ERROR_BIT)) 242 + 243 + #define I915_VMA_GGTT_BIT 14 244 + #define I915_VMA_CAN_FENCE_BIT 15 245 + #define I915_VMA_USERFAULT_BIT 16 246 + #define I915_VMA_GGTT_WRITE_BIT 17 247 + 248 + #define I915_VMA_GGTT ((int)BIT(I915_VMA_GGTT_BIT)) 249 + #define I915_VMA_CAN_FENCE ((int)BIT(I915_VMA_CAN_FENCE_BIT)) 250 + #define I915_VMA_USERFAULT ((int)BIT(I915_VMA_USERFAULT_BIT)) 251 + #define I915_VMA_GGTT_WRITE ((int)BIT(I915_VMA_GGTT_WRITE_BIT)) 252 + 253 + struct i915_active active; 254 + 255 + #define I915_VMA_PAGES_BIAS 24 256 + #define I915_VMA_PAGES_ACTIVE (BIT(24) | 1) 257 + atomic_t pages_count; /* number of active binds to the pages */ 258 + struct mutex pages_mutex; /* protect acquire/release of backing pages */ 259 + 260 + /** 261 + * Support different GGTT views into the same object. 262 + * This means there can be multiple VMA mappings per object and per VM. 263 + * i915_ggtt_view_type is used to distinguish between those entries. 264 + * The default one of zero (I915_GGTT_VIEW_NORMAL) is default and also 265 + * assumed in GEM functions which take no ggtt view parameter. 266 + */ 267 + struct i915_ggtt_view ggtt_view; 268 + 269 + /** This object's place on the active/inactive lists */ 270 + struct list_head vm_link; 271 + 272 + struct list_head obj_link; /* Link in the object's VMA list */ 273 + struct rb_node obj_node; 274 + struct hlist_node obj_hash; 275 + 276 + /** This vma's place in the execbuf reservation list */ 277 + struct list_head exec_link; 278 + struct list_head reloc_link; 279 + 280 + /** This vma's place in the eviction list */ 281 + struct list_head evict_link; 282 + 283 + struct list_head closed_link; 284 + 285 + /** 286 + * Used for performing relocations during execbuffer insertion. 287 + */ 288 + unsigned int *exec_flags; 289 + struct hlist_node exec_node; 290 + u32 exec_handle; 291 + }; 292 + 293 + #endif 294 +
+5 -5
drivers/gpu/drm/i915/intel_device_info.c
··· 519 519 } 520 520 } 521 521 522 - static void broadwell_sseu_info_init(struct drm_i915_private *dev_priv) 522 + static void bdw_sseu_info_init(struct drm_i915_private *dev_priv) 523 523 { 524 524 struct sseu_dev_info *sseu = &RUNTIME_INFO(dev_priv)->sseu; 525 525 int s, ss; ··· 600 600 sseu->has_eu_pg = 0; 601 601 } 602 602 603 - static void haswell_sseu_info_init(struct drm_i915_private *dev_priv) 603 + static void hsw_sseu_info_init(struct drm_i915_private *dev_priv) 604 604 { 605 605 struct sseu_dev_info *sseu = &RUNTIME_INFO(dev_priv)->sseu; 606 606 u32 fuse1; ··· 1021 1021 1022 1022 /* Initialize slice/subslice/EU info */ 1023 1023 if (IS_HASWELL(dev_priv)) 1024 - haswell_sseu_info_init(dev_priv); 1024 + hsw_sseu_info_init(dev_priv); 1025 1025 else if (IS_CHERRYVIEW(dev_priv)) 1026 1026 cherryview_sseu_info_init(dev_priv); 1027 1027 else if (IS_BROADWELL(dev_priv)) 1028 - broadwell_sseu_info_init(dev_priv); 1028 + bdw_sseu_info_init(dev_priv); 1029 1029 else if (IS_GEN(dev_priv, 9)) 1030 1030 gen9_sseu_info_init(dev_priv); 1031 1031 else if (IS_GEN(dev_priv, 10)) ··· 1093 1093 * hooked up to an SFC (Scaler & Format Converter) unit. 1094 1094 * In TGL each VDBOX has access to an SFC. 1095 1095 */ 1096 - if (IS_TIGERLAKE(dev_priv) || logical_vdbox++ % 2 == 0) 1096 + if (INTEL_GEN(dev_priv) >= 12 || logical_vdbox++ % 2 == 0) 1097 1097 RUNTIME_INFO(dev_priv)->vdbox_sfc_access |= BIT(i); 1098 1098 } 1099 1099 DRM_DEBUG_DRIVER("vdbox enable: %04x, instances: %04lx\n",
+28 -1
drivers/gpu/drm/i915/intel_memory_region.c
··· 16 16 [INTEL_REGION_STOLEN] = REGION_MAP(INTEL_MEMORY_STOLEN, 0), 17 17 }; 18 18 19 + struct intel_memory_region * 20 + intel_memory_region_by_type(struct drm_i915_private *i915, 21 + enum intel_memory_type mem_type) 22 + { 23 + struct intel_memory_region *mr; 24 + int id; 25 + 26 + for_each_memory_region(mr, i915, id) 27 + if (mr->type == mem_type) 28 + return mr; 29 + 30 + return NULL; 31 + } 32 + 19 33 static u64 20 34 intel_memory_region_free_pages(struct intel_memory_region *mem, 21 35 struct list_head *blocks) ··· 51 37 struct list_head *blocks) 52 38 { 53 39 mutex_lock(&mem->mm_lock); 54 - intel_memory_region_free_pages(mem, blocks); 40 + mem->avail += intel_memory_region_free_pages(mem, blocks); 55 41 mutex_unlock(&mem->mm_lock); 56 42 } 57 43 ··· 120 106 break; 121 107 } while (1); 122 108 109 + mem->avail -= size; 123 110 mutex_unlock(&mem->mm_lock); 124 111 return 0; 125 112 ··· 179 164 mem->io_start = io_start; 180 165 mem->min_page_size = min_page_size; 181 166 mem->ops = ops; 167 + mem->total = size; 168 + mem->avail = mem->total; 182 169 183 170 mutex_init(&mem->objects.lock); 184 171 INIT_LIST_HEAD(&mem->objects.list); ··· 200 183 err_free: 201 184 kfree(mem); 202 185 return ERR_PTR(err); 186 + } 187 + 188 + void intel_memory_region_set_name(struct intel_memory_region *mem, 189 + const char *fmt, ...) 190 + { 191 + va_list ap; 192 + 193 + va_start(ap, fmt); 194 + vsnprintf(mem->name, sizeof(mem->name), fmt, ap); 195 + va_end(ap); 203 196 } 204 197 205 198 static void __intel_memory_region_destroy(struct kref *kref)
+14
drivers/gpu/drm/i915/intel_memory_region.h
··· 47 47 #define I915_ALLOC_MIN_PAGE_SIZE BIT(0) 48 48 #define I915_ALLOC_CONTIGUOUS BIT(1) 49 49 50 + #define for_each_memory_region(mr, i915, id) \ 51 + for (id = 0; id < ARRAY_SIZE((i915)->mm.regions); id++) \ 52 + for_each_if((mr) = (i915)->mm.regions[id]) 53 + 50 54 /** 51 55 * Memory regions encoded as type | instance 52 56 */ ··· 86 82 87 83 resource_size_t io_start; 88 84 resource_size_t min_page_size; 85 + resource_size_t total; 86 + resource_size_t avail; 89 87 90 88 unsigned int type; 91 89 unsigned int instance; 92 90 unsigned int id; 91 + char name[8]; 93 92 94 93 dma_addr_t remap_addr; 95 94 ··· 132 125 133 126 int intel_memory_regions_hw_probe(struct drm_i915_private *i915); 134 127 void intel_memory_regions_driver_release(struct drm_i915_private *i915); 128 + struct intel_memory_region * 129 + intel_memory_region_by_type(struct drm_i915_private *i915, 130 + enum intel_memory_type mem_type); 131 + 132 + __printf(2, 3) void 133 + intel_memory_region_set_name(struct intel_memory_region *mem, 134 + const char *fmt, ...); 135 135 136 136 #endif
+24 -22
drivers/gpu/drm/i915/intel_pch.c
··· 12 12 { 13 13 switch (id) { 14 14 case INTEL_PCH_IBX_DEVICE_ID_TYPE: 15 - DRM_DEBUG_KMS("Found Ibex Peak PCH\n"); 15 + drm_dbg_kms(&dev_priv->drm, "Found Ibex Peak PCH\n"); 16 16 WARN_ON(!IS_GEN(dev_priv, 5)); 17 17 return PCH_IBX; 18 18 case INTEL_PCH_CPT_DEVICE_ID_TYPE: 19 - DRM_DEBUG_KMS("Found CougarPoint PCH\n"); 19 + drm_dbg_kms(&dev_priv->drm, "Found CougarPoint PCH\n"); 20 20 WARN_ON(!IS_GEN(dev_priv, 6) && !IS_IVYBRIDGE(dev_priv)); 21 21 return PCH_CPT; 22 22 case INTEL_PCH_PPT_DEVICE_ID_TYPE: 23 - DRM_DEBUG_KMS("Found PantherPoint PCH\n"); 23 + drm_dbg_kms(&dev_priv->drm, "Found PantherPoint PCH\n"); 24 24 WARN_ON(!IS_GEN(dev_priv, 6) && !IS_IVYBRIDGE(dev_priv)); 25 25 /* PantherPoint is CPT compatible */ 26 26 return PCH_CPT; 27 27 case INTEL_PCH_LPT_DEVICE_ID_TYPE: 28 - DRM_DEBUG_KMS("Found LynxPoint PCH\n"); 28 + drm_dbg_kms(&dev_priv->drm, "Found LynxPoint PCH\n"); 29 29 WARN_ON(!IS_HASWELL(dev_priv) && !IS_BROADWELL(dev_priv)); 30 30 WARN_ON(IS_HSW_ULT(dev_priv) || IS_BDW_ULT(dev_priv)); 31 31 return PCH_LPT; 32 32 case INTEL_PCH_LPT_LP_DEVICE_ID_TYPE: 33 - DRM_DEBUG_KMS("Found LynxPoint LP PCH\n"); 33 + drm_dbg_kms(&dev_priv->drm, "Found LynxPoint LP PCH\n"); 34 34 WARN_ON(!IS_HASWELL(dev_priv) && !IS_BROADWELL(dev_priv)); 35 35 WARN_ON(!IS_HSW_ULT(dev_priv) && !IS_BDW_ULT(dev_priv)); 36 36 return PCH_LPT; 37 37 case INTEL_PCH_WPT_DEVICE_ID_TYPE: 38 - DRM_DEBUG_KMS("Found WildcatPoint PCH\n"); 38 + drm_dbg_kms(&dev_priv->drm, "Found WildcatPoint PCH\n"); 39 39 WARN_ON(!IS_HASWELL(dev_priv) && !IS_BROADWELL(dev_priv)); 40 40 WARN_ON(IS_HSW_ULT(dev_priv) || IS_BDW_ULT(dev_priv)); 41 41 /* WildcatPoint is LPT compatible */ 42 42 return PCH_LPT; 43 43 case INTEL_PCH_WPT_LP_DEVICE_ID_TYPE: 44 - DRM_DEBUG_KMS("Found WildcatPoint LP PCH\n"); 44 + drm_dbg_kms(&dev_priv->drm, "Found WildcatPoint LP PCH\n"); 45 45 WARN_ON(!IS_HASWELL(dev_priv) && !IS_BROADWELL(dev_priv)); 46 46 WARN_ON(!IS_HSW_ULT(dev_priv) && !IS_BDW_ULT(dev_priv)); 47 47 /* WildcatPoint is LPT compatible */ 48 48 return PCH_LPT; 49 49 case INTEL_PCH_SPT_DEVICE_ID_TYPE: 50 - DRM_DEBUG_KMS("Found SunrisePoint PCH\n"); 50 + drm_dbg_kms(&dev_priv->drm, "Found SunrisePoint PCH\n"); 51 51 WARN_ON(!IS_SKYLAKE(dev_priv) && !IS_KABYLAKE(dev_priv)); 52 52 return PCH_SPT; 53 53 case INTEL_PCH_SPT_LP_DEVICE_ID_TYPE: 54 - DRM_DEBUG_KMS("Found SunrisePoint LP PCH\n"); 54 + drm_dbg_kms(&dev_priv->drm, "Found SunrisePoint LP PCH\n"); 55 55 WARN_ON(!IS_SKYLAKE(dev_priv) && !IS_KABYLAKE(dev_priv) && 56 56 !IS_COFFEELAKE(dev_priv)); 57 57 return PCH_SPT; 58 58 case INTEL_PCH_KBP_DEVICE_ID_TYPE: 59 - DRM_DEBUG_KMS("Found Kaby Lake PCH (KBP)\n"); 59 + drm_dbg_kms(&dev_priv->drm, "Found Kaby Lake PCH (KBP)\n"); 60 60 WARN_ON(!IS_SKYLAKE(dev_priv) && !IS_KABYLAKE(dev_priv) && 61 61 !IS_COFFEELAKE(dev_priv)); 62 62 /* KBP is SPT compatible */ 63 63 return PCH_SPT; 64 64 case INTEL_PCH_CNP_DEVICE_ID_TYPE: 65 - DRM_DEBUG_KMS("Found Cannon Lake PCH (CNP)\n"); 65 + drm_dbg_kms(&dev_priv->drm, "Found Cannon Lake PCH (CNP)\n"); 66 66 WARN_ON(!IS_CANNONLAKE(dev_priv) && !IS_COFFEELAKE(dev_priv)); 67 67 return PCH_CNP; 68 68 case INTEL_PCH_CNP_LP_DEVICE_ID_TYPE: 69 - DRM_DEBUG_KMS("Found Cannon Lake LP PCH (CNP-LP)\n"); 69 + drm_dbg_kms(&dev_priv->drm, 70 + "Found Cannon Lake LP PCH (CNP-LP)\n"); 70 71 WARN_ON(!IS_CANNONLAKE(dev_priv) && !IS_COFFEELAKE(dev_priv)); 71 72 return PCH_CNP; 72 73 case INTEL_PCH_CMP_DEVICE_ID_TYPE: 73 74 case INTEL_PCH_CMP2_DEVICE_ID_TYPE: 74 - DRM_DEBUG_KMS("Found Comet Lake PCH (CMP)\n"); 75 + drm_dbg_kms(&dev_priv->drm, "Found Comet Lake PCH (CMP)\n"); 75 76 WARN_ON(!IS_COFFEELAKE(dev_priv)); 76 77 /* CometPoint is CNP Compatible */ 77 78 return PCH_CNP; 78 79 case INTEL_PCH_CMP_V_DEVICE_ID_TYPE: 79 - DRM_DEBUG_KMS("Found Comet Lake V PCH (CMP-V)\n"); 80 + drm_dbg_kms(&dev_priv->drm, "Found Comet Lake V PCH (CMP-V)\n"); 80 81 WARN_ON(!IS_COFFEELAKE(dev_priv)); 81 82 /* Comet Lake V PCH is based on KBP, which is SPT compatible */ 82 83 return PCH_SPT; 83 84 case INTEL_PCH_ICP_DEVICE_ID_TYPE: 84 - DRM_DEBUG_KMS("Found Ice Lake PCH\n"); 85 + drm_dbg_kms(&dev_priv->drm, "Found Ice Lake PCH\n"); 85 86 WARN_ON(!IS_ICELAKE(dev_priv)); 86 87 return PCH_ICP; 87 88 case INTEL_PCH_MCC_DEVICE_ID_TYPE: 88 - DRM_DEBUG_KMS("Found Mule Creek Canyon PCH\n"); 89 + drm_dbg_kms(&dev_priv->drm, "Found Mule Creek Canyon PCH\n"); 89 90 WARN_ON(!IS_ELKHARTLAKE(dev_priv)); 90 91 return PCH_MCC; 91 92 case INTEL_PCH_TGP_DEVICE_ID_TYPE: 92 93 case INTEL_PCH_TGP2_DEVICE_ID_TYPE: 93 - DRM_DEBUG_KMS("Found Tiger Lake LP PCH\n"); 94 + drm_dbg_kms(&dev_priv->drm, "Found Tiger Lake LP PCH\n"); 94 95 WARN_ON(!IS_TIGERLAKE(dev_priv)); 95 96 return PCH_TGP; 96 97 case INTEL_PCH_JSP_DEVICE_ID_TYPE: 97 98 case INTEL_PCH_JSP2_DEVICE_ID_TYPE: 98 - DRM_DEBUG_KMS("Found Jasper Lake PCH\n"); 99 + drm_dbg_kms(&dev_priv->drm, "Found Jasper Lake PCH\n"); 99 100 WARN_ON(!IS_ELKHARTLAKE(dev_priv)); 100 101 return PCH_JSP; 101 102 default: ··· 146 145 id = INTEL_PCH_IBX_DEVICE_ID_TYPE; 147 146 148 147 if (id) 149 - DRM_DEBUG_KMS("Assuming PCH ID %04x\n", id); 148 + drm_dbg_kms(&dev_priv->drm, "Assuming PCH ID %04x\n", id); 150 149 else 151 - DRM_DEBUG_KMS("Assuming no PCH\n"); 150 + drm_dbg_kms(&dev_priv->drm, "Assuming no PCH\n"); 152 151 153 152 return id; 154 153 } ··· 202 201 * display. 203 202 */ 204 203 if (pch && !HAS_DISPLAY(dev_priv)) { 205 - DRM_DEBUG_KMS("Display disabled, reverting to NOP PCH\n"); 204 + drm_dbg_kms(&dev_priv->drm, 205 + "Display disabled, reverting to NOP PCH\n"); 206 206 dev_priv->pch_type = PCH_NOP; 207 207 dev_priv->pch_id = 0; 208 208 } 209 209 210 210 if (!pch) 211 - DRM_DEBUG_KMS("No PCH found.\n"); 211 + drm_dbg_kms(&dev_priv->drm, "No PCH found.\n"); 212 212 213 213 pci_dev_put(pch); 214 214 }
+232 -171
drivers/gpu/drm/i915/intel_pm.c
··· 140 140 141 141 } 142 142 143 - static void i915_pineview_get_mem_freq(struct drm_i915_private *dev_priv) 143 + static void pnv_get_mem_freq(struct drm_i915_private *dev_priv) 144 144 { 145 145 u32 tmp; 146 146 ··· 178 178 dev_priv->is_ddr3 = (tmp & CSHRDDR3CTL_DDR3) ? 1 : 0; 179 179 } 180 180 181 - static void i915_ironlake_get_mem_freq(struct drm_i915_private *dev_priv) 181 + static void ilk_get_mem_freq(struct drm_i915_private *dev_priv) 182 182 { 183 183 u16 ddrpll, csipll; 184 184 ··· 199 199 dev_priv->mem_freq = 1600; 200 200 break; 201 201 default: 202 - DRM_DEBUG_DRIVER("unknown memory frequency 0x%02x\n", 203 - ddrpll & 0xff); 202 + drm_dbg(&dev_priv->drm, "unknown memory frequency 0x%02x\n", 203 + ddrpll & 0xff); 204 204 dev_priv->mem_freq = 0; 205 205 break; 206 206 } ··· 228 228 dev_priv->fsb_freq = 6400; 229 229 break; 230 230 default: 231 - DRM_DEBUG_DRIVER("unknown fsb frequency 0x%04x\n", 232 - csipll & 0x3ff); 231 + drm_dbg(&dev_priv->drm, "unknown fsb frequency 0x%04x\n", 232 + csipll & 0x3ff); 233 233 dev_priv->fsb_freq = 0; 234 234 break; 235 235 } ··· 314 314 315 315 if (wait_for((vlv_punit_read(dev_priv, PUNIT_REG_DDR_SETUP2) & 316 316 FORCE_DDR_FREQ_REQ_ACK) == 0, 3)) 317 - DRM_ERROR("timed out waiting for Punit DDR DVFS request\n"); 317 + drm_err(&dev_priv->drm, 318 + "timed out waiting for Punit DDR DVFS request\n"); 318 319 319 320 vlv_punit_put(dev_priv); 320 321 } ··· 384 383 385 384 trace_intel_memory_cxsr(dev_priv, was_enabled, enable); 386 385 387 - DRM_DEBUG_KMS("memory self-refresh is %s (was %s)\n", 388 - enableddisabled(enable), 389 - enableddisabled(was_enabled)); 386 + drm_dbg_kms(&dev_priv->drm, "memory self-refresh is %s (was %s)\n", 387 + enableddisabled(enable), 388 + enableddisabled(was_enabled)); 390 389 391 390 return was_enabled; 392 391 } ··· 511 510 if (i9xx_plane == PLANE_B) 512 511 size = ((dsparb >> DSPARB_CSTART_SHIFT) & 0x7f) - size; 513 512 514 - DRM_DEBUG_KMS("FIFO size - (0x%08x) %c: %d\n", 515 - dsparb, plane_name(i9xx_plane), size); 513 + drm_dbg_kms(&dev_priv->drm, "FIFO size - (0x%08x) %c: %d\n", 514 + dsparb, plane_name(i9xx_plane), size); 516 515 517 516 return size; 518 517 } ··· 528 527 size = ((dsparb >> DSPARB_BEND_SHIFT) & 0x1ff) - size; 529 528 size >>= 1; /* Convert to cachelines */ 530 529 531 - DRM_DEBUG_KMS("FIFO size - (0x%08x) %c: %d\n", 532 - dsparb, plane_name(i9xx_plane), size); 530 + drm_dbg_kms(&dev_priv->drm, "FIFO size - (0x%08x) %c: %d\n", 531 + dsparb, plane_name(i9xx_plane), size); 533 532 534 533 return size; 535 534 } ··· 543 542 size = dsparb & 0x7f; 544 543 size >>= 2; /* Convert to cachelines */ 545 544 546 - DRM_DEBUG_KMS("FIFO size - (0x%08x) %c: %d\n", 547 - dsparb, plane_name(i9xx_plane), size); 545 + drm_dbg_kms(&dev_priv->drm, "FIFO size - (0x%08x) %c: %d\n", 546 + dsparb, plane_name(i9xx_plane), size); 548 547 549 548 return size; 550 549 } 551 550 552 551 /* Pineview has different values for various configs */ 553 - static const struct intel_watermark_params pineview_display_wm = { 552 + static const struct intel_watermark_params pnv_display_wm = { 554 553 .fifo_size = PINEVIEW_DISPLAY_FIFO, 555 554 .max_wm = PINEVIEW_MAX_WM, 556 555 .default_wm = PINEVIEW_DFT_WM, 557 556 .guard_size = PINEVIEW_GUARD_WM, 558 557 .cacheline_size = PINEVIEW_FIFO_LINE_SIZE, 559 558 }; 560 - static const struct intel_watermark_params pineview_display_hplloff_wm = { 559 + 560 + static const struct intel_watermark_params pnv_display_hplloff_wm = { 561 561 .fifo_size = PINEVIEW_DISPLAY_FIFO, 562 562 .max_wm = PINEVIEW_MAX_WM, 563 563 .default_wm = PINEVIEW_DFT_HPLLOFF_WM, 564 564 .guard_size = PINEVIEW_GUARD_WM, 565 565 .cacheline_size = PINEVIEW_FIFO_LINE_SIZE, 566 566 }; 567 - static const struct intel_watermark_params pineview_cursor_wm = { 567 + 568 + static const struct intel_watermark_params pnv_cursor_wm = { 568 569 .fifo_size = PINEVIEW_CURSOR_FIFO, 569 570 .max_wm = PINEVIEW_CURSOR_MAX_WM, 570 571 .default_wm = PINEVIEW_CURSOR_DFT_WM, 571 572 .guard_size = PINEVIEW_CURSOR_GUARD_WM, 572 573 .cacheline_size = PINEVIEW_FIFO_LINE_SIZE, 573 574 }; 574 - static const struct intel_watermark_params pineview_cursor_hplloff_wm = { 575 + 576 + static const struct intel_watermark_params pnv_cursor_hplloff_wm = { 575 577 .fifo_size = PINEVIEW_CURSOR_FIFO, 576 578 .max_wm = PINEVIEW_CURSOR_MAX_WM, 577 579 .default_wm = PINEVIEW_CURSOR_DFT_WM, 578 580 .guard_size = PINEVIEW_CURSOR_GUARD_WM, 579 581 .cacheline_size = PINEVIEW_FIFO_LINE_SIZE, 580 582 }; 583 + 581 584 static const struct intel_watermark_params i965_cursor_wm_info = { 582 585 .fifo_size = I965_CURSOR_FIFO, 583 586 .max_wm = I965_CURSOR_MAX_WM, ··· 589 584 .guard_size = 2, 590 585 .cacheline_size = I915_FIFO_LINE_SIZE, 591 586 }; 587 + 592 588 static const struct intel_watermark_params i945_wm_info = { 593 589 .fifo_size = I945_FIFO_SIZE, 594 590 .max_wm = I915_MAX_WM, ··· 597 591 .guard_size = 2, 598 592 .cacheline_size = I915_FIFO_LINE_SIZE, 599 593 }; 594 + 600 595 static const struct intel_watermark_params i915_wm_info = { 601 596 .fifo_size = I915_FIFO_SIZE, 602 597 .max_wm = I915_MAX_WM, ··· 605 598 .guard_size = 2, 606 599 .cacheline_size = I915_FIFO_LINE_SIZE, 607 600 }; 601 + 608 602 static const struct intel_watermark_params i830_a_wm_info = { 609 603 .fifo_size = I855GM_FIFO_SIZE, 610 604 .max_wm = I915_MAX_WM, ··· 613 605 .guard_size = 2, 614 606 .cacheline_size = I830_FIFO_LINE_SIZE, 615 607 }; 608 + 616 609 static const struct intel_watermark_params i830_bc_wm_info = { 617 610 .fifo_size = I855GM_FIFO_SIZE, 618 611 .max_wm = I915_MAX_WM/2, ··· 621 612 .guard_size = 2, 622 613 .cacheline_size = I830_FIFO_LINE_SIZE, 623 614 }; 615 + 624 616 static const struct intel_watermark_params i845_wm_info = { 625 617 .fifo_size = I830_FIFO_SIZE, 626 618 .max_wm = I915_MAX_WM, ··· 858 848 return enabled; 859 849 } 860 850 861 - static void pineview_update_wm(struct intel_crtc *unused_crtc) 851 + static void pnv_update_wm(struct intel_crtc *unused_crtc) 862 852 { 863 853 struct drm_i915_private *dev_priv = to_i915(unused_crtc->base.dev); 864 854 struct intel_crtc *crtc; ··· 871 861 dev_priv->fsb_freq, 872 862 dev_priv->mem_freq); 873 863 if (!latency) { 874 - DRM_DEBUG_KMS("Unknown FSB/MEM found, disable CxSR\n"); 864 + drm_dbg_kms(&dev_priv->drm, 865 + "Unknown FSB/MEM found, disable CxSR\n"); 875 866 intel_set_memory_cxsr(dev_priv, false); 876 867 return; 877 868 } ··· 887 876 int clock = adjusted_mode->crtc_clock; 888 877 889 878 /* Display SR */ 890 - wm = intel_calculate_wm(clock, &pineview_display_wm, 891 - pineview_display_wm.fifo_size, 879 + wm = intel_calculate_wm(clock, &pnv_display_wm, 880 + pnv_display_wm.fifo_size, 892 881 cpp, latency->display_sr); 893 882 reg = I915_READ(DSPFW1); 894 883 reg &= ~DSPFW_SR_MASK; 895 884 reg |= FW_WM(wm, SR); 896 885 I915_WRITE(DSPFW1, reg); 897 - DRM_DEBUG_KMS("DSPFW1 register is %x\n", reg); 886 + drm_dbg_kms(&dev_priv->drm, "DSPFW1 register is %x\n", reg); 898 887 899 888 /* cursor SR */ 900 - wm = intel_calculate_wm(clock, &pineview_cursor_wm, 901 - pineview_display_wm.fifo_size, 889 + wm = intel_calculate_wm(clock, &pnv_cursor_wm, 890 + pnv_display_wm.fifo_size, 902 891 4, latency->cursor_sr); 903 892 reg = I915_READ(DSPFW3); 904 893 reg &= ~DSPFW_CURSOR_SR_MASK; ··· 906 895 I915_WRITE(DSPFW3, reg); 907 896 908 897 /* Display HPLL off SR */ 909 - wm = intel_calculate_wm(clock, &pineview_display_hplloff_wm, 910 - pineview_display_hplloff_wm.fifo_size, 898 + wm = intel_calculate_wm(clock, &pnv_display_hplloff_wm, 899 + pnv_display_hplloff_wm.fifo_size, 911 900 cpp, latency->display_hpll_disable); 912 901 reg = I915_READ(DSPFW3); 913 902 reg &= ~DSPFW_HPLL_SR_MASK; ··· 915 904 I915_WRITE(DSPFW3, reg); 916 905 917 906 /* cursor HPLL off SR */ 918 - wm = intel_calculate_wm(clock, &pineview_cursor_hplloff_wm, 919 - pineview_display_hplloff_wm.fifo_size, 907 + wm = intel_calculate_wm(clock, &pnv_cursor_hplloff_wm, 908 + pnv_display_hplloff_wm.fifo_size, 920 909 4, latency->cursor_hpll_disable); 921 910 reg = I915_READ(DSPFW3); 922 911 reg &= ~DSPFW_HPLL_CURSOR_MASK; 923 912 reg |= FW_WM(wm, HPLL_CURSOR); 924 913 I915_WRITE(DSPFW3, reg); 925 - DRM_DEBUG_KMS("DSPFW3 register is %x\n", reg); 914 + drm_dbg_kms(&dev_priv->drm, "DSPFW3 register is %x\n", reg); 926 915 927 916 intel_set_memory_cxsr(dev_priv, true); 928 917 } else { ··· 1213 1202 const struct intel_plane_state *plane_state) 1214 1203 { 1215 1204 struct intel_plane *plane = to_intel_plane(plane_state->uapi.plane); 1205 + struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev); 1216 1206 int num_levels = intel_wm_num_levels(to_i915(plane->base.dev)); 1217 1207 enum plane_id plane_id = plane->id; 1218 1208 bool dirty = false; ··· 1266 1254 1267 1255 out: 1268 1256 if (dirty) { 1269 - DRM_DEBUG_KMS("%s watermarks: normal=%d, SR=%d, HPLL=%d\n", 1270 - plane->base.name, 1271 - crtc_state->wm.g4x.raw[G4X_WM_LEVEL_NORMAL].plane[plane_id], 1272 - crtc_state->wm.g4x.raw[G4X_WM_LEVEL_SR].plane[plane_id], 1273 - crtc_state->wm.g4x.raw[G4X_WM_LEVEL_HPLL].plane[plane_id]); 1257 + drm_dbg_kms(&dev_priv->drm, 1258 + "%s watermarks: normal=%d, SR=%d, HPLL=%d\n", 1259 + plane->base.name, 1260 + crtc_state->wm.g4x.raw[G4X_WM_LEVEL_NORMAL].plane[plane_id], 1261 + crtc_state->wm.g4x.raw[G4X_WM_LEVEL_SR].plane[plane_id], 1262 + crtc_state->wm.g4x.raw[G4X_WM_LEVEL_HPLL].plane[plane_id]); 1274 1263 1275 1264 if (plane_id == PLANE_PRIMARY) 1276 - DRM_DEBUG_KMS("FBC watermarks: SR=%d, HPLL=%d\n", 1277 - crtc_state->wm.g4x.raw[G4X_WM_LEVEL_SR].fbc, 1278 - crtc_state->wm.g4x.raw[G4X_WM_LEVEL_HPLL].fbc); 1265 + drm_dbg_kms(&dev_priv->drm, 1266 + "FBC watermarks: SR=%d, HPLL=%d\n", 1267 + crtc_state->wm.g4x.raw[G4X_WM_LEVEL_SR].fbc, 1268 + crtc_state->wm.g4x.raw[G4X_WM_LEVEL_HPLL].fbc); 1279 1269 } 1280 1270 1281 1271 return dirty; ··· 1795 1781 const struct intel_plane_state *plane_state) 1796 1782 { 1797 1783 struct intel_plane *plane = to_intel_plane(plane_state->uapi.plane); 1784 + struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev); 1798 1785 enum plane_id plane_id = plane->id; 1799 1786 int num_levels = intel_wm_num_levels(to_i915(plane->base.dev)); 1800 1787 int level; ··· 1823 1808 1824 1809 out: 1825 1810 if (dirty) 1826 - DRM_DEBUG_KMS("%s watermarks: PM2=%d, PM5=%d, DDR DVFS=%d\n", 1827 - plane->base.name, 1828 - crtc_state->wm.vlv.raw[VLV_WM_LEVEL_PM2].plane[plane_id], 1829 - crtc_state->wm.vlv.raw[VLV_WM_LEVEL_PM5].plane[plane_id], 1830 - crtc_state->wm.vlv.raw[VLV_WM_LEVEL_DDR_DVFS].plane[plane_id]); 1811 + drm_dbg_kms(&dev_priv->drm, 1812 + "%s watermarks: PM2=%d, PM5=%d, DDR DVFS=%d\n", 1813 + plane->base.name, 1814 + crtc_state->wm.vlv.raw[VLV_WM_LEVEL_PM2].plane[plane_id], 1815 + crtc_state->wm.vlv.raw[VLV_WM_LEVEL_PM5].plane[plane_id], 1816 + crtc_state->wm.vlv.raw[VLV_WM_LEVEL_DDR_DVFS].plane[plane_id]); 1831 1817 1832 1818 return dirty; 1833 1819 } ··· 2243 2227 if (srwm < 0) 2244 2228 srwm = 1; 2245 2229 srwm &= 0x1ff; 2246 - DRM_DEBUG_KMS("self-refresh entries: %d, wm: %d\n", 2247 - entries, srwm); 2230 + drm_dbg_kms(&dev_priv->drm, 2231 + "self-refresh entries: %d, wm: %d\n", 2232 + entries, srwm); 2248 2233 2249 2234 entries = intel_wm_method2(clock, htotal, 2250 2235 crtc->base.cursor->state->crtc_w, 4, ··· 2258 2241 if (cursor_sr > i965_cursor_wm_info.max_wm) 2259 2242 cursor_sr = i965_cursor_wm_info.max_wm; 2260 2243 2261 - DRM_DEBUG_KMS("self-refresh watermark: display plane %d " 2262 - "cursor %d\n", srwm, cursor_sr); 2244 + drm_dbg_kms(&dev_priv->drm, 2245 + "self-refresh watermark: display plane %d " 2246 + "cursor %d\n", srwm, cursor_sr); 2263 2247 2264 2248 cxsr_enabled = true; 2265 2249 } else { ··· 2269 2251 intel_set_memory_cxsr(dev_priv, false); 2270 2252 } 2271 2253 2272 - DRM_DEBUG_KMS("Setting FIFO watermarks - A: 8, B: 8, C: 8, SR %d\n", 2273 - srwm); 2254 + drm_dbg_kms(&dev_priv->drm, 2255 + "Setting FIFO watermarks - A: 8, B: 8, C: 8, SR %d\n", 2256 + srwm); 2274 2257 2275 2258 /* 965 has limitations... */ 2276 2259 I915_WRITE(DSPFW1, FW_WM(srwm, SR) | ··· 2361 2342 planeb_wm = wm_info->max_wm; 2362 2343 } 2363 2344 2364 - DRM_DEBUG_KMS("FIFO watermarks - A: %d, B: %d\n", planea_wm, planeb_wm); 2345 + drm_dbg_kms(&dev_priv->drm, 2346 + "FIFO watermarks - A: %d, B: %d\n", planea_wm, planeb_wm); 2365 2347 2366 2348 if (IS_I915GM(dev_priv) && enabled) { 2367 2349 struct drm_i915_gem_object *obj; ··· 2404 2384 entries = intel_wm_method2(clock, htotal, hdisplay, cpp, 2405 2385 sr_latency_ns / 100); 2406 2386 entries = DIV_ROUND_UP(entries, wm_info->cacheline_size); 2407 - DRM_DEBUG_KMS("self-refresh entries: %d\n", entries); 2387 + drm_dbg_kms(&dev_priv->drm, 2388 + "self-refresh entries: %d\n", entries); 2408 2389 srwm = wm_info->fifo_size - entries; 2409 2390 if (srwm < 0) 2410 2391 srwm = 1; ··· 2417 2396 I915_WRITE(FW_BLC_SELF, srwm & 0x3f); 2418 2397 } 2419 2398 2420 - DRM_DEBUG_KMS("Setting FIFO watermarks - A: %d, B: %d, C: %d, SR %d\n", 2421 - planea_wm, planeb_wm, cwm, srwm); 2399 + drm_dbg_kms(&dev_priv->drm, 2400 + "Setting FIFO watermarks - A: %d, B: %d, C: %d, SR %d\n", 2401 + planea_wm, planeb_wm, cwm, srwm); 2422 2402 2423 2403 fwater_lo = ((planeb_wm & 0x3f) << 16) | (planea_wm & 0x3f); 2424 2404 fwater_hi = (cwm & 0x1f); ··· 2455 2433 fwater_lo = I915_READ(FW_BLC) & ~0xfff; 2456 2434 fwater_lo |= (3<<8) | planea_wm; 2457 2435 2458 - DRM_DEBUG_KMS("Setting FIFO watermarks - A: %d\n", planea_wm); 2436 + drm_dbg_kms(&dev_priv->drm, 2437 + "Setting FIFO watermarks - A: %d\n", planea_wm); 2459 2438 2460 2439 I915_WRITE(FW_BLC, fwater_lo); 2461 2440 } ··· 2855 2832 &val, NULL); 2856 2833 2857 2834 if (ret) { 2858 - DRM_ERROR("SKL Mailbox read error = %d\n", ret); 2835 + drm_err(&dev_priv->drm, 2836 + "SKL Mailbox read error = %d\n", ret); 2859 2837 return; 2860 2838 } 2861 2839 ··· 2874 2850 GEN9_PCODE_READ_MEM_LATENCY, 2875 2851 &val, NULL); 2876 2852 if (ret) { 2877 - DRM_ERROR("SKL Mailbox read error = %d\n", ret); 2853 + drm_err(&dev_priv->drm, 2854 + "SKL Mailbox read error = %d\n", ret); 2878 2855 return; 2879 2856 } 2880 2857 ··· 2993 2968 unsigned int latency = wm[level]; 2994 2969 2995 2970 if (latency == 0) { 2996 - DRM_DEBUG_KMS("%s WM%d latency not provided\n", 2997 - name, level); 2971 + drm_dbg_kms(&dev_priv->drm, 2972 + "%s WM%d latency not provided\n", 2973 + name, level); 2998 2974 continue; 2999 2975 } 3000 2976 ··· 3008 2982 else if (level > 0) 3009 2983 latency *= 5; 3010 2984 3011 - DRM_DEBUG_KMS("%s WM%d latency %u (%u.%u usec)\n", 3012 - name, level, wm[level], 3013 - latency / 10, latency % 10); 2985 + drm_dbg_kms(&dev_priv->drm, 2986 + "%s WM%d latency %u (%u.%u usec)\n", name, level, 2987 + wm[level], latency / 10, latency % 10); 3014 2988 } 3015 2989 } 3016 2990 ··· 3044 3018 if (!changed) 3045 3019 return; 3046 3020 3047 - DRM_DEBUG_KMS("WM latency values increased to avoid potential underruns\n"); 3021 + drm_dbg_kms(&dev_priv->drm, 3022 + "WM latency values increased to avoid potential underruns\n"); 3048 3023 intel_print_wm_latency(dev_priv, "Primary", dev_priv->wm.pri_latency); 3049 3024 intel_print_wm_latency(dev_priv, "Sprite", dev_priv->wm.spr_latency); 3050 3025 intel_print_wm_latency(dev_priv, "Cursor", dev_priv->wm.cur_latency); ··· 3073 3046 dev_priv->wm.spr_latency[3] = 0; 3074 3047 dev_priv->wm.cur_latency[3] = 0; 3075 3048 3076 - DRM_DEBUG_KMS("LP3 watermarks disabled due to potential for lost interrupts\n"); 3049 + drm_dbg_kms(&dev_priv->drm, 3050 + "LP3 watermarks disabled due to potential for lost interrupts\n"); 3077 3051 intel_print_wm_latency(dev_priv, "Primary", dev_priv->wm.pri_latency); 3078 3052 intel_print_wm_latency(dev_priv, "Sprite", dev_priv->wm.spr_latency); 3079 3053 intel_print_wm_latency(dev_priv, "Cursor", dev_priv->wm.cur_latency); ··· 3124 3096 3125 3097 /* At least LP0 must be valid */ 3126 3098 if (!ilk_validate_wm_level(0, &max, &pipe_wm->wm[0])) { 3127 - DRM_DEBUG_KMS("LP0 watermark invalid\n"); 3099 + drm_dbg_kms(&dev_priv->drm, "LP0 watermark invalid\n"); 3128 3100 return false; 3129 3101 } 3130 3102 ··· 3701 3673 return; 3702 3674 } 3703 3675 3704 - DRM_DEBUG_DRIVER("Couldn't read SAGV block time!\n"); 3676 + drm_dbg(&dev_priv->drm, "Couldn't read SAGV block time!\n"); 3705 3677 } else if (IS_GEN(dev_priv, 11)) { 3706 3678 dev_priv->sagv_block_time_us = 10; 3707 3679 return; ··· 3741 3713 if (dev_priv->sagv_status == I915_SAGV_ENABLED) 3742 3714 return 0; 3743 3715 3744 - DRM_DEBUG_KMS("Enabling SAGV\n"); 3716 + drm_dbg_kms(&dev_priv->drm, "Enabling SAGV\n"); 3745 3717 ret = sandybridge_pcode_write(dev_priv, GEN9_PCODE_SAGV_CONTROL, 3746 3718 GEN9_SAGV_ENABLE); 3747 3719 ··· 3752 3724 * don't actually have SAGV. 3753 3725 */ 3754 3726 if (IS_SKYLAKE(dev_priv) && ret == -ENXIO) { 3755 - DRM_DEBUG_DRIVER("No SAGV found on system, ignoring\n"); 3727 + drm_dbg(&dev_priv->drm, "No SAGV found on system, ignoring\n"); 3756 3728 dev_priv->sagv_status = I915_SAGV_NOT_CONTROLLED; 3757 3729 return 0; 3758 3730 } else if (ret < 0) { 3759 - DRM_ERROR("Failed to enable SAGV\n"); 3731 + drm_err(&dev_priv->drm, "Failed to enable SAGV\n"); 3760 3732 return ret; 3761 3733 } 3762 3734 ··· 3775 3747 if (dev_priv->sagv_status == I915_SAGV_DISABLED) 3776 3748 return 0; 3777 3749 3778 - DRM_DEBUG_KMS("Disabling SAGV\n"); 3750 + drm_dbg_kms(&dev_priv->drm, "Disabling SAGV\n"); 3779 3751 /* bspec says to keep retrying for at least 1 ms */ 3780 3752 ret = skl_pcode_request(dev_priv, GEN9_PCODE_SAGV_CONTROL, 3781 3753 GEN9_SAGV_DISABLE, ··· 3786 3758 * don't actually have SAGV. 3787 3759 */ 3788 3760 if (IS_SKYLAKE(dev_priv) && ret == -ENXIO) { 3789 - DRM_DEBUG_DRIVER("No SAGV found on system, ignoring\n"); 3761 + drm_dbg(&dev_priv->drm, "No SAGV found on system, ignoring\n"); 3790 3762 dev_priv->sagv_status = I915_SAGV_NOT_CONTROLLED; 3791 3763 return 0; 3792 3764 } else if (ret < 0) { 3793 - DRM_ERROR("Failed to disable SAGV (%d)\n", ret); 3765 + drm_err(&dev_priv->drm, "Failed to disable SAGV (%d)\n", ret); 3794 3766 return ret; 3795 3767 } 3796 3768 ··· 4359 4331 } 4360 4332 4361 4333 if (level < 0) { 4362 - DRM_DEBUG_KMS("Requested display configuration exceeds system DDB limitations"); 4363 - DRM_DEBUG_KMS("minimum required %d/%d\n", blocks, 4364 - alloc_size); 4334 + drm_dbg_kms(&dev_priv->drm, 4335 + "Requested display configuration exceeds system DDB limitations"); 4336 + drm_dbg_kms(&dev_priv->drm, "minimum required %d/%d\n", 4337 + blocks, alloc_size); 4365 4338 return -EINVAL; 4366 4339 } 4367 4340 ··· 4590 4561 /* only planar format has two planes */ 4591 4562 if (color_plane == 1 && 4592 4563 !intel_format_info_is_yuv_semiplanar(format, modifier)) { 4593 - DRM_DEBUG_KMS("Non planar format have single plane\n"); 4564 + drm_dbg_kms(&dev_priv->drm, 4565 + "Non planar format have single plane\n"); 4594 4566 return -EINVAL; 4595 4567 } 4596 4568 ··· 5290 5260 if (skl_ddb_entry_equal(old, new)) 5291 5261 continue; 5292 5262 5293 - DRM_DEBUG_KMS("[PLANE:%d:%s] ddb (%4d - %4d) -> (%4d - %4d), size %4d -> %4d\n", 5294 - plane->base.base.id, plane->base.name, 5295 - old->start, old->end, new->start, new->end, 5296 - skl_ddb_entry_size(old), skl_ddb_entry_size(new)); 5263 + drm_dbg_kms(&dev_priv->drm, 5264 + "[PLANE:%d:%s] ddb (%4d - %4d) -> (%4d - %4d), size %4d -> %4d\n", 5265 + plane->base.base.id, plane->base.name, 5266 + old->start, old->end, new->start, new->end, 5267 + skl_ddb_entry_size(old), skl_ddb_entry_size(new)); 5297 5268 } 5298 5269 5299 5270 for_each_intel_plane_on_crtc(&dev_priv->drm, crtc, plane) { ··· 5307 5276 if (skl_plane_wm_equals(dev_priv, old_wm, new_wm)) 5308 5277 continue; 5309 5278 5310 - DRM_DEBUG_KMS("[PLANE:%d:%s] level %cwm0,%cwm1,%cwm2,%cwm3,%cwm4,%cwm5,%cwm6,%cwm7,%ctwm" 5311 - " -> %cwm0,%cwm1,%cwm2,%cwm3,%cwm4,%cwm5,%cwm6,%cwm7,%ctwm\n", 5312 - plane->base.base.id, plane->base.name, 5313 - enast(old_wm->wm[0].plane_en), enast(old_wm->wm[1].plane_en), 5314 - enast(old_wm->wm[2].plane_en), enast(old_wm->wm[3].plane_en), 5315 - enast(old_wm->wm[4].plane_en), enast(old_wm->wm[5].plane_en), 5316 - enast(old_wm->wm[6].plane_en), enast(old_wm->wm[7].plane_en), 5317 - enast(old_wm->trans_wm.plane_en), 5318 - enast(new_wm->wm[0].plane_en), enast(new_wm->wm[1].plane_en), 5319 - enast(new_wm->wm[2].plane_en), enast(new_wm->wm[3].plane_en), 5320 - enast(new_wm->wm[4].plane_en), enast(new_wm->wm[5].plane_en), 5321 - enast(new_wm->wm[6].plane_en), enast(new_wm->wm[7].plane_en), 5322 - enast(new_wm->trans_wm.plane_en)); 5279 + drm_dbg_kms(&dev_priv->drm, 5280 + "[PLANE:%d:%s] level %cwm0,%cwm1,%cwm2,%cwm3,%cwm4,%cwm5,%cwm6,%cwm7,%ctwm" 5281 + " -> %cwm0,%cwm1,%cwm2,%cwm3,%cwm4,%cwm5,%cwm6,%cwm7,%ctwm\n", 5282 + plane->base.base.id, plane->base.name, 5283 + enast(old_wm->wm[0].plane_en), enast(old_wm->wm[1].plane_en), 5284 + enast(old_wm->wm[2].plane_en), enast(old_wm->wm[3].plane_en), 5285 + enast(old_wm->wm[4].plane_en), enast(old_wm->wm[5].plane_en), 5286 + enast(old_wm->wm[6].plane_en), enast(old_wm->wm[7].plane_en), 5287 + enast(old_wm->trans_wm.plane_en), 5288 + enast(new_wm->wm[0].plane_en), enast(new_wm->wm[1].plane_en), 5289 + enast(new_wm->wm[2].plane_en), enast(new_wm->wm[3].plane_en), 5290 + enast(new_wm->wm[4].plane_en), enast(new_wm->wm[5].plane_en), 5291 + enast(new_wm->wm[6].plane_en), enast(new_wm->wm[7].plane_en), 5292 + enast(new_wm->trans_wm.plane_en)); 5323 5293 5324 - DRM_DEBUG_KMS("[PLANE:%d:%s] lines %c%3d,%c%3d,%c%3d,%c%3d,%c%3d,%c%3d,%c%3d,%c%3d,%c%3d" 5294 + drm_dbg_kms(&dev_priv->drm, 5295 + "[PLANE:%d:%s] lines %c%3d,%c%3d,%c%3d,%c%3d,%c%3d,%c%3d,%c%3d,%c%3d,%c%3d" 5325 5296 " -> %c%3d,%c%3d,%c%3d,%c%3d,%c%3d,%c%3d,%c%3d,%c%3d,%c%3d\n", 5326 - plane->base.base.id, plane->base.name, 5327 - enast(old_wm->wm[0].ignore_lines), old_wm->wm[0].plane_res_l, 5328 - enast(old_wm->wm[1].ignore_lines), old_wm->wm[1].plane_res_l, 5329 - enast(old_wm->wm[2].ignore_lines), old_wm->wm[2].plane_res_l, 5330 - enast(old_wm->wm[3].ignore_lines), old_wm->wm[3].plane_res_l, 5331 - enast(old_wm->wm[4].ignore_lines), old_wm->wm[4].plane_res_l, 5332 - enast(old_wm->wm[5].ignore_lines), old_wm->wm[5].plane_res_l, 5333 - enast(old_wm->wm[6].ignore_lines), old_wm->wm[6].plane_res_l, 5334 - enast(old_wm->wm[7].ignore_lines), old_wm->wm[7].plane_res_l, 5335 - enast(old_wm->trans_wm.ignore_lines), old_wm->trans_wm.plane_res_l, 5297 + plane->base.base.id, plane->base.name, 5298 + enast(old_wm->wm[0].ignore_lines), old_wm->wm[0].plane_res_l, 5299 + enast(old_wm->wm[1].ignore_lines), old_wm->wm[1].plane_res_l, 5300 + enast(old_wm->wm[2].ignore_lines), old_wm->wm[2].plane_res_l, 5301 + enast(old_wm->wm[3].ignore_lines), old_wm->wm[3].plane_res_l, 5302 + enast(old_wm->wm[4].ignore_lines), old_wm->wm[4].plane_res_l, 5303 + enast(old_wm->wm[5].ignore_lines), old_wm->wm[5].plane_res_l, 5304 + enast(old_wm->wm[6].ignore_lines), old_wm->wm[6].plane_res_l, 5305 + enast(old_wm->wm[7].ignore_lines), old_wm->wm[7].plane_res_l, 5306 + enast(old_wm->trans_wm.ignore_lines), old_wm->trans_wm.plane_res_l, 5336 5307 5337 - enast(new_wm->wm[0].ignore_lines), new_wm->wm[0].plane_res_l, 5338 - enast(new_wm->wm[1].ignore_lines), new_wm->wm[1].plane_res_l, 5339 - enast(new_wm->wm[2].ignore_lines), new_wm->wm[2].plane_res_l, 5340 - enast(new_wm->wm[3].ignore_lines), new_wm->wm[3].plane_res_l, 5341 - enast(new_wm->wm[4].ignore_lines), new_wm->wm[4].plane_res_l, 5342 - enast(new_wm->wm[5].ignore_lines), new_wm->wm[5].plane_res_l, 5343 - enast(new_wm->wm[6].ignore_lines), new_wm->wm[6].plane_res_l, 5344 - enast(new_wm->wm[7].ignore_lines), new_wm->wm[7].plane_res_l, 5345 - enast(new_wm->trans_wm.ignore_lines), new_wm->trans_wm.plane_res_l); 5308 + enast(new_wm->wm[0].ignore_lines), new_wm->wm[0].plane_res_l, 5309 + enast(new_wm->wm[1].ignore_lines), new_wm->wm[1].plane_res_l, 5310 + enast(new_wm->wm[2].ignore_lines), new_wm->wm[2].plane_res_l, 5311 + enast(new_wm->wm[3].ignore_lines), new_wm->wm[3].plane_res_l, 5312 + enast(new_wm->wm[4].ignore_lines), new_wm->wm[4].plane_res_l, 5313 + enast(new_wm->wm[5].ignore_lines), new_wm->wm[5].plane_res_l, 5314 + enast(new_wm->wm[6].ignore_lines), new_wm->wm[6].plane_res_l, 5315 + enast(new_wm->wm[7].ignore_lines), new_wm->wm[7].plane_res_l, 5316 + enast(new_wm->trans_wm.ignore_lines), new_wm->trans_wm.plane_res_l); 5346 5317 5347 - DRM_DEBUG_KMS("[PLANE:%d:%s] blocks %4d,%4d,%4d,%4d,%4d,%4d,%4d,%4d,%4d" 5348 - " -> %4d,%4d,%4d,%4d,%4d,%4d,%4d,%4d,%4d\n", 5349 - plane->base.base.id, plane->base.name, 5350 - old_wm->wm[0].plane_res_b, old_wm->wm[1].plane_res_b, 5351 - old_wm->wm[2].plane_res_b, old_wm->wm[3].plane_res_b, 5352 - old_wm->wm[4].plane_res_b, old_wm->wm[5].plane_res_b, 5353 - old_wm->wm[6].plane_res_b, old_wm->wm[7].plane_res_b, 5354 - old_wm->trans_wm.plane_res_b, 5355 - new_wm->wm[0].plane_res_b, new_wm->wm[1].plane_res_b, 5356 - new_wm->wm[2].plane_res_b, new_wm->wm[3].plane_res_b, 5357 - new_wm->wm[4].plane_res_b, new_wm->wm[5].plane_res_b, 5358 - new_wm->wm[6].plane_res_b, new_wm->wm[7].plane_res_b, 5359 - new_wm->trans_wm.plane_res_b); 5318 + drm_dbg_kms(&dev_priv->drm, 5319 + "[PLANE:%d:%s] blocks %4d,%4d,%4d,%4d,%4d,%4d,%4d,%4d,%4d" 5320 + " -> %4d,%4d,%4d,%4d,%4d,%4d,%4d,%4d,%4d\n", 5321 + plane->base.base.id, plane->base.name, 5322 + old_wm->wm[0].plane_res_b, old_wm->wm[1].plane_res_b, 5323 + old_wm->wm[2].plane_res_b, old_wm->wm[3].plane_res_b, 5324 + old_wm->wm[4].plane_res_b, old_wm->wm[5].plane_res_b, 5325 + old_wm->wm[6].plane_res_b, old_wm->wm[7].plane_res_b, 5326 + old_wm->trans_wm.plane_res_b, 5327 + new_wm->wm[0].plane_res_b, new_wm->wm[1].plane_res_b, 5328 + new_wm->wm[2].plane_res_b, new_wm->wm[3].plane_res_b, 5329 + new_wm->wm[4].plane_res_b, new_wm->wm[5].plane_res_b, 5330 + new_wm->wm[6].plane_res_b, new_wm->wm[7].plane_res_b, 5331 + new_wm->trans_wm.plane_res_b); 5360 5332 5361 - DRM_DEBUG_KMS("[PLANE:%d:%s] min_ddb %4d,%4d,%4d,%4d,%4d,%4d,%4d,%4d,%4d" 5362 - " -> %4d,%4d,%4d,%4d,%4d,%4d,%4d,%4d,%4d\n", 5363 - plane->base.base.id, plane->base.name, 5364 - old_wm->wm[0].min_ddb_alloc, old_wm->wm[1].min_ddb_alloc, 5365 - old_wm->wm[2].min_ddb_alloc, old_wm->wm[3].min_ddb_alloc, 5366 - old_wm->wm[4].min_ddb_alloc, old_wm->wm[5].min_ddb_alloc, 5367 - old_wm->wm[6].min_ddb_alloc, old_wm->wm[7].min_ddb_alloc, 5368 - old_wm->trans_wm.min_ddb_alloc, 5369 - new_wm->wm[0].min_ddb_alloc, new_wm->wm[1].min_ddb_alloc, 5370 - new_wm->wm[2].min_ddb_alloc, new_wm->wm[3].min_ddb_alloc, 5371 - new_wm->wm[4].min_ddb_alloc, new_wm->wm[5].min_ddb_alloc, 5372 - new_wm->wm[6].min_ddb_alloc, new_wm->wm[7].min_ddb_alloc, 5373 - new_wm->trans_wm.min_ddb_alloc); 5333 + drm_dbg_kms(&dev_priv->drm, 5334 + "[PLANE:%d:%s] min_ddb %4d,%4d,%4d,%4d,%4d,%4d,%4d,%4d,%4d" 5335 + " -> %4d,%4d,%4d,%4d,%4d,%4d,%4d,%4d,%4d\n", 5336 + plane->base.base.id, plane->base.name, 5337 + old_wm->wm[0].min_ddb_alloc, old_wm->wm[1].min_ddb_alloc, 5338 + old_wm->wm[2].min_ddb_alloc, old_wm->wm[3].min_ddb_alloc, 5339 + old_wm->wm[4].min_ddb_alloc, old_wm->wm[5].min_ddb_alloc, 5340 + old_wm->wm[6].min_ddb_alloc, old_wm->wm[7].min_ddb_alloc, 5341 + old_wm->trans_wm.min_ddb_alloc, 5342 + new_wm->wm[0].min_ddb_alloc, new_wm->wm[1].min_ddb_alloc, 5343 + new_wm->wm[2].min_ddb_alloc, new_wm->wm[3].min_ddb_alloc, 5344 + new_wm->wm[4].min_ddb_alloc, new_wm->wm[5].min_ddb_alloc, 5345 + new_wm->wm[6].min_ddb_alloc, new_wm->wm[7].min_ddb_alloc, 5346 + new_wm->trans_wm.min_ddb_alloc); 5374 5347 } 5375 5348 } 5376 5349 } ··· 5966 5931 crtc_state->wm.g4x.optimal = *active; 5967 5932 crtc_state->wm.g4x.intermediate = *active; 5968 5933 5969 - DRM_DEBUG_KMS("Initial watermarks: pipe %c, plane=%d, cursor=%d, sprite=%d\n", 5970 - pipe_name(pipe), 5971 - wm->pipe[pipe].plane[PLANE_PRIMARY], 5972 - wm->pipe[pipe].plane[PLANE_CURSOR], 5973 - wm->pipe[pipe].plane[PLANE_SPRITE0]); 5934 + drm_dbg_kms(&dev_priv->drm, 5935 + "Initial watermarks: pipe %c, plane=%d, cursor=%d, sprite=%d\n", 5936 + pipe_name(pipe), 5937 + wm->pipe[pipe].plane[PLANE_PRIMARY], 5938 + wm->pipe[pipe].plane[PLANE_CURSOR], 5939 + wm->pipe[pipe].plane[PLANE_SPRITE0]); 5974 5940 } 5975 5941 5976 - DRM_DEBUG_KMS("Initial SR watermarks: plane=%d, cursor=%d fbc=%d\n", 5977 - wm->sr.plane, wm->sr.cursor, wm->sr.fbc); 5978 - DRM_DEBUG_KMS("Initial HPLL watermarks: plane=%d, SR cursor=%d fbc=%d\n", 5979 - wm->hpll.plane, wm->hpll.cursor, wm->hpll.fbc); 5980 - DRM_DEBUG_KMS("Initial SR=%s HPLL=%s FBC=%s\n", 5981 - yesno(wm->cxsr), yesno(wm->hpll_en), yesno(wm->fbc_en)); 5942 + drm_dbg_kms(&dev_priv->drm, 5943 + "Initial SR watermarks: plane=%d, cursor=%d fbc=%d\n", 5944 + wm->sr.plane, wm->sr.cursor, wm->sr.fbc); 5945 + drm_dbg_kms(&dev_priv->drm, 5946 + "Initial HPLL watermarks: plane=%d, SR cursor=%d fbc=%d\n", 5947 + wm->hpll.plane, wm->hpll.cursor, wm->hpll.fbc); 5948 + drm_dbg_kms(&dev_priv->drm, "Initial SR=%s HPLL=%s FBC=%s\n", 5949 + yesno(wm->cxsr), yesno(wm->hpll_en), yesno(wm->fbc_en)); 5982 5950 } 5983 5951 5984 5952 void g4x_wm_sanitize(struct drm_i915_private *dev_priv) ··· 6073 6035 6074 6036 if (wait_for((vlv_punit_read(dev_priv, PUNIT_REG_DDR_SETUP2) & 6075 6037 FORCE_DDR_FREQ_REQ_ACK) == 0, 3)) { 6076 - DRM_DEBUG_KMS("Punit not acking DDR DVFS request, " 6077 - "assuming DDR DVFS is disabled\n"); 6038 + drm_dbg_kms(&dev_priv->drm, 6039 + "Punit not acking DDR DVFS request, " 6040 + "assuming DDR DVFS is disabled\n"); 6078 6041 dev_priv->wm.max_level = VLV_WM_LEVEL_PM5; 6079 6042 } else { 6080 6043 val = vlv_punit_read(dev_priv, PUNIT_REG_DDR_SETUP2); ··· 6126 6087 crtc_state->wm.vlv.optimal = *active; 6127 6088 crtc_state->wm.vlv.intermediate = *active; 6128 6089 6129 - DRM_DEBUG_KMS("Initial watermarks: pipe %c, plane=%d, cursor=%d, sprite0=%d, sprite1=%d\n", 6130 - pipe_name(pipe), 6131 - wm->pipe[pipe].plane[PLANE_PRIMARY], 6132 - wm->pipe[pipe].plane[PLANE_CURSOR], 6133 - wm->pipe[pipe].plane[PLANE_SPRITE0], 6134 - wm->pipe[pipe].plane[PLANE_SPRITE1]); 6090 + drm_dbg_kms(&dev_priv->drm, 6091 + "Initial watermarks: pipe %c, plane=%d, cursor=%d, sprite0=%d, sprite1=%d\n", 6092 + pipe_name(pipe), 6093 + wm->pipe[pipe].plane[PLANE_PRIMARY], 6094 + wm->pipe[pipe].plane[PLANE_CURSOR], 6095 + wm->pipe[pipe].plane[PLANE_SPRITE0], 6096 + wm->pipe[pipe].plane[PLANE_SPRITE1]); 6135 6097 } 6136 6098 6137 - DRM_DEBUG_KMS("Initial watermarks: SR plane=%d, SR cursor=%d level=%d cxsr=%d\n", 6138 - wm->sr.plane, wm->sr.cursor, wm->level, wm->cxsr); 6099 + drm_dbg_kms(&dev_priv->drm, 6100 + "Initial watermarks: SR plane=%d, SR cursor=%d level=%d cxsr=%d\n", 6101 + wm->sr.plane, wm->sr.cursor, wm->level, wm->cxsr); 6139 6102 } 6140 6103 6141 6104 void vlv_wm_sanitize(struct drm_i915_private *dev_priv) ··· 6453 6412 6454 6413 tmp = I915_READ(MCH_SSKPD); 6455 6414 if ((tmp & MCH_SSKPD_WM0_MASK) != MCH_SSKPD_WM0_VAL) 6456 - DRM_DEBUG_KMS("Wrong MCH_SSKPD value: 0x%08x This can cause underruns.\n", 6457 - tmp); 6415 + drm_dbg_kms(&dev_priv->drm, 6416 + "Wrong MCH_SSKPD value: 0x%08x This can cause underruns.\n", 6417 + tmp); 6458 6418 } 6459 6419 6460 6420 static void gen6_init_clock_gating(struct drm_i915_private *dev_priv) ··· 6632 6590 /* WaEnable32PlaneMode:icl */ 6633 6591 I915_WRITE(GEN9_CSFE_CHICKEN1_RCS, 6634 6592 _MASKED_BIT_ENABLE(GEN11_ENABLE_32_PLANE_MODE)); 6593 + 6594 + /* 6595 + * Wa_1408615072:icl,ehl (vsunit) 6596 + * Wa_1407596294:icl,ehl (hsunit) 6597 + */ 6598 + intel_uncore_rmw(&dev_priv->uncore, UNSLICE_UNIT_LEVEL_CLKGATE, 6599 + 0, VSUNIT_CLKGATE_DIS | HSUNIT_CLKGATE_DIS); 6600 + 6601 + /* Wa_1407352427:icl,ehl */ 6602 + intel_uncore_rmw(&dev_priv->uncore, UNSLICE_UNIT_LEVEL_CLKGATE2, 6603 + 0, PSDUNIT_CLKGATE_DIS); 6635 6604 } 6636 6605 6637 6606 static void tgl_init_clock_gating(struct drm_i915_private *dev_priv) 6638 6607 { 6639 6608 u32 vd_pg_enable = 0; 6640 6609 unsigned int i; 6610 + 6611 + /* Wa_1408615072:tgl */ 6612 + intel_uncore_rmw(&dev_priv->uncore, UNSLICE_UNIT_LEVEL_CLKGATE2, 6613 + 0, VSUNIT_CLKGATE_DIS_TGL); 6641 6614 6642 6615 /* This is not a WA. Enable VD HCP & MFX_ENC powergate */ 6643 6616 for (i = 0; i < I915_MAX_VCS; i++) { ··· 7170 7113 7171 7114 static void nop_init_clock_gating(struct drm_i915_private *dev_priv) 7172 7115 { 7173 - DRM_DEBUG_KMS("No clock gating settings or workarounds applied.\n"); 7116 + drm_dbg_kms(&dev_priv->drm, 7117 + "No clock gating settings or workarounds applied.\n"); 7174 7118 } 7175 7119 7176 7120 /** ··· 7238 7180 { 7239 7181 /* For cxsr */ 7240 7182 if (IS_PINEVIEW(dev_priv)) 7241 - i915_pineview_get_mem_freq(dev_priv); 7183 + pnv_get_mem_freq(dev_priv); 7242 7184 else if (IS_GEN(dev_priv, 5)) 7243 - i915_ironlake_get_mem_freq(dev_priv); 7185 + ilk_get_mem_freq(dev_priv); 7244 7186 7245 7187 if (intel_has_sagv(dev_priv)) 7246 7188 skl_setup_sagv_block_time(dev_priv); ··· 7266 7208 dev_priv->display.optimize_watermarks = 7267 7209 ilk_optimize_watermarks; 7268 7210 } else { 7269 - DRM_DEBUG_KMS("Failed to read display plane latency. " 7270 - "Disable CxSR\n"); 7211 + drm_dbg_kms(&dev_priv->drm, 7212 + "Failed to read display plane latency. " 7213 + "Disable CxSR\n"); 7271 7214 } 7272 7215 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) { 7273 7216 vlv_setup_wm_latency(dev_priv); ··· 7288 7229 dev_priv->is_ddr3, 7289 7230 dev_priv->fsb_freq, 7290 7231 dev_priv->mem_freq)) { 7291 - DRM_INFO("failed to find known CxSR latency " 7232 + drm_info(&dev_priv->drm, 7233 + "failed to find known CxSR latency " 7292 7234 "(found ddr%s fsb freq %d, mem freq %d), " 7293 7235 "disabling CxSR\n", 7294 7236 (dev_priv->is_ddr3 == 1) ? "3" : "2", ··· 7298 7238 intel_set_memory_cxsr(dev_priv, false); 7299 7239 dev_priv->display.update_wm = NULL; 7300 7240 } else 7301 - dev_priv->display.update_wm = pineview_update_wm; 7241 + dev_priv->display.update_wm = pnv_update_wm; 7302 7242 } else if (IS_GEN(dev_priv, 4)) { 7303 7243 dev_priv->display.update_wm = i965_update_wm; 7304 7244 } else if (IS_GEN(dev_priv, 3)) { ··· 7313 7253 dev_priv->display.get_fifo_size = i830_get_fifo_size; 7314 7254 } 7315 7255 } else { 7316 - DRM_ERROR("unexpected fall-through in intel_init_pm\n"); 7256 + drm_err(&dev_priv->drm, 7257 + "unexpected fall-through in %s\n", __func__); 7317 7258 } 7318 7259 } 7319 7260
+8 -4
drivers/gpu/drm/i915/intel_region_lmem.c
··· 90 90 if (ret) 91 91 io_mapping_fini(&mem->iomap); 92 92 93 + intel_memory_region_set_name(mem, "local"); 94 + 93 95 return ret; 94 96 } 95 97 ··· 125 123 io_start, 126 124 &intel_region_lmem_ops); 127 125 if (!IS_ERR(mem)) { 128 - DRM_INFO("Intel graphics fake LMEM: %pR\n", &mem->region); 129 - DRM_INFO("Intel graphics fake LMEM IO start: %llx\n", 130 - (u64)mem->io_start); 131 - DRM_INFO("Intel graphics fake LMEM size: %llx\n", 126 + drm_info(&i915->drm, "Intel graphics fake LMEM: %pR\n", 127 + &mem->region); 128 + drm_info(&i915->drm, 129 + "Intel graphics fake LMEM IO start: %llx\n", 130 + (u64)mem->io_start); 131 + drm_info(&i915->drm, "Intel graphics fake LMEM size: %llx\n", 132 132 (u64)resource_size(&mem->region)); 133 133 } 134 134
+17 -12
drivers/gpu/drm/i915/intel_sideband.c
··· 105 105 if (intel_wait_for_register(uncore, 106 106 VLV_IOSF_DOORBELL_REQ, IOSF_SB_BUSY, 0, 107 107 5)) { 108 - DRM_DEBUG_DRIVER("IOSF sideband idle wait (%s) timed out\n", 109 - is_read ? "read" : "write"); 108 + drm_dbg(&i915->drm, "IOSF sideband idle wait (%s) timed out\n", 109 + is_read ? "read" : "write"); 110 110 return -EAGAIN; 111 111 } 112 112 ··· 129 129 *val = intel_uncore_read_fw(uncore, VLV_IOSF_DATA); 130 130 err = 0; 131 131 } else { 132 - DRM_DEBUG_DRIVER("IOSF sideband finish wait (%s) timed out\n", 133 - is_read ? "read" : "write"); 132 + drm_dbg(&i915->drm, "IOSF sideband finish wait (%s) timed out\n", 133 + is_read ? "read" : "write"); 134 134 err = -ETIMEDOUT; 135 135 } 136 136 ··· 283 283 if (intel_wait_for_register_fw(uncore, 284 284 SBI_CTL_STAT, SBI_BUSY, 0, 285 285 100)) { 286 - DRM_ERROR("timeout waiting for SBI to become ready\n"); 286 + drm_err(&i915->drm, 287 + "timeout waiting for SBI to become ready\n"); 287 288 return -EBUSY; 288 289 } 289 290 ··· 302 301 if (__intel_wait_for_register_fw(uncore, 303 302 SBI_CTL_STAT, SBI_BUSY, 0, 304 303 100, 100, &cmd)) { 305 - DRM_ERROR("timeout waiting for SBI to complete read\n"); 304 + drm_err(&i915->drm, 305 + "timeout waiting for SBI to complete read\n"); 306 306 return -ETIMEDOUT; 307 307 } 308 308 309 309 if (cmd & SBI_RESPONSE_FAIL) { 310 - DRM_ERROR("error during SBI read of reg %x\n", reg); 310 + drm_err(&i915->drm, "error during SBI read of reg %x\n", reg); 311 311 return -ENXIO; 312 312 } 313 313 ··· 428 426 mutex_unlock(&i915->sb_lock); 429 427 430 428 if (err) { 431 - DRM_DEBUG_DRIVER("warning: pcode (read from mbox %x) mailbox access failed for %ps: %d\n", 432 - mbox, __builtin_return_address(0), err); 429 + drm_dbg(&i915->drm, 430 + "warning: pcode (read from mbox %x) mailbox access failed for %ps: %d\n", 431 + mbox, __builtin_return_address(0), err); 433 432 } 434 433 435 434 return err; ··· 450 447 mutex_unlock(&i915->sb_lock); 451 448 452 449 if (err) { 453 - DRM_DEBUG_DRIVER("warning: pcode (write of 0x%08x to mbox %x) mailbox access failed for %ps: %d\n", 454 - val, mbox, __builtin_return_address(0), err); 450 + drm_dbg(&i915->drm, 451 + "warning: pcode (write of 0x%08x to mbox %x) mailbox access failed for %ps: %d\n", 452 + val, mbox, __builtin_return_address(0), err); 455 453 } 456 454 457 455 return err; ··· 523 519 * requests, and for any quirks of the PCODE firmware that delays 524 520 * the request completion. 525 521 */ 526 - DRM_DEBUG_KMS("PCODE timeout, retrying with preemption disabled\n"); 522 + drm_dbg_kms(&i915->drm, 523 + "PCODE timeout, retrying with preemption disabled\n"); 527 524 WARN_ON_ONCE(timeout_base_ms > 3); 528 525 preempt_disable(); 529 526 ret = wait_for_atomic(COND, 50);
+13 -12
drivers/gpu/drm/i915/intel_uncore.c
··· 359 359 if (wait_for_atomic((n = fifo_free_entries(uncore)) > 360 360 GT_FIFO_NUM_RESERVED_ENTRIES, 361 361 GT_FIFO_TIMEOUT_MS)) { 362 - DRM_DEBUG("GT_FIFO timeout, entries: %u\n", n); 362 + drm_dbg(&uncore->i915->drm, 363 + "GT_FIFO timeout, entries: %u\n", n); 363 364 return; 364 365 } 365 366 } ··· 433 432 break; 434 433 435 434 if (--retry_count == 0) { 436 - DRM_ERROR("Timed out waiting for forcewake timers to finish\n"); 435 + drm_err(&uncore->i915->drm, "Timed out waiting for forcewake timers to finish\n"); 437 436 break; 438 437 } 439 438 ··· 491 490 fifodbg = __raw_uncore_read32(uncore, GTFIFODBG); 492 491 493 492 if (unlikely(fifodbg)) { 494 - DRM_DEBUG_DRIVER("GTFIFODBG = 0x08%x\n", fifodbg); 493 + drm_dbg(&uncore->i915->drm, "GTFIFODBG = 0x08%x\n", fifodbg); 495 494 __raw_uncore_write32(uncore, GTFIFODBG, fifodbg); 496 495 } 497 496 ··· 563 562 unsigned int restore_forcewake; 564 563 565 564 if (intel_uncore_unclaimed_mmio(uncore)) 566 - DRM_DEBUG("unclaimed mmio detected on resume, clearing\n"); 565 + drm_dbg(&uncore->i915->drm, "unclaimed mmio detected on resume, clearing\n"); 567 566 568 567 if (!intel_uncore_has_forcewake(uncore)) 569 568 return; ··· 1596 1595 spin_unlock_irq(&uncore->lock); 1597 1596 1598 1597 if (!(ecobus & FORCEWAKE_MT_ENABLE)) { 1599 - DRM_INFO("No MT forcewake available on Ivybridge, this can result in issues\n"); 1600 - DRM_INFO("when using vblank-synced partial screen updates.\n"); 1598 + drm_info(&i915->drm, "No MT forcewake available on Ivybridge, this can result in issues\n"); 1599 + drm_info(&i915->drm, "when using vblank-synced partial screen updates.\n"); 1601 1600 fw_domain_fini(uncore, FW_DOMAIN_ID_RENDER); 1602 1601 fw_domain_init(uncore, FW_DOMAIN_ID_RENDER, 1603 1602 FORCEWAKE, FORCEWAKE_ACK); ··· 1684 1683 mmio_size = 2 * 1024 * 1024; 1685 1684 uncore->regs = pci_iomap(pdev, mmio_bar, mmio_size); 1686 1685 if (uncore->regs == NULL) { 1687 - DRM_ERROR("failed to map registers\n"); 1688 - 1686 + drm_err(&i915->drm, "failed to map registers\n"); 1689 1687 return -EIO; 1690 1688 } 1691 1689 ··· 1807 1807 1808 1808 /* clear out unclaimed reg detection bit */ 1809 1809 if (intel_uncore_unclaimed_mmio(uncore)) 1810 - DRM_DEBUG("unclaimed mmio detected on uncore init, clearing\n"); 1810 + drm_dbg(&i915->drm, "unclaimed mmio detected on uncore init, clearing\n"); 1811 1811 1812 1812 return 0; 1813 1813 ··· 2072 2072 2073 2073 if (unlikely(check_for_unclaimed_mmio(uncore))) { 2074 2074 if (!i915_modparams.mmio_debug) { 2075 - DRM_DEBUG("Unclaimed register detected, " 2076 - "enabling oneshot unclaimed register reporting. " 2077 - "Please use i915.mmio_debug=N for more information.\n"); 2075 + drm_dbg(&uncore->i915->drm, 2076 + "Unclaimed register detected, " 2077 + "enabling oneshot unclaimed register reporting. " 2078 + "Please use i915.mmio_debug=N for more information.\n"); 2078 2079 i915_modparams.mmio_debug++; 2079 2080 } 2080 2081 uncore->debug->unclaimed_mmio_check--;
+3 -2
drivers/gpu/drm/i915/intel_wakeref.c
··· 95 95 void __intel_wakeref_init(struct intel_wakeref *wf, 96 96 struct intel_runtime_pm *rpm, 97 97 const struct intel_wakeref_ops *ops, 98 - struct lock_class_key *key) 98 + struct intel_wakeref_lockclass *key) 99 99 { 100 100 wf->rpm = rpm; 101 101 wf->ops = ops; 102 102 103 - __mutex_init(&wf->mutex, "wakeref", key); 103 + __mutex_init(&wf->mutex, "wakeref.mutex", &key->mutex); 104 104 atomic_set(&wf->count, 0); 105 105 wf->wakeref = 0; 106 106 107 107 INIT_WORK(&wf->work, __intel_wakeref_put_work); 108 + lockdep_init_map(&wf->work.lockdep_map, "wakeref.work", &key->work, 0); 108 109 } 109 110 110 111 int intel_wakeref_wait_for_idle(struct intel_wakeref *wf)
+7 -2
drivers/gpu/drm/i915/intel_wakeref.h
··· 44 44 struct work_struct work; 45 45 }; 46 46 47 + struct intel_wakeref_lockclass { 48 + struct lock_class_key mutex; 49 + struct lock_class_key work; 50 + }; 51 + 47 52 void __intel_wakeref_init(struct intel_wakeref *wf, 48 53 struct intel_runtime_pm *rpm, 49 54 const struct intel_wakeref_ops *ops, 50 - struct lock_class_key *key); 55 + struct intel_wakeref_lockclass *key); 51 56 #define intel_wakeref_init(wf, rpm, ops) do { \ 52 - static struct lock_class_key __key; \ 57 + static struct intel_wakeref_lockclass __key; \ 53 58 \ 54 59 __intel_wakeref_init((wf), (rpm), (ops), &__key); \ 55 60 } while (0)
-7
drivers/gpu/drm/i915/oa/Makefile
··· 1 - # SPDX-License-Identifier: MIT 2 - 3 - # For building individual subdir files on the command line 4 - subdir-ccflags-y += -I$(srctree)/$(src)/.. 5 - 6 - # Extra header tests 7 - header-test-pattern-$(CONFIG_DRM_I915_WERROR) := *.h
-2
drivers/gpu/drm/i915/selftests/i915_gem.c
··· 124 124 * that runtime-pm just works. 125 125 */ 126 126 with_intel_runtime_pm(&i915->runtime_pm, wakeref) { 127 - intel_gt_sanitize(&i915->gt, false); 128 - 129 127 i915_gem_restore_gtt_mappings(i915); 130 128 i915_gem_restore_fences(&i915->ggtt); 131 129
+34 -44
drivers/gpu/drm/i915/selftests/i915_gem_gtt.c
··· 34 34 35 35 #include "mock_drm.h" 36 36 #include "mock_gem_device.h" 37 + #include "mock_gtt.h" 37 38 #include "igt_flush_test.h" 38 39 39 40 static void cleanup_freed_objects(struct drm_i915_private *i915) ··· 152 151 if (!HAS_PPGTT(dev_priv)) 153 152 return 0; 154 153 155 - ppgtt = __ppgtt_create(dev_priv); 154 + ppgtt = i915_ppgtt_create(&dev_priv->gt); 156 155 if (IS_ERR(ppgtt)) 157 156 return PTR_ERR(ppgtt); 158 157 ··· 207 206 return err; 208 207 } 209 208 210 - static int lowlevel_hole(struct drm_i915_private *i915, 211 - struct i915_address_space *vm, 209 + static int lowlevel_hole(struct i915_address_space *vm, 212 210 u64 hole_start, u64 hole_end, 213 211 unsigned long end_time) 214 212 { ··· 256 256 * memory. We expect to hit -ENOMEM. 257 257 */ 258 258 259 - obj = fake_dma_object(i915, BIT_ULL(size)); 259 + obj = fake_dma_object(vm->i915, BIT_ULL(size)); 260 260 if (IS_ERR(obj)) { 261 261 kfree(order); 262 262 break; ··· 291 291 mock_vma->node.size = BIT_ULL(size); 292 292 mock_vma->node.start = addr; 293 293 294 - with_intel_runtime_pm(&i915->runtime_pm, wakeref) 294 + with_intel_runtime_pm(vm->gt->uncore->rpm, wakeref) 295 295 vm->insert_entries(vm, mock_vma, 296 296 I915_CACHE_NONE, 0); 297 297 } ··· 303 303 intel_wakeref_t wakeref; 304 304 305 305 GEM_BUG_ON(addr + BIT_ULL(size) > vm->total); 306 - with_intel_runtime_pm(&i915->runtime_pm, wakeref) 306 + with_intel_runtime_pm(vm->gt->uncore->rpm, wakeref) 307 307 vm->clear_range(vm, addr, BIT_ULL(size)); 308 308 } 309 309 ··· 312 312 313 313 kfree(order); 314 314 315 - cleanup_freed_objects(i915); 315 + cleanup_freed_objects(vm->i915); 316 316 } 317 317 318 318 kfree(mock_vma); ··· 340 340 } 341 341 } 342 342 343 - static int fill_hole(struct drm_i915_private *i915, 344 - struct i915_address_space *vm, 343 + static int fill_hole(struct i915_address_space *vm, 345 344 u64 hole_start, u64 hole_end, 346 345 unsigned long end_time) 347 346 { ··· 373 374 { } 374 375 }, *p; 375 376 376 - obj = fake_dma_object(i915, full_size); 377 + obj = fake_dma_object(vm->i915, full_size); 377 378 if (IS_ERR(obj)) 378 379 break; 379 380 ··· 541 542 } 542 543 543 544 close_object_list(&objects, vm); 544 - cleanup_freed_objects(i915); 545 + cleanup_freed_objects(vm->i915); 545 546 } 546 547 547 548 return 0; ··· 551 552 return err; 552 553 } 553 554 554 - static int walk_hole(struct drm_i915_private *i915, 555 - struct i915_address_space *vm, 555 + static int walk_hole(struct i915_address_space *vm, 556 556 u64 hole_start, u64 hole_end, 557 557 unsigned long end_time) 558 558 { ··· 573 575 u64 addr; 574 576 int err = 0; 575 577 576 - obj = fake_dma_object(i915, size << PAGE_SHIFT); 578 + obj = fake_dma_object(vm->i915, size << PAGE_SHIFT); 577 579 if (IS_ERR(obj)) 578 580 break; 579 581 ··· 628 630 if (err) 629 631 return err; 630 632 631 - cleanup_freed_objects(i915); 633 + cleanup_freed_objects(vm->i915); 632 634 } 633 635 634 636 return 0; 635 637 } 636 638 637 - static int pot_hole(struct drm_i915_private *i915, 638 - struct i915_address_space *vm, 639 + static int pot_hole(struct i915_address_space *vm, 639 640 u64 hole_start, u64 hole_end, 640 641 unsigned long end_time) 641 642 { ··· 648 651 if (i915_is_ggtt(vm)) 649 652 flags |= PIN_GLOBAL; 650 653 651 - obj = i915_gem_object_create_internal(i915, 2 * I915_GTT_PAGE_SIZE); 654 + obj = i915_gem_object_create_internal(vm->i915, 2 * I915_GTT_PAGE_SIZE); 652 655 if (IS_ERR(obj)) 653 656 return PTR_ERR(obj); 654 657 ··· 709 712 return err; 710 713 } 711 714 712 - static int drunk_hole(struct drm_i915_private *i915, 713 - struct i915_address_space *vm, 715 + static int drunk_hole(struct i915_address_space *vm, 714 716 u64 hole_start, u64 hole_end, 715 717 unsigned long end_time) 716 718 { ··· 754 758 * memory. We expect to hit -ENOMEM. 755 759 */ 756 760 757 - obj = fake_dma_object(i915, BIT_ULL(size)); 761 + obj = fake_dma_object(vm->i915, BIT_ULL(size)); 758 762 if (IS_ERR(obj)) { 759 763 kfree(order); 760 764 break; ··· 812 816 if (err) 813 817 return err; 814 818 815 - cleanup_freed_objects(i915); 819 + cleanup_freed_objects(vm->i915); 816 820 } 817 821 818 822 return 0; 819 823 } 820 824 821 - static int __shrink_hole(struct drm_i915_private *i915, 822 - struct i915_address_space *vm, 825 + static int __shrink_hole(struct i915_address_space *vm, 823 826 u64 hole_start, u64 hole_end, 824 827 unsigned long end_time) 825 828 { ··· 835 840 u64 size = BIT_ULL(order++); 836 841 837 842 size = min(size, hole_end - addr); 838 - obj = fake_dma_object(i915, size); 843 + obj = fake_dma_object(vm->i915, size); 839 844 if (IS_ERR(obj)) { 840 845 err = PTR_ERR(obj); 841 846 break; ··· 889 894 } 890 895 891 896 close_object_list(&objects, vm); 892 - cleanup_freed_objects(i915); 897 + cleanup_freed_objects(vm->i915); 893 898 return err; 894 899 } 895 900 896 - static int shrink_hole(struct drm_i915_private *i915, 897 - struct i915_address_space *vm, 901 + static int shrink_hole(struct i915_address_space *vm, 898 902 u64 hole_start, u64 hole_end, 899 903 unsigned long end_time) 900 904 { ··· 905 911 906 912 for_each_prime_number_from(prime, 0, ULONG_MAX - 1) { 907 913 vm->fault_attr.interval = prime; 908 - err = __shrink_hole(i915, vm, hole_start, hole_end, end_time); 914 + err = __shrink_hole(vm, hole_start, hole_end, end_time); 909 915 if (err) 910 916 break; 911 917 } ··· 915 921 return err; 916 922 } 917 923 918 - static int shrink_boom(struct drm_i915_private *i915, 919 - struct i915_address_space *vm, 924 + static int shrink_boom(struct i915_address_space *vm, 920 925 u64 hole_start, u64 hole_end, 921 926 unsigned long end_time) 922 927 { ··· 937 944 unsigned int size = sizes[i]; 938 945 struct i915_vma *vma; 939 946 940 - purge = fake_dma_object(i915, size); 947 + purge = fake_dma_object(vm->i915, size); 941 948 if (IS_ERR(purge)) 942 949 return PTR_ERR(purge); 943 950 ··· 954 961 /* Should now be ripe for purging */ 955 962 i915_vma_unpin(vma); 956 963 957 - explode = fake_dma_object(i915, size); 964 + explode = fake_dma_object(vm->i915, size); 958 965 if (IS_ERR(explode)) { 959 966 err = PTR_ERR(explode); 960 967 goto err_purge; ··· 980 987 i915_gem_object_put(explode); 981 988 982 989 memset(&vm->fault_attr, 0, sizeof(vm->fault_attr)); 983 - cleanup_freed_objects(i915); 990 + cleanup_freed_objects(vm->i915); 984 991 } 985 992 986 993 return 0; ··· 994 1001 } 995 1002 996 1003 static int exercise_ppgtt(struct drm_i915_private *dev_priv, 997 - int (*func)(struct drm_i915_private *i915, 998 - struct i915_address_space *vm, 1004 + int (*func)(struct i915_address_space *vm, 999 1005 u64 hole_start, u64 hole_end, 1000 1006 unsigned long end_time)) 1001 1007 { ··· 1010 1018 if (IS_ERR(file)) 1011 1019 return PTR_ERR(file); 1012 1020 1013 - ppgtt = i915_ppgtt_create(dev_priv); 1021 + ppgtt = i915_ppgtt_create(&dev_priv->gt); 1014 1022 if (IS_ERR(ppgtt)) { 1015 1023 err = PTR_ERR(ppgtt); 1016 1024 goto out_free; ··· 1018 1026 GEM_BUG_ON(offset_in_page(ppgtt->vm.total)); 1019 1027 GEM_BUG_ON(!atomic_read(&ppgtt->vm.open)); 1020 1028 1021 - err = func(dev_priv, &ppgtt->vm, 0, ppgtt->vm.total, end_time); 1029 + err = func(&ppgtt->vm, 0, ppgtt->vm.total, end_time); 1022 1030 1023 1031 i915_vm_put(&ppgtt->vm); 1024 1032 ··· 1074 1082 } 1075 1083 1076 1084 static int exercise_ggtt(struct drm_i915_private *i915, 1077 - int (*func)(struct drm_i915_private *i915, 1078 - struct i915_address_space *vm, 1085 + int (*func)(struct i915_address_space *vm, 1079 1086 u64 hole_start, u64 hole_end, 1080 1087 unsigned long end_time)) 1081 1088 { ··· 1096 1105 if (hole_start >= hole_end) 1097 1106 continue; 1098 1107 1099 - err = func(i915, &ggtt->vm, hole_start, hole_end, end_time); 1108 + err = func(&ggtt->vm, hole_start, hole_end, end_time); 1100 1109 if (err) 1101 1110 break; 1102 1111 ··· 1243 1252 } 1244 1253 1245 1254 static int exercise_mock(struct drm_i915_private *i915, 1246 - int (*func)(struct drm_i915_private *i915, 1247 - struct i915_address_space *vm, 1255 + int (*func)(struct i915_address_space *vm, 1248 1256 u64 hole_start, u64 hole_end, 1249 1257 unsigned long end_time)) 1250 1258 { ··· 1258 1268 return -ENOMEM; 1259 1269 1260 1270 vm = i915_gem_context_get_vm_rcu(ctx); 1261 - err = func(i915, vm, 0, min(vm->total, limit), end_time); 1271 + err = func(vm, 0, min(vm->total, limit), end_time); 1262 1272 i915_vm_put(vm); 1263 1273 1264 1274 mock_context_close(ctx);
+7 -1
drivers/gpu/drm/i915/selftests/i915_live_selftests.h
··· 1 1 /* SPDX-License-Identifier: GPL-2.0 */ 2 - /* List each unit test as selftest(name, function) 2 + 3 + #ifndef selftest 4 + #define selftest(x, y) 5 + #endif 6 + 7 + /* 8 + * List each unit test as selftest(name, function) 3 9 * 4 10 * The name is used as both an enum and expanded as subtest__name to create 5 11 * a module parameter. It must be unique and legal for a C identifier.
+7 -1
drivers/gpu/drm/i915/selftests/i915_mock_selftests.h
··· 1 1 /* SPDX-License-Identifier: GPL-2.0 */ 2 - /* List each unit test as selftest(name, function) 2 + 3 + #ifndef selftest 4 + #define selftest(x, y) 5 + #endif 6 + 7 + /* 8 + * List each unit test as selftest(name, function) 3 9 * 4 10 * The name is used as both an enum and expanded as subtest__name to create 5 11 * a module parameter. It must be unique and legal for a C identifier.
+7 -1
drivers/gpu/drm/i915/selftests/i915_perf_selftests.h
··· 1 1 /* SPDX-License-Identifier: GPL-2.0 */ 2 - /* List each unit test as selftest(name, function) 2 + 3 + #ifndef selftest 4 + #define selftest(x, y) 5 + #endif 6 + 7 + /* 8 + * List each unit test as selftest(name, function) 3 9 * 4 10 * The name is used as both an enum and expanded as subtest__name to create 5 11 * a module parameter. It must be unique and legal for a C identifier.
+1
drivers/gpu/drm/i915/selftests/i915_random.h
··· 25 25 #ifndef __I915_SELFTESTS_RANDOM_H__ 26 26 #define __I915_SELFTESTS_RANDOM_H__ 27 27 28 + #include <linux/math64.h> 28 29 #include <linux/random.h> 29 30 30 31 #include "../i915_selftest.h"
+47
drivers/gpu/drm/i915/selftests/igt_atomic.c
··· 1 + // SPDX-License-Identifier: MIT 2 + /* 3 + * Copyright © 2018 Intel Corporation 4 + */ 5 + 6 + #include <linux/preempt.h> 7 + #include <linux/bottom_half.h> 8 + #include <linux/irqflags.h> 9 + 10 + #include "igt_atomic.h" 11 + 12 + static void __preempt_begin(void) 13 + { 14 + preempt_disable(); 15 + } 16 + 17 + static void __preempt_end(void) 18 + { 19 + preempt_enable(); 20 + } 21 + 22 + static void __softirq_begin(void) 23 + { 24 + local_bh_disable(); 25 + } 26 + 27 + static void __softirq_end(void) 28 + { 29 + local_bh_enable(); 30 + } 31 + 32 + static void __hardirq_begin(void) 33 + { 34 + local_irq_disable(); 35 + } 36 + 37 + static void __hardirq_end(void) 38 + { 39 + local_irq_enable(); 40 + } 41 + 42 + const struct igt_atomic_section igt_atomic_phases[] = { 43 + { "preempt", __preempt_begin, __preempt_end }, 44 + { "softirq", __softirq_begin, __softirq_end }, 45 + { "hardirq", __hardirq_begin, __hardirq_end }, 46 + { } 47 + };
+1 -40
drivers/gpu/drm/i915/selftests/igt_atomic.h
··· 6 6 #ifndef IGT_ATOMIC_H 7 7 #define IGT_ATOMIC_H 8 8 9 - #include <linux/preempt.h> 10 - #include <linux/bottom_half.h> 11 - #include <linux/irqflags.h> 12 - 13 - static void __preempt_begin(void) 14 - { 15 - preempt_disable(); 16 - } 17 - 18 - static void __preempt_end(void) 19 - { 20 - preempt_enable(); 21 - } 22 - 23 - static void __softirq_begin(void) 24 - { 25 - local_bh_disable(); 26 - } 27 - 28 - static void __softirq_end(void) 29 - { 30 - local_bh_enable(); 31 - } 32 - 33 - static void __hardirq_begin(void) 34 - { 35 - local_irq_disable(); 36 - } 37 - 38 - static void __hardirq_end(void) 39 - { 40 - local_irq_enable(); 41 - } 42 - 43 9 struct igt_atomic_section { 44 10 const char *name; 45 11 void (*critical_section_begin)(void); 46 12 void (*critical_section_end)(void); 47 13 }; 48 14 49 - static const struct igt_atomic_section igt_atomic_phases[] = { 50 - { "preempt", __preempt_begin, __preempt_end }, 51 - { "softirq", __softirq_begin, __softirq_end }, 52 - { "hardirq", __hardirq_begin, __hardirq_end }, 53 - { } 54 - }; 15 + extern const struct igt_atomic_section igt_atomic_phases[]; 55 16 56 17 #endif /* IGT_ATOMIC_H */
+1 -1
drivers/gpu/drm/i915/selftests/igt_live_test.h
··· 7 7 #ifndef IGT_LIVE_TEST_H 8 8 #define IGT_LIVE_TEST_H 9 9 10 - #include "../i915_gem.h" 10 + #include "gt/intel_engine.h" /* for I915_NUM_ENGINES */ 11 11 12 12 struct drm_i915_private; 13 13
+14 -19
drivers/gpu/drm/i915/selftests/intel_memory_region.c
··· 270 270 271 271 static int igt_cpu_check(struct drm_i915_gem_object *obj, u32 dword, u32 val) 272 272 { 273 - unsigned long n; 273 + unsigned long n = obj->base.size >> PAGE_SHIFT; 274 + u32 *ptr; 274 275 int err; 275 276 276 - i915_gem_object_lock(obj); 277 - err = i915_gem_object_set_to_wc_domain(obj, false); 278 - i915_gem_object_unlock(obj); 277 + err = i915_gem_object_wait(obj, 0, MAX_SCHEDULE_TIMEOUT); 279 278 if (err) 280 279 return err; 281 280 282 - err = i915_gem_object_pin_pages(obj); 283 - if (err) 284 - return err; 281 + ptr = i915_gem_object_pin_map(obj, I915_MAP_WC); 282 + if (IS_ERR(ptr)) 283 + return PTR_ERR(ptr); 285 284 286 - for (n = 0; n < obj->base.size >> PAGE_SHIFT; ++n) { 287 - u32 __iomem *base; 288 - u32 read_val; 289 - 290 - base = i915_gem_object_lmem_io_map_page_atomic(obj, n); 291 - 292 - read_val = ioread32(base + dword); 293 - io_mapping_unmap_atomic(base); 294 - if (read_val != val) { 295 - pr_err("n=%lu base[%u]=%u, val=%u\n", 296 - n, dword, read_val, val); 285 + ptr += dword; 286 + while (n--) { 287 + if (*ptr != val) { 288 + pr_err("base[%u]=%08x, val=%08x\n", 289 + dword, *ptr, val); 297 290 err = -EINVAL; 298 291 break; 299 292 } 293 + 294 + ptr += PAGE_SIZE / sizeof(*ptr); 300 295 } 301 296 302 - i915_gem_object_unpin_pages(obj); 297 + i915_gem_object_unpin_map(obj); 303 298 return err; 304 299 } 305 300
+3
drivers/gpu/drm/i915/selftests/mock_gem_device.c
··· 58 58 mock_device_flush(i915); 59 59 intel_gt_driver_remove(&i915->gt); 60 60 61 + i915_gem_driver_release__contexts(i915); 62 + 61 63 i915_gem_drain_workqueue(i915); 62 64 i915_gem_drain_freed_objects(i915); 63 65 ··· 186 184 if (mock_engine_init(i915->engine[RCS0])) 187 185 goto err_context; 188 186 187 + __clear_bit(I915_WEDGED, &i915->gt.reset.flags); 189 188 intel_engines_driver_register(i915); 190 189 191 190 return i915;
+7 -2
drivers/gpu/drm/i915/selftests/mock_gtt.c
··· 55 55 { 56 56 } 57 57 58 + static void mock_clear_range(struct i915_address_space *vm, 59 + u64 start, u64 length) 60 + { 61 + } 62 + 58 63 struct i915_ppgtt *mock_ppgtt(struct drm_i915_private *i915, const char *name) 59 64 { 60 65 struct i915_ppgtt *ppgtt; ··· 75 70 76 71 i915_address_space_init(&ppgtt->vm, VM_CLASS_PPGTT); 77 72 78 - ppgtt->vm.clear_range = nop_clear_range; 73 + ppgtt->vm.clear_range = mock_clear_range; 79 74 ppgtt->vm.insert_page = mock_insert_page; 80 75 ppgtt->vm.insert_entries = mock_insert_entries; 81 76 ppgtt->vm.cleanup = mock_cleanup; ··· 112 107 ggtt->mappable_end = resource_size(&ggtt->gmadr); 113 108 ggtt->vm.total = 4096 * PAGE_SIZE; 114 109 115 - ggtt->vm.clear_range = nop_clear_range; 110 + ggtt->vm.clear_range = mock_clear_range; 116 111 ggtt->vm.insert_page = mock_insert_page; 117 112 ggtt->vm.insert_entries = mock_insert_entries; 118 113 ggtt->vm.cleanup = mock_cleanup;
-19
drivers/mfd/intel_soc_pmic_core.c
··· 9 9 */ 10 10 11 11 #include <linux/acpi.h> 12 - #include <linux/gpio/consumer.h> 13 - #include <linux/gpio/machine.h> 14 12 #include <linux/i2c.h> 15 13 #include <linux/interrupt.h> 16 14 #include <linux/module.h> ··· 22 24 /* Crystal Cove PMIC shares same ACPI ID between different platforms */ 23 25 #define BYT_CRC_HRV 2 24 26 #define CHT_CRC_HRV 3 25 - 26 - /* Lookup table for the Panel Enable/Disable line as GPIO signals */ 27 - static struct gpiod_lookup_table panel_gpio_table = { 28 - /* Intel GFX is consumer */ 29 - .dev_id = "0000:00:02.0", 30 - .table = { 31 - /* Panel EN/DISABLE */ 32 - GPIO_LOOKUP("gpio_crystalcove", 94, "panel", GPIO_ACTIVE_HIGH), 33 - { }, 34 - }, 35 - }; 36 27 37 28 /* PWM consumed by the Intel GFX */ 38 29 static struct pwm_lookup crc_pwm_lookup[] = { ··· 83 96 if (ret) 84 97 dev_warn(dev, "Can't enable IRQ as wake source: %d\n", ret); 85 98 86 - /* Add lookup table binding for Panel Control to the GPIO Chip */ 87 - gpiod_add_lookup_table(&panel_gpio_table); 88 - 89 99 /* Add lookup table for crc-pwm */ 90 100 pwm_add_table(crc_pwm_lookup, ARRAY_SIZE(crc_pwm_lookup)); 91 101 ··· 104 120 struct intel_soc_pmic *pmic = dev_get_drvdata(&i2c->dev); 105 121 106 122 regmap_del_irq_chip(pmic->irq, pmic->irq_chip_data); 107 - 108 - /* Remove lookup table for Panel Control from the GPIO Chip */ 109 - gpiod_remove_lookup_table(&panel_gpio_table); 110 123 111 124 /* remove crc-pwm lookup table */ 112 125 pwm_remove_table(crc_pwm_lookup, ARRAY_SIZE(crc_pwm_lookup));
+17 -26
drivers/pinctrl/core.c
··· 1376 1376 } 1377 1377 EXPORT_SYMBOL_GPL(devm_pinctrl_put); 1378 1378 1379 - int pinctrl_register_map(const struct pinctrl_map *maps, unsigned num_maps, 1380 - bool dup) 1379 + /** 1380 + * pinctrl_register_mappings() - register a set of pin controller mappings 1381 + * @maps: the pincontrol mappings table to register. Note the pinctrl-core 1382 + * keeps a reference to the passed in maps, so they should _not_ be 1383 + * marked with __initdata. 1384 + * @num_maps: the number of maps in the mapping table 1385 + */ 1386 + int pinctrl_register_mappings(const struct pinctrl_map *maps, 1387 + unsigned num_maps) 1381 1388 { 1382 1389 int i, ret; 1383 1390 struct pinctrl_maps *maps_node; ··· 1437 1430 if (!maps_node) 1438 1431 return -ENOMEM; 1439 1432 1433 + maps_node->maps = maps; 1440 1434 maps_node->num_maps = num_maps; 1441 - if (dup) { 1442 - maps_node->maps = kmemdup(maps, sizeof(*maps) * num_maps, 1443 - GFP_KERNEL); 1444 - if (!maps_node->maps) { 1445 - kfree(maps_node); 1446 - return -ENOMEM; 1447 - } 1448 - } else { 1449 - maps_node->maps = maps; 1450 - } 1451 1435 1452 1436 mutex_lock(&pinctrl_maps_mutex); 1453 1437 list_add_tail(&maps_node->node, &pinctrl_maps); ··· 1446 1448 1447 1449 return 0; 1448 1450 } 1449 - 1450 - /** 1451 - * pinctrl_register_mappings() - register a set of pin controller mappings 1452 - * @maps: the pincontrol mappings table to register. This should probably be 1453 - * marked with __initdata so it can be discarded after boot. This 1454 - * function will perform a shallow copy for the mapping entries. 1455 - * @num_maps: the number of maps in the mapping table 1456 - */ 1457 - int pinctrl_register_mappings(const struct pinctrl_map *maps, 1458 - unsigned num_maps) 1459 - { 1460 - return pinctrl_register_map(maps, num_maps, true); 1461 - } 1462 1451 EXPORT_SYMBOL_GPL(pinctrl_register_mappings); 1463 1452 1464 - void pinctrl_unregister_map(const struct pinctrl_map *map) 1453 + /** 1454 + * pinctrl_unregister_mappings() - unregister a set of pin controller mappings 1455 + * @maps: the pincontrol mappings table passed to pinctrl_register_mappings() 1456 + * when registering the mappings. 1457 + */ 1458 + void pinctrl_unregister_mappings(const struct pinctrl_map *map) 1465 1459 { 1466 1460 struct pinctrl_maps *maps_node; 1467 1461 ··· 1468 1478 } 1469 1479 mutex_unlock(&pinctrl_maps_mutex); 1470 1480 } 1481 + EXPORT_SYMBOL_GPL(pinctrl_unregister_mappings); 1471 1482 1472 1483 /** 1473 1484 * pinctrl_force_sleep() - turn a given controller device into sleep state
-4
drivers/pinctrl/core.h
··· 236 236 pinctrl_find_gpio_range_from_pin_nolock(struct pinctrl_dev *pctldev, 237 237 unsigned int pin); 238 238 239 - int pinctrl_register_map(const struct pinctrl_map *maps, unsigned num_maps, 240 - bool dup); 241 - void pinctrl_unregister_map(const struct pinctrl_map *map); 242 - 243 239 extern int pinctrl_force_sleep(struct pinctrl_dev *pctldev); 244 240 extern int pinctrl_force_default(struct pinctrl_dev *pctldev); 245 241
+2 -2
drivers/pinctrl/devicetree.c
··· 51 51 struct pinctrl_dt_map *dt_map, *n1; 52 52 53 53 list_for_each_entry_safe(dt_map, n1, &p->dt_maps, node) { 54 - pinctrl_unregister_map(dt_map->map); 54 + pinctrl_unregister_mappings(dt_map->map); 55 55 list_del(&dt_map->node); 56 56 dt_free_map(dt_map->pctldev, dt_map->map, 57 57 dt_map->num_maps); ··· 92 92 dt_map->num_maps = num_maps; 93 93 list_add_tail(&dt_map->node, &p->dt_maps); 94 94 95 - return pinctrl_register_map(map, num_maps, false); 95 + return pinctrl_register_mappings(map, num_maps); 96 96 97 97 err_free_map: 98 98 dt_free_map(pctldev, map, num_maps);
+4 -4
include/drm/drm_fourcc.h
··· 78 78 * triplet @char_per_block, @block_w, @block_h for better 79 79 * describing the pixel format. 80 80 */ 81 - u8 cpp[3]; 81 + u8 cpp[4]; 82 82 83 83 /** 84 84 * @char_per_block: ··· 104 104 * information from their drm_mode_config.get_format_info hook 105 105 * if they want the core to be validating the pitch. 106 106 */ 107 - u8 char_per_block[3]; 107 + u8 char_per_block[4]; 108 108 }; 109 109 110 110 /** ··· 113 113 * Block width in pixels, this is intended to be accessed through 114 114 * drm_format_info_block_width() 115 115 */ 116 - u8 block_w[3]; 116 + u8 block_w[4]; 117 117 118 118 /** 119 119 * @block_h: ··· 121 121 * Block height in pixels, this is intended to be accessed through 122 122 * drm_format_info_block_height() 123 123 */ 124 - u8 block_h[3]; 124 + u8 block_h[4]; 125 125 126 126 /** @hsub: Horizontal chroma subsampling factor */ 127 127 u8 hsub;
+5
include/linux/pinctrl/machine.h
··· 153 153 154 154 extern int pinctrl_register_mappings(const struct pinctrl_map *map, 155 155 unsigned num_maps); 156 + extern void pinctrl_unregister_mappings(const struct pinctrl_map *map); 156 157 extern void pinctrl_provide_dummies(void); 157 158 #else 158 159 ··· 161 160 unsigned num_maps) 162 161 { 163 162 return 0; 163 + } 164 + 165 + static inline void pinctrl_unregister_mappings(const struct pinctrl_map *map) 166 + { 164 167 } 165 168 166 169 static inline void pinctrl_provide_dummies(void)
+13
include/uapi/drm/drm_fourcc.h
··· 422 422 #define I915_FORMAT_MOD_Y_TILED_GEN12_RC_CCS fourcc_mod_code(INTEL, 6) 423 423 424 424 /* 425 + * Intel color control surfaces (CCS) for Gen-12 media compression 426 + * 427 + * The main surface is Y-tiled and at plane index 0, the CCS is linear and 428 + * at index 1. A 64B CCS cache line corresponds to an area of 4x1 tiles in 429 + * main surface. In other words, 4 bits in CCS map to a main surface cache 430 + * line pair. The main surface pitch is required to be a multiple of four 431 + * Y-tile widths. For semi-planar formats like NV12, CCS planes follow the 432 + * Y and UV planes i.e., planes 0 and 1 are used for Y and UV surfaces, 433 + * planes 2 and 3 for the respective CCS. 434 + */ 435 + #define I915_FORMAT_MOD_Y_TILED_GEN12_MC_CCS fourcc_mod_code(INTEL, 7) 436 + 437 + /* 425 438 * Tiled, NV12MT, grouped in 64 (pixels) x 32 (lines) -sized macroblocks 426 439 * 427 440 * Macroblocks are laid in a Z-shape, and each pixel data is following the