drm/xe: Move migration from GT to tile
[linux-2.6-microblaze.git] / drivers / gpu / drm / xe / xe_device_types.h
1 /* SPDX-License-Identifier: MIT */
2 /*
3  * Copyright © 2022-2023 Intel Corporation
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
15 #include "xe_devcoredump_types.h"
16 #include "xe_gt_types.h"
17 #include "xe_platform_types.h"
18 #include "xe_step_types.h"
19
20 struct xe_ggtt;
21
22 #define XE_BO_INVALID_OFFSET    LONG_MAX
23
24 #define GRAPHICS_VER(xe) ((xe)->info.graphics_verx100 / 100)
25 #define MEDIA_VER(xe) ((xe)->info.media_verx100 / 100)
26 #define GRAPHICS_VERx100(xe) ((xe)->info.graphics_verx100)
27 #define MEDIA_VERx100(xe) ((xe)->info.media_verx100)
28 #define IS_DGFX(xe) ((xe)->info.is_dgfx)
29
30 #define XE_VRAM_FLAGS_NEED64K           BIT(0)
31
32 #define XE_GT0          0
33 #define XE_GT1          1
34 #define XE_MAX_TILES_PER_DEVICE (XE_GT1 + 1)
35
36 #define XE_MAX_ASID     (BIT(20))
37
38 #define IS_PLATFORM_STEP(_xe, _platform, min_step, max_step)    \
39         ((_xe)->info.platform == (_platform) &&                 \
40          (_xe)->info.step.graphics >= (min_step) &&             \
41          (_xe)->info.step.graphics < (max_step))
42 #define IS_SUBPLATFORM_STEP(_xe, _platform, sub, min_step, max_step)    \
43         ((_xe)->info.platform == (_platform) &&                         \
44          (_xe)->info.subplatform == (sub) &&                            \
45          (_xe)->info.step.graphics >= (min_step) &&                     \
46          (_xe)->info.step.graphics < (max_step))
47
48 #define tile_to_xe(tile__)                                                              \
49         _Generic(tile__,                                                                \
50                  const struct xe_tile *: (const struct xe_device *)((tile__)->xe),      \
51                  struct xe_tile *: (tile__)->xe)
52
53 /**
54  * struct xe_tile - hardware tile structure
55  *
56  * From a driver perspective, a "tile" is effectively a complete GPU, containing
57  * an SGunit, 1-2 GTs, and (for discrete platforms) VRAM.
58  *
59  * Multi-tile platforms effectively bundle multiple GPUs behind a single PCI
60  * device and designate one "root" tile as being responsible for external PCI
61  * communication.  PCI BAR0 exposes the GGTT and MMIO register space for each
62  * tile in a stacked layout, and PCI BAR2 exposes the local memory associated
63  * with each tile similarly.  Device-wide interrupts can be enabled/disabled
64  * at the root tile, and the MSTR_TILE_INTR register will report which tiles
65  * have interrupts that need servicing.
66  */
67 struct xe_tile {
68         /** @xe: Backpointer to tile's PCI device */
69         struct xe_device *xe;
70
71         /** @id: ID of the tile */
72         u8 id;
73
74         /**
75          * @primary_gt: Primary GT
76          */
77         struct xe_gt primary_gt;
78
79         /* TODO: Add media GT here */
80
81         /**
82          * @mmio: MMIO info for a tile.
83          *
84          * Each tile has its own 16MB space in BAR0, laid out as:
85          * * 0-4MB: registers
86          * * 4MB-8MB: reserved
87          * * 8MB-16MB: global GTT
88          */
89         struct {
90                 /** @size: size of tile's MMIO space */
91                 size_t size;
92
93                 /** @regs: pointer to tile's MMIO space (starting with registers) */
94                 void *regs;
95         } mmio;
96
97         /** @mem: memory management info for tile */
98         struct {
99                 /**
100                  * @vram: VRAM info for tile.
101                  *
102                  * Although VRAM is associated with a specific tile, it can
103                  * still be accessed by all tiles' GTs.
104                  */
105                 struct {
106                         /** @io_start: IO start address of this VRAM instance */
107                         resource_size_t io_start;
108                         /**
109                          * @io_size: IO size of this VRAM instance
110                          *
111                          * This represents how much of this VRAM we can access
112                          * via the CPU through the VRAM BAR. This can be smaller
113                          * than @size, in which case only part of VRAM is CPU
114                          * accessible (typically the first 256M). This
115                          * configuration is known as small-bar.
116                          */
117                         resource_size_t io_size;
118                         /** @base: offset of VRAM starting base */
119                         resource_size_t base;
120                         /** @size: size of VRAM. */
121                         resource_size_t size;
122                         /** @mapping: pointer to VRAM mappable space */
123                         void *__iomem mapping;
124                 } vram;
125
126                 /** @vram_mgr: VRAM TTM manager */
127                 struct xe_ttm_vram_mgr *vram_mgr;
128
129                 /** @ggtt: Global graphics translation table */
130                 struct xe_ggtt *ggtt;
131
132                 /**
133                  * @kernel_bb_pool: Pool from which batchbuffers are allocated.
134                  *
135                  * Media GT shares a pool with its primary GT.
136                  */
137                 struct xe_sa_manager *kernel_bb_pool;
138         } mem;
139
140         /** @migrate: Migration helper for vram blits and clearing */
141         struct xe_migrate *migrate;
142 };
143
144 /**
145  * struct xe_device - Top level struct of XE device
146  */
147 struct xe_device {
148         /** @drm: drm device */
149         struct drm_device drm;
150
151         /** @devcoredump: device coredump */
152         struct xe_devcoredump devcoredump;
153
154         /** @info: device info */
155         struct intel_device_info {
156                 /** @graphics_name: graphics IP name */
157                 const char *graphics_name;
158                 /** @media_name: media IP name */
159                 const char *media_name;
160                 /** @graphics_verx100: graphics IP version */
161                 u32 graphics_verx100;
162                 /** @media_verx100: media IP version */
163                 u32 media_verx100;
164                 /** @mem_region_mask: mask of valid memory regions */
165                 u32 mem_region_mask;
166                 /** @platform: XE platform enum */
167                 enum xe_platform platform;
168                 /** @subplatform: XE subplatform enum */
169                 enum xe_subplatform subplatform;
170                 /** @devid: device ID */
171                 u16 devid;
172                 /** @revid: device revision */
173                 u8 revid;
174                 /** @step: stepping information for each IP */
175                 struct xe_step_info step;
176                 /** @dma_mask_size: DMA address bits */
177                 u8 dma_mask_size;
178                 /** @vram_flags: Vram flags */
179                 u8 vram_flags;
180                 /** @tile_count: Number of tiles */
181                 u8 tile_count;
182                 /** @vm_max_level: Max VM level */
183                 u8 vm_max_level;
184
185                 /** @is_dgfx: is discrete device */
186                 u8 is_dgfx:1;
187                 /** @supports_usm: Supports unified shared memory */
188                 u8 supports_usm:1;
189                 /** @has_asid: Has address space ID */
190                 u8 has_asid:1;
191                 /** @enable_guc: GuC submission enabled */
192                 u8 enable_guc:1;
193                 /** @has_flat_ccs: Whether flat CCS metadata is used */
194                 u8 has_flat_ccs:1;
195                 /** @has_4tile: Whether tile-4 tiling is supported */
196                 u8 has_4tile:1;
197                 /** @has_llc: Device has a shared CPU+GPU last level cache */
198                 u8 has_llc:1;
199                 /** @has_range_tlb_invalidation: Has range based TLB invalidations */
200                 u8 has_range_tlb_invalidation:1;
201                 /** @has_link_copy_engines: Whether the platform has link copy engines */
202                 u8 has_link_copy_engine:1;
203         } info;
204
205         /** @irq: device interrupt state */
206         struct {
207                 /** @lock: lock for processing irq's on this device */
208                 spinlock_t lock;
209
210                 /** @enabled: interrupts enabled on this device */
211                 bool enabled;
212         } irq;
213
214         /** @ttm: ttm device */
215         struct ttm_device ttm;
216
217         /** @mmio: mmio info for device */
218         struct {
219                 /** @size: size of MMIO space for device */
220                 size_t size;
221                 /** @regs: pointer to MMIO space for device */
222                 void *regs;
223         } mmio;
224
225         /** @mem: memory info for device */
226         struct {
227                 /** @vram: VRAM info for device */
228                 struct {
229                         /** @io_start: IO start address of VRAM */
230                         resource_size_t io_start;
231                         /**
232                          * @io_size: IO size of VRAM.
233                          *
234                          * This represents how much of VRAM the CPU can access
235                          * via the VRAM BAR.
236                          * On systems that do not support large BAR IO space,
237                          * this can be smaller than the actual memory size, in
238                          * which case only part of VRAM is CPU accessible
239                          * (typically the first 256M).  This configuration is
240                          * known as small-bar.
241                          */
242                         resource_size_t io_size;
243                         /** @size: Total size of VRAM */
244                         resource_size_t size;
245                         /** @base: Offset to apply for Device Physical Address control */
246                         resource_size_t base;
247                         /** @mapping: pointer to VRAM mappable space */
248                         void *__iomem mapping;
249                 } vram;
250                 /** @sys_mgr: system TTM manager */
251                 struct ttm_resource_manager sys_mgr;
252         } mem;
253
254         /** @usm: unified memory state */
255         struct {
256                 /** @asid: convert a ASID to VM */
257                 struct xarray asid_to_vm;
258                 /** @next_asid: next ASID, used to cyclical alloc asids */
259                 u32 next_asid;
260                 /** @num_vm_in_fault_mode: number of VM in fault mode */
261                 u32 num_vm_in_fault_mode;
262                 /** @num_vm_in_non_fault_mode: number of VM in non-fault mode */
263                 u32 num_vm_in_non_fault_mode;
264                 /** @lock: protects UM state */
265                 struct mutex lock;
266         } usm;
267
268         /** @persistent_engines: engines that are closed but still running */
269         struct {
270                 /** @lock: protects persistent engines */
271                 struct mutex lock;
272                 /** @list: list of persistent engines */
273                 struct list_head list;
274         } persistent_engines;
275
276         /** @pinned: pinned BO state */
277         struct {
278                 /** @lock: protected pinned BO list state */
279                 spinlock_t lock;
280                 /** @evicted: pinned kernel BO that are present */
281                 struct list_head kernel_bo_present;
282                 /** @evicted: pinned BO that have been evicted */
283                 struct list_head evicted;
284                 /** @external_vram: pinned external BO in vram*/
285                 struct list_head external_vram;
286         } pinned;
287
288         /** @ufence_wq: user fence wait queue */
289         wait_queue_head_t ufence_wq;
290
291         /** @ordered_wq: used to serialize compute mode resume */
292         struct workqueue_struct *ordered_wq;
293
294         /** @tiles: device tiles */
295         struct xe_tile tiles[XE_MAX_TILES_PER_DEVICE];
296
297         /**
298          * @mem_access: keep track of memory access in the device, possibly
299          * triggering additional actions when they occur.
300          */
301         struct {
302                 /** @ref: ref count of memory accesses */
303                 atomic_t ref;
304                 /** @hold_rpm: need to put rpm ref back at the end */
305                 bool hold_rpm;
306         } mem_access;
307
308         /** @d3cold_allowed: Indicates if d3cold is a valid device state */
309         bool d3cold_allowed;
310
311         /* For pcode */
312         struct mutex sb_lock;
313
314         u32 enabled_irq_mask;
315 };
316
317 /**
318  * struct xe_file - file handle for XE driver
319  */
320 struct xe_file {
321         /** @drm: base DRM file */
322         struct drm_file *drm;
323
324         /** @vm: VM state for file */
325         struct {
326                 /** @xe: xarray to store VMs */
327                 struct xarray xa;
328                 /** @lock: protects file VM state */
329                 struct mutex lock;
330         } vm;
331
332         /** @engine: Submission engine state for file */
333         struct {
334                 /** @xe: xarray to store engines */
335                 struct xarray xa;
336                 /** @lock: protects file engine state */
337                 struct mutex lock;
338         } engine;
339 };
340
341 #endif