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