Message ID | 1397809071-5353-9-git-send-email-hongbo.zhang@freescale.com (mailing list archive) |
---|---|
State | Not Applicable |
Headers | show |
On Fri, Apr 18, 2014 at 04:17:51PM +0800, hongbo.zhang@freescale.com wrote: > From: Hongbo Zhang <hongbo.zhang@freescale.com> > > This patch adds suspend resume functions for Freescale DMA driver. > .prepare callback is used to stop further descriptors from being added into the > pending queue, and also issue pending queues into execution if there is any. > .suspend callback makes sure all the pending jobs are cleaned up and all the > channels are idle, and save the mode registers. > .resume callback re-initializes the channels by restore the mode registers. > > + > +static const struct dev_pm_ops fsldma_pm_ops = { > + .prepare = fsldma_prepare, > + .suspend = fsldma_suspend, > + .resume = fsldma_resume, > +}; I think this is not correct. We discussed this sometime back on list. The DMAengine drivers should use late resume and early suspend to ensure they get suspended after clients (who should use normal ones) and resume before them
On 05/03/2014 12:46 AM, Vinod Koul wrote: > On Fri, Apr 18, 2014 at 04:17:51PM +0800, hongbo.zhang@freescale.com wrote: >> From: Hongbo Zhang <hongbo.zhang@freescale.com> >> >> This patch adds suspend resume functions for Freescale DMA driver. >> .prepare callback is used to stop further descriptors from being added into the >> pending queue, and also issue pending queues into execution if there is any. >> .suspend callback makes sure all the pending jobs are cleaned up and all the >> channels are idle, and save the mode registers. >> .resume callback re-initializes the channels by restore the mode registers. >> >> + >> +static const struct dev_pm_ops fsldma_pm_ops = { >> + .prepare = fsldma_prepare, >> + .suspend = fsldma_suspend, >> + .resume = fsldma_resume, >> +}; > I think this is not correct. We discussed this sometime back on list. The > DMAengine drivers should use late resume and early suspend to ensure they get > suspended after clients (who should use normal ones) and resume before them > OK, will update it like this: use .suspend to take place of current .prepare use .suspend_late to take place of current .suspend use .resume_early to take place of current .resume
On Sun, 2014-05-04 at 18:22 +0800, Hongbo Zhang wrote: > On 05/03/2014 12:46 AM, Vinod Koul wrote: > > On Fri, Apr 18, 2014 at 04:17:51PM +0800, hongbo.zhang@freescale.com wrote: > >> From: Hongbo Zhang <hongbo.zhang@freescale.com> > >> > >> This patch adds suspend resume functions for Freescale DMA driver. > >> .prepare callback is used to stop further descriptors from being added into the > >> pending queue, and also issue pending queues into execution if there is any. > >> .suspend callback makes sure all the pending jobs are cleaned up and all the > >> channels are idle, and save the mode registers. > >> .resume callback re-initializes the channels by restore the mode registers. > >> > >> + > >> +static const struct dev_pm_ops fsldma_pm_ops = { > >> + .prepare = fsldma_prepare, > >> + .suspend = fsldma_suspend, > >> + .resume = fsldma_resume, > >> +}; > > I think this is not correct. We discussed this sometime back on list. The > > DMAengine drivers should use late resume and early suspend to ensure they get > > suspended after clients (who should use normal ones) and resume before them > > > OK, will update it like this: > use .suspend to take place of current .prepare Could you remove this at all? Answering to your previous statements I could say that. Device drivers (DMAc users) that don't implement .suspend callback are on their own with troubles, you have not to care about them in the DMA driver. > use .suspend_late to take place of current .suspend > use .resume_early to take place of current .resume > > > > -- > To unsubscribe from this list: send the line "unsubscribe dmaengine" in > the body of a message to majordomo@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html -- Andy Shevchenko <andriy.shevchenko@intel.com> Intel Finland Oy --------------------------------------------------------------------- Intel Finland Oy Registered Address: PL 281, 00181 Helsinki Business Identity Code: 0357606 - 4 Domiciled in Helsinki This e-mail and any attachments may contain confidential material for the sole use of the intended recipient(s). Any review or distribution by others is strictly prohibited. If you are not the intended recipient, please contact the sender and delete all copies.
On 05/07/2014 04:31 PM, Shevchenko, Andriy wrote: > On Sun, 2014-05-04 at 18:22 +0800, Hongbo Zhang wrote: >> On 05/03/2014 12:46 AM, Vinod Koul wrote: >>> On Fri, Apr 18, 2014 at 04:17:51PM +0800, hongbo.zhang@freescale.com wrote: >>>> From: Hongbo Zhang <hongbo.zhang@freescale.com> >>>> >>>> This patch adds suspend resume functions for Freescale DMA driver. >>>> .prepare callback is used to stop further descriptors from being added into the >>>> pending queue, and also issue pending queues into execution if there is any. >>>> .suspend callback makes sure all the pending jobs are cleaned up and all the >>>> channels are idle, and save the mode registers. >>>> .resume callback re-initializes the channels by restore the mode registers. >>>> >>>> + >>>> +static const struct dev_pm_ops fsldma_pm_ops = { >>>> + .prepare = fsldma_prepare, >>>> + .suspend = fsldma_suspend, >>>> + .resume = fsldma_resume, >>>> +}; >>> I think this is not correct. We discussed this sometime back on list. The >>> DMAengine drivers should use late resume and early suspend to ensure they get >>> suspended after clients (who should use normal ones) and resume before them >>> >> OK, will update it like this: >> use .suspend to take place of current .prepare > Could you remove this at all? > > Answering to your previous statements I could say that. > Device drivers (DMAc users) that don't implement .suspend callback are > on their own with troubles, you have not to care about them in the DMA > driver. Thanks for pointing out this issue. Then how to handle the descriptors in the pending list if there is any? a. let them finished. but if the DMA user has already suspended prior DMA controller, it is meaningless somehow and may even ask for trouble. b. don't touch them. after resume these pending descriptors could be executed, it is also meaningless because the resumed DMA user may in different state from before being suspended. c. delete them. should we do this? is is a bit crude? d. return a non-success value then the whole suspend process is reversed, e.g. suspend fails. I've looked through some dma drivers, most of them is in case b. >> use .suspend_late to take place of current .suspend >> use .resume_early to take place of current .resume >> >> >> >> -- >> To unsubscribe from this list: send the line "unsubscribe dmaengine" in >> the body of a message to majordomo@vger.kernel.org >> More majordomo info at http://vger.kernel.org/majordomo-info.html >
On Thu, May 08, 2014 at 05:52:37PM +0800, Hongbo Zhang wrote: > > On 05/07/2014 04:31 PM, Shevchenko, Andriy wrote: > >On Sun, 2014-05-04 at 18:22 +0800, Hongbo Zhang wrote: > >>On 05/03/2014 12:46 AM, Vinod Koul wrote: > >>>On Fri, Apr 18, 2014 at 04:17:51PM +0800, hongbo.zhang@freescale.com wrote: > >>>>From: Hongbo Zhang <hongbo.zhang@freescale.com> > >>>> > >>>>This patch adds suspend resume functions for Freescale DMA driver. > >>>>.prepare callback is used to stop further descriptors from being added into the > >>>>pending queue, and also issue pending queues into execution if there is any. > >>>>.suspend callback makes sure all the pending jobs are cleaned up and all the > >>>>channels are idle, and save the mode registers. > >>>>.resume callback re-initializes the channels by restore the mode registers. > >>>> > >>>>+ > >>>>+static const struct dev_pm_ops fsldma_pm_ops = { > >>>>+ .prepare = fsldma_prepare, > >>>>+ .suspend = fsldma_suspend, > >>>>+ .resume = fsldma_resume, > >>>>+}; > >>>I think this is not correct. We discussed this sometime back on list. The > >>>DMAengine drivers should use late resume and early suspend to ensure they get > >>>suspended after clients (who should use normal ones) and resume before them > >>> > >>OK, will update it like this: > >>use .suspend to take place of current .prepare > >Could you remove this at all? > > > >Answering to your previous statements I could say that. > >Device drivers (DMAc users) that don't implement .suspend callback are > >on their own with troubles, you have not to care about them in the DMA > >driver. > > Thanks for pointing out this issue. > Then how to handle the descriptors in the pending list if there is any? > a. let them finished. > but if the DMA user has already suspended prior DMA controller, > it is meaningless somehow and may even ask for trouble. > b. don't touch them. > after resume these pending descriptors could be executed, it is > also meaningless because the resumed DMA user may in different state > from before being suspended. > c. delete them. > should we do this? is is a bit crude? > d. return a non-success value > then the whole suspend process is reversed, e.g. suspend fails. > I've looked through some dma drivers, most of them is in case b. Yes and that makese sense. In calssic suspend case we maybe in middle so graceful behaviour would be to for client to PAUSE or terminate and then suspend followed by DMA suspend. You need to rely on client doing the right thing here
On 05/21/2014 11:45 AM, Vinod Koul wrote: > On Thu, May 08, 2014 at 05:52:37PM +0800, Hongbo Zhang wrote: >> On 05/07/2014 04:31 PM, Shevchenko, Andriy wrote: >>> On Sun, 2014-05-04 at 18:22 +0800, Hongbo Zhang wrote: >>>> On 05/03/2014 12:46 AM, Vinod Koul wrote: >>>>> On Fri, Apr 18, 2014 at 04:17:51PM +0800, hongbo.zhang@freescale.com wrote: >>>>>> From: Hongbo Zhang <hongbo.zhang@freescale.com> >>>>>> >>>>>> This patch adds suspend resume functions for Freescale DMA driver. >>>>>> .prepare callback is used to stop further descriptors from being added into the >>>>>> pending queue, and also issue pending queues into execution if there is any. >>>>>> .suspend callback makes sure all the pending jobs are cleaned up and all the >>>>>> channels are idle, and save the mode registers. >>>>>> .resume callback re-initializes the channels by restore the mode registers. >>>>>> >>>>>> + >>>>>> +static const struct dev_pm_ops fsldma_pm_ops = { >>>>>> + .prepare = fsldma_prepare, >>>>>> + .suspend = fsldma_suspend, >>>>>> + .resume = fsldma_resume, >>>>>> +}; >>>>> I think this is not correct. We discussed this sometime back on list. The >>>>> DMAengine drivers should use late resume and early suspend to ensure they get >>>>> suspended after clients (who should use normal ones) and resume before them >>>>> >>>> OK, will update it like this: >>>> use .suspend to take place of current .prepare >>> Could you remove this at all? >>> >>> Answering to your previous statements I could say that. >>> Device drivers (DMAc users) that don't implement .suspend callback are >>> on their own with troubles, you have not to care about them in the DMA >>> driver. >> Thanks for pointing out this issue. >> Then how to handle the descriptors in the pending list if there is any? >> a. let them finished. >> but if the DMA user has already suspended prior DMA controller, >> it is meaningless somehow and may even ask for trouble. >> b. don't touch them. >> after resume these pending descriptors could be executed, it is >> also meaningless because the resumed DMA user may in different state >> from before being suspended. >> c. delete them. >> should we do this? is is a bit crude? >> d. return a non-success value >> then the whole suspend process is reversed, e.g. suspend fails. >> I've looked through some dma drivers, most of them is in case b. > Yes and that makese sense. > > In calssic suspend case we maybe in middle so graceful behaviour would be to for > client to PAUSE or terminate and then suspend followed by DMA suspend. > You need to rely on client doing the right thing here > OK, will resend this 6/8, 7/8 and 8/8 for another iteration, and will let the current 6/8 to be the last one for being reviewed and merged easier.
diff --git a/drivers/dma/fsldma.c b/drivers/dma/fsldma.c index 6e1c9b3..836fc27 100644 --- a/drivers/dma/fsldma.c +++ b/drivers/dma/fsldma.c @@ -400,6 +400,14 @@ static dma_cookie_t fsl_dma_tx_submit(struct dma_async_tx_descriptor *tx) spin_lock_bh(&chan->desc_lock); +#ifdef CONFIG_PM + if (unlikely(chan->pm_state != RUNNING)) { + chan_dbg(chan, "cannot submit due to suspend\n"); + spin_unlock_bh(&chan->desc_lock); + return -1; + } +#endif + /* * assign cookies to all of the software descriptors * that make up this transaction @@ -1312,6 +1320,9 @@ static int fsl_dma_chan_probe(struct fsldma_device *fdev, INIT_LIST_HEAD(&chan->ld_running); INIT_LIST_HEAD(&chan->ld_completed); chan->idle = true; +#ifdef CONFIG_PM + chan->pm_state = RUNNING; +#endif chan->common.device = &fdev->common; dma_cookie_init(&chan->common); @@ -1451,6 +1462,92 @@ static int fsldma_of_remove(struct platform_device *op) return 0; } +#ifdef CONFIG_PM +static int fsldma_prepare(struct device *dev) +{ + struct platform_device *pdev = to_platform_device(dev); + struct fsldma_device *fdev = platform_get_drvdata(pdev); + struct fsldma_chan *chan; + int i; + + for (i = 0; i < FSL_DMA_MAX_CHANS_PER_DEVICE; i++) { + chan = fdev->chan[i]; + if (!chan) + continue; + + spin_lock_bh(&chan->desc_lock); + chan->pm_state = SUSPENDING; + if (!list_empty(&chan->ld_pending)) + fsl_chan_xfer_ld_queue(chan); + spin_unlock_bh(&chan->desc_lock); + } + + return 0; +} + +static int fsldma_suspend(struct device *dev) +{ + struct platform_device *pdev = to_platform_device(dev); + struct fsldma_device *fdev = platform_get_drvdata(pdev); + struct fsldma_chan *chan; + int i; + + for (i = 0; i < FSL_DMA_MAX_CHANS_PER_DEVICE; i++) { + chan = fdev->chan[i]; + if (!chan) + continue; + + spin_lock_bh(&chan->desc_lock); + if (!chan->idle) + goto out; + chan->regs_save.mr = get_mr(chan); + chan->pm_state = SUSPENDED; + spin_unlock_bh(&chan->desc_lock); + } + return 0; + +out: + for (; i >= 0; i--) { + chan = fdev->chan[i]; + if (!chan) + continue; + chan->pm_state = RUNNING; + spin_unlock_bh(&chan->desc_lock); + } + return -EBUSY; +} + +static int fsldma_resume(struct device *dev) +{ + struct platform_device *pdev = to_platform_device(dev); + struct fsldma_device *fdev = platform_get_drvdata(pdev); + struct fsldma_chan *chan; + u32 mode; + int i; + + for (i = 0; i < FSL_DMA_MAX_CHANS_PER_DEVICE; i++) { + chan = fdev->chan[i]; + if (!chan) + continue; + + spin_lock_bh(&chan->desc_lock); + mode = chan->regs_save.mr + & ~FSL_DMA_MR_CS & ~FSL_DMA_MR_CC & ~FSL_DMA_MR_CA; + set_mr(chan, mode); + chan->pm_state = RUNNING; + spin_unlock_bh(&chan->desc_lock); + } + + return 0; +} + +static const struct dev_pm_ops fsldma_pm_ops = { + .prepare = fsldma_prepare, + .suspend = fsldma_suspend, + .resume = fsldma_resume, +}; +#endif + static const struct of_device_id fsldma_of_ids[] = { { .compatible = "fsl,elo3-dma", }, { .compatible = "fsl,eloplus-dma", }, @@ -1463,6 +1560,9 @@ static struct platform_driver fsldma_of_driver = { .name = "fsl-elo-dma", .owner = THIS_MODULE, .of_match_table = fsldma_of_ids, +#ifdef CONFIG_PM + .pm = &fsldma_pm_ops, +#endif }, .probe = fsldma_of_probe, .remove = fsldma_of_remove, diff --git a/drivers/dma/fsldma.h b/drivers/dma/fsldma.h index ec19517..eecaf9e 100644 --- a/drivers/dma/fsldma.h +++ b/drivers/dma/fsldma.h @@ -134,6 +134,18 @@ struct fsldma_device { #define FSL_DMA_CHAN_PAUSE_EXT 0x00001000 #define FSL_DMA_CHAN_START_EXT 0x00002000 +#ifdef CONFIG_PM +struct fsldma_chan_regs_save { + u32 mr; +}; + +enum fsldma_pm_state { + RUNNING = 0, + SUSPENDING, + SUSPENDED, +}; +#endif + struct fsldma_chan { char name[8]; /* Channel name */ struct fsldma_chan_regs __iomem *regs; @@ -161,6 +173,10 @@ struct fsldma_chan { struct tasklet_struct tasklet; u32 feature; bool idle; /* DMA controller is idle */ +#ifdef CONFIG_PM + struct fsldma_chan_regs_save regs_save; + enum fsldma_pm_state pm_state; +#endif void (*toggle_ext_pause)(struct fsldma_chan *fsl_chan, int enable); void (*toggle_ext_start)(struct fsldma_chan *fsl_chan, int enable);