Skip to contentSkip to conversation

platform/x86: amd-pmc: Store the pci_dev instance inside struct amd_pmc_dev

PATCH Superseded Sanket Goswami 2 participants 5 messages Oct 21, 2021 – Oct 22, 2021 x86 platform drivers

v2 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/2 platform/x86: amd-pmc: Store the pci_dev instance inside struct amd_pmc_dev

Store the root port information in amd_pmc_probe() so that the information can be used across multiple routines.

---
Changes in v2:
- Store the rdev info in amd_pmc_probe() as suggested by Hans.

 drivers/platform/x86/amd-pmc.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/platform/x86/amd-pmc.c +3 -1
index 55f14bdfdbfd..502f37eaba1f 100644
@@ -119,6 +119,7 @@ struct amd_pmc_dev {
 	u16 minor;
 	u16 rev;
 	struct device *dev;
+	struct pci_dev *rdev;
 	struct mutex lock; /* generic mutex lock */
 #if IS_ENABLED(CONFIG_DEBUG_FS)
 	struct dentry *dbgfs_dir;
@@ -482,6 +483,7 @@ static int amd_pmc_probe(struct platform_device *pdev)
 		return -ENODEV;
 	}
 
+	dev->rdev = rdev;
 	dev->cpu_id = rdev->device;
 	err = pci_write_config_dword(rdev, AMD_PMC_SMU_INDEX_ADDRESS, AMD_PMC_BASE_ADDR_LO);
 	if (err) {
@@ -512,7 +514,6 @@ static int amd_pmc_probe(struct platform_device *pdev)
 	}
 
 	base_addr_hi = val & AMD_PMC_BASE_ADDR_LO_MASK;
-	pci_dev_put(dev->rdev);
 	base_addr = ((u64)base_addr_hi << 32 | base_addr_lo);
 
 	dev->regbase = devm_ioremap(dev->dev, base_addr + AMD_PMC_BASE_ADDR_OFFSET,
@@ -546,6 +547,7 @@ static int amd_pmc_remove(struct platform_device *pdev)
 	struct amd_pmc_dev *dev = platform_get_drvdata(pdev);
 
 	amd_pmc_dbgfs_unregister(dev);
+	pci_dev_put(dev->rdev);
 	mutex_destroy(&dev->lock);
 	return 0;
 }
Signature · 1 line
2.25.1
#1 lore raw

Hi,

Quoted 7 lines · Sanket Goswami

Store the root port information in amd_pmc_probe() so that the information can be used across multiple routines.

---
Changes in v2:
- Store the rdev info in amd_pmc_probe() as suggested by Hans.

Thank you, but there are still some issues, see below.

Quoted 24 lines
 drivers/platform/x86/amd-pmc.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/platform/x86/amd-pmc.c +2 -0
index 55f14bdfdbfd..502f37eaba1f 100644
@@ -119,6 +119,7 @@ struct amd_pmc_dev {
 	u16 minor;
 	u16 rev;
 	struct device *dev;
+	struct pci_dev *rdev;
 	struct mutex lock; /* generic mutex lock */
 #if IS_ENABLED(CONFIG_DEBUG_FS)
 	struct dentry *dbgfs_dir;
@@ -482,6 +483,7 @@ static int amd_pmc_probe(struct platform_device *pdev)
 		return -ENODEV;
 	}
 
+	dev->rdev = rdev;
 	dev->cpu_id = rdev->device;
 	err = pci_write_config_dword(rdev, AMD_PMC_SMU_INDEX_ADDRESS, AMD_PMC_BASE_ADDR_LO);
 	if (err) {

drivers/platform/x86/amd-pmc.c static int amd_pmc_probe(struct platform_device *pdev) · line 515

Quoted 4 lines
drivers/platform/x86/amd-pmc.c +0 -1
@@ -512,7 +514,6 @@ static int amd_pmc_probe(struct platform_device *pdev)
 	}
 
 	base_addr_hi = val & AMD_PMC_BASE_ADDR_LO_MASK;
-	pci_dev_put(dev->rdev);

The current code here actually reads:

	pci_dev_put(rdev);

Note (rdev) not (dev->rdev). I don't know what you based this on, this is weird.

Also there are a bunch of error-exits from amd_pmc_probe() which not all need a "pci_dev_put(rdev)" added to them before there "return ERROR;" statement.

It would be best to add:

err_pci_dev_put:

	pci_dev_put(rdev);
	return err;

Add the end off the function (after the return 0;) and replace all "return FOO" error-exits with:

		err = <FOO>;
		goto err_pci_dev_put;
	}

Regards,

Hans

Quoted 12 lines
drivers/platform/x86/amd-pmc.c +1 -0
 	base_addr = ((u64)base_addr_hi << 32 | base_addr_lo);
 
 	dev->regbase = devm_ioremap(dev->dev, base_addr + AMD_PMC_BASE_ADDR_OFFSET,
@@ -546,6 +547,7 @@ static int amd_pmc_remove(struct platform_device *pdev)
 	struct amd_pmc_dev *dev = platform_get_drvdata(pdev);
 
 	amd_pmc_dbgfs_unregister(dev);
+	pci_dev_put(dev->rdev);
 	mutex_destroy(&dev->lock);
 	return 0;
 }
#2 lore raw

Hi Hans,

Quoted 42 lines · Hans de Goede

[CAUTION: External Email]

Hi,

Quoted 7 lines · Sanket Goswami

Store the root port information in amd_pmc_probe() so that the information can be used across multiple routines.

---
Changes in v2:
- Store the rdev info in amd_pmc_probe() as suggested by Hans.

Thank you, but there are still some issues, see below.

Quoted 26 lines
 drivers/platform/x86/amd-pmc.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/platform/x86/amd-pmc.c +2 -0
index 55f14bdfdbfd..502f37eaba1f 100644
@@ -119,6 +119,7 @@ struct amd_pmc_dev {
      u16 minor;
      u16 rev;
      struct device *dev;
+     struct pci_dev *rdev;
      struct mutex lock; /* generic mutex lock */
 #if IS_ENABLED(CONFIG_DEBUG_FS)
      struct dentry *dbgfs_dir;
@@ -482,6 +483,7 @@ static int amd_pmc_probe(struct platform_device *pdev)
              return -ENODEV;
      }
 
+     dev->rdev = rdev;
      dev->cpu_id = rdev->device;
      err = pci_write_config_dword(rdev, AMD_PMC_SMU_INDEX_ADDRESS, AMD_PMC_BASE_ADDR_LO);
      if (err) {
@@ -512,7 +514,6 @@ static int amd_pmc_probe(struct platform_device *pdev)
      }
 
Quoted 8 lines

drivers/platform/x86/amd-pmc.c static int amd_pmc_probe(struct platform_device *pdev) · line 515

Quoted 2 lines
drivers/platform/x86/amd-pmc.c +0 -1
      base_addr_hi = val & AMD_PMC_BASE_ADDR_LO_MASK;
-     pci_dev_put(dev->rdev);

The current code here actually reads:

        pci_dev_put(rdev);

Note (rdev) not (dev->rdev). I don't know what you based this on, this is weird.

rdev is already retrieved before doing this:

	     pci_dev_put(dev->rdev);

i.e.
in amd_pmc_probe()

rdev = pci_get_domain_bus_and_slot(0, 0, PCI_DEVFN(0, 0));
	if (!rdev || !pci_match_id(pmc_pci_ids, rdev)) {
		pci_dev_put(rdev);
		return -ENODEV;
	}

after this I am storing rdev in "dev->rdev"
i.e.
dev->rdev = rdev;

after this I am using "dev->rdev" at places where "rdev" was getting used earlier. Do you see any problem?

Quoted 11 lines

Also there are a bunch of error-exits from amd_pmc_probe() which not all need a "pci_dev_put(rdev)" added to them before there "return ERROR;" statement.

It would be best to add:

err_pci_dev_put:

        pci_dev_put(rdev);
        return err;
Quoted 7 lines

Add the end off the function (after the return 0;) and replace all "return FOO" error-exits with:

                err = <FOO>;
                goto err_pci_dev_put;
        }

Thank you, will take it as a separate patch in v3.

Thanks,
Sanket

#3 lore raw

Hi Sanket,

Quoted 66 lines · Sanket

Hi Hans,

Quoted 42 lines · Hans de Goede

[CAUTION: External Email]

Hi,

Quoted 7 lines · Sanket Goswami

Store the root port information in amd_pmc_probe() so that the information can be used across multiple routines.

---
Changes in v2:
- Store the rdev info in amd_pmc_probe() as suggested by Hans.

Thank you, but there are still some issues, see below.

Quoted 26 lines
 drivers/platform/x86/amd-pmc.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/platform/x86/amd-pmc.c +2 -0
index 55f14bdfdbfd..502f37eaba1f 100644
@@ -119,6 +119,7 @@ struct amd_pmc_dev {
      u16 minor;
      u16 rev;
      struct device *dev;
+     struct pci_dev *rdev;
      struct mutex lock; /* generic mutex lock */
 #if IS_ENABLED(CONFIG_DEBUG_FS)
      struct dentry *dbgfs_dir;
@@ -482,6 +483,7 @@ static int amd_pmc_probe(struct platform_device *pdev)
              return -ENODEV;
      }
 
+     dev->rdev = rdev;
      dev->cpu_id = rdev->device;
      err = pci_write_config_dword(rdev, AMD_PMC_SMU_INDEX_ADDRESS, AMD_PMC_BASE_ADDR_LO);
      if (err) {
@@ -512,7 +514,6 @@ static int amd_pmc_probe(struct platform_device *pdev)
      }
 
Quoted 8 lines

drivers/platform/x86/amd-pmc.c static int amd_pmc_probe(struct platform_device *pdev) · line 515

Quoted 2 lines
drivers/platform/x86/amd-pmc.c +0 -1
      base_addr_hi = val & AMD_PMC_BASE_ADDR_LO_MASK;
-     pci_dev_put(dev->rdev);

The current code here actually reads:

        pci_dev_put(rdev);

Note (rdev) not (dev->rdev). I don't know what you based this on, this is weird.

rdev is already retrieved before doing this:

	     pci_dev_put(dev->rdev);

i.e.
in amd_pmc_probe()

rdev = pci_get_domain_bus_and_slot(0, 0, PCI_DEVFN(0, 0));
	if (!rdev || !pci_match_id(pmc_pci_ids, rdev)) {
		pci_dev_put(rdev);
		return -ENODEV;
	}
Quoted 6 lines

after this I am storing rdev in "dev->rdev"
i.e.
dev->rdev = rdev;

after this I am using "dev->rdev" at places where "rdev" was getting used earlier. Do you see any problem?

What I was trying to say is that the patch does not apply, because it is trying to remove the pci_put_dev() line from a block of code like this:

	base_addr_hi = val & AMD_PMC_BASE_ADDR_LO_MASK;
	pci_dev_put(dev->rdev);
	base_addr = ((u64)base_addr_hi << 32 | base_addr_lo);

But the actual code in platform-drivers-x86/review-hans (and for-next too) has:

	base_addr_hi = val & AMD_PMC_BASE_ADDR_LO_MASK;
	pci_dev_put(rdev);
	base_addr = ((u64)base_addr_hi << 32 | base_addr_lo);

After your patch using dev->rdev instead of just rdev is fine (but please be consistent, which would mean use just rdev everywhere).

But your patch is removing a line which does not exist in that form, IOW it is based on some intermediate version of amd-pmc.c and not on the HEAD of platform-drivers-x86/review-hans.

Regards,

Hans

Quoted 25 lines
Quoted 12 lines

Also there are a bunch of error-exits from amd_pmc_probe() which not all need a "pci_dev_put(rdev)" added to them before there "return ERROR;" statement.

It would be best to add:

err_pci_dev_put:

        pci_dev_put(rdev);
        return err;
Quoted 7 lines

Add the end off the function (after the return 0;) and replace all "return FOO" error-exits with:

                err = <FOO>;
                goto err_pci_dev_put;
        }

Thank you, will take it as a separate patch in v3.

Thanks,
Sanket

#4 lore raw

Hi Hans,

Quoted 93 lines · Hans de Goede

[CAUTION: External Email]

Hi Sanket,

Quoted 66 lines · Sanket

Hi Hans,

Quoted 42 lines · Hans de Goede

[CAUTION: External Email]

Hi,

Quoted 7 lines · Sanket Goswami

Store the root port information in amd_pmc_probe() so that the information can be used across multiple routines.

---
Changes in v2:
- Store the rdev info in amd_pmc_probe() as suggested by Hans.

Thank you, but there are still some issues, see below.

Quoted 26 lines
 drivers/platform/x86/amd-pmc.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/platform/x86/amd-pmc.c +2 -0
index 55f14bdfdbfd..502f37eaba1f 100644
@@ -119,6 +119,7 @@ struct amd_pmc_dev {
      u16 minor;
      u16 rev;
      struct device *dev;
+     struct pci_dev *rdev;
      struct mutex lock; /* generic mutex lock */
 #if IS_ENABLED(CONFIG_DEBUG_FS)
      struct dentry *dbgfs_dir;
@@ -482,6 +483,7 @@ static int amd_pmc_probe(struct platform_device *pdev)
              return -ENODEV;
      }
 
+     dev->rdev = rdev;
      dev->cpu_id = rdev->device;
      err = pci_write_config_dword(rdev, AMD_PMC_SMU_INDEX_ADDRESS, AMD_PMC_BASE_ADDR_LO);
      if (err) {
@@ -512,7 +514,6 @@ static int amd_pmc_probe(struct platform_device *pdev)
      }
 
Quoted 8 lines

drivers/platform/x86/amd-pmc.c static int amd_pmc_probe(struct platform_device *pdev) · line 515

Quoted 2 lines
drivers/platform/x86/amd-pmc.c +0 -1
      base_addr_hi = val & AMD_PMC_BASE_ADDR_LO_MASK;
-     pci_dev_put(dev->rdev);

The current code here actually reads:

        pci_dev_put(rdev);

Note (rdev) not (dev->rdev). I don't know what you based this on, this is weird.

rdev is already retrieved before doing this:

           pci_dev_put(dev->rdev);

i.e.
in amd_pmc_probe()

rdev = pci_get_domain_bus_and_slot(0, 0, PCI_DEVFN(0, 0));
      if (!rdev || !pci_match_id(pmc_pci_ids, rdev)) {
              pci_dev_put(rdev);
              return -ENODEV;
      }
Quoted 6 lines

after this I am storing rdev in "dev->rdev"
i.e.
dev->rdev = rdev;

after this I am using "dev->rdev" at places where "rdev" was getting used earlier. Do you see any problem?

What I was trying to say is that the patch does not apply, because it is trying to remove the pci_put_dev() line from a block of code like this:

        base_addr_hi = val & AMD_PMC_BASE_ADDR_LO_MASK;
        pci_dev_put(dev->rdev);
        base_addr = ((u64)base_addr_hi << 32 | base_addr_lo);

But the actual code in platform-drivers-x86/review-hans (and for-next too) has:

        base_addr_hi = val & AMD_PMC_BASE_ADDR_LO_MASK;
        pci_dev_put(rdev);
        base_addr = ((u64)base_addr_hi << 32 | base_addr_lo);
Quoted 6 lines

After your patch using dev->rdev instead of just rdev is fine (but please be consistent, which would mean use just rdev everywhere).

But your patch is removing a line which does not exist in that form, IOW it is based on some intermediate version of amd-pmc.c and not on the HEAD of platform-drivers-x86/review-hans.

I will rebase it to review-hans branch and will respin a new version.

Thanks,
Sanket