Re: [v3,4/5] powerpc/pm: support deep sleep feature on T104x

From: Scott Wood
Date: Wed Sep 28 2016 - 16:03:34 EST


On Tue, 2016-09-27 at 11:05 +0000, C.H. Zhao wrote:
> From: Scott Wood <oss@xxxxxxxxxxxx>
> Sent: Sunday, September 25, 2016 3:24 PM
> To: C.H. Zhao
> Cc: linuxppc-dev@xxxxxxxxxxxxxxxx; linux-kernel@xxxxxxxxxxxxxxx; z.chenhui@g
> mail.com; Jason Jin
> Subject: Re: [v3,4/5] powerpc/pm: support deep sleep feature on T104x
> ÂÂÂÂ
> On Tue, Aug 02, 2016 at 07:59:31PM +0800, Chenhui Zhao wrote:
> >
> > T104x has deep sleep feature, which can switch off most parts of
> > the SoC when it is in deep sleep mode. This way, it becomes more
> > energy-efficient.
> >
> > The DDR controller will also be powered off in deep sleep. Therefore,
> > the last stage (the latter part of fsl_dp_enter_low) will run without DDR
> > access. This piece of code and related TLBs are prefetched in advance.
> >
> > Due to the different initialization code between 32-bit and 64-bit, they
> > have separate resume entry and precedure.
> >
> > The feature supports 32-bit and 64-bit kernel mode.
> >
> > Signed-off-by: Chenhui Zhao <chenhui.zhao@xxxxxxx>
> > ---
> > Â arch/powerpc/include/asm/fsl_pm.hÂÂÂÂÂÂÂÂÂÂÂÂ |Â 24 ++
> > Â arch/powerpc/kernel/asm-offsets.cÂÂÂÂÂÂÂÂÂÂÂÂ |Â 12 +
> > Â arch/powerpc/kernel/fsl_booke_entry_mapping.S |Â 10 +
> > Â arch/powerpc/kernel/head_64.SÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ |ÂÂ 2 +-
> > Â arch/powerpc/platforms/85xx/MakefileÂÂÂÂÂÂÂÂÂ |ÂÂ 1 +
> > Â arch/powerpc/platforms/85xx/deepsleep.cÂÂÂÂÂÂ | 278 ++++++++++++++
> > Â arch/powerpc/platforms/85xx/qoriq_pm.cÂÂÂÂÂÂÂ |Â 25 ++
> > Â arch/powerpc/platforms/85xx/t104x_deepsleep.S | 531
> > ++++++++++++++++++++++++++
> > Â arch/powerpc/sysdev/fsl_rcpm.cÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ |ÂÂ 8 +-
> > Â 9 files changed, 889 insertions(+), 2 deletions(-)
> > Â create mode 100644 arch/powerpc/platforms/85xx/deepsleep.c
> > Â create mode 100644 arch/powerpc/platforms/85xx/t104x_deepsleep.S
> >
> > diff --git a/arch/powerpc/include/asm/fsl_pm.h
> > b/arch/powerpc/include/asm/fsl_pm.h
> > index e05049b..48c2631 100644
> > --- a/arch/powerpc/include/asm/fsl_pm.h
> > +++ b/arch/powerpc/include/asm/fsl_pm.h
> > @@ -20,6 +20,7 @@
> > ÂÂ
> > Â #define PLAT_PM_SLEEPÂÂÂÂÂÂÂ 20
> > Â #define PLAT_PM_LPM20ÂÂÂÂÂÂÂ 30
> > +#define PLAT_PM_LPM35ÂÂÂÂÂÂÂ 40
> > ÂÂ
> > Â #define FSL_PM_SLEEPÂÂÂÂÂÂÂÂ (1 << 0)
> > Â #define FSL_PM_DEEP_SLEEPÂÂÂ (1 << 1)
> > @@ -48,4 +49,27 @@ extern const struct fsl_pm_ops *qoriq_pm_ops;
> > ÂÂ
> > Â int __init fsl_rcpm_init(void);
> > ÂÂ
> > +#ifdef CONFIG_FSL_QORIQ_PM
> > +int fsl_enter_deepsleep(void);
> > +int fsl_deepsleep_init(void);
> > +#else
> > +static inline int fsl_enter_deepsleep(void) { return -1; }
> > +static inline int fsl_deepsleep_init(void) { return -1; }
> > +#endif
> Please return proper error codes.
>
> Where can fsl_deepsleep_init() be called without CONFIG_FSL_QORIQ_PM?
>
> [Chenhui] I can get rid of the ifdef here. And add it
> inÂarch/powerpc/sysdev/fsl_rcpm.c.

No, this is the right place for the ifdef for functions that are called from
code that doesn't depend on CONFIG_FSL_QORIQ_PM. ÂBut fsl_deepsleep_init() is
called from deepsleep.c which is only built with CONFIG_FSL_QORIQ_PM, and it's
hard to picture a scenario where it would be called from elsewhere.

> > diff --git a/arch/powerpc/kernel/fsl_booke_entry_mapping.S
> > b/arch/powerpc/kernel/fsl_booke_entry_mapping.S
> > index 83dd0f6..659b059 100644
> > --- a/arch/powerpc/kernel/fsl_booke_entry_mapping.S
> > +++ b/arch/powerpc/kernel/fsl_booke_entry_mapping.S
> > @@ -173,6 +173,10 @@ skpinv:Â addiÂÂÂ r6,r6,1ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ /*
> > Increment */
> > ÂÂÂÂÂÂÂ lisÂÂÂÂ r6,MAS2_VAL(PAGE_OFFSET, BOOK3E_PAGESZ_64M, M_IF_NEEDED)@h
> > ÂÂÂÂÂÂÂ oriÂÂÂÂ r6,r6,MAS2_VAL(PAGE_OFFSET, BOOK3E_PAGESZ_64M,
> > M_IF_NEEDED)@l
> > ÂÂÂÂÂÂÂ mtsprÂÂ SPRN_MAS2,r6
> > +#ifdef ENTRY_DEEPSLEEP_SETUP
> > +ÂÂÂÂ LOAD_REG_IMMEDIATE(r8, MEMORY_START)
> > +ÂÂÂÂ oriÂÂÂÂ r8,r8,(MAS3_SX|MAS3_SW|MAS3_SR)
> > +#endif
> > ÂÂÂÂÂÂÂ mtsprÂÂ SPRN_MAS3,r8
> > ÂÂÂÂÂÂÂ tlbwe
> > ÂÂ
> Have you tried this with a relocatable kernel?
>
> [Chenhui] Not yet. Not sure whether it has been supported on QorIQ platform.

It is supported, and deep sleep needs to work with it.

> > +static void fsl_dp_set_resume_pointer(void)
> > +{
> > +ÂÂÂÂ u32 resume_addr;
> > +
> > +ÂÂÂÂ /* the bootloader will finally jump to this address to return kernel
> > */
> > +#ifdef CONFIG_PPC32
> > +ÂÂÂÂ resume_addr = (u32)(__pa(fsl_booke_deep_sleep_resume));
> > +#else
> > +ÂÂÂÂ resume_addr = (u32)(__pa(*(u64 *)fsl_booke_deep_sleep_resume)
> > +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ & 0xffffffff);
> > +#endif
> Why are you masking the physical address by 0xffffffff? Besides the
> (u32) cast accomplishing the same thing, wouldn't it be a problem if
> (e.g. due to a relocatable kernel) the address is above 4 GiB?
>
> [Chenhui] Here, I assumed kernel is below 4 GiB. Maybe I should add a
> comment here.

It needs a fix rather than a comment, unless you can show that the relocatable
mechanism doesn't support kernels over 4 GiB (I don't remember of the top of
my head whether it does).

-Scott