Rodrigo Vivi | 0bc12bc | 2014-11-14 08:52:28 -0800 | [diff] [blame] | 1 | /* |
| 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 |
| 21 | * DEALINGS IN THE SOFTWARE. |
| 22 | */ |
| 23 | |
Rodrigo Vivi | b2b89f5 | 2014-11-14 08:52:29 -0800 | [diff] [blame] | 24 | /** |
| 25 | * DOC: Panel Self Refresh (PSR/SRD) |
| 26 | * |
| 27 | * Since Haswell Display controller supports Panel Self-Refresh on display |
| 28 | * panels witch have a remote frame buffer (RFB) implemented according to PSR |
| 29 | * spec in eDP1.3. PSR feature allows the display to go to lower standby states |
| 30 | * when system is idle but display is on as it eliminates display refresh |
| 31 | * request to DDR memory completely as long as the frame buffer for that |
| 32 | * display is unchanged. |
| 33 | * |
| 34 | * Panel Self Refresh must be supported by both Hardware (source) and |
| 35 | * Panel (sink). |
| 36 | * |
| 37 | * PSR saves power by caching the framebuffer in the panel RFB, which allows us |
| 38 | * to power down the link and memory controller. For DSI panels the same idea |
| 39 | * is called "manual mode". |
| 40 | * |
| 41 | * The implementation uses the hardware-based PSR support which automatically |
| 42 | * enters/exits self-refresh mode. The hardware takes care of sending the |
| 43 | * required DP aux message and could even retrain the link (that part isn't |
| 44 | * enabled yet though). The hardware also keeps track of any frontbuffer |
| 45 | * changes to know when to exit self-refresh mode again. Unfortunately that |
| 46 | * part doesn't work too well, hence why the i915 PSR support uses the |
| 47 | * software frontbuffer tracking to make sure it doesn't miss a screen |
| 48 | * update. For this integration intel_psr_invalidate() and intel_psr_flush() |
| 49 | * get called by the frontbuffer tracking code. Note that because of locking |
| 50 | * issues the self-refresh re-enable code is done from a work queue, which |
| 51 | * must be correctly synchronized/cancelled when shutting down the pipe." |
| 52 | */ |
| 53 | |
Rodrigo Vivi | 0bc12bc | 2014-11-14 08:52:28 -0800 | [diff] [blame] | 54 | #include <drm/drmP.h> |
| 55 | |
| 56 | #include "intel_drv.h" |
| 57 | #include "i915_drv.h" |
| 58 | |
| 59 | static bool is_edp_psr(struct intel_dp *intel_dp) |
| 60 | { |
| 61 | return intel_dp->psr_dpcd[0] & DP_PSR_IS_SUPPORTED; |
| 62 | } |
| 63 | |
| 64 | bool intel_psr_is_enabled(struct drm_device *dev) |
| 65 | { |
| 66 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 67 | |
| 68 | if (!HAS_PSR(dev)) |
| 69 | return false; |
| 70 | |
| 71 | return I915_READ(EDP_PSR_CTL(dev)) & EDP_PSR_ENABLE; |
| 72 | } |
| 73 | |
| 74 | static void intel_psr_write_vsc(struct intel_dp *intel_dp, |
| 75 | struct edp_vsc_psr *vsc_psr) |
| 76 | { |
| 77 | struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp); |
| 78 | struct drm_device *dev = dig_port->base.base.dev; |
| 79 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 80 | struct intel_crtc *crtc = to_intel_crtc(dig_port->base.base.crtc); |
| 81 | u32 ctl_reg = HSW_TVIDEO_DIP_CTL(crtc->config.cpu_transcoder); |
| 82 | u32 data_reg = HSW_TVIDEO_DIP_VSC_DATA(crtc->config.cpu_transcoder); |
| 83 | uint32_t *data = (uint32_t *) vsc_psr; |
| 84 | unsigned int i; |
| 85 | |
| 86 | /* As per BSPec (Pipe Video Data Island Packet), we need to disable |
| 87 | the video DIP being updated before program video DIP data buffer |
| 88 | registers for DIP being updated. */ |
| 89 | I915_WRITE(ctl_reg, 0); |
| 90 | POSTING_READ(ctl_reg); |
| 91 | |
| 92 | for (i = 0; i < VIDEO_DIP_VSC_DATA_SIZE; i += 4) { |
| 93 | if (i < sizeof(struct edp_vsc_psr)) |
| 94 | I915_WRITE(data_reg + i, *data++); |
| 95 | else |
| 96 | I915_WRITE(data_reg + i, 0); |
| 97 | } |
| 98 | |
| 99 | I915_WRITE(ctl_reg, VIDEO_DIP_ENABLE_VSC_HSW); |
| 100 | POSTING_READ(ctl_reg); |
| 101 | } |
| 102 | |
| 103 | static void intel_psr_setup_vsc(struct intel_dp *intel_dp) |
| 104 | { |
| 105 | struct edp_vsc_psr psr_vsc; |
| 106 | |
| 107 | /* Prepare VSC packet as per EDP 1.3 spec, Table 3.10 */ |
| 108 | memset(&psr_vsc, 0, sizeof(psr_vsc)); |
| 109 | psr_vsc.sdp_header.HB0 = 0; |
| 110 | psr_vsc.sdp_header.HB1 = 0x7; |
| 111 | psr_vsc.sdp_header.HB2 = 0x2; |
| 112 | psr_vsc.sdp_header.HB3 = 0x8; |
| 113 | intel_psr_write_vsc(intel_dp, &psr_vsc); |
| 114 | } |
| 115 | |
| 116 | static void intel_psr_enable_sink(struct intel_dp *intel_dp) |
| 117 | { |
| 118 | struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp); |
| 119 | struct drm_device *dev = dig_port->base.base.dev; |
| 120 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 121 | uint32_t aux_clock_divider; |
| 122 | int precharge = 0x3; |
| 123 | bool only_standby = false; |
| 124 | static const uint8_t aux_msg[] = { |
| 125 | [0] = DP_AUX_NATIVE_WRITE << 4, |
| 126 | [1] = DP_SET_POWER >> 8, |
| 127 | [2] = DP_SET_POWER & 0xff, |
| 128 | [3] = 1 - 1, |
| 129 | [4] = DP_SET_POWER_D0, |
| 130 | }; |
| 131 | int i; |
| 132 | |
| 133 | BUILD_BUG_ON(sizeof(aux_msg) > 20); |
| 134 | |
| 135 | aux_clock_divider = intel_dp->get_aux_clock_divider(intel_dp, 0); |
| 136 | |
| 137 | if (IS_BROADWELL(dev) && dig_port->port != PORT_A) |
| 138 | only_standby = true; |
| 139 | |
| 140 | /* Enable PSR in sink */ |
| 141 | if (intel_dp->psr_dpcd[1] & DP_PSR_NO_TRAIN_ON_EXIT || only_standby) |
| 142 | drm_dp_dpcd_writeb(&intel_dp->aux, DP_PSR_EN_CFG, |
| 143 | DP_PSR_ENABLE & ~DP_PSR_MAIN_LINK_ACTIVE); |
| 144 | else |
| 145 | drm_dp_dpcd_writeb(&intel_dp->aux, DP_PSR_EN_CFG, |
| 146 | DP_PSR_ENABLE | DP_PSR_MAIN_LINK_ACTIVE); |
| 147 | |
| 148 | /* Setup AUX registers */ |
| 149 | for (i = 0; i < sizeof(aux_msg); i += 4) |
| 150 | I915_WRITE(EDP_PSR_AUX_DATA1(dev) + i, |
| 151 | intel_dp_pack_aux(&aux_msg[i], sizeof(aux_msg) - i)); |
| 152 | |
| 153 | I915_WRITE(EDP_PSR_AUX_CTL(dev), |
| 154 | DP_AUX_CH_CTL_TIME_OUT_400us | |
| 155 | (sizeof(aux_msg) << DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT) | |
| 156 | (precharge << DP_AUX_CH_CTL_PRECHARGE_2US_SHIFT) | |
| 157 | (aux_clock_divider << DP_AUX_CH_CTL_BIT_CLOCK_2X_SHIFT)); |
| 158 | } |
| 159 | |
| 160 | static void intel_psr_enable_source(struct intel_dp *intel_dp) |
| 161 | { |
| 162 | struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp); |
| 163 | struct drm_device *dev = dig_port->base.base.dev; |
| 164 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 165 | uint32_t max_sleep_time = 0x1f; |
Rodrigo Vivi | d44b4dc | 2014-11-14 08:52:31 -0800 | [diff] [blame^] | 166 | /* Lately it was identified that depending on panel idle frame count |
| 167 | * calculated at HW can be off by 1. So let's use what came |
| 168 | * from VBT + 1 and at minimum 2 to be on the safe side. |
| 169 | */ |
| 170 | uint32_t idle_frames = dev_priv->vbt.psr.idle_frames ? |
| 171 | dev_priv->vbt.psr.idle_frames + 1 : 2; |
Rodrigo Vivi | 0bc12bc | 2014-11-14 08:52:28 -0800 | [diff] [blame] | 172 | uint32_t val = 0x0; |
| 173 | const uint32_t link_entry_time = EDP_PSR_MIN_LINK_ENTRY_TIME_8_LINES; |
| 174 | bool only_standby = false; |
| 175 | |
| 176 | if (IS_BROADWELL(dev) && dig_port->port != PORT_A) |
| 177 | only_standby = true; |
| 178 | |
| 179 | if (intel_dp->psr_dpcd[1] & DP_PSR_NO_TRAIN_ON_EXIT || only_standby) { |
| 180 | val |= EDP_PSR_LINK_STANDBY; |
| 181 | val |= EDP_PSR_TP2_TP3_TIME_0us; |
| 182 | val |= EDP_PSR_TP1_TIME_0us; |
| 183 | val |= EDP_PSR_SKIP_AUX_EXIT; |
| 184 | val |= IS_BROADWELL(dev) ? BDW_PSR_SINGLE_FRAME : 0; |
| 185 | } else |
| 186 | val |= EDP_PSR_LINK_DISABLE; |
| 187 | |
| 188 | I915_WRITE(EDP_PSR_CTL(dev), val | |
| 189 | (IS_BROADWELL(dev) ? 0 : link_entry_time) | |
| 190 | max_sleep_time << EDP_PSR_MAX_SLEEP_TIME_SHIFT | |
| 191 | idle_frames << EDP_PSR_IDLE_FRAME_SHIFT | |
| 192 | EDP_PSR_ENABLE); |
| 193 | } |
| 194 | |
| 195 | static bool intel_psr_match_conditions(struct intel_dp *intel_dp) |
| 196 | { |
| 197 | struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp); |
| 198 | struct drm_device *dev = dig_port->base.base.dev; |
| 199 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 200 | struct drm_crtc *crtc = dig_port->base.base.crtc; |
| 201 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 202 | |
| 203 | lockdep_assert_held(&dev_priv->psr.lock); |
| 204 | WARN_ON(!drm_modeset_is_locked(&dev->mode_config.connection_mutex)); |
| 205 | WARN_ON(!drm_modeset_is_locked(&crtc->mutex)); |
| 206 | |
| 207 | dev_priv->psr.source_ok = false; |
| 208 | |
| 209 | if (IS_HASWELL(dev) && dig_port->port != PORT_A) { |
| 210 | DRM_DEBUG_KMS("HSW ties PSR to DDI A (eDP)\n"); |
| 211 | return false; |
| 212 | } |
| 213 | |
| 214 | if (!i915.enable_psr) { |
| 215 | DRM_DEBUG_KMS("PSR disable by flag\n"); |
| 216 | return false; |
| 217 | } |
| 218 | |
| 219 | /* Below limitations aren't valid for Broadwell */ |
| 220 | if (IS_BROADWELL(dev)) |
| 221 | goto out; |
| 222 | |
| 223 | if (I915_READ(HSW_STEREO_3D_CTL(intel_crtc->config.cpu_transcoder)) & |
| 224 | S3D_ENABLE) { |
| 225 | DRM_DEBUG_KMS("PSR condition failed: Stereo 3D is Enabled\n"); |
| 226 | return false; |
| 227 | } |
| 228 | |
| 229 | if (intel_crtc->config.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE) { |
| 230 | DRM_DEBUG_KMS("PSR condition failed: Interlaced is Enabled\n"); |
| 231 | return false; |
| 232 | } |
| 233 | |
| 234 | out: |
| 235 | dev_priv->psr.source_ok = true; |
| 236 | return true; |
| 237 | } |
| 238 | |
| 239 | static void intel_psr_do_enable(struct intel_dp *intel_dp) |
| 240 | { |
| 241 | struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp); |
| 242 | struct drm_device *dev = intel_dig_port->base.base.dev; |
| 243 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 244 | |
| 245 | WARN_ON(I915_READ(EDP_PSR_CTL(dev)) & EDP_PSR_ENABLE); |
| 246 | WARN_ON(dev_priv->psr.active); |
| 247 | lockdep_assert_held(&dev_priv->psr.lock); |
| 248 | |
| 249 | /* Enable/Re-enable PSR on the host */ |
| 250 | intel_psr_enable_source(intel_dp); |
| 251 | |
| 252 | dev_priv->psr.active = true; |
| 253 | } |
| 254 | |
Rodrigo Vivi | b2b89f5 | 2014-11-14 08:52:29 -0800 | [diff] [blame] | 255 | /** |
| 256 | * intel_psr_enable - Enable PSR |
| 257 | * @intel_dp: Intel DP |
| 258 | * |
| 259 | * This function can only be called after the pipe is fully trained and enabled. |
| 260 | */ |
Rodrigo Vivi | 0bc12bc | 2014-11-14 08:52:28 -0800 | [diff] [blame] | 261 | void intel_psr_enable(struct intel_dp *intel_dp) |
| 262 | { |
| 263 | struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp); |
| 264 | struct drm_device *dev = intel_dig_port->base.base.dev; |
| 265 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 266 | |
| 267 | if (!HAS_PSR(dev)) { |
| 268 | DRM_DEBUG_KMS("PSR not supported on this platform\n"); |
| 269 | return; |
| 270 | } |
| 271 | |
| 272 | if (!is_edp_psr(intel_dp)) { |
| 273 | DRM_DEBUG_KMS("PSR not supported by this panel\n"); |
| 274 | return; |
| 275 | } |
| 276 | |
| 277 | mutex_lock(&dev_priv->psr.lock); |
| 278 | if (dev_priv->psr.enabled) { |
| 279 | DRM_DEBUG_KMS("PSR already in use\n"); |
| 280 | goto unlock; |
| 281 | } |
| 282 | |
| 283 | if (!intel_psr_match_conditions(intel_dp)) |
| 284 | goto unlock; |
| 285 | |
| 286 | dev_priv->psr.busy_frontbuffer_bits = 0; |
| 287 | |
| 288 | intel_psr_setup_vsc(intel_dp); |
| 289 | |
| 290 | /* Avoid continuous PSR exit by masking memup and hpd */ |
| 291 | I915_WRITE(EDP_PSR_DEBUG_CTL(dev), EDP_PSR_DEBUG_MASK_MEMUP | |
| 292 | EDP_PSR_DEBUG_MASK_HPD | EDP_PSR_DEBUG_MASK_LPSP); |
| 293 | |
| 294 | /* Enable PSR on the panel */ |
| 295 | intel_psr_enable_sink(intel_dp); |
| 296 | |
| 297 | dev_priv->psr.enabled = intel_dp; |
| 298 | unlock: |
| 299 | mutex_unlock(&dev_priv->psr.lock); |
| 300 | } |
| 301 | |
Rodrigo Vivi | b2b89f5 | 2014-11-14 08:52:29 -0800 | [diff] [blame] | 302 | /** |
| 303 | * intel_psr_disable - Disable PSR |
| 304 | * @intel_dp: Intel DP |
| 305 | * |
| 306 | * This function needs to be called before disabling pipe. |
| 307 | */ |
Rodrigo Vivi | 0bc12bc | 2014-11-14 08:52:28 -0800 | [diff] [blame] | 308 | void intel_psr_disable(struct intel_dp *intel_dp) |
| 309 | { |
| 310 | struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp); |
| 311 | struct drm_device *dev = intel_dig_port->base.base.dev; |
| 312 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 313 | |
| 314 | mutex_lock(&dev_priv->psr.lock); |
| 315 | if (!dev_priv->psr.enabled) { |
| 316 | mutex_unlock(&dev_priv->psr.lock); |
| 317 | return; |
| 318 | } |
| 319 | |
| 320 | if (dev_priv->psr.active) { |
| 321 | I915_WRITE(EDP_PSR_CTL(dev), |
| 322 | I915_READ(EDP_PSR_CTL(dev)) & ~EDP_PSR_ENABLE); |
| 323 | |
| 324 | /* Wait till PSR is idle */ |
| 325 | if (_wait_for((I915_READ(EDP_PSR_STATUS_CTL(dev)) & |
| 326 | EDP_PSR_STATUS_STATE_MASK) == 0, 2000, 10)) |
| 327 | DRM_ERROR("Timed out waiting for PSR Idle State\n"); |
| 328 | |
| 329 | dev_priv->psr.active = false; |
| 330 | } else { |
| 331 | WARN_ON(I915_READ(EDP_PSR_CTL(dev)) & EDP_PSR_ENABLE); |
| 332 | } |
| 333 | |
| 334 | dev_priv->psr.enabled = NULL; |
| 335 | mutex_unlock(&dev_priv->psr.lock); |
| 336 | |
| 337 | cancel_delayed_work_sync(&dev_priv->psr.work); |
| 338 | } |
| 339 | |
| 340 | static void intel_psr_work(struct work_struct *work) |
| 341 | { |
| 342 | struct drm_i915_private *dev_priv = |
| 343 | container_of(work, typeof(*dev_priv), psr.work.work); |
| 344 | struct intel_dp *intel_dp = dev_priv->psr.enabled; |
| 345 | |
| 346 | /* We have to make sure PSR is ready for re-enable |
| 347 | * otherwise it keeps disabled until next full enable/disable cycle. |
| 348 | * PSR might take some time to get fully disabled |
| 349 | * and be ready for re-enable. |
| 350 | */ |
| 351 | if (wait_for((I915_READ(EDP_PSR_STATUS_CTL(dev_priv->dev)) & |
| 352 | EDP_PSR_STATUS_STATE_MASK) == 0, 50)) { |
| 353 | DRM_ERROR("Timed out waiting for PSR Idle for re-enable\n"); |
| 354 | return; |
| 355 | } |
| 356 | |
| 357 | mutex_lock(&dev_priv->psr.lock); |
| 358 | intel_dp = dev_priv->psr.enabled; |
| 359 | |
| 360 | if (!intel_dp) |
| 361 | goto unlock; |
| 362 | |
| 363 | /* |
| 364 | * The delayed work can race with an invalidate hence we need to |
| 365 | * recheck. Since psr_flush first clears this and then reschedules we |
| 366 | * won't ever miss a flush when bailing out here. |
| 367 | */ |
| 368 | if (dev_priv->psr.busy_frontbuffer_bits) |
| 369 | goto unlock; |
| 370 | |
| 371 | intel_psr_do_enable(intel_dp); |
| 372 | unlock: |
| 373 | mutex_unlock(&dev_priv->psr.lock); |
| 374 | } |
| 375 | |
| 376 | static void intel_psr_exit(struct drm_device *dev) |
| 377 | { |
| 378 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 379 | |
| 380 | if (dev_priv->psr.active) { |
| 381 | u32 val = I915_READ(EDP_PSR_CTL(dev)); |
| 382 | |
| 383 | WARN_ON(!(val & EDP_PSR_ENABLE)); |
| 384 | |
| 385 | I915_WRITE(EDP_PSR_CTL(dev), val & ~EDP_PSR_ENABLE); |
| 386 | |
| 387 | dev_priv->psr.active = false; |
| 388 | } |
| 389 | |
| 390 | } |
| 391 | |
Rodrigo Vivi | b2b89f5 | 2014-11-14 08:52:29 -0800 | [diff] [blame] | 392 | /** |
| 393 | * intel_psr_invalidate - Invalidade PSR |
| 394 | * @dev: DRM device |
| 395 | * @frontbuffer_bits: frontbuffer plane tracking bits |
| 396 | * |
| 397 | * Since the hardware frontbuffer tracking has gaps we need to integrate |
| 398 | * with the software frontbuffer tracking. This function gets called every |
| 399 | * time frontbuffer rendering starts and a buffer gets dirtied. PSR must be |
| 400 | * disabled if the frontbuffer mask contains a buffer relevant to PSR. |
| 401 | * |
| 402 | * Dirty frontbuffers relevant to PSR are tracked in busy_frontbuffer_bits." |
| 403 | */ |
Rodrigo Vivi | 0bc12bc | 2014-11-14 08:52:28 -0800 | [diff] [blame] | 404 | void intel_psr_invalidate(struct drm_device *dev, |
| 405 | unsigned frontbuffer_bits) |
| 406 | { |
| 407 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 408 | struct drm_crtc *crtc; |
| 409 | enum pipe pipe; |
| 410 | |
| 411 | mutex_lock(&dev_priv->psr.lock); |
| 412 | if (!dev_priv->psr.enabled) { |
| 413 | mutex_unlock(&dev_priv->psr.lock); |
| 414 | return; |
| 415 | } |
| 416 | |
| 417 | crtc = dp_to_dig_port(dev_priv->psr.enabled)->base.base.crtc; |
| 418 | pipe = to_intel_crtc(crtc)->pipe; |
| 419 | |
| 420 | intel_psr_exit(dev); |
| 421 | |
| 422 | frontbuffer_bits &= INTEL_FRONTBUFFER_ALL_MASK(pipe); |
| 423 | |
| 424 | dev_priv->psr.busy_frontbuffer_bits |= frontbuffer_bits; |
| 425 | mutex_unlock(&dev_priv->psr.lock); |
| 426 | } |
| 427 | |
Rodrigo Vivi | b2b89f5 | 2014-11-14 08:52:29 -0800 | [diff] [blame] | 428 | /** |
| 429 | * intel_psr_flush - Flush PSR |
| 430 | * @dev: DRM device |
| 431 | * @frontbuffer_bits: frontbuffer plane tracking bits |
| 432 | * |
| 433 | * Since the hardware frontbuffer tracking has gaps we need to integrate |
| 434 | * with the software frontbuffer tracking. This function gets called every |
| 435 | * time frontbuffer rendering has completed and flushed out to memory. PSR |
| 436 | * can be enabled again if no other frontbuffer relevant to PSR is dirty. |
| 437 | * |
| 438 | * Dirty frontbuffers relevant to PSR are tracked in busy_frontbuffer_bits. |
| 439 | */ |
Rodrigo Vivi | 0bc12bc | 2014-11-14 08:52:28 -0800 | [diff] [blame] | 440 | void intel_psr_flush(struct drm_device *dev, |
| 441 | unsigned frontbuffer_bits) |
| 442 | { |
| 443 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 444 | struct drm_crtc *crtc; |
| 445 | enum pipe pipe; |
| 446 | |
| 447 | mutex_lock(&dev_priv->psr.lock); |
| 448 | if (!dev_priv->psr.enabled) { |
| 449 | mutex_unlock(&dev_priv->psr.lock); |
| 450 | return; |
| 451 | } |
| 452 | |
| 453 | crtc = dp_to_dig_port(dev_priv->psr.enabled)->base.base.crtc; |
| 454 | pipe = to_intel_crtc(crtc)->pipe; |
| 455 | dev_priv->psr.busy_frontbuffer_bits &= ~frontbuffer_bits; |
| 456 | |
| 457 | /* |
| 458 | * On Haswell sprite plane updates don't result in a psr invalidating |
| 459 | * signal in the hardware. Which means we need to manually fake this in |
| 460 | * software for all flushes, not just when we've seen a preceding |
| 461 | * invalidation through frontbuffer rendering. |
| 462 | */ |
| 463 | if (IS_HASWELL(dev) && |
| 464 | (frontbuffer_bits & INTEL_FRONTBUFFER_SPRITE(pipe))) |
| 465 | intel_psr_exit(dev); |
| 466 | |
| 467 | if (!dev_priv->psr.active && !dev_priv->psr.busy_frontbuffer_bits) |
| 468 | schedule_delayed_work(&dev_priv->psr.work, |
| 469 | msecs_to_jiffies(100)); |
| 470 | mutex_unlock(&dev_priv->psr.lock); |
| 471 | } |
| 472 | |
Rodrigo Vivi | b2b89f5 | 2014-11-14 08:52:29 -0800 | [diff] [blame] | 473 | /** |
| 474 | * intel_psr_init - Init basic PSR work and mutex. |
| 475 | * @dev: DRM device |
| 476 | * |
| 477 | * This function is called only once at driver load to initialize basic |
| 478 | * PSR stuff. |
| 479 | */ |
Rodrigo Vivi | 0bc12bc | 2014-11-14 08:52:28 -0800 | [diff] [blame] | 480 | void intel_psr_init(struct drm_device *dev) |
| 481 | { |
| 482 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 483 | |
| 484 | INIT_DELAYED_WORK(&dev_priv->psr.work, intel_psr_work); |
| 485 | mutex_init(&dev_priv->psr.lock); |
| 486 | } |