i915_drv.h 37.6 KB
Newer Older
L
Linus Torvalds 已提交
1 2
/* i915_drv.h -- Private header for the I915 driver -*- linux-c -*-
 */
D
Dave Airlie 已提交
3
/*
4
 *
L
Linus Torvalds 已提交
5 6
 * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
 * All Rights Reserved.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the
 * "Software"), to deal in the Software without restriction, including
 * without limitation the rights to use, copy, modify, merge, publish,
 * distribute, sub license, and/or sell copies of the Software, and to
 * permit persons to whom the Software is furnished to do so, subject to
 * the following conditions:
 *
 * The above copyright notice and this permission notice (including the
 * next paragraph) shall be included in all copies or substantial portions
 * of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 *
D
Dave Airlie 已提交
28
 */
L
Linus Torvalds 已提交
29 30 31 32

#ifndef _I915_DRV_H_
#define _I915_DRV_H_

33 34
#include <uapi/drm/i915_drm.h>

35
#include <linux/pm_qos.h>
36

37
#include <drm/ttm/ttm_device.h>
38

39
#include "display/intel_display.h"
40
#include "display/intel_display_core.h"
41
#include "display/intel_display_power.h"
42
#include "display/intel_dsb.h"
43 44
#include "display/intel_frontbuffer.h"

45
#include "gem/i915_gem_context_types.h"
46
#include "gem/i915_gem_lmem.h"
47
#include "gem/i915_gem_shrinker.h"
48 49
#include "gem/i915_gem_stolen.h"

50
#include "gt/intel_engine.h"
51
#include "gt/intel_gt_types.h"
52
#include "gt/intel_region_lmem.h"
53
#include "gt/intel_workarounds.h"
54
#include "gt/uc/intel_uc.h"
55

56
#include "i915_drm_client.h"
57 58 59 60 61 62
#include "i915_gem.h"
#include "i915_gpu_error.h"
#include "i915_params.h"
#include "i915_perf_types.h"
#include "i915_scheduler.h"
#include "i915_utils.h"
63
#include "intel_device_info.h"
64
#include "intel_memory_region.h"
65
#include "intel_pch.h"
66
#include "intel_runtime_pm.h"
67
#include "intel_step.h"
68
#include "intel_uncore.h"
69
#include "intel_wopcm.h"
70

71
struct drm_i915_clock_gating_funcs;
72
struct drm_i915_gem_object;
73 74 75 76 77 78 79
struct drm_i915_private;
struct intel_connector;
struct intel_dp;
struct intel_encoder;
struct intel_limit;
struct intel_overlay_error_state;
struct vlv_s0ix_state;
80

81 82
/* Threshold == 5 for long IRQs, 50 for short */
#define HPD_STORM_DEFAULT_THRESHOLD 50
L
Lyude 已提交
83

84 85 86 87 88 89
#define I915_GEM_GPU_DOMAINS \
	(I915_GEM_DOMAIN_RENDER | \
	 I915_GEM_DOMAIN_SAMPLER | \
	 I915_GEM_DOMAIN_COMMAND | \
	 I915_GEM_DOMAIN_INSTRUCTION | \
	 I915_GEM_DOMAIN_VERTEX)
90

91 92
#define I915_COLOR_UNEVICTABLE (-1) /* a non-vma sharing the address space */

93 94
#define GEM_QUIRK_PIN_SWIZZLED_PAGES	BIT(0)

95
#define QUIRK_LVDS_SSC_DISABLE (1<<1)
96
#define QUIRK_INVERT_BRIGHTNESS (1<<2)
97
#define QUIRK_BACKLIGHT_PRESENT (1<<3)
98
#define QUIRK_INCREASE_T12_DELAY (1<<6)
99
#define QUIRK_INCREASE_DDI_DISABLED_TIME (1<<7)
100
#define QUIRK_NO_PPS_BACKLIGHT_POWER_HOOK (1<<8)
101

102
struct i915_suspend_saved_registers {
103
	u32 saveDSPARB;
J
Jesse Barnes 已提交
104 105
	u32 saveSWF0[16];
	u32 saveSWF1[16];
106
	u32 saveSWF3[3];
107
	u16 saveGCDGMBUS;
108
};
109

110
#define MAX_L3_SLICES 2
111
struct intel_l3_parity {
112
	u32 *remap_info[MAX_L3_SLICES];
113
	struct work_struct error_work;
114
	int which_slice;
115 116
};

117
struct i915_gem_mm {
118 119 120 121 122 123 124
	/*
	 * Shortcut for the stolen region. This points to either
	 * INTEL_REGION_STOLEN_SMEM for integrated platforms, or
	 * INTEL_REGION_STOLEN_LMEM for discrete, or NULL if the device doesn't
	 * support stolen.
	 */
	struct intel_memory_region *stolen_region;
125 126
	/** Memory allocator for GTT stolen memory */
	struct drm_mm stolen;
127 128 129 130
	/** Protects the usage of the GTT stolen memory allocator. This is
	 * always the inner lock when overlapping with struct_mutex. */
	struct mutex stolen_lock;

131 132 133
	/* Protects bound_list/unbound_list and #drm_i915_gem_object.mm.link */
	spinlock_t obj_lock;

134
	/**
135
	 * List of objects which are purgeable.
136
	 */
137 138
	struct list_head purge_list;

139
	/**
140
	 * List of objects which have allocated pages and are shrinkable.
141
	 */
142
	struct list_head shrink_list;
143

144 145 146 147
	/**
	 * List of objects which are pending destruction.
	 */
	struct llist_head free_list;
148
	struct work_struct free_work;
149 150 151 152 153
	/**
	 * Count of objects pending destructions. Used to skip needlessly
	 * waiting on an RCU barrier if no objects are waiting to be freed.
	 */
	atomic_t free_count;
154

M
Matthew Auld 已提交
155 156 157 158 159
	/**
	 * tmpfs instance used for shmem backed objects
	 */
	struct vfsmount *gemfs;

160 161
	struct intel_memory_region *regions[INTEL_REGION_UNKNOWN];

162
	struct notifier_block oom_notifier;
163
	struct notifier_block vmap_notifier;
164
	struct shrinker shrinker;
165

166
#ifdef CONFIG_MMU_NOTIFIER
167
	/**
168 169
	 * notifier_lock for mmu notifiers, memory may not be allocated
	 * while holding this lock.
170
	 */
171
	rwlock_t notifier_lock;
172
#endif
173

174 175 176
	/* shrinker accounting, also useful for userland debugging */
	u64 shrink_memory;
	u32 shrink_count;
177 178
};

179 180
#define I915_IDLE_ENGINES_TIMEOUT (200) /* in ms */

181 182 183 184 185 186 187 188 189
unsigned long i915_fence_context_timeout(const struct drm_i915_private *i915,
					 u64 context);

static inline unsigned long
i915_fence_timeout(const struct drm_i915_private *i915)
{
	return i915_fence_context_timeout(i915, U64_MAX);
}

190 191
#define HAS_HW_SAGV_WM(i915) (DISPLAY_VER(i915) >= 13 && !IS_DGFX(i915))

192
struct i915_frontbuffer_tracking {
193
	spinlock_t lock;
194 195 196 197 198 199 200 201 202

	/*
	 * Tracking bits for delayed frontbuffer flushing du to gpu activity or
	 * scheduled flips.
	 */
	unsigned busy_bits;
	unsigned flip_bits;
};

203
struct i915_virtual_gpu {
204
	struct mutex lock; /* serialises sending of g2v_notify command pkts */
205
	bool active;
206
	u32 caps;
207 208
	u32 *initial_mmio;
	u8 *initial_cfg_space;
209
	struct list_head entry;
210 211
};

212 213
struct i915_selftest_stash {
	atomic_t counter;
214
	struct ida mock_region_instances;
215 216
};

217
struct drm_i915_private {
218 219
	struct drm_device drm;

220 221
	struct intel_display display;

222 223 224
	/* FIXME: Device release actions should all be moved to drmm_ */
	bool do_release;

225 226 227
	/* i915 device parameters */
	struct i915_params params;

228
	const struct intel_device_info __info; /* Use INTEL_INFO() to access. */
229
	struct intel_runtime_info __runtime; /* Use RUNTIME_INFO() to access. */
230
	struct intel_driver_caps caps;
231

232 233 234
	/**
	 * Data Stolen Memory - aka "i915 stolen memory" gives us the start and
	 * end of stolen which we can optionally use to create GEM objects
235
	 * backed by stolen memory. Note that stolen_usable_size tells us
236 237 238 239
	 * exactly how much of this we are actually allowed to use, given that
	 * some portion of it is in fact reserved for use by hardware functions.
	 */
	struct resource dsm;
240 241 242 243
	/**
	 * Reseved portion of Data Stolen Memory
	 */
	struct resource dsm_reserved;
244

245 246 247 248 249 250 251 252 253
	/*
	 * Stolen memory is segmented in hardware with different portions
	 * offlimits to certain functions.
	 *
	 * The drm_mm is initialised to the total accessible range, as found
	 * from the PCI config. On Broadwell+, this is further restricted to
	 * avoid the first page! The upper end of stolen memory is reserved for
	 * hardware functions and similarly removed from the accessible range.
	 */
254
	resource_size_t stolen_usable_size;	/* Total size minus reserved ranges */
255

256
	struct intel_uncore uncore;
257
	struct intel_uncore_mmio_debug mmio_debug;
258

259 260
	struct i915_virtual_gpu vgpu;

261
	struct intel_gvt *gvt;
262

263 264
	struct intel_wopcm wopcm;

265
	struct pci_dev *bridge_dev;
266 267

	struct rb_root uabi_engines;
268
	unsigned int engine_uabi_class_count[I915_LAST_UABI_ENGINE_CLASS + 1];
269 270 271 272 273 274

	struct resource mch_res;

	/* protects the irq masks */
	spinlock_t irq_lock;

275 276
	bool display_irqs_enabled;

V
Ville Syrjälä 已提交
277 278
	/* Sideband mailbox protection */
	struct mutex sb_lock;
279
	struct pm_qos_request sb_qos;
280 281

	/** Cached value of IMR to avoid reads in updating the bitfield */
282 283 284 285
	union {
		u32 irq_mask;
		u32 de_irq_mask[I915_MAX_PIPES];
	};
286
	u32 pipestat_irq_mask[I915_MAX_PIPES];
287

288 289
	bool preserve_bios_swizzle;

290
	unsigned int fsb_freq, mem_freq, is_ddr3;
291
	unsigned int skl_preferred_vco_freq;
292

M
Mika Kahola 已提交
293
	unsigned int max_dotclk_freq;
294
	unsigned int hpll_freq;
295
	unsigned int fdi_pll_freq;
296
	unsigned int czclk_freq;
297

298 299 300 301 302 303 304
	struct {
		/* The current hardware dbuf configuration */
		u8 enabled_slices;

		struct intel_global_obj obj;
	} dbuf;

305 306 307 308 309 310 311
	/**
	 * wq - Driver workqueue for GEM.
	 *
	 * NOTE: Work items scheduled here are not allowed to grab any modeset
	 * locks, for otherwise the flushing done in the pageflip code will
	 * result in deadlocks.
	 */
312 313
	struct workqueue_struct *wq;

314 315
	/* ordered wq for modesets */
	struct workqueue_struct *modeset_wq;
316 317
	/* unbound hipri wq for page flips/plane updates */
	struct workqueue_struct *flip_wq;
318

319
	/* pm private clock gating functions */
320
	const struct drm_i915_clock_gating_funcs *clock_gating_funcs;
321

322 323
	/* PCH chipset type */
	enum intel_pch pch_type;
324
	unsigned short pch_id;
325

326
	unsigned long gem_quirks;
327 328
	unsigned long quirks;

329
	struct drm_atomic_state *modeset_restore_state;
330
	struct drm_modeset_acquire_ctx reset_ctx;
331

332
	struct i915_gem_mm mm;
333 334 335

	/* Kernel Modesetting */

336 337
	struct list_head global_obj_list;

338 339
	struct i915_frontbuffer_tracking fb_tracking;

340 341 342 343 344
	struct intel_atomic_helper {
		struct llist_head free_list;
		struct work_struct free_work;
	} atomic_helper;

345
	bool mchbar_need_disable;
346

347 348
	struct intel_l3_parity l3_parity;

M
Matt Roper 已提交
349 350 351 352 353 354 355 356
	/*
	 * HTI (aka HDPORT) state read during initial hw readout.  Most
	 * platforms don't have HTI, so this will just stay 0.  Those that do
	 * will use this later to figure out which PLLs and PHYs are unavailable
	 * for driver usage.
	 */
	u32 hti_state;

357 358 359 360 361
	/*
	 * edram size in MB.
	 * Cannot be determined by PCIID. You must always read a register.
	 */
	u32 edram_size_mb;
B
Ben Widawsky 已提交
362

363
	struct i915_power_domains power_domains;
364

365
	struct i915_gpu_error gpu_error;
366

367
	struct drm_property *broadcast_rgb_property;
368
	struct drm_property *force_audio_property;
369

370
	u32 fdi_rx_config;
371

372
	/* Shadow for DISPLAY_PHY_CONTROL which can't be safely read */
373
	u32 chv_phy_control;
374 375 376 377 378 379
	/*
	 * Shadows for CHV DPLL_MD regs to keep the state
	 * checker somewhat working in the presence hardware
	 * crappiness (can't read out DPLL_MD for pipes B & C).
	 */
	u32 chv_dpll_md[I915_MAX_PIPES];
380
	u32 bxt_phy_grc;
381

382
	u32 suspend_count;
383
	struct i915_suspend_saved_registers regfile;
384
	struct vlv_s0ix_state *vlv_s0ix_state;
385

386
	struct dram_info {
387
		bool wm_lv_0_adjust_needed;
388
		u8 num_channels;
389
		bool symmetric_memory;
V
Ville Syrjälä 已提交
390 391 392 393 394
		enum intel_dram_type {
			INTEL_DRAM_UNKNOWN,
			INTEL_DRAM_DDR3,
			INTEL_DRAM_DDR4,
			INTEL_DRAM_LPDDR3,
395 396 397
			INTEL_DRAM_LPDDR4,
			INTEL_DRAM_DDR5,
			INTEL_DRAM_LPDDR5,
V
Ville Syrjälä 已提交
398
		} type;
399
		u8 num_qgv_points;
400
		u8 num_psf_gv_points;
401 402
	} dram_info;

403
	struct intel_runtime_pm runtime_pm;
404

405
	struct i915_perf perf;
406

407
	/* Abstract the submission mechanism (legacy ringbuffer or execlists) away */
408
	struct intel_gt gt0;
409

410 411 412 413 414 415
	/*
	 * i915->gt[0] == &i915->gt0
	 */
#define I915_MAX_GT 4
	struct intel_gt *gt[I915_MAX_GT];

416 417
	struct kobject *sysfs_gt;

418
	struct {
419 420 421 422
		struct i915_gem_contexts {
			spinlock_t lock; /* locks list */
			struct list_head list;
		} contexts;
423 424 425 426 427 428 429 430 431 432

		/*
		 * We replace the local file with a global mappings as the
		 * backing storage for the mmap is on the device and not
		 * on the struct file, and we do not want to prolong the
		 * lifetime of the local fd. To minimise the number of
		 * anonymous inodes we create, we use a global singleton to
		 * share the global mapping.
		 */
		struct file *mmap_singleton;
433
	} gem;
434

435 436
	u8 pch_ssc_use;

437 438
	/* For i915gm/i945gm vblank irq workaround */
	u8 vblank_enabled;
439

440 441
	bool irq_enabled;

442 443 444 445 446 447 448 449 450 451
	union {
		/* perform PHY state sanity checks? */
		bool chv_phy_assert[2];

		/*
		 * DG2: Mask of PHYs that were not calibrated by the firmware
		 * and should not be used.
		 */
		u8 snps_phy_failed_calibration;
	};
452

M
Mahesh Kumar 已提交
453 454
	bool ipc_enabled;

455 456
	struct i915_pmu pmu;

457 458
	struct i915_drm_clients clients;

459 460 461
	/* The TTM device structure. */
	struct ttm_device bdev;

462 463
	I915_SELFTEST_DECLARE(struct i915_selftest_stash selftest;)

464 465 466 467
	/*
	 * NOTE: This is the dri1/ums dungeon, don't add stuff here. Your patch
	 * will be rejected. Instead look for a better place.
	 */
468
};
L
Linus Torvalds 已提交
469

470 471
static inline struct drm_i915_private *to_i915(const struct drm_device *dev)
{
472
	return container_of(dev, struct drm_i915_private, drm);
473 474
}

475
static inline struct drm_i915_private *kdev_to_i915(struct device *kdev)
I
Imre Deak 已提交
476
{
477 478 479 480 481 482
	return dev_get_drvdata(kdev);
}

static inline struct drm_i915_private *pdev_to_i915(struct pci_dev *pdev)
{
	return pci_get_drvdata(pdev);
I
Imre Deak 已提交
483 484
}

485 486
static inline struct intel_gt *to_gt(struct drm_i915_private *i915)
{
487
	return &i915->gt0;
488 489
}

490
/* Simple iterator over all initialised engines */
491 492 493 494 495
#define for_each_engine(engine__, dev_priv__, id__) \
	for ((id__) = 0; \
	     (id__) < I915_NUM_ENGINES; \
	     (id__)++) \
		for_each_if ((engine__) = (dev_priv__)->engine[(id__)])
496 497

/* Iterator over subset of engines selected by mask */
498
#define for_each_engine_masked(engine__, gt__, mask__, tmp__) \
499
	for ((tmp__) = (mask__) & (gt__)->info.engine_mask; \
500
	     (tmp__) ? \
501
	     ((engine__) = (gt__)->engine[__mask_next_bit(tmp__)]), 1 : \
502
	     0;)
503

504 505 506 507 508 509 510 511
#define rb_to_uabi_engine(rb) \
	rb_entry_safe(rb, struct intel_engine_cs, uabi_node)

#define for_each_uabi_engine(engine__, i915__) \
	for ((engine__) = rb_to_uabi_engine(rb_first(&(i915__)->uabi_engines));\
	     (engine__); \
	     (engine__) = rb_to_uabi_engine(rb_next(&(engine__)->uabi_node)))

512 513 514 515 516
#define for_each_uabi_class_engine(engine__, class__, i915__) \
	for ((engine__) = intel_engine_lookup_user((i915__), (class__), 0); \
	     (engine__) && (engine__)->uabi_class == (class__); \
	     (engine__) = rb_to_uabi_engine(rb_next(&(engine__)->uabi_node)))

517
#define I915_GTT_OFFSET_NONE ((u32)-1)
518

519
#define INTEL_INFO(dev_priv)	(&(dev_priv)->__info)
520
#define RUNTIME_INFO(dev_priv)	(&(dev_priv)->__runtime)
521
#define DRIVER_CAPS(dev_priv)	(&(dev_priv)->caps)
522

523
#define INTEL_DEVID(dev_priv)	(RUNTIME_INFO(dev_priv)->device_id)
524

525
#define IP_VER(ver, rel)		((ver) << 8 | (rel))
526

527 528 529
#define GRAPHICS_VER(i915)		(RUNTIME_INFO(i915)->graphics.ver)
#define GRAPHICS_VER_FULL(i915)		IP_VER(RUNTIME_INFO(i915)->graphics.ver, \
					       RUNTIME_INFO(i915)->graphics.rel)
530 531 532
#define IS_GRAPHICS_VER(i915, from, until) \
	(GRAPHICS_VER(i915) >= (from) && GRAPHICS_VER(i915) <= (until))

533
#define MEDIA_VER(i915)			(INTEL_INFO(i915)->media.ver)
534
#define MEDIA_VER_FULL(i915)		IP_VER(INTEL_INFO(i915)->media.ver, \
535
					       INTEL_INFO(i915)->media.rel)
536 537 538
#define IS_MEDIA_VER(i915, from, until) \
	(MEDIA_VER(i915) >= (from) && MEDIA_VER(i915) <= (until))

539
#define DISPLAY_VER(i915)	(INTEL_INFO(i915)->display.ver)
540
#define IS_DISPLAY_VER(i915, from, until) \
541 542
	(DISPLAY_VER(i915) >= (from) && DISPLAY_VER(i915) <= (until))

543
#define INTEL_REVID(dev_priv)	(to_pci_dev((dev_priv)->drm.dev)->revision)
544

545 546
#define HAS_DSB(dev_priv)	(INTEL_INFO(dev_priv)->display.has_dsb)

547
#define INTEL_DISPLAY_STEP(__i915) (RUNTIME_INFO(__i915)->step.display_step)
548
#define INTEL_GRAPHICS_STEP(__i915) (RUNTIME_INFO(__i915)->step.graphics_step)
549
#define INTEL_MEDIA_STEP(__i915) (RUNTIME_INFO(__i915)->step.media_step)
550
#define INTEL_BASEDIE_STEP(__i915) (RUNTIME_INFO(__i915)->step.basedie_step)
551 552 553

#define IS_DISPLAY_STEP(__i915, since, until) \
	(drm_WARN_ON(&(__i915)->drm, INTEL_DISPLAY_STEP(__i915) == STEP_NONE), \
554
	 INTEL_DISPLAY_STEP(__i915) >= (since) && INTEL_DISPLAY_STEP(__i915) < (until))
555

556 557 558
#define IS_GRAPHICS_STEP(__i915, since, until) \
	(drm_WARN_ON(&(__i915)->drm, INTEL_GRAPHICS_STEP(__i915) == STEP_NONE), \
	 INTEL_GRAPHICS_STEP(__i915) >= (since) && INTEL_GRAPHICS_STEP(__i915) < (until))
559

560 561 562 563
#define IS_MEDIA_STEP(__i915, since, until) \
	(drm_WARN_ON(&(__i915)->drm, INTEL_MEDIA_STEP(__i915) == STEP_NONE), \
	 INTEL_MEDIA_STEP(__i915) >= (since) && INTEL_MEDIA_STEP(__i915) < (until))

564 565 566 567
#define IS_BASEDIE_STEP(__i915, since, until) \
	(drm_WARN_ON(&(__i915)->drm, INTEL_BASEDIE_STEP(__i915) == STEP_NONE), \
	 INTEL_BASEDIE_STEP(__i915) >= (since) && INTEL_BASEDIE_STEP(__i915) < (until))

568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596
static __always_inline unsigned int
__platform_mask_index(const struct intel_runtime_info *info,
		      enum intel_platform p)
{
	const unsigned int pbits =
		BITS_PER_TYPE(info->platform_mask[0]) - INTEL_SUBPLATFORM_BITS;

	/* Expand the platform_mask array if this fails. */
	BUILD_BUG_ON(INTEL_MAX_PLATFORMS >
		     pbits * ARRAY_SIZE(info->platform_mask));

	return p / pbits;
}

static __always_inline unsigned int
__platform_mask_bit(const struct intel_runtime_info *info,
		    enum intel_platform p)
{
	const unsigned int pbits =
		BITS_PER_TYPE(info->platform_mask[0]) - INTEL_SUBPLATFORM_BITS;

	return p % pbits + INTEL_SUBPLATFORM_BITS;
}

static inline u32
intel_subplatform(const struct intel_runtime_info *info, enum intel_platform p)
{
	const unsigned int pi = __platform_mask_index(info, p);

597
	return info->platform_mask[pi] & INTEL_SUBPLATFORM_MASK;
598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628
}

static __always_inline bool
IS_PLATFORM(const struct drm_i915_private *i915, enum intel_platform p)
{
	const struct intel_runtime_info *info = RUNTIME_INFO(i915);
	const unsigned int pi = __platform_mask_index(info, p);
	const unsigned int pb = __platform_mask_bit(info, p);

	BUILD_BUG_ON(!__builtin_constant_p(p));

	return info->platform_mask[pi] & BIT(pb);
}

static __always_inline bool
IS_SUBPLATFORM(const struct drm_i915_private *i915,
	       enum intel_platform p, unsigned int s)
{
	const struct intel_runtime_info *info = RUNTIME_INFO(i915);
	const unsigned int pi = __platform_mask_index(info, p);
	const unsigned int pb = __platform_mask_bit(info, p);
	const unsigned int msb = BITS_PER_TYPE(info->platform_mask[0]) - 1;
	const u32 mask = info->platform_mask[pi];

	BUILD_BUG_ON(!__builtin_constant_p(p));
	BUILD_BUG_ON(!__builtin_constant_p(s));
	BUILD_BUG_ON((s) >= INTEL_SUBPLATFORM_BITS);

	/* Shift and test on the MSB position so sign flag can be used. */
	return ((mask << (msb - pb)) & (mask << (msb - s))) & BIT(msb);
}
T
Tvrtko Ursulin 已提交
629

630
#define IS_MOBILE(dev_priv)	(INTEL_INFO(dev_priv)->is_mobile)
631
#define IS_DGFX(dev_priv)   (INTEL_INFO(dev_priv)->is_dgfx)
632

T
Tvrtko Ursulin 已提交
633 634 635 636 637 638 639 640 641 642 643 644
#define IS_I830(dev_priv)	IS_PLATFORM(dev_priv, INTEL_I830)
#define IS_I845G(dev_priv)	IS_PLATFORM(dev_priv, INTEL_I845G)
#define IS_I85X(dev_priv)	IS_PLATFORM(dev_priv, INTEL_I85X)
#define IS_I865G(dev_priv)	IS_PLATFORM(dev_priv, INTEL_I865G)
#define IS_I915G(dev_priv)	IS_PLATFORM(dev_priv, INTEL_I915G)
#define IS_I915GM(dev_priv)	IS_PLATFORM(dev_priv, INTEL_I915GM)
#define IS_I945G(dev_priv)	IS_PLATFORM(dev_priv, INTEL_I945G)
#define IS_I945GM(dev_priv)	IS_PLATFORM(dev_priv, INTEL_I945GM)
#define IS_I965G(dev_priv)	IS_PLATFORM(dev_priv, INTEL_I965G)
#define IS_I965GM(dev_priv)	IS_PLATFORM(dev_priv, INTEL_I965GM)
#define IS_G45(dev_priv)	IS_PLATFORM(dev_priv, INTEL_G45)
#define IS_GM45(dev_priv)	IS_PLATFORM(dev_priv, INTEL_GM45)
645
#define IS_G4X(dev_priv)	(IS_G45(dev_priv) || IS_GM45(dev_priv))
T
Tvrtko Ursulin 已提交
646 647
#define IS_PINEVIEW(dev_priv)	IS_PLATFORM(dev_priv, INTEL_PINEVIEW)
#define IS_G33(dev_priv)	IS_PLATFORM(dev_priv, INTEL_G33)
648 649 650
#define IS_IRONLAKE(dev_priv)	IS_PLATFORM(dev_priv, INTEL_IRONLAKE)
#define IS_IRONLAKE_M(dev_priv) \
	(IS_PLATFORM(dev_priv, INTEL_IRONLAKE) && IS_MOBILE(dev_priv))
651
#define IS_SANDYBRIDGE(dev_priv) IS_PLATFORM(dev_priv, INTEL_SANDYBRIDGE)
T
Tvrtko Ursulin 已提交
652
#define IS_IVYBRIDGE(dev_priv)	IS_PLATFORM(dev_priv, INTEL_IVYBRIDGE)
653
#define IS_IVB_GT1(dev_priv)	(IS_IVYBRIDGE(dev_priv) && \
654
				 INTEL_INFO(dev_priv)->gt == 1)
T
Tvrtko Ursulin 已提交
655 656 657 658 659 660 661 662 663
#define IS_VALLEYVIEW(dev_priv)	IS_PLATFORM(dev_priv, INTEL_VALLEYVIEW)
#define IS_CHERRYVIEW(dev_priv)	IS_PLATFORM(dev_priv, INTEL_CHERRYVIEW)
#define IS_HASWELL(dev_priv)	IS_PLATFORM(dev_priv, INTEL_HASWELL)
#define IS_BROADWELL(dev_priv)	IS_PLATFORM(dev_priv, INTEL_BROADWELL)
#define IS_SKYLAKE(dev_priv)	IS_PLATFORM(dev_priv, INTEL_SKYLAKE)
#define IS_BROXTON(dev_priv)	IS_PLATFORM(dev_priv, INTEL_BROXTON)
#define IS_KABYLAKE(dev_priv)	IS_PLATFORM(dev_priv, INTEL_KABYLAKE)
#define IS_GEMINILAKE(dev_priv)	IS_PLATFORM(dev_priv, INTEL_GEMINILAKE)
#define IS_COFFEELAKE(dev_priv)	IS_PLATFORM(dev_priv, INTEL_COFFEELAKE)
664
#define IS_COMETLAKE(dev_priv)	IS_PLATFORM(dev_priv, INTEL_COMETLAKE)
665
#define IS_ICELAKE(dev_priv)	IS_PLATFORM(dev_priv, INTEL_ICELAKE)
666 667
#define IS_JSL_EHL(dev_priv)	(IS_PLATFORM(dev_priv, INTEL_JASPERLAKE) || \
				IS_PLATFORM(dev_priv, INTEL_ELKHARTLAKE))
668
#define IS_TIGERLAKE(dev_priv)	IS_PLATFORM(dev_priv, INTEL_TIGERLAKE)
669
#define IS_ROCKETLAKE(dev_priv)	IS_PLATFORM(dev_priv, INTEL_ROCKETLAKE)
670
#define IS_DG1(dev_priv)        IS_PLATFORM(dev_priv, INTEL_DG1)
671
#define IS_ALDERLAKE_S(dev_priv) IS_PLATFORM(dev_priv, INTEL_ALDERLAKE_S)
672
#define IS_ALDERLAKE_P(dev_priv) IS_PLATFORM(dev_priv, INTEL_ALDERLAKE_P)
673
#define IS_XEHPSDV(dev_priv) IS_PLATFORM(dev_priv, INTEL_XEHPSDV)
M
Matt Roper 已提交
674
#define IS_DG2(dev_priv)	IS_PLATFORM(dev_priv, INTEL_DG2)
675
#define IS_PONTEVECCHIO(dev_priv) IS_PLATFORM(dev_priv, INTEL_PONTEVECCHIO)
676
#define IS_METEORLAKE(dev_priv) IS_PLATFORM(dev_priv, INTEL_METEORLAKE)
677

678 679 680 681
#define IS_METEORLAKE_M(dev_priv) \
	IS_SUBPLATFORM(dev_priv, INTEL_METEORLAKE, INTEL_SUBPLATFORM_M)
#define IS_METEORLAKE_P(dev_priv) \
	IS_SUBPLATFORM(dev_priv, INTEL_METEORLAKE, INTEL_SUBPLATFORM_P)
M
Matt Roper 已提交
682 683 684 685
#define IS_DG2_G10(dev_priv) \
	IS_SUBPLATFORM(dev_priv, INTEL_DG2, INTEL_SUBPLATFORM_G10)
#define IS_DG2_G11(dev_priv) \
	IS_SUBPLATFORM(dev_priv, INTEL_DG2, INTEL_SUBPLATFORM_G11)
686 687
#define IS_DG2_G12(dev_priv) \
	IS_SUBPLATFORM(dev_priv, INTEL_DG2, INTEL_SUBPLATFORM_G12)
688
#define IS_ADLS_RPLS(dev_priv) \
M
Matt Atwood 已提交
689
	IS_SUBPLATFORM(dev_priv, INTEL_ALDERLAKE_S, INTEL_SUBPLATFORM_RPL)
690 691
#define IS_ADLP_N(dev_priv) \
	IS_SUBPLATFORM(dev_priv, INTEL_ALDERLAKE_P, INTEL_SUBPLATFORM_N)
M
Matt Atwood 已提交
692 693
#define IS_ADLP_RPLP(dev_priv) \
	IS_SUBPLATFORM(dev_priv, INTEL_ALDERLAKE_P, INTEL_SUBPLATFORM_RPL)
694 695
#define IS_HSW_EARLY_SDV(dev_priv) (IS_HASWELL(dev_priv) && \
				    (INTEL_DEVID(dev_priv) & 0xFF00) == 0x0C00)
696 697 698 699
#define IS_BDW_ULT(dev_priv) \
	IS_SUBPLATFORM(dev_priv, INTEL_BROADWELL, INTEL_SUBPLATFORM_ULT)
#define IS_BDW_ULX(dev_priv) \
	IS_SUBPLATFORM(dev_priv, INTEL_BROADWELL, INTEL_SUBPLATFORM_ULX)
700
#define IS_BDW_GT3(dev_priv)	(IS_BROADWELL(dev_priv) && \
701
				 INTEL_INFO(dev_priv)->gt == 3)
702 703
#define IS_HSW_ULT(dev_priv) \
	IS_SUBPLATFORM(dev_priv, INTEL_HASWELL, INTEL_SUBPLATFORM_ULT)
704
#define IS_HSW_GT3(dev_priv)	(IS_HASWELL(dev_priv) && \
705
				 INTEL_INFO(dev_priv)->gt == 3)
706
#define IS_HSW_GT1(dev_priv)	(IS_HASWELL(dev_priv) && \
707
				 INTEL_INFO(dev_priv)->gt == 1)
708
/* ULX machines are also considered ULT. */
709 710 711 712 713 714 715 716 717 718
#define IS_HSW_ULX(dev_priv) \
	IS_SUBPLATFORM(dev_priv, INTEL_HASWELL, INTEL_SUBPLATFORM_ULX)
#define IS_SKL_ULT(dev_priv) \
	IS_SUBPLATFORM(dev_priv, INTEL_SKYLAKE, INTEL_SUBPLATFORM_ULT)
#define IS_SKL_ULX(dev_priv) \
	IS_SUBPLATFORM(dev_priv, INTEL_SKYLAKE, INTEL_SUBPLATFORM_ULX)
#define IS_KBL_ULT(dev_priv) \
	IS_SUBPLATFORM(dev_priv, INTEL_KABYLAKE, INTEL_SUBPLATFORM_ULT)
#define IS_KBL_ULX(dev_priv) \
	IS_SUBPLATFORM(dev_priv, INTEL_KABYLAKE, INTEL_SUBPLATFORM_ULX)
719
#define IS_SKL_GT2(dev_priv)	(IS_SKYLAKE(dev_priv) && \
720
				 INTEL_INFO(dev_priv)->gt == 2)
721
#define IS_SKL_GT3(dev_priv)	(IS_SKYLAKE(dev_priv) && \
722
				 INTEL_INFO(dev_priv)->gt == 3)
723
#define IS_SKL_GT4(dev_priv)	(IS_SKYLAKE(dev_priv) && \
724
				 INTEL_INFO(dev_priv)->gt == 4)
725
#define IS_KBL_GT2(dev_priv)	(IS_KABYLAKE(dev_priv) && \
726
				 INTEL_INFO(dev_priv)->gt == 2)
727
#define IS_KBL_GT3(dev_priv)	(IS_KABYLAKE(dev_priv) && \
728
				 INTEL_INFO(dev_priv)->gt == 3)
729 730
#define IS_CFL_ULT(dev_priv) \
	IS_SUBPLATFORM(dev_priv, INTEL_COFFEELAKE, INTEL_SUBPLATFORM_ULT)
731 732
#define IS_CFL_ULX(dev_priv) \
	IS_SUBPLATFORM(dev_priv, INTEL_COFFEELAKE, INTEL_SUBPLATFORM_ULX)
733
#define IS_CFL_GT2(dev_priv)	(IS_COFFEELAKE(dev_priv) && \
734
				 INTEL_INFO(dev_priv)->gt == 2)
735
#define IS_CFL_GT3(dev_priv)	(IS_COFFEELAKE(dev_priv) && \
736
				 INTEL_INFO(dev_priv)->gt == 3)
737 738 739 740 741 742 743 744

#define IS_CML_ULT(dev_priv) \
	IS_SUBPLATFORM(dev_priv, INTEL_COMETLAKE, INTEL_SUBPLATFORM_ULT)
#define IS_CML_ULX(dev_priv) \
	IS_SUBPLATFORM(dev_priv, INTEL_COMETLAKE, INTEL_SUBPLATFORM_ULX)
#define IS_CML_GT2(dev_priv)	(IS_COMETLAKE(dev_priv) && \
				 INTEL_INFO(dev_priv)->gt == 2)

745 746
#define IS_ICL_WITH_PORT_F(dev_priv) \
	IS_SUBPLATFORM(dev_priv, INTEL_ICELAKE, INTEL_SUBPLATFORM_PORTF)
747

748 749
#define IS_TGL_UY(dev_priv) \
	IS_SUBPLATFORM(dev_priv, INTEL_TIGERLAKE, INTEL_SUBPLATFORM_UY)
750

751
#define IS_SKL_GRAPHICS_STEP(p, since, until) (IS_SKYLAKE(p) && IS_GRAPHICS_STEP(p, since, until))
752

753 754
#define IS_KBL_GRAPHICS_STEP(dev_priv, since, until) \
	(IS_KABYLAKE(dev_priv) && IS_GRAPHICS_STEP(dev_priv, since, until))
755 756
#define IS_KBL_DISPLAY_STEP(dev_priv, since, until) \
	(IS_KABYLAKE(dev_priv) && IS_DISPLAY_STEP(dev_priv, since, until))
M
Mika Kuoppala 已提交
757

758 759
#define IS_JSL_EHL_GRAPHICS_STEP(p, since, until) \
	(IS_JSL_EHL(p) && IS_GRAPHICS_STEP(p, since, until))
760 761
#define IS_JSL_EHL_DISPLAY_STEP(p, since, until) \
	(IS_JSL_EHL(p) && IS_DISPLAY_STEP(p, since, until))
762

763
#define IS_TGL_DISPLAY_STEP(__i915, since, until) \
764 765
	(IS_TIGERLAKE(__i915) && \
	 IS_DISPLAY_STEP(__i915, since, until))
766

767
#define IS_TGL_UY_GRAPHICS_STEP(__i915, since, until) \
768
	(IS_TGL_UY(__i915) && \
769
	 IS_GRAPHICS_STEP(__i915, since, until))
770

771
#define IS_TGL_GRAPHICS_STEP(__i915, since, until) \
772
	(IS_TIGERLAKE(__i915) && !IS_TGL_UY(__i915)) && \
773
	 IS_GRAPHICS_STEP(__i915, since, until))
M
Mika Kuoppala 已提交
774

775 776
#define IS_RKL_DISPLAY_STEP(p, since, until) \
	(IS_ROCKETLAKE(p) && IS_DISPLAY_STEP(p, since, until))
777

778 779
#define IS_DG1_GRAPHICS_STEP(p, since, until) \
	(IS_DG1(p) && IS_GRAPHICS_STEP(p, since, until))
780 781
#define IS_DG1_DISPLAY_STEP(p, since, until) \
	(IS_DG1(p) && IS_DISPLAY_STEP(p, since, until))
782

783
#define IS_ADLS_DISPLAY_STEP(__i915, since, until) \
784 785
	(IS_ALDERLAKE_S(__i915) && \
	 IS_DISPLAY_STEP(__i915, since, until))
786

787
#define IS_ADLS_GRAPHICS_STEP(__i915, since, until) \
788
	(IS_ALDERLAKE_S(__i915) && \
789
	 IS_GRAPHICS_STEP(__i915, since, until))
790

791 792 793 794
#define IS_ADLP_DISPLAY_STEP(__i915, since, until) \
	(IS_ALDERLAKE_P(__i915) && \
	 IS_DISPLAY_STEP(__i915, since, until))

795
#define IS_ADLP_GRAPHICS_STEP(__i915, since, until) \
796
	(IS_ALDERLAKE_P(__i915) && \
797
	 IS_GRAPHICS_STEP(__i915, since, until))
798

799 800
#define IS_XEHPSDV_GRAPHICS_STEP(__i915, since, until) \
	(IS_XEHPSDV(__i915) && IS_GRAPHICS_STEP(__i915, since, until))
801

M
Matt Roper 已提交
802
/*
803 804 805 806 807 808 809 810
 * DG2 hardware steppings are a bit unusual.  The hardware design was forked to
 * create three variants (G10, G11, and G12) which each have distinct
 * workaround sets.  The G11 and G12 forks of the DG2 design reset the GT
 * stepping back to "A0" for their first iterations, even though they're more
 * similar to a G10 B0 stepping and G10 C0 stepping respectively in terms of
 * functionality and workarounds.  However the display stepping does not reset
 * in the same manner --- a specific stepping like "B0" has a consistent
 * meaning regardless of whether it belongs to a G10, G11, or G12 DG2.
M
Matt Roper 已提交
811 812
 *
 * TLDR:  All GT workarounds and stepping-specific logic must be applied in
813
 * relation to a specific subplatform (G10/G11/G12), whereas display workarounds
M
Matt Roper 已提交
814 815 816
 * and stepping-specific logic will be applied with a general DG2-wide stepping
 * number.
 */
817
#define IS_DG2_GRAPHICS_STEP(__i915, variant, since, until) \
M
Matt Roper 已提交
818
	(IS_SUBPLATFORM(__i915, INTEL_DG2, INTEL_SUBPLATFORM_##variant) && \
819
	 IS_GRAPHICS_STEP(__i915, since, until))
M
Matt Roper 已提交
820

821
#define IS_DG2_DISPLAY_STEP(__i915, since, until) \
M
Matt Roper 已提交
822 823 824
	(IS_DG2(__i915) && \
	 IS_DISPLAY_STEP(__i915, since, until))

825 826 827 828 829 830 831 832
#define IS_PVC_BD_STEP(__i915, since, until) \
	(IS_PONTEVECCHIO(__i915) && \
	 IS_BASEDIE_STEP(__i915, since, until))

#define IS_PVC_CT_STEP(__i915, since, until) \
	(IS_PONTEVECCHIO(__i915) && \
	 IS_GRAPHICS_STEP(__i915, since, until))

833 834 835
#define IS_LP(dev_priv)		(INTEL_INFO(dev_priv)->is_lp)
#define IS_GEN9_LP(dev_priv)	(GRAPHICS_VER(dev_priv) == 9 && IS_LP(dev_priv))
#define IS_GEN9_BC(dev_priv)	(GRAPHICS_VER(dev_priv) == 9 && !IS_LP(dev_priv))
836

837
#define __HAS_ENGINE(engine_mask, id) ((engine_mask) & BIT(id))
838
#define HAS_ENGINE(gt, id) __HAS_ENGINE((gt)->info.engine_mask, id)
839

840
#define ENGINE_INSTANCES_MASK(gt, first, count) ({		\
841 842
	unsigned int first__ = (first);					\
	unsigned int count__ = (count);					\
843
	((gt)->info.engine_mask &						\
844
	 GENMASK(first__ + count__ - 1, first__)) >> first__;		\
845
})
846 847
#define RCS_MASK(gt) \
	ENGINE_INSTANCES_MASK(gt, RCS0, I915_MAX_RCS)
848 849
#define BCS_MASK(gt) \
	ENGINE_INSTANCES_MASK(gt, BCS0, I915_MAX_BCS)
850 851 852 853
#define VDBOX_MASK(gt) \
	ENGINE_INSTANCES_MASK(gt, VCS0, I915_MAX_VCS)
#define VEBOX_MASK(gt) \
	ENGINE_INSTANCES_MASK(gt, VECS0, I915_MAX_VECS)
854 855
#define CCS_MASK(gt) \
	ENGINE_INSTANCES_MASK(gt, CCS0, I915_MAX_CCS)
856

857 858
#define HAS_MEDIA_RATIO_MODE(dev_priv) (INTEL_INFO(dev_priv)->has_media_ratio_mode)

859 860 861 862
/*
 * The Gen7 cmdparser copies the scanned buffer to the ggtt for execution
 * All later gens can run the final buffer from the ppgtt
 */
863
#define CMDPARSER_USES_GGTT(dev_priv) (GRAPHICS_VER(dev_priv) == 7)
864

865
#define HAS_LLC(dev_priv)	(INTEL_INFO(dev_priv)->has_llc)
866
#define HAS_4TILE(dev_priv)	(INTEL_INFO(dev_priv)->has_4tile)
867
#define HAS_SNOOP(dev_priv)	(INTEL_INFO(dev_priv)->has_snoop)
868
#define HAS_EDRAM(dev_priv)	((dev_priv)->edram_size_mb)
869
#define HAS_SECURE_BATCHES(dev_priv) (GRAPHICS_VER(dev_priv) < 6)
870
#define HAS_WT(dev_priv)	HAS_EDRAM(dev_priv)
871

872
#define HWS_NEEDS_PHYSICAL(dev_priv)	(INTEL_INFO(dev_priv)->hws_needs_physical)
873

874
#define HAS_LOGICAL_RING_CONTEXTS(dev_priv) \
875
		(INTEL_INFO(dev_priv)->has_logical_ring_contexts)
876
#define HAS_LOGICAL_RING_ELSQ(dev_priv) \
877
		(INTEL_INFO(dev_priv)->has_logical_ring_elsq)
878 879 880

#define HAS_EXECLISTS(dev_priv) HAS_LOGICAL_RING_CONTEXTS(dev_priv)

881
#define INTEL_PPGTT(dev_priv) (RUNTIME_INFO(dev_priv)->ppgtt_type)
882 883 884 885 886
#define HAS_PPGTT(dev_priv) \
	(INTEL_PPGTT(dev_priv) != INTEL_PPGTT_NONE)
#define HAS_FULL_PPGTT(dev_priv) \
	(INTEL_PPGTT(dev_priv) >= INTEL_PPGTT_FULL)

887 888
#define HAS_PAGE_SIZES(dev_priv, sizes) ({ \
	GEM_BUG_ON((sizes) == 0); \
889
	((sizes) & ~RUNTIME_INFO(dev_priv)->page_sizes) == 0; \
890
})
891

892
#define HAS_OVERLAY(dev_priv)		 (INTEL_INFO(dev_priv)->display.has_overlay)
893
#define OVERLAY_NEEDS_PHYSICAL(dev_priv) \
894
		(INTEL_INFO(dev_priv)->display.overlay_needs_physical)
895

896
/* Early gen2 have a totally busted CS tlb and require pinned batches. */
897
#define HAS_BROKEN_CS_TLB(dev_priv)	(IS_I830(dev_priv) || IS_I845G(dev_priv))
898

899
#define NEEDS_RC6_CTX_CORRUPTION_WA(dev_priv)	\
900
	(IS_BROADWELL(dev_priv) || GRAPHICS_VER(dev_priv) == 9)
901

902
/* WaRsDisableCoarsePowerGating:skl,cnl */
903
#define NEEDS_WaRsDisableCoarsePowerGating(dev_priv)			\
904
	(IS_SKL_GT3(dev_priv) || IS_SKL_GT4(dev_priv))
905

906 907
#define HAS_GMBUS_IRQ(dev_priv) (DISPLAY_VER(dev_priv) >= 4)
#define HAS_GMBUS_BURST_READ(dev_priv) (DISPLAY_VER(dev_priv) >= 11 || \
R
Ramalingam C 已提交
908 909
					IS_GEMINILAKE(dev_priv) || \
					IS_KABYLAKE(dev_priv))
910

911 912 913
/* With the 945 and later, Y tiling got adjusted so that it was 32 128-byte
 * rows, which changed the alignment requirements and fence programming.
 */
914 915
#define HAS_128_BYTE_Y_TILING(dev_priv) (GRAPHICS_VER(dev_priv) != 2 && \
					 !(IS_I915G(dev_priv) || IS_I915GM(dev_priv)))
916 917
#define SUPPORTS_TV(dev_priv)		(INTEL_INFO(dev_priv)->display.supports_tv)
#define I915_HAS_HOTPLUG(dev_priv)	(INTEL_INFO(dev_priv)->display.has_hotplug)
918

919
#define HAS_FW_BLC(dev_priv)	(DISPLAY_VER(dev_priv) > 2)
920
#define HAS_FBC(dev_priv)	(RUNTIME_INFO(dev_priv)->fbc_mask != 0)
921
#define HAS_CUR_FBC(dev_priv)	(!HAS_GMCH(dev_priv) && DISPLAY_VER(dev_priv) >= 7)
922

923
#define HAS_IPS(dev_priv)	(IS_HSW_ULT(dev_priv) || IS_BROADWELL(dev_priv))
924

925
#define HAS_DP_MST(dev_priv)	(INTEL_INFO(dev_priv)->display.has_dp_mst)
926
#define HAS_DP20(dev_priv)	(IS_DG2(dev_priv) || DISPLAY_VER(dev_priv) >= 14)
927

928
#define HAS_CDCLK_CRAWL(dev_priv)	 (INTEL_INFO(dev_priv)->display.has_cdclk_crawl)
929
#define HAS_DDI(dev_priv)		 (INTEL_INFO(dev_priv)->display.has_ddi)
930
#define HAS_FPGA_DBG_UNCLAIMED(dev_priv) (INTEL_INFO(dev_priv)->display.has_fpga_dbg)
931
#define HAS_PSR(dev_priv)		 (INTEL_INFO(dev_priv)->display.has_psr)
932 933
#define HAS_PSR_HW_TRACKING(dev_priv) \
	(INTEL_INFO(dev_priv)->display.has_psr_hw_tracking)
934
#define HAS_PSR2_SEL_FETCH(dev_priv)	 (DISPLAY_VER(dev_priv) >= 12)
935
#define HAS_TRANSCODER(dev_priv, trans)	 ((RUNTIME_INFO(dev_priv)->cpu_transcoder_mask & BIT(trans)) != 0)
936

937 938
#define HAS_RC6(dev_priv)		 (INTEL_INFO(dev_priv)->has_rc6)
#define HAS_RC6p(dev_priv)		 (INTEL_INFO(dev_priv)->has_rc6p)
939
#define HAS_RC6pp(dev_priv)		 (false) /* HW was never validated */
P
Paulo Zanoni 已提交
940

941 942
#define HAS_RPS(dev_priv)	(INTEL_INFO(dev_priv)->has_rps)

943
#define HAS_DMC(dev_priv)	(RUNTIME_INFO(dev_priv)->has_dmc)
944

945 946 947 948 949 950 951 952
#define HAS_HECI_PXP(dev_priv) \
	(INTEL_INFO(dev_priv)->has_heci_pxp)

#define HAS_HECI_GSCFI(dev_priv) \
	(INTEL_INFO(dev_priv)->has_heci_gscfi)

#define HAS_HECI_GSC(dev_priv) (HAS_HECI_PXP(dev_priv) || HAS_HECI_GSCFI(dev_priv))

953
#define HAS_MSO(i915)		(DISPLAY_VER(i915) >= 12)
954

955 956
#define HAS_RUNTIME_PM(dev_priv) (INTEL_INFO(dev_priv)->has_runtime_pm)
#define HAS_64BIT_RELOC(dev_priv) (INTEL_INFO(dev_priv)->has_64bit_reloc)
957

S
Stuart Summers 已提交
958 959
/*
 * Set this flag, when platform requires 64K GTT page sizes or larger for
960
 * device local memory access.
S
Stuart Summers 已提交
961 962 963
 */
#define HAS_64K_PAGES(dev_priv) (INTEL_INFO(dev_priv)->has_64k_pages)

964 965 966 967 968 969 970
/*
 * Set this flag when platform doesn't allow both 64k pages and 4k pages in
 * the same PT. this flag means we need to support compact PT layout for the
 * ppGTT when using the 64K GTT pages.
 */
#define NEEDS_COMPACT_PT(dev_priv) (INTEL_INFO(dev_priv)->needs_compact_pt)

971
#define HAS_IPC(dev_priv)		 (INTEL_INFO(dev_priv)->display.has_ipc)
972

973
#define HAS_REGION(i915, i) (RUNTIME_INFO(i915)->memory_regions & (i))
974
#define HAS_LMEM(i915) HAS_REGION(i915, REGION_LMEM)
975

976 977 978 979 980 981
/*
 * Platform has the dedicated compression control state for each lmem surfaces
 * stored in lmem to support the 3D and media compression formats.
 */
#define HAS_FLAT_CCS(dev_priv)   (INTEL_INFO(dev_priv)->has_flat_ccs)

982
#define HAS_GT_UC(dev_priv)	(INTEL_INFO(dev_priv)->has_gt_uc)
983

984
#define HAS_POOLED_EU(dev_priv)	(RUNTIME_INFO(dev_priv)->has_pooled_eu)
985

986 987
#define HAS_GLOBAL_MOCS_REGISTERS(dev_priv)	(INTEL_INFO(dev_priv)->has_global_mocs)

988 989
#define HAS_PXP(dev_priv)  ((IS_ENABLED(CONFIG_DRM_I915_PXP) && \
			    INTEL_INFO(dev_priv)->has_pxp) && \
M
Michał Winiarski 已提交
990
			    VDBOX_MASK(to_gt(dev_priv)))
991

R
Rodrigo Vivi 已提交
992
#define HAS_GMCH(dev_priv) (INTEL_INFO(dev_priv)->display.has_gmch)
993

994
#define HAS_LSPCON(dev_priv) (IS_DISPLAY_VER(dev_priv, 9, 10))
995

996 997
#define HAS_L3_CCS_READ(i915) (INTEL_INFO(i915)->has_l3_ccs_read)

998
/* DPF == dynamic parity feature */
999
#define HAS_L3_DPF(dev_priv) (INTEL_INFO(dev_priv)->has_l3_dpf)
1000 1001
#define NUM_L3_SLICES(dev_priv) (IS_HSW_GT3(dev_priv) ? \
				 2 : HAS_L3_DPF(dev_priv))
1002

1003
#define GT_FREQUENCY_MULTIPLIER 50
A
Akash Goel 已提交
1004
#define GEN9_FREQ_SCALER 3
1005

1006
#define INTEL_NUM_PIPES(dev_priv) (hweight8(RUNTIME_INFO(dev_priv)->pipe_mask))
1007

1008
#define HAS_DISPLAY(dev_priv) (RUNTIME_INFO(dev_priv)->pipe_mask != 0)
1009

1010
#define HAS_VRR(i915)	(DISPLAY_VER(i915) >= 11)
1011

1012 1013
#define HAS_ASYNC_FLIPS(i915)		(DISPLAY_VER(i915) >= 5)

1014
/* Only valid when HAS_DISPLAY() is true */
1015
#define INTEL_DISPLAY_ENABLED(dev_priv) \
1016 1017 1018
	(drm_WARN_ON(&(dev_priv)->drm, !HAS_DISPLAY(dev_priv)),		\
	 !(dev_priv)->params.disable_display &&				\
	 !intel_opregion_headless_sku(dev_priv))
1019

1020 1021 1022
#define HAS_GUC_DEPRIVILEGE(dev_priv) \
	(INTEL_INFO(dev_priv)->has_guc_deprivilege)

1023 1024 1025
#define HAS_PERCTX_PREEMPT_CTRL(i915) \
	((GRAPHICS_VER(i915) >= 9) &&  GRAPHICS_VER_FULL(i915) < IP_VER(12, 55))

1026 1027 1028
#define HAS_D12_PLANE_MINIMIZATION(dev_priv) (IS_ROCKETLAKE(dev_priv) || \
					      IS_ALDERLAKE_S(dev_priv))

1029
#define HAS_MBUS_JOINING(i915) (IS_ALDERLAKE_P(i915) || DISPLAY_VER(i915) >= 14)
1030

1031 1032
#define HAS_3D_PIPELINE(i915)	(INTEL_INFO(i915)->has_3d_pipeline)

M
Matt Roper 已提交
1033 1034
#define HAS_ONE_EU_PER_FUSE_BIT(i915)	(INTEL_INFO(i915)->has_one_eu_per_fuse_bit)

1035
/* i915_gem.c */
1036
void i915_gem_init_early(struct drm_i915_private *dev_priv);
1037
void i915_gem_cleanup_early(struct drm_i915_private *dev_priv);
1038

1039 1040
static inline void i915_gem_drain_freed_objects(struct drm_i915_private *i915)
{
1041 1042
	/*
	 * A single pass should suffice to release all the freed objects (along
1043 1044 1045 1046 1047
	 * most call paths) , but be a little more paranoid in that freeing
	 * the objects does take a little amount of time, during which the rcu
	 * callbacks could have added new objects into the freed list, and
	 * armed the work again.
	 */
1048
	while (atomic_read(&i915->mm.free_count)) {
1049
		flush_work(&i915->mm.free_work);
1050
		flush_delayed_work(&i915->bdev.wq);
1051
		rcu_barrier();
1052
	}
1053 1054
}

1055 1056 1057 1058 1059 1060 1061 1062 1063 1064
static inline void i915_gem_drain_workqueue(struct drm_i915_private *i915)
{
	/*
	 * Similar to objects above (see i915_gem_drain_freed-objects), in
	 * general we have workers that are armed by RCU and then rearm
	 * themselves in their callbacks. To be paranoid, we need to
	 * drain the workqueue a second time after waiting for the RCU
	 * grace period so that we catch work queued via RCU from the first
	 * pass. As neither drain_workqueue() nor flush_workqueue() report
	 * a result, we make an assumption that we only don't require more
1065
	 * than 3 passes to catch all _recursive_ RCU delayed work.
1066 1067
	 *
	 */
1068
	int pass = 3;
1069
	do {
1070
		flush_workqueue(i915->wq);
1071
		rcu_barrier();
1072
		i915_gem_drain_freed_objects(i915);
1073
	} while (--pass);
1074
	drain_workqueue(i915->wq);
1075 1076
}

C
Chris Wilson 已提交
1077
struct i915_vma * __must_check
1078 1079 1080 1081 1082
i915_gem_object_ggtt_pin_ww(struct drm_i915_gem_object *obj,
			    struct i915_gem_ww_ctx *ww,
			    const struct i915_ggtt_view *view,
			    u64 size, u64 alignment, u64 flags);

1083
struct i915_vma * __must_check
1084 1085
i915_gem_object_ggtt_pin(struct drm_i915_gem_object *obj,
			 const struct i915_ggtt_view *view,
1086
			 u64 size, u64 alignment, u64 flags);
1087

1088 1089 1090
int i915_gem_object_unbind(struct drm_i915_gem_object *obj,
			   unsigned long flags);
#define I915_GEM_OBJECT_UNBIND_ACTIVE BIT(0)
1091
#define I915_GEM_OBJECT_UNBIND_BARRIER BIT(1)
1092
#define I915_GEM_OBJECT_UNBIND_TEST BIT(2)
1093
#define I915_GEM_OBJECT_UNBIND_VM_TRYLOCK BIT(3)
1094
#define I915_GEM_OBJECT_UNBIND_ASYNC BIT(4)
1095

1096 1097
void i915_gem_runtime_suspend(struct drm_i915_private *dev_priv);

1098
int __must_check i915_gem_set_global_seqno(struct drm_device *dev, u32 seqno);
1099

1100
int __must_check i915_gem_init(struct drm_i915_private *dev_priv);
1101 1102
void i915_gem_driver_register(struct drm_i915_private *i915);
void i915_gem_driver_unregister(struct drm_i915_private *i915);
1103
void i915_gem_driver_remove(struct drm_i915_private *dev_priv);
1104
void i915_gem_driver_release(struct drm_i915_private *dev_priv);
1105

1106
int i915_gem_open(struct drm_i915_private *i915, struct drm_file *file);
1107

1108 1109 1110 1111
/* intel_device_info.c */
static inline struct intel_device_info *
mkwrite_device_info(struct drm_i915_private *dev_priv)
{
1112
	return (struct intel_device_info *)INTEL_INFO(dev_priv);
1113 1114
}

1115
static inline enum i915_map_type
1116 1117
i915_coherent_map_type(struct drm_i915_private *i915,
		       struct drm_i915_gem_object *obj, bool always_coherent)
1118
{
1119 1120 1121 1122 1123 1124
	if (i915_gem_object_is_lmem(obj))
		return I915_MAP_WC;
	if (HAS_LLC(i915) || always_coherent)
		return I915_MAP_WB;
	else
		return I915_MAP_WC;
1125 1126
}

L
Linus Torvalds 已提交
1127
#endif