dri-devel.lists.freedesktop.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3 0/6] drm/debugfs: Make the debugfs structure more generic
@ 2023-01-31 19:58 Maíra Canal
  2023-01-31 19:58 ` [PATCH v3 1/6] drm/debugfs: Introduce wrapper for debugfs list Maíra Canal
                   ` (5 more replies)
  0 siblings, 6 replies; 14+ messages in thread
From: Maíra Canal @ 2023-01-31 19:58 UTC (permalink / raw)
  To: Daniel Vetter, David Airlie, Maarten Lankhorst, Maxime Ripard,
	Thomas Zimmermann, Liviu Dudau, Brian Starkey,
	Noralf Trønnes, Melissa Wen, Rodrigo Siqueira, Jani Nikula
  Cc: Maíra Canal, André Almeida, dri-devel

This series is the first step to introduce a debugfs structure to KMS objects
and it is inspired by the feedback provided in [1]. Thanks, Jani and Daniel for
all the feedback provided!

This first step is making the current API more generic and preparing it to
receive the KMS objects in the future. Moreover, this will help to avoid
copypasting when expanding the API.

Make the debug structure more generic by:

- Passing the right pointer to the functions as an explicit parameter. So, the
  show function signature should be

    int show(struct seq_file *m, struct drm_device *dev, void *data)

  Note that with this approach, the show callback doesn't need to use the struct
  drm_debugfs_entry anymore.

- Switch the pointer in struct drm_debugfs_entry to void *, so that, in the
  future, the struct drm_debugfs_entry can receive different types of DRM
  objects (struct drm_device, struct drm_connector, struct drm_crtc...).

- Switch the show callback pointer to void * and cast it in the show callback
  wrapper. This way in the future we can create different callback wrappers and
  cast each one to the proper function signature.

- Add a struct wrapper for debugfs_list and debugfs_mutex, and also create
  helpers to init the list, destroy the list, register the list's files and add
  files to the list.

v1 -> v2: https://lore.kernel.org/dri-devel/20230116102815.95063-1-mcanal@igalia.com/T/

- Use forward declaration instead of the header (Jani Nikula).
- Make the struct drm_debugfs_files a pointer in struct drm_device (Jani Nikula).
- Change the parameter order of `drm_debugfs_files_add` (Jani Nikula).
- s/struct drm_debugfs_list/struct drm_debugfs_files (Jani Nikula).

v2 -> v3: https://lore.kernel.org/dri-devel/20230130123008.287141-1-mcanal@igalia.com/T/

- Fix compilation errors for CONFIG_DEBUG_FS=n (kernel test robot).

[1] https://lore.kernel.org/dri-devel/20230111173748.752659-1-mcanal@igalia.com/T/

Best Regards,
- Maíra Canal

Maíra Canal (6):
  drm/debugfs: Introduce wrapper for debugfs list
  drm/debugfs: Make drm_device use the struct drm_debugfs_files
  drm/debugfs: Create wrapper to add files to debugfs list
  drm/debugfs: Create wrapper to register debugfs
  drm/debugfs: Make the show callback pass the pointer to the right
    object
  drm/debugfs: Make the struct drm_debugfs_entry independent of DRM
    device

 drivers/gpu/drm/arm/hdlcd_drv.c       |  8 +--
 drivers/gpu/drm/drm_atomic.c          |  4 +-
 drivers/gpu/drm/drm_client.c          |  5 +-
 drivers/gpu/drm/drm_debugfs.c         | 81 +++++++++++++++++----------
 drivers/gpu/drm/drm_drv.c             |  7 ++-
 drivers/gpu/drm/drm_framebuffer.c     |  4 +-
 drivers/gpu/drm/drm_gem_vram_helper.c |  5 +-
 drivers/gpu/drm/drm_internal.h        | 12 ++++
 drivers/gpu/drm/gud/gud_drv.c         |  5 +-
 drivers/gpu/drm/v3d/v3d_debugfs.c     | 16 ++----
 drivers/gpu/drm/vc4/vc4_bo.c          |  4 +-
 drivers/gpu/drm/vc4/vc4_debugfs.c     |  6 +-
 drivers/gpu/drm/vc4/vc4_hdmi.c        |  6 +-
 drivers/gpu/drm/vc4/vc4_hvs.c         |  8 +--
 drivers/gpu/drm/vc4/vc4_v3d.c         |  4 +-
 drivers/gpu/drm/vkms/vkms_drv.c       |  4 +-
 include/drm/drm_debugfs.h             | 34 ++++++++---
 include/drm/drm_device.h              | 12 +---
 18 files changed, 120 insertions(+), 105 deletions(-)

-- 
2.39.1


^ permalink raw reply	[flat|nested] 14+ messages in thread

* [PATCH v3 1/6] drm/debugfs: Introduce wrapper for debugfs list
  2023-01-31 19:58 [PATCH v3 0/6] drm/debugfs: Make the debugfs structure more generic Maíra Canal
@ 2023-01-31 19:58 ` Maíra Canal
  2023-02-08 18:06   ` Daniel Vetter
  2023-01-31 19:58 ` [PATCH v3 2/6] drm/debugfs: Make drm_device use the struct drm_debugfs_files Maíra Canal
                   ` (4 subsequent siblings)
  5 siblings, 1 reply; 14+ messages in thread
From: Maíra Canal @ 2023-01-31 19:58 UTC (permalink / raw)
  To: Daniel Vetter, David Airlie, Maarten Lankhorst, Maxime Ripard,
	Thomas Zimmermann, Liviu Dudau, Brian Starkey,
	Noralf Trønnes, Melissa Wen, Rodrigo Siqueira, Jani Nikula
  Cc: Maíra Canal, André Almeida, dri-devel

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  | 18 ++++++++++++++++++
 drivers/gpu/drm/drm_internal.h | 12 ++++++++++++
 include/drm/drm_debugfs.h      | 16 ++++++++++++++++
 3 files changed, 46 insertions(+)

diff --git a/drivers/gpu/drm/drm_debugfs.c b/drivers/gpu/drm/drm_debugfs.c
index 4f643a490dc3..8658d3929ea5 100644
--- a/drivers/gpu/drm/drm_debugfs.c
+++ b/drivers/gpu/drm/drm_debugfs.c
@@ -218,6 +218,24 @@ void drm_debugfs_create_files(const struct drm_info_list *files, int count,
 }
 EXPORT_SYMBOL(drm_debugfs_create_files);
 
+struct drm_debugfs_files *drm_debugfs_files_init(void)
+{
+	struct drm_debugfs_files *debugfs_files;
+
+	debugfs_files = kzalloc(sizeof(*debugfs_files), GFP_KERNEL);
+
+	INIT_LIST_HEAD(&debugfs_files->list);
+	mutex_init(&debugfs_files->mutex);
+
+	return debugfs_files;
+}
+
+void drm_debugfs_files_destroy(struct drm_debugfs_files *debugfs_files)
+{
+	mutex_destroy(&debugfs_files->mutex);
+	kfree(debugfs_files);
+}
+
 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..f1c8766ed828 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)
+struct drm_debugfs_files *drm_debugfs_files_init(void);
+void drm_debugfs_files_destroy(struct drm_debugfs_files *debugfs_files);
 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,15 @@ 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 struct drm_debugfs_files *drm_debugfs_files_init(void)
+{
+	return NULL;
+}
+
+static inline void drm_debugfs_files_destroy(struct drm_debugfs_files *debugfs_files)
+{
+}
+
 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..423aa3de506a 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_files - 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_files {
+	/** @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
  *
-- 
2.39.1


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH v3 2/6] drm/debugfs: Make drm_device use the struct drm_debugfs_files
  2023-01-31 19:58 [PATCH v3 0/6] drm/debugfs: Make the debugfs structure more generic Maíra Canal
  2023-01-31 19:58 ` [PATCH v3 1/6] drm/debugfs: Introduce wrapper for debugfs list Maíra Canal
@ 2023-01-31 19:58 ` Maíra Canal
  2023-01-31 19:58 ` [PATCH v3 3/6] drm/debugfs: Create wrapper to add files to debugfs list Maíra Canal
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 14+ messages in thread
From: Maíra Canal @ 2023-01-31 19:58 UTC (permalink / raw)
  To: Daniel Vetter, David Airlie, Maarten Lankhorst, Maxime Ripard,
	Thomas Zimmermann, Liviu Dudau, Brian Starkey,
	Noralf Trønnes, Melissa Wen, Rodrigo Siqueira, Jani Nikula
  Cc: Maíra Canal, André Almeida, dri-devel

The struct drm_debugfs_files encapsulates all the debugfs-related
objects, so that they can be initialized and destroyed with two helpers.
Therefore, make the struct drm_device use the struct drm_debugfs_files
instead of instantiating the debugfs list and mutex separated.

Signed-off-by: Maíra Canal <mcanal@igalia.com>
---
 drivers/gpu/drm/drm_debugfs.c | 10 +++++-----
 drivers/gpu/drm/drm_drv.c     |  7 ++++---
 include/drm/drm_device.h      | 12 +++---------
 3 files changed, 12 insertions(+), 17 deletions(-)

diff --git a/drivers/gpu/drm/drm_debugfs.c b/drivers/gpu/drm/drm_debugfs.c
index 8658d3929ea5..aa83f230c402 100644
--- a/drivers/gpu/drm/drm_debugfs.c
+++ b/drivers/gpu/drm/drm_debugfs.c
@@ -263,7 +263,7 @@ int drm_debugfs_init(struct drm_minor *minor, int minor_id,
 	if (dev->driver->debugfs_init)
 		dev->driver->debugfs_init(minor);
 
-	list_for_each_entry_safe(entry, tmp, &dev->debugfs_list, list) {
+	list_for_each_entry_safe(entry, tmp, &dev->debugfs_files->list, list) {
 		debugfs_create_file(entry->file.name, 0444,
 				    minor->debugfs_root, entry, &drm_debugfs_entry_fops);
 		list_del(&entry->list);
@@ -280,7 +280,7 @@ void drm_debugfs_late_register(struct drm_device *dev)
 	if (!minor)
 		return;
 
-	list_for_each_entry_safe(entry, tmp, &dev->debugfs_list, list) {
+	list_for_each_entry_safe(entry, tmp, &dev->debugfs_files->list, list) {
 		debugfs_create_file(entry->file.name, 0444,
 				    minor->debugfs_root, entry, &drm_debugfs_entry_fops);
 		list_del(&entry->list);
@@ -357,9 +357,9 @@ void drm_debugfs_add_file(struct drm_device *dev, const char *name,
 	entry->file.data = data;
 	entry->dev = dev;
 
-	mutex_lock(&dev->debugfs_mutex);
-	list_add(&entry->list, &dev->debugfs_list);
-	mutex_unlock(&dev->debugfs_mutex);
+	mutex_lock(&dev->debugfs_files->mutex);
+	list_add(&entry->list, &dev->debugfs_files->list);
+	mutex_unlock(&dev->debugfs_files->mutex);
 }
 EXPORT_SYMBOL(drm_debugfs_add_file);
 
diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
index c6eb8972451a..50812cbe1d81 100644
--- a/drivers/gpu/drm/drm_drv.c
+++ b/drivers/gpu/drm/drm_drv.c
@@ -39,6 +39,7 @@
 #include <drm/drm_cache.h>
 #include <drm/drm_client.h>
 #include <drm/drm_color_mgmt.h>
+#include <drm/drm_debugfs.h>
 #include <drm/drm_drv.h>
 #include <drm/drm_file.h>
 #include <drm/drm_managed.h>
@@ -598,7 +599,7 @@ static void drm_dev_init_release(struct drm_device *dev, void *res)
 	mutex_destroy(&dev->clientlist_mutex);
 	mutex_destroy(&dev->filelist_mutex);
 	mutex_destroy(&dev->struct_mutex);
-	mutex_destroy(&dev->debugfs_mutex);
+	drm_debugfs_files_destroy(dev->debugfs_files);
 	drm_legacy_destroy_members(dev);
 }
 
@@ -639,14 +640,14 @@ static int drm_dev_init(struct drm_device *dev,
 	INIT_LIST_HEAD(&dev->filelist_internal);
 	INIT_LIST_HEAD(&dev->clientlist);
 	INIT_LIST_HEAD(&dev->vblank_event_list);
-	INIT_LIST_HEAD(&dev->debugfs_list);
 
 	spin_lock_init(&dev->event_lock);
 	mutex_init(&dev->struct_mutex);
 	mutex_init(&dev->filelist_mutex);
 	mutex_init(&dev->clientlist_mutex);
 	mutex_init(&dev->master_mutex);
-	mutex_init(&dev->debugfs_mutex);
+
+	dev->debugfs_files = drm_debugfs_files_init();
 
 	ret = drmm_add_action_or_reset(dev, drm_dev_init_release, NULL);
 	if (ret)
diff --git a/include/drm/drm_device.h b/include/drm/drm_device.h
index 7cf4afae2e79..77290f4a06ff 100644
--- a/include/drm/drm_device.h
+++ b/include/drm/drm_device.h
@@ -16,6 +16,7 @@ struct drm_vblank_crtc;
 struct drm_vma_offset_manager;
 struct drm_vram_mm;
 struct drm_fb_helper;
+struct drm_debugfs_files;
 
 struct inode;
 
@@ -312,19 +313,12 @@ struct drm_device {
 	struct drm_fb_helper *fb_helper;
 
 	/**
-	 * @debugfs_mutex:
-	 *
-	 * Protects &debugfs_list access.
-	 */
-	struct mutex debugfs_mutex;
-
-	/**
-	 * @debugfs_list:
+	 * @debugfs_files:
 	 *
 	 * List of debugfs files to be created by the DRM device. The files
 	 * must be added during drm_dev_register().
 	 */
-	struct list_head debugfs_list;
+	struct drm_debugfs_files *debugfs_files;
 
 	/* Everything below here is for legacy driver, never use! */
 	/* private: */
-- 
2.39.1


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH v3 3/6] drm/debugfs: Create wrapper to add files to debugfs list
  2023-01-31 19:58 [PATCH v3 0/6] drm/debugfs: Make the debugfs structure more generic Maíra Canal
  2023-01-31 19:58 ` [PATCH v3 1/6] drm/debugfs: Introduce wrapper for debugfs list Maíra Canal
  2023-01-31 19:58 ` [PATCH v3 2/6] drm/debugfs: Make drm_device use the struct drm_debugfs_files Maíra Canal
@ 2023-01-31 19:58 ` Maíra Canal
  2023-01-31 19:58 ` [PATCH v3 4/6] drm/debugfs: Create wrapper to register debugfs Maíra Canal
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 14+ messages in thread
From: Maíra Canal @ 2023-01-31 19:58 UTC (permalink / raw)
  To: Daniel Vetter, David Airlie, Maarten Lankhorst, Maxime Ripard,
	Thomas Zimmermann, Liviu Dudau, Brian Starkey,
	Noralf Trønnes, Melissa Wen, Rodrigo Siqueira, Jani Nikula
  Cc: Maíra Canal, André Almeida, dri-devel

Create a helper to encapsulate the code that adds a new debugfs file to
a linked list related to a object. Moreover, the helper also provides
more flexibily, as the parameter is a struct drm_debugfs_files.

Signed-off-by: Maíra Canal <mcanal@igalia.com>
---
 drivers/gpu/drm/drm_debugfs.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/drm_debugfs.c b/drivers/gpu/drm/drm_debugfs.c
index aa83f230c402..0e3f3ffa9f88 100644
--- a/drivers/gpu/drm/drm_debugfs.c
+++ b/drivers/gpu/drm/drm_debugfs.c
@@ -236,6 +236,13 @@ void drm_debugfs_files_destroy(struct drm_debugfs_files *debugfs_files)
 	kfree(debugfs_files);
 }
 
+static void drm_debugfs_files_add(struct drm_debugfs_files *debugfs_files, struct list_head *entry)
+{
+	mutex_lock(&debugfs_files->mutex);
+	list_add(entry, &debugfs_files->list);
+	mutex_unlock(&debugfs_files->mutex);
+}
+
 int drm_debugfs_init(struct drm_minor *minor, int minor_id,
 		     struct dentry *root)
 {
@@ -357,9 +364,7 @@ void drm_debugfs_add_file(struct drm_device *dev, const char *name,
 	entry->file.data = data;
 	entry->dev = dev;
 
-	mutex_lock(&dev->debugfs_files->mutex);
-	list_add(&entry->list, &dev->debugfs_files->list);
-	mutex_unlock(&dev->debugfs_files->mutex);
+	drm_debugfs_files_add(dev->debugfs_files, &entry->list);
 }
 EXPORT_SYMBOL(drm_debugfs_add_file);
 
-- 
2.39.1


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH v3 4/6] drm/debugfs: Create wrapper to register debugfs
  2023-01-31 19:58 [PATCH v3 0/6] drm/debugfs: Make the debugfs structure more generic Maíra Canal
                   ` (2 preceding siblings ...)
  2023-01-31 19:58 ` [PATCH v3 3/6] drm/debugfs: Create wrapper to add files to debugfs list Maíra Canal
@ 2023-01-31 19:58 ` Maíra Canal
  2023-01-31 19:58 ` [PATCH v3 5/6] drm/debugfs: Make the show callback pass the pointer to the right object Maíra Canal
  2023-01-31 19:58 ` [PATCH v3 6/6] drm/debugfs: Make the struct drm_debugfs_entry independent of DRM device Maíra Canal
  5 siblings, 0 replies; 14+ messages in thread
From: Maíra Canal @ 2023-01-31 19:58 UTC (permalink / raw)
  To: Daniel Vetter, David Airlie, Maarten Lankhorst, Maxime Ripard,
	Thomas Zimmermann, Liviu Dudau, Brian Starkey,
	Noralf Trønnes, Melissa Wen, Rodrigo Siqueira, Jani Nikula
  Cc: Maíra Canal, André Almeida, dri-devel

Create a helper to encapsulate the code that creates a new debugfs files
from a linked list related to an object. Moreover, the helper also
provides more flexibily on the type of the object.

Signed-off-by: Maíra Canal <mcanal@igalia.com>
---
 drivers/gpu/drm/drm_debugfs.c | 25 +++++++++++++------------
 1 file changed, 13 insertions(+), 12 deletions(-)

diff --git a/drivers/gpu/drm/drm_debugfs.c b/drivers/gpu/drm/drm_debugfs.c
index 0e3f3ffa9f88..b4d2e7dd87f5 100644
--- a/drivers/gpu/drm/drm_debugfs.c
+++ b/drivers/gpu/drm/drm_debugfs.c
@@ -243,11 +243,21 @@ static void drm_debugfs_files_add(struct drm_debugfs_files *debugfs_files, struc
 	mutex_unlock(&debugfs_files->mutex);
 }
 
+static void drm_debugfs_register(struct drm_minor *minor, struct drm_debugfs_files *debugfs_files)
+{
+	struct drm_debugfs_entry *entry, *tmp;
+
+	list_for_each_entry_safe(entry, tmp, &debugfs_files->list, list) {
+		debugfs_create_file(entry->file.name, 0444,
+				    minor->debugfs_root, entry, &drm_debugfs_entry_fops);
+		list_del(&entry->list);
+	}
+}
+
 int drm_debugfs_init(struct drm_minor *minor, int minor_id,
 		     struct dentry *root)
 {
 	struct drm_device *dev = minor->dev;
-	struct drm_debugfs_entry *entry, *tmp;
 	char name[64];
 
 	INIT_LIST_HEAD(&minor->debugfs_list);
@@ -270,11 +280,7 @@ int drm_debugfs_init(struct drm_minor *minor, int minor_id,
 	if (dev->driver->debugfs_init)
 		dev->driver->debugfs_init(minor);
 
-	list_for_each_entry_safe(entry, tmp, &dev->debugfs_files->list, list) {
-		debugfs_create_file(entry->file.name, 0444,
-				    minor->debugfs_root, entry, &drm_debugfs_entry_fops);
-		list_del(&entry->list);
-	}
+	drm_debugfs_register(minor, dev->debugfs_files);
 
 	return 0;
 }
@@ -282,16 +288,11 @@ int drm_debugfs_init(struct drm_minor *minor, int minor_id,
 void drm_debugfs_late_register(struct drm_device *dev)
 {
 	struct drm_minor *minor = dev->primary;
-	struct drm_debugfs_entry *entry, *tmp;
 
 	if (!minor)
 		return;
 
-	list_for_each_entry_safe(entry, tmp, &dev->debugfs_files->list, list) {
-		debugfs_create_file(entry->file.name, 0444,
-				    minor->debugfs_root, entry, &drm_debugfs_entry_fops);
-		list_del(&entry->list);
-	}
+	drm_debugfs_register(minor, dev->debugfs_files);
 }
 
 int drm_debugfs_remove_files(const struct drm_info_list *files, int count,
-- 
2.39.1


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH v3 5/6] drm/debugfs: Make the show callback pass the pointer to the right object
  2023-01-31 19:58 [PATCH v3 0/6] drm/debugfs: Make the debugfs structure more generic Maíra Canal
                   ` (3 preceding siblings ...)
  2023-01-31 19:58 ` [PATCH v3 4/6] drm/debugfs: Create wrapper to register debugfs Maíra Canal
@ 2023-01-31 19:58 ` Maíra Canal
  2023-02-08 18:12   ` Daniel Vetter
  2023-01-31 19:58 ` [PATCH v3 6/6] drm/debugfs: Make the struct drm_debugfs_entry independent of DRM device Maíra Canal
  5 siblings, 1 reply; 14+ messages in thread
From: Maíra Canal @ 2023-01-31 19:58 UTC (permalink / raw)
  To: Daniel Vetter, David Airlie, Maarten Lankhorst, Maxime Ripard,
	Thomas Zimmermann, Liviu Dudau, Brian Starkey,
	Noralf Trønnes, Melissa Wen, Rodrigo Siqueira, Jani Nikula
  Cc: Maíra Canal, André Almeida, dri-devel

Currently, the drivers need to access the struct drm_debugfs_entry to
get the proper device on the show callback. There is no need for such
thing, as you can wrap the show callback in order to provide to the
driver the proper parameters: the struct seq_file, the struct drm_device
and the driver-specific data stored in the struct drm_debugfs_info.

Therefore, make the show callback pass the pointer to the right object
in the parameters, which makes the API more type-safe.

Signed-off-by: Maíra Canal <mcanal@igalia.com>
---
 drivers/gpu/drm/arm/hdlcd_drv.c       |  8 ++------
 drivers/gpu/drm/drm_atomic.c          |  4 +---
 drivers/gpu/drm/drm_client.c          |  5 ++---
 drivers/gpu/drm/drm_debugfs.c         | 25 ++++++++++++-------------
 drivers/gpu/drm/drm_framebuffer.c     |  4 +---
 drivers/gpu/drm/drm_gem_vram_helper.c |  5 ++---
 drivers/gpu/drm/gud/gud_drv.c         |  5 ++---
 drivers/gpu/drm/v3d/v3d_debugfs.c     | 16 ++++------------
 drivers/gpu/drm/vc4/vc4_bo.c          |  4 +---
 drivers/gpu/drm/vc4/vc4_debugfs.c     |  6 ++----
 drivers/gpu/drm/vc4/vc4_hdmi.c        |  6 ++----
 drivers/gpu/drm/vc4/vc4_hvs.c         |  8 ++------
 drivers/gpu/drm/vc4/vc4_v3d.c         |  4 +---
 drivers/gpu/drm/vkms/vkms_drv.c       |  4 +---
 include/drm/drm_debugfs.h             | 14 ++++++++------
 15 files changed, 43 insertions(+), 75 deletions(-)

diff --git a/drivers/gpu/drm/arm/hdlcd_drv.c b/drivers/gpu/drm/arm/hdlcd_drv.c
index e3507dd6f82a..b70bc7b11764 100644
--- a/drivers/gpu/drm/arm/hdlcd_drv.c
+++ b/drivers/gpu/drm/arm/hdlcd_drv.c
@@ -193,10 +193,8 @@ static int hdlcd_setup_mode_config(struct drm_device *drm)
 }
 
 #ifdef CONFIG_DEBUG_FS
-static int hdlcd_show_underrun_count(struct seq_file *m, void *arg)
+static int hdlcd_show_underrun_count(struct seq_file *m, struct drm_device *drm, void *arg)
 {
-	struct drm_debugfs_entry *entry = m->private;
-	struct drm_device *drm = entry->dev;
 	struct hdlcd_drm_private *hdlcd = drm_to_hdlcd_priv(drm);
 
 	seq_printf(m, "underrun : %d\n", atomic_read(&hdlcd->buffer_underrun_count));
@@ -206,10 +204,8 @@ static int hdlcd_show_underrun_count(struct seq_file *m, void *arg)
 	return 0;
 }
 
-static int hdlcd_show_pxlclock(struct seq_file *m, void *arg)
+static int hdlcd_show_pxlclock(struct seq_file *m, struct drm_device *drm, void *arg)
 {
-	struct drm_debugfs_entry *entry = m->private;
-	struct drm_device *drm = entry->dev;
 	struct hdlcd_drm_private *hdlcd = drm_to_hdlcd_priv(drm);
 	unsigned long clkrate = clk_get_rate(hdlcd->clk);
 	unsigned long mode_clock = hdlcd->crtc.mode.crtc_clock * 1000;
diff --git a/drivers/gpu/drm/drm_atomic.c b/drivers/gpu/drm/drm_atomic.c
index 5457c02ca1ab..38f140481fcc 100644
--- a/drivers/gpu/drm/drm_atomic.c
+++ b/drivers/gpu/drm/drm_atomic.c
@@ -1754,10 +1754,8 @@ void drm_state_dump(struct drm_device *dev, struct drm_printer *p)
 EXPORT_SYMBOL(drm_state_dump);
 
 #ifdef CONFIG_DEBUG_FS
-static int drm_state_info(struct seq_file *m, void *data)
+static int drm_state_info(struct seq_file *m, struct drm_device *dev, void *data)
 {
-	struct drm_debugfs_entry *entry = m->private;
-	struct drm_device *dev = entry->dev;
 	struct drm_printer p = drm_seq_file_printer(m);
 
 	__drm_state_dump(dev, &p, true);
diff --git a/drivers/gpu/drm/drm_client.c b/drivers/gpu/drm/drm_client.c
index 009e7b10455c..ec2e6bc3515d 100644
--- a/drivers/gpu/drm/drm_client.c
+++ b/drivers/gpu/drm/drm_client.c
@@ -488,10 +488,9 @@ int drm_client_framebuffer_flush(struct drm_client_buffer *buffer, struct drm_re
 EXPORT_SYMBOL(drm_client_framebuffer_flush);
 
 #ifdef CONFIG_DEBUG_FS
-static int drm_client_debugfs_internal_clients(struct seq_file *m, void *data)
+static int drm_client_debugfs_internal_clients(struct seq_file *m, struct drm_device *dev,
+					       void *data)
 {
-	struct drm_debugfs_entry *entry = m->private;
-	struct drm_device *dev = entry->dev;
 	struct drm_printer p = drm_seq_file_printer(m);
 	struct drm_client_dev *client;
 
diff --git a/drivers/gpu/drm/drm_debugfs.c b/drivers/gpu/drm/drm_debugfs.c
index b4d2e7dd87f5..21f01c7d0ab1 100644
--- a/drivers/gpu/drm/drm_debugfs.c
+++ b/drivers/gpu/drm/drm_debugfs.c
@@ -49,10 +49,8 @@
  * Initialization, etc.
  **************************************************/
 
-static int drm_name_info(struct seq_file *m, void *data)
+static int drm_name_info(struct seq_file *m, struct drm_device *dev, void *data)
 {
-	struct drm_debugfs_entry *entry = m->private;
-	struct drm_device *dev = entry->dev;
 	struct drm_master *master;
 
 	mutex_lock(&dev->master_mutex);
@@ -70,10 +68,8 @@ static int drm_name_info(struct seq_file *m, void *data)
 	return 0;
 }
 
-static int drm_clients_info(struct seq_file *m, void *data)
+static int drm_clients_info(struct seq_file *m, struct drm_device *dev, void *data)
 {
-	struct drm_debugfs_entry *entry = m->private;
-	struct drm_device *dev = entry->dev;
 	struct drm_file *priv;
 	kuid_t uid;
 
@@ -122,11 +118,8 @@ static int drm_gem_one_name_info(int id, void *ptr, void *data)
 	return 0;
 }
 
-static int drm_gem_name_info(struct seq_file *m, void *data)
+static int drm_gem_name_info(struct seq_file *m, struct drm_device *dev, void *data)
 {
-	struct drm_debugfs_entry *entry = m->private;
-	struct drm_device *dev = entry->dev;
-
 	seq_printf(m, "  name     size handles refcount\n");
 
 	mutex_lock(&dev->object_name_lock);
@@ -143,6 +136,13 @@ static const struct drm_debugfs_info drm_debugfs_list[] = {
 };
 #define DRM_DEBUGFS_ENTRIES ARRAY_SIZE(drm_debugfs_list)
 
+static int drm_debugfs_dev_show(struct seq_file *m, void *unused)
+{
+	struct drm_debugfs_entry *entry = m->private;
+	int (*show)(struct seq_file *, struct drm_device *, void *) = entry->file.show;
+
+	return show(m, entry->dev, entry->file.data);
+}
 
 static int drm_debugfs_open(struct inode *inode, struct file *file)
 {
@@ -154,9 +154,8 @@ static int drm_debugfs_open(struct inode *inode, struct file *file)
 static int drm_debugfs_entry_open(struct inode *inode, struct file *file)
 {
 	struct drm_debugfs_entry *entry = inode->i_private;
-	struct drm_debugfs_info *node = &entry->file;
 
-	return single_open(file, node->show, entry);
+	return single_open(file, drm_debugfs_dev_show, entry);
 }
 
 static const struct file_operations drm_debugfs_entry_fops = {
@@ -353,7 +352,7 @@ void drm_debugfs_cleanup(struct drm_minor *minor)
  * drm_debugfs_init.
  */
 void drm_debugfs_add_file(struct drm_device *dev, const char *name,
-			  int (*show)(struct seq_file*, void*), void *data)
+			  int (*show)(struct seq_file*, struct drm_device*, void*), void *data)
 {
 	struct drm_debugfs_entry *entry = drmm_kzalloc(dev, sizeof(*entry), GFP_KERNEL);
 
diff --git a/drivers/gpu/drm/drm_framebuffer.c b/drivers/gpu/drm/drm_framebuffer.c
index aff3746dedfb..f01b3cca9e06 100644
--- a/drivers/gpu/drm/drm_framebuffer.c
+++ b/drivers/gpu/drm/drm_framebuffer.c
@@ -1201,10 +1201,8 @@ void drm_framebuffer_print_info(struct drm_printer *p, unsigned int indent,
 }
 
 #ifdef CONFIG_DEBUG_FS
-static int drm_framebuffer_info(struct seq_file *m, void *data)
+static int drm_framebuffer_info(struct seq_file *m, struct drm_device *dev, void *data)
 {
-	struct drm_debugfs_entry *entry = m->private;
-	struct drm_device *dev = entry->dev;
 	struct drm_printer p = drm_seq_file_printer(m);
 	struct drm_framebuffer *fb;
 
diff --git a/drivers/gpu/drm/drm_gem_vram_helper.c b/drivers/gpu/drm/drm_gem_vram_helper.c
index d40b3edb52d0..5fc78317ad9d 100644
--- a/drivers/gpu/drm/drm_gem_vram_helper.c
+++ b/drivers/gpu/drm/drm_gem_vram_helper.c
@@ -955,10 +955,9 @@ static struct ttm_device_funcs bo_driver = {
  * struct drm_vram_mm
  */
 
-static int drm_vram_mm_debugfs(struct seq_file *m, void *data)
+static int drm_vram_mm_debugfs(struct seq_file *m, struct drm_device *dev, void *data)
 {
-	struct drm_debugfs_entry *entry = m->private;
-	struct drm_vram_mm *vmm = entry->dev->vram_mm;
+	struct drm_vram_mm *vmm = dev->vram_mm;
 	struct ttm_resource_manager *man = ttm_manager_type(&vmm->bdev, TTM_PL_VRAM);
 	struct drm_printer p = drm_seq_file_printer(m);
 
diff --git a/drivers/gpu/drm/gud/gud_drv.c b/drivers/gpu/drm/gud/gud_drv.c
index 9d7bf8ee45f1..cfd887de599a 100644
--- a/drivers/gpu/drm/gud/gud_drv.c
+++ b/drivers/gpu/drm/gud/gud_drv.c
@@ -323,10 +323,9 @@ static struct drm_gem_object *gud_gem_prime_import(struct drm_device *drm, struc
 	return drm_gem_prime_import_dev(drm, dma_buf, gdrm->dmadev);
 }
 
-static int gud_stats_debugfs(struct seq_file *m, void *data)
+static int gud_stats_debugfs(struct seq_file *m, struct drm_device *dev, void *data)
 {
-	struct drm_debugfs_entry *entry = m->private;
-	struct gud_device *gdrm = to_gud_device(entry->dev);
+	struct gud_device *gdrm = to_gud_device(dev);
 	char buf[10];
 
 	string_get_size(gdrm->bulk_len, 1, STRING_UNITS_2, buf, sizeof(buf));
diff --git a/drivers/gpu/drm/v3d/v3d_debugfs.c b/drivers/gpu/drm/v3d/v3d_debugfs.c
index 330669f51fa7..a142615f4789 100644
--- a/drivers/gpu/drm/v3d/v3d_debugfs.c
+++ b/drivers/gpu/drm/v3d/v3d_debugfs.c
@@ -77,10 +77,8 @@ static const struct v3d_reg_def v3d_csd_reg_defs[] = {
 	REGDEF(V3D_CSD_CURRENT_CFG6),
 };
 
-static int v3d_v3d_debugfs_regs(struct seq_file *m, void *unused)
+static int v3d_v3d_debugfs_regs(struct seq_file *m, struct drm_device *dev, void *unused)
 {
-	struct drm_debugfs_entry *entry = m->private;
-	struct drm_device *dev = entry->dev;
 	struct v3d_dev *v3d = to_v3d_dev(dev);
 	int i, core;
 
@@ -124,10 +122,8 @@ static int v3d_v3d_debugfs_regs(struct seq_file *m, void *unused)
 	return 0;
 }
 
-static int v3d_v3d_debugfs_ident(struct seq_file *m, void *unused)
+static int v3d_v3d_debugfs_ident(struct seq_file *m, struct drm_device *dev, void *unused)
 {
-	struct drm_debugfs_entry *entry = m->private;
-	struct drm_device *dev = entry->dev;
 	struct v3d_dev *v3d = to_v3d_dev(dev);
 	u32 ident0, ident1, ident2, ident3, cores;
 	int core;
@@ -186,10 +182,8 @@ static int v3d_v3d_debugfs_ident(struct seq_file *m, void *unused)
 	return 0;
 }
 
-static int v3d_debugfs_bo_stats(struct seq_file *m, void *unused)
+static int v3d_debugfs_bo_stats(struct seq_file *m, struct drm_device *dev, void *unused)
 {
-	struct drm_debugfs_entry *entry = m->private;
-	struct drm_device *dev = entry->dev;
 	struct v3d_dev *v3d = to_v3d_dev(dev);
 
 	mutex_lock(&v3d->bo_lock);
@@ -202,10 +196,8 @@ static int v3d_debugfs_bo_stats(struct seq_file *m, void *unused)
 	return 0;
 }
 
-static int v3d_measure_clock(struct seq_file *m, void *unused)
+static int v3d_measure_clock(struct seq_file *m, struct drm_device *dev, void *unused)
 {
-	struct drm_debugfs_entry *entry = m->private;
-	struct drm_device *dev = entry->dev;
 	struct v3d_dev *v3d = to_v3d_dev(dev);
 	uint32_t cycles;
 	int core = 0;
diff --git a/drivers/gpu/drm/vc4/vc4_bo.c b/drivers/gpu/drm/vc4/vc4_bo.c
index 86d629e45307..ea58728799da 100644
--- a/drivers/gpu/drm/vc4/vc4_bo.c
+++ b/drivers/gpu/drm/vc4/vc4_bo.c
@@ -67,10 +67,8 @@ static void vc4_bo_stats_print(struct drm_printer *p, struct vc4_dev *vc4)
 	mutex_unlock(&vc4->purgeable.lock);
 }
 
-static int vc4_bo_stats_debugfs(struct seq_file *m, void *unused)
+static int vc4_bo_stats_debugfs(struct seq_file *m, struct drm_device *dev, void *unused)
 {
-	struct drm_debugfs_entry *entry = m->private;
-	struct drm_device *dev = entry->dev;
 	struct vc4_dev *vc4 = to_vc4_dev(dev);
 	struct drm_printer p = drm_seq_file_printer(m);
 
diff --git a/drivers/gpu/drm/vc4/vc4_debugfs.c b/drivers/gpu/drm/vc4/vc4_debugfs.c
index fac624a663ea..42c5d3c95a3f 100644
--- a/drivers/gpu/drm/vc4/vc4_debugfs.c
+++ b/drivers/gpu/drm/vc4/vc4_debugfs.c
@@ -32,11 +32,9 @@ vc4_debugfs_init(struct drm_minor *minor)
 	}
 }
 
-static int vc4_debugfs_regset32(struct seq_file *m, void *unused)
+static int vc4_debugfs_regset32(struct seq_file *m, struct drm_device *drm, void *data)
 {
-	struct drm_debugfs_entry *entry = m->private;
-	struct drm_device *drm = entry->dev;
-	struct debugfs_regset32 *regset = entry->file.data;
+	struct debugfs_regset32 *regset = data;
 	struct drm_printer p = drm_seq_file_printer(m);
 	int idx;
 
diff --git a/drivers/gpu/drm/vc4/vc4_hdmi.c b/drivers/gpu/drm/vc4/vc4_hdmi.c
index 14628864487a..5e1e1edc55db 100644
--- a/drivers/gpu/drm/vc4/vc4_hdmi.c
+++ b/drivers/gpu/drm/vc4/vc4_hdmi.c
@@ -158,11 +158,9 @@ static bool vc4_hdmi_is_full_range_rgb(struct vc4_hdmi *vc4_hdmi,
 		drm_default_rgb_quant_range(mode) == HDMI_QUANTIZATION_RANGE_FULL;
 }
 
-static int vc4_hdmi_debugfs_regs(struct seq_file *m, void *unused)
+static int vc4_hdmi_debugfs_regs(struct seq_file *m, struct drm_device *drm, void *data)
 {
-	struct drm_debugfs_entry *entry = m->private;
-	struct vc4_hdmi *vc4_hdmi = entry->file.data;
-	struct drm_device *drm = vc4_hdmi->connector.dev;
+	struct vc4_hdmi *vc4_hdmi = data;
 	struct drm_printer p = drm_seq_file_printer(m);
 	int idx;
 
diff --git a/drivers/gpu/drm/vc4/vc4_hvs.c b/drivers/gpu/drm/vc4/vc4_hvs.c
index 4da66ef96783..8c37b5c3cb05 100644
--- a/drivers/gpu/drm/vc4/vc4_hvs.c
+++ b/drivers/gpu/drm/vc4/vc4_hvs.c
@@ -91,10 +91,8 @@ void vc4_hvs_dump_state(struct vc4_hvs *hvs)
 	drm_dev_exit(idx);
 }
 
-static int vc4_hvs_debugfs_underrun(struct seq_file *m, void *data)
+static int vc4_hvs_debugfs_underrun(struct seq_file *m, struct drm_device *dev, void *data)
 {
-	struct drm_debugfs_entry *entry = m->private;
-	struct drm_device *dev = entry->dev;
 	struct vc4_dev *vc4 = to_vc4_dev(dev);
 	struct drm_printer p = drm_seq_file_printer(m);
 
@@ -103,10 +101,8 @@ static int vc4_hvs_debugfs_underrun(struct seq_file *m, void *data)
 	return 0;
 }
 
-static int vc4_hvs_debugfs_dlist(struct seq_file *m, void *data)
+static int vc4_hvs_debugfs_dlist(struct seq_file *m, struct drm_device *dev, void *data)
 {
-	struct drm_debugfs_entry *entry = m->private;
-	struct drm_device *dev = entry->dev;
 	struct vc4_dev *vc4 = to_vc4_dev(dev);
 	struct vc4_hvs *hvs = vc4->hvs;
 	struct drm_printer p = drm_seq_file_printer(m);
diff --git a/drivers/gpu/drm/vc4/vc4_v3d.c b/drivers/gpu/drm/vc4/vc4_v3d.c
index 29a664c8bf44..49eb48a270db 100644
--- a/drivers/gpu/drm/vc4/vc4_v3d.c
+++ b/drivers/gpu/drm/vc4/vc4_v3d.c
@@ -94,10 +94,8 @@ static const struct debugfs_reg32 v3d_regs[] = {
 	VC4_REG32(V3D_ERRSTAT),
 };
 
-static int vc4_v3d_debugfs_ident(struct seq_file *m, void *unused)
+static int vc4_v3d_debugfs_ident(struct seq_file *m, struct drm_device *dev, void *unused)
 {
-	struct drm_debugfs_entry *entry = m->private;
-	struct drm_device *dev = entry->dev;
 	struct vc4_dev *vc4 = to_vc4_dev(dev);
 	int ret = vc4_v3d_pm_get(vc4);
 
diff --git a/drivers/gpu/drm/vkms/vkms_drv.c b/drivers/gpu/drm/vkms/vkms_drv.c
index 6d3a2d57d992..dde6a500f3b1 100644
--- a/drivers/gpu/drm/vkms/vkms_drv.c
+++ b/drivers/gpu/drm/vkms/vkms_drv.c
@@ -90,10 +90,8 @@ static void vkms_atomic_commit_tail(struct drm_atomic_state *old_state)
 	drm_atomic_helper_cleanup_planes(dev, old_state);
 }
 
-static int vkms_config_show(struct seq_file *m, void *data)
+static int vkms_config_show(struct seq_file *m, struct drm_device *dev, void *data)
 {
-	struct drm_debugfs_entry *entry = m->private;
-	struct drm_device *dev = entry->dev;
 	struct vkms_device *vkmsdev = drm_device_to_vkms_device(dev);
 
 	seq_printf(m, "writeback=%d\n", vkmsdev->config->writeback);
diff --git a/include/drm/drm_debugfs.h b/include/drm/drm_debugfs.h
index 423aa3de506a..0fb7ad5f6893 100644
--- a/include/drm/drm_debugfs.h
+++ b/include/drm/drm_debugfs.h
@@ -36,6 +36,9 @@
 #include <linux/mutex.h>
 #include <linux/types.h>
 #include <linux/seq_file.h>
+
+struct drm_device;
+
 /**
  * struct drm_info_list - debugfs info list entry
  *
@@ -108,11 +111,10 @@ struct drm_debugfs_info {
 	/**
 	 * @show:
 	 *
-	 * Show callback. &seq_file->private will be set to the &struct
-	 * drm_debugfs_entry corresponding to the instance of this info
-	 * on a given &struct drm_device.
+	 * Show callback. This callback will be casted in order to provide
+	 * the &seq_file, the DRM object and the data stored in this struct.
 	 */
-	int (*show)(struct seq_file*, void*);
+	void *show;
 
 	/** @driver_features: Required driver features for this entry. */
 	u32 driver_features;
@@ -146,7 +148,7 @@ int drm_debugfs_remove_files(const struct drm_info_list *files,
 			     int count, struct drm_minor *minor);
 
 void drm_debugfs_add_file(struct drm_device *dev, const char *name,
-			  int (*show)(struct seq_file*, void*), void *data);
+			  int (*show)(struct seq_file*, struct drm_device*, void*), void *data);
 
 void drm_debugfs_add_files(struct drm_device *dev,
 			   const struct drm_debugfs_info *files, int count);
@@ -163,7 +165,7 @@ static inline int drm_debugfs_remove_files(const struct drm_info_list *files,
 }
 
 static inline void drm_debugfs_add_file(struct drm_device *dev, const char *name,
-					int (*show)(struct seq_file*, void*),
+					int (*show)(struct seq_file*, struct drm_device*, void*),
 					void *data)
 {}
 
-- 
2.39.1


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH v3 6/6] drm/debugfs: Make the struct drm_debugfs_entry independent of DRM device
  2023-01-31 19:58 [PATCH v3 0/6] drm/debugfs: Make the debugfs structure more generic Maíra Canal
                   ` (4 preceding siblings ...)
  2023-01-31 19:58 ` [PATCH v3 5/6] drm/debugfs: Make the show callback pass the pointer to the right object Maíra Canal
@ 2023-01-31 19:58 ` Maíra Canal
  5 siblings, 0 replies; 14+ messages in thread
From: Maíra Canal @ 2023-01-31 19:58 UTC (permalink / raw)
  To: Daniel Vetter, David Airlie, Maarten Lankhorst, Maxime Ripard,
	Thomas Zimmermann, Liviu Dudau, Brian Starkey,
	Noralf Trønnes, Melissa Wen, Rodrigo Siqueira, Jani Nikula
  Cc: Maíra Canal, André Almeida, dri-devel

In order to turn the API more expansible to other DRM objects, such as
the struct drm_connector, make the struct drm_debugfs_entry hold a void
pointer and cast the void pointer to the struct drm_device when needed.

Signed-off-by: Maíra Canal <mcanal@igalia.com>
---
 drivers/gpu/drm/drm_debugfs.c | 4 ++--
 include/drm/drm_debugfs.h     | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/gpu/drm/drm_debugfs.c b/drivers/gpu/drm/drm_debugfs.c
index 21f01c7d0ab1..f12c3fdf61bb 100644
--- a/drivers/gpu/drm/drm_debugfs.c
+++ b/drivers/gpu/drm/drm_debugfs.c
@@ -141,7 +141,7 @@ static int drm_debugfs_dev_show(struct seq_file *m, void *unused)
 	struct drm_debugfs_entry *entry = m->private;
 	int (*show)(struct seq_file *, struct drm_device *, void *) = entry->file.show;
 
-	return show(m, entry->dev, entry->file.data);
+	return show(m, entry->object, entry->file.data);
 }
 
 static int drm_debugfs_open(struct inode *inode, struct file *file)
@@ -362,7 +362,7 @@ void drm_debugfs_add_file(struct drm_device *dev, const char *name,
 	entry->file.name = name;
 	entry->file.show = show;
 	entry->file.data = data;
-	entry->dev = dev;
+	entry->object = dev;
 
 	drm_debugfs_files_add(dev->debugfs_files, &entry->list);
 }
diff --git a/include/drm/drm_debugfs.h b/include/drm/drm_debugfs.h
index 0fb7ad5f6893..4ab0557f55e0 100644
--- a/include/drm/drm_debugfs.h
+++ b/include/drm/drm_debugfs.h
@@ -130,8 +130,8 @@ struct drm_debugfs_info {
  * drm_debugfs_info on a &struct drm_device.
  */
 struct drm_debugfs_entry {
-	/** @dev: &struct drm_device for this node. */
-	struct drm_device *dev;
+	/** @object: The DRM object that owns this node. */
+	void *object;
 
 	/** @file: Template for this node. */
 	struct drm_debugfs_info file;
-- 
2.39.1


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* Re: [PATCH v3 1/6] drm/debugfs: Introduce wrapper for debugfs list
  2023-01-31 19:58 ` [PATCH v3 1/6] drm/debugfs: Introduce wrapper for debugfs list Maíra Canal
@ 2023-02-08 18:06   ` Daniel Vetter
  2023-02-08 18:19     ` Daniel Vetter
  2023-02-08 18:39     ` Maíra Canal
  0 siblings, 2 replies; 14+ messages in thread
From: Daniel Vetter @ 2023-02-08 18:06 UTC (permalink / raw)
  To: Maíra Canal
  Cc: André Almeida, Thomas Zimmermann, Rodrigo Siqueira,
	Liviu Dudau, dri-devel, Melissa Wen, Noralf Trønnes

On Tue, Jan 31, 2023 at 04:58:21PM -0300, Maíra Canal wrote:
> 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  | 18 ++++++++++++++++++
>  drivers/gpu/drm/drm_internal.h | 12 ++++++++++++
>  include/drm/drm_debugfs.h      | 16 ++++++++++++++++
>  3 files changed, 46 insertions(+)
> 
> diff --git a/drivers/gpu/drm/drm_debugfs.c b/drivers/gpu/drm/drm_debugfs.c
> index 4f643a490dc3..8658d3929ea5 100644
> --- a/drivers/gpu/drm/drm_debugfs.c
> +++ b/drivers/gpu/drm/drm_debugfs.c
> @@ -218,6 +218,24 @@ void drm_debugfs_create_files(const struct drm_info_list *files, int count,
>  }
>  EXPORT_SYMBOL(drm_debugfs_create_files);
>  
> +struct drm_debugfs_files *drm_debugfs_files_init(void)
> +{
> +	struct drm_debugfs_files *debugfs_files;
> +
> +	debugfs_files = kzalloc(sizeof(*debugfs_files), GFP_KERNEL);
> +
> +	INIT_LIST_HEAD(&debugfs_files->list);
> +	mutex_init(&debugfs_files->mutex);
> +
> +	return debugfs_files;
> +}
> +
> +void drm_debugfs_files_destroy(struct drm_debugfs_files *debugfs_files)
> +{
> +	mutex_destroy(&debugfs_files->mutex);
> +	kfree(debugfs_files);
> +}
> +
>  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..f1c8766ed828 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)
> +struct drm_debugfs_files *drm_debugfs_files_init(void);
> +void drm_debugfs_files_destroy(struct drm_debugfs_files *debugfs_files);
>  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,15 @@ 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 struct drm_debugfs_files *drm_debugfs_files_init(void)
> +{
> +	return NULL;
> +}
> +
> +static inline void drm_debugfs_files_destroy(struct drm_debugfs_files *debugfs_files)
> +{
> +}
> +
>  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..423aa3de506a 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_files - 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_files {
> +	/** @list: List of debugfs files to be created by the DRM object. */
> +	struct list_head list;
> +
> +	/** @mutex: Protects &list access. */
> +	struct mutex mutex;

I'm not seeing any use for the mutex here? Also unless you also plan to
put like the debugfs directory pointers in this struct, I'm not sure we
need this abstraction since it's purely internal to debugfs code (so also
should really be in the headers where drivers could perhaps come up with
funny ideas).
-Daniel

> +};
> +
>  /**
>   * struct drm_debugfs_info - debugfs info list entry
>   *
> -- 
> 2.39.1
> 

-- 
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH v3 5/6] drm/debugfs: Make the show callback pass the pointer to the right object
  2023-01-31 19:58 ` [PATCH v3 5/6] drm/debugfs: Make the show callback pass the pointer to the right object Maíra Canal
@ 2023-02-08 18:12   ` Daniel Vetter
  2023-02-08 18:17     ` Daniel Vetter
  0 siblings, 1 reply; 14+ messages in thread
From: Daniel Vetter @ 2023-02-08 18:12 UTC (permalink / raw)
  To: Maíra Canal
  Cc: André Almeida, Thomas Zimmermann, Rodrigo Siqueira,
	Liviu Dudau, dri-devel, Melissa Wen, Noralf Trønnes

On Tue, Jan 31, 2023 at 04:58:25PM -0300, Maíra Canal wrote:
> Currently, the drivers need to access the struct drm_debugfs_entry to
> get the proper device on the show callback. There is no need for such
> thing, as you can wrap the show callback in order to provide to the
> driver the proper parameters: the struct seq_file, the struct drm_device
> and the driver-specific data stored in the struct drm_debugfs_info.
> 
> Therefore, make the show callback pass the pointer to the right object
> in the parameters, which makes the API more type-safe.
> 
> Signed-off-by: Maíra Canal <mcanal@igalia.com>
> ---
>  drivers/gpu/drm/arm/hdlcd_drv.c       |  8 ++------
>  drivers/gpu/drm/drm_atomic.c          |  4 +---
>  drivers/gpu/drm/drm_client.c          |  5 ++---
>  drivers/gpu/drm/drm_debugfs.c         | 25 ++++++++++++-------------
>  drivers/gpu/drm/drm_framebuffer.c     |  4 +---
>  drivers/gpu/drm/drm_gem_vram_helper.c |  5 ++---
>  drivers/gpu/drm/gud/gud_drv.c         |  5 ++---
>  drivers/gpu/drm/v3d/v3d_debugfs.c     | 16 ++++------------
>  drivers/gpu/drm/vc4/vc4_bo.c          |  4 +---
>  drivers/gpu/drm/vc4/vc4_debugfs.c     |  6 ++----
>  drivers/gpu/drm/vc4/vc4_hdmi.c        |  6 ++----
>  drivers/gpu/drm/vc4/vc4_hvs.c         |  8 ++------
>  drivers/gpu/drm/vc4/vc4_v3d.c         |  4 +---
>  drivers/gpu/drm/vkms/vkms_drv.c       |  4 +---
>  include/drm/drm_debugfs.h             | 14 ++++++++------
>  15 files changed, 43 insertions(+), 75 deletions(-)
> 
> diff --git a/drivers/gpu/drm/arm/hdlcd_drv.c b/drivers/gpu/drm/arm/hdlcd_drv.c
> index e3507dd6f82a..b70bc7b11764 100644
> --- a/drivers/gpu/drm/arm/hdlcd_drv.c
> +++ b/drivers/gpu/drm/arm/hdlcd_drv.c
> @@ -193,10 +193,8 @@ static int hdlcd_setup_mode_config(struct drm_device *drm)
>  }
>  
>  #ifdef CONFIG_DEBUG_FS
> -static int hdlcd_show_underrun_count(struct seq_file *m, void *arg)
> +static int hdlcd_show_underrun_count(struct seq_file *m, struct drm_device *drm, void *arg)
>  {
> -	struct drm_debugfs_entry *entry = m->private;
> -	struct drm_device *drm = entry->dev;
>  	struct hdlcd_drm_private *hdlcd = drm_to_hdlcd_priv(drm);
>  
>  	seq_printf(m, "underrun : %d\n", atomic_read(&hdlcd->buffer_underrun_count));
> @@ -206,10 +204,8 @@ static int hdlcd_show_underrun_count(struct seq_file *m, void *arg)
>  	return 0;
>  }
>  
> -static int hdlcd_show_pxlclock(struct seq_file *m, void *arg)
> +static int hdlcd_show_pxlclock(struct seq_file *m, struct drm_device *drm, void *arg)
>  {
> -	struct drm_debugfs_entry *entry = m->private;
> -	struct drm_device *drm = entry->dev;
>  	struct hdlcd_drm_private *hdlcd = drm_to_hdlcd_priv(drm);
>  	unsigned long clkrate = clk_get_rate(hdlcd->clk);
>  	unsigned long mode_clock = hdlcd->crtc.mode.crtc_clock * 1000;
> diff --git a/drivers/gpu/drm/drm_atomic.c b/drivers/gpu/drm/drm_atomic.c
> index 5457c02ca1ab..38f140481fcc 100644
> --- a/drivers/gpu/drm/drm_atomic.c
> +++ b/drivers/gpu/drm/drm_atomic.c
> @@ -1754,10 +1754,8 @@ void drm_state_dump(struct drm_device *dev, struct drm_printer *p)
>  EXPORT_SYMBOL(drm_state_dump);
>  
>  #ifdef CONFIG_DEBUG_FS
> -static int drm_state_info(struct seq_file *m, void *data)
> +static int drm_state_info(struct seq_file *m, struct drm_device *dev, void *data)
>  {
> -	struct drm_debugfs_entry *entry = m->private;
> -	struct drm_device *dev = entry->dev;
>  	struct drm_printer p = drm_seq_file_printer(m);
>  
>  	__drm_state_dump(dev, &p, true);
> diff --git a/drivers/gpu/drm/drm_client.c b/drivers/gpu/drm/drm_client.c
> index 009e7b10455c..ec2e6bc3515d 100644
> --- a/drivers/gpu/drm/drm_client.c
> +++ b/drivers/gpu/drm/drm_client.c
> @@ -488,10 +488,9 @@ int drm_client_framebuffer_flush(struct drm_client_buffer *buffer, struct drm_re
>  EXPORT_SYMBOL(drm_client_framebuffer_flush);
>  
>  #ifdef CONFIG_DEBUG_FS
> -static int drm_client_debugfs_internal_clients(struct seq_file *m, void *data)
> +static int drm_client_debugfs_internal_clients(struct seq_file *m, struct drm_device *dev,
> +					       void *data)
>  {
> -	struct drm_debugfs_entry *entry = m->private;
> -	struct drm_device *dev = entry->dev;
>  	struct drm_printer p = drm_seq_file_printer(m);
>  	struct drm_client_dev *client;
>  
> diff --git a/drivers/gpu/drm/drm_debugfs.c b/drivers/gpu/drm/drm_debugfs.c
> index b4d2e7dd87f5..21f01c7d0ab1 100644
> --- a/drivers/gpu/drm/drm_debugfs.c
> +++ b/drivers/gpu/drm/drm_debugfs.c
> @@ -49,10 +49,8 @@
>   * Initialization, etc.
>   **************************************************/
>  
> -static int drm_name_info(struct seq_file *m, void *data)
> +static int drm_name_info(struct seq_file *m, struct drm_device *dev, void *data)
>  {
> -	struct drm_debugfs_entry *entry = m->private;
> -	struct drm_device *dev = entry->dev;
>  	struct drm_master *master;
>  
>  	mutex_lock(&dev->master_mutex);
> @@ -70,10 +68,8 @@ static int drm_name_info(struct seq_file *m, void *data)
>  	return 0;
>  }
>  
> -static int drm_clients_info(struct seq_file *m, void *data)
> +static int drm_clients_info(struct seq_file *m, struct drm_device *dev, void *data)
>  {
> -	struct drm_debugfs_entry *entry = m->private;
> -	struct drm_device *dev = entry->dev;
>  	struct drm_file *priv;
>  	kuid_t uid;
>  
> @@ -122,11 +118,8 @@ static int drm_gem_one_name_info(int id, void *ptr, void *data)
>  	return 0;
>  }
>  
> -static int drm_gem_name_info(struct seq_file *m, void *data)
> +static int drm_gem_name_info(struct seq_file *m, struct drm_device *dev, void *data)
>  {
> -	struct drm_debugfs_entry *entry = m->private;
> -	struct drm_device *dev = entry->dev;
> -
>  	seq_printf(m, "  name     size handles refcount\n");
>  
>  	mutex_lock(&dev->object_name_lock);
> @@ -143,6 +136,13 @@ static const struct drm_debugfs_info drm_debugfs_list[] = {
>  };
>  #define DRM_DEBUGFS_ENTRIES ARRAY_SIZE(drm_debugfs_list)
>  
> +static int drm_debugfs_dev_show(struct seq_file *m, void *unused)
> +{
> +	struct drm_debugfs_entry *entry = m->private;
> +	int (*show)(struct seq_file *, struct drm_device *, void *) = entry->file.show;
> +
> +	return show(m, entry->dev, entry->file.data);
> +}
>  
>  static int drm_debugfs_open(struct inode *inode, struct file *file)
>  {
> @@ -154,9 +154,8 @@ static int drm_debugfs_open(struct inode *inode, struct file *file)
>  static int drm_debugfs_entry_open(struct inode *inode, struct file *file)
>  {
>  	struct drm_debugfs_entry *entry = inode->i_private;
> -	struct drm_debugfs_info *node = &entry->file;
>  
> -	return single_open(file, node->show, entry);
> +	return single_open(file, drm_debugfs_dev_show, entry);
>  }
>  
>  static const struct file_operations drm_debugfs_entry_fops = {
> @@ -353,7 +352,7 @@ void drm_debugfs_cleanup(struct drm_minor *minor)
>   * drm_debugfs_init.
>   */
>  void drm_debugfs_add_file(struct drm_device *dev, const char *name,
> -			  int (*show)(struct seq_file*, void*), void *data)
> +			  int (*show)(struct seq_file*, struct drm_device*, void*), void *data)
>  {
>  	struct drm_debugfs_entry *entry = drmm_kzalloc(dev, sizeof(*entry), GFP_KERNEL);
>  
> diff --git a/drivers/gpu/drm/drm_framebuffer.c b/drivers/gpu/drm/drm_framebuffer.c
> index aff3746dedfb..f01b3cca9e06 100644
> --- a/drivers/gpu/drm/drm_framebuffer.c
> +++ b/drivers/gpu/drm/drm_framebuffer.c
> @@ -1201,10 +1201,8 @@ void drm_framebuffer_print_info(struct drm_printer *p, unsigned int indent,
>  }
>  
>  #ifdef CONFIG_DEBUG_FS
> -static int drm_framebuffer_info(struct seq_file *m, void *data)
> +static int drm_framebuffer_info(struct seq_file *m, struct drm_device *dev, void *data)
>  {
> -	struct drm_debugfs_entry *entry = m->private;
> -	struct drm_device *dev = entry->dev;
>  	struct drm_printer p = drm_seq_file_printer(m);
>  	struct drm_framebuffer *fb;
>  
> diff --git a/drivers/gpu/drm/drm_gem_vram_helper.c b/drivers/gpu/drm/drm_gem_vram_helper.c
> index d40b3edb52d0..5fc78317ad9d 100644
> --- a/drivers/gpu/drm/drm_gem_vram_helper.c
> +++ b/drivers/gpu/drm/drm_gem_vram_helper.c
> @@ -955,10 +955,9 @@ static struct ttm_device_funcs bo_driver = {
>   * struct drm_vram_mm
>   */
>  
> -static int drm_vram_mm_debugfs(struct seq_file *m, void *data)
> +static int drm_vram_mm_debugfs(struct seq_file *m, struct drm_device *dev, void *data)
>  {
> -	struct drm_debugfs_entry *entry = m->private;
> -	struct drm_vram_mm *vmm = entry->dev->vram_mm;
> +	struct drm_vram_mm *vmm = dev->vram_mm;
>  	struct ttm_resource_manager *man = ttm_manager_type(&vmm->bdev, TTM_PL_VRAM);
>  	struct drm_printer p = drm_seq_file_printer(m);
>  
> diff --git a/drivers/gpu/drm/gud/gud_drv.c b/drivers/gpu/drm/gud/gud_drv.c
> index 9d7bf8ee45f1..cfd887de599a 100644
> --- a/drivers/gpu/drm/gud/gud_drv.c
> +++ b/drivers/gpu/drm/gud/gud_drv.c
> @@ -323,10 +323,9 @@ static struct drm_gem_object *gud_gem_prime_import(struct drm_device *drm, struc
>  	return drm_gem_prime_import_dev(drm, dma_buf, gdrm->dmadev);
>  }
>  
> -static int gud_stats_debugfs(struct seq_file *m, void *data)
> +static int gud_stats_debugfs(struct seq_file *m, struct drm_device *dev, void *data)
>  {
> -	struct drm_debugfs_entry *entry = m->private;
> -	struct gud_device *gdrm = to_gud_device(entry->dev);
> +	struct gud_device *gdrm = to_gud_device(dev);
>  	char buf[10];
>  
>  	string_get_size(gdrm->bulk_len, 1, STRING_UNITS_2, buf, sizeof(buf));
> diff --git a/drivers/gpu/drm/v3d/v3d_debugfs.c b/drivers/gpu/drm/v3d/v3d_debugfs.c
> index 330669f51fa7..a142615f4789 100644
> --- a/drivers/gpu/drm/v3d/v3d_debugfs.c
> +++ b/drivers/gpu/drm/v3d/v3d_debugfs.c
> @@ -77,10 +77,8 @@ static const struct v3d_reg_def v3d_csd_reg_defs[] = {
>  	REGDEF(V3D_CSD_CURRENT_CFG6),
>  };
>  
> -static int v3d_v3d_debugfs_regs(struct seq_file *m, void *unused)
> +static int v3d_v3d_debugfs_regs(struct seq_file *m, struct drm_device *dev, void *unused)
>  {
> -	struct drm_debugfs_entry *entry = m->private;
> -	struct drm_device *dev = entry->dev;
>  	struct v3d_dev *v3d = to_v3d_dev(dev);
>  	int i, core;
>  
> @@ -124,10 +122,8 @@ static int v3d_v3d_debugfs_regs(struct seq_file *m, void *unused)
>  	return 0;
>  }
>  
> -static int v3d_v3d_debugfs_ident(struct seq_file *m, void *unused)
> +static int v3d_v3d_debugfs_ident(struct seq_file *m, struct drm_device *dev, void *unused)
>  {
> -	struct drm_debugfs_entry *entry = m->private;
> -	struct drm_device *dev = entry->dev;
>  	struct v3d_dev *v3d = to_v3d_dev(dev);
>  	u32 ident0, ident1, ident2, ident3, cores;
>  	int core;
> @@ -186,10 +182,8 @@ static int v3d_v3d_debugfs_ident(struct seq_file *m, void *unused)
>  	return 0;
>  }
>  
> -static int v3d_debugfs_bo_stats(struct seq_file *m, void *unused)
> +static int v3d_debugfs_bo_stats(struct seq_file *m, struct drm_device *dev, void *unused)
>  {
> -	struct drm_debugfs_entry *entry = m->private;
> -	struct drm_device *dev = entry->dev;
>  	struct v3d_dev *v3d = to_v3d_dev(dev);
>  
>  	mutex_lock(&v3d->bo_lock);
> @@ -202,10 +196,8 @@ static int v3d_debugfs_bo_stats(struct seq_file *m, void *unused)
>  	return 0;
>  }
>  
> -static int v3d_measure_clock(struct seq_file *m, void *unused)
> +static int v3d_measure_clock(struct seq_file *m, struct drm_device *dev, void *unused)
>  {
> -	struct drm_debugfs_entry *entry = m->private;
> -	struct drm_device *dev = entry->dev;
>  	struct v3d_dev *v3d = to_v3d_dev(dev);
>  	uint32_t cycles;
>  	int core = 0;
> diff --git a/drivers/gpu/drm/vc4/vc4_bo.c b/drivers/gpu/drm/vc4/vc4_bo.c
> index 86d629e45307..ea58728799da 100644
> --- a/drivers/gpu/drm/vc4/vc4_bo.c
> +++ b/drivers/gpu/drm/vc4/vc4_bo.c
> @@ -67,10 +67,8 @@ static void vc4_bo_stats_print(struct drm_printer *p, struct vc4_dev *vc4)
>  	mutex_unlock(&vc4->purgeable.lock);
>  }
>  
> -static int vc4_bo_stats_debugfs(struct seq_file *m, void *unused)
> +static int vc4_bo_stats_debugfs(struct seq_file *m, struct drm_device *dev, void *unused)
>  {
> -	struct drm_debugfs_entry *entry = m->private;
> -	struct drm_device *dev = entry->dev;
>  	struct vc4_dev *vc4 = to_vc4_dev(dev);
>  	struct drm_printer p = drm_seq_file_printer(m);
>  
> diff --git a/drivers/gpu/drm/vc4/vc4_debugfs.c b/drivers/gpu/drm/vc4/vc4_debugfs.c
> index fac624a663ea..42c5d3c95a3f 100644
> --- a/drivers/gpu/drm/vc4/vc4_debugfs.c
> +++ b/drivers/gpu/drm/vc4/vc4_debugfs.c
> @@ -32,11 +32,9 @@ vc4_debugfs_init(struct drm_minor *minor)
>  	}
>  }
>  
> -static int vc4_debugfs_regset32(struct seq_file *m, void *unused)
> +static int vc4_debugfs_regset32(struct seq_file *m, struct drm_device *drm, void *data)
>  {
> -	struct drm_debugfs_entry *entry = m->private;
> -	struct drm_device *drm = entry->dev;
> -	struct debugfs_regset32 *regset = entry->file.data;
> +	struct debugfs_regset32 *regset = data;
>  	struct drm_printer p = drm_seq_file_printer(m);
>  	int idx;
>  
> diff --git a/drivers/gpu/drm/vc4/vc4_hdmi.c b/drivers/gpu/drm/vc4/vc4_hdmi.c
> index 14628864487a..5e1e1edc55db 100644
> --- a/drivers/gpu/drm/vc4/vc4_hdmi.c
> +++ b/drivers/gpu/drm/vc4/vc4_hdmi.c
> @@ -158,11 +158,9 @@ static bool vc4_hdmi_is_full_range_rgb(struct vc4_hdmi *vc4_hdmi,
>  		drm_default_rgb_quant_range(mode) == HDMI_QUANTIZATION_RANGE_FULL;
>  }
>  
> -static int vc4_hdmi_debugfs_regs(struct seq_file *m, void *unused)
> +static int vc4_hdmi_debugfs_regs(struct seq_file *m, struct drm_device *drm, void *data)
>  {
> -	struct drm_debugfs_entry *entry = m->private;
> -	struct vc4_hdmi *vc4_hdmi = entry->file.data;
> -	struct drm_device *drm = vc4_hdmi->connector.dev;
> +	struct vc4_hdmi *vc4_hdmi = data;
>  	struct drm_printer p = drm_seq_file_printer(m);
>  	int idx;
>  
> diff --git a/drivers/gpu/drm/vc4/vc4_hvs.c b/drivers/gpu/drm/vc4/vc4_hvs.c
> index 4da66ef96783..8c37b5c3cb05 100644
> --- a/drivers/gpu/drm/vc4/vc4_hvs.c
> +++ b/drivers/gpu/drm/vc4/vc4_hvs.c
> @@ -91,10 +91,8 @@ void vc4_hvs_dump_state(struct vc4_hvs *hvs)
>  	drm_dev_exit(idx);
>  }
>  
> -static int vc4_hvs_debugfs_underrun(struct seq_file *m, void *data)
> +static int vc4_hvs_debugfs_underrun(struct seq_file *m, struct drm_device *dev, void *data)
>  {
> -	struct drm_debugfs_entry *entry = m->private;
> -	struct drm_device *dev = entry->dev;
>  	struct vc4_dev *vc4 = to_vc4_dev(dev);
>  	struct drm_printer p = drm_seq_file_printer(m);
>  
> @@ -103,10 +101,8 @@ static int vc4_hvs_debugfs_underrun(struct seq_file *m, void *data)
>  	return 0;
>  }
>  
> -static int vc4_hvs_debugfs_dlist(struct seq_file *m, void *data)
> +static int vc4_hvs_debugfs_dlist(struct seq_file *m, struct drm_device *dev, void *data)
>  {
> -	struct drm_debugfs_entry *entry = m->private;
> -	struct drm_device *dev = entry->dev;
>  	struct vc4_dev *vc4 = to_vc4_dev(dev);
>  	struct vc4_hvs *hvs = vc4->hvs;
>  	struct drm_printer p = drm_seq_file_printer(m);
> diff --git a/drivers/gpu/drm/vc4/vc4_v3d.c b/drivers/gpu/drm/vc4/vc4_v3d.c
> index 29a664c8bf44..49eb48a270db 100644
> --- a/drivers/gpu/drm/vc4/vc4_v3d.c
> +++ b/drivers/gpu/drm/vc4/vc4_v3d.c
> @@ -94,10 +94,8 @@ static const struct debugfs_reg32 v3d_regs[] = {
>  	VC4_REG32(V3D_ERRSTAT),
>  };
>  
> -static int vc4_v3d_debugfs_ident(struct seq_file *m, void *unused)
> +static int vc4_v3d_debugfs_ident(struct seq_file *m, struct drm_device *dev, void *unused)
>  {
> -	struct drm_debugfs_entry *entry = m->private;
> -	struct drm_device *dev = entry->dev;
>  	struct vc4_dev *vc4 = to_vc4_dev(dev);
>  	int ret = vc4_v3d_pm_get(vc4);
>  
> diff --git a/drivers/gpu/drm/vkms/vkms_drv.c b/drivers/gpu/drm/vkms/vkms_drv.c
> index 6d3a2d57d992..dde6a500f3b1 100644
> --- a/drivers/gpu/drm/vkms/vkms_drv.c
> +++ b/drivers/gpu/drm/vkms/vkms_drv.c
> @@ -90,10 +90,8 @@ static void vkms_atomic_commit_tail(struct drm_atomic_state *old_state)
>  	drm_atomic_helper_cleanup_planes(dev, old_state);
>  }
>  
> -static int vkms_config_show(struct seq_file *m, void *data)
> +static int vkms_config_show(struct seq_file *m, struct drm_device *dev, void *data)
>  {
> -	struct drm_debugfs_entry *entry = m->private;
> -	struct drm_device *dev = entry->dev;
>  	struct vkms_device *vkmsdev = drm_device_to_vkms_device(dev);
>  
>  	seq_printf(m, "writeback=%d\n", vkmsdev->config->writeback);
> diff --git a/include/drm/drm_debugfs.h b/include/drm/drm_debugfs.h
> index 423aa3de506a..0fb7ad5f6893 100644
> --- a/include/drm/drm_debugfs.h
> +++ b/include/drm/drm_debugfs.h
> @@ -36,6 +36,9 @@
>  #include <linux/mutex.h>
>  #include <linux/types.h>
>  #include <linux/seq_file.h>
> +
> +struct drm_device;
> +
>  /**
>   * struct drm_info_list - debugfs info list entry
>   *
> @@ -108,11 +111,10 @@ struct drm_debugfs_info {
>  	/**
>  	 * @show:
>  	 *
> -	 * Show callback. &seq_file->private will be set to the &struct
> -	 * drm_debugfs_entry corresponding to the instance of this info
> -	 * on a given &struct drm_device.
> +	 * Show callback. This callback will be casted in order to provide
> +	 * the &seq_file, the DRM object and the data stored in this struct.
>  	 */
> -	int (*show)(struct seq_file*, void*);
> +	void *show;

The problem here is that with this we loose type-checking, and so all the
users of drm_debugfs_add_file() have been missed in the conversion. That's
not very good :-/

I think the only way to sort this out is if we duplicate the driver-facing
functions/structs (maybe we don't need the add_files() functions in all
cases?), and only use the type-unsafe void* internally.
-Daniel

>  
>  	/** @driver_features: Required driver features for this entry. */
>  	u32 driver_features;
> @@ -146,7 +148,7 @@ int drm_debugfs_remove_files(const struct drm_info_list *files,
>  			     int count, struct drm_minor *minor);
>  
>  void drm_debugfs_add_file(struct drm_device *dev, const char *name,
> -			  int (*show)(struct seq_file*, void*), void *data);
> +			  int (*show)(struct seq_file*, struct drm_device*, void*), void *data);
>  
>  void drm_debugfs_add_files(struct drm_device *dev,
>  			   const struct drm_debugfs_info *files, int count);
> @@ -163,7 +165,7 @@ static inline int drm_debugfs_remove_files(const struct drm_info_list *files,
>  }
>  
>  static inline void drm_debugfs_add_file(struct drm_device *dev, const char *name,
> -					int (*show)(struct seq_file*, void*),
> +					int (*show)(struct seq_file*, struct drm_device*, void*),
>  					void *data)
>  {}
>  
> -- 
> 2.39.1
> 

-- 
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH v3 5/6] drm/debugfs: Make the show callback pass the pointer to the right object
  2023-02-08 18:12   ` Daniel Vetter
@ 2023-02-08 18:17     ` Daniel Vetter
  2023-02-08 19:16       ` Maíra Canal
  0 siblings, 1 reply; 14+ messages in thread
From: Daniel Vetter @ 2023-02-08 18:17 UTC (permalink / raw)
  To: Maíra Canal
  Cc: André Almeida, Thomas Zimmermann, Rodrigo Siqueira,
	Liviu Dudau, dri-devel, Melissa Wen, Noralf Trønnes

On Wed, Feb 08, 2023 at 07:12:22PM +0100, Daniel Vetter wrote:
> On Tue, Jan 31, 2023 at 04:58:25PM -0300, Maíra Canal wrote:
> > Currently, the drivers need to access the struct drm_debugfs_entry to
> > get the proper device on the show callback. There is no need for such
> > thing, as you can wrap the show callback in order to provide to the
> > driver the proper parameters: the struct seq_file, the struct drm_device
> > and the driver-specific data stored in the struct drm_debugfs_info.
> > 
> > Therefore, make the show callback pass the pointer to the right object
> > in the parameters, which makes the API more type-safe.
> > 
> > Signed-off-by: Maíra Canal <mcanal@igalia.com>
> > ---
> >  drivers/gpu/drm/arm/hdlcd_drv.c       |  8 ++------
> >  drivers/gpu/drm/drm_atomic.c          |  4 +---
> >  drivers/gpu/drm/drm_client.c          |  5 ++---
> >  drivers/gpu/drm/drm_debugfs.c         | 25 ++++++++++++-------------
> >  drivers/gpu/drm/drm_framebuffer.c     |  4 +---
> >  drivers/gpu/drm/drm_gem_vram_helper.c |  5 ++---
> >  drivers/gpu/drm/gud/gud_drv.c         |  5 ++---
> >  drivers/gpu/drm/v3d/v3d_debugfs.c     | 16 ++++------------
> >  drivers/gpu/drm/vc4/vc4_bo.c          |  4 +---
> >  drivers/gpu/drm/vc4/vc4_debugfs.c     |  6 ++----
> >  drivers/gpu/drm/vc4/vc4_hdmi.c        |  6 ++----
> >  drivers/gpu/drm/vc4/vc4_hvs.c         |  8 ++------
> >  drivers/gpu/drm/vc4/vc4_v3d.c         |  4 +---
> >  drivers/gpu/drm/vkms/vkms_drv.c       |  4 +---
> >  include/drm/drm_debugfs.h             | 14 ++++++++------
> >  15 files changed, 43 insertions(+), 75 deletions(-)
> > 
> > diff --git a/drivers/gpu/drm/arm/hdlcd_drv.c b/drivers/gpu/drm/arm/hdlcd_drv.c
> > index e3507dd6f82a..b70bc7b11764 100644
> > --- a/drivers/gpu/drm/arm/hdlcd_drv.c
> > +++ b/drivers/gpu/drm/arm/hdlcd_drv.c
> > @@ -193,10 +193,8 @@ static int hdlcd_setup_mode_config(struct drm_device *drm)
> >  }
> >  
> >  #ifdef CONFIG_DEBUG_FS
> > -static int hdlcd_show_underrun_count(struct seq_file *m, void *arg)
> > +static int hdlcd_show_underrun_count(struct seq_file *m, struct drm_device *drm, void *arg)
> >  {
> > -	struct drm_debugfs_entry *entry = m->private;
> > -	struct drm_device *drm = entry->dev;
> >  	struct hdlcd_drm_private *hdlcd = drm_to_hdlcd_priv(drm);
> >  
> >  	seq_printf(m, "underrun : %d\n", atomic_read(&hdlcd->buffer_underrun_count));
> > @@ -206,10 +204,8 @@ static int hdlcd_show_underrun_count(struct seq_file *m, void *arg)
> >  	return 0;
> >  }
> >  
> > -static int hdlcd_show_pxlclock(struct seq_file *m, void *arg)
> > +static int hdlcd_show_pxlclock(struct seq_file *m, struct drm_device *drm, void *arg)
> >  {
> > -	struct drm_debugfs_entry *entry = m->private;
> > -	struct drm_device *drm = entry->dev;
> >  	struct hdlcd_drm_private *hdlcd = drm_to_hdlcd_priv(drm);
> >  	unsigned long clkrate = clk_get_rate(hdlcd->clk);
> >  	unsigned long mode_clock = hdlcd->crtc.mode.crtc_clock * 1000;
> > diff --git a/drivers/gpu/drm/drm_atomic.c b/drivers/gpu/drm/drm_atomic.c
> > index 5457c02ca1ab..38f140481fcc 100644
> > --- a/drivers/gpu/drm/drm_atomic.c
> > +++ b/drivers/gpu/drm/drm_atomic.c
> > @@ -1754,10 +1754,8 @@ void drm_state_dump(struct drm_device *dev, struct drm_printer *p)
> >  EXPORT_SYMBOL(drm_state_dump);
> >  
> >  #ifdef CONFIG_DEBUG_FS
> > -static int drm_state_info(struct seq_file *m, void *data)
> > +static int drm_state_info(struct seq_file *m, struct drm_device *dev, void *data)
> >  {
> > -	struct drm_debugfs_entry *entry = m->private;
> > -	struct drm_device *dev = entry->dev;
> >  	struct drm_printer p = drm_seq_file_printer(m);
> >  
> >  	__drm_state_dump(dev, &p, true);
> > diff --git a/drivers/gpu/drm/drm_client.c b/drivers/gpu/drm/drm_client.c
> > index 009e7b10455c..ec2e6bc3515d 100644
> > --- a/drivers/gpu/drm/drm_client.c
> > +++ b/drivers/gpu/drm/drm_client.c
> > @@ -488,10 +488,9 @@ int drm_client_framebuffer_flush(struct drm_client_buffer *buffer, struct drm_re
> >  EXPORT_SYMBOL(drm_client_framebuffer_flush);
> >  
> >  #ifdef CONFIG_DEBUG_FS
> > -static int drm_client_debugfs_internal_clients(struct seq_file *m, void *data)
> > +static int drm_client_debugfs_internal_clients(struct seq_file *m, struct drm_device *dev,
> > +					       void *data)
> >  {
> > -	struct drm_debugfs_entry *entry = m->private;
> > -	struct drm_device *dev = entry->dev;
> >  	struct drm_printer p = drm_seq_file_printer(m);
> >  	struct drm_client_dev *client;
> >  
> > diff --git a/drivers/gpu/drm/drm_debugfs.c b/drivers/gpu/drm/drm_debugfs.c
> > index b4d2e7dd87f5..21f01c7d0ab1 100644
> > --- a/drivers/gpu/drm/drm_debugfs.c
> > +++ b/drivers/gpu/drm/drm_debugfs.c
> > @@ -49,10 +49,8 @@
> >   * Initialization, etc.
> >   **************************************************/
> >  
> > -static int drm_name_info(struct seq_file *m, void *data)
> > +static int drm_name_info(struct seq_file *m, struct drm_device *dev, void *data)
> >  {
> > -	struct drm_debugfs_entry *entry = m->private;
> > -	struct drm_device *dev = entry->dev;
> >  	struct drm_master *master;
> >  
> >  	mutex_lock(&dev->master_mutex);
> > @@ -70,10 +68,8 @@ static int drm_name_info(struct seq_file *m, void *data)
> >  	return 0;
> >  }
> >  
> > -static int drm_clients_info(struct seq_file *m, void *data)
> > +static int drm_clients_info(struct seq_file *m, struct drm_device *dev, void *data)
> >  {
> > -	struct drm_debugfs_entry *entry = m->private;
> > -	struct drm_device *dev = entry->dev;
> >  	struct drm_file *priv;
> >  	kuid_t uid;
> >  
> > @@ -122,11 +118,8 @@ static int drm_gem_one_name_info(int id, void *ptr, void *data)
> >  	return 0;
> >  }
> >  
> > -static int drm_gem_name_info(struct seq_file *m, void *data)
> > +static int drm_gem_name_info(struct seq_file *m, struct drm_device *dev, void *data)
> >  {
> > -	struct drm_debugfs_entry *entry = m->private;
> > -	struct drm_device *dev = entry->dev;
> > -
> >  	seq_printf(m, "  name     size handles refcount\n");
> >  
> >  	mutex_lock(&dev->object_name_lock);
> > @@ -143,6 +136,13 @@ static const struct drm_debugfs_info drm_debugfs_list[] = {
> >  };
> >  #define DRM_DEBUGFS_ENTRIES ARRAY_SIZE(drm_debugfs_list)
> >  
> > +static int drm_debugfs_dev_show(struct seq_file *m, void *unused)
> > +{
> > +	struct drm_debugfs_entry *entry = m->private;
> > +	int (*show)(struct seq_file *, struct drm_device *, void *) = entry->file.show;
> > +
> > +	return show(m, entry->dev, entry->file.data);
> > +}
> >  
> >  static int drm_debugfs_open(struct inode *inode, struct file *file)
> >  {
> > @@ -154,9 +154,8 @@ static int drm_debugfs_open(struct inode *inode, struct file *file)
> >  static int drm_debugfs_entry_open(struct inode *inode, struct file *file)
> >  {
> >  	struct drm_debugfs_entry *entry = inode->i_private;
> > -	struct drm_debugfs_info *node = &entry->file;
> >  
> > -	return single_open(file, node->show, entry);
> > +	return single_open(file, drm_debugfs_dev_show, entry);
> >  }
> >  
> >  static const struct file_operations drm_debugfs_entry_fops = {
> > @@ -353,7 +352,7 @@ void drm_debugfs_cleanup(struct drm_minor *minor)
> >   * drm_debugfs_init.
> >   */
> >  void drm_debugfs_add_file(struct drm_device *dev, const char *name,
> > -			  int (*show)(struct seq_file*, void*), void *data)
> > +			  int (*show)(struct seq_file*, struct drm_device*, void*), void *data)
> >  {
> >  	struct drm_debugfs_entry *entry = drmm_kzalloc(dev, sizeof(*entry), GFP_KERNEL);
> >  
> > diff --git a/drivers/gpu/drm/drm_framebuffer.c b/drivers/gpu/drm/drm_framebuffer.c
> > index aff3746dedfb..f01b3cca9e06 100644
> > --- a/drivers/gpu/drm/drm_framebuffer.c
> > +++ b/drivers/gpu/drm/drm_framebuffer.c
> > @@ -1201,10 +1201,8 @@ void drm_framebuffer_print_info(struct drm_printer *p, unsigned int indent,
> >  }
> >  
> >  #ifdef CONFIG_DEBUG_FS
> > -static int drm_framebuffer_info(struct seq_file *m, void *data)
> > +static int drm_framebuffer_info(struct seq_file *m, struct drm_device *dev, void *data)
> >  {
> > -	struct drm_debugfs_entry *entry = m->private;
> > -	struct drm_device *dev = entry->dev;
> >  	struct drm_printer p = drm_seq_file_printer(m);
> >  	struct drm_framebuffer *fb;
> >  
> > diff --git a/drivers/gpu/drm/drm_gem_vram_helper.c b/drivers/gpu/drm/drm_gem_vram_helper.c
> > index d40b3edb52d0..5fc78317ad9d 100644
> > --- a/drivers/gpu/drm/drm_gem_vram_helper.c
> > +++ b/drivers/gpu/drm/drm_gem_vram_helper.c
> > @@ -955,10 +955,9 @@ static struct ttm_device_funcs bo_driver = {
> >   * struct drm_vram_mm
> >   */
> >  
> > -static int drm_vram_mm_debugfs(struct seq_file *m, void *data)
> > +static int drm_vram_mm_debugfs(struct seq_file *m, struct drm_device *dev, void *data)
> >  {
> > -	struct drm_debugfs_entry *entry = m->private;
> > -	struct drm_vram_mm *vmm = entry->dev->vram_mm;
> > +	struct drm_vram_mm *vmm = dev->vram_mm;
> >  	struct ttm_resource_manager *man = ttm_manager_type(&vmm->bdev, TTM_PL_VRAM);
> >  	struct drm_printer p = drm_seq_file_printer(m);
> >  
> > diff --git a/drivers/gpu/drm/gud/gud_drv.c b/drivers/gpu/drm/gud/gud_drv.c
> > index 9d7bf8ee45f1..cfd887de599a 100644
> > --- a/drivers/gpu/drm/gud/gud_drv.c
> > +++ b/drivers/gpu/drm/gud/gud_drv.c
> > @@ -323,10 +323,9 @@ static struct drm_gem_object *gud_gem_prime_import(struct drm_device *drm, struc
> >  	return drm_gem_prime_import_dev(drm, dma_buf, gdrm->dmadev);
> >  }
> >  
> > -static int gud_stats_debugfs(struct seq_file *m, void *data)
> > +static int gud_stats_debugfs(struct seq_file *m, struct drm_device *dev, void *data)
> >  {
> > -	struct drm_debugfs_entry *entry = m->private;
> > -	struct gud_device *gdrm = to_gud_device(entry->dev);
> > +	struct gud_device *gdrm = to_gud_device(dev);
> >  	char buf[10];
> >  
> >  	string_get_size(gdrm->bulk_len, 1, STRING_UNITS_2, buf, sizeof(buf));
> > diff --git a/drivers/gpu/drm/v3d/v3d_debugfs.c b/drivers/gpu/drm/v3d/v3d_debugfs.c
> > index 330669f51fa7..a142615f4789 100644
> > --- a/drivers/gpu/drm/v3d/v3d_debugfs.c
> > +++ b/drivers/gpu/drm/v3d/v3d_debugfs.c
> > @@ -77,10 +77,8 @@ static const struct v3d_reg_def v3d_csd_reg_defs[] = {
> >  	REGDEF(V3D_CSD_CURRENT_CFG6),
> >  };
> >  
> > -static int v3d_v3d_debugfs_regs(struct seq_file *m, void *unused)
> > +static int v3d_v3d_debugfs_regs(struct seq_file *m, struct drm_device *dev, void *unused)
> >  {
> > -	struct drm_debugfs_entry *entry = m->private;
> > -	struct drm_device *dev = entry->dev;
> >  	struct v3d_dev *v3d = to_v3d_dev(dev);
> >  	int i, core;
> >  
> > @@ -124,10 +122,8 @@ static int v3d_v3d_debugfs_regs(struct seq_file *m, void *unused)
> >  	return 0;
> >  }
> >  
> > -static int v3d_v3d_debugfs_ident(struct seq_file *m, void *unused)
> > +static int v3d_v3d_debugfs_ident(struct seq_file *m, struct drm_device *dev, void *unused)
> >  {
> > -	struct drm_debugfs_entry *entry = m->private;
> > -	struct drm_device *dev = entry->dev;
> >  	struct v3d_dev *v3d = to_v3d_dev(dev);
> >  	u32 ident0, ident1, ident2, ident3, cores;
> >  	int core;
> > @@ -186,10 +182,8 @@ static int v3d_v3d_debugfs_ident(struct seq_file *m, void *unused)
> >  	return 0;
> >  }
> >  
> > -static int v3d_debugfs_bo_stats(struct seq_file *m, void *unused)
> > +static int v3d_debugfs_bo_stats(struct seq_file *m, struct drm_device *dev, void *unused)
> >  {
> > -	struct drm_debugfs_entry *entry = m->private;
> > -	struct drm_device *dev = entry->dev;
> >  	struct v3d_dev *v3d = to_v3d_dev(dev);
> >  
> >  	mutex_lock(&v3d->bo_lock);
> > @@ -202,10 +196,8 @@ static int v3d_debugfs_bo_stats(struct seq_file *m, void *unused)
> >  	return 0;
> >  }
> >  
> > -static int v3d_measure_clock(struct seq_file *m, void *unused)
> > +static int v3d_measure_clock(struct seq_file *m, struct drm_device *dev, void *unused)
> >  {
> > -	struct drm_debugfs_entry *entry = m->private;
> > -	struct drm_device *dev = entry->dev;
> >  	struct v3d_dev *v3d = to_v3d_dev(dev);
> >  	uint32_t cycles;
> >  	int core = 0;
> > diff --git a/drivers/gpu/drm/vc4/vc4_bo.c b/drivers/gpu/drm/vc4/vc4_bo.c
> > index 86d629e45307..ea58728799da 100644
> > --- a/drivers/gpu/drm/vc4/vc4_bo.c
> > +++ b/drivers/gpu/drm/vc4/vc4_bo.c
> > @@ -67,10 +67,8 @@ static void vc4_bo_stats_print(struct drm_printer *p, struct vc4_dev *vc4)
> >  	mutex_unlock(&vc4->purgeable.lock);
> >  }
> >  
> > -static int vc4_bo_stats_debugfs(struct seq_file *m, void *unused)
> > +static int vc4_bo_stats_debugfs(struct seq_file *m, struct drm_device *dev, void *unused)
> >  {
> > -	struct drm_debugfs_entry *entry = m->private;
> > -	struct drm_device *dev = entry->dev;
> >  	struct vc4_dev *vc4 = to_vc4_dev(dev);
> >  	struct drm_printer p = drm_seq_file_printer(m);
> >  
> > diff --git a/drivers/gpu/drm/vc4/vc4_debugfs.c b/drivers/gpu/drm/vc4/vc4_debugfs.c
> > index fac624a663ea..42c5d3c95a3f 100644
> > --- a/drivers/gpu/drm/vc4/vc4_debugfs.c
> > +++ b/drivers/gpu/drm/vc4/vc4_debugfs.c
> > @@ -32,11 +32,9 @@ vc4_debugfs_init(struct drm_minor *minor)
> >  	}
> >  }
> >  
> > -static int vc4_debugfs_regset32(struct seq_file *m, void *unused)
> > +static int vc4_debugfs_regset32(struct seq_file *m, struct drm_device *drm, void *data)
> >  {
> > -	struct drm_debugfs_entry *entry = m->private;
> > -	struct drm_device *drm = entry->dev;
> > -	struct debugfs_regset32 *regset = entry->file.data;
> > +	struct debugfs_regset32 *regset = data;
> >  	struct drm_printer p = drm_seq_file_printer(m);
> >  	int idx;
> >  
> > diff --git a/drivers/gpu/drm/vc4/vc4_hdmi.c b/drivers/gpu/drm/vc4/vc4_hdmi.c
> > index 14628864487a..5e1e1edc55db 100644
> > --- a/drivers/gpu/drm/vc4/vc4_hdmi.c
> > +++ b/drivers/gpu/drm/vc4/vc4_hdmi.c
> > @@ -158,11 +158,9 @@ static bool vc4_hdmi_is_full_range_rgb(struct vc4_hdmi *vc4_hdmi,
> >  		drm_default_rgb_quant_range(mode) == HDMI_QUANTIZATION_RANGE_FULL;
> >  }
> >  
> > -static int vc4_hdmi_debugfs_regs(struct seq_file *m, void *unused)
> > +static int vc4_hdmi_debugfs_regs(struct seq_file *m, struct drm_device *drm, void *data)
> >  {
> > -	struct drm_debugfs_entry *entry = m->private;
> > -	struct vc4_hdmi *vc4_hdmi = entry->file.data;
> > -	struct drm_device *drm = vc4_hdmi->connector.dev;
> > +	struct vc4_hdmi *vc4_hdmi = data;
> >  	struct drm_printer p = drm_seq_file_printer(m);
> >  	int idx;
> >  
> > diff --git a/drivers/gpu/drm/vc4/vc4_hvs.c b/drivers/gpu/drm/vc4/vc4_hvs.c
> > index 4da66ef96783..8c37b5c3cb05 100644
> > --- a/drivers/gpu/drm/vc4/vc4_hvs.c
> > +++ b/drivers/gpu/drm/vc4/vc4_hvs.c
> > @@ -91,10 +91,8 @@ void vc4_hvs_dump_state(struct vc4_hvs *hvs)
> >  	drm_dev_exit(idx);
> >  }
> >  
> > -static int vc4_hvs_debugfs_underrun(struct seq_file *m, void *data)
> > +static int vc4_hvs_debugfs_underrun(struct seq_file *m, struct drm_device *dev, void *data)
> >  {
> > -	struct drm_debugfs_entry *entry = m->private;
> > -	struct drm_device *dev = entry->dev;
> >  	struct vc4_dev *vc4 = to_vc4_dev(dev);
> >  	struct drm_printer p = drm_seq_file_printer(m);
> >  
> > @@ -103,10 +101,8 @@ static int vc4_hvs_debugfs_underrun(struct seq_file *m, void *data)
> >  	return 0;
> >  }
> >  
> > -static int vc4_hvs_debugfs_dlist(struct seq_file *m, void *data)
> > +static int vc4_hvs_debugfs_dlist(struct seq_file *m, struct drm_device *dev, void *data)
> >  {
> > -	struct drm_debugfs_entry *entry = m->private;
> > -	struct drm_device *dev = entry->dev;
> >  	struct vc4_dev *vc4 = to_vc4_dev(dev);
> >  	struct vc4_hvs *hvs = vc4->hvs;
> >  	struct drm_printer p = drm_seq_file_printer(m);
> > diff --git a/drivers/gpu/drm/vc4/vc4_v3d.c b/drivers/gpu/drm/vc4/vc4_v3d.c
> > index 29a664c8bf44..49eb48a270db 100644
> > --- a/drivers/gpu/drm/vc4/vc4_v3d.c
> > +++ b/drivers/gpu/drm/vc4/vc4_v3d.c
> > @@ -94,10 +94,8 @@ static const struct debugfs_reg32 v3d_regs[] = {
> >  	VC4_REG32(V3D_ERRSTAT),
> >  };
> >  
> > -static int vc4_v3d_debugfs_ident(struct seq_file *m, void *unused)
> > +static int vc4_v3d_debugfs_ident(struct seq_file *m, struct drm_device *dev, void *unused)
> >  {
> > -	struct drm_debugfs_entry *entry = m->private;
> > -	struct drm_device *dev = entry->dev;
> >  	struct vc4_dev *vc4 = to_vc4_dev(dev);
> >  	int ret = vc4_v3d_pm_get(vc4);
> >  
> > diff --git a/drivers/gpu/drm/vkms/vkms_drv.c b/drivers/gpu/drm/vkms/vkms_drv.c
> > index 6d3a2d57d992..dde6a500f3b1 100644
> > --- a/drivers/gpu/drm/vkms/vkms_drv.c
> > +++ b/drivers/gpu/drm/vkms/vkms_drv.c
> > @@ -90,10 +90,8 @@ static void vkms_atomic_commit_tail(struct drm_atomic_state *old_state)
> >  	drm_atomic_helper_cleanup_planes(dev, old_state);
> >  }
> >  
> > -static int vkms_config_show(struct seq_file *m, void *data)
> > +static int vkms_config_show(struct seq_file *m, struct drm_device *dev, void *data)
> >  {
> > -	struct drm_debugfs_entry *entry = m->private;
> > -	struct drm_device *dev = entry->dev;
> >  	struct vkms_device *vkmsdev = drm_device_to_vkms_device(dev);
> >  
> >  	seq_printf(m, "writeback=%d\n", vkmsdev->config->writeback);
> > diff --git a/include/drm/drm_debugfs.h b/include/drm/drm_debugfs.h
> > index 423aa3de506a..0fb7ad5f6893 100644
> > --- a/include/drm/drm_debugfs.h
> > +++ b/include/drm/drm_debugfs.h
> > @@ -36,6 +36,9 @@
> >  #include <linux/mutex.h>
> >  #include <linux/types.h>
> >  #include <linux/seq_file.h>
> > +
> > +struct drm_device;
> > +
> >  /**
> >   * struct drm_info_list - debugfs info list entry
> >   *
> > @@ -108,11 +111,10 @@ struct drm_debugfs_info {
> >  	/**
> >  	 * @show:
> >  	 *
> > -	 * Show callback. &seq_file->private will be set to the &struct
> > -	 * drm_debugfs_entry corresponding to the instance of this info
> > -	 * on a given &struct drm_device.
> > +	 * Show callback. This callback will be casted in order to provide
> > +	 * the &seq_file, the DRM object and the data stored in this struct.
> >  	 */
> > -	int (*show)(struct seq_file*, void*);
> > +	void *show;
> 
> The problem here is that with this we loose type-checking, and so all the
> users of drm_debugfs_add_file() have been missed in the conversion. That's
> not very good :-/

Correction, you didn't miss that, but it's the risk that could happen
because the driver doesn't check things.

> I think the only way to sort this out is if we duplicate the driver-facing
> functions/structs (maybe we don't need the add_files() functions in all
> cases?), and only use the type-unsafe void* internally.

Since I didnt' spell it out: If you only keep the change to add the
drm_device *dev pointer in this patch, but keep the full type everywhere,
then struct drm_debugfs_entry becomes an implementation detail and you can
move it into drm_debugfs.c. Once you have that you can throw out the
driver api facing struct drm_debugfs_info and just put all the required
pointers and things directly in there as void *, and it should work out
with reasonable amounts of code sharing, while the driver api all stays
type safe.
-Daniel

> -Daniel
> 
> >  
> >  	/** @driver_features: Required driver features for this entry. */
> >  	u32 driver_features;
> > @@ -146,7 +148,7 @@ int drm_debugfs_remove_files(const struct drm_info_list *files,
> >  			     int count, struct drm_minor *minor);
> >  
> >  void drm_debugfs_add_file(struct drm_device *dev, const char *name,
> > -			  int (*show)(struct seq_file*, void*), void *data);
> > +			  int (*show)(struct seq_file*, struct drm_device*, void*), void *data);
> >  
> >  void drm_debugfs_add_files(struct drm_device *dev,
> >  			   const struct drm_debugfs_info *files, int count);
> > @@ -163,7 +165,7 @@ static inline int drm_debugfs_remove_files(const struct drm_info_list *files,
> >  }
> >  
> >  static inline void drm_debugfs_add_file(struct drm_device *dev, const char *name,
> > -					int (*show)(struct seq_file*, void*),
> > +					int (*show)(struct seq_file*, struct drm_device*, void*),
> >  					void *data)
> >  {}
> >  
> > -- 
> > 2.39.1
> > 
> 
> -- 
> Daniel Vetter
> Software Engineer, Intel Corporation
> http://blog.ffwll.ch

-- 
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH v3 1/6] drm/debugfs: Introduce wrapper for debugfs list
  2023-02-08 18:06   ` Daniel Vetter
@ 2023-02-08 18:19     ` Daniel Vetter
  2023-02-08 18:39     ` Maíra Canal
  1 sibling, 0 replies; 14+ messages in thread
From: Daniel Vetter @ 2023-02-08 18:19 UTC (permalink / raw)
  To: Maíra Canal
  Cc: André Almeida, Thomas Zimmermann, Rodrigo Siqueira,
	Liviu Dudau, dri-devel, Melissa Wen, Noralf Trønnes

On Wed, Feb 08, 2023 at 07:06:19PM +0100, Daniel Vetter wrote:
> On Tue, Jan 31, 2023 at 04:58:21PM -0300, Maíra Canal wrote:
> > 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  | 18 ++++++++++++++++++
> >  drivers/gpu/drm/drm_internal.h | 12 ++++++++++++
> >  include/drm/drm_debugfs.h      | 16 ++++++++++++++++
> >  3 files changed, 46 insertions(+)
> > 
> > diff --git a/drivers/gpu/drm/drm_debugfs.c b/drivers/gpu/drm/drm_debugfs.c
> > index 4f643a490dc3..8658d3929ea5 100644
> > --- a/drivers/gpu/drm/drm_debugfs.c
> > +++ b/drivers/gpu/drm/drm_debugfs.c
> > @@ -218,6 +218,24 @@ void drm_debugfs_create_files(const struct drm_info_list *files, int count,
> >  }
> >  EXPORT_SYMBOL(drm_debugfs_create_files);
> >  
> > +struct drm_debugfs_files *drm_debugfs_files_init(void)
> > +{
> > +	struct drm_debugfs_files *debugfs_files;
> > +
> > +	debugfs_files = kzalloc(sizeof(*debugfs_files), GFP_KERNEL);
> > +
> > +	INIT_LIST_HEAD(&debugfs_files->list);
> > +	mutex_init(&debugfs_files->mutex);
> > +
> > +	return debugfs_files;
> > +}
> > +
> > +void drm_debugfs_files_destroy(struct drm_debugfs_files *debugfs_files)
> > +{
> > +	mutex_destroy(&debugfs_files->mutex);
> > +	kfree(debugfs_files);
> > +}
> > +
> >  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..f1c8766ed828 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)
> > +struct drm_debugfs_files *drm_debugfs_files_init(void);
> > +void drm_debugfs_files_destroy(struct drm_debugfs_files *debugfs_files);
> >  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,15 @@ 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 struct drm_debugfs_files *drm_debugfs_files_init(void)
> > +{
> > +	return NULL;
> > +}
> > +
> > +static inline void drm_debugfs_files_destroy(struct drm_debugfs_files *debugfs_files)
> > +{
> > +}
> > +
> >  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..423aa3de506a 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_files - 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_files {
> > +	/** @list: List of debugfs files to be created by the DRM object. */
> > +	struct list_head list;
> > +
> > +	/** @mutex: Protects &list access. */
> > +	struct mutex mutex;
> 
> I'm not seeing any use for the mutex here? Also unless you also plan to
> put like the debugfs directory pointers in this struct, I'm not sure we
> need this abstraction since it's purely internal to debugfs code (so also
> should really be in the headers where drivers could perhaps come up with
> funny ideas).

To clarify, I think any struct or code which is potentially type unsafe,
like this one here or the drm_debugfs_entry one, should be moved into
drm_debugfs.c. That way drivers do not ever see the potentially dangerous
pieces, and only have a type-safe interface for everything.
-Daniel
-- 
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH v3 1/6] drm/debugfs: Introduce wrapper for debugfs list
  2023-02-08 18:06   ` Daniel Vetter
  2023-02-08 18:19     ` Daniel Vetter
@ 2023-02-08 18:39     ` Maíra Canal
  2023-02-08 18:58       ` Daniel Vetter
  1 sibling, 1 reply; 14+ messages in thread
From: Maíra Canal @ 2023-02-08 18:39 UTC (permalink / raw)
  To: Daniel Vetter
  Cc: André Almeida, Rodrigo Siqueira, Liviu Dudau, dri-devel,
	Melissa Wen, Noralf Trønnes, Thomas Zimmermann

On 2/8/23 15:06, Daniel Vetter wrote:
> On Tue, Jan 31, 2023 at 04:58:21PM -0300, Maíra Canal wrote:
>> 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  | 18 ++++++++++++++++++
>>   drivers/gpu/drm/drm_internal.h | 12 ++++++++++++
>>   include/drm/drm_debugfs.h      | 16 ++++++++++++++++
>>   3 files changed, 46 insertions(+)
>>
>> diff --git a/drivers/gpu/drm/drm_debugfs.c b/drivers/gpu/drm/drm_debugfs.c
>> index 4f643a490dc3..8658d3929ea5 100644
>> --- a/drivers/gpu/drm/drm_debugfs.c
>> +++ b/drivers/gpu/drm/drm_debugfs.c
>> @@ -218,6 +218,24 @@ void drm_debugfs_create_files(const struct drm_info_list *files, int count,
>>   }
>>   EXPORT_SYMBOL(drm_debugfs_create_files);
>>   
>> +struct drm_debugfs_files *drm_debugfs_files_init(void)
>> +{
>> +	struct drm_debugfs_files *debugfs_files;
>> +
>> +	debugfs_files = kzalloc(sizeof(*debugfs_files), GFP_KERNEL);
>> +
>> +	INIT_LIST_HEAD(&debugfs_files->list);
>> +	mutex_init(&debugfs_files->mutex);
>> +
>> +	return debugfs_files;
>> +}
>> +
>> +void drm_debugfs_files_destroy(struct drm_debugfs_files *debugfs_files)
>> +{
>> +	mutex_destroy(&debugfs_files->mutex);
>> +	kfree(debugfs_files);
>> +}
>> +
>>   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..f1c8766ed828 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)
>> +struct drm_debugfs_files *drm_debugfs_files_init(void);
>> +void drm_debugfs_files_destroy(struct drm_debugfs_files *debugfs_files);
>>   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,15 @@ 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 struct drm_debugfs_files *drm_debugfs_files_init(void)
>> +{
>> +	return NULL;
>> +}
>> +
>> +static inline void drm_debugfs_files_destroy(struct drm_debugfs_files *debugfs_files)
>> +{
>> +}
>> +
>>   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..423aa3de506a 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_files - 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_files {
>> +	/** @list: List of debugfs files to be created by the DRM object. */
>> +	struct list_head list;
>> +
>> +	/** @mutex: Protects &list access. */
>> +	struct mutex mutex;
> 
> I'm not seeing any use for the mutex here? Also unless you also plan to
> put like the debugfs directory pointers in this struct, I'm not sure we
> need this abstraction since it's purely internal to debugfs code (so also
> should really be in the headers where drivers could perhaps come up with
> funny ideas).

Isn't this mutex needed to guarantee race-conditions safety when adding new
files to the list, as drm_debugfs_add_file() is called by the drivers? [1]

[1] https://cgit.freedesktop.org/drm/drm-misc/tree/drivers/gpu/drm/drm_debugfs.c#n343

Best Regards,
- Maíra Canal

> -Daniel
> 
>> +};
>> +
>>   /**
>>    * struct drm_debugfs_info - debugfs info list entry
>>    *
>> -- 
>> 2.39.1
>>
> 

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH v3 1/6] drm/debugfs: Introduce wrapper for debugfs list
  2023-02-08 18:39     ` Maíra Canal
@ 2023-02-08 18:58       ` Daniel Vetter
  0 siblings, 0 replies; 14+ messages in thread
From: Daniel Vetter @ 2023-02-08 18:58 UTC (permalink / raw)
  To: Maíra Canal
  Cc: André Almeida, Rodrigo Siqueira, Liviu Dudau, dri-devel,
	Melissa Wen, Noralf Trønnes, Thomas Zimmermann

On Wed, Feb 08, 2023 at 03:39:13PM -0300, Maíra Canal wrote:
> On 2/8/23 15:06, Daniel Vetter wrote:
> > On Tue, Jan 31, 2023 at 04:58:21PM -0300, Maíra Canal wrote:
> > > 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  | 18 ++++++++++++++++++
> > >   drivers/gpu/drm/drm_internal.h | 12 ++++++++++++
> > >   include/drm/drm_debugfs.h      | 16 ++++++++++++++++
> > >   3 files changed, 46 insertions(+)
> > > 
> > > diff --git a/drivers/gpu/drm/drm_debugfs.c b/drivers/gpu/drm/drm_debugfs.c
> > > index 4f643a490dc3..8658d3929ea5 100644
> > > --- a/drivers/gpu/drm/drm_debugfs.c
> > > +++ b/drivers/gpu/drm/drm_debugfs.c
> > > @@ -218,6 +218,24 @@ void drm_debugfs_create_files(const struct drm_info_list *files, int count,
> > >   }
> > >   EXPORT_SYMBOL(drm_debugfs_create_files);
> > > +struct drm_debugfs_files *drm_debugfs_files_init(void)
> > > +{
> > > +	struct drm_debugfs_files *debugfs_files;
> > > +
> > > +	debugfs_files = kzalloc(sizeof(*debugfs_files), GFP_KERNEL);
> > > +
> > > +	INIT_LIST_HEAD(&debugfs_files->list);
> > > +	mutex_init(&debugfs_files->mutex);
> > > +
> > > +	return debugfs_files;
> > > +}
> > > +
> > > +void drm_debugfs_files_destroy(struct drm_debugfs_files *debugfs_files)
> > > +{
> > > +	mutex_destroy(&debugfs_files->mutex);
> > > +	kfree(debugfs_files);
> > > +}
> > > +
> > >   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..f1c8766ed828 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)
> > > +struct drm_debugfs_files *drm_debugfs_files_init(void);
> > > +void drm_debugfs_files_destroy(struct drm_debugfs_files *debugfs_files);
> > >   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,15 @@ 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 struct drm_debugfs_files *drm_debugfs_files_init(void)
> > > +{
> > > +	return NULL;
> > > +}
> > > +
> > > +static inline void drm_debugfs_files_destroy(struct drm_debugfs_files *debugfs_files)
> > > +{
> > > +}
> > > +
> > >   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..423aa3de506a 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_files - 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_files {
> > > +	/** @list: List of debugfs files to be created by the DRM object. */
> > > +	struct list_head list;
> > > +
> > > +	/** @mutex: Protects &list access. */
> > > +	struct mutex mutex;
> > 
> > I'm not seeing any use for the mutex here? Also unless you also plan to
> > put like the debugfs directory pointers in this struct, I'm not sure we
> > need this abstraction since it's purely internal to debugfs code (so also
> > should really be in the headers where drivers could perhaps come up with
> > funny ideas).
> 
> Isn't this mutex needed to guarantee race-conditions safety when adding new
> files to the list, as drm_debugfs_add_file() is called by the drivers? [1]
> 
> [1] https://cgit.freedesktop.org/drm/drm-misc/tree/drivers/gpu/drm/drm_debugfs.c#n343

Hm I looked at the wrong place and only spotted the locking for the old
drm_minor debugfs stuff ... it does look a bit funny if we only do this in
add_file(), also usually drivers really don't have anything multi-threaded
in there. If you e.g. look at __drm_universal_plane_init() then the

	list_add_tail(&plane->head, &config->plane_list);

also doesn't have any locks. The assumption that driver load code isn't
multi-threaded is pretty deeply in-grained (note that it's different for
drm_connector because those can be hotplugged at any later point and even
concurrently with driver load finishing). So I don't think we need this in
the debugfs side. But since it's there already definitely a separate patch
to remove that locking.
-Daniel

> 
> Best Regards,
> - Maíra Canal
> 
> > -Daniel
> > 
> > > +};
> > > +
> > >   /**
> > >    * struct drm_debugfs_info - debugfs info list entry
> > >    *
> > > -- 
> > > 2.39.1
> > > 
> > 

-- 
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH v3 5/6] drm/debugfs: Make the show callback pass the pointer to the right object
  2023-02-08 18:17     ` Daniel Vetter
@ 2023-02-08 19:16       ` Maíra Canal
  0 siblings, 0 replies; 14+ messages in thread
From: Maíra Canal @ 2023-02-08 19:16 UTC (permalink / raw)
  To: Daniel Vetter
  Cc: André Almeida, Rodrigo Siqueira, Liviu Dudau, dri-devel,
	Melissa Wen, Noralf Trønnes, Thomas Zimmermann

On 2/8/23 15:17, Daniel Vetter wrote:
> On Wed, Feb 08, 2023 at 07:12:22PM +0100, Daniel Vetter wrote:
>> On Tue, Jan 31, 2023 at 04:58:25PM -0300, Maíra Canal wrote:
>>> Currently, the drivers need to access the struct drm_debugfs_entry to
>>> get the proper device on the show callback. There is no need for such
>>> thing, as you can wrap the show callback in order to provide to the
>>> driver the proper parameters: the struct seq_file, the struct drm_device
>>> and the driver-specific data stored in the struct drm_debugfs_info.
>>>
>>> Therefore, make the show callback pass the pointer to the right object
>>> in the parameters, which makes the API more type-safe.
>>>
>>> Signed-off-by: Maíra Canal <mcanal@igalia.com>
>>> ---
>>>   drivers/gpu/drm/arm/hdlcd_drv.c       |  8 ++------
>>>   drivers/gpu/drm/drm_atomic.c          |  4 +---
>>>   drivers/gpu/drm/drm_client.c          |  5 ++---
>>>   drivers/gpu/drm/drm_debugfs.c         | 25 ++++++++++++-------------
>>>   drivers/gpu/drm/drm_framebuffer.c     |  4 +---
>>>   drivers/gpu/drm/drm_gem_vram_helper.c |  5 ++---
>>>   drivers/gpu/drm/gud/gud_drv.c         |  5 ++---
>>>   drivers/gpu/drm/v3d/v3d_debugfs.c     | 16 ++++------------
>>>   drivers/gpu/drm/vc4/vc4_bo.c          |  4 +---
>>>   drivers/gpu/drm/vc4/vc4_debugfs.c     |  6 ++----
>>>   drivers/gpu/drm/vc4/vc4_hdmi.c        |  6 ++----
>>>   drivers/gpu/drm/vc4/vc4_hvs.c         |  8 ++------
>>>   drivers/gpu/drm/vc4/vc4_v3d.c         |  4 +---
>>>   drivers/gpu/drm/vkms/vkms_drv.c       |  4 +---
>>>   include/drm/drm_debugfs.h             | 14 ++++++++------
>>>   15 files changed, 43 insertions(+), 75 deletions(-)
>>>

[...]

>>> diff --git a/include/drm/drm_debugfs.h b/include/drm/drm_debugfs.h
>>> index 423aa3de506a..0fb7ad5f6893 100644
>>> --- a/include/drm/drm_debugfs.h
>>> +++ b/include/drm/drm_debugfs.h
>>> @@ -36,6 +36,9 @@
>>>   #include <linux/mutex.h>
>>>   #include <linux/types.h>
>>>   #include <linux/seq_file.h>
>>> +
>>> +struct drm_device;
>>> +
>>>   /**
>>>    * struct drm_info_list - debugfs info list entry
>>>    *
>>> @@ -108,11 +111,10 @@ struct drm_debugfs_info {
>>>   	/**
>>>   	 * @show:
>>>   	 *
>>> -	 * Show callback. &seq_file->private will be set to the &struct
>>> -	 * drm_debugfs_entry corresponding to the instance of this info
>>> -	 * on a given &struct drm_device.
>>> +	 * Show callback. This callback will be casted in order to provide
>>> +	 * the &seq_file, the DRM object and the data stored in this struct.
>>>   	 */
>>> -	int (*show)(struct seq_file*, void*);
>>> +	void *show;
>>
>> The problem here is that with this we loose type-checking, and so all the
>> users of drm_debugfs_add_file() have been missed in the conversion. That's
>> not very good :-/
> 
> Correction, you didn't miss that, but it's the risk that could happen
> because the driver doesn't check things.
> 
>> I think the only way to sort this out is if we duplicate the driver-facing
>> functions/structs (maybe we don't need the add_files() functions in all
>> cases?), and only use the type-unsafe void* internally.
> 
> Since I didnt' spell it out: If you only keep the change to add the
> drm_device *dev pointer in this patch, but keep the full type everywhere,
> then struct drm_debugfs_entry becomes an implementation detail and you can
> move it into drm_debugfs.c. Once you have that you can throw out the
> driver api facing struct drm_debugfs_info and just put all the required
> pointers and things directly in there as void *, and it should work out
> with reasonable amounts of code sharing, while the driver api all stays
> type safe.

So basically, the idea is to make this patchset using
int (*show)(struct seq_file*, struct drm_device*, void*)? I'm not sure
how could we could reuse the struct drm_debugfs_info if we don't use
void * in the show callback, as add_files needs the struct.

The type-checking is handle by the add_file and the show wrapper.
Otherwise, we would have to duplicate the drm_debugfs_info and add_file
for each object. Or do you have any other idea on how to implement
it?

Anyway, I'll send a new version with
int (*show)(struct seq_file*, struct drm_device*, void*) and moving
the struct drm_debugfs_entry to drm_debugfs.c and we can keep working
on the API.

Thanks for all the feedback!

Best Regards,
- Maíra Canal

> -Daniel
> 
>> -Daniel
>>
>>>   
>>>   	/** @driver_features: Required driver features for this entry. */
>>>   	u32 driver_features;
>>> @@ -146,7 +148,7 @@ int drm_debugfs_remove_files(const struct drm_info_list *files,
>>>   			     int count, struct drm_minor *minor);
>>>   
>>>   void drm_debugfs_add_file(struct drm_device *dev, const char *name,
>>> -			  int (*show)(struct seq_file*, void*), void *data);
>>> +			  int (*show)(struct seq_file*, struct drm_device*, void*), void *data);
>>>   
>>>   void drm_debugfs_add_files(struct drm_device *dev,
>>>   			   const struct drm_debugfs_info *files, int count);
>>> @@ -163,7 +165,7 @@ static inline int drm_debugfs_remove_files(const struct drm_info_list *files,
>>>   }
>>>   
>>>   static inline void drm_debugfs_add_file(struct drm_device *dev, const char *name,
>>> -					int (*show)(struct seq_file*, void*),
>>> +					int (*show)(struct seq_file*, struct drm_device*, void*),
>>>   					void *data)
>>>   {}
>>>   
>>> -- 
>>> 2.39.1
>>>
>>
>> -- 
>> Daniel Vetter
>> Software Engineer, Intel Corporation
>> http://blog.ffwll.ch
> 

^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2023-02-08 19:17 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-31 19:58 [PATCH v3 0/6] drm/debugfs: Make the debugfs structure more generic Maíra Canal
2023-01-31 19:58 ` [PATCH v3 1/6] drm/debugfs: Introduce wrapper for debugfs list Maíra Canal
2023-02-08 18:06   ` Daniel Vetter
2023-02-08 18:19     ` Daniel Vetter
2023-02-08 18:39     ` Maíra Canal
2023-02-08 18:58       ` Daniel Vetter
2023-01-31 19:58 ` [PATCH v3 2/6] drm/debugfs: Make drm_device use the struct drm_debugfs_files Maíra Canal
2023-01-31 19:58 ` [PATCH v3 3/6] drm/debugfs: Create wrapper to add files to debugfs list Maíra Canal
2023-01-31 19:58 ` [PATCH v3 4/6] drm/debugfs: Create wrapper to register debugfs Maíra Canal
2023-01-31 19:58 ` [PATCH v3 5/6] drm/debugfs: Make the show callback pass the pointer to the right object Maíra Canal
2023-02-08 18:12   ` Daniel Vetter
2023-02-08 18:17     ` Daniel Vetter
2023-02-08 19:16       ` Maíra Canal
2023-01-31 19:58 ` [PATCH v3 6/6] drm/debugfs: Make the struct drm_debugfs_entry independent of DRM device Maíra Canal

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).