From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 7CF31C3DA7E for ; Tue, 30 Jul 2024 11:47:16 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 41E3010E50A; Tue, 30 Jul 2024 11:47:16 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.b="UDPwYetN"; dkim-atps=neutral Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.14]) by gabe.freedesktop.org (Postfix) with ESMTPS id BBE3910E50E for ; Tue, 30 Jul 2024 11:47:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1722340035; x=1753876035; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=MZvmKYNFk0egXajpSFryQHn72sl8pknpeqddKCf3mVU=; b=UDPwYetNo5YQf48wA7OWq9oR9rCZ0HiRD3UAIgfkivgskoVbRNa41uh/ cmEFKuDICJRep5QYQbGhgNHFoPyBPHuLAZ4ONxsA2xPxn/UuweLshoOCA 88aKOrwAlq+nsppiWziqnV0h8eVUKdEMdmP4dcXdaddGp2sSP/1tv3kMr 8Juan4MpBluiVePOcPMlHRAR94bG2SejYE7tvOP4pgS4j+pHqx4CYvEF+ mCN9umXENFJqPxZEq7bTgCzr8pKTsyCI6bu2j91ZNeGKvzoFQIOgjjPRT jACsVPezkGEXxmBzXmjFv3KauSepVET91kOidKY0xKUQLAEbGvl3uL4a4 w==; X-CSE-ConnectionGUID: oxI5jMv+RxqNjBIhfWpI8w== X-CSE-MsgGUID: yyzy2ByYSkOqfbg7ZDCjHQ== X-IronPort-AV: E=McAfee;i="6700,10204,11148"; a="23937196" X-IronPort-AV: E=Sophos;i="6.09,248,1716274800"; d="scan'208";a="23937196" Received: from fmviesa008.fm.intel.com ([10.60.135.148]) by orvoesa106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Jul 2024 04:47:15 -0700 X-CSE-ConnectionGUID: O697P1jNRqCq56a4pM5qdw== X-CSE-MsgGUID: V+lsJ5JYRjOLEwC02zeH2Q== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.09,248,1716274800"; d="scan'208";a="54216571" Received: from cpetruta-mobl1.ger.corp.intel.com (HELO localhost.localdomain) ([10.245.246.43]) by fmviesa008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Jul 2024 04:47:12 -0700 From: Christoph Manszewski To: igt-dev@lists.freedesktop.org Cc: =?UTF-8?q?Zbigniew=20Kempczy=C5=84ski?= , Kamil Konieczny , Dominik Grzegorzek , Maciej Patelczyk , =?UTF-8?q?Dominik=20Karol=20Pi=C4=85tkowski?= , Pawel Sikora , Andrzej Hajda , Kolanupaka Naveena , Mika Kuoppala , Gwan-gyeong Mun Subject: [PATCH i-g-t v2 11/66] lib/xe_eudebug: Add support for dynamic debugger sysfs toggle Date: Tue, 30 Jul 2024 13:44:28 +0200 Message-Id: <20240730114523.334156-12-christoph.manszewski@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240730114523.334156-1-christoph.manszewski@intel.com> References: <20240730114523.334156-1-christoph.manszewski@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: igt-dev@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development mailing list for IGT GPU Tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: igt-dev-bounces@lists.freedesktop.org Sender: "igt-dev" The debugger now uses a dedicated sysfs entry: /sys/class/drm/card/device/enable_eudebug to toggle the debugger on/off. This change adds helper functons for toggling the debugger. Signed-off-by: Mika Kuoppala Signed-off-by: Christoph Manszewski Cc: Dominik Grzegorzek --- lib/xe/xe_eudebug.c | 88 +++++++++++++++++++++++++++++++++++++++++++++ lib/xe/xe_eudebug.h | 3 ++ 2 files changed, 91 insertions(+) diff --git a/lib/xe/xe_eudebug.c b/lib/xe/xe_eudebug.c index af7cc5fc4..36eef25c7 100644 --- a/lib/xe/xe_eudebug.c +++ b/lib/xe/xe_eudebug.c @@ -7,10 +7,12 @@ #include #include #include +#include #include #include #include "igt.h" +#include "igt_sysfs.h" #include "intel_pat.h" #include "xe_eudebug.h" #include "xe_ioctl.h" @@ -1040,6 +1042,24 @@ static void *debugger_worker_loop(void *data) return NULL; } +/** + * xe_eudebug_debugger_available: + * @fd: Xe file descriptor + * + * Returns: true it debugger connection is available, false otherwise. + */ +bool xe_eudebug_debugger_available(int fd) +{ + struct drm_xe_eudebug_connect param = { .pid = getpid() }; + int debugfd; + + debugfd = igt_ioctl(fd, DRM_IOCTL_XE_EUDEBUG_CONNECT, ¶m); + if (debugfd >= 0) + close(debugfd); + + return debugfd >= 0; +} + /** * xe_eudebug_debugger_create: * @master_fd: xe client used to open the debugger connection @@ -1563,6 +1583,74 @@ static void metadata_event(struct xe_eudebug_client *c, uint32_t flags, xe_eudebug_event_log_write(c->log, (void *)&em); } +static int enable_getset(int fd, bool *old, bool *new) +{ + static const char * const fname = "enable_eudebug"; + int ret = 0; + + int sysfs, device_fd; + bool val_before; + struct stat st; + + igt_assert(new || old); + + igt_assert_eq(fstat(fd, &st), 0); + sysfs = igt_sysfs_open(fd); + if (sysfs < 0) + return -1; + + device_fd = openat(sysfs, "device", O_DIRECTORY | O_RDONLY); + close(sysfs); + if (device_fd < 0) + return -1; + + if (!__igt_sysfs_get_boolean(device_fd, fname, &val_before)) { + ret = -1; + goto out; + } + + igt_debug("enable_eudebug before: %d\n", val_before); + + if (old) + *old = val_before; + + ret = 0; + if (new) { + if (__igt_sysfs_set_boolean(device_fd, fname, *new)) + igt_assert_eq(igt_sysfs_get_boolean(device_fd, fname), *new); + else + ret = -1; + } + +out: + close(device_fd); + return ret; +} + +/** + * xe_eudebug_enable + * @fd: xe client + * @enable: state toggle - true to enable, false to disable + * + * Enables/disables eudebug capability by writing to + * '/sys/class/drm/card/device/enable_eudebug' sysfs entry. + * + * Returns: previous toggle value, i.e. true when eudebugging was enabled, + * false when eudebugging was disabled. + */ +bool xe_eudebug_enable(int fd, bool enable) +{ + bool old = false; + int ret = enable_getset(fd, &old, &enable); + + if (ret) { + igt_skip_on(enable); + old = false; + } + + return old; +} + /* Eu debugger wrappers around resource creating xe ioctls. */ /** diff --git a/lib/xe/xe_eudebug.h b/lib/xe/xe_eudebug.h index ec75634f5..1343cb25c 100644 --- a/lib/xe/xe_eudebug.h +++ b/lib/xe/xe_eudebug.h @@ -123,6 +123,7 @@ void xe_eudebug_event_log_compare(struct xe_eudebug_event_log *c, struct xe_eude void xe_eudebug_event_log_write(struct xe_eudebug_event_log *l, struct drm_xe_eudebug_event *e); void xe_eudebug_event_log_match_opposite(struct xe_eudebug_event_log *l, uint32_t filter); +bool xe_eudebug_debugger_available(int fd); struct xe_eudebug_debugger * xe_eudebug_debugger_create(int xe, uint64_t flags, void *data); void xe_eudebug_debugger_destroy(struct xe_eudebug_debugger *d); @@ -146,6 +147,8 @@ void xe_eudebug_client_wait_stage(struct xe_eudebug_client *c, uint64_t stage); uint64_t xe_eudebug_client_get_seqno(struct xe_eudebug_client *c); void xe_eudebug_client_set_data(struct xe_eudebug_client *c, void *ptr); +bool xe_eudebug_enable(int fd, bool enable); + int xe_eudebug_client_open_driver(struct xe_eudebug_client *c); void xe_eudebug_client_close_driver(struct xe_eudebug_client *c, int fd); uint32_t xe_eudebug_client_vm_create(struct xe_eudebug_client *c, int fd, -- 2.34.1