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 DEALINGS 21 * IN THE SOFTWARE. 22 * 23 * Authors: 24 * Daniel Vetter <daniel.vetter@ffwll.ch> 25 * 26 */ 27 28 #include <drm/drm_print.h> 29 30 #include "i915_reg.h" 31 #include "intel_de.h" 32 #include "intel_display_irq.h" 33 #include "intel_display_trace.h" 34 #include "intel_display_types.h" 35 #include "intel_fbc.h" 36 #include "intel_fifo_underrun.h" 37 #include "intel_pch_display.h" 38 39 /** 40 * DOC: fifo underrun handling 41 * 42 * The i915 driver checks for display fifo underruns using the interrupt signals 43 * provided by the hardware. This is enabled by default and fairly useful to 44 * debug display issues, especially watermark settings. 45 * 46 * If an underrun is detected this is logged into dmesg. To avoid flooding logs 47 * and occupying the cpu underrun interrupts are disabled after the first 48 * occurrence until the next modeset on a given pipe. 49 * 50 * Note that underrun detection on gmch platforms is a bit more ugly since there 51 * is no interrupt (despite that the signalling bit is in the PIPESTAT pipe 52 * interrupt register). Also on some other platforms underrun interrupts are 53 * shared, which means that if we detect an underrun we need to disable underrun 54 * reporting on all pipes. 55 * 56 * The code also supports underrun detection on the PCH transcoder. 57 */ 58 59 static bool ivb_can_enable_err_int(struct intel_display *display) 60 { 61 struct intel_crtc *crtc; 62 enum pipe pipe; 63 64 lockdep_assert_held(&display->irq.lock); 65 66 for_each_pipe(display, pipe) { 67 crtc = intel_crtc_for_pipe(display, pipe); 68 69 if (crtc->cpu_fifo_underrun_disabled) 70 return false; 71 } 72 73 return true; 74 } 75 76 static bool cpt_can_enable_serr_int(struct intel_display *display) 77 { 78 enum pipe pipe; 79 struct intel_crtc *crtc; 80 81 lockdep_assert_held(&display->irq.lock); 82 83 for_each_pipe(display, pipe) { 84 crtc = intel_crtc_for_pipe(display, pipe); 85 86 if (crtc->pch_fifo_underrun_disabled) 87 return false; 88 } 89 90 return true; 91 } 92 93 static void i9xx_check_fifo_underruns(struct intel_crtc *crtc) 94 { 95 struct intel_display *display = to_intel_display(crtc); 96 i915_reg_t reg = PIPESTAT(display, crtc->pipe); 97 u32 enable_mask; 98 99 lockdep_assert_held(&display->irq.lock); 100 101 if ((intel_de_read(display, reg) & PIPE_FIFO_UNDERRUN_STATUS) == 0) 102 return; 103 104 enable_mask = i915_pipestat_enable_mask(display, crtc->pipe); 105 intel_de_write(display, reg, enable_mask | PIPE_FIFO_UNDERRUN_STATUS); 106 intel_de_posting_read(display, reg); 107 108 trace_intel_cpu_fifo_underrun(display, crtc->pipe); 109 drm_err(display->drm, "pipe %c underrun\n", pipe_name(crtc->pipe)); 110 } 111 112 static void i9xx_set_fifo_underrun_reporting(struct intel_display *display, 113 enum pipe pipe, 114 bool enable, bool old) 115 { 116 i915_reg_t reg = PIPESTAT(display, pipe); 117 118 lockdep_assert_held(&display->irq.lock); 119 120 if (enable) { 121 u32 enable_mask = i915_pipestat_enable_mask(display, pipe); 122 123 intel_de_write(display, reg, 124 enable_mask | PIPE_FIFO_UNDERRUN_STATUS); 125 intel_de_posting_read(display, reg); 126 } else { 127 if (old && intel_de_read(display, reg) & PIPE_FIFO_UNDERRUN_STATUS) 128 drm_err(display->drm, "pipe %c underrun\n", 129 pipe_name(pipe)); 130 } 131 } 132 133 static void ilk_set_fifo_underrun_reporting(struct intel_display *display, 134 enum pipe pipe, bool enable) 135 { 136 u32 bit = (pipe == PIPE_A) ? 137 DE_PIPEA_FIFO_UNDERRUN : DE_PIPEB_FIFO_UNDERRUN; 138 139 if (enable) 140 ilk_enable_display_irq(display, bit); 141 else 142 ilk_disable_display_irq(display, bit); 143 } 144 145 static void ivb_check_fifo_underruns(struct intel_crtc *crtc) 146 { 147 struct intel_display *display = to_intel_display(crtc); 148 enum pipe pipe = crtc->pipe; 149 u32 err_int = intel_de_read(display, GEN7_ERR_INT); 150 151 lockdep_assert_held(&display->irq.lock); 152 153 if ((err_int & ERR_INT_FIFO_UNDERRUN(pipe)) == 0) 154 return; 155 156 intel_de_write(display, GEN7_ERR_INT, ERR_INT_FIFO_UNDERRUN(pipe)); 157 intel_de_posting_read(display, GEN7_ERR_INT); 158 159 trace_intel_cpu_fifo_underrun(display, pipe); 160 drm_err(display->drm, "fifo underrun on pipe %c\n", pipe_name(pipe)); 161 } 162 163 static void ivb_set_fifo_underrun_reporting(struct intel_display *display, 164 enum pipe pipe, bool enable, 165 bool old) 166 { 167 if (enable) { 168 intel_de_write(display, GEN7_ERR_INT, 169 ERR_INT_FIFO_UNDERRUN(pipe)); 170 171 if (!ivb_can_enable_err_int(display)) 172 return; 173 174 ilk_enable_display_irq(display, DE_ERR_INT_IVB); 175 } else { 176 ilk_disable_display_irq(display, DE_ERR_INT_IVB); 177 178 if (old && 179 intel_de_read(display, GEN7_ERR_INT) & ERR_INT_FIFO_UNDERRUN(pipe)) { 180 drm_err(display->drm, 181 "uncleared fifo underrun on pipe %c\n", 182 pipe_name(pipe)); 183 } 184 } 185 } 186 187 static void bdw_set_fifo_underrun_reporting(struct intel_display *display, 188 enum pipe pipe, bool enable) 189 { 190 if (enable) 191 bdw_enable_pipe_irq(display, pipe, GEN8_PIPE_FIFO_UNDERRUN); 192 else 193 bdw_disable_pipe_irq(display, pipe, GEN8_PIPE_FIFO_UNDERRUN); 194 } 195 196 static void ibx_set_fifo_underrun_reporting(struct intel_display *display, 197 enum pipe pch_transcoder, 198 bool enable) 199 { 200 u32 bit = (pch_transcoder == PIPE_A) ? 201 SDE_TRANSA_FIFO_UNDER : SDE_TRANSB_FIFO_UNDER; 202 203 if (enable) 204 ibx_enable_display_interrupt(display, bit); 205 else 206 ibx_disable_display_interrupt(display, bit); 207 } 208 209 static void cpt_check_pch_fifo_underruns(struct intel_crtc *crtc) 210 { 211 struct intel_display *display = to_intel_display(crtc); 212 enum pipe pch_transcoder = crtc->pipe; 213 u32 serr_int = intel_de_read(display, SERR_INT); 214 215 lockdep_assert_held(&display->irq.lock); 216 217 if ((serr_int & SERR_INT_TRANS_FIFO_UNDERRUN(pch_transcoder)) == 0) 218 return; 219 220 intel_de_write(display, SERR_INT, 221 SERR_INT_TRANS_FIFO_UNDERRUN(pch_transcoder)); 222 intel_de_posting_read(display, SERR_INT); 223 224 trace_intel_pch_fifo_underrun(display, pch_transcoder); 225 drm_err(display->drm, "pch fifo underrun on pch transcoder %c\n", 226 pipe_name(pch_transcoder)); 227 } 228 229 static void cpt_set_fifo_underrun_reporting(struct intel_display *display, 230 enum pipe pch_transcoder, 231 bool enable, bool old) 232 { 233 if (enable) { 234 intel_de_write(display, SERR_INT, 235 SERR_INT_TRANS_FIFO_UNDERRUN(pch_transcoder)); 236 237 if (!cpt_can_enable_serr_int(display)) 238 return; 239 240 ibx_enable_display_interrupt(display, SDE_ERROR_CPT); 241 } else { 242 ibx_disable_display_interrupt(display, SDE_ERROR_CPT); 243 244 if (old && intel_de_read(display, SERR_INT) & 245 SERR_INT_TRANS_FIFO_UNDERRUN(pch_transcoder)) { 246 drm_err(display->drm, 247 "uncleared pch fifo underrun on pch transcoder %c\n", 248 pipe_name(pch_transcoder)); 249 } 250 } 251 } 252 253 static bool __intel_set_cpu_fifo_underrun_reporting(struct intel_display *display, 254 enum pipe pipe, bool enable) 255 { 256 struct intel_crtc *crtc = intel_crtc_for_pipe(display, pipe); 257 bool old; 258 259 lockdep_assert_held(&display->irq.lock); 260 261 old = !crtc->cpu_fifo_underrun_disabled; 262 crtc->cpu_fifo_underrun_disabled = !enable; 263 264 if (HAS_GMCH(display)) 265 i9xx_set_fifo_underrun_reporting(display, pipe, enable, old); 266 else if (display->platform.ironlake || display->platform.sandybridge) 267 ilk_set_fifo_underrun_reporting(display, pipe, enable); 268 else if (DISPLAY_VER(display) == 7) 269 ivb_set_fifo_underrun_reporting(display, pipe, enable, old); 270 else if (DISPLAY_VER(display) >= 8) 271 bdw_set_fifo_underrun_reporting(display, pipe, enable); 272 273 return old; 274 } 275 276 /** 277 * intel_set_cpu_fifo_underrun_reporting - set cpu fifo underrun reporting state 278 * @display: display device instance 279 * @pipe: (CPU) pipe to set state for 280 * @enable: whether underruns should be reported or not 281 * 282 * This function sets the fifo underrun state for @pipe. It is used in the 283 * modeset code to avoid false positives since on many platforms underruns are 284 * expected when disabling or enabling the pipe. 285 * 286 * Notice that on some platforms disabling underrun reports for one pipe 287 * disables for all due to shared interrupts. Actual reporting is still per-pipe 288 * though. 289 * 290 * Returns the previous state of underrun reporting. 291 */ 292 bool intel_set_cpu_fifo_underrun_reporting(struct intel_display *display, 293 enum pipe pipe, bool enable) 294 { 295 unsigned long flags; 296 bool ret; 297 298 spin_lock_irqsave(&display->irq.lock, flags); 299 ret = __intel_set_cpu_fifo_underrun_reporting(display, pipe, enable); 300 spin_unlock_irqrestore(&display->irq.lock, flags); 301 302 return ret; 303 } 304 305 /** 306 * intel_set_pch_fifo_underrun_reporting - set PCH fifo underrun reporting state 307 * @display: display device instance 308 * @pch_transcoder: the PCH transcoder (same as pipe on IVB and older) 309 * @enable: whether underruns should be reported or not 310 * 311 * This function makes us disable or enable PCH fifo underruns for a specific 312 * PCH transcoder. Notice that on some PCHs (e.g. CPT/PPT), disabling FIFO 313 * underrun reporting for one transcoder may also disable all the other PCH 314 * error interruts for the other transcoders, due to the fact that there's just 315 * one interrupt mask/enable bit for all the transcoders. 316 * 317 * Returns the previous state of underrun reporting. 318 */ 319 bool intel_set_pch_fifo_underrun_reporting(struct intel_display *display, 320 enum pipe pch_transcoder, 321 bool enable) 322 { 323 struct intel_crtc *crtc = intel_crtc_for_pipe(display, pch_transcoder); 324 unsigned long flags; 325 bool old; 326 327 /* 328 * NOTE: Pre-LPT has a fixed cpu pipe -> pch transcoder mapping, but LPT 329 * has only one pch transcoder A that all pipes can use. To avoid racy 330 * pch transcoder -> pipe lookups from interrupt code simply store the 331 * underrun statistics in crtc A. Since we never expose this anywhere 332 * nor use it outside of the fifo underrun code here using the "wrong" 333 * crtc on LPT won't cause issues. 334 */ 335 336 spin_lock_irqsave(&display->irq.lock, flags); 337 338 old = !crtc->pch_fifo_underrun_disabled; 339 crtc->pch_fifo_underrun_disabled = !enable; 340 341 if (HAS_PCH_IBX(display)) 342 ibx_set_fifo_underrun_reporting(display, 343 pch_transcoder, 344 enable); 345 else 346 cpt_set_fifo_underrun_reporting(display, 347 pch_transcoder, 348 enable, old); 349 350 spin_unlock_irqrestore(&display->irq.lock, flags); 351 return old; 352 } 353 354 /** 355 * intel_cpu_fifo_underrun_irq_handler - handle CPU fifo underrun interrupt 356 * @display: display device instance 357 * @pipe: (CPU) pipe to set state for 358 * 359 * This handles a CPU fifo underrun interrupt, generating an underrun warning 360 * into dmesg if underrun reporting is enabled and then disables the underrun 361 * interrupt to avoid an irq storm. 362 */ 363 void intel_cpu_fifo_underrun_irq_handler(struct intel_display *display, 364 enum pipe pipe) 365 { 366 struct intel_crtc *crtc = intel_crtc_for_pipe(display, pipe); 367 368 /* We may be called too early in init, thanks BIOS! */ 369 if (crtc == NULL) 370 return; 371 372 /* GMCH can't disable fifo underruns, filter them. */ 373 if (HAS_GMCH(display) && 374 crtc->cpu_fifo_underrun_disabled) 375 return; 376 377 if (intel_set_cpu_fifo_underrun_reporting(display, pipe, false)) { 378 trace_intel_cpu_fifo_underrun(display, pipe); 379 380 drm_err(display->drm, "CPU pipe %c FIFO underrun\n", pipe_name(pipe)); 381 } 382 383 intel_fbc_handle_fifo_underrun_irq(display); 384 } 385 386 /** 387 * intel_pch_fifo_underrun_irq_handler - handle PCH fifo underrun interrupt 388 * @display: display device instance 389 * @pch_transcoder: the PCH transcoder (same as pipe on IVB and older) 390 * 391 * This handles a PCH fifo underrun interrupt, generating an underrun warning 392 * into dmesg if underrun reporting is enabled and then disables the underrun 393 * interrupt to avoid an irq storm. 394 */ 395 void intel_pch_fifo_underrun_irq_handler(struct intel_display *display, 396 enum pipe pch_transcoder) 397 { 398 if (intel_set_pch_fifo_underrun_reporting(display, pch_transcoder, 399 false)) { 400 trace_intel_pch_fifo_underrun(display, pch_transcoder); 401 drm_err(display->drm, "PCH transcoder %c FIFO underrun\n", 402 pipe_name(pch_transcoder)); 403 } 404 } 405 406 /** 407 * intel_check_cpu_fifo_underruns - check for CPU fifo underruns immediately 408 * @display: display device instance 409 * 410 * Check for CPU fifo underruns immediately. Useful on IVB/HSW where the shared 411 * error interrupt may have been disabled, and so CPU fifo underruns won't 412 * necessarily raise an interrupt, and on GMCH platforms where underruns never 413 * raise an interrupt. 414 */ 415 void intel_check_cpu_fifo_underruns(struct intel_display *display) 416 { 417 struct intel_crtc *crtc; 418 419 spin_lock_irq(&display->irq.lock); 420 421 for_each_intel_crtc(display->drm, crtc) { 422 if (crtc->cpu_fifo_underrun_disabled) 423 continue; 424 425 if (HAS_GMCH(display)) 426 i9xx_check_fifo_underruns(crtc); 427 else if (DISPLAY_VER(display) == 7) 428 ivb_check_fifo_underruns(crtc); 429 } 430 431 spin_unlock_irq(&display->irq.lock); 432 } 433 434 /** 435 * intel_check_pch_fifo_underruns - check for PCH fifo underruns immediately 436 * @display: display device instance 437 * 438 * Check for PCH fifo underruns immediately. Useful on CPT/PPT where the shared 439 * error interrupt may have been disabled, and so PCH fifo underruns won't 440 * necessarily raise an interrupt. 441 */ 442 void intel_check_pch_fifo_underruns(struct intel_display *display) 443 { 444 struct intel_crtc *crtc; 445 446 spin_lock_irq(&display->irq.lock); 447 448 for_each_intel_crtc(display->drm, crtc) { 449 if (crtc->pch_fifo_underrun_disabled) 450 continue; 451 452 if (HAS_PCH_CPT(display)) 453 cpt_check_pch_fifo_underruns(crtc); 454 } 455 456 spin_unlock_irq(&display->irq.lock); 457 } 458 459 void intel_init_fifo_underrun_reporting(struct intel_display *display, 460 struct intel_crtc *crtc, 461 bool enable) 462 { 463 crtc->cpu_fifo_underrun_disabled = !enable; 464 465 /* 466 * We track the PCH trancoder underrun reporting state 467 * within the crtc. With crtc for pipe A housing the underrun 468 * reporting state for PCH transcoder A, crtc for pipe B housing 469 * it for PCH transcoder B, etc. LPT-H has only PCH transcoder A, 470 * and marking underrun reporting as disabled for the non-existing 471 * PCH transcoders B and C would prevent enabling the south 472 * error interrupt (see cpt_can_enable_serr_int()). 473 */ 474 if (intel_has_pch_trancoder(display, crtc->pipe)) 475 crtc->pch_fifo_underrun_disabled = !enable; 476 } 477