Skip to contentSkip to conversation

staging: drm: radeon: de-midlayer driver loading

PATCH In review Aastha Gupta 1 participant 2 messages Oct 5, 2017 – Oct 13, 2017

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 staging: drm: radeon: de-midlayer driver loading

This patch gets rid of the driver’s ->load callbacks and open-codes the load sequence properly.
The goal is to de-midlayer driver's loading.

---
 drivers/gpu/drm/radeon/radeon.h     |  1 +
 drivers/gpu/drm/radeon/radeon_drv.c |  8 +++--
 drivers/gpu/drm/radeon/radeon_kms.c | 70 +++++++++++++++++++++++++------------
 3 files changed, 53 insertions(+), 26 deletions(-)
drivers/gpu/drm/radeon/radeon.h +1 -0
index 8cbaeec..54d5ab5 100644
@@ -2311,6 +2311,7 @@ typedef void (*radeon_wreg_t)(struct radeon_device*, uint32_t, uint32_t);
 
 struct radeon_device {
 	struct device			*dev;
+	struct drm_device		drm;
 	struct drm_device		*ddev;
 	struct pci_dev			*pdev;
 	struct rw_semaphore		exclusive_lock;
drivers/gpu/drm/radeon/radeon_drv.c +5 -3
index f4becad..2505d96 100644
@@ -104,7 +104,9 @@
 #define KMS_DRIVER_MAJOR	2
 #define KMS_DRIVER_MINOR	50
 #define KMS_DRIVER_PATCHLEVEL	0
-int radeon_driver_load_kms(struct drm_device *dev, unsigned long flags);
+int radeon_driver_load_kms(struct pci_dev *pdev,
+			   const struct pci_device_id *ent,
+			   struct drm_driver *driver)
 void radeon_driver_unload_kms(struct drm_device *dev);
 void radeon_driver_lastclose_kms(struct drm_device *dev);
 int radeon_driver_open_kms(struct drm_device *dev, struct drm_file *file_priv);
@@ -354,7 +356,8 @@ static int radeon_pci_probe(struct pci_dev *pdev,
 	if (ret)
 		return ret;
 
-	return drm_get_pci_dev(pdev, ent, &kms_driver);
+	return radeon_driver_load_kms(pdev, ent, &kms_driver);
+
 }
 
 static void
@@ -563,7 +566,6 @@ static struct drm_driver kms_driver = {
 	    DRIVER_USE_AGP |
 	    DRIVER_HAVE_IRQ | DRIVER_IRQ_SHARED | DRIVER_GEM |
 	    DRIVER_PRIME | DRIVER_RENDER,
-	.load = radeon_driver_load_kms,
 	.open = radeon_driver_open_kms,
 	.postclose = radeon_driver_postclose_kms,
 	.lastclose = radeon_driver_lastclose_kms,
drivers/gpu/drm/radeon/radeon_kms.c +47 -23

134 lines not on this page · raw message

Signature · 1 line
2.7.4
#1 lore raw
Quoted 202 lines · Aastha Gupta

This patch gets rid of the driver’s ->load callbacks and open-codes the load sequence properly.
The goal is to de-midlayer driver's loading.

---
 drivers/gpu/drm/radeon/radeon.h     |  1 +
 drivers/gpu/drm/radeon/radeon_drv.c |  8 +++--
 drivers/gpu/drm/radeon/radeon_kms.c | 70 +++++++++++++++++++++++++------------
 3 files changed, 53 insertions(+), 26 deletions(-)
drivers/gpu/drm/radeon/radeon.h +1 -0
index 8cbaeec..54d5ab5 100644
@@ -2311,6 +2311,7 @@ typedef void (*radeon_wreg_t)(struct radeon_device*, uint32_t, uint32_t);
 
 struct radeon_device {
        struct device                   *dev;
+       struct drm_device               drm;
        struct drm_device               *ddev;
        struct pci_dev                  *pdev;
        struct rw_semaphore             exclusive_lock;
drivers/gpu/drm/radeon/radeon_drv.c +5 -3
index f4becad..2505d96 100644
@@ -104,7 +104,9 @@
 #define KMS_DRIVER_MAJOR       2
 #define KMS_DRIVER_MINOR       50
 #define KMS_DRIVER_PATCHLEVEL  0
-int radeon_driver_load_kms(struct drm_device *dev, unsigned long flags);
+int radeon_driver_load_kms(struct pci_dev *pdev,
+                          const struct pci_device_id *ent,
+                          struct drm_driver *driver)
 void radeon_driver_unload_kms(struct drm_device *dev);
 void radeon_driver_lastclose_kms(struct drm_device *dev);
 int radeon_driver_open_kms(struct drm_device *dev, struct drm_file *file_priv);
@@ -354,7 +356,8 @@ static int radeon_pci_probe(struct pci_dev *pdev,
        if (ret)
                return ret;
 
-       return drm_get_pci_dev(pdev, ent, &kms_driver);
+       return radeon_driver_load_kms(pdev, ent, &kms_driver);
+
 }
 
 static void
@@ -563,7 +566,6 @@ static struct drm_driver kms_driver = {
            DRIVER_USE_AGP |
            DRIVER_HAVE_IRQ | DRIVER_IRQ_SHARED | DRIVER_GEM |
            DRIVER_PRIME | DRIVER_RENDER,
-       .load = radeon_driver_load_kms,
        .open = radeon_driver_open_kms,
        .postclose = radeon_driver_postclose_kms,
        .lastclose = radeon_driver_lastclose_kms,
drivers/gpu/drm/radeon/radeon_kms.c +47 -24
index dfee8f7..a392ff8 100644
@@ -93,10 +93,14 @@ void radeon_driver_unload_kms(struct drm_device *dev)
  * (crtcs, encoders, hotplug detect, etc.).
  * Returns 0 on success, error on failure.
  */
-int radeon_driver_load_kms(struct drm_device *dev, unsigned long flags)
+int radeon_driver_load_kms(struct pci_dev *pdev,
+                          const struct pci_device_id *ent,
+                          struct drm_driver *driver)
 {
        struct radeon_device *rdev;
-       int r, acpi_status;
+       int acpi_status, r = 0;
+
+       uint32_t flags = 0;
 
        if (!radeon_si_support) {
                switch (flags & RADEON_FAMILY_MASK) {
@@ -105,7 +109,7 @@ int radeon_driver_load_kms(struct drm_device *dev, unsigned long flags)
                case CHIP_VERDE:
                case CHIP_OLAND:
                case CHIP_HAINAN:
-                       dev_info(dev->dev,
+                       dev_info(pdev->dev,
                                 "SI support disabled by module param\n");
                        return -ENODEV;
                }
@@ -117,22 +121,40 @@ int radeon_driver_load_kms(struct drm_device *dev, unsigned long flags)
                case CHIP_HAWAII:
                case CHIP_KABINI:
                case CHIP_MULLINS:
-                       dev_info(dev->dev,
+                       dev_info(pdev->dev,
                                 "CIK support disabled by module param\n");
                        return -ENODEV;
                }
        }
 
+       int ret;
+
+       ret = -ENOMEM;
        rdev = kzalloc(sizeof(struct radeon_device), GFP_KERNEL);
-       if (rdev == NULL) {
-               return -ENOMEM;
+       if (rdev)
+               ret = drm_dev_init(&rdev->drm, driver, &pdev->dev);
+       if (ret) {
+               dev_error(&pdev->dev,
+                         "[" DRM_NAME ":%s] allocation failed\n", __func__);
+               kfree(rdev);
+               return ret;
+       }
+
+       rdev->drm.pdev = pdev;
+       rdev->drm.dev_private = rdev;
+       rdev->dev = &rdev->drm;
+
+       r = pci_enable_device(pdev);
+       if (r) {
+               goto out;
        }
-       dev->dev_private = (void *)rdev;
+
+       pci_set_drvdata(pdev, &rdev->drm);
 
        /* update BUS flag */
-       if (pci_find_capability(dev->pdev, PCI_CAP_ID_AGP)) {
+       if (pci_find_capability(pdev, PCI_CAP_ID_AGP)) {
                flags |= RADEON_IS_AGP;
-       } else if (pci_is_pcie(dev->pdev)) {
+       } else if (pci_is_pcie(pdev)) {
                flags |= RADEON_IS_PCIE;
        } else {
                flags |= RADEON_IS_PCI;
@@ -141,7 +163,7 @@ int radeon_driver_load_kms(struct drm_device *dev, unsigned long flags)
        if ((radeon_runtime_pm != 0) &&
            radeon_has_atpx() &&
            ((flags & RADEON_IS_IGP) == 0) &&
-           !pci_is_thunderbolt_attached(dev->pdev))
+           !pci_is_thunderbolt_attached(pdev))
                flags |= RADEON_IS_PX;
 
        /* radeon_device_init should report only fatal error
@@ -150,9 +172,9 @@ int radeon_driver_load_kms(struct drm_device *dev, unsigned long flags)
         * properly initialize the GPU MC controller and permit
         * VRAM allocation
         */
-       r = radeon_device_init(rdev, dev, dev->pdev, flags);
+       r = radeon_device_init(rdev, rdev->dev, pdev, flags);
        if (r) {
-               dev_err(&dev->pdev->dev, "Fatal error during GPU init\n");
+               dev_err(&pdev->dev, "Fatal error during GPU init\n");
                goto out;
        }
 
@@ -162,7 +184,7 @@ int radeon_driver_load_kms(struct drm_device *dev, unsigned long flags)
         */
        r = radeon_modeset_init(rdev);
        if (r)
-               dev_err(&dev->pdev->dev, "Fatal error during modeset init\n");
+               dev_err(&pdev->dev, "Fatal error during modeset init\n");
 
        /* Call ACPI methods: require modeset init
         * but failure is not fatal
@@ -170,25 +192,27 @@ int radeon_driver_load_kms(struct drm_device *dev, unsigned long flags)
        if (!r) {
                acpi_status = radeon_acpi_init(rdev);
                if (acpi_status)
-               dev_dbg(&dev->pdev->dev,
+                       dev_dbg(&pdev->dev,
                                "Error during ACPI methods call\n");
        }
 
        radeon_kfd_device_probe(rdev);
        radeon_kfd_device_init(rdev);
 
-       if (radeon_is_px(dev)) {
-               pm_runtime_use_autosuspend(dev->dev);
-               pm_runtime_set_autosuspend_delay(dev->dev, 5000);
-               pm_runtime_set_active(dev->dev);
-               pm_runtime_allow(dev->dev);
-               pm_runtime_mark_last_busy(dev->dev);
-               pm_runtime_put_autosuspend(dev->dev);
+       if (radeon_is_px(pdev->dev)) {
+               pm_runtime_use_autosuspend(pdev->dev->dev);
+               pm_runtime_set_autosuspend_delay(pdev->dev->dev, 5000);
+               pm_runtime_set_active(pdev->dev->dev);
+               pm_runtime_allow(pdev->dev->dev);
+               pm_runtime_mark_last_busy(pdev->dev->dev);
+               pm_runtime_put_autosuspend(pdev->dev->dev);
        }
 
 out:
-       if (r)
-               radeon_driver_unload_kms(dev);
+       if (r) {
+               radeon_driver_unload_kms(pdev->dev);
+               pci_disable_device(pdev);
+       }
 
 
        return r;
--
Quoted 2 lines

2.7.4

Any update?

Aastha