All of lore.kernel.org
 help / color / mirror / Atom feed
From: Matt Roper <matthew.d.roper@intel.com>
To: intel-xe@lists.freedesktop.org
Cc: Rodrigo Vivi <rodrigo.vivi@intel.com>,
	 Stuart Summers <stuart.summers@intel.com>,
	 Matt Roper <matthew.d.roper@intel.com>
Subject: [PATCH 2/2] drm/xe/configfs: Consolidate duplicated configfs lookup boilerplate
Date: Tue, 01 Dec 2026 16:23:49 -0800	[thread overview]
Message-ID: <20261201-configfs_simplify-v1-2-c90660854833@intel.com> (raw)
In-Reply-To: <20261201-configfs_simplify-v1-0-c90660854833@intel.com>

Several of our configfs attributes have lookup functions intended to be
called from other parts of the driver.  These lookup functions handle
some non-obvious reference counting and locking before returning either
the pdev-specific value (when available) or a default value otherwise.
This code is mostly identical between several of these functions, so we
can pull the common boilerplate out to a macro that can be used to
provide the function body and avoid any accidental mistakes when adding
new attributes.

Since these functions are intended for use elsewhere in the driver, them
macros added here only generate the function body, not the entire
function, so that the functions will still be easily searchable and
discoverable via tools like cscope/ctags.  Some of these functions also
have kerneldoc which we want to preserve.

Note that the existing implementations were somewhat inconsistent in how
they implemented the "unavailable" case --- some returned the value from
device_defaults, while others returned a literal value that matched the
value from device_defaults.  The new macros always perform the lookup
from device_defaults for consistency.

There should be no functional change here, only
refactoring/consolidation.

Signed-off-by: Matt Roper <matthew.d.roper@intel.com>
---
 drivers/gpu/drm/xe/xe_configfs.c | 101 +++++++++++++--------------------------
 1 file changed, 32 insertions(+), 69 deletions(-)

diff --git a/drivers/gpu/drm/xe/xe_configfs.c b/drivers/gpu/drm/xe/xe_configfs.c
index dffa4c37ec8f..5d0ddfcf4bab 100644
--- a/drivers/gpu/drm/xe/xe_configfs.c
+++ b/drivers/gpu/drm/xe/xe_configfs.c
@@ -926,6 +926,32 @@ static ssize_t gt_types_allowed_store(struct config_item *item, const char *page
 	return len;
 }
 
+#define _XE_SIMPLE_CONFIGFS_LOOKUP_NODEV_DEFAULT(name) {			\
+	if (!dev)								\
+		return device_defaults.name;					\
+}
+
+#define _XE_SIMPLE_CONFIGFS_LOOKUP_NODEV_DEBUG(name) {				\
+	if (!dev || !IS_ENABLED(CONFIG_DRM_XE_DEBUG)) {				\
+		if (dev)							\
+			config_group_put(&dev->group);				\
+		return device_defaults.name;					\
+	}									\
+}
+
+#define XE_SIMPLE_CONFIGFS_LOOKUP(name, buildtype) {				\
+	struct xe_config_group_device *dev = find_xe_config_group_device(pdev); \
+	typeof(dev->config.name) ret;						\
+										\
+	_XE_SIMPLE_CONFIGFS_LOOKUP_NODEV_##buildtype(name);			\
+										\
+	scoped_guard(mutex, &dev->lock)						\
+		ret = dev->config.name;						\
+	config_group_put(&dev->group);						\
+										\
+	return ret;								\
+}
+
 /**
  * xe_configfs_get_migrate_ulls_period_ms - get configfs migrate_ulls_period_ms setting
  * @pdev: pci device
@@ -934,17 +960,7 @@ static ssize_t gt_types_allowed_store(struct config_item *item, const char *page
  */
 u32 xe_configfs_get_migrate_ulls_period_ms(struct pci_dev *pdev)
 {
-	struct xe_config_group_device *dev = find_xe_config_group_device(pdev);
-	u32 ret;
-
-	if (!dev)
-		return device_defaults.migrate_ulls_period_ms;
-
-	scoped_guard(mutex, &dev->lock)
-		ret = dev->config.migrate_ulls_period_ms;
-	config_group_put(&dev->group);
-
-	return ret;
+	XE_SIMPLE_CONFIGFS_LOOKUP(migrate_ulls_period_ms, DEFAULT);
 }
 
 /**
@@ -955,17 +971,7 @@ u32 xe_configfs_get_migrate_ulls_period_ms(struct pci_dev *pdev)
  */
 u8 xe_configfs_get_survivability_mode(struct pci_dev *pdev)
 {
-	struct xe_config_group_device *dev = find_xe_config_group_device(pdev);
-	u8 mode;
-
-	if (!dev)
-		return device_defaults.survivability_mode;
-
-	scoped_guard(mutex, &dev->lock)
-		mode = dev->config.survivability_mode;
-	config_group_put(&dev->group);
-
-	return mode;
+	XE_SIMPLE_CONFIGFS_LOOKUP(survivability_mode, DEFAULT);
 }
 
 /**
@@ -977,17 +983,7 @@ u8 xe_configfs_get_survivability_mode(struct pci_dev *pdev)
  */
 bool xe_configfs_get_enable_multi_queue(struct pci_dev *pdev)
 {
-	struct xe_config_group_device *dev = find_xe_config_group_device(pdev);
-	bool ret;
-
-	if (!dev)
-		return true;
-
-	scoped_guard(mutex, &dev->lock)
-		ret = dev->config.enable_multi_queue;
-	config_group_put(&dev->group);
-
-	return ret;
+	XE_SIMPLE_CONFIGFS_LOOKUP(enable_multi_queue, DEFAULT);
 }
 
 /**
@@ -998,17 +994,7 @@ bool xe_configfs_get_enable_multi_queue(struct pci_dev *pdev)
  */
 bool xe_configfs_get_psmi_enabled(struct pci_dev *pdev)
 {
-	struct xe_config_group_device *dev = find_xe_config_group_device(pdev);
-	bool ret;
-
-	if (!dev)
-		return false;
-
-	scoped_guard(mutex, &dev->lock)
-		ret = dev->config.enable_psmi;
-	config_group_put(&dev->group);
-
-	return ret;
+	XE_SIMPLE_CONFIGFS_LOOKUP(enable_psmi, DEFAULT);
 }
 
 /**
@@ -1019,35 +1005,12 @@ bool xe_configfs_get_psmi_enabled(struct pci_dev *pdev)
  */
 bool xe_configfs_get_enable_vram_page_offline(struct pci_dev *pdev)
 {
-	struct xe_config_group_device *dev = find_xe_config_group_device(pdev);
-	bool ret;
-
-	if (!dev)
-		return device_defaults.enable_vram_page_offline;
-
-	scoped_guard(mutex, &dev->lock)
-		ret = dev->config.enable_vram_page_offline;
-	config_group_put(&dev->group);
-
-	return ret;
+	XE_SIMPLE_CONFIGFS_LOOKUP(enable_vram_page_offline, DEFAULT);
 }
 
 bool xe_configfs_get_force_ocode_load(struct pci_dev *pdev)
 {
-	struct xe_config_group_device *dev = find_xe_config_group_device(pdev);
-	bool force_load;
-
-	if (!dev || !IS_ENABLED(CONFIG_DRM_XE_DEBUG)) {
-		if (dev)
-			config_group_put(&dev->group);
-		return false;
-	}
-
-	scoped_guard(mutex, &dev->lock)
-		force_load = dev->config.force_ocode_load;
-	config_group_put(&dev->group);
-
-	return force_load;
+	XE_SIMPLE_CONFIGFS_LOOKUP(force_ocode_load, DEBUG);
 }
 
 static bool check_survivability_mode(u8 val)

-- 
2.43.0


  parent reply	other threads:[~2026-12-02  0:24 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-02  0:23 [PATCH 0/2] Reduce duplicate code for simple configfs attributes Matt Roper
2026-12-02  0:23 ` [PATCH 1/2] drm/xe/configfs: Reduce attribute getters/setters duplication via macros Matt Roper
2026-12-02  0:23 ` Matt Roper [this message]
2026-12-02  1:14 ` ✗ CI.checkpatch: warning for Reduce duplicate code for simple configfs attributes Patchwork
2026-12-02  1:17 ` ✓ CI.KUnit: success " Patchwork
2026-12-02  1:52 ` ✓ Xe.CI.BAT: " Patchwork
2026-12-02 16:30 ` [PATCH 0/2] " Summers, Stuart

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261201-configfs_simplify-v1-2-c90660854833@intel.com \
    --to=matthew.d.roper@intel.com \
    --cc=intel-xe@lists.freedesktop.org \
    --cc=rodrigo.vivi@intel.com \
    --cc=stuart.summers@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.