Merge tag 'soc-drivers-6.9' of git://git.kernel.org/pub/scm/linux/kernel/git/soc/soc
[linux-block.git] / drivers / gpu / drm / xe / xe_device_types.h
CommitLineData
dd08ebf6
MB
1/* SPDX-License-Identifier: MIT */
2/*
7f075300 3 * Copyright © 2022-2023 Intel Corporation
dd08ebf6
MB
4 */
5
6#ifndef _XE_DEVICE_TYPES_H_
7#define _XE_DEVICE_TYPES_H_
8
9#include <linux/pci.h>
10
11#include <drm/drm_device.h>
12#include <drm/drm_file.h>
13#include <drm/ttm/ttm_device.h>
14
e7994850 15#include "xe_devcoredump_types.h"
87a4c85d 16#include "xe_heci_gsc.h"
dd08ebf6 17#include "xe_gt_types.h"
b1d20405 18#include "xe_lmtt_types.h"
dd08ebf6 19#include "xe_platform_types.h"
0d68247e 20#include "xe_pt_types.h"
13e5c32c 21#include "xe_sriov_types.h"
dd08ebf6
MB
22#include "xe_step_types.h"
23
44e69495
ML
24#if IS_ENABLED(CONFIG_DRM_XE_DISPLAY)
25#include "soc/intel_pch.h"
26#include "intel_display_core.h"
27#include "intel_display_device.h"
28#endif
29
ad703e06 30struct xe_ggtt;
b445be57 31struct xe_pat_ops;
ad703e06 32
dd08ebf6
MB
33#define XE_BO_INVALID_OFFSET LONG_MAX
34
35#define GRAPHICS_VER(xe) ((xe)->info.graphics_verx100 / 100)
36#define MEDIA_VER(xe) ((xe)->info.media_verx100 / 100)
37#define GRAPHICS_VERx100(xe) ((xe)->info.graphics_verx100)
38#define MEDIA_VERx100(xe) ((xe)->info.media_verx100)
39#define IS_DGFX(xe) ((xe)->info.is_dgfx)
437d7a84 40#define HAS_HECI_GSCFI(xe) ((xe)->info.has_heci_gscfi)
dd08ebf6
MB
41
42#define XE_VRAM_FLAGS_NEED64K BIT(0)
43
44#define XE_GT0 0
45#define XE_GT1 1
a5edc7cd 46#define XE_MAX_TILES_PER_DEVICE (XE_GT1 + 1)
dd08ebf6
MB
47
48#define XE_MAX_ASID (BIT(20))
49
50#define IS_PLATFORM_STEP(_xe, _platform, min_step, max_step) \
51 ((_xe)->info.platform == (_platform) && \
52 (_xe)->info.step.graphics >= (min_step) && \
53 (_xe)->info.step.graphics < (max_step))
54#define IS_SUBPLATFORM_STEP(_xe, _platform, sub, min_step, max_step) \
55 ((_xe)->info.platform == (_platform) && \
56 (_xe)->info.subplatform == (sub) && \
57 (_xe)->info.step.graphics >= (min_step) && \
58 (_xe)->info.step.graphics < (max_step))
59
a5edc7cd
MR
60#define tile_to_xe(tile__) \
61 _Generic(tile__, \
4cd6d492
FD
62 const struct xe_tile * : (const struct xe_device *)((tile__)->xe), \
63 struct xe_tile * : (tile__)->xe)
a5edc7cd 64
0887a2e7
OZ
65/**
66 * struct xe_mem_region - memory region structure
67 * This is used to describe a memory region in xe
68 * device, such as HBM memory or CXL extension memory.
69 */
70struct xe_mem_region {
71 /** @io_start: IO start address of this VRAM instance */
72 resource_size_t io_start;
73 /**
74 * @io_size: IO size of this VRAM instance
75 *
76 * This represents how much of this VRAM we can access
77 * via the CPU through the VRAM BAR. This can be smaller
78 * than @usable_size, in which case only part of VRAM is CPU
79 * accessible (typically the first 256M). This
80 * configuration is known as small-bar.
81 */
82 resource_size_t io_size;
83 /** @dpa_base: This memory regions's DPA (device physical address) base */
84 resource_size_t dpa_base;
85 /**
86 * @usable_size: usable size of VRAM
87 *
88 * Usable size of VRAM excluding reserved portions
89 * (e.g stolen mem)
90 */
91 resource_size_t usable_size;
92 /**
93 * @actual_physical_size: Actual VRAM size
94 *
95 * Actual VRAM size including reserved portions
96 * (e.g stolen mem)
97 */
98 resource_size_t actual_physical_size;
99 /** @mapping: pointer to VRAM mappable space */
77232e6a 100 void __iomem *mapping;
0887a2e7
OZ
101};
102
a5edc7cd
MR
103/**
104 * struct xe_tile - hardware tile structure
105 *
106 * From a driver perspective, a "tile" is effectively a complete GPU, containing
107 * an SGunit, 1-2 GTs, and (for discrete platforms) VRAM.
108 *
109 * Multi-tile platforms effectively bundle multiple GPUs behind a single PCI
110 * device and designate one "root" tile as being responsible for external PCI
111 * communication. PCI BAR0 exposes the GGTT and MMIO register space for each
112 * tile in a stacked layout, and PCI BAR2 exposes the local memory associated
113 * with each tile similarly. Device-wide interrupts can be enabled/disabled
114 * at the root tile, and the MSTR_TILE_INTR register will report which tiles
115 * have interrupts that need servicing.
116 */
117struct xe_tile {
118 /** @xe: Backpointer to tile's PCI device */
119 struct xe_device *xe;
120
121 /** @id: ID of the tile */
122 u8 id;
123
124 /**
125 * @primary_gt: Primary GT
126 */
f6929e80 127 struct xe_gt *primary_gt;
a5edc7cd 128
e2682f61
MR
129 /**
130 * @media_gt: Media GT
131 *
132 * Only present on devices with media version >= 13.
133 */
134 struct xe_gt *media_gt;
3b0d4a55
MR
135
136 /**
137 * @mmio: MMIO info for a tile.
138 *
139 * Each tile has its own 16MB space in BAR0, laid out as:
140 * * 0-4MB: registers
141 * * 4MB-8MB: reserved
142 * * 8MB-16MB: global GTT
143 */
144 struct {
145 /** @size: size of tile's MMIO space */
146 size_t size;
147
148 /** @regs: pointer to tile's MMIO space (starting with registers) */
5c63e757 149 void __iomem *regs;
3b0d4a55 150 } mmio;
ad703e06 151
399a1332
KE
152 /**
153 * @mmio_ext: MMIO-extension info for a tile.
154 *
155 * Each tile has its own additional 256MB (28-bit) MMIO-extension space.
156 */
157 struct {
158 /** @size: size of tile's additional MMIO-extension space */
159 size_t size;
160
161 /** @regs: pointer to tile's additional MMIO-extension space */
5c63e757 162 void __iomem *regs;
399a1332
KE
163 } mmio_ext;
164
ad703e06
MR
165 /** @mem: memory management info for tile */
166 struct {
ebd288cb
MR
167 /**
168 * @vram: VRAM info for tile.
169 *
170 * Although VRAM is associated with a specific tile, it can
171 * still be accessed by all tiles' GTs.
172 */
0887a2e7 173 struct xe_mem_region vram;
ebd288cb
MR
174
175 /** @vram_mgr: VRAM TTM manager */
176 struct xe_ttm_vram_mgr *vram_mgr;
177
ad703e06
MR
178 /** @ggtt: Global graphics translation table */
179 struct xe_ggtt *ggtt;
876611c2
MR
180
181 /**
182 * @kernel_bb_pool: Pool from which batchbuffers are allocated.
183 *
184 * Media GT shares a pool with its primary GT.
185 */
186 struct xe_sa_manager *kernel_bb_pool;
ad703e06 187 } mem;
08dea767 188
b1d20405
MW
189 /** @sriov: tile level virtualization data */
190 union {
191 struct {
192 /** @sriov.pf.lmtt: Local Memory Translation Table. */
193 struct xe_lmtt lmtt;
194 } pf;
195 } sriov;
196
08dea767
MR
197 /** @migrate: Migration helper for vram blits and clearing */
198 struct xe_migrate *migrate;
e5a845fd
TU
199
200 /** @sysfs: sysfs' kobj used by xe_tile_sysfs */
201 struct kobject *sysfs;
a5edc7cd
MR
202};
203
dd08ebf6
MB
204/**
205 * struct xe_device - Top level struct of XE device
206 */
207struct xe_device {
208 /** @drm: drm device */
209 struct drm_device drm;
210
e7994850
RV
211 /** @devcoredump: device coredump */
212 struct xe_devcoredump devcoredump;
213
dd08ebf6
MB
214 /** @info: device info */
215 struct intel_device_info {
9a08b2b9
MR
216 /** @graphics_name: graphics IP name */
217 const char *graphics_name;
218 /** @media_name: media IP name */
219 const char *media_name;
866b2b17
KE
220 /** @tile_mmio_ext_size: size of MMIO extension space, per-tile */
221 u32 tile_mmio_ext_size;
dd08ebf6
MB
222 /** @graphics_verx100: graphics IP version */
223 u32 graphics_verx100;
224 /** @media_verx100: media IP version */
225 u32 media_verx100;
226 /** @mem_region_mask: mask of valid memory regions */
227 u32 mem_region_mask;
dd08ebf6
MB
228 /** @platform: XE platform enum */
229 enum xe_platform platform;
230 /** @subplatform: XE subplatform enum */
231 enum xe_subplatform subplatform;
232 /** @devid: device ID */
233 u16 devid;
234 /** @revid: device revision */
235 u8 revid;
236 /** @step: stepping information for each IP */
237 struct xe_step_info step;
238 /** @dma_mask_size: DMA address bits */
239 u8 dma_mask_size;
240 /** @vram_flags: Vram flags */
241 u8 vram_flags;
242 /** @tile_count: Number of tiles */
243 u8 tile_count;
37efea9c
MR
244 /** @gt_count: Total number of GTs for entire device */
245 u8 gt_count;
dd08ebf6
MB
246 /** @vm_max_level: Max VM level */
247 u8 vm_max_level;
e9bb0891
MR
248 /** @va_bits: Maximum bits of a virtual address */
249 u8 va_bits;
689f40f5
MR
250
251 /** @is_dgfx: is discrete device */
252 u8 is_dgfx:1;
5669899e 253 /** @has_asid: Has address space ID */
689f40f5 254 u8 has_asid:1;
c8dc1546
RV
255 /** @force_execlist: Forced execlist submission */
256 u8 force_execlist:1;
dd08ebf6 257 /** @has_flat_ccs: Whether flat CCS metadata is used */
689f40f5 258 u8 has_flat_ccs:1;
bf08dd47
MR
259 /** @has_llc: Device has a shared CPU+GPU last level cache */
260 u8 has_llc:1;
5a92da34
LDM
261 /** @has_mmio_ext: Device has extra MMIO address range */
262 u8 has_mmio_ext:1;
9d25e284 263 /** @has_range_tlb_invalidation: Has range based TLB invalidations */
689f40f5 264 u8 has_range_tlb_invalidation:1;
d6d14854
MW
265 /** @has_sriov: Supports SR-IOV */
266 u8 has_sriov:1;
5a92da34
LDM
267 /** @has_usm: Device has unified shared memory support */
268 u8 has_usm:1;
44e69495
ML
269 /** @enable_display: display enabled */
270 u8 enable_display:1;
0c923a68
KE
271 /** @skip_mtcfg: skip Multi-Tile configuration from MTCFG register */
272 u8 skip_mtcfg:1;
082802a3
KE
273 /** @skip_pcode: skip access to PCODE uC */
274 u8 skip_pcode:1;
437d7a84
VL
275 /** @has_heci_gscfi: device has heci gscfi */
276 u8 has_heci_gscfi:1;
f1cb5f64
VB
277 /** @skip_guc_pc: Skip GuC based PM feature init */
278 u8 skip_guc_pc:1;
44e69495
ML
279
280#if IS_ENABLED(CONFIG_DRM_XE_DISPLAY)
281 struct {
282 u32 rawclk_freq;
283 } i915_runtime;
284#endif
dd08ebf6
MB
285 } info;
286
287 /** @irq: device interrupt state */
288 struct {
289 /** @lock: lock for processing irq's on this device */
290 spinlock_t lock;
291
292 /** @enabled: interrupts enabled on this device */
293 bool enabled;
294 } irq;
295
296 /** @ttm: ttm device */
297 struct ttm_device ttm;
298
299 /** @mmio: mmio info for device */
300 struct {
301 /** @size: size of MMIO space for device */
302 size_t size;
303 /** @regs: pointer to MMIO space for device */
5c63e757 304 void __iomem *regs;
dd08ebf6
MB
305 } mmio;
306
307 /** @mem: memory info for device */
308 struct {
309 /** @vram: VRAM info for device */
0887a2e7 310 struct xe_mem_region vram;
1a545ed7
CB
311 /** @sys_mgr: system TTM manager */
312 struct ttm_resource_manager sys_mgr;
dd08ebf6
MB
313 } mem;
314
13e5c32c
MW
315 /** @sriov: device level virtualization data */
316 struct {
317 /** @sriov.__mode: SR-IOV mode (Don't access directly!) */
318 enum xe_sriov_mode __mode;
319 } sriov;
320
78e2701a
NV
321 /** @clients: drm clients info */
322 struct {
323 /** @lock: Protects drm clients info */
324 spinlock_t lock;
325
326 /** @count: number of drm clients */
327 u64 count;
328 } clients;
329
dd08ebf6
MB
330 /** @usm: unified memory state */
331 struct {
332 /** @asid: convert a ASID to VM */
333 struct xarray asid_to_vm;
334 /** @next_asid: next ASID, used to cyclical alloc asids */
335 u32 next_asid;
336 /** @num_vm_in_fault_mode: number of VM in fault mode */
337 u32 num_vm_in_fault_mode;
338 /** @num_vm_in_non_fault_mode: number of VM in non-fault mode */
339 u32 num_vm_in_non_fault_mode;
340 /** @lock: protects UM state */
341 struct mutex lock;
342 } usm;
343
dd08ebf6
MB
344 /** @pinned: pinned BO state */
345 struct {
346 /** @lock: protected pinned BO list state */
347 spinlock_t lock;
348 /** @evicted: pinned kernel BO that are present */
349 struct list_head kernel_bo_present;
350 /** @evicted: pinned BO that have been evicted */
351 struct list_head evicted;
352 /** @external_vram: pinned external BO in vram*/
353 struct list_head external_vram;
354 } pinned;
355
356 /** @ufence_wq: user fence wait queue */
357 wait_queue_head_t ufence_wq;
358
359 /** @ordered_wq: used to serialize compute mode resume */
360 struct workqueue_struct *ordered_wq;
361
44e69495
ML
362 /** @unordered_wq: used to serialize unordered work, mostly display */
363 struct workqueue_struct *unordered_wq;
364
a5edc7cd
MR
365 /** @tiles: device tiles */
366 struct xe_tile tiles[XE_MAX_TILES_PER_DEVICE];
dd08ebf6
MB
367
368 /**
369 * @mem_access: keep track of memory access in the device, possibly
370 * triggering additional actions when they occur.
371 */
372 struct {
dd08ebf6 373 /** @ref: ref count of memory accesses */
38c04b47 374 atomic_t ref;
dd08ebf6
MB
375 } mem_access;
376
b445be57
LDM
377 /**
378 * @pat: Encapsulate PAT related stuff
379 */
380 struct {
381 /** Internal operations to abstract platforms */
382 const struct xe_pat_ops *ops;
383 /** PAT table to program in the HW */
f6a22e68 384 const struct xe_pat_table_entry *table;
b445be57
LDM
385 /** Number of PAT entries */
386 int n_entries;
0d68247e 387 u32 idx[__XE_CACHE_LEVEL_COUNT];
b445be57
LDM
388 } pat;
389
b2d75619
AG
390 /** @d3cold: Encapsulate d3cold related stuff */
391 struct {
392 /** capable: Indicates if root port is d3cold capable */
393 bool capable;
394
395 /** @allowed: Indicates if d3cold is a valid device state */
396 bool allowed;
ac0be3b5 397
09d88e3b
AG
398 /** @power_lost: Indicates if card has really lost power. */
399 bool power_lost;
400
b2d75619
AG
401 /**
402 * @vram_threshold:
403 *
404 * This represents the permissible threshold(in megabytes)
405 * for vram save/restore. d3cold will be disallowed,
406 * when vram_usages is above or equals the threshold value
407 * to avoid the vram save/restore latency.
408 * Default threshold value is 300mb.
409 */
410 u32 vram_threshold;
411 /** @lock: protect vram_threshold */
412 struct mutex lock;
413 } d3cold;
dd08ebf6 414
a00b8f1a
MA
415 /**
416 * @pm_callback_task: Track the active task that is running in either
417 * the runtime_suspend or runtime_resume callbacks.
418 */
419 struct task_struct *pm_callback_task;
420
fb1b7060
BN
421 /** @hwmon: hwmon subsystem integration */
422 struct xe_hwmon *hwmon;
423
87a4c85d
VL
424 /** @heci_gsc: graphics security controller */
425 struct xe_heci_gsc heci_gsc;
426
57162274
AH
427 /** @needs_flr_on_fini: requests function-reset on fini */
428 bool needs_flr_on_fini;
429
e5b6e616
LDM
430 /* private: */
431
44e69495
ML
432#if IS_ENABLED(CONFIG_DRM_XE_DISPLAY)
433 /*
434 * Any fields below this point are the ones used by display.
435 * They are temporarily added here so xe_device can be desguised as
436 * drm_i915_private during build. After cleanup these should go away,
437 * migrating to the right sub-structs
438 */
439 struct intel_display display;
440 enum intel_pch pch_type;
441 u16 pch_id;
442
443 struct dram_info {
444 bool wm_lv_0_adjust_needed;
445 u8 num_channels;
446 bool symmetric_memory;
447 enum intel_dram_type {
448 INTEL_DRAM_UNKNOWN,
449 INTEL_DRAM_DDR3,
450 INTEL_DRAM_DDR4,
451 INTEL_DRAM_LPDDR3,
452 INTEL_DRAM_LPDDR4,
453 INTEL_DRAM_DDR5,
454 INTEL_DRAM_LPDDR5,
455 } type;
456 u8 num_qgv_points;
457 u8 num_psf_gv_points;
458 } dram_info;
459
460 /*
461 * edram size in MB.
462 * Cannot be determined by PCIID. You must always read a register.
463 */
464 u32 edram_size_mb;
465
466 /* To shut up runtime pm macros.. */
467 struct xe_runtime_pm {} runtime_pm;
468
dd08ebf6
MB
469 /* For pcode */
470 struct mutex sb_lock;
471
44e69495
ML
472 /* Should be in struct intel_display */
473 u32 skl_preferred_vco_freq, max_dotclk_freq, hti_state;
474 u8 snps_phy_failed_calibration;
475 struct drm_atomic_state *modeset_restore_state;
476 struct list_head global_obj_list;
477
478 union {
479 /* only to allow build, not used functionally */
480 u32 irq_mask;
481 u32 de_irq_mask[I915_MAX_PIPES];
482 };
483 u32 pipestat_irq_mask[I915_MAX_PIPES];
484
485 bool display_irqs_enabled;
dd08ebf6 486 u32 enabled_irq_mask;
44e69495
ML
487
488 struct intel_uncore {
489 spinlock_t lock;
490 } uncore;
491
492 /* only to allow build, not used functionally */
493 struct {
494 unsigned int hpll_freq;
495 unsigned int czclk_freq;
496 unsigned int fsb_freq, mem_freq, is_ddr3;
497 u8 vblank_enabled;
498 };
499 struct {
500 const char *dmc_firmware_path;
501 } params;
502
503 void *pxp;
504#endif
dd08ebf6
MB
505};
506
507/**
508 * struct xe_file - file handle for XE driver
509 */
510struct xe_file {
8f965392
TU
511 /** @xe: xe DEVICE **/
512 struct xe_device *xe;
513
dd08ebf6
MB
514 /** @drm: base DRM file */
515 struct drm_file *drm;
516
517 /** @vm: VM state for file */
518 struct {
519 /** @xe: xarray to store VMs */
520 struct xarray xa;
521 /** @lock: protects file VM state */
522 struct mutex lock;
523 } vm;
524
9b9529ce 525 /** @exec_queue: Submission exec queue state for file */
dd08ebf6
MB
526 struct {
527 /** @xe: xarray to store engines */
528 struct xarray xa;
529 /** @lock: protects file engine state */
530 struct mutex lock;
9b9529ce 531 } exec_queue;
8f965392
TU
532
533 /** @client: drm client */
534 struct xe_drm_client *client;
dd08ebf6
MB
535};
536
537#endif