1c0e09200SDave Airlie /* i915_drv.h -- Private header for the I915 driver -*- linux-c -*-
2c0e09200SDave Airlie */
3c0e09200SDave Airlie /*
4c0e09200SDave Airlie *
5c0e09200SDave Airlie * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
6c0e09200SDave Airlie * All Rights Reserved.
7c0e09200SDave Airlie *
8c0e09200SDave Airlie * Permission is hereby granted, free of charge, to any person obtaining a
9c0e09200SDave Airlie * copy of this software and associated documentation files (the
10c0e09200SDave Airlie * "Software"), to deal in the Software without restriction, including
11c0e09200SDave Airlie * without limitation the rights to use, copy, modify, merge, publish,
12c0e09200SDave Airlie * distribute, sub license, and/or sell copies of the Software, and to
13c0e09200SDave Airlie * permit persons to whom the Software is furnished to do so, subject to
14c0e09200SDave Airlie * the following conditions:
15c0e09200SDave Airlie *
16c0e09200SDave Airlie * The above copyright notice and this permission notice (including the
17c0e09200SDave Airlie * next paragraph) shall be included in all copies or substantial portions
18c0e09200SDave Airlie * of the Software.
19c0e09200SDave Airlie *
20c0e09200SDave Airlie * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
21c0e09200SDave Airlie * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22c0e09200SDave Airlie * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
23c0e09200SDave Airlie * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
24c0e09200SDave Airlie * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
25c0e09200SDave Airlie * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
26c0e09200SDave Airlie * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27c0e09200SDave Airlie *
28c0e09200SDave Airlie */
29c0e09200SDave Airlie
30c0e09200SDave Airlie #ifndef _I915_DRV_H_
31c0e09200SDave Airlie #define _I915_DRV_H_
32c0e09200SDave Airlie
33e9b73c67SChris Wilson #include <uapi/drm/i915_drm.h>
34e9b73c67SChris Wilson
359ee32feaSDaniel Vetter #include <linux/pm_qos.h>
36e73bdd20SChris Wilson
37d1487389SThomas Hellström #include <drm/ttm/ttm_device.h>
38e73bdd20SChris Wilson
39acc855d3SJani Nikula #include "display/intel_display_limits.h"
403b10f851SJani Nikula #include "display/intel_display_core.h"
41df0566a6SJani Nikula
426401fafbSJani Nikula #include "gem/i915_gem_context_types.h"
43be80bc36SJani Nikula #include "gem/i915_gem_shrinker.h"
446401fafbSJani Nikula #include "gem/i915_gem_stolen.h"
456401fafbSJani Nikula
46112ed2d3SChris Wilson #include "gt/intel_engine.h"
47e5be5c7aSTvrtko Ursulin #include "gt/intel_gt_types.h"
48f178b897SMatthew Auld #include "gt/intel_region_lmem.h"
49112ed2d3SChris Wilson #include "gt/intel_workarounds.h"
500f261b24SDaniele Ceraolo Spurio #include "gt/uc/intel_uc.h"
51112ed2d3SChris Wilson
52f052febdSJani Nikula #include "soc/intel_pch.h"
53f052febdSJani Nikula
545f0d4d14STvrtko Ursulin #include "i915_drm_client.h"
554feb2e9eSJani Nikula #include "i915_gem.h"
564feb2e9eSJani Nikula #include "i915_gpu_error.h"
574feb2e9eSJani Nikula #include "i915_params.h"
584feb2e9eSJani Nikula #include "i915_perf_types.h"
594feb2e9eSJani Nikula #include "i915_scheduler.h"
604feb2e9eSJani Nikula #include "i915_utils.h"
61b978520dSMichal Wajdeczko #include "intel_device_info.h"
627eb186bbSJani Nikula #include "intel_memory_region.h"
630d5adc5fSJani Nikula #include "intel_runtime_pm.h"
647eb186bbSJani Nikula #include "intel_step.h"
653846a9b1SMichal Wajdeczko #include "intel_uncore.h"
66e73bdd20SChris Wilson
67edbb9242SJani Nikula struct drm_i915_clock_gating_funcs;
682ecf64a0SJani Nikula struct vlv_s0ix_state;
69f67986b0SAlan Previn struct intel_pxp;
705e5d2e20SChris Wilson
7195086cb9SJani Nikula #define GEM_QUIRK_PIN_SWIZZLED_PAGES BIT(0)
7295086cb9SJani Nikula
731eca0778SJani Nikula /* Data Stolen Memory (DSM) aka "i915 stolen memory" */
741eca0778SJani Nikula struct i915_dsm {
751eca0778SJani Nikula /*
761eca0778SJani Nikula * The start and end of DSM which we can optionally use to create GEM
771eca0778SJani Nikula * objects backed by stolen memory.
781eca0778SJani Nikula *
791eca0778SJani Nikula * Note that usable_size tells us exactly how much of this we are
801eca0778SJani Nikula * actually allowed to use, given that some portion of it is in fact
811eca0778SJani Nikula * reserved for use by hardware functions.
821eca0778SJani Nikula */
831eca0778SJani Nikula struct resource stolen;
841eca0778SJani Nikula
851eca0778SJani Nikula /*
861eca0778SJani Nikula * Reserved portion of DSM.
871eca0778SJani Nikula */
881eca0778SJani Nikula struct resource reserved;
891eca0778SJani Nikula
901eca0778SJani Nikula /*
911eca0778SJani Nikula * Total size minus reserved ranges.
921eca0778SJani Nikula *
931eca0778SJani Nikula * DSM is segmented in hardware with different portions offlimits to
941eca0778SJani Nikula * certain functions.
951eca0778SJani Nikula *
961eca0778SJani Nikula * The drm_mm is initialised to the total accessible range, as found
971eca0778SJani Nikula * from the PCI config. On Broadwell+, this is further restricted to
981eca0778SJani Nikula * avoid the first page! The upper end of DSM is reserved for hardware
991eca0778SJani Nikula * functions and similarly removed from the accessible range.
1001eca0778SJani Nikula */
1011eca0778SJani Nikula resource_size_t usable_size;
1021eca0778SJani Nikula };
1031eca0778SJani Nikula
104f4c956adSDaniel Vetter struct i915_suspend_saved_registers {
105c0e09200SDave Airlie u32 saveDSPARB;
106c0e09200SDave Airlie u32 saveSWF0[16];
107c0e09200SDave Airlie u32 saveSWF1[16];
10885fa792bSVille Syrjälä u32 saveSWF3[3];
1099f49c376SJesse Barnes u16 saveGCDGMBUS;
110f4c956adSDaniel Vetter };
111c85aa885SDaniel Vetter
11235a85ac6SBen Widawsky #define MAX_L3_SLICES 2
113a4da4fa4SDaniel Vetter struct intel_l3_parity {
11435a85ac6SBen Widawsky u32 *remap_info[MAX_L3_SLICES];
115a4da4fa4SDaniel Vetter struct work_struct error_work;
11635a85ac6SBen Widawsky int which_slice;
117a4da4fa4SDaniel Vetter };
118a4da4fa4SDaniel Vetter
1194b5aed62SDaniel Vetter struct i915_gem_mm {
120d57d4a1dSCQ Tang /*
121d57d4a1dSCQ Tang * Shortcut for the stolen region. This points to either
122d57d4a1dSCQ Tang * INTEL_REGION_STOLEN_SMEM for integrated platforms, or
123d57d4a1dSCQ Tang * INTEL_REGION_STOLEN_LMEM for discrete, or NULL if the device doesn't
124d57d4a1dSCQ Tang * support stolen.
125d57d4a1dSCQ Tang */
126d57d4a1dSCQ Tang struct intel_memory_region *stolen_region;
1274b5aed62SDaniel Vetter /** Memory allocator for GTT stolen memory */
1284b5aed62SDaniel Vetter struct drm_mm stolen;
12992e97d2fSPaulo Zanoni /** Protects the usage of the GTT stolen memory allocator. This is
13092e97d2fSPaulo Zanoni * always the inner lock when overlapping with struct_mutex. */
13192e97d2fSPaulo Zanoni struct mutex stolen_lock;
13292e97d2fSPaulo Zanoni
133f2123818SChris Wilson /* Protects bound_list/unbound_list and #drm_i915_gem_object.mm.link */
134f2123818SChris Wilson spinlock_t obj_lock;
135f2123818SChris Wilson
1364b5aed62SDaniel Vetter /**
137ecab9be1SChris Wilson * List of objects which are purgeable.
1383b4fa964SChris Wilson */
1393b4fa964SChris Wilson struct list_head purge_list;
1404b5aed62SDaniel Vetter
141ecab9be1SChris Wilson /**
142ecab9be1SChris Wilson * List of objects which have allocated pages and are shrinkable.
143ecab9be1SChris Wilson */
144ecab9be1SChris Wilson struct list_head shrink_list;
145ecab9be1SChris Wilson
146fbbd37b3SChris Wilson /**
147fbbd37b3SChris Wilson * List of objects which are pending destruction.
148fbbd37b3SChris Wilson */
149fbbd37b3SChris Wilson struct llist_head free_list;
1502826d447SChris Wilson struct work_struct free_work;
151c9c70471SChris Wilson /**
152c9c70471SChris Wilson * Count of objects pending destructions. Used to skip needlessly
153c9c70471SChris Wilson * waiting on an RCU barrier if no objects are waiting to be freed.
154c9c70471SChris Wilson */
155c9c70471SChris Wilson atomic_t free_count;
156fbbd37b3SChris Wilson
15766df1014SChris Wilson /**
158465c403cSMatthew Auld * tmpfs instance used for shmem backed objects
159465c403cSMatthew Auld */
160465c403cSMatthew Auld struct vfsmount *gemfs;
161465c403cSMatthew Auld
1623aae9d08SAbdiel Janulgue struct intel_memory_region *regions[INTEL_REGION_UNKNOWN];
1633aae9d08SAbdiel Janulgue
1642cfcd32aSChris Wilson struct notifier_block oom_notifier;
165e87666b5SChris Wilson struct notifier_block vmap_notifier;
166ceabbba5SChris Wilson struct shrinker shrinker;
1674b5aed62SDaniel Vetter
16820ee27bdSMaarten Lankhorst #ifdef CONFIG_MMU_NOTIFIER
1698a2421bdSChris Wilson /**
170ed29c269SMaarten Lankhorst * notifier_lock for mmu notifiers, memory may not be allocated
171ed29c269SMaarten Lankhorst * while holding this lock.
1728a2421bdSChris Wilson */
173b4b9731bSThomas Hellström rwlock_t notifier_lock;
17420ee27bdSMaarten Lankhorst #endif
1758a2421bdSChris Wilson
176d82b4b26SChris Wilson /* shrinker accounting, also useful for userland debugging */
177d82b4b26SChris Wilson u64 shrink_memory;
178d82b4b26SChris Wilson u32 shrink_count;
1794b5aed62SDaniel Vetter };
1804b5aed62SDaniel Vetter
181cf9d2890SYu Zhang struct i915_virtual_gpu {
18252988009SXiaolin Zhang struct mutex lock; /* serialises sending of g2v_notify command pkts */
183cf9d2890SYu Zhang bool active;
1848a4ab66fSTina Zhang u32 caps;
18566e7a806SZhi Wang u32 *initial_mmio;
18666e7a806SZhi Wang u8 *initial_cfg_space;
1878b750bf7SChristoph Hellwig struct list_head entry;
188cf9d2890SYu Zhang };
189cf9d2890SYu Zhang
190f05816cbSChris Wilson struct i915_selftest_stash {
191f05816cbSChris Wilson atomic_t counter;
192d1487389SThomas Hellström struct ida mock_region_instances;
193f05816cbSChris Wilson };
194f05816cbSChris Wilson
19577fec556SJani Nikula struct drm_i915_private {
1968f460e2cSChris Wilson struct drm_device drm;
1978f460e2cSChris Wilson
1983b10f851SJani Nikula struct intel_display display;
1993b10f851SJani Nikula
2007fb81e9dSDaniel Vetter /* FIXME: Device release actions should all be moved to drmm_ */
2017fb81e9dSDaniel Vetter bool do_release;
2027fb81e9dSDaniel Vetter
2038a25c4beSJani Nikula /* i915 device parameters */
2048a25c4beSJani Nikula struct i915_params params;
2058a25c4beSJani Nikula
2060c4f52baSJani Nikula const struct intel_device_info *__info; /* Use INTEL_INFO() to access. */
2070258404fSJani Nikula struct intel_runtime_info __runtime; /* Use RUNTIME_INFO() to access. */
2083fed1808SChris Wilson struct intel_driver_caps caps;
209f4c956adSDaniel Vetter
2101eca0778SJani Nikula struct i915_dsm dsm;
211b1ace601SMatthew Auld
212907b28c5SChris Wilson struct intel_uncore uncore;
2130a9b2630SDaniele Ceraolo Spurio struct intel_uncore_mmio_debug mmio_debug;
214f4c956adSDaniel Vetter
215cf9d2890SYu Zhang struct i915_virtual_gpu vgpu;
216cf9d2890SYu Zhang
217feddf6e8SZhenyu Wang struct intel_gvt *gvt;
2180ad35fedSZhi Wang
2199bd5de4aSJani Nikula struct {
2209bd5de4aSJani Nikula struct pci_dev *pdev;
2219bd5de4aSJani Nikula struct resource mch_res;
2229bd5de4aSJani Nikula bool mchbar_need_disable;
2239bd5de4aSJani Nikula } gmch;
224750e76b4SChris Wilson
225750e76b4SChris Wilson struct rb_root uabi_engines;
226e2d0ff35STvrtko Ursulin unsigned int engine_uabi_class_count[I915_LAST_UABI_ENGINE_CLASS + 1];
227f4c956adSDaniel Vetter
228f4c956adSDaniel Vetter /* protects the irq masks */
229f4c956adSDaniel Vetter spinlock_t irq_lock;
230f4c956adSDaniel Vetter
231f8b79e58SImre Deak bool display_irqs_enabled;
232f8b79e58SImre Deak
233a580516dSVille Syrjälä /* Sideband mailbox protection */
234a580516dSVille Syrjälä struct mutex sb_lock;
235a75d035fSChris Wilson struct pm_qos_request sb_qos;
236f4c956adSDaniel Vetter
237f4c956adSDaniel Vetter /** Cached value of IMR to avoid reads in updating the bitfield */
238abd58f01SBen Widawsky union {
239f4c956adSDaniel Vetter u32 irq_mask;
240abd58f01SBen Widawsky u32 de_irq_mask[I915_MAX_PIPES];
241abd58f01SBen Widawsky };
24291d181ddSImre Deak u32 pipestat_irq_mask[I915_MAX_PIPES];
243f4c956adSDaniel Vetter
244d9ceb816SJesse Barnes bool preserve_bios_swizzle;
245d9ceb816SJesse Barnes
246f4c956adSDaniel Vetter unsigned int fsb_freq, mem_freq, is_ddr3;
247b2045352SVille Syrjälä unsigned int skl_preferred_vco_freq;
2488d96561aSVille Syrjälä
249adafdc6fSMika Kahola unsigned int max_dotclk_freq;
2506bcda4f0SVille Syrjälä unsigned int hpll_freq;
251bfa7df01SVille Syrjälä unsigned int czclk_freq;
252f4c956adSDaniel Vetter
253645416f5SDaniel Vetter /**
254645416f5SDaniel Vetter * wq - Driver workqueue for GEM.
255645416f5SDaniel Vetter *
256645416f5SDaniel Vetter * NOTE: Work items scheduled here are not allowed to grab any modeset
257645416f5SDaniel Vetter * locks, for otherwise the flushing done in the pageflip code will
258645416f5SDaniel Vetter * result in deadlocks.
259645416f5SDaniel Vetter */
260f4c956adSDaniel Vetter struct workqueue_struct *wq;
261f4c956adSDaniel Vetter
262848a4e5cSLuca Coelho /**
263848a4e5cSLuca Coelho * unordered_wq - internal workqueue for unordered work
264848a4e5cSLuca Coelho *
265848a4e5cSLuca Coelho * This workqueue should be used for all unordered work
266848a4e5cSLuca Coelho * scheduling within i915, which used to be scheduled on the
267848a4e5cSLuca Coelho * system_wq before moving to a driver instance due
268848a4e5cSLuca Coelho * deprecation of flush_scheduled_work().
269848a4e5cSLuca Coelho */
270848a4e5cSLuca Coelho struct workqueue_struct *unordered_wq;
271848a4e5cSLuca Coelho
27246d8e4a1SDave Airlie /* pm private clock gating functions */
273eba4b796SDave Airlie const struct drm_i915_clock_gating_funcs *clock_gating_funcs;
27446d8e4a1SDave Airlie
275f4c956adSDaniel Vetter /* PCH chipset type */
276f4c956adSDaniel Vetter enum intel_pch pch_type;
27717a303ecSPaulo Zanoni unsigned short pch_id;
278f4c956adSDaniel Vetter
27995086cb9SJani Nikula unsigned long gem_quirks;
280f4c956adSDaniel Vetter
2814b5aed62SDaniel Vetter struct i915_gem_mm mm;
2828781342dSDaniel Vetter
283a4da4fa4SDaniel Vetter struct intel_l3_parity l3_parity;
284c6a828d3SDaniel Vetter
285f6ac993fSDaniele Ceraolo Spurio /*
286f6ac993fSDaniele Ceraolo Spurio * edram size in MB.
287f6ac993fSDaniele Ceraolo Spurio * Cannot be determined by PCIID. You must always read a register.
288f6ac993fSDaniele Ceraolo Spurio */
289f6ac993fSDaniele Ceraolo Spurio u32 edram_size_mb;
29059124506SBen Widawsky
29199584db3SDaniel Vetter struct i915_gpu_error gpu_error;
292ae681d96SChris Wilson
293842f1c8bSDaniel Vetter u32 suspend_count;
294f4c956adSDaniel Vetter struct i915_suspend_saved_registers regfile;
2951bcd8688SDaniele Ceraolo Spurio struct vlv_s0ix_state *vlv_s0ix_state;
296231f42a4SDaniel Vetter
297cbfa59d4SMahesh Kumar struct dram_info {
29866a24509SJosé Roberto de Souza bool wm_lv_0_adjust_needed;
299cbfa59d4SMahesh Kumar u8 num_channels;
3008a6c5447SMahesh Kumar bool symmetric_memory;
301b185a352SVille Syrjälä enum intel_dram_type {
302b185a352SVille Syrjälä INTEL_DRAM_UNKNOWN,
303b185a352SVille Syrjälä INTEL_DRAM_DDR3,
304b185a352SVille Syrjälä INTEL_DRAM_DDR4,
305b185a352SVille Syrjälä INTEL_DRAM_LPDDR3,
3061f1257a6SClint Taylor INTEL_DRAM_LPDDR4,
3071f1257a6SClint Taylor INTEL_DRAM_DDR5,
3081f1257a6SClint Taylor INTEL_DRAM_LPDDR5,
309b185a352SVille Syrjälä } type;
3105d0c938eSJosé Roberto de Souza u8 num_qgv_points;
311192fbfb7SStanislav Lisovskiy u8 num_psf_gv_points;
312cbfa59d4SMahesh Kumar } dram_info;
313cbfa59d4SMahesh Kumar
3141bf676ccSDaniele Ceraolo Spurio struct intel_runtime_pm runtime_pm;
3158a187455SPaulo Zanoni
3168f8b1171SChris Wilson struct i915_perf perf;
317eec688e1SRobert Bragg
318b3b088e2SDale B Stimson struct i915_hwmon *hwmon;
319b3b088e2SDale B Stimson
320a83014d3SOscar Mateo /* Abstract the submission mechanism (legacy ringbuffer or execlists) away */
321f54ffa12SAndi Shyti struct intel_gt gt0;
32223c3c3d0SChris Wilson
323bec68cc9STvrtko Ursulin /*
324bec68cc9STvrtko Ursulin * i915->gt[0] == &i915->gt0
325bec68cc9STvrtko Ursulin */
326bec68cc9STvrtko Ursulin struct intel_gt *gt[I915_MAX_GT];
327bec68cc9STvrtko Ursulin
328b770bcfaSAndi Shyti struct kobject *sysfs_gt;
329b770bcfaSAndi Shyti
33051aec8bfSMatt Roper /* Quick lookup of media GT (current platforms only have one) */
33151aec8bfSMatt Roper struct intel_gt *media_gt;
33251aec8bfSMatt Roper
33323c3c3d0SChris Wilson struct {
334a4e7ccdaSChris Wilson struct i915_gem_contexts {
335a4e7ccdaSChris Wilson spinlock_t lock; /* locks list */
336a4e7ccdaSChris Wilson struct list_head list;
337a4e7ccdaSChris Wilson } contexts;
338f17b8980SChris Wilson
339f17b8980SChris Wilson /*
340f17b8980SChris Wilson * We replace the local file with a global mappings as the
341f17b8980SChris Wilson * backing storage for the mmap is on the device and not
342f17b8980SChris Wilson * on the struct file, and we do not want to prolong the
343f17b8980SChris Wilson * lifetime of the local fd. To minimise the number of
344f17b8980SChris Wilson * anonymous inodes we create, we use a global singleton to
345f17b8980SChris Wilson * share the global mapping.
346f17b8980SChris Wilson */
347f17b8980SChris Wilson struct file *mmap_singleton;
34823c3c3d0SChris Wilson } gem;
349a83014d3SOscar Mateo
350f67986b0SAlan Previn struct intel_pxp *pxp;
351f67986b0SAlan Previn
3527d423af9SVille Syrjälä /* For i915gm/i945gm vblank irq workaround */
3537d423af9SVille Syrjälä u8 vblank_enabled;
354d938da6bSVille Syrjälä
355ac1723c1SThomas Zimmermann bool irq_enabled;
356ac1723c1SThomas Zimmermann
357b46a33e2STvrtko Ursulin struct i915_pmu pmu;
358b46a33e2STvrtko Ursulin
359d1487389SThomas Hellström /* The TTM device structure. */
360d1487389SThomas Hellström struct ttm_device bdev;
361d1487389SThomas Hellström
362f05816cbSChris Wilson I915_SELFTEST_DECLARE(struct i915_selftest_stash selftest;)
363f05816cbSChris Wilson
364bdf1e7e3SDaniel Vetter /*
365bdf1e7e3SDaniel Vetter * NOTE: This is the dri1/ums dungeon, don't add stuff here. Your patch
366bdf1e7e3SDaniel Vetter * will be rejected. Instead look for a better place.
367bdf1e7e3SDaniel Vetter */
36877fec556SJani Nikula };
369c0e09200SDave Airlie
to_i915(const struct drm_device * dev)3702c1792a1SChris Wilson static inline struct drm_i915_private *to_i915(const struct drm_device *dev)
3712c1792a1SChris Wilson {
372091387c1SChris Wilson return container_of(dev, struct drm_i915_private, drm);
3732c1792a1SChris Wilson }
3742c1792a1SChris Wilson
kdev_to_i915(struct device * kdev)375c49d13eeSDavid Weinehall static inline struct drm_i915_private *kdev_to_i915(struct device *kdev)
376888d0d42SImre Deak {
377361f9dc2SChris Wilson return dev_get_drvdata(kdev);
378361f9dc2SChris Wilson }
379361f9dc2SChris Wilson
pdev_to_i915(struct pci_dev * pdev)380361f9dc2SChris Wilson static inline struct drm_i915_private *pdev_to_i915(struct pci_dev *pdev)
381361f9dc2SChris Wilson {
382361f9dc2SChris Wilson return pci_get_drvdata(pdev);
383888d0d42SImre Deak }
384888d0d42SImre Deak
to_gt(struct drm_i915_private * i915)385c0f0dab8SMichał Winiarski static inline struct intel_gt *to_gt(struct drm_i915_private *i915)
386c0f0dab8SMichał Winiarski {
387f54ffa12SAndi Shyti return &i915->gt0;
388c0f0dab8SMichał Winiarski }
389c0f0dab8SMichał Winiarski
390b4ac5afcSDave Gordon /* Simple iterator over all initialised engines */
39164e22551SAndi Shyti #define for_each_engine(engine__, gt__, id__) \
3923b3f1650SAkash Goel for ((id__) = 0; \
3933b3f1650SAkash Goel (id__) < I915_NUM_ENGINES; \
3943b3f1650SAkash Goel (id__)++) \
39564e22551SAndi Shyti for_each_if ((engine__) = (gt__)->engine[(id__)])
396c3232b18SDave Gordon
397c3232b18SDave Gordon /* Iterator over subset of engines selected by mask */
398a50134b1STvrtko Ursulin #define for_each_engine_masked(engine__, gt__, mask__, tmp__) \
399792592e7SDaniele Ceraolo Spurio for ((tmp__) = (mask__) & (gt__)->info.engine_mask; \
40019d3cf00STvrtko Ursulin (tmp__) ? \
401a50134b1STvrtko Ursulin ((engine__) = (gt__)->engine[__mask_next_bit(tmp__)]), 1 : \
40219d3cf00STvrtko Ursulin 0;)
403ee4b6fafSMika Kuoppala
404750e76b4SChris Wilson #define rb_to_uabi_engine(rb) \
405750e76b4SChris Wilson rb_entry_safe(rb, struct intel_engine_cs, uabi_node)
406750e76b4SChris Wilson
407750e76b4SChris Wilson #define for_each_uabi_engine(engine__, i915__) \
408750e76b4SChris Wilson for ((engine__) = rb_to_uabi_engine(rb_first(&(i915__)->uabi_engines));\
409750e76b4SChris Wilson (engine__); \
410750e76b4SChris Wilson (engine__) = rb_to_uabi_engine(rb_next(&(engine__)->uabi_node)))
411750e76b4SChris Wilson
412d61345f3SChris Wilson #define for_each_uabi_class_engine(engine__, class__, i915__) \
413d61345f3SChris Wilson for ((engine__) = intel_engine_lookup_user((i915__), (class__), 0); \
414d61345f3SChris Wilson (engine__) && (engine__)->uabi_class == (class__); \
415d61345f3SChris Wilson (engine__) = rb_to_uabi_engine(rb_next(&(engine__)->uabi_node)))
416d61345f3SChris Wilson
4170c4f52baSJani Nikula #define INTEL_INFO(i915) ((i915)->__info)
41866ca1d8fSAndi Shyti #define RUNTIME_INFO(i915) (&(i915)->__runtime)
419e672f9e9SJani Nikula #define DISPLAY_INFO(i915) ((i915)->display.info.__device_info)
420e672f9e9SJani Nikula #define DISPLAY_RUNTIME_INFO(i915) (&(i915)->display.info.__runtime_info)
42166ca1d8fSAndi Shyti #define DRIVER_CAPS(i915) (&(i915)->caps)
42250a0bc90STvrtko Ursulin
42366ca1d8fSAndi Shyti #define INTEL_DEVID(i915) (RUNTIME_INFO(i915)->device_id)
424cae5852dSZou Nan hai
425f3973035SLucas De Marchi #define IP_VER(ver, rel) ((ver) << 8 | (rel))
426f3973035SLucas De Marchi
427f9e932a8SRadhakrishna Sripada #define GRAPHICS_VER(i915) (RUNTIME_INFO(i915)->graphics.ip.ver)
428f9e932a8SRadhakrishna Sripada #define GRAPHICS_VER_FULL(i915) IP_VER(RUNTIME_INFO(i915)->graphics.ip.ver, \
429f9e932a8SRadhakrishna Sripada RUNTIME_INFO(i915)->graphics.ip.rel)
43093babb06SLucas De Marchi #define IS_GRAPHICS_VER(i915, from, until) \
43193babb06SLucas De Marchi (GRAPHICS_VER(i915) >= (from) && GRAPHICS_VER(i915) <= (until))
43293babb06SLucas De Marchi
433f9e932a8SRadhakrishna Sripada #define MEDIA_VER(i915) (RUNTIME_INFO(i915)->media.ip.ver)
434f9e932a8SRadhakrishna Sripada #define MEDIA_VER_FULL(i915) IP_VER(RUNTIME_INFO(i915)->media.ip.ver, \
435f9e932a8SRadhakrishna Sripada RUNTIME_INFO(i915)->media.ip.rel)
43693babb06SLucas De Marchi #define IS_MEDIA_VER(i915, from, until) \
43793babb06SLucas De Marchi (MEDIA_VER(i915) >= (from) && MEDIA_VER(i915) <= (until))
43893babb06SLucas De Marchi
43918e0deeeSMatt Roper #define DISPLAY_VER(i915) (DISPLAY_RUNTIME_INFO(i915)->ip.ver)
44093e7e61eSLucas De Marchi #define IS_DISPLAY_VER(i915, from, until) \
44101eb15c9SMatt Roper (DISPLAY_VER(i915) >= (from) && DISPLAY_VER(i915) <= (until))
44201eb15c9SMatt Roper
44366ca1d8fSAndi Shyti #define INTEL_REVID(i915) (to_pci_dev((i915)->drm.dev)->revision)
444ac657f64STvrtko Ursulin
44526475ca9SJani Nikula #define INTEL_DISPLAY_STEP(__i915) (RUNTIME_INFO(__i915)->step.display_step)
446c1f110eeSJosé Roberto de Souza #define INTEL_GRAPHICS_STEP(__i915) (RUNTIME_INFO(__i915)->step.graphics_step)
447e181fa1dSJosé Roberto de Souza #define INTEL_MEDIA_STEP(__i915) (RUNTIME_INFO(__i915)->step.media_step)
4488b449f1cSMatt Roper #define INTEL_BASEDIE_STEP(__i915) (RUNTIME_INFO(__i915)->step.basedie_step)
449439c8dccSJani Nikula
450439c8dccSJani Nikula #define IS_DISPLAY_STEP(__i915, since, until) \
451439c8dccSJani Nikula (drm_WARN_ON(&(__i915)->drm, INTEL_DISPLAY_STEP(__i915) == STEP_NONE), \
45246b0d709SMatt Roper INTEL_DISPLAY_STEP(__i915) >= (since) && INTEL_DISPLAY_STEP(__i915) < (until))
453439c8dccSJani Nikula
454c1f110eeSJosé Roberto de Souza #define IS_GRAPHICS_STEP(__i915, since, until) \
455c1f110eeSJosé Roberto de Souza (drm_WARN_ON(&(__i915)->drm, INTEL_GRAPHICS_STEP(__i915) == STEP_NONE), \
456c1f110eeSJosé Roberto de Souza INTEL_GRAPHICS_STEP(__i915) >= (since) && INTEL_GRAPHICS_STEP(__i915) < (until))
457439c8dccSJani Nikula
458e181fa1dSJosé Roberto de Souza #define IS_MEDIA_STEP(__i915, since, until) \
459e181fa1dSJosé Roberto de Souza (drm_WARN_ON(&(__i915)->drm, INTEL_MEDIA_STEP(__i915) == STEP_NONE), \
460e181fa1dSJosé Roberto de Souza INTEL_MEDIA_STEP(__i915) >= (since) && INTEL_MEDIA_STEP(__i915) < (until))
461e181fa1dSJosé Roberto de Souza
4628b449f1cSMatt Roper #define IS_BASEDIE_STEP(__i915, since, until) \
4638b449f1cSMatt Roper (drm_WARN_ON(&(__i915)->drm, INTEL_BASEDIE_STEP(__i915) == STEP_NONE), \
4648b449f1cSMatt Roper INTEL_BASEDIE_STEP(__i915) >= (since) && INTEL_BASEDIE_STEP(__i915) < (until))
4658b449f1cSMatt Roper
466805446c8STvrtko Ursulin static __always_inline unsigned int
__platform_mask_index(const struct intel_runtime_info * info,enum intel_platform p)467805446c8STvrtko Ursulin __platform_mask_index(const struct intel_runtime_info *info,
468805446c8STvrtko Ursulin enum intel_platform p)
469805446c8STvrtko Ursulin {
470805446c8STvrtko Ursulin const unsigned int pbits =
471805446c8STvrtko Ursulin BITS_PER_TYPE(info->platform_mask[0]) - INTEL_SUBPLATFORM_BITS;
472805446c8STvrtko Ursulin
473805446c8STvrtko Ursulin /* Expand the platform_mask array if this fails. */
474805446c8STvrtko Ursulin BUILD_BUG_ON(INTEL_MAX_PLATFORMS >
475805446c8STvrtko Ursulin pbits * ARRAY_SIZE(info->platform_mask));
476805446c8STvrtko Ursulin
477805446c8STvrtko Ursulin return p / pbits;
478805446c8STvrtko Ursulin }
479805446c8STvrtko Ursulin
480805446c8STvrtko Ursulin static __always_inline unsigned int
__platform_mask_bit(const struct intel_runtime_info * info,enum intel_platform p)481805446c8STvrtko Ursulin __platform_mask_bit(const struct intel_runtime_info *info,
482805446c8STvrtko Ursulin enum intel_platform p)
483805446c8STvrtko Ursulin {
484805446c8STvrtko Ursulin const unsigned int pbits =
485805446c8STvrtko Ursulin BITS_PER_TYPE(info->platform_mask[0]) - INTEL_SUBPLATFORM_BITS;
486805446c8STvrtko Ursulin
487805446c8STvrtko Ursulin return p % pbits + INTEL_SUBPLATFORM_BITS;
488805446c8STvrtko Ursulin }
489805446c8STvrtko Ursulin
490805446c8STvrtko Ursulin static inline u32
intel_subplatform(const struct intel_runtime_info * info,enum intel_platform p)491805446c8STvrtko Ursulin intel_subplatform(const struct intel_runtime_info *info, enum intel_platform p)
492805446c8STvrtko Ursulin {
493805446c8STvrtko Ursulin const unsigned int pi = __platform_mask_index(info, p);
494805446c8STvrtko Ursulin
49556afa701STvrtko Ursulin return info->platform_mask[pi] & INTEL_SUBPLATFORM_MASK;
496805446c8STvrtko Ursulin }
497805446c8STvrtko Ursulin
498805446c8STvrtko Ursulin static __always_inline bool
IS_PLATFORM(const struct drm_i915_private * i915,enum intel_platform p)499805446c8STvrtko Ursulin IS_PLATFORM(const struct drm_i915_private *i915, enum intel_platform p)
500805446c8STvrtko Ursulin {
501805446c8STvrtko Ursulin const struct intel_runtime_info *info = RUNTIME_INFO(i915);
502805446c8STvrtko Ursulin const unsigned int pi = __platform_mask_index(info, p);
503805446c8STvrtko Ursulin const unsigned int pb = __platform_mask_bit(info, p);
504805446c8STvrtko Ursulin
505805446c8STvrtko Ursulin BUILD_BUG_ON(!__builtin_constant_p(p));
506805446c8STvrtko Ursulin
507805446c8STvrtko Ursulin return info->platform_mask[pi] & BIT(pb);
508805446c8STvrtko Ursulin }
509805446c8STvrtko Ursulin
510805446c8STvrtko Ursulin static __always_inline bool
IS_SUBPLATFORM(const struct drm_i915_private * i915,enum intel_platform p,unsigned int s)511805446c8STvrtko Ursulin IS_SUBPLATFORM(const struct drm_i915_private *i915,
512805446c8STvrtko Ursulin enum intel_platform p, unsigned int s)
513805446c8STvrtko Ursulin {
514805446c8STvrtko Ursulin const struct intel_runtime_info *info = RUNTIME_INFO(i915);
515805446c8STvrtko Ursulin const unsigned int pi = __platform_mask_index(info, p);
516805446c8STvrtko Ursulin const unsigned int pb = __platform_mask_bit(info, p);
517805446c8STvrtko Ursulin const unsigned int msb = BITS_PER_TYPE(info->platform_mask[0]) - 1;
518805446c8STvrtko Ursulin const u32 mask = info->platform_mask[pi];
519805446c8STvrtko Ursulin
520805446c8STvrtko Ursulin BUILD_BUG_ON(!__builtin_constant_p(p));
521805446c8STvrtko Ursulin BUILD_BUG_ON(!__builtin_constant_p(s));
522805446c8STvrtko Ursulin BUILD_BUG_ON((s) >= INTEL_SUBPLATFORM_BITS);
523805446c8STvrtko Ursulin
524805446c8STvrtko Ursulin /* Shift and test on the MSB position so sign flag can be used. */
525805446c8STvrtko Ursulin return ((mask << (msb - pb)) & (mask << (msb - s))) & BIT(msb);
526805446c8STvrtko Ursulin }
5275a127a8cSTvrtko Ursulin
52866ca1d8fSAndi Shyti #define IS_MOBILE(i915) (INTEL_INFO(i915)->is_mobile)
52966ca1d8fSAndi Shyti #define IS_DGFX(i915) (INTEL_INFO(i915)->is_dgfx)
530e08891a5STvrtko Ursulin
53166ca1d8fSAndi Shyti #define IS_I830(i915) IS_PLATFORM(i915, INTEL_I830)
53266ca1d8fSAndi Shyti #define IS_I845G(i915) IS_PLATFORM(i915, INTEL_I845G)
53366ca1d8fSAndi Shyti #define IS_I85X(i915) IS_PLATFORM(i915, INTEL_I85X)
53466ca1d8fSAndi Shyti #define IS_I865G(i915) IS_PLATFORM(i915, INTEL_I865G)
53566ca1d8fSAndi Shyti #define IS_I915G(i915) IS_PLATFORM(i915, INTEL_I915G)
53666ca1d8fSAndi Shyti #define IS_I915GM(i915) IS_PLATFORM(i915, INTEL_I915GM)
53766ca1d8fSAndi Shyti #define IS_I945G(i915) IS_PLATFORM(i915, INTEL_I945G)
53866ca1d8fSAndi Shyti #define IS_I945GM(i915) IS_PLATFORM(i915, INTEL_I945GM)
53966ca1d8fSAndi Shyti #define IS_I965G(i915) IS_PLATFORM(i915, INTEL_I965G)
54066ca1d8fSAndi Shyti #define IS_I965GM(i915) IS_PLATFORM(i915, INTEL_I965GM)
54166ca1d8fSAndi Shyti #define IS_G45(i915) IS_PLATFORM(i915, INTEL_G45)
54266ca1d8fSAndi Shyti #define IS_GM45(i915) IS_PLATFORM(i915, INTEL_GM45)
54366ca1d8fSAndi Shyti #define IS_G4X(i915) (IS_G45(i915) || IS_GM45(i915))
54466ca1d8fSAndi Shyti #define IS_PINEVIEW(i915) IS_PLATFORM(i915, INTEL_PINEVIEW)
54566ca1d8fSAndi Shyti #define IS_G33(i915) IS_PLATFORM(i915, INTEL_G33)
54666ca1d8fSAndi Shyti #define IS_IRONLAKE(i915) IS_PLATFORM(i915, INTEL_IRONLAKE)
54766ca1d8fSAndi Shyti #define IS_IRONLAKE_M(i915) \
54866ca1d8fSAndi Shyti (IS_PLATFORM(i915, INTEL_IRONLAKE) && IS_MOBILE(i915))
54966ca1d8fSAndi Shyti #define IS_SANDYBRIDGE(i915) IS_PLATFORM(i915, INTEL_SANDYBRIDGE)
55066ca1d8fSAndi Shyti #define IS_IVYBRIDGE(i915) IS_PLATFORM(i915, INTEL_IVYBRIDGE)
55166ca1d8fSAndi Shyti #define IS_IVB_GT1(i915) (IS_IVYBRIDGE(i915) && \
55266ca1d8fSAndi Shyti INTEL_INFO(i915)->gt == 1)
55366ca1d8fSAndi Shyti #define IS_VALLEYVIEW(i915) IS_PLATFORM(i915, INTEL_VALLEYVIEW)
55466ca1d8fSAndi Shyti #define IS_CHERRYVIEW(i915) IS_PLATFORM(i915, INTEL_CHERRYVIEW)
55566ca1d8fSAndi Shyti #define IS_HASWELL(i915) IS_PLATFORM(i915, INTEL_HASWELL)
55666ca1d8fSAndi Shyti #define IS_BROADWELL(i915) IS_PLATFORM(i915, INTEL_BROADWELL)
55766ca1d8fSAndi Shyti #define IS_SKYLAKE(i915) IS_PLATFORM(i915, INTEL_SKYLAKE)
55866ca1d8fSAndi Shyti #define IS_BROXTON(i915) IS_PLATFORM(i915, INTEL_BROXTON)
55966ca1d8fSAndi Shyti #define IS_KABYLAKE(i915) IS_PLATFORM(i915, INTEL_KABYLAKE)
56066ca1d8fSAndi Shyti #define IS_GEMINILAKE(i915) IS_PLATFORM(i915, INTEL_GEMINILAKE)
56166ca1d8fSAndi Shyti #define IS_COFFEELAKE(i915) IS_PLATFORM(i915, INTEL_COFFEELAKE)
56266ca1d8fSAndi Shyti #define IS_COMETLAKE(i915) IS_PLATFORM(i915, INTEL_COMETLAKE)
56366ca1d8fSAndi Shyti #define IS_ICELAKE(i915) IS_PLATFORM(i915, INTEL_ICELAKE)
5640c65dc06SDnyaneshwar Bhadane #define IS_JASPERLAKE(i915) IS_PLATFORM(i915, INTEL_JASPERLAKE)
5650c65dc06SDnyaneshwar Bhadane #define IS_ELKHARTLAKE(i915) IS_PLATFORM(i915, INTEL_ELKHARTLAKE)
56666ca1d8fSAndi Shyti #define IS_TIGERLAKE(i915) IS_PLATFORM(i915, INTEL_TIGERLAKE)
56766ca1d8fSAndi Shyti #define IS_ROCKETLAKE(i915) IS_PLATFORM(i915, INTEL_ROCKETLAKE)
56866ca1d8fSAndi Shyti #define IS_DG1(i915) IS_PLATFORM(i915, INTEL_DG1)
56966ca1d8fSAndi Shyti #define IS_ALDERLAKE_S(i915) IS_PLATFORM(i915, INTEL_ALDERLAKE_S)
57066ca1d8fSAndi Shyti #define IS_ALDERLAKE_P(i915) IS_PLATFORM(i915, INTEL_ALDERLAKE_P)
57166ca1d8fSAndi Shyti #define IS_XEHPSDV(i915) IS_PLATFORM(i915, INTEL_XEHPSDV)
57266ca1d8fSAndi Shyti #define IS_DG2(i915) IS_PLATFORM(i915, INTEL_DG2)
57366ca1d8fSAndi Shyti #define IS_PONTEVECCHIO(i915) IS_PLATFORM(i915, INTEL_PONTEVECCHIO)
57466ca1d8fSAndi Shyti #define IS_METEORLAKE(i915) IS_PLATFORM(i915, INTEL_METEORLAKE)
575448a54acSStuart Summers
57666ca1d8fSAndi Shyti #define IS_METEORLAKE_M(i915) \
57766ca1d8fSAndi Shyti IS_SUBPLATFORM(i915, INTEL_METEORLAKE, INTEL_SUBPLATFORM_M)
57866ca1d8fSAndi Shyti #define IS_METEORLAKE_P(i915) \
57966ca1d8fSAndi Shyti IS_SUBPLATFORM(i915, INTEL_METEORLAKE, INTEL_SUBPLATFORM_P)
58066ca1d8fSAndi Shyti #define IS_DG2_G10(i915) \
58166ca1d8fSAndi Shyti IS_SUBPLATFORM(i915, INTEL_DG2, INTEL_SUBPLATFORM_G10)
58266ca1d8fSAndi Shyti #define IS_DG2_G11(i915) \
58366ca1d8fSAndi Shyti IS_SUBPLATFORM(i915, INTEL_DG2, INTEL_SUBPLATFORM_G11)
58466ca1d8fSAndi Shyti #define IS_DG2_G12(i915) \
58566ca1d8fSAndi Shyti IS_SUBPLATFORM(i915, INTEL_DG2, INTEL_SUBPLATFORM_G12)
586*2aa01e4dSDnyaneshwar Bhadane #define IS_RAPTORLAKE_S(i915) \
58766ca1d8fSAndi Shyti IS_SUBPLATFORM(i915, INTEL_ALDERLAKE_S, INTEL_SUBPLATFORM_RPL)
5886373b793SAnusha Srivatsa #define IS_ALDERLAKE_P_N(i915) \
58966ca1d8fSAndi Shyti IS_SUBPLATFORM(i915, INTEL_ALDERLAKE_P, INTEL_SUBPLATFORM_N)
590de01a919SDnyaneshwar Bhadane #define IS_RAPTORLAKE_P(i915) \
59166ca1d8fSAndi Shyti IS_SUBPLATFORM(i915, INTEL_ALDERLAKE_P, INTEL_SUBPLATFORM_RPL)
592e5706c04SDnyaneshwar Bhadane #define IS_RAPTORLAKE_U(i915) \
59366ca1d8fSAndi Shyti IS_SUBPLATFORM(i915, INTEL_ALDERLAKE_P, INTEL_SUBPLATFORM_RPLU)
594927a8e38SDnyaneshwar Bhadane #define IS_HASWELL_EARLY_SDV(i915) (IS_HASWELL(i915) && \
59566ca1d8fSAndi Shyti (INTEL_DEVID(i915) & 0xFF00) == 0x0C00)
596c224d89cSDnyaneshwar Bhadane #define IS_BROADWELL_ULT(i915) \
59766ca1d8fSAndi Shyti IS_SUBPLATFORM(i915, INTEL_BROADWELL, INTEL_SUBPLATFORM_ULT)
598c224d89cSDnyaneshwar Bhadane #define IS_BROADWELL_ULX(i915) \
59966ca1d8fSAndi Shyti IS_SUBPLATFORM(i915, INTEL_BROADWELL, INTEL_SUBPLATFORM_ULX)
600c224d89cSDnyaneshwar Bhadane #define IS_BROADWELL_GT3(i915) (IS_BROADWELL(i915) && \
60166ca1d8fSAndi Shyti INTEL_INFO(i915)->gt == 3)
602927a8e38SDnyaneshwar Bhadane #define IS_HASWELL_ULT(i915) \
60366ca1d8fSAndi Shyti IS_SUBPLATFORM(i915, INTEL_HASWELL, INTEL_SUBPLATFORM_ULT)
604927a8e38SDnyaneshwar Bhadane #define IS_HASWELL_GT3(i915) (IS_HASWELL(i915) && \
60566ca1d8fSAndi Shyti INTEL_INFO(i915)->gt == 3)
606927a8e38SDnyaneshwar Bhadane #define IS_HASWELL_GT1(i915) (IS_HASWELL(i915) && \
60766ca1d8fSAndi Shyti INTEL_INFO(i915)->gt == 1)
6089bbfd20aSPaulo Zanoni /* ULX machines are also considered ULT. */
609927a8e38SDnyaneshwar Bhadane #define IS_HASWELL_ULX(i915) \
61066ca1d8fSAndi Shyti IS_SUBPLATFORM(i915, INTEL_HASWELL, INTEL_SUBPLATFORM_ULX)
611bd21470fSDnyaneshwar Bhadane #define IS_SKYLAKE_ULT(i915) \
61266ca1d8fSAndi Shyti IS_SUBPLATFORM(i915, INTEL_SKYLAKE, INTEL_SUBPLATFORM_ULT)
613bd21470fSDnyaneshwar Bhadane #define IS_SKYLAKE_ULX(i915) \
61466ca1d8fSAndi Shyti IS_SUBPLATFORM(i915, INTEL_SKYLAKE, INTEL_SUBPLATFORM_ULX)
615b1c52560SDnyaneshwar Bhadane #define IS_KABYLAKE_ULT(i915) \
61666ca1d8fSAndi Shyti IS_SUBPLATFORM(i915, INTEL_KABYLAKE, INTEL_SUBPLATFORM_ULT)
617b1c52560SDnyaneshwar Bhadane #define IS_KABYLAKE_ULX(i915) \
61866ca1d8fSAndi Shyti IS_SUBPLATFORM(i915, INTEL_KABYLAKE, INTEL_SUBPLATFORM_ULX)
619bd21470fSDnyaneshwar Bhadane #define IS_SKYLAKE_GT2(i915) (IS_SKYLAKE(i915) && \
62066ca1d8fSAndi Shyti INTEL_INFO(i915)->gt == 2)
621bd21470fSDnyaneshwar Bhadane #define IS_SKYLAKE_GT3(i915) (IS_SKYLAKE(i915) && \
62266ca1d8fSAndi Shyti INTEL_INFO(i915)->gt == 3)
623bd21470fSDnyaneshwar Bhadane #define IS_SKYLAKE_GT4(i915) (IS_SKYLAKE(i915) && \
62466ca1d8fSAndi Shyti INTEL_INFO(i915)->gt == 4)
625b1c52560SDnyaneshwar Bhadane #define IS_KABYLAKE_GT2(i915) (IS_KABYLAKE(i915) && \
62666ca1d8fSAndi Shyti INTEL_INFO(i915)->gt == 2)
627b1c52560SDnyaneshwar Bhadane #define IS_KABYLAKE_GT3(i915) (IS_KABYLAKE(i915) && \
62866ca1d8fSAndi Shyti INTEL_INFO(i915)->gt == 3)
629ac8140dbSDnyaneshwar Bhadane #define IS_COFFEELAKE_ULT(i915) \
63066ca1d8fSAndi Shyti IS_SUBPLATFORM(i915, INTEL_COFFEELAKE, INTEL_SUBPLATFORM_ULT)
631ac8140dbSDnyaneshwar Bhadane #define IS_COFFEELAKE_ULX(i915) \
63266ca1d8fSAndi Shyti IS_SUBPLATFORM(i915, INTEL_COFFEELAKE, INTEL_SUBPLATFORM_ULX)
633ac8140dbSDnyaneshwar Bhadane #define IS_COFFEELAKE_GT2(i915) (IS_COFFEELAKE(i915) && \
63466ca1d8fSAndi Shyti INTEL_INFO(i915)->gt == 2)
635ac8140dbSDnyaneshwar Bhadane #define IS_COFFEELAKE_GT3(i915) (IS_COFFEELAKE(i915) && \
63666ca1d8fSAndi Shyti INTEL_INFO(i915)->gt == 3)
6375f4ae270SChris Wilson
638bd7b8501SDnyaneshwar Bhadane #define IS_COMETLAKE_ULT(i915) \
63966ca1d8fSAndi Shyti IS_SUBPLATFORM(i915, INTEL_COMETLAKE, INTEL_SUBPLATFORM_ULT)
640bd7b8501SDnyaneshwar Bhadane #define IS_COMETLAKE_ULX(i915) \
64166ca1d8fSAndi Shyti IS_SUBPLATFORM(i915, INTEL_COMETLAKE, INTEL_SUBPLATFORM_ULX)
642bd7b8501SDnyaneshwar Bhadane #define IS_COMETLAKE_GT2(i915) (IS_COMETLAKE(i915) && \
64366ca1d8fSAndi Shyti INTEL_INFO(i915)->gt == 2)
6445f4ae270SChris Wilson
64566ca1d8fSAndi Shyti #define IS_ICL_WITH_PORT_F(i915) \
64666ca1d8fSAndi Shyti IS_SUBPLATFORM(i915, INTEL_ICELAKE, INTEL_SUBPLATFORM_PORTF)
6477a58bad0SSagar Arun Kamble
64848077b0bSDnyaneshwar Bhadane #define IS_TIGERLAKE_UY(i915) \
64966ca1d8fSAndi Shyti IS_SUBPLATFORM(i915, INTEL_TIGERLAKE, INTEL_SUBPLATFORM_UY)
6501d3cc7abSJosé Roberto de Souza
651e87a005dSJani Nikula
652c033a37cSMika Kuoppala
65361b088c5SSwathi Dhanavanthri
654613716bbSMika Kuoppala
655123f62deSMatt Roper
6560883d63bSCaz Yokoyama
657b2c6eaf2SJosé Roberto de Souza
658c1f110eeSJosé Roberto de Souza #define IS_XEHPSDV_GRAPHICS_STEP(__i915, since, until) \
659c1f110eeSJosé Roberto de Souza (IS_XEHPSDV(__i915) && IS_GRAPHICS_STEP(__i915, since, until))
660086df54eSLucas De Marchi
6612357f2b2SJouni Högander #define IS_MTL_DISPLAY_STEP(__i915, since, until) \
6622357f2b2SJouni Högander (IS_METEORLAKE(__i915) && \
6632357f2b2SJouni Högander IS_DISPLAY_STEP(__i915, since, until))
6642357f2b2SJouni Högander
665eda94a6eSMatt Roper #define IS_MTL_MEDIA_STEP(__i915, since, until) \
666eda94a6eSMatt Roper (IS_METEORLAKE(__i915) && \
667eda94a6eSMatt Roper IS_MEDIA_STEP(__i915, since, until))
668eda94a6eSMatt Roper
6699e22cfc5SMatt Roper /*
67086df4141SMatt Roper * DG2 hardware steppings are a bit unusual. The hardware design was forked to
67186df4141SMatt Roper * create three variants (G10, G11, and G12) which each have distinct
67286df4141SMatt Roper * workaround sets. The G11 and G12 forks of the DG2 design reset the GT
67386df4141SMatt Roper * stepping back to "A0" for their first iterations, even though they're more
67486df4141SMatt Roper * similar to a G10 B0 stepping and G10 C0 stepping respectively in terms of
67586df4141SMatt Roper * functionality and workarounds. However the display stepping does not reset
67686df4141SMatt Roper * in the same manner --- a specific stepping like "B0" has a consistent
67786df4141SMatt Roper * meaning regardless of whether it belongs to a G10, G11, or G12 DG2.
6789e22cfc5SMatt Roper *
6799e22cfc5SMatt Roper * TLDR: All GT workarounds and stepping-specific logic must be applied in
68086df4141SMatt Roper * relation to a specific subplatform (G10/G11/G12), whereas display workarounds
6819e22cfc5SMatt Roper * and stepping-specific logic will be applied with a general DG2-wide stepping
6829e22cfc5SMatt Roper * number.
6839e22cfc5SMatt Roper */
684c1f110eeSJosé Roberto de Souza #define IS_DG2_GRAPHICS_STEP(__i915, variant, since, until) \
6859e22cfc5SMatt Roper (IS_SUBPLATFORM(__i915, INTEL_DG2, INTEL_SUBPLATFORM_##variant) && \
686c1f110eeSJosé Roberto de Souza IS_GRAPHICS_STEP(__i915, since, until))
6879e22cfc5SMatt Roper
688c0234324SMatt Roper #define IS_DG2_DISPLAY_STEP(__i915, since, until) \
6899e22cfc5SMatt Roper (IS_DG2(__i915) && \
6909e22cfc5SMatt Roper IS_DISPLAY_STEP(__i915, since, until))
6919e22cfc5SMatt Roper
6928b449f1cSMatt Roper #define IS_PVC_BD_STEP(__i915, since, until) \
6938b449f1cSMatt Roper (IS_PONTEVECCHIO(__i915) && \
6948b449f1cSMatt Roper IS_BASEDIE_STEP(__i915, since, until))
6958b449f1cSMatt Roper
6968b449f1cSMatt Roper #define IS_PVC_CT_STEP(__i915, since, until) \
6978b449f1cSMatt Roper (IS_PONTEVECCHIO(__i915) && \
6988b449f1cSMatt Roper IS_GRAPHICS_STEP(__i915, since, until))
6998b449f1cSMatt Roper
70066ca1d8fSAndi Shyti #define IS_LP(i915) (INTEL_INFO(i915)->is_lp)
70166ca1d8fSAndi Shyti #define IS_GEN9_LP(i915) (GRAPHICS_VER(i915) == 9 && IS_LP(i915))
70266ca1d8fSAndi Shyti #define IS_GEN9_BC(i915) (GRAPHICS_VER(i915) == 9 && !IS_LP(i915))
7033e4274f8SAnder Conselvan de Oliveira
704242613afSDaniele Ceraolo Spurio #define __HAS_ENGINE(engine_mask, id) ((engine_mask) & BIT(id))
705792592e7SDaniele Ceraolo Spurio #define HAS_ENGINE(gt, id) __HAS_ENGINE((gt)->info.engine_mask, id)
706a19d6ff2STvrtko Ursulin
707472098c8SDaniele Ceraolo Spurio #define __ENGINE_INSTANCES_MASK(mask, first, count) ({ \
70897ee6e92SDaniele Ceraolo Spurio unsigned int first__ = (first); \
70997ee6e92SDaniele Ceraolo Spurio unsigned int count__ = (count); \
710472098c8SDaniele Ceraolo Spurio ((mask) & GENMASK(first__ + count__ - 1, first__)) >> first__; \
71197ee6e92SDaniele Ceraolo Spurio })
712472098c8SDaniele Ceraolo Spurio
713472098c8SDaniele Ceraolo Spurio #define ENGINE_INSTANCES_MASK(gt, first, count) \
714472098c8SDaniele Ceraolo Spurio __ENGINE_INSTANCES_MASK((gt)->info.engine_mask, first, count)
715472098c8SDaniele Ceraolo Spurio
716f9576e36SMatt Roper #define RCS_MASK(gt) \
717f9576e36SMatt Roper ENGINE_INSTANCES_MASK(gt, RCS0, I915_MAX_RCS)
718e41388d5SMatt Roper #define BCS_MASK(gt) \
719e41388d5SMatt Roper ENGINE_INSTANCES_MASK(gt, BCS0, I915_MAX_BCS)
720242613afSDaniele Ceraolo Spurio #define VDBOX_MASK(gt) \
721242613afSDaniele Ceraolo Spurio ENGINE_INSTANCES_MASK(gt, VCS0, I915_MAX_VCS)
722242613afSDaniele Ceraolo Spurio #define VEBOX_MASK(gt) \
723242613afSDaniele Ceraolo Spurio ENGINE_INSTANCES_MASK(gt, VECS0, I915_MAX_VECS)
724505c4857SMatt Roper #define CCS_MASK(gt) \
725505c4857SMatt Roper ENGINE_INSTANCES_MASK(gt, CCS0, I915_MAX_CCS)
72697ee6e92SDaniele Ceraolo Spurio
72766ca1d8fSAndi Shyti #define HAS_MEDIA_RATIO_MODE(i915) (INTEL_INFO(i915)->has_media_ratio_mode)
72885a040bcSAshutosh Dixit
7294f7af194SJon Bloomfield /*
7304f7af194SJon Bloomfield * The Gen7 cmdparser copies the scanned buffer to the ggtt for execution
7314f7af194SJon Bloomfield * All later gens can run the final buffer from the ppgtt
7324f7af194SJon Bloomfield */
73366ca1d8fSAndi Shyti #define CMDPARSER_USES_GGTT(i915) (GRAPHICS_VER(i915) == 7)
7344f7af194SJon Bloomfield
73566ca1d8fSAndi Shyti #define HAS_LLC(i915) (INTEL_INFO(i915)->has_llc)
73666ca1d8fSAndi Shyti #define HAS_4TILE(i915) (INTEL_INFO(i915)->has_4tile)
73766ca1d8fSAndi Shyti #define HAS_SNOOP(i915) (INTEL_INFO(i915)->has_snoop)
73866ca1d8fSAndi Shyti #define HAS_EDRAM(i915) ((i915)->edram_size_mb)
73966ca1d8fSAndi Shyti #define HAS_SECURE_BATCHES(i915) (GRAPHICS_VER(i915) < 6)
74066ca1d8fSAndi Shyti #define HAS_WT(i915) HAS_EDRAM(i915)
741cae5852dSZou Nan hai
74266ca1d8fSAndi Shyti #define HWS_NEEDS_PHYSICAL(i915) (INTEL_INFO(i915)->hws_needs_physical)
7431d2a314cSDaniel Vetter
74466ca1d8fSAndi Shyti #define HAS_LOGICAL_RING_CONTEXTS(i915) \
74566ca1d8fSAndi Shyti (INTEL_INFO(i915)->has_logical_ring_contexts)
74666ca1d8fSAndi Shyti #define HAS_LOGICAL_RING_ELSQ(i915) \
74766ca1d8fSAndi Shyti (INTEL_INFO(i915)->has_logical_ring_elsq)
748fb5c551aSChris Wilson
74966ca1d8fSAndi Shyti #define HAS_EXECLISTS(i915) HAS_LOGICAL_RING_CONTEXTS(i915)
750fb5c551aSChris Wilson
75166ca1d8fSAndi Shyti #define INTEL_PPGTT(i915) (RUNTIME_INFO(i915)->ppgtt_type)
75266ca1d8fSAndi Shyti #define HAS_PPGTT(i915) \
75366ca1d8fSAndi Shyti (INTEL_PPGTT(i915) != INTEL_PPGTT_NONE)
75466ca1d8fSAndi Shyti #define HAS_FULL_PPGTT(i915) \
75566ca1d8fSAndi Shyti (INTEL_PPGTT(i915) >= INTEL_PPGTT_FULL)
7564bdafb9dSChris Wilson
75766ca1d8fSAndi Shyti #define HAS_PAGE_SIZES(i915, sizes) ({ \
758a5c08166SMatthew Auld GEM_BUG_ON((sizes) == 0); \
75966ca1d8fSAndi Shyti ((sizes) & ~RUNTIME_INFO(i915)->page_sizes) == 0; \
760a5c08166SMatthew Auld })
7610031fb96STvrtko Ursulin
762b45305fcSDaniel Vetter /* Early gen2 have a totally busted CS tlb and require pinned batches. */
76366ca1d8fSAndi Shyti #define HAS_BROKEN_CS_TLB(i915) (IS_I830(i915) || IS_I845G(i915))
76406e668acSMika Kuoppala
76566ca1d8fSAndi Shyti #define NEEDS_RC6_CTX_CORRUPTION_WA(i915) \
76666ca1d8fSAndi Shyti (IS_BROADWELL(i915) || GRAPHICS_VER(i915) == 9)
7672248a283SImre Deak
768d66047e4SRodrigo Vivi /* WaRsDisableCoarsePowerGating:skl,cnl */
76966ca1d8fSAndi Shyti #define NEEDS_WaRsDisableCoarsePowerGating(i915) \
770bd21470fSDnyaneshwar Bhadane (IS_SKYLAKE_GT3(i915) || IS_SKYLAKE_GT4(i915))
771185c66e5SMika Kuoppala
772cae5852dSZou Nan hai /* With the 945 and later, Y tiling got adjusted so that it was 32 128-byte
773cae5852dSZou Nan hai * rows, which changed the alignment requirements and fence programming.
774cae5852dSZou Nan hai */
77566ca1d8fSAndi Shyti #define HAS_128_BYTE_Y_TILING(i915) (GRAPHICS_VER(i915) != 2 && \
77666ca1d8fSAndi Shyti !(IS_I915G(i915) || IS_I915GM(i915)))
777cae5852dSZou Nan hai
77866ca1d8fSAndi Shyti #define HAS_RC6(i915) (INTEL_INFO(i915)->has_rc6)
77966ca1d8fSAndi Shyti #define HAS_RC6p(i915) (INTEL_INFO(i915)->has_rc6p)
78066ca1d8fSAndi Shyti #define HAS_RC6pp(i915) (false) /* HW was never validated */
781fb6db0f5SChris Wilson
78266ca1d8fSAndi Shyti #define HAS_RPS(i915) (INTEL_INFO(i915)->has_rps)
783affa9354SPaulo Zanoni
78466ca1d8fSAndi Shyti #define HAS_HECI_PXP(i915) \
78566ca1d8fSAndi Shyti (INTEL_INFO(i915)->has_heci_pxp)
78691cbdb83SChris Wilson
78766ca1d8fSAndi Shyti #define HAS_HECI_GSCFI(i915) \
78866ca1d8fSAndi Shyti (INTEL_INFO(i915)->has_heci_gscfi)
7891e3dc1d8STomas Winkler
79066ca1d8fSAndi Shyti #define HAS_HECI_GSC(i915) (HAS_HECI_PXP(i915) || HAS_HECI_GSCFI(i915))
7911e3dc1d8STomas Winkler
79266ca1d8fSAndi Shyti #define HAS_RUNTIME_PM(i915) (INTEL_INFO(i915)->has_runtime_pm)
79366ca1d8fSAndi Shyti #define HAS_64BIT_RELOC(i915) (INTEL_INFO(i915)->has_64bit_reloc)
7941e3dc1d8STomas Winkler
79566ca1d8fSAndi Shyti #define HAS_OA_BPC_REPORTING(i915) \
79666ca1d8fSAndi Shyti (INTEL_INFO(i915)->has_oa_bpc_reporting)
79766ca1d8fSAndi Shyti #define HAS_OA_SLICE_CONTRIB_LIMITS(i915) \
79866ca1d8fSAndi Shyti (INTEL_INFO(i915)->has_oa_slice_contrib_limits)
79966ca1d8fSAndi Shyti #define HAS_OAM(i915) \
80066ca1d8fSAndi Shyti (INTEL_INFO(i915)->has_oam)
801cceb0849SUmesh Nerlige Ramappa
802c83125bbSStuart Summers /*
803c83125bbSStuart Summers * Set this flag, when platform requires 64K GTT page sizes or larger for
804132aaaf0SRamalingam C * device local memory access.
805c83125bbSStuart Summers */
80666ca1d8fSAndi Shyti #define HAS_64K_PAGES(i915) (INTEL_INFO(i915)->has_64k_pages)
807c83125bbSStuart Summers
8088776711eSJani Nikula #define HAS_REGION(i915, i) (INTEL_INFO(i915)->memory_regions & (i))
809b908be54SMatthew Auld #define HAS_LMEM(i915) HAS_REGION(i915, REGION_LMEM)
8103aae9d08SAbdiel Janulgue
81166ca1d8fSAndi Shyti #define HAS_EXTRA_GT_LIST(i915) (INTEL_INFO(i915)->extra_gt_list)
81270fff19aSMatt Roper
8135e3094cfSCQ Tang /*
8145e3094cfSCQ Tang * Platform has the dedicated compression control state for each lmem surfaces
8155e3094cfSCQ Tang * stored in lmem to support the 3D and media compression formats.
8165e3094cfSCQ Tang */
81766ca1d8fSAndi Shyti #define HAS_FLAT_CCS(i915) (INTEL_INFO(i915)->has_flat_ccs)
8185e3094cfSCQ Tang
81966ca1d8fSAndi Shyti #define HAS_GT_UC(i915) (INTEL_INFO(i915)->has_gt_uc)
8202fe2d4e3SMichal Wajdeczko
82166ca1d8fSAndi Shyti #define HAS_POOLED_EU(i915) (RUNTIME_INFO(i915)->has_pooled_eu)
82233e141edSarun.siluvery@linux.intel.com
82366ca1d8fSAndi Shyti #define HAS_GLOBAL_MOCS_REGISTERS(i915) (INTEL_INFO(i915)->has_global_mocs)
824a7a7a0e6SMichel Thierry
825c2c70752SMatt Roper #define HAS_GMD_ID(i915) (INTEL_INFO(i915)->has_gmd_id)
826c2c70752SMatt Roper
8279d67edbaSAyaz A Siddiqui #define HAS_L3_CCS_READ(i915) (INTEL_INFO(i915)->has_l3_ccs_read)
8289d67edbaSAyaz A Siddiqui
829040d2baaSBen Widawsky /* DPF == dynamic parity feature */
83066ca1d8fSAndi Shyti #define HAS_L3_DPF(i915) (INTEL_INFO(i915)->has_l3_dpf)
831927a8e38SDnyaneshwar Bhadane #define NUM_L3_SLICES(i915) (IS_HASWELL_GT3(i915) ? \
83266ca1d8fSAndi Shyti 2 : HAS_L3_DPF(i915))
833e1ef7cc2SBen Widawsky
834a2b69ea4SJani Nikula /* Only valid when HAS_DISPLAY() is true */
83566ca1d8fSAndi Shyti #define INTEL_DISPLAY_ENABLED(i915) \
83666ca1d8fSAndi Shyti (drm_WARN_ON(&(i915)->drm, !HAS_DISPLAY(i915)), \
83766ca1d8fSAndi Shyti !(i915)->params.disable_display && \
83866ca1d8fSAndi Shyti !intel_opregion_headless_sku(i915))
839a2b69ea4SJani Nikula
84066ca1d8fSAndi Shyti #define HAS_GUC_DEPRIVILEGE(i915) \
84166ca1d8fSAndi Shyti (INTEL_INFO(i915)->has_guc_deprivilege)
842db3b3f3eSDaniele Ceraolo Spurio
8431eb31338SStuart Summers #define HAS_3D_PIPELINE(i915) (INTEL_INFO(i915)->has_3d_pipeline)
8441eb31338SStuart Summers
8455ac342efSMatt Roper #define HAS_ONE_EU_PER_FUSE_BIT(i915) (INTEL_INFO(i915)->has_one_eu_per_fuse_bit)
8465ac342efSMatt Roper
84703eababbSVille Syrjälä #define HAS_LMEMBAR_SMEM_STOLEN(i915) (!HAS_LMEM(i915) && \
848dbb2ffbfSAravind Iddamsetty GRAPHICS_VER_FULL(i915) >= IP_VER(12, 70))
849dbb2ffbfSAravind Iddamsetty
850c0e09200SDave Airlie #endif
851