xref: /linux/drivers/gpu/drm/i915/i915_drv.h (revision f86ad0ed620cb3c91ec7d5468e93ac68d727539d)
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 
35 #include <linux/pci.h>
36 #include <linux/pm_qos.h>
37 
38 #include <drm/ttm/ttm_device.h>
39 
40 #include "gem/i915_gem_context_types.h"
41 #include "gem/i915_gem_shrinker.h"
42 #include "gem/i915_gem_stolen.h"
43 
44 #include "gt/intel_engine.h"
45 #include "gt/intel_gt_types.h"
46 #include "gt/intel_region_lmem.h"
47 #include "gt/intel_workarounds.h"
48 #include "gt/uc/intel_uc.h"
49 
50 #include "i915_drm_client.h"
51 #include "i915_gem.h"
52 #include "i915_gpu_error.h"
53 #include "i915_params.h"
54 #include "i915_perf_types.h"
55 #include "i915_scheduler.h"
56 #include "i915_utils.h"
57 #include "intel_device_info.h"
58 #include "intel_memory_region.h"
59 #include "intel_runtime_pm.h"
60 #include "intel_step.h"
61 #include "intel_uncore.h"
62 
63 struct dram_info;
64 struct drm_i915_clock_gating_funcs;
65 struct intel_display;
66 struct intel_pxp;
67 struct vlv_s0ix_state;
68 
69 #define GEM_QUIRK_PIN_SWIZZLED_PAGES	BIT(0)
70 
71 /* Data Stolen Memory (DSM) aka "i915 stolen memory" */
72 struct i915_dsm {
73 	/*
74 	 * The start and end of DSM which we can optionally use to create GEM
75 	 * objects backed by stolen memory.
76 	 *
77 	 * Note that usable_size tells us exactly how much of this we are
78 	 * actually allowed to use, given that some portion of it is in fact
79 	 * reserved for use by hardware functions.
80 	 */
81 	struct resource stolen;
82 
83 	/*
84 	 * Reserved portion of DSM.
85 	 */
86 	struct resource reserved;
87 
88 	/*
89 	 * Total size minus reserved ranges.
90 	 *
91 	 * DSM is segmented in hardware with different portions offlimits to
92 	 * certain functions.
93 	 *
94 	 * The drm_mm is initialised to the total accessible range, as found
95 	 * from the PCI config. On Broadwell+, this is further restricted to
96 	 * avoid the first page! The upper end of DSM is reserved for hardware
97 	 * functions and similarly removed from the accessible range.
98 	 */
99 	resource_size_t usable_size;
100 };
101 
102 #define MAX_L3_SLICES 2
103 struct intel_l3_parity {
104 	u32 *remap_info[MAX_L3_SLICES];
105 	struct work_struct error_work;
106 	int which_slice;
107 };
108 
109 struct i915_gem_mm {
110 	/*
111 	 * Shortcut for the stolen region. This points to either
112 	 * INTEL_REGION_STOLEN_SMEM for integrated platforms, or
113 	 * INTEL_REGION_STOLEN_LMEM for discrete, or NULL if the device doesn't
114 	 * support stolen.
115 	 */
116 	struct intel_memory_region *stolen_region;
117 	/** Memory allocator for GTT stolen memory */
118 	struct drm_mm stolen;
119 	/** Protects the usage of the GTT stolen memory allocator. This is
120 	 * always the inner lock when overlapping with struct_mutex. */
121 	struct mutex stolen_lock;
122 
123 	/* Protects bound_list/unbound_list and #drm_i915_gem_object.mm.link */
124 	spinlock_t obj_lock;
125 
126 	/**
127 	 * List of objects which are purgeable.
128 	 */
129 	struct list_head purge_list;
130 
131 	/**
132 	 * List of objects which have allocated pages and are shrinkable.
133 	 */
134 	struct list_head shrink_list;
135 
136 	/**
137 	 * List of objects which are pending destruction.
138 	 */
139 	struct llist_head free_list;
140 	struct work_struct free_work;
141 	/**
142 	 * Count of objects pending destructions. Used to skip needlessly
143 	 * waiting on an RCU barrier if no objects are waiting to be freed.
144 	 */
145 	atomic_t free_count;
146 
147 	/**
148 	 * tmpfs instance used for shmem backed objects
149 	 */
150 	struct vfsmount *gemfs;
151 
152 	struct intel_memory_region *regions[INTEL_REGION_UNKNOWN];
153 
154 	struct notifier_block oom_notifier;
155 	struct notifier_block vmap_notifier;
156 	struct shrinker *shrinker;
157 
158 	/* shrinker accounting, also useful for userland debugging */
159 	u64 shrink_memory;
160 	u32 shrink_count;
161 };
162 
163 struct i915_virtual_gpu {
164 	struct mutex lock; /* serialises sending of g2v_notify command pkts */
165 	bool active;
166 	u32 caps;
167 	u32 *initial_mmio;
168 	u8 *initial_cfg_space;
169 	struct list_head entry;
170 };
171 
172 struct i915_selftest_stash {
173 	atomic_t counter;
174 	struct ida mock_region_instances;
175 };
176 
177 struct drm_i915_private {
178 	struct drm_device drm;
179 
180 	struct intel_display *display;
181 
182 	/* FIXME: Device release actions should all be moved to drmm_ */
183 	bool do_release;
184 
185 	/* i915 device parameters */
186 	struct i915_params params;
187 
188 	const struct intel_device_info *__info; /* Use INTEL_INFO() to access. */
189 	struct intel_runtime_info __runtime; /* Use RUNTIME_INFO() to access. */
190 	struct intel_driver_caps caps;
191 
192 	struct i915_dsm dsm;
193 
194 	struct intel_uncore uncore;
195 	struct intel_uncore_mmio_debug mmio_debug;
196 
197 	struct i915_virtual_gpu vgpu;
198 
199 	struct intel_gvt *gvt;
200 
201 	struct {
202 		struct pci_dev *pdev;
203 		struct resource mch_res;
204 		bool mchbar_need_disable;
205 	} gmch;
206 
207 	/*
208 	 * Chaining user engines happens in multiple stages, starting with a
209 	 * simple lock-less linked list created by intel_engine_add_user(),
210 	 * which later gets sorted and converted to an intermediate regular
211 	 * list, just to be converted once again to its final rb tree structure
212 	 * in intel_engines_driver_register().
213 	 *
214 	 * Make sure to use the right iterator helper, depending on if the code
215 	 * in question runs before or after intel_engines_driver_register() --
216 	 * for_each_uabi_engine() can only be used afterwards!
217 	 */
218 	union {
219 		struct llist_head uabi_engines_llist;
220 		struct list_head uabi_engines_list;
221 		struct rb_root uabi_engines;
222 	};
223 	unsigned int engine_uabi_class_count[I915_LAST_UABI_ENGINE_CLASS + 1];
224 
225 	bool irqs_enabled;
226 
227 	/* VLV/CHV IOSF sideband */
228 	struct {
229 		struct mutex lock; /* protect sideband access */
230 		unsigned long locked_unit_mask;
231 		struct pm_qos_request qos;
232 	} vlv_iosf_sb;
233 
234 	/* Sideband mailbox protection */
235 	struct mutex sb_lock;
236 
237 	/** Cached value of IMR to avoid reads in updating the bitfield */
238 	u32 irq_mask;
239 
240 	bool preserve_bios_swizzle;
241 
242 	unsigned int fsb_freq, mem_freq, is_ddr3;
243 
244 	unsigned int hpll_freq;
245 	unsigned int czclk_freq;
246 
247 	/**
248 	 * wq - Driver workqueue for GEM.
249 	 *
250 	 * NOTE: Work items scheduled here are not allowed to grab any modeset
251 	 * locks, for otherwise the flushing done in the pageflip code will
252 	 * result in deadlocks.
253 	 */
254 	struct workqueue_struct *wq;
255 
256 	/**
257 	 * unordered_wq - internal workqueue for unordered work
258 	 *
259 	 * This workqueue should be used for all unordered work
260 	 * scheduling within i915, which used to be scheduled on the
261 	 * system_wq before moving to a driver instance due
262 	 * deprecation of flush_scheduled_work().
263 	 */
264 	struct workqueue_struct *unordered_wq;
265 
266 	/* pm private clock gating functions */
267 	const struct drm_i915_clock_gating_funcs *clock_gating_funcs;
268 
269 	unsigned long gem_quirks;
270 
271 	struct i915_gem_mm mm;
272 
273 	struct intel_l3_parity l3_parity;
274 
275 	/*
276 	 * edram size in MB.
277 	 * Cannot be determined by PCIID. You must always read a register.
278 	 */
279 	u32 edram_size_mb;
280 
281 	struct i915_gpu_error gpu_error;
282 
283 	u32 suspend_count;
284 	struct vlv_s0ix_state *vlv_s0ix_state;
285 
286 	const struct dram_info *dram_info;
287 
288 	struct intel_runtime_pm runtime_pm;
289 
290 	struct i915_perf perf;
291 
292 	struct i915_hwmon *hwmon;
293 
294 	struct intel_gt *gt[I915_MAX_GT];
295 
296 	struct kobject *sysfs_gt;
297 
298 	/* Quick lookup of media GT (current platforms only have one) */
299 	struct intel_gt *media_gt;
300 
301 	struct {
302 		struct i915_gem_contexts {
303 			spinlock_t lock; /* locks list */
304 			struct list_head list;
305 		} contexts;
306 
307 		/*
308 		 * We replace the local file with a global mappings as the
309 		 * backing storage for the mmap is on the device and not
310 		 * on the struct file, and we do not want to prolong the
311 		 * lifetime of the local fd. To minimise the number of
312 		 * anonymous inodes we create, we use a global singleton to
313 		 * share the global mapping.
314 		 */
315 		struct file *mmap_singleton;
316 	} gem;
317 
318 	struct intel_pxp *pxp;
319 
320 	struct i915_pmu pmu;
321 
322 	/* The TTM device structure. */
323 	struct ttm_device bdev;
324 
325 	I915_SELFTEST_DECLARE(struct i915_selftest_stash selftest;)
326 
327 	/*
328 	 * NOTE: This is the dri1/ums dungeon, don't add stuff here. Your patch
329 	 * will be rejected. Instead look for a better place.
330 	 */
331 };
332 
333 static inline struct drm_i915_private *to_i915(const struct drm_device *dev)
334 {
335 	return container_of(dev, struct drm_i915_private, drm);
336 }
337 
338 static inline struct drm_i915_private *kdev_to_i915(struct device *kdev)
339 {
340 	struct drm_device *drm = dev_get_drvdata(kdev);
341 
342 	return drm ? to_i915(drm) : NULL;
343 }
344 
345 static inline struct drm_i915_private *pdev_to_i915(struct pci_dev *pdev)
346 {
347 	struct drm_device *drm = pci_get_drvdata(pdev);
348 
349 	return drm ? to_i915(drm) : NULL;
350 }
351 
352 static inline struct intel_gt *to_gt(const struct drm_i915_private *i915)
353 {
354 	return i915->gt[0];
355 }
356 
357 #define rb_to_uabi_engine(rb) \
358 	rb_entry_safe(rb, struct intel_engine_cs, uabi_node)
359 
360 #define for_each_uabi_engine(engine__, i915__) \
361 	for ((engine__) = rb_to_uabi_engine(rb_first(&(i915__)->uabi_engines));\
362 	     (engine__); \
363 	     (engine__) = rb_to_uabi_engine(rb_next(&(engine__)->uabi_node)))
364 
365 #define INTEL_INFO(i915)	((i915)->__info)
366 #define RUNTIME_INFO(i915)	(&(i915)->__runtime)
367 #define DRIVER_CAPS(i915)	(&(i915)->caps)
368 
369 #define INTEL_DEVID(i915)	(RUNTIME_INFO(i915)->device_id)
370 
371 #define IP_VER(ver, rel)		((ver) << 8 | (rel))
372 
373 #define GRAPHICS_VER(i915)		(RUNTIME_INFO(i915)->graphics.ip.ver)
374 #define GRAPHICS_VER_FULL(i915)		IP_VER(RUNTIME_INFO(i915)->graphics.ip.ver, \
375 					       RUNTIME_INFO(i915)->graphics.ip.rel)
376 #define IS_GRAPHICS_VER(i915, from, until) \
377 	(GRAPHICS_VER(i915) >= (from) && GRAPHICS_VER(i915) <= (until))
378 
379 #define MEDIA_VER(i915)			(RUNTIME_INFO(i915)->media.ip.ver)
380 #define MEDIA_VER_FULL(i915)		IP_VER(RUNTIME_INFO(i915)->media.ip.ver, \
381 					       RUNTIME_INFO(i915)->media.ip.rel)
382 #define IS_MEDIA_VER(i915, from, until) \
383 	(MEDIA_VER(i915) >= (from) && MEDIA_VER(i915) <= (until))
384 
385 #define INTEL_REVID(i915)	(to_pci_dev((i915)->drm.dev)->revision)
386 
387 #define INTEL_GRAPHICS_STEP(__i915) (RUNTIME_INFO(__i915)->step.graphics_step)
388 #define INTEL_MEDIA_STEP(__i915) (RUNTIME_INFO(__i915)->step.media_step)
389 
390 #define IS_GRAPHICS_STEP(__i915, since, until) \
391 	(drm_WARN_ON(&(__i915)->drm, INTEL_GRAPHICS_STEP(__i915) == STEP_NONE), \
392 	 INTEL_GRAPHICS_STEP(__i915) >= (since) && INTEL_GRAPHICS_STEP(__i915) < (until))
393 
394 #define IS_MEDIA_STEP(__i915, since, until) \
395 	(drm_WARN_ON(&(__i915)->drm, INTEL_MEDIA_STEP(__i915) == STEP_NONE), \
396 	 INTEL_MEDIA_STEP(__i915) >= (since) && INTEL_MEDIA_STEP(__i915) < (until))
397 
398 static __always_inline unsigned int
399 __platform_mask_index(const struct intel_runtime_info *info,
400 		      enum intel_platform p)
401 {
402 	const unsigned int pbits =
403 		BITS_PER_TYPE(info->platform_mask[0]) - INTEL_SUBPLATFORM_BITS;
404 
405 	/* Expand the platform_mask array if this fails. */
406 	BUILD_BUG_ON(INTEL_MAX_PLATFORMS >
407 		     pbits * ARRAY_SIZE(info->platform_mask));
408 
409 	return p / pbits;
410 }
411 
412 static __always_inline unsigned int
413 __platform_mask_bit(const struct intel_runtime_info *info,
414 		    enum intel_platform p)
415 {
416 	const unsigned int pbits =
417 		BITS_PER_TYPE(info->platform_mask[0]) - INTEL_SUBPLATFORM_BITS;
418 
419 	return p % pbits + INTEL_SUBPLATFORM_BITS;
420 }
421 
422 static inline u32
423 intel_subplatform(const struct intel_runtime_info *info, enum intel_platform p)
424 {
425 	const unsigned int pi = __platform_mask_index(info, p);
426 
427 	return info->platform_mask[pi] & INTEL_SUBPLATFORM_MASK;
428 }
429 
430 static __always_inline bool
431 IS_PLATFORM(const struct drm_i915_private *i915, enum intel_platform p)
432 {
433 	const struct intel_runtime_info *info = RUNTIME_INFO(i915);
434 	const unsigned int pi = __platform_mask_index(info, p);
435 	const unsigned int pb = __platform_mask_bit(info, p);
436 
437 	BUILD_BUG_ON(!__builtin_constant_p(p));
438 
439 	return info->platform_mask[pi] & BIT(pb);
440 }
441 
442 static __always_inline bool
443 IS_SUBPLATFORM(const struct drm_i915_private *i915,
444 	       enum intel_platform p, unsigned int s)
445 {
446 	const struct intel_runtime_info *info = RUNTIME_INFO(i915);
447 	const unsigned int pi = __platform_mask_index(info, p);
448 	const unsigned int pb = __platform_mask_bit(info, p);
449 	const unsigned int msb = BITS_PER_TYPE(info->platform_mask[0]) - 1;
450 	const u32 mask = info->platform_mask[pi];
451 
452 	BUILD_BUG_ON(!__builtin_constant_p(p));
453 	BUILD_BUG_ON(!__builtin_constant_p(s));
454 	BUILD_BUG_ON((s) >= INTEL_SUBPLATFORM_BITS);
455 
456 	/* Shift and test on the MSB position so sign flag can be used. */
457 	return ((mask << (msb - pb)) & (mask << (msb - s))) & BIT(msb);
458 }
459 
460 #define IS_MOBILE(i915)	(INTEL_INFO(i915)->is_mobile)
461 #define IS_DGFX(i915)   (INTEL_INFO(i915)->is_dgfx)
462 
463 #define IS_I830(i915)	IS_PLATFORM(i915, INTEL_I830)
464 #define IS_I845G(i915)	IS_PLATFORM(i915, INTEL_I845G)
465 #define IS_I85X(i915)	IS_PLATFORM(i915, INTEL_I85X)
466 #define IS_I865G(i915)	IS_PLATFORM(i915, INTEL_I865G)
467 #define IS_I915G(i915)	IS_PLATFORM(i915, INTEL_I915G)
468 #define IS_I915GM(i915)	IS_PLATFORM(i915, INTEL_I915GM)
469 #define IS_I945G(i915)	IS_PLATFORM(i915, INTEL_I945G)
470 #define IS_I945GM(i915)	IS_PLATFORM(i915, INTEL_I945GM)
471 #define IS_I965G(i915)	IS_PLATFORM(i915, INTEL_I965G)
472 #define IS_I965GM(i915)	IS_PLATFORM(i915, INTEL_I965GM)
473 #define IS_G45(i915)	IS_PLATFORM(i915, INTEL_G45)
474 #define IS_GM45(i915)	IS_PLATFORM(i915, INTEL_GM45)
475 #define IS_G4X(i915)	(IS_G45(i915) || IS_GM45(i915))
476 #define IS_PINEVIEW(i915)	IS_PLATFORM(i915, INTEL_PINEVIEW)
477 #define IS_G33(i915)	IS_PLATFORM(i915, INTEL_G33)
478 #define IS_IRONLAKE(i915)	IS_PLATFORM(i915, INTEL_IRONLAKE)
479 #define IS_IRONLAKE_M(i915) \
480 	(IS_PLATFORM(i915, INTEL_IRONLAKE) && IS_MOBILE(i915))
481 #define IS_SANDYBRIDGE(i915) IS_PLATFORM(i915, INTEL_SANDYBRIDGE)
482 #define IS_IVYBRIDGE(i915)	IS_PLATFORM(i915, INTEL_IVYBRIDGE)
483 #define IS_VALLEYVIEW(i915)	IS_PLATFORM(i915, INTEL_VALLEYVIEW)
484 #define IS_CHERRYVIEW(i915)	IS_PLATFORM(i915, INTEL_CHERRYVIEW)
485 #define IS_HASWELL(i915)	IS_PLATFORM(i915, INTEL_HASWELL)
486 #define IS_BROADWELL(i915)	IS_PLATFORM(i915, INTEL_BROADWELL)
487 #define IS_SKYLAKE(i915)	IS_PLATFORM(i915, INTEL_SKYLAKE)
488 #define IS_BROXTON(i915)	IS_PLATFORM(i915, INTEL_BROXTON)
489 #define IS_KABYLAKE(i915)	IS_PLATFORM(i915, INTEL_KABYLAKE)
490 #define IS_GEMINILAKE(i915)	IS_PLATFORM(i915, INTEL_GEMINILAKE)
491 #define IS_COFFEELAKE(i915)	IS_PLATFORM(i915, INTEL_COFFEELAKE)
492 #define IS_COMETLAKE(i915)	IS_PLATFORM(i915, INTEL_COMETLAKE)
493 #define IS_ICELAKE(i915)	IS_PLATFORM(i915, INTEL_ICELAKE)
494 #define IS_JASPERLAKE(i915)	IS_PLATFORM(i915, INTEL_JASPERLAKE)
495 #define IS_ELKHARTLAKE(i915)	IS_PLATFORM(i915, INTEL_ELKHARTLAKE)
496 #define IS_TIGERLAKE(i915)	IS_PLATFORM(i915, INTEL_TIGERLAKE)
497 #define IS_ROCKETLAKE(i915)	IS_PLATFORM(i915, INTEL_ROCKETLAKE)
498 #define IS_DG1(i915)        IS_PLATFORM(i915, INTEL_DG1)
499 #define IS_ALDERLAKE_S(i915) IS_PLATFORM(i915, INTEL_ALDERLAKE_S)
500 #define IS_ALDERLAKE_P(i915) IS_PLATFORM(i915, INTEL_ALDERLAKE_P)
501 #define IS_DG2(i915)	IS_PLATFORM(i915, INTEL_DG2)
502 #define IS_METEORLAKE(i915) IS_PLATFORM(i915, INTEL_METEORLAKE)
503 /*
504  * Display code shared by i915 and Xe relies on macros like IS_LUNARLAKE,
505  * so we need to define these even on platforms that the i915 base driver
506  * doesn't support.  Ensure the parameter is used in the definition to
507  * avoid 'unused variable' warnings when compiling the shared display code
508  * for i915.
509  */
510 #define IS_LUNARLAKE(i915) (0 && i915)
511 #define IS_BATTLEMAGE(i915)  (0 && i915)
512 #define IS_PANTHERLAKE(i915) (0 && i915)
513 
514 #define IS_ARROWLAKE_H(i915) \
515 	IS_SUBPLATFORM(i915, INTEL_METEORLAKE, INTEL_SUBPLATFORM_ARL_H)
516 #define IS_ARROWLAKE_U(i915) \
517 	IS_SUBPLATFORM(i915, INTEL_METEORLAKE, INTEL_SUBPLATFORM_ARL_U)
518 #define IS_ARROWLAKE_S(i915) \
519 	IS_SUBPLATFORM(i915, INTEL_METEORLAKE, INTEL_SUBPLATFORM_ARL_S)
520 #define IS_DG2_G10(i915) \
521 	IS_SUBPLATFORM(i915, INTEL_DG2, INTEL_SUBPLATFORM_G10)
522 #define IS_DG2_G11(i915) \
523 	IS_SUBPLATFORM(i915, INTEL_DG2, INTEL_SUBPLATFORM_G11)
524 #define IS_DG2_G12(i915) \
525 	IS_SUBPLATFORM(i915, INTEL_DG2, INTEL_SUBPLATFORM_G12)
526 #define IS_DG2_D(i915) \
527 	IS_SUBPLATFORM(i915, INTEL_DG2, INTEL_SUBPLATFORM_D)
528 #define IS_RAPTORLAKE_S(i915) \
529 	IS_SUBPLATFORM(i915, INTEL_ALDERLAKE_S, INTEL_SUBPLATFORM_RPL)
530 #define IS_ALDERLAKE_P_N(i915) \
531 	IS_SUBPLATFORM(i915, INTEL_ALDERLAKE_P, INTEL_SUBPLATFORM_N)
532 #define IS_RAPTORLAKE_P(i915) \
533 	IS_SUBPLATFORM(i915, INTEL_ALDERLAKE_P, INTEL_SUBPLATFORM_RPL)
534 #define IS_RAPTORLAKE_U(i915) \
535 	IS_SUBPLATFORM(i915, INTEL_ALDERLAKE_P, INTEL_SUBPLATFORM_RPLU)
536 #define IS_HASWELL_EARLY_SDV(i915) (IS_HASWELL(i915) && \
537 				    (INTEL_DEVID(i915) & 0xFF00) == 0x0C00)
538 #define IS_BROADWELL_ULT(i915) \
539 	IS_SUBPLATFORM(i915, INTEL_BROADWELL, INTEL_SUBPLATFORM_ULT)
540 #define IS_BROADWELL_ULX(i915) \
541 	IS_SUBPLATFORM(i915, INTEL_BROADWELL, INTEL_SUBPLATFORM_ULX)
542 #define IS_HASWELL_ULT(i915) \
543 	IS_SUBPLATFORM(i915, INTEL_HASWELL, INTEL_SUBPLATFORM_ULT)
544 /* ULX machines are also considered ULT. */
545 #define IS_HASWELL_ULX(i915) \
546 	IS_SUBPLATFORM(i915, INTEL_HASWELL, INTEL_SUBPLATFORM_ULX)
547 #define IS_SKYLAKE_ULT(i915) \
548 	IS_SUBPLATFORM(i915, INTEL_SKYLAKE, INTEL_SUBPLATFORM_ULT)
549 #define IS_SKYLAKE_ULX(i915) \
550 	IS_SUBPLATFORM(i915, INTEL_SKYLAKE, INTEL_SUBPLATFORM_ULX)
551 #define IS_KABYLAKE_ULT(i915) \
552 	IS_SUBPLATFORM(i915, INTEL_KABYLAKE, INTEL_SUBPLATFORM_ULT)
553 #define IS_KABYLAKE_ULX(i915) \
554 	IS_SUBPLATFORM(i915, INTEL_KABYLAKE, INTEL_SUBPLATFORM_ULX)
555 #define IS_COFFEELAKE_ULT(i915) \
556 	IS_SUBPLATFORM(i915, INTEL_COFFEELAKE, INTEL_SUBPLATFORM_ULT)
557 #define IS_COFFEELAKE_ULX(i915) \
558 	IS_SUBPLATFORM(i915, INTEL_COFFEELAKE, INTEL_SUBPLATFORM_ULX)
559 #define IS_COMETLAKE_ULT(i915) \
560 	IS_SUBPLATFORM(i915, INTEL_COMETLAKE, INTEL_SUBPLATFORM_ULT)
561 #define IS_COMETLAKE_ULX(i915) \
562 	IS_SUBPLATFORM(i915, INTEL_COMETLAKE, INTEL_SUBPLATFORM_ULX)
563 
564 #define IS_ICL_WITH_PORT_F(i915) \
565 	IS_SUBPLATFORM(i915, INTEL_ICELAKE, INTEL_SUBPLATFORM_PORTF)
566 
567 #define IS_TIGERLAKE_UY(i915) \
568 	IS_SUBPLATFORM(i915, INTEL_TIGERLAKE, INTEL_SUBPLATFORM_UY)
569 
570 #define IS_GEN9_LP(i915)	(IS_BROXTON(i915) || IS_GEMINILAKE(i915))
571 #define IS_GEN9_BC(i915)	(GRAPHICS_VER(i915) == 9 && !IS_GEN9_LP(i915))
572 
573 #define __HAS_ENGINE(engine_mask, id) ((engine_mask) & BIT(id))
574 #define HAS_ENGINE(gt, id) __HAS_ENGINE((gt)->info.engine_mask, id)
575 
576 #define __ENGINE_INSTANCES_MASK(mask, first, count) ({			\
577 	unsigned int first__ = (first);					\
578 	unsigned int count__ = (count);					\
579 	((mask) & GENMASK(first__ + count__ - 1, first__)) >> first__;	\
580 })
581 
582 #define ENGINE_INSTANCES_MASK(gt, first, count) \
583 	__ENGINE_INSTANCES_MASK((gt)->info.engine_mask, first, count)
584 
585 #define RCS_MASK(gt) \
586 	ENGINE_INSTANCES_MASK(gt, RCS0, I915_MAX_RCS)
587 #define BCS_MASK(gt) \
588 	ENGINE_INSTANCES_MASK(gt, BCS0, I915_MAX_BCS)
589 #define VDBOX_MASK(gt) \
590 	ENGINE_INSTANCES_MASK(gt, VCS0, I915_MAX_VCS)
591 #define VEBOX_MASK(gt) \
592 	ENGINE_INSTANCES_MASK(gt, VECS0, I915_MAX_VECS)
593 #define CCS_MASK(gt) \
594 	ENGINE_INSTANCES_MASK(gt, CCS0, I915_MAX_CCS)
595 
596 #define HAS_MEDIA_RATIO_MODE(i915) (INTEL_INFO(i915)->has_media_ratio_mode)
597 
598 /*
599  * The Gen7 cmdparser copies the scanned buffer to the ggtt for execution
600  * All later gens can run the final buffer from the ppgtt
601  */
602 #define CMDPARSER_USES_GGTT(i915) (GRAPHICS_VER(i915) == 7)
603 
604 #define HAS_LLC(i915)	(INTEL_INFO(i915)->has_llc)
605 #define HAS_SNOOP(i915)	(INTEL_INFO(i915)->has_snoop)
606 #define HAS_EDRAM(i915)	((i915)->edram_size_mb)
607 #define HAS_SECURE_BATCHES(i915) (GRAPHICS_VER(i915) < 6)
608 #define HAS_WT(i915)	HAS_EDRAM(i915)
609 
610 #define HWS_NEEDS_PHYSICAL(i915)	(INTEL_INFO(i915)->hws_needs_physical)
611 
612 #define HAS_LOGICAL_RING_CONTEXTS(i915) \
613 		(INTEL_INFO(i915)->has_logical_ring_contexts)
614 #define HAS_LOGICAL_RING_ELSQ(i915) \
615 		(INTEL_INFO(i915)->has_logical_ring_elsq)
616 
617 #define HAS_EXECLISTS(i915) HAS_LOGICAL_RING_CONTEXTS(i915)
618 
619 #define INTEL_PPGTT(i915) (RUNTIME_INFO(i915)->ppgtt_type)
620 #define HAS_PPGTT(i915) \
621 	(INTEL_PPGTT(i915) != INTEL_PPGTT_NONE)
622 #define HAS_FULL_PPGTT(i915) \
623 	(INTEL_PPGTT(i915) >= INTEL_PPGTT_FULL)
624 
625 #define HAS_PAGE_SIZES(i915, sizes) ({ \
626 	GEM_BUG_ON((sizes) == 0); \
627 	((sizes) & ~RUNTIME_INFO(i915)->page_sizes) == 0; \
628 })
629 
630 #define NEEDS_RC6_CTX_CORRUPTION_WA(i915)	\
631 	(IS_BROADWELL(i915) || GRAPHICS_VER(i915) == 9)
632 
633 /* WaRsDisableCoarsePowerGating:skl,cnl */
634 #define NEEDS_WaRsDisableCoarsePowerGating(i915)			\
635 	(IS_SKYLAKE(i915) && (INTEL_INFO(i915)->gt == 3 || INTEL_INFO(i915)->gt == 4))
636 
637 /* With the 945 and later, Y tiling got adjusted so that it was 32 128-byte
638  * rows, which changed the alignment requirements and fence programming.
639  */
640 #define HAS_128_BYTE_Y_TILING(i915) (GRAPHICS_VER(i915) != 2 && \
641 					 !(IS_I915G(i915) || IS_I915GM(i915)))
642 
643 #define HAS_RC6(i915)		 (INTEL_INFO(i915)->has_rc6)
644 #define HAS_RC6p(i915)		 (INTEL_INFO(i915)->has_rc6p)
645 #define HAS_RC6pp(i915)		 (false) /* HW was never validated */
646 
647 #define HAS_RPS(i915)	(INTEL_INFO(i915)->has_rps)
648 
649 #define HAS_PXP(i915) \
650 	(IS_ENABLED(CONFIG_DRM_I915_PXP) && INTEL_INFO(i915)->has_pxp)
651 
652 #define HAS_HECI_PXP(i915) \
653 	(INTEL_INFO(i915)->has_heci_pxp)
654 
655 #define HAS_HECI_GSCFI(i915) \
656 	(INTEL_INFO(i915)->has_heci_gscfi)
657 
658 #define HAS_HECI_GSC(i915) (HAS_HECI_PXP(i915) || HAS_HECI_GSCFI(i915))
659 
660 #define HAS_RUNTIME_PM(i915) (INTEL_INFO(i915)->has_runtime_pm)
661 #define HAS_64BIT_RELOC(i915) (INTEL_INFO(i915)->has_64bit_reloc)
662 
663 #define HAS_OA_BPC_REPORTING(i915) \
664 	(INTEL_INFO(i915)->has_oa_bpc_reporting)
665 #define HAS_OA_SLICE_CONTRIB_LIMITS(i915) \
666 	(INTEL_INFO(i915)->has_oa_slice_contrib_limits)
667 #define HAS_OAM(i915) \
668 	(INTEL_INFO(i915)->has_oam)
669 
670 /*
671  * Set this flag, when platform requires 64K GTT page sizes or larger for
672  * device local memory access.
673  */
674 #define HAS_64K_PAGES(i915) (INTEL_INFO(i915)->has_64k_pages)
675 
676 #define HAS_REGION(i915, id) (INTEL_INFO(i915)->memory_regions & BIT(id))
677 #define HAS_LMEM(i915) HAS_REGION(i915, INTEL_REGION_LMEM_0)
678 
679 #define HAS_EXTRA_GT_LIST(i915)   (INTEL_INFO(i915)->extra_gt_list)
680 
681 /*
682  * Platform has the dedicated compression control state for each lmem surfaces
683  * stored in lmem to support the 3D and media compression formats.
684  */
685 #define HAS_FLAT_CCS(i915)   (INTEL_INFO(i915)->has_flat_ccs)
686 
687 #define HAS_GT_UC(i915)	(INTEL_INFO(i915)->has_gt_uc)
688 
689 #define HAS_POOLED_EU(i915)	(RUNTIME_INFO(i915)->has_pooled_eu)
690 
691 #define HAS_GLOBAL_MOCS_REGISTERS(i915)	(INTEL_INFO(i915)->has_global_mocs)
692 
693 #define HAS_GMD_ID(i915)	(INTEL_INFO(i915)->has_gmd_id)
694 
695 #define HAS_L3_CCS_READ(i915) (INTEL_INFO(i915)->has_l3_ccs_read)
696 
697 /* DPF == dynamic parity feature */
698 #define HAS_L3_DPF(i915) (INTEL_INFO(i915)->has_l3_dpf)
699 #define NUM_L3_SLICES(i915) (IS_HASWELL(i915) && INTEL_INFO(i915)->gt == 3 ? \
700 				 2 : HAS_L3_DPF(i915))
701 
702 #define HAS_GUC_DEPRIVILEGE(i915) \
703 	(INTEL_INFO(i915)->has_guc_deprivilege)
704 
705 #define HAS_GUC_TLB_INVALIDATION(i915)	(INTEL_INFO(i915)->has_guc_tlb_invalidation)
706 
707 #define HAS_3D_PIPELINE(i915)	(INTEL_INFO(i915)->has_3d_pipeline)
708 
709 #define HAS_ONE_EU_PER_FUSE_BIT(i915)	(INTEL_INFO(i915)->has_one_eu_per_fuse_bit)
710 
711 #define HAS_LMEMBAR_SMEM_STOLEN(i915) (!HAS_LMEM(i915) && \
712 				       GRAPHICS_VER_FULL(i915) >= IP_VER(12, 70))
713 
714 #endif
715