xref: /openbsd/sys/dev/pci/drm/i915/i915_drv.h (revision 3cab2bb3)
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/dma-resv.h>
47 #include <linux/shmem_fs.h>
48 #include <linux/stackdepot.h>
49 #include <linux/xarray.h>
50 
51 #include <drm/intel-gtt.h>
52 #include <drm/drm_legacy.h> /* for struct drm_dma_handle */
53 #include <drm/drm_gem.h>
54 #include <drm/drm_auth.h>
55 #include <drm/drm_cache.h>
56 #include <drm/drm_util.h>
57 #include <drm/drm_dsc.h>
58 #include <drm/drm_atomic.h>
59 #include <drm/drm_connector.h>
60 #include <drm/i915_mei_hdcp_interface.h>
61 
62 #include "vga.h"
63 
64 struct inteldrm_softc;
65 #define drm_i915_private inteldrm_softc
66 
67 #include "i915_params.h"
68 #include "i915_reg.h"
69 #include "i915_utils.h"
70 
71 #include "display/intel_bios.h"
72 #include "display/intel_display.h"
73 #include "display/intel_display_power.h"
74 #include "display/intel_dpll_mgr.h"
75 #include "display/intel_dsb.h"
76 #include "display/intel_frontbuffer.h"
77 #include "display/intel_global_state.h"
78 #include "display/intel_gmbus.h"
79 #include "display/intel_opregion.h"
80 
81 #include "gem/i915_gem_context_types.h"
82 #include "gem/i915_gem_shrinker.h"
83 #include "gem/i915_gem_stolen.h"
84 
85 #include "gt/intel_lrc.h"
86 #include "gt/intel_engine.h"
87 #include "gt/intel_gt_types.h"
88 #include "gt/intel_workarounds.h"
89 #include "gt/uc/intel_uc.h"
90 
91 #include "intel_device_info.h"
92 #include "intel_pch.h"
93 #include "intel_runtime_pm.h"
94 #include "intel_memory_region.h"
95 #include "intel_uncore.h"
96 #include "intel_wakeref.h"
97 #include "intel_wopcm.h"
98 
99 #include "i915_gem.h"
100 #include "i915_gem_fence_reg.h"
101 #include "i915_gem_gtt.h"
102 #include "i915_gpu_error.h"
103 #include "i915_perf_types.h"
104 #include "i915_request.h"
105 #include "i915_scheduler.h"
106 #include "gt/intel_timeline.h"
107 #include "i915_vma.h"
108 #include "i915_irq.h"
109 
110 #include "intel_region_lmem.h"
111 
112 #include "drm.h"
113 #include "vga.h"
114 
115 #include <dev/ic/mc6845reg.h>
116 #include <dev/ic/pcdisplayvar.h>
117 #include <dev/ic/vgareg.h>
118 #include <dev/ic/vgavar.h>
119 
120 #include <sys/task.h>
121 #include <dev/pci/vga_pcivar.h>
122 #include <dev/wscons/wsconsio.h>
123 #include <dev/wscons/wsdisplayvar.h>
124 #include <dev/rasops/rasops.h>
125 
126 /* General customization:
127  */
128 
129 #define DRIVER_NAME		"i915"
130 #define DRIVER_DESC		"Intel Graphics"
131 #define DRIVER_DATE		"20200313"
132 #define DRIVER_TIMESTAMP	1584144591
133 
134 struct drm_i915_gem_object;
135 
136 /*
137  * The code assumes that the hpd_pins below have consecutive values and
138  * starting with HPD_PORT_A, the HPD pin associated with any port can be
139  * retrieved by adding the corresponding port (or phy) enum value to
140  * HPD_PORT_A in most cases. For example:
141  * HPD_PORT_C = HPD_PORT_A + PHY_C - PHY_A
142  */
143 enum hpd_pin {
144 	HPD_NONE = 0,
145 	HPD_TV = HPD_NONE,     /* TV is known to be unreliable */
146 	HPD_CRT,
147 	HPD_SDVO_B,
148 	HPD_SDVO_C,
149 	HPD_PORT_A,
150 	HPD_PORT_B,
151 	HPD_PORT_C,
152 	HPD_PORT_D,
153 	HPD_PORT_E,
154 	HPD_PORT_F,
155 	HPD_PORT_G,
156 	HPD_PORT_H,
157 	HPD_PORT_I,
158 
159 	HPD_NUM_PINS
160 };
161 
162 #define for_each_hpd_pin(__pin) \
163 	for ((__pin) = (HPD_NONE + 1); (__pin) < HPD_NUM_PINS; (__pin)++)
164 
165 /* Threshold == 5 for long IRQs, 50 for short */
166 #define HPD_STORM_DEFAULT_THRESHOLD 50
167 
168 struct i915_hotplug {
169 	struct delayed_work hotplug_work;
170 
171 	struct {
172 		unsigned long last_jiffies;
173 		int count;
174 		enum {
175 			HPD_ENABLED = 0,
176 			HPD_DISABLED = 1,
177 			HPD_MARK_DISABLED = 2
178 		} state;
179 	} stats[HPD_NUM_PINS];
180 	u32 event_bits;
181 	u32 retry_bits;
182 	struct delayed_work reenable_work;
183 
184 	u32 long_port_mask;
185 	u32 short_port_mask;
186 	struct work_struct dig_port_work;
187 
188 	struct work_struct poll_init_work;
189 	bool poll_enabled;
190 
191 	unsigned int hpd_storm_threshold;
192 	/* Whether or not to count short HPD IRQs in HPD storms */
193 	u8 hpd_short_storm_enabled;
194 
195 	/*
196 	 * if we get a HPD irq from DP and a HPD irq from non-DP
197 	 * the non-DP HPD could block the workqueue on a mode config
198 	 * mutex getting, that userspace may have taken. However
199 	 * userspace is waiting on the DP workqueue to run which is
200 	 * blocked behind the non-DP one.
201 	 */
202 	struct workqueue_struct *dp_wq;
203 };
204 
205 #define I915_GEM_GPU_DOMAINS \
206 	(I915_GEM_DOMAIN_RENDER | \
207 	 I915_GEM_DOMAIN_SAMPLER | \
208 	 I915_GEM_DOMAIN_COMMAND | \
209 	 I915_GEM_DOMAIN_INSTRUCTION | \
210 	 I915_GEM_DOMAIN_VERTEX)
211 
212 struct drm_i915_private;
213 struct i915_mm_struct;
214 struct i915_mmu_object;
215 
216 struct drm_i915_file_private {
217 	struct drm_i915_private *dev_priv;
218 
219 	union {
220 		struct drm_file *file;
221 		struct rcu_head rcu;
222 	};
223 
224 	struct {
225 		spinlock_t lock;
226 		struct list_head request_list;
227 	} mm;
228 
229 	struct xarray context_xa;
230 	struct xarray vm_xa;
231 
232 	unsigned int bsd_engine;
233 
234 /*
235  * Every context ban increments per client ban score. Also
236  * hangs in short succession increments ban score. If ban threshold
237  * is reached, client is considered banned and submitting more work
238  * will fail. This is a stop gap measure to limit the badly behaving
239  * clients access to gpu. Note that unbannable contexts never increment
240  * the client ban score.
241  */
242 #define I915_CLIENT_SCORE_HANG_FAST	1
243 #define   I915_CLIENT_FAST_HANG_JIFFIES (60 * HZ)
244 #define I915_CLIENT_SCORE_CONTEXT_BAN   3
245 #define I915_CLIENT_SCORE_BANNED	9
246 	/** ban_score: Accumulated score of all ctx bans and fast hangs. */
247 	atomic_t ban_score;
248 	unsigned long hang_timestamp;
249 };
250 
251 /* Interface history:
252  *
253  * 1.1: Original.
254  * 1.2: Add Power Management
255  * 1.3: Add vblank support
256  * 1.4: Fix cmdbuffer path, add heap destroy
257  * 1.5: Add vblank pipe configuration
258  * 1.6: - New ioctl for scheduling buffer swaps on vertical blank
259  *      - Support vertical blank on secondary display pipe
260  */
261 #define DRIVER_MAJOR		1
262 #define DRIVER_MINOR		6
263 #define DRIVER_PATCHLEVEL	0
264 
265 struct intel_overlay;
266 struct intel_overlay_error_state;
267 
268 struct sdvo_device_mapping {
269 	u8 initialized;
270 	u8 dvo_port;
271 	u8 slave_addr;
272 	u8 dvo_wiring;
273 	u8 i2c_pin;
274 	u8 ddc_pin;
275 };
276 
277 struct intel_connector;
278 struct intel_encoder;
279 struct intel_atomic_state;
280 struct intel_cdclk_config;
281 struct intel_cdclk_state;
282 struct intel_cdclk_vals;
283 struct intel_initial_plane_config;
284 struct intel_crtc;
285 struct intel_limit;
286 struct dpll;
287 
288 struct drm_i915_display_funcs {
289 	void (*get_cdclk)(struct drm_i915_private *dev_priv,
290 			  struct intel_cdclk_config *cdclk_config);
291 	void (*set_cdclk)(struct drm_i915_private *dev_priv,
292 			  const struct intel_cdclk_config *cdclk_config,
293 			  enum pipe pipe);
294 	int (*get_fifo_size)(struct drm_i915_private *dev_priv,
295 			     enum i9xx_plane_id i9xx_plane);
296 	int (*compute_pipe_wm)(struct intel_crtc_state *crtc_state);
297 	int (*compute_intermediate_wm)(struct intel_crtc_state *crtc_state);
298 	void (*initial_watermarks)(struct intel_atomic_state *state,
299 				   struct intel_crtc *crtc);
300 	void (*atomic_update_watermarks)(struct intel_atomic_state *state,
301 					 struct intel_crtc *crtc);
302 	void (*optimize_watermarks)(struct intel_atomic_state *state,
303 				    struct intel_crtc *crtc);
304 	int (*compute_global_watermarks)(struct intel_atomic_state *state);
305 	void (*update_wm)(struct intel_crtc *crtc);
306 	int (*modeset_calc_cdclk)(struct intel_cdclk_state *state);
307 	u8 (*calc_voltage_level)(int cdclk);
308 	/* Returns the active state of the crtc, and if the crtc is active,
309 	 * fills out the pipe-config with the hw state. */
310 	bool (*get_pipe_config)(struct intel_crtc *,
311 				struct intel_crtc_state *);
312 	void (*get_initial_plane_config)(struct intel_crtc *,
313 					 struct intel_initial_plane_config *);
314 	int (*crtc_compute_clock)(struct intel_crtc *crtc,
315 				  struct intel_crtc_state *crtc_state);
316 	void (*crtc_enable)(struct intel_atomic_state *state,
317 			    struct intel_crtc *crtc);
318 	void (*crtc_disable)(struct intel_atomic_state *state,
319 			     struct intel_crtc *crtc);
320 	void (*commit_modeset_enables)(struct intel_atomic_state *state);
321 	void (*commit_modeset_disables)(struct intel_atomic_state *state);
322 	void (*audio_codec_enable)(struct intel_encoder *encoder,
323 				   const struct intel_crtc_state *crtc_state,
324 				   const struct drm_connector_state *conn_state);
325 	void (*audio_codec_disable)(struct intel_encoder *encoder,
326 				    const struct intel_crtc_state *old_crtc_state,
327 				    const struct drm_connector_state *old_conn_state);
328 	void (*fdi_link_train)(struct intel_crtc *crtc,
329 			       const struct intel_crtc_state *crtc_state);
330 	void (*init_clock_gating)(struct drm_i915_private *dev_priv);
331 	void (*hpd_irq_setup)(struct drm_i915_private *dev_priv);
332 	/* clock updates for mode set */
333 	/* cursor updates */
334 	/* render clock increase/decrease */
335 	/* display clock increase/decrease */
336 	/* pll clock increase/decrease */
337 
338 	int (*color_check)(struct intel_crtc_state *crtc_state);
339 	/*
340 	 * Program double buffered color management registers during
341 	 * vblank evasion. The registers should then latch during the
342 	 * next vblank start, alongside any other double buffered registers
343 	 * involved with the same commit.
344 	 */
345 	void (*color_commit)(const struct intel_crtc_state *crtc_state);
346 	/*
347 	 * Load LUTs (and other single buffered color management
348 	 * registers). Will (hopefully) be called during the vblank
349 	 * following the latching of any double buffered registers
350 	 * involved with the same commit.
351 	 */
352 	void (*load_luts)(const struct intel_crtc_state *crtc_state);
353 	void (*read_luts)(struct intel_crtc_state *crtc_state);
354 };
355 
356 struct intel_csr {
357 	struct work_struct work;
358 	const char *fw_path;
359 	u32 required_version;
360 	u32 max_fw_size; /* bytes */
361 	u32 *dmc_payload;
362 	u32 dmc_fw_size; /* dwords */
363 	u32 version;
364 	u32 mmio_count;
365 	i915_reg_t mmioaddr[20];
366 	u32 mmiodata[20];
367 	u32 dc_state;
368 	u32 target_dc_state;
369 	u32 allowed_dc_mask;
370 	intel_wakeref_t wakeref;
371 };
372 
373 enum i915_cache_level {
374 	I915_CACHE_NONE = 0,
375 	I915_CACHE_LLC, /* also used for snoopable memory on non-LLC */
376 	I915_CACHE_L3_LLC, /* gen7+, L3 sits between the domain specifc
377 			      caches, eg sampler/render caches, and the
378 			      large Last-Level-Cache. LLC is coherent with
379 			      the CPU, but L3 is only visible to the GPU. */
380 	I915_CACHE_WT, /* hsw:gt3e WriteThrough for scanouts */
381 };
382 
383 #define I915_COLOR_UNEVICTABLE (-1) /* a non-vma sharing the address space */
384 
385 struct intel_fbc {
386 	/* This is always the inner lock when overlapping with struct_mutex and
387 	 * it's the outer lock when overlapping with stolen_lock. */
388 	struct rwlock lock;
389 	unsigned threshold;
390 	unsigned int possible_framebuffer_bits;
391 	unsigned int busy_bits;
392 	struct intel_crtc *crtc;
393 
394 	struct drm_mm_node compressed_fb;
395 	struct drm_mm_node *compressed_llb;
396 
397 	bool false_color;
398 
399 	bool active;
400 	bool activated;
401 	bool flip_pending;
402 
403 	bool underrun_detected;
404 	struct work_struct underrun_work;
405 
406 	/*
407 	 * Due to the atomic rules we can't access some structures without the
408 	 * appropriate locking, so we cache information here in order to avoid
409 	 * these problems.
410 	 */
411 	struct intel_fbc_state_cache {
412 		struct {
413 			unsigned int mode_flags;
414 			u32 hsw_bdw_pixel_rate;
415 		} crtc;
416 
417 		struct {
418 			unsigned int rotation;
419 			int src_w;
420 			int src_h;
421 			bool visible;
422 			/*
423 			 * Display surface base address adjustement for
424 			 * pageflips. Note that on gen4+ this only adjusts up
425 			 * to a tile, offsets within a tile are handled in
426 			 * the hw itself (with the TILEOFF register).
427 			 */
428 			int adjusted_x;
429 			int adjusted_y;
430 
431 			int y;
432 
433 			u16 pixel_blend_mode;
434 		} plane;
435 
436 		struct {
437 			const struct drm_format_info *format;
438 			unsigned int stride;
439 		} fb;
440 		u16 gen9_wa_cfb_stride;
441 		s8 fence_id;
442 	} state_cache;
443 
444 	/*
445 	 * This structure contains everything that's relevant to program the
446 	 * hardware registers. When we want to figure out if we need to disable
447 	 * and re-enable FBC for a new configuration we just check if there's
448 	 * something different in the struct. The genx_fbc_activate functions
449 	 * are supposed to read from it in order to program the registers.
450 	 */
451 	struct intel_fbc_reg_params {
452 		struct {
453 			enum pipe pipe;
454 			enum i9xx_plane_id i9xx_plane;
455 			unsigned int fence_y_offset;
456 		} crtc;
457 
458 		struct {
459 			const struct drm_format_info *format;
460 			unsigned int stride;
461 		} fb;
462 
463 		int cfb_size;
464 		u16 gen9_wa_cfb_stride;
465 		s8 fence_id;
466 		bool plane_visible;
467 	} params;
468 
469 	const char *no_fbc_reason;
470 };
471 
472 /*
473  * HIGH_RR is the highest eDP panel refresh rate read from EDID
474  * LOW_RR is the lowest eDP panel refresh rate found from EDID
475  * parsing for same resolution.
476  */
477 enum drrs_refresh_rate_type {
478 	DRRS_HIGH_RR,
479 	DRRS_LOW_RR,
480 	DRRS_MAX_RR, /* RR count */
481 };
482 
483 enum drrs_support_type {
484 	DRRS_NOT_SUPPORTED = 0,
485 	STATIC_DRRS_SUPPORT = 1,
486 	SEAMLESS_DRRS_SUPPORT = 2
487 };
488 
489 struct intel_dp;
490 struct i915_drrs {
491 	struct rwlock mutex;
492 	struct delayed_work work;
493 	struct intel_dp *dp;
494 	unsigned busy_frontbuffer_bits;
495 	enum drrs_refresh_rate_type refresh_rate_type;
496 	enum drrs_support_type type;
497 };
498 
499 struct i915_psr {
500 	struct rwlock lock;
501 
502 #define I915_PSR_DEBUG_MODE_MASK	0x0f
503 #define I915_PSR_DEBUG_DEFAULT		0x00
504 #define I915_PSR_DEBUG_DISABLE		0x01
505 #define I915_PSR_DEBUG_ENABLE		0x02
506 #define I915_PSR_DEBUG_FORCE_PSR1	0x03
507 #define I915_PSR_DEBUG_IRQ		0x10
508 
509 	u32 debug;
510 	bool sink_support;
511 	bool enabled;
512 	struct intel_dp *dp;
513 	enum pipe pipe;
514 	enum transcoder transcoder;
515 	bool active;
516 	struct work_struct work;
517 	unsigned busy_frontbuffer_bits;
518 	bool sink_psr2_support;
519 	bool link_standby;
520 	bool colorimetry_support;
521 	bool psr2_enabled;
522 	u8 sink_sync_latency;
523 	ktime_t last_entry_attempt;
524 	ktime_t last_exit;
525 	bool sink_not_reliable;
526 	bool irq_aux_error;
527 	u16 su_x_granularity;
528 	bool dc3co_enabled;
529 	u32 dc3co_exit_delay;
530 	struct delayed_work dc3co_work;
531 	bool force_mode_changed;
532 };
533 
534 #define QUIRK_LVDS_SSC_DISABLE (1<<1)
535 #define QUIRK_INVERT_BRIGHTNESS (1<<2)
536 #define QUIRK_BACKLIGHT_PRESENT (1<<3)
537 #define QUIRK_PIN_SWIZZLED_PAGES (1<<5)
538 #define QUIRK_INCREASE_T12_DELAY (1<<6)
539 #define QUIRK_INCREASE_DDI_DISABLED_TIME (1<<7)
540 
541 struct intel_fbdev;
542 struct intel_fbc_work;
543 
544 struct intel_gmbus {
545 	struct i2c_adapter adapter;
546 #define GMBUS_FORCE_BIT_RETRY (1U << 31)
547 	u32 force_bit;
548 	u32 reg0;
549 	i915_reg_t gpio_reg;
550 	struct i2c_algo_bit_data bit_algo;
551 	struct drm_i915_private *dev_priv;
552 };
553 
554 struct i915_suspend_saved_registers {
555 	u32 saveDSPARB;
556 	u32 saveFBC_CONTROL;
557 	u32 saveCACHE_MODE_0;
558 	u32 saveMI_ARB_STATE;
559 	u32 saveSWF0[16];
560 	u32 saveSWF1[16];
561 	u32 saveSWF3[3];
562 	u64 saveFENCE[I915_MAX_NUM_FENCES];
563 	u32 savePCH_PORT_HOTPLUG;
564 	u16 saveGCDGMBUS;
565 };
566 
567 struct vlv_s0ix_state;
568 
569 #define MAX_L3_SLICES 2
570 struct intel_l3_parity {
571 	u32 *remap_info[MAX_L3_SLICES];
572 	struct work_struct error_work;
573 	int which_slice;
574 };
575 
576 struct i915_gem_mm {
577 	/** Memory allocator for GTT stolen memory */
578 	struct drm_mm stolen;
579 	/** Protects the usage of the GTT stolen memory allocator. This is
580 	 * always the inner lock when overlapping with struct_mutex. */
581 	struct rwlock stolen_lock;
582 
583 	/* Protects bound_list/unbound_list and #drm_i915_gem_object.mm.link */
584 	spinlock_t obj_lock;
585 
586 	/**
587 	 * List of objects which are purgeable.
588 	 */
589 	struct list_head purge_list;
590 
591 	/**
592 	 * List of objects which have allocated pages and are shrinkable.
593 	 */
594 	struct list_head shrink_list;
595 
596 	/**
597 	 * List of objects which are pending destruction.
598 	 */
599 	struct llist_head free_list;
600 	struct work_struct free_work;
601 	/**
602 	 * Count of objects pending destructions. Used to skip needlessly
603 	 * waiting on an RCU barrier if no objects are waiting to be freed.
604 	 */
605 	atomic_t free_count;
606 
607 	/**
608 	 * Small stash of WC pages
609 	 */
610 	struct pagestash wc_stash;
611 
612 	/**
613 	 * tmpfs instance used for shmem backed objects
614 	 */
615 	struct vfsmount *gemfs;
616 
617 	struct intel_memory_region *regions[INTEL_REGION_UNKNOWN];
618 
619 	struct notifier_block oom_notifier;
620 	struct notifier_block vmap_notifier;
621 	struct shrinker shrinker;
622 
623 	/**
624 	 * Workqueue to fault in userptr pages, flushed by the execbuf
625 	 * when required but otherwise left to userspace to try again
626 	 * on EAGAIN.
627 	 */
628 	struct workqueue_struct *userptr_wq;
629 
630 	/* shrinker accounting, also useful for userland debugging */
631 	u64 shrink_memory;
632 	u32 shrink_count;
633 };
634 
635 #define I915_IDLE_ENGINES_TIMEOUT (200) /* in ms */
636 
637 #define I915_RESET_TIMEOUT (10 * HZ) /* 10s */
638 #define I915_FENCE_TIMEOUT (10 * HZ) /* 10s */
639 
640 #define I915_ENGINE_DEAD_TIMEOUT  (4 * HZ)  /* Seqno, head and subunits dead */
641 #define I915_SEQNO_DEAD_TIMEOUT   (12 * HZ) /* Seqno dead with active head */
642 
643 #define I915_ENGINE_WEDGED_TIMEOUT  (60 * HZ)  /* Reset but no recovery? */
644 
645 /* Amount of SAGV/QGV points, BSpec precisely defines this */
646 #define I915_NUM_QGV_POINTS 8
647 
648 struct ddi_vbt_port_info {
649 	/* Non-NULL if port present. */
650 	const struct child_device_config *child;
651 
652 	int max_tmds_clock;
653 
654 	/* This is an index in the HDMI/DVI DDI buffer translation table. */
655 	u8 hdmi_level_shift;
656 	u8 hdmi_level_shift_set:1;
657 
658 	u8 supports_dvi:1;
659 	u8 supports_hdmi:1;
660 	u8 supports_dp:1;
661 	u8 supports_edp:1;
662 	u8 supports_typec_usb:1;
663 	u8 supports_tbt:1;
664 
665 	u8 alternate_aux_channel;
666 	u8 alternate_ddc_pin;
667 
668 	u8 dp_boost_level;
669 	u8 hdmi_boost_level;
670 	int dp_max_link_rate;		/* 0 for not limited by VBT */
671 };
672 
673 enum psr_lines_to_wait {
674 	PSR_0_LINES_TO_WAIT = 0,
675 	PSR_1_LINE_TO_WAIT,
676 	PSR_4_LINES_TO_WAIT,
677 	PSR_8_LINES_TO_WAIT
678 };
679 
680 struct intel_vbt_data {
681 	struct drm_display_mode *lfp_lvds_vbt_mode; /* if any */
682 	struct drm_display_mode *sdvo_lvds_vbt_mode; /* if any */
683 
684 	/* Feature bits */
685 	unsigned int int_tv_support:1;
686 	unsigned int lvds_dither:1;
687 	unsigned int int_crt_support:1;
688 	unsigned int lvds_use_ssc:1;
689 	unsigned int int_lvds_support:1;
690 	unsigned int display_clock_mode:1;
691 	unsigned int fdi_rx_polarity_inverted:1;
692 	unsigned int panel_type:4;
693 	int lvds_ssc_freq;
694 	unsigned int bios_lvds_val; /* initial [PCH_]LVDS reg val in VBIOS */
695 	enum drm_panel_orientation orientation;
696 
697 	enum drrs_support_type drrs_type;
698 
699 	struct {
700 		int rate;
701 		int lanes;
702 		int preemphasis;
703 		int vswing;
704 		bool low_vswing;
705 		bool initialized;
706 		int bpp;
707 		struct edp_power_seq pps;
708 	} edp;
709 
710 	struct {
711 		bool enable;
712 		bool full_link;
713 		bool require_aux_wakeup;
714 		int idle_frames;
715 		enum psr_lines_to_wait lines_to_wait;
716 		int tp1_wakeup_time_us;
717 		int tp2_tp3_wakeup_time_us;
718 		int psr2_tp2_tp3_wakeup_time_us;
719 	} psr;
720 
721 	struct {
722 		u16 pwm_freq_hz;
723 		bool present;
724 		bool active_low_pwm;
725 		u8 min_brightness;	/* min_brightness/255 of max */
726 		u8 controller;		/* brightness controller number */
727 		enum intel_backlight_type type;
728 	} backlight;
729 
730 	/* MIPI DSI */
731 	struct {
732 		u16 panel_id;
733 		struct mipi_config *config;
734 		struct mipi_pps_data *pps;
735 		u16 bl_ports;
736 		u16 cabc_ports;
737 		u8 seq_version;
738 		u32 size;
739 		u8 *data;
740 		const u8 *sequence[MIPI_SEQ_MAX];
741 		u8 *deassert_seq; /* Used by fixup_mipi_sequences() */
742 		enum drm_panel_orientation orientation;
743 	} dsi;
744 
745 	int crt_ddc_pin;
746 
747 	struct list_head display_devices;
748 
749 	struct ddi_vbt_port_info ddi_port_info[I915_MAX_PORTS];
750 	struct sdvo_device_mapping sdvo_mappings[2];
751 };
752 
753 enum intel_ddb_partitioning {
754 	INTEL_DDB_PART_1_2,
755 	INTEL_DDB_PART_5_6, /* IVB+ */
756 };
757 
758 struct ilk_wm_values {
759 	u32 wm_pipe[3];
760 	u32 wm_lp[3];
761 	u32 wm_lp_spr[3];
762 	bool enable_fbc_wm;
763 	enum intel_ddb_partitioning partitioning;
764 };
765 
766 struct g4x_pipe_wm {
767 	u16 plane[I915_MAX_PLANES];
768 	u16 fbc;
769 };
770 
771 struct g4x_sr_wm {
772 	u16 plane;
773 	u16 cursor;
774 	u16 fbc;
775 };
776 
777 struct vlv_wm_ddl_values {
778 	u8 plane[I915_MAX_PLANES];
779 };
780 
781 struct vlv_wm_values {
782 	struct g4x_pipe_wm pipe[3];
783 	struct g4x_sr_wm sr;
784 	struct vlv_wm_ddl_values ddl[3];
785 	u8 level;
786 	bool cxsr;
787 };
788 
789 struct g4x_wm_values {
790 	struct g4x_pipe_wm pipe[2];
791 	struct g4x_sr_wm sr;
792 	struct g4x_sr_wm hpll;
793 	bool cxsr;
794 	bool hpll_en;
795 	bool fbc_en;
796 };
797 
798 struct skl_ddb_entry {
799 	u16 start, end;	/* in number of blocks, 'end' is exclusive */
800 };
801 
802 static inline u16 skl_ddb_entry_size(const struct skl_ddb_entry *entry)
803 {
804 	return entry->end - entry->start;
805 }
806 
807 static inline bool skl_ddb_entry_equal(const struct skl_ddb_entry *e1,
808 				       const struct skl_ddb_entry *e2)
809 {
810 	if (e1->start == e2->start && e1->end == e2->end)
811 		return true;
812 
813 	return false;
814 }
815 
816 struct i915_frontbuffer_tracking {
817 	spinlock_t lock;
818 
819 	/*
820 	 * Tracking bits for delayed frontbuffer flushing du to gpu activity or
821 	 * scheduled flips.
822 	 */
823 	unsigned busy_bits;
824 	unsigned flip_bits;
825 };
826 
827 struct i915_virtual_gpu {
828 	struct rwlock lock; /* serialises sending of g2v_notify command pkts */
829 	bool active;
830 	u32 caps;
831 };
832 
833 struct intel_cdclk_config {
834 	unsigned int cdclk, vco, ref, bypass;
835 	u8 voltage_level;
836 };
837 
838 struct i915_selftest_stash {
839 	atomic_t counter;
840 };
841 
842 
843 struct inteldrm_softc {
844 #ifdef __OpenBSD__
845 	struct device sc_dev;
846 	bus_dma_tag_t dmat;
847 	bus_space_tag_t bst;
848 	struct agp_map *agph;
849 	bus_space_handle_t opregion_ioh;
850 	bus_space_handle_t opregion_rvda_ioh;
851 	bus_size_t opregion_rvda_size;
852 #endif
853 
854 	struct drm_device drm;
855 
856 	const struct intel_device_info __info; /* Use INTEL_INFO() to access. */
857 	struct intel_runtime_info __runtime; /* Use RUNTIME_INFO() to access. */
858 	struct intel_driver_caps caps;
859 
860 	/**
861 	 * Data Stolen Memory - aka "i915 stolen memory" gives us the start and
862 	 * end of stolen which we can optionally use to create GEM objects
863 	 * backed by stolen memory. Note that stolen_usable_size tells us
864 	 * exactly how much of this we are actually allowed to use, given that
865 	 * some portion of it is in fact reserved for use by hardware functions.
866 	 */
867 	struct resource dsm;
868 	/**
869 	 * Reseved portion of Data Stolen Memory
870 	 */
871 	struct resource dsm_reserved;
872 
873 	/*
874 	 * Stolen memory is segmented in hardware with different portions
875 	 * offlimits to certain functions.
876 	 *
877 	 * The drm_mm is initialised to the total accessible range, as found
878 	 * from the PCI config. On Broadwell+, this is further restricted to
879 	 * avoid the first page! The upper end of stolen memory is reserved for
880 	 * hardware functions and similarly removed from the accessible range.
881 	 */
882 	resource_size_t stolen_usable_size;	/* Total size minus reserved ranges */
883 
884 #ifdef __OpenBSD__
885 	pci_chipset_tag_t pc;
886 	pcitag_t tag;
887 	struct extent *memex;
888 	pci_intr_handle_t ih;
889 	irqreturn_t(*irq_handler) (int, void *);
890 	void *irqh;
891 
892 	struct vga_pci_bar bar;
893 	struct vga_pci_bar *vga_regs;
894 
895 	const struct pci_device_id *id;
896 
897 	int console;
898 	int primary;
899 	int nscreens;
900 	void (*switchcb)(void *, int, int);
901 	void *switchcbarg;
902 	void *switchcookie;
903 	struct task switchtask;
904 	struct rasops_info ro;
905 
906 	struct task burner_task;
907 	int burner_fblank;
908 
909 	struct backlight_device *backlight;
910 
911 	union flush {
912 		struct {
913 			bus_space_tag_t		bst;
914 			bus_space_handle_t	bsh;
915 		} i9xx;
916 		struct {
917 			bus_dma_segment_t	seg;
918 			caddr_t			kva;
919 		} i8xx;
920 	}			 ifp;
921 	struct vm_page *pgs;
922 #endif
923 
924 	struct intel_uncore uncore;
925 	struct intel_uncore_mmio_debug mmio_debug;
926 
927 	struct i915_virtual_gpu vgpu;
928 
929 	struct intel_gvt *gvt;
930 
931 	struct intel_wopcm wopcm;
932 
933 	struct intel_csr csr;
934 
935 	struct intel_gmbus gmbus[GMBUS_NUM_PINS];
936 
937 	/** gmbus_mutex protects against concurrent usage of the single hw gmbus
938 	 * controller on different i2c buses. */
939 	struct rwlock gmbus_mutex;
940 
941 	/**
942 	 * Base address of where the gmbus and gpio blocks are located (either
943 	 * on PCH or on SoC for platforms without PCH).
944 	 */
945 	u32 gpio_mmio_base;
946 
947 	u32 hsw_psr_mmio_adjust;
948 
949 	/* MMIO base address for MIPI regs */
950 	u32 mipi_mmio_base;
951 
952 	u32 pps_mmio_base;
953 
954 	wait_queue_head_t gmbus_wait_queue;
955 
956 	struct pci_dev *bridge_dev;
957 
958 	struct intel_engine_cs *engine[I915_NUM_ENGINES];
959 	struct rb_root uabi_engines;
960 
961 	struct resource mch_res;
962 
963 	/* protects the irq masks */
964 	spinlock_t irq_lock;
965 
966 	bool display_irqs_enabled;
967 
968 	/* To control wakeup latency, e.g. for irq-driven dp aux transfers. */
969 	struct pm_qos_request pm_qos;
970 
971 	/* Sideband mailbox protection */
972 	struct rwlock sb_lock;
973 	struct pm_qos_request sb_qos;
974 
975 	/** Cached value of IMR to avoid reads in updating the bitfield */
976 	union {
977 		u32 irq_mask;
978 		u32 de_irq_mask[I915_MAX_PIPES];
979 	};
980 	u32 pipestat_irq_mask[I915_MAX_PIPES];
981 
982 	struct i915_hotplug hotplug;
983 	struct intel_fbc fbc;
984 	struct i915_drrs drrs;
985 	struct intel_opregion opregion;
986 	struct intel_vbt_data vbt;
987 
988 	bool preserve_bios_swizzle;
989 
990 	/* overlay */
991 	struct intel_overlay *overlay;
992 
993 	/* backlight registers and fields in struct intel_panel */
994 	struct rwlock backlight_lock;
995 
996 	/* protects panel power sequencer state */
997 	struct rwlock pps_mutex;
998 
999 	unsigned int fsb_freq, mem_freq, is_ddr3;
1000 	unsigned int skl_preferred_vco_freq;
1001 	unsigned int max_cdclk_freq;
1002 
1003 	unsigned int max_dotclk_freq;
1004 	unsigned int hpll_freq;
1005 	unsigned int fdi_pll_freq;
1006 	unsigned int czclk_freq;
1007 
1008 	struct {
1009 		/* The current hardware cdclk configuration */
1010 		struct intel_cdclk_config hw;
1011 
1012 		/* cdclk, divider, and ratio table from bspec */
1013 		const struct intel_cdclk_vals *table;
1014 
1015 		struct intel_global_obj obj;
1016 	} cdclk;
1017 
1018 	/**
1019 	 * wq - Driver workqueue for GEM.
1020 	 *
1021 	 * NOTE: Work items scheduled here are not allowed to grab any modeset
1022 	 * locks, for otherwise the flushing done in the pageflip code will
1023 	 * result in deadlocks.
1024 	 */
1025 	struct workqueue_struct *wq;
1026 
1027 	/* ordered wq for modesets */
1028 	struct workqueue_struct *modeset_wq;
1029 	/* unbound hipri wq for page flips/plane updates */
1030 	struct workqueue_struct *flip_wq;
1031 
1032 	/* Display functions */
1033 	struct drm_i915_display_funcs display;
1034 
1035 	/* PCH chipset type */
1036 	enum intel_pch pch_type;
1037 	unsigned short pch_id;
1038 
1039 	unsigned long quirks;
1040 
1041 	struct drm_atomic_state *modeset_restore_state;
1042 	struct drm_modeset_acquire_ctx reset_ctx;
1043 
1044 	struct i915_ggtt ggtt; /* VM representing the global address space */
1045 
1046 	struct i915_gem_mm mm;
1047 	DECLARE_HASHTABLE(mm_structs, 7);
1048 	struct rwlock mm_lock;
1049 
1050 	/* Kernel Modesetting */
1051 
1052 	struct intel_crtc *plane_to_crtc_mapping[I915_MAX_PIPES];
1053 	struct intel_crtc *pipe_to_crtc_mapping[I915_MAX_PIPES];
1054 
1055 	/**
1056 	 * dpll and cdclk state is protected by connection_mutex
1057 	 * dpll.lock serializes intel_{prepare,enable,disable}_shared_dpll.
1058 	 * Must be global rather than per dpll, because on some platforms plls
1059 	 * share registers.
1060 	 */
1061 	struct {
1062 		struct rwlock lock;
1063 
1064 		int num_shared_dpll;
1065 		struct intel_shared_dpll shared_dplls[I915_NUM_PLLS];
1066 		const struct intel_dpll_mgr *mgr;
1067 
1068 		struct {
1069 			int nssc;
1070 			int ssc;
1071 		} ref_clks;
1072 	} dpll;
1073 
1074 	struct list_head global_obj_list;
1075 
1076 	/*
1077 	 * For reading active_pipes holding any crtc lock is
1078 	 * sufficient, for writing must hold all of them.
1079 	 */
1080 	u8 active_pipes;
1081 
1082 	int dpio_phy_iosf_port[I915_NUM_PHYS_VLV];
1083 
1084 	struct i915_wa_list gt_wa_list;
1085 
1086 	struct i915_frontbuffer_tracking fb_tracking;
1087 
1088 	struct intel_atomic_helper {
1089 		struct llist_head free_list;
1090 		struct work_struct free_work;
1091 	} atomic_helper;
1092 
1093 	bool mchbar_need_disable;
1094 
1095 	struct intel_l3_parity l3_parity;
1096 
1097 	/*
1098 	 * edram size in MB.
1099 	 * Cannot be determined by PCIID. You must always read a register.
1100 	 */
1101 	u32 edram_size_mb;
1102 
1103 	struct i915_power_domains power_domains;
1104 
1105 	struct i915_psr psr;
1106 
1107 	struct i915_gpu_error gpu_error;
1108 
1109 	struct drm_i915_gem_object *vlv_pctx;
1110 
1111 	/* list of fbdev register on this device */
1112 	struct intel_fbdev *fbdev;
1113 	struct work_struct fbdev_suspend_work;
1114 
1115 	struct drm_property *broadcast_rgb_property;
1116 	struct drm_property *force_audio_property;
1117 
1118 	/* hda/i915 audio component */
1119 	struct i915_audio_component *audio_component;
1120 	bool audio_component_registered;
1121 	/**
1122 	 * av_mutex - mutex for audio/video sync
1123 	 *
1124 	 */
1125 	struct rwlock av_mutex;
1126 	int audio_power_refcount;
1127 	u32 audio_freq_cntrl;
1128 
1129 	u32 fdi_rx_config;
1130 
1131 	/* Shadow for DISPLAY_PHY_CONTROL which can't be safely read */
1132 	u32 chv_phy_control;
1133 	/*
1134 	 * Shadows for CHV DPLL_MD regs to keep the state
1135 	 * checker somewhat working in the presence hardware
1136 	 * crappiness (can't read out DPLL_MD for pipes B & C).
1137 	 */
1138 	u32 chv_dpll_md[I915_MAX_PIPES];
1139 	u32 bxt_phy_grc;
1140 
1141 	u32 suspend_count;
1142 	bool power_domains_suspended;
1143 	struct i915_suspend_saved_registers regfile;
1144 	struct vlv_s0ix_state *vlv_s0ix_state;
1145 
1146 	enum {
1147 		I915_SAGV_UNKNOWN = 0,
1148 		I915_SAGV_DISABLED,
1149 		I915_SAGV_ENABLED,
1150 		I915_SAGV_NOT_CONTROLLED
1151 	} sagv_status;
1152 
1153 	u32 sagv_block_time_us;
1154 
1155 	struct {
1156 		/*
1157 		 * Raw watermark latency values:
1158 		 * in 0.1us units for WM0,
1159 		 * in 0.5us units for WM1+.
1160 		 */
1161 		/* primary */
1162 		u16 pri_latency[5];
1163 		/* sprite */
1164 		u16 spr_latency[5];
1165 		/* cursor */
1166 		u16 cur_latency[5];
1167 		/*
1168 		 * Raw watermark memory latency values
1169 		 * for SKL for all 8 levels
1170 		 * in 1us units.
1171 		 */
1172 		u16 skl_latency[8];
1173 
1174 		/* current hardware state */
1175 		union {
1176 			struct ilk_wm_values hw;
1177 			struct vlv_wm_values vlv;
1178 			struct g4x_wm_values g4x;
1179 		};
1180 
1181 		u8 max_level;
1182 
1183 		/*
1184 		 * Should be held around atomic WM register writing; also
1185 		 * protects * intel_crtc->wm.active and
1186 		 * crtc_state->wm.need_postvbl_update.
1187 		 */
1188 		struct rwlock wm_mutex;
1189 
1190 		/*
1191 		 * Set during HW readout of watermarks/DDB.  Some platforms
1192 		 * need to know when we're still using BIOS-provided values
1193 		 * (which we don't fully trust).
1194 		 */
1195 		bool distrust_bios_wm;
1196 	} wm;
1197 
1198 	u8 enabled_dbuf_slices_mask; /* GEN11 has configurable 2 slices */
1199 
1200 	struct dram_info {
1201 		bool valid;
1202 		bool is_16gb_dimm;
1203 		u8 num_channels;
1204 		u8 ranks;
1205 		u32 bandwidth_kbps;
1206 		bool symmetric_memory;
1207 		enum intel_dram_type {
1208 			INTEL_DRAM_UNKNOWN,
1209 			INTEL_DRAM_DDR3,
1210 			INTEL_DRAM_DDR4,
1211 			INTEL_DRAM_LPDDR3,
1212 			INTEL_DRAM_LPDDR4
1213 		} type;
1214 	} dram_info;
1215 
1216 	struct intel_bw_info {
1217 		/* for each QGV point */
1218 		unsigned int deratedbw[I915_NUM_QGV_POINTS];
1219 		u8 num_qgv_points;
1220 		u8 num_planes;
1221 	} max_bw[6];
1222 
1223 	struct intel_global_obj bw_obj;
1224 
1225 	struct intel_runtime_pm runtime_pm;
1226 
1227 	struct i915_perf perf;
1228 
1229 	/* Abstract the submission mechanism (legacy ringbuffer or execlists) away */
1230 	struct intel_gt gt;
1231 
1232 	struct {
1233 		struct i915_gem_contexts {
1234 			spinlock_t lock; /* locks list */
1235 			struct list_head list;
1236 
1237 			struct llist_head free_list;
1238 			struct work_struct free_work;
1239 		} contexts;
1240 
1241 		/*
1242 		 * We replace the local file with a global mappings as the
1243 		 * backing storage for the mmap is on the device and not
1244 		 * on the struct file, and we do not want to prolong the
1245 		 * lifetime of the local fd. To minimise the number of
1246 		 * anonymous inodes we create, we use a global singleton to
1247 		 * share the global mapping.
1248 		 */
1249 		struct file *mmap_singleton;
1250 	} gem;
1251 
1252 	u8 pch_ssc_use;
1253 
1254 	/* For i915gm/i945gm vblank irq workaround */
1255 	u8 vblank_enabled;
1256 
1257 	/* perform PHY state sanity checks? */
1258 	bool chv_phy_assert[2];
1259 
1260 	bool ipc_enabled;
1261 
1262 	/* Used to save the pipe-to-encoder mapping for audio */
1263 	struct intel_encoder *av_enc_map[I915_MAX_PIPES];
1264 
1265 	/* necessary resource sharing with HDMI LPE audio driver. */
1266 	struct {
1267 		struct platform_device *platdev;
1268 		int	irq;
1269 	} lpe_audio;
1270 
1271 	struct i915_pmu pmu;
1272 
1273 	struct i915_hdcp_comp_master *hdcp_master;
1274 	bool hdcp_comp_added;
1275 
1276 	/* Mutex to protect the above hdcp component related values. */
1277 	struct rwlock hdcp_comp_mutex;
1278 
1279 	I915_SELFTEST_DECLARE(struct i915_selftest_stash selftest;)
1280 
1281 	/*
1282 	 * NOTE: This is the dri1/ums dungeon, don't add stuff here. Your patch
1283 	 * will be rejected. Instead look for a better place.
1284 	 */
1285 };
1286 
1287 static inline struct drm_i915_private *to_i915(const struct drm_device *dev)
1288 {
1289 	return container_of(dev, struct drm_i915_private, drm);
1290 }
1291 
1292 static inline struct drm_i915_private *kdev_to_i915(struct device *kdev)
1293 {
1294 	return dev_get_drvdata(kdev);
1295 }
1296 
1297 static inline struct drm_i915_private *pdev_to_i915(struct pci_dev *pdev)
1298 {
1299 	STUB();
1300 	return NULL;
1301 #ifdef notyet
1302 	return pci_get_drvdata(pdev);
1303 #endif
1304 }
1305 
1306 /* Simple iterator over all initialised engines */
1307 #define for_each_engine(engine__, dev_priv__, id__) \
1308 	for ((id__) = 0; \
1309 	     (id__) < I915_NUM_ENGINES; \
1310 	     (id__)++) \
1311 		for_each_if ((engine__) = (dev_priv__)->engine[(id__)])
1312 
1313 /* Iterator over subset of engines selected by mask */
1314 #define for_each_engine_masked(engine__, gt__, mask__, tmp__) \
1315 	for ((tmp__) = (mask__) & INTEL_INFO((gt__)->i915)->engine_mask; \
1316 	     (tmp__) ? \
1317 	     ((engine__) = (gt__)->engine[__mask_next_bit(tmp__)]), 1 : \
1318 	     0;)
1319 
1320 #define rb_to_uabi_engine(rb) \
1321 	rb_entry_safe(rb, struct intel_engine_cs, uabi_node)
1322 
1323 #define for_each_uabi_engine(engine__, i915__) \
1324 	for ((engine__) = rb_to_uabi_engine(rb_first(&(i915__)->uabi_engines));\
1325 	     (engine__); \
1326 	     (engine__) = rb_to_uabi_engine(rb_next(&(engine__)->uabi_node)))
1327 
1328 #define I915_GTT_OFFSET_NONE ((u32)-1)
1329 
1330 /*
1331  * Frontbuffer tracking bits. Set in obj->frontbuffer_bits while a gem bo is
1332  * considered to be the frontbuffer for the given plane interface-wise. This
1333  * doesn't mean that the hw necessarily already scans it out, but that any
1334  * rendering (by the cpu or gpu) will land in the frontbuffer eventually.
1335  *
1336  * We have one bit per pipe and per scanout plane type.
1337  */
1338 #define INTEL_FRONTBUFFER_BITS_PER_PIPE 8
1339 #define INTEL_FRONTBUFFER(pipe, plane_id) ({ \
1340 	BUILD_BUG_ON(INTEL_FRONTBUFFER_BITS_PER_PIPE * I915_MAX_PIPES > 32); \
1341 	BUILD_BUG_ON(I915_MAX_PLANES > INTEL_FRONTBUFFER_BITS_PER_PIPE); \
1342 	BIT((plane_id) + INTEL_FRONTBUFFER_BITS_PER_PIPE * (pipe)); \
1343 })
1344 #define INTEL_FRONTBUFFER_OVERLAY(pipe) \
1345 	BIT(INTEL_FRONTBUFFER_BITS_PER_PIPE - 1 + INTEL_FRONTBUFFER_BITS_PER_PIPE * (pipe))
1346 #define INTEL_FRONTBUFFER_ALL_MASK(pipe) \
1347 	GENMASK(INTEL_FRONTBUFFER_BITS_PER_PIPE * ((pipe) + 1) - 1, \
1348 		INTEL_FRONTBUFFER_BITS_PER_PIPE * (pipe))
1349 
1350 #define INTEL_INFO(dev_priv)	(&(dev_priv)->__info)
1351 #define RUNTIME_INFO(dev_priv)	(&(dev_priv)->__runtime)
1352 #define DRIVER_CAPS(dev_priv)	(&(dev_priv)->caps)
1353 
1354 #define INTEL_GEN(dev_priv)	(INTEL_INFO(dev_priv)->gen)
1355 #define INTEL_DEVID(dev_priv)	(RUNTIME_INFO(dev_priv)->device_id)
1356 
1357 #define REVID_FOREVER		0xff
1358 #define INTEL_REVID(dev_priv)	((dev_priv)->drm.pdev->revision)
1359 
1360 #define INTEL_GEN_MASK(s, e) ( \
1361 	BUILD_BUG_ON_ZERO(!__builtin_constant_p(s)) + \
1362 	BUILD_BUG_ON_ZERO(!__builtin_constant_p(e)) + \
1363 	GENMASK((e) - 1, (s) - 1))
1364 
1365 /* Returns true if Gen is in inclusive range [Start, End] */
1366 #define IS_GEN_RANGE(dev_priv, s, e) \
1367 	(!!(INTEL_INFO(dev_priv)->gen_mask & INTEL_GEN_MASK((s), (e))))
1368 
1369 #define IS_GEN(dev_priv, n) \
1370 	(BUILD_BUG_ON_ZERO(!__builtin_constant_p(n)) + \
1371 	 INTEL_INFO(dev_priv)->gen == (n))
1372 
1373 #define HAS_DSB(dev_priv)	(INTEL_INFO(dev_priv)->display.has_dsb)
1374 
1375 /*
1376  * Return true if revision is in range [since,until] inclusive.
1377  *
1378  * Use 0 for open-ended since, and REVID_FOREVER for open-ended until.
1379  */
1380 #define IS_REVID(p, since, until) \
1381 	(INTEL_REVID(p) >= (since) && INTEL_REVID(p) <= (until))
1382 
1383 static __always_inline unsigned int
1384 __platform_mask_index(const struct intel_runtime_info *info,
1385 		      enum intel_platform p)
1386 {
1387 	const unsigned int pbits =
1388 		BITS_PER_TYPE(info->platform_mask[0]) - INTEL_SUBPLATFORM_BITS;
1389 
1390 	/* Expand the platform_mask array if this fails. */
1391 	BUILD_BUG_ON(INTEL_MAX_PLATFORMS >
1392 		     pbits * ARRAY_SIZE(info->platform_mask));
1393 
1394 	return p / pbits;
1395 }
1396 
1397 static __always_inline unsigned int
1398 __platform_mask_bit(const struct intel_runtime_info *info,
1399 		    enum intel_platform p)
1400 {
1401 	const unsigned int pbits =
1402 		BITS_PER_TYPE(info->platform_mask[0]) - INTEL_SUBPLATFORM_BITS;
1403 
1404 	return p % pbits + INTEL_SUBPLATFORM_BITS;
1405 }
1406 
1407 static inline u32
1408 intel_subplatform(const struct intel_runtime_info *info, enum intel_platform p)
1409 {
1410 	const unsigned int pi = __platform_mask_index(info, p);
1411 
1412 	return info->platform_mask[pi] & INTEL_SUBPLATFORM_BITS;
1413 }
1414 
1415 static __always_inline bool
1416 IS_PLATFORM(const struct drm_i915_private *i915, enum intel_platform p)
1417 {
1418 	const struct intel_runtime_info *info = RUNTIME_INFO(i915);
1419 	const unsigned int pi = __platform_mask_index(info, p);
1420 	const unsigned int pb = __platform_mask_bit(info, p);
1421 
1422 #ifdef notyet
1423 	BUILD_BUG_ON(!__builtin_constant_p(p));
1424 #endif
1425 
1426 	return info->platform_mask[pi] & BIT(pb);
1427 }
1428 
1429 static __always_inline bool
1430 IS_SUBPLATFORM(const struct drm_i915_private *i915,
1431 	       enum intel_platform p, unsigned int s)
1432 {
1433 	const struct intel_runtime_info *info = RUNTIME_INFO(i915);
1434 	const unsigned int pi = __platform_mask_index(info, p);
1435 	const unsigned int pb = __platform_mask_bit(info, p);
1436 	const unsigned int msb = BITS_PER_TYPE(info->platform_mask[0]) - 1;
1437 	const u32 mask = info->platform_mask[pi];
1438 
1439 #ifdef notyet
1440 	BUILD_BUG_ON(!__builtin_constant_p(p));
1441 	BUILD_BUG_ON(!__builtin_constant_p(s));
1442 	BUILD_BUG_ON((s) >= INTEL_SUBPLATFORM_BITS);
1443 #endif
1444 
1445 	/* Shift and test on the MSB position so sign flag can be used. */
1446 	return ((mask << (msb - pb)) & (mask << (msb - s))) & BIT(msb);
1447 }
1448 
1449 #define IS_MOBILE(dev_priv)	(INTEL_INFO(dev_priv)->is_mobile)
1450 #define IS_DGFX(dev_priv)   (INTEL_INFO(dev_priv)->is_dgfx)
1451 
1452 #define IS_I830(dev_priv)	IS_PLATFORM(dev_priv, INTEL_I830)
1453 #define IS_I845G(dev_priv)	IS_PLATFORM(dev_priv, INTEL_I845G)
1454 #define IS_I85X(dev_priv)	IS_PLATFORM(dev_priv, INTEL_I85X)
1455 #define IS_I865G(dev_priv)	IS_PLATFORM(dev_priv, INTEL_I865G)
1456 #define IS_I915G(dev_priv)	IS_PLATFORM(dev_priv, INTEL_I915G)
1457 #define IS_I915GM(dev_priv)	IS_PLATFORM(dev_priv, INTEL_I915GM)
1458 #define IS_I945G(dev_priv)	IS_PLATFORM(dev_priv, INTEL_I945G)
1459 #define IS_I945GM(dev_priv)	IS_PLATFORM(dev_priv, INTEL_I945GM)
1460 #define IS_I965G(dev_priv)	IS_PLATFORM(dev_priv, INTEL_I965G)
1461 #define IS_I965GM(dev_priv)	IS_PLATFORM(dev_priv, INTEL_I965GM)
1462 #define IS_G45(dev_priv)	IS_PLATFORM(dev_priv, INTEL_G45)
1463 #define IS_GM45(dev_priv)	IS_PLATFORM(dev_priv, INTEL_GM45)
1464 #define IS_G4X(dev_priv)	(IS_G45(dev_priv) || IS_GM45(dev_priv))
1465 #define IS_PINEVIEW(dev_priv)	IS_PLATFORM(dev_priv, INTEL_PINEVIEW)
1466 #define IS_G33(dev_priv)	IS_PLATFORM(dev_priv, INTEL_G33)
1467 #define IS_IRONLAKE(dev_priv)	IS_PLATFORM(dev_priv, INTEL_IRONLAKE)
1468 #define IS_IRONLAKE_M(dev_priv) \
1469 	(IS_PLATFORM(dev_priv, INTEL_IRONLAKE) && IS_MOBILE(dev_priv))
1470 #define IS_IVYBRIDGE(dev_priv)	IS_PLATFORM(dev_priv, INTEL_IVYBRIDGE)
1471 #define IS_IVB_GT1(dev_priv)	(IS_IVYBRIDGE(dev_priv) && \
1472 				 INTEL_INFO(dev_priv)->gt == 1)
1473 #define IS_VALLEYVIEW(dev_priv)	IS_PLATFORM(dev_priv, INTEL_VALLEYVIEW)
1474 #define IS_CHERRYVIEW(dev_priv)	IS_PLATFORM(dev_priv, INTEL_CHERRYVIEW)
1475 #define IS_HASWELL(dev_priv)	IS_PLATFORM(dev_priv, INTEL_HASWELL)
1476 #define IS_BROADWELL(dev_priv)	IS_PLATFORM(dev_priv, INTEL_BROADWELL)
1477 #define IS_SKYLAKE(dev_priv)	IS_PLATFORM(dev_priv, INTEL_SKYLAKE)
1478 #define IS_BROXTON(dev_priv)	IS_PLATFORM(dev_priv, INTEL_BROXTON)
1479 #define IS_KABYLAKE(dev_priv)	IS_PLATFORM(dev_priv, INTEL_KABYLAKE)
1480 #define IS_GEMINILAKE(dev_priv)	IS_PLATFORM(dev_priv, INTEL_GEMINILAKE)
1481 #define IS_COFFEELAKE(dev_priv)	IS_PLATFORM(dev_priv, INTEL_COFFEELAKE)
1482 #define IS_CANNONLAKE(dev_priv)	IS_PLATFORM(dev_priv, INTEL_CANNONLAKE)
1483 #define IS_ICELAKE(dev_priv)	IS_PLATFORM(dev_priv, INTEL_ICELAKE)
1484 #define IS_ELKHARTLAKE(dev_priv)	IS_PLATFORM(dev_priv, INTEL_ELKHARTLAKE)
1485 #define IS_TIGERLAKE(dev_priv)	IS_PLATFORM(dev_priv, INTEL_TIGERLAKE)
1486 #define IS_HSW_EARLY_SDV(dev_priv) (IS_HASWELL(dev_priv) && \
1487 				    (INTEL_DEVID(dev_priv) & 0xFF00) == 0x0C00)
1488 #define IS_BDW_ULT(dev_priv) \
1489 	IS_SUBPLATFORM(dev_priv, INTEL_BROADWELL, INTEL_SUBPLATFORM_ULT)
1490 #define IS_BDW_ULX(dev_priv) \
1491 	IS_SUBPLATFORM(dev_priv, INTEL_BROADWELL, INTEL_SUBPLATFORM_ULX)
1492 #define IS_BDW_GT3(dev_priv)	(IS_BROADWELL(dev_priv) && \
1493 				 INTEL_INFO(dev_priv)->gt == 3)
1494 #define IS_HSW_ULT(dev_priv) \
1495 	IS_SUBPLATFORM(dev_priv, INTEL_HASWELL, INTEL_SUBPLATFORM_ULT)
1496 #define IS_HSW_GT3(dev_priv)	(IS_HASWELL(dev_priv) && \
1497 				 INTEL_INFO(dev_priv)->gt == 3)
1498 #define IS_HSW_GT1(dev_priv)	(IS_HASWELL(dev_priv) && \
1499 				 INTEL_INFO(dev_priv)->gt == 1)
1500 /* ULX machines are also considered ULT. */
1501 #define IS_HSW_ULX(dev_priv) \
1502 	IS_SUBPLATFORM(dev_priv, INTEL_HASWELL, INTEL_SUBPLATFORM_ULX)
1503 #define IS_SKL_ULT(dev_priv) \
1504 	IS_SUBPLATFORM(dev_priv, INTEL_SKYLAKE, INTEL_SUBPLATFORM_ULT)
1505 #define IS_SKL_ULX(dev_priv) \
1506 	IS_SUBPLATFORM(dev_priv, INTEL_SKYLAKE, INTEL_SUBPLATFORM_ULX)
1507 #define IS_KBL_ULT(dev_priv) \
1508 	IS_SUBPLATFORM(dev_priv, INTEL_KABYLAKE, INTEL_SUBPLATFORM_ULT)
1509 #define IS_KBL_ULX(dev_priv) \
1510 	IS_SUBPLATFORM(dev_priv, INTEL_KABYLAKE, INTEL_SUBPLATFORM_ULX)
1511 #define IS_SKL_GT2(dev_priv)	(IS_SKYLAKE(dev_priv) && \
1512 				 INTEL_INFO(dev_priv)->gt == 2)
1513 #define IS_SKL_GT3(dev_priv)	(IS_SKYLAKE(dev_priv) && \
1514 				 INTEL_INFO(dev_priv)->gt == 3)
1515 #define IS_SKL_GT4(dev_priv)	(IS_SKYLAKE(dev_priv) && \
1516 				 INTEL_INFO(dev_priv)->gt == 4)
1517 #define IS_KBL_GT2(dev_priv)	(IS_KABYLAKE(dev_priv) && \
1518 				 INTEL_INFO(dev_priv)->gt == 2)
1519 #define IS_KBL_GT3(dev_priv)	(IS_KABYLAKE(dev_priv) && \
1520 				 INTEL_INFO(dev_priv)->gt == 3)
1521 #define IS_CFL_ULT(dev_priv) \
1522 	IS_SUBPLATFORM(dev_priv, INTEL_COFFEELAKE, INTEL_SUBPLATFORM_ULT)
1523 #define IS_CFL_ULX(dev_priv) \
1524 	IS_SUBPLATFORM(dev_priv, INTEL_COFFEELAKE, INTEL_SUBPLATFORM_ULX)
1525 #define IS_CFL_GT2(dev_priv)	(IS_COFFEELAKE(dev_priv) && \
1526 				 INTEL_INFO(dev_priv)->gt == 2)
1527 #define IS_CFL_GT3(dev_priv)	(IS_COFFEELAKE(dev_priv) && \
1528 				 INTEL_INFO(dev_priv)->gt == 3)
1529 #define IS_CNL_WITH_PORT_F(dev_priv) \
1530 	IS_SUBPLATFORM(dev_priv, INTEL_CANNONLAKE, INTEL_SUBPLATFORM_PORTF)
1531 #define IS_ICL_WITH_PORT_F(dev_priv) \
1532 	IS_SUBPLATFORM(dev_priv, INTEL_ICELAKE, INTEL_SUBPLATFORM_PORTF)
1533 
1534 #define SKL_REVID_A0		0x0
1535 #define SKL_REVID_B0		0x1
1536 #define SKL_REVID_C0		0x2
1537 #define SKL_REVID_D0		0x3
1538 #define SKL_REVID_E0		0x4
1539 #define SKL_REVID_F0		0x5
1540 #define SKL_REVID_G0		0x6
1541 #define SKL_REVID_H0		0x7
1542 
1543 #define IS_SKL_REVID(p, since, until) (IS_SKYLAKE(p) && IS_REVID(p, since, until))
1544 
1545 #define BXT_REVID_A0		0x0
1546 #define BXT_REVID_A1		0x1
1547 #define BXT_REVID_B0		0x3
1548 #define BXT_REVID_B_LAST	0x8
1549 #define BXT_REVID_C0		0x9
1550 
1551 #define IS_BXT_REVID(dev_priv, since, until) \
1552 	(IS_BROXTON(dev_priv) && IS_REVID(dev_priv, since, until))
1553 
1554 #define KBL_REVID_A0		0x0
1555 #define KBL_REVID_B0		0x1
1556 #define KBL_REVID_C0		0x2
1557 #define KBL_REVID_D0		0x3
1558 #define KBL_REVID_E0		0x4
1559 
1560 #define IS_KBL_REVID(dev_priv, since, until) \
1561 	(IS_KABYLAKE(dev_priv) && IS_REVID(dev_priv, since, until))
1562 
1563 #define GLK_REVID_A0		0x0
1564 #define GLK_REVID_A1		0x1
1565 #define GLK_REVID_A2		0x2
1566 #define GLK_REVID_B0		0x3
1567 
1568 #define IS_GLK_REVID(dev_priv, since, until) \
1569 	(IS_GEMINILAKE(dev_priv) && IS_REVID(dev_priv, since, until))
1570 
1571 #define CNL_REVID_A0		0x0
1572 #define CNL_REVID_B0		0x1
1573 #define CNL_REVID_C0		0x2
1574 
1575 #define IS_CNL_REVID(p, since, until) \
1576 	(IS_CANNONLAKE(p) && IS_REVID(p, since, until))
1577 
1578 #define ICL_REVID_A0		0x0
1579 #define ICL_REVID_A2		0x1
1580 #define ICL_REVID_B0		0x3
1581 #define ICL_REVID_B2		0x4
1582 #define ICL_REVID_C0		0x5
1583 
1584 #define IS_ICL_REVID(p, since, until) \
1585 	(IS_ICELAKE(p) && IS_REVID(p, since, until))
1586 
1587 #define TGL_REVID_A0		0x0
1588 #define TGL_REVID_B0		0x1
1589 #define TGL_REVID_C0		0x2
1590 
1591 #define IS_TGL_REVID(p, since, until) \
1592 	(IS_TIGERLAKE(p) && IS_REVID(p, since, until))
1593 
1594 #define IS_LP(dev_priv)	(INTEL_INFO(dev_priv)->is_lp)
1595 #define IS_GEN9_LP(dev_priv)	(IS_GEN(dev_priv, 9) && IS_LP(dev_priv))
1596 #define IS_GEN9_BC(dev_priv)	(IS_GEN(dev_priv, 9) && !IS_LP(dev_priv))
1597 
1598 #define HAS_ENGINE(dev_priv, id) (INTEL_INFO(dev_priv)->engine_mask & BIT(id))
1599 
1600 #define ENGINE_INSTANCES_MASK(dev_priv, first, count) ({		\
1601 	unsigned int first__ = (first);					\
1602 	unsigned int count__ = (count);					\
1603 	(INTEL_INFO(dev_priv)->engine_mask &				\
1604 	 GENMASK(first__ + count__ - 1, first__)) >> first__;		\
1605 })
1606 #define VDBOX_MASK(dev_priv) \
1607 	ENGINE_INSTANCES_MASK(dev_priv, VCS0, I915_MAX_VCS)
1608 #define VEBOX_MASK(dev_priv) \
1609 	ENGINE_INSTANCES_MASK(dev_priv, VECS0, I915_MAX_VECS)
1610 
1611 /*
1612  * The Gen7 cmdparser copies the scanned buffer to the ggtt for execution
1613  * All later gens can run the final buffer from the ppgtt
1614  */
1615 #define CMDPARSER_USES_GGTT(dev_priv) IS_GEN(dev_priv, 7)
1616 
1617 #define HAS_LLC(dev_priv)	(INTEL_INFO(dev_priv)->has_llc)
1618 #define HAS_SNOOP(dev_priv)	(INTEL_INFO(dev_priv)->has_snoop)
1619 #define HAS_EDRAM(dev_priv)	((dev_priv)->edram_size_mb)
1620 #define HAS_SECURE_BATCHES(dev_priv) (INTEL_GEN(dev_priv) < 6)
1621 #define HAS_WT(dev_priv)	((IS_HASWELL(dev_priv) || \
1622 				 IS_BROADWELL(dev_priv)) && HAS_EDRAM(dev_priv))
1623 
1624 #define HWS_NEEDS_PHYSICAL(dev_priv)	(INTEL_INFO(dev_priv)->hws_needs_physical)
1625 
1626 #define HAS_LOGICAL_RING_CONTEXTS(dev_priv) \
1627 		(INTEL_INFO(dev_priv)->has_logical_ring_contexts)
1628 #define HAS_LOGICAL_RING_ELSQ(dev_priv) \
1629 		(INTEL_INFO(dev_priv)->has_logical_ring_elsq)
1630 #define HAS_LOGICAL_RING_PREEMPTION(dev_priv) \
1631 		(INTEL_INFO(dev_priv)->has_logical_ring_preemption)
1632 
1633 #define HAS_EXECLISTS(dev_priv) HAS_LOGICAL_RING_CONTEXTS(dev_priv)
1634 
1635 #define INTEL_PPGTT(dev_priv) (INTEL_INFO(dev_priv)->ppgtt_type)
1636 #define HAS_PPGTT(dev_priv) \
1637 	(INTEL_PPGTT(dev_priv) != INTEL_PPGTT_NONE)
1638 #define HAS_FULL_PPGTT(dev_priv) \
1639 	(INTEL_PPGTT(dev_priv) >= INTEL_PPGTT_FULL)
1640 
1641 #define HAS_PAGE_SIZES(dev_priv, sizes) ({ \
1642 	GEM_BUG_ON((sizes) == 0); \
1643 	((sizes) & ~INTEL_INFO(dev_priv)->page_sizes) == 0; \
1644 })
1645 
1646 #define HAS_OVERLAY(dev_priv)		 (INTEL_INFO(dev_priv)->display.has_overlay)
1647 #define OVERLAY_NEEDS_PHYSICAL(dev_priv) \
1648 		(INTEL_INFO(dev_priv)->display.overlay_needs_physical)
1649 
1650 /* Early gen2 have a totally busted CS tlb and require pinned batches. */
1651 #define HAS_BROKEN_CS_TLB(dev_priv)	(IS_I830(dev_priv) || IS_I845G(dev_priv))
1652 
1653 #define NEEDS_RC6_CTX_CORRUPTION_WA(dev_priv)	\
1654 	(IS_BROADWELL(dev_priv) || IS_GEN(dev_priv, 9))
1655 
1656 /* WaRsDisableCoarsePowerGating:skl,cnl */
1657 #define NEEDS_WaRsDisableCoarsePowerGating(dev_priv)			\
1658 	(IS_CANNONLAKE(dev_priv) ||					\
1659 	 IS_SKL_GT3(dev_priv) ||					\
1660 	 IS_SKL_GT4(dev_priv))
1661 
1662 #define HAS_GMBUS_IRQ(dev_priv) (INTEL_GEN(dev_priv) >= 4)
1663 #define HAS_GMBUS_BURST_READ(dev_priv) (INTEL_GEN(dev_priv) >= 10 || \
1664 					IS_GEMINILAKE(dev_priv) || \
1665 					IS_KABYLAKE(dev_priv))
1666 
1667 /* With the 945 and later, Y tiling got adjusted so that it was 32 128-byte
1668  * rows, which changed the alignment requirements and fence programming.
1669  */
1670 #define HAS_128_BYTE_Y_TILING(dev_priv) (!IS_GEN(dev_priv, 2) && \
1671 					 !(IS_I915G(dev_priv) || \
1672 					 IS_I915GM(dev_priv)))
1673 #define SUPPORTS_TV(dev_priv)		(INTEL_INFO(dev_priv)->display.supports_tv)
1674 #define I915_HAS_HOTPLUG(dev_priv)	(INTEL_INFO(dev_priv)->display.has_hotplug)
1675 
1676 #define HAS_FW_BLC(dev_priv) 	(INTEL_GEN(dev_priv) > 2)
1677 #define HAS_FBC(dev_priv)	(INTEL_INFO(dev_priv)->display.has_fbc)
1678 #define HAS_CUR_FBC(dev_priv)	(!HAS_GMCH(dev_priv) && INTEL_GEN(dev_priv) >= 7)
1679 
1680 #define HAS_IPS(dev_priv)	(IS_HSW_ULT(dev_priv) || IS_BROADWELL(dev_priv))
1681 
1682 #define HAS_DP_MST(dev_priv)	(INTEL_INFO(dev_priv)->display.has_dp_mst)
1683 
1684 #define HAS_DDI(dev_priv)		 (INTEL_INFO(dev_priv)->display.has_ddi)
1685 #define HAS_FPGA_DBG_UNCLAIMED(dev_priv) (INTEL_INFO(dev_priv)->has_fpga_dbg)
1686 #define HAS_PSR(dev_priv)		 (INTEL_INFO(dev_priv)->display.has_psr)
1687 #define HAS_TRANSCODER_EDP(dev_priv)	 (INTEL_INFO(dev_priv)->trans_offsets[TRANSCODER_EDP] != 0)
1688 
1689 #define HAS_RC6(dev_priv)		 (INTEL_INFO(dev_priv)->has_rc6)
1690 #define HAS_RC6p(dev_priv)		 (INTEL_INFO(dev_priv)->has_rc6p)
1691 #define HAS_RC6pp(dev_priv)		 (false) /* HW was never validated */
1692 
1693 #define HAS_RPS(dev_priv)	(INTEL_INFO(dev_priv)->has_rps)
1694 
1695 #define HAS_CSR(dev_priv)	(INTEL_INFO(dev_priv)->display.has_csr)
1696 
1697 #define HAS_RUNTIME_PM(dev_priv) (INTEL_INFO(dev_priv)->has_runtime_pm)
1698 #define HAS_64BIT_RELOC(dev_priv) (INTEL_INFO(dev_priv)->has_64bit_reloc)
1699 
1700 #define HAS_IPC(dev_priv)		 (INTEL_INFO(dev_priv)->display.has_ipc)
1701 
1702 #define HAS_REGION(i915, i) (INTEL_INFO(i915)->memory_regions & (i))
1703 #define HAS_LMEM(i915) HAS_REGION(i915, REGION_LMEM)
1704 
1705 #define HAS_GT_UC(dev_priv)	(INTEL_INFO(dev_priv)->has_gt_uc)
1706 
1707 #define HAS_POOLED_EU(dev_priv)	(INTEL_INFO(dev_priv)->has_pooled_eu)
1708 
1709 #define HAS_GLOBAL_MOCS_REGISTERS(dev_priv)	(INTEL_INFO(dev_priv)->has_global_mocs)
1710 
1711 
1712 #define HAS_GMCH(dev_priv) (INTEL_INFO(dev_priv)->display.has_gmch)
1713 
1714 #define HAS_LSPCON(dev_priv) (INTEL_GEN(dev_priv) >= 9)
1715 
1716 /* DPF == dynamic parity feature */
1717 #define HAS_L3_DPF(dev_priv) (INTEL_INFO(dev_priv)->has_l3_dpf)
1718 #define NUM_L3_SLICES(dev_priv) (IS_HSW_GT3(dev_priv) ? \
1719 				 2 : HAS_L3_DPF(dev_priv))
1720 
1721 #define GT_FREQUENCY_MULTIPLIER 50
1722 #define GEN9_FREQ_SCALER 3
1723 
1724 #define INTEL_NUM_PIPES(dev_priv) (hweight8(INTEL_INFO(dev_priv)->pipe_mask))
1725 
1726 #define HAS_DISPLAY(dev_priv) (INTEL_INFO(dev_priv)->pipe_mask != 0)
1727 
1728 /* Only valid when HAS_DISPLAY() is true */
1729 #define INTEL_DISPLAY_ENABLED(dev_priv) (WARN_ON(!HAS_DISPLAY(dev_priv)), !i915_modparams.disable_display)
1730 
1731 static inline bool intel_vtd_active(void)
1732 {
1733 #ifdef CONFIG_INTEL_IOMMU
1734 	if (intel_iommu_gfx_mapped)
1735 		return true;
1736 #endif
1737 	return false;
1738 }
1739 
1740 static inline bool intel_scanout_needs_vtd_wa(struct drm_i915_private *dev_priv)
1741 {
1742 	return INTEL_GEN(dev_priv) >= 6 && intel_vtd_active();
1743 }
1744 
1745 static inline bool
1746 intel_ggtt_update_needs_vtd_wa(struct drm_i915_private *dev_priv)
1747 {
1748 	return IS_BROXTON(dev_priv) && intel_vtd_active();
1749 }
1750 
1751 /* i915_drv.c */
1752 extern const struct dev_pm_ops i915_pm_ops;
1753 
1754 #ifdef __linux__
1755 int i915_driver_probe(struct pci_dev *pdev, const struct pci_device_id *ent);
1756 #endif
1757 void i915_driver_remove(struct drm_i915_private *i915);
1758 
1759 int i915_resume_switcheroo(struct drm_i915_private *i915);
1760 int i915_suspend_switcheroo(struct drm_i915_private *i915, pm_message_t state);
1761 
1762 int i915_getparam_ioctl(struct drm_device *dev, void *data,
1763 			struct drm_file *file_priv);
1764 
1765 /* i915_gem.c */
1766 int i915_gem_init_userptr(struct drm_i915_private *dev_priv);
1767 void i915_gem_cleanup_userptr(struct drm_i915_private *dev_priv);
1768 void i915_gem_init_early(struct drm_i915_private *dev_priv);
1769 void i915_gem_cleanup_early(struct drm_i915_private *dev_priv);
1770 int i915_gem_freeze(struct drm_i915_private *dev_priv);
1771 int i915_gem_freeze_late(struct drm_i915_private *dev_priv);
1772 
1773 struct intel_memory_region *i915_gem_shmem_setup(struct drm_i915_private *i915);
1774 
1775 static inline void i915_gem_drain_freed_objects(struct drm_i915_private *i915)
1776 {
1777 	/*
1778 	 * A single pass should suffice to release all the freed objects (along
1779 	 * most call paths) , but be a little more paranoid in that freeing
1780 	 * the objects does take a little amount of time, during which the rcu
1781 	 * callbacks could have added new objects into the freed list, and
1782 	 * armed the work again.
1783 	 */
1784 	while (atomic_read(&i915->mm.free_count)) {
1785 		flush_work(&i915->mm.free_work);
1786 		rcu_barrier();
1787 	}
1788 }
1789 
1790 static inline void i915_gem_drain_workqueue(struct drm_i915_private *i915)
1791 {
1792 	/*
1793 	 * Similar to objects above (see i915_gem_drain_freed-objects), in
1794 	 * general we have workers that are armed by RCU and then rearm
1795 	 * themselves in their callbacks. To be paranoid, we need to
1796 	 * drain the workqueue a second time after waiting for the RCU
1797 	 * grace period so that we catch work queued via RCU from the first
1798 	 * pass. As neither drain_workqueue() nor flush_workqueue() report
1799 	 * a result, we make an assumption that we only don't require more
1800 	 * than 3 passes to catch all _recursive_ RCU delayed work.
1801 	 *
1802 	 */
1803 	int pass = 3;
1804 	do {
1805 		flush_workqueue(i915->wq);
1806 		rcu_barrier();
1807 		i915_gem_drain_freed_objects(i915);
1808 	} while (--pass);
1809 	drain_workqueue(i915->wq);
1810 }
1811 
1812 struct i915_vma * __must_check
1813 i915_gem_object_ggtt_pin(struct drm_i915_gem_object *obj,
1814 			 const struct i915_ggtt_view *view,
1815 			 u64 size,
1816 			 u64 alignment,
1817 			 u64 flags);
1818 
1819 int i915_gem_object_unbind(struct drm_i915_gem_object *obj,
1820 			   unsigned long flags);
1821 #define I915_GEM_OBJECT_UNBIND_ACTIVE BIT(0)
1822 #define I915_GEM_OBJECT_UNBIND_BARRIER BIT(1)
1823 
1824 void i915_gem_runtime_suspend(struct drm_i915_private *dev_priv);
1825 
1826 int i915_gem_dumb_create(struct drm_file *file_priv,
1827 			 struct drm_device *dev,
1828 			 struct drm_mode_create_dumb *args);
1829 
1830 int __must_check i915_gem_set_global_seqno(struct drm_device *dev, u32 seqno);
1831 
1832 static inline u32 i915_reset_count(struct i915_gpu_error *error)
1833 {
1834 	return atomic_read(&error->reset_count);
1835 }
1836 
1837 static inline u32 i915_reset_engine_count(struct i915_gpu_error *error,
1838 					  const struct intel_engine_cs *engine)
1839 {
1840 	return atomic_read(&error->reset_engine_count[engine->uabi_class]);
1841 }
1842 
1843 int __must_check i915_gem_init(struct drm_i915_private *dev_priv);
1844 void i915_gem_driver_register(struct drm_i915_private *i915);
1845 void i915_gem_driver_unregister(struct drm_i915_private *i915);
1846 void i915_gem_driver_remove(struct drm_i915_private *dev_priv);
1847 void i915_gem_driver_release(struct drm_i915_private *dev_priv);
1848 void i915_gem_suspend(struct drm_i915_private *dev_priv);
1849 void i915_gem_suspend_late(struct drm_i915_private *dev_priv);
1850 void i915_gem_resume(struct drm_i915_private *dev_priv);
1851 
1852 int i915_gem_open(struct drm_i915_private *i915, struct drm_file *file);
1853 void i915_gem_release(struct drm_device *dev, struct drm_file *file);
1854 
1855 int i915_gem_object_set_cache_level(struct drm_i915_gem_object *obj,
1856 				    enum i915_cache_level cache_level);
1857 
1858 struct drm_gem_object *i915_gem_prime_import(struct drm_device *dev,
1859 				struct dma_buf *dma_buf);
1860 
1861 struct dma_buf *i915_gem_prime_export(struct drm_gem_object *gem_obj, int flags);
1862 
1863 static inline struct i915_gem_context *
1864 __i915_gem_context_lookup_rcu(struct drm_i915_file_private *file_priv, u32 id)
1865 {
1866 	return xa_load(&file_priv->context_xa, id);
1867 }
1868 
1869 static inline struct i915_gem_context *
1870 i915_gem_context_lookup(struct drm_i915_file_private *file_priv, u32 id)
1871 {
1872 	struct i915_gem_context *ctx;
1873 
1874 	rcu_read_lock();
1875 	ctx = __i915_gem_context_lookup_rcu(file_priv, id);
1876 	if (ctx && !kref_get_unless_zero(&ctx->ref))
1877 		ctx = NULL;
1878 	rcu_read_unlock();
1879 
1880 	return ctx;
1881 }
1882 
1883 /* i915_gem_evict.c */
1884 int __must_check i915_gem_evict_something(struct i915_address_space *vm,
1885 					  u64 min_size, u64 alignment,
1886 					  unsigned long color,
1887 					  u64 start, u64 end,
1888 					  unsigned flags);
1889 int __must_check i915_gem_evict_for_node(struct i915_address_space *vm,
1890 					 struct drm_mm_node *node,
1891 					 unsigned int flags);
1892 int i915_gem_evict_vm(struct i915_address_space *vm);
1893 
1894 /* i915_gem_internal.c */
1895 struct drm_i915_gem_object *
1896 i915_gem_object_create_internal(struct drm_i915_private *dev_priv,
1897 				phys_addr_t size);
1898 
1899 /* i915_gem_tiling.c */
1900 static inline bool i915_gem_object_needs_bit17_swizzle(struct drm_i915_gem_object *obj)
1901 {
1902 	struct drm_i915_private *i915 = to_i915(obj->base.dev);
1903 
1904 	return i915->ggtt.bit_6_swizzle_x == I915_BIT_6_SWIZZLE_9_10_17 &&
1905 		i915_gem_object_is_tiled(obj);
1906 }
1907 
1908 u32 i915_gem_fence_size(struct drm_i915_private *dev_priv, u32 size,
1909 			unsigned int tiling, unsigned int stride);
1910 u32 i915_gem_fence_alignment(struct drm_i915_private *dev_priv, u32 size,
1911 			     unsigned int tiling, unsigned int stride);
1912 
1913 const char *i915_cache_level_str(struct drm_i915_private *i915, int type);
1914 
1915 int i915_gem_fault(struct drm_gem_object *gem_obj, struct uvm_faultinfo *ufi,
1916 		   off_t offset, vaddr_t vaddr, vm_page_t *pps, int npages,
1917 		   int centeridx, vm_prot_t access_type, int flags);
1918 
1919 /* i915_cmd_parser.c */
1920 int i915_cmd_parser_get_version(struct drm_i915_private *dev_priv);
1921 void intel_engine_init_cmd_parser(struct intel_engine_cs *engine);
1922 void intel_engine_cleanup_cmd_parser(struct intel_engine_cs *engine);
1923 int intel_engine_cmd_parser(struct intel_engine_cs *engine,
1924 			    struct i915_vma *batch,
1925 			    u32 batch_offset,
1926 			    u32 batch_length,
1927 			    struct i915_vma *shadow,
1928 			    bool trampoline);
1929 #define I915_CMD_PARSER_TRAMPOLINE_SIZE 8
1930 
1931 /* intel_device_info.c */
1932 static inline struct intel_device_info *
1933 mkwrite_device_info(struct drm_i915_private *dev_priv)
1934 {
1935 	return (struct intel_device_info *)INTEL_INFO(dev_priv);
1936 }
1937 
1938 int i915_reg_read_ioctl(struct drm_device *dev, void *data,
1939 			struct drm_file *file);
1940 
1941 #define __I915_REG_OP(op__, dev_priv__, ...) \
1942 	intel_uncore_##op__(&(dev_priv__)->uncore, __VA_ARGS__)
1943 
1944 #define I915_READ(reg__)	 __I915_REG_OP(read, dev_priv, (reg__))
1945 #define I915_WRITE(reg__, val__) __I915_REG_OP(write, dev_priv, (reg__), (val__))
1946 
1947 #define POSTING_READ(reg__)	__I915_REG_OP(posting_read, dev_priv, (reg__))
1948 
1949 /* These are untraced mmio-accessors that are only valid to be used inside
1950  * critical sections, such as inside IRQ handlers, where forcewake is explicitly
1951  * controlled.
1952  *
1953  * Think twice, and think again, before using these.
1954  *
1955  * As an example, these accessors can possibly be used between:
1956  *
1957  * spin_lock_irq(&dev_priv->uncore.lock);
1958  * intel_uncore_forcewake_get__locked();
1959  *
1960  * and
1961  *
1962  * intel_uncore_forcewake_put__locked();
1963  * spin_unlock_irq(&dev_priv->uncore.lock);
1964  *
1965  *
1966  * Note: some registers may not need forcewake held, so
1967  * intel_uncore_forcewake_{get,put} can be omitted, see
1968  * intel_uncore_forcewake_for_reg().
1969  *
1970  * Certain architectures will die if the same cacheline is concurrently accessed
1971  * by different clients (e.g. on Ivybridge). Access to registers should
1972  * therefore generally be serialised, by either the dev_priv->uncore.lock or
1973  * a more localised lock guarding all access to that bank of registers.
1974  */
1975 #define I915_READ_FW(reg__) __I915_REG_OP(read_fw, dev_priv, (reg__))
1976 #define I915_WRITE_FW(reg__, val__) __I915_REG_OP(write_fw, dev_priv, (reg__), (val__))
1977 
1978 /* i915_mm.c */
1979 #ifdef notyet
1980 int remap_io_mapping(struct vm_area_struct *vma,
1981 		     unsigned long addr, unsigned long pfn, unsigned long size,
1982 		     struct io_mapping *iomap);
1983 int remap_io_sg(struct vm_area_struct *vma,
1984 		unsigned long addr, unsigned long size,
1985 		struct scatterlist *sgl, resource_size_t iobase);
1986 #endif
1987 
1988 static inline int intel_hws_csb_write_index(struct drm_i915_private *i915)
1989 {
1990 	if (INTEL_GEN(i915) >= 10)
1991 		return CNL_HWS_CSB_WRITE_INDEX;
1992 	else
1993 		return I915_HWS_CSB_WRITE_INDEX;
1994 }
1995 
1996 static inline enum i915_map_type
1997 i915_coherent_map_type(struct drm_i915_private *i915)
1998 {
1999 	return HAS_LLC(i915) ? I915_MAP_WB : I915_MAP_WC;
2000 }
2001 
2002 #endif
2003