]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
drm/xe: Add debugfs to dump GuC's hwconfig
authorMatt Roper <matthew.d.roper@intel.com>
Thu, 15 Aug 2024 17:26:03 +0000 (10:26 -0700)
committerMatt Roper <matthew.d.roper@intel.com>
Fri, 16 Aug 2024 18:07:11 +0000 (11:07 -0700)
Although the query uapi is the official way to get at the GuC's hwconfig
table contents, it's still useful to have a quick debugfs interface to
dump the table in a human-readable format while debugging the driver.

Signed-off-by: Matt Roper <matthew.d.roper@intel.com>
Reviewed-by: Jonathan Cavitt <jonathan.cavitt@intel.com>
Reviewed-by: Jagmeet Randhawa <jagmeet.randhawa@intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20240815172602.2729146-3-matthew.d.roper@intel.com
drivers/gpu/drm/xe/xe_gt_debugfs.c
drivers/gpu/drm/xe/xe_guc_hwconfig.c
drivers/gpu/drm/xe/xe_guc_hwconfig.h

index 5125d76ccfac3f643dfb0f3bf315208c4e092d5d..8f95d3a5949bc3858dbb5104d05003a99ddf747a 100644 (file)
@@ -19,6 +19,7 @@
 #include "xe_gt_sriov_vf_debugfs.h"
 #include "xe_gt_stats.h"
 #include "xe_gt_topology.h"
+#include "xe_guc_hwconfig.h"
 #include "xe_hw_engine.h"
 #include "xe_lrc.h"
 #include "xe_macros.h"
@@ -270,6 +271,15 @@ static int vecs_default_lrc(struct xe_gt *gt, struct drm_printer *p)
        return 0;
 }
 
+static int hwconfig(struct xe_gt *gt, struct drm_printer *p)
+{
+       xe_pm_runtime_get(gt_to_xe(gt));
+       xe_guc_hwconfig_dump(&gt->uc.guc, p);
+       xe_pm_runtime_put(gt_to_xe(gt));
+
+       return 0;
+}
+
 static const struct drm_info_list debugfs_list[] = {
        {"hw_engines", .show = xe_gt_debugfs_simple_show, .data = hw_engines},
        {"force_reset", .show = xe_gt_debugfs_simple_show, .data = force_reset},
@@ -288,6 +298,7 @@ static const struct drm_info_list debugfs_list[] = {
        {"default_lrc_vcs", .show = xe_gt_debugfs_simple_show, .data = vcs_default_lrc},
        {"default_lrc_vecs", .show = xe_gt_debugfs_simple_show, .data = vecs_default_lrc},
        {"stats", .show = xe_gt_debugfs_simple_show, .data = xe_gt_stats_print_info},
+       {"hwconfig", .show = xe_gt_debugfs_simple_show, .data = hwconfig},
 };
 
 void xe_gt_debugfs_register(struct xe_gt *gt)
index d9b570a154a261e5b257f9cb3dd114b3c85cbcb5..025bad70155657973ed554f87af27417ddbb468e 100644 (file)
@@ -6,6 +6,7 @@
 #include "xe_guc_hwconfig.h"
 
 #include <drm/drm_managed.h>
+#include <drm/drm_print.h>
 
 #include "abi/guc_actions_abi.h"
 #include "xe_bo.h"
@@ -103,3 +104,59 @@ void xe_guc_hwconfig_copy(struct xe_guc *guc, void *dst)
        xe_map_memcpy_from(xe, dst, &guc->hwconfig.bo->vmap, 0,
                           guc->hwconfig.size);
 }
+
+void xe_guc_hwconfig_dump(struct xe_guc *guc, struct drm_printer *p)
+{
+       size_t size = xe_guc_hwconfig_size(guc);
+       u32 *hwconfig;
+       u64 num_dw;
+       u32 extra_bytes;
+       int i = 0;
+
+       if (size == 0) {
+               drm_printf(p, "No hwconfig available\n");
+               return;
+       }
+
+       num_dw = div_u64_rem(size, sizeof(u32), &extra_bytes);
+
+       hwconfig = kzalloc(size, GFP_KERNEL);
+       if (!hwconfig) {
+               drm_printf(p, "Error: could not allocate hwconfig memory\n");
+               return;
+       }
+
+       xe_guc_hwconfig_copy(guc, hwconfig);
+
+       /* An entry requires at least three dwords for key, length, value */
+       while (i + 3 <= num_dw) {
+               u32 attribute = hwconfig[i++];
+               u32 len_dw = hwconfig[i++];
+
+               if (i + len_dw > num_dw) {
+                       drm_printf(p, "Error: Attribute %u is %u dwords, but only %llu remain\n",
+                                  attribute, len_dw, num_dw - i);
+                       len_dw = num_dw - i;
+               }
+
+               /*
+                * If it's a single dword (as most hwconfig attributes are),
+                * then it's probably a number that makes sense to display
+                * in decimal form.  In the rare cases where it's more than
+                * one dword, just print it in hex form and let the user
+                * figure out how to interpret it.
+                */
+               if (len_dw == 1)
+                       drm_printf(p, "[%2u] = %u\n", attribute, hwconfig[i]);
+               else
+                       drm_printf(p, "[%2u] = { %*ph }\n", attribute,
+                                  (int)(len_dw * sizeof(u32)), &hwconfig[i]);
+               i += len_dw;
+       }
+
+       if (i < num_dw || extra_bytes)
+               drm_printf(p, "Error: %llu extra bytes at end of hwconfig\n",
+                          (num_dw - i) * sizeof(u32) + extra_bytes);
+
+       kfree(hwconfig);
+}
index b5794d6419006ca476d5356eb8f577b0ace74c13..7df315900e1cfb91c49fedc8ac9d558dc323ec21 100644 (file)
@@ -8,10 +8,12 @@
 
 #include <linux/types.h>
 
+struct drm_printer;
 struct xe_guc;
 
 int xe_guc_hwconfig_init(struct xe_guc *guc);
 u32 xe_guc_hwconfig_size(struct xe_guc *guc);
 void xe_guc_hwconfig_copy(struct xe_guc *guc, void *dst);
+void xe_guc_hwconfig_dump(struct xe_guc *guc, struct drm_printer *p);
 
 #endif