dmaengine: pch_dma: use generic power management
PATCH 1/1 dmaengine: pch_dma: use generic power management
Drivers using legacy PM have to manage PCI states and device's PM states themselves. They also need to take care of configuration registers.
With improved and powerful support of generic PM, PCI Core takes care of above mentioned, device-independent, jobs.
This driver makes use of PCI helper functions like pci_save/restore_state(), pci_enable/disable_device(),
and pci_set_power_state() to do required operations. In generic mode, they are no longer needed.
Change function parameter in both .suspend() and .resume() to "struct device*" type. Use dev_get_drvdata() to get drv data.
Compile-tested only.
--- drivers/dma/pch_dma.c | 35 +++++++++-------------------------- 1 file changed, 9 insertions(+), 26 deletions(-)
drivers/dma/pch_dma.c +9 -26
@@ -735,8 +735,7 @@ static irqreturn_t pd_irq(int irq, void *devid)return ret0 | ret2; } -#ifdef CONFIG_PM -static void pch_dma_save_regs (struct pch_dma *pd) +static void __maybe_unused pch_dma_save_regs (struct pch_dma *pd) {struct pch_dma_chan *pd_chan;struct dma_chan *chan, *_c;
@@ -759,7 +758,7 @@ static void pch_dma_save_regs(struct pch_dma *pd) } } -static void pch_dma_restore_regs (struct pch_dma *pd) +static void __maybe_unused pch_dma_restore_regs (struct pch_dma *pd) {struct pch_dma_chan *pd_chan;struct dma_chan *chan, *_c;
@@ -782,40 +781,25 @@ static void pch_dma_restore_regs(struct pch_dma *pd) } } -static int pch_dma_suspend (struct pci_dev *pdev,pm_message_t state) +static int __maybe_unused pch_dma_suspend (struct device *dev) { -struct pch_dma *pd =pci_get_drvdata (pdev); +struct pch_dma *pd =dev_get_drvdata (dev);if (pd)pch_dma_save_regs (pd); -pci_save_state (pdev); -pci_disable_device (pdev); -pci_set_power_state (pdev,pci_choose_state (pdev, state)); -return 0 ; } -static int pch_dma_resume (struct pci_dev *pdev) +static int __maybe_unused pch_dma_resume (struct device *dev) { -struct pch_dma *pd =pci_get_drvdata (pdev); -int err; - -pci_set_power_state (pdev,PCI_D0 ); -pci_restore_state (pdev); - - err =pci_enable_device (pdev); -if (err) { -dev_dbg (&pdev->dev,"failed to enable device\n" ); -return err; - } +struct pch_dma *pd =dev_get_drvdata (dev);if (pd)pch_dma_restore_regs (pd);return 0 ; } -#endif static int pch_dma_probe (struct pci_dev *pdev,const struct pci_device_id *id)
@@ -993,15 +977,14 @@ static const struct pci_device_id pch_dma_id_table[] = { { 0, }, }; +static SIMPLE_DEV_PM_OPS(pch_dma_pm_ops, pch_dma_suspend, pch_dma_resume); +static struct pci_driver pch_dma_driver = { .name =DRV_NAME , .id_table = pch_dma_id_table, .probe = pch_dma_probe, .remove = pch_dma_remove, -#ifdef CONFIG_PM - .suspend = pch_dma_suspend, - .resume = pch_dma_resume, -#endif + .driver.pm = &pch_dma_pm_ops, };module_pci_driver (pch_dma_driver);
Signature · 1 line
2.27.0
Vinod Koul
maintainerHi Vaibhav,
Quoted 6 lines · Vaibhav Gupta
Drivers using legacy PM have to manage PCI states and device's PM states themselves. They also need to take care of configuration registers.
With improved and powerful support of generic PM, PCI Core takes care of above mentioned, device-independent, jobs.
Quoted 7 lines
This driver makes use of PCI helper functions like pci_save/restore_state(), pci_enable/disable_device(),
andpci_set_power_state()to do required operations. In generic mode, they are no longer needed.Change function parameter in both .suspend() and .resume() to "struct device*" type. Use
dev_get_drvdata()to get drv data.
You are doing too many things in One patch. Do consider splitting them up to a change per patch. for example using __maybe could be one patch, removing code is suspend-resume callbacks would be other one.
Quoted 2 lines
Compile-tested only.
I would like to see some testing before we merge this
Quoted 95 lines
Signed-off-by Vaibhav Gupta <[email protected]>--- drivers/dma/pch_dma.c | 35 +++++++++-------------------------- 1 file changed, 9 insertions(+), 26 deletions(-)drivers/dma/pch_dma.c +9
-26@@ -735,8 +735,7 @@ static irqreturn_t pd_irq(int irq, void *devid)return ret0 | ret2; } -#ifdef CONFIG_PM -static void pch_dma_save_regs (struct pch_dma *pd) +static void __maybe_unused pch_dma_save_regs (struct pch_dma *pd) {struct pch_dma_chan *pd_chan;struct dma_chan *chan, *_c;@@ -759,7 +758,7 @@ static void pch_dma_save_regs(struct pch_dma *pd) } } -static void pch_dma_restore_regs (struct pch_dma *pd) +static void __maybe_unused pch_dma_restore_regs (struct pch_dma *pd) {struct pch_dma_chan *pd_chan;struct dma_chan *chan, *_c;@@ -782,40 +781,25 @@ static void pch_dma_restore_regs(struct pch_dma *pd) } } -static int pch_dma_suspend (struct pci_dev *pdev,pm_message_t state) +static int __maybe_unused pch_dma_suspend (struct device *dev) { -struct pch_dma *pd =pci_get_drvdata (pdev); +struct pch_dma *pd =dev_get_drvdata (dev);if (pd)pch_dma_save_regs (pd); -pci_save_state (pdev); -pci_disable_device (pdev); -pci_set_power_state (pdev,pci_choose_state (pdev, state)); -return 0 ; } -static int pch_dma_resume (struct pci_dev *pdev) +static int __maybe_unused pch_dma_resume (struct device *dev) { -struct pch_dma *pd =pci_get_drvdata (pdev); -int err; - -pci_set_power_state (pdev,PCI_D0 ); -pci_restore_state (pdev); - - err =pci_enable_device (pdev); -if (err) { -dev_dbg (&pdev->dev,"failed to enable device\n" ); -return err; - } +struct pch_dma *pd =dev_get_drvdata (dev);if (pd)pch_dma_restore_regs (pd);return 0 ; } -#endif static int pch_dma_probe (struct pci_dev *pdev,const struct pci_device_id *id)@@ -993,15 +977,14 @@ static const struct pci_device_id pch_dma_id_table[] = { { 0, }, }; +static SIMPLE_DEV_PM_OPS(pch_dma_pm_ops, pch_dma_suspend, pch_dma_resume); +static struct pci_driver pch_dma_driver = { .name =DRV_NAME , .id_table = pch_dma_id_table, .probe = pch_dma_probe, .remove = pch_dma_remove, -#ifdef CONFIG_PM - .suspend = pch_dma_suspend, - .resume = pch_dma_resume, -#endif + .driver.pm = &pch_dma_pm_ops, };module_pci_driver (pch_dma_driver);Signature · 1 line
2.27.0
Signature · 1 line
~Vinod
Quoted 14 lines · Vinod Koul
Hi Vaibhav,
Quoted 11 lines · Vaibhav Gupta
Drivers using legacy PM have to manage PCI states and device's PM states themselves. They also need to take care of configuration registers.
With improved and powerful support of generic PM, PCI Core takes care of above mentioned, device-independent, jobs.
This driver makes use of PCI helper functions like pci_save/restore_state(), pci_enable/disable_device(),
andpci_set_power_state()to do required operations. In generic mode, they are no longer needed.
Quoted 7 lines
Quoted 2 lines
Change function parameter in both .suspend() and .resume() to "struct device*" type. Use
dev_get_drvdata()to get drv data.You are doing too many things in One patch. Do consider splitting them up to a change per patch. for example using
__maybecould be one patch, removing code is suspend-resume callbacks would be other one.
Sure. But I guess just marking of "__maybe_unused" is not some significant change. All the legacy PCI drivers have .suspend() and .resume() inside "#ifdef CONFIG_PM" container.
It is only when I am upgrading them one by one to generic, I remove the container and mark them with the attribute. So it is like a part of complete generic upgrade.
Thanks
Vaibhav Gupta
Quoted 96 lines
Quoted 1 line
Compile-tested only.
I would like to see some testing before we merge this
Quoted 92 lines
Signed-off-by Vaibhav Gupta <[email protected]>--- drivers/dma/pch_dma.c | 35 +++++++++-------------------------- 1 file changed, 9 insertions(+), 26 deletions(-)drivers/dma/pch_dma.c +9
-26@@ -735,8 +735,7 @@ static irqreturn_t pd_irq(int irq, void *devid)return ret0 | ret2; } -#ifdef CONFIG_PM -static void pch_dma_save_regs (struct pch_dma *pd) +static void __maybe_unused pch_dma_save_regs (struct pch_dma *pd) {struct pch_dma_chan *pd_chan;struct dma_chan *chan, *_c;@@ -759,7 +758,7 @@ static void pch_dma_save_regs(struct pch_dma *pd) } } -static void pch_dma_restore_regs (struct pch_dma *pd) +static void __maybe_unused pch_dma_restore_regs (struct pch_dma *pd) {struct pch_dma_chan *pd_chan;struct dma_chan *chan, *_c;@@ -782,40 +781,25 @@ static void pch_dma_restore_regs(struct pch_dma *pd) } } -static int pch_dma_suspend (struct pci_dev *pdev,pm_message_t state) +static int __maybe_unused pch_dma_suspend (struct device *dev) { -struct pch_dma *pd =pci_get_drvdata (pdev); +struct pch_dma *pd =dev_get_drvdata (dev);if (pd)pch_dma_save_regs (pd); -pci_save_state (pdev); -pci_disable_device (pdev); -pci_set_power_state (pdev,pci_choose_state (pdev, state)); -return 0 ; } -static int pch_dma_resume (struct pci_dev *pdev) +static int __maybe_unused pch_dma_resume (struct device *dev) { -struct pch_dma *pd =pci_get_drvdata (pdev); -int err; - -pci_set_power_state (pdev,PCI_D0 ); -pci_restore_state (pdev); - - err =pci_enable_device (pdev); -if (err) { -dev_dbg (&pdev->dev,"failed to enable device\n" ); -return err; - } +struct pch_dma *pd =dev_get_drvdata (dev);if (pd)pch_dma_restore_regs (pd);return 0 ; } -#endif static int pch_dma_probe (struct pci_dev *pdev,const struct pci_device_id *id)@@ -993,15 +977,14 @@ static const struct pci_device_id pch_dma_id_table[] = { { 0, }, }; +static SIMPLE_DEV_PM_OPS(pch_dma_pm_ops, pch_dma_suspend, pch_dma_resume); +static struct pci_driver pch_dma_driver = { .name =DRV_NAME , .id_table = pch_dma_id_table, .probe = pch_dma_probe, .remove = pch_dma_remove, -#ifdef CONFIG_PM - .suspend = pch_dma_suspend, - .resume = pch_dma_resume, -#endif + .driver.pm = &pch_dma_pm_ops, };
Quoted 6 lines
Quoted 3 lines
drivers/dma/pch_dma.c +0
-0module_pci_driver (pch_dma_driver);Signature · 1 line
2.27.0Signature · 1 line
~Vinod
_______________________________________________
Linux-kernel-mentees mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
Andy Shevchenko
Reviewed-byQuoted 12 lines · Vinod Koul
Quoted 11 lines · Vaibhav Gupta
Drivers using legacy PM have to manage PCI states and device's PM states themselves. They also need to take care of configuration registers.
With improved and powerful support of generic PM, PCI Core takes care of above mentioned, device-independent, jobs.
This driver makes use of PCI helper functions like pci_save/restore_state(), pci_enable/disable_device(),
andpci_set_power_state()to do required operations. In generic mode, they are no longer needed.
Quoted 6 lines
Quoted 2 lines
Change function parameter in both .suspend() and .resume() to "struct device*" type. Use
dev_get_drvdata()to get drv data.You are doing too many things in One patch. Do consider splitting them up to a change per patch. for example using
__maybecould be one patch, removing code is suspend-resume callbacks would be other one.
Vinod, while I completely agree with you in general, in this case it would make more unnecessary churn and will be rather unhelpful in all
ways: for the contributor to do this work, for the reader to collect all the pieces. It also will be a bisectability issue, because the #ifdeffery replacement (IIRC you need to move from CONFIG_PM to CONFIG_PM_SLEEP). I really don't see any advantages of the splitting here.
Quoted 3 lines
Quoted 1 line
Compile-tested only.
I would like to see some testing before we merge this
I have hardware to test (Intel Minnowboard v1) but have no time. And taking into account that I did similar changes for many other drivers, I can give my
and take responsibility if somebody complains in the future (I don't believe it will be one).
P.S. Another scenario if Vaibhav can find that board (there were dozens of thousands at least produced and floating on the second hand market) and test himself. It may be good since he touches the full lot of PCH (EGT20) drivers.
Quoted 97 lines
Quoted 93 lines
Signed-off-by Vaibhav Gupta <[email protected]>--- drivers/dma/pch_dma.c | 35 +++++++++-------------------------- 1 file changed, 9 insertions(+), 26 deletions(-)drivers/dma/pch_dma.c +9
-27@@ -735,8 +735,7 @@ static irqreturn_t pd_irq(int irq, void *devid)return ret0 | ret2; } -#ifdef CONFIG_PM -static void pch_dma_save_regs (struct pch_dma *pd) +static void __maybe_unused pch_dma_save_regs (struct pch_dma *pd) {struct pch_dma_chan *pd_chan;struct dma_chan *chan, *_c;@@ -759,7 +758,7 @@ static void pch_dma_save_regs(struct pch_dma *pd) } } -static void pch_dma_restore_regs (struct pch_dma *pd) +static void __maybe_unused pch_dma_restore_regs (struct pch_dma *pd) {struct pch_dma_chan *pd_chan;struct dma_chan *chan, *_c;@@ -782,40 +781,25 @@ static void pch_dma_restore_regs(struct pch_dma *pd) } } -static int pch_dma_suspend (struct pci_dev *pdev,pm_message_t state) +static int __maybe_unused pch_dma_suspend (struct device *dev) { -struct pch_dma *pd =pci_get_drvdata (pdev); +struct pch_dma *pd =dev_get_drvdata (dev);if (pd)pch_dma_save_regs (pd); -pci_save_state (pdev); -pci_disable_device (pdev); -pci_set_power_state (pdev,pci_choose_state (pdev, state)); -return 0 ; } -static int pch_dma_resume (struct pci_dev *pdev) +static int __maybe_unused pch_dma_resume (struct device *dev) { -struct pch_dma *pd =pci_get_drvdata (pdev); -int err; - -pci_set_power_state (pdev,PCI_D0 ); -pci_restore_state (pdev); - - err =pci_enable_device (pdev); -if (err) { -dev_dbg (&pdev->dev,"failed to enable device\n" ); -return err; - } +struct pch_dma *pd =dev_get_drvdata (dev);if (pd)pch_dma_restore_regs (pd);return 0 ; } -#endif static int pch_dma_probe (struct pci_dev *pdev,const struct pci_device_id *id)@@ -993,15 +977,14 @@ static const struct pci_device_id pch_dma_id_table[] = { { 0, }, }; +static SIMPLE_DEV_PM_OPS(pch_dma_pm_ops, pch_dma_suspend, pch_dma_resume); +static struct pci_driver pch_dma_driver = { .name =DRV_NAME , .id_table = pch_dma_id_table, .probe = pch_dma_probe, .remove = pch_dma_remove, -#ifdef CONFIG_PM - .suspend = pch_dma_suspend, - .resume = pch_dma_resume, -#endif + .driver.pm = &pch_dma_pm_ops, };module_pci_driver (pch_dma_driver); --Quoted 1 line
2.27.0
--
~Vinod
Signature · 2 lines
With Best Regards, Andy Shevchenko
Quoted 30 lines · Andy Shevchenko
Quoted 12 lines · Vinod Koul
Quoted 11 lines · Vaibhav Gupta
Drivers using legacy PM have to manage PCI states and device's PM states themselves. They also need to take care of configuration registers.
With improved and powerful support of generic PM, PCI Core takes care of above mentioned, device-independent, jobs.
This driver makes use of PCI helper functions like pci_save/restore_state(), pci_enable/disable_device(),
andpci_set_power_state()to do required operations. In generic mode, they are no longer needed.Quoted 6 lines
Quoted 2 lines
Change function parameter in both .suspend() and .resume() to "struct device*" type. Use
dev_get_drvdata()to get drv data.You are doing too many things in One patch. Do consider splitting them up to a change per patch. for example using
__maybecould be one patch, removing code is suspend-resume callbacks would be other one.Vinod, while I completely agree with you in general, in this case it would make more unnecessary churn and will be rather unhelpful in all
ways: for the contributor to do this work, for the reader to collect all the pieces. It also will be a bisectability issue, because the #ifdeffery replacement (IIRC you need to move fromCONFIG_PMtoCONFIG_PM_SLEEP). I really don't see any advantages of the splitting here.Quoted 2 lines
Quoted 1 line
Compile-tested only.
Quoted 9 lines
Quoted 1 line
I would like to see some testing before we merge this
I have hardware to test (Intel Minnowboard v1) but have no time. And taking into account that I did similar changes for many other drivers, I can give my
Reviewed-by Andy Shevchenko <[email protected]>and take responsibility if somebody complains in the future (I don't believe it will be one).
Thanks! :D
Quoted 5 lines
P.S. Another scenario if Vaibhav can find that board (there were dozens of thousands at least produced and floating on the second hand market) and test himself. It may be good since he touches the full lot of PCH (EGT20) drivers.
I cannot promise, but surely will try to get my hands on it :)
Thanks
Vaibhav Gupta
Quoted 103 lines
Quoted 97 lines
Quoted 93 lines
Signed-off-by Vaibhav Gupta <[email protected]>--- drivers/dma/pch_dma.c | 35 +++++++++-------------------------- 1 file changed, 9 insertions(+), 26 deletions(-)drivers/dma/pch_dma.c +9
-27@@ -735,8 +735,7 @@ static irqreturn_t pd_irq(int irq, void *devid)return ret0 | ret2; } -#ifdef CONFIG_PM -static void pch_dma_save_regs (struct pch_dma *pd) +static void __maybe_unused pch_dma_save_regs (struct pch_dma *pd) {struct pch_dma_chan *pd_chan;struct dma_chan *chan, *_c;@@ -759,7 +758,7 @@ static void pch_dma_save_regs(struct pch_dma *pd) } } -static void pch_dma_restore_regs (struct pch_dma *pd) +static void __maybe_unused pch_dma_restore_regs (struct pch_dma *pd) {struct pch_dma_chan *pd_chan;struct dma_chan *chan, *_c;@@ -782,40 +781,25 @@ static void pch_dma_restore_regs(struct pch_dma *pd) } } -static int pch_dma_suspend (struct pci_dev *pdev,pm_message_t state) +static int __maybe_unused pch_dma_suspend (struct device *dev) { -struct pch_dma *pd =pci_get_drvdata (pdev); +struct pch_dma *pd =dev_get_drvdata (dev);if (pd)pch_dma_save_regs (pd); -pci_save_state (pdev); -pci_disable_device (pdev); -pci_set_power_state (pdev,pci_choose_state (pdev, state)); -return 0 ; } -static int pch_dma_resume (struct pci_dev *pdev) +static int __maybe_unused pch_dma_resume (struct device *dev) { -struct pch_dma *pd =pci_get_drvdata (pdev); -int err; - -pci_set_power_state (pdev,PCI_D0 ); -pci_restore_state (pdev); - - err =pci_enable_device (pdev); -if (err) { -dev_dbg (&pdev->dev,"failed to enable device\n" ); -return err; - } +struct pch_dma *pd =dev_get_drvdata (dev);if (pd)pch_dma_restore_regs (pd);return 0 ; } -#endif static int pch_dma_probe (struct pci_dev *pdev,const struct pci_device_id *id)@@ -993,15 +977,14 @@ static const struct pci_device_id pch_dma_id_table[] = { { 0, }, }; +static SIMPLE_DEV_PM_OPS(pch_dma_pm_ops, pch_dma_suspend, pch_dma_resume); +static struct pci_driver pch_dma_driver = { .name =DRV_NAME , .id_table = pch_dma_id_table, .probe = pch_dma_probe, .remove = pch_dma_remove, -#ifdef CONFIG_PM - .suspend = pch_dma_suspend, - .resume = pch_dma_resume, -#endif + .driver.pm = &pch_dma_pm_ops, };module_pci_driver (pch_dma_driver); --Quoted 1 line
2.27.0
--
~VinodSignature · 2 lines
With Best Regards, Andy Shevchenko
Vinod Koul
maintainerQuoted 35 lines · Andy Shevchenko
Quoted 12 lines · Vinod Koul
Quoted 11 lines · Vaibhav Gupta
Drivers using legacy PM have to manage PCI states and device's PM states themselves. They also need to take care of configuration registers.
With improved and powerful support of generic PM, PCI Core takes care of above mentioned, device-independent, jobs.
This driver makes use of PCI helper functions like pci_save/restore_state(), pci_enable/disable_device(),
andpci_set_power_state()to do required operations. In generic mode, they are no longer needed.Quoted 6 lines
Quoted 2 lines
Change function parameter in both .suspend() and .resume() to "struct device*" type. Use
dev_get_drvdata()to get drv data.You are doing too many things in One patch. Do consider splitting them up to a change per patch. for example using
__maybecould be one patch, removing code is suspend-resume callbacks would be other one.Vinod, while I completely agree with you in general, in this case it would make more unnecessary churn and will be rather unhelpful in all
ways: for the contributor to do this work, for the reader to collect all the pieces. It also will be a bisectability issue, because the #ifdeffery replacement (IIRC you need to move fromCONFIG_PMtoCONFIG_PM_SLEEP). I really don't see any advantages of the splitting here.Quoted 3 lines
Quoted 1 line
Compile-tested only.
I would like to see some testing before we merge this
I have hardware to test (Intel Minnowboard v1) but have no time. And taking into account that I did similar changes for many other drivers, I can give my
Quoted 8 lines
Reviewed-by Andy Shevchenko <[email protected]>and take responsibility if somebody complains in the future (I don't believe it will be one).
P.S. Another scenario if Vaibhav can find that board (there were dozens of thousands at least produced and floating on the second hand market) and test himself. It may be good since he touches the full lot of PCH (EGT20) drivers.
Applied now, thanks
Signature · 1 line
~Vinod