]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
drm/xe: Probe for tile count during device info initialization
authorGustavo Sousa <gustavo.sousa@intel.com>
Mon, 18 Aug 2025 18:15:46 +0000 (15:15 -0300)
committerGustavo Sousa <gustavo.sousa@intel.com>
Wed, 20 Aug 2025 21:59:41 +0000 (18:59 -0300)
The function mmio_multi_tile_setup() does not look like the proper
location for probing for the number of existing tiles in the hardware.
It should not be that function's responsibility and such information
should instead be already available when it gets called.

The fact that we need to adjust gt_count is a symptom of that.

Move probing of available tile count to a dedicated function named
xe_info_probe_tile_count() and call it from xe_info_init(), which seems
like a more appropriate place for that.

With that move, we no longer need to (and shouldn't) adjust gt_count as
a part of xe_info_probe_tile_count(), as that field will be initialized
later in xe_info_init().

v4:
  - Only probe for tile count if the default tile_count != 1 (just like
    was done in mmio_multi_tile_setup()). (CI)
v3:
  - Unchanged.
v2:
  - Use KUnit static stub so that we do not try to query hardware when
    running KUnit tests. (CI)
  - Tweak last paragraph of commit message to make it clearer.
    (Jonathan)

Reviewed-by: Jonathan Cavitt <jonathan.cavitt@intel.com>
Reviewed-by: Rodrigo Vivi <rodrigo.vivi@intel.com>
Link: https://lore.kernel.org/r/20250818-gt_count-improvements-v4-1-ee12870c6f57@intel.com
Signed-off-by: Gustavo Sousa <gustavo.sousa@intel.com>
drivers/gpu/drm/xe/tests/xe_pci.c
drivers/gpu/drm/xe/xe_mmio.c
drivers/gpu/drm/xe/xe_pci.c

index 9c715e59f030c418f16e5123ff70823342281b5d..db30c5156d0c6efb1447997072665ddb0ef4a8f1 100644 (file)
@@ -101,6 +101,11 @@ static void fake_read_gmdid(struct xe_device *xe, enum xe_gmdid_type type,
        }
 }
 
+static void fake_xe_info_probe_tile_count(struct xe_device *xe)
+{
+       /* Nothing to do, just use the statically defined value. */
+}
+
 int xe_pci_fake_device_init(struct xe_device *xe)
 {
        struct kunit *test = kunit_get_current_test();
@@ -138,6 +143,8 @@ done:
                           data->sriov_mode : XE_SRIOV_MODE_NONE;
 
        kunit_activate_static_stub(test, read_gmdid, fake_read_gmdid);
+       kunit_activate_static_stub(test, xe_info_probe_tile_count,
+                                  fake_xe_info_probe_tile_count);
 
        xe_info_init_early(xe, desc, subplatform_desc);
        xe_info_init(xe, desc);
index e4db8d58ea2db383d165fd3fcd50a8da01eb3fe0..ef6f3ea573a2cdfb1842657558bdf5204c2b396c 100644 (file)
@@ -58,7 +58,6 @@ static void tiles_fini(void *arg)
 static void mmio_multi_tile_setup(struct xe_device *xe, size_t tile_mmio_size)
 {
        struct xe_tile *tile;
-       struct xe_gt *gt;
        u8 id;
 
        /*
@@ -68,38 +67,6 @@ static void mmio_multi_tile_setup(struct xe_device *xe, size_t tile_mmio_size)
        if (xe->info.tile_count == 1)
                return;
 
-       /* Possibly override number of tile based on configuration register */
-       if (!xe->info.skip_mtcfg) {
-               struct xe_mmio *mmio = xe_root_tile_mmio(xe);
-               u8 tile_count, gt_count;
-               u32 mtcfg;
-
-               /*
-                * Although the per-tile mmio regs are not yet initialized, this
-                * is fine as it's going to the root tile's mmio, that's
-                * guaranteed to be initialized earlier in xe_mmio_probe_early()
-                */
-               mtcfg = xe_mmio_read32(mmio, XEHP_MTCFG_ADDR);
-               tile_count = REG_FIELD_GET(TILE_COUNT, mtcfg) + 1;
-
-               if (tile_count < xe->info.tile_count) {
-                       drm_info(&xe->drm, "tile_count: %d, reduced_tile_count %d\n",
-                                xe->info.tile_count, tile_count);
-                       xe->info.tile_count = tile_count;
-
-                       /*
-                        * We've already setup gt_count according to the full
-                        * tile count.  Re-calculate it to only include the GTs
-                        * that belong to the remaining tile(s).
-                        */
-                       gt_count = 0;
-                       for_each_gt(gt, xe, id)
-                               if (gt->info.id < tile_count * xe->info.max_gt_per_tile)
-                                       gt_count++;
-                       xe->info.gt_count = gt_count;
-               }
-       }
-
        for_each_remote_tile(tile, xe, id)
                xe_mmio_init(&tile->mmio, tile, xe->mmio.regs + id * tile_mmio_size, SZ_4M);
 }
index 053faa7f9b017ff1848eb7714d9e5543bf0abd1c..bc73fe17616527c67d898b95d0b76f58df935b5f 100644 (file)
@@ -17,6 +17,7 @@
 
 #include "display/xe_display.h"
 #include "regs/xe_gt_regs.h"
+#include "regs/xe_regs.h"
 #include "xe_device.h"
 #include "xe_drv.h"
 #include "xe_gt.h"
@@ -603,6 +604,44 @@ static int xe_info_init_early(struct xe_device *xe,
        return 0;
 }
 
+/*
+ * Possibly override number of tile based on configuration register.
+ */
+static void xe_info_probe_tile_count(struct xe_device *xe)
+{
+       struct xe_mmio *mmio;
+       u8 tile_count;
+       u32 mtcfg;
+
+       KUNIT_STATIC_STUB_REDIRECT(xe_info_probe_tile_count, xe);
+
+       /*
+        * Probe for tile count only for platforms that support multiple
+        * tiles.
+        */
+       if (xe->info.tile_count == 1)
+               return;
+
+       if (xe->info.skip_mtcfg)
+               return;
+
+       mmio = xe_root_tile_mmio(xe);
+
+       /*
+        * Although the per-tile mmio regs are not yet initialized, this
+        * is fine as it's going to the root tile's mmio, that's
+        * guaranteed to be initialized earlier in xe_mmio_probe_early()
+        */
+       mtcfg = xe_mmio_read32(mmio, XEHP_MTCFG_ADDR);
+       tile_count = REG_FIELD_GET(TILE_COUNT, mtcfg) + 1;
+
+       if (tile_count < xe->info.tile_count) {
+               drm_info(&xe->drm, "tile_count: %d, reduced_tile_count %d\n",
+                        xe->info.tile_count, tile_count);
+               xe->info.tile_count = tile_count;
+       }
+}
+
 /*
  * Initialize device info content that does require knowledge about
  * graphics / media IP version.
@@ -677,6 +716,8 @@ static int xe_info_init(struct xe_device *xe,
        xe->info.has_usm = graphics_desc->has_usm;
        xe->info.has_64bit_timestamp = graphics_desc->has_64bit_timestamp;
 
+       xe_info_probe_tile_count(xe);
+
        for_each_remote_tile(tile, xe, id) {
                int err;