Commit | Line | Data |
---|---|---|
dd08ebf6 MB |
1 | /* SPDX-License-Identifier: MIT */ |
2 | /* | |
3 | * Copyright © 2021 Intel Corporation | |
4 | */ | |
5 | ||
6 | #ifndef _XE_DEVICE_H_ | |
7 | #define _XE_DEVICE_H_ | |
8 | ||
9b9529ce | 9 | struct xe_exec_queue; |
dd08ebf6 MB |
10 | struct xe_file; |
11 | ||
12 | #include <drm/drm_util.h> | |
13 | ||
63955b3b | 14 | #include "regs/xe_gpu_commands.h" |
dd08ebf6 | 15 | #include "xe_device_types.h" |
dd08ebf6 | 16 | #include "xe_force_wake.h" |
ea9f879d | 17 | #include "xe_macros.h" |
dd08ebf6 | 18 | |
9700a1df MA |
19 | #ifdef CONFIG_LOCKDEP |
20 | extern struct lockdep_map xe_device_mem_access_lockdep_map; | |
21 | #endif | |
22 | ||
dd08ebf6 MB |
23 | static inline struct xe_device *to_xe_device(const struct drm_device *dev) |
24 | { | |
25 | return container_of(dev, struct xe_device, drm); | |
26 | } | |
27 | ||
28 | static inline struct xe_device *pdev_to_xe_device(struct pci_dev *pdev) | |
29 | { | |
30 | return pci_get_drvdata(pdev); | |
31 | } | |
32 | ||
33 | static inline struct xe_device *ttm_to_xe_device(struct ttm_device *ttm) | |
34 | { | |
35 | return container_of(ttm, struct xe_device, ttm); | |
36 | } | |
37 | ||
38 | struct xe_device *xe_device_create(struct pci_dev *pdev, | |
39 | const struct pci_device_id *ent); | |
4f122766 | 40 | int xe_device_probe_early(struct xe_device *xe); |
dd08ebf6 MB |
41 | int xe_device_probe(struct xe_device *xe); |
42 | void xe_device_remove(struct xe_device *xe); | |
43 | void xe_device_shutdown(struct xe_device *xe); | |
44 | ||
dd08ebf6 MB |
45 | void xe_device_wmb(struct xe_device *xe); |
46 | ||
47 | static inline struct xe_file *to_xe_file(const struct drm_file *file) | |
48 | { | |
49 | return file->driver_priv; | |
50 | } | |
51 | ||
a5edc7cd MR |
52 | static inline struct xe_tile *xe_device_get_root_tile(struct xe_device *xe) |
53 | { | |
54 | return &xe->tiles[0]; | |
55 | } | |
56 | ||
37efea9c MR |
57 | #define XE_MAX_GT_PER_TILE 2 |
58 | ||
59 | static inline struct xe_gt *xe_tile_get_gt(struct xe_tile *tile, u8 gt_id) | |
60 | { | |
23e1ee3a | 61 | if (drm_WARN_ON(&tile_to_xe(tile)->drm, gt_id >= XE_MAX_GT_PER_TILE)) |
37efea9c MR |
62 | gt_id = 0; |
63 | ||
64 | return gt_id ? tile->media_gt : tile->primary_gt; | |
65 | } | |
66 | ||
dd08ebf6 MB |
67 | static inline struct xe_gt *xe_device_get_gt(struct xe_device *xe, u8 gt_id) |
68 | { | |
37efea9c | 69 | struct xe_tile *root_tile = xe_device_get_root_tile(xe); |
dd08ebf6 MB |
70 | struct xe_gt *gt; |
71 | ||
37efea9c MR |
72 | /* |
73 | * FIXME: This only works for now because multi-tile and standalone | |
74 | * media are mutually exclusive on the platforms we have today. | |
75 | * | |
76 | * id => GT mapping may change once we settle on how we want to handle | |
77 | * our UAPI. | |
78 | */ | |
79 | if (MEDIA_VER(xe) >= 13) { | |
80 | gt = xe_tile_get_gt(root_tile, gt_id); | |
81 | } else { | |
b45f20fa | 82 | if (drm_WARN_ON(&xe->drm, gt_id >= XE_MAX_TILES_PER_DEVICE)) |
37efea9c MR |
83 | gt_id = 0; |
84 | ||
85 | gt = xe->tiles[gt_id].primary_gt; | |
86 | } | |
87 | ||
88 | if (!gt) | |
f6929e80 MR |
89 | return NULL; |
90 | ||
37efea9c MR |
91 | drm_WARN_ON(&xe->drm, gt->info.id != gt_id); |
92 | drm_WARN_ON(&xe->drm, gt->info.type == XE_GT_TYPE_UNINITIALIZED); | |
dd08ebf6 MB |
93 | |
94 | return gt; | |
95 | } | |
96 | ||
97 | /* | |
ed006ba5 MR |
98 | * Provide a GT structure suitable for performing non-GT MMIO operations against |
99 | * the primary tile. Primarily intended for early tile initialization, display | |
100 | * handling, top-most interrupt enable/disable, etc. Since anything using the | |
101 | * MMIO handle returned by this function doesn't need GSI offset translation, | |
102 | * we'll return the primary GT from the root tile. | |
103 | * | |
104 | * FIXME: Fix the driver design so that 'gt' isn't the target of all MMIO | |
105 | * operations. | |
106 | * | |
107 | * Returns the primary gt of the root tile. | |
dd08ebf6 | 108 | */ |
ed006ba5 | 109 | static inline struct xe_gt *xe_root_mmio_gt(struct xe_device *xe) |
dd08ebf6 | 110 | { |
f6929e80 | 111 | return xe_device_get_root_tile(xe)->primary_gt; |
dd08ebf6 MB |
112 | } |
113 | ||
c4991ee0 | 114 | static inline bool xe_device_uc_enabled(struct xe_device *xe) |
dd08ebf6 | 115 | { |
c8dc1546 | 116 | return !xe->info.force_execlist; |
dd08ebf6 MB |
117 | } |
118 | ||
3643e637 MR |
119 | #define for_each_tile(tile__, xe__, id__) \ |
120 | for ((id__) = 0; (id__) < (xe__)->info.tile_count; (id__)++) \ | |
4cd6d492 | 121 | for_each_if((tile__) = &(xe__)->tiles[(id__)]) |
3643e637 | 122 | |
4f122766 MW |
123 | #define for_each_remote_tile(tile__, xe__, id__) \ |
124 | for ((id__) = 1; (id__) < (xe__)->info.tile_count; (id__)++) \ | |
125 | for_each_if((tile__) = &(xe__)->tiles[(id__)]) | |
126 | ||
37efea9c MR |
127 | /* |
128 | * FIXME: This only works for now since multi-tile and standalone media | |
129 | * happen to be mutually exclusive. Future platforms may change this... | |
130 | */ | |
dd08ebf6 | 131 | #define for_each_gt(gt__, xe__, id__) \ |
37efea9c | 132 | for ((id__) = 0; (id__) < (xe__)->info.gt_count; (id__)++) \ |
4cd6d492 | 133 | for_each_if((gt__) = xe_device_get_gt((xe__), (id__))) |
dd08ebf6 | 134 | |
4ab5901c | 135 | static inline struct xe_force_wake *gt_to_fw(struct xe_gt *gt) |
dd08ebf6 MB |
136 | { |
137 | return >->mmio.fw; | |
138 | } | |
139 | ||
140 | void xe_device_mem_access_get(struct xe_device *xe); | |
c4bbc32e | 141 | bool xe_device_mem_access_get_if_ongoing(struct xe_device *xe); |
dd08ebf6 MB |
142 | void xe_device_mem_access_put(struct xe_device *xe); |
143 | ||
a00b8f1a MA |
144 | void xe_device_assert_mem_access(struct xe_device *xe); |
145 | bool xe_device_mem_access_ongoing(struct xe_device *xe); | |
dd08ebf6 MB |
146 | |
147 | static inline bool xe_device_in_fault_mode(struct xe_device *xe) | |
148 | { | |
149 | return xe->usm.num_vm_in_fault_mode != 0; | |
150 | } | |
151 | ||
152 | static inline bool xe_device_in_non_fault_mode(struct xe_device *xe) | |
153 | { | |
154 | return xe->usm.num_vm_in_non_fault_mode != 0; | |
155 | } | |
156 | ||
157 | static inline bool xe_device_has_flat_ccs(struct xe_device *xe) | |
158 | { | |
159 | return xe->info.has_flat_ccs; | |
160 | } | |
161 | ||
d6d14854 MW |
162 | static inline bool xe_device_has_sriov(struct xe_device *xe) |
163 | { | |
164 | return xe->info.has_sriov; | |
165 | } | |
166 | ||
a6581ebe MW |
167 | static inline bool xe_device_has_memirq(struct xe_device *xe) |
168 | { | |
169 | return GRAPHICS_VERx100(xe) >= 1250; | |
170 | } | |
171 | ||
dd08ebf6 | 172 | u32 xe_device_ccs_bytes(struct xe_device *xe, u64 size); |
1a545ed7 | 173 | |
4376cee6 JRS |
174 | void xe_device_snapshot_print(struct xe_device *xe, struct drm_printer *p); |
175 | ||
5746eaaa JRS |
176 | u64 xe_device_canonicalize_addr(struct xe_device *xe, u64 address); |
177 | u64 xe_device_uncanonicalize_addr(struct xe_device *xe, u64 address); | |
178 | ||
dd08ebf6 | 179 | #endif |