diff mbox series

[RFC,6/9] drm/i915/gt: Add sysfs cleanup function for engines

Message ID 20240723112046.123938-7-andi.shyti@linux.intel.com (mailing list archive)
State New, archived
Headers show
Series CCS static load balance | expand

Commit Message

Andi Shyti July 23, 2024, 11:20 a.m. UTC
Engines and their properties are exposed in:

/sys/class/drm/cardX/engine/<engine_name>

These files are cleaned up when the driver is removed. However,
when the presence of engines starts changing dynamically, we need
a function to clean up the existing ones.

Store the engine-related objects (kobj and kobj_defaults) in the
'intel_engine_cs' structure, and store the main directory's
object (sysfs_engines) in the 'drm_i915_private' structure.

No functional changes intended at this point, as this function
does not have users yet.

Signed-off-by: Andi Shyti <andi.shyti@linux.intel.com>
---
 drivers/gpu/drm/i915/gt/intel_engine_cs.c    |  2 ++
 drivers/gpu/drm/i915/gt/intel_engine_types.h |  3 +++
 drivers/gpu/drm/i915/gt/sysfs_engines.c      | 18 ++++++++++++++++++
 drivers/gpu/drm/i915/gt/sysfs_engines.h      |  1 +
 drivers/gpu/drm/i915/i915_drv.h              |  1 +
 5 files changed, 25 insertions(+)
diff mbox series

Patch

diff --git a/drivers/gpu/drm/i915/gt/intel_engine_cs.c b/drivers/gpu/drm/i915/gt/intel_engine_cs.c
index 8011df30023e..92043ad19409 100644
--- a/drivers/gpu/drm/i915/gt/intel_engine_cs.c
+++ b/drivers/gpu/drm/i915/gt/intel_engine_cs.c
@@ -716,6 +716,8 @@  void intel_engines_free(struct intel_gt *gt)
 		kfree(engine);
 		gt->engine[id] = NULL;
 	}
+
+	memset(gt->engine_class, 0, sizeof(gt->engine_class));
 }
 
 static
diff --git a/drivers/gpu/drm/i915/gt/intel_engine_types.h b/drivers/gpu/drm/i915/gt/intel_engine_types.h
index ba55c059063d..a0f2f5c08388 100644
--- a/drivers/gpu/drm/i915/gt/intel_engine_types.h
+++ b/drivers/gpu/drm/i915/gt/intel_engine_types.h
@@ -388,6 +388,9 @@  struct intel_engine_cs {
 	u32 context_size;
 	u32 mmio_base;
 
+	struct kobject *kobj;
+	struct kobject *kobj_defaults;
+
 	struct intel_engine_tlb_inv tlb_inv;
 
 	/*
diff --git a/drivers/gpu/drm/i915/gt/sysfs_engines.c b/drivers/gpu/drm/i915/gt/sysfs_engines.c
index 021f51d9b456..a38c1732848e 100644
--- a/drivers/gpu/drm/i915/gt/sysfs_engines.c
+++ b/drivers/gpu/drm/i915/gt/sysfs_engines.c
@@ -479,6 +479,8 @@  static void add_defaults(struct kobj_engine *parent)
 	if (intel_engine_has_preempt_reset(ke->engine) &&
 	    sysfs_create_file(&ke->base, &preempt_timeout_def.attr))
 		return;
+
+	parent->engine->kobj_defaults = &ke->base;
 }
 
 void intel_engines_add_sysfs(struct drm_i915_private *i915)
@@ -506,6 +508,8 @@  void intel_engines_add_sysfs(struct drm_i915_private *i915)
 	if (!dir)
 		return;
 
+	i915->sysfs_engine = dir;
+
 	for_each_uabi_engine(engine, i915) {
 		struct kobject *kobj;
 
@@ -526,6 +530,8 @@  void intel_engines_add_sysfs(struct drm_i915_private *i915)
 
 		add_defaults(container_of(kobj, struct kobj_engine, base));
 
+		engine->kobj = kobj;
+
 		if (0) {
 err_object:
 			kobject_put(kobj);
@@ -536,3 +542,15 @@  void intel_engines_add_sysfs(struct drm_i915_private *i915)
 		}
 	}
 }
+
+void intel_engines_remove_sysfs(struct drm_i915_private *i915)
+{
+	struct intel_engine_cs *engine;
+
+	for_each_uabi_engine(engine, i915) {
+		kobject_put(engine->kobj_defaults);
+		kobject_put(engine->kobj);
+	}
+
+	kobject_put(i915->sysfs_engine);
+}
diff --git a/drivers/gpu/drm/i915/gt/sysfs_engines.h b/drivers/gpu/drm/i915/gt/sysfs_engines.h
index 9546fffe03a7..09293a010025 100644
--- a/drivers/gpu/drm/i915/gt/sysfs_engines.h
+++ b/drivers/gpu/drm/i915/gt/sysfs_engines.h
@@ -9,5 +9,6 @@ 
 struct drm_i915_private;
 
 void intel_engines_add_sysfs(struct drm_i915_private *i915);
+void intel_engines_remove_sysfs(struct drm_i915_private *i915);
 
 #endif /* INTEL_ENGINE_SYSFS_H */
diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
index d7723dd11c80..1bdf9a0115c1 100644
--- a/drivers/gpu/drm/i915/i915_drv.h
+++ b/drivers/gpu/drm/i915/i915_drv.h
@@ -320,6 +320,7 @@  struct drm_i915_private {
 	struct intel_gt *gt[I915_MAX_GT];
 
 	struct kobject *sysfs_gt;
+	struct kobject *sysfs_engine;
 
 	/* Quick lookup of media GT (current platforms only have one) */
 	struct intel_gt *media_gt;