linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH drm/hisilicon 0/3] Add the new api to install irq
@ 2020-11-26 12:02 Tian Tao
  2020-11-26 12:02 ` [PATCH drm/hisilicon 1/3] drm/hisilicon: Code refactoring for hibmc_drm_drv Tian Tao
                   ` (2 more replies)
  0 siblings, 3 replies; 12+ messages in thread
From: Tian Tao @ 2020-11-26 12:02 UTC (permalink / raw)
  To: airlied, daniel, tzimmermann, kraxel, alexander.deucher, tglx,
	dri-devel, xinliang.liu, maarten.lankhorst, mripard
  Cc: linux-kernel

patch #1 is code refactorings to use devm_drm_dev_alloc and
devm_drm_irq_install.
patch #2 add the new api to install irq, patch #3 is hibmc driver uses
the newly added api to register interrupts.

Tian Tao (3):
  drm/hisilicon: Code refactoring for hibmc_drm_drv
  drm/irq: Add the new api to install irq
  drm/hisilicon: Use the new api devm_drm_irq_install

 drivers/gpu/drm/drm_irq.c                        | 34 ++++++++++++++
 drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_de.c   |  2 +-
 drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c  | 56 ++++++++++--------------
 drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.h  |  2 +-
 drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_vdac.c |  2 +-
 drivers/gpu/drm/hisilicon/hibmc/hibmc_ttm.c      |  8 ++--
 include/drm/drm_irq.h                            |  2 +-
 7 files changed, 67 insertions(+), 39 deletions(-)

-- 
2.7.4


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

* [PATCH drm/hisilicon 1/3] drm/hisilicon: Code refactoring for hibmc_drm_drv
  2020-11-26 12:02 [PATCH drm/hisilicon 0/3] Add the new api to install irq Tian Tao
@ 2020-11-26 12:02 ` Tian Tao
  2020-11-26 13:05   ` Thomas Zimmermann
  2020-11-26 12:02 ` [PATCH drm/hisilicon 2/3] drm/irq: Add the new api to install irq Tian Tao
  2020-11-26 12:02 ` [PATCH drm/hisilicon 3/3] drm/hisilicon: Use the new api devm_drm_irq_install Tian Tao
  2 siblings, 1 reply; 12+ messages in thread
From: Tian Tao @ 2020-11-26 12:02 UTC (permalink / raw)
  To: airlied, daniel, tzimmermann, kraxel, alexander.deucher, tglx,
	dri-devel, xinliang.liu, maarten.lankhorst, mripard
  Cc: linux-kernel

Use the devm_drm_dev_alloc provided by the drm framework to alloc
a struct hibmc_drm_private.

Signed-off-by: Tian Tao <tiantao6@hisilicon.com>
---
 drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_de.c   |  2 +-
 drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c  | 51 +++++++++++-------------
 drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.h  |  2 +-
 drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_vdac.c |  2 +-
 drivers/gpu/drm/hisilicon/hibmc/hibmc_ttm.c      |  8 ++--
 5 files changed, 31 insertions(+), 34 deletions(-)

diff --git a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_de.c b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_de.c
index ea962ac..096eea9 100644
--- a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_de.c
+++ b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_de.c
@@ -499,7 +499,7 @@ static const struct drm_crtc_helper_funcs hibmc_crtc_helper_funcs = {
 
 int hibmc_de_init(struct hibmc_drm_private *priv)
 {
-	struct drm_device *dev = priv->dev;
+	struct drm_device *dev = &priv->dev;
 	struct drm_crtc *crtc = &priv->crtc;
 	struct drm_plane *plane = &priv->primary_plane;
 	int ret;
diff --git a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c
index d845657..ea3d81b 100644
--- a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c
+++ b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c
@@ -80,30 +80,31 @@ static const struct dev_pm_ops hibmc_pm_ops = {
 static int hibmc_kms_init(struct hibmc_drm_private *priv)
 {
 	int ret;
+	struct drm_device *dev = &priv->dev;
 
-	drm_mode_config_init(priv->dev);
+	drm_mode_config_init(dev);
 	priv->mode_config_initialized = true;
 
-	priv->dev->mode_config.min_width = 0;
-	priv->dev->mode_config.min_height = 0;
-	priv->dev->mode_config.max_width = 1920;
-	priv->dev->mode_config.max_height = 1200;
+	dev->mode_config.min_width = 0;
+	dev->mode_config.min_height = 0;
+	dev->mode_config.max_width = 1920;
+	dev->mode_config.max_height = 1200;
 
-	priv->dev->mode_config.fb_base = priv->fb_base;
-	priv->dev->mode_config.preferred_depth = 32;
-	priv->dev->mode_config.prefer_shadow = 1;
+	dev->mode_config.fb_base = priv->fb_base;
+	dev->mode_config.preferred_depth = 32;
+	dev->mode_config.prefer_shadow = 1;
 
-	priv->dev->mode_config.funcs = (void *)&hibmc_mode_funcs;
+	dev->mode_config.funcs = (void *)&hibmc_mode_funcs;
 
 	ret = hibmc_de_init(priv);
 	if (ret) {
-		drm_err(priv->dev, "failed to init de: %d\n", ret);
+		drm_err(dev, "failed to init de: %d\n", ret);
 		return ret;
 	}
 
 	ret = hibmc_vdac_init(priv);
 	if (ret) {
-		drm_err(priv->dev, "failed to init vdac: %d\n", ret);
+		drm_err(dev, "failed to init vdac: %d\n", ret);
 		return ret;
 	}
 
@@ -113,7 +114,7 @@ static int hibmc_kms_init(struct hibmc_drm_private *priv)
 static void hibmc_kms_fini(struct hibmc_drm_private *priv)
 {
 	if (priv->mode_config_initialized) {
-		drm_mode_config_cleanup(priv->dev);
+		drm_mode_config_cleanup(&priv->dev);
 		priv->mode_config_initialized = false;
 	}
 }
@@ -202,7 +203,7 @@ static void hibmc_hw_config(struct hibmc_drm_private *priv)
 
 static int hibmc_hw_map(struct hibmc_drm_private *priv)
 {
-	struct drm_device *dev = priv->dev;
+	struct drm_device *dev = &priv->dev;
 	struct pci_dev *pdev = dev->pdev;
 	resource_size_t addr, size, ioaddr, iosize;
 
@@ -258,17 +259,9 @@ static int hibmc_unload(struct drm_device *dev)
 
 static int hibmc_load(struct drm_device *dev)
 {
-	struct hibmc_drm_private *priv;
+	struct hibmc_drm_private *priv = dev->dev_private;
 	int ret;
 
-	priv = drmm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
-	if (!priv) {
-		drm_err(dev, "no memory to allocate for hibmc_drm_private\n");
-		return -ENOMEM;
-	}
-	dev->dev_private = priv;
-	priv->dev = dev;
-
 	ret = hibmc_hw_init(priv);
 	if (ret)
 		goto err;
@@ -310,6 +303,7 @@ static int hibmc_load(struct drm_device *dev)
 static int hibmc_pci_probe(struct pci_dev *pdev,
 			   const struct pci_device_id *ent)
 {
+	struct hibmc_drm_private *priv;
 	struct drm_device *dev;
 	int ret;
 
@@ -318,19 +312,22 @@ static int hibmc_pci_probe(struct pci_dev *pdev,
 	if (ret)
 		return ret;
 
-	dev = drm_dev_alloc(&hibmc_driver, &pdev->dev);
-	if (IS_ERR(dev)) {
+	priv = devm_drm_dev_alloc(&pdev->dev, &hibmc_driver,
+				  struct hibmc_drm_private, dev);
+	if (IS_ERR(priv)) {
 		DRM_ERROR("failed to allocate drm_device\n");
-		return PTR_ERR(dev);
+		return PTR_ERR(priv);
 	}
 
+	dev = &priv->dev;
+	dev->dev_private = priv;
 	dev->pdev = pdev;
 	pci_set_drvdata(pdev, dev);
 
 	ret = pci_enable_device(pdev);
 	if (ret) {
 		drm_err(dev, "failed to enable pci device: %d\n", ret);
-		goto err_free;
+		return ret;
 	}
 
 	ret = hibmc_load(dev);
@@ -354,8 +351,6 @@ static int hibmc_pci_probe(struct pci_dev *pdev,
 	hibmc_unload(dev);
 err_disable:
 	pci_disable_device(pdev);
-err_free:
-	drm_dev_put(dev);
 
 	return ret;
 }
diff --git a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.h b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.h
index f310a83..e35353a 100644
--- a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.h
+++ b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.h
@@ -37,7 +37,7 @@ struct hibmc_drm_private {
 	resource_size_t  fb_size;
 
 	/* drm */
-	struct drm_device  *dev;
+	struct drm_device dev;
 	struct drm_plane primary_plane;
 	struct drm_crtc crtc;
 	struct drm_encoder encoder;
diff --git a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_vdac.c b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_vdac.c
index 74e26c2..d35548d 100644
--- a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_vdac.c
+++ b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_vdac.c
@@ -96,7 +96,7 @@ static const struct drm_encoder_funcs hibmc_encoder_funcs = {
 
 int hibmc_vdac_init(struct hibmc_drm_private *priv)
 {
-	struct drm_device *dev = priv->dev;
+	struct drm_device *dev = &priv->dev;
 	struct hibmc_connector *hibmc_connector = &priv->connector;
 	struct drm_encoder *encoder = &priv->encoder;
 	struct drm_connector *connector = &hibmc_connector->base;
diff --git a/drivers/gpu/drm/hisilicon/hibmc/hibmc_ttm.c b/drivers/gpu/drm/hisilicon/hibmc/hibmc_ttm.c
index 602ece1..e84fb81 100644
--- a/drivers/gpu/drm/hisilicon/hibmc/hibmc_ttm.c
+++ b/drivers/gpu/drm/hisilicon/hibmc/hibmc_ttm.c
@@ -25,7 +25,7 @@ int hibmc_mm_init(struct hibmc_drm_private *hibmc)
 {
 	struct drm_vram_mm *vmm;
 	int ret;
-	struct drm_device *dev = hibmc->dev;
+	struct drm_device *dev = &hibmc->dev;
 
 	vmm = drm_vram_helper_alloc_mm(dev,
 				       pci_resource_start(dev->pdev, 0),
@@ -41,10 +41,12 @@ int hibmc_mm_init(struct hibmc_drm_private *hibmc)
 
 void hibmc_mm_fini(struct hibmc_drm_private *hibmc)
 {
-	if (!hibmc->dev->vram_mm)
+	struct drm_device *dev = &hibmc->dev;
+
+	if (!dev->vram_mm)
 		return;
 
-	drm_vram_helper_release_mm(hibmc->dev);
+	drm_vram_helper_release_mm(dev);
 }
 
 int hibmc_dumb_create(struct drm_file *file, struct drm_device *dev,
-- 
2.7.4


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

* [PATCH drm/hisilicon 2/3] drm/irq: Add the new api to install irq
  2020-11-26 12:02 [PATCH drm/hisilicon 0/3] Add the new api to install irq Tian Tao
  2020-11-26 12:02 ` [PATCH drm/hisilicon 1/3] drm/hisilicon: Code refactoring for hibmc_drm_drv Tian Tao
@ 2020-11-26 12:02 ` Tian Tao
  2020-11-26 13:12   ` Thomas Zimmermann
  2020-11-26 12:02 ` [PATCH drm/hisilicon 3/3] drm/hisilicon: Use the new api devm_drm_irq_install Tian Tao
  2 siblings, 1 reply; 12+ messages in thread
From: Tian Tao @ 2020-11-26 12:02 UTC (permalink / raw)
  To: airlied, daniel, tzimmermann, kraxel, alexander.deucher, tglx,
	dri-devel, xinliang.liu, maarten.lankhorst, mripard
  Cc: linux-kernel

Add new api devm_drm_irq_install() to register interrupts,
no need to call drm_irq_uninstall() when the drm module is removed.

Signed-off-by: Tian Tao <tiantao6@hisilicon.com>
---
 drivers/gpu/drm/drm_irq.c | 34 ++++++++++++++++++++++++++++++++++
 include/drm/drm_irq.h     |  2 +-
 2 files changed, 35 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/drm_irq.c b/drivers/gpu/drm/drm_irq.c
index 09d6e9e..983ad6b 100644
--- a/drivers/gpu/drm/drm_irq.c
+++ b/drivers/gpu/drm/drm_irq.c
@@ -214,6 +214,40 @@ int drm_irq_uninstall(struct drm_device *dev)
 }
 EXPORT_SYMBOL(drm_irq_uninstall);
 
+static void devm_drm_irq_uninstall(void *data)
+{
+	drm_irq_uninstall(data);
+}
+
+/**
+ * devm_drm_irq_install - install IRQ handler
+ * @dev: DRM device
+ * @irq: IRQ number to install the handler for
+ *
+ * devm_drm_irq_install is the help function of drm_irq_install,
+ * when the driver uses devm_drm_irq_install, there is no need
+ * to call drm_irq_uninstall when the drm module is uninstalled,
+ * and this will done automagically.
+ *
+ * Returns:
+ * Zero on success or a negative error code on failure.
+ */
+int devm_drm_irq_install(struct drm_device *dev, int irq)
+{
+	int ret;
+
+	ret = drm_irq_install(dev, irq);
+	if (ret)
+		return ret;
+
+	ret = devm_add_action(dev->dev, devm_drm_irq_uninstall, dev);
+	if (ret)
+		devm_drm_irq_uninstall(dev);
+
+	return ret;
+}
+EXPORT_SYMBOL(devm_drm_irq_install);
+
 #if IS_ENABLED(CONFIG_DRM_LEGACY)
 int drm_legacy_irq_control(struct drm_device *dev, void *data,
 			   struct drm_file *file_priv)
diff --git a/include/drm/drm_irq.h b/include/drm/drm_irq.h
index d77f6e6..631b22f 100644
--- a/include/drm/drm_irq.h
+++ b/include/drm/drm_irq.h
@@ -28,5 +28,5 @@ struct drm_device;
 
 int drm_irq_install(struct drm_device *dev, int irq);
 int drm_irq_uninstall(struct drm_device *dev);
-
+int devm_drm_irq_install(struct drm_device *dev, int irq);
 #endif
-- 
2.7.4


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

* [PATCH drm/hisilicon 3/3] drm/hisilicon: Use the new api devm_drm_irq_install
  2020-11-26 12:02 [PATCH drm/hisilicon 0/3] Add the new api to install irq Tian Tao
  2020-11-26 12:02 ` [PATCH drm/hisilicon 1/3] drm/hisilicon: Code refactoring for hibmc_drm_drv Tian Tao
  2020-11-26 12:02 ` [PATCH drm/hisilicon 2/3] drm/irq: Add the new api to install irq Tian Tao
@ 2020-11-26 12:02 ` Tian Tao
  2020-11-26 13:15   ` Thomas Zimmermann
  2 siblings, 1 reply; 12+ messages in thread
From: Tian Tao @ 2020-11-26 12:02 UTC (permalink / raw)
  To: airlied, daniel, tzimmermann, kraxel, alexander.deucher, tglx,
	dri-devel, xinliang.liu, maarten.lankhorst, mripard
  Cc: linux-kernel

Use devm_drm_irq_install to register interrupts so that
drm_irq_uninstall is not called when hibmc is removed.

Signed-off-by: Tian Tao <tiantao6@hisilicon.com>
---
 drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c
index ea3d81b..77792e3 100644
--- a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c
+++ b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c
@@ -247,9 +247,6 @@ static int hibmc_unload(struct drm_device *dev)
 
 	drm_atomic_helper_shutdown(dev);
 
-	if (dev->irq_enabled)
-		drm_irq_uninstall(dev);
-
 	pci_disable_msi(dev->pdev);
 	hibmc_kms_fini(priv);
 	hibmc_mm_fini(priv);
@@ -284,7 +281,7 @@ static int hibmc_load(struct drm_device *dev)
 	if (ret) {
 		drm_warn(dev, "enabling MSI failed: %d\n", ret);
 	} else {
-		ret = drm_irq_install(dev, dev->pdev->irq);
+		ret = devm_drm_irq_install(dev, dev->pdev->irq);
 		if (ret)
 			drm_warn(dev, "install irq failed: %d\n", ret);
 	}
-- 
2.7.4


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

* Re: [PATCH drm/hisilicon 1/3] drm/hisilicon: Code refactoring for hibmc_drm_drv
  2020-11-26 12:02 ` [PATCH drm/hisilicon 1/3] drm/hisilicon: Code refactoring for hibmc_drm_drv Tian Tao
@ 2020-11-26 13:05   ` Thomas Zimmermann
  2020-11-26 13:13     ` Thomas Zimmermann
  0 siblings, 1 reply; 12+ messages in thread
From: Thomas Zimmermann @ 2020-11-26 13:05 UTC (permalink / raw)
  To: Tian Tao, airlied, daniel, kraxel, alexander.deucher, tglx,
	dri-devel, xinliang.liu, maarten.lankhorst, mripard
  Cc: linux-kernel


[-- Attachment #1.1.1: Type: text/plain, Size: 8422 bytes --]

Hi

Am 26.11.20 um 13:02 schrieb Tian Tao:
> Use the devm_drm_dev_alloc provided by the drm framework to alloc
> a struct hibmc_drm_private.
> 
> Signed-off-by: Tian Tao <tiantao6@hisilicon.com>
> ---
>   drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_de.c   |  2 +-
>   drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c  | 51 +++++++++++-------------
>   drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.h  |  2 +-
>   drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_vdac.c |  2 +-
>   drivers/gpu/drm/hisilicon/hibmc/hibmc_ttm.c      |  8 ++--
>   5 files changed, 31 insertions(+), 34 deletions(-)
> 
> diff --git a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_de.c b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_de.c
> index ea962ac..096eea9 100644
> --- a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_de.c
> +++ b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_de.c
> @@ -499,7 +499,7 @@ static const struct drm_crtc_helper_funcs hibmc_crtc_helper_funcs = {
>   
>   int hibmc_de_init(struct hibmc_drm_private *priv)
>   {
> -	struct drm_device *dev = priv->dev;
> +	struct drm_device *dev = &priv->dev;
>   	struct drm_crtc *crtc = &priv->crtc;
>   	struct drm_plane *plane = &priv->primary_plane;
>   	int ret;
> diff --git a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c
> index d845657..ea3d81b 100644
> --- a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c
> +++ b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c
> @@ -80,30 +80,31 @@ static const struct dev_pm_ops hibmc_pm_ops = {
>   static int hibmc_kms_init(struct hibmc_drm_private *priv)
>   {
>   	int ret;
> +	struct drm_device *dev = &priv->dev;

I think that's good style. Pointers deserve their own local variable if 
they are used multiple times within a function. I would move this change 
into a separate patch, because it's only semi-related to the actual changes.

>   
> -	drm_mode_config_init(priv->dev);
> +	drm_mode_config_init(dev);
>   	priv->mode_config_initialized = true;
>   
> -	priv->dev->mode_config.min_width = 0;
> -	priv->dev->mode_config.min_height = 0;
> -	priv->dev->mode_config.max_width = 1920;
> -	priv->dev->mode_config.max_height = 1200;
> +	dev->mode_config.min_width = 0;
> +	dev->mode_config.min_height = 0;
> +	dev->mode_config.max_width = 1920;
> +	dev->mode_config.max_height = 1200;
>   
> -	priv->dev->mode_config.fb_base = priv->fb_base;
> -	priv->dev->mode_config.preferred_depth = 32;
> -	priv->dev->mode_config.prefer_shadow = 1;
> +	dev->mode_config.fb_base = priv->fb_base;
> +	dev->mode_config.preferred_depth = 32;
> +	dev->mode_config.prefer_shadow = 1;
>   
> -	priv->dev->mode_config.funcs = (void *)&hibmc_mode_funcs;
> +	dev->mode_config.funcs = (void *)&hibmc_mode_funcs;
>   
>   	ret = hibmc_de_init(priv);
>   	if (ret) {
> -		drm_err(priv->dev, "failed to init de: %d\n", ret);
> +		drm_err(dev, "failed to init de: %d\n", ret);
>   		return ret;
>   	}
>   
>   	ret = hibmc_vdac_init(priv);
>   	if (ret) {
> -		drm_err(priv->dev, "failed to init vdac: %d\n", ret);
> +		drm_err(dev, "failed to init vdac: %d\n", ret);
>   		return ret;
>   	}
>   
> @@ -113,7 +114,7 @@ static int hibmc_kms_init(struct hibmc_drm_private *priv)
>   static void hibmc_kms_fini(struct hibmc_drm_private *priv)
>   {
>   	if (priv->mode_config_initialized) {
> -		drm_mode_config_cleanup(priv->dev);
> +		drm_mode_config_cleanup(&priv->dev);
>   		priv->mode_config_initialized = false;
>   	}
>   }
> @@ -202,7 +203,7 @@ static void hibmc_hw_config(struct hibmc_drm_private *priv)
>   
>   static int hibmc_hw_map(struct hibmc_drm_private *priv)
>   {
> -	struct drm_device *dev = priv->dev;
> +	struct drm_device *dev = &priv->dev;
>   	struct pci_dev *pdev = dev->pdev;
>   	resource_size_t addr, size, ioaddr, iosize;
>   
> @@ -258,17 +259,9 @@ static int hibmc_unload(struct drm_device *dev)
>   
>   static int hibmc_load(struct drm_device *dev)
>   {
> -	struct hibmc_drm_private *priv;
> +	struct hibmc_drm_private *priv = dev->dev_private;

Please use to_hibmc_drm_private() instead. dev_private is deprecated.

>   	int ret;
>   
> -	priv = drmm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
> -	if (!priv) {
> -		drm_err(dev, "no memory to allocate for hibmc_drm_private\n");
> -		return -ENOMEM;
> -	}
> -	dev->dev_private = priv;
> -	priv->dev = dev;
> -
>   	ret = hibmc_hw_init(priv);
>   	if (ret)
>   		goto err;
> @@ -310,6 +303,7 @@ static int hibmc_load(struct drm_device *dev)
>   static int hibmc_pci_probe(struct pci_dev *pdev,
>   			   const struct pci_device_id *ent)
>   {
> +	struct hibmc_drm_private *priv;
>   	struct drm_device *dev;
>   	int ret;
>   
> @@ -318,19 +312,22 @@ static int hibmc_pci_probe(struct pci_dev *pdev,
>   	if (ret)
>   		return ret;
>   
> -	dev = drm_dev_alloc(&hibmc_driver, &pdev->dev);
> -	if (IS_ERR(dev)) {
> +	priv = devm_drm_dev_alloc(&pdev->dev, &hibmc_driver,
> +				  struct hibmc_drm_private, dev);
> +	if (IS_ERR(priv)) {
>   		DRM_ERROR("failed to allocate drm_device\n");
> -		return PTR_ERR(dev);
> +		return PTR_ERR(priv);
>   	}
>   
> +	dev = &priv->dev;
> +	dev->dev_private = priv;

Don't do this assignment. After this patch, no code in hibmc should 
touch dev_private. Instead, change to_hibmc_drm_private() to upcast from 
dev. As in [1].

>   	dev->pdev = pdev;
>   	pci_set_drvdata(pdev, dev);
>   
>   	ret = pci_enable_device(pdev);
>   	if (ret) {
>   		drm_err(dev, "failed to enable pci device: %d\n", ret);
> -		goto err_free;
> +		return ret;
>   	}
>   
>   	ret = hibmc_load(dev);
> @@ -354,8 +351,6 @@ static int hibmc_pci_probe(struct pci_dev *pdev,
>   	hibmc_unload(dev);
>   err_disable:
>   	pci_disable_device(pdev);
> -err_free:
> -	drm_dev_put(dev);
>   
>   	return ret;
>   }
> diff --git a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.h b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.h
> index f310a83..e35353a 100644
> --- a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.h
> +++ b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.h
> @@ -37,7 +37,7 @@ struct hibmc_drm_private {
>   	resource_size_t  fb_size;
>   
>   	/* drm */
> -	struct drm_device  *dev;
> +	struct drm_device dev;
>   	struct drm_plane primary_plane;
>   	struct drm_crtc crtc;
>   	struct drm_encoder encoder;
> diff --git a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_vdac.c b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_vdac.c
> index 74e26c2..d35548d 100644
> --- a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_vdac.c
> +++ b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_vdac.c
> @@ -96,7 +96,7 @@ static const struct drm_encoder_funcs hibmc_encoder_funcs = {
>   
>   int hibmc_vdac_init(struct hibmc_drm_private *priv)
>   {
> -	struct drm_device *dev = priv->dev;
> +	struct drm_device *dev = &priv->dev;
>   	struct hibmc_connector *hibmc_connector = &priv->connector;
>   	struct drm_encoder *encoder = &priv->encoder;
>   	struct drm_connector *connector = &hibmc_connector->base;
> diff --git a/drivers/gpu/drm/hisilicon/hibmc/hibmc_ttm.c b/drivers/gpu/drm/hisilicon/hibmc/hibmc_ttm.c
> index 602ece1..e84fb81 100644
> --- a/drivers/gpu/drm/hisilicon/hibmc/hibmc_ttm.c
> +++ b/drivers/gpu/drm/hisilicon/hibmc/hibmc_ttm.c
> @@ -25,7 +25,7 @@ int hibmc_mm_init(struct hibmc_drm_private *hibmc)
>   {
>   	struct drm_vram_mm *vmm;
>   	int ret;
> -	struct drm_device *dev = hibmc->dev;
> +	struct drm_device *dev = &hibmc->dev;
>   
>   	vmm = drm_vram_helper_alloc_mm(dev,
>   				       pci_resource_start(dev->pdev, 0),
> @@ -41,10 +41,12 @@ int hibmc_mm_init(struct hibmc_drm_private *hibmc)
>   
>   void hibmc_mm_fini(struct hibmc_drm_private *hibmc)
>   {
> -	if (!hibmc->dev->vram_mm)
> +	struct drm_device *dev = &hibmc->dev;
> +
> +	if (!dev->vram_mm)
>   		return;
>   
> -	drm_vram_helper_release_mm(hibmc->dev);
> +	drm_vram_helper_release_mm(dev);

That's OK for now. A good follow-up patchset is the conversion to 
managed DRM helpers. We have these for modesetting, vram helpers and others.

>   }
>   
>   int hibmc_dumb_create(struct drm_file *file, struct drm_device *dev,
> 

-- 
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Maxfeldstr. 5, 90409 Nürnberg, Germany
(HRB 36809, AG Nürnberg)
Geschäftsführer: Felix Imendörffer

[-- Attachment #1.1.2: OpenPGP_0x680DC11D530B7A23.asc --]
[-- Type: application/pgp-keys, Size: 8003 bytes --]

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 840 bytes --]

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

* Re: [PATCH drm/hisilicon 2/3] drm/irq: Add the new api to install irq
  2020-11-26 12:02 ` [PATCH drm/hisilicon 2/3] drm/irq: Add the new api to install irq Tian Tao
@ 2020-11-26 13:12   ` Thomas Zimmermann
  0 siblings, 0 replies; 12+ messages in thread
From: Thomas Zimmermann @ 2020-11-26 13:12 UTC (permalink / raw)
  To: Tian Tao, airlied, daniel, kraxel, alexander.deucher, tglx,
	dri-devel, xinliang.liu, maarten.lankhorst, mripard
  Cc: linux-kernel


[-- Attachment #1.1.1: Type: text/plain, Size: 2709 bytes --]

Hi

Am 26.11.20 um 13:02 schrieb Tian Tao:
> Add new api devm_drm_irq_install() to register interrupts,
> no need to call drm_irq_uninstall() when the drm module is removed.
> 
> Signed-off-by: Tian Tao <tiantao6@hisilicon.com>
> ---
>   drivers/gpu/drm/drm_irq.c | 34 ++++++++++++++++++++++++++++++++++
>   include/drm/drm_irq.h     |  2 +-
>   2 files changed, 35 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/gpu/drm/drm_irq.c b/drivers/gpu/drm/drm_irq.c
> index 09d6e9e..983ad6b 100644
> --- a/drivers/gpu/drm/drm_irq.c
> +++ b/drivers/gpu/drm/drm_irq.c
> @@ -214,6 +214,40 @@ int drm_irq_uninstall(struct drm_device *dev)
>   }
>   EXPORT_SYMBOL(drm_irq_uninstall);
>   
> +static void devm_drm_irq_uninstall(void *data)
> +{
> +	drm_irq_uninstall(data);
> +}
> +
> +/**
> + * devm_drm_irq_install - install IRQ handler
> + * @dev: DRM device
> + * @irq: IRQ number to install the handler for
> + *
> + * devm_drm_irq_install is the help function of drm_irq_install,

'the help' -> 'a helper'. I'd do a full stop with period at the end of 
the line.

> + * when the driver uses devm_drm_irq_install, there is no need

when -> If

> + * to call drm_irq_uninstall when the drm module is uninstalled,

'is uninstalled' -> 'gets unloaded'

> + * and this will done automagically.

and -> as

> + *
> + * Returns:
> + * Zero on success or a negative error code on failure.
> + */
> +int devm_drm_irq_install(struct drm_device *dev, int irq)
> +{
> +	int ret;
> +
> +	ret = drm_irq_install(dev, irq);
> +	if (ret)
> +		return ret;
> +
> +	ret = devm_add_action(dev->dev, devm_drm_irq_uninstall, dev);
> +	if (ret)
> +		devm_drm_irq_uninstall(dev);

This pattern can be replaced by devm_add_action_or_reset()

With my comments addressed,

Reviewed-by: Thomas Zimmermann <tzimmermann@suse.de>

Best regards
Thomas

> +
> +	return ret;
> +}
> +EXPORT_SYMBOL(devm_drm_irq_install);
> +
>   #if IS_ENABLED(CONFIG_DRM_LEGACY)
>   int drm_legacy_irq_control(struct drm_device *dev, void *data,
>   			   struct drm_file *file_priv)
> diff --git a/include/drm/drm_irq.h b/include/drm/drm_irq.h
> index d77f6e6..631b22f 100644
> --- a/include/drm/drm_irq.h
> +++ b/include/drm/drm_irq.h
> @@ -28,5 +28,5 @@ struct drm_device;
>   
>   int drm_irq_install(struct drm_device *dev, int irq);
>   int drm_irq_uninstall(struct drm_device *dev);
> -
> +int devm_drm_irq_install(struct drm_device *dev, int irq);
>   #endif
> 

-- 
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Maxfeldstr. 5, 90409 Nürnberg, Germany
(HRB 36809, AG Nürnberg)
Geschäftsführer: Felix Imendörffer

[-- Attachment #1.1.2: OpenPGP_0x680DC11D530B7A23.asc --]
[-- Type: application/pgp-keys, Size: 8003 bytes --]

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 840 bytes --]

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

* Re: [PATCH drm/hisilicon 1/3] drm/hisilicon: Code refactoring for hibmc_drm_drv
  2020-11-26 13:05   ` Thomas Zimmermann
@ 2020-11-26 13:13     ` Thomas Zimmermann
  0 siblings, 0 replies; 12+ messages in thread
From: Thomas Zimmermann @ 2020-11-26 13:13 UTC (permalink / raw)
  To: Tian Tao, airlied, daniel, kraxel, alexander.deucher, tglx,
	dri-devel, xinliang.liu, maarten.lankhorst, mripard
  Cc: linux-kernel


[-- Attachment #1.1.1: Type: text/plain, Size: 9984 bytes --]

Hi

Am 26.11.20 um 14:05 schrieb Thomas Zimmermann:
> Hi
> 
> Am 26.11.20 um 13:02 schrieb Tian Tao:
>> Use the devm_drm_dev_alloc provided by the drm framework to alloc
>> a struct hibmc_drm_private.
>>
>> Signed-off-by: Tian Tao <tiantao6@hisilicon.com>
>> ---
>>   drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_de.c   |  2 +-
>>   drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c  | 51 
>> +++++++++++-------------
>>   drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.h  |  2 +-
>>   drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_vdac.c |  2 +-
>>   drivers/gpu/drm/hisilicon/hibmc/hibmc_ttm.c      |  8 ++--
>>   5 files changed, 31 insertions(+), 34 deletions(-)
>>
>> diff --git a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_de.c 
>> b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_de.c
>> index ea962ac..096eea9 100644
>> --- a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_de.c
>> +++ b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_de.c
>> @@ -499,7 +499,7 @@ static const struct drm_crtc_helper_funcs 
>> hibmc_crtc_helper_funcs = {
>>   int hibmc_de_init(struct hibmc_drm_private *priv)
>>   {
>> -    struct drm_device *dev = priv->dev;
>> +    struct drm_device *dev = &priv->dev;
>>       struct drm_crtc *crtc = &priv->crtc;
>>       struct drm_plane *plane = &priv->primary_plane;
>>       int ret;
>> diff --git a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c 
>> b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c
>> index d845657..ea3d81b 100644
>> --- a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c
>> +++ b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c
>> @@ -80,30 +80,31 @@ static const struct dev_pm_ops hibmc_pm_ops = {
>>   static int hibmc_kms_init(struct hibmc_drm_private *priv)
>>   {
>>       int ret;
>> +    struct drm_device *dev = &priv->dev;
> 
> I think that's good style. Pointers deserve their own local variable if 
> they are used multiple times within a function. I would move this change 
> into a separate patch, because it's only semi-related to the actual 
> changes.
> 
>> -    drm_mode_config_init(priv->dev);
>> +    drm_mode_config_init(dev);
>>       priv->mode_config_initialized = true;
>> -    priv->dev->mode_config.min_width = 0;
>> -    priv->dev->mode_config.min_height = 0;
>> -    priv->dev->mode_config.max_width = 1920;
>> -    priv->dev->mode_config.max_height = 1200;
>> +    dev->mode_config.min_width = 0;
>> +    dev->mode_config.min_height = 0;
>> +    dev->mode_config.max_width = 1920;
>> +    dev->mode_config.max_height = 1200;
>> -    priv->dev->mode_config.fb_base = priv->fb_base;
>> -    priv->dev->mode_config.preferred_depth = 32;
>> -    priv->dev->mode_config.prefer_shadow = 1;
>> +    dev->mode_config.fb_base = priv->fb_base;
>> +    dev->mode_config.preferred_depth = 32;
>> +    dev->mode_config.prefer_shadow = 1;
>> -    priv->dev->mode_config.funcs = (void *)&hibmc_mode_funcs;
>> +    dev->mode_config.funcs = (void *)&hibmc_mode_funcs;
>>       ret = hibmc_de_init(priv);
>>       if (ret) {
>> -        drm_err(priv->dev, "failed to init de: %d\n", ret);
>> +        drm_err(dev, "failed to init de: %d\n", ret);
>>           return ret;
>>       }
>>       ret = hibmc_vdac_init(priv);
>>       if (ret) {
>> -        drm_err(priv->dev, "failed to init vdac: %d\n", ret);
>> +        drm_err(dev, "failed to init vdac: %d\n", ret);
>>           return ret;
>>       }
>> @@ -113,7 +114,7 @@ static int hibmc_kms_init(struct hibmc_drm_private 
>> *priv)
>>   static void hibmc_kms_fini(struct hibmc_drm_private *priv)
>>   {
>>       if (priv->mode_config_initialized) {
>> -        drm_mode_config_cleanup(priv->dev);
>> +        drm_mode_config_cleanup(&priv->dev);
>>           priv->mode_config_initialized = false;
>>       }
>>   }
>> @@ -202,7 +203,7 @@ static void hibmc_hw_config(struct 
>> hibmc_drm_private *priv)
>>   static int hibmc_hw_map(struct hibmc_drm_private *priv)
>>   {
>> -    struct drm_device *dev = priv->dev;
>> +    struct drm_device *dev = &priv->dev;
>>       struct pci_dev *pdev = dev->pdev;
>>       resource_size_t addr, size, ioaddr, iosize;
>> @@ -258,17 +259,9 @@ static int hibmc_unload(struct drm_device *dev)
>>   static int hibmc_load(struct drm_device *dev)
>>   {
>> -    struct hibmc_drm_private *priv;
>> +    struct hibmc_drm_private *priv = dev->dev_private;
> 
> Please use to_hibmc_drm_private() instead. dev_private is deprecated.
> 
>>       int ret;
>> -    priv = drmm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
>> -    if (!priv) {
>> -        drm_err(dev, "no memory to allocate for hibmc_drm_private\n");
>> -        return -ENOMEM;
>> -    }
>> -    dev->dev_private = priv;
>> -    priv->dev = dev;
>> -
>>       ret = hibmc_hw_init(priv);
>>       if (ret)
>>           goto err;
>> @@ -310,6 +303,7 @@ static int hibmc_load(struct drm_device *dev)
>>   static int hibmc_pci_probe(struct pci_dev *pdev,
>>                  const struct pci_device_id *ent)
>>   {
>> +    struct hibmc_drm_private *priv;
>>       struct drm_device *dev;
>>       int ret;
>> @@ -318,19 +312,22 @@ static int hibmc_pci_probe(struct pci_dev *pdev,
>>       if (ret)
>>           return ret;
>> -    dev = drm_dev_alloc(&hibmc_driver, &pdev->dev);
>> -    if (IS_ERR(dev)) {
>> +    priv = devm_drm_dev_alloc(&pdev->dev, &hibmc_driver,
>> +                  struct hibmc_drm_private, dev);
>> +    if (IS_ERR(priv)) {
>>           DRM_ERROR("failed to allocate drm_device\n");
>> -        return PTR_ERR(dev);
>> +        return PTR_ERR(priv);
>>       }
>> +    dev = &priv->dev;
>> +    dev->dev_private = priv;
> 
> Don't do this assignment. After this patch, no code in hibmc should 
> touch dev_private. Instead, change to_hibmc_drm_private() to upcast from 
> dev. As in [1].

[1] was supposed to be

 
https://elixir.bootlin.com/linux/v5.9.11/source/drivers/gpu/drm/mgag200/mgag200_drv.h#L177

Best regards
Thomas

> 
>>       dev->pdev = pdev;
>>       pci_set_drvdata(pdev, dev);
>>       ret = pci_enable_device(pdev);
>>       if (ret) {
>>           drm_err(dev, "failed to enable pci device: %d\n", ret);
>> -        goto err_free;
>> +        return ret;
>>       }
>>       ret = hibmc_load(dev);
>> @@ -354,8 +351,6 @@ static int hibmc_pci_probe(struct pci_dev *pdev,
>>       hibmc_unload(dev);
>>   err_disable:
>>       pci_disable_device(pdev);
>> -err_free:
>> -    drm_dev_put(dev);
>>       return ret;
>>   }
>> diff --git a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.h 
>> b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.h
>> index f310a83..e35353a 100644
>> --- a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.h
>> +++ b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.h
>> @@ -37,7 +37,7 @@ struct hibmc_drm_private {
>>       resource_size_t  fb_size;
>>       /* drm */
>> -    struct drm_device  *dev;
>> +    struct drm_device dev;
>>       struct drm_plane primary_plane;
>>       struct drm_crtc crtc;
>>       struct drm_encoder encoder;
>> diff --git a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_vdac.c 
>> b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_vdac.c
>> index 74e26c2..d35548d 100644
>> --- a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_vdac.c
>> +++ b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_vdac.c
>> @@ -96,7 +96,7 @@ static const struct drm_encoder_funcs 
>> hibmc_encoder_funcs = {
>>   int hibmc_vdac_init(struct hibmc_drm_private *priv)
>>   {
>> -    struct drm_device *dev = priv->dev;
>> +    struct drm_device *dev = &priv->dev;
>>       struct hibmc_connector *hibmc_connector = &priv->connector;
>>       struct drm_encoder *encoder = &priv->encoder;
>>       struct drm_connector *connector = &hibmc_connector->base;
>> diff --git a/drivers/gpu/drm/hisilicon/hibmc/hibmc_ttm.c 
>> b/drivers/gpu/drm/hisilicon/hibmc/hibmc_ttm.c
>> index 602ece1..e84fb81 100644
>> --- a/drivers/gpu/drm/hisilicon/hibmc/hibmc_ttm.c
>> +++ b/drivers/gpu/drm/hisilicon/hibmc/hibmc_ttm.c
>> @@ -25,7 +25,7 @@ int hibmc_mm_init(struct hibmc_drm_private *hibmc)
>>   {
>>       struct drm_vram_mm *vmm;
>>       int ret;
>> -    struct drm_device *dev = hibmc->dev;
>> +    struct drm_device *dev = &hibmc->dev;
>>       vmm = drm_vram_helper_alloc_mm(dev,
>>                          pci_resource_start(dev->pdev, 0),
>> @@ -41,10 +41,12 @@ int hibmc_mm_init(struct hibmc_drm_private *hibmc)
>>   void hibmc_mm_fini(struct hibmc_drm_private *hibmc)
>>   {
>> -    if (!hibmc->dev->vram_mm)
>> +    struct drm_device *dev = &hibmc->dev;
>> +
>> +    if (!dev->vram_mm)
>>           return;
>> -    drm_vram_helper_release_mm(hibmc->dev);
>> +    drm_vram_helper_release_mm(dev);
> 
> That's OK for now. A good follow-up patchset is the conversion to 
> managed DRM helpers. We have these for modesetting, vram helpers and 
> others.
> 
>>   }
>>   int hibmc_dumb_create(struct drm_file *file, struct drm_device *dev,
>>
> 
> 
> _______________________________________________
> dri-devel mailing list
> dri-devel@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/dri-devel
> 

-- 
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Maxfeldstr. 5, 90409 Nürnberg, Germany
(HRB 36809, AG Nürnberg)
Geschäftsführer: Felix Imendörffer

[-- Attachment #1.1.2: OpenPGP_0x680DC11D530B7A23.asc --]
[-- Type: application/pgp-keys, Size: 8003 bytes --]

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 840 bytes --]

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

* Re: [PATCH drm/hisilicon 3/3] drm/hisilicon: Use the new api devm_drm_irq_install
  2020-11-26 12:02 ` [PATCH drm/hisilicon 3/3] drm/hisilicon: Use the new api devm_drm_irq_install Tian Tao
@ 2020-11-26 13:15   ` Thomas Zimmermann
  0 siblings, 0 replies; 12+ messages in thread
From: Thomas Zimmermann @ 2020-11-26 13:15 UTC (permalink / raw)
  To: Tian Tao, airlied, daniel, kraxel, alexander.deucher, tglx,
	dri-devel, xinliang.liu, maarten.lankhorst, mripard
  Cc: linux-kernel


[-- Attachment #1.1.1: Type: text/plain, Size: 1492 bytes --]

Hi

Am 26.11.20 um 13:02 schrieb Tian Tao:
> Use devm_drm_irq_install to register interrupts so that
> drm_irq_uninstall is not called when hibmc is removed.
> 
> Signed-off-by: Tian Tao <tiantao6@hisilicon.com>

Reviewed-by: Thomas Zimmermann <tzimmermann@suse.de>

Thanks!

> ---
>   drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c | 5 +----
>   1 file changed, 1 insertion(+), 4 deletions(-)
> 
> diff --git a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c
> index ea3d81b..77792e3 100644
> --- a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c
> +++ b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c
> @@ -247,9 +247,6 @@ static int hibmc_unload(struct drm_device *dev)
>   
>   	drm_atomic_helper_shutdown(dev);
>   
> -	if (dev->irq_enabled)
> -		drm_irq_uninstall(dev);
> -
>   	pci_disable_msi(dev->pdev);
>   	hibmc_kms_fini(priv);
>   	hibmc_mm_fini(priv);
> @@ -284,7 +281,7 @@ static int hibmc_load(struct drm_device *dev)
>   	if (ret) {
>   		drm_warn(dev, "enabling MSI failed: %d\n", ret);
>   	} else {
> -		ret = drm_irq_install(dev, dev->pdev->irq);
> +		ret = devm_drm_irq_install(dev, dev->pdev->irq);
>   		if (ret)
>   			drm_warn(dev, "install irq failed: %d\n", ret);
>   	}
> 

-- 
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Maxfeldstr. 5, 90409 Nürnberg, Germany
(HRB 36809, AG Nürnberg)
Geschäftsführer: Felix Imendörffer

[-- Attachment #1.1.2: OpenPGP_0x680DC11D530B7A23.asc --]
[-- Type: application/pgp-keys, Size: 8003 bytes --]

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 840 bytes --]

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

* Re: [PATCH drm/hisilicon 2/3] drm/irq: Add the new api to install irq
  2020-12-03 20:07   ` Sam Ravnborg
@ 2020-12-03 21:33     ` Sam Ravnborg
  0 siblings, 0 replies; 12+ messages in thread
From: Sam Ravnborg @ 2020-12-03 21:33 UTC (permalink / raw)
  To: Tian Tao
  Cc: airlied, linux-kernel, dri-devel, xinliang.liu, kraxel,
	tzimmermann, alexander.deucher, tglx

Hi Tian,

> > +	ret = devm_add_action_or_reset(dev->dev, devm_drm_irq_uninstall, dev);
> > +	if (ret)
> > +		devm_drm_irq_uninstall(dev);
> devm_add_action_or_reset() will call devm_drm_irq_uninstall() if ret is
> != 0. See include/device.h.
> 
> I guess that is the "_or_reset" part of the name that can tell us that.
> So you can drop the if condition as it just will cause the code to call
> drm_irq_uninstall() twice.

Noticed this was fixed in v2 - so all is fine here.

	Sam

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

* Re: [PATCH drm/hisilicon 2/3] drm/irq: Add the new api to install irq
  2020-12-02  8:47 ` [PATCH drm/hisilicon 2/3] drm/irq: " Tian Tao
  2020-12-02  8:59   ` Thomas Zimmermann
@ 2020-12-03 20:07   ` Sam Ravnborg
  2020-12-03 21:33     ` Sam Ravnborg
  1 sibling, 1 reply; 12+ messages in thread
From: Sam Ravnborg @ 2020-12-03 20:07 UTC (permalink / raw)
  To: Tian Tao
  Cc: airlied, daniel, tzimmermann, kraxel, alexander.deucher, tglx,
	dri-devel, xinliang.liu, maarten.lankhorst, mripard,
	linux-kernel

Hi Tian.

On Wed, Dec 02, 2020 at 04:47:14PM +0800, Tian Tao wrote:
> Add new api devm_drm_irq_install() to register interrupts,
> no need to call drm_irq_uninstall() when the drm module is removed.
> 
> Signed-off-by: Tian Tao <tiantao6@hisilicon.com>

Just a few details to fix.

	Sam

> ---
>  drivers/gpu/drm/drm_irq.c | 35 +++++++++++++++++++++++++++++++++++
>  include/drm/drm_irq.h     |  2 +-
>  2 files changed, 36 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/gpu/drm/drm_irq.c b/drivers/gpu/drm/drm_irq.c
> index 09d6e9e..b363dec 100644
> --- a/drivers/gpu/drm/drm_irq.c
> +++ b/drivers/gpu/drm/drm_irq.c
> @@ -214,6 +214,41 @@ int drm_irq_uninstall(struct drm_device *dev)
>  }
>  EXPORT_SYMBOL(drm_irq_uninstall);
>  
> +static void devm_drm_irq_uninstall(void *data)
> +{
> +	drm_irq_uninstall(data);
> +}
> +
> +/**
> + * devm_drm_irq_install - install IRQ handler
> + * @dev: DRM device
> + * @irq: IRQ number to install the handler for
> + *
> + * devm_drm_irq_install is a  help function of drm_irq_install.
Drop the extra space after "is a"
> + *
> + * if the driver uses devm_drm_irq_install, there is no need
Start with capital "I" in If
> + * to call drm_irq_uninstall when the drm module get unloaded,
> + * as this will done automagically.
> + *
> + * Returns:
> + * Zero on success or a negative error code on failure.
> + */
> +int devm_drm_irq_install(struct drm_device *dev, int irq)
> +{
> +	int ret;
> +
> +	ret = drm_irq_install(dev, irq);
> +	if (ret)
> +		return ret;
> +
> +	ret = devm_add_action_or_reset(dev->dev, devm_drm_irq_uninstall, dev);
> +	if (ret)
> +		devm_drm_irq_uninstall(dev);
devm_add_action_or_reset() will call devm_drm_irq_uninstall() if ret is
!= 0. See include/device.h.

I guess that is the "_or_reset" part of the name that can tell us that.
So you can drop the if condition as it just will cause the code to call
drm_irq_uninstall() twice.

> +
> +	return ret;
> +}
> +EXPORT_SYMBOL(devm_drm_irq_install);
> +
>  #if IS_ENABLED(CONFIG_DRM_LEGACY)
>  int drm_legacy_irq_control(struct drm_device *dev, void *data,
>  			   struct drm_file *file_priv)
> diff --git a/include/drm/drm_irq.h b/include/drm/drm_irq.h
> index d77f6e6..631b22f 100644
> --- a/include/drm/drm_irq.h
> +++ b/include/drm/drm_irq.h
> @@ -28,5 +28,5 @@ struct drm_device;
>  
>  int drm_irq_install(struct drm_device *dev, int irq);
>  int drm_irq_uninstall(struct drm_device *dev);
> -
> +int devm_drm_irq_install(struct drm_device *dev, int irq);
>  #endif
> -- 
> 2.7.4
> 
> _______________________________________________
> dri-devel mailing list
> dri-devel@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/dri-devel

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

* Re: [PATCH drm/hisilicon 2/3] drm/irq: Add the new api to install irq
  2020-12-02  8:47 ` [PATCH drm/hisilicon 2/3] drm/irq: " Tian Tao
@ 2020-12-02  8:59   ` Thomas Zimmermann
  2020-12-03 20:07   ` Sam Ravnborg
  1 sibling, 0 replies; 12+ messages in thread
From: Thomas Zimmermann @ 2020-12-02  8:59 UTC (permalink / raw)
  To: Tian Tao, airlied, daniel, kraxel, alexander.deucher, tglx,
	dri-devel, xinliang.liu, maarten.lankhorst, mripard
  Cc: linux-kernel


[-- Attachment #1.1: Type: text/plain, Size: 2654 bytes --]

Hi

Am 02.12.20 um 09:47 schrieb Tian Tao:
> Add new api devm_drm_irq_install() to register interrupts,
> no need to call drm_irq_uninstall() when the drm module is removed.
> 
> Signed-off-by: Tian Tao <tiantao6@hisilicon.com>
> ---
>   drivers/gpu/drm/drm_irq.c | 35 +++++++++++++++++++++++++++++++++++
>   include/drm/drm_irq.h     |  2 +-
>   2 files changed, 36 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/gpu/drm/drm_irq.c b/drivers/gpu/drm/drm_irq.c
> index 09d6e9e..b363dec 100644
> --- a/drivers/gpu/drm/drm_irq.c
> +++ b/drivers/gpu/drm/drm_irq.c
> @@ -214,6 +214,41 @@ int drm_irq_uninstall(struct drm_device *dev)
>   }
>   EXPORT_SYMBOL(drm_irq_uninstall);
>   
> +static void devm_drm_irq_uninstall(void *data)
> +{
> +	drm_irq_uninstall(data);
> +}
> +
> +/**
> + * devm_drm_irq_install - install IRQ handler
> + * @dev: DRM device
> + * @irq: IRQ number to install the handler for
> + *
> + * devm_drm_irq_install is a  help function of drm_irq_install.
> + *
> + * if the driver uses devm_drm_irq_install, there is no need
> + * to call drm_irq_uninstall when the drm module get unloaded,
> + * as this will done automagically.
> + *
> + * Returns:
> + * Zero on success or a negative error code on failure.
> + */
> +int devm_drm_irq_install(struct drm_device *dev, int irq)
> +{
> +	int ret;
> +
> +	ret = drm_irq_install(dev, irq);
> +	if (ret)
> +		return ret;
> +
> +	ret = devm_add_action_or_reset(dev->dev, devm_drm_irq_uninstall, dev);
> +	if (ret)
> +		devm_drm_irq_uninstall(dev);

If anything went wrong, devm_add_action_or_reset() will have already 
cleaned up for you. [1] So just return the result of 
devm_add_action_or_reset().

Best regards
Thomas

[1] 
https://elixir.bootlin.com/linux/latest/source/include/linux/device.h#L255

> +
> +	return ret;
> +}
> +EXPORT_SYMBOL(devm_drm_irq_install);
> +
>   #if IS_ENABLED(CONFIG_DRM_LEGACY)
>   int drm_legacy_irq_control(struct drm_device *dev, void *data,
>   			   struct drm_file *file_priv)
> diff --git a/include/drm/drm_irq.h b/include/drm/drm_irq.h
> index d77f6e6..631b22f 100644
> --- a/include/drm/drm_irq.h
> +++ b/include/drm/drm_irq.h
> @@ -28,5 +28,5 @@ struct drm_device;
>   
>   int drm_irq_install(struct drm_device *dev, int irq);
>   int drm_irq_uninstall(struct drm_device *dev);
> -
> +int devm_drm_irq_install(struct drm_device *dev, int irq);
>   #endif
> 

-- 
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Maxfeldstr. 5, 90409 Nürnberg, Germany
(HRB 36809, AG Nürnberg)
Geschäftsführer: Felix Imendörffer


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 840 bytes --]

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

* [PATCH drm/hisilicon 2/3] drm/irq: Add the new api to install irq
  2020-12-02  8:47 [PATCH drm/hisilicon 0/3] Add the new api to install irq Tian Tao
@ 2020-12-02  8:47 ` Tian Tao
  2020-12-02  8:59   ` Thomas Zimmermann
  2020-12-03 20:07   ` Sam Ravnborg
  0 siblings, 2 replies; 12+ messages in thread
From: Tian Tao @ 2020-12-02  8:47 UTC (permalink / raw)
  To: airlied, daniel, tzimmermann, kraxel, alexander.deucher, tglx,
	dri-devel, xinliang.liu, maarten.lankhorst, mripard
  Cc: linux-kernel

Add new api devm_drm_irq_install() to register interrupts,
no need to call drm_irq_uninstall() when the drm module is removed.

Signed-off-by: Tian Tao <tiantao6@hisilicon.com>
---
 drivers/gpu/drm/drm_irq.c | 35 +++++++++++++++++++++++++++++++++++
 include/drm/drm_irq.h     |  2 +-
 2 files changed, 36 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/drm_irq.c b/drivers/gpu/drm/drm_irq.c
index 09d6e9e..b363dec 100644
--- a/drivers/gpu/drm/drm_irq.c
+++ b/drivers/gpu/drm/drm_irq.c
@@ -214,6 +214,41 @@ int drm_irq_uninstall(struct drm_device *dev)
 }
 EXPORT_SYMBOL(drm_irq_uninstall);
 
+static void devm_drm_irq_uninstall(void *data)
+{
+	drm_irq_uninstall(data);
+}
+
+/**
+ * devm_drm_irq_install - install IRQ handler
+ * @dev: DRM device
+ * @irq: IRQ number to install the handler for
+ *
+ * devm_drm_irq_install is a  help function of drm_irq_install.
+ *
+ * if the driver uses devm_drm_irq_install, there is no need
+ * to call drm_irq_uninstall when the drm module get unloaded,
+ * as this will done automagically.
+ *
+ * Returns:
+ * Zero on success or a negative error code on failure.
+ */
+int devm_drm_irq_install(struct drm_device *dev, int irq)
+{
+	int ret;
+
+	ret = drm_irq_install(dev, irq);
+	if (ret)
+		return ret;
+
+	ret = devm_add_action_or_reset(dev->dev, devm_drm_irq_uninstall, dev);
+	if (ret)
+		devm_drm_irq_uninstall(dev);
+
+	return ret;
+}
+EXPORT_SYMBOL(devm_drm_irq_install);
+
 #if IS_ENABLED(CONFIG_DRM_LEGACY)
 int drm_legacy_irq_control(struct drm_device *dev, void *data,
 			   struct drm_file *file_priv)
diff --git a/include/drm/drm_irq.h b/include/drm/drm_irq.h
index d77f6e6..631b22f 100644
--- a/include/drm/drm_irq.h
+++ b/include/drm/drm_irq.h
@@ -28,5 +28,5 @@ struct drm_device;
 
 int drm_irq_install(struct drm_device *dev, int irq);
 int drm_irq_uninstall(struct drm_device *dev);
-
+int devm_drm_irq_install(struct drm_device *dev, int irq);
 #endif
-- 
2.7.4


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

end of thread, other threads:[~2020-12-03 21:34 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-26 12:02 [PATCH drm/hisilicon 0/3] Add the new api to install irq Tian Tao
2020-11-26 12:02 ` [PATCH drm/hisilicon 1/3] drm/hisilicon: Code refactoring for hibmc_drm_drv Tian Tao
2020-11-26 13:05   ` Thomas Zimmermann
2020-11-26 13:13     ` Thomas Zimmermann
2020-11-26 12:02 ` [PATCH drm/hisilicon 2/3] drm/irq: Add the new api to install irq Tian Tao
2020-11-26 13:12   ` Thomas Zimmermann
2020-11-26 12:02 ` [PATCH drm/hisilicon 3/3] drm/hisilicon: Use the new api devm_drm_irq_install Tian Tao
2020-11-26 13:15   ` Thomas Zimmermann
2020-12-02  8:47 [PATCH drm/hisilicon 0/3] Add the new api to install irq Tian Tao
2020-12-02  8:47 ` [PATCH drm/hisilicon 2/3] drm/irq: " Tian Tao
2020-12-02  8:59   ` Thomas Zimmermann
2020-12-03 20:07   ` Sam Ravnborg
2020-12-03 21:33     ` Sam Ravnborg

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).