Inform the GuC which contexts are debuggable, as their
handling differs from ordinary contexts.

v2: void return, use xe_gt_dbg, no need for lrc (Matt)
v3: add the workaround enabling (Daniele)
v4: version needed to 70.49.4
v5: bail out early before registering eq (Daniele)
v6: export the guc action for future (Mika)
v7: remove redundant xe_gt_info (Sashiko)

Cc: Matthew Brost <[email protected]>
Cc: Lucas De Marchi <[email protected]>
Cc: Daniele Ceraolo Spurio <[email protected]>
Cc: Jan Sokolowski <[email protected]>
Signed-off-by: Dominik Grzegorzek <[email protected]>
Signed-off-by: Maciej Patelczyk <[email protected]>
Signed-off-by: Mika Kuoppala <[email protected]>
Reviewed-by: Daniele Ceraolo Spurio <[email protected]>
---
 drivers/gpu/drm/xe/abi/guc_actions_abi.h |  5 ++++
 drivers/gpu/drm/xe/abi/guc_klvs_abi.h    |  1 +
 drivers/gpu/drm/xe/xe_exec_queue.c       |  5 ++++
 drivers/gpu/drm/xe/xe_guc.c              | 15 +++++++++++
 drivers/gpu/drm/xe/xe_guc.h              |  6 +++++
 drivers/gpu/drm/xe/xe_guc_ads.c          |  5 ++++
 drivers/gpu/drm/xe/xe_guc_submit.c       | 34 ++++++++++++++++++++++++
 drivers/gpu/drm/xe/xe_wa_oob.rules       |  2 ++
 include/uapi/drm/xe_drm.h                |  5 ++--
 9 files changed, 76 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/xe/abi/guc_actions_abi.h 
b/drivers/gpu/drm/xe/abi/guc_actions_abi.h
index f5c9b37038d4..48ba41fd8ccb 100644
--- a/drivers/gpu/drm/xe/abi/guc_actions_abi.h
+++ b/drivers/gpu/drm/xe/abi/guc_actions_abi.h
@@ -162,6 +162,7 @@ enum xe_guc_action {
        XE_GUC_ACTION_NOTIFY_FLUSH_LOG_BUFFER_TO_FILE = 0x8003,
        XE_GUC_ACTION_NOTIFY_CRASH_DUMP_POSTED = 0x8004,
        XE_GUC_ACTION_NOTIFY_EXCEPTION = 0x8005,
+       XE_GUC_ACTION_EU_KERNEL_DEBUG = 0x8006,
        XE_GUC_ACTION_TEST_G2G_SEND = 0xF001,
        XE_GUC_ACTION_TEST_G2G_RECV = 0xF002,
        XE_GUC_ACTION_LIMIT
@@ -285,4 +286,8 @@ enum xe_guc_g2g_type {
 /* invalid type for XE_GUC_ACTION_NOTIFY_MEMORY_CAT_ERROR */
 #define XE_GUC_CAT_ERR_TYPE_INVALID 0xdeadbeef
 
+enum xe_guc_eu_kernel_debug_request_type {
+       XE_GUC_EU_KERNEL_DEBUG_ENABLE = 0x3,
+};
+
 #endif
diff --git a/drivers/gpu/drm/xe/abi/guc_klvs_abi.h 
b/drivers/gpu/drm/xe/abi/guc_klvs_abi.h
index 4bcdc1a96785..147a1d0a1472 100644
--- a/drivers/gpu/drm/xe/abi/guc_klvs_abi.h
+++ b/drivers/gpu/drm/xe/abi/guc_klvs_abi.h
@@ -522,6 +522,7 @@ enum xe_guc_klv_ids {
        GUC_WA_KLV_WAKE_POWER_DOMAINS_FOR_OUTBOUND_MMIO                         
        = 0x900a,
        GUC_WA_KLV_RESET_BB_STACK_PTR_ON_VF_SWITCH                              
        = 0x900b,
        GUC_WA_KLV_RESTORE_UNSAVED_MEDIA_CONTROL_REG                            
        = 0x900c,
+       GUC_WA_KLV_RESET_DEP_ENGINES_ON_DEBUG_CTX_SWITCH                        
        = 0x900d,
        GUC_WA_KLV_CLR_CS_INDIRECT_RING_STATE_IF_IDLE_AT_CTX_REG                
        = 0x900e,
        GUC_WA_KLV_REMAP_RANGED_TLB_INV                                         
        = 0x900f,
        GUC_WA_KLV_IGNORE_MMIO_READ_SEM_TOKEN_64                                
        = 0x9010,
diff --git a/drivers/gpu/drm/xe/xe_exec_queue.c 
b/drivers/gpu/drm/xe/xe_exec_queue.c
index 3eeb8a108b40..870abbf08d2e 100644
--- a/drivers/gpu/drm/xe/xe_exec_queue.c
+++ b/drivers/gpu/drm/xe/xe_exec_queue.c
@@ -21,6 +21,7 @@
 #include "xe_gt.h"
 #include "xe_gt_sriov_pf.h"
 #include "xe_gt_sriov_vf.h"
+#include "xe_guc.h"
 #include "xe_hw_engine_class_sysfs.h"
 #include "xe_hw_engine_group.h"
 #include "xe_irq.h"
@@ -1058,6 +1059,7 @@ static int exec_queue_set_eudebug(struct xe_device *xe, 
struct xe_exec_queue *q,
                                  u64 value)
 {
        const u64 known_flags = DRM_XE_EXEC_QUEUE_EUDEBUG_FLAG_ENABLE;
+       struct xe_guc *guc = &q->gt->uc.guc;
 
        if (XE_IOCTL_DBG(xe, !xe_engine_supports_eudebug(q->class)))
                return -EINVAL;
@@ -1068,6 +1070,9 @@ static int exec_queue_set_eudebug(struct xe_device *xe, 
struct xe_exec_queue *q,
        if (XE_IOCTL_DBG(xe, !IS_ENABLED(CONFIG_DRM_XE_EUDEBUG)))
                return -EOPNOTSUPP;
 
+       if (XE_IOCTL_DBG(xe, !xe_guc_has_debug_contexts(guc)))
+               return -EOPNOTSUPP;
+
        /*
         * The preemption timeout below is infinite, which is only safe where
         * no dma-fence waits for the queue to be preempted: a fault mode vm
diff --git a/drivers/gpu/drm/xe/xe_guc.c b/drivers/gpu/drm/xe/xe_guc.c
index 300126e6624f..8b9af0c483b5 100644
--- a/drivers/gpu/drm/xe/xe_guc.c
+++ b/drivers/gpu/drm/xe/xe_guc.c
@@ -823,6 +823,13 @@ int xe_guc_init(struct xe_guc *guc)
                return 0;
        }
 
+       if (IS_ENABLED(CONFIG_DRM_XE_EUDEBUG) && XE_GT_WA(gt, 14022766366) &&
+           !xe_guc_has_debug_contexts(guc))
+               xe_gt_info(gt, "eudebug needs GuC version %u.%u.%u or 
greater\n",
+                          XE_GUC_VER_DEBUG_CONTEXTS_MAJOR,
+                          XE_GUC_VER_DEBUG_CONTEXTS_MINOR,
+                          XE_GUC_VER_DEBUG_CONTEXTS_PATCH);
+
        ret = xe_guc_log_init(&guc->log);
        if (ret)
                goto out;
@@ -1959,6 +1966,14 @@ u16 xe_hwe_guc_logical_instance(struct xe_hw_engine *hwe)
        return hwe->logical_instance;
 }
 
+bool xe_guc_has_debug_contexts(struct xe_guc *guc)
+{
+       return GUC_FIRMWARE_VER_AT_LEAST(guc,
+                                        XE_GUC_VER_DEBUG_CONTEXTS_MAJOR,
+                                        XE_GUC_VER_DEBUG_CONTEXTS_MINOR,
+                                        XE_GUC_VER_DEBUG_CONTEXTS_PATCH);
+}
+
 #if IS_ENABLED(CONFIG_DRM_XE_KUNIT_TEST)
 #include "tests/xe_guc_g2g_test.c"
 #endif
diff --git a/drivers/gpu/drm/xe/xe_guc.h b/drivers/gpu/drm/xe/xe_guc.h
index 543ba4e5981e..79d76970995d 100644
--- a/drivers/gpu/drm/xe/xe_guc.h
+++ b/drivers/gpu/drm/xe/xe_guc.h
@@ -29,6 +29,11 @@
 #define GUC_FIRMWARE_VER_AT_LEAST(guc, ver...) \
        xe_guc_fw_version_at_least((guc), MAKE_GUC_VER_ARGS(ver))
 
+/* Lowest GuC version that knows how to handle debuggable contexts */
+#define XE_GUC_VER_DEBUG_CONTEXTS_MAJOR        70
+#define XE_GUC_VER_DEBUG_CONTEXTS_MINOR        49
+#define XE_GUC_VER_DEBUG_CONTEXTS_PATCH        4
+
 struct drm_printer;
 struct xe_gt;
 
@@ -66,6 +71,7 @@ int xe_guc_start(struct xe_guc *guc);
 void xe_guc_wedge_declare(struct xe_guc *guc);
 bool xe_guc_using_main_gamctrl_queues(struct xe_guc *guc);
 bool xe_guc_has_paging_engine(struct xe_guc *guc);
+bool xe_guc_has_debug_contexts(struct xe_guc *guc);
 
 #if IS_ENABLED(CONFIG_DRM_XE_KUNIT_TEST)
 int xe_guc_g2g_test_notification(struct xe_guc *guc, u32 *payload, u32 len);
diff --git a/drivers/gpu/drm/xe/xe_guc_ads.c b/drivers/gpu/drm/xe/xe_guc_ads.c
index c3ce3c8c905a..0b1bdb40230b 100644
--- a/drivers/gpu/drm/xe/xe_guc_ads.c
+++ b/drivers/gpu/drm/xe/xe_guc_ads.c
@@ -402,6 +402,11 @@ static void guc_waklv_init(struct xe_guc_ads *ads)
                                 GUC_FEATURE_KLV_DISABLE_MULTI_QUEUE);
        }
 
+       if (IS_ENABLED(CONFIG_DRM_XE_EUDEBUG) && XE_GT_WA(gt, 14022766366) &&
+           xe_guc_has_debug_contexts(&gt->uc.guc))
+               guc_waklv_enable(ads, NULL, 0, &offset, &remain,
+                                
GUC_WA_KLV_RESET_DEP_ENGINES_ON_DEBUG_CTX_SWITCH);
+
        size = guc_ads_waklv_size(ads) - remain;
        if (!size)
                return;
diff --git a/drivers/gpu/drm/xe/xe_guc_submit.c 
b/drivers/gpu/drm/xe/xe_guc_submit.c
index b14b37b767f5..61a7d731f7d1 100644
--- a/drivers/gpu/drm/xe/xe_guc_submit.c
+++ b/drivers/gpu/drm/xe/xe_guc_submit.c
@@ -1023,6 +1023,37 @@ static u32 xe_hwe_guc_logical_to_submit_mask(struct 
xe_hw_engine *hwe, u32 logic
        return logical_mask;
 }
 
+static int guc_action_eu_kernel_debug(struct xe_guc *guc, u32 id, u32 cmd)
+{
+       const u32 action[] = {
+               XE_GUC_ACTION_EU_KERNEL_DEBUG,
+               id,
+               cmd,
+               0, /* reserved */
+       };
+
+       return xe_guc_ct_send(&guc->ct, action,
+                             ARRAY_SIZE(action), 0, 0);
+}
+
+static void set_eu_kernel_debug(struct xe_exec_queue *q)
+{
+       struct xe_guc *guc = exec_queue_to_guc(q);
+       struct xe_gt *gt = guc_to_gt(guc);
+       int ret;
+
+       ret = guc_action_eu_kernel_debug(guc, q->guc->id,
+                                        XE_GUC_EU_KERNEL_DEBUG_ENABLE);
+
+       if (ret)
+               xe_gt_err_ratelimited(gt,
+                                     "GuC ctx=%u debug enabling failed with 
%d\n",
+                                     q->guc->id, ret);
+       else
+               xe_gt_dbg(gt,
+                         "GuC ctx=%u debug enable requested\n", q->guc->id);
+}
+
 static void register_exec_queue(struct xe_exec_queue *q, int ctx_type)
 {
        struct xe_guc *guc = exec_queue_to_guc(q);
@@ -1084,6 +1115,9 @@ static void register_exec_queue(struct xe_exec_queue *q, 
int ctx_type)
 
        if (xe_exec_queue_is_multi_queue_secondary(q))
                guc_exec_queue_send_cgp_sync(q, CGP_SYNC_REGISTRATION);
+
+       if (xe_exec_queue_is_debuggable(q))
+               set_eu_kernel_debug(q);
 }
 
 static u32 wq_space_until_wrap(struct xe_exec_queue *q)
diff --git a/drivers/gpu/drm/xe/xe_wa_oob.rules 
b/drivers/gpu/drm/xe/xe_wa_oob.rules
index 61aa50a63764..da774e17cb69 100644
--- a/drivers/gpu/drm/xe/xe_wa_oob.rules
+++ b/drivers/gpu/drm/xe/xe_wa_oob.rules
@@ -78,3 +78,5 @@
                MEDIA_VERSION_RANGE(1301, 3503), FUNC(xe_rtp_match_not_sriov_vf)
 16030224309    GRAPHICS_VERSION_RANGE(3510, 3511)
 14028709524    GRAPHICS_VERSION(3510)
+14022766366    GRAPHICS_VERSION_RANGE(2001, 2004)
+               GRAPHICS_VERSION_RANGE(3000, 3005)
diff --git a/include/uapi/drm/xe_drm.h b/include/uapi/drm/xe_drm.h
index 1a157bf1589c..759e76b7ac52 100644
--- a/include/uapi/drm/xe_drm.h
+++ b/include/uapi/drm/xe_drm.h
@@ -1404,8 +1404,9 @@ struct drm_xe_vm_get_property {
  *    %DRM_XE_VM_CREATE_FLAG_FAULT_MODE,
  *    not combined with %DRM_XE_EXEC_QUEUE_SET_PROPERTY_PXP_TYPE or
  *    %DRM_XE_EXEC_QUEUE_SET_PROPERTY_MULTI_GROUP. Fails with
- *    -EOPNOTSUPP if the kernel is built without CONFIG_DRM_XE_EUDEBUG,
- *    and with -EPERM if eudebug is not enabled through sysfs.
+ *    -EOPNOTSUPP if the kernel is built without CONFIG_DRM_XE_EUDEBUG
+ *    or the GuC does not support debug contexts, and with -EPERM if
+ *    eudebug is not enabled through sysfs.
  *
  * The example below shows how to use &struct drm_xe_exec_queue_create to 
create
  * a simple exec_queue (no parallel submission) of class
-- 
2.53.0

Reply via email to