Patchwork [RFC,1/4] ahci: port legacy pm interface to struct dev_pm_ops

login
register
mail settings
Submitter Lin Ming
Date Dec. 15, 2011, 1:12 p.m.
Message ID <1323954769-3918-2-git-send-email-ming.m.lin@intel.com>
Download mbox | patch
Permalink /patch/131603/
State Not Applicable
Delegated to: David Miller
Headers show

Comments

Lin Ming - Dec. 15, 2011, 1:12 p.m.
So we can add runtime pm callbacks later.

Signed-off-by: Lin Ming <ming.m.lin@intel.com>
---
 drivers/ata/ahci.c |   61 +++++++++++++++++++++++++++++++++++-----------------
 1 files changed, 41 insertions(+), 20 deletions(-)
Rafael J. Wysocki - Dec. 15, 2011, 7:53 p.m.
On Thursday, December 15, 2011, Lin Ming wrote:
> So we can add runtime pm callbacks later.
> 
> Signed-off-by: Lin Ming <ming.m.lin@intel.com>
> ---
>  drivers/ata/ahci.c |   61 +++++++++++++++++++++++++++++++++++-----------------
>  1 files changed, 41 insertions(+), 20 deletions(-)
> 
> diff --git a/drivers/ata/ahci.c b/drivers/ata/ahci.c
> index cf26222..c745603 100644
> --- a/drivers/ata/ahci.c
> +++ b/drivers/ata/ahci.c
> @@ -84,8 +84,9 @@ static int ahci_vt8251_hardreset(struct ata_link *link, unsigned int *class,
>  static int ahci_p5wdh_hardreset(struct ata_link *link, unsigned int *class,
>  				unsigned long deadline);
>  #ifdef CONFIG_PM
> -static int ahci_pci_device_suspend(struct pci_dev *pdev, pm_message_t mesg);
> -static int ahci_pci_device_resume(struct pci_dev *pdev);
> +static int ahci_pci_device_suspend(struct device *dev);
> +static int ahci_pci_device_hibernate(struct device *dev);
> +static int ahci_pci_device_resume(struct device *dev);
>  #endif
>  
>  static struct scsi_host_template ahci_sht = {
> @@ -400,6 +401,11 @@ static const struct pci_device_id ahci_pci_tbl[] = {
>  	{ }	/* terminate list */
>  };
>  
> +static struct dev_pm_ops ahci_pci_pm_ops = {
> +	.suspend		= ahci_pci_device_suspend,
> +	.resume			= ahci_pci_device_resume,
> +	.poweroff		= ahci_pci_device_hibernate,
> +};

So seem to have forgotten about .restore().  Please define it at least or
resume from hibernation will be broken.

Also, are .freeze() and .thaw() callbacks really unnecessary?

Rafael


>  static struct pci_driver ahci_pci_driver = {
>  	.name			= DRV_NAME,
> @@ -407,8 +413,9 @@ static struct pci_driver ahci_pci_driver = {
>  	.probe			= ahci_init_one,
>  	.remove			= ata_pci_remove_one,
>  #ifdef CONFIG_PM
> -	.suspend		= ahci_pci_device_suspend,
> -	.resume			= ahci_pci_device_resume,
> +	.driver			= {
> +		.pm = &ahci_pci_pm_ops
> +	},
>  #endif
>  };
>  
> @@ -567,37 +574,51 @@ static int ahci_p5wdh_hardreset(struct ata_link *link, unsigned int *class,
>  }
>  
>  #ifdef CONFIG_PM
> -static int ahci_pci_device_suspend(struct pci_dev *pdev, pm_message_t mesg)
> +static int ahci_pci_device_suspend_common(struct pci_dev *pdev, pm_message_t mesg)
>  {
>  	struct ata_host *host = dev_get_drvdata(&pdev->dev);
>  	struct ahci_host_priv *hpriv = host->private_data;
>  	void __iomem *mmio = hpriv->mmio;
>  	u32 ctl;
>  
> -	if (mesg.event & PM_EVENT_SUSPEND &&
> -	    hpriv->flags & AHCI_HFLAG_NO_SUSPEND) {
> +	/* AHCI spec rev1.1 section 8.3.3:
> +	 * Software must disable interrupts prior to requesting a
> +	 * transition of the HBA to D3 state.
> +	 */
> +	ctl = readl(mmio + HOST_CTL);
> +	ctl &= ~HOST_IRQ_EN;
> +	writel(ctl, mmio + HOST_CTL);
> +	readl(mmio + HOST_CTL); /* flush */
> +
> +	return ata_pci_device_suspend(pdev, mesg);
> +}
> +
> +static int ahci_pci_device_suspend(struct device *dev)
> +{
> +	struct ata_host *host = dev_get_drvdata(dev);
> +	struct ahci_host_priv *hpriv = host->private_data;
> +	struct pci_dev *pdev = to_pci_dev(dev);
> +
> +	if (hpriv->flags & AHCI_HFLAG_NO_SUSPEND) {
>  		dev_err(&pdev->dev,
>  			"BIOS update required for suspend/resume\n");
>  		return -EIO;
>  	}
>  
> -	if (mesg.event & PM_EVENT_SLEEP) {
> -		/* AHCI spec rev1.1 section 8.3.3:
> -		 * Software must disable interrupts prior to requesting a
> -		 * transition of the HBA to D3 state.
> -		 */
> -		ctl = readl(mmio + HOST_CTL);
> -		ctl &= ~HOST_IRQ_EN;
> -		writel(ctl, mmio + HOST_CTL);
> -		readl(mmio + HOST_CTL); /* flush */
> -	}
> +	return ahci_pci_device_suspend_common(pdev, PMSG_SUSPEND);
> +}
>  
> -	return ata_pci_device_suspend(pdev, mesg);
> +static int ahci_pci_device_hibernate(struct device *dev)
> +{
> +	struct pci_dev *pdev = to_pci_dev(dev);
> +
> +	return ahci_pci_device_suspend_common(pdev, PMSG_HIBERNATE);
>  }
>  
> -static int ahci_pci_device_resume(struct pci_dev *pdev)
> +static int ahci_pci_device_resume(struct device *dev)
>  {
> -	struct ata_host *host = dev_get_drvdata(&pdev->dev);
> +	struct ata_host *host = dev_get_drvdata(dev);
> +	struct pci_dev *pdev = to_pci_dev(dev);
>  	int rc;
>  
>  	rc = ata_pci_device_do_resume(pdev);
> 

--
To unsubscribe from this list: send the line "unsubscribe linux-ide" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Lin Ming - Dec. 16, 2011, 1:07 p.m.
2011/12/16 Rafael J. Wysocki <rjw@sisk.pl>:
> On Thursday, December 15, 2011, Lin Ming wrote:
>> So we can add runtime pm callbacks later.
>>
>> Signed-off-by: Lin Ming <ming.m.lin@intel.com>
>> ---
>>  drivers/ata/ahci.c |   61 +++++++++++++++++++++++++++++++++++-----------------
>>  1 files changed, 41 insertions(+), 20 deletions(-)
>>
>> diff --git a/drivers/ata/ahci.c b/drivers/ata/ahci.c
>> index cf26222..c745603 100644
>> --- a/drivers/ata/ahci.c
>> +++ b/drivers/ata/ahci.c
>> @@ -84,8 +84,9 @@ static int ahci_vt8251_hardreset(struct ata_link *link, unsigned int *class,
>>  static int ahci_p5wdh_hardreset(struct ata_link *link, unsigned int *class,
>>                               unsigned long deadline);
>>  #ifdef CONFIG_PM
>> -static int ahci_pci_device_suspend(struct pci_dev *pdev, pm_message_t mesg);
>> -static int ahci_pci_device_resume(struct pci_dev *pdev);
>> +static int ahci_pci_device_suspend(struct device *dev);
>> +static int ahci_pci_device_hibernate(struct device *dev);
>> +static int ahci_pci_device_resume(struct device *dev);
>>  #endif
>>
>>  static struct scsi_host_template ahci_sht = {
>> @@ -400,6 +401,11 @@ static const struct pci_device_id ahci_pci_tbl[] = {
>>       { }     /* terminate list */
>>  };
>>
>> +static struct dev_pm_ops ahci_pci_pm_ops = {
>> +     .suspend                = ahci_pci_device_suspend,
>> +     .resume                 = ahci_pci_device_resume,
>> +     .poweroff               = ahci_pci_device_hibernate,
>> +};
>
> So seem to have forgotten about .restore().  Please define it at least or
> resume from hibernation will be broken.

Will add it.

>
> Also, are .freeze() and .thaw() callbacks really unnecessary?

I'm not sure for now.
Will test hibernation.

Thanks for the comments.

Lin Ming

>
> Rafael
--
To unsubscribe from this list: send the line "unsubscribe linux-ide" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Patch

diff --git a/drivers/ata/ahci.c b/drivers/ata/ahci.c
index cf26222..c745603 100644
--- a/drivers/ata/ahci.c
+++ b/drivers/ata/ahci.c
@@ -84,8 +84,9 @@  static int ahci_vt8251_hardreset(struct ata_link *link, unsigned int *class,
 static int ahci_p5wdh_hardreset(struct ata_link *link, unsigned int *class,
 				unsigned long deadline);
 #ifdef CONFIG_PM
-static int ahci_pci_device_suspend(struct pci_dev *pdev, pm_message_t mesg);
-static int ahci_pci_device_resume(struct pci_dev *pdev);
+static int ahci_pci_device_suspend(struct device *dev);
+static int ahci_pci_device_hibernate(struct device *dev);
+static int ahci_pci_device_resume(struct device *dev);
 #endif
 
 static struct scsi_host_template ahci_sht = {
@@ -400,6 +401,11 @@  static const struct pci_device_id ahci_pci_tbl[] = {
 	{ }	/* terminate list */
 };
 
+static struct dev_pm_ops ahci_pci_pm_ops = {
+	.suspend		= ahci_pci_device_suspend,
+	.resume			= ahci_pci_device_resume,
+	.poweroff		= ahci_pci_device_hibernate,
+};
 
 static struct pci_driver ahci_pci_driver = {
 	.name			= DRV_NAME,
@@ -407,8 +413,9 @@  static struct pci_driver ahci_pci_driver = {
 	.probe			= ahci_init_one,
 	.remove			= ata_pci_remove_one,
 #ifdef CONFIG_PM
-	.suspend		= ahci_pci_device_suspend,
-	.resume			= ahci_pci_device_resume,
+	.driver			= {
+		.pm = &ahci_pci_pm_ops
+	},
 #endif
 };
 
@@ -567,37 +574,51 @@  static int ahci_p5wdh_hardreset(struct ata_link *link, unsigned int *class,
 }
 
 #ifdef CONFIG_PM
-static int ahci_pci_device_suspend(struct pci_dev *pdev, pm_message_t mesg)
+static int ahci_pci_device_suspend_common(struct pci_dev *pdev, pm_message_t mesg)
 {
 	struct ata_host *host = dev_get_drvdata(&pdev->dev);
 	struct ahci_host_priv *hpriv = host->private_data;
 	void __iomem *mmio = hpriv->mmio;
 	u32 ctl;
 
-	if (mesg.event & PM_EVENT_SUSPEND &&
-	    hpriv->flags & AHCI_HFLAG_NO_SUSPEND) {
+	/* AHCI spec rev1.1 section 8.3.3:
+	 * Software must disable interrupts prior to requesting a
+	 * transition of the HBA to D3 state.
+	 */
+	ctl = readl(mmio + HOST_CTL);
+	ctl &= ~HOST_IRQ_EN;
+	writel(ctl, mmio + HOST_CTL);
+	readl(mmio + HOST_CTL); /* flush */
+
+	return ata_pci_device_suspend(pdev, mesg);
+}
+
+static int ahci_pci_device_suspend(struct device *dev)
+{
+	struct ata_host *host = dev_get_drvdata(dev);
+	struct ahci_host_priv *hpriv = host->private_data;
+	struct pci_dev *pdev = to_pci_dev(dev);
+
+	if (hpriv->flags & AHCI_HFLAG_NO_SUSPEND) {
 		dev_err(&pdev->dev,
 			"BIOS update required for suspend/resume\n");
 		return -EIO;
 	}
 
-	if (mesg.event & PM_EVENT_SLEEP) {
-		/* AHCI spec rev1.1 section 8.3.3:
-		 * Software must disable interrupts prior to requesting a
-		 * transition of the HBA to D3 state.
-		 */
-		ctl = readl(mmio + HOST_CTL);
-		ctl &= ~HOST_IRQ_EN;
-		writel(ctl, mmio + HOST_CTL);
-		readl(mmio + HOST_CTL); /* flush */
-	}
+	return ahci_pci_device_suspend_common(pdev, PMSG_SUSPEND);
+}
 
-	return ata_pci_device_suspend(pdev, mesg);
+static int ahci_pci_device_hibernate(struct device *dev)
+{
+	struct pci_dev *pdev = to_pci_dev(dev);
+
+	return ahci_pci_device_suspend_common(pdev, PMSG_HIBERNATE);
 }
 
-static int ahci_pci_device_resume(struct pci_dev *pdev)
+static int ahci_pci_device_resume(struct device *dev)
 {
-	struct ata_host *host = dev_get_drvdata(&pdev->dev);
+	struct ata_host *host = dev_get_drvdata(dev);
+	struct pci_dev *pdev = to_pci_dev(dev);
 	int rc;
 
 	rc = ata_pci_device_do_resume(pdev);