drm/xe: Allow GT looping and lookup on standalone media
authorMatt Roper <matthew.d.roper@intel.com>
Thu, 1 Jun 2023 21:52:41 +0000 (14:52 -0700)
committerRodrigo Vivi <rodrigo.vivi@intel.com>
Tue, 19 Dec 2023 23:34:20 +0000 (18:34 -0500)
Allow xe_device_get_gt() and for_each_gt() to operate as expected on
platforms with standalone media.

FIXME: We need to figure out a consistent ID scheme for GTs.  This patch
keeps the pre-existing behavior of 0/1 being the GT IDs for both PVC
(multi-tile) and MTL (multi-GT), but depending on the direction we
decide to go with uapi, we may change this in the future (e.g., to
return 0/1 on PVC and 0/2 on MTL).  Or if we decide we only need to
expose tiles to userspace and not GTs, we may not even need ID numbers
for the GTs anymore.

v2:
 - Restructure a bit to make the assertions more clear.
 - Clarify in commit message that the goal here is to preserve existing
   behavior; UAPI-visible changes may be introduced in the future once
   we settle on what we really want.
v3:
 - Store total GT count in xe_device for ease of lookup.  (Brian)
 - s/(id__++)/(id__)++/  (Gustavo)

Cc: Lucas De Marchi <lucas.demarchi@intel.com>
Cc: Gustavo Sousa <gustavo.sousa@intel.com>
Cc: Brian Welty <brian.welty@intel.com>
Acked-by: Gustavo Sousa <gustavo.sousa@intel.com>
Reviewed-by: Lucas De Marchi <lucas.demarchi@intel.com>
Link: https://lore.kernel.org/r/20230601215244.678611-29-matthew.d.roper@intel.com
Signed-off-by: Matt Roper <matthew.d.roper@intel.com>
Signed-off-by: Rodrigo Vivi <rodrigo.vivi@intel.com>
drivers/gpu/drm/xe/xe_device.h
drivers/gpu/drm/xe/xe_device_types.h
drivers/gpu/drm/xe/xe_pci.c

index f2d8479f6ff6206aa7201ebba73fefc43ec97ee0..779f71d066e6e20641b1d3560ca00b349c4bbedc 100644 (file)
@@ -53,18 +53,42 @@ static inline struct xe_tile *xe_device_get_root_tile(struct xe_device *xe)
        return &xe->tiles[0];
 }
 
+#define XE_MAX_GT_PER_TILE 2
+
+static inline struct xe_gt *xe_tile_get_gt(struct xe_tile *tile, u8 gt_id)
+{
+       if (drm_WARN_ON(&tile_to_xe(tile)->drm, gt_id > XE_MAX_GT_PER_TILE))
+               gt_id = 0;
+
+       return gt_id ? tile->media_gt : tile->primary_gt;
+}
+
 static inline struct xe_gt *xe_device_get_gt(struct xe_device *xe, u8 gt_id)
 {
+       struct xe_tile *root_tile = xe_device_get_root_tile(xe);
        struct xe_gt *gt;
 
-       XE_BUG_ON(gt_id > XE_MAX_TILES_PER_DEVICE);
-
-       gt = xe->tiles[gt_id].primary_gt;
-       if (drm_WARN_ON(&xe->drm, !gt))
+       /*
+        * FIXME: This only works for now because multi-tile and standalone
+        * media are mutually exclusive on the platforms we have today.
+        *
+        * id => GT mapping may change once we settle on how we want to handle
+        * our UAPI.
+        */
+       if (MEDIA_VER(xe) >= 13) {
+               gt = xe_tile_get_gt(root_tile, gt_id);
+       } else {
+               if (drm_WARN_ON(&xe->drm, gt_id > XE_MAX_TILES_PER_DEVICE))
+                       gt_id = 0;
+
+               gt = xe->tiles[gt_id].primary_gt;
+       }
+
+       if (!gt)
                return NULL;
 
-       XE_BUG_ON(gt->info.id != gt_id);
-       XE_BUG_ON(gt->info.type == XE_GT_TYPE_UNINITIALIZED);
+       drm_WARN_ON(&xe->drm, gt->info.id != gt_id);
+       drm_WARN_ON(&xe->drm, gt->info.type == XE_GT_TYPE_UNINITIALIZED);
 
        return gt;
 }
@@ -100,8 +124,12 @@ static inline void xe_device_guc_submission_disable(struct xe_device *xe)
        for ((id__) = 0; (id__) < (xe__)->info.tile_count; (id__)++) \
                for_each_if ((tile__) = &(xe__)->tiles[(id__)])
 
+/*
+ * FIXME: This only works for now since multi-tile and standalone media
+ * happen to be mutually exclusive.  Future platforms may change this...
+ */
 #define for_each_gt(gt__, xe__, id__) \
-       for ((id__) = 0; (id__) < (xe__)->info.tile_count; (id__++)) \
+       for ((id__) = 0; (id__) < (xe__)->info.gt_count; (id__)++) \
                for_each_if ((gt__) = xe_device_get_gt((xe__), (id__)))
 
 static inline struct xe_force_wake * gt_to_fw(struct xe_gt *gt)
index 16a77703d4298bf7be56c750a7f3966b413a8d9b..3b50134cdcc0dd387342f577fde2a190eae33c9f 100644 (file)
@@ -184,6 +184,8 @@ struct xe_device {
                u8 vram_flags;
                /** @tile_count: Number of tiles */
                u8 tile_count;
+               /** @gt_count: Total number of GTs for entire device */
+               u8 gt_count;
                /** @vm_max_level: Max VM level */
                u8 vm_max_level;
 
index be51c9e97a79630fd5d39ef2802dbaa6322ed808..abb2f13260079edfd3edaf77a510e20d27c6725a 100644 (file)
@@ -535,7 +535,11 @@ static int xe_info_init(struct xe_device *xe,
                        return PTR_ERR(tile->primary_gt);
 
                gt = tile->primary_gt;
-               gt->info.id = id;       /* FIXME: Determine sensible numbering */
+               /*
+                * FIXME: GT numbering scheme may change depending on UAPI
+                * decisions.
+                */
+               gt->info.id = xe->info.gt_count++;
                gt->info.type = XE_GT_TYPE_MAIN;
                gt->info.__engine_mask = graphics_desc->hw_engine_mask;
                if (MEDIA_VER(xe) < 13 && media_desc)