projects/linux·blob master · refs

300 lines · 7.7 KiB

1/* SPDX-License-Identifier: MIT */
2/*
3 * Copyright © 2021 Intel Corporation
4 */
5
6#ifndef _XE_DEVICE_H_
7#define _XE_DEVICE_H_
8
9#include <drm/drm_util.h>
10
11#include "xe_device_types.h"
12#include "xe_gt_types.h"
13#include "xe_sriov.h"
14
15struct xe_vm;
16
17static inline struct xe_device *to_xe_device(const struct drm_device *dev)
18{
19 return container_of(dev, struct xe_device, drm);
20}
21
22static inline struct xe_device *kdev_to_xe_device(struct device *kdev)
23{
24 struct drm_device *drm = dev_get_drvdata(kdev);
25
26 return drm ? to_xe_device(drm) : NULL;
27}
28
29static inline struct xe_device *pdev_to_xe_device(struct pci_dev *pdev)
30{
31 struct drm_device *drm = pci_get_drvdata(pdev);
32
33 return drm ? to_xe_device(drm) : NULL;
34}
35
36static inline struct xe_device *xe_device_const_cast(const struct xe_device *xe)
37{
38 return (struct xe_device *)xe;
39}
40
41static inline struct xe_device *ttm_to_xe_device(struct ttm_device *ttm)
42{
43 return container_of(ttm, struct xe_device, ttm);
44}
45
46struct xe_device *xe_device_create(struct pci_dev *pdev);
47int xe_device_init_early(struct xe_device *xe);
48int xe_device_probe_early(struct xe_device *xe);
49int xe_device_probe(struct xe_device *xe);
50void xe_device_remove(struct xe_device *xe);
51void xe_device_shutdown(struct xe_device *xe);
52
53void xe_device_wmb(struct xe_device *xe);
54
55static inline struct xe_file *to_xe_file(const struct drm_file *file)
56{
57 return file->driver_priv;
58}
59
60static inline struct xe_tile *xe_device_get_root_tile(struct xe_device *xe)
61{
62 return &xe->tiles[0];
63}
64
65static inline struct xe_gt *xe_device_get_gt(struct xe_device *xe, u8 gt_id)
66{
67 struct xe_tile *tile;
68 struct xe_gt *gt;
69
70 if (gt_id >= xe->info.tile_count * xe->info.max_gt_per_tile)
71 return NULL;
72
73 tile = &xe->tiles[gt_id / xe->info.max_gt_per_tile];
74 switch (gt_id % xe->info.max_gt_per_tile) {
75 default:
76 xe_assert(xe, false);
77 fallthrough;
78 case 0:
79 gt = tile->primary_gt;
80 break;
81 case 1:
82 gt = tile->media_gt;
83 break;
84 }
85
86 if (!gt)
87 return NULL;
88
89 drm_WARN_ON(&xe->drm, gt->info.id != gt_id);
90 drm_WARN_ON(&xe->drm, gt->info.type == XE_GT_TYPE_UNINITIALIZED);
91
92 return gt;
93}
94
95/*
96 * Provide a GT structure suitable for performing non-GT MMIO operations against
97 * the primary tile. Primarily intended for early tile initialization, display
98 * handling, top-most interrupt enable/disable, etc. Since anything using the
99 * MMIO handle returned by this function doesn't need GSI offset translation,
100 * we'll return the primary GT from the root tile.
101 *
102 * FIXME: Fix the driver design so that 'gt' isn't the target of all MMIO
103 * operations.
104 *
105 * Returns the primary gt of the root tile.
106 */
107static inline struct xe_gt *xe_root_mmio_gt(struct xe_device *xe)
108{
109 return xe_device_get_root_tile(xe)->primary_gt;
110}
111
112static inline struct xe_mmio *xe_root_tile_mmio(struct xe_device *xe)
113{
114 return &xe->tiles[0].mmio;
115}
116
117static inline bool xe_device_uc_enabled(struct xe_device *xe)
118{
119 return true;
120}
121
122#define for_each_tile(tile__, xe__, id__) \
123 for ((id__) = 0; (id__) < (xe__)->info.tile_count; (id__)++) \
124 for_each_if((tile__) = &(xe__)->tiles[(id__)])
125
126#define for_each_remote_tile(tile__, xe__, id__) \
127 for ((id__) = 1; (id__) < (xe__)->info.tile_count; (id__)++) \
128 for_each_if((tile__) = &(xe__)->tiles[(id__)])
129
130#define for_each_gt(gt__, xe__, id__) \
131 for ((id__) = 0; (id__) < (xe__)->info.tile_count * (xe__)->info.max_gt_per_tile; (id__)++) \
132 for_each_if((gt__) = xe_device_get_gt((xe__), (id__)))
133
134#define for_each_gt_with_type(gt__, xe__, id__, typemask__) \
135 for_each_gt((gt__), (xe__), (id__)) \
136 for_each_if((typemask__) & BIT((gt__)->info.type))
137
138#define for_each_gt_on_tile(gt__, tile__, id__) \
139 for_each_gt((gt__), (tile__)->xe, (id__)) \
140 for_each_if((gt__)->tile == (tile__))
141
142static inline struct xe_force_wake *gt_to_fw(struct xe_gt *gt)
143{
144 return &gt->pm.fw;
145}
146
147void xe_device_assert_mem_access(struct xe_device *xe);
148
149static inline bool xe_device_has_flat_ccs(const struct xe_device *xe)
150{
151 return xe->info.has_flat_ccs;
152}
153
154static inline bool xe_device_has_sriov(const struct xe_device *xe)
155{
156 return xe->info.has_sriov;
157}
158
159static inline bool xe_device_has_msix(const struct xe_device *xe)
160{
161 return xe->irq.msix.nvec > 0;
162}
163
164static inline bool xe_device_has_memirq(const struct xe_device *xe)
165{
166 return GRAPHICS_VERx100(xe) >= 1250;
167}
168
169static inline bool xe_device_uses_memirq(const struct xe_device *xe)
170{
171 return xe_device_has_memirq(xe) && (IS_SRIOV_VF(xe) || xe_device_has_msix(xe));
172}
173
174static inline bool xe_device_has_lmtt(const struct xe_device *xe)
175{
176 return IS_DGFX(xe);
177}
178
179static inline bool xe_device_has_mert(const struct xe_device *xe)
180{
181 return xe->info.has_mert;
182}
183
184static inline bool xe_device_is_in_reset(struct xe_device *xe)
185{
186 return atomic_read(&xe->in_reset);
187}
188
189static inline void xe_device_set_in_reset(struct xe_device *xe)
190{
191 atomic_set(&xe->in_reset, 1);
192}
193
194static inline void xe_device_clear_in_reset(struct xe_device *xe)
195{
196 atomic_set(&xe->in_reset, 0);
197}
198
199u32 xe_device_ccs_bytes(struct xe_device *xe, u64 size);
200
201void xe_device_snapshot_print(struct xe_device *xe, struct drm_printer *p);
202
203u64 xe_device_canonicalize_addr(struct xe_device *xe, u64 address);
204u64 xe_device_uncanonicalize_addr(struct xe_device *xe, u64 address);
205
206bool xe_device_is_l2_flush_optimized(struct xe_device *xe);
207void xe_device_td_flush(struct xe_device *xe);
208void xe_device_l2_flush(struct xe_device *xe);
209
210static inline bool xe_device_wedged(struct xe_device *xe)
211{
212 return atomic_read(&xe->wedged.flag);
213}
214
215#ifdef CONFIG_DRM_XE_DEBUG_PAGE_SIZE
216static inline bool xe_debug_page_size_supported(struct xe_device *xe)
217{
218 return IS_DGFX(xe);
219}
220
221static inline bool xe_debug_page_size_mode_not_none(struct xe_device *xe)
222{
223 enum xe_page_size_alloc_ctrl_mode mode;
224
225 if (!xe_debug_page_size_supported(xe))
226 return false;
227
228 mode = READ_ONCE(xe->page_size_alloc_ctrl.mode);
229
230 return mode == XE_PAGE_SIZE_ALLOC_CTRL_MODE_ONLY_2M ||
231 mode == XE_PAGE_SIZE_ALLOC_CTRL_MODE_ONLY_1G ||
232 mode == XE_PAGE_SIZE_ALLOC_CTRL_MODE_MIXED;
233}
234
235static inline bool xe_debug_page_size_mode_is_mixed(struct xe_device *xe)
236{
237 enum xe_page_size_alloc_ctrl_mode mode;
238
239 if (!xe_debug_page_size_supported(xe))
240 return false;
241
242 mode = READ_ONCE(xe->page_size_alloc_ctrl.mode);
243
244 return mode == XE_PAGE_SIZE_ALLOC_CTRL_MODE_MIXED;
245}
246#else
247static inline bool xe_debug_page_size_supported(struct xe_device *xe)
248{
249 return false;
250}
251
252static inline bool xe_debug_page_size_mode_not_none(struct xe_device *xe)
253{
254 return false;
255}
256
257static inline bool xe_debug_page_size_mode_is_mixed(struct xe_device *xe)
258{
259 return false;
260}
261#endif
262
263void xe_device_set_wedged_method(struct xe_device *xe, unsigned long method);
264void xe_device_declare_wedged(struct xe_device *xe);
265int xe_device_validate_wedged_mode(struct xe_device *xe, unsigned int mode);
266const char *xe_wedged_mode_to_string(enum xe_wedged_mode mode);
267
268struct xe_file *xe_file_get(struct xe_file *xef);
269void xe_file_put(struct xe_file *xef);
270
271int xe_is_injection_active(void);
272
273bool xe_is_xe_file(const struct file *file);
274
275struct xe_vm *xe_device_asid_to_vm(struct xe_device *xe, u32 asid);
276
277#ifdef CONFIG_PCI_IOV
278bool xe_device_is_admin_only(const struct xe_device *xe);
279#else
280static inline bool xe_device_is_admin_only(const struct xe_device *xe)
281{
282 return false;
283}
284#endif
285
286/*
287 * Occasionally it is seen that the G2H worker starts running after a delay of more than
288 * a second even after being queued and activated by the Linux workqueue subsystem. This
289 * leads to G2H timeout error. The root cause of issue lies with scheduling latency of
290 * Lunarlake Hybrid CPU. Issue disappears if we disable Lunarlake atom cores from BIOS
291 * and this is beyond xe kmd.
292 *
293 * TODO: Drop this change once workqueue scheduling delay issue is fixed on LNL Hybrid CPU.
294 */
295#define LNL_FLUSH_WORKQUEUE(wq__) \
296 flush_workqueue(wq__)
297#define LNL_FLUSH_WORK(wrk__) \
298 flush_work(wrk__)
299
300#endif