diff mbox

[RFC,2/3] drm: Register drmfs filesystem from drm init

Message ID 1480575753-5837-3-git-send-email-swati.dhingra@intel.com (mailing list archive)
State New, archived
Headers show

Commit Message

swati.dhingra@intel.com Dec. 1, 2016, 7:02 a.m. UTC
From: Swati Dhingra <swati.dhingra@intel.com>

During drm module initialization, drm_core_init initializes the drmfs
filesystem and register this with kernel. A driver specific directory is created
inside drmfs root, and dentry of this directory is saved for subsequent use
by the driver (e.g. i915). The driver can then create files/directories inside
this root directory directly.
In case of i915 driver, the top directory is created at '/sys/kernel/drm/i915'.

Signed-off-by: Sourab Gupta <sourab.gupta@intel.com>
Signed-off-by: Swati Dhingra <swati.dhingra@intel.com>
---
 drivers/gpu/drm/drm_drv.c | 22 ++++++++++++++++++++++
 include/drm/drm_drv.h     |  3 +++
 2 files changed, 25 insertions(+)

Comments

Chris Wilson Dec. 1, 2016, 8:15 a.m. UTC | #1
On Thu, Dec 01, 2016 at 12:32:32PM +0530, swati.dhingra@intel.com wrote:
> diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
> index 84fcfcb..ead360bd 100644
> --- a/drivers/gpu/drm/drm_drv.c
> +++ b/drivers/gpu/drm/drm_drv.c
> @@ -688,6 +688,14 @@ int drm_dev_register(struct drm_device *dev, unsigned long flags)
>  {
>  	int ret;
>  
> +#ifdef CONFIG_DRMFS

Rule of thumb: avoid #ifdeffry in the body of the code, use headers to
hide conditional compilation.

> +	dev->driver->drmfs_root = drmfs_create_dir(dev->driver->name, NULL);
> +	if (IS_ERR(dev->driver->drmfs_root)) {
> +		DRM_ERROR("Failed to get drmfs root dentry\n");
> +		return PTR_ERR(dev->driver->drmfs_root);
> +	}

Considering use of drmfs is optional, should an error here prevent the
driver from loading?
-Chris
sourab.gupta@intel.com Dec. 1, 2016, 8:41 a.m. UTC | #2
On Thu, 2016-12-01 at 00:15 -0800, Chris Wilson wrote:
> On Thu, Dec 01, 2016 at 12:32:32PM +0530, swati.dhingra@intel.com wrote:
> > diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
> > index 84fcfcb..ead360bd 100644
> > --- a/drivers/gpu/drm/drm_drv.c
> > +++ b/drivers/gpu/drm/drm_drv.c
> > @@ -688,6 +688,14 @@ int drm_dev_register(struct drm_device *dev, unsigned long flags)
> >  {
> >  	int ret;
> >  
> > +#ifdef CONFIG_DRMFS
> 
> Rule of thumb: avoid #ifdeffry in the body of the code, use headers to
> hide conditional compilation.
Ok. Will do the requisite changes.
> 
> > +	dev->driver->drmfs_root = drmfs_create_dir(dev->driver->name, NULL);
> > +	if (IS_ERR(dev->driver->drmfs_root)) {
> > +		DRM_ERROR("Failed to get drmfs root dentry\n");
> > +		return PTR_ERR(dev->driver->drmfs_root);
> > +	}
> 
> Considering use of drmfs is optional, should an error here prevent the
> driver from loading?
> -Chris

Ok. Will remove the return on the error here.
diff mbox

Patch

diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
index 84fcfcb..ead360bd 100644
--- a/drivers/gpu/drm/drm_drv.c
+++ b/drivers/gpu/drm/drm_drv.c
@@ -688,6 +688,14 @@  int drm_dev_register(struct drm_device *dev, unsigned long flags)
 {
 	int ret;
 
+#ifdef CONFIG_DRMFS
+	dev->driver->drmfs_root = drmfs_create_dir(dev->driver->name, NULL);
+	if (IS_ERR(dev->driver->drmfs_root)) {
+		DRM_ERROR("Failed to get drmfs root dentry\n");
+		return PTR_ERR(dev->driver->drmfs_root);
+	}
+#endif
+
 	mutex_lock(&drm_global_mutex);
 
 	ret = drm_minor_register(dev, DRM_MINOR_CONTROL);
@@ -758,6 +766,9 @@  void drm_dev_unregister(struct drm_device *dev)
 	drm_minor_unregister(dev, DRM_MINOR_PRIMARY);
 	drm_minor_unregister(dev, DRM_MINOR_RENDER);
 	drm_minor_unregister(dev, DRM_MINOR_CONTROL);
+#ifdef CONFIG_DRMFS
+	drmfs_remove(dev->driver->drmfs_root);
+#endif
 }
 EXPORT_SYMBOL(drm_dev_unregister);
 
@@ -825,6 +836,9 @@  static void drm_core_exit(void)
 {
 	unregister_chrdev(DRM_MAJOR, "drm");
 	debugfs_remove(drm_debugfs_root);
+#ifdef CONFIG_DRMFS
+	drmfs_fini();
+#endif
 	drm_sysfs_destroy();
 	idr_destroy(&drm_minors_idr);
 	drm_connector_ida_destroy();
@@ -845,6 +859,14 @@  static int __init drm_core_init(void)
 		goto error;
 	}
 
+#ifdef CONFIG_DRMFS
+	ret = drmfs_init();
+	if (ret < 0) {
+		DRM_ERROR("Cannot create DRM FS: %d\n", ret);
+		goto error;
+	}
+#endif
+
 	drm_debugfs_root = debugfs_create_dir("dri", NULL);
 	if (!drm_debugfs_root) {
 		ret = -ENOMEM;
diff --git a/include/drm/drm_drv.h b/include/drm/drm_drv.h
index aad8bba..34804de 100644
--- a/include/drm/drm_drv.h
+++ b/include/drm/drm_drv.h
@@ -403,6 +403,9 @@  struct drm_driver {
 
 	/* List of devices hanging off this driver with stealth attach. */
 	struct list_head legacy_dev_list;
+
+	/* drmfs parent directory dentry for this driver */
+	struct dentry *drmfs_root;
 };
 
 extern __printf(6, 7)