diff mbox series

[1/6] drm/debugfs: Introduce wrapper for debugfs list

Message ID 20230116102815.95063-2-mcanal@igalia.com (mailing list archive)
State New, archived
Headers show
Series drm/debugfs: Make the debugfs structure more generic | expand

Commit Message

Maíra Canal Jan. 16, 2023, 10:28 a.m. UTC
Introduce a struct wrapper for all the debugfs-related stuff: the list
of debugfs files and the mutex that protects it. This will make it
easier to initialize all the debugfs list in a DRM object and will
create a good abstraction for a possible implementation of the debugfs
infrastructure for KMS objects.

Signed-off-by: Maíra Canal <mcanal@igalia.com>
---
 drivers/gpu/drm/drm_debugfs.c  | 11 +++++++++++
 drivers/gpu/drm/drm_internal.h | 11 +++++++++++
 include/drm/drm_debugfs.h      | 16 ++++++++++++++++
 3 files changed, 38 insertions(+)
diff mbox series

Patch

diff --git a/drivers/gpu/drm/drm_debugfs.c b/drivers/gpu/drm/drm_debugfs.c
index 4f643a490dc3..2f104a9e4276 100644
--- a/drivers/gpu/drm/drm_debugfs.c
+++ b/drivers/gpu/drm/drm_debugfs.c
@@ -218,6 +218,17 @@  void drm_debugfs_create_files(const struct drm_info_list *files, int count,
 }
 EXPORT_SYMBOL(drm_debugfs_create_files);
 
+void drm_debugfs_list_init(struct drm_debugfs_list *debugfs_list)
+{
+	INIT_LIST_HEAD(&debugfs_list->list);
+	mutex_init(&debugfs_list->mutex);
+}
+
+void drm_debugfs_list_destroy(struct drm_debugfs_list *debugfs_list)
+{
+	mutex_destroy(&debugfs_list->mutex);
+}
+
 int drm_debugfs_init(struct drm_minor *minor, int minor_id,
 		     struct dentry *root)
 {
diff --git a/drivers/gpu/drm/drm_internal.h b/drivers/gpu/drm/drm_internal.h
index ed2103ee272c..8fdecefb50bd 100644
--- a/drivers/gpu/drm/drm_internal.h
+++ b/drivers/gpu/drm/drm_internal.h
@@ -23,6 +23,7 @@ 
 
 #include <linux/kthread.h>
 
+#include <drm/drm_debugfs.h>
 #include <drm/drm_ioctl.h>
 #include <drm/drm_vblank.h>
 
@@ -183,6 +184,8 @@  int drm_gem_dumb_destroy(struct drm_file *file, struct drm_device *dev,
 
 /* drm_debugfs.c drm_debugfs_crc.c */
 #if defined(CONFIG_DEBUG_FS)
+void drm_debugfs_list_init(struct drm_debugfs_list *debugfs_list);
+void drm_debugfs_list_destroy(struct drm_debugfs_list *debugfs_list);
 int drm_debugfs_init(struct drm_minor *minor, int minor_id,
 		     struct dentry *root);
 void drm_debugfs_cleanup(struct drm_minor *minor);
@@ -193,6 +196,14 @@  void drm_debugfs_crtc_add(struct drm_crtc *crtc);
 void drm_debugfs_crtc_remove(struct drm_crtc *crtc);
 void drm_debugfs_crtc_crc_add(struct drm_crtc *crtc);
 #else
+static inline void drm_debugfs_list_init(struct drm_debugfs_list *debugfs_list)
+{
+}
+
+static inline void drm_debugfs_list_destroy(struct drm_debugfs_list *debugfs_list)
+{
+}
+
 static inline int drm_debugfs_init(struct drm_minor *minor, int minor_id,
 				   struct dentry *root)
 {
diff --git a/include/drm/drm_debugfs.h b/include/drm/drm_debugfs.h
index 7616f457ce70..8658e97a88cf 100644
--- a/include/drm/drm_debugfs.h
+++ b/include/drm/drm_debugfs.h
@@ -32,6 +32,8 @@ 
 #ifndef _DRM_DEBUGFS_H_
 #define _DRM_DEBUGFS_H_
 
+#include <linux/list.h>
+#include <linux/mutex.h>
 #include <linux/types.h>
 #include <linux/seq_file.h>
 /**
@@ -79,6 +81,20 @@  struct drm_info_node {
 	struct dentry *dent;
 };
 
+/**
+ * struct drm_debugfs_list - Encapsulates the debugfs list and its mutex
+ *
+ * This structure represents the debugfs list of files and is encapsulated
+ * with a mutex to protect the access of the list.
+ */
+struct drm_debugfs_list {
+	/** @list: List of debugfs files to be created by the DRM object. */
+	struct list_head list;
+
+	/** @mutex: Protects &list access. */
+	struct mutex mutex;
+};
+
 /**
  * struct drm_debugfs_info - debugfs info list entry
  *