1 /* i915_drv.h -- Private header for the I915 driver -*- linux-c -*- 2 */ 3 /* 4 * 5 * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas. 6 * All Rights Reserved. 7 * 8 * Permission is hereby granted, free of charge, to any person obtaining a 9 * copy of this software and associated documentation files (the 10 * "Software"), to deal in the Software without restriction, including 11 * without limitation the rights to use, copy, modify, merge, publish, 12 * distribute, sub license, and/or sell copies of the Software, and to 13 * permit persons to whom the Software is furnished to do so, subject to 14 * the following conditions: 15 * 16 * The above copyright notice and this permission notice (including the 17 * next paragraph) shall be included in all copies or substantial portions 18 * of the Software. 19 * 20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 21 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 22 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. 23 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR 24 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 25 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 26 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 27 * 28 */ 29 30 #ifndef _I915_DRV_H_ 31 #define _I915_DRV_H_ 32 33 #include <uapi/drm/i915_drm.h> 34 #include <uapi/drm/drm_fourcc.h> 35 36 #include <linux/io-mapping.h> 37 #include <linux/i2c.h> 38 #include <linux/i2c-algo-bit.h> 39 #include <linux/backlight.h> 40 #include <linux/hash.h> 41 #include <linux/intel-iommu.h> 42 #include <linux/kref.h> 43 #include <linux/mm_types.h> 44 #include <linux/perf_event.h> 45 #include <linux/pm_qos.h> 46 #include <linux/reservation.h> 47 #include <linux/shmem_fs.h> 48 49 #include <drm/drmP.h> 50 #include <drm/intel-gtt.h> 51 #include <drm/drm_legacy.h> /* for struct drm_dma_handle */ 52 #include <drm/drm_gem.h> 53 #include <drm/drm_auth.h> 54 #include <drm/drm_cache.h> 55 #include <drm/drm_util.h> 56 57 #include "i915_params.h" 58 #include "i915_reg.h" 59 #include "i915_utils.h" 60 61 #include "intel_bios.h" 62 #include "intel_device_info.h" 63 #include "intel_display.h" 64 #include "intel_dpll_mgr.h" 65 #include "intel_lrc.h" 66 #include "intel_opregion.h" 67 #include "intel_ringbuffer.h" 68 #include "intel_uncore.h" 69 #include "intel_wopcm.h" 70 #include "intel_workarounds.h" 71 #include "intel_uc.h" 72 73 #include "i915_gem.h" 74 #include "i915_gem_context.h" 75 #include "i915_gem_fence_reg.h" 76 #include "i915_gem_object.h" 77 #include "i915_gem_gtt.h" 78 #include "i915_gpu_error.h" 79 #include "i915_request.h" 80 #include "i915_scheduler.h" 81 #include "i915_timeline.h" 82 #include "i915_vma.h" 83 84 #include "intel_gvt.h" 85 86 /* General customization: 87 */ 88 89 #define DRIVER_NAME "i915" 90 #define DRIVER_DESC "Intel Graphics" 91 #define DRIVER_DATE "20180921" 92 #define DRIVER_TIMESTAMP 1537521997 93 94 /* Use I915_STATE_WARN(x) and I915_STATE_WARN_ON() (rather than WARN() and 95 * WARN_ON()) for hw state sanity checks to check for unexpected conditions 96 * which may not necessarily be a user visible problem. This will either 97 * WARN() or DRM_ERROR() depending on the verbose_checks moduleparam, to 98 * enable distros and users to tailor their preferred amount of i915 abrt 99 * spam. 100 */ 101 #define I915_STATE_WARN(condition, format...) ({ \ 102 int __ret_warn_on = !!(condition); \ 103 if (unlikely(__ret_warn_on)) \ 104 if (!WARN(i915_modparams.verbose_state_checks, format)) \ 105 DRM_ERROR(format); \ 106 unlikely(__ret_warn_on); \ 107 }) 108 109 #define I915_STATE_WARN_ON(x) \ 110 I915_STATE_WARN((x), "%s", "WARN_ON(" __stringify(x) ")") 111 112 #if IS_ENABLED(CONFIG_DRM_I915_DEBUG) 113 114 bool __i915_inject_load_failure(const char *func, int line); 115 #define i915_inject_load_failure() \ 116 __i915_inject_load_failure(__func__, __LINE__) 117 118 bool i915_error_injected(void); 119 120 #else 121 122 #define i915_inject_load_failure() false 123 #define i915_error_injected() false 124 125 #endif 126 127 #define i915_load_error(i915, fmt, ...) \ 128 __i915_printk(i915, i915_error_injected() ? KERN_DEBUG : KERN_ERR, \ 129 fmt, ##__VA_ARGS__) 130 131 typedef struct { 132 uint32_t val; 133 } uint_fixed_16_16_t; 134 135 #define FP_16_16_MAX ({ \ 136 uint_fixed_16_16_t fp; \ 137 fp.val = UINT_MAX; \ 138 fp; \ 139 }) 140 141 static inline bool is_fixed16_zero(uint_fixed_16_16_t val) 142 { 143 if (val.val == 0) 144 return true; 145 return false; 146 } 147 148 static inline uint_fixed_16_16_t u32_to_fixed16(uint32_t val) 149 { 150 uint_fixed_16_16_t fp; 151 152 WARN_ON(val > U16_MAX); 153 154 fp.val = val << 16; 155 return fp; 156 } 157 158 static inline uint32_t fixed16_to_u32_round_up(uint_fixed_16_16_t fp) 159 { 160 return DIV_ROUND_UP(fp.val, 1 << 16); 161 } 162 163 static inline uint32_t fixed16_to_u32(uint_fixed_16_16_t fp) 164 { 165 return fp.val >> 16; 166 } 167 168 static inline uint_fixed_16_16_t min_fixed16(uint_fixed_16_16_t min1, 169 uint_fixed_16_16_t min2) 170 { 171 uint_fixed_16_16_t min; 172 173 min.val = min(min1.val, min2.val); 174 return min; 175 } 176 177 static inline uint_fixed_16_16_t max_fixed16(uint_fixed_16_16_t max1, 178 uint_fixed_16_16_t max2) 179 { 180 uint_fixed_16_16_t max; 181 182 max.val = max(max1.val, max2.val); 183 return max; 184 } 185 186 static inline uint_fixed_16_16_t clamp_u64_to_fixed16(uint64_t val) 187 { 188 uint_fixed_16_16_t fp; 189 WARN_ON(val > U32_MAX); 190 fp.val = (uint32_t) val; 191 return fp; 192 } 193 194 static inline uint32_t div_round_up_fixed16(uint_fixed_16_16_t val, 195 uint_fixed_16_16_t d) 196 { 197 return DIV_ROUND_UP(val.val, d.val); 198 } 199 200 static inline uint32_t mul_round_up_u32_fixed16(uint32_t val, 201 uint_fixed_16_16_t mul) 202 { 203 uint64_t intermediate_val; 204 205 intermediate_val = (uint64_t) val * mul.val; 206 intermediate_val = DIV_ROUND_UP_ULL(intermediate_val, 1 << 16); 207 WARN_ON(intermediate_val > U32_MAX); 208 return (uint32_t) intermediate_val; 209 } 210 211 static inline uint_fixed_16_16_t mul_fixed16(uint_fixed_16_16_t val, 212 uint_fixed_16_16_t mul) 213 { 214 uint64_t intermediate_val; 215 216 intermediate_val = (uint64_t) val.val * mul.val; 217 intermediate_val = intermediate_val >> 16; 218 return clamp_u64_to_fixed16(intermediate_val); 219 } 220 221 static inline uint_fixed_16_16_t div_fixed16(uint32_t val, uint32_t d) 222 { 223 uint64_t interm_val; 224 225 interm_val = (uint64_t)val << 16; 226 interm_val = DIV_ROUND_UP_ULL(interm_val, d); 227 return clamp_u64_to_fixed16(interm_val); 228 } 229 230 static inline uint32_t div_round_up_u32_fixed16(uint32_t val, 231 uint_fixed_16_16_t d) 232 { 233 uint64_t interm_val; 234 235 interm_val = (uint64_t)val << 16; 236 interm_val = DIV_ROUND_UP_ULL(interm_val, d.val); 237 WARN_ON(interm_val > U32_MAX); 238 return (uint32_t) interm_val; 239 } 240 241 static inline uint_fixed_16_16_t mul_u32_fixed16(uint32_t val, 242 uint_fixed_16_16_t mul) 243 { 244 uint64_t intermediate_val; 245 246 intermediate_val = (uint64_t) val * mul.val; 247 return clamp_u64_to_fixed16(intermediate_val); 248 } 249 250 static inline uint_fixed_16_16_t add_fixed16(uint_fixed_16_16_t add1, 251 uint_fixed_16_16_t add2) 252 { 253 uint64_t interm_sum; 254 255 interm_sum = (uint64_t) add1.val + add2.val; 256 return clamp_u64_to_fixed16(interm_sum); 257 } 258 259 static inline uint_fixed_16_16_t add_fixed16_u32(uint_fixed_16_16_t add1, 260 uint32_t add2) 261 { 262 uint64_t interm_sum; 263 uint_fixed_16_16_t interm_add2 = u32_to_fixed16(add2); 264 265 interm_sum = (uint64_t) add1.val + interm_add2.val; 266 return clamp_u64_to_fixed16(interm_sum); 267 } 268 269 enum hpd_pin { 270 HPD_NONE = 0, 271 HPD_TV = HPD_NONE, /* TV is known to be unreliable */ 272 HPD_CRT, 273 HPD_SDVO_B, 274 HPD_SDVO_C, 275 HPD_PORT_A, 276 HPD_PORT_B, 277 HPD_PORT_C, 278 HPD_PORT_D, 279 HPD_PORT_E, 280 HPD_PORT_F, 281 HPD_NUM_PINS 282 }; 283 284 #define for_each_hpd_pin(__pin) \ 285 for ((__pin) = (HPD_NONE + 1); (__pin) < HPD_NUM_PINS; (__pin)++) 286 287 #define HPD_STORM_DEFAULT_THRESHOLD 5 288 289 struct i915_hotplug { 290 struct work_struct hotplug_work; 291 292 struct { 293 unsigned long last_jiffies; 294 int count; 295 enum { 296 HPD_ENABLED = 0, 297 HPD_DISABLED = 1, 298 HPD_MARK_DISABLED = 2 299 } state; 300 } stats[HPD_NUM_PINS]; 301 u32 event_bits; 302 struct delayed_work reenable_work; 303 304 u32 long_port_mask; 305 u32 short_port_mask; 306 struct work_struct dig_port_work; 307 308 struct work_struct poll_init_work; 309 bool poll_enabled; 310 311 unsigned int hpd_storm_threshold; 312 313 /* 314 * if we get a HPD irq from DP and a HPD irq from non-DP 315 * the non-DP HPD could block the workqueue on a mode config 316 * mutex getting, that userspace may have taken. However 317 * userspace is waiting on the DP workqueue to run which is 318 * blocked behind the non-DP one. 319 */ 320 struct workqueue_struct *dp_wq; 321 }; 322 323 #define I915_GEM_GPU_DOMAINS \ 324 (I915_GEM_DOMAIN_RENDER | \ 325 I915_GEM_DOMAIN_SAMPLER | \ 326 I915_GEM_DOMAIN_COMMAND | \ 327 I915_GEM_DOMAIN_INSTRUCTION | \ 328 I915_GEM_DOMAIN_VERTEX) 329 330 struct drm_i915_private; 331 struct i915_mm_struct; 332 struct i915_mmu_object; 333 334 struct drm_i915_file_private { 335 struct drm_i915_private *dev_priv; 336 struct drm_file *file; 337 338 struct { 339 spinlock_t lock; 340 struct list_head request_list; 341 /* 20ms is a fairly arbitrary limit (greater than the average frame time) 342 * chosen to prevent the CPU getting more than a frame ahead of the GPU 343 * (when using lax throttling for the frontbuffer). We also use it to 344 * offer free GPU waitboosts for severely congested workloads. 345 */ 346 #define DRM_I915_THROTTLE_JIFFIES msecs_to_jiffies(20) 347 } mm; 348 struct idr context_idr; 349 350 struct intel_rps_client { 351 atomic_t boosts; 352 } rps_client; 353 354 unsigned int bsd_engine; 355 356 /* 357 * Every context ban increments per client ban score. Also 358 * hangs in short succession increments ban score. If ban threshold 359 * is reached, client is considered banned and submitting more work 360 * will fail. This is a stop gap measure to limit the badly behaving 361 * clients access to gpu. Note that unbannable contexts never increment 362 * the client ban score. 363 */ 364 #define I915_CLIENT_SCORE_HANG_FAST 1 365 #define I915_CLIENT_FAST_HANG_JIFFIES (60 * HZ) 366 #define I915_CLIENT_SCORE_CONTEXT_BAN 3 367 #define I915_CLIENT_SCORE_BANNED 9 368 /** ban_score: Accumulated score of all ctx bans and fast hangs. */ 369 atomic_t ban_score; 370 unsigned long hang_timestamp; 371 }; 372 373 /* Interface history: 374 * 375 * 1.1: Original. 376 * 1.2: Add Power Management 377 * 1.3: Add vblank support 378 * 1.4: Fix cmdbuffer path, add heap destroy 379 * 1.5: Add vblank pipe configuration 380 * 1.6: - New ioctl for scheduling buffer swaps on vertical blank 381 * - Support vertical blank on secondary display pipe 382 */ 383 #define DRIVER_MAJOR 1 384 #define DRIVER_MINOR 6 385 #define DRIVER_PATCHLEVEL 0 386 387 struct intel_overlay; 388 struct intel_overlay_error_state; 389 390 struct sdvo_device_mapping { 391 u8 initialized; 392 u8 dvo_port; 393 u8 slave_addr; 394 u8 dvo_wiring; 395 u8 i2c_pin; 396 u8 ddc_pin; 397 }; 398 399 struct intel_connector; 400 struct intel_encoder; 401 struct intel_atomic_state; 402 struct intel_crtc_state; 403 struct intel_initial_plane_config; 404 struct intel_crtc; 405 struct intel_limit; 406 struct dpll; 407 struct intel_cdclk_state; 408 409 struct drm_i915_display_funcs { 410 void (*get_cdclk)(struct drm_i915_private *dev_priv, 411 struct intel_cdclk_state *cdclk_state); 412 void (*set_cdclk)(struct drm_i915_private *dev_priv, 413 const struct intel_cdclk_state *cdclk_state); 414 int (*get_fifo_size)(struct drm_i915_private *dev_priv, 415 enum i9xx_plane_id i9xx_plane); 416 int (*compute_pipe_wm)(struct intel_crtc_state *cstate); 417 int (*compute_intermediate_wm)(struct drm_device *dev, 418 struct intel_crtc *intel_crtc, 419 struct intel_crtc_state *newstate); 420 void (*initial_watermarks)(struct intel_atomic_state *state, 421 struct intel_crtc_state *cstate); 422 void (*atomic_update_watermarks)(struct intel_atomic_state *state, 423 struct intel_crtc_state *cstate); 424 void (*optimize_watermarks)(struct intel_atomic_state *state, 425 struct intel_crtc_state *cstate); 426 int (*compute_global_watermarks)(struct drm_atomic_state *state); 427 void (*update_wm)(struct intel_crtc *crtc); 428 int (*modeset_calc_cdclk)(struct drm_atomic_state *state); 429 /* Returns the active state of the crtc, and if the crtc is active, 430 * fills out the pipe-config with the hw state. */ 431 bool (*get_pipe_config)(struct intel_crtc *, 432 struct intel_crtc_state *); 433 void (*get_initial_plane_config)(struct intel_crtc *, 434 struct intel_initial_plane_config *); 435 int (*crtc_compute_clock)(struct intel_crtc *crtc, 436 struct intel_crtc_state *crtc_state); 437 void (*crtc_enable)(struct intel_crtc_state *pipe_config, 438 struct drm_atomic_state *old_state); 439 void (*crtc_disable)(struct intel_crtc_state *old_crtc_state, 440 struct drm_atomic_state *old_state); 441 void (*update_crtcs)(struct drm_atomic_state *state); 442 void (*audio_codec_enable)(struct intel_encoder *encoder, 443 const struct intel_crtc_state *crtc_state, 444 const struct drm_connector_state *conn_state); 445 void (*audio_codec_disable)(struct intel_encoder *encoder, 446 const struct intel_crtc_state *old_crtc_state, 447 const struct drm_connector_state *old_conn_state); 448 void (*fdi_link_train)(struct intel_crtc *crtc, 449 const struct intel_crtc_state *crtc_state); 450 void (*init_clock_gating)(struct drm_i915_private *dev_priv); 451 void (*hpd_irq_setup)(struct drm_i915_private *dev_priv); 452 /* clock updates for mode set */ 453 /* cursor updates */ 454 /* render clock increase/decrease */ 455 /* display clock increase/decrease */ 456 /* pll clock increase/decrease */ 457 458 void (*load_csc_matrix)(struct drm_crtc_state *crtc_state); 459 void (*load_luts)(struct drm_crtc_state *crtc_state); 460 }; 461 462 #define CSR_VERSION(major, minor) ((major) << 16 | (minor)) 463 #define CSR_VERSION_MAJOR(version) ((version) >> 16) 464 #define CSR_VERSION_MINOR(version) ((version) & 0xffff) 465 466 struct intel_csr { 467 struct work_struct work; 468 const char *fw_path; 469 uint32_t *dmc_payload; 470 uint32_t dmc_fw_size; 471 uint32_t version; 472 uint32_t mmio_count; 473 i915_reg_t mmioaddr[8]; 474 uint32_t mmiodata[8]; 475 uint32_t dc_state; 476 uint32_t allowed_dc_mask; 477 }; 478 479 enum i915_cache_level { 480 I915_CACHE_NONE = 0, 481 I915_CACHE_LLC, /* also used for snoopable memory on non-LLC */ 482 I915_CACHE_L3_LLC, /* gen7+, L3 sits between the domain specifc 483 caches, eg sampler/render caches, and the 484 large Last-Level-Cache. LLC is coherent with 485 the CPU, but L3 is only visible to the GPU. */ 486 I915_CACHE_WT, /* hsw:gt3e WriteThrough for scanouts */ 487 }; 488 489 #define I915_COLOR_UNEVICTABLE (-1) /* a non-vma sharing the address space */ 490 491 enum fb_op_origin { 492 ORIGIN_GTT, 493 ORIGIN_CPU, 494 ORIGIN_CS, 495 ORIGIN_FLIP, 496 ORIGIN_DIRTYFB, 497 }; 498 499 struct intel_fbc { 500 /* This is always the inner lock when overlapping with struct_mutex and 501 * it's the outer lock when overlapping with stolen_lock. */ 502 struct mutex lock; 503 unsigned threshold; 504 unsigned int possible_framebuffer_bits; 505 unsigned int busy_bits; 506 unsigned int visible_pipes_mask; 507 struct intel_crtc *crtc; 508 509 struct drm_mm_node compressed_fb; 510 struct drm_mm_node *compressed_llb; 511 512 bool false_color; 513 514 bool enabled; 515 bool active; 516 bool flip_pending; 517 518 bool underrun_detected; 519 struct work_struct underrun_work; 520 521 /* 522 * Due to the atomic rules we can't access some structures without the 523 * appropriate locking, so we cache information here in order to avoid 524 * these problems. 525 */ 526 struct intel_fbc_state_cache { 527 struct i915_vma *vma; 528 unsigned long flags; 529 530 struct { 531 unsigned int mode_flags; 532 uint32_t hsw_bdw_pixel_rate; 533 } crtc; 534 535 struct { 536 unsigned int rotation; 537 int src_w; 538 int src_h; 539 bool visible; 540 /* 541 * Display surface base address adjustement for 542 * pageflips. Note that on gen4+ this only adjusts up 543 * to a tile, offsets within a tile are handled in 544 * the hw itself (with the TILEOFF register). 545 */ 546 int adjusted_x; 547 int adjusted_y; 548 549 int y; 550 } plane; 551 552 struct { 553 const struct drm_format_info *format; 554 unsigned int stride; 555 } fb; 556 } state_cache; 557 558 /* 559 * This structure contains everything that's relevant to program the 560 * hardware registers. When we want to figure out if we need to disable 561 * and re-enable FBC for a new configuration we just check if there's 562 * something different in the struct. The genx_fbc_activate functions 563 * are supposed to read from it in order to program the registers. 564 */ 565 struct intel_fbc_reg_params { 566 struct i915_vma *vma; 567 unsigned long flags; 568 569 struct { 570 enum pipe pipe; 571 enum i9xx_plane_id i9xx_plane; 572 unsigned int fence_y_offset; 573 } crtc; 574 575 struct { 576 const struct drm_format_info *format; 577 unsigned int stride; 578 } fb; 579 580 int cfb_size; 581 unsigned int gen9_wa_cfb_stride; 582 } params; 583 584 const char *no_fbc_reason; 585 }; 586 587 /* 588 * HIGH_RR is the highest eDP panel refresh rate read from EDID 589 * LOW_RR is the lowest eDP panel refresh rate found from EDID 590 * parsing for same resolution. 591 */ 592 enum drrs_refresh_rate_type { 593 DRRS_HIGH_RR, 594 DRRS_LOW_RR, 595 DRRS_MAX_RR, /* RR count */ 596 }; 597 598 enum drrs_support_type { 599 DRRS_NOT_SUPPORTED = 0, 600 STATIC_DRRS_SUPPORT = 1, 601 SEAMLESS_DRRS_SUPPORT = 2 602 }; 603 604 struct intel_dp; 605 struct i915_drrs { 606 struct mutex mutex; 607 struct delayed_work work; 608 struct intel_dp *dp; 609 unsigned busy_frontbuffer_bits; 610 enum drrs_refresh_rate_type refresh_rate_type; 611 enum drrs_support_type type; 612 }; 613 614 struct i915_psr { 615 struct mutex lock; 616 617 #define I915_PSR_DEBUG_MODE_MASK 0x0f 618 #define I915_PSR_DEBUG_DEFAULT 0x00 619 #define I915_PSR_DEBUG_DISABLE 0x01 620 #define I915_PSR_DEBUG_ENABLE 0x02 621 #define I915_PSR_DEBUG_FORCE_PSR1 0x03 622 #define I915_PSR_DEBUG_IRQ 0x10 623 624 u32 debug; 625 bool sink_support; 626 bool prepared, enabled; 627 struct intel_dp *dp; 628 bool active; 629 struct work_struct work; 630 unsigned busy_frontbuffer_bits; 631 bool sink_psr2_support; 632 bool link_standby; 633 bool colorimetry_support; 634 bool alpm; 635 bool psr2_enabled; 636 u8 sink_sync_latency; 637 ktime_t last_entry_attempt; 638 ktime_t last_exit; 639 }; 640 641 enum intel_pch { 642 PCH_NONE = 0, /* No PCH present */ 643 PCH_IBX, /* Ibexpeak PCH */ 644 PCH_CPT, /* Cougarpoint/Pantherpoint PCH */ 645 PCH_LPT, /* Lynxpoint/Wildcatpoint PCH */ 646 PCH_SPT, /* Sunrisepoint PCH */ 647 PCH_KBP, /* Kaby Lake PCH */ 648 PCH_CNP, /* Cannon Lake PCH */ 649 PCH_ICP, /* Ice Lake PCH */ 650 PCH_NOP, /* PCH without south display */ 651 }; 652 653 enum intel_sbi_destination { 654 SBI_ICLK, 655 SBI_MPHY, 656 }; 657 658 #define QUIRK_LVDS_SSC_DISABLE (1<<1) 659 #define QUIRK_INVERT_BRIGHTNESS (1<<2) 660 #define QUIRK_BACKLIGHT_PRESENT (1<<3) 661 #define QUIRK_PIN_SWIZZLED_PAGES (1<<5) 662 #define QUIRK_INCREASE_T12_DELAY (1<<6) 663 #define QUIRK_INCREASE_DDI_DISABLED_TIME (1<<7) 664 665 struct intel_fbdev; 666 struct intel_fbc_work; 667 668 struct intel_gmbus { 669 struct i2c_adapter adapter; 670 #define GMBUS_FORCE_BIT_RETRY (1U << 31) 671 u32 force_bit; 672 u32 reg0; 673 i915_reg_t gpio_reg; 674 struct i2c_algo_bit_data bit_algo; 675 struct drm_i915_private *dev_priv; 676 }; 677 678 struct i915_suspend_saved_registers { 679 u32 saveDSPARB; 680 u32 saveFBC_CONTROL; 681 u32 saveCACHE_MODE_0; 682 u32 saveMI_ARB_STATE; 683 u32 saveSWF0[16]; 684 u32 saveSWF1[16]; 685 u32 saveSWF3[3]; 686 uint64_t saveFENCE[I915_MAX_NUM_FENCES]; 687 u32 savePCH_PORT_HOTPLUG; 688 u16 saveGCDGMBUS; 689 }; 690 691 struct vlv_s0ix_state { 692 /* GAM */ 693 u32 wr_watermark; 694 u32 gfx_prio_ctrl; 695 u32 arb_mode; 696 u32 gfx_pend_tlb0; 697 u32 gfx_pend_tlb1; 698 u32 lra_limits[GEN7_LRA_LIMITS_REG_NUM]; 699 u32 media_max_req_count; 700 u32 gfx_max_req_count; 701 u32 render_hwsp; 702 u32 ecochk; 703 u32 bsd_hwsp; 704 u32 blt_hwsp; 705 u32 tlb_rd_addr; 706 707 /* MBC */ 708 u32 g3dctl; 709 u32 gsckgctl; 710 u32 mbctl; 711 712 /* GCP */ 713 u32 ucgctl1; 714 u32 ucgctl3; 715 u32 rcgctl1; 716 u32 rcgctl2; 717 u32 rstctl; 718 u32 misccpctl; 719 720 /* GPM */ 721 u32 gfxpause; 722 u32 rpdeuhwtc; 723 u32 rpdeuc; 724 u32 ecobus; 725 u32 pwrdwnupctl; 726 u32 rp_down_timeout; 727 u32 rp_deucsw; 728 u32 rcubmabdtmr; 729 u32 rcedata; 730 u32 spare2gh; 731 732 /* Display 1 CZ domain */ 733 u32 gt_imr; 734 u32 gt_ier; 735 u32 pm_imr; 736 u32 pm_ier; 737 u32 gt_scratch[GEN7_GT_SCRATCH_REG_NUM]; 738 739 /* GT SA CZ domain */ 740 u32 tilectl; 741 u32 gt_fifoctl; 742 u32 gtlc_wake_ctrl; 743 u32 gtlc_survive; 744 u32 pmwgicz; 745 746 /* Display 2 CZ domain */ 747 u32 gu_ctl0; 748 u32 gu_ctl1; 749 u32 pcbr; 750 u32 clock_gate_dis2; 751 }; 752 753 struct intel_rps_ei { 754 ktime_t ktime; 755 u32 render_c0; 756 u32 media_c0; 757 }; 758 759 struct intel_rps { 760 /* 761 * work, interrupts_enabled and pm_iir are protected by 762 * dev_priv->irq_lock 763 */ 764 struct work_struct work; 765 bool interrupts_enabled; 766 u32 pm_iir; 767 768 /* PM interrupt bits that should never be masked */ 769 u32 pm_intrmsk_mbz; 770 771 /* Frequencies are stored in potentially platform dependent multiples. 772 * In other words, *_freq needs to be multiplied by X to be interesting. 773 * Soft limits are those which are used for the dynamic reclocking done 774 * by the driver (raise frequencies under heavy loads, and lower for 775 * lighter loads). Hard limits are those imposed by the hardware. 776 * 777 * A distinction is made for overclocking, which is never enabled by 778 * default, and is considered to be above the hard limit if it's 779 * possible at all. 780 */ 781 u8 cur_freq; /* Current frequency (cached, may not == HW) */ 782 u8 min_freq_softlimit; /* Minimum frequency permitted by the driver */ 783 u8 max_freq_softlimit; /* Max frequency permitted by the driver */ 784 u8 max_freq; /* Maximum frequency, RP0 if not overclocking */ 785 u8 min_freq; /* AKA RPn. Minimum frequency */ 786 u8 boost_freq; /* Frequency to request when wait boosting */ 787 u8 idle_freq; /* Frequency to request when we are idle */ 788 u8 efficient_freq; /* AKA RPe. Pre-determined balanced frequency */ 789 u8 rp1_freq; /* "less than" RP0 power/freqency */ 790 u8 rp0_freq; /* Non-overclocked max frequency. */ 791 u16 gpll_ref_freq; /* vlv/chv GPLL reference frequency */ 792 793 int last_adj; 794 795 struct { 796 struct mutex mutex; 797 798 enum { LOW_POWER, BETWEEN, HIGH_POWER } mode; 799 unsigned int interactive; 800 801 u8 up_threshold; /* Current %busy required to uplock */ 802 u8 down_threshold; /* Current %busy required to downclock */ 803 } power; 804 805 bool enabled; 806 atomic_t num_waiters; 807 atomic_t boosts; 808 809 /* manual wa residency calculations */ 810 struct intel_rps_ei ei; 811 }; 812 813 struct intel_rc6 { 814 bool enabled; 815 u64 prev_hw_residency[4]; 816 u64 cur_residency[4]; 817 }; 818 819 struct intel_llc_pstate { 820 bool enabled; 821 }; 822 823 struct intel_gen6_power_mgmt { 824 struct intel_rps rps; 825 struct intel_rc6 rc6; 826 struct intel_llc_pstate llc_pstate; 827 }; 828 829 /* defined intel_pm.c */ 830 extern spinlock_t mchdev_lock; 831 832 struct intel_ilk_power_mgmt { 833 u8 cur_delay; 834 u8 min_delay; 835 u8 max_delay; 836 u8 fmax; 837 u8 fstart; 838 839 u64 last_count1; 840 unsigned long last_time1; 841 unsigned long chipset_power; 842 u64 last_count2; 843 u64 last_time2; 844 unsigned long gfx_power; 845 u8 corr; 846 847 int c_m; 848 int r_t; 849 }; 850 851 struct drm_i915_private; 852 struct i915_power_well; 853 854 struct i915_power_well_ops { 855 /* 856 * Synchronize the well's hw state to match the current sw state, for 857 * example enable/disable it based on the current refcount. Called 858 * during driver init and resume time, possibly after first calling 859 * the enable/disable handlers. 860 */ 861 void (*sync_hw)(struct drm_i915_private *dev_priv, 862 struct i915_power_well *power_well); 863 /* 864 * Enable the well and resources that depend on it (for example 865 * interrupts located on the well). Called after the 0->1 refcount 866 * transition. 867 */ 868 void (*enable)(struct drm_i915_private *dev_priv, 869 struct i915_power_well *power_well); 870 /* 871 * Disable the well and resources that depend on it. Called after 872 * the 1->0 refcount transition. 873 */ 874 void (*disable)(struct drm_i915_private *dev_priv, 875 struct i915_power_well *power_well); 876 /* Returns the hw enabled state. */ 877 bool (*is_enabled)(struct drm_i915_private *dev_priv, 878 struct i915_power_well *power_well); 879 }; 880 881 struct i915_power_well_regs { 882 i915_reg_t bios; 883 i915_reg_t driver; 884 i915_reg_t kvmr; 885 i915_reg_t debug; 886 }; 887 888 /* Power well structure for haswell */ 889 struct i915_power_well_desc { 890 const char *name; 891 bool always_on; 892 u64 domains; 893 /* unique identifier for this power well */ 894 enum i915_power_well_id id; 895 /* 896 * Arbitraty data associated with this power well. Platform and power 897 * well specific. 898 */ 899 union { 900 struct { 901 /* 902 * request/status flag index in the PUNIT power well 903 * control/status registers. 904 */ 905 u8 idx; 906 } vlv; 907 struct { 908 enum dpio_phy phy; 909 } bxt; 910 struct { 911 const struct i915_power_well_regs *regs; 912 /* 913 * request/status flag index in the power well 914 * constrol/status registers. 915 */ 916 u8 idx; 917 /* Mask of pipes whose IRQ logic is backed by the pw */ 918 u8 irq_pipe_mask; 919 /* The pw is backing the VGA functionality */ 920 bool has_vga:1; 921 bool has_fuses:1; 922 } hsw; 923 }; 924 const struct i915_power_well_ops *ops; 925 }; 926 927 struct i915_power_well { 928 const struct i915_power_well_desc *desc; 929 /* power well enable/disable usage count */ 930 int count; 931 /* cached hw enabled state */ 932 bool hw_enabled; 933 }; 934 935 struct i915_power_domains { 936 /* 937 * Power wells needed for initialization at driver init and suspend 938 * time are on. They are kept on until after the first modeset. 939 */ 940 bool initializing; 941 bool display_core_suspended; 942 int power_well_count; 943 944 struct mutex lock; 945 int domain_use_count[POWER_DOMAIN_NUM]; 946 struct i915_power_well *power_wells; 947 }; 948 949 #define MAX_L3_SLICES 2 950 struct intel_l3_parity { 951 u32 *remap_info[MAX_L3_SLICES]; 952 struct work_struct error_work; 953 int which_slice; 954 }; 955 956 struct i915_gem_mm { 957 /** Memory allocator for GTT stolen memory */ 958 struct drm_mm stolen; 959 /** Protects the usage of the GTT stolen memory allocator. This is 960 * always the inner lock when overlapping with struct_mutex. */ 961 struct mutex stolen_lock; 962 963 /* Protects bound_list/unbound_list and #drm_i915_gem_object.mm.link */ 964 spinlock_t obj_lock; 965 966 /** List of all objects in gtt_space. Used to restore gtt 967 * mappings on resume */ 968 struct list_head bound_list; 969 /** 970 * List of objects which are not bound to the GTT (thus 971 * are idle and not used by the GPU). These objects may or may 972 * not actually have any pages attached. 973 */ 974 struct list_head unbound_list; 975 976 /** List of all objects in gtt_space, currently mmaped by userspace. 977 * All objects within this list must also be on bound_list. 978 */ 979 struct list_head userfault_list; 980 981 /** 982 * List of objects which are pending destruction. 983 */ 984 struct llist_head free_list; 985 struct work_struct free_work; 986 spinlock_t free_lock; 987 /** 988 * Count of objects pending destructions. Used to skip needlessly 989 * waiting on an RCU barrier if no objects are waiting to be freed. 990 */ 991 atomic_t free_count; 992 993 /** 994 * Small stash of WC pages 995 */ 996 struct pagestash wc_stash; 997 998 /** 999 * tmpfs instance used for shmem backed objects 1000 */ 1001 struct vfsmount *gemfs; 1002 1003 /** PPGTT used for aliasing the PPGTT with the GTT */ 1004 struct i915_hw_ppgtt *aliasing_ppgtt; 1005 1006 struct notifier_block oom_notifier; 1007 struct notifier_block vmap_notifier; 1008 struct shrinker shrinker; 1009 1010 /** LRU list of objects with fence regs on them. */ 1011 struct list_head fence_list; 1012 1013 /** 1014 * Workqueue to fault in userptr pages, flushed by the execbuf 1015 * when required but otherwise left to userspace to try again 1016 * on EAGAIN. 1017 */ 1018 struct workqueue_struct *userptr_wq; 1019 1020 u64 unordered_timeline; 1021 1022 /* the indicator for dispatch video commands on two BSD rings */ 1023 atomic_t bsd_engine_dispatch_index; 1024 1025 /** Bit 6 swizzling required for X tiling */ 1026 uint32_t bit_6_swizzle_x; 1027 /** Bit 6 swizzling required for Y tiling */ 1028 uint32_t bit_6_swizzle_y; 1029 1030 /* accounting, useful for userland debugging */ 1031 spinlock_t object_stat_lock; 1032 u64 object_memory; 1033 u32 object_count; 1034 }; 1035 1036 #define I915_IDLE_ENGINES_TIMEOUT (200) /* in ms */ 1037 1038 #define I915_RESET_TIMEOUT (10 * HZ) /* 10s */ 1039 #define I915_FENCE_TIMEOUT (10 * HZ) /* 10s */ 1040 1041 #define I915_ENGINE_DEAD_TIMEOUT (4 * HZ) /* Seqno, head and subunits dead */ 1042 #define I915_SEQNO_DEAD_TIMEOUT (12 * HZ) /* Seqno dead with active head */ 1043 1044 #define I915_ENGINE_WEDGED_TIMEOUT (60 * HZ) /* Reset but no recovery? */ 1045 1046 #define DP_AUX_A 0x40 1047 #define DP_AUX_B 0x10 1048 #define DP_AUX_C 0x20 1049 #define DP_AUX_D 0x30 1050 #define DP_AUX_E 0x50 1051 #define DP_AUX_F 0x60 1052 1053 #define DDC_PIN_B 0x05 1054 #define DDC_PIN_C 0x04 1055 #define DDC_PIN_D 0x06 1056 1057 struct ddi_vbt_port_info { 1058 int max_tmds_clock; 1059 1060 /* 1061 * This is an index in the HDMI/DVI DDI buffer translation table. 1062 * The special value HDMI_LEVEL_SHIFT_UNKNOWN means the VBT didn't 1063 * populate this field. 1064 */ 1065 #define HDMI_LEVEL_SHIFT_UNKNOWN 0xff 1066 uint8_t hdmi_level_shift; 1067 1068 uint8_t supports_dvi:1; 1069 uint8_t supports_hdmi:1; 1070 uint8_t supports_dp:1; 1071 uint8_t supports_edp:1; 1072 1073 uint8_t alternate_aux_channel; 1074 uint8_t alternate_ddc_pin; 1075 1076 uint8_t dp_boost_level; 1077 uint8_t hdmi_boost_level; 1078 int dp_max_link_rate; /* 0 for not limited by VBT */ 1079 }; 1080 1081 enum psr_lines_to_wait { 1082 PSR_0_LINES_TO_WAIT = 0, 1083 PSR_1_LINE_TO_WAIT, 1084 PSR_4_LINES_TO_WAIT, 1085 PSR_8_LINES_TO_WAIT 1086 }; 1087 1088 struct intel_vbt_data { 1089 struct drm_display_mode *lfp_lvds_vbt_mode; /* if any */ 1090 struct drm_display_mode *sdvo_lvds_vbt_mode; /* if any */ 1091 1092 /* Feature bits */ 1093 unsigned int int_tv_support:1; 1094 unsigned int lvds_dither:1; 1095 unsigned int int_crt_support:1; 1096 unsigned int lvds_use_ssc:1; 1097 unsigned int int_lvds_support:1; 1098 unsigned int display_clock_mode:1; 1099 unsigned int fdi_rx_polarity_inverted:1; 1100 unsigned int panel_type:4; 1101 int lvds_ssc_freq; 1102 unsigned int bios_lvds_val; /* initial [PCH_]LVDS reg val in VBIOS */ 1103 1104 enum drrs_support_type drrs_type; 1105 1106 struct { 1107 int rate; 1108 int lanes; 1109 int preemphasis; 1110 int vswing; 1111 bool low_vswing; 1112 bool initialized; 1113 int bpp; 1114 struct edp_power_seq pps; 1115 } edp; 1116 1117 struct { 1118 bool enable; 1119 bool full_link; 1120 bool require_aux_wakeup; 1121 int idle_frames; 1122 enum psr_lines_to_wait lines_to_wait; 1123 int tp1_wakeup_time_us; 1124 int tp2_tp3_wakeup_time_us; 1125 } psr; 1126 1127 struct { 1128 u16 pwm_freq_hz; 1129 bool present; 1130 bool active_low_pwm; 1131 u8 min_brightness; /* min_brightness/255 of max */ 1132 u8 controller; /* brightness controller number */ 1133 enum intel_backlight_type type; 1134 } backlight; 1135 1136 /* MIPI DSI */ 1137 struct { 1138 u16 panel_id; 1139 struct mipi_config *config; 1140 struct mipi_pps_data *pps; 1141 u16 bl_ports; 1142 u16 cabc_ports; 1143 u8 seq_version; 1144 u32 size; 1145 u8 *data; 1146 const u8 *sequence[MIPI_SEQ_MAX]; 1147 u8 *deassert_seq; /* Used by fixup_mipi_sequences() */ 1148 } dsi; 1149 1150 int crt_ddc_pin; 1151 1152 int child_dev_num; 1153 struct child_device_config *child_dev; 1154 1155 struct ddi_vbt_port_info ddi_port_info[I915_MAX_PORTS]; 1156 struct sdvo_device_mapping sdvo_mappings[2]; 1157 }; 1158 1159 enum intel_ddb_partitioning { 1160 INTEL_DDB_PART_1_2, 1161 INTEL_DDB_PART_5_6, /* IVB+ */ 1162 }; 1163 1164 struct intel_wm_level { 1165 bool enable; 1166 uint32_t pri_val; 1167 uint32_t spr_val; 1168 uint32_t cur_val; 1169 uint32_t fbc_val; 1170 }; 1171 1172 struct ilk_wm_values { 1173 uint32_t wm_pipe[3]; 1174 uint32_t wm_lp[3]; 1175 uint32_t wm_lp_spr[3]; 1176 uint32_t wm_linetime[3]; 1177 bool enable_fbc_wm; 1178 enum intel_ddb_partitioning partitioning; 1179 }; 1180 1181 struct g4x_pipe_wm { 1182 uint16_t plane[I915_MAX_PLANES]; 1183 uint16_t fbc; 1184 }; 1185 1186 struct g4x_sr_wm { 1187 uint16_t plane; 1188 uint16_t cursor; 1189 uint16_t fbc; 1190 }; 1191 1192 struct vlv_wm_ddl_values { 1193 uint8_t plane[I915_MAX_PLANES]; 1194 }; 1195 1196 struct vlv_wm_values { 1197 struct g4x_pipe_wm pipe[3]; 1198 struct g4x_sr_wm sr; 1199 struct vlv_wm_ddl_values ddl[3]; 1200 uint8_t level; 1201 bool cxsr; 1202 }; 1203 1204 struct g4x_wm_values { 1205 struct g4x_pipe_wm pipe[2]; 1206 struct g4x_sr_wm sr; 1207 struct g4x_sr_wm hpll; 1208 bool cxsr; 1209 bool hpll_en; 1210 bool fbc_en; 1211 }; 1212 1213 struct skl_ddb_entry { 1214 uint16_t start, end; /* in number of blocks, 'end' is exclusive */ 1215 }; 1216 1217 static inline uint16_t skl_ddb_entry_size(const struct skl_ddb_entry *entry) 1218 { 1219 return entry->end - entry->start; 1220 } 1221 1222 static inline bool skl_ddb_entry_equal(const struct skl_ddb_entry *e1, 1223 const struct skl_ddb_entry *e2) 1224 { 1225 if (e1->start == e2->start && e1->end == e2->end) 1226 return true; 1227 1228 return false; 1229 } 1230 1231 struct skl_ddb_allocation { 1232 /* packed/y */ 1233 struct skl_ddb_entry plane[I915_MAX_PIPES][I915_MAX_PLANES]; 1234 struct skl_ddb_entry uv_plane[I915_MAX_PIPES][I915_MAX_PLANES]; 1235 u8 enabled_slices; /* GEN11 has configurable 2 slices */ 1236 }; 1237 1238 struct skl_ddb_values { 1239 unsigned dirty_pipes; 1240 struct skl_ddb_allocation ddb; 1241 }; 1242 1243 struct skl_wm_level { 1244 bool plane_en; 1245 uint16_t plane_res_b; 1246 uint8_t plane_res_l; 1247 }; 1248 1249 /* Stores plane specific WM parameters */ 1250 struct skl_wm_params { 1251 bool x_tiled, y_tiled; 1252 bool rc_surface; 1253 bool is_planar; 1254 uint32_t width; 1255 uint8_t cpp; 1256 uint32_t plane_pixel_rate; 1257 uint32_t y_min_scanlines; 1258 uint32_t plane_bytes_per_line; 1259 uint_fixed_16_16_t plane_blocks_per_line; 1260 uint_fixed_16_16_t y_tile_minimum; 1261 uint32_t linetime_us; 1262 uint32_t dbuf_block_size; 1263 }; 1264 1265 /* 1266 * This struct helps tracking the state needed for runtime PM, which puts the 1267 * device in PCI D3 state. Notice that when this happens, nothing on the 1268 * graphics device works, even register access, so we don't get interrupts nor 1269 * anything else. 1270 * 1271 * Every piece of our code that needs to actually touch the hardware needs to 1272 * either call intel_runtime_pm_get or call intel_display_power_get with the 1273 * appropriate power domain. 1274 * 1275 * Our driver uses the autosuspend delay feature, which means we'll only really 1276 * suspend if we stay with zero refcount for a certain amount of time. The 1277 * default value is currently very conservative (see intel_runtime_pm_enable), but 1278 * it can be changed with the standard runtime PM files from sysfs. 1279 * 1280 * The irqs_disabled variable becomes true exactly after we disable the IRQs and 1281 * goes back to false exactly before we reenable the IRQs. We use this variable 1282 * to check if someone is trying to enable/disable IRQs while they're supposed 1283 * to be disabled. This shouldn't happen and we'll print some error messages in 1284 * case it happens. 1285 * 1286 * For more, read the Documentation/power/runtime_pm.txt. 1287 */ 1288 struct i915_runtime_pm { 1289 atomic_t wakeref_count; 1290 bool suspended; 1291 bool irqs_enabled; 1292 }; 1293 1294 enum intel_pipe_crc_source { 1295 INTEL_PIPE_CRC_SOURCE_NONE, 1296 INTEL_PIPE_CRC_SOURCE_PLANE1, 1297 INTEL_PIPE_CRC_SOURCE_PLANE2, 1298 INTEL_PIPE_CRC_SOURCE_PF, 1299 INTEL_PIPE_CRC_SOURCE_PIPE, 1300 /* TV/DP on pre-gen5/vlv can't use the pipe source. */ 1301 INTEL_PIPE_CRC_SOURCE_TV, 1302 INTEL_PIPE_CRC_SOURCE_DP_B, 1303 INTEL_PIPE_CRC_SOURCE_DP_C, 1304 INTEL_PIPE_CRC_SOURCE_DP_D, 1305 INTEL_PIPE_CRC_SOURCE_AUTO, 1306 INTEL_PIPE_CRC_SOURCE_MAX, 1307 }; 1308 1309 #define INTEL_PIPE_CRC_ENTRIES_NR 128 1310 struct intel_pipe_crc { 1311 spinlock_t lock; 1312 int skipped; 1313 enum intel_pipe_crc_source source; 1314 }; 1315 1316 struct i915_frontbuffer_tracking { 1317 spinlock_t lock; 1318 1319 /* 1320 * Tracking bits for delayed frontbuffer flushing du to gpu activity or 1321 * scheduled flips. 1322 */ 1323 unsigned busy_bits; 1324 unsigned flip_bits; 1325 }; 1326 1327 struct i915_wa_reg { 1328 u32 addr; 1329 u32 value; 1330 /* bitmask representing WA bits */ 1331 u32 mask; 1332 }; 1333 1334 #define I915_MAX_WA_REGS 16 1335 1336 struct i915_workarounds { 1337 struct i915_wa_reg reg[I915_MAX_WA_REGS]; 1338 u32 count; 1339 }; 1340 1341 struct i915_virtual_gpu { 1342 bool active; 1343 u32 caps; 1344 }; 1345 1346 /* used in computing the new watermarks state */ 1347 struct intel_wm_config { 1348 unsigned int num_pipes_active; 1349 bool sprites_enabled; 1350 bool sprites_scaled; 1351 }; 1352 1353 struct i915_oa_format { 1354 u32 format; 1355 int size; 1356 }; 1357 1358 struct i915_oa_reg { 1359 i915_reg_t addr; 1360 u32 value; 1361 }; 1362 1363 struct i915_oa_config { 1364 char uuid[UUID_STRING_LEN + 1]; 1365 int id; 1366 1367 const struct i915_oa_reg *mux_regs; 1368 u32 mux_regs_len; 1369 const struct i915_oa_reg *b_counter_regs; 1370 u32 b_counter_regs_len; 1371 const struct i915_oa_reg *flex_regs; 1372 u32 flex_regs_len; 1373 1374 struct attribute_group sysfs_metric; 1375 struct attribute *attrs[2]; 1376 struct device_attribute sysfs_metric_id; 1377 1378 atomic_t ref_count; 1379 }; 1380 1381 struct i915_perf_stream; 1382 1383 /** 1384 * struct i915_perf_stream_ops - the OPs to support a specific stream type 1385 */ 1386 struct i915_perf_stream_ops { 1387 /** 1388 * @enable: Enables the collection of HW samples, either in response to 1389 * `I915_PERF_IOCTL_ENABLE` or implicitly called when stream is opened 1390 * without `I915_PERF_FLAG_DISABLED`. 1391 */ 1392 void (*enable)(struct i915_perf_stream *stream); 1393 1394 /** 1395 * @disable: Disables the collection of HW samples, either in response 1396 * to `I915_PERF_IOCTL_DISABLE` or implicitly called before destroying 1397 * the stream. 1398 */ 1399 void (*disable)(struct i915_perf_stream *stream); 1400 1401 /** 1402 * @poll_wait: Call poll_wait, passing a wait queue that will be woken 1403 * once there is something ready to read() for the stream 1404 */ 1405 void (*poll_wait)(struct i915_perf_stream *stream, 1406 struct file *file, 1407 poll_table *wait); 1408 1409 /** 1410 * @wait_unlocked: For handling a blocking read, wait until there is 1411 * something to ready to read() for the stream. E.g. wait on the same 1412 * wait queue that would be passed to poll_wait(). 1413 */ 1414 int (*wait_unlocked)(struct i915_perf_stream *stream); 1415 1416 /** 1417 * @read: Copy buffered metrics as records to userspace 1418 * **buf**: the userspace, destination buffer 1419 * **count**: the number of bytes to copy, requested by userspace 1420 * **offset**: zero at the start of the read, updated as the read 1421 * proceeds, it represents how many bytes have been copied so far and 1422 * the buffer offset for copying the next record. 1423 * 1424 * Copy as many buffered i915 perf samples and records for this stream 1425 * to userspace as will fit in the given buffer. 1426 * 1427 * Only write complete records; returning -%ENOSPC if there isn't room 1428 * for a complete record. 1429 * 1430 * Return any error condition that results in a short read such as 1431 * -%ENOSPC or -%EFAULT, even though these may be squashed before 1432 * returning to userspace. 1433 */ 1434 int (*read)(struct i915_perf_stream *stream, 1435 char __user *buf, 1436 size_t count, 1437 size_t *offset); 1438 1439 /** 1440 * @destroy: Cleanup any stream specific resources. 1441 * 1442 * The stream will always be disabled before this is called. 1443 */ 1444 void (*destroy)(struct i915_perf_stream *stream); 1445 }; 1446 1447 /** 1448 * struct i915_perf_stream - state for a single open stream FD 1449 */ 1450 struct i915_perf_stream { 1451 /** 1452 * @dev_priv: i915 drm device 1453 */ 1454 struct drm_i915_private *dev_priv; 1455 1456 /** 1457 * @link: Links the stream into ``&drm_i915_private->streams`` 1458 */ 1459 struct list_head link; 1460 1461 /** 1462 * @sample_flags: Flags representing the `DRM_I915_PERF_PROP_SAMPLE_*` 1463 * properties given when opening a stream, representing the contents 1464 * of a single sample as read() by userspace. 1465 */ 1466 u32 sample_flags; 1467 1468 /** 1469 * @sample_size: Considering the configured contents of a sample 1470 * combined with the required header size, this is the total size 1471 * of a single sample record. 1472 */ 1473 int sample_size; 1474 1475 /** 1476 * @ctx: %NULL if measuring system-wide across all contexts or a 1477 * specific context that is being monitored. 1478 */ 1479 struct i915_gem_context *ctx; 1480 1481 /** 1482 * @enabled: Whether the stream is currently enabled, considering 1483 * whether the stream was opened in a disabled state and based 1484 * on `I915_PERF_IOCTL_ENABLE` and `I915_PERF_IOCTL_DISABLE` calls. 1485 */ 1486 bool enabled; 1487 1488 /** 1489 * @ops: The callbacks providing the implementation of this specific 1490 * type of configured stream. 1491 */ 1492 const struct i915_perf_stream_ops *ops; 1493 1494 /** 1495 * @oa_config: The OA configuration used by the stream. 1496 */ 1497 struct i915_oa_config *oa_config; 1498 }; 1499 1500 /** 1501 * struct i915_oa_ops - Gen specific implementation of an OA unit stream 1502 */ 1503 struct i915_oa_ops { 1504 /** 1505 * @is_valid_b_counter_reg: Validates register's address for 1506 * programming boolean counters for a particular platform. 1507 */ 1508 bool (*is_valid_b_counter_reg)(struct drm_i915_private *dev_priv, 1509 u32 addr); 1510 1511 /** 1512 * @is_valid_mux_reg: Validates register's address for programming mux 1513 * for a particular platform. 1514 */ 1515 bool (*is_valid_mux_reg)(struct drm_i915_private *dev_priv, u32 addr); 1516 1517 /** 1518 * @is_valid_flex_reg: Validates register's address for programming 1519 * flex EU filtering for a particular platform. 1520 */ 1521 bool (*is_valid_flex_reg)(struct drm_i915_private *dev_priv, u32 addr); 1522 1523 /** 1524 * @init_oa_buffer: Resets the head and tail pointers of the 1525 * circular buffer for periodic OA reports. 1526 * 1527 * Called when first opening a stream for OA metrics, but also may be 1528 * called in response to an OA buffer overflow or other error 1529 * condition. 1530 * 1531 * Note it may be necessary to clear the full OA buffer here as part of 1532 * maintaining the invariable that new reports must be written to 1533 * zeroed memory for us to be able to reliable detect if an expected 1534 * report has not yet landed in memory. (At least on Haswell the OA 1535 * buffer tail pointer is not synchronized with reports being visible 1536 * to the CPU) 1537 */ 1538 void (*init_oa_buffer)(struct drm_i915_private *dev_priv); 1539 1540 /** 1541 * @enable_metric_set: Selects and applies any MUX configuration to set 1542 * up the Boolean and Custom (B/C) counters that are part of the 1543 * counter reports being sampled. May apply system constraints such as 1544 * disabling EU clock gating as required. 1545 */ 1546 int (*enable_metric_set)(struct drm_i915_private *dev_priv, 1547 const struct i915_oa_config *oa_config); 1548 1549 /** 1550 * @disable_metric_set: Remove system constraints associated with using 1551 * the OA unit. 1552 */ 1553 void (*disable_metric_set)(struct drm_i915_private *dev_priv); 1554 1555 /** 1556 * @oa_enable: Enable periodic sampling 1557 */ 1558 void (*oa_enable)(struct drm_i915_private *dev_priv); 1559 1560 /** 1561 * @oa_disable: Disable periodic sampling 1562 */ 1563 void (*oa_disable)(struct drm_i915_private *dev_priv); 1564 1565 /** 1566 * @read: Copy data from the circular OA buffer into a given userspace 1567 * buffer. 1568 */ 1569 int (*read)(struct i915_perf_stream *stream, 1570 char __user *buf, 1571 size_t count, 1572 size_t *offset); 1573 1574 /** 1575 * @oa_hw_tail_read: read the OA tail pointer register 1576 * 1577 * In particular this enables us to share all the fiddly code for 1578 * handling the OA unit tail pointer race that affects multiple 1579 * generations. 1580 */ 1581 u32 (*oa_hw_tail_read)(struct drm_i915_private *dev_priv); 1582 }; 1583 1584 struct intel_cdclk_state { 1585 unsigned int cdclk, vco, ref, bypass; 1586 u8 voltage_level; 1587 }; 1588 1589 struct drm_i915_private { 1590 struct drm_device drm; 1591 1592 struct kmem_cache *objects; 1593 struct kmem_cache *vmas; 1594 struct kmem_cache *luts; 1595 struct kmem_cache *requests; 1596 struct kmem_cache *dependencies; 1597 struct kmem_cache *priorities; 1598 1599 const struct intel_device_info info; 1600 struct intel_driver_caps caps; 1601 1602 /** 1603 * Data Stolen Memory - aka "i915 stolen memory" gives us the start and 1604 * end of stolen which we can optionally use to create GEM objects 1605 * backed by stolen memory. Note that stolen_usable_size tells us 1606 * exactly how much of this we are actually allowed to use, given that 1607 * some portion of it is in fact reserved for use by hardware functions. 1608 */ 1609 struct resource dsm; 1610 /** 1611 * Reseved portion of Data Stolen Memory 1612 */ 1613 struct resource dsm_reserved; 1614 1615 /* 1616 * Stolen memory is segmented in hardware with different portions 1617 * offlimits to certain functions. 1618 * 1619 * The drm_mm is initialised to the total accessible range, as found 1620 * from the PCI config. On Broadwell+, this is further restricted to 1621 * avoid the first page! The upper end of stolen memory is reserved for 1622 * hardware functions and similarly removed from the accessible range. 1623 */ 1624 resource_size_t stolen_usable_size; /* Total size minus reserved ranges */ 1625 1626 void __iomem *regs; 1627 1628 struct intel_uncore uncore; 1629 1630 struct i915_virtual_gpu vgpu; 1631 1632 struct intel_gvt *gvt; 1633 1634 struct intel_wopcm wopcm; 1635 1636 struct intel_huc huc; 1637 struct intel_guc guc; 1638 1639 struct intel_csr csr; 1640 1641 struct intel_gmbus gmbus[GMBUS_NUM_PINS]; 1642 1643 /** gmbus_mutex protects against concurrent usage of the single hw gmbus 1644 * controller on different i2c buses. */ 1645 struct mutex gmbus_mutex; 1646 1647 /** 1648 * Base address of where the gmbus and gpio blocks are located (either 1649 * on PCH or on SoC for platforms without PCH). 1650 */ 1651 uint32_t gpio_mmio_base; 1652 1653 /* MMIO base address for MIPI regs */ 1654 uint32_t mipi_mmio_base; 1655 1656 uint32_t psr_mmio_base; 1657 1658 uint32_t pps_mmio_base; 1659 1660 wait_queue_head_t gmbus_wait_queue; 1661 1662 struct pci_dev *bridge_dev; 1663 struct intel_engine_cs *engine[I915_NUM_ENGINES]; 1664 /* Context used internally to idle the GPU and setup initial state */ 1665 struct i915_gem_context *kernel_context; 1666 /* Context only to be used for injecting preemption commands */ 1667 struct i915_gem_context *preempt_context; 1668 struct intel_engine_cs *engine_class[MAX_ENGINE_CLASS + 1] 1669 [MAX_ENGINE_INSTANCE + 1]; 1670 1671 struct resource mch_res; 1672 1673 /* protects the irq masks */ 1674 spinlock_t irq_lock; 1675 1676 bool display_irqs_enabled; 1677 1678 /* To control wakeup latency, e.g. for irq-driven dp aux transfers. */ 1679 struct pm_qos_request pm_qos; 1680 1681 /* Sideband mailbox protection */ 1682 struct mutex sb_lock; 1683 1684 /** Cached value of IMR to avoid reads in updating the bitfield */ 1685 union { 1686 u32 irq_mask; 1687 u32 de_irq_mask[I915_MAX_PIPES]; 1688 }; 1689 u32 gt_irq_mask; 1690 u32 pm_imr; 1691 u32 pm_ier; 1692 u32 pm_rps_events; 1693 u32 pm_guc_events; 1694 u32 pipestat_irq_mask[I915_MAX_PIPES]; 1695 1696 struct i915_hotplug hotplug; 1697 struct intel_fbc fbc; 1698 struct i915_drrs drrs; 1699 struct intel_opregion opregion; 1700 struct intel_vbt_data vbt; 1701 1702 bool preserve_bios_swizzle; 1703 1704 /* overlay */ 1705 struct intel_overlay *overlay; 1706 1707 /* backlight registers and fields in struct intel_panel */ 1708 struct mutex backlight_lock; 1709 1710 /* LVDS info */ 1711 bool no_aux_handshake; 1712 1713 /* protects panel power sequencer state */ 1714 struct mutex pps_mutex; 1715 1716 struct drm_i915_fence_reg fence_regs[I915_MAX_NUM_FENCES]; /* assume 965 */ 1717 int num_fence_regs; /* 8 on pre-965, 16 otherwise */ 1718 1719 unsigned int fsb_freq, mem_freq, is_ddr3; 1720 unsigned int skl_preferred_vco_freq; 1721 unsigned int max_cdclk_freq; 1722 1723 unsigned int max_dotclk_freq; 1724 unsigned int rawclk_freq; 1725 unsigned int hpll_freq; 1726 unsigned int fdi_pll_freq; 1727 unsigned int czclk_freq; 1728 1729 struct { 1730 /* 1731 * The current logical cdclk state. 1732 * See intel_atomic_state.cdclk.logical 1733 * 1734 * For reading holding any crtc lock is sufficient, 1735 * for writing must hold all of them. 1736 */ 1737 struct intel_cdclk_state logical; 1738 /* 1739 * The current actual cdclk state. 1740 * See intel_atomic_state.cdclk.actual 1741 */ 1742 struct intel_cdclk_state actual; 1743 /* The current hardware cdclk state */ 1744 struct intel_cdclk_state hw; 1745 } cdclk; 1746 1747 /** 1748 * wq - Driver workqueue for GEM. 1749 * 1750 * NOTE: Work items scheduled here are not allowed to grab any modeset 1751 * locks, for otherwise the flushing done in the pageflip code will 1752 * result in deadlocks. 1753 */ 1754 struct workqueue_struct *wq; 1755 1756 /* ordered wq for modesets */ 1757 struct workqueue_struct *modeset_wq; 1758 1759 /* Display functions */ 1760 struct drm_i915_display_funcs display; 1761 1762 /* PCH chipset type */ 1763 enum intel_pch pch_type; 1764 unsigned short pch_id; 1765 1766 unsigned long quirks; 1767 1768 struct drm_atomic_state *modeset_restore_state; 1769 struct drm_modeset_acquire_ctx reset_ctx; 1770 1771 struct i915_ggtt ggtt; /* VM representing the global address space */ 1772 1773 struct i915_gem_mm mm; 1774 DECLARE_HASHTABLE(mm_structs, 7); 1775 struct mutex mm_lock; 1776 1777 struct intel_ppat ppat; 1778 1779 /* Kernel Modesetting */ 1780 1781 struct intel_crtc *plane_to_crtc_mapping[I915_MAX_PIPES]; 1782 struct intel_crtc *pipe_to_crtc_mapping[I915_MAX_PIPES]; 1783 1784 #ifdef CONFIG_DEBUG_FS 1785 struct intel_pipe_crc pipe_crc[I915_MAX_PIPES]; 1786 #endif 1787 1788 /* dpll and cdclk state is protected by connection_mutex */ 1789 int num_shared_dpll; 1790 struct intel_shared_dpll shared_dplls[I915_NUM_PLLS]; 1791 const struct intel_dpll_mgr *dpll_mgr; 1792 1793 /* 1794 * dpll_lock serializes intel_{prepare,enable,disable}_shared_dpll. 1795 * Must be global rather than per dpll, because on some platforms 1796 * plls share registers. 1797 */ 1798 struct mutex dpll_lock; 1799 1800 unsigned int active_crtcs; 1801 /* minimum acceptable cdclk for each pipe */ 1802 int min_cdclk[I915_MAX_PIPES]; 1803 /* minimum acceptable voltage level for each pipe */ 1804 u8 min_voltage_level[I915_MAX_PIPES]; 1805 1806 int dpio_phy_iosf_port[I915_NUM_PHYS_VLV]; 1807 1808 struct i915_workarounds workarounds; 1809 struct i915_wa_list gt_wa_list; 1810 1811 struct i915_frontbuffer_tracking fb_tracking; 1812 1813 struct intel_atomic_helper { 1814 struct llist_head free_list; 1815 struct work_struct free_work; 1816 } atomic_helper; 1817 1818 u16 orig_clock; 1819 1820 bool mchbar_need_disable; 1821 1822 struct intel_l3_parity l3_parity; 1823 1824 /* Cannot be determined by PCIID. You must always read a register. */ 1825 u32 edram_cap; 1826 1827 /* 1828 * Protects RPS/RC6 register access and PCU communication. 1829 * Must be taken after struct_mutex if nested. Note that 1830 * this lock may be held for long periods of time when 1831 * talking to hw - so only take it when talking to hw! 1832 */ 1833 struct mutex pcu_lock; 1834 1835 /* gen6+ GT PM state */ 1836 struct intel_gen6_power_mgmt gt_pm; 1837 1838 /* ilk-only ips/rps state. Everything in here is protected by the global 1839 * mchdev_lock in intel_pm.c */ 1840 struct intel_ilk_power_mgmt ips; 1841 1842 struct i915_power_domains power_domains; 1843 1844 struct i915_psr psr; 1845 1846 struct i915_gpu_error gpu_error; 1847 1848 struct drm_i915_gem_object *vlv_pctx; 1849 1850 /* list of fbdev register on this device */ 1851 struct intel_fbdev *fbdev; 1852 struct work_struct fbdev_suspend_work; 1853 1854 struct drm_property *broadcast_rgb_property; 1855 struct drm_property *force_audio_property; 1856 1857 /* hda/i915 audio component */ 1858 struct i915_audio_component *audio_component; 1859 bool audio_component_registered; 1860 /** 1861 * av_mutex - mutex for audio/video sync 1862 * 1863 */ 1864 struct mutex av_mutex; 1865 1866 struct { 1867 struct mutex mutex; 1868 struct list_head list; 1869 struct llist_head free_list; 1870 struct work_struct free_work; 1871 1872 /* The hw wants to have a stable context identifier for the 1873 * lifetime of the context (for OA, PASID, faults, etc). 1874 * This is limited in execlists to 21 bits. 1875 */ 1876 struct ida hw_ida; 1877 #define MAX_CONTEXT_HW_ID (1<<21) /* exclusive */ 1878 #define MAX_GUC_CONTEXT_HW_ID (1 << 20) /* exclusive */ 1879 #define GEN11_MAX_CONTEXT_HW_ID (1<<11) /* exclusive */ 1880 struct list_head hw_id_list; 1881 } contexts; 1882 1883 u32 fdi_rx_config; 1884 1885 /* Shadow for DISPLAY_PHY_CONTROL which can't be safely read */ 1886 u32 chv_phy_control; 1887 /* 1888 * Shadows for CHV DPLL_MD regs to keep the state 1889 * checker somewhat working in the presence hardware 1890 * crappiness (can't read out DPLL_MD for pipes B & C). 1891 */ 1892 u32 chv_dpll_md[I915_MAX_PIPES]; 1893 u32 bxt_phy_grc; 1894 1895 u32 suspend_count; 1896 bool power_domains_suspended; 1897 struct i915_suspend_saved_registers regfile; 1898 struct vlv_s0ix_state vlv_s0ix_state; 1899 1900 enum { 1901 I915_SAGV_UNKNOWN = 0, 1902 I915_SAGV_DISABLED, 1903 I915_SAGV_ENABLED, 1904 I915_SAGV_NOT_CONTROLLED 1905 } sagv_status; 1906 1907 struct { 1908 /* 1909 * Raw watermark latency values: 1910 * in 0.1us units for WM0, 1911 * in 0.5us units for WM1+. 1912 */ 1913 /* primary */ 1914 uint16_t pri_latency[5]; 1915 /* sprite */ 1916 uint16_t spr_latency[5]; 1917 /* cursor */ 1918 uint16_t cur_latency[5]; 1919 /* 1920 * Raw watermark memory latency values 1921 * for SKL for all 8 levels 1922 * in 1us units. 1923 */ 1924 uint16_t skl_latency[8]; 1925 1926 /* current hardware state */ 1927 union { 1928 struct ilk_wm_values hw; 1929 struct skl_ddb_values skl_hw; 1930 struct vlv_wm_values vlv; 1931 struct g4x_wm_values g4x; 1932 }; 1933 1934 uint8_t max_level; 1935 1936 /* 1937 * Should be held around atomic WM register writing; also 1938 * protects * intel_crtc->wm.active and 1939 * cstate->wm.need_postvbl_update. 1940 */ 1941 struct mutex wm_mutex; 1942 1943 /* 1944 * Set during HW readout of watermarks/DDB. Some platforms 1945 * need to know when we're still using BIOS-provided values 1946 * (which we don't fully trust). 1947 */ 1948 bool distrust_bios_wm; 1949 } wm; 1950 1951 struct dram_info { 1952 bool valid; 1953 bool is_16gb_dimm; 1954 u8 num_channels; 1955 enum dram_rank { 1956 I915_DRAM_RANK_INVALID = 0, 1957 I915_DRAM_RANK_SINGLE, 1958 I915_DRAM_RANK_DUAL 1959 } rank; 1960 u32 bandwidth_kbps; 1961 bool symmetric_memory; 1962 } dram_info; 1963 1964 struct i915_runtime_pm runtime_pm; 1965 1966 struct { 1967 bool initialized; 1968 1969 struct kobject *metrics_kobj; 1970 struct ctl_table_header *sysctl_header; 1971 1972 /* 1973 * Lock associated with adding/modifying/removing OA configs 1974 * in dev_priv->perf.metrics_idr. 1975 */ 1976 struct mutex metrics_lock; 1977 1978 /* 1979 * List of dynamic configurations, you need to hold 1980 * dev_priv->perf.metrics_lock to access it. 1981 */ 1982 struct idr metrics_idr; 1983 1984 /* 1985 * Lock associated with anything below within this structure 1986 * except exclusive_stream. 1987 */ 1988 struct mutex lock; 1989 struct list_head streams; 1990 1991 struct { 1992 /* 1993 * The stream currently using the OA unit. If accessed 1994 * outside a syscall associated to its file 1995 * descriptor, you need to hold 1996 * dev_priv->drm.struct_mutex. 1997 */ 1998 struct i915_perf_stream *exclusive_stream; 1999 2000 struct intel_context *pinned_ctx; 2001 u32 specific_ctx_id; 2002 u32 specific_ctx_id_mask; 2003 2004 struct hrtimer poll_check_timer; 2005 wait_queue_head_t poll_wq; 2006 bool pollin; 2007 2008 /** 2009 * For rate limiting any notifications of spurious 2010 * invalid OA reports 2011 */ 2012 struct ratelimit_state spurious_report_rs; 2013 2014 bool periodic; 2015 int period_exponent; 2016 2017 struct i915_oa_config test_config; 2018 2019 struct { 2020 struct i915_vma *vma; 2021 u8 *vaddr; 2022 u32 last_ctx_id; 2023 int format; 2024 int format_size; 2025 2026 /** 2027 * Locks reads and writes to all head/tail state 2028 * 2029 * Consider: the head and tail pointer state 2030 * needs to be read consistently from a hrtimer 2031 * callback (atomic context) and read() fop 2032 * (user context) with tail pointer updates 2033 * happening in atomic context and head updates 2034 * in user context and the (unlikely) 2035 * possibility of read() errors needing to 2036 * reset all head/tail state. 2037 * 2038 * Note: Contention or performance aren't 2039 * currently a significant concern here 2040 * considering the relatively low frequency of 2041 * hrtimer callbacks (5ms period) and that 2042 * reads typically only happen in response to a 2043 * hrtimer event and likely complete before the 2044 * next callback. 2045 * 2046 * Note: This lock is not held *while* reading 2047 * and copying data to userspace so the value 2048 * of head observed in htrimer callbacks won't 2049 * represent any partial consumption of data. 2050 */ 2051 spinlock_t ptr_lock; 2052 2053 /** 2054 * One 'aging' tail pointer and one 'aged' 2055 * tail pointer ready to used for reading. 2056 * 2057 * Initial values of 0xffffffff are invalid 2058 * and imply that an update is required 2059 * (and should be ignored by an attempted 2060 * read) 2061 */ 2062 struct { 2063 u32 offset; 2064 } tails[2]; 2065 2066 /** 2067 * Index for the aged tail ready to read() 2068 * data up to. 2069 */ 2070 unsigned int aged_tail_idx; 2071 2072 /** 2073 * A monotonic timestamp for when the current 2074 * aging tail pointer was read; used to 2075 * determine when it is old enough to trust. 2076 */ 2077 u64 aging_timestamp; 2078 2079 /** 2080 * Although we can always read back the head 2081 * pointer register, we prefer to avoid 2082 * trusting the HW state, just to avoid any 2083 * risk that some hardware condition could 2084 * somehow bump the head pointer unpredictably 2085 * and cause us to forward the wrong OA buffer 2086 * data to userspace. 2087 */ 2088 u32 head; 2089 } oa_buffer; 2090 2091 u32 gen7_latched_oastatus1; 2092 u32 ctx_oactxctrl_offset; 2093 u32 ctx_flexeu0_offset; 2094 2095 /** 2096 * The RPT_ID/reason field for Gen8+ includes a bit 2097 * to determine if the CTX ID in the report is valid 2098 * but the specific bit differs between Gen 8 and 9 2099 */ 2100 u32 gen8_valid_ctx_bit; 2101 2102 struct i915_oa_ops ops; 2103 const struct i915_oa_format *oa_formats; 2104 } oa; 2105 } perf; 2106 2107 /* Abstract the submission mechanism (legacy ringbuffer or execlists) away */ 2108 struct { 2109 void (*resume)(struct drm_i915_private *); 2110 void (*cleanup_engine)(struct intel_engine_cs *engine); 2111 2112 struct list_head timelines; 2113 2114 struct list_head active_rings; 2115 struct list_head closed_vma; 2116 u32 active_requests; 2117 u32 request_serial; 2118 2119 /** 2120 * Is the GPU currently considered idle, or busy executing 2121 * userspace requests? Whilst idle, we allow runtime power 2122 * management to power down the hardware and display clocks. 2123 * In order to reduce the effect on performance, there 2124 * is a slight delay before we do so. 2125 */ 2126 bool awake; 2127 2128 /** 2129 * The number of times we have woken up. 2130 */ 2131 unsigned int epoch; 2132 #define I915_EPOCH_INVALID 0 2133 2134 /** 2135 * We leave the user IRQ off as much as possible, 2136 * but this means that requests will finish and never 2137 * be retired once the system goes idle. Set a timer to 2138 * fire periodically while the ring is running. When it 2139 * fires, go retire requests. 2140 */ 2141 struct delayed_work retire_work; 2142 2143 /** 2144 * When we detect an idle GPU, we want to turn on 2145 * powersaving features. So once we see that there 2146 * are no more requests outstanding and no more 2147 * arrive within a small period of time, we fire 2148 * off the idle_work. 2149 */ 2150 struct delayed_work idle_work; 2151 2152 ktime_t last_init_time; 2153 2154 struct i915_vma *scratch; 2155 } gt; 2156 2157 /* perform PHY state sanity checks? */ 2158 bool chv_phy_assert[2]; 2159 2160 bool ipc_enabled; 2161 2162 /* Used to save the pipe-to-encoder mapping for audio */ 2163 struct intel_encoder *av_enc_map[I915_MAX_PIPES]; 2164 2165 /* necessary resource sharing with HDMI LPE audio driver. */ 2166 struct { 2167 struct platform_device *platdev; 2168 int irq; 2169 } lpe_audio; 2170 2171 struct i915_pmu pmu; 2172 2173 /* 2174 * NOTE: This is the dri1/ums dungeon, don't add stuff here. Your patch 2175 * will be rejected. Instead look for a better place. 2176 */ 2177 }; 2178 2179 struct dram_channel_info { 2180 struct info { 2181 u8 size, width; 2182 enum dram_rank rank; 2183 } l_info, s_info; 2184 enum dram_rank rank; 2185 bool is_16gb_dimm; 2186 }; 2187 2188 static inline struct drm_i915_private *to_i915(const struct drm_device *dev) 2189 { 2190 return container_of(dev, struct drm_i915_private, drm); 2191 } 2192 2193 static inline struct drm_i915_private *kdev_to_i915(struct device *kdev) 2194 { 2195 return to_i915(dev_get_drvdata(kdev)); 2196 } 2197 2198 static inline struct drm_i915_private *wopcm_to_i915(struct intel_wopcm *wopcm) 2199 { 2200 return container_of(wopcm, struct drm_i915_private, wopcm); 2201 } 2202 2203 static inline struct drm_i915_private *guc_to_i915(struct intel_guc *guc) 2204 { 2205 return container_of(guc, struct drm_i915_private, guc); 2206 } 2207 2208 static inline struct drm_i915_private *huc_to_i915(struct intel_huc *huc) 2209 { 2210 return container_of(huc, struct drm_i915_private, huc); 2211 } 2212 2213 /* Simple iterator over all initialised engines */ 2214 #define for_each_engine(engine__, dev_priv__, id__) \ 2215 for ((id__) = 0; \ 2216 (id__) < I915_NUM_ENGINES; \ 2217 (id__)++) \ 2218 for_each_if ((engine__) = (dev_priv__)->engine[(id__)]) 2219 2220 /* Iterator over subset of engines selected by mask */ 2221 #define for_each_engine_masked(engine__, dev_priv__, mask__, tmp__) \ 2222 for ((tmp__) = (mask__) & INTEL_INFO(dev_priv__)->ring_mask; \ 2223 (tmp__) ? \ 2224 ((engine__) = (dev_priv__)->engine[__mask_next_bit(tmp__)]), 1 : \ 2225 0;) 2226 2227 enum hdmi_force_audio { 2228 HDMI_AUDIO_OFF_DVI = -2, /* no aux data for HDMI-DVI converter */ 2229 HDMI_AUDIO_OFF, /* force turn off HDMI audio */ 2230 HDMI_AUDIO_AUTO, /* trust EDID */ 2231 HDMI_AUDIO_ON, /* force turn on HDMI audio */ 2232 }; 2233 2234 #define I915_GTT_OFFSET_NONE ((u32)-1) 2235 2236 /* 2237 * Frontbuffer tracking bits. Set in obj->frontbuffer_bits while a gem bo is 2238 * considered to be the frontbuffer for the given plane interface-wise. This 2239 * doesn't mean that the hw necessarily already scans it out, but that any 2240 * rendering (by the cpu or gpu) will land in the frontbuffer eventually. 2241 * 2242 * We have one bit per pipe and per scanout plane type. 2243 */ 2244 #define INTEL_FRONTBUFFER_BITS_PER_PIPE 8 2245 #define INTEL_FRONTBUFFER(pipe, plane_id) ({ \ 2246 BUILD_BUG_ON(INTEL_FRONTBUFFER_BITS_PER_PIPE * I915_MAX_PIPES > 32); \ 2247 BUILD_BUG_ON(I915_MAX_PLANES > INTEL_FRONTBUFFER_BITS_PER_PIPE); \ 2248 BIT((plane_id) + INTEL_FRONTBUFFER_BITS_PER_PIPE * (pipe)); \ 2249 }) 2250 #define INTEL_FRONTBUFFER_OVERLAY(pipe) \ 2251 BIT(INTEL_FRONTBUFFER_BITS_PER_PIPE - 1 + INTEL_FRONTBUFFER_BITS_PER_PIPE * (pipe)) 2252 #define INTEL_FRONTBUFFER_ALL_MASK(pipe) \ 2253 GENMASK(INTEL_FRONTBUFFER_BITS_PER_PIPE * ((pipe) + 1) - 1, \ 2254 INTEL_FRONTBUFFER_BITS_PER_PIPE * (pipe)) 2255 2256 /* 2257 * Optimised SGL iterator for GEM objects 2258 */ 2259 static __always_inline struct sgt_iter { 2260 struct scatterlist *sgp; 2261 union { 2262 unsigned long pfn; 2263 dma_addr_t dma; 2264 }; 2265 unsigned int curr; 2266 unsigned int max; 2267 } __sgt_iter(struct scatterlist *sgl, bool dma) { 2268 struct sgt_iter s = { .sgp = sgl }; 2269 2270 if (s.sgp) { 2271 s.max = s.curr = s.sgp->offset; 2272 s.max += s.sgp->length; 2273 if (dma) 2274 s.dma = sg_dma_address(s.sgp); 2275 else 2276 s.pfn = page_to_pfn(sg_page(s.sgp)); 2277 } 2278 2279 return s; 2280 } 2281 2282 static inline struct scatterlist *____sg_next(struct scatterlist *sg) 2283 { 2284 ++sg; 2285 if (unlikely(sg_is_chain(sg))) 2286 sg = sg_chain_ptr(sg); 2287 return sg; 2288 } 2289 2290 /** 2291 * __sg_next - return the next scatterlist entry in a list 2292 * @sg: The current sg entry 2293 * 2294 * Description: 2295 * If the entry is the last, return NULL; otherwise, step to the next 2296 * element in the array (@sg@+1). If that's a chain pointer, follow it; 2297 * otherwise just return the pointer to the current element. 2298 **/ 2299 static inline struct scatterlist *__sg_next(struct scatterlist *sg) 2300 { 2301 return sg_is_last(sg) ? NULL : ____sg_next(sg); 2302 } 2303 2304 /** 2305 * for_each_sgt_dma - iterate over the DMA addresses of the given sg_table 2306 * @__dmap: DMA address (output) 2307 * @__iter: 'struct sgt_iter' (iterator state, internal) 2308 * @__sgt: sg_table to iterate over (input) 2309 */ 2310 #define for_each_sgt_dma(__dmap, __iter, __sgt) \ 2311 for ((__iter) = __sgt_iter((__sgt)->sgl, true); \ 2312 ((__dmap) = (__iter).dma + (__iter).curr); \ 2313 (((__iter).curr += I915_GTT_PAGE_SIZE) >= (__iter).max) ? \ 2314 (__iter) = __sgt_iter(__sg_next((__iter).sgp), true), 0 : 0) 2315 2316 /** 2317 * for_each_sgt_page - iterate over the pages of the given sg_table 2318 * @__pp: page pointer (output) 2319 * @__iter: 'struct sgt_iter' (iterator state, internal) 2320 * @__sgt: sg_table to iterate over (input) 2321 */ 2322 #define for_each_sgt_page(__pp, __iter, __sgt) \ 2323 for ((__iter) = __sgt_iter((__sgt)->sgl, false); \ 2324 ((__pp) = (__iter).pfn == 0 ? NULL : \ 2325 pfn_to_page((__iter).pfn + ((__iter).curr >> PAGE_SHIFT))); \ 2326 (((__iter).curr += PAGE_SIZE) >= (__iter).max) ? \ 2327 (__iter) = __sgt_iter(__sg_next((__iter).sgp), false), 0 : 0) 2328 2329 static inline unsigned int i915_sg_page_sizes(struct scatterlist *sg) 2330 { 2331 unsigned int page_sizes; 2332 2333 page_sizes = 0; 2334 while (sg) { 2335 GEM_BUG_ON(sg->offset); 2336 GEM_BUG_ON(!IS_ALIGNED(sg->length, PAGE_SIZE)); 2337 page_sizes |= sg->length; 2338 sg = __sg_next(sg); 2339 } 2340 2341 return page_sizes; 2342 } 2343 2344 static inline unsigned int i915_sg_segment_size(void) 2345 { 2346 unsigned int size = swiotlb_max_segment(); 2347 2348 if (size == 0) 2349 return SCATTERLIST_MAX_SEGMENT; 2350 2351 size = rounddown(size, PAGE_SIZE); 2352 /* swiotlb_max_segment_size can return 1 byte when it means one page. */ 2353 if (size < PAGE_SIZE) 2354 size = PAGE_SIZE; 2355 2356 return size; 2357 } 2358 2359 static inline const struct intel_device_info * 2360 intel_info(const struct drm_i915_private *dev_priv) 2361 { 2362 return &dev_priv->info; 2363 } 2364 2365 #define INTEL_INFO(dev_priv) intel_info((dev_priv)) 2366 #define DRIVER_CAPS(dev_priv) (&(dev_priv)->caps) 2367 2368 #define INTEL_GEN(dev_priv) ((dev_priv)->info.gen) 2369 #define INTEL_DEVID(dev_priv) ((dev_priv)->info.device_id) 2370 2371 #define REVID_FOREVER 0xff 2372 #define INTEL_REVID(dev_priv) ((dev_priv)->drm.pdev->revision) 2373 2374 #define GEN_FOREVER (0) 2375 2376 #define INTEL_GEN_MASK(s, e) ( \ 2377 BUILD_BUG_ON_ZERO(!__builtin_constant_p(s)) + \ 2378 BUILD_BUG_ON_ZERO(!__builtin_constant_p(e)) + \ 2379 GENMASK((e) != GEN_FOREVER ? (e) - 1 : BITS_PER_LONG - 1, \ 2380 (s) != GEN_FOREVER ? (s) - 1 : 0) \ 2381 ) 2382 2383 /* 2384 * Returns true if Gen is in inclusive range [Start, End]. 2385 * 2386 * Use GEN_FOREVER for unbound start and or end. 2387 */ 2388 #define IS_GEN(dev_priv, s, e) \ 2389 (!!((dev_priv)->info.gen_mask & INTEL_GEN_MASK((s), (e)))) 2390 2391 /* 2392 * Return true if revision is in range [since,until] inclusive. 2393 * 2394 * Use 0 for open-ended since, and REVID_FOREVER for open-ended until. 2395 */ 2396 #define IS_REVID(p, since, until) \ 2397 (INTEL_REVID(p) >= (since) && INTEL_REVID(p) <= (until)) 2398 2399 #define IS_PLATFORM(dev_priv, p) ((dev_priv)->info.platform_mask & BIT(p)) 2400 2401 #define IS_I830(dev_priv) IS_PLATFORM(dev_priv, INTEL_I830) 2402 #define IS_I845G(dev_priv) IS_PLATFORM(dev_priv, INTEL_I845G) 2403 #define IS_I85X(dev_priv) IS_PLATFORM(dev_priv, INTEL_I85X) 2404 #define IS_I865G(dev_priv) IS_PLATFORM(dev_priv, INTEL_I865G) 2405 #define IS_I915G(dev_priv) IS_PLATFORM(dev_priv, INTEL_I915G) 2406 #define IS_I915GM(dev_priv) IS_PLATFORM(dev_priv, INTEL_I915GM) 2407 #define IS_I945G(dev_priv) IS_PLATFORM(dev_priv, INTEL_I945G) 2408 #define IS_I945GM(dev_priv) IS_PLATFORM(dev_priv, INTEL_I945GM) 2409 #define IS_I965G(dev_priv) IS_PLATFORM(dev_priv, INTEL_I965G) 2410 #define IS_I965GM(dev_priv) IS_PLATFORM(dev_priv, INTEL_I965GM) 2411 #define IS_G45(dev_priv) IS_PLATFORM(dev_priv, INTEL_G45) 2412 #define IS_GM45(dev_priv) IS_PLATFORM(dev_priv, INTEL_GM45) 2413 #define IS_G4X(dev_priv) (IS_G45(dev_priv) || IS_GM45(dev_priv)) 2414 #define IS_PINEVIEW_G(dev_priv) (INTEL_DEVID(dev_priv) == 0xa001) 2415 #define IS_PINEVIEW_M(dev_priv) (INTEL_DEVID(dev_priv) == 0xa011) 2416 #define IS_PINEVIEW(dev_priv) IS_PLATFORM(dev_priv, INTEL_PINEVIEW) 2417 #define IS_G33(dev_priv) IS_PLATFORM(dev_priv, INTEL_G33) 2418 #define IS_IRONLAKE_M(dev_priv) (INTEL_DEVID(dev_priv) == 0x0046) 2419 #define IS_IVYBRIDGE(dev_priv) IS_PLATFORM(dev_priv, INTEL_IVYBRIDGE) 2420 #define IS_IVB_GT1(dev_priv) (IS_IVYBRIDGE(dev_priv) && \ 2421 (dev_priv)->info.gt == 1) 2422 #define IS_VALLEYVIEW(dev_priv) IS_PLATFORM(dev_priv, INTEL_VALLEYVIEW) 2423 #define IS_CHERRYVIEW(dev_priv) IS_PLATFORM(dev_priv, INTEL_CHERRYVIEW) 2424 #define IS_HASWELL(dev_priv) IS_PLATFORM(dev_priv, INTEL_HASWELL) 2425 #define IS_BROADWELL(dev_priv) IS_PLATFORM(dev_priv, INTEL_BROADWELL) 2426 #define IS_SKYLAKE(dev_priv) IS_PLATFORM(dev_priv, INTEL_SKYLAKE) 2427 #define IS_BROXTON(dev_priv) IS_PLATFORM(dev_priv, INTEL_BROXTON) 2428 #define IS_KABYLAKE(dev_priv) IS_PLATFORM(dev_priv, INTEL_KABYLAKE) 2429 #define IS_GEMINILAKE(dev_priv) IS_PLATFORM(dev_priv, INTEL_GEMINILAKE) 2430 #define IS_COFFEELAKE(dev_priv) IS_PLATFORM(dev_priv, INTEL_COFFEELAKE) 2431 #define IS_CANNONLAKE(dev_priv) IS_PLATFORM(dev_priv, INTEL_CANNONLAKE) 2432 #define IS_ICELAKE(dev_priv) IS_PLATFORM(dev_priv, INTEL_ICELAKE) 2433 #define IS_MOBILE(dev_priv) ((dev_priv)->info.is_mobile) 2434 #define IS_HSW_EARLY_SDV(dev_priv) (IS_HASWELL(dev_priv) && \ 2435 (INTEL_DEVID(dev_priv) & 0xFF00) == 0x0C00) 2436 #define IS_BDW_ULT(dev_priv) (IS_BROADWELL(dev_priv) && \ 2437 ((INTEL_DEVID(dev_priv) & 0xf) == 0x6 || \ 2438 (INTEL_DEVID(dev_priv) & 0xf) == 0xb || \ 2439 (INTEL_DEVID(dev_priv) & 0xf) == 0xe)) 2440 /* ULX machines are also considered ULT. */ 2441 #define IS_BDW_ULX(dev_priv) (IS_BROADWELL(dev_priv) && \ 2442 (INTEL_DEVID(dev_priv) & 0xf) == 0xe) 2443 #define IS_BDW_GT3(dev_priv) (IS_BROADWELL(dev_priv) && \ 2444 (dev_priv)->info.gt == 3) 2445 #define IS_HSW_ULT(dev_priv) (IS_HASWELL(dev_priv) && \ 2446 (INTEL_DEVID(dev_priv) & 0xFF00) == 0x0A00) 2447 #define IS_HSW_GT3(dev_priv) (IS_HASWELL(dev_priv) && \ 2448 (dev_priv)->info.gt == 3) 2449 /* ULX machines are also considered ULT. */ 2450 #define IS_HSW_ULX(dev_priv) (INTEL_DEVID(dev_priv) == 0x0A0E || \ 2451 INTEL_DEVID(dev_priv) == 0x0A1E) 2452 #define IS_SKL_ULT(dev_priv) (INTEL_DEVID(dev_priv) == 0x1906 || \ 2453 INTEL_DEVID(dev_priv) == 0x1913 || \ 2454 INTEL_DEVID(dev_priv) == 0x1916 || \ 2455 INTEL_DEVID(dev_priv) == 0x1921 || \ 2456 INTEL_DEVID(dev_priv) == 0x1926) 2457 #define IS_SKL_ULX(dev_priv) (INTEL_DEVID(dev_priv) == 0x190E || \ 2458 INTEL_DEVID(dev_priv) == 0x1915 || \ 2459 INTEL_DEVID(dev_priv) == 0x191E) 2460 #define IS_KBL_ULT(dev_priv) (INTEL_DEVID(dev_priv) == 0x5906 || \ 2461 INTEL_DEVID(dev_priv) == 0x5913 || \ 2462 INTEL_DEVID(dev_priv) == 0x5916 || \ 2463 INTEL_DEVID(dev_priv) == 0x5921 || \ 2464 INTEL_DEVID(dev_priv) == 0x5926) 2465 #define IS_KBL_ULX(dev_priv) (INTEL_DEVID(dev_priv) == 0x590E || \ 2466 INTEL_DEVID(dev_priv) == 0x5915 || \ 2467 INTEL_DEVID(dev_priv) == 0x591E) 2468 #define IS_SKL_GT2(dev_priv) (IS_SKYLAKE(dev_priv) && \ 2469 (dev_priv)->info.gt == 2) 2470 #define IS_SKL_GT3(dev_priv) (IS_SKYLAKE(dev_priv) && \ 2471 (dev_priv)->info.gt == 3) 2472 #define IS_SKL_GT4(dev_priv) (IS_SKYLAKE(dev_priv) && \ 2473 (dev_priv)->info.gt == 4) 2474 #define IS_KBL_GT2(dev_priv) (IS_KABYLAKE(dev_priv) && \ 2475 (dev_priv)->info.gt == 2) 2476 #define IS_KBL_GT3(dev_priv) (IS_KABYLAKE(dev_priv) && \ 2477 (dev_priv)->info.gt == 3) 2478 #define IS_CFL_ULT(dev_priv) (IS_COFFEELAKE(dev_priv) && \ 2479 (INTEL_DEVID(dev_priv) & 0x00F0) == 0x00A0) 2480 #define IS_CFL_GT2(dev_priv) (IS_COFFEELAKE(dev_priv) && \ 2481 (dev_priv)->info.gt == 2) 2482 #define IS_CFL_GT3(dev_priv) (IS_COFFEELAKE(dev_priv) && \ 2483 (dev_priv)->info.gt == 3) 2484 #define IS_CNL_WITH_PORT_F(dev_priv) (IS_CANNONLAKE(dev_priv) && \ 2485 (INTEL_DEVID(dev_priv) & 0x0004) == 0x0004) 2486 2487 #define IS_ALPHA_SUPPORT(intel_info) ((intel_info)->is_alpha_support) 2488 2489 #define SKL_REVID_A0 0x0 2490 #define SKL_REVID_B0 0x1 2491 #define SKL_REVID_C0 0x2 2492 #define SKL_REVID_D0 0x3 2493 #define SKL_REVID_E0 0x4 2494 #define SKL_REVID_F0 0x5 2495 #define SKL_REVID_G0 0x6 2496 #define SKL_REVID_H0 0x7 2497 2498 #define IS_SKL_REVID(p, since, until) (IS_SKYLAKE(p) && IS_REVID(p, since, until)) 2499 2500 #define BXT_REVID_A0 0x0 2501 #define BXT_REVID_A1 0x1 2502 #define BXT_REVID_B0 0x3 2503 #define BXT_REVID_B_LAST 0x8 2504 #define BXT_REVID_C0 0x9 2505 2506 #define IS_BXT_REVID(dev_priv, since, until) \ 2507 (IS_BROXTON(dev_priv) && IS_REVID(dev_priv, since, until)) 2508 2509 #define KBL_REVID_A0 0x0 2510 #define KBL_REVID_B0 0x1 2511 #define KBL_REVID_C0 0x2 2512 #define KBL_REVID_D0 0x3 2513 #define KBL_REVID_E0 0x4 2514 2515 #define IS_KBL_REVID(dev_priv, since, until) \ 2516 (IS_KABYLAKE(dev_priv) && IS_REVID(dev_priv, since, until)) 2517 2518 #define GLK_REVID_A0 0x0 2519 #define GLK_REVID_A1 0x1 2520 2521 #define IS_GLK_REVID(dev_priv, since, until) \ 2522 (IS_GEMINILAKE(dev_priv) && IS_REVID(dev_priv, since, until)) 2523 2524 #define CNL_REVID_A0 0x0 2525 #define CNL_REVID_B0 0x1 2526 #define CNL_REVID_C0 0x2 2527 2528 #define IS_CNL_REVID(p, since, until) \ 2529 (IS_CANNONLAKE(p) && IS_REVID(p, since, until)) 2530 2531 #define ICL_REVID_A0 0x0 2532 #define ICL_REVID_A2 0x1 2533 #define ICL_REVID_B0 0x3 2534 #define ICL_REVID_B2 0x4 2535 #define ICL_REVID_C0 0x5 2536 2537 #define IS_ICL_REVID(p, since, until) \ 2538 (IS_ICELAKE(p) && IS_REVID(p, since, until)) 2539 2540 /* 2541 * The genX designation typically refers to the render engine, so render 2542 * capability related checks should use IS_GEN, while display and other checks 2543 * have their own (e.g. HAS_PCH_SPLIT for ILK+ display, IS_foo for particular 2544 * chips, etc.). 2545 */ 2546 #define IS_GEN2(dev_priv) (!!((dev_priv)->info.gen_mask & BIT(1))) 2547 #define IS_GEN3(dev_priv) (!!((dev_priv)->info.gen_mask & BIT(2))) 2548 #define IS_GEN4(dev_priv) (!!((dev_priv)->info.gen_mask & BIT(3))) 2549 #define IS_GEN5(dev_priv) (!!((dev_priv)->info.gen_mask & BIT(4))) 2550 #define IS_GEN6(dev_priv) (!!((dev_priv)->info.gen_mask & BIT(5))) 2551 #define IS_GEN7(dev_priv) (!!((dev_priv)->info.gen_mask & BIT(6))) 2552 #define IS_GEN8(dev_priv) (!!((dev_priv)->info.gen_mask & BIT(7))) 2553 #define IS_GEN9(dev_priv) (!!((dev_priv)->info.gen_mask & BIT(8))) 2554 #define IS_GEN10(dev_priv) (!!((dev_priv)->info.gen_mask & BIT(9))) 2555 #define IS_GEN11(dev_priv) (!!((dev_priv)->info.gen_mask & BIT(10))) 2556 2557 #define IS_LP(dev_priv) (INTEL_INFO(dev_priv)->is_lp) 2558 #define IS_GEN9_LP(dev_priv) (IS_GEN9(dev_priv) && IS_LP(dev_priv)) 2559 #define IS_GEN9_BC(dev_priv) (IS_GEN9(dev_priv) && !IS_LP(dev_priv)) 2560 2561 #define ENGINE_MASK(id) BIT(id) 2562 #define RENDER_RING ENGINE_MASK(RCS) 2563 #define BSD_RING ENGINE_MASK(VCS) 2564 #define BLT_RING ENGINE_MASK(BCS) 2565 #define VEBOX_RING ENGINE_MASK(VECS) 2566 #define BSD2_RING ENGINE_MASK(VCS2) 2567 #define BSD3_RING ENGINE_MASK(VCS3) 2568 #define BSD4_RING ENGINE_MASK(VCS4) 2569 #define VEBOX2_RING ENGINE_MASK(VECS2) 2570 #define ALL_ENGINES (~0) 2571 2572 #define HAS_ENGINE(dev_priv, id) \ 2573 (!!((dev_priv)->info.ring_mask & ENGINE_MASK(id))) 2574 2575 #define HAS_BSD(dev_priv) HAS_ENGINE(dev_priv, VCS) 2576 #define HAS_BSD2(dev_priv) HAS_ENGINE(dev_priv, VCS2) 2577 #define HAS_BLT(dev_priv) HAS_ENGINE(dev_priv, BCS) 2578 #define HAS_VEBOX(dev_priv) HAS_ENGINE(dev_priv, VECS) 2579 2580 #define HAS_LEGACY_SEMAPHORES(dev_priv) IS_GEN7(dev_priv) 2581 2582 #define HAS_LLC(dev_priv) ((dev_priv)->info.has_llc) 2583 #define HAS_SNOOP(dev_priv) ((dev_priv)->info.has_snoop) 2584 #define HAS_EDRAM(dev_priv) (!!((dev_priv)->edram_cap & EDRAM_ENABLED)) 2585 #define HAS_WT(dev_priv) ((IS_HASWELL(dev_priv) || \ 2586 IS_BROADWELL(dev_priv)) && HAS_EDRAM(dev_priv)) 2587 2588 #define HWS_NEEDS_PHYSICAL(dev_priv) ((dev_priv)->info.hws_needs_physical) 2589 2590 #define HAS_LOGICAL_RING_CONTEXTS(dev_priv) \ 2591 ((dev_priv)->info.has_logical_ring_contexts) 2592 #define HAS_LOGICAL_RING_ELSQ(dev_priv) \ 2593 ((dev_priv)->info.has_logical_ring_elsq) 2594 #define HAS_LOGICAL_RING_PREEMPTION(dev_priv) \ 2595 ((dev_priv)->info.has_logical_ring_preemption) 2596 2597 #define HAS_EXECLISTS(dev_priv) HAS_LOGICAL_RING_CONTEXTS(dev_priv) 2598 2599 #define USES_PPGTT(dev_priv) (i915_modparams.enable_ppgtt) 2600 #define USES_FULL_PPGTT(dev_priv) (i915_modparams.enable_ppgtt >= 2) 2601 #define USES_FULL_48BIT_PPGTT(dev_priv) (i915_modparams.enable_ppgtt == 3) 2602 #define HAS_PAGE_SIZES(dev_priv, sizes) ({ \ 2603 GEM_BUG_ON((sizes) == 0); \ 2604 ((sizes) & ~(dev_priv)->info.page_sizes) == 0; \ 2605 }) 2606 2607 #define HAS_OVERLAY(dev_priv) ((dev_priv)->info.has_overlay) 2608 #define OVERLAY_NEEDS_PHYSICAL(dev_priv) \ 2609 ((dev_priv)->info.overlay_needs_physical) 2610 2611 /* Early gen2 have a totally busted CS tlb and require pinned batches. */ 2612 #define HAS_BROKEN_CS_TLB(dev_priv) (IS_I830(dev_priv) || IS_I845G(dev_priv)) 2613 2614 /* WaRsDisableCoarsePowerGating:skl,cnl */ 2615 #define NEEDS_WaRsDisableCoarsePowerGating(dev_priv) \ 2616 (IS_CANNONLAKE(dev_priv) || \ 2617 IS_SKL_GT3(dev_priv) || IS_SKL_GT4(dev_priv)) 2618 2619 #define HAS_GMBUS_IRQ(dev_priv) (INTEL_GEN(dev_priv) >= 4) 2620 #define HAS_GMBUS_BURST_READ(dev_priv) (INTEL_GEN(dev_priv) >= 10 || \ 2621 IS_GEMINILAKE(dev_priv) || \ 2622 IS_KABYLAKE(dev_priv)) 2623 2624 /* With the 945 and later, Y tiling got adjusted so that it was 32 128-byte 2625 * rows, which changed the alignment requirements and fence programming. 2626 */ 2627 #define HAS_128_BYTE_Y_TILING(dev_priv) (!IS_GEN2(dev_priv) && \ 2628 !(IS_I915G(dev_priv) || \ 2629 IS_I915GM(dev_priv))) 2630 #define SUPPORTS_TV(dev_priv) ((dev_priv)->info.supports_tv) 2631 #define I915_HAS_HOTPLUG(dev_priv) ((dev_priv)->info.has_hotplug) 2632 2633 #define HAS_FW_BLC(dev_priv) (INTEL_GEN(dev_priv) > 2) 2634 #define HAS_FBC(dev_priv) ((dev_priv)->info.has_fbc) 2635 #define HAS_CUR_FBC(dev_priv) (!HAS_GMCH_DISPLAY(dev_priv) && INTEL_GEN(dev_priv) >= 7) 2636 2637 #define HAS_IPS(dev_priv) (IS_HSW_ULT(dev_priv) || IS_BROADWELL(dev_priv)) 2638 2639 #define HAS_DP_MST(dev_priv) ((dev_priv)->info.has_dp_mst) 2640 2641 #define HAS_DDI(dev_priv) ((dev_priv)->info.has_ddi) 2642 #define HAS_FPGA_DBG_UNCLAIMED(dev_priv) ((dev_priv)->info.has_fpga_dbg) 2643 #define HAS_PSR(dev_priv) ((dev_priv)->info.has_psr) 2644 2645 #define HAS_RC6(dev_priv) ((dev_priv)->info.has_rc6) 2646 #define HAS_RC6p(dev_priv) ((dev_priv)->info.has_rc6p) 2647 #define HAS_RC6pp(dev_priv) (false) /* HW was never validated */ 2648 2649 #define HAS_CSR(dev_priv) ((dev_priv)->info.has_csr) 2650 2651 #define HAS_RUNTIME_PM(dev_priv) ((dev_priv)->info.has_runtime_pm) 2652 #define HAS_64BIT_RELOC(dev_priv) ((dev_priv)->info.has_64bit_reloc) 2653 2654 #define HAS_IPC(dev_priv) ((dev_priv)->info.has_ipc) 2655 2656 /* 2657 * For now, anything with a GuC requires uCode loading, and then supports 2658 * command submission once loaded. But these are logically independent 2659 * properties, so we have separate macros to test them. 2660 */ 2661 #define HAS_GUC(dev_priv) ((dev_priv)->info.has_guc) 2662 #define HAS_GUC_CT(dev_priv) ((dev_priv)->info.has_guc_ct) 2663 #define HAS_GUC_UCODE(dev_priv) (HAS_GUC(dev_priv)) 2664 #define HAS_GUC_SCHED(dev_priv) (HAS_GUC(dev_priv)) 2665 2666 /* For now, anything with a GuC has also HuC */ 2667 #define HAS_HUC(dev_priv) (HAS_GUC(dev_priv)) 2668 #define HAS_HUC_UCODE(dev_priv) (HAS_GUC(dev_priv)) 2669 2670 /* Having a GuC is not the same as using a GuC */ 2671 #define USES_GUC(dev_priv) intel_uc_is_using_guc() 2672 #define USES_GUC_SUBMISSION(dev_priv) intel_uc_is_using_guc_submission() 2673 #define USES_HUC(dev_priv) intel_uc_is_using_huc() 2674 2675 #define HAS_POOLED_EU(dev_priv) ((dev_priv)->info.has_pooled_eu) 2676 2677 #define INTEL_PCH_DEVICE_ID_MASK 0xff80 2678 #define INTEL_PCH_IBX_DEVICE_ID_TYPE 0x3b00 2679 #define INTEL_PCH_CPT_DEVICE_ID_TYPE 0x1c00 2680 #define INTEL_PCH_PPT_DEVICE_ID_TYPE 0x1e00 2681 #define INTEL_PCH_LPT_DEVICE_ID_TYPE 0x8c00 2682 #define INTEL_PCH_LPT_LP_DEVICE_ID_TYPE 0x9c00 2683 #define INTEL_PCH_WPT_DEVICE_ID_TYPE 0x8c80 2684 #define INTEL_PCH_WPT_LP_DEVICE_ID_TYPE 0x9c80 2685 #define INTEL_PCH_SPT_DEVICE_ID_TYPE 0xA100 2686 #define INTEL_PCH_SPT_LP_DEVICE_ID_TYPE 0x9D00 2687 #define INTEL_PCH_KBP_DEVICE_ID_TYPE 0xA280 2688 #define INTEL_PCH_CNP_DEVICE_ID_TYPE 0xA300 2689 #define INTEL_PCH_CNP_LP_DEVICE_ID_TYPE 0x9D80 2690 #define INTEL_PCH_ICP_DEVICE_ID_TYPE 0x3480 2691 #define INTEL_PCH_P2X_DEVICE_ID_TYPE 0x7100 2692 #define INTEL_PCH_P3X_DEVICE_ID_TYPE 0x7000 2693 #define INTEL_PCH_QEMU_DEVICE_ID_TYPE 0x2900 /* qemu q35 has 2918 */ 2694 2695 #define INTEL_PCH_TYPE(dev_priv) ((dev_priv)->pch_type) 2696 #define INTEL_PCH_ID(dev_priv) ((dev_priv)->pch_id) 2697 #define HAS_PCH_ICP(dev_priv) (INTEL_PCH_TYPE(dev_priv) == PCH_ICP) 2698 #define HAS_PCH_CNP(dev_priv) (INTEL_PCH_TYPE(dev_priv) == PCH_CNP) 2699 #define HAS_PCH_CNP_LP(dev_priv) \ 2700 (INTEL_PCH_ID(dev_priv) == INTEL_PCH_CNP_LP_DEVICE_ID_TYPE) 2701 #define HAS_PCH_KBP(dev_priv) (INTEL_PCH_TYPE(dev_priv) == PCH_KBP) 2702 #define HAS_PCH_SPT(dev_priv) (INTEL_PCH_TYPE(dev_priv) == PCH_SPT) 2703 #define HAS_PCH_LPT(dev_priv) (INTEL_PCH_TYPE(dev_priv) == PCH_LPT) 2704 #define HAS_PCH_LPT_LP(dev_priv) \ 2705 (INTEL_PCH_ID(dev_priv) == INTEL_PCH_LPT_LP_DEVICE_ID_TYPE || \ 2706 INTEL_PCH_ID(dev_priv) == INTEL_PCH_WPT_LP_DEVICE_ID_TYPE) 2707 #define HAS_PCH_LPT_H(dev_priv) \ 2708 (INTEL_PCH_ID(dev_priv) == INTEL_PCH_LPT_DEVICE_ID_TYPE || \ 2709 INTEL_PCH_ID(dev_priv) == INTEL_PCH_WPT_DEVICE_ID_TYPE) 2710 #define HAS_PCH_CPT(dev_priv) (INTEL_PCH_TYPE(dev_priv) == PCH_CPT) 2711 #define HAS_PCH_IBX(dev_priv) (INTEL_PCH_TYPE(dev_priv) == PCH_IBX) 2712 #define HAS_PCH_NOP(dev_priv) (INTEL_PCH_TYPE(dev_priv) == PCH_NOP) 2713 #define HAS_PCH_SPLIT(dev_priv) (INTEL_PCH_TYPE(dev_priv) != PCH_NONE) 2714 2715 #define HAS_GMCH_DISPLAY(dev_priv) ((dev_priv)->info.has_gmch_display) 2716 2717 #define HAS_LSPCON(dev_priv) (INTEL_GEN(dev_priv) >= 9) 2718 2719 /* DPF == dynamic parity feature */ 2720 #define HAS_L3_DPF(dev_priv) ((dev_priv)->info.has_l3_dpf) 2721 #define NUM_L3_SLICES(dev_priv) (IS_HSW_GT3(dev_priv) ? \ 2722 2 : HAS_L3_DPF(dev_priv)) 2723 2724 #define GT_FREQUENCY_MULTIPLIER 50 2725 #define GEN9_FREQ_SCALER 3 2726 2727 #include "i915_trace.h" 2728 2729 static inline bool intel_vtd_active(void) 2730 { 2731 #ifdef CONFIG_INTEL_IOMMU 2732 if (intel_iommu_gfx_mapped) 2733 return true; 2734 #endif 2735 return false; 2736 } 2737 2738 static inline bool intel_scanout_needs_vtd_wa(struct drm_i915_private *dev_priv) 2739 { 2740 return INTEL_GEN(dev_priv) >= 6 && intel_vtd_active(); 2741 } 2742 2743 static inline bool 2744 intel_ggtt_update_needs_vtd_wa(struct drm_i915_private *dev_priv) 2745 { 2746 return IS_BROXTON(dev_priv) && intel_vtd_active(); 2747 } 2748 2749 int intel_sanitize_enable_ppgtt(struct drm_i915_private *dev_priv, 2750 int enable_ppgtt); 2751 2752 /* i915_drv.c */ 2753 void __printf(3, 4) 2754 __i915_printk(struct drm_i915_private *dev_priv, const char *level, 2755 const char *fmt, ...); 2756 2757 #define i915_report_error(dev_priv, fmt, ...) \ 2758 __i915_printk(dev_priv, KERN_ERR, fmt, ##__VA_ARGS__) 2759 2760 #ifdef CONFIG_COMPAT 2761 extern long i915_compat_ioctl(struct file *filp, unsigned int cmd, 2762 unsigned long arg); 2763 #else 2764 #define i915_compat_ioctl NULL 2765 #endif 2766 extern const struct dev_pm_ops i915_pm_ops; 2767 2768 extern int i915_driver_load(struct pci_dev *pdev, 2769 const struct pci_device_id *ent); 2770 extern void i915_driver_unload(struct drm_device *dev); 2771 extern int intel_gpu_reset(struct drm_i915_private *dev_priv, u32 engine_mask); 2772 extern bool intel_has_gpu_reset(struct drm_i915_private *dev_priv); 2773 2774 extern void i915_reset(struct drm_i915_private *i915, 2775 unsigned int stalled_mask, 2776 const char *reason); 2777 extern int i915_reset_engine(struct intel_engine_cs *engine, 2778 const char *reason); 2779 2780 extern bool intel_has_reset_engine(struct drm_i915_private *dev_priv); 2781 extern int intel_reset_guc(struct drm_i915_private *dev_priv); 2782 extern int intel_guc_reset_engine(struct intel_guc *guc, 2783 struct intel_engine_cs *engine); 2784 extern void intel_engine_init_hangcheck(struct intel_engine_cs *engine); 2785 extern void intel_hangcheck_init(struct drm_i915_private *dev_priv); 2786 extern unsigned long i915_chipset_val(struct drm_i915_private *dev_priv); 2787 extern unsigned long i915_mch_val(struct drm_i915_private *dev_priv); 2788 extern unsigned long i915_gfx_val(struct drm_i915_private *dev_priv); 2789 extern void i915_update_gfx_val(struct drm_i915_private *dev_priv); 2790 int vlv_force_gfx_clock(struct drm_i915_private *dev_priv, bool on); 2791 2792 int intel_engines_init_mmio(struct drm_i915_private *dev_priv); 2793 int intel_engines_init(struct drm_i915_private *dev_priv); 2794 2795 u32 intel_calculate_mcr_s_ss_select(struct drm_i915_private *dev_priv); 2796 2797 /* intel_hotplug.c */ 2798 void intel_hpd_irq_handler(struct drm_i915_private *dev_priv, 2799 u32 pin_mask, u32 long_mask); 2800 void intel_hpd_init(struct drm_i915_private *dev_priv); 2801 void intel_hpd_init_work(struct drm_i915_private *dev_priv); 2802 void intel_hpd_cancel_work(struct drm_i915_private *dev_priv); 2803 enum hpd_pin intel_hpd_pin_default(struct drm_i915_private *dev_priv, 2804 enum port port); 2805 bool intel_hpd_disable(struct drm_i915_private *dev_priv, enum hpd_pin pin); 2806 void intel_hpd_enable(struct drm_i915_private *dev_priv, enum hpd_pin pin); 2807 2808 /* i915_irq.c */ 2809 static inline void i915_queue_hangcheck(struct drm_i915_private *dev_priv) 2810 { 2811 unsigned long delay; 2812 2813 if (unlikely(!i915_modparams.enable_hangcheck)) 2814 return; 2815 2816 /* Don't continually defer the hangcheck so that it is always run at 2817 * least once after work has been scheduled on any ring. Otherwise, 2818 * we will ignore a hung ring if a second ring is kept busy. 2819 */ 2820 2821 delay = round_jiffies_up_relative(DRM_I915_HANGCHECK_JIFFIES); 2822 queue_delayed_work(system_long_wq, 2823 &dev_priv->gpu_error.hangcheck_work, delay); 2824 } 2825 2826 __printf(4, 5) 2827 void i915_handle_error(struct drm_i915_private *dev_priv, 2828 u32 engine_mask, 2829 unsigned long flags, 2830 const char *fmt, ...); 2831 #define I915_ERROR_CAPTURE BIT(0) 2832 2833 extern void intel_irq_init(struct drm_i915_private *dev_priv); 2834 extern void intel_irq_fini(struct drm_i915_private *dev_priv); 2835 int intel_irq_install(struct drm_i915_private *dev_priv); 2836 void intel_irq_uninstall(struct drm_i915_private *dev_priv); 2837 2838 void i915_clear_error_registers(struct drm_i915_private *dev_priv); 2839 2840 static inline bool intel_gvt_active(struct drm_i915_private *dev_priv) 2841 { 2842 return dev_priv->gvt; 2843 } 2844 2845 static inline bool intel_vgpu_active(struct drm_i915_private *dev_priv) 2846 { 2847 return dev_priv->vgpu.active; 2848 } 2849 2850 u32 i915_pipestat_enable_mask(struct drm_i915_private *dev_priv, 2851 enum pipe pipe); 2852 void 2853 i915_enable_pipestat(struct drm_i915_private *dev_priv, enum pipe pipe, 2854 u32 status_mask); 2855 2856 void 2857 i915_disable_pipestat(struct drm_i915_private *dev_priv, enum pipe pipe, 2858 u32 status_mask); 2859 2860 void valleyview_enable_display_irqs(struct drm_i915_private *dev_priv); 2861 void valleyview_disable_display_irqs(struct drm_i915_private *dev_priv); 2862 void i915_hotplug_interrupt_update(struct drm_i915_private *dev_priv, 2863 uint32_t mask, 2864 uint32_t bits); 2865 void ilk_update_display_irq(struct drm_i915_private *dev_priv, 2866 uint32_t interrupt_mask, 2867 uint32_t enabled_irq_mask); 2868 static inline void 2869 ilk_enable_display_irq(struct drm_i915_private *dev_priv, uint32_t bits) 2870 { 2871 ilk_update_display_irq(dev_priv, bits, bits); 2872 } 2873 static inline void 2874 ilk_disable_display_irq(struct drm_i915_private *dev_priv, uint32_t bits) 2875 { 2876 ilk_update_display_irq(dev_priv, bits, 0); 2877 } 2878 void bdw_update_pipe_irq(struct drm_i915_private *dev_priv, 2879 enum pipe pipe, 2880 uint32_t interrupt_mask, 2881 uint32_t enabled_irq_mask); 2882 static inline void bdw_enable_pipe_irq(struct drm_i915_private *dev_priv, 2883 enum pipe pipe, uint32_t bits) 2884 { 2885 bdw_update_pipe_irq(dev_priv, pipe, bits, bits); 2886 } 2887 static inline void bdw_disable_pipe_irq(struct drm_i915_private *dev_priv, 2888 enum pipe pipe, uint32_t bits) 2889 { 2890 bdw_update_pipe_irq(dev_priv, pipe, bits, 0); 2891 } 2892 void ibx_display_interrupt_update(struct drm_i915_private *dev_priv, 2893 uint32_t interrupt_mask, 2894 uint32_t enabled_irq_mask); 2895 static inline void 2896 ibx_enable_display_interrupt(struct drm_i915_private *dev_priv, uint32_t bits) 2897 { 2898 ibx_display_interrupt_update(dev_priv, bits, bits); 2899 } 2900 static inline void 2901 ibx_disable_display_interrupt(struct drm_i915_private *dev_priv, uint32_t bits) 2902 { 2903 ibx_display_interrupt_update(dev_priv, bits, 0); 2904 } 2905 2906 /* i915_gem.c */ 2907 int i915_gem_create_ioctl(struct drm_device *dev, void *data, 2908 struct drm_file *file_priv); 2909 int i915_gem_pread_ioctl(struct drm_device *dev, void *data, 2910 struct drm_file *file_priv); 2911 int i915_gem_pwrite_ioctl(struct drm_device *dev, void *data, 2912 struct drm_file *file_priv); 2913 int i915_gem_mmap_ioctl(struct drm_device *dev, void *data, 2914 struct drm_file *file_priv); 2915 int i915_gem_mmap_gtt_ioctl(struct drm_device *dev, void *data, 2916 struct drm_file *file_priv); 2917 int i915_gem_set_domain_ioctl(struct drm_device *dev, void *data, 2918 struct drm_file *file_priv); 2919 int i915_gem_sw_finish_ioctl(struct drm_device *dev, void *data, 2920 struct drm_file *file_priv); 2921 int i915_gem_execbuffer_ioctl(struct drm_device *dev, void *data, 2922 struct drm_file *file_priv); 2923 int i915_gem_execbuffer2_ioctl(struct drm_device *dev, void *data, 2924 struct drm_file *file_priv); 2925 int i915_gem_busy_ioctl(struct drm_device *dev, void *data, 2926 struct drm_file *file_priv); 2927 int i915_gem_get_caching_ioctl(struct drm_device *dev, void *data, 2928 struct drm_file *file); 2929 int i915_gem_set_caching_ioctl(struct drm_device *dev, void *data, 2930 struct drm_file *file); 2931 int i915_gem_throttle_ioctl(struct drm_device *dev, void *data, 2932 struct drm_file *file_priv); 2933 int i915_gem_madvise_ioctl(struct drm_device *dev, void *data, 2934 struct drm_file *file_priv); 2935 int i915_gem_set_tiling_ioctl(struct drm_device *dev, void *data, 2936 struct drm_file *file_priv); 2937 int i915_gem_get_tiling_ioctl(struct drm_device *dev, void *data, 2938 struct drm_file *file_priv); 2939 int i915_gem_init_userptr(struct drm_i915_private *dev_priv); 2940 void i915_gem_cleanup_userptr(struct drm_i915_private *dev_priv); 2941 int i915_gem_userptr_ioctl(struct drm_device *dev, void *data, 2942 struct drm_file *file); 2943 int i915_gem_get_aperture_ioctl(struct drm_device *dev, void *data, 2944 struct drm_file *file_priv); 2945 int i915_gem_wait_ioctl(struct drm_device *dev, void *data, 2946 struct drm_file *file_priv); 2947 void i915_gem_sanitize(struct drm_i915_private *i915); 2948 int i915_gem_init_early(struct drm_i915_private *dev_priv); 2949 void i915_gem_cleanup_early(struct drm_i915_private *dev_priv); 2950 void i915_gem_load_init_fences(struct drm_i915_private *dev_priv); 2951 int i915_gem_freeze(struct drm_i915_private *dev_priv); 2952 int i915_gem_freeze_late(struct drm_i915_private *dev_priv); 2953 2954 void *i915_gem_object_alloc(struct drm_i915_private *dev_priv); 2955 void i915_gem_object_free(struct drm_i915_gem_object *obj); 2956 void i915_gem_object_init(struct drm_i915_gem_object *obj, 2957 const struct drm_i915_gem_object_ops *ops); 2958 struct drm_i915_gem_object * 2959 i915_gem_object_create(struct drm_i915_private *dev_priv, u64 size); 2960 struct drm_i915_gem_object * 2961 i915_gem_object_create_from_data(struct drm_i915_private *dev_priv, 2962 const void *data, size_t size); 2963 void i915_gem_close_object(struct drm_gem_object *gem, struct drm_file *file); 2964 void i915_gem_free_object(struct drm_gem_object *obj); 2965 2966 static inline void i915_gem_drain_freed_objects(struct drm_i915_private *i915) 2967 { 2968 if (!atomic_read(&i915->mm.free_count)) 2969 return; 2970 2971 /* A single pass should suffice to release all the freed objects (along 2972 * most call paths) , but be a little more paranoid in that freeing 2973 * the objects does take a little amount of time, during which the rcu 2974 * callbacks could have added new objects into the freed list, and 2975 * armed the work again. 2976 */ 2977 do { 2978 rcu_barrier(); 2979 } while (flush_work(&i915->mm.free_work)); 2980 } 2981 2982 static inline void i915_gem_drain_workqueue(struct drm_i915_private *i915) 2983 { 2984 /* 2985 * Similar to objects above (see i915_gem_drain_freed-objects), in 2986 * general we have workers that are armed by RCU and then rearm 2987 * themselves in their callbacks. To be paranoid, we need to 2988 * drain the workqueue a second time after waiting for the RCU 2989 * grace period so that we catch work queued via RCU from the first 2990 * pass. As neither drain_workqueue() nor flush_workqueue() report 2991 * a result, we make an assumption that we only don't require more 2992 * than 2 passes to catch all recursive RCU delayed work. 2993 * 2994 */ 2995 int pass = 2; 2996 do { 2997 rcu_barrier(); 2998 drain_workqueue(i915->wq); 2999 } while (--pass); 3000 } 3001 3002 struct i915_vma * __must_check 3003 i915_gem_object_ggtt_pin(struct drm_i915_gem_object *obj, 3004 const struct i915_ggtt_view *view, 3005 u64 size, 3006 u64 alignment, 3007 u64 flags); 3008 3009 int i915_gem_object_unbind(struct drm_i915_gem_object *obj); 3010 void i915_gem_release_mmap(struct drm_i915_gem_object *obj); 3011 3012 void i915_gem_runtime_suspend(struct drm_i915_private *dev_priv); 3013 3014 static inline int __sg_page_count(const struct scatterlist *sg) 3015 { 3016 return sg->length >> PAGE_SHIFT; 3017 } 3018 3019 struct scatterlist * 3020 i915_gem_object_get_sg(struct drm_i915_gem_object *obj, 3021 unsigned int n, unsigned int *offset); 3022 3023 struct page * 3024 i915_gem_object_get_page(struct drm_i915_gem_object *obj, 3025 unsigned int n); 3026 3027 struct page * 3028 i915_gem_object_get_dirty_page(struct drm_i915_gem_object *obj, 3029 unsigned int n); 3030 3031 dma_addr_t 3032 i915_gem_object_get_dma_address(struct drm_i915_gem_object *obj, 3033 unsigned long n); 3034 3035 void __i915_gem_object_set_pages(struct drm_i915_gem_object *obj, 3036 struct sg_table *pages, 3037 unsigned int sg_page_sizes); 3038 int __i915_gem_object_get_pages(struct drm_i915_gem_object *obj); 3039 3040 static inline int __must_check 3041 i915_gem_object_pin_pages(struct drm_i915_gem_object *obj) 3042 { 3043 might_lock(&obj->mm.lock); 3044 3045 if (atomic_inc_not_zero(&obj->mm.pages_pin_count)) 3046 return 0; 3047 3048 return __i915_gem_object_get_pages(obj); 3049 } 3050 3051 static inline bool 3052 i915_gem_object_has_pages(struct drm_i915_gem_object *obj) 3053 { 3054 return !IS_ERR_OR_NULL(READ_ONCE(obj->mm.pages)); 3055 } 3056 3057 static inline void 3058 __i915_gem_object_pin_pages(struct drm_i915_gem_object *obj) 3059 { 3060 GEM_BUG_ON(!i915_gem_object_has_pages(obj)); 3061 3062 atomic_inc(&obj->mm.pages_pin_count); 3063 } 3064 3065 static inline bool 3066 i915_gem_object_has_pinned_pages(struct drm_i915_gem_object *obj) 3067 { 3068 return atomic_read(&obj->mm.pages_pin_count); 3069 } 3070 3071 static inline void 3072 __i915_gem_object_unpin_pages(struct drm_i915_gem_object *obj) 3073 { 3074 GEM_BUG_ON(!i915_gem_object_has_pages(obj)); 3075 GEM_BUG_ON(!i915_gem_object_has_pinned_pages(obj)); 3076 3077 atomic_dec(&obj->mm.pages_pin_count); 3078 } 3079 3080 static inline void 3081 i915_gem_object_unpin_pages(struct drm_i915_gem_object *obj) 3082 { 3083 __i915_gem_object_unpin_pages(obj); 3084 } 3085 3086 enum i915_mm_subclass { /* lockdep subclass for obj->mm.lock */ 3087 I915_MM_NORMAL = 0, 3088 I915_MM_SHRINKER 3089 }; 3090 3091 void __i915_gem_object_put_pages(struct drm_i915_gem_object *obj, 3092 enum i915_mm_subclass subclass); 3093 void __i915_gem_object_invalidate(struct drm_i915_gem_object *obj); 3094 3095 enum i915_map_type { 3096 I915_MAP_WB = 0, 3097 I915_MAP_WC, 3098 #define I915_MAP_OVERRIDE BIT(31) 3099 I915_MAP_FORCE_WB = I915_MAP_WB | I915_MAP_OVERRIDE, 3100 I915_MAP_FORCE_WC = I915_MAP_WC | I915_MAP_OVERRIDE, 3101 }; 3102 3103 static inline enum i915_map_type 3104 i915_coherent_map_type(struct drm_i915_private *i915) 3105 { 3106 return HAS_LLC(i915) ? I915_MAP_WB : I915_MAP_WC; 3107 } 3108 3109 /** 3110 * i915_gem_object_pin_map - return a contiguous mapping of the entire object 3111 * @obj: the object to map into kernel address space 3112 * @type: the type of mapping, used to select pgprot_t 3113 * 3114 * Calls i915_gem_object_pin_pages() to prevent reaping of the object's 3115 * pages and then returns a contiguous mapping of the backing storage into 3116 * the kernel address space. Based on the @type of mapping, the PTE will be 3117 * set to either WriteBack or WriteCombine (via pgprot_t). 3118 * 3119 * The caller is responsible for calling i915_gem_object_unpin_map() when the 3120 * mapping is no longer required. 3121 * 3122 * Returns the pointer through which to access the mapped object, or an 3123 * ERR_PTR() on error. 3124 */ 3125 void *__must_check i915_gem_object_pin_map(struct drm_i915_gem_object *obj, 3126 enum i915_map_type type); 3127 3128 /** 3129 * i915_gem_object_unpin_map - releases an earlier mapping 3130 * @obj: the object to unmap 3131 * 3132 * After pinning the object and mapping its pages, once you are finished 3133 * with your access, call i915_gem_object_unpin_map() to release the pin 3134 * upon the mapping. Once the pin count reaches zero, that mapping may be 3135 * removed. 3136 */ 3137 static inline void i915_gem_object_unpin_map(struct drm_i915_gem_object *obj) 3138 { 3139 i915_gem_object_unpin_pages(obj); 3140 } 3141 3142 int i915_gem_obj_prepare_shmem_read(struct drm_i915_gem_object *obj, 3143 unsigned int *needs_clflush); 3144 int i915_gem_obj_prepare_shmem_write(struct drm_i915_gem_object *obj, 3145 unsigned int *needs_clflush); 3146 #define CLFLUSH_BEFORE BIT(0) 3147 #define CLFLUSH_AFTER BIT(1) 3148 #define CLFLUSH_FLAGS (CLFLUSH_BEFORE | CLFLUSH_AFTER) 3149 3150 static inline void 3151 i915_gem_obj_finish_shmem_access(struct drm_i915_gem_object *obj) 3152 { 3153 i915_gem_object_unpin_pages(obj); 3154 } 3155 3156 int __must_check i915_mutex_lock_interruptible(struct drm_device *dev); 3157 int i915_gem_dumb_create(struct drm_file *file_priv, 3158 struct drm_device *dev, 3159 struct drm_mode_create_dumb *args); 3160 int i915_gem_mmap_gtt(struct drm_file *file_priv, struct drm_device *dev, 3161 uint32_t handle, uint64_t *offset); 3162 int i915_gem_mmap_gtt_version(void); 3163 3164 void i915_gem_track_fb(struct drm_i915_gem_object *old, 3165 struct drm_i915_gem_object *new, 3166 unsigned frontbuffer_bits); 3167 3168 int __must_check i915_gem_set_global_seqno(struct drm_device *dev, u32 seqno); 3169 3170 struct i915_request * 3171 i915_gem_find_active_request(struct intel_engine_cs *engine); 3172 3173 static inline bool i915_reset_backoff(struct i915_gpu_error *error) 3174 { 3175 return unlikely(test_bit(I915_RESET_BACKOFF, &error->flags)); 3176 } 3177 3178 static inline bool i915_reset_handoff(struct i915_gpu_error *error) 3179 { 3180 return unlikely(test_bit(I915_RESET_HANDOFF, &error->flags)); 3181 } 3182 3183 static inline bool i915_terminally_wedged(struct i915_gpu_error *error) 3184 { 3185 return unlikely(test_bit(I915_WEDGED, &error->flags)); 3186 } 3187 3188 static inline bool i915_reset_backoff_or_wedged(struct i915_gpu_error *error) 3189 { 3190 return i915_reset_backoff(error) | i915_terminally_wedged(error); 3191 } 3192 3193 static inline u32 i915_reset_count(struct i915_gpu_error *error) 3194 { 3195 return READ_ONCE(error->reset_count); 3196 } 3197 3198 static inline u32 i915_reset_engine_count(struct i915_gpu_error *error, 3199 struct intel_engine_cs *engine) 3200 { 3201 return READ_ONCE(error->reset_engine_count[engine->id]); 3202 } 3203 3204 struct i915_request * 3205 i915_gem_reset_prepare_engine(struct intel_engine_cs *engine); 3206 int i915_gem_reset_prepare(struct drm_i915_private *dev_priv); 3207 void i915_gem_reset(struct drm_i915_private *dev_priv, 3208 unsigned int stalled_mask); 3209 void i915_gem_reset_finish_engine(struct intel_engine_cs *engine); 3210 void i915_gem_reset_finish(struct drm_i915_private *dev_priv); 3211 void i915_gem_set_wedged(struct drm_i915_private *dev_priv); 3212 bool i915_gem_unset_wedged(struct drm_i915_private *dev_priv); 3213 void i915_gem_reset_engine(struct intel_engine_cs *engine, 3214 struct i915_request *request, 3215 bool stalled); 3216 3217 void i915_gem_init_mmio(struct drm_i915_private *i915); 3218 int __must_check i915_gem_init(struct drm_i915_private *dev_priv); 3219 int __must_check i915_gem_init_hw(struct drm_i915_private *dev_priv); 3220 void i915_gem_init_swizzling(struct drm_i915_private *dev_priv); 3221 void i915_gem_fini(struct drm_i915_private *dev_priv); 3222 void i915_gem_cleanup_engines(struct drm_i915_private *dev_priv); 3223 int i915_gem_wait_for_idle(struct drm_i915_private *dev_priv, 3224 unsigned int flags, long timeout); 3225 int __must_check i915_gem_suspend(struct drm_i915_private *dev_priv); 3226 void i915_gem_suspend_late(struct drm_i915_private *dev_priv); 3227 void i915_gem_resume(struct drm_i915_private *dev_priv); 3228 vm_fault_t i915_gem_fault(struct vm_fault *vmf); 3229 int i915_gem_object_wait(struct drm_i915_gem_object *obj, 3230 unsigned int flags, 3231 long timeout, 3232 struct intel_rps_client *rps); 3233 int i915_gem_object_wait_priority(struct drm_i915_gem_object *obj, 3234 unsigned int flags, 3235 const struct i915_sched_attr *attr); 3236 #define I915_PRIORITY_DISPLAY I915_PRIORITY_MAX 3237 3238 int __must_check 3239 i915_gem_object_set_to_wc_domain(struct drm_i915_gem_object *obj, bool write); 3240 int __must_check 3241 i915_gem_object_set_to_gtt_domain(struct drm_i915_gem_object *obj, bool write); 3242 int __must_check 3243 i915_gem_object_set_to_cpu_domain(struct drm_i915_gem_object *obj, bool write); 3244 struct i915_vma * __must_check 3245 i915_gem_object_pin_to_display_plane(struct drm_i915_gem_object *obj, 3246 u32 alignment, 3247 const struct i915_ggtt_view *view, 3248 unsigned int flags); 3249 void i915_gem_object_unpin_from_display_plane(struct i915_vma *vma); 3250 int i915_gem_object_attach_phys(struct drm_i915_gem_object *obj, 3251 int align); 3252 int i915_gem_open(struct drm_i915_private *i915, struct drm_file *file); 3253 void i915_gem_release(struct drm_device *dev, struct drm_file *file); 3254 3255 int i915_gem_object_set_cache_level(struct drm_i915_gem_object *obj, 3256 enum i915_cache_level cache_level); 3257 3258 struct drm_gem_object *i915_gem_prime_import(struct drm_device *dev, 3259 struct dma_buf *dma_buf); 3260 3261 struct dma_buf *i915_gem_prime_export(struct drm_device *dev, 3262 struct drm_gem_object *gem_obj, int flags); 3263 3264 static inline struct i915_hw_ppgtt * 3265 i915_vm_to_ppgtt(struct i915_address_space *vm) 3266 { 3267 return container_of(vm, struct i915_hw_ppgtt, vm); 3268 } 3269 3270 /* i915_gem_fence_reg.c */ 3271 struct drm_i915_fence_reg * 3272 i915_reserve_fence(struct drm_i915_private *dev_priv); 3273 void i915_unreserve_fence(struct drm_i915_fence_reg *fence); 3274 3275 void i915_gem_revoke_fences(struct drm_i915_private *dev_priv); 3276 void i915_gem_restore_fences(struct drm_i915_private *dev_priv); 3277 3278 void i915_gem_detect_bit_6_swizzle(struct drm_i915_private *dev_priv); 3279 void i915_gem_object_do_bit_17_swizzle(struct drm_i915_gem_object *obj, 3280 struct sg_table *pages); 3281 void i915_gem_object_save_bit_17_swizzle(struct drm_i915_gem_object *obj, 3282 struct sg_table *pages); 3283 3284 static inline struct i915_gem_context * 3285 __i915_gem_context_lookup_rcu(struct drm_i915_file_private *file_priv, u32 id) 3286 { 3287 return idr_find(&file_priv->context_idr, id); 3288 } 3289 3290 static inline struct i915_gem_context * 3291 i915_gem_context_lookup(struct drm_i915_file_private *file_priv, u32 id) 3292 { 3293 struct i915_gem_context *ctx; 3294 3295 rcu_read_lock(); 3296 ctx = __i915_gem_context_lookup_rcu(file_priv, id); 3297 if (ctx && !kref_get_unless_zero(&ctx->ref)) 3298 ctx = NULL; 3299 rcu_read_unlock(); 3300 3301 return ctx; 3302 } 3303 3304 int i915_perf_open_ioctl(struct drm_device *dev, void *data, 3305 struct drm_file *file); 3306 int i915_perf_add_config_ioctl(struct drm_device *dev, void *data, 3307 struct drm_file *file); 3308 int i915_perf_remove_config_ioctl(struct drm_device *dev, void *data, 3309 struct drm_file *file); 3310 void i915_oa_init_reg_state(struct intel_engine_cs *engine, 3311 struct i915_gem_context *ctx, 3312 uint32_t *reg_state); 3313 3314 /* i915_gem_evict.c */ 3315 int __must_check i915_gem_evict_something(struct i915_address_space *vm, 3316 u64 min_size, u64 alignment, 3317 unsigned cache_level, 3318 u64 start, u64 end, 3319 unsigned flags); 3320 int __must_check i915_gem_evict_for_node(struct i915_address_space *vm, 3321 struct drm_mm_node *node, 3322 unsigned int flags); 3323 int i915_gem_evict_vm(struct i915_address_space *vm); 3324 3325 void i915_gem_flush_ggtt_writes(struct drm_i915_private *dev_priv); 3326 3327 /* belongs in i915_gem_gtt.h */ 3328 static inline void i915_gem_chipset_flush(struct drm_i915_private *dev_priv) 3329 { 3330 wmb(); 3331 if (INTEL_GEN(dev_priv) < 6) 3332 intel_gtt_chipset_flush(); 3333 } 3334 3335 /* i915_gem_stolen.c */ 3336 int i915_gem_stolen_insert_node(struct drm_i915_private *dev_priv, 3337 struct drm_mm_node *node, u64 size, 3338 unsigned alignment); 3339 int i915_gem_stolen_insert_node_in_range(struct drm_i915_private *dev_priv, 3340 struct drm_mm_node *node, u64 size, 3341 unsigned alignment, u64 start, 3342 u64 end); 3343 void i915_gem_stolen_remove_node(struct drm_i915_private *dev_priv, 3344 struct drm_mm_node *node); 3345 int i915_gem_init_stolen(struct drm_i915_private *dev_priv); 3346 void i915_gem_cleanup_stolen(struct drm_i915_private *dev_priv); 3347 struct drm_i915_gem_object * 3348 i915_gem_object_create_stolen(struct drm_i915_private *dev_priv, 3349 resource_size_t size); 3350 struct drm_i915_gem_object * 3351 i915_gem_object_create_stolen_for_preallocated(struct drm_i915_private *dev_priv, 3352 resource_size_t stolen_offset, 3353 resource_size_t gtt_offset, 3354 resource_size_t size); 3355 3356 /* i915_gem_internal.c */ 3357 struct drm_i915_gem_object * 3358 i915_gem_object_create_internal(struct drm_i915_private *dev_priv, 3359 phys_addr_t size); 3360 3361 /* i915_gem_shrinker.c */ 3362 unsigned long i915_gem_shrink(struct drm_i915_private *i915, 3363 unsigned long target, 3364 unsigned long *nr_scanned, 3365 unsigned flags); 3366 #define I915_SHRINK_PURGEABLE 0x1 3367 #define I915_SHRINK_UNBOUND 0x2 3368 #define I915_SHRINK_BOUND 0x4 3369 #define I915_SHRINK_ACTIVE 0x8 3370 #define I915_SHRINK_VMAPS 0x10 3371 unsigned long i915_gem_shrink_all(struct drm_i915_private *i915); 3372 void i915_gem_shrinker_register(struct drm_i915_private *i915); 3373 void i915_gem_shrinker_unregister(struct drm_i915_private *i915); 3374 void i915_gem_shrinker_taints_mutex(struct mutex *mutex); 3375 3376 /* i915_gem_tiling.c */ 3377 static inline bool i915_gem_object_needs_bit17_swizzle(struct drm_i915_gem_object *obj) 3378 { 3379 struct drm_i915_private *dev_priv = to_i915(obj->base.dev); 3380 3381 return dev_priv->mm.bit_6_swizzle_x == I915_BIT_6_SWIZZLE_9_10_17 && 3382 i915_gem_object_is_tiled(obj); 3383 } 3384 3385 u32 i915_gem_fence_size(struct drm_i915_private *dev_priv, u32 size, 3386 unsigned int tiling, unsigned int stride); 3387 u32 i915_gem_fence_alignment(struct drm_i915_private *dev_priv, u32 size, 3388 unsigned int tiling, unsigned int stride); 3389 3390 /* i915_debugfs.c */ 3391 #ifdef CONFIG_DEBUG_FS 3392 int i915_debugfs_register(struct drm_i915_private *dev_priv); 3393 int i915_debugfs_connector_add(struct drm_connector *connector); 3394 void intel_display_crc_init(struct drm_i915_private *dev_priv); 3395 #else 3396 static inline int i915_debugfs_register(struct drm_i915_private *dev_priv) {return 0;} 3397 static inline int i915_debugfs_connector_add(struct drm_connector *connector) 3398 { return 0; } 3399 static inline void intel_display_crc_init(struct drm_i915_private *dev_priv) {} 3400 #endif 3401 3402 const char *i915_cache_level_str(struct drm_i915_private *i915, int type); 3403 3404 /* i915_cmd_parser.c */ 3405 int i915_cmd_parser_get_version(struct drm_i915_private *dev_priv); 3406 void intel_engine_init_cmd_parser(struct intel_engine_cs *engine); 3407 void intel_engine_cleanup_cmd_parser(struct intel_engine_cs *engine); 3408 int intel_engine_cmd_parser(struct intel_engine_cs *engine, 3409 struct drm_i915_gem_object *batch_obj, 3410 struct drm_i915_gem_object *shadow_batch_obj, 3411 u32 batch_start_offset, 3412 u32 batch_len, 3413 bool is_master); 3414 3415 /* i915_perf.c */ 3416 extern void i915_perf_init(struct drm_i915_private *dev_priv); 3417 extern void i915_perf_fini(struct drm_i915_private *dev_priv); 3418 extern void i915_perf_register(struct drm_i915_private *dev_priv); 3419 extern void i915_perf_unregister(struct drm_i915_private *dev_priv); 3420 3421 /* i915_suspend.c */ 3422 extern int i915_save_state(struct drm_i915_private *dev_priv); 3423 extern int i915_restore_state(struct drm_i915_private *dev_priv); 3424 3425 /* i915_sysfs.c */ 3426 void i915_setup_sysfs(struct drm_i915_private *dev_priv); 3427 void i915_teardown_sysfs(struct drm_i915_private *dev_priv); 3428 3429 /* intel_lpe_audio.c */ 3430 int intel_lpe_audio_init(struct drm_i915_private *dev_priv); 3431 void intel_lpe_audio_teardown(struct drm_i915_private *dev_priv); 3432 void intel_lpe_audio_irq_handler(struct drm_i915_private *dev_priv); 3433 void intel_lpe_audio_notify(struct drm_i915_private *dev_priv, 3434 enum pipe pipe, enum port port, 3435 const void *eld, int ls_clock, bool dp_output); 3436 3437 /* intel_i2c.c */ 3438 extern int intel_setup_gmbus(struct drm_i915_private *dev_priv); 3439 extern void intel_teardown_gmbus(struct drm_i915_private *dev_priv); 3440 extern bool intel_gmbus_is_valid_pin(struct drm_i915_private *dev_priv, 3441 unsigned int pin); 3442 extern int intel_gmbus_output_aksv(struct i2c_adapter *adapter); 3443 3444 extern struct i2c_adapter * 3445 intel_gmbus_get_adapter(struct drm_i915_private *dev_priv, unsigned int pin); 3446 extern void intel_gmbus_set_speed(struct i2c_adapter *adapter, int speed); 3447 extern void intel_gmbus_force_bit(struct i2c_adapter *adapter, bool force_bit); 3448 static inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter) 3449 { 3450 return container_of(adapter, struct intel_gmbus, adapter)->force_bit; 3451 } 3452 extern void intel_i2c_reset(struct drm_i915_private *dev_priv); 3453 3454 /* intel_bios.c */ 3455 void intel_bios_init(struct drm_i915_private *dev_priv); 3456 void intel_bios_cleanup(struct drm_i915_private *dev_priv); 3457 bool intel_bios_is_valid_vbt(const void *buf, size_t size); 3458 bool intel_bios_is_tv_present(struct drm_i915_private *dev_priv); 3459 bool intel_bios_is_lvds_present(struct drm_i915_private *dev_priv, u8 *i2c_pin); 3460 bool intel_bios_is_port_present(struct drm_i915_private *dev_priv, enum port port); 3461 bool intel_bios_is_port_edp(struct drm_i915_private *dev_priv, enum port port); 3462 bool intel_bios_is_port_dp_dual_mode(struct drm_i915_private *dev_priv, enum port port); 3463 bool intel_bios_is_dsi_present(struct drm_i915_private *dev_priv, enum port *port); 3464 bool intel_bios_is_port_hpd_inverted(struct drm_i915_private *dev_priv, 3465 enum port port); 3466 bool intel_bios_is_lspcon_present(struct drm_i915_private *dev_priv, 3467 enum port port); 3468 3469 /* intel_acpi.c */ 3470 #ifdef CONFIG_ACPI 3471 extern void intel_register_dsm_handler(void); 3472 extern void intel_unregister_dsm_handler(void); 3473 #else 3474 static inline void intel_register_dsm_handler(void) { return; } 3475 static inline void intel_unregister_dsm_handler(void) { return; } 3476 #endif /* CONFIG_ACPI */ 3477 3478 /* intel_device_info.c */ 3479 static inline struct intel_device_info * 3480 mkwrite_device_info(struct drm_i915_private *dev_priv) 3481 { 3482 return (struct intel_device_info *)&dev_priv->info; 3483 } 3484 3485 /* modesetting */ 3486 extern void intel_modeset_init_hw(struct drm_device *dev); 3487 extern int intel_modeset_init(struct drm_device *dev); 3488 extern void intel_modeset_cleanup(struct drm_device *dev); 3489 extern int intel_connector_register(struct drm_connector *); 3490 extern void intel_connector_unregister(struct drm_connector *); 3491 extern int intel_modeset_vga_set_state(struct drm_i915_private *dev_priv, 3492 bool state); 3493 extern void intel_display_resume(struct drm_device *dev); 3494 extern void i915_redisable_vga(struct drm_i915_private *dev_priv); 3495 extern void i915_redisable_vga_power_on(struct drm_i915_private *dev_priv); 3496 extern bool ironlake_set_drps(struct drm_i915_private *dev_priv, u8 val); 3497 extern void intel_init_pch_refclk(struct drm_i915_private *dev_priv); 3498 extern int intel_set_rps(struct drm_i915_private *dev_priv, u8 val); 3499 extern void intel_rps_mark_interactive(struct drm_i915_private *i915, 3500 bool interactive); 3501 extern bool intel_set_memory_cxsr(struct drm_i915_private *dev_priv, 3502 bool enable); 3503 3504 int i915_reg_read_ioctl(struct drm_device *dev, void *data, 3505 struct drm_file *file); 3506 3507 /* overlay */ 3508 extern struct intel_overlay_error_state * 3509 intel_overlay_capture_error_state(struct drm_i915_private *dev_priv); 3510 extern void intel_overlay_print_error_state(struct drm_i915_error_state_buf *e, 3511 struct intel_overlay_error_state *error); 3512 3513 extern struct intel_display_error_state * 3514 intel_display_capture_error_state(struct drm_i915_private *dev_priv); 3515 extern void intel_display_print_error_state(struct drm_i915_error_state_buf *e, 3516 struct intel_display_error_state *error); 3517 3518 int sandybridge_pcode_read(struct drm_i915_private *dev_priv, u32 mbox, u32 *val); 3519 int sandybridge_pcode_write_timeout(struct drm_i915_private *dev_priv, u32 mbox, 3520 u32 val, int fast_timeout_us, 3521 int slow_timeout_ms); 3522 #define sandybridge_pcode_write(dev_priv, mbox, val) \ 3523 sandybridge_pcode_write_timeout(dev_priv, mbox, val, 500, 0) 3524 3525 int skl_pcode_request(struct drm_i915_private *dev_priv, u32 mbox, u32 request, 3526 u32 reply_mask, u32 reply, int timeout_base_ms); 3527 3528 /* intel_sideband.c */ 3529 u32 vlv_punit_read(struct drm_i915_private *dev_priv, u32 addr); 3530 int vlv_punit_write(struct drm_i915_private *dev_priv, u32 addr, u32 val); 3531 u32 vlv_nc_read(struct drm_i915_private *dev_priv, u8 addr); 3532 u32 vlv_iosf_sb_read(struct drm_i915_private *dev_priv, u8 port, u32 reg); 3533 void vlv_iosf_sb_write(struct drm_i915_private *dev_priv, u8 port, u32 reg, u32 val); 3534 u32 vlv_cck_read(struct drm_i915_private *dev_priv, u32 reg); 3535 void vlv_cck_write(struct drm_i915_private *dev_priv, u32 reg, u32 val); 3536 u32 vlv_ccu_read(struct drm_i915_private *dev_priv, u32 reg); 3537 void vlv_ccu_write(struct drm_i915_private *dev_priv, u32 reg, u32 val); 3538 u32 vlv_bunit_read(struct drm_i915_private *dev_priv, u32 reg); 3539 void vlv_bunit_write(struct drm_i915_private *dev_priv, u32 reg, u32 val); 3540 u32 vlv_dpio_read(struct drm_i915_private *dev_priv, enum pipe pipe, int reg); 3541 void vlv_dpio_write(struct drm_i915_private *dev_priv, enum pipe pipe, int reg, u32 val); 3542 u32 intel_sbi_read(struct drm_i915_private *dev_priv, u16 reg, 3543 enum intel_sbi_destination destination); 3544 void intel_sbi_write(struct drm_i915_private *dev_priv, u16 reg, u32 value, 3545 enum intel_sbi_destination destination); 3546 u32 vlv_flisdsi_read(struct drm_i915_private *dev_priv, u32 reg); 3547 void vlv_flisdsi_write(struct drm_i915_private *dev_priv, u32 reg, u32 val); 3548 3549 /* intel_dpio_phy.c */ 3550 void bxt_port_to_phy_channel(struct drm_i915_private *dev_priv, enum port port, 3551 enum dpio_phy *phy, enum dpio_channel *ch); 3552 void bxt_ddi_phy_set_signal_level(struct drm_i915_private *dev_priv, 3553 enum port port, u32 margin, u32 scale, 3554 u32 enable, u32 deemphasis); 3555 void bxt_ddi_phy_init(struct drm_i915_private *dev_priv, enum dpio_phy phy); 3556 void bxt_ddi_phy_uninit(struct drm_i915_private *dev_priv, enum dpio_phy phy); 3557 bool bxt_ddi_phy_is_enabled(struct drm_i915_private *dev_priv, 3558 enum dpio_phy phy); 3559 bool bxt_ddi_phy_verify_state(struct drm_i915_private *dev_priv, 3560 enum dpio_phy phy); 3561 uint8_t bxt_ddi_phy_calc_lane_lat_optim_mask(uint8_t lane_count); 3562 void bxt_ddi_phy_set_lane_optim_mask(struct intel_encoder *encoder, 3563 uint8_t lane_lat_optim_mask); 3564 uint8_t bxt_ddi_phy_get_lane_lat_optim_mask(struct intel_encoder *encoder); 3565 3566 void chv_set_phy_signal_level(struct intel_encoder *encoder, 3567 u32 deemph_reg_value, u32 margin_reg_value, 3568 bool uniq_trans_scale); 3569 void chv_data_lane_soft_reset(struct intel_encoder *encoder, 3570 const struct intel_crtc_state *crtc_state, 3571 bool reset); 3572 void chv_phy_pre_pll_enable(struct intel_encoder *encoder, 3573 const struct intel_crtc_state *crtc_state); 3574 void chv_phy_pre_encoder_enable(struct intel_encoder *encoder, 3575 const struct intel_crtc_state *crtc_state); 3576 void chv_phy_release_cl2_override(struct intel_encoder *encoder); 3577 void chv_phy_post_pll_disable(struct intel_encoder *encoder, 3578 const struct intel_crtc_state *old_crtc_state); 3579 3580 void vlv_set_phy_signal_level(struct intel_encoder *encoder, 3581 u32 demph_reg_value, u32 preemph_reg_value, 3582 u32 uniqtranscale_reg_value, u32 tx3_demph); 3583 void vlv_phy_pre_pll_enable(struct intel_encoder *encoder, 3584 const struct intel_crtc_state *crtc_state); 3585 void vlv_phy_pre_encoder_enable(struct intel_encoder *encoder, 3586 const struct intel_crtc_state *crtc_state); 3587 void vlv_phy_reset_lanes(struct intel_encoder *encoder, 3588 const struct intel_crtc_state *old_crtc_state); 3589 3590 int intel_gpu_freq(struct drm_i915_private *dev_priv, int val); 3591 int intel_freq_opcode(struct drm_i915_private *dev_priv, int val); 3592 u64 intel_rc6_residency_ns(struct drm_i915_private *dev_priv, 3593 const i915_reg_t reg); 3594 3595 u32 intel_get_cagf(struct drm_i915_private *dev_priv, u32 rpstat1); 3596 3597 static inline u64 intel_rc6_residency_us(struct drm_i915_private *dev_priv, 3598 const i915_reg_t reg) 3599 { 3600 return DIV_ROUND_UP_ULL(intel_rc6_residency_ns(dev_priv, reg), 1000); 3601 } 3602 3603 #define I915_READ8(reg) dev_priv->uncore.funcs.mmio_readb(dev_priv, (reg), true) 3604 #define I915_WRITE8(reg, val) dev_priv->uncore.funcs.mmio_writeb(dev_priv, (reg), (val), true) 3605 3606 #define I915_READ16(reg) dev_priv->uncore.funcs.mmio_readw(dev_priv, (reg), true) 3607 #define I915_WRITE16(reg, val) dev_priv->uncore.funcs.mmio_writew(dev_priv, (reg), (val), true) 3608 #define I915_READ16_NOTRACE(reg) dev_priv->uncore.funcs.mmio_readw(dev_priv, (reg), false) 3609 #define I915_WRITE16_NOTRACE(reg, val) dev_priv->uncore.funcs.mmio_writew(dev_priv, (reg), (val), false) 3610 3611 #define I915_READ(reg) dev_priv->uncore.funcs.mmio_readl(dev_priv, (reg), true) 3612 #define I915_WRITE(reg, val) dev_priv->uncore.funcs.mmio_writel(dev_priv, (reg), (val), true) 3613 #define I915_READ_NOTRACE(reg) dev_priv->uncore.funcs.mmio_readl(dev_priv, (reg), false) 3614 #define I915_WRITE_NOTRACE(reg, val) dev_priv->uncore.funcs.mmio_writel(dev_priv, (reg), (val), false) 3615 3616 /* Be very careful with read/write 64-bit values. On 32-bit machines, they 3617 * will be implemented using 2 32-bit writes in an arbitrary order with 3618 * an arbitrary delay between them. This can cause the hardware to 3619 * act upon the intermediate value, possibly leading to corruption and 3620 * machine death. For this reason we do not support I915_WRITE64, or 3621 * dev_priv->uncore.funcs.mmio_writeq. 3622 * 3623 * When reading a 64-bit value as two 32-bit values, the delay may cause 3624 * the two reads to mismatch, e.g. a timestamp overflowing. Also note that 3625 * occasionally a 64-bit register does not actualy support a full readq 3626 * and must be read using two 32-bit reads. 3627 * 3628 * You have been warned. 3629 */ 3630 #define I915_READ64(reg) dev_priv->uncore.funcs.mmio_readq(dev_priv, (reg), true) 3631 3632 #define I915_READ64_2x32(lower_reg, upper_reg) ({ \ 3633 u32 upper, lower, old_upper, loop = 0; \ 3634 upper = I915_READ(upper_reg); \ 3635 do { \ 3636 old_upper = upper; \ 3637 lower = I915_READ(lower_reg); \ 3638 upper = I915_READ(upper_reg); \ 3639 } while (upper != old_upper && loop++ < 2); \ 3640 (u64)upper << 32 | lower; }) 3641 3642 #define POSTING_READ(reg) (void)I915_READ_NOTRACE(reg) 3643 #define POSTING_READ16(reg) (void)I915_READ16_NOTRACE(reg) 3644 3645 #define __raw_read(x, s) \ 3646 static inline uint##x##_t __raw_i915_read##x(const struct drm_i915_private *dev_priv, \ 3647 i915_reg_t reg) \ 3648 { \ 3649 return read##s(dev_priv->regs + i915_mmio_reg_offset(reg)); \ 3650 } 3651 3652 #define __raw_write(x, s) \ 3653 static inline void __raw_i915_write##x(const struct drm_i915_private *dev_priv, \ 3654 i915_reg_t reg, uint##x##_t val) \ 3655 { \ 3656 write##s(val, dev_priv->regs + i915_mmio_reg_offset(reg)); \ 3657 } 3658 __raw_read(8, b) 3659 __raw_read(16, w) 3660 __raw_read(32, l) 3661 __raw_read(64, q) 3662 3663 __raw_write(8, b) 3664 __raw_write(16, w) 3665 __raw_write(32, l) 3666 __raw_write(64, q) 3667 3668 #undef __raw_read 3669 #undef __raw_write 3670 3671 /* These are untraced mmio-accessors that are only valid to be used inside 3672 * critical sections, such as inside IRQ handlers, where forcewake is explicitly 3673 * controlled. 3674 * 3675 * Think twice, and think again, before using these. 3676 * 3677 * As an example, these accessors can possibly be used between: 3678 * 3679 * spin_lock_irq(&dev_priv->uncore.lock); 3680 * intel_uncore_forcewake_get__locked(); 3681 * 3682 * and 3683 * 3684 * intel_uncore_forcewake_put__locked(); 3685 * spin_unlock_irq(&dev_priv->uncore.lock); 3686 * 3687 * 3688 * Note: some registers may not need forcewake held, so 3689 * intel_uncore_forcewake_{get,put} can be omitted, see 3690 * intel_uncore_forcewake_for_reg(). 3691 * 3692 * Certain architectures will die if the same cacheline is concurrently accessed 3693 * by different clients (e.g. on Ivybridge). Access to registers should 3694 * therefore generally be serialised, by either the dev_priv->uncore.lock or 3695 * a more localised lock guarding all access to that bank of registers. 3696 */ 3697 #define I915_READ_FW(reg__) __raw_i915_read32(dev_priv, (reg__)) 3698 #define I915_WRITE_FW(reg__, val__) __raw_i915_write32(dev_priv, (reg__), (val__)) 3699 #define I915_WRITE64_FW(reg__, val__) __raw_i915_write64(dev_priv, (reg__), (val__)) 3700 #define POSTING_READ_FW(reg__) (void)I915_READ_FW(reg__) 3701 3702 /* "Broadcast RGB" property */ 3703 #define INTEL_BROADCAST_RGB_AUTO 0 3704 #define INTEL_BROADCAST_RGB_FULL 1 3705 #define INTEL_BROADCAST_RGB_LIMITED 2 3706 3707 static inline i915_reg_t i915_vgacntrl_reg(struct drm_i915_private *dev_priv) 3708 { 3709 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) 3710 return VLV_VGACNTRL; 3711 else if (INTEL_GEN(dev_priv) >= 5) 3712 return CPU_VGACNTRL; 3713 else 3714 return VGACNTRL; 3715 } 3716 3717 static inline unsigned long msecs_to_jiffies_timeout(const unsigned int m) 3718 { 3719 unsigned long j = msecs_to_jiffies(m); 3720 3721 return min_t(unsigned long, MAX_JIFFY_OFFSET, j + 1); 3722 } 3723 3724 static inline unsigned long nsecs_to_jiffies_timeout(const u64 n) 3725 { 3726 /* nsecs_to_jiffies64() does not guard against overflow */ 3727 if (NSEC_PER_SEC % HZ && 3728 div_u64(n, NSEC_PER_SEC) >= MAX_JIFFY_OFFSET / HZ) 3729 return MAX_JIFFY_OFFSET; 3730 3731 return min_t(u64, MAX_JIFFY_OFFSET, nsecs_to_jiffies64(n) + 1); 3732 } 3733 3734 /* 3735 * If you need to wait X milliseconds between events A and B, but event B 3736 * doesn't happen exactly after event A, you record the timestamp (jiffies) of 3737 * when event A happened, then just before event B you call this function and 3738 * pass the timestamp as the first argument, and X as the second argument. 3739 */ 3740 static inline void 3741 wait_remaining_ms_from_jiffies(unsigned long timestamp_jiffies, int to_wait_ms) 3742 { 3743 unsigned long target_jiffies, tmp_jiffies, remaining_jiffies; 3744 3745 /* 3746 * Don't re-read the value of "jiffies" every time since it may change 3747 * behind our back and break the math. 3748 */ 3749 tmp_jiffies = jiffies; 3750 target_jiffies = timestamp_jiffies + 3751 msecs_to_jiffies_timeout(to_wait_ms); 3752 3753 if (time_after(target_jiffies, tmp_jiffies)) { 3754 remaining_jiffies = target_jiffies - tmp_jiffies; 3755 while (remaining_jiffies) 3756 remaining_jiffies = 3757 schedule_timeout_uninterruptible(remaining_jiffies); 3758 } 3759 } 3760 3761 static inline bool 3762 __i915_request_irq_complete(const struct i915_request *rq) 3763 { 3764 struct intel_engine_cs *engine = rq->engine; 3765 u32 seqno; 3766 3767 /* Note that the engine may have wrapped around the seqno, and 3768 * so our request->global_seqno will be ahead of the hardware, 3769 * even though it completed the request before wrapping. We catch 3770 * this by kicking all the waiters before resetting the seqno 3771 * in hardware, and also signal the fence. 3772 */ 3773 if (test_bit(DMA_FENCE_FLAG_SIGNALED_BIT, &rq->fence.flags)) 3774 return true; 3775 3776 /* The request was dequeued before we were awoken. We check after 3777 * inspecting the hw to confirm that this was the same request 3778 * that generated the HWS update. The memory barriers within 3779 * the request execution are sufficient to ensure that a check 3780 * after reading the value from hw matches this request. 3781 */ 3782 seqno = i915_request_global_seqno(rq); 3783 if (!seqno) 3784 return false; 3785 3786 /* Before we do the heavier coherent read of the seqno, 3787 * check the value (hopefully) in the CPU cacheline. 3788 */ 3789 if (__i915_request_completed(rq, seqno)) 3790 return true; 3791 3792 /* Ensure our read of the seqno is coherent so that we 3793 * do not "miss an interrupt" (i.e. if this is the last 3794 * request and the seqno write from the GPU is not visible 3795 * by the time the interrupt fires, we will see that the 3796 * request is incomplete and go back to sleep awaiting 3797 * another interrupt that will never come.) 3798 * 3799 * Strictly, we only need to do this once after an interrupt, 3800 * but it is easier and safer to do it every time the waiter 3801 * is woken. 3802 */ 3803 if (engine->irq_seqno_barrier && 3804 test_and_clear_bit(ENGINE_IRQ_BREADCRUMB, &engine->irq_posted)) { 3805 struct intel_breadcrumbs *b = &engine->breadcrumbs; 3806 3807 /* The ordering of irq_posted versus applying the barrier 3808 * is crucial. The clearing of the current irq_posted must 3809 * be visible before we perform the barrier operation, 3810 * such that if a subsequent interrupt arrives, irq_posted 3811 * is reasserted and our task rewoken (which causes us to 3812 * do another __i915_request_irq_complete() immediately 3813 * and reapply the barrier). Conversely, if the clear 3814 * occurs after the barrier, then an interrupt that arrived 3815 * whilst we waited on the barrier would not trigger a 3816 * barrier on the next pass, and the read may not see the 3817 * seqno update. 3818 */ 3819 engine->irq_seqno_barrier(engine); 3820 3821 /* If we consume the irq, but we are no longer the bottom-half, 3822 * the real bottom-half may not have serialised their own 3823 * seqno check with the irq-barrier (i.e. may have inspected 3824 * the seqno before we believe it coherent since they see 3825 * irq_posted == false but we are still running). 3826 */ 3827 spin_lock_irq(&b->irq_lock); 3828 if (b->irq_wait && b->irq_wait->tsk != current) 3829 /* Note that if the bottom-half is changed as we 3830 * are sending the wake-up, the new bottom-half will 3831 * be woken by whomever made the change. We only have 3832 * to worry about when we steal the irq-posted for 3833 * ourself. 3834 */ 3835 wake_up_process(b->irq_wait->tsk); 3836 spin_unlock_irq(&b->irq_lock); 3837 3838 if (__i915_request_completed(rq, seqno)) 3839 return true; 3840 } 3841 3842 return false; 3843 } 3844 3845 void i915_memcpy_init_early(struct drm_i915_private *dev_priv); 3846 bool i915_memcpy_from_wc(void *dst, const void *src, unsigned long len); 3847 3848 /* The movntdqa instructions used for memcpy-from-wc require 16-byte alignment, 3849 * as well as SSE4.1 support. i915_memcpy_from_wc() will report if it cannot 3850 * perform the operation. To check beforehand, pass in the parameters to 3851 * to i915_can_memcpy_from_wc() - since we only care about the low 4 bits, 3852 * you only need to pass in the minor offsets, page-aligned pointers are 3853 * always valid. 3854 * 3855 * For just checking for SSE4.1, in the foreknowledge that the future use 3856 * will be correctly aligned, just use i915_has_memcpy_from_wc(). 3857 */ 3858 #define i915_can_memcpy_from_wc(dst, src, len) \ 3859 i915_memcpy_from_wc((void *)((unsigned long)(dst) | (unsigned long)(src) | (len)), NULL, 0) 3860 3861 #define i915_has_memcpy_from_wc() \ 3862 i915_memcpy_from_wc(NULL, NULL, 0) 3863 3864 /* i915_mm.c */ 3865 int remap_io_mapping(struct vm_area_struct *vma, 3866 unsigned long addr, unsigned long pfn, unsigned long size, 3867 struct io_mapping *iomap); 3868 3869 static inline int intel_hws_csb_write_index(struct drm_i915_private *i915) 3870 { 3871 if (INTEL_GEN(i915) >= 10) 3872 return CNL_HWS_CSB_WRITE_INDEX; 3873 else 3874 return I915_HWS_CSB_WRITE_INDEX; 3875 } 3876 3877 static inline u32 i915_scratch_offset(const struct drm_i915_private *i915) 3878 { 3879 return i915_ggtt_offset(i915->gt.scratch); 3880 } 3881 3882 #endif 3883