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 13 static inline struct xe_device *to_xe_device(const struct drm_device *dev) 14 { 15 return container_of(dev, struct xe_device, drm); 16 } 17 18 static inline struct xe_device *kdev_to_xe_device(struct device *kdev) 19 { 20 struct drm_device *drm = dev_get_drvdata(kdev); 21 22 return drm ? to_xe_device(drm) : NULL; 23 } 24 25 static inline struct xe_device *pdev_to_xe_device(struct pci_dev *pdev) 26 { 27 struct drm_device *drm = pci_get_drvdata(pdev); 28 29 return drm ? to_xe_device(drm) : NULL; 30 } 31 32 static inline struct xe_device *xe_device_const_cast(const struct xe_device *xe) 33 { 34 return (struct xe_device *)xe; 35 } 36 37 static inline struct xe_device *ttm_to_xe_device(struct ttm_device *ttm) 38 { 39 return container_of(ttm, struct xe_device, ttm); 40 } 41 42 struct xe_device *xe_device_create(struct pci_dev *pdev, 43 const struct pci_device_id *ent); 44 int xe_device_probe_early(struct xe_device *xe); 45 int xe_device_probe(struct xe_device *xe); 46 void xe_device_remove(struct xe_device *xe); 47 void xe_device_shutdown(struct xe_device *xe); 48 49 void xe_device_wmb(struct xe_device *xe); 50 51 static inline struct xe_file *to_xe_file(const struct drm_file *file) 52 { 53 return file->driver_priv; 54 } 55 56 static inline struct xe_tile *xe_device_get_root_tile(struct xe_device *xe) 57 { 58 return &xe->tiles[0]; 59 } 60 61 #define XE_MAX_GT_PER_TILE 2 62 63 static inline struct xe_gt *xe_tile_get_gt(struct xe_tile *tile, u8 gt_id) 64 { 65 if (drm_WARN_ON(&tile_to_xe(tile)->drm, gt_id >= XE_MAX_GT_PER_TILE)) 66 gt_id = 0; 67 68 return gt_id ? tile->media_gt : tile->primary_gt; 69 } 70 71 static inline struct xe_gt *xe_device_get_gt(struct xe_device *xe, u8 gt_id) 72 { 73 struct xe_tile *root_tile = xe_device_get_root_tile(xe); 74 struct xe_gt *gt; 75 76 /* 77 * FIXME: This only works for now because multi-tile and standalone 78 * media are mutually exclusive on the platforms we have today. 79 * 80 * id => GT mapping may change once we settle on how we want to handle 81 * our UAPI. 82 */ 83 if (MEDIA_VER(xe) >= 13) { 84 gt = xe_tile_get_gt(root_tile, gt_id); 85 } else { 86 if (drm_WARN_ON(&xe->drm, gt_id >= XE_MAX_TILES_PER_DEVICE)) 87 gt_id = 0; 88 89 gt = xe->tiles[gt_id].primary_gt; 90 } 91 92 if (!gt) 93 return NULL; 94 95 drm_WARN_ON(&xe->drm, gt->info.id != gt_id); 96 drm_WARN_ON(&xe->drm, gt->info.type == XE_GT_TYPE_UNINITIALIZED); 97 98 return gt; 99 } 100 101 /* 102 * Provide a GT structure suitable for performing non-GT MMIO operations against 103 * the primary tile. Primarily intended for early tile initialization, display 104 * handling, top-most interrupt enable/disable, etc. Since anything using the 105 * MMIO handle returned by this function doesn't need GSI offset translation, 106 * we'll return the primary GT from the root tile. 107 * 108 * FIXME: Fix the driver design so that 'gt' isn't the target of all MMIO 109 * operations. 110 * 111 * Returns the primary gt of the root tile. 112 */ 113 static inline struct xe_gt *xe_root_mmio_gt(struct xe_device *xe) 114 { 115 return xe_device_get_root_tile(xe)->primary_gt; 116 } 117 118 static inline bool xe_device_uc_enabled(struct xe_device *xe) 119 { 120 return !xe->info.force_execlist; 121 } 122 123 #define for_each_tile(tile__, xe__, id__) \ 124 for ((id__) = 0; (id__) < (xe__)->info.tile_count; (id__)++) \ 125 for_each_if((tile__) = &(xe__)->tiles[(id__)]) 126 127 #define for_each_remote_tile(tile__, xe__, id__) \ 128 for ((id__) = 1; (id__) < (xe__)->info.tile_count; (id__)++) \ 129 for_each_if((tile__) = &(xe__)->tiles[(id__)]) 130 131 /* 132 * FIXME: This only works for now since multi-tile and standalone media 133 * happen to be mutually exclusive. Future platforms may change this... 134 */ 135 #define for_each_gt(gt__, xe__, id__) \ 136 for ((id__) = 0; (id__) < (xe__)->info.gt_count; (id__)++) \ 137 for_each_if((gt__) = xe_device_get_gt((xe__), (id__))) 138 139 static inline struct xe_force_wake *gt_to_fw(struct xe_gt *gt) 140 { 141 return >->mmio.fw; 142 } 143 144 void xe_device_assert_mem_access(struct xe_device *xe); 145 146 static inline bool xe_device_has_flat_ccs(struct xe_device *xe) 147 { 148 return xe->info.has_flat_ccs; 149 } 150 151 static inline bool xe_device_has_sriov(struct xe_device *xe) 152 { 153 return xe->info.has_sriov; 154 } 155 156 static inline bool xe_device_has_memirq(struct xe_device *xe) 157 { 158 return GRAPHICS_VERx100(xe) >= 1250; 159 } 160 161 u32 xe_device_ccs_bytes(struct xe_device *xe, u64 size); 162 163 void xe_device_snapshot_print(struct xe_device *xe, struct drm_printer *p); 164 165 u64 xe_device_canonicalize_addr(struct xe_device *xe, u64 address); 166 u64 xe_device_uncanonicalize_addr(struct xe_device *xe, u64 address); 167 168 void xe_device_td_flush(struct xe_device *xe); 169 void xe_device_l2_flush(struct xe_device *xe); 170 171 static inline bool xe_device_wedged(struct xe_device *xe) 172 { 173 return atomic_read(&xe->wedged.flag); 174 } 175 176 void xe_device_declare_wedged(struct xe_device *xe); 177 178 struct xe_file *xe_file_get(struct xe_file *xef); 179 void xe_file_put(struct xe_file *xef); 180 181 #endif 182