Skip to contentSkip to conversation

drm/exynos: add full modularity support to sub drivers

RFC PATCH Superseded Inki Dae 3 participants 9 messages Nov 18, 2014 – Nov 19, 2014

Subsystems (4)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Inki Dae

author maintainer
#0 lore raw

cover drm/exynos: add full modularity support to sub drivers

Hi all,

This patch set adds full modularity to sub drivers, kms and non kms drivers.

For this, this patch sets consists into three patches. first patch modularizes kms drivers, second patch for non kms drivers, and third patch for vidi driver.

I hope we could resolve infinite loop issue and kernel lockup reported by other people. This patch set is RFC so there might be my missing points. Welcome to any comments.

This patch set is based on top of exynos-drm-next branch.

Thanks,
Inki Dae

Inki Dae (3):
drm/exynos: make kms drivers to be independent modules drm/exynos: make non kms drivers to be indenpendent modules drm/exynos: make vidi driver to be independent module

 drivers/gpu/drm/exynos/Kconfig              |    8 +-
 drivers/gpu/drm/exynos/exynos_dp_core.c     |   13 +++
 drivers/gpu/drm/exynos/exynos_drm_core.c    |  166 +++++++++++++++++++++++----
 drivers/gpu/drm/exynos/exynos_drm_drv.c     |  105 +----------------
 drivers/gpu/drm/exynos/exynos_drm_drv.h     |   42 ++-----
 drivers/gpu/drm/exynos/exynos_drm_dsi.c     |   13 +++
 drivers/gpu/drm/exynos/exynos_drm_fimc.c    |   13 +++
 drivers/gpu/drm/exynos/exynos_drm_fimd.c    |   13 +++
 drivers/gpu/drm/exynos/exynos_drm_g2d.c     |   34 ++++++
 drivers/gpu/drm/exynos/exynos_drm_gsc.c     |   12 ++
 drivers/gpu/drm/exynos/exynos_drm_ipp.c     |   39 ++++++-
 drivers/gpu/drm/exynos/exynos_drm_rotator.c |   13 +++
 drivers/gpu/drm/exynos/exynos_drm_vidi.c    |   81 ++++++++-----
 drivers/gpu/drm/exynos/exynos_hdmi.c        |   13 +++
 drivers/gpu/drm/exynos/exynos_mixer.c       |   13 +++
 15 files changed, 391 insertions(+), 187 deletions(-)
Signature · 1 line
1.7.9.5
author maintainer
#1 lore raw

RFC PATCH 1/3 drm/exynos: make kms drivers to be independent modules

This patch makes kms drivers to be independent modules. For this, it removes all register codes to kms drivers from exynos_drm_drv module and adds module_init/exit for each kms driver so that each kms driver can be called independently.

---
 drivers/gpu/drm/exynos/Kconfig           |    8 +++---
 drivers/gpu/drm/exynos/exynos_dp_core.c  |   13 +++++++++
 drivers/gpu/drm/exynos/exynos_drm_drv.c  |   43 +++---------------------------
 drivers/gpu/drm/exynos/exynos_drm_drv.h  |    5 ----
 drivers/gpu/drm/exynos/exynos_drm_dsi.c  |   13 +++++++++
 drivers/gpu/drm/exynos/exynos_drm_fimd.c |   13 +++++++++
 drivers/gpu/drm/exynos/exynos_hdmi.c     |   13 +++++++++
 drivers/gpu/drm/exynos/exynos_mixer.c    |   13 +++++++++
 8 files changed, 72 insertions(+), 49 deletions(-)
drivers/gpu/drm/exynos/Kconfig +4 -4
index 7f9f6f9..3d5fa69 100644
@@ -25,7 +25,7 @@ config DRM_EXYNOS_DMABUF
 	  Choose this option if you want to use DMABUF feature for DRM.
 
 config DRM_EXYNOS_FIMD
-	bool "Exynos DRM FIMD"
+	tristate "Exynos DRM FIMD"
 	depends on DRM_EXYNOS && !FB_S3C
 	select FB_MODE_HELPERS
 	select MFD_SYSCON
@@ -41,7 +41,7 @@ config DRM_EXYNOS_DPI
 	  This enables support for Exynos parallel output.
 
 config DRM_EXYNOS_DSI
-	bool "EXYNOS DRM MIPI-DSI driver support"
+	tristate "EXYNOS DRM MIPI-DSI driver support"
 	depends on DRM_EXYNOS_FIMD
 	select DRM_MIPI_DSI
 	select DRM_PANEL
@@ -50,7 +50,7 @@ config DRM_EXYNOS_DSI
 	  This enables support for Exynos MIPI-DSI device.
 
 config DRM_EXYNOS_DP
-	bool "EXYNOS DRM DP driver support"
+	tristate "EXYNOS DRM DP driver support"
 	depends on DRM_EXYNOS_FIMD && ARCH_EXYNOS && (DRM_PTN3460=n || DRM_PTN3460=y || DRM_PTN3460=DRM_EXYNOS)
 	default DRM_EXYNOS
 	select DRM_PANEL
@@ -58,7 +58,7 @@ config DRM_EXYNOS_DP
 	  This enables support for DP device.
 
 config DRM_EXYNOS_HDMI
-	bool "Exynos DRM HDMI"
+	tristate "Exynos DRM HDMI"
 	depends on DRM_EXYNOS && !VIDEO_SAMSUNG_S5P_TV
 	help
 	  Choose this option if you want to use Exynos HDMI for DRM.
drivers/gpu/drm/exynos/exynos_dp_core.c +13 -0
index ed818b9..b08d97b 100644
@@ -1408,6 +1408,19 @@ struct platform_driver dp_driver = {
 	},
 };
 
+static int exynos_dp_init(void)
+{
+	return platform_driver_register(&dp_driver);
+}
+
+static void exynos_dp_exit(void)
+{
+	platform_driver_unregister(&dp_driver);
+}
+
+module_init(exynos_dp_init);
+module_exit(exynos_dp_exit);
+
 MODULE_AUTHOR("Jingoo Han <[email protected]>");
 MODULE_DESCRIPTION("Samsung SoC DP Driver");
 MODULE_LICENSE("GPL v2");
drivers/gpu/drm/exynos/exynos_drm_drv.c +3 -40

78 lines not on this page · raw message

drivers/gpu/drm/exynos/exynos_drm_drv.h +0 -5
index 262a459..352a9f9 100644
@@ -331,11 +331,6 @@ int exynos_drm_component_add(struct device *dev,
 void exynos_drm_component_del(struct device *dev,
 				enum exynos_drm_device_type dev_type);
 
-extern struct platform_driver fimd_driver;
-extern struct platform_driver dp_driver;
-extern struct platform_driver dsi_driver;
-extern struct platform_driver mixer_driver;
-extern struct platform_driver hdmi_driver;
 extern struct platform_driver exynos_drm_common_hdmi_driver;
 extern struct platform_driver vidi_driver;
 extern struct platform_driver g2d_driver;
drivers/gpu/drm/exynos/exynos_drm_dsi.c +13 -0
index 66d427e..ebc3383 100644
@@ -1799,6 +1799,19 @@ struct platform_driver dsi_driver = {
 	},
 };
 
+static int exynos_dsi_driver_init(void)
+{
+	return platform_driver_register(&dsi_driver);
+}
+
+static void exynos_dsi_driver_exit(void)
+{
+	platform_driver_unregister(&dsi_driver);
+}
+
+module_init(exynos_dsi_driver_init);
+module_exit(exynos_dsi_driver_exit);
+
 MODULE_AUTHOR("Tomasz Figa <[email protected]>");
 MODULE_AUTHOR("Andrzej Hajda <[email protected]>");
 MODULE_DESCRIPTION("Samsung SoC MIPI DSI Master");
drivers/gpu/drm/exynos/exynos_drm_fimd.c +13 -0
index 0673a39..eed51c6 100644
@@ -1240,3 +1240,16 @@ struct platform_driver fimd_driver = {
 		.of_match_table = fimd_driver_dt_match,
 	},
 };
+
+static int exynos_drm_fimd_init(void)
+{
+	return platform_driver_register(&fimd_driver);
+}
+
+static void exynos_drm_fimd_exit(void)
+{
+	platform_driver_unregister(&fimd_driver);
+}
+
+module_init(exynos_drm_fimd_init);
+module_exit(exynos_drm_fimd_exit);
drivers/gpu/drm/exynos/exynos_hdmi.c +13 -0
index 563a19e..83198f7 100644
@@ -2537,3 +2537,16 @@ struct platform_driver hdmi_driver = {
 		.of_match_table = hdmi_match_types,
 	},
 };
+
+static int hdmi_init(void)
+{
+	return platform_driver_register(&hdmi_driver);
+}
+
+static void hdmi_exit(void)
+{
+	platform_driver_unregister(&hdmi_driver);
+}
+
+module_init(hdmi_init);
+module_exit(hdmi_exit);
drivers/gpu/drm/exynos/exynos_mixer.c +13 -0
index a41c84e..4d812f1 100644
@@ -1349,3 +1349,16 @@ struct platform_driver mixer_driver = {
 	.remove = mixer_remove,
 	.id_table	= mixer_driver_types,
 };
+
+static int mixer_init(void)
+{
+	return platform_driver_register(&mixer_driver);
+}
+
+static void mixer_exit(void)
+{
+	platform_driver_unregister(&mixer_driver);
+}
+
+module_init(mixer_init);
+module_exit(mixer_exit);
Signature · 6 lines
1.7.9.5

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel
#2 lore raw

Re: [RFC PATCH 1/3] drm/exynos: make kms drivers to be independent modules

Quoted 5 lines · Inki Dae

This patch makes kms drivers to be independent modules. For this, it removes all register codes to kms drivers from exynos_drm_drv module and adds module_init/exit for each kms driver so that each kms driver can be called independently.

It is hard to test if modules are working because I am not able to build modules :), see comments below.

Quoted 45 lines
---
 drivers/gpu/drm/exynos/Kconfig           |    8 +++---
 drivers/gpu/drm/exynos/exynos_dp_core.c  |   13 +++++++++
 drivers/gpu/drm/exynos/exynos_drm_drv.c  |   43 +++---------------------------
 drivers/gpu/drm/exynos/exynos_drm_drv.h  |    5 ----
 drivers/gpu/drm/exynos/exynos_drm_dsi.c  |   13 +++++++++
 drivers/gpu/drm/exynos/exynos_drm_fimd.c |   13 +++++++++
 drivers/gpu/drm/exynos/exynos_hdmi.c     |   13 +++++++++
 drivers/gpu/drm/exynos/exynos_mixer.c    |   13 +++++++++
 8 files changed, 72 insertions(+), 49 deletions(-)
drivers/gpu/drm/exynos/Kconfig +3 -3
index 7f9f6f9..3d5fa69 100644
@@ -25,7 +25,7 @@ config DRM_EXYNOS_DMABUF
 	  Choose this option if you want to use DMABUF feature for DRM.
 
 config DRM_EXYNOS_FIMD
-	bool "Exynos DRM FIMD"
+	tristate "Exynos DRM FIMD"
 	depends on DRM_EXYNOS && !FB_S3C
 	select FB_MODE_HELPERS
 	select MFD_SYSCON
@@ -41,7 +41,7 @@ config DRM_EXYNOS_DPI
 	  This enables support for Exynos parallel output.
 
 config DRM_EXYNOS_DSI
-	bool "EXYNOS DRM MIPI-DSI driver support"
+	tristate "EXYNOS DRM MIPI-DSI driver support"
 	depends on DRM_EXYNOS_FIMD
 	select DRM_MIPI_DSI
 	select DRM_PANEL
@@ -50,7 +50,7 @@ config DRM_EXYNOS_DSI
 	  This enables support for Exynos MIPI-DSI device.
 
 config DRM_EXYNOS_DP
-	bool "EXYNOS DRM DP driver support"
+	tristate "EXYNOS DRM DP driver support"
 	depends on DRM_EXYNOS_FIMD && ARCH_EXYNOS && (DRM_PTN3460=n || DRM_PTN3460=y || DRM_PTN3460=DRM_EXYNOS)
 	default DRM_EXYNOS
 	select DRM_PANEL

drivers/gpu/drm/exynos/Kconfig config DRM_EXYNOS_DP · line 64

Quoted 8 lines
drivers/gpu/drm/exynos/Kconfig +1 -1
@@ -58,7 +58,7 @@ config DRM_EXYNOS_DP
 	  This enables support for DP device.
 
 config DRM_EXYNOS_HDMI
-	bool "Exynos DRM HDMI"
+	tristate "Exynos DRM HDMI"
 	depends on DRM_EXYNOS && !VIDEO_SAMSUNG_S5P_TV
 	help
 	  Choose this option if you want to use Exynos HDMI for DRM.

Without corresponding changes in Makefiles you cannot build it as modules.

Quoted 11 lines
drivers/gpu/drm/exynos/exynos_dp_core.c +3 -0
index ed818b9..b08d97b 100644
@@ -1408,6 +1408,19 @@ struct platform_driver dp_driver = {
 	},
 };
 
+static int exynos_dp_init(void)
+{
+	return platform_driver_register(&dp_driver);

drivers/gpu/drm/exynos/exynos_dp_core.c struct platform_driver dp_driver = { · line 1423

Quoted 10 lines
drivers/gpu/drm/exynos/exynos_dp_core.c +10 -0
+}
+
+static void exynos_dp_exit(void)
+{
+	platform_driver_unregister(&dp_driver);
+}
+
+module_init(exynos_dp_init);
+module_exit(exynos_dp_exit);
+

Here and in other modules you can use module_platform_driver macro.

Quoted 8 lines
drivers/gpu/drm/exynos/exynos_dp_core.c +0 -0
 MODULE_AUTHOR("Jingoo Han <[email protected]>");
 MODULE_DESCRIPTION("Samsung SoC DP Driver");
 MODULE_LICENSE("GPL v2");
drivers/gpu/drm/exynos/exynos_drm_drv.c +0 -0
index eab12f0..02d4772 100644

drivers/gpu/drm/exynos/exynos_drm_drv.c static struct component_match *exynos_drm_match_add(struct device *dev) · line 492

Quoted 9 lines
drivers/gpu/drm/exynos/exynos_drm_drv.c +0 -6
@@ -484,12 +484,6 @@ static struct component_match *exynos_drm_match_add(struct device *dev)
 
 	mutex_lock(&drm_component_lock);
 
-	/* Do not retry to probe if there is no any kms driver regitered. */
-	if (list_empty(&drm_component_list)) {
-		mutex_unlock(&drm_component_lock);
-		return ERR_PTR(-ENODEV);
-	}
-

It is hard to guess how and why it should work with modules. For example what should happen if fimd/dsi modules are loaded but hdmi/mixer not. When exynos_drv should wait with initialization for hdmi and when it should create drmdev.

DRM system is rather monolithic splitting its components to modules seems strange.

Regards
Andrzej

Quoted 167 lines
drivers/gpu/drm/exynos/exynos_drm_drv.c +3 -34
 	list_for_each_entry(cdev, &drm_component_list, list) {
 		/*
 		 * Add components to master only in case that crtc and
@@ -545,22 +539,6 @@ static const struct component_master_ops exynos_drm_ops = {
 	.unbind		= exynos_drm_unbind,
 };
 
-static struct platform_driver *const exynos_drm_kms_drivers[] = {
-#ifdef CONFIG_DRM_EXYNOS_FIMD
-	&fimd_driver,
-#endif
-#ifdef CONFIG_DRM_EXYNOS_DP
-	&dp_driver,
-#endif
-#ifdef CONFIG_DRM_EXYNOS_DSI
-	&dsi_driver,
-#endif
-#ifdef CONFIG_DRM_EXYNOS_HDMI
-	&mixer_driver,
-	&hdmi_driver,
-#endif
-};
-
 static struct platform_driver *const exynos_drm_non_kms_drivers[] = {
 #ifdef CONFIG_DRM_EXYNOS_G2D
 	&g2d_driver,
@@ -587,22 +565,14 @@ static int exynos_drm_platform_probe(struct platform_device *pdev)
 	pdev->dev.coherent_dma_mask = DMA_BIT_MASK(32);
 	exynos_drm_driver.num_ioctls = ARRAY_SIZE(exynos_ioctls);
 
-	for (i = 0; i < ARRAY_SIZE(exynos_drm_kms_drivers); ++i) {
-		ret = platform_driver_register(exynos_drm_kms_drivers[i]);
-		if (ret < 0)
-			goto err_unregister_kms_drivers;
-	}
-
 	match = exynos_drm_match_add(&pdev->dev);
-	if (IS_ERR(match)) {
-		ret = PTR_ERR(match);
-		goto err_unregister_kms_drivers;
-	}
+	if (IS_ERR(match))
+		return PTR_ERR(match);
 
 	ret = component_master_add_with_match(&pdev->dev, &exynos_drm_ops,
 						match);
 	if (ret < 0)
-		goto err_unregister_kms_drivers;
+		return ret;
 
 	for (j = 0; j < ARRAY_SIZE(exynos_drm_non_kms_drivers); ++j) {
 		ret = platform_driver_register(exynos_drm_non_kms_drivers[j]);
@@ -632,10 +602,6 @@ err_unregister_non_kms_drivers:
 err_del_component_master:
 	component_master_del(&pdev->dev, &exynos_drm_ops);
 
-err_unregister_kms_drivers:
-	while (--i >= 0)
-		platform_driver_unregister(exynos_drm_kms_drivers[i]);
-
 	return ret;
 }
 
@@ -654,9 +620,6 @@ static int exynos_drm_platform_remove(struct platform_device *pdev)
 
 	component_master_del(&pdev->dev, &exynos_drm_ops);
 
-	for (i = ARRAY_SIZE(exynos_drm_kms_drivers) - 1; i >= 0; --i)
-		platform_driver_unregister(exynos_drm_kms_drivers[i]);
-
 	return 0;
 }
 
drivers/gpu/drm/exynos/exynos_drm_drv.h +0 -5
index 262a459..352a9f9 100644
@@ -331,11 +331,6 @@ int exynos_drm_component_add(struct device *dev,
 void exynos_drm_component_del(struct device *dev,
 				enum exynos_drm_device_type dev_type);
 
-extern struct platform_driver fimd_driver;
-extern struct platform_driver dp_driver;
-extern struct platform_driver dsi_driver;
-extern struct platform_driver mixer_driver;
-extern struct platform_driver hdmi_driver;
 extern struct platform_driver exynos_drm_common_hdmi_driver;
 extern struct platform_driver vidi_driver;
 extern struct platform_driver g2d_driver;
drivers/gpu/drm/exynos/exynos_drm_dsi.c +13 -0
index 66d427e..ebc3383 100644
@@ -1799,6 +1799,19 @@ struct platform_driver dsi_driver = {
 	},
 };
 
+static int exynos_dsi_driver_init(void)
+{
+	return platform_driver_register(&dsi_driver);
+}
+
+static void exynos_dsi_driver_exit(void)
+{
+	platform_driver_unregister(&dsi_driver);
+}
+
+module_init(exynos_dsi_driver_init);
+module_exit(exynos_dsi_driver_exit);
+
 MODULE_AUTHOR("Tomasz Figa <[email protected]>");
 MODULE_AUTHOR("Andrzej Hajda <[email protected]>");
 MODULE_DESCRIPTION("Samsung SoC MIPI DSI Master");
drivers/gpu/drm/exynos/exynos_drm_fimd.c +13 -0
index 0673a39..eed51c6 100644
@@ -1240,3 +1240,16 @@ struct platform_driver fimd_driver = {
 		.of_match_table = fimd_driver_dt_match,
 	},
 };
+
+static int exynos_drm_fimd_init(void)
+{
+	return platform_driver_register(&fimd_driver);
+}
+
+static void exynos_drm_fimd_exit(void)
+{
+	platform_driver_unregister(&fimd_driver);
+}
+
+module_init(exynos_drm_fimd_init);
+module_exit(exynos_drm_fimd_exit);
drivers/gpu/drm/exynos/exynos_hdmi.c +13 -0
index 563a19e..83198f7 100644
@@ -2537,3 +2537,16 @@ struct platform_driver hdmi_driver = {
 		.of_match_table = hdmi_match_types,
 	},
 };
+
+static int hdmi_init(void)
+{
+	return platform_driver_register(&hdmi_driver);
+}
+
+static void hdmi_exit(void)
+{
+	platform_driver_unregister(&hdmi_driver);
+}
+
+module_init(hdmi_init);
+module_exit(hdmi_exit);
drivers/gpu/drm/exynos/exynos_mixer.c +3 -0
index a41c84e..4d812f1 100644
@@ -1349,3 +1349,16 @@ struct platform_driver mixer_driver = {
 	.remove = mixer_remove,
 	.id_table	= mixer_driver_types,
 };
+
+static int mixer_init(void)
+{

drivers/gpu/drm/exynos/exynos_mixer.c struct platform_driver mixer_driver = { · line 1364

Quoted 10 lines
drivers/gpu/drm/exynos/exynos_mixer.c +10 -0
+	return platform_driver_register(&mixer_driver);
+}
+
+static void mixer_exit(void)
+{
+	platform_driver_unregister(&mixer_driver);
+}
+
+module_init(mixer_init);
+module_exit(mixer_exit);

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel

author maintainer
#3 lore raw

Re: [RFC PATCH 1/3] drm/exynos: make kms drivers to be independent modules

2014-11-19 17:49 GMT+09:00 Andrzej Hajda <[email protected]>:

Quoted 105 lines · Inki Dae
Quoted 5 lines

This patch makes kms drivers to be independent modules. For this, it removes all register codes to kms drivers from exynos_drm_drv module and adds module_init/exit for each kms driver so that each kms driver can be called independently.

It is hard to test if modules are working because I am not able to build modules :), see comments below.

Quoted 45 lines
---
 drivers/gpu/drm/exynos/Kconfig           |    8 +++---
 drivers/gpu/drm/exynos/exynos_dp_core.c  |   13 +++++++++
 drivers/gpu/drm/exynos/exynos_drm_drv.c  |   43 +++---------------------------
 drivers/gpu/drm/exynos/exynos_drm_drv.h  |    5 ----
 drivers/gpu/drm/exynos/exynos_drm_dsi.c  |   13 +++++++++
 drivers/gpu/drm/exynos/exynos_drm_fimd.c |   13 +++++++++
 drivers/gpu/drm/exynos/exynos_hdmi.c     |   13 +++++++++
 drivers/gpu/drm/exynos/exynos_mixer.c    |   13 +++++++++
 8 files changed, 72 insertions(+), 49 deletions(-)
drivers/gpu/drm/exynos/Kconfig +3 -3
index 7f9f6f9..3d5fa69 100644
@@ -25,7 +25,7 @@ config DRM_EXYNOS_DMABUF
        Choose this option if you want to use DMABUF feature for DRM.
 
 config DRM_EXYNOS_FIMD
-     bool "Exynos DRM FIMD"
+     tristate "Exynos DRM FIMD"
      depends on DRM_EXYNOS && !FB_S3C
      select FB_MODE_HELPERS
      select MFD_SYSCON
@@ -41,7 +41,7 @@ config DRM_EXYNOS_DPI
        This enables support for Exynos parallel output.
 
 config DRM_EXYNOS_DSI
-     bool "EXYNOS DRM MIPI-DSI driver support"
+     tristate "EXYNOS DRM MIPI-DSI driver support"
      depends on DRM_EXYNOS_FIMD
      select DRM_MIPI_DSI
      select DRM_PANEL
@@ -50,7 +50,7 @@ config DRM_EXYNOS_DSI
        This enables support for Exynos MIPI-DSI device.
 
 config DRM_EXYNOS_DP
-     bool "EXYNOS DRM DP driver support"
+     tristate "EXYNOS DRM DP driver support"
      depends on DRM_EXYNOS_FIMD && ARCH_EXYNOS && (DRM_PTN3460=n || DRM_PTN3460=y || DRM_PTN3460=DRM_EXYNOS)
      default DRM_EXYNOS
      select DRM_PANEL

drivers/gpu/drm/exynos/Kconfig config DRM_EXYNOS_DP · line 64

Quoted 8 lines
drivers/gpu/drm/exynos/Kconfig +1 -1
@@ -58,7 +58,7 @@ config DRM_EXYNOS_DP
        This enables support for DP device.
 
 config DRM_EXYNOS_HDMI
-     bool "Exynos DRM HDMI"
+     tristate "Exynos DRM HDMI"
      depends on DRM_EXYNOS && !VIDEO_SAMSUNG_S5P_TV
      help
        Choose this option if you want to use Exynos HDMI for DRM.

Without corresponding changes in Makefiles you cannot build it as modules.

Quoted 11 lines
drivers/gpu/drm/exynos/exynos_dp_core.c +3 -0
index ed818b9..b08d97b 100644
@@ -1408,6 +1408,19 @@ struct platform_driver dp_driver = {
      },
 };
 
+static int exynos_dp_init(void)
+{
+     return platform_driver_register(&dp_driver);

drivers/gpu/drm/exynos/exynos_dp_core.c struct platform_driver dp_driver = { · line 1423

Quoted 10 lines
drivers/gpu/drm/exynos/exynos_dp_core.c +10 -0
+}
+
+static void exynos_dp_exit(void)
+{
+     platform_driver_unregister(&dp_driver);
+}
+
+module_init(exynos_dp_init);
+module_exit(exynos_dp_exit);
+

Here and in other modules you can use module_platform_driver macro.

Quoted 11 lines
drivers/gpu/drm/exynos/exynos_dp_core.c +0 -0
 MODULE_AUTHOR("Jingoo Han <[email protected]>");
 MODULE_DESCRIPTION("Samsung SoC DP Driver");
 MODULE_LICENSE("GPL v2");
drivers/gpu/drm/exynos/exynos_drm_drv.c +0 -0
index eab12f0..02d4772 100644
@@ -484,12 +484,6 @@ static struct component_match *exynos_drm_match_add(struct device *dev)
 
      mutex_lock(&drm_component_lock);
 
Quoted 10 lines

drivers/gpu/drm/exynos/exynos_drm_drv.c static struct component_match *exynos_drm_match_add(struct device *dev) · line 492

Quoted 6 lines
drivers/gpu/drm/exynos/exynos_drm_drv.c +0 -6
-     /* Do not retry to probe if there is no any kms driver regitered. */
-     if (list_empty(&drm_component_list)) {
-             mutex_unlock(&drm_component_lock);
-             return ERR_PTR(-ENODEV);
-     }
-

It is hard to guess how and why it should work with modules. For example what should happen if fimd/dsi modules are loaded but hdmi/mixer not. When exynos_drv should wait with initialization for hdmi

Right, hdmi/mixer cannot be probed, which means module doesn't work correctly.

Quoted 4 lines

and when it should create drmdev.

DRM system is rather monolithic splitting its components to modules seems strange.

Yes, good point. I missed a big point that DRM system should be monolithic, integrated driver.
However I strongly think it's better to separate them into independent drivers so that entry point of each sub driver can be called itself. With this, the probe order of each sub driver can be handled by component and Exynos drm core properly. it's really not good for all register codes of sub drivers to be placed in exynos_drm_drv, and this was my plan for cleanning up Exynos drm long ago: but still remaining one more thing, applying super device node.
So I will just modify for them to be built in kernel image by reverting the change of Kconfig, which means that all sub drivers cannot be configured as a separeated module like now.

Thanks,
Inki Dae

Quoted 178 lines

Regards
Andrzej

Quoted 174 lines
drivers/gpu/drm/exynos/exynos_drm_drv.c +3 -34
      list_for_each_entry(cdev, &drm_component_list, list) {
              /*
               * Add components to master only in case that crtc and
@@ -545,22 +539,6 @@ static const struct component_master_ops exynos_drm_ops = {
      .unbind         = exynos_drm_unbind,
 };
 
-static struct platform_driver *const exynos_drm_kms_drivers[] = {
-#ifdef CONFIG_DRM_EXYNOS_FIMD
-     &fimd_driver,
-#endif
-#ifdef CONFIG_DRM_EXYNOS_DP
-     &dp_driver,
-#endif
-#ifdef CONFIG_DRM_EXYNOS_DSI
-     &dsi_driver,
-#endif
-#ifdef CONFIG_DRM_EXYNOS_HDMI
-     &mixer_driver,
-     &hdmi_driver,
-#endif
-};
-
 static struct platform_driver *const exynos_drm_non_kms_drivers[] = {
 #ifdef CONFIG_DRM_EXYNOS_G2D
      &g2d_driver,
@@ -587,22 +565,14 @@ static int exynos_drm_platform_probe(struct platform_device *pdev)
      pdev->dev.coherent_dma_mask = DMA_BIT_MASK(32);
      exynos_drm_driver.num_ioctls = ARRAY_SIZE(exynos_ioctls);
 
-     for (i = 0; i < ARRAY_SIZE(exynos_drm_kms_drivers); ++i) {
-             ret = platform_driver_register(exynos_drm_kms_drivers[i]);
-             if (ret < 0)
-                     goto err_unregister_kms_drivers;
-     }
-
      match = exynos_drm_match_add(&pdev->dev);
-     if (IS_ERR(match)) {
-             ret = PTR_ERR(match);
-             goto err_unregister_kms_drivers;
-     }
+     if (IS_ERR(match))
+             return PTR_ERR(match);
 
      ret = component_master_add_with_match(&pdev->dev, &exynos_drm_ops,
                                              match);
      if (ret < 0)
-             goto err_unregister_kms_drivers;
+             return ret;
 
      for (j = 0; j < ARRAY_SIZE(exynos_drm_non_kms_drivers); ++j) {
              ret = platform_driver_register(exynos_drm_non_kms_drivers[j]);
@@ -632,10 +602,6 @@ err_unregister_non_kms_drivers:
 err_del_component_master:
      component_master_del(&pdev->dev, &exynos_drm_ops);
 
-err_unregister_kms_drivers:
-     while (--i >= 0)
-             platform_driver_unregister(exynos_drm_kms_drivers[i]);
-
      return ret;
 }
 
@@ -654,9 +620,6 @@ static int exynos_drm_platform_remove(struct platform_device *pdev)
 
      component_master_del(&pdev->dev, &exynos_drm_ops);
 
-     for (i = ARRAY_SIZE(exynos_drm_kms_drivers) - 1; i >= 0; --i)
-             platform_driver_unregister(exynos_drm_kms_drivers[i]);
-
      return 0;
 }
 
drivers/gpu/drm/exynos/exynos_drm_drv.h +0 -5
index 262a459..352a9f9 100644
@@ -331,11 +331,6 @@ int exynos_drm_component_add(struct device *dev,
 void exynos_drm_component_del(struct device *dev,
                              enum exynos_drm_device_type dev_type);
 
-extern struct platform_driver fimd_driver;
-extern struct platform_driver dp_driver;
-extern struct platform_driver dsi_driver;
-extern struct platform_driver mixer_driver;
-extern struct platform_driver hdmi_driver;
 extern struct platform_driver exynos_drm_common_hdmi_driver;
 extern struct platform_driver vidi_driver;
 extern struct platform_driver g2d_driver;
drivers/gpu/drm/exynos/exynos_drm_dsi.c +13 -0
index 66d427e..ebc3383 100644
@@ -1799,6 +1799,19 @@ struct platform_driver dsi_driver = {
      },
 };
 
+static int exynos_dsi_driver_init(void)
+{
+     return platform_driver_register(&dsi_driver);
+}
+
+static void exynos_dsi_driver_exit(void)
+{
+     platform_driver_unregister(&dsi_driver);
+}
+
+module_init(exynos_dsi_driver_init);
+module_exit(exynos_dsi_driver_exit);
+
 MODULE_AUTHOR("Tomasz Figa <[email protected]>");
 MODULE_AUTHOR("Andrzej Hajda <[email protected]>");
 MODULE_DESCRIPTION("Samsung SoC MIPI DSI Master");
drivers/gpu/drm/exynos/exynos_drm_fimd.c +13 -0
index 0673a39..eed51c6 100644
@@ -1240,3 +1240,16 @@ struct platform_driver fimd_driver = {
              .of_match_table = fimd_driver_dt_match,
      },
 };
+
+static int exynos_drm_fimd_init(void)
+{
+     return platform_driver_register(&fimd_driver);
+}
+
+static void exynos_drm_fimd_exit(void)
+{
+     platform_driver_unregister(&fimd_driver);
+}
+
+module_init(exynos_drm_fimd_init);
+module_exit(exynos_drm_fimd_exit);
drivers/gpu/drm/exynos/exynos_hdmi.c +13 -0
index 563a19e..83198f7 100644
@@ -2537,3 +2537,16 @@ struct platform_driver hdmi_driver = {
              .of_match_table = hdmi_match_types,
      },
 };
+
+static int hdmi_init(void)
+{
+     return platform_driver_register(&hdmi_driver);
+}
+
+static void hdmi_exit(void)
+{
+     platform_driver_unregister(&hdmi_driver);
+}
+
+module_init(hdmi_init);
+module_exit(hdmi_exit);
drivers/gpu/drm/exynos/exynos_mixer.c +11 -0
index a41c84e..4d812f1 100644
@@ -1349,3 +1349,16 @@ struct platform_driver mixer_driver = {
      .remove = mixer_remove,
      .id_table       = mixer_driver_types,
 };
+
+static int mixer_init(void)
+{
+     return platform_driver_register(&mixer_driver);
+}
+
+static void mixer_exit(void)
+{
+     platform_driver_unregister(&mixer_driver);
+}
+
Quoted 8 lines

drivers/gpu/drm/exynos/exynos_mixer.c struct platform_driver mixer_driver = { · line 1364

Quoted 3 lines
drivers/gpu/drm/exynos/exynos_mixer.c +2 -0
+module_init(mixer_init);
+module_exit(mixer_exit);

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel

author maintainer
#4 lore raw

RFC PATCH 2/3 drm/exynos: make non kms drivers to be indenpendent modules

In reply to Inki Dae

This patch makes non kms drivers to be independent modules. For this, it removes all register codes to non kms drivers from exynos_drm_drv module and adds module_init/exit for each non kms driver so that each non kms driver can be called independently.

In addition, this patch adds non kms register/unregister functions to exynos_drm_core module and also modifies existing codes relevant to sub driver.

The idea is that non kms driver is registered by entry point, module_init, of each non kms driver and sets its own sub driver to registered non kms driver object when the sub driver is probed. For this, this patch adds a new structure, exynos_drm_non_kms_dev, to exynos_drm_core module.

---
 drivers/gpu/drm/exynos/exynos_drm_core.c    |  166 +++++++++++++++++++++++----
 drivers/gpu/drm/exynos/exynos_drm_drv.c     |   50 +-------
 drivers/gpu/drm/exynos/exynos_drm_drv.h     |   28 ++---
 drivers/gpu/drm/exynos/exynos_drm_fimc.c    |   13 +++
 drivers/gpu/drm/exynos/exynos_drm_g2d.c     |   34 ++++++
 drivers/gpu/drm/exynos/exynos_drm_gsc.c     |   12 ++
 drivers/gpu/drm/exynos/exynos_drm_ipp.c     |   39 ++++++-
 drivers/gpu/drm/exynos/exynos_drm_rotator.c |   13 +++
 8 files changed, 265 insertions(+), 90 deletions(-)
drivers/gpu/drm/exynos/exynos_drm_core.c +142 -24
index 4c9f972..2ce63bc 100644
@@ -19,6 +19,13 @@
 #include "exynos_drm_fbdev.h"
 
 static LIST_HEAD(exynos_drm_subdrv_list);
+DEFINE_MUTEX(list_lock);
+
+struct exynos_drm_non_kms_dev {
+	struct list_head list;
+	struct exynos_drm_subdrv *subdrv;
+	unsigned int device_type;
+};
 
 int exynos_drm_create_enc_conn(struct drm_device *dev,
 					struct exynos_drm_display *display)
@@ -55,12 +62,66 @@ err_destroy_encoder:
 	return ret;
 }
 
+int exynos_drm_non_kms_register(unsigned int device_type)
+{
+	struct exynos_drm_non_kms_dev *dev;
+
+	dev = kzalloc(sizeof(*dev), GFP_KERNEL);
+	if (!dev)
+		return -ENOMEM;
+
+	dev->device_type = device_type;
+
+	mutex_lock(&list_lock);
+	list_add_tail(&dev->list, &exynos_drm_subdrv_list);
+	mutex_unlock(&list_lock);
+
+	return 0;
+}
+
+void exynos_drm_non_kms_unregister(unsigned int device_type)
+{
+	struct exynos_drm_non_kms_dev *dev, *next;
+
+	mutex_lock(&list_lock);
+	list_for_each_entry_safe(dev, next, &exynos_drm_subdrv_list, list) {
+		mutex_unlock(&list_lock);
+		if (dev->device_type == device_type) {
+			list_del_init(&dev->list);
+			kfree(dev);
+			mutex_lock(&list_lock);
+			break;
+		}
+		mutex_lock(&list_lock);
+	}
+	mutex_unlock(&list_lock);
+}
+
 int exynos_drm_subdrv_register(struct exynos_drm_subdrv *subdrv)
 {
+	struct exynos_drm_non_kms_dev *dev;
+
 	if (!subdrv)
 		return -EINVAL;
 
-	list_add_tail(&subdrv->list, &exynos_drm_subdrv_list);
+	mutex_lock(&list_lock);
+	if (list_empty(&exynos_drm_subdrv_list)) {
+		mutex_unlock(&list_lock);
+		return -ENODEV;
+	}
+	mutex_unlock(&list_lock);
+
+	mutex_lock(&list_lock);
+	list_for_each_entry(dev, &exynos_drm_subdrv_list, list) {
+		mutex_unlock(&list_lock);
+		if (dev->device_type == subdrv->device_type) {
+			dev->subdrv = subdrv;
+			mutex_lock(&list_lock);
+			break;
+		}
+		mutex_lock(&list_lock);
+	}
+	mutex_unlock(&list_lock);
 
 	return 0;
 }
@@ -68,94 +129,151 @@ EXPORT_SYMBOL_GPL(exynos_drm_subdrv_register);
 
 int exynos_drm_subdrv_unregister(struct exynos_drm_subdrv *subdrv)
 {
+	struct exynos_drm_non_kms_dev *dev;
+
 	if (!subdrv)
 		return -EINVAL;
 
-	list_del(&subdrv->list);
+	mutex_lock(&list_lock);
+	list_for_each_entry(dev, &exynos_drm_subdrv_list, list) {
+		mutex_unlock(&list_lock);
+		if (dev->device_type == subdrv->device_type) {
+			dev->subdrv = NULL;
+			break;
+		}
+		mutex_lock(&list_lock);
+	}
+	mutex_unlock(&list_lock);
 
 	return 0;
 }
 EXPORT_SYMBOL_GPL(exynos_drm_subdrv_unregister);
 
-int exynos_drm_device_subdrv_probe(struct drm_device *dev)
+int exynos_drm_device_subdrv_probe(struct drm_device *drm_dev)
 {
-	struct exynos_drm_subdrv *subdrv, *n;
+	struct exynos_drm_non_kms_dev *dev, *n;
 	int err;
 
-	if (!dev)
+	if (!drm_dev)
 		return -EINVAL;
 
-	list_for_each_entry_safe(subdrv, n, &exynos_drm_subdrv_list, list) {
+	mutex_lock(&list_lock);
+	if (list_empty(&exynos_drm_subdrv_list)) {
+		mutex_unlock(&list_lock);
+		return -EPROBE_DEFER;
+	}
+
+	list_for_each_entry(dev, &exynos_drm_subdrv_list, list) {
+		mutex_unlock(&list_lock);
+
+		/* Retry to probe if there is sub driver not registered yet. */
+		if (!dev->subdrv) {
+			return -EPROBE_DEFER;
+		}
+		mutex_lock(&list_lock);
+	}
+
+	list_for_each_entry_safe(dev, n, &exynos_drm_subdrv_list, list) {
+		struct exynos_drm_subdrv *subdrv = dev->subdrv;
+
+		mutex_unlock(&list_lock);
 		if (subdrv->probe) {
-			subdrv->drm_dev = dev;
+			subdrv->drm_dev = drm_dev;
 
 			/*
 			 * this probe callback would be called by sub driver
 			 * after setting of all resources to this sub driver,
 			 * such as clock, irq and register map are done.
 			 */
-			err = subdrv->probe(dev, subdrv->dev);
+			err = subdrv->probe(drm_dev, subdrv->dev);
 			if (err) {
 				DRM_DEBUG("exynos drm subdrv probe failed.\n");
-				list_del(&subdrv->list);
+				list_del_init(&dev->list);
+				mutex_lock(&list_lock);
 				continue;
 			}
 		}
+		mutex_lock(&list_lock);
 	}
+	mutex_unlock(&list_lock);
 
 	return 0;
 }
 EXPORT_SYMBOL_GPL(exynos_drm_device_subdrv_probe);
 
-int exynos_drm_device_subdrv_remove(struct drm_device *dev)
+int exynos_drm_device_subdrv_remove(struct drm_device *drm_dev)
 {
-	struct exynos_drm_subdrv *subdrv;
+	struct exynos_drm_non_kms_dev *dev;
 
-	if (!dev) {
+	if (!drm_dev) {
 		WARN(1, "Unexpected drm device unregister!\n");
 		return -EINVAL;
 	}
 
-	list_for_each_entry(subdrv, &exynos_drm_subdrv_list, list) {
+	mutex_lock(&list_lock);
+	list_for_each_entry(dev, &exynos_drm_subdrv_list, list) {
+		struct exynos_drm_subdrv *subdrv = dev->subdrv;
+
+		mutex_unlock(&list_lock);
 		if (subdrv->remove)
-			subdrv->remove(dev, subdrv->dev);
+			subdrv->remove(drm_dev, subdrv->dev);
+		mutex_lock(&list_lock);
 	}
+	mutex_unlock(&list_lock);
 
 	return 0;
 }
 EXPORT_SYMBOL_GPL(exynos_drm_device_subdrv_remove);
 
-int exynos_drm_subdrv_open(struct drm_device *dev, struct drm_file *file)
+int exynos_drm_subdrv_open(struct drm_device *drm_dev, struct drm_file *file)
 {
-	struct exynos_drm_subdrv *subdrv;
+	struct exynos_drm_non_kms_dev *dev;
 	int ret;
 
-	list_for_each_entry(subdrv, &exynos_drm_subdrv_list, list) {
+	mutex_lock(&list_lock);
+	list_for_each_entry(dev, &exynos_drm_subdrv_list, list) {
+		struct exynos_drm_subdrv *subdrv = dev->subdrv;
+
+		mutex_unlock(&list_lock);
 		if (subdrv->open) {
-			ret = subdrv->open(dev, subdrv->dev, file);
+			ret = subdrv->open(drm_dev, subdrv->dev, file);
 			if (ret)
 				goto err;
 		}
+		mutex_lock(&list_lock);
 	}
+	mutex_unlock(&list_lock);
 
 	return 0;
 
 err:
-	list_for_each_entry_reverse(subdrv, &subdrv->list, list) {
+	mutex_lock(&list_lock);
+	list_for_each_entry_reverse(dev, &exynos_drm_subdrv_list, list) {
+		struct exynos_drm_subdrv *subdrv = dev->subdrv;
+
+		mutex_unlock(&list_lock);
 		if (subdrv->close)
-			subdrv->close(dev, subdrv->dev, file);
+			subdrv->close(drm_dev, subdrv->dev, file);
+		mutex_lock(&list_lock);
 	}
+	mutex_lock(&list_lock);
 	return ret;
 }
 EXPORT_SYMBOL_GPL(exynos_drm_subdrv_open);
 
-void exynos_drm_subdrv_close(struct drm_device *dev, struct drm_file *file)
+void exynos_drm_subdrv_close(struct drm_device *drm_dev, struct drm_file *file)
 {
-	struct exynos_drm_subdrv *subdrv;
+	struct exynos_drm_non_kms_dev *dev;
+
+	mutex_lock(&list_lock);
+	list_for_each_entry(dev, &exynos_drm_subdrv_list, list) {
+		struct exynos_drm_subdrv *subdrv = dev->subdrv;
 
-	list_for_each_entry(subdrv, &exynos_drm_subdrv_list, list) {
+		mutex_unlock(&list_lock);
 		if (subdrv->close)
-			subdrv->close(dev, subdrv->dev, file);
+			subdrv->close(drm_dev, subdrv->dev, file);
+		mutex_lock(&list_lock);
 	}
+	mutex_unlock(&list_lock);
 }
 EXPORT_SYMBOL_GPL(exynos_drm_subdrv_close);
drivers/gpu/drm/exynos/exynos_drm_drv.c +2 -48

78 lines not on this page · raw message

drivers/gpu/drm/exynos/exynos_drm_drv.h +12 -16
index 352a9f9..5b3305c 100644
@@ -41,6 +41,13 @@ enum exynos_drm_output_type {
 	EXYNOS_DISPLAY_TYPE_VIDI,
 };
 
+/* This enumerates non kms device type. */
+enum exynos_drm_non_kms_type {
+	EXYNOS_DRM_NON_KMS_NONE,
+	EXYNOS_DRM_NON_KMS_G2D,
+	EXYNOS_DRM_NON_KMS_IPP,
+};
+
 /*
  * Exynos drm common overlay structure.
  *
@@ -259,10 +266,10 @@ struct exynos_drm_private {
 /*
  * Exynos drm sub driver structure.
  *
- * @list: sub driver has its own list object to register to exynos drm driver.
  * @dev: pointer to device object for subdrv device driver.
  * @drm_dev: pointer to drm_device and this pointer would be set
  *	when sub driver calls exynos_drm_subdrv_register().
+ * @device_type: non kms device type.
  * @probe: this callback would be called by exynos drm driver after
  *     subdrv is registered to it.
  * @remove: this callback is used to release resources created
@@ -271,9 +278,9 @@ struct exynos_drm_private {
  * @close: this would be called with drm device file close.
  */
 struct exynos_drm_subdrv {
-	struct list_head list;
 	struct device *dev;
 	struct drm_device *drm_dev;
+	unsigned int device_type;
 
 	int (*probe)(struct drm_device *drm_dev, struct device *dev);
 	void (*remove)(struct drm_device *drm_dev, struct device *dev);
@@ -294,15 +301,6 @@ int exynos_drm_device_subdrv_remove(struct drm_device *dev);
 int exynos_drm_subdrv_open(struct drm_device *dev, struct drm_file *file);
 void exynos_drm_subdrv_close(struct drm_device *dev, struct drm_file *file);
 
-#ifdef CONFIG_DRM_EXYNOS_IPP
-int exynos_platform_device_ipp_register(void);
-void exynos_platform_device_ipp_unregister(void);
-#else
-static inline int exynos_platform_device_ipp_register(void) { return 0; }
-static inline void exynos_platform_device_ipp_unregister(void) {}
-#endif
-
-
 #ifdef CONFIG_DRM_EXYNOS_DPI
 struct exynos_drm_display * exynos_dpi_probe(struct device *dev);
 int exynos_dpi_remove(struct device *dev);
@@ -331,11 +329,9 @@ int exynos_drm_component_add(struct device *dev,
 void exynos_drm_component_del(struct device *dev,
 				enum exynos_drm_device_type dev_type);
 
+extern int exynos_drm_non_kms_register(unsigned int device_type);
+extern void exynos_drm_non_kms_unregister(unsigned int device_type);
+
 extern struct platform_driver exynos_drm_common_hdmi_driver;
 extern struct platform_driver vidi_driver;
-extern struct platform_driver g2d_driver;
-extern struct platform_driver fimc_driver;
-extern struct platform_driver rotator_driver;
-extern struct platform_driver gsc_driver;
-extern struct platform_driver ipp_driver;
 #endif
drivers/gpu/drm/exynos/exynos_drm_fimc.c +13 -0
index 68d38eb..05000ee 100644
@@ -1860,3 +1860,16 @@ struct platform_driver fimc_driver = {
 	},
 };
 
+static int fimc_driver_init(void)
+{
+	return platform_driver_register(&fimc_driver);
+}
+
+static void fimc_driver_exit(void)
+{
+	platform_driver_unregister(&fimc_driver);
+}
+
+module_init(fimc_driver_init);
+module_exit(fimc_driver_exit);
+
drivers/gpu/drm/exynos/exynos_drm_g2d.c +34 -0
index 6ff8599..fa37603 100644
@@ -1464,6 +1464,7 @@ static int g2d_probe(struct platform_device *pdev)
 	platform_set_drvdata(pdev, g2d);
 
 	subdrv = &g2d->subdrv;
+	subdrv->device_type = EXYNOS_DRM_NON_KMS_G2D;
 	subdrv->dev = dev;
 	subdrv->probe = g2d_subdrv_probe;
 	subdrv->remove = g2d_subdrv_remove;
@@ -1585,3 +1586,36 @@ struct platform_driver g2d_driver = {
 		.of_match_table = exynos_g2d_match,
 	},
 };
+
+static int exynos_g2d_init(void)
+{
+	int ret;
+
+	/*
+	 * Register non kms driver only in case that g2d device node exists
+	 * and the device node is enabled.
+	 *
+	 * TODO. this code should be replaced with super device node.
+	 */
+	if (!of_machine_is_compatible("samsung,exynos5250-g2d") &&
+			!of_machine_is_compatible("samsung,exynos4212-g2d"))
+		return -ENODEV;
+
+	ret = exynos_drm_non_kms_register(EXYNOS_DRM_NON_KMS_G2D);
+	if (ret)
+		return ret;
+
+	ret = platform_driver_register(&g2d_driver);
+	if (ret)
+		exynos_drm_non_kms_unregister(EXYNOS_DRM_NON_KMS_G2D);
+
+	return ret;
+}
+
+static void exynos_g2d_exit(void)
+{
+	platform_driver_unregister(&g2d_driver);
+}
+
+module_init(exynos_g2d_init);
+module_exit(exynos_g2d_exit);
drivers/gpu/drm/exynos/exynos_drm_gsc.c +12 -0
index c6a013f..0cbed55 100644
@@ -1799,3 +1799,15 @@ struct platform_driver gsc_driver = {
 	},
 };
 
+static int gsc_driver_init(void)
+{
+	return platform_driver_register(&gsc_driver);
+}
+
+static void gsc_driver_exit(void)
+{
+	platform_driver_unregister(&gsc_driver);
+}
+
+module_init(gsc_driver_init);
+module_exit(gsc_driver_exit);
drivers/gpu/drm/exynos/exynos_drm_ipp.c +37 -2
index 00d74b1..559ee65 100644
@@ -102,7 +102,7 @@ static LIST_HEAD(exynos_drm_ippdrv_list);
 static DEFINE_MUTEX(exynos_drm_ippdrv_lock);
 static BLOCKING_NOTIFIER_HEAD(exynos_drm_ippnb_list);
 
-int exynos_platform_device_ipp_register(void)
+static int exynos_platform_device_ipp_register(void)
 {
 	struct platform_device *pdev;
 
@@ -118,7 +118,7 @@ int exynos_platform_device_ipp_register(void)
 	return 0;
 }
 
-void exynos_platform_device_ipp_unregister(void)
+static void exynos_platform_device_ipp_unregister(void)
 {
 	if (exynos_drm_ipp_pdev) {
 		platform_device_unregister(exynos_drm_ipp_pdev);
@@ -1718,6 +1718,7 @@ static int ipp_probe(struct platform_device *pdev)
 
 	/* set sub driver informations */
 	subdrv = &ctx->subdrv;
+	subdrv->device_type = EXYNOS_DRM_NON_KMS_IPP;
 	subdrv->dev = dev;
 	subdrv->probe = ipp_subdrv_probe;
 	subdrv->remove = ipp_subdrv_remove;
@@ -1773,3 +1774,37 @@ struct platform_driver ipp_driver = {
 	},
 };
 
+static int ipp_driver_init(void)
+{
+	int ret;
+
+	ret = exynos_drm_non_kms_register(EXYNOS_DRM_NON_KMS_IPP);
+	if (ret)
+		return ret;
+
+	ret = exynos_platform_device_ipp_register();
+	if (ret)
+		goto err_unregister_non_kms;
+
+	ret = platform_driver_register(&ipp_driver);
+	if (ret)
+		goto err_unregister_ipp_device;
+
+	return ret;
+
+err_unregister_ipp_device:
+	exynos_platform_device_ipp_unregister();
+err_unregister_non_kms:
+	exynos_drm_non_kms_unregister(EXYNOS_DRM_NON_KMS_IPP);
+
+	return ret;
+}
+
+static void ipp_driver_exit(void)
+{
+	platform_driver_unregister(&ipp_driver);
+}
+
+module_init(ipp_driver_init);
+module_exit(ipp_driver_exit);
+
drivers/gpu/drm/exynos/exynos_drm_rotator.c +13 -0
index b6a37d4..ffa0166 100644
@@ -854,3 +854,16 @@ struct platform_driver rotator_driver = {
 		.of_match_table = exynos_rotator_match,
 	},
 };
+
+static int rotator_driver_init(void)
+{
+	return platform_driver_register(&rotator_driver);
+}
+
+static void rotator_driver_exit(void)
+{
+	platform_driver_unregister(&rotator_driver);
+}
+
+module_init(rotator_driver_init);
+module_exit(rotator_driver_exit);
Signature · 1 line
1.7.9.5
author maintainer
#5 lore raw

RFC PATCH v2 1/1 drm/exynos: make non kms drivers to be indenpendent modules

This patch makes non kms drivers to be independent modules. For this, it removes all register codes to non kms drivers from exynos_drm_drv module and adds module_init/exit for each non kms driver so that each non kms driver can be called independently.

In addition, this patch adds non kms register/unregister functions to exynos_drm_core module and also modifies existing codes relevant to sub driver.

The idea is that non kms driver is registered by entry point, module_init, of each non kms driver and sets its own sub driver to registered non kms driver object when the sub driver is probed. For this, this patch adds a new structure, exynos_drm_non_kms_dev, to exynos_drm_core module.

Changelog v2:
- check if available g2d device node.
- return 0 instead of -EPROBE_DEFER in case of no non kms device registered. This case is not error.

---
 drivers/gpu/drm/exynos/exynos_drm_core.c    |  164 +++++++++++++++++++++++----
 drivers/gpu/drm/exynos/exynos_drm_drv.c     |   50 +-------
 drivers/gpu/drm/exynos/exynos_drm_drv.h     |   28 ++---
 drivers/gpu/drm/exynos/exynos_drm_fimc.c    |   13 +++
 drivers/gpu/drm/exynos/exynos_drm_g2d.c     |   42 +++++++
 drivers/gpu/drm/exynos/exynos_drm_gsc.c     |   12 ++
 drivers/gpu/drm/exynos/exynos_drm_ipp.c     |   39 ++++++-
 drivers/gpu/drm/exynos/exynos_drm_rotator.c |   13 +++
 8 files changed, 271 insertions(+), 90 deletions(-)
drivers/gpu/drm/exynos/exynos_drm_core.c +140 -24
index 4c9f972..715a0ad 100644
@@ -19,6 +19,13 @@
 #include "exynos_drm_fbdev.h"
 
 static LIST_HEAD(exynos_drm_subdrv_list);
+DEFINE_MUTEX(list_lock);
+
+struct exynos_drm_non_kms_dev {
+	struct list_head list;
+	struct exynos_drm_subdrv *subdrv;
+	unsigned int device_type;
+};
 
 int exynos_drm_create_enc_conn(struct drm_device *dev,
 					struct exynos_drm_display *display)
@@ -55,12 +62,66 @@ err_destroy_encoder:
 	return ret;
 }
 
+int exynos_drm_non_kms_register(unsigned int device_type)
+{
+	struct exynos_drm_non_kms_dev *dev;
+
+	dev = kzalloc(sizeof(*dev), GFP_KERNEL);
+	if (!dev)
+		return -ENOMEM;
+
+	dev->device_type = device_type;
+
+	mutex_lock(&list_lock);
+	list_add_tail(&dev->list, &exynos_drm_subdrv_list);
+	mutex_unlock(&list_lock);
+
+	return 0;
+}
+
+void exynos_drm_non_kms_unregister(unsigned int device_type)
+{
+	struct exynos_drm_non_kms_dev *dev, *next;
+
+	mutex_lock(&list_lock);
+	list_for_each_entry_safe(dev, next, &exynos_drm_subdrv_list, list) {
+		mutex_unlock(&list_lock);
+		if (dev->device_type == device_type) {
+			list_del_init(&dev->list);
+			kfree(dev);
+			mutex_lock(&list_lock);
+			break;
+		}
+		mutex_lock(&list_lock);
+	}
+	mutex_unlock(&list_lock);
+}
+
 int exynos_drm_subdrv_register(struct exynos_drm_subdrv *subdrv)
 {
+	struct exynos_drm_non_kms_dev *dev;
+
 	if (!subdrv)
 		return -EINVAL;
 
-	list_add_tail(&subdrv->list, &exynos_drm_subdrv_list);
+	mutex_lock(&list_lock);
+	if (list_empty(&exynos_drm_subdrv_list)) {
+		mutex_unlock(&list_lock);
+		return -ENODEV;
+	}
+	mutex_unlock(&list_lock);
+
+	mutex_lock(&list_lock);
+	list_for_each_entry(dev, &exynos_drm_subdrv_list, list) {
+		mutex_unlock(&list_lock);
+		if (dev->device_type == subdrv->device_type) {
+			dev->subdrv = subdrv;
+			mutex_lock(&list_lock);
+			break;
+		}
+		mutex_lock(&list_lock);
+	}
+	mutex_unlock(&list_lock);
 
 	return 0;
 }
@@ -68,94 +129,149 @@ EXPORT_SYMBOL_GPL(exynos_drm_subdrv_register);
 
 int exynos_drm_subdrv_unregister(struct exynos_drm_subdrv *subdrv)
 {
+	struct exynos_drm_non_kms_dev *dev;
+
 	if (!subdrv)
 		return -EINVAL;
 
-	list_del(&subdrv->list);
+	mutex_lock(&list_lock);
+	list_for_each_entry(dev, &exynos_drm_subdrv_list, list) {
+		mutex_unlock(&list_lock);
+		if (dev->device_type == subdrv->device_type) {
+			dev->subdrv = NULL;
+			break;
+		}
+		mutex_lock(&list_lock);
+	}
+	mutex_unlock(&list_lock);
 
 	return 0;
 }
 EXPORT_SYMBOL_GPL(exynos_drm_subdrv_unregister);
 
-int exynos_drm_device_subdrv_probe(struct drm_device *dev)
+int exynos_drm_device_subdrv_probe(struct drm_device *drm_dev)
 {
-	struct exynos_drm_subdrv *subdrv, *n;
+	struct exynos_drm_non_kms_dev *dev, *n;
 	int err;
 
-	if (!dev)
+	if (!drm_dev)
 		return -EINVAL;
 
-	list_for_each_entry_safe(subdrv, n, &exynos_drm_subdrv_list, list) {
+	mutex_lock(&list_lock);
+	if (list_empty(&exynos_drm_subdrv_list)) {
+		mutex_unlock(&list_lock);
+		return 0;
+	}
+
+	list_for_each_entry(dev, &exynos_drm_subdrv_list, list) {
+		mutex_unlock(&list_lock);
+		/* Retry to probe if there is sub driver not registered yet. */
+		if (!dev->subdrv)
+			return -EPROBE_DEFER;
+		mutex_lock(&list_lock);
+	}
+
+	list_for_each_entry_safe(dev, n, &exynos_drm_subdrv_list, list) {
+		struct exynos_drm_subdrv *subdrv = dev->subdrv;
+
+		mutex_unlock(&list_lock);
 		if (subdrv->probe) {
-			subdrv->drm_dev = dev;
+			subdrv->drm_dev = drm_dev;
 
 			/*
 			 * this probe callback would be called by sub driver
 			 * after setting of all resources to this sub driver,
 			 * such as clock, irq and register map are done.
 			 */
-			err = subdrv->probe(dev, subdrv->dev);
+			err = subdrv->probe(drm_dev, subdrv->dev);
 			if (err) {
 				DRM_DEBUG("exynos drm subdrv probe failed.\n");
-				list_del(&subdrv->list);
+				list_del_init(&dev->list);
+				mutex_lock(&list_lock);
 				continue;
 			}
 		}
+		mutex_lock(&list_lock);
 	}
+	mutex_unlock(&list_lock);
 
 	return 0;
 }
 EXPORT_SYMBOL_GPL(exynos_drm_device_subdrv_probe);
 
-int exynos_drm_device_subdrv_remove(struct drm_device *dev)
+int exynos_drm_device_subdrv_remove(struct drm_device *drm_dev)
 {
-	struct exynos_drm_subdrv *subdrv;
+	struct exynos_drm_non_kms_dev *dev;
 
-	if (!dev) {
+	if (!drm_dev) {
 		WARN(1, "Unexpected drm device unregister!\n");
 		return -EINVAL;
 	}
 
-	list_for_each_entry(subdrv, &exynos_drm_subdrv_list, list) {
+	mutex_lock(&list_lock);
+	list_for_each_entry(dev, &exynos_drm_subdrv_list, list) {
+		struct exynos_drm_subdrv *subdrv = dev->subdrv;
+
+		mutex_unlock(&list_lock);
 		if (subdrv->remove)
-			subdrv->remove(dev, subdrv->dev);
+			subdrv->remove(drm_dev, subdrv->dev);
+		mutex_lock(&list_lock);
 	}
+	mutex_unlock(&list_lock);
 
 	return 0;
 }
 EXPORT_SYMBOL_GPL(exynos_drm_device_subdrv_remove);
 
-int exynos_drm_subdrv_open(struct drm_device *dev, struct drm_file *file)
+int exynos_drm_subdrv_open(struct drm_device *drm_dev, struct drm_file *file)
 {
-	struct exynos_drm_subdrv *subdrv;
+	struct exynos_drm_non_kms_dev *dev;
 	int ret;
 
-	list_for_each_entry(subdrv, &exynos_drm_subdrv_list, list) {
+	mutex_lock(&list_lock);
+	list_for_each_entry(dev, &exynos_drm_subdrv_list, list) {
+		struct exynos_drm_subdrv *subdrv = dev->subdrv;
+
+		mutex_unlock(&list_lock);
 		if (subdrv->open) {
-			ret = subdrv->open(dev, subdrv->dev, file);
+			ret = subdrv->open(drm_dev, subdrv->dev, file);
 			if (ret)
 				goto err;
 		}
+		mutex_lock(&list_lock);
 	}
+	mutex_unlock(&list_lock);
 
 	return 0;
 
 err:
-	list_for_each_entry_reverse(subdrv, &subdrv->list, list) {
+	mutex_lock(&list_lock);
+	list_for_each_entry_reverse(dev, &exynos_drm_subdrv_list, list) {
+		struct exynos_drm_subdrv *subdrv = dev->subdrv;
+
+		mutex_unlock(&list_lock);
 		if (subdrv->close)
-			subdrv->close(dev, subdrv->dev, file);
+			subdrv->close(drm_dev, subdrv->dev, file);
+		mutex_lock(&list_lock);
 	}
+	mutex_lock(&list_lock);
 	return ret;
 }
 EXPORT_SYMBOL_GPL(exynos_drm_subdrv_open);
 
-void exynos_drm_subdrv_close(struct drm_device *dev, struct drm_file *file)
+void exynos_drm_subdrv_close(struct drm_device *drm_dev, struct drm_file *file)
 {
-	struct exynos_drm_subdrv *subdrv;
+	struct exynos_drm_non_kms_dev *dev;
+
+	mutex_lock(&list_lock);
+	list_for_each_entry(dev, &exynos_drm_subdrv_list, list) {
+		struct exynos_drm_subdrv *subdrv = dev->subdrv;
 
-	list_for_each_entry(subdrv, &exynos_drm_subdrv_list, list) {
+		mutex_unlock(&list_lock);
 		if (subdrv->close)
-			subdrv->close(dev, subdrv->dev, file);
+			subdrv->close(drm_dev, subdrv->dev, file);
+		mutex_lock(&list_lock);
 	}
+	mutex_unlock(&list_lock);
 }
 EXPORT_SYMBOL_GPL(exynos_drm_subdrv_close);
drivers/gpu/drm/exynos/exynos_drm_drv.c +2 -48

78 lines not on this page · raw message

drivers/gpu/drm/exynos/exynos_drm_drv.h +12 -16
index 352a9f9..5b3305c 100644
@@ -41,6 +41,13 @@ enum exynos_drm_output_type {
 	EXYNOS_DISPLAY_TYPE_VIDI,
 };
 
+/* This enumerates non kms device type. */
+enum exynos_drm_non_kms_type {
+	EXYNOS_DRM_NON_KMS_NONE,
+	EXYNOS_DRM_NON_KMS_G2D,
+	EXYNOS_DRM_NON_KMS_IPP,
+};
+
 /*
  * Exynos drm common overlay structure.
  *
@@ -259,10 +266,10 @@ struct exynos_drm_private {
 /*
  * Exynos drm sub driver structure.
  *
- * @list: sub driver has its own list object to register to exynos drm driver.
  * @dev: pointer to device object for subdrv device driver.
  * @drm_dev: pointer to drm_device and this pointer would be set
  *	when sub driver calls exynos_drm_subdrv_register().
+ * @device_type: non kms device type.
  * @probe: this callback would be called by exynos drm driver after
  *     subdrv is registered to it.
  * @remove: this callback is used to release resources created
@@ -271,9 +278,9 @@ struct exynos_drm_private {
  * @close: this would be called with drm device file close.
  */
 struct exynos_drm_subdrv {
-	struct list_head list;
 	struct device *dev;
 	struct drm_device *drm_dev;
+	unsigned int device_type;
 
 	int (*probe)(struct drm_device *drm_dev, struct device *dev);
 	void (*remove)(struct drm_device *drm_dev, struct device *dev);
@@ -294,15 +301,6 @@ int exynos_drm_device_subdrv_remove(struct drm_device *dev);
 int exynos_drm_subdrv_open(struct drm_device *dev, struct drm_file *file);
 void exynos_drm_subdrv_close(struct drm_device *dev, struct drm_file *file);
 
-#ifdef CONFIG_DRM_EXYNOS_IPP
-int exynos_platform_device_ipp_register(void);
-void exynos_platform_device_ipp_unregister(void);
-#else
-static inline int exynos_platform_device_ipp_register(void) { return 0; }
-static inline void exynos_platform_device_ipp_unregister(void) {}
-#endif
-
-
 #ifdef CONFIG_DRM_EXYNOS_DPI
 struct exynos_drm_display * exynos_dpi_probe(struct device *dev);
 int exynos_dpi_remove(struct device *dev);
@@ -331,11 +329,9 @@ int exynos_drm_component_add(struct device *dev,
 void exynos_drm_component_del(struct device *dev,
 				enum exynos_drm_device_type dev_type);
 
+extern int exynos_drm_non_kms_register(unsigned int device_type);
+extern void exynos_drm_non_kms_unregister(unsigned int device_type);
+
 extern struct platform_driver exynos_drm_common_hdmi_driver;
 extern struct platform_driver vidi_driver;
-extern struct platform_driver g2d_driver;
-extern struct platform_driver fimc_driver;
-extern struct platform_driver rotator_driver;
-extern struct platform_driver gsc_driver;
-extern struct platform_driver ipp_driver;
 #endif
drivers/gpu/drm/exynos/exynos_drm_fimc.c +13 -0
index 68d38eb..05000ee 100644
@@ -1860,3 +1860,16 @@ struct platform_driver fimc_driver = {
 	},
 };
 
+static int fimc_driver_init(void)
+{
+	return platform_driver_register(&fimc_driver);
+}
+
+static void fimc_driver_exit(void)
+{
+	platform_driver_unregister(&fimc_driver);
+}
+
+module_init(fimc_driver_init);
+module_exit(fimc_driver_exit);
+
drivers/gpu/drm/exynos/exynos_drm_g2d.c +42 -0

51 lines not on this page · raw message

drivers/gpu/drm/exynos/exynos_drm_gsc.c +12 -0
index c6a013f..0cbed55 100644
@@ -1799,3 +1799,15 @@ struct platform_driver gsc_driver = {
 	},
 };
 
+static int gsc_driver_init(void)
+{
+	return platform_driver_register(&gsc_driver);
+}
+
+static void gsc_driver_exit(void)
+{
+	platform_driver_unregister(&gsc_driver);
+}
+
+module_init(gsc_driver_init);
+module_exit(gsc_driver_exit);
drivers/gpu/drm/exynos/exynos_drm_ipp.c +37 -2
index 00d74b1..559ee65 100644
@@ -102,7 +102,7 @@ static LIST_HEAD(exynos_drm_ippdrv_list);
 static DEFINE_MUTEX(exynos_drm_ippdrv_lock);
 static BLOCKING_NOTIFIER_HEAD(exynos_drm_ippnb_list);
 
-int exynos_platform_device_ipp_register(void)
+static int exynos_platform_device_ipp_register(void)
 {
 	struct platform_device *pdev;
 
@@ -118,7 +118,7 @@ int exynos_platform_device_ipp_register(void)
 	return 0;
 }
 
-void exynos_platform_device_ipp_unregister(void)
+static void exynos_platform_device_ipp_unregister(void)
 {
 	if (exynos_drm_ipp_pdev) {
 		platform_device_unregister(exynos_drm_ipp_pdev);
@@ -1718,6 +1718,7 @@ static int ipp_probe(struct platform_device *pdev)
 
 	/* set sub driver informations */
 	subdrv = &ctx->subdrv;
+	subdrv->device_type = EXYNOS_DRM_NON_KMS_IPP;
 	subdrv->dev = dev;
 	subdrv->probe = ipp_subdrv_probe;
 	subdrv->remove = ipp_subdrv_remove;
@@ -1773,3 +1774,37 @@ struct platform_driver ipp_driver = {
 	},
 };
 
+static int ipp_driver_init(void)
+{
+	int ret;
+
+	ret = exynos_drm_non_kms_register(EXYNOS_DRM_NON_KMS_IPP);
+	if (ret)
+		return ret;
+
+	ret = exynos_platform_device_ipp_register();
+	if (ret)
+		goto err_unregister_non_kms;
+
+	ret = platform_driver_register(&ipp_driver);
+	if (ret)
+		goto err_unregister_ipp_device;
+
+	return ret;
+
+err_unregister_ipp_device:
+	exynos_platform_device_ipp_unregister();
+err_unregister_non_kms:
+	exynos_drm_non_kms_unregister(EXYNOS_DRM_NON_KMS_IPP);
+
+	return ret;
+}
+
+static void ipp_driver_exit(void)
+{
+	platform_driver_unregister(&ipp_driver);
+}
+
+module_init(ipp_driver_init);
+module_exit(ipp_driver_exit);
+
drivers/gpu/drm/exynos/exynos_drm_rotator.c +13 -0
index b6a37d4..ffa0166 100644
@@ -854,3 +854,16 @@ struct platform_driver rotator_driver = {
 		.of_match_table = exynos_rotator_match,
 	},
 };
+
+static int rotator_driver_init(void)
+{
+	return platform_driver_register(&rotator_driver);
+}
+
+static void rotator_driver_exit(void)
+{
+	platform_driver_unregister(&rotator_driver);
+}
+
+module_init(rotator_driver_init);
+module_exit(rotator_driver_exit);
Signature · 1 line
1.7.9.5
#6 lore raw

Re: [RFC PATCH v2] drm/exynos: make non kms drivers to be indenpendent modules

Hi Inki,

There are 3 comments below.

Quoted 94 lines · Inki Dae

This patch makes non kms drivers to be independent modules. For this, it removes all register codes to non kms drivers from exynos_drm_drv module and adds module_init/exit for each non kms driver so that each non kms driver can be called independently.

In addition, this patch adds non kms register/unregister functions to exynos_drm_core module and also modifies existing codes relevant to sub driver.

The idea is that non kms driver is registered by entry point, module_init, of each non kms driver and sets its own sub driver to registered non kms driver object when the sub driver is probed. For this, this patch adds a new structure, exynos_drm_non_kms_dev, to exynos_drm_core module.

Changelog v2:
- check if available g2d device node.
- return 0 instead of -EPROBE_DEFER in case of no non kms device registered. This case is not error.

---
  drivers/gpu/drm/exynos/exynos_drm_core.c    |  164 +++++++++++++++++++++++----
  drivers/gpu/drm/exynos/exynos_drm_drv.c     |   50 +-------
  drivers/gpu/drm/exynos/exynos_drm_drv.h     |   28 ++---
  drivers/gpu/drm/exynos/exynos_drm_fimc.c    |   13 +++
  drivers/gpu/drm/exynos/exynos_drm_g2d.c     |   42 +++++++
  drivers/gpu/drm/exynos/exynos_drm_gsc.c     |   12 ++
  drivers/gpu/drm/exynos/exynos_drm_ipp.c     |   39 ++++++-
  drivers/gpu/drm/exynos/exynos_drm_rotator.c |   13 +++
  8 files changed, 271 insertions(+), 90 deletions(-)
drivers/gpu/drm/exynos/exynos_drm_core.c +44 -0
index 4c9f972..715a0ad 100644
@@ -19,6 +19,13 @@
  #include "exynos_drm_fbdev.h"
 
  static LIST_HEAD(exynos_drm_subdrv_list);
+DEFINE_MUTEX(list_lock);
+
+struct exynos_drm_non_kms_dev {
+	struct list_head list;
+	struct exynos_drm_subdrv *subdrv;
+	unsigned int device_type;
+};
 
  int exynos_drm_create_enc_conn(struct drm_device *dev,
  					struct exynos_drm_display *display)
@@ -55,12 +62,66 @@ err_destroy_encoder:
  	return ret;
  }
 
+int exynos_drm_non_kms_register(unsigned int device_type)
+{
+	struct exynos_drm_non_kms_dev *dev;
+
+	dev = kzalloc(sizeof(*dev), GFP_KERNEL);
+	if (!dev)
+		return -ENOMEM;
+
+	dev->device_type = device_type;
+
+	mutex_lock(&list_lock);
+	list_add_tail(&dev->list, &exynos_drm_subdrv_list);
+	mutex_unlock(&list_lock);
+
+	return 0;
+}
+
+void exynos_drm_non_kms_unregister(unsigned int device_type)
+{
+	struct exynos_drm_non_kms_dev *dev, *next;
+
+	mutex_lock(&list_lock);
+	list_for_each_entry_safe(dev, next, &exynos_drm_subdrv_list, list) {
+		mutex_unlock(&list_lock);
+		if (dev->device_type == device_type) {
+			list_del_init(&dev->list);
+			kfree(dev);
+			mutex_lock(&list_lock);
+			break;
+		}
+		mutex_lock(&list_lock);
+	}
+	mutex_unlock(&list_lock);
+}
+
  int exynos_drm_subdrv_register(struct exynos_drm_subdrv *subdrv)
  {
+	struct exynos_drm_non_kms_dev *dev;
+

drivers/gpu/drm/exynos/exynos_drm_core.c err_destroy_encoder: · line 112

Quoted 10 lines
drivers/gpu/drm/exynos/exynos_drm_core.c +6 -1
  	if (!subdrv)
  		return -EINVAL;
 
-	list_add_tail(&subdrv->list, &exynos_drm_subdrv_list);
+	mutex_lock(&list_lock);
+	if (list_empty(&exynos_drm_subdrv_list)) {
+		mutex_unlock(&list_lock);
+		return -ENODEV;
+	}
+	mutex_unlock(&list_lock);

The list_for_each_entry() could handle empty list, so list_empty() could be removed.

Quoted 48 lines
drivers/gpu/drm/exynos/exynos_drm_core.c +26 -4
+
+	mutex_lock(&list_lock);
+	list_for_each_entry(dev, &exynos_drm_subdrv_list, list) {
+		mutex_unlock(&list_lock);
+		if (dev->device_type == subdrv->device_type) {
+			dev->subdrv = subdrv;
+			mutex_lock(&list_lock);
+			break;
+		}
+		mutex_lock(&list_lock);
+	}
+	mutex_unlock(&list_lock);
 
  	return 0;
  }
@@ -68,94 +129,149 @@ EXPORT_SYMBOL_GPL(exynos_drm_subdrv_register);
 
  int exynos_drm_subdrv_unregister(struct exynos_drm_subdrv *subdrv)
  {
+	struct exynos_drm_non_kms_dev *dev;
+
  	if (!subdrv)
  		return -EINVAL;
 
-	list_del(&subdrv->list);
+	mutex_lock(&list_lock);
+	list_for_each_entry(dev, &exynos_drm_subdrv_list, list) {
+		mutex_unlock(&list_lock);
+		if (dev->device_type == subdrv->device_type) {
+			dev->subdrv = NULL;
+			break;
+		}
+		mutex_lock(&list_lock);
+	}
+	mutex_unlock(&list_lock);
 
  	return 0;
  }
  EXPORT_SYMBOL_GPL(exynos_drm_subdrv_unregister);
 
-int exynos_drm_device_subdrv_probe(struct drm_device *dev)
+int exynos_drm_device_subdrv_probe(struct drm_device *drm_dev)
  {
-	struct exynos_drm_subdrv *subdrv, *n;
+	struct exynos_drm_non_kms_dev *dev, *n;
  	int err;
 
-	if (!dev)

drivers/gpu/drm/exynos/exynos_drm_core.c EXPORT_SYMBOL_GPL(exynos_drm_subdrv_register); · line 165

Quoted 10 lines
drivers/gpu/drm/exynos/exynos_drm_core.c +7 -1
+	if (!drm_dev)
  		return -EINVAL;
 
-	list_for_each_entry_safe(subdrv, n, &exynos_drm_subdrv_list, list) {
+	mutex_lock(&list_lock);
+	if (list_empty(&exynos_drm_subdrv_list)) {
+		mutex_unlock(&list_lock);
+		return 0;
+	}
+

ditto

Quoted 96 lines
drivers/gpu/drm/exynos/exynos_drm_core.c +40 -13
+	list_for_each_entry(dev, &exynos_drm_subdrv_list, list) {
+		mutex_unlock(&list_lock);
+		/* Retry to probe if there is sub driver not registered yet. */
+		if (!dev->subdrv)
+			return -EPROBE_DEFER;
+		mutex_lock(&list_lock);
+	}
+
+	list_for_each_entry_safe(dev, n, &exynos_drm_subdrv_list, list) {
+		struct exynos_drm_subdrv *subdrv = dev->subdrv;
+
+		mutex_unlock(&list_lock);
  		if (subdrv->probe) {
-			subdrv->drm_dev = dev;
+			subdrv->drm_dev = drm_dev;
 
  			/*
  			 * this probe callback would be called by sub driver
  			 * after setting of all resources to this sub driver,
  			 * such as clock, irq and register map are done.
  			 */
-			err = subdrv->probe(dev, subdrv->dev);
+			err = subdrv->probe(drm_dev, subdrv->dev);
  			if (err) {
  				DRM_DEBUG("exynos drm subdrv probe failed.\n");
-				list_del(&subdrv->list);
+				list_del_init(&dev->list);
+				mutex_lock(&list_lock);
  				continue;
  			}
  		}
+		mutex_lock(&list_lock);
  	}
+	mutex_unlock(&list_lock);
 
  	return 0;
  }
  EXPORT_SYMBOL_GPL(exynos_drm_device_subdrv_probe);
 
-int exynos_drm_device_subdrv_remove(struct drm_device *dev)
+int exynos_drm_device_subdrv_remove(struct drm_device *drm_dev)
  {
-	struct exynos_drm_subdrv *subdrv;
+	struct exynos_drm_non_kms_dev *dev;
 
-	if (!dev) {
+	if (!drm_dev) {
  		WARN(1, "Unexpected drm device unregister!\n");
  		return -EINVAL;
  	}
 
-	list_for_each_entry(subdrv, &exynos_drm_subdrv_list, list) {
+	mutex_lock(&list_lock);
+	list_for_each_entry(dev, &exynos_drm_subdrv_list, list) {
+		struct exynos_drm_subdrv *subdrv = dev->subdrv;
+
+		mutex_unlock(&list_lock);
  		if (subdrv->remove)
-			subdrv->remove(dev, subdrv->dev);
+			subdrv->remove(drm_dev, subdrv->dev);
+		mutex_lock(&list_lock);
  	}
+	mutex_unlock(&list_lock);
 
  	return 0;
  }
  EXPORT_SYMBOL_GPL(exynos_drm_device_subdrv_remove);
 
-int exynos_drm_subdrv_open(struct drm_device *dev, struct drm_file *file)
+int exynos_drm_subdrv_open(struct drm_device *drm_dev, struct drm_file *file)
  {
-	struct exynos_drm_subdrv *subdrv;
+	struct exynos_drm_non_kms_dev *dev;
  	int ret;
 
-	list_for_each_entry(subdrv, &exynos_drm_subdrv_list, list) {
+	mutex_lock(&list_lock);
+	list_for_each_entry(dev, &exynos_drm_subdrv_list, list) {
+		struct exynos_drm_subdrv *subdrv = dev->subdrv;
+
+		mutex_unlock(&list_lock);
  		if (subdrv->open) {
-			ret = subdrv->open(dev, subdrv->dev, file);
+			ret = subdrv->open(drm_dev, subdrv->dev, file);
  			if (ret)
  				goto err;
  		}
+		mutex_lock(&list_lock);
  	}
+	mutex_unlock(&list_lock);
 
  	return 0;
 
  err:
-	list_for_each_entry_reverse(subdrv, &subdrv->list, list) {
+	mutex_lock(&list_lock);

drivers/gpu/drm/exynos/exynos_drm_core.c EXPORT_SYMBOL_GPL(exynos_drm_subdrv_register); · line 257

Quoted 10 lines
drivers/gpu/drm/exynos/exynos_drm_core.c +7 -1
+	list_for_each_entry_reverse(dev, &exynos_drm_subdrv_list, list) {
+		struct exynos_drm_subdrv *subdrv = dev->subdrv;
+
+		mutex_unlock(&list_lock);
  		if (subdrv->close)
-			subdrv->close(dev, subdrv->dev, file);
+			subdrv->close(drm_dev, subdrv->dev, file);
+		mutex_lock(&list_lock);
  	}
+	mutex_lock(&list_lock);

mutex_unlock(&list_lock);

Thank you.
Best regards YJ

Quoted 369 lines
drivers/gpu/drm/exynos/exynos_drm_core.c +10 -4
  	return ret;
  }
  EXPORT_SYMBOL_GPL(exynos_drm_subdrv_open);
 
-void exynos_drm_subdrv_close(struct drm_device *dev, struct drm_file *file)
+void exynos_drm_subdrv_close(struct drm_device *drm_dev, struct drm_file *file)
  {
-	struct exynos_drm_subdrv *subdrv;
+	struct exynos_drm_non_kms_dev *dev;
+
+	mutex_lock(&list_lock);
+	list_for_each_entry(dev, &exynos_drm_subdrv_list, list) {
+		struct exynos_drm_subdrv *subdrv = dev->subdrv;
 
-	list_for_each_entry(subdrv, &exynos_drm_subdrv_list, list) {
+		mutex_unlock(&list_lock);
  		if (subdrv->close)
-			subdrv->close(dev, subdrv->dev, file);
+			subdrv->close(drm_dev, subdrv->dev, file);
+		mutex_lock(&list_lock);
  	}
+	mutex_unlock(&list_lock);
  }
  EXPORT_SYMBOL_GPL(exynos_drm_subdrv_close);
drivers/gpu/drm/exynos/exynos_drm_drv.c +2 -48
index 02d4772..7f1186e 100644
@@ -539,28 +539,10 @@ static const struct component_master_ops exynos_drm_ops = {
  	.unbind		= exynos_drm_unbind,
  };
 
-static struct platform_driver *const exynos_drm_non_kms_drivers[] = {
-#ifdef CONFIG_DRM_EXYNOS_G2D
-	&g2d_driver,
-#endif
-#ifdef CONFIG_DRM_EXYNOS_FIMC
-	&fimc_driver,
-#endif
-#ifdef CONFIG_DRM_EXYNOS_ROTATOR
-	&rotator_driver,
-#endif
-#ifdef CONFIG_DRM_EXYNOS_GSC
-	&gsc_driver,
-#endif
-#ifdef CONFIG_DRM_EXYNOS_IPP
-	&ipp_driver,
-#endif
-};
-
  static int exynos_drm_platform_probe(struct platform_device *pdev)
  {
  	struct component_match *match;
-	int ret, i, j;
+	int ret;
 
  	pdev->dev.coherent_dma_mask = DMA_BIT_MASK(32);
  	exynos_drm_driver.num_ioctls = ARRAY_SIZE(exynos_ioctls);
@@ -574,31 +556,13 @@ static int exynos_drm_platform_probe(struct platform_device *pdev)
  	if (ret < 0)
  		return ret;
 
-	for (j = 0; j < ARRAY_SIZE(exynos_drm_non_kms_drivers); ++j) {
-		ret = platform_driver_register(exynos_drm_non_kms_drivers[j]);
-		if (ret < 0)
-			goto err_del_component_master;
-	}
-
-	ret = exynos_platform_device_ipp_register();
-	if (ret < 0)
-		goto err_unregister_non_kms_drivers;
-
  	/* Probe non kms sub drivers and virtual display driver. */
  	ret = exynos_drm_device_subdrv_probe(platform_get_drvdata(pdev));
  	if (ret)
-		goto err_unregister_resources;
+		goto err_del_component_master;
 
  	return ret;
 
-err_unregister_resources:
-#ifdef CONFIG_DRM_EXYNOS_IPP
-	exynos_platform_device_ipp_unregister();
-#endif
-err_unregister_non_kms_drivers:
-	while (--j >= 0)
-		platform_driver_unregister(exynos_drm_non_kms_drivers[j]);
-
  err_del_component_master:
  	component_master_del(&pdev->dev, &exynos_drm_ops);
 
@@ -607,17 +571,7 @@ err_del_component_master:
 
  static int exynos_drm_platform_remove(struct platform_device *pdev)
  {
-	int i;
-
  	exynos_drm_device_subdrv_remove(platform_get_drvdata(pdev));
-
-#ifdef CONFIG_DRM_EXYNOS_IPP
-	exynos_platform_device_ipp_unregister();
-#endif
-
-	for (i = ARRAY_SIZE(exynos_drm_non_kms_drivers) - 1; i >= 0; --i)
-		platform_driver_unregister(exynos_drm_non_kms_drivers[i]);
-
  	component_master_del(&pdev->dev, &exynos_drm_ops);
 
  	return 0;
drivers/gpu/drm/exynos/exynos_drm_drv.h +12 -16
index 352a9f9..5b3305c 100644
@@ -41,6 +41,13 @@ enum exynos_drm_output_type {
  	EXYNOS_DISPLAY_TYPE_VIDI,
  };
 
+/* This enumerates non kms device type. */
+enum exynos_drm_non_kms_type {
+	EXYNOS_DRM_NON_KMS_NONE,
+	EXYNOS_DRM_NON_KMS_G2D,
+	EXYNOS_DRM_NON_KMS_IPP,
+};
+
  /*
   * Exynos drm common overlay structure.
   *
@@ -259,10 +266,10 @@ struct exynos_drm_private {
  /*
   * Exynos drm sub driver structure.
   *
- * @list: sub driver has its own list object to register to exynos drm driver.
   * @dev: pointer to device object for subdrv device driver.
   * @drm_dev: pointer to drm_device and this pointer would be set
   *	when sub driver calls exynos_drm_subdrv_register().
+ * @device_type: non kms device type.
   * @probe: this callback would be called by exynos drm driver after
   *     subdrv is registered to it.
   * @remove: this callback is used to release resources created
@@ -271,9 +278,9 @@ struct exynos_drm_private {
   * @close: this would be called with drm device file close.
   */
  struct exynos_drm_subdrv {
-	struct list_head list;
  	struct device *dev;
  	struct drm_device *drm_dev;
+	unsigned int device_type;
 
  	int (*probe)(struct drm_device *drm_dev, struct device *dev);
  	void (*remove)(struct drm_device *drm_dev, struct device *dev);
@@ -294,15 +301,6 @@ int exynos_drm_device_subdrv_remove(struct drm_device *dev);
  int exynos_drm_subdrv_open(struct drm_device *dev, struct drm_file *file);
  void exynos_drm_subdrv_close(struct drm_device *dev, struct drm_file *file);
 
-#ifdef CONFIG_DRM_EXYNOS_IPP
-int exynos_platform_device_ipp_register(void);
-void exynos_platform_device_ipp_unregister(void);
-#else
-static inline int exynos_platform_device_ipp_register(void) { return 0; }
-static inline void exynos_platform_device_ipp_unregister(void) {}
-#endif
-
-
  #ifdef CONFIG_DRM_EXYNOS_DPI
  struct exynos_drm_display * exynos_dpi_probe(struct device *dev);
  int exynos_dpi_remove(struct device *dev);
@@ -331,11 +329,9 @@ int exynos_drm_component_add(struct device *dev,
  void exynos_drm_component_del(struct device *dev,
  				enum exynos_drm_device_type dev_type);
 
+extern int exynos_drm_non_kms_register(unsigned int device_type);
+extern void exynos_drm_non_kms_unregister(unsigned int device_type);
+
  extern struct platform_driver exynos_drm_common_hdmi_driver;
  extern struct platform_driver vidi_driver;
-extern struct platform_driver g2d_driver;
-extern struct platform_driver fimc_driver;
-extern struct platform_driver rotator_driver;
-extern struct platform_driver gsc_driver;
-extern struct platform_driver ipp_driver;
  #endif
drivers/gpu/drm/exynos/exynos_drm_fimc.c +13 -0
index 68d38eb..05000ee 100644
@@ -1860,3 +1860,16 @@ struct platform_driver fimc_driver = {
  	},
  };
 
+static int fimc_driver_init(void)
+{
+	return platform_driver_register(&fimc_driver);
+}
+
+static void fimc_driver_exit(void)
+{
+	platform_driver_unregister(&fimc_driver);
+}
+
+module_init(fimc_driver_init);
+module_exit(fimc_driver_exit);
+
drivers/gpu/drm/exynos/exynos_drm_g2d.c +42 -0
index 6ff8599..1f1dd20 100644
@@ -1464,6 +1464,7 @@ static int g2d_probe(struct platform_device *pdev)
  	platform_set_drvdata(pdev, g2d);
 
  	subdrv = &g2d->subdrv;
+	subdrv->device_type = EXYNOS_DRM_NON_KMS_G2D;
  	subdrv->dev = dev;
  	subdrv->probe = g2d_subdrv_probe;
  	subdrv->remove = g2d_subdrv_remove;
@@ -1585,3 +1586,44 @@ struct platform_driver g2d_driver = {
  		.of_match_table = exynos_g2d_match,
  	},
  };
+
+static const char * const strings[] = {
+	"samsung,exynos4212-g2d",
+	"samsung,exynos5250-g2d",
+};
+
+static int exynos_g2d_init(void)
+{
+	struct device_node *np;
+	int ret, i;
+
+	/*
+	 * Register non kms driver only in case that g2d device node exists
+	 * and the device node is enabled.
+	 *
+	 * TODO. this code should be replaced with super device node.
+	 */
+	for (i = 0; i < ARRAY_SIZE(strings); i++) {
+		np = of_find_compatible_node(NULL, NULL, strings[i]);
+		if (!np || !of_device_is_available(np))
+			return -ENODEV;
+	}
+
+	ret = exynos_drm_non_kms_register(EXYNOS_DRM_NON_KMS_G2D);
+	if (ret)
+		return ret;
+
+	ret = platform_driver_register(&g2d_driver);
+	if (ret)
+		exynos_drm_non_kms_unregister(EXYNOS_DRM_NON_KMS_G2D);
+
+	return ret;
+}
+
+static void exynos_g2d_exit(void)
+{
+	platform_driver_unregister(&g2d_driver);
+}
+
+module_init(exynos_g2d_init);
+module_exit(exynos_g2d_exit);
drivers/gpu/drm/exynos/exynos_drm_gsc.c +12 -0
index c6a013f..0cbed55 100644
@@ -1799,3 +1799,15 @@ struct platform_driver gsc_driver = {
  	},
  };
 
+static int gsc_driver_init(void)
+{
+	return platform_driver_register(&gsc_driver);
+}
+
+static void gsc_driver_exit(void)
+{
+	platform_driver_unregister(&gsc_driver);
+}
+
+module_init(gsc_driver_init);
+module_exit(gsc_driver_exit);
drivers/gpu/drm/exynos/exynos_drm_ipp.c +37 -2
index 00d74b1..559ee65 100644
@@ -102,7 +102,7 @@ static LIST_HEAD(exynos_drm_ippdrv_list);
  static DEFINE_MUTEX(exynos_drm_ippdrv_lock);
  static BLOCKING_NOTIFIER_HEAD(exynos_drm_ippnb_list);
 
-int exynos_platform_device_ipp_register(void)
+static int exynos_platform_device_ipp_register(void)
  {
  	struct platform_device *pdev;
 
@@ -118,7 +118,7 @@ int exynos_platform_device_ipp_register(void)
  	return 0;
  }
 
-void exynos_platform_device_ipp_unregister(void)
+static void exynos_platform_device_ipp_unregister(void)
  {
  	if (exynos_drm_ipp_pdev) {
  		platform_device_unregister(exynos_drm_ipp_pdev);
@@ -1718,6 +1718,7 @@ static int ipp_probe(struct platform_device *pdev)
 
  	/* set sub driver informations */
  	subdrv = &ctx->subdrv;
+	subdrv->device_type = EXYNOS_DRM_NON_KMS_IPP;
  	subdrv->dev = dev;
  	subdrv->probe = ipp_subdrv_probe;
  	subdrv->remove = ipp_subdrv_remove;
@@ -1773,3 +1774,37 @@ struct platform_driver ipp_driver = {
  	},
  };
 
+static int ipp_driver_init(void)
+{
+	int ret;
+
+	ret = exynos_drm_non_kms_register(EXYNOS_DRM_NON_KMS_IPP);
+	if (ret)
+		return ret;
+
+	ret = exynos_platform_device_ipp_register();
+	if (ret)
+		goto err_unregister_non_kms;
+
+	ret = platform_driver_register(&ipp_driver);
+	if (ret)
+		goto err_unregister_ipp_device;
+
+	return ret;
+
+err_unregister_ipp_device:
+	exynos_platform_device_ipp_unregister();
+err_unregister_non_kms:
+	exynos_drm_non_kms_unregister(EXYNOS_DRM_NON_KMS_IPP);
+
+	return ret;
+}
+
+static void ipp_driver_exit(void)
+{
+	platform_driver_unregister(&ipp_driver);
+}
+
+module_init(ipp_driver_init);
+module_exit(ipp_driver_exit);
+
drivers/gpu/drm/exynos/exynos_drm_rotator.c +13 -0
index b6a37d4..ffa0166 100644
@@ -854,3 +854,16 @@ struct platform_driver rotator_driver = {
  		.of_match_table = exynos_rotator_match,
  	},
  };
+
+static int rotator_driver_init(void)
+{
+	return platform_driver_register(&rotator_driver);
+}
+
+static void rotator_driver_exit(void)
+{
+	platform_driver_unregister(&rotator_driver);
+}
+
+module_init(rotator_driver_init);
+module_exit(rotator_driver_exit);
author maintainer
#7 lore raw

Re: [RFC PATCH v2] drm/exynos: make non kms drivers to be indenpendent modules

Hi YoungJun,

Quoted 104 lines · YoungJun Cho

Hi Inki,

There are 3 comments below.

Quoted 99 lines · Inki Dae

This patch makes non kms drivers to be independent modules. For this, it removes all register codes to non kms drivers from exynos_drm_drv module and adds module_init/exit for each non kms driver so that each non kms driver can be called independently.

In addition, this patch adds non kms register/unregister functions to exynos_drm_core module and also modifies existing codes relevant to sub driver.

The idea is that non kms driver is registered by entry point, module_init, of each non kms driver and sets its own sub driver to registered non kms driver object when the sub driver is probed. For this, this patch adds a new structure, exynos_drm_non_kms_dev, to exynos_drm_core module.

Changelog v2:
- check if available g2d device node.
- return 0 instead of -EPROBE_DEFER in case of no non kms device registered. This case is not error.

---
  drivers/gpu/drm/exynos/exynos_drm_core.c    |  164
+++++++++++++++++++++++----
  drivers/gpu/drm/exynos/exynos_drm_drv.c     |   50 +-------
  drivers/gpu/drm/exynos/exynos_drm_drv.h     |   28 ++---
  drivers/gpu/drm/exynos/exynos_drm_fimc.c    |   13 +++
  drivers/gpu/drm/exynos/exynos_drm_g2d.c     |   42 +++++++
  drivers/gpu/drm/exynos/exynos_drm_gsc.c     |   12 ++
  drivers/gpu/drm/exynos/exynos_drm_ipp.c     |   39 ++++++-
  drivers/gpu/drm/exynos/exynos_drm_rotator.c |   13 +++
  8 files changed, 271 insertions(+), 90 deletions(-)
drivers/gpu/drm/exynos/exynos_drm_core.c +44 -0
index 4c9f972..715a0ad 100644
@@ -19,6 +19,13 @@
  #include "exynos_drm_fbdev.h"
 
  static LIST_HEAD(exynos_drm_subdrv_list);
+DEFINE_MUTEX(list_lock);
+
+struct exynos_drm_non_kms_dev {
+    struct list_head list;
+    struct exynos_drm_subdrv *subdrv;
+    unsigned int device_type;
+};
 
  int exynos_drm_create_enc_conn(struct drm_device *dev,
                      struct exynos_drm_display *display)
@@ -55,12 +62,66 @@ err_destroy_encoder:
      return ret;
  }
 
+int exynos_drm_non_kms_register(unsigned int device_type)
+{
+    struct exynos_drm_non_kms_dev *dev;
+
+    dev = kzalloc(sizeof(*dev), GFP_KERNEL);
+    if (!dev)
+        return -ENOMEM;
+
+    dev->device_type = device_type;
+
+    mutex_lock(&list_lock);
+    list_add_tail(&dev->list, &exynos_drm_subdrv_list);
+    mutex_unlock(&list_lock);
+
+    return 0;
+}
+
+void exynos_drm_non_kms_unregister(unsigned int device_type)
+{
+    struct exynos_drm_non_kms_dev *dev, *next;
+
+    mutex_lock(&list_lock);
+    list_for_each_entry_safe(dev, next, &exynos_drm_subdrv_list, list) {
+        mutex_unlock(&list_lock);
+        if (dev->device_type == device_type) {
+            list_del_init(&dev->list);
+            kfree(dev);
+            mutex_lock(&list_lock);
+            break;
+        }
+        mutex_lock(&list_lock);
+    }
+    mutex_unlock(&list_lock);
+}
+
  int exynos_drm_subdrv_register(struct exynos_drm_subdrv *subdrv)
  {
+    struct exynos_drm_non_kms_dev *dev;
+
      if (!subdrv)
          return -EINVAL;
 
Quoted 10 lines

drivers/gpu/drm/exynos/exynos_drm_core.c err_destroy_encoder: · line 112

Quoted 7 lines
drivers/gpu/drm/exynos/exynos_drm_core.c +6 -1
-    list_add_tail(&subdrv->list, &exynos_drm_subdrv_list);
+    mutex_lock(&list_lock);
+    if (list_empty(&exynos_drm_subdrv_list)) {
+        mutex_unlock(&list_lock);
+        return -ENODEV;
+    }
+    mutex_unlock(&list_lock);

The list_for_each_entry() could handle empty list, so list_empty() could be removed.

This is required for some codes for checking which error type should be returned. So it would better to just check list_empty.

Quoted 52 lines
Quoted 52 lines
drivers/gpu/drm/exynos/exynos_drm_core.c +27 -4
+
+    mutex_lock(&list_lock);
+    list_for_each_entry(dev, &exynos_drm_subdrv_list, list) {
+        mutex_unlock(&list_lock);
+        if (dev->device_type == subdrv->device_type) {
+            dev->subdrv = subdrv;
+            mutex_lock(&list_lock);
+            break;
+        }
+        mutex_lock(&list_lock);
+    }
+    mutex_unlock(&list_lock);
 
      return 0;
  }
@@ -68,94 +129,149 @@ EXPORT_SYMBOL_GPL(exynos_drm_subdrv_register);
 
  int exynos_drm_subdrv_unregister(struct exynos_drm_subdrv *subdrv)
  {
+    struct exynos_drm_non_kms_dev *dev;
+
      if (!subdrv)
          return -EINVAL;
 
-    list_del(&subdrv->list);
+    mutex_lock(&list_lock);
+    list_for_each_entry(dev, &exynos_drm_subdrv_list, list) {
+        mutex_unlock(&list_lock);
+        if (dev->device_type == subdrv->device_type) {
+            dev->subdrv = NULL;
+            break;
+        }
+        mutex_lock(&list_lock);
+    }
+    mutex_unlock(&list_lock);
 
      return 0;
  }
  EXPORT_SYMBOL_GPL(exynos_drm_subdrv_unregister);
 
-int exynos_drm_device_subdrv_probe(struct drm_device *dev)
+int exynos_drm_device_subdrv_probe(struct drm_device *drm_dev)
  {
-    struct exynos_drm_subdrv *subdrv, *n;
+    struct exynos_drm_non_kms_dev *dev, *n;
      int err;
 
-    if (!dev)
+    if (!drm_dev)
          return -EINVAL;
 
Quoted 9 lines

drivers/gpu/drm/exynos/exynos_drm_core.c EXPORT_SYMBOL_GPL(exynos_drm_subdrv_register); · line 165

Quoted 7 lines
drivers/gpu/drm/exynos/exynos_drm_core.c +6 -1
-    list_for_each_entry_safe(subdrv, n, &exynos_drm_subdrv_list, list) {
+    mutex_lock(&list_lock);
+    if (list_empty(&exynos_drm_subdrv_list)) {
+        mutex_unlock(&list_lock);
+        return 0;
+    }
+

ditto

Ditto.

Quoted 96 lines
Quoted 96 lines
drivers/gpu/drm/exynos/exynos_drm_core.c +39 -12
+    list_for_each_entry(dev, &exynos_drm_subdrv_list, list) {
+        mutex_unlock(&list_lock);
+        /* Retry to probe if there is sub driver not registered yet. */
+        if (!dev->subdrv)
+            return -EPROBE_DEFER;
+        mutex_lock(&list_lock);
+    }
+
+    list_for_each_entry_safe(dev, n, &exynos_drm_subdrv_list, list) {
+        struct exynos_drm_subdrv *subdrv = dev->subdrv;
+
+        mutex_unlock(&list_lock);
          if (subdrv->probe) {
-            subdrv->drm_dev = dev;
+            subdrv->drm_dev = drm_dev;
 
              /*
               * this probe callback would be called by sub driver
               * after setting of all resources to this sub driver,
               * such as clock, irq and register map are done.
               */
-            err = subdrv->probe(dev, subdrv->dev);
+            err = subdrv->probe(drm_dev, subdrv->dev);
              if (err) {
                  DRM_DEBUG("exynos drm subdrv probe failed.\n");
-                list_del(&subdrv->list);
+                list_del_init(&dev->list);
+                mutex_lock(&list_lock);
                  continue;
              }
          }
+        mutex_lock(&list_lock);
      }
+    mutex_unlock(&list_lock);
 
      return 0;
  }
  EXPORT_SYMBOL_GPL(exynos_drm_device_subdrv_probe);
 
-int exynos_drm_device_subdrv_remove(struct drm_device *dev)
+int exynos_drm_device_subdrv_remove(struct drm_device *drm_dev)
  {
-    struct exynos_drm_subdrv *subdrv;
+    struct exynos_drm_non_kms_dev *dev;
 
-    if (!dev) {
+    if (!drm_dev) {
          WARN(1, "Unexpected drm device unregister!\n");
          return -EINVAL;
      }
 
-    list_for_each_entry(subdrv, &exynos_drm_subdrv_list, list) {
+    mutex_lock(&list_lock);
+    list_for_each_entry(dev, &exynos_drm_subdrv_list, list) {
+        struct exynos_drm_subdrv *subdrv = dev->subdrv;
+
+        mutex_unlock(&list_lock);
          if (subdrv->remove)
-            subdrv->remove(dev, subdrv->dev);
+            subdrv->remove(drm_dev, subdrv->dev);
+        mutex_lock(&list_lock);
      }
+    mutex_unlock(&list_lock);
 
      return 0;
  }
  EXPORT_SYMBOL_GPL(exynos_drm_device_subdrv_remove);
 
-int exynos_drm_subdrv_open(struct drm_device *dev, struct drm_file
 *file)
+int exynos_drm_subdrv_open(struct drm_device *drm_dev, struct
 drm_file *file)
  {
-    struct exynos_drm_subdrv *subdrv;
+    struct exynos_drm_non_kms_dev *dev;
      int ret;
 
-    list_for_each_entry(subdrv, &exynos_drm_subdrv_list, list) {
+    mutex_lock(&list_lock);
+    list_for_each_entry(dev, &exynos_drm_subdrv_list, list) {
+        struct exynos_drm_subdrv *subdrv = dev->subdrv;
+
+        mutex_unlock(&list_lock);
          if (subdrv->open) {
-            ret = subdrv->open(dev, subdrv->dev, file);
+            ret = subdrv->open(drm_dev, subdrv->dev, file);
              if (ret)
                  goto err;
          }
+        mutex_lock(&list_lock);
      }
+    mutex_unlock(&list_lock);
 
      return 0;
 
Quoted 15 lines

drivers/gpu/drm/exynos/exynos_drm_core.c EXPORT_SYMBOL_GPL(exynos_drm_subdrv_register); · line 257

Quoted 13 lines
drivers/gpu/drm/exynos/exynos_drm_core.c +8 -2
  err:
-    list_for_each_entry_reverse(subdrv, &subdrv->list, list) {
+    mutex_lock(&list_lock);
+    list_for_each_entry_reverse(dev, &exynos_drm_subdrv_list, list) {
+        struct exynos_drm_subdrv *subdrv = dev->subdrv;
+
+        mutex_unlock(&list_lock);
          if (subdrv->close)
-            subdrv->close(dev, subdrv->dev, file);
+            subdrv->close(drm_dev, subdrv->dev, file);
+        mutex_lock(&list_lock);
      }
+    mutex_lock(&list_lock);

mutex_unlock(&list_lock);

Oops, thanks :)

Quoted 381 lines

Thank you.
Best regards YJ

Quoted 377 lines
drivers/gpu/drm/exynos/exynos_drm_core.c +10 -4
      return ret;
  }
  EXPORT_SYMBOL_GPL(exynos_drm_subdrv_open);
 
-void exynos_drm_subdrv_close(struct drm_device *dev, struct drm_file
 *file)
+void exynos_drm_subdrv_close(struct drm_device *drm_dev, struct
 drm_file *file)
  {
-    struct exynos_drm_subdrv *subdrv;
+    struct exynos_drm_non_kms_dev *dev;
+
+    mutex_lock(&list_lock);
+    list_for_each_entry(dev, &exynos_drm_subdrv_list, list) {
+        struct exynos_drm_subdrv *subdrv = dev->subdrv;
 
-    list_for_each_entry(subdrv, &exynos_drm_subdrv_list, list) {
+        mutex_unlock(&list_lock);
          if (subdrv->close)
-            subdrv->close(dev, subdrv->dev, file);
+            subdrv->close(drm_dev, subdrv->dev, file);
+        mutex_lock(&list_lock);
      }
+    mutex_unlock(&list_lock);
  }
  EXPORT_SYMBOL_GPL(exynos_drm_subdrv_close);
drivers/gpu/drm/exynos/exynos_drm_drv.c +1 -19
index 02d4772..7f1186e 100644
@@ -539,28 +539,10 @@ static const struct component_master_ops
 exynos_drm_ops = {
      .unbind        = exynos_drm_unbind,
  };
 
-static struct platform_driver *const exynos_drm_non_kms_drivers[] = {
-#ifdef CONFIG_DRM_EXYNOS_G2D
-    &g2d_driver,
-#endif
-#ifdef CONFIG_DRM_EXYNOS_FIMC
-    &fimc_driver,
-#endif
-#ifdef CONFIG_DRM_EXYNOS_ROTATOR
-    &rotator_driver,
-#endif
-#ifdef CONFIG_DRM_EXYNOS_GSC
-    &gsc_driver,
-#endif
-#ifdef CONFIG_DRM_EXYNOS_IPP
-    &ipp_driver,
-#endif
-};
-
  static int exynos_drm_platform_probe(struct platform_device *pdev)
  {
      struct component_match *match;
-    int ret, i, j;
+    int ret;
 
      pdev->dev.coherent_dma_mask = DMA_BIT_MASK(32);
      exynos_drm_driver.num_ioctls = ARRAY_SIZE(exynos_ioctls);
drivers/gpu/drm/exynos/exynos_drm_drv.c +1 -29
@@ -574,31 +556,13 @@ static int exynos_drm_platform_probe(struct
 platform_device *pdev)
      if (ret < 0)
          return ret;
 
-    for (j = 0; j < ARRAY_SIZE(exynos_drm_non_kms_drivers); ++j) {
-        ret = platform_driver_register(exynos_drm_non_kms_drivers[j]);
-        if (ret < 0)
-            goto err_del_component_master;
-    }
-
-    ret = exynos_platform_device_ipp_register();
-    if (ret < 0)
-        goto err_unregister_non_kms_drivers;
-
      /* Probe non kms sub drivers and virtual display driver. */
      ret = exynos_drm_device_subdrv_probe(platform_get_drvdata(pdev));
      if (ret)
-        goto err_unregister_resources;
+        goto err_del_component_master;
 
      return ret;
 
-err_unregister_resources:
-#ifdef CONFIG_DRM_EXYNOS_IPP
-    exynos_platform_device_ipp_unregister();
-#endif
-err_unregister_non_kms_drivers:
-    while (--j >= 0)
-        platform_driver_unregister(exynos_drm_non_kms_drivers[j]);
-
  err_del_component_master:
      component_master_del(&pdev->dev, &exynos_drm_ops);
@@ -607,17 +571,7 @@ err_del_component_master:
 
  static int exynos_drm_platform_remove(struct platform_device *pdev)
  {
-    int i;
-
      exynos_drm_device_subdrv_remove(platform_get_drvdata(pdev));
-
-#ifdef CONFIG_DRM_EXYNOS_IPP
-    exynos_platform_device_ipp_unregister();
-#endif
-
-    for (i = ARRAY_SIZE(exynos_drm_non_kms_drivers) - 1; i >= 0; --i)
-        platform_driver_unregister(exynos_drm_non_kms_drivers[i]);
-
      component_master_del(&pdev->dev, &exynos_drm_ops);
 
      return 0;
drivers/gpu/drm/exynos/exynos_drm_drv.h +7 -1
index 352a9f9..5b3305c 100644
@@ -41,6 +41,13 @@ enum exynos_drm_output_type {
      EXYNOS_DISPLAY_TYPE_VIDI,
  };
 
+/* This enumerates non kms device type. */
+enum exynos_drm_non_kms_type {
+    EXYNOS_DRM_NON_KMS_NONE,
+    EXYNOS_DRM_NON_KMS_G2D,
+    EXYNOS_DRM_NON_KMS_IPP,
+};
+
  /*
   * Exynos drm common overlay structure.
   *
@@ -259,10 +266,10 @@ struct exynos_drm_private {
  /*
   * Exynos drm sub driver structure.
   *
- * @list: sub driver has its own list object to register to exynos

drm driver.
* @dev: pointer to device object for subdrv device driver.
* @drm_dev: pointer to drm_device and this pointer would be set
* when sub driver calls exynos_drm_subdrv_register().
+ * @device_type: non kms device type.
* @probe: this callback would be called by exynos drm driver after
* subdrv is registered to it.
* @remove: this callback is used to release resources created

drivers/gpu/drm/exynos/exynos_drm_drv.h +1 -6
@@ -271,9 +278,9 @@ struct exynos_drm_private {
   * @close: this would be called with drm device file close.
   */
  struct exynos_drm_subdrv {
-    struct list_head list;
      struct device *dev;
      struct drm_device *drm_dev;
+    unsigned int device_type;
 
      int (*probe)(struct drm_device *drm_dev, struct device *dev);
      void (*remove)(struct drm_device *drm_dev, struct device *dev);
@@ -294,15 +301,6 @@ int exynos_drm_device_subdrv_remove(struct
 drm_device *dev);
  int exynos_drm_subdrv_open(struct drm_device *dev, struct drm_file
 *file);
  void exynos_drm_subdrv_close(struct drm_device *dev, struct drm_file
 *file);
 
-#ifdef CONFIG_DRM_EXYNOS_IPP
-int exynos_platform_device_ipp_register(void);
-void exynos_platform_device_ipp_unregister(void);
-#else
-static inline int exynos_platform_device_ipp_register(void) { return

0; }

drivers/gpu/drm/exynos/exynos_drm_drv.h +3 -9
-static inline void exynos_platform_device_ipp_unregister(void) {}
-#endif
-
-
  #ifdef CONFIG_DRM_EXYNOS_DPI
  struct exynos_drm_display * exynos_dpi_probe(struct device *dev);
  int exynos_dpi_remove(struct device *dev);
@@ -331,11 +329,9 @@ int exynos_drm_component_add(struct device *dev,
  void exynos_drm_component_del(struct device *dev,
                  enum exynos_drm_device_type dev_type);
 
+extern int exynos_drm_non_kms_register(unsigned int device_type);
+extern void exynos_drm_non_kms_unregister(unsigned int device_type);
+
  extern struct platform_driver exynos_drm_common_hdmi_driver;
  extern struct platform_driver vidi_driver;
-extern struct platform_driver g2d_driver;
-extern struct platform_driver fimc_driver;
-extern struct platform_driver rotator_driver;
-extern struct platform_driver gsc_driver;
-extern struct platform_driver ipp_driver;
  #endif
drivers/gpu/drm/exynos/exynos_drm_fimc.c +13 -0
index 68d38eb..05000ee 100644
@@ -1860,3 +1860,16 @@ struct platform_driver fimc_driver = {
      },
  };
 
+static int fimc_driver_init(void)
+{
+    return platform_driver_register(&fimc_driver);
+}
+
+static void fimc_driver_exit(void)
+{
+    platform_driver_unregister(&fimc_driver);
+}
+
+module_init(fimc_driver_init);
+module_exit(fimc_driver_exit);
+
drivers/gpu/drm/exynos/exynos_drm_g2d.c +42 -0
index 6ff8599..1f1dd20 100644
@@ -1464,6 +1464,7 @@ static int g2d_probe(struct platform_device *pdev)
      platform_set_drvdata(pdev, g2d);
 
      subdrv = &g2d->subdrv;
+    subdrv->device_type = EXYNOS_DRM_NON_KMS_G2D;
      subdrv->dev = dev;
      subdrv->probe = g2d_subdrv_probe;
      subdrv->remove = g2d_subdrv_remove;
@@ -1585,3 +1586,44 @@ struct platform_driver g2d_driver = {
          .of_match_table = exynos_g2d_match,
      },
  };
+
+static const char * const strings[] = {
+    "samsung,exynos4212-g2d",
+    "samsung,exynos5250-g2d",
+};
+
+static int exynos_g2d_init(void)
+{
+    struct device_node *np;
+    int ret, i;
+
+    /*
+     * Register non kms driver only in case that g2d device node exists
+     * and the device node is enabled.
+     *
+     * TODO. this code should be replaced with super device node.
+     */
+    for (i = 0; i < ARRAY_SIZE(strings); i++) {
+        np = of_find_compatible_node(NULL, NULL, strings[i]);
+        if (!np || !of_device_is_available(np))
+            return -ENODEV;
+    }
+
+    ret = exynos_drm_non_kms_register(EXYNOS_DRM_NON_KMS_G2D);
+    if (ret)
+        return ret;
+
+    ret = platform_driver_register(&g2d_driver);
+    if (ret)
+        exynos_drm_non_kms_unregister(EXYNOS_DRM_NON_KMS_G2D);
+
+    return ret;
+}
+
+static void exynos_g2d_exit(void)
+{
+    platform_driver_unregister(&g2d_driver);
+}
+
+module_init(exynos_g2d_init);
+module_exit(exynos_g2d_exit);
drivers/gpu/drm/exynos/exynos_drm_gsc.c +12 -0
index c6a013f..0cbed55 100644
@@ -1799,3 +1799,15 @@ struct platform_driver gsc_driver = {
      },
  };
 
+static int gsc_driver_init(void)
+{
+    return platform_driver_register(&gsc_driver);
+}
+
+static void gsc_driver_exit(void)
+{
+    platform_driver_unregister(&gsc_driver);
+}
+
+module_init(gsc_driver_init);
+module_exit(gsc_driver_exit);
drivers/gpu/drm/exynos/exynos_drm_ipp.c +37 -2
index 00d74b1..559ee65 100644
@@ -102,7 +102,7 @@ static LIST_HEAD(exynos_drm_ippdrv_list);
  static DEFINE_MUTEX(exynos_drm_ippdrv_lock);
  static BLOCKING_NOTIFIER_HEAD(exynos_drm_ippnb_list);
 
-int exynos_platform_device_ipp_register(void)
+static int exynos_platform_device_ipp_register(void)
  {
      struct platform_device *pdev;
 
@@ -118,7 +118,7 @@ int exynos_platform_device_ipp_register(void)
      return 0;
  }
 
-void exynos_platform_device_ipp_unregister(void)
+static void exynos_platform_device_ipp_unregister(void)
  {
      if (exynos_drm_ipp_pdev) {
          platform_device_unregister(exynos_drm_ipp_pdev);
@@ -1718,6 +1718,7 @@ static int ipp_probe(struct platform_device *pdev)
 
      /* set sub driver informations */
      subdrv = &ctx->subdrv;
+    subdrv->device_type = EXYNOS_DRM_NON_KMS_IPP;
      subdrv->dev = dev;
      subdrv->probe = ipp_subdrv_probe;
      subdrv->remove = ipp_subdrv_remove;
@@ -1773,3 +1774,37 @@ struct platform_driver ipp_driver = {
      },
  };
 
+static int ipp_driver_init(void)
+{
+    int ret;
+
+    ret = exynos_drm_non_kms_register(EXYNOS_DRM_NON_KMS_IPP);
+    if (ret)
+        return ret;
+
+    ret = exynos_platform_device_ipp_register();
+    if (ret)
+        goto err_unregister_non_kms;
+
+    ret = platform_driver_register(&ipp_driver);
+    if (ret)
+        goto err_unregister_ipp_device;
+
+    return ret;
+
+err_unregister_ipp_device:
+    exynos_platform_device_ipp_unregister();
+err_unregister_non_kms:
+    exynos_drm_non_kms_unregister(EXYNOS_DRM_NON_KMS_IPP);
+
+    return ret;
+}
+
+static void ipp_driver_exit(void)
+{
+    platform_driver_unregister(&ipp_driver);
+}
+
+module_init(ipp_driver_init);
+module_exit(ipp_driver_exit);
+
drivers/gpu/drm/exynos/exynos_drm_rotator.c +6 -0
index b6a37d4..ffa0166 100644
@@ -854,3 +854,16 @@ struct platform_driver rotator_driver = {
          .of_match_table = exynos_rotator_match,
      },
  };
+
+static int rotator_driver_init(void)
+{
+    return platform_driver_register(&rotator_driver);
+}
+
Quoted 15 lines
Quoted 8 lines
drivers/gpu/drm/exynos/exynos_drm_rotator.c +7 -0
+static void rotator_driver_exit(void)
+{
+    platform_driver_unregister(&rotator_driver);
+}
+
+module_init(rotator_driver_init);
+module_exit(rotator_driver_exit);
Signature · 4 lines
To unsubscribe from this list: send the line "unsubscribe
linux-samsung-soc" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel

author maintainer
#8 lore raw

RFC PATCH 3/3 drm/exynos: make vidi driver to be independent module

In reply to Inki Dae

This patch makes vidi driver to be independent module. For this, it removes register codes to vidi driver from exynos_drm_drv module and adds module_init/exit for vidi driver so that this driver can be called independently.

In addition, this patch adds component support to vidi driver, which is required for modularity.

---
 drivers/gpu/drm/exynos/exynos_drm_drv.c  |   12 +----
 drivers/gpu/drm/exynos/exynos_drm_drv.h  |    9 ----
 drivers/gpu/drm/exynos/exynos_drm_vidi.c |   81 +++++++++++++++++++-----------
 3 files changed, 54 insertions(+), 48 deletions(-)
drivers/gpu/drm/exynos/exynos_drm_drv.c +1 -11
index 7f1186e..3ac39b6 100644
@@ -608,19 +608,12 @@ static int exynos_drm_init(void)
 	if (IS_ERR(exynos_drm_pdev))
 		return PTR_ERR(exynos_drm_pdev);
 
-	ret = exynos_drm_probe_vidi();
-	if (ret < 0)
-		goto err_unregister_pd;
-
 	ret = platform_driver_register(&exynos_drm_platform_driver);
 	if (ret)
-		goto err_remove_vidi;
+		goto err_unregister_pd;
 
 	return 0;
 
-err_remove_vidi:
-	exynos_drm_remove_vidi();
-
 err_unregister_pd:
 	platform_device_unregister(exynos_drm_pdev);
 
@@ -630,9 +623,6 @@ err_unregister_pd:
 static void exynos_drm_exit(void)
 {
 	platform_driver_unregister(&exynos_drm_platform_driver);
-
-	exynos_drm_remove_vidi();
-
 	platform_device_unregister(exynos_drm_pdev);
 }
 
drivers/gpu/drm/exynos/exynos_drm_drv.h +0 -9
index 5b3305c..7c2ba06 100644
@@ -310,14 +310,6 @@ exynos_dpi_probe(struct device *dev) { return NULL; }
 static inline int exynos_dpi_remove(struct device *dev) { return 0; }
 #endif
 
-#ifdef CONFIG_DRM_EXYNOS_VIDI
-int exynos_drm_probe_vidi(void);
-void exynos_drm_remove_vidi(void);
-#else
-static inline int exynos_drm_probe_vidi(void) { return 0; }
-static inline void exynos_drm_remove_vidi(void) {}
-#endif
-
 /* This function creates a encoder and a connector, and initializes them. */
 int exynos_drm_create_enc_conn(struct drm_device *dev,
 				struct exynos_drm_display *display);
@@ -333,5 +325,4 @@ extern int exynos_drm_non_kms_register(unsigned int device_type);
 extern void exynos_drm_non_kms_unregister(unsigned int device_type);
 
 extern struct platform_driver exynos_drm_common_hdmi_driver;
-extern struct platform_driver vidi_driver;
 #endif
drivers/gpu/drm/exynos/exynos_drm_vidi.c +53 -28

151 lines not on this page · raw message

Signature · 6 lines
1.7.9.5

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel